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 .
22 #include <cppuhelper/implbase.hxx>
23 #include <cppuhelper/supportsservice.hxx>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/lang/XInitialization.hpp>
26 #include <com/sun/star/rdf/XURI.hpp>
27 #include <com/sun/star/rdf/URIs.hpp>
29 #include <com/sun/star/lang/IllegalArgumentException.hpp>
32 /// anonymous implementation namespace
36 public ::cppu::WeakImplHelper
<
37 css::lang::XServiceInfo
,
38 css::lang::XInitialization
,
44 // css::lang::XServiceInfo:
45 virtual OUString SAL_CALL
getImplementationName() override
;
46 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) override
;
47 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
49 // css::lang::XInitialization:
50 virtual void SAL_CALL
initialize(const css::uno::Sequence
< css::uno::Any
> & aArguments
) override
;
53 virtual OUString SAL_CALL
getStringValue() override
;
56 virtual OUString SAL_CALL
getLocalName() override
;
57 virtual OUString SAL_CALL
getNamespace() override
;
60 CURI(CURI
const&) = delete;
61 CURI
& operator=(CURI
const&) = delete;
63 /// handle css.rdf.URIs
64 void initFromConstant(const sal_Int16 i_Constant
);
71 m_Namespace(), m_LocalName()
74 // com.sun.star.uno.XServiceInfo:
75 OUString SAL_CALL
CURI::getImplementationName()
77 return comp_CURI::_getImplementationName();
80 sal_Bool SAL_CALL
CURI::supportsService(OUString
const & serviceName
)
82 return cppu::supportsService(this, serviceName
);
85 css::uno::Sequence
< OUString
> SAL_CALL
CURI::getSupportedServiceNames()
87 return comp_CURI::_getSupportedServiceNames();
90 const char s_nsXSD
[] = "http://www.w3.org/2001/XMLSchema-datatypes#";
91 const char s_nsRDF
[] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
92 const char s_nsRDFs
[] = "http://www.w3.org/2000/01/rdf-schema#";
93 const char s_nsOWL
[] = "http://www.w3.org/2002/07/owl#";
94 const char s_nsPkg
[] =
95 "http://docs.oasis-open.org/ns/office/1.2/meta/pkg#";
96 const char s_nsODF
[] =
97 "http://docs.oasis-open.org/ns/office/1.2/meta/odf#";
99 void CURI::initFromConstant(const sal_Int16 i_Constant
)
101 const char *ns(nullptr);
102 const char *ln(nullptr);
105 case css::rdf::URIs::XSD_NCNAME
:
110 case css::rdf::URIs::XSD_STRING
:
115 case css::rdf::URIs::XSD_NORMALIZEDSTRING
:
117 ln
= "normalizedString";
120 case css::rdf::URIs::XSD_BOOLEAN
:
125 case css::rdf::URIs::XSD_DECIMAL
:
130 case css::rdf::URIs::XSD_FLOAT
:
135 case css::rdf::URIs::XSD_DOUBLE
:
140 case css::rdf::URIs::XSD_INTEGER
:
145 case css::rdf::URIs::XSD_NONNEGATIVEINTEGER
:
147 ln
= "nonNegativeInteger";
150 case css::rdf::URIs::XSD_POSITIVEINTEGER
:
152 ln
= "positiveInteger";
155 case css::rdf::URIs::XSD_NONPOSITIVEINTEGER
:
157 ln
= "nonPositiveInteger";
160 case css::rdf::URIs::XSD_NEGATIVEINTEGER
:
162 ln
= "negativeInteger";
165 case css::rdf::URIs::XSD_LONG
:
170 case css::rdf::URIs::XSD_INT
:
175 case css::rdf::URIs::XSD_SHORT
:
180 case css::rdf::URIs::XSD_BYTE
:
185 case css::rdf::URIs::XSD_UNSIGNEDLONG
:
190 case css::rdf::URIs::XSD_UNSIGNEDINT
:
195 case css::rdf::URIs::XSD_UNSIGNEDSHORT
:
197 ln
= "unsignedShort";
200 case css::rdf::URIs::XSD_UNSIGNEDBYTE
:
205 case css::rdf::URIs::XSD_HEXBINARY
:
210 case css::rdf::URIs::XSD_BASE64BINARY
:
215 case css::rdf::URIs::XSD_DATETIME
:
220 case css::rdf::URIs::XSD_TIME
:
225 case css::rdf::URIs::XSD_DATE
:
230 case css::rdf::URIs::XSD_GYEARMONTH
:
235 case css::rdf::URIs::XSD_GYEAR
:
240 case css::rdf::URIs::XSD_GMONTHDAY
:
245 case css::rdf::URIs::XSD_GDAY
:
250 case css::rdf::URIs::XSD_GMONTH
:
255 case css::rdf::URIs::XSD_ANYURI
:
260 case css::rdf::URIs::XSD_TOKEN
:
265 case css::rdf::URIs::XSD_LANGUAGE
:
270 case css::rdf::URIs::XSD_NMTOKEN
:
275 case css::rdf::URIs::XSD_NAME
:
280 case css::rdf::URIs::XSD_DURATION
:
285 case css::rdf::URIs::XSD_QNAME
:
290 case css::rdf::URIs::XSD_NOTATION
:
295 case css::rdf::URIs::XSD_NMTOKENS
:
300 case css::rdf::URIs::XSD_ID
:
305 case css::rdf::URIs::XSD_IDREF
:
310 case css::rdf::URIs::XSD_IDREFS
:
315 case css::rdf::URIs::XSD_ENTITY
:
320 case css::rdf::URIs::XSD_ENTITIES
:
325 case css::rdf::URIs::RDF_TYPE
:
330 case css::rdf::URIs::RDF_SUBJECT
:
335 case css::rdf::URIs::RDF_PREDICATE
:
340 case css::rdf::URIs::RDF_OBJECT
:
345 case css::rdf::URIs::RDF_PROPERTY
:
350 case css::rdf::URIs::RDF_STATEMENT
:
355 case css::rdf::URIs::RDF_VALUE
:
360 case css::rdf::URIs::RDF_FIRST
:
365 case css::rdf::URIs::RDF_REST
:
370 case css::rdf::URIs::RDF_NIL
:
375 case css::rdf::URIs::RDF_XMLLITERAL
:
380 case css::rdf::URIs::RDF_ALT
:
385 case css::rdf::URIs::RDF_BAG
:
390 case css::rdf::URIs::RDF_LIST
:
395 case css::rdf::URIs::RDF_SEQ
:
400 case css::rdf::URIs::RDF_1
:
405 case css::rdf::URIs::RDFS_COMMENT
:
410 case css::rdf::URIs::RDFS_LABEL
:
415 case css::rdf::URIs::RDFS_DOMAIN
:
420 case css::rdf::URIs::RDFS_RANGE
:
425 case css::rdf::URIs::RDFS_SUBCLASSOF
:
430 case css::rdf::URIs::RDFS_LITERAL
:
435 case css::rdf::URIs::OWL_CLASS
:
440 case css::rdf::URIs::OWL_OBJECTPROPERTY
:
442 ln
= "ObjectProperty";
445 case css::rdf::URIs::OWL_DATATYPEPROPERTY
:
447 ln
= "DatatypeProperty";
450 case css::rdf::URIs::OWL_FUNCTIONALPROPERTY
:
452 ln
= "FunctionalProperty";
455 case css::rdf::URIs::OWL_THING
:
460 case css::rdf::URIs::OWL_NOTHING
:
465 case css::rdf::URIs::OWL_INDIVIDUAL
:
470 case css::rdf::URIs::OWL_EQUIVALENTCLASS
:
472 ln
= "equivalentClass";
475 case css::rdf::URIs::OWL_EQUIVALENTPROPERTY
:
477 ln
= "equivalentProperty";
480 case css::rdf::URIs::OWL_SAMEAS
:
485 case css::rdf::URIs::OWL_DIFFERENTFROM
:
487 ln
= "differentFrom";
490 case css::rdf::URIs::OWL_ALLDIFFERENT
:
495 case css::rdf::URIs::OWL_DISTINCTMEMBERS
:
497 ln
= "distinctMembers";
500 case css::rdf::URIs::OWL_INVERSEOF
:
505 case css::rdf::URIs::OWL_TRANSITIVEPROPERTY
:
507 ln
= "TransitiveProperty";
510 case css::rdf::URIs::OWL_SYMMETRICPROPERTY
:
512 ln
= "SymmetricProperty";
515 case css::rdf::URIs::OWL_INVERSEFUNCTIONALPROPERTY
:
517 ln
= "InverseFunctionalProperty";
520 case css::rdf::URIs::OWL_RESTRICTION
:
525 case css::rdf::URIs::OWL_ONPROPERTY
:
530 case css::rdf::URIs::OWL_ALLVALUESFROM
:
532 ln
= "allValuesFrom";
535 case css::rdf::URIs::OWL_SOMEVALUESFROM
:
537 ln
= "someValuesFrom";
540 case css::rdf::URIs::OWL_MINCARDINALITY
:
542 ln
= "minCardinality";
545 case css::rdf::URIs::OWL_MAXCARDINALITY
:
547 ln
= "maxCardinality";
550 case css::rdf::URIs::OWL_CARDINALITY
:
555 case css::rdf::URIs::OWL_ONTOLOGY
:
560 case css::rdf::URIs::OWL_IMPORTS
:
565 case css::rdf::URIs::OWL_VERSIONINFO
:
570 case css::rdf::URIs::OWL_PRIORVERSION
:
575 case css::rdf::URIs::OWL_BACKWARDCOMPATIBLEWITH
:
577 ln
= "backwardCompatibleWith";
580 case css::rdf::URIs::OWL_INCOMPATIBLEWITH
:
582 ln
= "incompatibleWith";
585 case css::rdf::URIs::OWL_DEPRECATEDCLASS
:
587 ln
= "DeprecatedClass";
590 case css::rdf::URIs::OWL_DEPRECATEDPROPERTY
:
592 ln
= "DeprecatedProperty";
595 case css::rdf::URIs::OWL_ANNOTATIONPROPERTY
:
597 ln
= "AnnotationProperty";
600 case css::rdf::URIs::OWL_ONTOLOGYPROPERTY
:
602 ln
= "OntologyProperty";
605 case css::rdf::URIs::OWL_ONEOF
:
610 case css::rdf::URIs::OWL_DATARANGE
:
615 case css::rdf::URIs::OWL_DISJOINTWITH
:
620 case css::rdf::URIs::OWL_UNIONOF
:
625 case css::rdf::URIs::OWL_COMPLEMENTOF
:
630 case css::rdf::URIs::OWL_INTERSECTIONOF
:
632 ln
= "intersectionOf";
635 case css::rdf::URIs::OWL_HASVALUE
:
641 case css::rdf::URIs::PKG_HASPART
:
646 case css::rdf::URIs::PKG_MIMETYPE
:
651 case css::rdf::URIs::PKG_PACKAGE
:
656 case css::rdf::URIs::PKG_ELEMENT
:
661 case css::rdf::URIs::PKG_FILE
:
666 case css::rdf::URIs::PKG_METADATAFILE
:
671 case css::rdf::URIs::PKG_DOCUMENT
:
676 case css::rdf::URIs::ODF_PREFIX
:
681 case css::rdf::URIs::ODF_SUFFIX
:
686 case css::rdf::URIs::ODF_ELEMENT
:
691 case css::rdf::URIs::ODF_CONTENTFILE
:
696 case css::rdf::URIs::ODF_STYLESFILE
:
702 throw css::lang::IllegalArgumentException(
703 "CURI::initialize: invalid URIs constant argument", *this, 0);
705 m_Namespace
= OUString::createFromAscii(ns
).intern();
706 m_LocalName
= OUString::createFromAscii(ln
).intern();
709 // css::lang::XInitialization:
710 void SAL_CALL
CURI::initialize(const css::uno::Sequence
< css::uno::Any
> & aArguments
)
712 sal_Int32 len
= aArguments
.getLength();
713 if ((len
< 1) || (len
> 2)) {
714 throw css::lang::IllegalArgumentException(
715 "CURI::initialize: must give 1 or 2 argument(s)", *this, 2);
721 if (aArguments
[0] >>= arg
) {
722 // integer argument: constant from rdf::URIs
724 throw css::lang::IllegalArgumentException(
725 "CURI::initialize: must give 1 int argument", *this, 1);
727 initFromConstant(arg
);
730 if (!(aArguments
[0] >>= arg0
)) {
731 throw css::lang::IllegalArgumentException(
732 "CURI::initialize: argument must be string or short", *this, 0);
735 if (!(aArguments
[1] >>= arg1
)) {
736 throw css::lang::IllegalArgumentException(
737 "CURI::initialize: argument must be string", *this, 1);
739 // just append the parameters and then split them again; seems simplest
746 if ( ((idx
= arg0
.indexOf ('#')) < 0)
747 && ((idx
= arg0
.lastIndexOf('/')) < 0)
748 && ((idx
= arg0
.lastIndexOf(':')) < 0) )
750 throw css::lang::IllegalArgumentException(
751 "CURI::initialize: argument not splittable: no separator [#/:]", *this, 0);
753 if (idx
< arg0
.getLength() - 1) {
754 arg1
= arg0
.copy(idx
+1);
755 arg0
= arg0
.copy(0, idx
+1);
758 //FIXME: what is legal?
759 if (arg0
.isEmpty()) {
760 throw css::lang::IllegalArgumentException(
761 "CURI::initialize: argument is not valid namespace", *this, 0);
765 //FIXME: what is legal?
767 throw css::lang::IllegalArgumentException(
768 "CURI::initialize: argument is not valid local name", *this, 1);
774 OUString SAL_CALL
CURI::getStringValue()
776 return m_Namespace
+ m_LocalName
;
780 OUString SAL_CALL
CURI::getNamespace()
785 OUString SAL_CALL
CURI::getLocalName()
790 } // closing anonymous implementation namespace
793 // component helper namespace
794 namespace comp_CURI
{
796 OUString
_getImplementationName() {
801 css::uno::Sequence
< OUString
> _getSupportedServiceNames()
803 css::uno::Sequence
< OUString
> s
{ "com.sun.star.rdf.URI" };
807 css::uno::Reference
< css::uno::XInterface
> _create(
808 const css::uno::Reference
< css::uno::XComponentContext
> & )
810 return static_cast< ::cppu::OWeakObject
* >(new CURI
);
813 } // closing component helper namespace
815 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */