LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/framework/source/fwe/xml - menuconfiguration.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 20 45 44.4 %
Date: 2013-07-09 Functions: 6 8 75.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <framework/menuconfiguration.hxx>
      21             : 
      22             : #include <framework/bmkmenu.hxx>
      23             : #include <framework/addonmenu.hxx>
      24             : #include <xml/menudocumenthandler.hxx>
      25             : #include <xml/saxnamespacefilter.hxx>
      26             : #include <services.h>
      27             : 
      28             : #include <uielement/rootitemcontainer.hxx>
      29             : 
      30             : #include <com/sun/star/xml/sax/Parser.hpp>
      31             : #include <com/sun/star/xml/sax/Writer.hpp>
      32             : #include <com/sun/star/io/XActiveDataSource.hpp>
      33             : #include <com/sun/star/frame/XFrame.hpp>
      34             : #include <comphelper/processfactory.hxx>
      35             : 
      36             : using namespace ::com::sun::star::uno;
      37             : using namespace ::com::sun::star::lang;
      38             : using namespace ::com::sun::star::beans;
      39             : using namespace ::com::sun::star::xml::sax;
      40             : using namespace ::com::sun::star::container;
      41             : using namespace ::com::sun::star::io;
      42             : 
      43             : namespace framework
      44             : {
      45             : 
      46         688 : MenuConfiguration::MenuConfiguration(
      47             :     const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext )
      48         688 : :   m_xContext( rxContext )
      49             : {
      50         688 : }
      51             : 
      52             : 
      53         688 : MenuConfiguration::~MenuConfiguration()
      54             : {
      55         688 : }
      56             : 
      57             : 
      58          48 : Reference< XIndexAccess > MenuConfiguration::CreateMenuBarConfigurationFromXML(
      59             :     Reference< XInputStream >& rInputStream )
      60             : throw ( WrappedTargetException )
      61             : {
      62          48 :     Reference< XParser > xParser = Parser::create( m_xContext );
      63             : 
      64             :     // connect stream to input stream to the parser
      65          96 :     InputSource aInputSource;
      66             : 
      67          48 :     aInputSource.aInputStream = rInputStream;
      68             : 
      69             : 
      70             :     // create menu bar
      71          96 :     Reference< XIndexContainer > xItemContainer( static_cast< cppu::OWeakObject *>( new RootItemContainer()), UNO_QUERY );
      72             : 
      73             :     // create namespace filter and set menudocument handler inside to support xml namespaces
      74             : 
      75          96 :     Reference< XDocumentHandler > xDocHandler( new OReadMenuDocumentHandler( xItemContainer ));
      76             : 
      77          96 :     Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
      78             : 
      79             :     // connect parser and filter
      80          48 :     xParser->setDocumentHandler( xFilter );
      81             : 
      82             :     try
      83             :     {
      84          48 :         xParser->parseStream( aInputSource );
      85          96 :         return xItemContainer;
      86             :     }
      87           0 :     catch ( const RuntimeException& e )
      88             :     {
      89           0 :         throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
      90             :     }
      91           0 :     catch( const SAXException& e )
      92             :     {
      93           0 :         SAXException aWrappedSAXException;
      94             : 
      95           0 :         if ( !( e.WrappedException >>= aWrappedSAXException ))
      96           0 :             throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
      97             :         else
      98           0 :             throw WrappedTargetException( aWrappedSAXException.Message, Reference< XInterface >(), Any() );
      99             :     }
     100           0 :     catch( const ::com::sun::star::io::IOException& e )
     101             :     {
     102           0 :         throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
     103          48 :     }
     104             : }
     105             : 
     106         640 : PopupMenu* MenuConfiguration::CreateBookmarkMenu(
     107             :     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
     108             :     const OUString& aURL )
     109             : throw ( ::com::sun::star::lang::WrappedTargetException )
     110             : {
     111         640 :     if ( aURL == BOOKMARK_NEWMENU )
     112         640 :         return new BmkMenu( rFrame, BmkMenu::BMK_NEWMENU );
     113           0 :     else if ( aURL == BOOKMARK_WIZARDMENU )
     114           0 :         return new BmkMenu( rFrame, BmkMenu::BMK_WIZARDMENU );
     115             :     else
     116           0 :         return NULL;
     117             : }
     118             : 
     119           0 : void MenuConfiguration::StoreMenuBarConfigurationToXML(
     120             :     Reference< XIndexAccess >& rMenuBarConfiguration,
     121             :     Reference< XOutputStream >& rOutputStream )
     122             : throw ( WrappedTargetException )
     123             : {
     124           0 :     Reference< XWriter > xWriter = Writer::create(m_xContext);
     125           0 :     xWriter->setOutputStream( rOutputStream );
     126             : 
     127             :     try
     128             :     {
     129           0 :         OWriteMenuDocumentHandler aWriteMenuDocumentHandler( rMenuBarConfiguration, xWriter );
     130           0 :         aWriteMenuDocumentHandler.WriteMenuDocument();
     131             :     }
     132           0 :     catch ( const RuntimeException& e )
     133             :     {
     134           0 :         throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
     135             :     }
     136           0 :     catch ( const SAXException& e )
     137             :     {
     138           0 :         throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
     139             :     }
     140           0 :     catch ( const ::com::sun::star::io::IOException& e )
     141             :     {
     142           0 :         throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
     143           0 :     }
     144           0 : }
     145             : 
     146         411 : }
     147             : 
     148             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10