LCOV - code coverage report
Current view: top level - package/source/manifest - ManifestReader.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 33 42 78.6 %
Date: 2014-11-03 Functions: 8 11 72.7 %
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 <ManifestReader.hxx>
      21             : #include <ManifestImport.hxx>
      22             : #include <comphelper/processfactory.hxx>
      23             : #include <cppuhelper/factory.hxx>
      24             : #include <cppuhelper/supportsservice.hxx>
      25             : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
      26             : #include <com/sun/star/xml/sax/SAXParseException.hpp>
      27             : #include <com/sun/star/xml/sax/Parser.hpp>
      28             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      29             : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
      30             : #include <vector>
      31             : 
      32             : using namespace ::std;
      33             : using namespace ::com::sun::star::uno;
      34             : using namespace ::com::sun::star::beans;
      35             : using namespace ::com::sun::star::io;
      36             : using namespace ::com::sun::star::lang;
      37             : using namespace ::com::sun::star::registry;
      38             : using namespace ::com::sun::star::packages;
      39             : using namespace ::com::sun::star::xml::sax;
      40             : 
      41        1390 : ManifestReader::ManifestReader( const Reference < XComponentContext > & xContext )
      42        1390 : : m_xContext ( xContext )
      43             : {
      44        1390 : }
      45        2780 : ManifestReader::~ManifestReader()
      46             : {
      47        2780 : }
      48        1388 : Sequence< Sequence< PropertyValue > > SAL_CALL ManifestReader::readManifestSequence( const Reference< XInputStream >& rStream )
      49             :     throw (::com::sun::star::uno::RuntimeException, std::exception)
      50             : {
      51        1388 :     Sequence < Sequence < PropertyValue > > aManifestSequence;
      52        2776 :     Reference < XParser > xParser  = Parser::create(m_xContext);
      53             :     try
      54             :     {
      55        1388 :         vector < Sequence < PropertyValue > > aManVector;
      56        2776 :         Reference < XDocumentHandler > xFilter = new ManifestImport( aManVector );
      57        2776 :         InputSource aParserInput;
      58        1388 :         aParserInput.aInputStream = rStream;
      59        1388 :         aParserInput.sSystemId = "META-INF/manifest.xml";
      60        1388 :         xParser->setDocumentHandler ( xFilter );
      61        1388 :         xParser->parseStream( aParserInput );
      62        1388 :         aManifestSequence.realloc ( aManVector.size() );
      63        1388 :         Sequence < PropertyValue > * pSequence = aManifestSequence.getArray();
      64        1388 :         ::std::vector < Sequence < PropertyValue > >::const_iterator aIter = aManVector.begin();
      65        1388 :         ::std::vector < Sequence < PropertyValue > >::const_iterator aEnd = aManVector.end();
      66       15998 :         while( aIter != aEnd )
      67       14610 :             *pSequence++ = (*aIter++);
      68             :     }
      69           0 :     catch (SAXParseException& e)
      70             :     {
      71             :         SAL_WARN("package", "ignoring SAXParseException " + e.Message);
      72             :     }
      73           0 :     catch (SAXException& e)
      74             :     {
      75             :         SAL_WARN("package", "ignoring SAXException " + e.Message);
      76             :     }
      77           0 :     catch (IOException& e)
      78             :     {
      79             :         SAL_WARN("package", "ignoring IOException " + e.Message);
      80             :     }
      81        1388 :     xParser->setDocumentHandler ( Reference < XDocumentHandler > () );
      82        2776 :     return aManifestSequence;
      83             : }
      84             : // Component functions
      85             : 
      86        1390 : Reference < XInterface > SAL_CALL ManifestReader_createInstance( Reference< XMultiServiceFactory > const & rServiceFactory )
      87             : {
      88        1390 :     return *new ManifestReader( comphelper::getComponentContext(rServiceFactory) );
      89             : }
      90         650 : OUString ManifestReader::static_getImplementationName()
      91             : {
      92         650 :     return OUString( "com.sun.star.packages.manifest.comp.ManifestReader" );
      93             : }
      94             : 
      95         126 : Sequence < OUString > ManifestReader::static_getSupportedServiceNames()
      96             : {
      97         126 :     Sequence < OUString > aNames(1);
      98         126 :     aNames[0] = "com.sun.star.packages.manifest.ManifestReader";
      99         126 :     return aNames;
     100             : }
     101             : 
     102           0 : OUString ManifestReader::getImplementationName()
     103             :     throw (RuntimeException, std::exception)
     104             : {
     105           0 :     return static_getImplementationName();
     106             : }
     107             : 
     108           0 : sal_Bool SAL_CALL ManifestReader::supportsService(OUString const & rServiceName)
     109             :     throw (RuntimeException, std::exception)
     110             : {
     111           0 :     return cppu::supportsService(this, rServiceName );
     112             : }
     113             : 
     114           0 : Sequence < OUString > ManifestReader::getSupportedServiceNames()
     115             :     throw (RuntimeException, std::exception)
     116             : {
     117           0 :     return static_getSupportedServiceNames();
     118             : }
     119         126 : Reference < XSingleServiceFactory > ManifestReader::createServiceFactory( Reference < XMultiServiceFactory > const & rServiceFactory )
     120             : {
     121             :     return cppu::createSingleFactory (rServiceFactory,
     122             :                                            static_getImplementationName(),
     123             :                                            ManifestReader_createInstance,
     124         126 :                                            static_getSupportedServiceNames());
     125             : }
     126             : 
     127             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10