Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / unoxml / source / rdf / CURI.cxx
blobcef43fa224889e5848dfa1faeeba3a40f56bc36d
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 "CNodes.hxx"
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
33 namespace {
35 class CURI:
36 public ::cppu::WeakImplHelper<
37 css::lang::XServiceInfo,
38 css::lang::XInitialization,
39 css::rdf::XURI>
41 public:
42 explicit CURI();
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;
52 // css::rdf::XNode:
53 virtual OUString SAL_CALL getStringValue() override;
55 // css::rdf::XURI:
56 virtual OUString SAL_CALL getLocalName() override;
57 virtual OUString SAL_CALL getNamespace() override;
59 private:
60 CURI(CURI const&) = delete;
61 CURI& operator=(CURI const&) = delete;
63 /// handle css.rdf.URIs
64 void initFromConstant(const sal_Int16 i_Constant);
66 OUString m_Namespace;
67 OUString m_LocalName;
70 CURI::CURI() :
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);
103 switch (i_Constant)
105 case css::rdf::URIs::XSD_NCNAME:
106 ns = s_nsXSD;
107 ln = "NCName";
108 break;
110 case css::rdf::URIs::XSD_STRING:
111 ns = s_nsXSD;
112 ln = "string";
113 break;
115 case css::rdf::URIs::XSD_NORMALIZEDSTRING:
116 ns = s_nsXSD;
117 ln = "normalizedString";
118 break;
120 case css::rdf::URIs::XSD_BOOLEAN:
121 ns = s_nsXSD;
122 ln = "boolean";
123 break;
125 case css::rdf::URIs::XSD_DECIMAL:
126 ns = s_nsXSD;
127 ln = "decimal";
128 break;
130 case css::rdf::URIs::XSD_FLOAT:
131 ns = s_nsXSD;
132 ln = "float";
133 break;
135 case css::rdf::URIs::XSD_DOUBLE:
136 ns = s_nsXSD;
137 ln = "double";
138 break;
140 case css::rdf::URIs::XSD_INTEGER:
141 ns = s_nsXSD;
142 ln = "integer";
143 break;
145 case css::rdf::URIs::XSD_NONNEGATIVEINTEGER:
146 ns = s_nsXSD;
147 ln = "nonNegativeInteger";
148 break;
150 case css::rdf::URIs::XSD_POSITIVEINTEGER:
151 ns = s_nsXSD;
152 ln = "positiveInteger";
153 break;
155 case css::rdf::URIs::XSD_NONPOSITIVEINTEGER:
156 ns = s_nsXSD;
157 ln = "nonPositiveInteger";
158 break;
160 case css::rdf::URIs::XSD_NEGATIVEINTEGER:
161 ns = s_nsXSD;
162 ln = "negativeInteger";
163 break;
165 case css::rdf::URIs::XSD_LONG:
166 ns = s_nsXSD;
167 ln = "long";
168 break;
170 case css::rdf::URIs::XSD_INT:
171 ns = s_nsXSD;
172 ln = "int";
173 break;
175 case css::rdf::URIs::XSD_SHORT:
176 ns = s_nsXSD;
177 ln = "short";
178 break;
180 case css::rdf::URIs::XSD_BYTE:
181 ns = s_nsXSD;
182 ln = "byte";
183 break;
185 case css::rdf::URIs::XSD_UNSIGNEDLONG:
186 ns = s_nsXSD;
187 ln = "unsignedLong";
188 break;
190 case css::rdf::URIs::XSD_UNSIGNEDINT:
191 ns = s_nsXSD;
192 ln = "unsignedInt";
193 break;
195 case css::rdf::URIs::XSD_UNSIGNEDSHORT:
196 ns = s_nsXSD;
197 ln = "unsignedShort";
198 break;
200 case css::rdf::URIs::XSD_UNSIGNEDBYTE:
201 ns = s_nsXSD;
202 ln = "unsignedByte";
203 break;
205 case css::rdf::URIs::XSD_HEXBINARY:
206 ns = s_nsXSD;
207 ln = "hexBinary";
208 break;
210 case css::rdf::URIs::XSD_BASE64BINARY:
211 ns = s_nsXSD;
212 ln = "base64Binary";
213 break;
215 case css::rdf::URIs::XSD_DATETIME:
216 ns = s_nsXSD;
217 ln = "dateTime";
218 break;
220 case css::rdf::URIs::XSD_TIME:
221 ns = s_nsXSD;
222 ln = "time";
223 break;
225 case css::rdf::URIs::XSD_DATE:
226 ns = s_nsXSD;
227 ln = "date";
228 break;
230 case css::rdf::URIs::XSD_GYEARMONTH:
231 ns = s_nsXSD;
232 ln = "gYearMonth";
233 break;
235 case css::rdf::URIs::XSD_GYEAR:
236 ns = s_nsXSD;
237 ln = "gYear";
238 break;
240 case css::rdf::URIs::XSD_GMONTHDAY:
241 ns = s_nsXSD;
242 ln = "gMonthDay";
243 break;
245 case css::rdf::URIs::XSD_GDAY:
246 ns = s_nsXSD;
247 ln = "gDay";
248 break;
250 case css::rdf::URIs::XSD_GMONTH:
251 ns = s_nsXSD;
252 ln = "gMonth";
253 break;
255 case css::rdf::URIs::XSD_ANYURI:
256 ns = s_nsXSD;
257 ln = "anyURI";
258 break;
260 case css::rdf::URIs::XSD_TOKEN:
261 ns = s_nsXSD;
262 ln = "token";
263 break;
265 case css::rdf::URIs::XSD_LANGUAGE:
266 ns = s_nsXSD;
267 ln = "language";
268 break;
270 case css::rdf::URIs::XSD_NMTOKEN:
271 ns = s_nsXSD;
272 ln = "NMTOKEN";
273 break;
275 case css::rdf::URIs::XSD_NAME:
276 ns = s_nsXSD;
277 ln = "Name";
278 break;
280 case css::rdf::URIs::XSD_DURATION:
281 ns = s_nsXSD;
282 ln = "duration";
283 break;
285 case css::rdf::URIs::XSD_QNAME:
286 ns = s_nsXSD;
287 ln = "QName";
288 break;
290 case css::rdf::URIs::XSD_NOTATION:
291 ns = s_nsXSD;
292 ln = "NOTATION";
293 break;
295 case css::rdf::URIs::XSD_NMTOKENS:
296 ns = s_nsXSD;
297 ln = "NMTOKENS";
298 break;
300 case css::rdf::URIs::XSD_ID:
301 ns = s_nsXSD;
302 ln = "ID";
303 break;
305 case css::rdf::URIs::XSD_IDREF:
306 ns = s_nsXSD;
307 ln = "IDREF";
308 break;
310 case css::rdf::URIs::XSD_IDREFS:
311 ns = s_nsXSD;
312 ln = "IDREFS";
313 break;
315 case css::rdf::URIs::XSD_ENTITY:
316 ns = s_nsXSD;
317 ln = "ENTITY";
318 break;
320 case css::rdf::URIs::XSD_ENTITIES:
321 ns = s_nsXSD;
322 ln = "ENTITIES";
323 break;
325 case css::rdf::URIs::RDF_TYPE:
326 ns = s_nsRDF;
327 ln = "type";
328 break;
330 case css::rdf::URIs::RDF_SUBJECT:
331 ns = s_nsRDF;
332 ln = "subject";
333 break;
335 case css::rdf::URIs::RDF_PREDICATE:
336 ns = s_nsRDF;
337 ln = "predicate";
338 break;
340 case css::rdf::URIs::RDF_OBJECT:
341 ns = s_nsRDF;
342 ln = "object";
343 break;
345 case css::rdf::URIs::RDF_PROPERTY:
346 ns = s_nsRDF;
347 ln = "Property";
348 break;
350 case css::rdf::URIs::RDF_STATEMENT:
351 ns = s_nsRDF;
352 ln = "Statement";
353 break;
355 case css::rdf::URIs::RDF_VALUE:
356 ns = s_nsRDF;
357 ln = "value";
358 break;
360 case css::rdf::URIs::RDF_FIRST:
361 ns = s_nsRDF;
362 ln = "first";
363 break;
365 case css::rdf::URIs::RDF_REST:
366 ns = s_nsRDF;
367 ln = "rest";
368 break;
370 case css::rdf::URIs::RDF_NIL:
371 ns = s_nsRDF;
372 ln = "nil";
373 break;
375 case css::rdf::URIs::RDF_XMLLITERAL:
376 ns = s_nsRDF;
377 ln = "XMLLiteral";
378 break;
380 case css::rdf::URIs::RDF_ALT:
381 ns = s_nsRDF;
382 ln = "Alt";
383 break;
385 case css::rdf::URIs::RDF_BAG:
386 ns = s_nsRDF;
387 ln = "Bag";
388 break;
390 case css::rdf::URIs::RDF_LIST:
391 ns = s_nsRDF;
392 ln = "List";
393 break;
395 case css::rdf::URIs::RDF_SEQ:
396 ns = s_nsRDF;
397 ln = "Seq";
398 break;
400 case css::rdf::URIs::RDF_1:
401 ns = s_nsRDF;
402 ln = "_1";
403 break;
405 case css::rdf::URIs::RDFS_COMMENT:
406 ns = s_nsRDFs;
407 ln = "comment";
408 break;
410 case css::rdf::URIs::RDFS_LABEL:
411 ns = s_nsRDFs;
412 ln = "label";
413 break;
415 case css::rdf::URIs::RDFS_DOMAIN:
416 ns = s_nsRDFs;
417 ln = "domain";
418 break;
420 case css::rdf::URIs::RDFS_RANGE:
421 ns = s_nsRDFs;
422 ln = "range";
423 break;
425 case css::rdf::URIs::RDFS_SUBCLASSOF:
426 ns = s_nsRDFs;
427 ln = "subClassOf";
428 break;
430 case css::rdf::URIs::RDFS_LITERAL:
431 ns = s_nsRDFs;
432 ln = "Literal";
433 break;
435 case css::rdf::URIs::OWL_CLASS:
436 ns = s_nsOWL;
437 ln = "Class";
438 break;
440 case css::rdf::URIs::OWL_OBJECTPROPERTY:
441 ns = s_nsOWL;
442 ln = "ObjectProperty";
443 break;
445 case css::rdf::URIs::OWL_DATATYPEPROPERTY:
446 ns = s_nsOWL;
447 ln = "DatatypeProperty";
448 break;
450 case css::rdf::URIs::OWL_FUNCTIONALPROPERTY:
451 ns = s_nsOWL;
452 ln = "FunctionalProperty";
453 break;
455 case css::rdf::URIs::OWL_THING:
456 ns = s_nsOWL;
457 ln = "Thing";
458 break;
460 case css::rdf::URIs::OWL_NOTHING:
461 ns = s_nsOWL;
462 ln = "Nothing";
463 break;
465 case css::rdf::URIs::OWL_INDIVIDUAL:
466 ns = s_nsOWL;
467 ln = "Individual";
468 break;
470 case css::rdf::URIs::OWL_EQUIVALENTCLASS:
471 ns = s_nsOWL;
472 ln = "equivalentClass";
473 break;
475 case css::rdf::URIs::OWL_EQUIVALENTPROPERTY:
476 ns = s_nsOWL;
477 ln = "equivalentProperty";
478 break;
480 case css::rdf::URIs::OWL_SAMEAS:
481 ns = s_nsOWL;
482 ln = "sameAs";
483 break;
485 case css::rdf::URIs::OWL_DIFFERENTFROM:
486 ns = s_nsOWL;
487 ln = "differentFrom";
488 break;
490 case css::rdf::URIs::OWL_ALLDIFFERENT:
491 ns = s_nsOWL;
492 ln = "AllDifferent";
493 break;
495 case css::rdf::URIs::OWL_DISTINCTMEMBERS:
496 ns = s_nsOWL;
497 ln = "distinctMembers";
498 break;
500 case css::rdf::URIs::OWL_INVERSEOF:
501 ns = s_nsOWL;
502 ln = "inverseOf";
503 break;
505 case css::rdf::URIs::OWL_TRANSITIVEPROPERTY:
506 ns = s_nsOWL;
507 ln = "TransitiveProperty";
508 break;
510 case css::rdf::URIs::OWL_SYMMETRICPROPERTY:
511 ns = s_nsOWL;
512 ln = "SymmetricProperty";
513 break;
515 case css::rdf::URIs::OWL_INVERSEFUNCTIONALPROPERTY:
516 ns = s_nsOWL;
517 ln = "InverseFunctionalProperty";
518 break;
520 case css::rdf::URIs::OWL_RESTRICTION:
521 ns = s_nsOWL;
522 ln = "Restriction";
523 break;
525 case css::rdf::URIs::OWL_ONPROPERTY:
526 ns = s_nsOWL;
527 ln = "onProperty";
528 break;
530 case css::rdf::URIs::OWL_ALLVALUESFROM:
531 ns = s_nsOWL;
532 ln = "allValuesFrom";
533 break;
535 case css::rdf::URIs::OWL_SOMEVALUESFROM:
536 ns = s_nsOWL;
537 ln = "someValuesFrom";
538 break;
540 case css::rdf::URIs::OWL_MINCARDINALITY:
541 ns = s_nsOWL;
542 ln = "minCardinality";
543 break;
545 case css::rdf::URIs::OWL_MAXCARDINALITY:
546 ns = s_nsOWL;
547 ln = "maxCardinality";
548 break;
550 case css::rdf::URIs::OWL_CARDINALITY:
551 ns = s_nsOWL;
552 ln = "cardinality";
553 break;
555 case css::rdf::URIs::OWL_ONTOLOGY:
556 ns = s_nsOWL;
557 ln = "Ontology";
558 break;
560 case css::rdf::URIs::OWL_IMPORTS:
561 ns = s_nsOWL;
562 ln = "imports";
563 break;
565 case css::rdf::URIs::OWL_VERSIONINFO:
566 ns = s_nsOWL;
567 ln = "versionInfo";
568 break;
570 case css::rdf::URIs::OWL_PRIORVERSION:
571 ns = s_nsOWL;
572 ln = "priorVersion";
573 break;
575 case css::rdf::URIs::OWL_BACKWARDCOMPATIBLEWITH:
576 ns = s_nsOWL;
577 ln = "backwardCompatibleWith";
578 break;
580 case css::rdf::URIs::OWL_INCOMPATIBLEWITH:
581 ns = s_nsOWL;
582 ln = "incompatibleWith";
583 break;
585 case css::rdf::URIs::OWL_DEPRECATEDCLASS:
586 ns = s_nsOWL;
587 ln = "DeprecatedClass";
588 break;
590 case css::rdf::URIs::OWL_DEPRECATEDPROPERTY:
591 ns = s_nsOWL;
592 ln = "DeprecatedProperty";
593 break;
595 case css::rdf::URIs::OWL_ANNOTATIONPROPERTY:
596 ns = s_nsOWL;
597 ln = "AnnotationProperty";
598 break;
600 case css::rdf::URIs::OWL_ONTOLOGYPROPERTY:
601 ns = s_nsOWL;
602 ln = "OntologyProperty";
603 break;
605 case css::rdf::URIs::OWL_ONEOF:
606 ns = s_nsOWL;
607 ln = "oneOf";
608 break;
610 case css::rdf::URIs::OWL_DATARANGE:
611 ns = s_nsOWL;
612 ln = "dataRange";
613 break;
615 case css::rdf::URIs::OWL_DISJOINTWITH:
616 ns = s_nsOWL;
617 ln = "disjointWith";
618 break;
620 case css::rdf::URIs::OWL_UNIONOF:
621 ns = s_nsOWL;
622 ln = "unionOf";
623 break;
625 case css::rdf::URIs::OWL_COMPLEMENTOF:
626 ns = s_nsOWL;
627 ln = "complementOf";
628 break;
630 case css::rdf::URIs::OWL_INTERSECTIONOF:
631 ns = s_nsOWL;
632 ln = "intersectionOf";
633 break;
635 case css::rdf::URIs::OWL_HASVALUE:
636 ns = s_nsOWL;
637 ln = "hasValue";
638 break;
641 case css::rdf::URIs::PKG_HASPART:
642 ns = s_nsPkg;
643 ln = "hasPart";
644 break;
646 case css::rdf::URIs::PKG_MIMETYPE:
647 ns = s_nsPkg;
648 ln = "mimeType";
649 break;
651 case css::rdf::URIs::PKG_PACKAGE:
652 ns = s_nsPkg;
653 ln = "Package";
654 break;
656 case css::rdf::URIs::PKG_ELEMENT:
657 ns = s_nsPkg;
658 ln = "Element";
659 break;
661 case css::rdf::URIs::PKG_FILE:
662 ns = s_nsPkg;
663 ln = "File";
664 break;
666 case css::rdf::URIs::PKG_METADATAFILE:
667 ns = s_nsPkg;
668 ln = "MetadataFile";
669 break;
671 case css::rdf::URIs::PKG_DOCUMENT:
672 ns = s_nsPkg;
673 ln = "Document";
674 break;
676 case css::rdf::URIs::ODF_PREFIX:
677 ns = s_nsODF;
678 ln = "prefix";
679 break;
681 case css::rdf::URIs::ODF_SUFFIX:
682 ns = s_nsODF;
683 ln = "suffix";
684 break;
686 case css::rdf::URIs::ODF_ELEMENT:
687 ns = s_nsODF;
688 ln = "Element";
689 break;
691 case css::rdf::URIs::ODF_CONTENTFILE:
692 ns = s_nsODF;
693 ln = "ContentFile";
694 break;
696 case css::rdf::URIs::ODF_STYLESFILE:
697 ns = s_nsODF;
698 ln = "StylesFile";
699 break;
701 default:
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);
718 sal_Int16 arg(0);
719 OUString arg0;
720 OUString arg1;
721 if (aArguments[0] >>= arg) {
722 // integer argument: constant from rdf::URIs
723 if (len != 1) {
724 throw css::lang::IllegalArgumentException(
725 "CURI::initialize: must give 1 int argument", *this, 1);
727 initFromConstant(arg);
728 return;
730 if (!(aArguments[0] >>= arg0)) {
731 throw css::lang::IllegalArgumentException(
732 "CURI::initialize: argument must be string or short", *this, 0);
734 if (len > 1) {
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
740 arg0 = arg0 + arg1;
741 arg1.clear();
744 // split parameter
745 sal_Int32 idx;
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);
763 m_Namespace = arg0;
765 //FIXME: what is legal?
766 if ((false)) {
767 throw css::lang::IllegalArgumentException(
768 "CURI::initialize: argument is not valid local name", *this, 1);
770 m_LocalName = arg1;
773 // css::rdf::XNode:
774 OUString SAL_CALL CURI::getStringValue()
776 return m_Namespace + m_LocalName;
779 // css::rdf::XURI:
780 OUString SAL_CALL CURI::getNamespace()
782 return m_Namespace;
785 OUString SAL_CALL CURI::getLocalName()
787 return m_LocalName;
790 } // closing anonymous implementation namespace
793 // component helper namespace
794 namespace comp_CURI {
796 OUString _getImplementationName() {
797 return
798 "CURI";
801 css::uno::Sequence< OUString > _getSupportedServiceNames()
803 css::uno::Sequence< OUString > s { "com.sun.star.rdf.URI" };
804 return s;
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: */