Bump version to 4.1-6
[LibreOffice.git] / configmgr / source / xmldata.cxx
blob577e1e68d38b5080936a67c27aa05f0883a4469d
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"
50 namespace configmgr {
52 namespace xmldata {
54 Type parseType(
55 xmlreader::XmlReader const & reader, xmlreader::Span const & text)
57 assert(text.is());
58 sal_Int32 i = rtl_str_indexOfChar_WithLength(text.begin, text.length, ':');
59 if (i >= 0) {
60 switch (reader.getNamespaceId(xmlreader::Span(text.begin, i))) {
61 case ParseManager::NAMESPACE_OOR:
62 if (xmlreader::Span(text.begin + i + 1, text.length - (i + 1)).
63 equals("any"))
65 return TYPE_ANY;
66 } else if (xmlreader::Span(
67 text.begin + i + 1, text.length - (i + 1)).
68 equals("boolean-list"))
70 return TYPE_BOOLEAN_LIST;
71 } else if (xmlreader::Span(
72 text.begin + i + 1, text.length - (i + 1)).
73 equals("short-list"))
75 return TYPE_SHORT_LIST;
76 } else if (xmlreader::Span(
77 text.begin + i + 1, text.length - (i + 1)).
78 equals("int-list"))
80 return TYPE_INT_LIST;
81 } else if (xmlreader::Span(
82 text.begin + i + 1, text.length - (i + 1)).
83 equals("long-list"))
85 return TYPE_LONG_LIST;
86 } else if (xmlreader::Span(
87 text.begin + i + 1, text.length - (i + 1)).
88 equals("double-list"))
90 return TYPE_DOUBLE_LIST;
91 } else if (xmlreader::Span(
92 text.begin + i + 1, text.length - (i + 1)).
93 equals("string-list"))
95 return TYPE_STRING_LIST;
96 } else if (xmlreader::Span(
97 text.begin + i + 1, text.length - (i + 1)).
98 equals("hexBinary-list"))
100 return TYPE_HEXBINARY_LIST;
102 break;
103 case ParseManager::NAMESPACE_XS:
104 if (xmlreader::Span(text.begin + i + 1, text.length - (i + 1)).
105 equals("boolean"))
107 return TYPE_BOOLEAN;
108 } else if (xmlreader::Span(
109 text.begin + i + 1, text.length - (i + 1)).
110 equals("short"))
112 return TYPE_SHORT;
113 } else if (xmlreader::Span(
114 text.begin + i + 1, text.length - (i + 1)).
115 equals("int"))
117 return TYPE_INT;
118 } else if (xmlreader::Span(
119 text.begin + i + 1, text.length - (i + 1)).
120 equals("long"))
122 return TYPE_LONG;
123 } else if (xmlreader::Span(
124 text.begin + i + 1, text.length - (i + 1)).
125 equals("double"))
127 return TYPE_DOUBLE;
128 } else if (xmlreader::Span(
129 text.begin + i + 1, text.length - (i + 1)).
130 equals("string"))
132 return TYPE_STRING;
133 } else if (xmlreader::Span(
134 text.begin + i + 1, text.length - (i + 1)).
135 equals("hexBinary"))
137 return TYPE_HEXBINARY;
139 break;
140 default:
141 break;
144 throw css::uno::RuntimeException(
145 "invalid type " + text.convertFromUtf8(),
146 css::uno::Reference< css::uno::XInterface >());
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(),
159 css::uno::Reference< css::uno::XInterface >());
162 OUString parseTemplateReference(
163 OUString const & component, bool hasNodeType,
164 OUString const & nodeType, OUString const * defaultTemplateName)
166 if (!hasNodeType) {
167 if (defaultTemplateName != 0) {
168 return *defaultTemplateName;
170 throw css::uno::RuntimeException(
171 "missing node-type attribute",
172 css::uno::Reference< css::uno::XInterface >());
174 return Data::fullTemplateName(component, nodeType);
181 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */