LibreOffice Module unoxml (master) 1
CLiteral.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
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
31namespace {
32
33class CLiteral:
34 public ::cppu::WeakImplHelper<
35 css::lang::XServiceInfo,
36 css::lang::XInitialization,
37 css::rdf::XLiteral>
38{
39public:
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
58private:
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
67CLiteral::CLiteral()
68{}
69
70// com.sun.star.uno.XServiceInfo:
71OUString SAL_CALL CLiteral::getImplementationName()
72{
73 return "CLiteral";
74}
75
76sal_Bool SAL_CALL CLiteral::supportsService(OUString const & serviceName)
77{
78 return cppu::supportsService(this, serviceName);
79}
80
81css::uno::Sequence< OUString > SAL_CALL CLiteral::getSupportedServiceNames()
82{
83 return { "com.sun.star.rdf.Literal" };
84}
85
86// css::lang::XInitialization:
87void SAL_CALL CLiteral::initialize(const css::uno::Sequence< css::uno::Any > & aArguments)
88{
89 const sal_Int32 len( aArguments.getLength() );
90 if (len < 1 || len > 2) {
91 throw css::lang::IllegalArgumentException(
92 "CLiteral::initialize: must give 1 or 2 argument(s)", *this, 2);
93 }
94
95 OUString arg0;
96 if (!(aArguments[0] >>= arg0)) {
97 throw css::lang::IllegalArgumentException(
98 "CLiteral::initialize: argument must be string", *this, 0);
99 }
100 //FIXME: what is legal?
101 if (!(true)) {
102 throw css::lang::IllegalArgumentException(
103 "CLiteral::initialize: argument is not valid literal value", *this, 0);
104 }
105 m_Value = arg0;
106
107 if (len <= 1)
108 return;
109
110 OUString arg1;
111 css::uno::Reference< css::rdf::XURI > xURI;
112 if (aArguments[1] >>= arg1) {
113 if (arg1.isEmpty()) {
114 throw css::lang::IllegalArgumentException(
115 "CLiteral::initialize: argument is not valid language", *this, 1);
116 }
117 m_Language = arg1;
118 } else if (aArguments[1] >>= xURI) {
119 if (!xURI.is()) {
120 throw css::lang::IllegalArgumentException(
121 "CLiteral::initialize: argument is null", *this, 1);
122 }
123 m_xDatatype = xURI;
124 } else {
125 throw css::lang::IllegalArgumentException(
126 "CLiteral::initialize: argument must be string or URI", *this, 1);
127 }
128}
129
130// css::rdf::XNode:
131OUString SAL_CALL CLiteral::getStringValue()
132{
133 if (!m_Language.isEmpty()) {
134 return m_Value + "@" + m_Language;
135 } else if (m_xDatatype.is()) {
136 return m_Value + "^^" + m_xDatatype->getStringValue();
137 } else {
138 return m_Value;
139 }
140}
141
142// css::rdf::XLiteral:
143OUString SAL_CALL CLiteral::getValue()
144{
145 return m_Value;
146}
147
148OUString SAL_CALL CLiteral::getLanguage()
149{
150 return m_Language;
151}
152
153css::uno::Reference< css::rdf::XURI > SAL_CALL CLiteral::getDatatype()
154{
155 return m_xDatatype;
156}
157
158} // closing anonymous implementation namespace
159
160extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
162 css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&)
163{
164 return cppu::acquire(new CLiteral());
165}
166
167/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * unoxml_CLiteral_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Definition: CLiteral.cxx:161
Sequence< PropertyValue > aArguments
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
css::beans::Optional< css::uno::Any > getValue(std::u16string_view id)
unsigned char sal_Bool