Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / configmgr / source / xmldata.cxx
blob6e3def05159c7d0065ebc4e780f207e327d22a8d
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/strbuf.hxx"
33 #include "rtl/string.h"
34 #include "rtl/ustrbuf.hxx"
35 #include "rtl/ustring.h"
36 #include "rtl/ustring.hxx"
37 #include "sal/types.h"
38 #include "xmlreader/span.hxx"
39 #include "xmlreader/xmlreader.hxx"
41 #include "data.hxx"
42 #include "groupnode.hxx"
43 #include "localizedpropertynode.hxx"
44 #include "localizedvaluenode.hxx"
45 #include "node.hxx"
46 #include "nodemap.hxx"
47 #include "parsemanager.hxx"
48 #include "parser.hxx"
49 #include "propertynode.hxx"
50 #include "setnode.hxx"
51 #include "type.hxx"
53 namespace configmgr {
55 namespace xmldata {
57 Type parseType(
58 xmlreader::XmlReader const & reader, xmlreader::Span const & text)
60 assert(text.is());
61 sal_Int32 i = rtl_str_indexOfChar_WithLength(text.begin, text.length, ':');
62 if (i >= 0) {
63 switch (reader.getNamespaceId(xmlreader::Span(text.begin, i))) {
64 case ParseManager::NAMESPACE_OOR:
65 if (xmlreader::Span(text.begin + i + 1, text.length - (i + 1)).
66 equals(RTL_CONSTASCII_STRINGPARAM("any")))
68 return TYPE_ANY;
69 } else if (xmlreader::Span(
70 text.begin + i + 1, text.length - (i + 1)).
71 equals(RTL_CONSTASCII_STRINGPARAM("boolean-list")))
73 return TYPE_BOOLEAN_LIST;
74 } else if (xmlreader::Span(
75 text.begin + i + 1, text.length - (i + 1)).
76 equals(RTL_CONSTASCII_STRINGPARAM("short-list")))
78 return TYPE_SHORT_LIST;
79 } else if (xmlreader::Span(
80 text.begin + i + 1, text.length - (i + 1)).
81 equals(RTL_CONSTASCII_STRINGPARAM("int-list")))
83 return TYPE_INT_LIST;
84 } else if (xmlreader::Span(
85 text.begin + i + 1, text.length - (i + 1)).
86 equals(RTL_CONSTASCII_STRINGPARAM("long-list")))
88 return TYPE_LONG_LIST;
89 } else if (xmlreader::Span(
90 text.begin + i + 1, text.length - (i + 1)).
91 equals(RTL_CONSTASCII_STRINGPARAM("double-list")))
93 return TYPE_DOUBLE_LIST;
94 } else if (xmlreader::Span(
95 text.begin + i + 1, text.length - (i + 1)).
96 equals(RTL_CONSTASCII_STRINGPARAM("string-list")))
98 return TYPE_STRING_LIST;
99 } else if (xmlreader::Span(
100 text.begin + i + 1, text.length - (i + 1)).
101 equals(RTL_CONSTASCII_STRINGPARAM("hexBinary-list")))
103 return TYPE_HEXBINARY_LIST;
105 break;
106 case ParseManager::NAMESPACE_XS:
107 if (xmlreader::Span(text.begin + i + 1, text.length - (i + 1)).
108 equals(RTL_CONSTASCII_STRINGPARAM("boolean")))
110 return TYPE_BOOLEAN;
111 } else if (xmlreader::Span(
112 text.begin + i + 1, text.length - (i + 1)).
113 equals(RTL_CONSTASCII_STRINGPARAM("short")))
115 return TYPE_SHORT;
116 } else if (xmlreader::Span(
117 text.begin + i + 1, text.length - (i + 1)).
118 equals(RTL_CONSTASCII_STRINGPARAM("int")))
120 return TYPE_INT;
121 } else if (xmlreader::Span(
122 text.begin + i + 1, text.length - (i + 1)).
123 equals(RTL_CONSTASCII_STRINGPARAM("long")))
125 return TYPE_LONG;
126 } else if (xmlreader::Span(
127 text.begin + i + 1, text.length - (i + 1)).
128 equals(RTL_CONSTASCII_STRINGPARAM("double")))
130 return TYPE_DOUBLE;
131 } else if (xmlreader::Span(
132 text.begin + i + 1, text.length - (i + 1)).
133 equals(RTL_CONSTASCII_STRINGPARAM("string")))
135 return TYPE_STRING;
136 } else if (xmlreader::Span(
137 text.begin + i + 1, text.length - (i + 1)).
138 equals(RTL_CONSTASCII_STRINGPARAM("hexBinary")))
140 return TYPE_HEXBINARY;
142 break;
143 default:
144 break;
147 throw css::uno::RuntimeException(
148 (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("invalid type ")) +
149 text.convertFromUtf8()),
150 css::uno::Reference< css::uno::XInterface >());
153 bool parseBoolean(xmlreader::Span const & text) {
154 assert(text.is());
155 if (text.equals(RTL_CONSTASCII_STRINGPARAM("true"))) {
156 return true;
158 if (text.equals(RTL_CONSTASCII_STRINGPARAM("false"))) {
159 return false;
161 throw css::uno::RuntimeException(
162 (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("invalid boolean ")) +
163 text.convertFromUtf8()),
164 css::uno::Reference< css::uno::XInterface >());
167 rtl::OUString parseTemplateReference(
168 rtl::OUString const & component, bool hasNodeType,
169 rtl::OUString const & nodeType, rtl::OUString const * defaultTemplateName)
171 if (!hasNodeType) {
172 if (defaultTemplateName != 0) {
173 return *defaultTemplateName;
175 throw css::uno::RuntimeException(
176 rtl::OUString(
177 RTL_CONSTASCII_USTRINGPARAM("missing node-type attribute")),
178 css::uno::Reference< css::uno::XInterface >());
180 return Data::fullTemplateName(component, nodeType);
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */