1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <cppuhelper/implbase.hxx>
21 #include <cppuhelper/supportsservice.hxx>
22 #include <com/sun/star/lang/XServiceInfo.hpp>
23 #include <com/sun/star/lang/XInitialization.hpp>
24 #include <com/sun/star/rdf/XURI.hpp>
25 #include <com/sun/star/rdf/URIs.hpp>
26 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <com/sun/star/lang/IllegalArgumentException.hpp>
31 /// anonymous implementation namespace
35 public ::cppu::WeakImplHelper
<
36 css::lang::XServiceInfo
,
37 css::lang::XInitialization
,
43 // css::lang::XServiceInfo:
44 virtual OUString SAL_CALL
getImplementationName() override
;
45 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
46 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
48 // css::lang::XInitialization:
49 virtual void SAL_CALL
initialize(const css::uno::Sequence
< css::uno::Any
> & aArguments
) override
;
52 virtual OUString SAL_CALL
getStringValue() override
;
55 virtual OUString SAL_CALL
getLocalName() override
;
56 virtual OUString SAL_CALL
getNamespace() override
;
59 CURI(CURI
const&) = delete;
60 CURI
& operator=(CURI
const&) = delete;
62 /// handle css.rdf.URIs
63 void initFromConstant(const sal_Int16 i_Constant
);
72 // com.sun.star.uno.XServiceInfo:
73 OUString SAL_CALL
CURI::getImplementationName()
78 sal_Bool SAL_CALL
CURI::supportsService(OUString
const & serviceName
)
80 return cppu::supportsService(this, serviceName
);
83 css::uno::Sequence
< OUString
> SAL_CALL
CURI::getSupportedServiceNames()
85 return { u
"com.sun.star.rdf.URI"_ustr
};
88 constexpr OUString s_nsXSD
= u
"http://www.w3.org/2001/XMLSchema-datatypes#"_ustr
;
89 constexpr OUString s_nsRDF
= u
"http://www.w3.org/1999/02/22-rdf-syntax-ns#"_ustr
;
90 constexpr OUString s_nsRDFs
= u
"http://www.w3.org/2000/01/rdf-schema#"_ustr
;
91 constexpr OUString s_nsOWL
= u
"http://www.w3.org/2002/07/owl#"_ustr
;
92 constexpr OUString s_nsPkg
= u
"http://docs.oasis-open.org/ns/office/1.2/meta/pkg#"_ustr
;
93 constexpr OUString s_nsODF
= u
"http://docs.oasis-open.org/ns/office/1.2/meta/odf#"_ustr
;
94 constexpr OUString s_nsLO_EXT
=
95 u
"urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0odf#"_ustr
;
97 void CURI::initFromConstant(const sal_Int16 i_Constant
)
103 case css::rdf::URIs::XSD_NCNAME
:
108 case css::rdf::URIs::XSD_STRING
:
113 case css::rdf::URIs::XSD_NORMALIZEDSTRING
:
115 ln
= u
"normalizedString"_ustr
;
118 case css::rdf::URIs::XSD_BOOLEAN
:
120 ln
= u
"boolean"_ustr
;
123 case css::rdf::URIs::XSD_DECIMAL
:
125 ln
= u
"decimal"_ustr
;
128 case css::rdf::URIs::XSD_FLOAT
:
133 case css::rdf::URIs::XSD_DOUBLE
:
138 case css::rdf::URIs::XSD_INTEGER
:
140 ln
= u
"integer"_ustr
;
143 case css::rdf::URIs::XSD_NONNEGATIVEINTEGER
:
145 ln
= u
"nonNegativeInteger"_ustr
;
148 case css::rdf::URIs::XSD_POSITIVEINTEGER
:
150 ln
= u
"positiveInteger"_ustr
;
153 case css::rdf::URIs::XSD_NONPOSITIVEINTEGER
:
155 ln
= u
"nonPositiveInteger"_ustr
;
158 case css::rdf::URIs::XSD_NEGATIVEINTEGER
:
160 ln
= u
"negativeInteger"_ustr
;
163 case css::rdf::URIs::XSD_LONG
:
168 case css::rdf::URIs::XSD_INT
:
173 case css::rdf::URIs::XSD_SHORT
:
178 case css::rdf::URIs::XSD_BYTE
:
183 case css::rdf::URIs::XSD_UNSIGNEDLONG
:
185 ln
= u
"unsignedLong"_ustr
;
188 case css::rdf::URIs::XSD_UNSIGNEDINT
:
190 ln
= u
"unsignedInt"_ustr
;
193 case css::rdf::URIs::XSD_UNSIGNEDSHORT
:
195 ln
= u
"unsignedShort"_ustr
;
198 case css::rdf::URIs::XSD_UNSIGNEDBYTE
:
200 ln
= u
"unsignedByte"_ustr
;
203 case css::rdf::URIs::XSD_HEXBINARY
:
205 ln
= u
"hexBinary"_ustr
;
208 case css::rdf::URIs::XSD_BASE64BINARY
:
210 ln
= u
"base64Binary"_ustr
;
213 case css::rdf::URIs::XSD_DATETIME
:
215 ln
= u
"dateTime"_ustr
;
218 case css::rdf::URIs::XSD_TIME
:
223 case css::rdf::URIs::XSD_DATE
:
228 case css::rdf::URIs::XSD_GYEARMONTH
:
230 ln
= u
"gYearMonth"_ustr
;
233 case css::rdf::URIs::XSD_GYEAR
:
238 case css::rdf::URIs::XSD_GMONTHDAY
:
240 ln
= u
"gMonthDay"_ustr
;
243 case css::rdf::URIs::XSD_GDAY
:
248 case css::rdf::URIs::XSD_GMONTH
:
253 case css::rdf::URIs::XSD_ANYURI
:
258 case css::rdf::URIs::XSD_TOKEN
:
263 case css::rdf::URIs::XSD_LANGUAGE
:
265 ln
= u
"language"_ustr
;
268 case css::rdf::URIs::XSD_NMTOKEN
:
270 ln
= u
"NMTOKEN"_ustr
;
273 case css::rdf::URIs::XSD_NAME
:
278 case css::rdf::URIs::XSD_DURATION
:
280 ln
= u
"duration"_ustr
;
283 case css::rdf::URIs::XSD_QNAME
:
288 case css::rdf::URIs::XSD_NOTATION
:
290 ln
= u
"NOTATION"_ustr
;
293 case css::rdf::URIs::XSD_NMTOKENS
:
295 ln
= u
"NMTOKENS"_ustr
;
298 case css::rdf::URIs::XSD_ID
:
303 case css::rdf::URIs::XSD_IDREF
:
308 case css::rdf::URIs::XSD_IDREFS
:
313 case css::rdf::URIs::XSD_ENTITY
:
318 case css::rdf::URIs::XSD_ENTITIES
:
320 ln
= u
"ENTITIES"_ustr
;
323 case css::rdf::URIs::RDF_TYPE
:
328 case css::rdf::URIs::RDF_SUBJECT
:
330 ln
= u
"subject"_ustr
;
333 case css::rdf::URIs::RDF_PREDICATE
:
335 ln
= u
"predicate"_ustr
;
338 case css::rdf::URIs::RDF_OBJECT
:
343 case css::rdf::URIs::RDF_PROPERTY
:
345 ln
= u
"Property"_ustr
;
348 case css::rdf::URIs::RDF_STATEMENT
:
350 ln
= u
"Statement"_ustr
;
353 case css::rdf::URIs::RDF_VALUE
:
358 case css::rdf::URIs::RDF_FIRST
:
363 case css::rdf::URIs::RDF_REST
:
368 case css::rdf::URIs::RDF_NIL
:
373 case css::rdf::URIs::RDF_XMLLITERAL
:
375 ln
= u
"XMLLiteral"_ustr
;
378 case css::rdf::URIs::RDF_ALT
:
383 case css::rdf::URIs::RDF_BAG
:
388 case css::rdf::URIs::RDF_LIST
:
393 case css::rdf::URIs::RDF_SEQ
:
398 case css::rdf::URIs::RDF_1
:
403 case css::rdf::URIs::RDFS_COMMENT
:
405 ln
= u
"comment"_ustr
;
408 case css::rdf::URIs::RDFS_LABEL
:
413 case css::rdf::URIs::RDFS_DOMAIN
:
418 case css::rdf::URIs::RDFS_RANGE
:
423 case css::rdf::URIs::RDFS_SUBCLASSOF
:
425 ln
= u
"subClassOf"_ustr
;
428 case css::rdf::URIs::RDFS_LITERAL
:
430 ln
= u
"Literal"_ustr
;
433 case css::rdf::URIs::OWL_CLASS
:
438 case css::rdf::URIs::OWL_OBJECTPROPERTY
:
440 ln
= u
"ObjectProperty"_ustr
;
443 case css::rdf::URIs::OWL_DATATYPEPROPERTY
:
445 ln
= u
"DatatypeProperty"_ustr
;
448 case css::rdf::URIs::OWL_FUNCTIONALPROPERTY
:
450 ln
= u
"FunctionalProperty"_ustr
;
453 case css::rdf::URIs::OWL_THING
:
458 case css::rdf::URIs::OWL_NOTHING
:
460 ln
= u
"Nothing"_ustr
;
463 case css::rdf::URIs::OWL_INDIVIDUAL
:
465 ln
= u
"Individual"_ustr
;
468 case css::rdf::URIs::OWL_EQUIVALENTCLASS
:
470 ln
= u
"equivalentClass"_ustr
;
473 case css::rdf::URIs::OWL_EQUIVALENTPROPERTY
:
475 ln
= u
"equivalentProperty"_ustr
;
478 case css::rdf::URIs::OWL_SAMEAS
:
483 case css::rdf::URIs::OWL_DIFFERENTFROM
:
485 ln
= u
"differentFrom"_ustr
;
488 case css::rdf::URIs::OWL_ALLDIFFERENT
:
490 ln
= u
"AllDifferent"_ustr
;
493 case css::rdf::URIs::OWL_DISTINCTMEMBERS
:
495 ln
= u
"distinctMembers"_ustr
;
498 case css::rdf::URIs::OWL_INVERSEOF
:
500 ln
= u
"inverseOf"_ustr
;
503 case css::rdf::URIs::OWL_TRANSITIVEPROPERTY
:
505 ln
= u
"TransitiveProperty"_ustr
;
508 case css::rdf::URIs::OWL_SYMMETRICPROPERTY
:
510 ln
= u
"SymmetricProperty"_ustr
;
513 case css::rdf::URIs::OWL_INVERSEFUNCTIONALPROPERTY
:
515 ln
= u
"InverseFunctionalProperty"_ustr
;
518 case css::rdf::URIs::OWL_RESTRICTION
:
520 ln
= u
"Restriction"_ustr
;
523 case css::rdf::URIs::OWL_ONPROPERTY
:
525 ln
= u
"onProperty"_ustr
;
528 case css::rdf::URIs::OWL_ALLVALUESFROM
:
530 ln
= u
"allValuesFrom"_ustr
;
533 case css::rdf::URIs::OWL_SOMEVALUESFROM
:
535 ln
= u
"someValuesFrom"_ustr
;
538 case css::rdf::URIs::OWL_MINCARDINALITY
:
540 ln
= u
"minCardinality"_ustr
;
543 case css::rdf::URIs::OWL_MAXCARDINALITY
:
545 ln
= u
"maxCardinality"_ustr
;
548 case css::rdf::URIs::OWL_CARDINALITY
:
550 ln
= u
"cardinality"_ustr
;
553 case css::rdf::URIs::OWL_ONTOLOGY
:
555 ln
= u
"Ontology"_ustr
;
558 case css::rdf::URIs::OWL_IMPORTS
:
560 ln
= u
"imports"_ustr
;
563 case css::rdf::URIs::OWL_VERSIONINFO
:
565 ln
= u
"versionInfo"_ustr
;
568 case css::rdf::URIs::OWL_PRIORVERSION
:
570 ln
= u
"priorVersion"_ustr
;
573 case css::rdf::URIs::OWL_BACKWARDCOMPATIBLEWITH
:
575 ln
= u
"backwardCompatibleWith"_ustr
;
578 case css::rdf::URIs::OWL_INCOMPATIBLEWITH
:
580 ln
= u
"incompatibleWith"_ustr
;
583 case css::rdf::URIs::OWL_DEPRECATEDCLASS
:
585 ln
= u
"DeprecatedClass"_ustr
;
588 case css::rdf::URIs::OWL_DEPRECATEDPROPERTY
:
590 ln
= u
"DeprecatedProperty"_ustr
;
593 case css::rdf::URIs::OWL_ANNOTATIONPROPERTY
:
595 ln
= u
"AnnotationProperty"_ustr
;
598 case css::rdf::URIs::OWL_ONTOLOGYPROPERTY
:
600 ln
= u
"OntologyProperty"_ustr
;
603 case css::rdf::URIs::OWL_ONEOF
:
608 case css::rdf::URIs::OWL_DATARANGE
:
610 ln
= u
"dataRange"_ustr
;
613 case css::rdf::URIs::OWL_DISJOINTWITH
:
615 ln
= u
"disjointWith"_ustr
;
618 case css::rdf::URIs::OWL_UNIONOF
:
620 ln
= u
"unionOf"_ustr
;
623 case css::rdf::URIs::OWL_COMPLEMENTOF
:
625 ln
= u
"complementOf"_ustr
;
628 case css::rdf::URIs::OWL_INTERSECTIONOF
:
630 ln
= u
"intersectionOf"_ustr
;
633 case css::rdf::URIs::OWL_HASVALUE
:
635 ln
= u
"hasValue"_ustr
;
639 case css::rdf::URIs::PKG_HASPART
:
641 ln
= u
"hasPart"_ustr
;
644 case css::rdf::URIs::PKG_MIMETYPE
:
646 ln
= u
"mimeType"_ustr
;
649 case css::rdf::URIs::PKG_PACKAGE
:
651 ln
= u
"Package"_ustr
;
654 case css::rdf::URIs::PKG_ELEMENT
:
656 ln
= u
"Element"_ustr
;
659 case css::rdf::URIs::PKG_FILE
:
664 case css::rdf::URIs::PKG_METADATAFILE
:
666 ln
= u
"MetadataFile"_ustr
;
669 case css::rdf::URIs::PKG_DOCUMENT
:
671 ln
= u
"Document"_ustr
;
674 case css::rdf::URIs::ODF_PREFIX
:
679 case css::rdf::URIs::ODF_SUFFIX
:
684 case css::rdf::URIs::ODF_ELEMENT
:
686 ln
= u
"Element"_ustr
;
689 case css::rdf::URIs::ODF_CONTENTFILE
:
691 ln
= u
"ContentFile"_ustr
;
694 case css::rdf::URIs::ODF_STYLESFILE
:
696 ln
= u
"StylesFile"_ustr
;
699 case css::rdf::URIs::LO_EXT_SHADING
:
701 ln
= u
"shading"_ustr
;
705 throw css::lang::IllegalArgumentException(
706 u
"CURI::initialize: invalid URIs constant argument"_ustr
, *this, 0);
712 // css::lang::XInitialization:
713 void SAL_CALL
CURI::initialize(const css::uno::Sequence
< css::uno::Any
> & aArguments
)
715 sal_Int32 len
= aArguments
.getLength();
716 if ((len
< 1) || (len
> 2)) {
717 throw css::lang::IllegalArgumentException(
718 u
"CURI::initialize: must give 1 or 2 argument(s)"_ustr
, *this, 2);
724 if (aArguments
[0] >>= arg
) {
725 // integer argument: constant from rdf::URIs
727 throw css::lang::IllegalArgumentException(
728 u
"CURI::initialize: must give 1 int argument"_ustr
, *this, 1);
730 initFromConstant(arg
);
733 if (!(aArguments
[0] >>= arg0
)) {
734 throw css::lang::IllegalArgumentException(
735 u
"CURI::initialize: argument must be string or short"_ustr
, *this, 0);
738 if (!(aArguments
[1] >>= arg1
)) {
739 throw css::lang::IllegalArgumentException(
740 u
"CURI::initialize: argument must be string"_ustr
, *this, 1);
742 // just append the parameters and then split them again; seems simplest
748 sal_Int32 idx
= arg0
.indexOf('#');
750 idx
= arg0
.lastIndexOf('/');
752 idx
= arg0
.lastIndexOf(':');
755 throw css::lang::IllegalArgumentException(
756 u
"CURI::initialize: argument not splittable: no separator [#/:]"_ustr
, *this, 0);
758 if (idx
< arg0
.getLength() - 1) {
759 arg1
= arg0
.copy(idx
+1);
760 arg0
= arg0
.copy(0, idx
+1);
763 //FIXME: what is legal?
764 if (arg0
.isEmpty()) {
765 throw css::lang::IllegalArgumentException(
766 u
"CURI::initialize: argument is not valid namespace"_ustr
, *this, 0);
770 //FIXME: what is legal?
772 throw css::lang::IllegalArgumentException(
773 u
"CURI::initialize: argument is not valid local name"_ustr
, *this, 1);
779 OUString SAL_CALL
CURI::getStringValue()
781 return m_Namespace
+ m_LocalName
;
785 OUString SAL_CALL
CURI::getNamespace()
790 OUString SAL_CALL
CURI::getLocalName()
795 } // closing anonymous implementation namespace
798 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
799 unoxml_CURI_get_implementation(
800 css::uno::XComponentContext
* , css::uno::Sequence
<css::uno::Any
> const&)
802 return cppu::acquire(new CURI());
805 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */