bump product version to 5.0.4.1
[LibreOffice.git] / configmgr / source / xmldata.cxx
blob95a7891bef70d2722b60e38f0cfb75924f77296b
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>
23 #include <climits>
24 #include <stack>
26 #include <com/sun/star/uno/Any.hxx>
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <com/sun/star/uno/RuntimeException.hpp>
29 #include <com/sun/star/uno/XInterface.hpp>
30 #include <osl/file.hxx>
31 #include <rtl/ref.hxx>
32 #include <rtl/string.h>
33 #include <rtl/ustring.hxx>
34 #include <sal/types.h>
35 #include <xmlreader/span.hxx>
36 #include <xmlreader/xmlreader.hxx>
38 #include "data.hxx"
39 #include "groupnode.hxx"
40 #include "localizedpropertynode.hxx"
41 #include "localizedvaluenode.hxx"
42 #include "node.hxx"
43 #include "nodemap.hxx"
44 #include "parsemanager.hxx"
45 #include "parser.hxx"
46 #include "propertynode.hxx"
47 #include "setnode.hxx"
48 #include "type.hxx"
49 #include "xmldata.hxx"
51 namespace configmgr {
53 namespace xmldata {
55 Type parseType(
56 xmlreader::XmlReader const & reader, xmlreader::Span const & text)
58 assert(text.is());
59 sal_Int32 i = rtl_str_indexOfChar_WithLength(text.begin, text.length, ':');
60 if (i >= 0) {
61 switch (reader.getNamespaceId(xmlreader::Span(text.begin, i))) {
62 case ParseManager::NAMESPACE_OOR:
63 if (xmlreader::Span(text.begin + i + 1, text.length - (i + 1)).
64 equals("any"))
66 return TYPE_ANY;
67 } else if (xmlreader::Span(
68 text.begin + i + 1, text.length - (i + 1)).
69 equals("boolean-list"))
71 return TYPE_BOOLEAN_LIST;
72 } else if (xmlreader::Span(
73 text.begin + i + 1, text.length - (i + 1)).
74 equals("short-list"))
76 return TYPE_SHORT_LIST;
77 } else if (xmlreader::Span(
78 text.begin + i + 1, text.length - (i + 1)).
79 equals("int-list"))
81 return TYPE_INT_LIST;
82 } else if (xmlreader::Span(
83 text.begin + i + 1, text.length - (i + 1)).
84 equals("long-list"))
86 return TYPE_LONG_LIST;
87 } else if (xmlreader::Span(
88 text.begin + i + 1, text.length - (i + 1)).
89 equals("double-list"))
91 return TYPE_DOUBLE_LIST;
92 } else if (xmlreader::Span(
93 text.begin + i + 1, text.length - (i + 1)).
94 equals("string-list"))
96 return TYPE_STRING_LIST;
97 } else if (xmlreader::Span(
98 text.begin + i + 1, text.length - (i + 1)).
99 equals("hexBinary-list"))
101 return TYPE_HEXBINARY_LIST;
103 break;
104 case ParseManager::NAMESPACE_XS:
105 if (xmlreader::Span(text.begin + i + 1, text.length - (i + 1)).
106 equals("boolean"))
108 return TYPE_BOOLEAN;
109 } else if (xmlreader::Span(
110 text.begin + i + 1, text.length - (i + 1)).
111 equals("short"))
113 return TYPE_SHORT;
114 } else if (xmlreader::Span(
115 text.begin + i + 1, text.length - (i + 1)).
116 equals("int"))
118 return TYPE_INT;
119 } else if (xmlreader::Span(
120 text.begin + i + 1, text.length - (i + 1)).
121 equals("long"))
123 return TYPE_LONG;
124 } else if (xmlreader::Span(
125 text.begin + i + 1, text.length - (i + 1)).
126 equals("double"))
128 return TYPE_DOUBLE;
129 } else if (xmlreader::Span(
130 text.begin + i + 1, text.length - (i + 1)).
131 equals("string"))
133 return TYPE_STRING;
134 } else if (xmlreader::Span(
135 text.begin + i + 1, text.length - (i + 1)).
136 equals("hexBinary"))
138 return TYPE_HEXBINARY;
140 break;
141 default:
142 break;
145 throw css::uno::RuntimeException(
146 "invalid type " + text.convertFromUtf8());
149 bool parseBoolean(xmlreader::Span const & text) {
150 assert(text.is());
151 if (text.equals("true")) {
152 return true;
154 if (text.equals("false")) {
155 return false;
157 throw css::uno::RuntimeException(
158 "invalid boolean " + text.convertFromUtf8());
161 OUString parseTemplateReference(
162 OUString const & component, bool hasNodeType,
163 OUString const & nodeType, OUString const * defaultTemplateName)
165 if (!hasNodeType) {
166 if (defaultTemplateName != 0) {
167 return *defaultTemplateName;
169 throw css::uno::RuntimeException(
170 "missing node-type attribute");
172 return Data::fullTemplateName(component, nodeType);
179 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */