Bump version to 21.06.18.1
[LibreOffice.git] / unoxml / source / rdf / CLiteral.cxx
blobac0eadcd6985e0769bb3a0a94a8478c2b587f9cf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
31 namespace {
33 class CLiteral:
34 public ::cppu::WeakImplHelper<
35 css::lang::XServiceInfo,
36 css::lang::XInitialization,
37 css::rdf::XLiteral>
39 public:
40 explicit CLiteral();
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;
50 // css::rdf::XNode:
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;
58 private:
59 CLiteral(CLiteral const&) = delete;
60 CLiteral& operator=(CLiteral const&) = delete;
62 OUString m_Value;
63 OUString m_Language;
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()
74 return "CLiteral";
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);
96 OUString arg0;
97 if (!(aArguments[0] >>= arg0)) {
98 throw css::lang::IllegalArgumentException(
99 "CLiteral::initialize: argument must be string", *this, 0);
101 //FIXME: what is legal?
102 if (!(true)) {
103 throw css::lang::IllegalArgumentException(
104 "CLiteral::initialize: argument is not valid literal value", *this, 0);
106 m_Value = arg0;
108 if (len <= 1)
109 return;
111 OUString arg1;
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);
118 m_Language = arg1;
119 } else if (aArguments[1] >>= xURI) {
120 if (!xURI.is()) {
121 throw css::lang::IllegalArgumentException(
122 "CLiteral::initialize: argument is null", *this, 1);
124 m_xDatatype = xURI;
125 } else {
126 throw css::lang::IllegalArgumentException(
127 "CLiteral::initialize: argument must be string or URI", *this, 1);
131 // css::rdf::XNode:
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();
138 } else {
139 return m_Value;
143 // css::rdf::XLiteral:
144 OUString SAL_CALL CLiteral::getValue()
146 return m_Value;
149 OUString SAL_CALL CLiteral::getLanguage()
151 return m_Language;
154 css::uno::Reference< css::rdf::XURI > SAL_CALL CLiteral::getDatatype()
156 return m_xDatatype;
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: */