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: CURI.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/XURI.hpp>
37 #include <com/sun/star/rdf/URIs.hpp>
39 #include <com/sun/star/lang/IllegalArgumentException.hpp>
42 /// anonymous implementation namespace
45 namespace css
= ::com::sun::star
;
48 public ::cppu::WeakImplHelper3
<
49 css::lang::XServiceInfo
,
50 css::lang::XInitialization
,
54 explicit CURI(css::uno::Reference
< css::uno::XComponentContext
> const & context
);
57 // ::com::sun::star::lang::XServiceInfo:
58 virtual ::rtl::OUString SAL_CALL
getImplementationName() throw (css::uno::RuntimeException
);
59 virtual ::sal_Bool SAL_CALL
supportsService(const ::rtl::OUString
& ServiceName
) throw (css::uno::RuntimeException
);
60 virtual css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames() throw (css::uno::RuntimeException
);
62 // ::com::sun::star::lang::XInitialization:
63 virtual void SAL_CALL
initialize(const css::uno::Sequence
< ::com::sun::star::uno::Any
> & aArguments
) throw (css::uno::RuntimeException
, css::uno::Exception
);
65 // ::com::sun::star::rdf::XNode:
66 virtual ::rtl::OUString SAL_CALL
getStringValue() throw (css::uno::RuntimeException
);
68 // ::com::sun::star::rdf::XURI:
69 virtual ::rtl::OUString SAL_CALL
getLocalName() throw (css::uno::RuntimeException
);
70 virtual ::rtl::OUString SAL_CALL
getNamespace() throw (css::uno::RuntimeException
);
73 CURI(const CURI
&); // not defined
74 CURI
& operator=(const CURI
&); // not defined
76 /// handle css.rdf.URIs
77 void SAL_CALL
initFromConstant(const sal_Int16 i_Constant
);
79 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
81 ::rtl::OUString m_Namespace
;
82 ::rtl::OUString m_LocalName
;
85 CURI::CURI(css::uno::Reference
< css::uno::XComponentContext
> const & context
) :
86 m_xContext(context
), m_Namespace(), m_LocalName()
89 // com.sun.star.uno.XServiceInfo:
90 ::rtl::OUString SAL_CALL
CURI::getImplementationName() throw (css::uno::RuntimeException
)
92 return comp_CURI::_getImplementationName();
95 ::sal_Bool SAL_CALL
CURI::supportsService(::rtl::OUString
const & serviceName
) throw (css::uno::RuntimeException
)
97 css::uno::Sequence
< ::rtl::OUString
> serviceNames
= comp_CURI::_getSupportedServiceNames();
98 for (::sal_Int32 i
= 0; i
< serviceNames
.getLength(); ++i
) {
99 if (serviceNames
[i
] == serviceName
)
105 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
CURI::getSupportedServiceNames() throw (css::uno::RuntimeException
)
107 return comp_CURI::_getSupportedServiceNames();
110 const char s_nsXS
[] = "http://www.w3.org/2001/XMLSchema#";
111 const char s_nsXSD
[] = "http://www.w3.org/2001/XMLSchema-datatypes#";
112 const char s_nsRDF
[] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
113 const char s_nsRDFs
[] = "http://www.w3.org/2000/01/rdf-schema#";
114 const char s_nsOWL
[] = "http://www.w3.org/2002/07/owl#";
115 const char s_nsPkg
[] =
116 "http://docs.oasis-open.org/ns/office/1.2/meta/pkg#";
117 const char s_nsODF
[] =
118 "http://docs.oasis-open.org/ns/office/1.2/meta/odf#";
120 void SAL_CALL
CURI::initFromConstant(const sal_Int16 i_Constant
)
126 case css::rdf::URIs::XSD_NCNAME
:
131 case css::rdf::URIs::XSD_STRING
:
136 case css::rdf::URIs::XSD_NORMALIZEDSTRING
:
138 ln
= "normalizedString";
141 case css::rdf::URIs::XSD_BOOLEAN
:
146 case css::rdf::URIs::XSD_DECIMAL
:
151 case css::rdf::URIs::XSD_FLOAT
:
156 case css::rdf::URIs::XSD_DOUBLE
:
161 case css::rdf::URIs::XSD_INTEGER
:
166 case css::rdf::URIs::XSD_NONNEGATIVEINTEGER
:
168 ln
= "nonNegativeInteger";
171 case css::rdf::URIs::XSD_POSITIVEINTEGER
:
173 ln
= "positiveInteger";
176 case css::rdf::URIs::XSD_NONPOSITIVEINTEGER
:
178 ln
= "nonPositiveInteger";
181 case css::rdf::URIs::XSD_NEGATIVEINTEGER
:
183 ln
= "negativeInteger";
186 case css::rdf::URIs::XSD_LONG
:
191 case css::rdf::URIs::XSD_INT
:
196 case css::rdf::URIs::XSD_SHORT
:
201 case css::rdf::URIs::XSD_BYTE
:
206 case css::rdf::URIs::XSD_UNSIGNEDLONG
:
211 case css::rdf::URIs::XSD_UNSIGNEDINT
:
216 case css::rdf::URIs::XSD_UNSIGNEDSHORT
:
218 ln
= "unsignedShort";
221 case css::rdf::URIs::XSD_UNSIGNEDBYTE
:
226 case css::rdf::URIs::XSD_HEXBINARY
:
231 case css::rdf::URIs::XSD_BASE64BINARY
:
236 case css::rdf::URIs::XSD_DATETIME
:
241 case css::rdf::URIs::XSD_TIME
:
246 case css::rdf::URIs::XSD_DATE
:
251 case css::rdf::URIs::XSD_GYEARMONTH
:
256 case css::rdf::URIs::XSD_GYEAR
:
261 case css::rdf::URIs::XSD_GMONTHDAY
:
266 case css::rdf::URIs::XSD_GDAY
:
271 case css::rdf::URIs::XSD_GMONTH
:
276 case css::rdf::URIs::XSD_ANYURI
:
281 case css::rdf::URIs::XSD_TOKEN
:
286 case css::rdf::URIs::XSD_LANGUAGE
:
291 case css::rdf::URIs::XSD_NMTOKEN
:
296 case css::rdf::URIs::XSD_NAME
:
301 case css::rdf::URIs::XSD_DURATION
:
306 case css::rdf::URIs::XSD_QNAME
:
311 case css::rdf::URIs::XSD_NOTATION
:
316 case css::rdf::URIs::XSD_NMTOKENS
:
321 case css::rdf::URIs::XSD_ID
:
326 case css::rdf::URIs::XSD_IDREF
:
331 case css::rdf::URIs::XSD_IDREFS
:
336 case css::rdf::URIs::XSD_ENTITY
:
341 case css::rdf::URIs::XSD_ENTITIES
:
346 case css::rdf::URIs::RDF_TYPE
:
351 case css::rdf::URIs::RDF_SUBJECT
:
356 case css::rdf::URIs::RDF_PREDICATE
:
361 case css::rdf::URIs::RDF_OBJECT
:
366 case css::rdf::URIs::RDF_PROPERTY
:
371 case css::rdf::URIs::RDF_STATEMENT
:
376 case css::rdf::URIs::RDF_VALUE
:
381 case css::rdf::URIs::RDF_FIRST
:
386 case css::rdf::URIs::RDF_REST
:
391 case css::rdf::URIs::RDF_NIL
:
396 case css::rdf::URIs::RDF_XMLLITERAL
:
401 case css::rdf::URIs::RDF_ALT
:
406 case css::rdf::URIs::RDF_BAG
:
411 case css::rdf::URIs::RDF_LIST
:
416 case css::rdf::URIs::RDF_SEQ
:
421 case css::rdf::URIs::RDF_1
:
426 case css::rdf::URIs::RDFS_COMMENT
:
431 case css::rdf::URIs::RDFS_LABEL
:
436 case css::rdf::URIs::RDFS_DOMAIN
:
441 case css::rdf::URIs::RDFS_RANGE
:
446 case css::rdf::URIs::RDFS_SUBCLASSOF
:
451 case css::rdf::URIs::RDFS_LITERAL
:
456 case css::rdf::URIs::OWL_CLASS
:
461 case css::rdf::URIs::OWL_OBJECTPROPERTY
:
463 ln
= "ObjectProperty";
466 case css::rdf::URIs::OWL_DATATYPEPROPERTY
:
468 ln
= "DatatypeProperty";
471 case css::rdf::URIs::OWL_FUNCTIONALPROPERTY
:
473 ln
= "FunctionalProperty";
476 case css::rdf::URIs::OWL_THING
:
481 case css::rdf::URIs::OWL_NOTHING
:
486 case css::rdf::URIs::OWL_INDIVIDUAL
:
491 case css::rdf::URIs::OWL_EQUIVALENTCLASS
:
493 ln
= "equivalentClass";
496 case css::rdf::URIs::OWL_EQUIVALENTPROPERTY
:
498 ln
= "equivalentProperty";
501 case css::rdf::URIs::OWL_SAMEAS
:
506 case css::rdf::URIs::OWL_DIFFERENTFROM
:
508 ln
= "differentFrom";
511 case css::rdf::URIs::OWL_ALLDIFFERENT
:
516 case css::rdf::URIs::OWL_DISTINCTMEMBERS
:
518 ln
= "distinctMembers";
521 case css::rdf::URIs::OWL_INVERSEOF
:
526 case css::rdf::URIs::OWL_TRANSITIVEPROPERTY
:
528 ln
= "TransitiveProperty";
531 case css::rdf::URIs::OWL_SYMMETRICPROPERTY
:
533 ln
= "SymmetricProperty";
536 case css::rdf::URIs::OWL_INVERSEFUNCTIONALPROPERTY
:
538 ln
= "InverseFunctionalProperty";
541 case css::rdf::URIs::OWL_RESTRICTION
:
546 case css::rdf::URIs::OWL_ONPROPERTY
:
551 case css::rdf::URIs::OWL_ALLVALUESFROM
:
553 ln
= "allValuesFrom";
556 case css::rdf::URIs::OWL_SOMEVALUESFROM
:
558 ln
= "someValuesFrom";
561 case css::rdf::URIs::OWL_MINCARDINALITY
:
563 ln
= "minCardinality";
566 case css::rdf::URIs::OWL_MAXCARDINALITY
:
568 ln
= "maxCardinality";
571 case css::rdf::URIs::OWL_CARDINALITY
:
576 case css::rdf::URIs::OWL_ONTOLOGY
:
581 case css::rdf::URIs::OWL_IMPORTS
:
586 case css::rdf::URIs::OWL_VERSIONINFO
:
591 case css::rdf::URIs::OWL_PRIORVERSION
:
596 case css::rdf::URIs::OWL_BACKWARDCOMPATIBLEWITH
:
598 ln
= "backwardCompatibleWith";
601 case css::rdf::URIs::OWL_INCOMPATIBLEWITH
:
603 ln
= "incompatibleWith";
606 case css::rdf::URIs::OWL_DEPRECATEDCLASS
:
608 ln
= "DeprecatedClass";
611 case css::rdf::URIs::OWL_DEPRECATEDPROPERTY
:
613 ln
= "DeprecatedProperty";
616 case css::rdf::URIs::OWL_ANNOTATIONPROPERTY
:
618 ln
= "AnnotationProperty";
621 case css::rdf::URIs::OWL_ONTOLOGYPROPERTY
:
623 ln
= "OntologyProperty";
626 case css::rdf::URIs::OWL_ONEOF
:
631 case css::rdf::URIs::OWL_DATARANGE
:
636 case css::rdf::URIs::OWL_DISJOINTWITH
:
641 case css::rdf::URIs::OWL_UNIONOF
:
646 case css::rdf::URIs::OWL_COMPLEMENTOF
:
651 case css::rdf::URIs::OWL_INTERSECTIONOF
:
653 ln
= "intersectionOf";
656 case css::rdf::URIs::OWL_HASVALUE
:
662 case css::rdf::URIs::PKG_HASPART
:
668 case css::rdf::URIs::PKG_IDREF:
673 case css::rdf::URIs::PKG_PATH:
679 case css::rdf::URIs::PKG_MIMETYPE
:
684 case css::rdf::URIs::PKG_PACKAGE
:
689 case css::rdf::URIs::PKG_ELEMENT
:
694 case css::rdf::URIs::PKG_FILE
:
699 case css::rdf::URIs::PKG_METADATAFILE
:
704 case css::rdf::URIs::PKG_DOCUMENT
:
709 case css::rdf::URIs::ODF_PREFIX
:
714 case css::rdf::URIs::ODF_SUFFIX
:
719 case css::rdf::URIs::ODF_ELEMENT
:
724 case css::rdf::URIs::ODF_CONTENTFILE
:
729 case css::rdf::URIs::ODF_STYLESFILE
:
735 case css::rdf::URIs::ODF_METADATAFILE:
742 throw css::lang::IllegalArgumentException(
743 ::rtl::OUString::createFromAscii("CURI::initialize: "
744 "invalid URIs constant argument"), *this, 0);
746 m_Namespace
= ::rtl::OUString::createFromAscii(ns
).intern();
747 m_LocalName
= ::rtl::OUString::createFromAscii(ln
).intern();
751 // ::com::sun::star::lang::XInitialization:
752 void SAL_CALL
CURI::initialize(const css::uno::Sequence
< ::com::sun::star::uno::Any
> & aArguments
) throw (css::uno::RuntimeException
, css::uno::Exception
)
754 sal_Int32 len
= aArguments
.getLength();
755 if ((len
< 1) || (len
> 2)) {
756 throw css::lang::IllegalArgumentException(
757 ::rtl::OUString::createFromAscii("CURI::initialize: "
758 "must give 1 or 2 argument(s)"), *this, 2);
762 ::rtl::OUString arg0
;
763 ::rtl::OUString arg1
;
764 if ((aArguments
[0] >>= arg
)) {
765 // integer argument: constant from rdf::URIs
767 throw css::lang::IllegalArgumentException(
768 ::rtl::OUString::createFromAscii("CURI::initialize: "
769 "must give 1 int argument"), *this, 1);
771 initFromConstant(arg
);
774 if (!(aArguments
[0] >>= arg0
)) {
775 throw css::lang::IllegalArgumentException(
776 ::rtl::OUString::createFromAscii("CURI::initialize: "
777 "argument must be string or short"), *this, 0);
780 if (!(aArguments
[1] >>= arg1
)) {
781 throw css::lang::IllegalArgumentException(
782 ::rtl::OUString::createFromAscii("CURI::initialize: "
783 "argument must be string"), *this, 1);
785 // just append the parameters and then split them again; seems simplest
787 arg1
= ::rtl::OUString();
792 if ( ((idx
= arg0
.indexOf ('#')) >= 0)
793 || ((idx
= arg0
.lastIndexOf('/')) >= 0)
794 || ((idx
= arg0
.lastIndexOf(':')) >= 0))
797 if (idx
< arg0
.getLength() - 1) {
798 arg1
= arg0
.copy(idx
+1);
799 arg0
= arg0
.copy(0, idx
+1);
802 throw css::lang::IllegalArgumentException(
803 ::rtl::OUString::createFromAscii("CURI::initialize: "
804 "argument not splittable: no separator [#/:]"), *this, 0);
807 //FIXME: what is legal?
808 if (arg0
.getLength() > 0) {
811 throw css::lang::IllegalArgumentException(
812 ::rtl::OUString::createFromAscii("CURI::initialize: "
813 "argument is not valid namespace"), *this, 0);
815 //FIXME: what is legal?
819 throw css::lang::IllegalArgumentException(
820 ::rtl::OUString::createFromAscii("CURI::initialize: "
821 "argument is not valid local name"), *this, 1);
825 // ::com::sun::star::rdf::XNode:
826 ::rtl::OUString SAL_CALL
CURI::getStringValue() throw (css::uno::RuntimeException
)
828 return m_Namespace
+ m_LocalName
;
831 // ::com::sun::star::rdf::XURI:
832 ::rtl::OUString SAL_CALL
CURI::getNamespace() throw (css::uno::RuntimeException
)
837 ::rtl::OUString SAL_CALL
CURI::getLocalName() throw (css::uno::RuntimeException
)
842 } // closing anonymous implementation namespace
846 // component helper namespace
847 namespace comp_CURI
{
849 ::rtl::OUString SAL_CALL
_getImplementationName() {
850 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
854 css::uno::Sequence
< ::rtl::OUString
> SAL_CALL
_getSupportedServiceNames()
856 css::uno::Sequence
< ::rtl::OUString
> s(1);
857 s
[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
858 "com.sun.star.rdf.URI"));
862 css::uno::Reference
< css::uno::XInterface
> SAL_CALL
_create(
863 const css::uno::Reference
< css::uno::XComponentContext
> & context
)
864 SAL_THROW((css::uno::Exception
))
866 return static_cast< ::cppu::OWeakObject
* >(new CURI(context
));
869 } // closing component helper namespace