LCOV - code coverage report
Current view: top level - libreoffice/framework/source/fwe/xml - menuconfiguration.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 45 0.0 %
Date: 2012-12-27 Functions: 0 6 0.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           0 : MenuConfiguration::MenuConfiguration(
      47             :     const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rServiceManager )
      48           0 : :   m_rxServiceManager( rServiceManager )
      49             : {
      50           0 : }
      51             : 
      52             : 
      53           0 : MenuConfiguration::~MenuConfiguration()
      54             : {
      55           0 : }
      56             : 
      57             : 
      58           0 : Reference< XIndexAccess > MenuConfiguration::CreateMenuBarConfigurationFromXML(
      59             :     Reference< XInputStream >& rInputStream )
      60             : throw ( WrappedTargetException )
      61             : {
      62           0 :     Reference< XParser > xParser = Parser::create( comphelper::getComponentContext(m_rxServiceManager) );
      63             : 
      64             :     // connect stream to input stream to the parser
      65           0 :     InputSource aInputSource;
      66             : 
      67           0 :     aInputSource.aInputStream = rInputStream;
      68             : 
      69             : 
      70             :     // create menu bar
      71           0 :     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           0 :     Reference< XDocumentHandler > xDocHandler( new OReadMenuDocumentHandler( xItemContainer ));
      76             : 
      77           0 :     Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
      78             : 
      79             :     // connect parser and filter
      80           0 :     xParser->setDocumentHandler( xFilter );
      81             : 
      82             :     try
      83             :     {
      84           0 :         xParser->parseStream( aInputSource );
      85           0 :         return Reference< XIndexAccess >( xItemContainer, UNO_QUERY );
      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           0 :     }
     104             : }
     105             : 
     106           0 : PopupMenu* MenuConfiguration::CreateBookmarkMenu(
     107             :     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame,
     108             :     const ::rtl::OUString& aURL )
     109             : throw ( ::com::sun::star::lang::WrappedTargetException )
     110             : {
     111           0 :     if ( aURL == BOOKMARK_NEWMENU )
     112           0 :         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(comphelper::getComponentContext(m_rxServiceManager));
     125           0 :     xWriter->setOutputStream( rOutputStream );
     126             : 
     127             :     try
     128             :     {
     129           0 :         Reference< XDocumentHandler > xHandler(xWriter, UNO_QUERY_THROW);
     130           0 :         OWriteMenuDocumentHandler aWriteMenuDocumentHandler( rMenuBarConfiguration, xHandler );
     131           0 :         aWriteMenuDocumentHandler.WriteMenuDocument();
     132             :     }
     133           0 :     catch ( const RuntimeException& e )
     134             :     {
     135           0 :         throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
     136             :     }
     137           0 :     catch ( const SAXException& e )
     138             :     {
     139           0 :         throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
     140             :     }
     141           0 :     catch ( const ::com::sun::star::io::IOException& e )
     142             :     {
     143           0 :         throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
     144           0 :     }
     145           0 : }
     146             : 
     147             : }
     148             : 
     149             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10