Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / configmgr / source / xmldata.cxx
blobe919d08e7824882d09fe041de37b7847dc89f420
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 <sal/config.h>
22 #include <cassert>
24 #include <com/sun/star/uno/RuntimeException.hpp>
25 #include <rtl/string.h>
26 #include <rtl/ustring.hxx>
27 #include <sal/types.h>
28 #include <xmlreader/span.hxx>
29 #include <xmlreader/xmlreader.hxx>
31 #include "data.hxx"
32 #include "parsemanager.hxx"
33 #include "type.hxx"
34 #include "xmldata.hxx"
36 namespace configmgr {
38 namespace xmldata {
40 Type parseType(
41 xmlreader::XmlReader const & reader, xmlreader::Span const & text)
43 assert(text.is());
44 sal_Int32 i = rtl_str_indexOfChar_WithLength(text.begin, text.length, ':');
45 if (i >= 0) {
46 xmlreader::Span token(text.begin + i + 1, text.length - (i + 1));
47 switch (reader.getNamespaceId(xmlreader::Span(text.begin, i))) {
48 case ParseManager::NAMESPACE_OOR:
49 if (token == "any")
51 return TYPE_ANY;
52 } else if (token == "boolean-list")
54 return TYPE_BOOLEAN_LIST;
55 } else if (token == "short-list")
57 return TYPE_SHORT_LIST;
58 } else if (token == "int-list")
60 return TYPE_INT_LIST;
61 } else if (token == "long-list")
63 return TYPE_LONG_LIST;
64 } else if (token == "double-list")
66 return TYPE_DOUBLE_LIST;
67 } else if (token == "string-list")
69 return TYPE_STRING_LIST;
70 } else if (token == "hexBinary-list")
72 return TYPE_HEXBINARY_LIST;
74 break;
75 case ParseManager::NAMESPACE_XS:
76 if (token == "boolean")
78 return TYPE_BOOLEAN;
79 } else if (token =="short")
81 return TYPE_SHORT;
82 } else if (token =="int")
84 return TYPE_INT;
85 } else if (token =="long")
87 return TYPE_LONG;
88 } else if (token =="double")
90 return TYPE_DOUBLE;
91 } else if (token =="string")
93 return TYPE_STRING;
94 } else if (token =="hexBinary")
96 return TYPE_HEXBINARY;
98 break;
99 default:
100 break;
103 throw css::uno::RuntimeException(
104 "invalid type " + text.convertFromUtf8());
107 bool parseBoolean(xmlreader::Span const & text) {
108 assert(text.is());
109 if (text == "true") {
110 return true;
112 if (text == "false") {
113 return false;
115 throw css::uno::RuntimeException(
116 "invalid boolean " + text.convertFromUtf8());
119 OUString parseTemplateReference(
120 OUString const & component, bool hasNodeType,
121 OUString const & nodeType, OUString const * defaultTemplateName)
123 if (!hasNodeType) {
124 if (defaultTemplateName != nullptr) {
125 return *defaultTemplateName;
127 throw css::uno::RuntimeException(
128 "missing node-type attribute");
130 return Data::fullTemplateName(component, nodeType);
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */