Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "sal/config.h"
21 :
22 : #include <cassert>
23 : #include <climits>
24 : #include <stack>
25 :
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"
40 :
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"
52 :
53 : namespace configmgr {
54 :
55 : namespace xmldata {
56 :
57 815187 : Type parseType(
58 : xmlreader::XmlReader const & reader, xmlreader::Span const & text)
59 : {
60 : assert(text.is());
61 815187 : sal_Int32 i = rtl_str_indexOfChar_WithLength(text.begin, text.length, ':');
62 815187 : if (i >= 0) {
63 815187 : switch (reader.getNamespaceId(xmlreader::Span(text.begin, i))) {
64 : case ParseManager::NAMESPACE_OOR:
65 36702 : if (xmlreader::Span(text.begin + i + 1, text.length - (i + 1)).
66 36702 : equals(RTL_CONSTASCII_STRINGPARAM("any")))
67 : {
68 294 : return TYPE_ANY;
69 23880 : } else if (xmlreader::Span(
70 11940 : text.begin + i + 1, text.length - (i + 1)).
71 35820 : equals(RTL_CONSTASCII_STRINGPARAM("boolean-list")))
72 : {
73 0 : return TYPE_BOOLEAN_LIST;
74 23880 : } else if (xmlreader::Span(
75 11940 : text.begin + i + 1, text.length - (i + 1)).
76 35820 : equals(RTL_CONSTASCII_STRINGPARAM("short-list")))
77 : {
78 0 : return TYPE_SHORT_LIST;
79 23880 : } else if (xmlreader::Span(
80 11940 : text.begin + i + 1, text.length - (i + 1)).
81 35820 : equals(RTL_CONSTASCII_STRINGPARAM("int-list")))
82 : {
83 294 : return TYPE_INT_LIST;
84 23292 : } else if (xmlreader::Span(
85 11646 : text.begin + i + 1, text.length - (i + 1)).
86 34938 : equals(RTL_CONSTASCII_STRINGPARAM("long-list")))
87 : {
88 98 : return TYPE_LONG_LIST;
89 23096 : } else if (xmlreader::Span(
90 11548 : text.begin + i + 1, text.length - (i + 1)).
91 34644 : equals(RTL_CONSTASCII_STRINGPARAM("double-list")))
92 : {
93 0 : return TYPE_DOUBLE_LIST;
94 23096 : } else if (xmlreader::Span(
95 11548 : text.begin + i + 1, text.length - (i + 1)).
96 34644 : equals(RTL_CONSTASCII_STRINGPARAM("string-list")))
97 : {
98 11548 : return TYPE_STRING_LIST;
99 0 : } else if (xmlreader::Span(
100 0 : text.begin + i + 1, text.length - (i + 1)).
101 0 : equals(RTL_CONSTASCII_STRINGPARAM("hexBinary-list")))
102 : {
103 0 : return TYPE_HEXBINARY_LIST;
104 : }
105 0 : break;
106 : case ParseManager::NAMESPACE_XS:
107 2408859 : if (xmlreader::Span(text.begin + i + 1, text.length - (i + 1)).
108 2408859 : equals(RTL_CONSTASCII_STRINGPARAM("boolean")))
109 : {
110 186870 : return TYPE_BOOLEAN;
111 1232166 : } else if (xmlreader::Span(
112 616083 : text.begin + i + 1, text.length - (i + 1)).
113 1848249 : equals(RTL_CONSTASCII_STRINGPARAM("short")))
114 : {
115 11074 : return TYPE_SHORT;
116 1210018 : } else if (xmlreader::Span(
117 605009 : text.begin + i + 1, text.length - (i + 1)).
118 1815027 : equals(RTL_CONSTASCII_STRINGPARAM("int")))
119 : {
120 166592 : return TYPE_INT;
121 876834 : } else if (xmlreader::Span(
122 438417 : text.begin + i + 1, text.length - (i + 1)).
123 1315251 : equals(RTL_CONSTASCII_STRINGPARAM("long")))
124 : {
125 2512 : return TYPE_LONG;
126 871810 : } else if (xmlreader::Span(
127 435905 : text.begin + i + 1, text.length - (i + 1)).
128 1307715 : equals(RTL_CONSTASCII_STRINGPARAM("double")))
129 : {
130 4900 : return TYPE_DOUBLE;
131 862010 : } else if (xmlreader::Span(
132 431005 : text.begin + i + 1, text.length - (i + 1)).
133 1293015 : equals(RTL_CONSTASCII_STRINGPARAM("string")))
134 : {
135 430417 : return TYPE_STRING;
136 1176 : } else if (xmlreader::Span(
137 588 : text.begin + i + 1, text.length - (i + 1)).
138 1764 : equals(RTL_CONSTASCII_STRINGPARAM("hexBinary")))
139 : {
140 588 : return TYPE_HEXBINARY;
141 : }
142 0 : break;
143 : default:
144 0 : break;
145 : }
146 : }
147 : throw css::uno::RuntimeException(
148 : (OUString("invalid type ") +
149 0 : text.convertFromUtf8()),
150 0 : css::uno::Reference< css::uno::XInterface >());
151 : }
152 :
153 336941 : bool parseBoolean(xmlreader::Span const & text) {
154 : assert(text.is());
155 336941 : if (text.equals(RTL_CONSTASCII_STRINGPARAM("true"))) {
156 202551 : return true;
157 : }
158 134390 : if (text.equals(RTL_CONSTASCII_STRINGPARAM("false"))) {
159 134390 : return false;
160 : }
161 : throw css::uno::RuntimeException(
162 : (OUString("invalid boolean ") +
163 0 : text.convertFromUtf8()),
164 0 : css::uno::Reference< css::uno::XInterface >());
165 : }
166 :
167 787991 : OUString parseTemplateReference(
168 : OUString const & component, bool hasNodeType,
169 : OUString const & nodeType, OUString const * defaultTemplateName)
170 : {
171 787991 : if (!hasNodeType) {
172 760379 : if (defaultTemplateName != 0) {
173 760379 : return *defaultTemplateName;
174 : }
175 : throw css::uno::RuntimeException(
176 : OUString("missing node-type attribute"),
177 0 : css::uno::Reference< css::uno::XInterface >());
178 : }
179 27612 : return Data::fullTemplateName(component, nodeType);
180 : }
181 :
182 : }
183 :
184 : }
185 :
186 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|