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 { "com.sun.star.rdf.URI" };
88 const char s_nsXSD
[] = "http://www.w3.org/2001/XMLSchema-datatypes#";
89 const char s_nsRDF
[] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
90 const char s_nsRDFs
[] = "http://www.w3.org/2000/01/rdf-schema#";
91 const char s_nsOWL
[] = "http://www.w3.org/2002/07/owl#";
92 const char s_nsPkg
[] =
93 "http://docs.oasis-open.org/ns/office/1.2/meta/pkg#";
94 const char s_nsODF
[] =
95 "http://docs.oasis-open.org/ns/office/1.2/meta/odf#";
96 const char s_nsLO_EXT
[] =
97 "urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0odf#";
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
:
701 case css::rdf::URIs::LO_EXT_SHADING
:
707 throw css::lang::IllegalArgumentException(
708 "CURI::initialize: invalid URIs constant argument", *this, 0);
710 m_Namespace
= OUString::createFromAscii(ns
);
711 m_LocalName
= OUString::createFromAscii(ln
);
714 // css::lang::XInitialization:
715 void SAL_CALL
CURI::initialize(const css::uno::Sequence
< css::uno::Any
> & aArguments
)
717 sal_Int32 len
= aArguments
.getLength();
718 if ((len
< 1) || (len
> 2)) {
719 throw css::lang::IllegalArgumentException(
720 "CURI::initialize: must give 1 or 2 argument(s)", *this, 2);
726 if (aArguments
[0] >>= arg
) {
727 // integer argument: constant from rdf::URIs
729 throw css::lang::IllegalArgumentException(
730 "CURI::initialize: must give 1 int argument", *this, 1);
732 initFromConstant(arg
);
735 if (!(aArguments
[0] >>= arg0
)) {
736 throw css::lang::IllegalArgumentException(
737 "CURI::initialize: argument must be string or short", *this, 0);
740 if (!(aArguments
[1] >>= arg1
)) {
741 throw css::lang::IllegalArgumentException(
742 "CURI::initialize: argument must be string", *this, 1);
744 // just append the parameters and then split them again; seems simplest
750 sal_Int32 idx
= arg0
.indexOf('#');
752 idx
= arg0
.lastIndexOf('/');
754 idx
= arg0
.lastIndexOf(':');
757 throw css::lang::IllegalArgumentException(
758 "CURI::initialize: argument not splittable: no separator [#/:]", *this, 0);
760 if (idx
< arg0
.getLength() - 1) {
761 arg1
= arg0
.copy(idx
+1);
762 arg0
= arg0
.copy(0, idx
+1);
765 //FIXME: what is legal?
766 if (arg0
.isEmpty()) {
767 throw css::lang::IllegalArgumentException(
768 "CURI::initialize: argument is not valid namespace", *this, 0);
772 //FIXME: what is legal?
774 throw css::lang::IllegalArgumentException(
775 "CURI::initialize: argument is not valid local name", *this, 1);
781 OUString SAL_CALL
CURI::getStringValue()
783 return m_Namespace
+ m_LocalName
;
787 OUString SAL_CALL
CURI::getNamespace()
792 OUString SAL_CALL
CURI::getLocalName()
797 } // closing anonymous implementation namespace
800 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
801 unoxml_CURI_get_implementation(
802 css::uno::XComponentContext
* , css::uno::Sequence
<css::uno::Any
> const&)
804 return cppu::acquire(new CURI());
807 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */