1a3872823SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3a3872823SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4a3872823SAndrew Rist * or more contributor license agreements. See the NOTICE file 5a3872823SAndrew Rist * distributed with this work for additional information 6a3872823SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7a3872823SAndrew Rist * to you under the Apache License, Version 2.0 (the 8a3872823SAndrew Rist * "License"); you may not use this file except in compliance 9a3872823SAndrew Rist * with the License. You may obtain a copy of the License at 10a3872823SAndrew Rist * 11a3872823SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12a3872823SAndrew Rist * 13a3872823SAndrew Rist * Unless required by applicable law or agreed to in writing, 14a3872823SAndrew Rist * software distributed under the License is distributed on an 15a3872823SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16a3872823SAndrew Rist * KIND, either express or implied. See the License for the 17a3872823SAndrew Rist * specific language governing permissions and limitations 18a3872823SAndrew Rist * under the License. 19a3872823SAndrew Rist * 20a3872823SAndrew Rist *************************************************************/ 21a3872823SAndrew Rist 22a3872823SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_package.hxx" 26cdf0e10cSrcweir #include <ManifestReader.hxx> 27cdf0e10cSrcweir #include <ManifestImport.hxx> 28cdf0e10cSrcweir #include <cppuhelper/factory.hxx> 29cdf0e10cSrcweir #ifndef _COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP 30cdf0e10cSrcweir #include <com/sun/star/xml/sax/XDocumentHandler.hpp> 31cdf0e10cSrcweir #endif 32cdf0e10cSrcweir #ifndef _COM_SUN_STAR_XML_SAX_SAXPARSEEXCEPTION_HPP 33cdf0e10cSrcweir #include <com/sun/star/xml/sax/SAXParseException.hpp> 34cdf0e10cSrcweir #endif 35cdf0e10cSrcweir #ifndef _COM_SUN_STAR_XML_SAX_XPARSER_HPP 36cdf0e10cSrcweir #include <com/sun/star/xml/sax/XParser.hpp> 37cdf0e10cSrcweir #endif 38cdf0e10cSrcweir #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP 39cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 40cdf0e10cSrcweir #endif 41cdf0e10cSrcweir #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP 42cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp> 43cdf0e10cSrcweir #endif 44cdf0e10cSrcweir #include <vector> 45cdf0e10cSrcweir 46cdf0e10cSrcweir using namespace ::rtl; 47cdf0e10cSrcweir using namespace ::std; 48cdf0e10cSrcweir using namespace ::com::sun::star::uno; 49cdf0e10cSrcweir using namespace ::com::sun::star::beans; 50cdf0e10cSrcweir using namespace ::com::sun::star::io; 51cdf0e10cSrcweir using namespace ::com::sun::star::lang; 52cdf0e10cSrcweir using namespace ::com::sun::star::registry; 53cdf0e10cSrcweir using namespace ::com::sun::star::packages; 54cdf0e10cSrcweir using namespace ::com::sun::star::xml::sax; 55cdf0e10cSrcweir using namespace ::com::sun::star::packages::manifest; 56cdf0e10cSrcweir ManifestReader(const Reference<XMultiServiceFactory> & xNewFactory)57cdf0e10cSrcweirManifestReader::ManifestReader( const Reference < XMultiServiceFactory > & xNewFactory ) 58cdf0e10cSrcweir : xFactory ( xNewFactory ) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir } ~ManifestReader()61cdf0e10cSrcweirManifestReader::~ManifestReader() 62cdf0e10cSrcweir { 63cdf0e10cSrcweir } readManifestSequence(const Reference<XInputStream> & rStream)64cdf0e10cSrcweirSequence< Sequence< PropertyValue > > SAL_CALL ManifestReader::readManifestSequence( const Reference< XInputStream >& rStream ) 65cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir Sequence < Sequence < PropertyValue > > aManifestSequence; 68cdf0e10cSrcweir Reference < XParser > xParser (xFactory->createInstance ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.xml.sax.Parser" ) ) ), UNO_QUERY ); 69cdf0e10cSrcweir if (xParser.is()) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir try 72cdf0e10cSrcweir { 73cdf0e10cSrcweir vector < Sequence < PropertyValue > > aManVector; 74cdf0e10cSrcweir Reference < XDocumentHandler > xFilter = new ManifestImport( aManVector ); 75cdf0e10cSrcweir InputSource aParserInput; 76cdf0e10cSrcweir aParserInput.aInputStream = rStream; 77cdf0e10cSrcweir aParserInput.sSystemId = OUString ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml" ) ); 78cdf0e10cSrcweir xParser->setDocumentHandler ( xFilter ); 79cdf0e10cSrcweir xParser->parseStream( aParserInput ); 80cdf0e10cSrcweir aManifestSequence.realloc ( aManVector.size() ); 81cdf0e10cSrcweir Sequence < PropertyValue > * pSequence = aManifestSequence.getArray(); 82cdf0e10cSrcweir ::std::vector < Sequence < PropertyValue > >::const_iterator aIter = aManVector.begin(); 83cdf0e10cSrcweir ::std::vector < Sequence < PropertyValue > >::const_iterator aEnd = aManVector.end(); 84cdf0e10cSrcweir while( aIter != aEnd ) 85cdf0e10cSrcweir *pSequence++ = (*aIter++); 86cdf0e10cSrcweir } 87cdf0e10cSrcweir catch (SAXParseException& ) 88cdf0e10cSrcweir { 89cdf0e10cSrcweir } 90cdf0e10cSrcweir catch (SAXException& ) 91cdf0e10cSrcweir { 92cdf0e10cSrcweir } 93cdf0e10cSrcweir catch (IOException& ) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir } 96cdf0e10cSrcweir } 97cdf0e10cSrcweir xParser->setDocumentHandler ( Reference < XDocumentHandler > () ); 98cdf0e10cSrcweir return aManifestSequence; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir // Component functions 101cdf0e10cSrcweir ManifestReader_createInstance(Reference<XMultiServiceFactory> const & rServiceFactory)102cdf0e10cSrcweirReference < XInterface > SAL_CALL ManifestReader_createInstance( Reference< XMultiServiceFactory > const & rServiceFactory ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir return *new ManifestReader( rServiceFactory ); 105cdf0e10cSrcweir } static_getImplementationName()106cdf0e10cSrcweirOUString ManifestReader::static_getImplementationName() 107cdf0e10cSrcweir { 108cdf0e10cSrcweir return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.comp.ManifestReader" ) ); 109cdf0e10cSrcweir } 110cdf0e10cSrcweir static_supportsService(OUString const & rServiceName)111cdf0e10cSrcweirsal_Bool SAL_CALL ManifestReader::static_supportsService(OUString const & rServiceName) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir return rServiceName == getSupportedServiceNames()[0]; 114cdf0e10cSrcweir } 115cdf0e10cSrcweir static_getSupportedServiceNames()116cdf0e10cSrcweirSequence < OUString > ManifestReader::static_getSupportedServiceNames() 117cdf0e10cSrcweir { 118cdf0e10cSrcweir Sequence < OUString > aNames(1); 119cdf0e10cSrcweir aNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestReader" ) ); 120cdf0e10cSrcweir return aNames; 121cdf0e10cSrcweir } 122cdf0e10cSrcweir getImplementationName()123cdf0e10cSrcweirOUString ManifestReader::getImplementationName() 124cdf0e10cSrcweir throw (RuntimeException) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir return static_getImplementationName(); 127cdf0e10cSrcweir } 128cdf0e10cSrcweir supportsService(OUString const & rServiceName)129cdf0e10cSrcweirsal_Bool SAL_CALL ManifestReader::supportsService(OUString const & rServiceName) 130cdf0e10cSrcweir throw (RuntimeException) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir return static_supportsService ( rServiceName ); 133cdf0e10cSrcweir } 134cdf0e10cSrcweir getSupportedServiceNames()135cdf0e10cSrcweirSequence < OUString > ManifestReader::getSupportedServiceNames() 136cdf0e10cSrcweir throw (RuntimeException) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir return static_getSupportedServiceNames(); 139cdf0e10cSrcweir } createServiceFactory(Reference<XMultiServiceFactory> const & rServiceFactory)140cdf0e10cSrcweirReference < XSingleServiceFactory > ManifestReader::createServiceFactory( Reference < XMultiServiceFactory > const & rServiceFactory ) 141cdf0e10cSrcweir { 142cdf0e10cSrcweir return cppu::createSingleFactory (rServiceFactory, 143cdf0e10cSrcweir static_getImplementationName(), 144cdf0e10cSrcweir ManifestReader_createInstance, 145cdf0e10cSrcweir static_getSupportedServiceNames()); 146cdf0e10cSrcweir } 147