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 <xmloff/xmlnamespace.hxx>
21 #include <xmloff/xmltoken.hxx>
22 #include <xmloff/xmlmetai.hxx>
23 #include <xmloff/xmlimp.hxx>
24 #include <com/sun/star/uno/Reference.hxx>
25 #include <com/sun/star/document/XDocumentProperties.hpp>
26 #include <com/sun/star/lang/IllegalArgumentException.hpp>
28 using namespace ::com::sun::star
;
29 using namespace ::xmloff::token
;
33 class XMLMetaImportComponent
: public SvXMLImport
36 css::uno::Reference
< css::document::XDocumentProperties
> mxDocProps
;
39 // XMLMetaImportComponent() throw();
40 explicit XMLMetaImportComponent(
41 const css::uno::Reference
< css::uno::XComponentContext
>& xContext
46 virtual SvXMLImportContext
*CreateFastContext( sal_Int32 nElement
,
47 const ::css::uno::Reference
< ::css::xml::sax::XFastAttributeList
>& xAttrList
) override
;
50 virtual void SAL_CALL
setTargetDocument( const css::uno::Reference
< css::lang::XComponent
>& xDoc
) override
;
55 // global functions to support the component
57 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
58 XMLMetaImportComponent_get_implementation(
59 css::uno::XComponentContext
*context
,
60 css::uno::Sequence
<css::uno::Any
> const &)
62 return cppu::acquire(new XMLMetaImportComponent(context
));
65 XMLMetaImportComponent::XMLMetaImportComponent(
66 const uno::Reference
< uno::XComponentContext
>& xContext
)
67 : SvXMLImport(xContext
, u
"XMLMetaImportComponent"_ustr
)
71 SvXMLImportContext
*XMLMetaImportComponent::CreateFastContext( sal_Int32 nElement
,
72 const uno::Reference
< xml::sax::XFastAttributeList
>& /*xAttrList*/ )
74 if (nElement
== XML_ELEMENT( OFFICE
, XML_DOCUMENT_META
))
76 if (!mxDocProps
.is()) {
77 throw uno::RuntimeException(
78 u
"XMLMetaImportComponent::CreateFastContext: setTargetDocument "
79 "has not been called"_ustr
, *this);
81 return new SvXMLMetaDocumentContext(
87 void SAL_CALL
XMLMetaImportComponent::setTargetDocument(
88 const uno::Reference
< lang::XComponent
>& xDoc
)
90 mxDocProps
.set( xDoc
, uno::UNO_QUERY
);
91 if( !mxDocProps
.is() )
92 throw lang::IllegalArgumentException(
93 u
"XMLMetaImportComponent::setTargetDocument: argument is no "
94 "XDocumentProperties"_ustr
, uno::Reference
<uno::XInterface
>(*this), 0);
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */