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
;
67 CLiteral::CLiteral() :
68 m_Value(), m_Language(), m_xDatatype()
71 // com.sun.star.uno.XServiceInfo:
72 OUString SAL_CALL
CLiteral::getImplementationName()
77 sal_Bool SAL_CALL
CLiteral::supportsService(OUString
const & serviceName
)
79 return cppu::supportsService(this, serviceName
);
82 css::uno::Sequence
< OUString
> SAL_CALL
CLiteral::getSupportedServiceNames()
84 return { "com.sun.star.rdf.Literal" };
87 // css::lang::XInitialization:
88 void SAL_CALL
CLiteral::initialize(const css::uno::Sequence
< css::uno::Any
> & aArguments
)
90 const sal_Int32
len( aArguments
.getLength() );
91 if (len
< 1 || len
> 2) {
92 throw css::lang::IllegalArgumentException(
93 "CLiteral::initialize: must give 1 or 2 argument(s)", *this, 2);
97 if (!(aArguments
[0] >>= arg0
)) {
98 throw css::lang::IllegalArgumentException(
99 "CLiteral::initialize: argument must be string", *this, 0);
101 //FIXME: what is legal?
103 throw css::lang::IllegalArgumentException(
104 "CLiteral::initialize: argument is not valid literal value", *this, 0);
112 css::uno::Reference
< css::rdf::XURI
> xURI
;
113 if (aArguments
[1] >>= arg1
) {
114 if (arg1
.isEmpty()) {
115 throw css::lang::IllegalArgumentException(
116 "CLiteral::initialize: argument is not valid language", *this, 1);
119 } else if (aArguments
[1] >>= xURI
) {
121 throw css::lang::IllegalArgumentException(
122 "CLiteral::initialize: argument is null", *this, 1);
126 throw css::lang::IllegalArgumentException(
127 "CLiteral::initialize: argument must be string or URI", *this, 1);
132 OUString SAL_CALL
CLiteral::getStringValue()
134 if (!m_Language
.isEmpty()) {
135 return m_Value
+ "@" + m_Language
;
136 } else if (m_xDatatype
.is()) {
137 return m_Value
+ "^^" + m_xDatatype
->getStringValue();
143 // css::rdf::XLiteral:
144 OUString SAL_CALL
CLiteral::getValue()
149 OUString SAL_CALL
CLiteral::getLanguage()
154 css::uno::Reference
< css::rdf::XURI
> SAL_CALL
CLiteral::getDatatype()
159 } // closing anonymous implementation namespace
161 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
162 unoxml_CLiteral_get_implementation(
163 css::uno::XComponentContext
* , css::uno::Sequence
<css::uno::Any
> const&)
165 return cppu::acquire(new CLiteral());
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */