Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <ManifestReader.hxx>
21 : #include <ManifestImport.hxx>
22 : #include <comphelper/processfactory.hxx>
23 : #include <cppuhelper/factory.hxx>
24 : #include <cppuhelper/supportsservice.hxx>
25 : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
26 : #include <com/sun/star/xml/sax/SAXParseException.hpp>
27 : #include <com/sun/star/xml/sax/Parser.hpp>
28 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
30 : #include <vector>
31 :
32 : using namespace ::std;
33 : using namespace ::com::sun::star::uno;
34 : using namespace ::com::sun::star::beans;
35 : using namespace ::com::sun::star::io;
36 : using namespace ::com::sun::star::lang;
37 : using namespace ::com::sun::star::registry;
38 : using namespace ::com::sun::star::packages;
39 : using namespace ::com::sun::star::xml::sax;
40 : using namespace ::com::sun::star::packages::manifest;
41 :
42 0 : ManifestReader::ManifestReader( const Reference < XComponentContext > & xContext )
43 0 : : m_xContext ( xContext )
44 : {
45 0 : }
46 0 : ManifestReader::~ManifestReader()
47 : {
48 0 : }
49 0 : Sequence< Sequence< PropertyValue > > SAL_CALL ManifestReader::readManifestSequence( const Reference< XInputStream >& rStream )
50 : throw (::com::sun::star::uno::RuntimeException, std::exception)
51 : {
52 0 : Sequence < Sequence < PropertyValue > > aManifestSequence;
53 0 : Reference < XParser > xParser = Parser::create(m_xContext);
54 : try
55 : {
56 0 : vector < Sequence < PropertyValue > > aManVector;
57 0 : Reference < XDocumentHandler > xFilter = new ManifestImport( aManVector );
58 0 : InputSource aParserInput;
59 0 : aParserInput.aInputStream = rStream;
60 0 : aParserInput.sSystemId = "META-INF/manifest.xml";
61 0 : xParser->setDocumentHandler ( xFilter );
62 0 : xParser->parseStream( aParserInput );
63 0 : aManifestSequence.realloc ( aManVector.size() );
64 0 : Sequence < PropertyValue > * pSequence = aManifestSequence.getArray();
65 0 : ::std::vector < Sequence < PropertyValue > >::const_iterator aIter = aManVector.begin();
66 0 : ::std::vector < Sequence < PropertyValue > >::const_iterator aEnd = aManVector.end();
67 0 : while( aIter != aEnd )
68 0 : *pSequence++ = (*aIter++);
69 : }
70 0 : catch (SAXParseException& e)
71 : {
72 : SAL_WARN("package", "ignoring SAXParseException " + e.Message);
73 : }
74 0 : catch (SAXException& e)
75 : {
76 : SAL_WARN("package", "ignoring SAXException " + e.Message);
77 : }
78 0 : catch (IOException& e)
79 : {
80 : SAL_WARN("package", "ignoring IOException " + e.Message);
81 : }
82 0 : xParser->setDocumentHandler ( Reference < XDocumentHandler > () );
83 0 : return aManifestSequence;
84 : }
85 : // Component functions
86 :
87 0 : Reference < XInterface > SAL_CALL ManifestReader_createInstance( Reference< XMultiServiceFactory > const & rServiceFactory )
88 : {
89 0 : return *new ManifestReader( comphelper::getComponentContext(rServiceFactory) );
90 : }
91 0 : OUString ManifestReader::static_getImplementationName()
92 : {
93 0 : return OUString( "com.sun.star.packages.manifest.comp.ManifestReader" );
94 : }
95 :
96 0 : Sequence < OUString > ManifestReader::static_getSupportedServiceNames()
97 : {
98 0 : Sequence < OUString > aNames(1);
99 0 : aNames[0] = "com.sun.star.packages.manifest.ManifestReader";
100 0 : return aNames;
101 : }
102 :
103 0 : OUString ManifestReader::getImplementationName()
104 : throw (RuntimeException, std::exception)
105 : {
106 0 : return static_getImplementationName();
107 : }
108 :
109 0 : sal_Bool SAL_CALL ManifestReader::supportsService(OUString const & rServiceName)
110 : throw (RuntimeException, std::exception)
111 : {
112 0 : return cppu::supportsService(this, rServiceName );
113 : }
114 :
115 0 : Sequence < OUString > ManifestReader::getSupportedServiceNames()
116 : throw (RuntimeException, std::exception)
117 : {
118 0 : return static_getSupportedServiceNames();
119 : }
120 0 : Reference < XSingleServiceFactory > ManifestReader::createServiceFactory( Reference < XMultiServiceFactory > const & rServiceFactory )
121 : {
122 : return cppu::createSingleFactory (rServiceFactory,
123 : static_getImplementationName(),
124 : ManifestReader_createInstance,
125 0 : static_getSupportedServiceNames());
126 : }
127 :
128 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|