LibreOffice Module xmloff (master) 1
MetaImportComponent.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
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>
27
28using namespace ::com::sun::star;
29using namespace ::xmloff::token;
30
31namespace {
32
33class XMLMetaImportComponent : public SvXMLImport
34{
35private:
36 css::uno::Reference< css::document::XDocumentProperties> mxDocProps;
37
38public:
39 // XMLMetaImportComponent() throw();
40 explicit XMLMetaImportComponent(
41 const css::uno::Reference< css::uno::XComponentContext >& xContext
42 );
43
44protected:
45
46 virtual SvXMLImportContext *CreateFastContext( sal_Int32 nElement,
47 const ::css::uno::Reference< ::css::xml::sax::XFastAttributeList >& xAttrList ) override;
48
49 // XImporter
50 virtual void SAL_CALL setTargetDocument( const css::uno::Reference< css::lang::XComponent >& xDoc ) override;
51};
52
53}
54
55// global functions to support the component
56
57extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
59 css::uno::XComponentContext *context,
60 css::uno::Sequence<css::uno::Any> const &)
61{
62 return cppu::acquire(new XMLMetaImportComponent(context));
63}
64
65XMLMetaImportComponent::XMLMetaImportComponent(
66 const uno::Reference< uno::XComponentContext >& xContext)
67 : SvXMLImport(xContext, "XMLMetaImportComponent")
68{
69}
70
71SvXMLImportContext *XMLMetaImportComponent::CreateFastContext( sal_Int32 nElement,
72 const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
73{
74 if (nElement == XML_ELEMENT( OFFICE, XML_DOCUMENT_META ))
75 {
76 if (!mxDocProps.is()) {
77 throw uno::RuntimeException(
78 "XMLMetaImportComponent::CreateFastContext: setTargetDocument "
79 "has not been called", *this);
80 }
81 return new SvXMLMetaDocumentContext(
82 *this, mxDocProps);
83 }
84 return nullptr;
85}
86
87void SAL_CALL XMLMetaImportComponent::setTargetDocument(
88 const uno::Reference< lang::XComponent >& xDoc )
89{
90 mxDocProps.set( xDoc, uno::UNO_QUERY );
91 if( !mxDocProps.is() )
92 throw lang::IllegalArgumentException(
93 "XMLMetaImportComponent::setTargetDocument: argument is no "
94 "XDocumentProperties", uno::Reference<uno::XInterface>(*this), 0);
95}
96
97/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * XMLMetaImportComponent_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
This class deliberately does not support XWeak, to improve performance when loading large documents.
Definition: xmlictxt.hxx:48
handles the top-level office:document-meta element of meta.xml documents
Definition: xmlmetai.hxx:37
Handling of tokens in XML:
#define XML_ELEMENT(prefix, name)
Definition: xmlimp.hxx:97