build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / unoxml / source / rdf / CLiteral.cxx
blob9d488d9e991b999f976743c33436c76434b4d4b3
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();
44 virtual ~CLiteral() override {}
46 // css::lang::XServiceInfo:
47 virtual OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException, std::exception) override;
48 virtual sal_Bool SAL_CALL supportsService(const OUString & ServiceName) throw (css::uno::RuntimeException, std::exception) override;
49 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception) override;
51 // css::lang::XInitialization:
52 virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > & aArguments) throw (css::uno::RuntimeException, css::uno::Exception, std::exception) override;
54 // css::rdf::XNode:
55 virtual OUString SAL_CALL getStringValue() throw (css::uno::RuntimeException, std::exception) override;
57 // css::rdf::XLiteral:
58 virtual OUString SAL_CALL getValue() throw (css::uno::RuntimeException, std::exception) override;
59 virtual OUString SAL_CALL getLanguage() throw (css::uno::RuntimeException, std::exception) override;
60 virtual css::uno::Reference< css::rdf::XURI > SAL_CALL getDatatype() throw (css::uno::RuntimeException, std::exception) override;
62 private:
63 CLiteral(CLiteral const&) = delete;
64 CLiteral& operator=(CLiteral const&) = delete;
66 OUString m_Value;
67 OUString m_Language;
68 css::uno::Reference< css::rdf::XURI > m_xDatatype;
71 CLiteral::CLiteral() :
72 m_Value(), m_Language(), m_xDatatype()
75 // com.sun.star.uno.XServiceInfo:
76 OUString SAL_CALL CLiteral::getImplementationName() throw (css::uno::RuntimeException, std::exception)
78 return comp_CLiteral::_getImplementationName();
81 sal_Bool SAL_CALL CLiteral::supportsService(OUString const & serviceName) throw (css::uno::RuntimeException, std::exception)
83 return cppu::supportsService(this, serviceName);
86 css::uno::Sequence< OUString > SAL_CALL CLiteral::getSupportedServiceNames() throw (css::uno::RuntimeException, std::exception)
88 return comp_CLiteral::_getSupportedServiceNames();
91 // css::lang::XInitialization:
92 void SAL_CALL CLiteral::initialize(const css::uno::Sequence< css::uno::Any > & aArguments) throw (css::uno::RuntimeException, css::uno::Exception, std::exception)
94 const sal_Int32 len( aArguments.getLength() );
95 if (len < 1 || len > 2) {
96 throw css::lang::IllegalArgumentException(
97 OUString("CLiteral::initialize: "
98 "must give 1 or 2 argument(s)"), *this, 2);
101 OUString arg0;
102 if (!(aArguments[0] >>= arg0)) {
103 throw css::lang::IllegalArgumentException(
104 OUString("CLiteral::initialize: "
105 "argument must be string"), *this, 0);
107 //FIXME: what is legal?
108 if (true) {
109 m_Value = arg0;
110 } else {
111 throw css::lang::IllegalArgumentException(
112 OUString("CLiteral::initialize: "
113 "argument is not valid literal value"), *this, 0);
116 if (len > 1) {
117 OUString arg1;
118 css::uno::Reference< css::rdf::XURI > xURI;
119 if ((aArguments[1] >>= arg1)) {
120 if (!arg1.isEmpty()) {
121 m_Language = arg1;
122 } else {
123 throw css::lang::IllegalArgumentException(
124 OUString("CLiteral::initialize: "
125 "argument is not valid language"), *this, 1);
127 } else if ((aArguments[1] >>= xURI)) {
128 if (xURI.is()) {
129 m_xDatatype = xURI;
130 } else {
131 throw css::lang::IllegalArgumentException(
132 OUString("CLiteral::initialize: "
133 "argument is null"), *this, 1);
135 } else {
136 throw css::lang::IllegalArgumentException(
137 OUString("CLiteral::initialize: "
138 "argument must be string or URI"), *this, 1);
143 // css::rdf::XNode:
144 OUString SAL_CALL CLiteral::getStringValue() throw (css::uno::RuntimeException, std::exception)
146 if (!m_Language.isEmpty()) {
147 OUStringBuffer buf(m_Value);
148 buf.append("@");
149 buf.append(m_Language);
150 return buf.makeStringAndClear();
151 } else if (m_xDatatype.is()) {
152 OUStringBuffer buf(m_Value);
153 buf.append("^^");
154 buf.append(m_xDatatype->getStringValue());
155 return buf.makeStringAndClear();
156 } else {
157 return m_Value;
161 // css::rdf::XLiteral:
162 OUString SAL_CALL CLiteral::getValue() throw (css::uno::RuntimeException, std::exception)
164 return m_Value;
167 OUString SAL_CALL CLiteral::getLanguage() throw (css::uno::RuntimeException, std::exception)
169 return m_Language;
172 css::uno::Reference< css::rdf::XURI > SAL_CALL CLiteral::getDatatype() throw (css::uno::RuntimeException, std::exception)
174 return m_xDatatype;
177 } // closing anonymous implementation namespace
180 // component helper namespace
181 namespace comp_CLiteral {
183 OUString SAL_CALL _getImplementationName() {
184 return OUString( "CLiteral");
187 css::uno::Sequence< OUString > SAL_CALL _getSupportedServiceNames()
189 css::uno::Sequence< OUString > s { "com.sun.star.rdf.Literal" };
190 return s;
193 css::uno::Reference< css::uno::XInterface > SAL_CALL _create(
194 const css::uno::Reference< css::uno::XComponentContext > & )
196 return static_cast< ::cppu::OWeakObject * >(new CLiteral);
199 } // closing component helper namespace
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */