1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 #include <cppuhelper/implbase3.hxx>
31 #include <com/sun/star/lang/XServiceInfo.hpp>
32 #include <com/sun/star/lang/XInitialization.hpp>
33 #include <com/sun/star/rdf/XLiteral.hpp>
35 #include <com/sun/star/lang/IllegalArgumentException.hpp>
37 #include <rtl/ustrbuf.hxx>
40 /// anonymous implementation namespace
43 namespace css
= ::com::sun::star
;
46 public ::cppu::WeakImplHelper3
<
47 css::lang::XServiceInfo
,
48 css::lang::XInitialization
,
52 explicit CLiteral(css::uno::Reference
< css::uno::XComponentContext
> const & context
);
53 virtual ~CLiteral() {}
55 // ::com::sun::star::lang::XServiceInfo:
56 virtual ::rtl::OUString SAL_CALL
getImplementationName() throw (css::uno::RuntimeException
);
57 virtual ::sal_Bool SAL_CALL
supportsService(const ::rtl::OUString
& ServiceName
) throw (css::uno::RuntimeException
);
58 virtual css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames() throw (css::uno::RuntimeException
);
60 // ::com::sun::star::lang::XInitialization:
61 virtual void SAL_CALL
initialize(const css::uno::Sequence
< ::com::sun::star::uno::Any
> & aArguments
) throw (css::uno::RuntimeException
, css::uno::Exception
);
63 // ::com::sun::star::rdf::XNode:
64 virtual ::rtl::OUString SAL_CALL
getStringValue() throw (css::uno::RuntimeException
);
66 // ::com::sun::star::rdf::XLiteral:
67 virtual ::rtl::OUString SAL_CALL
getValue() throw (css::uno::RuntimeException
);
68 virtual ::rtl::OUString SAL_CALL
getLanguage() throw (css::uno::RuntimeException
);
69 virtual css::uno::Reference
< css::rdf::XURI
> SAL_CALL
getDatatype() throw (css::uno::RuntimeException
);
72 CLiteral(const CLiteral
&); // not defined
73 CLiteral
& operator=(const CLiteral
&); // not defined
75 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
77 ::rtl::OUString m_Value
;
78 ::rtl::OUString m_Language
;
79 css::uno::Reference
< css::rdf::XURI
> m_xDatatype
;
82 CLiteral::CLiteral(css::uno::Reference
< css::uno::XComponentContext
> const & context
) :
83 m_xContext(context
), m_Value(), m_Language(), m_xDatatype()
86 // com.sun.star.uno.XServiceInfo:
87 ::rtl::OUString SAL_CALL
CLiteral::getImplementationName() throw (css::uno::RuntimeException
)
89 return comp_CLiteral::_getImplementationName();
92 ::sal_Bool SAL_CALL
CLiteral::supportsService(::rtl::OUString
const & serviceName
) throw (css::uno::RuntimeException
)
94 css::uno::Sequence
< ::rtl::OUString
> serviceNames
= comp_CLiteral::_getSupportedServiceNames();
95 for (::sal_Int32 i
= 0; i
< serviceNames
.getLength(); ++i
) {
96 if (serviceNames
[i
] == serviceName
)
102 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
CLiteral::getSupportedServiceNames() throw (css::uno::RuntimeException
)
104 return comp_CLiteral::_getSupportedServiceNames();
107 // ::com::sun::star::lang::XInitialization:
108 void SAL_CALL
CLiteral::initialize(const css::uno::Sequence
< ::com::sun::star::uno::Any
> & aArguments
) throw (css::uno::RuntimeException
, css::uno::Exception
)
110 const sal_Int32
len( aArguments
.getLength() );
111 if (len
< 1 || len
> 2) {
112 throw css::lang::IllegalArgumentException(
113 ::rtl::OUString::createFromAscii("CLiteral::initialize: "
114 "must give 1 or 2 argument(s)"), *this, 2);
117 ::rtl::OUString arg0
;
118 if (!(aArguments
[0] >>= arg0
)) {
119 throw css::lang::IllegalArgumentException(
120 ::rtl::OUString::createFromAscii("CLiteral::initialize: "
121 "argument must be string"), *this, 0);
123 //FIXME: what is legal?
127 throw css::lang::IllegalArgumentException(
128 ::rtl::OUString::createFromAscii("CLiteral::initialize: "
129 "argument is not valid literal value"), *this, 0);
133 ::rtl::OUString arg1
;
134 css::uno::Reference
< css::rdf::XURI
> xURI
;
135 if ((aArguments
[1] >>= arg1
)) {
136 if (arg1
.getLength() > 0) {
139 throw css::lang::IllegalArgumentException(
140 ::rtl::OUString::createFromAscii("CLiteral::initialize: "
141 "argument is not valid language"), *this, 1);
143 } else if ((aArguments
[1] >>= xURI
)) {
147 throw css::lang::IllegalArgumentException(
148 ::rtl::OUString::createFromAscii("CLiteral::initialize: "
149 "argument is null"), *this, 1);
152 throw css::lang::IllegalArgumentException(
153 ::rtl::OUString::createFromAscii("CLiteral::initialize: "
154 "argument must be string or URI"), *this, 1);
159 // ::com::sun::star::rdf::XNode:
160 ::rtl::OUString SAL_CALL
CLiteral::getStringValue() throw (css::uno::RuntimeException
)
162 if (!m_Language
.equalsAscii("")) {
163 ::rtl::OUStringBuffer
buf(m_Value
);
164 buf
.appendAscii("@");
165 buf
.append(m_Language
);
166 return buf
.makeStringAndClear();
167 } else if (m_xDatatype
.is()) {
168 ::rtl::OUStringBuffer
buf(m_Value
);
169 buf
.appendAscii("^^");
170 buf
.append(m_xDatatype
->getStringValue());
171 return buf
.makeStringAndClear();
177 // ::com::sun::star::rdf::XLiteral:
178 ::rtl::OUString SAL_CALL
CLiteral::getValue() throw (css::uno::RuntimeException
)
183 ::rtl::OUString SAL_CALL
CLiteral::getLanguage() throw (css::uno::RuntimeException
)
188 css::uno::Reference
< css::rdf::XURI
> SAL_CALL
CLiteral::getDatatype() throw (css::uno::RuntimeException
)
193 } // closing anonymous implementation namespace
197 // component helper namespace
198 namespace comp_CLiteral
{
200 ::rtl::OUString SAL_CALL
_getImplementationName() {
201 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
205 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
_getSupportedServiceNames()
207 css::uno::Sequence
< ::rtl::OUString
> s(1);
208 s
[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
209 "com.sun.star.rdf.Literal"));
213 css::uno::Reference
< css::uno::XInterface
> SAL_CALL
_create(
214 const css::uno::Reference
< css::uno::XComponentContext
> & context
)
215 SAL_THROW((css::uno::Exception
))
217 return static_cast< ::cppu::OWeakObject
* >(new CLiteral(context
));
220 } // closing component helper namespace