Branch data 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 <cppuhelper/factory.hxx>
23 : : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
24 : : #include <com/sun/star/xml/sax/SAXParseException.hpp>
25 : : #include <com/sun/star/xml/sax/XParser.hpp>
26 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 : : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
28 : : #include <vector>
29 : :
30 : : using namespace ::std;
31 : : using namespace ::com::sun::star::uno;
32 : : using namespace ::com::sun::star::beans;
33 : : using namespace ::com::sun::star::io;
34 : : using namespace ::com::sun::star::lang;
35 : : using namespace ::com::sun::star::registry;
36 : : using namespace ::com::sun::star::packages;
37 : : using namespace ::com::sun::star::xml::sax;
38 : : using namespace ::com::sun::star::packages::manifest;
39 : : using ::rtl::OUString;
40 : :
41 : 1571 : ManifestReader::ManifestReader( const Reference < XMultiServiceFactory > & xNewFactory )
42 : 1571 : : xFactory ( xNewFactory )
43 : : {
44 : 1571 : }
45 : 1571 : ManifestReader::~ManifestReader()
46 : : {
47 [ - + ]: 3142 : }
48 : 1571 : Sequence< Sequence< PropertyValue > > SAL_CALL ManifestReader::readManifestSequence( const Reference< XInputStream >& rStream )
49 : : throw (::com::sun::star::uno::RuntimeException)
50 : : {
51 [ + - ]: 1571 : Sequence < Sequence < PropertyValue > > aManifestSequence;
52 [ + - ][ + - ]: 1571 : Reference < XParser > xParser (xFactory->createInstance ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.xml.sax.Parser" ) ) ), UNO_QUERY );
[ + - ][ + - ]
53 [ + - ]: 1571 : if (xParser.is())
54 : : {
55 : : try
56 : : {
57 [ + - ]: 1571 : vector < Sequence < PropertyValue > > aManVector;
58 [ + - ][ + - ]: 1571 : Reference < XDocumentHandler > xFilter = new ManifestImport( aManVector );
[ + - ]
59 [ + - ]: 1571 : InputSource aParserInput;
60 [ + - ]: 1571 : aParserInput.aInputStream = rStream;
61 [ + - ]: 1571 : aParserInput.sSystemId = OUString ( RTL_CONSTASCII_USTRINGPARAM ( "META-INF/manifest.xml" ) );
62 [ + - ][ + - ]: 1571 : xParser->setDocumentHandler ( xFilter );
63 [ + - ][ + - ]: 1571 : xParser->parseStream( aParserInput );
64 [ + - ]: 1571 : aManifestSequence.realloc ( aManVector.size() );
65 [ + - ]: 1571 : Sequence < PropertyValue > * pSequence = aManifestSequence.getArray();
66 [ + - ]: 1571 : ::std::vector < Sequence < PropertyValue > >::const_iterator aIter = aManVector.begin();
67 [ + - ]: 1571 : ::std::vector < Sequence < PropertyValue > >::const_iterator aEnd = aManVector.end();
68 [ + - ][ + + ]: 11323 : while( aIter != aEnd )
69 [ + - ][ + - ]: 11323 : *pSequence++ = (*aIter++);
[ + - ]
[ # # # # ]
70 : : }
71 [ # # ]: 0 : catch (SAXParseException& )
72 : : {
73 : : }
74 [ # # ]: 0 : catch (SAXException& )
75 : : {
76 : : }
77 [ # # ]: 0 : catch (IOException& )
78 : : {
79 : : }
80 : : }
81 [ + - ][ + - ]: 1571 : xParser->setDocumentHandler ( Reference < XDocumentHandler > () );
82 : 1571 : return aManifestSequence;
83 : : }
84 : : // Component functions
85 : :
86 : 1571 : Reference < XInterface > SAL_CALL ManifestReader_createInstance( Reference< XMultiServiceFactory > const & rServiceFactory )
87 : : {
88 [ + - ]: 1571 : return *new ManifestReader( rServiceFactory );
89 : : }
90 : 674 : OUString ManifestReader::static_getImplementationName()
91 : : {
92 : 674 : return OUString ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.comp.ManifestReader" ) );
93 : : }
94 : :
95 : 0 : sal_Bool SAL_CALL ManifestReader::static_supportsService(OUString const & rServiceName)
96 : : {
97 [ # # ]: 0 : return rServiceName == getSupportedServiceNames()[0];
98 : : }
99 : :
100 : 170 : Sequence < OUString > ManifestReader::static_getSupportedServiceNames()
101 : : {
102 : 170 : Sequence < OUString > aNames(1);
103 [ + - ][ + - ]: 170 : aNames[0] = OUString(RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.packages.manifest.ManifestReader" ) );
104 : 170 : return aNames;
105 : : }
106 : :
107 : 0 : OUString ManifestReader::getImplementationName()
108 : : throw (RuntimeException)
109 : : {
110 : 0 : return static_getImplementationName();
111 : : }
112 : :
113 : 0 : sal_Bool SAL_CALL ManifestReader::supportsService(OUString const & rServiceName)
114 : : throw (RuntimeException)
115 : : {
116 : 0 : return static_supportsService ( rServiceName );
117 : : }
118 : :
119 : 0 : Sequence < OUString > ManifestReader::getSupportedServiceNames()
120 : : throw (RuntimeException)
121 : : {
122 : 0 : return static_getSupportedServiceNames();
123 : : }
124 : 170 : Reference < XSingleServiceFactory > ManifestReader::createServiceFactory( Reference < XMultiServiceFactory > const & rServiceFactory )
125 : : {
126 : : return cppu::createSingleFactory (rServiceFactory,
127 : : static_getImplementationName(),
128 : : ManifestReader_createInstance,
129 [ + - ][ + - ]: 170 : static_getSupportedServiceNames());
130 : : }
131 : :
132 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|