LCOV - code coverage report
Current view: top level - framework/source/fwe/xml - toolboxconfiguration.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 10 30 33.3 %
Date: 2015-06-13 12:38:46 Functions: 1 2 50.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/toolboxconfiguration.hxx>
      21             : #include <xml/toolboxdocumenthandler.hxx>
      22             : #include <xml/saxnamespacefilter.hxx>
      23             : #include <services.h>
      24             : 
      25             : #include <com/sun/star/xml/sax/Parser.hpp>
      26             : #include <com/sun/star/xml/sax/Writer.hpp>
      27             : #include <com/sun/star/io/XActiveDataSource.hpp>
      28             : #include <com/sun/star/io/XInputStream.hpp>
      29             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      30             : 
      31             : #include <comphelper/processfactory.hxx>
      32             : #include <unotools/streamwrap.hxx>
      33             : 
      34             : using namespace ::com::sun::star::uno;
      35             : using namespace ::com::sun::star::xml::sax;
      36             : using namespace ::com::sun::star::lang;
      37             : using namespace ::com::sun::star::io;
      38             : using namespace ::com::sun::star::container;
      39             : 
      40             : namespace framework
      41             : {
      42             : 
      43         125 : bool ToolBoxConfiguration::LoadToolBox(
      44             :     const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
      45             :     const ::com::sun::star::uno::Reference< ::com::sun::star::io::XInputStream >& rInputStream,
      46             :     const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& rToolbarConfiguration )
      47             : {
      48         125 :     Reference< XParser > xParser = Parser::create(rxContext);
      49             : 
      50             :     // connect stream to input stream to the parser
      51         250 :     InputSource aInputSource;
      52             : 
      53         125 :     aInputSource.aInputStream = rInputStream;
      54             : 
      55             :     // create namespace filter and set menudocument handler inside to support xml namespaces
      56         250 :     Reference< XDocumentHandler > xDocHandler( new OReadToolBoxDocumentHandler( rToolbarConfiguration ));
      57         250 :     Reference< XDocumentHandler > xFilter( new SaxNamespaceFilter( xDocHandler ));
      58             : 
      59             :     // connect parser and filter
      60         125 :     xParser->setDocumentHandler( xFilter );
      61             : 
      62             :     try
      63             :     {
      64         125 :         xParser->parseStream( aInputSource );
      65         125 :         return true;
      66             :     }
      67           0 :     catch ( const RuntimeException& )
      68             :     {
      69           0 :         return false;
      70             :     }
      71           0 :     catch( const SAXException& )
      72             :     {
      73           0 :         return false;
      74             :     }
      75           0 :     catch( const ::com::sun::star::io::IOException& )
      76             :     {
      77           0 :         return false;
      78         125 :     }
      79             : }
      80             : 
      81           0 : bool ToolBoxConfiguration::StoreToolBox(
      82             :     const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& rxContext,
      83             :     const ::com::sun::star::uno::Reference< ::com::sun::star::io::XOutputStream >& rOutputStream,
      84             :     const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rToolbarConfiguration )
      85             : {
      86           0 :     Reference< XWriter > xWriter = Writer::create(rxContext);
      87           0 :     xWriter->setOutputStream( rOutputStream );
      88             : 
      89             :     try
      90             :     {
      91           0 :         Reference< XDocumentHandler > xHandler( xWriter, UNO_QUERY_THROW );
      92           0 :         OWriteToolBoxDocumentHandler aWriteToolBoxDocumentHandler( rToolbarConfiguration, xHandler );
      93           0 :         aWriteToolBoxDocumentHandler.WriteToolBoxDocument();
      94           0 :         return true;
      95             :     }
      96           0 :     catch ( const RuntimeException& )
      97             :     {
      98           0 :         return false;
      99             :     }
     100           0 :     catch ( const SAXException& )
     101             :     {
     102           0 :         return false;
     103             :     }
     104           0 :     catch ( const ::com::sun::star::io::IOException& )
     105             :     {
     106           0 :         return false;
     107           0 :     }
     108             : }
     109             : 
     110             : }
     111             : 
     112             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11