LibreOffice Module package (master) 1
ManifestReader.cxx
Go to the documentation of this file.
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"
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 <vector>
31
32using namespace ::com::sun::star::uno;
33using namespace ::com::sun::star::beans;
34using namespace ::com::sun::star::io;
35using namespace ::com::sun::star::lang;
36using namespace ::com::sun::star::registry;
37using namespace ::com::sun::star::packages;
38using namespace ::com::sun::star::xml::sax;
39
40ManifestReader::ManifestReader( const Reference < XComponentContext > & xContext )
41: m_xContext ( xContext )
42{
43}
45{
46}
47Sequence< Sequence< PropertyValue > > SAL_CALL ManifestReader::readManifestSequence( const Reference< XInputStream >& rStream )
48{
49 Sequence < Sequence < PropertyValue > > aManifestSequence;
50 Reference < XParser > xParser = Parser::create(m_xContext);
51 try
52 {
53 std::vector < Sequence < PropertyValue > > aManVector;
54 Reference < XDocumentHandler > xFilter = new ManifestImport( aManVector );
55 InputSource aParserInput;
56 aParserInput.aInputStream = rStream;
57 aParserInput.sSystemId = "META-INF/manifest.xml";
58 xParser->setDocumentHandler ( xFilter );
59 xParser->parseStream( aParserInput );
60 aManifestSequence = comphelper::containerToSequence(aManVector);
61 }
62 catch (const SAXParseException&)
63 {
64 TOOLS_WARN_EXCEPTION("package", "ignoring");
65 }
66 catch (const SAXException&)
67 {
68 TOOLS_WARN_EXCEPTION("package", "ignoring");
69 }
70 catch (const IOException&)
71 {
72 TOOLS_WARN_EXCEPTION("package", "ignoring");
73 }
74 xParser->setDocumentHandler ( Reference < XDocumentHandler > () );
75 return aManifestSequence;
76}
77// Component functions
78
79
81{
82 return "com.sun.star.packages.manifest.comp.ManifestReader";
83}
84
85sal_Bool SAL_CALL ManifestReader::supportsService(OUString const & rServiceName)
86{
87 return cppu::supportsService(this, rServiceName );
88}
89
91{
92 return { "com.sun.star.packages.manifest.ManifestReader" };
93}
94
95
96extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
98 css::uno::XComponentContext* context , css::uno::Sequence<css::uno::Any> const&)
99{
100 return cppu::acquire(new ManifestReader(context));
101}
102
103
104/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * package_ManifestReader_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Reference< XComponentContext > m_xContext
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual ~ManifestReader() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > SAL_CALL readManifestSequence(const css::uno::Reference< css::io::XInputStream > &rStream) override
ManifestReader(const css::uno::Reference< css::uno::XComponentContext > &xContext)
#define TOOLS_WARN_EXCEPTION(area, stream)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
unsigned char sal_Bool