LCOV - code coverage report
Current view: top level - framework/source/fwe/xml - menuconfiguration.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 32 57 56.1 %
Date: 2015-06-13 12:38:46 Functions: 7 9 77.8 %
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         667 : MenuConfiguration::MenuConfiguration(
      47             :     const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext )
      48         667 : :   m_xContext( rxContext )
      49             : {
      50         667 : }
      51             : 
      52         667 : MenuConfiguration::~MenuConfiguration()
      53             : {
      54         667 : }
      55             : 
      56          61 : Reference< XIndexAccess > MenuConfiguration::CreateMenuBarConfigurationFromXML(
      57             :     Reference< XInputStream >& rInputStream )
      58             :         throw (WrappedTargetException, RuntimeException)
      59             : {
      60          61 :     Reference< XParser > xParser = Parser::create( m_xContext );
      61             : 
      62             :     // connect stream to input stream to the parser
      63         122 :     InputSource aInputSource;
      64             : 
      65          61 :     aInputSource.aInputStream = rInputStream;
      66             : 
      67             :     // create menu bar
      68         122 :     Reference< XIndexContainer > xItemContainer( static_cast< cppu::OWeakObject *>( new RootItemContainer()), UNO_QUERY );
      69             : 
      70             :     // create namespace filter and set menudocument handler inside to support xml namespaces
      71             : 
      72         122 :     Reference< XDocumentHandler > xDocHandler( new OReadMenuDocumentHandler( xItemContainer ));
      73             : 
      74         122 :     Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
      75             : 
      76             :     // connect parser and filter
      77          61 :     xParser->setDocumentHandler( xFilter );
      78             : 
      79             :     try
      80             :     {
      81          61 :         xParser->parseStream( aInputSource );
      82         122 :         return xItemContainer;
      83             :     }
      84           0 :     catch ( const RuntimeException& e )
      85             :     {
      86           0 :         throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
      87             :     }
      88           0 :     catch( const SAXException& e )
      89             :     {
      90           0 :         SAXException aWrappedSAXException;
      91             : 
      92           0 :         if ( !( e.WrappedException >>= aWrappedSAXException ))
      93           0 :             throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
      94             :         else
      95           0 :             throw WrappedTargetException( aWrappedSAXException.Message, Reference< XInterface >(), Any() );
      96             :     }
      97           0 :     catch( const ::com::sun::star::io::IOException& e )
      98             :     {
      99           0 :         throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
     100          61 :     }
     101             : }
     102             : 
     103         606 : PopupMenu* MenuConfiguration::CreateBookmarkMenu(css::uno::Reference<css::frame::XFrame >& rFrame, const OUString& aURL)
     104             :     throw (css::lang::WrappedTargetException,
     105             :            css::uno::RuntimeException)
     106             : {
     107         606 :     if ( aURL == BOOKMARK_NEWMENU )
     108         606 :         return new BmkMenu( rFrame, BmkMenu::BMK_NEWMENU );
     109           0 :     else if ( aURL == BOOKMARK_WIZARDMENU )
     110           0 :         return new BmkMenu( rFrame, BmkMenu::BMK_WIZARDMENU );
     111             :     else
     112           0 :         return NULL;
     113             : }
     114             : 
     115           0 : void MenuConfiguration::StoreMenuBarConfigurationToXML(
     116             :     Reference< XIndexAccess >& rMenuBarConfiguration,
     117             :     Reference< XOutputStream >& rOutputStream )
     118             :     throw (WrappedTargetException, RuntimeException)
     119             : {
     120           0 :     Reference< XWriter > xWriter = Writer::create(m_xContext);
     121           0 :     xWriter->setOutputStream( rOutputStream );
     122             : 
     123             :     try
     124             :     {
     125           0 :         OWriteMenuDocumentHandler aWriteMenuDocumentHandler( rMenuBarConfiguration, xWriter );
     126           0 :         aWriteMenuDocumentHandler.WriteMenuDocument();
     127             :     }
     128           0 :     catch ( const RuntimeException& e )
     129             :     {
     130           0 :         throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
     131             :     }
     132           0 :     catch ( const SAXException& e )
     133             :     {
     134           0 :         throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
     135             :     }
     136           0 :     catch ( const ::com::sun::star::io::IOException& e )
     137             :     {
     138           0 :         throw WrappedTargetException( e.Message, Reference< XInterface >(), Any() );
     139           0 :     }
     140           0 : }
     141             : 
     142        7272 : sal_uIntPtr MenuAttributes::CreateAttribute(const OUString& rFrame, const OUString& rImageIdStr)
     143             : {
     144        7272 :     MenuAttributes* pAttributes = new MenuAttributes(rFrame, rImageIdStr);
     145        7272 :     pAttributes->acquire();
     146        7272 :     return reinterpret_cast<sal_uIntPtr>(pAttributes);
     147             : }
     148             : 
     149          16 : sal_uIntPtr MenuAttributes::CreateAttribute(const css::uno::WeakReference<css::frame::XDispatchProvider>& rDispatchProvider)
     150             : {
     151          16 :     MenuAttributes* pAttributes = new MenuAttributes(rDispatchProvider);
     152          16 :     pAttributes->acquire();
     153          16 :     return reinterpret_cast<sal_uIntPtr>(pAttributes);
     154             : }
     155             : 
     156       14552 : void MenuAttributes::ReleaseAttribute(sal_uIntPtr nAttributePtr)
     157             : {
     158       14552 :     if (!nAttributePtr)
     159       14552 :         return;
     160       14552 :     MenuAttributes* pAttributes = reinterpret_cast<MenuAttributes*>(nAttributePtr);
     161       14552 :     pAttributes->release();
     162             : }
     163             : 
     164             : }
     165             : 
     166             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11