Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include "CNodes.hxx"
21 : :
22 : : #include <cppuhelper/implbase3.hxx>
23 : : #include <com/sun/star/lang/XServiceInfo.hpp>
24 : : #include <com/sun/star/lang/XInitialization.hpp>
25 : : #include <com/sun/star/rdf/XLiteral.hpp>
26 : :
27 : : #include <com/sun/star/lang/IllegalArgumentException.hpp>
28 : :
29 : : #include <rtl/ustrbuf.hxx>
30 : :
31 : :
32 : : /// anonymous implementation namespace
33 : : namespace {
34 : :
35 : : namespace css = ::com::sun::star;
36 : :
37 : : class CLiteral:
38 : : public ::cppu::WeakImplHelper3<
39 : : css::lang::XServiceInfo,
40 : : css::lang::XInitialization,
41 : : css::rdf::XLiteral>
42 : : {
43 : : public:
44 : : explicit CLiteral(css::uno::Reference< css::uno::XComponentContext > const & context);
45 [ - + ]: 952 : virtual ~CLiteral() {}
46 : :
47 : : // ::com::sun::star::lang::XServiceInfo:
48 : : virtual ::rtl::OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException);
49 : : virtual ::sal_Bool SAL_CALL supportsService(const ::rtl::OUString & ServiceName) throw (css::uno::RuntimeException);
50 : : virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (css::uno::RuntimeException);
51 : :
52 : : // ::com::sun::star::lang::XInitialization:
53 : : virtual void SAL_CALL initialize(const css::uno::Sequence< ::com::sun::star::uno::Any > & aArguments) throw (css::uno::RuntimeException, css::uno::Exception);
54 : :
55 : : // ::com::sun::star::rdf::XNode:
56 : : virtual ::rtl::OUString SAL_CALL getStringValue() throw (css::uno::RuntimeException);
57 : :
58 : : // ::com::sun::star::rdf::XLiteral:
59 : : virtual ::rtl::OUString SAL_CALL getValue() throw (css::uno::RuntimeException);
60 : : virtual ::rtl::OUString SAL_CALL getLanguage() throw (css::uno::RuntimeException);
61 : : virtual css::uno::Reference< css::rdf::XURI > SAL_CALL getDatatype() throw (css::uno::RuntimeException);
62 : :
63 : : private:
64 : : CLiteral(const CLiteral &); // not defined
65 : : CLiteral& operator=(const CLiteral &); // not defined
66 : :
67 : : css::uno::Reference< css::uno::XComponentContext > m_xContext;
68 : :
69 : : ::rtl::OUString m_Value;
70 : : ::rtl::OUString m_Language;
71 : : css::uno::Reference< css::rdf::XURI > m_xDatatype;
72 : : };
73 : :
74 : 476 : CLiteral::CLiteral(css::uno::Reference< css::uno::XComponentContext > const & context) :
75 : 476 : m_xContext(context), m_Value(), m_Language(), m_xDatatype()
76 : 476 : {}
77 : :
78 : : // com.sun.star.uno.XServiceInfo:
79 : 0 : ::rtl::OUString SAL_CALL CLiteral::getImplementationName() throw (css::uno::RuntimeException)
80 : : {
81 : 0 : return comp_CLiteral::_getImplementationName();
82 : : }
83 : :
84 : 0 : ::sal_Bool SAL_CALL CLiteral::supportsService(::rtl::OUString const & serviceName) throw (css::uno::RuntimeException)
85 : : {
86 [ # # ]: 0 : css::uno::Sequence< ::rtl::OUString > serviceNames = comp_CLiteral::_getSupportedServiceNames();
87 [ # # ]: 0 : for (::sal_Int32 i = 0; i < serviceNames.getLength(); ++i) {
88 [ # # ][ # # ]: 0 : if (serviceNames[i] == serviceName)
89 : 0 : return sal_True;
90 : : }
91 [ # # ]: 0 : return sal_False;
92 : : }
93 : :
94 : 0 : css::uno::Sequence< ::rtl::OUString > SAL_CALL CLiteral::getSupportedServiceNames() throw (css::uno::RuntimeException)
95 : : {
96 : 0 : return comp_CLiteral::_getSupportedServiceNames();
97 : : }
98 : :
99 : : // ::com::sun::star::lang::XInitialization:
100 : 476 : void SAL_CALL CLiteral::initialize(const css::uno::Sequence< ::com::sun::star::uno::Any > & aArguments) throw (css::uno::RuntimeException, css::uno::Exception)
101 : : {
102 : 476 : const sal_Int32 len( aArguments.getLength() );
103 [ - + ][ + - ]: 476 : if (len < 1 || len > 2) {
104 : : throw css::lang::IllegalArgumentException(
105 : : ::rtl::OUString("CLiteral::initialize: "
106 [ # # ][ # # ]: 0 : "must give 1 or 2 argument(s)"), *this, 2);
107 : : }
108 : :
109 : 476 : ::rtl::OUString arg0;
110 [ - + ]: 476 : if (!(aArguments[0] >>= arg0)) {
111 : : throw css::lang::IllegalArgumentException(
112 : : ::rtl::OUString("CLiteral::initialize: "
113 [ # # ][ # # ]: 0 : "argument must be string"), *this, 0);
114 : : }
115 : : //FIXME: what is legal?
116 : : if (true) {
117 : 476 : m_Value = arg0;
118 : : } else {
119 : : throw css::lang::IllegalArgumentException(
120 : : ::rtl::OUString("CLiteral::initialize: "
121 : : "argument is not valid literal value"), *this, 0);
122 : : }
123 : :
124 [ + + ]: 476 : if (len > 1) {
125 : 84 : ::rtl::OUString arg1;
126 : 84 : css::uno::Reference< css::rdf::XURI > xURI;
127 [ + + ]: 84 : if ((aArguments[1] >>= arg1)) {
128 [ + - ]: 10 : if (!arg1.isEmpty()) {
129 : 10 : m_Language = arg1;
130 : : } else {
131 : : throw css::lang::IllegalArgumentException(
132 : : ::rtl::OUString("CLiteral::initialize: "
133 [ # # ][ # # ]: 0 : "argument is not valid language"), *this, 1);
134 : : }
135 [ + - ][ + - ]: 74 : } else if ((aArguments[1] >>= xURI)) {
136 [ + - ]: 74 : if (xURI.is()) {
137 [ + - ]: 74 : m_xDatatype = xURI;
138 : : } else {
139 : : throw css::lang::IllegalArgumentException(
140 : : ::rtl::OUString("CLiteral::initialize: "
141 [ # # ][ # # ]: 0 : "argument is null"), *this, 1);
142 : : }
143 : : } else {
144 : : throw css::lang::IllegalArgumentException(
145 : : ::rtl::OUString("CLiteral::initialize: "
146 [ # # ][ # # ]: 0 : "argument must be string or URI"), *this, 1);
147 : 84 : }
148 : 476 : }
149 : 476 : }
150 : :
151 : : // ::com::sun::star::rdf::XNode:
152 : 364 : ::rtl::OUString SAL_CALL CLiteral::getStringValue() throw (css::uno::RuntimeException)
153 : : {
154 [ + + ]: 364 : if (!m_Language.isEmpty()) {
155 [ + - ]: 22 : ::rtl::OUStringBuffer buf(m_Value);
156 [ + - ]: 22 : buf.appendAscii("@");
157 [ + - ]: 22 : buf.append(m_Language);
158 [ + - ]: 22 : return buf.makeStringAndClear();
159 [ + + ]: 342 : } else if (m_xDatatype.is()) {
160 [ + - ]: 92 : ::rtl::OUStringBuffer buf(m_Value);
161 [ + - ]: 92 : buf.appendAscii("^^");
162 [ + - ][ + - ]: 92 : buf.append(m_xDatatype->getStringValue());
[ + - ]
163 [ + - ]: 92 : return buf.makeStringAndClear();
164 : : } else {
165 : 364 : return m_Value;
166 : : }
167 : : }
168 : :
169 : : // ::com::sun::star::rdf::XLiteral:
170 : 254 : ::rtl::OUString SAL_CALL CLiteral::getValue() throw (css::uno::RuntimeException)
171 : : {
172 : 254 : return m_Value;
173 : : }
174 : :
175 : 102 : ::rtl::OUString SAL_CALL CLiteral::getLanguage() throw (css::uno::RuntimeException)
176 : : {
177 : 102 : return m_Language;
178 : : }
179 : :
180 : 136 : css::uno::Reference< css::rdf::XURI > SAL_CALL CLiteral::getDatatype() throw (css::uno::RuntimeException)
181 : : {
182 : 136 : return m_xDatatype;
183 : : }
184 : :
185 : : } // closing anonymous implementation namespace
186 : :
187 : :
188 : :
189 : : // component helper namespace
190 : : namespace comp_CLiteral {
191 : :
192 : 50 : ::rtl::OUString SAL_CALL _getImplementationName() {
193 : 50 : return ::rtl::OUString( "CLiteral");
194 : : }
195 : :
196 : 6 : css::uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames()
197 : : {
198 : 6 : css::uno::Sequence< ::rtl::OUString > s(1);
199 [ + - ]: 6 : s[0] = ::rtl::OUString( "com.sun.star.rdf.Literal");
200 : 6 : return s;
201 : : }
202 : :
203 : 476 : css::uno::Reference< css::uno::XInterface > SAL_CALL _create(
204 : : const css::uno::Reference< css::uno::XComponentContext > & context)
205 : : SAL_THROW((css::uno::Exception))
206 : : {
207 [ + - ]: 476 : return static_cast< ::cppu::OWeakObject * >(new CLiteral(context));
208 : : }
209 : :
210 : : } // closing component helper namespace
211 : :
212 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|