1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <ManifestReader.hxx>
21 #include <ManifestImport.hxx>
22 #include <comphelper/processfactory.hxx>
23 #include <cppuhelper/factory.hxx>
24 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
25 #include <com/sun/star/xml/sax/SAXParseException.hpp>
26 #include <com/sun/star/xml/sax/Parser.hpp>
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
31 using namespace ::std
;
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star::beans
;
34 using namespace ::com::sun::star::io
;
35 using namespace ::com::sun::star::lang
;
36 using namespace ::com::sun::star::registry
;
37 using namespace ::com::sun::star::packages
;
38 using namespace ::com::sun::star::xml::sax
;
39 using namespace ::com::sun::star::packages::manifest
;
41 ManifestReader::ManifestReader( const Reference
< XComponentContext
> & xContext
)
42 : m_xContext ( xContext
)
45 ManifestReader::~ManifestReader()
48 Sequence
< Sequence
< PropertyValue
> > SAL_CALL
ManifestReader::readManifestSequence( const Reference
< XInputStream
>& rStream
)
49 throw (::com::sun::star::uno::RuntimeException
)
51 Sequence
< Sequence
< PropertyValue
> > aManifestSequence
;
52 Reference
< XParser
> xParser
= Parser::create(m_xContext
);
55 vector
< Sequence
< PropertyValue
> > aManVector
;
56 Reference
< XDocumentHandler
> xFilter
= new ManifestImport( aManVector
);
57 InputSource aParserInput
;
58 aParserInput
.aInputStream
= rStream
;
59 aParserInput
.sSystemId
= "META-INF/manifest.xml";
60 xParser
->setDocumentHandler ( xFilter
);
61 xParser
->parseStream( aParserInput
);
62 aManifestSequence
.realloc ( aManVector
.size() );
63 Sequence
< PropertyValue
> * pSequence
= aManifestSequence
.getArray();
64 ::std::vector
< Sequence
< PropertyValue
> >::const_iterator aIter
= aManVector
.begin();
65 ::std::vector
< Sequence
< PropertyValue
> >::const_iterator aEnd
= aManVector
.end();
66 while( aIter
!= aEnd
)
67 *pSequence
++ = (*aIter
++);
69 catch (SAXParseException
& e
)
71 SAL_WARN("package", "ignoring SAXParseException " + e
.Message
);
73 catch (SAXException
& e
)
75 SAL_WARN("package", "ignoring SAXException " + e
.Message
);
77 catch (IOException
& e
)
79 SAL_WARN("package", "ignoring IOException " + e
.Message
);
81 xParser
->setDocumentHandler ( Reference
< XDocumentHandler
> () );
82 return aManifestSequence
;
84 // Component functions
86 Reference
< XInterface
> SAL_CALL
ManifestReader_createInstance( Reference
< XMultiServiceFactory
> const & rServiceFactory
)
88 return *new ManifestReader( comphelper::getComponentContext(rServiceFactory
) );
90 OUString
ManifestReader::static_getImplementationName()
92 return OUString( "com.sun.star.packages.manifest.comp.ManifestReader" );
95 sal_Bool SAL_CALL
ManifestReader::static_supportsService(OUString
const & rServiceName
)
97 return rServiceName
== getSupportedServiceNames()[0];
100 Sequence
< OUString
> ManifestReader::static_getSupportedServiceNames()
102 Sequence
< OUString
> aNames(1);
103 aNames
[0] = "com.sun.star.packages.manifest.ManifestReader";
107 OUString
ManifestReader::getImplementationName()
108 throw (RuntimeException
)
110 return static_getImplementationName();
113 sal_Bool SAL_CALL
ManifestReader::supportsService(OUString
const & rServiceName
)
114 throw (RuntimeException
)
116 return static_supportsService ( rServiceName
);
119 Sequence
< OUString
> ManifestReader::getSupportedServiceNames()
120 throw (RuntimeException
)
122 return static_getSupportedServiceNames();
124 Reference
< XSingleServiceFactory
> ManifestReader::createServiceFactory( Reference
< XMultiServiceFactory
> const & rServiceFactory
)
126 return cppu::createSingleFactory (rServiceFactory
,
127 static_getImplementationName(),
128 ManifestReader_createInstance
,
129 static_getSupportedServiceNames());
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */