1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ManifestReader.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_package.hxx"
33 #include <ManifestReader.hxx>
34 #include <ManifestImport.hxx>
35 #include <cppuhelper/factory.hxx>
36 #ifndef _COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP
37 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
39 #ifndef _COM_SUN_STAR_XML_SAX_SAXPARSEEXCEPTION_HPP
40 #include <com/sun/star/xml/sax/SAXParseException.hpp>
42 #ifndef _COM_SUN_STAR_XML_SAX_XPARSER_HPP
43 #include <com/sun/star/xml/sax/XParser.hpp>
45 #ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP
46 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
48 #ifndef _COM_SUN_STAR_LANG_XSINGLESERVICEFACTORY_HPP
49 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
53 using namespace ::rtl
;
54 using namespace ::std
;
55 using namespace ::com::sun::star::uno
;
56 using namespace ::com::sun::star::beans
;
57 using namespace ::com::sun::star::io
;
58 using namespace ::com::sun::star::lang
;
59 using namespace ::com::sun::star::registry
;
60 using namespace ::com::sun::star::packages
;
61 using namespace ::com::sun::star::xml::sax
;
62 using namespace ::com::sun::star::packages::manifest
;
64 ManifestReader::ManifestReader( const Reference
< XMultiServiceFactory
> & xNewFactory
)
65 : xFactory ( xNewFactory
)
68 ManifestReader::~ManifestReader()
71 Sequence
< Sequence
< PropertyValue
> > SAL_CALL
ManifestReader::readManifestSequence( const Reference
< XInputStream
>& rStream
)
72 throw (::com::sun::star::uno::RuntimeException
)
74 Sequence
< Sequence
< PropertyValue
> > aManifestSequence
;
75 Reference
< XParser
> xParser (xFactory
->createInstance ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.xml.sax.Parser" ) ) ), UNO_QUERY
);
80 vector
< Sequence
< PropertyValue
> > aManVector
;
81 Reference
< XDocumentHandler
> xFilter
= new ManifestImport( aManVector
);
82 InputSource aParserInput
;
83 aParserInput
.aInputStream
= rStream
;
84 aParserInput
.sSystemId
= OUString ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml" ) );
85 xParser
->setDocumentHandler ( xFilter
);
86 xParser
->parseStream( aParserInput
);
87 aManifestSequence
.realloc ( aManVector
.size() );
88 Sequence
< PropertyValue
> * pSequence
= aManifestSequence
.getArray();
89 ::std::vector
< Sequence
< PropertyValue
> >::const_iterator aIter
= aManVector
.begin();
90 ::std::vector
< Sequence
< PropertyValue
> >::const_iterator aEnd
= aManVector
.end();
91 while( aIter
!= aEnd
)
92 *pSequence
++ = (*aIter
++);
94 catch (SAXParseException
& )
97 catch (SAXException
& )
100 catch (IOException
& )
104 xParser
->setDocumentHandler ( Reference
< XDocumentHandler
> () );
105 return aManifestSequence
;
107 // Component functions
109 Reference
< XInterface
> SAL_CALL
ManifestReader_createInstance( Reference
< XMultiServiceFactory
> const & rServiceFactory
)
111 return *new ManifestReader( rServiceFactory
);
113 OUString
ManifestReader::static_getImplementationName()
115 return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.comp.ManifestReader" ) );
118 sal_Bool SAL_CALL
ManifestReader::static_supportsService(OUString
const & rServiceName
)
120 return rServiceName
== getSupportedServiceNames()[0];
123 Sequence
< OUString
> ManifestReader::static_getSupportedServiceNames()
125 Sequence
< OUString
> aNames(1);
126 aNames
[0] = OUString(RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestReader" ) );
130 OUString
ManifestReader::getImplementationName()
131 throw (RuntimeException
)
133 return static_getImplementationName();
136 sal_Bool SAL_CALL
ManifestReader::supportsService(OUString
const & rServiceName
)
137 throw (RuntimeException
)
139 return static_supportsService ( rServiceName
);
142 Sequence
< OUString
> ManifestReader::getSupportedServiceNames()
143 throw (RuntimeException
)
145 return static_getSupportedServiceNames();
147 Reference
< XSingleServiceFactory
> ManifestReader::createServiceFactory( Reference
< XMultiServiceFactory
> const & rServiceFactory
)
149 return cppu::createSingleFactory (rServiceFactory
,
150 static_getImplementationName(),
151 ManifestReader_createInstance
,
152 static_getSupportedServiceNames());