1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
31 #include <cppuhelper/implbase3.hxx>
32 #include <com/sun/star/lang/XServiceInfo.hpp>
33 #include <com/sun/star/lang/XInitialization.hpp>
34 #include <com/sun/star/rdf/XLiteral.hpp>
36 #include <com/sun/star/lang/IllegalArgumentException.hpp>
38 #include <rtl/ustrbuf.hxx>
41 /// anonymous implementation namespace
44 namespace css
= ::com::sun::star
;
47 public ::cppu::WeakImplHelper3
<
48 css::lang::XServiceInfo
,
49 css::lang::XInitialization
,
53 explicit CLiteral(css::uno::Reference
< css::uno::XComponentContext
> const & context
);
54 virtual ~CLiteral() {}
56 // ::com::sun::star::lang::XServiceInfo:
57 virtual ::rtl::OUString SAL_CALL
getImplementationName() throw (css::uno::RuntimeException
);
58 virtual ::sal_Bool SAL_CALL
supportsService(const ::rtl::OUString
& ServiceName
) throw (css::uno::RuntimeException
);
59 virtual css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames() throw (css::uno::RuntimeException
);
61 // ::com::sun::star::lang::XInitialization:
62 virtual void SAL_CALL
initialize(const css::uno::Sequence
< ::com::sun::star::uno::Any
> & aArguments
) throw (css::uno::RuntimeException
, css::uno::Exception
);
64 // ::com::sun::star::rdf::XNode:
65 virtual ::rtl::OUString SAL_CALL
getStringValue() throw (css::uno::RuntimeException
);
67 // ::com::sun::star::rdf::XLiteral:
68 virtual ::rtl::OUString SAL_CALL
getValue() throw (css::uno::RuntimeException
);
69 virtual ::rtl::OUString SAL_CALL
getLanguage() throw (css::uno::RuntimeException
);
70 virtual css::uno::Reference
< css::rdf::XURI
> SAL_CALL
getDatatype() throw (css::uno::RuntimeException
);
73 CLiteral(const CLiteral
&); // not defined
74 CLiteral
& operator=(const CLiteral
&); // not defined
76 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
78 ::rtl::OUString m_Value
;
79 ::rtl::OUString m_Language
;
80 css::uno::Reference
< css::rdf::XURI
> m_xDatatype
;
83 CLiteral::CLiteral(css::uno::Reference
< css::uno::XComponentContext
> const & context
) :
84 m_xContext(context
), m_Value(), m_Language(), m_xDatatype()
87 // com.sun.star.uno.XServiceInfo:
88 ::rtl::OUString SAL_CALL
CLiteral::getImplementationName() throw (css::uno::RuntimeException
)
90 return comp_CLiteral::_getImplementationName();
93 ::sal_Bool SAL_CALL
CLiteral::supportsService(::rtl::OUString
const & serviceName
) throw (css::uno::RuntimeException
)
95 css::uno::Sequence
< ::rtl::OUString
> serviceNames
= comp_CLiteral::_getSupportedServiceNames();
96 for (::sal_Int32 i
= 0; i
< serviceNames
.getLength(); ++i
) {
97 if (serviceNames
[i
] == serviceName
)
103 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
CLiteral::getSupportedServiceNames() throw (css::uno::RuntimeException
)
105 return comp_CLiteral::_getSupportedServiceNames();
108 // ::com::sun::star::lang::XInitialization:
109 void SAL_CALL
CLiteral::initialize(const css::uno::Sequence
< ::com::sun::star::uno::Any
> & aArguments
) throw (css::uno::RuntimeException
, css::uno::Exception
)
111 const sal_Int32
len( aArguments
.getLength() );
112 if (len
< 1 || len
> 2) {
113 throw css::lang::IllegalArgumentException(
114 ::rtl::OUString("CLiteral::initialize: "
115 "must give 1 or 2 argument(s)"), *this, 2);
118 ::rtl::OUString arg0
;
119 if (!(aArguments
[0] >>= arg0
)) {
120 throw css::lang::IllegalArgumentException(
121 ::rtl::OUString("CLiteral::initialize: "
122 "argument must be string"), *this, 0);
124 //FIXME: what is legal?
128 throw css::lang::IllegalArgumentException(
129 ::rtl::OUString("CLiteral::initialize: "
130 "argument is not valid literal value"), *this, 0);
134 ::rtl::OUString arg1
;
135 css::uno::Reference
< css::rdf::XURI
> xURI
;
136 if ((aArguments
[1] >>= arg1
)) {
137 if (!arg1
.isEmpty()) {
140 throw css::lang::IllegalArgumentException(
141 ::rtl::OUString("CLiteral::initialize: "
142 "argument is not valid language"), *this, 1);
144 } else if ((aArguments
[1] >>= xURI
)) {
148 throw css::lang::IllegalArgumentException(
149 ::rtl::OUString("CLiteral::initialize: "
150 "argument is null"), *this, 1);
153 throw css::lang::IllegalArgumentException(
154 ::rtl::OUString("CLiteral::initialize: "
155 "argument must be string or URI"), *this, 1);
160 // ::com::sun::star::rdf::XNode:
161 ::rtl::OUString SAL_CALL
CLiteral::getStringValue() throw (css::uno::RuntimeException
)
163 if (!m_Language
.isEmpty()) {
164 ::rtl::OUStringBuffer
buf(m_Value
);
165 buf
.appendAscii("@");
166 buf
.append(m_Language
);
167 return buf
.makeStringAndClear();
168 } else if (m_xDatatype
.is()) {
169 ::rtl::OUStringBuffer
buf(m_Value
);
170 buf
.appendAscii("^^");
171 buf
.append(m_xDatatype
->getStringValue());
172 return buf
.makeStringAndClear();
178 // ::com::sun::star::rdf::XLiteral:
179 ::rtl::OUString SAL_CALL
CLiteral::getValue() throw (css::uno::RuntimeException
)
184 ::rtl::OUString SAL_CALL
CLiteral::getLanguage() throw (css::uno::RuntimeException
)
189 css::uno::Reference
< css::rdf::XURI
> SAL_CALL
CLiteral::getDatatype() throw (css::uno::RuntimeException
)
194 } // closing anonymous implementation namespace
198 // component helper namespace
199 namespace comp_CLiteral
{
201 ::rtl::OUString SAL_CALL
_getImplementationName() {
202 return ::rtl::OUString( "CLiteral");
205 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
_getSupportedServiceNames()
207 css::uno::Sequence
< ::rtl::OUString
> s(1);
208 s
[0] = ::rtl::OUString( "com.sun.star.rdf.Literal");
212 css::uno::Reference
< css::uno::XInterface
> SAL_CALL
_create(
213 const css::uno::Reference
< css::uno::XComponentContext
> & context
)
214 SAL_THROW((css::uno::Exception
))
216 return static_cast< ::cppu::OWeakObject
* >(new CLiteral(context
));
219 } // closing component helper namespace
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */