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
,
45 // css::lang::XServiceInfo:
46 virtual OUString SAL_CALL
getImplementationName() throw (css::uno::RuntimeException
, std::exception
) override
;
47 virtual sal_Bool SAL_CALL
supportsService(const OUString
& ServiceName
) throw (css::uno::RuntimeException
, std::exception
) override
;
48 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() throw (css::uno::RuntimeException
, std::exception
) override
;
50 // css::lang::XInitialization:
51 virtual void SAL_CALL
initialize(const css::uno::Sequence
< css::uno::Any
> & aArguments
) throw (css::uno::RuntimeException
, css::uno::Exception
, std::exception
) override
;
54 virtual OUString SAL_CALL
getStringValue() throw (css::uno::RuntimeException
, std::exception
) override
;
57 virtual OUString SAL_CALL
getLocalName() throw (css::uno::RuntimeException
, std::exception
) override
;
58 virtual OUString SAL_CALL
getNamespace() throw (css::uno::RuntimeException
, std::exception
) override
;
61 CURI(CURI
const&) = delete;
62 CURI
& operator=(CURI
const&) = delete;
64 /// handle css.rdf.URIs
65 void SAL_CALL
initFromConstant(const sal_Int16 i_Constant
);
72 m_Namespace(), m_LocalName()
75 // com.sun.star.uno.XServiceInfo:
76 OUString SAL_CALL
CURI::getImplementationName() throw (css::uno::RuntimeException
, std::exception
)
78 return comp_CURI::_getImplementationName();
81 sal_Bool SAL_CALL
CURI::supportsService(OUString
const & serviceName
) throw (css::uno::RuntimeException
, std::exception
)
83 return cppu::supportsService(this, serviceName
);
86 css::uno::Sequence
< OUString
> SAL_CALL
CURI::getSupportedServiceNames() throw (css::uno::RuntimeException
, std::exception
)
88 return comp_CURI::_getSupportedServiceNames();
91 const char s_nsXSD
[] = "http://www.w3.org/2001/XMLSchema-datatypes#";
92 const char s_nsRDF
[] = "http://www.w3.org/1999/02/22-rdf-syntax-ns#";
93 const char s_nsRDFs
[] = "http://www.w3.org/2000/01/rdf-schema#";
94 const char s_nsOWL
[] = "http://www.w3.org/2002/07/owl#";
95 const char s_nsPkg
[] =
96 "http://docs.oasis-open.org/ns/office/1.2/meta/pkg#";
97 const char s_nsODF
[] =
98 "http://docs.oasis-open.org/ns/office/1.2/meta/odf#";
100 void SAL_CALL
CURI::initFromConstant(const sal_Int16 i_Constant
)
102 const char *ns(nullptr);
103 const char *ln(nullptr);
106 case css::rdf::URIs::XSD_NCNAME
:
111 case css::rdf::URIs::XSD_STRING
:
116 case css::rdf::URIs::XSD_NORMALIZEDSTRING
:
118 ln
= "normalizedString";
121 case css::rdf::URIs::XSD_BOOLEAN
:
126 case css::rdf::URIs::XSD_DECIMAL
:
131 case css::rdf::URIs::XSD_FLOAT
:
136 case css::rdf::URIs::XSD_DOUBLE
:
141 case css::rdf::URIs::XSD_INTEGER
:
146 case css::rdf::URIs::XSD_NONNEGATIVEINTEGER
:
148 ln
= "nonNegativeInteger";
151 case css::rdf::URIs::XSD_POSITIVEINTEGER
:
153 ln
= "positiveInteger";
156 case css::rdf::URIs::XSD_NONPOSITIVEINTEGER
:
158 ln
= "nonPositiveInteger";
161 case css::rdf::URIs::XSD_NEGATIVEINTEGER
:
163 ln
= "negativeInteger";
166 case css::rdf::URIs::XSD_LONG
:
171 case css::rdf::URIs::XSD_INT
:
176 case css::rdf::URIs::XSD_SHORT
:
181 case css::rdf::URIs::XSD_BYTE
:
186 case css::rdf::URIs::XSD_UNSIGNEDLONG
:
191 case css::rdf::URIs::XSD_UNSIGNEDINT
:
196 case css::rdf::URIs::XSD_UNSIGNEDSHORT
:
198 ln
= "unsignedShort";
201 case css::rdf::URIs::XSD_UNSIGNEDBYTE
:
206 case css::rdf::URIs::XSD_HEXBINARY
:
211 case css::rdf::URIs::XSD_BASE64BINARY
:
216 case css::rdf::URIs::XSD_DATETIME
:
221 case css::rdf::URIs::XSD_TIME
:
226 case css::rdf::URIs::XSD_DATE
:
231 case css::rdf::URIs::XSD_GYEARMONTH
:
236 case css::rdf::URIs::XSD_GYEAR
:
241 case css::rdf::URIs::XSD_GMONTHDAY
:
246 case css::rdf::URIs::XSD_GDAY
:
251 case css::rdf::URIs::XSD_GMONTH
:
256 case css::rdf::URIs::XSD_ANYURI
:
261 case css::rdf::URIs::XSD_TOKEN
:
266 case css::rdf::URIs::XSD_LANGUAGE
:
271 case css::rdf::URIs::XSD_NMTOKEN
:
276 case css::rdf::URIs::XSD_NAME
:
281 case css::rdf::URIs::XSD_DURATION
:
286 case css::rdf::URIs::XSD_QNAME
:
291 case css::rdf::URIs::XSD_NOTATION
:
296 case css::rdf::URIs::XSD_NMTOKENS
:
301 case css::rdf::URIs::XSD_ID
:
306 case css::rdf::URIs::XSD_IDREF
:
311 case css::rdf::URIs::XSD_IDREFS
:
316 case css::rdf::URIs::XSD_ENTITY
:
321 case css::rdf::URIs::XSD_ENTITIES
:
326 case css::rdf::URIs::RDF_TYPE
:
331 case css::rdf::URIs::RDF_SUBJECT
:
336 case css::rdf::URIs::RDF_PREDICATE
:
341 case css::rdf::URIs::RDF_OBJECT
:
346 case css::rdf::URIs::RDF_PROPERTY
:
351 case css::rdf::URIs::RDF_STATEMENT
:
356 case css::rdf::URIs::RDF_VALUE
:
361 case css::rdf::URIs::RDF_FIRST
:
366 case css::rdf::URIs::RDF_REST
:
371 case css::rdf::URIs::RDF_NIL
:
376 case css::rdf::URIs::RDF_XMLLITERAL
:
381 case css::rdf::URIs::RDF_ALT
:
386 case css::rdf::URIs::RDF_BAG
:
391 case css::rdf::URIs::RDF_LIST
:
396 case css::rdf::URIs::RDF_SEQ
:
401 case css::rdf::URIs::RDF_1
:
406 case css::rdf::URIs::RDFS_COMMENT
:
411 case css::rdf::URIs::RDFS_LABEL
:
416 case css::rdf::URIs::RDFS_DOMAIN
:
421 case css::rdf::URIs::RDFS_RANGE
:
426 case css::rdf::URIs::RDFS_SUBCLASSOF
:
431 case css::rdf::URIs::RDFS_LITERAL
:
436 case css::rdf::URIs::OWL_CLASS
:
441 case css::rdf::URIs::OWL_OBJECTPROPERTY
:
443 ln
= "ObjectProperty";
446 case css::rdf::URIs::OWL_DATATYPEPROPERTY
:
448 ln
= "DatatypeProperty";
451 case css::rdf::URIs::OWL_FUNCTIONALPROPERTY
:
453 ln
= "FunctionalProperty";
456 case css::rdf::URIs::OWL_THING
:
461 case css::rdf::URIs::OWL_NOTHING
:
466 case css::rdf::URIs::OWL_INDIVIDUAL
:
471 case css::rdf::URIs::OWL_EQUIVALENTCLASS
:
473 ln
= "equivalentClass";
476 case css::rdf::URIs::OWL_EQUIVALENTPROPERTY
:
478 ln
= "equivalentProperty";
481 case css::rdf::URIs::OWL_SAMEAS
:
486 case css::rdf::URIs::OWL_DIFFERENTFROM
:
488 ln
= "differentFrom";
491 case css::rdf::URIs::OWL_ALLDIFFERENT
:
496 case css::rdf::URIs::OWL_DISTINCTMEMBERS
:
498 ln
= "distinctMembers";
501 case css::rdf::URIs::OWL_INVERSEOF
:
506 case css::rdf::URIs::OWL_TRANSITIVEPROPERTY
:
508 ln
= "TransitiveProperty";
511 case css::rdf::URIs::OWL_SYMMETRICPROPERTY
:
513 ln
= "SymmetricProperty";
516 case css::rdf::URIs::OWL_INVERSEFUNCTIONALPROPERTY
:
518 ln
= "InverseFunctionalProperty";
521 case css::rdf::URIs::OWL_RESTRICTION
:
526 case css::rdf::URIs::OWL_ONPROPERTY
:
531 case css::rdf::URIs::OWL_ALLVALUESFROM
:
533 ln
= "allValuesFrom";
536 case css::rdf::URIs::OWL_SOMEVALUESFROM
:
538 ln
= "someValuesFrom";
541 case css::rdf::URIs::OWL_MINCARDINALITY
:
543 ln
= "minCardinality";
546 case css::rdf::URIs::OWL_MAXCARDINALITY
:
548 ln
= "maxCardinality";
551 case css::rdf::URIs::OWL_CARDINALITY
:
556 case css::rdf::URIs::OWL_ONTOLOGY
:
561 case css::rdf::URIs::OWL_IMPORTS
:
566 case css::rdf::URIs::OWL_VERSIONINFO
:
571 case css::rdf::URIs::OWL_PRIORVERSION
:
576 case css::rdf::URIs::OWL_BACKWARDCOMPATIBLEWITH
:
578 ln
= "backwardCompatibleWith";
581 case css::rdf::URIs::OWL_INCOMPATIBLEWITH
:
583 ln
= "incompatibleWith";
586 case css::rdf::URIs::OWL_DEPRECATEDCLASS
:
588 ln
= "DeprecatedClass";
591 case css::rdf::URIs::OWL_DEPRECATEDPROPERTY
:
593 ln
= "DeprecatedProperty";
596 case css::rdf::URIs::OWL_ANNOTATIONPROPERTY
:
598 ln
= "AnnotationProperty";
601 case css::rdf::URIs::OWL_ONTOLOGYPROPERTY
:
603 ln
= "OntologyProperty";
606 case css::rdf::URIs::OWL_ONEOF
:
611 case css::rdf::URIs::OWL_DATARANGE
:
616 case css::rdf::URIs::OWL_DISJOINTWITH
:
621 case css::rdf::URIs::OWL_UNIONOF
:
626 case css::rdf::URIs::OWL_COMPLEMENTOF
:
631 case css::rdf::URIs::OWL_INTERSECTIONOF
:
633 ln
= "intersectionOf";
636 case css::rdf::URIs::OWL_HASVALUE
:
642 case css::rdf::URIs::PKG_HASPART
:
647 case css::rdf::URIs::PKG_MIMETYPE
:
652 case css::rdf::URIs::PKG_PACKAGE
:
657 case css::rdf::URIs::PKG_ELEMENT
:
662 case css::rdf::URIs::PKG_FILE
:
667 case css::rdf::URIs::PKG_METADATAFILE
:
672 case css::rdf::URIs::PKG_DOCUMENT
:
677 case css::rdf::URIs::ODF_PREFIX
:
682 case css::rdf::URIs::ODF_SUFFIX
:
687 case css::rdf::URIs::ODF_ELEMENT
:
692 case css::rdf::URIs::ODF_CONTENTFILE
:
697 case css::rdf::URIs::ODF_STYLESFILE
:
703 throw css::lang::IllegalArgumentException(
704 OUString("CURI::initialize: "
705 "invalid URIs constant argument"), *this, 0);
707 m_Namespace
= OUString::createFromAscii(ns
).intern();
708 m_LocalName
= OUString::createFromAscii(ln
).intern();
712 // css::lang::XInitialization:
713 void SAL_CALL
CURI::initialize(const css::uno::Sequence
< css::uno::Any
> & aArguments
) throw (css::uno::RuntimeException
, css::uno::Exception
, std::exception
)
715 sal_Int32 len
= aArguments
.getLength();
716 if ((len
< 1) || (len
> 2)) {
717 throw css::lang::IllegalArgumentException(
718 OUString("CURI::initialize: "
719 "must give 1 or 2 argument(s)"), *this, 2);
725 if ((aArguments
[0] >>= arg
)) {
726 // integer argument: constant from rdf::URIs
728 throw css::lang::IllegalArgumentException(
729 OUString("CURI::initialize: "
730 "must give 1 int argument"), *this, 1);
732 initFromConstant(arg
);
735 if (!(aArguments
[0] >>= arg0
)) {
736 throw css::lang::IllegalArgumentException(
737 OUString("CURI::initialize: "
738 "argument must be string or short"), *this, 0);
741 if (!(aArguments
[1] >>= arg1
)) {
742 throw css::lang::IllegalArgumentException(
743 OUString("CURI::initialize: "
744 "argument must be string"), *this, 1);
746 // just append the parameters and then split them again; seems simplest
753 if ( ((idx
= arg0
.indexOf ('#')) >= 0)
754 || ((idx
= arg0
.lastIndexOf('/')) >= 0)
755 || ((idx
= arg0
.lastIndexOf(':')) >= 0))
758 if (idx
< arg0
.getLength() - 1) {
759 arg1
= arg0
.copy(idx
+1);
760 arg0
= arg0
.copy(0, idx
+1);
763 throw css::lang::IllegalArgumentException(
764 OUString("CURI::initialize: "
765 "argument not splittable: no separator [#/:]"), *this, 0);
768 //FIXME: what is legal?
769 if (!arg0
.isEmpty()) {
772 throw css::lang::IllegalArgumentException(
773 OUString("CURI::initialize: "
774 "argument is not valid namespace"), *this, 0);
776 //FIXME: what is legal?
780 throw css::lang::IllegalArgumentException(
781 OUString("CURI::initialize: "
782 "argument is not valid local name"), *this, 1);
787 OUString SAL_CALL
CURI::getStringValue() throw (css::uno::RuntimeException
, std::exception
)
789 return m_Namespace
+ m_LocalName
;
793 OUString SAL_CALL
CURI::getNamespace() throw (css::uno::RuntimeException
, std::exception
)
798 OUString SAL_CALL
CURI::getLocalName() throw (css::uno::RuntimeException
, std::exception
)
803 } // closing anonymous implementation namespace
806 // component helper namespace
807 namespace comp_CURI
{
809 OUString SAL_CALL
_getImplementationName() {
814 css::uno::Sequence
< OUString
> SAL_CALL
_getSupportedServiceNames()
816 css::uno::Sequence
< OUString
> s
{ "com.sun.star.rdf.URI" };
820 css::uno::Reference
< css::uno::XInterface
> SAL_CALL
_create(
821 const css::uno::Reference
< css::uno::XComponentContext
> & )
823 return static_cast< ::cppu::OWeakObject
* >(new CURI
);
826 } // closing component helper namespace
828 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */