Coverage Report

Created: 2026-07-10 11:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/xmloff/source/meta/MetaImportComponent.cxx
Line
Count
Source
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 <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>
27
28
using namespace ::com::sun::star;
29
using namespace ::xmloff::token;
30
31
namespace {
32
33
class XMLMetaImportComponent : public SvXMLImport
34
{
35
private:
36
    css::uno::Reference< css::document::XDocumentProperties> mxDocProps;
37
38
public:
39
    // XMLMetaImportComponent() throw();
40
    explicit XMLMetaImportComponent(
41
        const css::uno::Reference< css::uno::XComponentContext >& xContext
42
        );
43
44
protected:
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
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 &)
61
0
{
62
0
    return cppu::acquire(new XMLMetaImportComponent(context));
63
0
}
64
65
XMLMetaImportComponent::XMLMetaImportComponent(
66
    const uno::Reference< uno::XComponentContext >& xContext)
67
0
    :   SvXMLImport(xContext, u"XMLMetaImportComponent"_ustr)
68
0
{
69
0
}
70
71
SvXMLImportContext *XMLMetaImportComponent::CreateFastContext( sal_Int32 nElement,
72
        const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ )
73
0
{
74
0
    if (nElement == XML_ELEMENT( OFFICE, XML_DOCUMENT_META ))
75
0
    {
76
0
        if (!mxDocProps.is()) {
77
0
            throw uno::RuntimeException(
78
0
                u"XMLMetaImportComponent::CreateFastContext: setTargetDocument "
79
0
                "has not been called"_ustr, *this);
80
0
        }
81
0
        return new SvXMLMetaDocumentContext(
82
0
                        *this, mxDocProps);
83
0
    }
84
0
    return nullptr;
85
0
}
86
87
void SAL_CALL XMLMetaImportComponent::setTargetDocument(
88
    const uno::Reference< lang::XComponent >& xDoc )
89
0
{
90
0
    mxDocProps.set( xDoc, uno::UNO_QUERY );
91
0
    if( !mxDocProps.is() )
92
0
        throw lang::IllegalArgumentException(
93
0
            u"XMLMetaImportComponent::setTargetDocument: argument is no "
94
0
            "XDocumentProperties"_ustr, uno::Reference<uno::XInterface>(*this), 0);
95
0
}
96
97
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */