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 .
22 #include <cppuhelper/implbase.hxx>
23 #include <cppuhelper/supportsservice.hxx>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/lang/XInitialization.hpp>
26 #include <com/sun/star/rdf/XLiteral.hpp>
28 #include <com/sun/star/lang/IllegalArgumentException.hpp>
30 #include <rtl/ustrbuf.hxx>
33 /// anonymous implementation namespace
37 public ::cppu::WeakImplHelper
<
38 css::lang::XServiceInfo
,
39 css::lang::XInitialization
,
45 // css::lang::XServiceInfo:
46 virtual OUString SAL_CALL
getImplementationName() override
;
47 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
48 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
50 // css::lang::XInitialization:
51 virtual void SAL_CALL
initialize(const css::uno::Sequence
< css::uno::Any
> & aArguments
) override
;
54 virtual OUString SAL_CALL
getStringValue() override
;
56 // css::rdf::XLiteral:
57 virtual OUString SAL_CALL
getValue() override
;
58 virtual OUString SAL_CALL
getLanguage() override
;
59 virtual css::uno::Reference
< css::rdf::XURI
> SAL_CALL
getDatatype() override
;
62 CLiteral(CLiteral
const&) = delete;
63 CLiteral
& operator=(CLiteral
const&) = delete;
67 css::uno::Reference
< css::rdf::XURI
> m_xDatatype
;
70 CLiteral::CLiteral() :
71 m_Value(), m_Language(), m_xDatatype()
74 // com.sun.star.uno.XServiceInfo:
75 OUString SAL_CALL
CLiteral::getImplementationName()
77 return comp_CLiteral::_getImplementationName();
80 sal_Bool SAL_CALL
CLiteral::supportsService(OUString
const & serviceName
)
82 return cppu::supportsService(this, serviceName
);
85 css::uno::Sequence
< OUString
> SAL_CALL
CLiteral::getSupportedServiceNames()
87 return comp_CLiteral::_getSupportedServiceNames();
90 // css::lang::XInitialization:
91 void SAL_CALL
CLiteral::initialize(const css::uno::Sequence
< css::uno::Any
> & aArguments
)
93 const sal_Int32
len( aArguments
.getLength() );
94 if (len
< 1 || len
> 2) {
95 throw css::lang::IllegalArgumentException(
96 "CLiteral::initialize: must give 1 or 2 argument(s)", *this, 2);
100 if (!(aArguments
[0] >>= arg0
)) {
101 throw css::lang::IllegalArgumentException(
102 "CLiteral::initialize: argument must be string", *this, 0);
104 //FIXME: what is legal?
106 throw css::lang::IllegalArgumentException(
107 "CLiteral::initialize: argument is not valid literal value", *this, 0);
113 css::uno::Reference
< css::rdf::XURI
> xURI
;
114 if (aArguments
[1] >>= arg1
) {
115 if (arg1
.isEmpty()) {
116 throw css::lang::IllegalArgumentException(
117 "CLiteral::initialize: argument is not valid language", *this, 1);
120 } else if (aArguments
[1] >>= xURI
) {
122 throw css::lang::IllegalArgumentException(
123 "CLiteral::initialize: argument is null", *this, 1);
127 throw css::lang::IllegalArgumentException(
128 "CLiteral::initialize: argument must be string or URI", *this, 1);
134 OUString SAL_CALL
CLiteral::getStringValue()
136 if (!m_Language
.isEmpty()) {
137 return m_Value
+ "@" + m_Language
;
138 } else if (m_xDatatype
.is()) {
139 return m_Value
+ "^^" + m_xDatatype
->getStringValue();
145 // css::rdf::XLiteral:
146 OUString SAL_CALL
CLiteral::getValue()
151 OUString SAL_CALL
CLiteral::getLanguage()
156 css::uno::Reference
< css::rdf::XURI
> SAL_CALL
CLiteral::getDatatype()
161 } // closing anonymous implementation namespace
164 // component helper namespace
165 namespace comp_CLiteral
{
167 OUString
_getImplementationName() {
171 css::uno::Sequence
< OUString
> _getSupportedServiceNames()
173 return { "com.sun.star.rdf.Literal" };
176 css::uno::Reference
< css::uno::XInterface
> _create(
177 const css::uno::Reference
< css::uno::XComponentContext
> & )
179 return static_cast< ::cppu::OWeakObject
* >(new CLiteral
);
182 } // closing component helper namespace
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */