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
);
70 m_Namespace(), m_LocalName()
73 // com.sun.star.uno.XServiceInfo:
74 OUString SAL_CALL
CURI::getImplementationName()
79 sal_Bool SAL_CALL
CURI::supportsService(OUString
const & serviceName
)
81 return cppu::supportsService(this, serviceName
);
84 css::uno::Sequence
< OUString
> SAL_CALL
CURI::getSupportedServiceNames()
86 return { "com.sun.star.rdf.URI" };
89 const char s_nsXSD
[] = "http://www.w3.org/2001/XMLSchema-datatypes#";
90 const char s_nsRDF
[] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
91 const char s_nsRDFs
[] = "http://www.w3.org/2000/01/rdf-schema#";
92 const char s_nsOWL
[] = "http://www.w3.org/2002/07/owl#";
93 const char s_nsPkg
[] =
94 "http://docs.oasis-open.org/ns/office/1.2/meta/pkg#";
95 const char s_nsODF
[] =
96 "http://docs.oasis-open.org/ns/office/1.2/meta/odf#";
98 void CURI::initFromConstant(const sal_Int16 i_Constant
)
100 const char *ns(nullptr);
101 const char *ln(nullptr);
104 case css::rdf::URIs::XSD_NCNAME
:
109 case css::rdf::URIs::XSD_STRING
:
114 case css::rdf::URIs::XSD_NORMALIZEDSTRING
:
116 ln
= "normalizedString";
119 case css::rdf::URIs::XSD_BOOLEAN
:
124 case css::rdf::URIs::XSD_DECIMAL
:
129 case css::rdf::URIs::XSD_FLOAT
:
134 case css::rdf::URIs::XSD_DOUBLE
:
139 case css::rdf::URIs::XSD_INTEGER
:
144 case css::rdf::URIs::XSD_NONNEGATIVEINTEGER
:
146 ln
= "nonNegativeInteger";
149 case css::rdf::URIs::XSD_POSITIVEINTEGER
:
151 ln
= "positiveInteger";
154 case css::rdf::URIs::XSD_NONPOSITIVEINTEGER
:
156 ln
= "nonPositiveInteger";
159 case css::rdf::URIs::XSD_NEGATIVEINTEGER
:
161 ln
= "negativeInteger";
164 case css::rdf::URIs::XSD_LONG
:
169 case css::rdf::URIs::XSD_INT
:
174 case css::rdf::URIs::XSD_SHORT
:
179 case css::rdf::URIs::XSD_BYTE
:
184 case css::rdf::URIs::XSD_UNSIGNEDLONG
:
189 case css::rdf::URIs::XSD_UNSIGNEDINT
:
194 case css::rdf::URIs::XSD_UNSIGNEDSHORT
:
196 ln
= "unsignedShort";
199 case css::rdf::URIs::XSD_UNSIGNEDBYTE
:
204 case css::rdf::URIs::XSD_HEXBINARY
:
209 case css::rdf::URIs::XSD_BASE64BINARY
:
214 case css::rdf::URIs::XSD_DATETIME
:
219 case css::rdf::URIs::XSD_TIME
:
224 case css::rdf::URIs::XSD_DATE
:
229 case css::rdf::URIs::XSD_GYEARMONTH
:
234 case css::rdf::URIs::XSD_GYEAR
:
239 case css::rdf::URIs::XSD_GMONTHDAY
:
244 case css::rdf::URIs::XSD_GDAY
:
249 case css::rdf::URIs::XSD_GMONTH
:
254 case css::rdf::URIs::XSD_ANYURI
:
259 case css::rdf::URIs::XSD_TOKEN
:
264 case css::rdf::URIs::XSD_LANGUAGE
:
269 case css::rdf::URIs::XSD_NMTOKEN
:
274 case css::rdf::URIs::XSD_NAME
:
279 case css::rdf::URIs::XSD_DURATION
:
284 case css::rdf::URIs::XSD_QNAME
:
289 case css::rdf::URIs::XSD_NOTATION
:
294 case css::rdf::URIs::XSD_NMTOKENS
:
299 case css::rdf::URIs::XSD_ID
:
304 case css::rdf::URIs::XSD_IDREF
:
309 case css::rdf::URIs::XSD_IDREFS
:
314 case css::rdf::URIs::XSD_ENTITY
:
319 case css::rdf::URIs::XSD_ENTITIES
:
324 case css::rdf::URIs::RDF_TYPE
:
329 case css::rdf::URIs::RDF_SUBJECT
:
334 case css::rdf::URIs::RDF_PREDICATE
:
339 case css::rdf::URIs::RDF_OBJECT
:
344 case css::rdf::URIs::RDF_PROPERTY
:
349 case css::rdf::URIs::RDF_STATEMENT
:
354 case css::rdf::URIs::RDF_VALUE
:
359 case css::rdf::URIs::RDF_FIRST
:
364 case css::rdf::URIs::RDF_REST
:
369 case css::rdf::URIs::RDF_NIL
:
374 case css::rdf::URIs::RDF_XMLLITERAL
:
379 case css::rdf::URIs::RDF_ALT
:
384 case css::rdf::URIs::RDF_BAG
:
389 case css::rdf::URIs::RDF_LIST
:
394 case css::rdf::URIs::RDF_SEQ
:
399 case css::rdf::URIs::RDF_1
:
404 case css::rdf::URIs::RDFS_COMMENT
:
409 case css::rdf::URIs::RDFS_LABEL
:
414 case css::rdf::URIs::RDFS_DOMAIN
:
419 case css::rdf::URIs::RDFS_RANGE
:
424 case css::rdf::URIs::RDFS_SUBCLASSOF
:
429 case css::rdf::URIs::RDFS_LITERAL
:
434 case css::rdf::URIs::OWL_CLASS
:
439 case css::rdf::URIs::OWL_OBJECTPROPERTY
:
441 ln
= "ObjectProperty";
444 case css::rdf::URIs::OWL_DATATYPEPROPERTY
:
446 ln
= "DatatypeProperty";
449 case css::rdf::URIs::OWL_FUNCTIONALPROPERTY
:
451 ln
= "FunctionalProperty";
454 case css::rdf::URIs::OWL_THING
:
459 case css::rdf::URIs::OWL_NOTHING
:
464 case css::rdf::URIs::OWL_INDIVIDUAL
:
469 case css::rdf::URIs::OWL_EQUIVALENTCLASS
:
471 ln
= "equivalentClass";
474 case css::rdf::URIs::OWL_EQUIVALENTPROPERTY
:
476 ln
= "equivalentProperty";
479 case css::rdf::URIs::OWL_SAMEAS
:
484 case css::rdf::URIs::OWL_DIFFERENTFROM
:
486 ln
= "differentFrom";
489 case css::rdf::URIs::OWL_ALLDIFFERENT
:
494 case css::rdf::URIs::OWL_DISTINCTMEMBERS
:
496 ln
= "distinctMembers";
499 case css::rdf::URIs::OWL_INVERSEOF
:
504 case css::rdf::URIs::OWL_TRANSITIVEPROPERTY
:
506 ln
= "TransitiveProperty";
509 case css::rdf::URIs::OWL_SYMMETRICPROPERTY
:
511 ln
= "SymmetricProperty";
514 case css::rdf::URIs::OWL_INVERSEFUNCTIONALPROPERTY
:
516 ln
= "InverseFunctionalProperty";
519 case css::rdf::URIs::OWL_RESTRICTION
:
524 case css::rdf::URIs::OWL_ONPROPERTY
:
529 case css::rdf::URIs::OWL_ALLVALUESFROM
:
531 ln
= "allValuesFrom";
534 case css::rdf::URIs::OWL_SOMEVALUESFROM
:
536 ln
= "someValuesFrom";
539 case css::rdf::URIs::OWL_MINCARDINALITY
:
541 ln
= "minCardinality";
544 case css::rdf::URIs::OWL_MAXCARDINALITY
:
546 ln
= "maxCardinality";
549 case css::rdf::URIs::OWL_CARDINALITY
:
554 case css::rdf::URIs::OWL_ONTOLOGY
:
559 case css::rdf::URIs::OWL_IMPORTS
:
564 case css::rdf::URIs::OWL_VERSIONINFO
:
569 case css::rdf::URIs::OWL_PRIORVERSION
:
574 case css::rdf::URIs::OWL_BACKWARDCOMPATIBLEWITH
:
576 ln
= "backwardCompatibleWith";
579 case css::rdf::URIs::OWL_INCOMPATIBLEWITH
:
581 ln
= "incompatibleWith";
584 case css::rdf::URIs::OWL_DEPRECATEDCLASS
:
586 ln
= "DeprecatedClass";
589 case css::rdf::URIs::OWL_DEPRECATEDPROPERTY
:
591 ln
= "DeprecatedProperty";
594 case css::rdf::URIs::OWL_ANNOTATIONPROPERTY
:
596 ln
= "AnnotationProperty";
599 case css::rdf::URIs::OWL_ONTOLOGYPROPERTY
:
601 ln
= "OntologyProperty";
604 case css::rdf::URIs::OWL_ONEOF
:
609 case css::rdf::URIs::OWL_DATARANGE
:
614 case css::rdf::URIs::OWL_DISJOINTWITH
:
619 case css::rdf::URIs::OWL_UNIONOF
:
624 case css::rdf::URIs::OWL_COMPLEMENTOF
:
629 case css::rdf::URIs::OWL_INTERSECTIONOF
:
631 ln
= "intersectionOf";
634 case css::rdf::URIs::OWL_HASVALUE
:
640 case css::rdf::URIs::PKG_HASPART
:
645 case css::rdf::URIs::PKG_MIMETYPE
:
650 case css::rdf::URIs::PKG_PACKAGE
:
655 case css::rdf::URIs::PKG_ELEMENT
:
660 case css::rdf::URIs::PKG_FILE
:
665 case css::rdf::URIs::PKG_METADATAFILE
:
670 case css::rdf::URIs::PKG_DOCUMENT
:
675 case css::rdf::URIs::ODF_PREFIX
:
680 case css::rdf::URIs::ODF_SUFFIX
:
685 case css::rdf::URIs::ODF_ELEMENT
:
690 case css::rdf::URIs::ODF_CONTENTFILE
:
695 case css::rdf::URIs::ODF_STYLESFILE
:
701 throw css::lang::IllegalArgumentException(
702 "CURI::initialize: invalid URIs constant argument", *this, 0);
704 m_Namespace
= OUString::createFromAscii(ns
).intern();
705 m_LocalName
= OUString::createFromAscii(ln
).intern();
708 // css::lang::XInitialization:
709 void SAL_CALL
CURI::initialize(const css::uno::Sequence
< css::uno::Any
> & aArguments
)
711 sal_Int32 len
= aArguments
.getLength();
712 if ((len
< 1) || (len
> 2)) {
713 throw css::lang::IllegalArgumentException(
714 "CURI::initialize: must give 1 or 2 argument(s)", *this, 2);
720 if (aArguments
[0] >>= arg
) {
721 // integer argument: constant from rdf::URIs
723 throw css::lang::IllegalArgumentException(
724 "CURI::initialize: must give 1 int argument", *this, 1);
726 initFromConstant(arg
);
729 if (!(aArguments
[0] >>= arg0
)) {
730 throw css::lang::IllegalArgumentException(
731 "CURI::initialize: argument must be string or short", *this, 0);
734 if (!(aArguments
[1] >>= arg1
)) {
735 throw css::lang::IllegalArgumentException(
736 "CURI::initialize: argument must be string", *this, 1);
738 // just append the parameters and then split them again; seems simplest
744 sal_Int32 idx
= arg0
.indexOf('#');
746 idx
= arg0
.lastIndexOf('/');
748 idx
= arg0
.lastIndexOf(':');
751 throw css::lang::IllegalArgumentException(
752 "CURI::initialize: argument not splittable: no separator [#/:]", *this, 0);
754 if (idx
< arg0
.getLength() - 1) {
755 arg1
= arg0
.copy(idx
+1);
756 arg0
= arg0
.copy(0, idx
+1);
759 //FIXME: what is legal?
760 if (arg0
.isEmpty()) {
761 throw css::lang::IllegalArgumentException(
762 "CURI::initialize: argument is not valid namespace", *this, 0);
766 //FIXME: what is legal?
768 throw css::lang::IllegalArgumentException(
769 "CURI::initialize: argument is not valid local name", *this, 1);
775 OUString SAL_CALL
CURI::getStringValue()
777 return m_Namespace
+ m_LocalName
;
781 OUString SAL_CALL
CURI::getNamespace()
786 OUString SAL_CALL
CURI::getLocalName()
791 } // closing anonymous implementation namespace
794 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
795 unoxml_CURI_get_implementation(
796 css::uno::XComponentContext
* , css::uno::Sequence
<css::uno::Any
> const&)
798 return cppu::acquire(new CURI());
801 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */