Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/unoxml/source/rdf/CLiteral.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 <cppuhelper/implbase.hxx>
21
#include <cppuhelper/supportsservice.hxx>
22
#include <com/sun/star/lang/XServiceInfo.hpp>
23
#include <com/sun/star/lang/XInitialization.hpp>
24
#include <com/sun/star/rdf/XLiteral.hpp>
25
#include <com/sun/star/uno/XComponentContext.hpp>
26
27
#include <com/sun/star/lang/IllegalArgumentException.hpp>
28
29
30
/// anonymous implementation namespace
31
namespace {
32
33
class CLiteral:
34
    public ::cppu::WeakImplHelper<
35
        css::lang::XServiceInfo,
36
        css::lang::XInitialization,
37
        css::rdf::XLiteral>
38
{
39
public:
40
    explicit CLiteral();
41
42
    // css::lang::XServiceInfo:
43
    virtual OUString SAL_CALL getImplementationName() override;
44
    virtual sal_Bool SAL_CALL supportsService(const OUString & ServiceName) override;
45
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
46
47
    // css::lang::XInitialization:
48
    virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > & aArguments) override;
49
50
    // css::rdf::XNode:
51
    virtual OUString SAL_CALL getStringValue() override;
52
53
    // css::rdf::XLiteral:
54
    virtual OUString SAL_CALL getValue() override;
55
    virtual OUString SAL_CALL getLanguage() override;
56
    virtual css::uno::Reference< css::rdf::XURI > SAL_CALL getDatatype() override;
57
58
private:
59
    CLiteral(CLiteral const&) = delete;
60
    CLiteral& operator=(CLiteral const&) = delete;
61
62
    OUString m_Value;
63
    OUString m_Language;
64
    css::uno::Reference< css::rdf::XURI > m_xDatatype;
65
};
66
67
CLiteral::CLiteral()
68
0
{}
69
70
// com.sun.star.uno.XServiceInfo:
71
OUString SAL_CALL CLiteral::getImplementationName()
72
0
{
73
0
    return u"CLiteral"_ustr;
74
0
}
75
76
sal_Bool SAL_CALL CLiteral::supportsService(OUString const & serviceName)
77
0
{
78
0
    return cppu::supportsService(this, serviceName);
79
0
}
80
81
css::uno::Sequence< OUString > SAL_CALL CLiteral::getSupportedServiceNames()
82
0
{
83
0
    return { u"com.sun.star.rdf.Literal"_ustr };
84
0
}
85
86
// css::lang::XInitialization:
87
void SAL_CALL CLiteral::initialize(const css::uno::Sequence< css::uno::Any > & aArguments)
88
0
{
89
0
    const sal_Int32 len( aArguments.getLength() );
90
0
    if (len < 1 || len > 2) {
91
0
            throw css::lang::IllegalArgumentException(
92
0
                u"CLiteral::initialize: must give 1 or 2 argument(s)"_ustr, *this, 2);
93
0
    }
94
95
0
    OUString arg0;
96
0
    if (!(aArguments[0] >>= arg0)) {
97
0
        throw css::lang::IllegalArgumentException(
98
0
            u"CLiteral::initialize: argument must be string"_ustr, *this, 0);
99
0
    }
100
    //FIXME: what is legal?
101
0
    if (!(true)) {
102
0
        throw css::lang::IllegalArgumentException(
103
0
            u"CLiteral::initialize: argument is not valid literal value"_ustr, *this, 0);
104
0
    }
105
0
    m_Value = arg0;
106
107
0
    if (len <= 1)
108
0
        return;
109
110
0
    OUString arg1;
111
0
    css::uno::Reference< css::rdf::XURI > xURI;
112
0
    if (aArguments[1] >>= arg1) {
113
0
        if (arg1.isEmpty()) {
114
0
            throw css::lang::IllegalArgumentException(
115
0
                u"CLiteral::initialize: argument is not valid language"_ustr, *this, 1);
116
0
        }
117
0
        m_Language = arg1;
118
0
    } else if (aArguments[1] >>= xURI) {
119
0
        if (!xURI.is()) {
120
0
            throw css::lang::IllegalArgumentException(
121
0
                u"CLiteral::initialize: argument is null"_ustr, *this, 1);
122
0
        }
123
0
        m_xDatatype = std::move(xURI);
124
0
    } else {
125
0
        throw css::lang::IllegalArgumentException(
126
0
            u"CLiteral::initialize: argument must be string or URI"_ustr, *this, 1);
127
0
    }
128
0
}
129
130
// css::rdf::XNode:
131
OUString SAL_CALL CLiteral::getStringValue()
132
0
{
133
0
    if (!m_Language.isEmpty()) {
134
0
        return m_Value + "@" + m_Language;
135
0
    } else if (m_xDatatype.is()) {
136
0
        return m_Value + "^^" +  m_xDatatype->getStringValue();
137
0
    } else {
138
0
        return m_Value;
139
0
    }
140
0
}
141
142
// css::rdf::XLiteral:
143
OUString SAL_CALL CLiteral::getValue()
144
0
{
145
0
    return m_Value;
146
0
}
147
148
OUString SAL_CALL CLiteral::getLanguage()
149
0
{
150
0
    return m_Language;
151
0
}
152
153
css::uno::Reference< css::rdf::XURI > SAL_CALL CLiteral::getDatatype()
154
0
{
155
0
    return m_xDatatype;
156
0
}
157
158
} // closing anonymous implementation namespace
159
160
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
161
unoxml_CLiteral_get_implementation(
162
    css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
163
0
{
164
0
    return cppu::acquire(new CLiteral());
165
0
}
166
167
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */