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/XURI.hpp>
34 #include <com/sun/star/rdf/URIs.hpp>
36 #include <com/sun/star/lang/IllegalArgumentException.hpp>
39 /// anonymous implementation namespace
42 namespace css
= ::com::sun::star
;
45 public ::cppu::WeakImplHelper3
<
46 css::lang::XServiceInfo
,
47 css::lang::XInitialization
,
51 explicit CURI(css::uno::Reference
< css::uno::XComponentContext
> const & context
);
54 // ::com::sun::star::lang::XServiceInfo:
55 virtual ::rtl::OUString SAL_CALL
getImplementationName() throw (css::uno::RuntimeException
);
56 virtual ::sal_Bool SAL_CALL
supportsService(const ::rtl::OUString
& ServiceName
) throw (css::uno::RuntimeException
);
57 virtual css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames() throw (css::uno::RuntimeException
);
59 // ::com::sun::star::lang::XInitialization:
60 virtual void SAL_CALL
initialize(const css::uno::Sequence
< ::com::sun::star::uno::Any
> & aArguments
) throw (css::uno::RuntimeException
, css::uno::Exception
);
62 // ::com::sun::star::rdf::XNode:
63 virtual ::rtl::OUString SAL_CALL
getStringValue() throw (css::uno::RuntimeException
);
65 // ::com::sun::star::rdf::XURI:
66 virtual ::rtl::OUString SAL_CALL
getLocalName() throw (css::uno::RuntimeException
);
67 virtual ::rtl::OUString SAL_CALL
getNamespace() throw (css::uno::RuntimeException
);
70 CURI(const CURI
&); // not defined
71 CURI
& operator=(const CURI
&); // not defined
73 /// handle css.rdf.URIs
74 void SAL_CALL
initFromConstant(const sal_Int16 i_Constant
);
76 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
78 ::rtl::OUString m_Namespace
;
79 ::rtl::OUString m_LocalName
;
82 CURI::CURI(css::uno::Reference
< css::uno::XComponentContext
> const & context
) :
83 m_xContext(context
), m_Namespace(), m_LocalName()
86 // com.sun.star.uno.XServiceInfo:
87 ::rtl::OUString SAL_CALL
CURI::getImplementationName() throw (css::uno::RuntimeException
)
89 return comp_CURI::_getImplementationName();
92 ::sal_Bool SAL_CALL
CURI::supportsService(::rtl::OUString
const & serviceName
) throw (css::uno::RuntimeException
)
94 css::uno::Sequence
< ::rtl::OUString
> serviceNames
= comp_CURI::_getSupportedServiceNames();
95 for (::sal_Int32 i
= 0; i
< serviceNames
.getLength(); ++i
) {
96 if (serviceNames
[i
] == serviceName
)
102 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
CURI::getSupportedServiceNames() throw (css::uno::RuntimeException
)
104 return comp_CURI::_getSupportedServiceNames();
107 const char s_nsXS
[] = "http://www.w3.org/2001/XMLSchema#";
108 const char s_nsXSD
[] = "http://www.w3.org/2001/XMLSchema-datatypes#";
109 const char s_nsRDF
[] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
110 const char s_nsRDFs
[] = "http://www.w3.org/2000/01/rdf-schema#";
111 const char s_nsOWL
[] = "http://www.w3.org/2002/07/owl#";
112 const char s_nsPkg
[] =
113 "http://docs.oasis-open.org/ns/office/1.2/meta/pkg#";
114 const char s_nsODF
[] =
115 "http://docs.oasis-open.org/ns/office/1.2/meta/odf#";
117 void SAL_CALL
CURI::initFromConstant(const sal_Int16 i_Constant
)
123 case css::rdf::URIs::XSD_NCNAME
:
128 case css::rdf::URIs::XSD_STRING
:
133 case css::rdf::URIs::XSD_NORMALIZEDSTRING
:
135 ln
= "normalizedString";
138 case css::rdf::URIs::XSD_BOOLEAN
:
143 case css::rdf::URIs::XSD_DECIMAL
:
148 case css::rdf::URIs::XSD_FLOAT
:
153 case css::rdf::URIs::XSD_DOUBLE
:
158 case css::rdf::URIs::XSD_INTEGER
:
163 case css::rdf::URIs::XSD_NONNEGATIVEINTEGER
:
165 ln
= "nonNegativeInteger";
168 case css::rdf::URIs::XSD_POSITIVEINTEGER
:
170 ln
= "positiveInteger";
173 case css::rdf::URIs::XSD_NONPOSITIVEINTEGER
:
175 ln
= "nonPositiveInteger";
178 case css::rdf::URIs::XSD_NEGATIVEINTEGER
:
180 ln
= "negativeInteger";
183 case css::rdf::URIs::XSD_LONG
:
188 case css::rdf::URIs::XSD_INT
:
193 case css::rdf::URIs::XSD_SHORT
:
198 case css::rdf::URIs::XSD_BYTE
:
203 case css::rdf::URIs::XSD_UNSIGNEDLONG
:
208 case css::rdf::URIs::XSD_UNSIGNEDINT
:
213 case css::rdf::URIs::XSD_UNSIGNEDSHORT
:
215 ln
= "unsignedShort";
218 case css::rdf::URIs::XSD_UNSIGNEDBYTE
:
223 case css::rdf::URIs::XSD_HEXBINARY
:
228 case css::rdf::URIs::XSD_BASE64BINARY
:
233 case css::rdf::URIs::XSD_DATETIME
:
238 case css::rdf::URIs::XSD_TIME
:
243 case css::rdf::URIs::XSD_DATE
:
248 case css::rdf::URIs::XSD_GYEARMONTH
:
253 case css::rdf::URIs::XSD_GYEAR
:
258 case css::rdf::URIs::XSD_GMONTHDAY
:
263 case css::rdf::URIs::XSD_GDAY
:
268 case css::rdf::URIs::XSD_GMONTH
:
273 case css::rdf::URIs::XSD_ANYURI
:
278 case css::rdf::URIs::XSD_TOKEN
:
283 case css::rdf::URIs::XSD_LANGUAGE
:
288 case css::rdf::URIs::XSD_NMTOKEN
:
293 case css::rdf::URIs::XSD_NAME
:
298 case css::rdf::URIs::XSD_DURATION
:
303 case css::rdf::URIs::XSD_QNAME
:
308 case css::rdf::URIs::XSD_NOTATION
:
313 case css::rdf::URIs::XSD_NMTOKENS
:
318 case css::rdf::URIs::XSD_ID
:
323 case css::rdf::URIs::XSD_IDREF
:
328 case css::rdf::URIs::XSD_IDREFS
:
333 case css::rdf::URIs::XSD_ENTITY
:
338 case css::rdf::URIs::XSD_ENTITIES
:
343 case css::rdf::URIs::RDF_TYPE
:
348 case css::rdf::URIs::RDF_SUBJECT
:
353 case css::rdf::URIs::RDF_PREDICATE
:
358 case css::rdf::URIs::RDF_OBJECT
:
363 case css::rdf::URIs::RDF_PROPERTY
:
368 case css::rdf::URIs::RDF_STATEMENT
:
373 case css::rdf::URIs::RDF_VALUE
:
378 case css::rdf::URIs::RDF_FIRST
:
383 case css::rdf::URIs::RDF_REST
:
388 case css::rdf::URIs::RDF_NIL
:
393 case css::rdf::URIs::RDF_XMLLITERAL
:
398 case css::rdf::URIs::RDF_ALT
:
403 case css::rdf::URIs::RDF_BAG
:
408 case css::rdf::URIs::RDF_LIST
:
413 case css::rdf::URIs::RDF_SEQ
:
418 case css::rdf::URIs::RDF_1
:
423 case css::rdf::URIs::RDFS_COMMENT
:
428 case css::rdf::URIs::RDFS_LABEL
:
433 case css::rdf::URIs::RDFS_DOMAIN
:
438 case css::rdf::URIs::RDFS_RANGE
:
443 case css::rdf::URIs::RDFS_SUBCLASSOF
:
448 case css::rdf::URIs::RDFS_LITERAL
:
453 case css::rdf::URIs::OWL_CLASS
:
458 case css::rdf::URIs::OWL_OBJECTPROPERTY
:
460 ln
= "ObjectProperty";
463 case css::rdf::URIs::OWL_DATATYPEPROPERTY
:
465 ln
= "DatatypeProperty";
468 case css::rdf::URIs::OWL_FUNCTIONALPROPERTY
:
470 ln
= "FunctionalProperty";
473 case css::rdf::URIs::OWL_THING
:
478 case css::rdf::URIs::OWL_NOTHING
:
483 case css::rdf::URIs::OWL_INDIVIDUAL
:
488 case css::rdf::URIs::OWL_EQUIVALENTCLASS
:
490 ln
= "equivalentClass";
493 case css::rdf::URIs::OWL_EQUIVALENTPROPERTY
:
495 ln
= "equivalentProperty";
498 case css::rdf::URIs::OWL_SAMEAS
:
503 case css::rdf::URIs::OWL_DIFFERENTFROM
:
505 ln
= "differentFrom";
508 case css::rdf::URIs::OWL_ALLDIFFERENT
:
513 case css::rdf::URIs::OWL_DISTINCTMEMBERS
:
515 ln
= "distinctMembers";
518 case css::rdf::URIs::OWL_INVERSEOF
:
523 case css::rdf::URIs::OWL_TRANSITIVEPROPERTY
:
525 ln
= "TransitiveProperty";
528 case css::rdf::URIs::OWL_SYMMETRICPROPERTY
:
530 ln
= "SymmetricProperty";
533 case css::rdf::URIs::OWL_INVERSEFUNCTIONALPROPERTY
:
535 ln
= "InverseFunctionalProperty";
538 case css::rdf::URIs::OWL_RESTRICTION
:
543 case css::rdf::URIs::OWL_ONPROPERTY
:
548 case css::rdf::URIs::OWL_ALLVALUESFROM
:
550 ln
= "allValuesFrom";
553 case css::rdf::URIs::OWL_SOMEVALUESFROM
:
555 ln
= "someValuesFrom";
558 case css::rdf::URIs::OWL_MINCARDINALITY
:
560 ln
= "minCardinality";
563 case css::rdf::URIs::OWL_MAXCARDINALITY
:
565 ln
= "maxCardinality";
568 case css::rdf::URIs::OWL_CARDINALITY
:
573 case css::rdf::URIs::OWL_ONTOLOGY
:
578 case css::rdf::URIs::OWL_IMPORTS
:
583 case css::rdf::URIs::OWL_VERSIONINFO
:
588 case css::rdf::URIs::OWL_PRIORVERSION
:
593 case css::rdf::URIs::OWL_BACKWARDCOMPATIBLEWITH
:
595 ln
= "backwardCompatibleWith";
598 case css::rdf::URIs::OWL_INCOMPATIBLEWITH
:
600 ln
= "incompatibleWith";
603 case css::rdf::URIs::OWL_DEPRECATEDCLASS
:
605 ln
= "DeprecatedClass";
608 case css::rdf::URIs::OWL_DEPRECATEDPROPERTY
:
610 ln
= "DeprecatedProperty";
613 case css::rdf::URIs::OWL_ANNOTATIONPROPERTY
:
615 ln
= "AnnotationProperty";
618 case css::rdf::URIs::OWL_ONTOLOGYPROPERTY
:
620 ln
= "OntologyProperty";
623 case css::rdf::URIs::OWL_ONEOF
:
628 case css::rdf::URIs::OWL_DATARANGE
:
633 case css::rdf::URIs::OWL_DISJOINTWITH
:
638 case css::rdf::URIs::OWL_UNIONOF
:
643 case css::rdf::URIs::OWL_COMPLEMENTOF
:
648 case css::rdf::URIs::OWL_INTERSECTIONOF
:
650 ln
= "intersectionOf";
653 case css::rdf::URIs::OWL_HASVALUE
:
659 case css::rdf::URIs::PKG_HASPART
:
665 case css::rdf::URIs::PKG_IDREF:
670 case css::rdf::URIs::PKG_PATH:
676 case css::rdf::URIs::PKG_MIMETYPE
:
681 case css::rdf::URIs::PKG_PACKAGE
:
686 case css::rdf::URIs::PKG_ELEMENT
:
691 case css::rdf::URIs::PKG_FILE
:
696 case css::rdf::URIs::PKG_METADATAFILE
:
701 case css::rdf::URIs::PKG_DOCUMENT
:
706 case css::rdf::URIs::ODF_PREFIX
:
711 case css::rdf::URIs::ODF_SUFFIX
:
716 case css::rdf::URIs::ODF_ELEMENT
:
721 case css::rdf::URIs::ODF_CONTENTFILE
:
726 case css::rdf::URIs::ODF_STYLESFILE
:
732 case css::rdf::URIs::ODF_METADATAFILE:
739 throw css::lang::IllegalArgumentException(
740 ::rtl::OUString::createFromAscii("CURI::initialize: "
741 "invalid URIs constant argument"), *this, 0);
743 m_Namespace
= ::rtl::OUString::createFromAscii(ns
).intern();
744 m_LocalName
= ::rtl::OUString::createFromAscii(ln
).intern();
748 // ::com::sun::star::lang::XInitialization:
749 void SAL_CALL
CURI::initialize(const css::uno::Sequence
< ::com::sun::star::uno::Any
> & aArguments
) throw (css::uno::RuntimeException
, css::uno::Exception
)
751 sal_Int32 len
= aArguments
.getLength();
752 if ((len
< 1) || (len
> 2)) {
753 throw css::lang::IllegalArgumentException(
754 ::rtl::OUString::createFromAscii("CURI::initialize: "
755 "must give 1 or 2 argument(s)"), *this, 2);
759 ::rtl::OUString arg0
;
760 ::rtl::OUString arg1
;
761 if ((aArguments
[0] >>= arg
)) {
762 // integer argument: constant from rdf::URIs
764 throw css::lang::IllegalArgumentException(
765 ::rtl::OUString::createFromAscii("CURI::initialize: "
766 "must give 1 int argument"), *this, 1);
768 initFromConstant(arg
);
771 if (!(aArguments
[0] >>= arg0
)) {
772 throw css::lang::IllegalArgumentException(
773 ::rtl::OUString::createFromAscii("CURI::initialize: "
774 "argument must be string or short"), *this, 0);
777 if (!(aArguments
[1] >>= arg1
)) {
778 throw css::lang::IllegalArgumentException(
779 ::rtl::OUString::createFromAscii("CURI::initialize: "
780 "argument must be string"), *this, 1);
782 // just append the parameters and then split them again; seems simplest
784 arg1
= ::rtl::OUString();
789 if ( ((idx
= arg0
.indexOf ('#')) >= 0)
790 || ((idx
= arg0
.lastIndexOf('/')) >= 0)
791 || ((idx
= arg0
.lastIndexOf(':')) >= 0))
794 if (idx
< arg0
.getLength() - 1) {
795 arg1
= arg0
.copy(idx
+1);
796 arg0
= arg0
.copy(0, idx
+1);
799 throw css::lang::IllegalArgumentException(
800 ::rtl::OUString::createFromAscii("CURI::initialize: "
801 "argument not splittable: no separator [#/:]"), *this, 0);
804 //FIXME: what is legal?
805 if (arg0
.getLength() > 0) {
808 throw css::lang::IllegalArgumentException(
809 ::rtl::OUString::createFromAscii("CURI::initialize: "
810 "argument is not valid namespace"), *this, 0);
812 //FIXME: what is legal?
816 throw css::lang::IllegalArgumentException(
817 ::rtl::OUString::createFromAscii("CURI::initialize: "
818 "argument is not valid local name"), *this, 1);
822 // ::com::sun::star::rdf::XNode:
823 ::rtl::OUString SAL_CALL
CURI::getStringValue() throw (css::uno::RuntimeException
)
825 return m_Namespace
+ m_LocalName
;
828 // ::com::sun::star::rdf::XURI:
829 ::rtl::OUString SAL_CALL
CURI::getNamespace() throw (css::uno::RuntimeException
)
834 ::rtl::OUString SAL_CALL
CURI::getLocalName() throw (css::uno::RuntimeException
)
839 } // closing anonymous implementation namespace
843 // component helper namespace
844 namespace comp_CURI
{
846 ::rtl::OUString SAL_CALL
_getImplementationName() {
847 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
851 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
_getSupportedServiceNames()
853 css::uno::Sequence
< ::rtl::OUString
> s(1);
854 s
[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
855 "com.sun.star.rdf.URI"));
859 css::uno::Reference
< css::uno::XInterface
> SAL_CALL
_create(
860 const css::uno::Reference
< css::uno::XComponentContext
> & context
)
861 SAL_THROW((css::uno::Exception
))
863 return static_cast< ::cppu::OWeakObject
* >(new CURI(context
));
866 } // closing component helper namespace