xref: /AOO41X/main/package/source/manifest/ManifestReader.cxx (revision a38728232e8c39f9058a1a2aa8ee4e6db7b8ca34)
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)57 ManifestReader::ManifestReader( const Reference < XMultiServiceFactory > & xNewFactory )
58 : xFactory ( xNewFactory )
59 {
60 }
~ManifestReader()61 ManifestReader::~ManifestReader()
62 {
63 }
readManifestSequence(const Reference<XInputStream> & rStream)64 Sequence< Sequence< PropertyValue > > SAL_CALL ManifestReader::readManifestSequence( const Reference< XInputStream >& rStream )
65     throw (::com::sun::star::uno::RuntimeException)
66 {
67     Sequence < Sequence < PropertyValue > > aManifestSequence;
68     Reference < XParser > xParser (xFactory->createInstance ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.xml.sax.Parser" ) ) ), UNO_QUERY );
69     if (xParser.is())
70     {
71         try
72         {
73             vector < Sequence < PropertyValue > > aManVector;
74             Reference < XDocumentHandler > xFilter = new ManifestImport( aManVector );
75             InputSource aParserInput;
76             aParserInput.aInputStream = rStream;
77             aParserInput.sSystemId = OUString ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml" ) );
78             xParser->setDocumentHandler ( xFilter );
79             xParser->parseStream( aParserInput );
80             aManifestSequence.realloc ( aManVector.size() );
81             Sequence < PropertyValue > * pSequence = aManifestSequence.getArray();
82             ::std::vector < Sequence < PropertyValue > >::const_iterator aIter = aManVector.begin();
83             ::std::vector < Sequence < PropertyValue > >::const_iterator aEnd = aManVector.end();
84             while( aIter != aEnd )
85                 *pSequence++ = (*aIter++);
86         }
87         catch (SAXParseException& )
88         {
89         }
90         catch (SAXException& )
91         {
92         }
93         catch (IOException& )
94         {
95         }
96     }
97     xParser->setDocumentHandler ( Reference < XDocumentHandler > () );
98     return aManifestSequence;
99 }
100 // Component functions
101 
ManifestReader_createInstance(Reference<XMultiServiceFactory> const & rServiceFactory)102 Reference < XInterface > SAL_CALL ManifestReader_createInstance( Reference< XMultiServiceFactory > const & rServiceFactory )
103 {
104     return *new ManifestReader( rServiceFactory );
105 }
static_getImplementationName()106 OUString ManifestReader::static_getImplementationName()
107 {
108     return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.comp.ManifestReader" ) );
109 }
110 
static_supportsService(OUString const & rServiceName)111 sal_Bool SAL_CALL ManifestReader::static_supportsService(OUString const & rServiceName)
112 {
113     return rServiceName == getSupportedServiceNames()[0];
114 }
115 
static_getSupportedServiceNames()116 Sequence < OUString > ManifestReader::static_getSupportedServiceNames()
117 {
118     Sequence < OUString > aNames(1);
119     aNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestReader" ) );
120     return aNames;
121 }
122 
getImplementationName()123 OUString ManifestReader::getImplementationName()
124     throw (RuntimeException)
125 {
126     return static_getImplementationName();
127 }
128 
supportsService(OUString const & rServiceName)129 sal_Bool SAL_CALL ManifestReader::supportsService(OUString const & rServiceName)
130     throw (RuntimeException)
131 {
132     return static_supportsService ( rServiceName );
133 }
134 
getSupportedServiceNames()135 Sequence < OUString > ManifestReader::getSupportedServiceNames()
136     throw (RuntimeException)
137 {
138     return static_getSupportedServiceNames();
139 }
createServiceFactory(Reference<XMultiServiceFactory> const & rServiceFactory)140 Reference < XSingleServiceFactory > ManifestReader::createServiceFactory( Reference < XMultiServiceFactory > const & rServiceFactory )
141 {
142     return cppu::createSingleFactory (rServiceFactory,
143                                            static_getImplementationName(),
144                                            ManifestReader_createInstance,
145                                            static_getSupportedServiceNames());
146 }
147