build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / xmloff / source / meta / MetaImportComponent.cxx
blob24ef1cffeee1d86e190c00884196b1d7de89feb8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <xmloff/xmlnmspe.hxx>
21 #include <xmloff/xmltoken.hxx>
22 #include <xmloff/xmlmetai.hxx>
23 #include <xmloff/nmspmap.hxx>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <comphelper/processfactory.hxx>
26 #include <xmloff/xmlimp.hxx>
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <com/sun/star/document/XDocumentProperties.hpp>
30 using namespace ::com::sun::star;
31 using namespace ::xmloff::token;
33 class XMLMetaImportComponent : public SvXMLImport
35 private:
36 css::uno::Reference< css::document::XDocumentProperties> mxDocProps;
38 public:
39 // XMLMetaImportComponent() throw();
40 explicit XMLMetaImportComponent(
41 const css::uno::Reference< css::uno::XComponentContext >& xContext
42 ) throw();
44 virtual ~XMLMetaImportComponent() throw() override;
46 protected:
48 virtual SvXMLImportContext* CreateContext(
49 sal_uInt16 nPrefix,
50 const OUString& rLocalName,
51 const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override;
53 // XImporter
54 virtual void SAL_CALL setTargetDocument( const css::uno::Reference< css::lang::XComponent >& xDoc )
55 throw(css::lang::IllegalArgumentException, css::uno::RuntimeException, std::exception) override;
58 // global functions to support the component
60 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
61 XMLMetaImportComponent_get_implementation(
62 css::uno::XComponentContext *context,
63 css::uno::Sequence<css::uno::Any> const &)
65 return cppu::acquire(new XMLMetaImportComponent(context));
68 XMLMetaImportComponent::XMLMetaImportComponent(
69 const uno::Reference< uno::XComponentContext >& xContext) throw()
70 : SvXMLImport(xContext, ""), mxDocProps()
74 XMLMetaImportComponent::~XMLMetaImportComponent() throw()
78 SvXMLImportContext* XMLMetaImportComponent::CreateContext(
79 sal_uInt16 nPrefix,
80 const OUString& rLocalName,
81 const uno::Reference<xml::sax::XAttributeList > & xAttrList )
83 if ( (XML_NAMESPACE_OFFICE == nPrefix) &&
84 IsXMLToken(rLocalName, XML_DOCUMENT_META) )
86 if (!mxDocProps.is()) {
87 throw uno::RuntimeException(OUString(
88 "XMLMetaImportComponent::CreateContext: setTargetDocument "
89 "has not been called"), *this);
91 return new SvXMLMetaDocumentContext(
92 *this, nPrefix, rLocalName, mxDocProps);
94 else
96 return SvXMLImport::CreateContext(nPrefix, rLocalName, xAttrList);
100 void SAL_CALL XMLMetaImportComponent::setTargetDocument(
101 const uno::Reference< lang::XComponent >& xDoc )
102 throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
104 mxDocProps.set( xDoc, uno::UNO_QUERY );
105 if( !mxDocProps.is() )
106 throw lang::IllegalArgumentException(OUString(
107 "XMLMetaImportComponent::setTargetDocument: argument is no "
108 "XDocumentProperties"), uno::Reference<uno::XInterface>(*this), 0);
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */