xref: /AOO41X/main/package/source/manifest/ManifestReader.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_package.hxx"
30 #include <ManifestReader.hxx>
31 #include <ManifestImport.hxx>
32 #include <cppuhelper/factory.hxx>
33 #ifndef _COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP
34 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
35 #endif
36 #ifndef _COM_SUN_STAR_XML_SAX_SAXPARSEEXCEPTION_HPP
37 #include <com/sun/star/xml/sax/SAXParseException.hpp>
38 #endif
39 #ifndef _COM_SUN_STAR_XML_SAX_XPARSER_HPP
40 #include <com/sun/star/xml/sax/XParser.hpp>
41 #endif
42 #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP
43 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
44 #endif
45 #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP
46 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
47 #endif
48 #include <vector>
49 
50 using namespace ::rtl;
51 using namespace ::std;
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::beans;
54 using namespace ::com::sun::star::io;
55 using namespace ::com::sun::star::lang;
56 using namespace ::com::sun::star::registry;
57 using namespace ::com::sun::star::packages;
58 using namespace ::com::sun::star::xml::sax;
59 using namespace ::com::sun::star::packages::manifest;
60 
61 ManifestReader::ManifestReader( const Reference < XMultiServiceFactory > & xNewFactory )
62 : xFactory ( xNewFactory )
63 {
64 }
65 ManifestReader::~ManifestReader()
66 {
67 }
68 Sequence< Sequence< PropertyValue > > SAL_CALL ManifestReader::readManifestSequence( const Reference< XInputStream >& rStream )
69     throw (::com::sun::star::uno::RuntimeException)
70 {
71     Sequence < Sequence < PropertyValue > > aManifestSequence;
72     Reference < XParser > xParser (xFactory->createInstance ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.xml.sax.Parser" ) ) ), UNO_QUERY );
73     if (xParser.is())
74     {
75         try
76         {
77             vector < Sequence < PropertyValue > > aManVector;
78             Reference < XDocumentHandler > xFilter = new ManifestImport( aManVector );
79             InputSource aParserInput;
80             aParserInput.aInputStream = rStream;
81             aParserInput.sSystemId = OUString ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml" ) );
82             xParser->setDocumentHandler ( xFilter );
83             xParser->parseStream( aParserInput );
84             aManifestSequence.realloc ( aManVector.size() );
85             Sequence < PropertyValue > * pSequence = aManifestSequence.getArray();
86             ::std::vector < Sequence < PropertyValue > >::const_iterator aIter = aManVector.begin();
87             ::std::vector < Sequence < PropertyValue > >::const_iterator aEnd = aManVector.end();
88             while( aIter != aEnd )
89                 *pSequence++ = (*aIter++);
90         }
91         catch (SAXParseException& )
92         {
93         }
94         catch (SAXException& )
95         {
96         }
97         catch (IOException& )
98         {
99         }
100     }
101     xParser->setDocumentHandler ( Reference < XDocumentHandler > () );
102     return aManifestSequence;
103 }
104 // Component functions
105 
106 Reference < XInterface > SAL_CALL ManifestReader_createInstance( Reference< XMultiServiceFactory > const & rServiceFactory )
107 {
108     return *new ManifestReader( rServiceFactory );
109 }
110 OUString ManifestReader::static_getImplementationName()
111 {
112     return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.comp.ManifestReader" ) );
113 }
114 
115 sal_Bool SAL_CALL ManifestReader::static_supportsService(OUString const & rServiceName)
116 {
117     return rServiceName == getSupportedServiceNames()[0];
118 }
119 
120 Sequence < OUString > ManifestReader::static_getSupportedServiceNames()
121 {
122     Sequence < OUString > aNames(1);
123     aNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestReader" ) );
124     return aNames;
125 }
126 
127 OUString ManifestReader::getImplementationName()
128     throw (RuntimeException)
129 {
130     return static_getImplementationName();
131 }
132 
133 sal_Bool SAL_CALL ManifestReader::supportsService(OUString const & rServiceName)
134     throw (RuntimeException)
135 {
136     return static_supportsService ( rServiceName );
137 }
138 
139 Sequence < OUString > ManifestReader::getSupportedServiceNames()
140     throw (RuntimeException)
141 {
142     return static_getSupportedServiceNames();
143 }
144 Reference < XSingleServiceFactory > ManifestReader::createServiceFactory( Reference < XMultiServiceFactory > const & rServiceFactory )
145 {
146     return cppu::createSingleFactory (rServiceFactory,
147                                            static_getImplementationName(),
148                                            ManifestReader_createInstance,
149                                            static_getSupportedServiceNames());
150 }
151