1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CLiteral.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #include <cppuhelper/implbase3.hxx>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/lang/XInitialization.hpp>
36 #include <com/sun/star/rdf/XLiteral.hpp>
38 #include <com/sun/star/lang/IllegalArgumentException.hpp>
40 #include <rtl/ustrbuf.hxx>
43 /// anonymous implementation namespace
46 namespace css
= ::com::sun::star
;
49 public ::cppu::WeakImplHelper3
<
50 css::lang::XServiceInfo
,
51 css::lang::XInitialization
,
55 explicit CLiteral(css::uno::Reference
< css::uno::XComponentContext
> const & context
);
56 virtual ~CLiteral() {}
58 // ::com::sun::star::lang::XServiceInfo:
59 virtual ::rtl::OUString SAL_CALL
getImplementationName() throw (css::uno::RuntimeException
);
60 virtual ::sal_Bool SAL_CALL
supportsService(const ::rtl::OUString
& ServiceName
) throw (css::uno::RuntimeException
);
61 virtual css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames() throw (css::uno::RuntimeException
);
63 // ::com::sun::star::lang::XInitialization:
64 virtual void SAL_CALL
initialize(const css::uno::Sequence
< ::com::sun::star::uno::Any
> & aArguments
) throw (css::uno::RuntimeException
, css::uno::Exception
);
66 // ::com::sun::star::rdf::XNode:
67 virtual ::rtl::OUString SAL_CALL
getStringValue() throw (css::uno::RuntimeException
);
69 // ::com::sun::star::rdf::XLiteral:
70 virtual ::rtl::OUString SAL_CALL
getValue() throw (css::uno::RuntimeException
);
71 virtual ::rtl::OUString SAL_CALL
getLanguage() throw (css::uno::RuntimeException
);
72 virtual css::uno::Reference
< css::rdf::XURI
> SAL_CALL
getDatatype() throw (css::uno::RuntimeException
);
75 CLiteral(const CLiteral
&); // not defined
76 CLiteral
& operator=(const CLiteral
&); // not defined
78 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
80 ::rtl::OUString m_Value
;
81 ::rtl::OUString m_Language
;
82 css::uno::Reference
< css::rdf::XURI
> m_xDatatype
;
85 CLiteral::CLiteral(css::uno::Reference
< css::uno::XComponentContext
> const & context
) :
86 m_xContext(context
), m_Value(), m_Language(), m_xDatatype()
89 // com.sun.star.uno.XServiceInfo:
90 ::rtl::OUString SAL_CALL
CLiteral::getImplementationName() throw (css::uno::RuntimeException
)
92 return comp_CLiteral::_getImplementationName();
95 ::sal_Bool SAL_CALL
CLiteral::supportsService(::rtl::OUString
const & serviceName
) throw (css::uno::RuntimeException
)
97 css::uno::Sequence
< ::rtl::OUString
> serviceNames
= comp_CLiteral::_getSupportedServiceNames();
98 for (::sal_Int32 i
= 0; i
< serviceNames
.getLength(); ++i
) {
99 if (serviceNames
[i
] == serviceName
)
105 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
CLiteral::getSupportedServiceNames() throw (css::uno::RuntimeException
)
107 return comp_CLiteral::_getSupportedServiceNames();
110 // ::com::sun::star::lang::XInitialization:
111 void SAL_CALL
CLiteral::initialize(const css::uno::Sequence
< ::com::sun::star::uno::Any
> & aArguments
) throw (css::uno::RuntimeException
, css::uno::Exception
)
113 const sal_Int32
len( aArguments
.getLength() );
114 if (len
< 1 || len
> 2) {
115 throw css::lang::IllegalArgumentException(
116 ::rtl::OUString::createFromAscii("CLiteral::initialize: "
117 "must give 1 or 2 argument(s)"), *this, 2);
120 ::rtl::OUString arg0
;
121 if (!(aArguments
[0] >>= arg0
)) {
122 throw css::lang::IllegalArgumentException(
123 ::rtl::OUString::createFromAscii("CLiteral::initialize: "
124 "argument must be string"), *this, 0);
126 //FIXME: what is legal?
130 throw css::lang::IllegalArgumentException(
131 ::rtl::OUString::createFromAscii("CLiteral::initialize: "
132 "argument is not valid literal value"), *this, 0);
136 ::rtl::OUString arg1
;
137 css::uno::Reference
< css::rdf::XURI
> xURI
;
138 if ((aArguments
[1] >>= arg1
)) {
139 if (arg1
.getLength() > 0) {
142 throw css::lang::IllegalArgumentException(
143 ::rtl::OUString::createFromAscii("CLiteral::initialize: "
144 "argument is not valid language"), *this, 1);
146 } else if ((aArguments
[1] >>= xURI
)) {
150 throw css::lang::IllegalArgumentException(
151 ::rtl::OUString::createFromAscii("CLiteral::initialize: "
152 "argument is null"), *this, 1);
155 throw css::lang::IllegalArgumentException(
156 ::rtl::OUString::createFromAscii("CLiteral::initialize: "
157 "argument must be string or URI"), *this, 1);
162 // ::com::sun::star::rdf::XNode:
163 ::rtl::OUString SAL_CALL
CLiteral::getStringValue() throw (css::uno::RuntimeException
)
165 if (!m_Language
.equalsAscii("")) {
166 ::rtl::OUStringBuffer
buf(m_Value
);
167 buf
.appendAscii("@");
168 buf
.append(m_Language
);
169 return buf
.makeStringAndClear();
170 } else if (m_xDatatype
.is()) {
171 ::rtl::OUStringBuffer
buf(m_Value
);
172 buf
.appendAscii("^^");
173 buf
.append(m_xDatatype
->getStringValue());
174 return buf
.makeStringAndClear();
180 // ::com::sun::star::rdf::XLiteral:
181 ::rtl::OUString SAL_CALL
CLiteral::getValue() throw (css::uno::RuntimeException
)
186 ::rtl::OUString SAL_CALL
CLiteral::getLanguage() throw (css::uno::RuntimeException
)
191 css::uno::Reference
< css::rdf::XURI
> SAL_CALL
CLiteral::getDatatype() throw (css::uno::RuntimeException
)
196 } // closing anonymous implementation namespace
200 // component helper namespace
201 namespace comp_CLiteral
{
203 ::rtl::OUString SAL_CALL
_getImplementationName() {
204 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
208 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
_getSupportedServiceNames()
210 css::uno::Sequence
< ::rtl::OUString
> s(1);
211 s
[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
212 "com.sun.star.rdf.Literal"));
216 css::uno::Reference
< css::uno::XInterface
> SAL_CALL
_create(
217 const css::uno::Reference
< css::uno::XComponentContext
> & context
)
218 SAL_THROW((css::uno::Exception
))
220 return static_cast< ::cppu::OWeakObject
* >(new CLiteral(context
));
223 } // closing component helper namespace