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 <comphelper/sequence.hxx>
24 #include <cppuhelper/factory.hxx>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <com/sun/star/io/IOException.hpp>
27 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
28 #include <com/sun/star/xml/sax/SAXParseException.hpp>
29 #include <com/sun/star/xml/sax/Parser.hpp>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
34 using namespace ::std
;
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star::beans
;
37 using namespace ::com::sun::star::io
;
38 using namespace ::com::sun::star::lang
;
39 using namespace ::com::sun::star::registry
;
40 using namespace ::com::sun::star::packages
;
41 using namespace ::com::sun::star::xml::sax
;
43 ManifestReader::ManifestReader( const Reference
< XComponentContext
> & xContext
)
44 : m_xContext ( xContext
)
47 ManifestReader::~ManifestReader()
50 Sequence
< Sequence
< PropertyValue
> > SAL_CALL
ManifestReader::readManifestSequence( const Reference
< XInputStream
>& rStream
)
52 Sequence
< Sequence
< PropertyValue
> > aManifestSequence
;
53 Reference
< XParser
> xParser
= Parser::create(m_xContext
);
56 vector
< Sequence
< PropertyValue
> > aManVector
;
57 Reference
< XDocumentHandler
> xFilter
= new ManifestImport( aManVector
);
58 InputSource aParserInput
;
59 aParserInput
.aInputStream
= rStream
;
60 aParserInput
.sSystemId
= "META-INF/manifest.xml";
61 xParser
->setDocumentHandler ( xFilter
);
62 xParser
->parseStream( aParserInput
);
63 aManifestSequence
= comphelper::containerToSequence(aManVector
);
65 catch (SAXParseException
& e
)
67 SAL_WARN("package", "ignoring " << e
);
69 catch (SAXException
& e
)
71 SAL_WARN("package", "ignoring " << e
);
73 catch (IOException
& e
)
75 SAL_WARN("package", "ignoring " << e
);
77 xParser
->setDocumentHandler ( Reference
< XDocumentHandler
> () );
78 return aManifestSequence
;
80 // Component functions
82 Reference
< XInterface
> ManifestReader_createInstance( Reference
< XMultiServiceFactory
> const & rServiceFactory
)
84 return *new ManifestReader( comphelper::getComponentContext(rServiceFactory
) );
86 OUString
ManifestReader::static_getImplementationName()
88 return OUString( "com.sun.star.packages.manifest.comp.ManifestReader" );
91 Sequence
< OUString
> ManifestReader::static_getSupportedServiceNames()
93 Sequence
< OUString
> aNames
{ "com.sun.star.packages.manifest.ManifestReader" };
97 OUString
ManifestReader::getImplementationName()
99 return static_getImplementationName();
102 sal_Bool SAL_CALL
ManifestReader::supportsService(OUString
const & rServiceName
)
104 return cppu::supportsService(this, rServiceName
);
107 Sequence
< OUString
> ManifestReader::getSupportedServiceNames()
109 return static_getSupportedServiceNames();
111 Reference
< XSingleServiceFactory
> ManifestReader::createServiceFactory( Reference
< XMultiServiceFactory
> const & rServiceFactory
)
113 return cppu::createSingleFactory (rServiceFactory
,
114 static_getImplementationName(),
115 ManifestReader_createInstance
,
116 static_getSupportedServiceNames());
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */