fix disable qrcodegen option
[LibreOffice.git] / unoxml / source / rdf / CLiteral.cxx
blobf7f8c726e62637a493f23128904cf846b54dcdf2
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 "CNodes.hxx"
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
34 namespace {
36 class CLiteral:
37 public ::cppu::WeakImplHelper<
38 css::lang::XServiceInfo,
39 css::lang::XInitialization,
40 css::rdf::XLiteral>
42 public:
43 explicit CLiteral();
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;
53 // css::rdf::XNode:
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;
61 private:
62 CLiteral(CLiteral const&) = delete;
63 CLiteral& operator=(CLiteral const&) = delete;
65 OUString m_Value;
66 OUString m_Language;
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);
99 OUString arg0;
100 if (!(aArguments[0] >>= arg0)) {
101 throw css::lang::IllegalArgumentException(
102 "CLiteral::initialize: argument must be string", *this, 0);
104 //FIXME: what is legal?
105 if (!(true)) {
106 throw css::lang::IllegalArgumentException(
107 "CLiteral::initialize: argument is not valid literal value", *this, 0);
109 m_Value = arg0;
111 if (len > 1) {
112 OUString arg1;
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);
119 m_Language = arg1;
120 } else if (aArguments[1] >>= xURI) {
121 if (!xURI.is()) {
122 throw css::lang::IllegalArgumentException(
123 "CLiteral::initialize: argument is null", *this, 1);
125 m_xDatatype = xURI;
126 } else {
127 throw css::lang::IllegalArgumentException(
128 "CLiteral::initialize: argument must be string or URI", *this, 1);
133 // css::rdf::XNode:
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();
140 } else {
141 return m_Value;
145 // css::rdf::XLiteral:
146 OUString SAL_CALL CLiteral::getValue()
148 return m_Value;
151 OUString SAL_CALL CLiteral::getLanguage()
153 return m_Language;
156 css::uno::Reference< css::rdf::XURI > SAL_CALL CLiteral::getDatatype()
158 return m_xDatatype;
161 } // closing anonymous implementation namespace
164 // component helper namespace
165 namespace comp_CLiteral {
167 OUString _getImplementationName() {
168 return "CLiteral";
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: */