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