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 <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>
27 #include <com/sun/star/lang/IllegalArgumentException.hpp>
30 /// anonymous implementation namespace
34 public ::cppu::WeakImplHelper
<
35 css::lang::XServiceInfo
,
36 css::lang::XInitialization
,
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
;
47 // css::lang::XInitialization:
48 virtual void SAL_CALL
initialize(const css::uno::Sequence
< css::uno::Any
> & aArguments
) override
;
51 virtual OUString SAL_CALL
getStringValue() override
;
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
;
59 CLiteral(CLiteral
const&) = delete;
60 CLiteral
& operator=(CLiteral
const&) = delete;
64 css::uno::Reference
< css::rdf::XURI
> m_xDatatype
;
70 // com.sun.star.uno.XServiceInfo:
71 OUString SAL_CALL
CLiteral::getImplementationName()
73 return u
"CLiteral"_ustr
;
76 sal_Bool SAL_CALL
CLiteral::supportsService(OUString
const & serviceName
)
78 return cppu::supportsService(this, serviceName
);
81 css::uno::Sequence
< OUString
> SAL_CALL
CLiteral::getSupportedServiceNames()
83 return { u
"com.sun.star.rdf.Literal"_ustr
};
86 // css::lang::XInitialization:
87 void SAL_CALL
CLiteral::initialize(const css::uno::Sequence
< css::uno::Any
> & aArguments
)
89 const sal_Int32
len( aArguments
.getLength() );
90 if (len
< 1 || len
> 2) {
91 throw css::lang::IllegalArgumentException(
92 u
"CLiteral::initialize: must give 1 or 2 argument(s)"_ustr
, *this, 2);
96 if (!(aArguments
[0] >>= arg0
)) {
97 throw css::lang::IllegalArgumentException(
98 u
"CLiteral::initialize: argument must be string"_ustr
, *this, 0);
100 //FIXME: what is legal?
102 throw css::lang::IllegalArgumentException(
103 u
"CLiteral::initialize: argument is not valid literal value"_ustr
, *this, 0);
111 css::uno::Reference
< css::rdf::XURI
> xURI
;
112 if (aArguments
[1] >>= arg1
) {
113 if (arg1
.isEmpty()) {
114 throw css::lang::IllegalArgumentException(
115 u
"CLiteral::initialize: argument is not valid language"_ustr
, *this, 1);
118 } else if (aArguments
[1] >>= xURI
) {
120 throw css::lang::IllegalArgumentException(
121 u
"CLiteral::initialize: argument is null"_ustr
, *this, 1);
123 m_xDatatype
= std::move(xURI
);
125 throw css::lang::IllegalArgumentException(
126 u
"CLiteral::initialize: argument must be string or URI"_ustr
, *this, 1);
131 OUString SAL_CALL
CLiteral::getStringValue()
133 if (!m_Language
.isEmpty()) {
134 return m_Value
+ "@" + m_Language
;
135 } else if (m_xDatatype
.is()) {
136 return m_Value
+ "^^" + m_xDatatype
->getStringValue();
142 // css::rdf::XLiteral:
143 OUString SAL_CALL
CLiteral::getValue()
148 OUString SAL_CALL
CLiteral::getLanguage()
153 css::uno::Reference
< css::rdf::XURI
> SAL_CALL
CLiteral::getDatatype()
158 } // closing anonymous implementation namespace
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&)
164 return cppu::acquire(new CLiteral());
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */