Bump version to 21.06.18.1
[LibreOffice.git] / unoxml / source / rdf / CURI.cxx
blob0a154d037f8e4e6ca50fd5c7696fac53a66a38cd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
32 namespace {
34 class CURI:
35 public ::cppu::WeakImplHelper<
36 css::lang::XServiceInfo,
37 css::lang::XInitialization,
38 css::rdf::XURI>
40 public:
41 explicit CURI();
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;
51 // css::rdf::XNode:
52 virtual OUString SAL_CALL getStringValue() override;
54 // css::rdf::XURI:
55 virtual OUString SAL_CALL getLocalName() override;
56 virtual OUString SAL_CALL getNamespace() override;
58 private:
59 CURI(CURI const&) = delete;
60 CURI& operator=(CURI const&) = delete;
62 /// handle css.rdf.URIs
63 void initFromConstant(const sal_Int16 i_Constant);
65 OUString m_Namespace;
66 OUString m_LocalName;
69 CURI::CURI() :
70 m_Namespace(), m_LocalName()
73 // com.sun.star.uno.XServiceInfo:
74 OUString SAL_CALL CURI::getImplementationName()
76 return "CURI";
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);
102 switch (i_Constant)
104 case css::rdf::URIs::XSD_NCNAME:
105 ns = s_nsXSD;
106 ln = "NCName";
107 break;
109 case css::rdf::URIs::XSD_STRING:
110 ns = s_nsXSD;
111 ln = "string";
112 break;
114 case css::rdf::URIs::XSD_NORMALIZEDSTRING:
115 ns = s_nsXSD;
116 ln = "normalizedString";
117 break;
119 case css::rdf::URIs::XSD_BOOLEAN:
120 ns = s_nsXSD;
121 ln = "boolean";
122 break;
124 case css::rdf::URIs::XSD_DECIMAL:
125 ns = s_nsXSD;
126 ln = "decimal";
127 break;
129 case css::rdf::URIs::XSD_FLOAT:
130 ns = s_nsXSD;
131 ln = "float";
132 break;
134 case css::rdf::URIs::XSD_DOUBLE:
135 ns = s_nsXSD;
136 ln = "double";
137 break;
139 case css::rdf::URIs::XSD_INTEGER:
140 ns = s_nsXSD;
141 ln = "integer";
142 break;
144 case css::rdf::URIs::XSD_NONNEGATIVEINTEGER:
145 ns = s_nsXSD;
146 ln = "nonNegativeInteger";
147 break;
149 case css::rdf::URIs::XSD_POSITIVEINTEGER:
150 ns = s_nsXSD;
151 ln = "positiveInteger";
152 break;
154 case css::rdf::URIs::XSD_NONPOSITIVEINTEGER:
155 ns = s_nsXSD;
156 ln = "nonPositiveInteger";
157 break;
159 case css::rdf::URIs::XSD_NEGATIVEINTEGER:
160 ns = s_nsXSD;
161 ln = "negativeInteger";
162 break;
164 case css::rdf::URIs::XSD_LONG:
165 ns = s_nsXSD;
166 ln = "long";
167 break;
169 case css::rdf::URIs::XSD_INT:
170 ns = s_nsXSD;
171 ln = "int";
172 break;
174 case css::rdf::URIs::XSD_SHORT:
175 ns = s_nsXSD;
176 ln = "short";
177 break;
179 case css::rdf::URIs::XSD_BYTE:
180 ns = s_nsXSD;
181 ln = "byte";
182 break;
184 case css::rdf::URIs::XSD_UNSIGNEDLONG:
185 ns = s_nsXSD;
186 ln = "unsignedLong";
187 break;
189 case css::rdf::URIs::XSD_UNSIGNEDINT:
190 ns = s_nsXSD;
191 ln = "unsignedInt";
192 break;
194 case css::rdf::URIs::XSD_UNSIGNEDSHORT:
195 ns = s_nsXSD;
196 ln = "unsignedShort";
197 break;
199 case css::rdf::URIs::XSD_UNSIGNEDBYTE:
200 ns = s_nsXSD;
201 ln = "unsignedByte";
202 break;
204 case css::rdf::URIs::XSD_HEXBINARY:
205 ns = s_nsXSD;
206 ln = "hexBinary";
207 break;
209 case css::rdf::URIs::XSD_BASE64BINARY:
210 ns = s_nsXSD;
211 ln = "base64Binary";
212 break;
214 case css::rdf::URIs::XSD_DATETIME:
215 ns = s_nsXSD;
216 ln = "dateTime";
217 break;
219 case css::rdf::URIs::XSD_TIME:
220 ns = s_nsXSD;
221 ln = "time";
222 break;
224 case css::rdf::URIs::XSD_DATE:
225 ns = s_nsXSD;
226 ln = "date";
227 break;
229 case css::rdf::URIs::XSD_GYEARMONTH:
230 ns = s_nsXSD;
231 ln = "gYearMonth";
232 break;
234 case css::rdf::URIs::XSD_GYEAR:
235 ns = s_nsXSD;
236 ln = "gYear";
237 break;
239 case css::rdf::URIs::XSD_GMONTHDAY:
240 ns = s_nsXSD;
241 ln = "gMonthDay";
242 break;
244 case css::rdf::URIs::XSD_GDAY:
245 ns = s_nsXSD;
246 ln = "gDay";
247 break;
249 case css::rdf::URIs::XSD_GMONTH:
250 ns = s_nsXSD;
251 ln = "gMonth";
252 break;
254 case css::rdf::URIs::XSD_ANYURI:
255 ns = s_nsXSD;
256 ln = "anyURI";
257 break;
259 case css::rdf::URIs::XSD_TOKEN:
260 ns = s_nsXSD;
261 ln = "token";
262 break;
264 case css::rdf::URIs::XSD_LANGUAGE:
265 ns = s_nsXSD;
266 ln = "language";
267 break;
269 case css::rdf::URIs::XSD_NMTOKEN:
270 ns = s_nsXSD;
271 ln = "NMTOKEN";
272 break;
274 case css::rdf::URIs::XSD_NAME:
275 ns = s_nsXSD;
276 ln = "Name";
277 break;
279 case css::rdf::URIs::XSD_DURATION:
280 ns = s_nsXSD;
281 ln = "duration";
282 break;
284 case css::rdf::URIs::XSD_QNAME:
285 ns = s_nsXSD;
286 ln = "QName";
287 break;
289 case css::rdf::URIs::XSD_NOTATION:
290 ns = s_nsXSD;
291 ln = "NOTATION";
292 break;
294 case css::rdf::URIs::XSD_NMTOKENS:
295 ns = s_nsXSD;
296 ln = "NMTOKENS";
297 break;
299 case css::rdf::URIs::XSD_ID:
300 ns = s_nsXSD;
301 ln = "ID";
302 break;
304 case css::rdf::URIs::XSD_IDREF:
305 ns = s_nsXSD;
306 ln = "IDREF";
307 break;
309 case css::rdf::URIs::XSD_IDREFS:
310 ns = s_nsXSD;
311 ln = "IDREFS";
312 break;
314 case css::rdf::URIs::XSD_ENTITY:
315 ns = s_nsXSD;
316 ln = "ENTITY";
317 break;
319 case css::rdf::URIs::XSD_ENTITIES:
320 ns = s_nsXSD;
321 ln = "ENTITIES";
322 break;
324 case css::rdf::URIs::RDF_TYPE:
325 ns = s_nsRDF;
326 ln = "type";
327 break;
329 case css::rdf::URIs::RDF_SUBJECT:
330 ns = s_nsRDF;
331 ln = "subject";
332 break;
334 case css::rdf::URIs::RDF_PREDICATE:
335 ns = s_nsRDF;
336 ln = "predicate";
337 break;
339 case css::rdf::URIs::RDF_OBJECT:
340 ns = s_nsRDF;
341 ln = "object";
342 break;
344 case css::rdf::URIs::RDF_PROPERTY:
345 ns = s_nsRDF;
346 ln = "Property";
347 break;
349 case css::rdf::URIs::RDF_STATEMENT:
350 ns = s_nsRDF;
351 ln = "Statement";
352 break;
354 case css::rdf::URIs::RDF_VALUE:
355 ns = s_nsRDF;
356 ln = "value";
357 break;
359 case css::rdf::URIs::RDF_FIRST:
360 ns = s_nsRDF;
361 ln = "first";
362 break;
364 case css::rdf::URIs::RDF_REST:
365 ns = s_nsRDF;
366 ln = "rest";
367 break;
369 case css::rdf::URIs::RDF_NIL:
370 ns = s_nsRDF;
371 ln = "nil";
372 break;
374 case css::rdf::URIs::RDF_XMLLITERAL:
375 ns = s_nsRDF;
376 ln = "XMLLiteral";
377 break;
379 case css::rdf::URIs::RDF_ALT:
380 ns = s_nsRDF;
381 ln = "Alt";
382 break;
384 case css::rdf::URIs::RDF_BAG:
385 ns = s_nsRDF;
386 ln = "Bag";
387 break;
389 case css::rdf::URIs::RDF_LIST:
390 ns = s_nsRDF;
391 ln = "List";
392 break;
394 case css::rdf::URIs::RDF_SEQ:
395 ns = s_nsRDF;
396 ln = "Seq";
397 break;
399 case css::rdf::URIs::RDF_1:
400 ns = s_nsRDF;
401 ln = "_1";
402 break;
404 case css::rdf::URIs::RDFS_COMMENT:
405 ns = s_nsRDFs;
406 ln = "comment";
407 break;
409 case css::rdf::URIs::RDFS_LABEL:
410 ns = s_nsRDFs;
411 ln = "label";
412 break;
414 case css::rdf::URIs::RDFS_DOMAIN:
415 ns = s_nsRDFs;
416 ln = "domain";
417 break;
419 case css::rdf::URIs::RDFS_RANGE:
420 ns = s_nsRDFs;
421 ln = "range";
422 break;
424 case css::rdf::URIs::RDFS_SUBCLASSOF:
425 ns = s_nsRDFs;
426 ln = "subClassOf";
427 break;
429 case css::rdf::URIs::RDFS_LITERAL:
430 ns = s_nsRDFs;
431 ln = "Literal";
432 break;
434 case css::rdf::URIs::OWL_CLASS:
435 ns = s_nsOWL;
436 ln = "Class";
437 break;
439 case css::rdf::URIs::OWL_OBJECTPROPERTY:
440 ns = s_nsOWL;
441 ln = "ObjectProperty";
442 break;
444 case css::rdf::URIs::OWL_DATATYPEPROPERTY:
445 ns = s_nsOWL;
446 ln = "DatatypeProperty";
447 break;
449 case css::rdf::URIs::OWL_FUNCTIONALPROPERTY:
450 ns = s_nsOWL;
451 ln = "FunctionalProperty";
452 break;
454 case css::rdf::URIs::OWL_THING:
455 ns = s_nsOWL;
456 ln = "Thing";
457 break;
459 case css::rdf::URIs::OWL_NOTHING:
460 ns = s_nsOWL;
461 ln = "Nothing";
462 break;
464 case css::rdf::URIs::OWL_INDIVIDUAL:
465 ns = s_nsOWL;
466 ln = "Individual";
467 break;
469 case css::rdf::URIs::OWL_EQUIVALENTCLASS:
470 ns = s_nsOWL;
471 ln = "equivalentClass";
472 break;
474 case css::rdf::URIs::OWL_EQUIVALENTPROPERTY:
475 ns = s_nsOWL;
476 ln = "equivalentProperty";
477 break;
479 case css::rdf::URIs::OWL_SAMEAS:
480 ns = s_nsOWL;
481 ln = "sameAs";
482 break;
484 case css::rdf::URIs::OWL_DIFFERENTFROM:
485 ns = s_nsOWL;
486 ln = "differentFrom";
487 break;
489 case css::rdf::URIs::OWL_ALLDIFFERENT:
490 ns = s_nsOWL;
491 ln = "AllDifferent";
492 break;
494 case css::rdf::URIs::OWL_DISTINCTMEMBERS:
495 ns = s_nsOWL;
496 ln = "distinctMembers";
497 break;
499 case css::rdf::URIs::OWL_INVERSEOF:
500 ns = s_nsOWL;
501 ln = "inverseOf";
502 break;
504 case css::rdf::URIs::OWL_TRANSITIVEPROPERTY:
505 ns = s_nsOWL;
506 ln = "TransitiveProperty";
507 break;
509 case css::rdf::URIs::OWL_SYMMETRICPROPERTY:
510 ns = s_nsOWL;
511 ln = "SymmetricProperty";
512 break;
514 case css::rdf::URIs::OWL_INVERSEFUNCTIONALPROPERTY:
515 ns = s_nsOWL;
516 ln = "InverseFunctionalProperty";
517 break;
519 case css::rdf::URIs::OWL_RESTRICTION:
520 ns = s_nsOWL;
521 ln = "Restriction";
522 break;
524 case css::rdf::URIs::OWL_ONPROPERTY:
525 ns = s_nsOWL;
526 ln = "onProperty";
527 break;
529 case css::rdf::URIs::OWL_ALLVALUESFROM:
530 ns = s_nsOWL;
531 ln = "allValuesFrom";
532 break;
534 case css::rdf::URIs::OWL_SOMEVALUESFROM:
535 ns = s_nsOWL;
536 ln = "someValuesFrom";
537 break;
539 case css::rdf::URIs::OWL_MINCARDINALITY:
540 ns = s_nsOWL;
541 ln = "minCardinality";
542 break;
544 case css::rdf::URIs::OWL_MAXCARDINALITY:
545 ns = s_nsOWL;
546 ln = "maxCardinality";
547 break;
549 case css::rdf::URIs::OWL_CARDINALITY:
550 ns = s_nsOWL;
551 ln = "cardinality";
552 break;
554 case css::rdf::URIs::OWL_ONTOLOGY:
555 ns = s_nsOWL;
556 ln = "Ontology";
557 break;
559 case css::rdf::URIs::OWL_IMPORTS:
560 ns = s_nsOWL;
561 ln = "imports";
562 break;
564 case css::rdf::URIs::OWL_VERSIONINFO:
565 ns = s_nsOWL;
566 ln = "versionInfo";
567 break;
569 case css::rdf::URIs::OWL_PRIORVERSION:
570 ns = s_nsOWL;
571 ln = "priorVersion";
572 break;
574 case css::rdf::URIs::OWL_BACKWARDCOMPATIBLEWITH:
575 ns = s_nsOWL;
576 ln = "backwardCompatibleWith";
577 break;
579 case css::rdf::URIs::OWL_INCOMPATIBLEWITH:
580 ns = s_nsOWL;
581 ln = "incompatibleWith";
582 break;
584 case css::rdf::URIs::OWL_DEPRECATEDCLASS:
585 ns = s_nsOWL;
586 ln = "DeprecatedClass";
587 break;
589 case css::rdf::URIs::OWL_DEPRECATEDPROPERTY:
590 ns = s_nsOWL;
591 ln = "DeprecatedProperty";
592 break;
594 case css::rdf::URIs::OWL_ANNOTATIONPROPERTY:
595 ns = s_nsOWL;
596 ln = "AnnotationProperty";
597 break;
599 case css::rdf::URIs::OWL_ONTOLOGYPROPERTY:
600 ns = s_nsOWL;
601 ln = "OntologyProperty";
602 break;
604 case css::rdf::URIs::OWL_ONEOF:
605 ns = s_nsOWL;
606 ln = "oneOf";
607 break;
609 case css::rdf::URIs::OWL_DATARANGE:
610 ns = s_nsOWL;
611 ln = "dataRange";
612 break;
614 case css::rdf::URIs::OWL_DISJOINTWITH:
615 ns = s_nsOWL;
616 ln = "disjointWith";
617 break;
619 case css::rdf::URIs::OWL_UNIONOF:
620 ns = s_nsOWL;
621 ln = "unionOf";
622 break;
624 case css::rdf::URIs::OWL_COMPLEMENTOF:
625 ns = s_nsOWL;
626 ln = "complementOf";
627 break;
629 case css::rdf::URIs::OWL_INTERSECTIONOF:
630 ns = s_nsOWL;
631 ln = "intersectionOf";
632 break;
634 case css::rdf::URIs::OWL_HASVALUE:
635 ns = s_nsOWL;
636 ln = "hasValue";
637 break;
640 case css::rdf::URIs::PKG_HASPART:
641 ns = s_nsPkg;
642 ln = "hasPart";
643 break;
645 case css::rdf::URIs::PKG_MIMETYPE:
646 ns = s_nsPkg;
647 ln = "mimeType";
648 break;
650 case css::rdf::URIs::PKG_PACKAGE:
651 ns = s_nsPkg;
652 ln = "Package";
653 break;
655 case css::rdf::URIs::PKG_ELEMENT:
656 ns = s_nsPkg;
657 ln = "Element";
658 break;
660 case css::rdf::URIs::PKG_FILE:
661 ns = s_nsPkg;
662 ln = "File";
663 break;
665 case css::rdf::URIs::PKG_METADATAFILE:
666 ns = s_nsPkg;
667 ln = "MetadataFile";
668 break;
670 case css::rdf::URIs::PKG_DOCUMENT:
671 ns = s_nsPkg;
672 ln = "Document";
673 break;
675 case css::rdf::URIs::ODF_PREFIX:
676 ns = s_nsODF;
677 ln = "prefix";
678 break;
680 case css::rdf::URIs::ODF_SUFFIX:
681 ns = s_nsODF;
682 ln = "suffix";
683 break;
685 case css::rdf::URIs::ODF_ELEMENT:
686 ns = s_nsODF;
687 ln = "Element";
688 break;
690 case css::rdf::URIs::ODF_CONTENTFILE:
691 ns = s_nsODF;
692 ln = "ContentFile";
693 break;
695 case css::rdf::URIs::ODF_STYLESFILE:
696 ns = s_nsODF;
697 ln = "StylesFile";
698 break;
700 default:
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);
717 sal_Int16 arg(0);
718 OUString arg0;
719 OUString arg1;
720 if (aArguments[0] >>= arg) {
721 // integer argument: constant from rdf::URIs
722 if (len != 1) {
723 throw css::lang::IllegalArgumentException(
724 "CURI::initialize: must give 1 int argument", *this, 1);
726 initFromConstant(arg);
727 return;
729 if (!(aArguments[0] >>= arg0)) {
730 throw css::lang::IllegalArgumentException(
731 "CURI::initialize: argument must be string or short", *this, 0);
733 if (len > 1) {
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
739 arg0 = arg0 + arg1;
740 arg1.clear();
743 // split parameter
744 sal_Int32 idx = arg0.indexOf('#');
745 if (idx < 0)
746 idx = arg0.lastIndexOf('/');
747 if (idx < 0)
748 idx = arg0.lastIndexOf(':');
749 if (idx < 0)
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);
764 m_Namespace = arg0;
766 //FIXME: what is legal?
767 if ((false)) {
768 throw css::lang::IllegalArgumentException(
769 "CURI::initialize: argument is not valid local name", *this, 1);
771 m_LocalName = arg1;
774 // css::rdf::XNode:
775 OUString SAL_CALL CURI::getStringValue()
777 return m_Namespace + m_LocalName;
780 // css::rdf::XURI:
781 OUString SAL_CALL CURI::getNamespace()
783 return m_Namespace;
786 OUString SAL_CALL CURI::getLocalName()
788 return m_LocalName;
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: */