1*3a7cf181SAndrew Rist /**************************************************************
2*3a7cf181SAndrew Rist *
3*3a7cf181SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*3a7cf181SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*3a7cf181SAndrew Rist * distributed with this work for additional information
6*3a7cf181SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*3a7cf181SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*3a7cf181SAndrew Rist * "License"); you may not use this file except in compliance
9*3a7cf181SAndrew Rist * with the License. You may obtain a copy of the License at
10*3a7cf181SAndrew Rist *
11*3a7cf181SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*3a7cf181SAndrew Rist *
13*3a7cf181SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*3a7cf181SAndrew Rist * software distributed under the License is distributed on an
15*3a7cf181SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3a7cf181SAndrew Rist * KIND, either express or implied. See the License for the
17*3a7cf181SAndrew Rist * specific language governing permissions and limitations
18*3a7cf181SAndrew Rist * under the License.
19*3a7cf181SAndrew Rist *
20*3a7cf181SAndrew Rist *************************************************************/
21*3a7cf181SAndrew Rist
22*3a7cf181SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "precompiled_configmgr.hxx"
25cdf0e10cSrcweir #include "sal/config.h"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <climits>
28cdf0e10cSrcweir #include <stack>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include "com/sun/star/uno/Any.hxx"
31cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
32cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
33cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
34cdf0e10cSrcweir #include "osl/diagnose.h"
35cdf0e10cSrcweir #include "osl/file.hxx"
36cdf0e10cSrcweir #include "rtl/ref.hxx"
37cdf0e10cSrcweir #include "rtl/strbuf.hxx"
38cdf0e10cSrcweir #include "rtl/string.h"
39cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
40cdf0e10cSrcweir #include "rtl/ustring.h"
41cdf0e10cSrcweir #include "rtl/ustring.hxx"
42cdf0e10cSrcweir #include "sal/types.h"
43cdf0e10cSrcweir #include "xmlreader/span.hxx"
44cdf0e10cSrcweir #include "xmlreader/xmlreader.hxx"
45cdf0e10cSrcweir
46cdf0e10cSrcweir #include "data.hxx"
47cdf0e10cSrcweir #include "groupnode.hxx"
48cdf0e10cSrcweir #include "localizedpropertynode.hxx"
49cdf0e10cSrcweir #include "localizedvaluenode.hxx"
50cdf0e10cSrcweir #include "node.hxx"
51cdf0e10cSrcweir #include "nodemap.hxx"
52cdf0e10cSrcweir #include "parsemanager.hxx"
53cdf0e10cSrcweir #include "parser.hxx"
54cdf0e10cSrcweir #include "propertynode.hxx"
55cdf0e10cSrcweir #include "setnode.hxx"
56cdf0e10cSrcweir #include "type.hxx"
57cdf0e10cSrcweir
58cdf0e10cSrcweir namespace configmgr {
59cdf0e10cSrcweir
60cdf0e10cSrcweir namespace xmldata {
61cdf0e10cSrcweir
62cdf0e10cSrcweir namespace {
63cdf0e10cSrcweir
64cdf0e10cSrcweir namespace css = com::sun::star;
65cdf0e10cSrcweir
66cdf0e10cSrcweir }
67cdf0e10cSrcweir
parseType(xmlreader::XmlReader const & reader,xmlreader::Span const & text)68cdf0e10cSrcweir Type parseType(
69cdf0e10cSrcweir xmlreader::XmlReader const & reader, xmlreader::Span const & text)
70cdf0e10cSrcweir {
71cdf0e10cSrcweir OSL_ASSERT(text.is());
72cdf0e10cSrcweir sal_Int32 i = rtl_str_indexOfChar_WithLength(text.begin, text.length, ':');
73cdf0e10cSrcweir if (i >= 0) {
74cdf0e10cSrcweir switch (reader.getNamespaceId(xmlreader::Span(text.begin, i))) {
75cdf0e10cSrcweir case ParseManager::NAMESPACE_OOR:
76cdf0e10cSrcweir if (xmlreader::Span(text.begin + i + 1, text.length - (i + 1)).
77cdf0e10cSrcweir equals(RTL_CONSTASCII_STRINGPARAM("any")))
78cdf0e10cSrcweir {
79cdf0e10cSrcweir return TYPE_ANY;
80cdf0e10cSrcweir } else if (xmlreader::Span(
81cdf0e10cSrcweir text.begin + i + 1, text.length - (i + 1)).
82cdf0e10cSrcweir equals(RTL_CONSTASCII_STRINGPARAM("boolean-list")))
83cdf0e10cSrcweir {
84cdf0e10cSrcweir return TYPE_BOOLEAN_LIST;
85cdf0e10cSrcweir } else if (xmlreader::Span(
86cdf0e10cSrcweir text.begin + i + 1, text.length - (i + 1)).
87cdf0e10cSrcweir equals(RTL_CONSTASCII_STRINGPARAM("short-list")))
88cdf0e10cSrcweir {
89cdf0e10cSrcweir return TYPE_SHORT_LIST;
90cdf0e10cSrcweir } else if (xmlreader::Span(
91cdf0e10cSrcweir text.begin + i + 1, text.length - (i + 1)).
92cdf0e10cSrcweir equals(RTL_CONSTASCII_STRINGPARAM("int-list")))
93cdf0e10cSrcweir {
94cdf0e10cSrcweir return TYPE_INT_LIST;
95cdf0e10cSrcweir } else if (xmlreader::Span(
96cdf0e10cSrcweir text.begin + i + 1, text.length - (i + 1)).
97cdf0e10cSrcweir equals(RTL_CONSTASCII_STRINGPARAM("long-list")))
98cdf0e10cSrcweir {
99cdf0e10cSrcweir return TYPE_LONG_LIST;
100cdf0e10cSrcweir } else if (xmlreader::Span(
101cdf0e10cSrcweir text.begin + i + 1, text.length - (i + 1)).
102cdf0e10cSrcweir equals(RTL_CONSTASCII_STRINGPARAM("double-list")))
103cdf0e10cSrcweir {
104cdf0e10cSrcweir return TYPE_DOUBLE_LIST;
105cdf0e10cSrcweir } else if (xmlreader::Span(
106cdf0e10cSrcweir text.begin + i + 1, text.length - (i + 1)).
107cdf0e10cSrcweir equals(RTL_CONSTASCII_STRINGPARAM("string-list")))
108cdf0e10cSrcweir {
109cdf0e10cSrcweir return TYPE_STRING_LIST;
110cdf0e10cSrcweir } else if (xmlreader::Span(
111cdf0e10cSrcweir text.begin + i + 1, text.length - (i + 1)).
112cdf0e10cSrcweir equals(RTL_CONSTASCII_STRINGPARAM("hexBinary-list")))
113cdf0e10cSrcweir {
114cdf0e10cSrcweir return TYPE_HEXBINARY_LIST;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir break;
117cdf0e10cSrcweir case ParseManager::NAMESPACE_XS:
118cdf0e10cSrcweir if (xmlreader::Span(text.begin + i + 1, text.length - (i + 1)).
119cdf0e10cSrcweir equals(RTL_CONSTASCII_STRINGPARAM("boolean")))
120cdf0e10cSrcweir {
121cdf0e10cSrcweir return TYPE_BOOLEAN;
122cdf0e10cSrcweir } else if (xmlreader::Span(
123cdf0e10cSrcweir text.begin + i + 1, text.length - (i + 1)).
124cdf0e10cSrcweir equals(RTL_CONSTASCII_STRINGPARAM("short")))
125cdf0e10cSrcweir {
126cdf0e10cSrcweir return TYPE_SHORT;
127cdf0e10cSrcweir } else if (xmlreader::Span(
128cdf0e10cSrcweir text.begin + i + 1, text.length - (i + 1)).
129cdf0e10cSrcweir equals(RTL_CONSTASCII_STRINGPARAM("int")))
130cdf0e10cSrcweir {
131cdf0e10cSrcweir return TYPE_INT;
132cdf0e10cSrcweir } else if (xmlreader::Span(
133cdf0e10cSrcweir text.begin + i + 1, text.length - (i + 1)).
134cdf0e10cSrcweir equals(RTL_CONSTASCII_STRINGPARAM("long")))
135cdf0e10cSrcweir {
136cdf0e10cSrcweir return TYPE_LONG;
137cdf0e10cSrcweir } else if (xmlreader::Span(
138cdf0e10cSrcweir text.begin + i + 1, text.length - (i + 1)).
139cdf0e10cSrcweir equals(RTL_CONSTASCII_STRINGPARAM("double")))
140cdf0e10cSrcweir {
141cdf0e10cSrcweir return TYPE_DOUBLE;
142cdf0e10cSrcweir } else if (xmlreader::Span(
143cdf0e10cSrcweir text.begin + i + 1, text.length - (i + 1)).
144cdf0e10cSrcweir equals(RTL_CONSTASCII_STRINGPARAM("string")))
145cdf0e10cSrcweir {
146cdf0e10cSrcweir return TYPE_STRING;
147cdf0e10cSrcweir } else if (xmlreader::Span(
148cdf0e10cSrcweir text.begin + i + 1, text.length - (i + 1)).
149cdf0e10cSrcweir equals(RTL_CONSTASCII_STRINGPARAM("hexBinary")))
150cdf0e10cSrcweir {
151cdf0e10cSrcweir return TYPE_HEXBINARY;
152cdf0e10cSrcweir }
153cdf0e10cSrcweir break;
154cdf0e10cSrcweir default:
155cdf0e10cSrcweir break;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir }
158cdf0e10cSrcweir throw css::uno::RuntimeException(
159cdf0e10cSrcweir (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("invalid type ")) +
160cdf0e10cSrcweir text.convertFromUtf8()),
161cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >());
162cdf0e10cSrcweir }
163cdf0e10cSrcweir
parseBoolean(xmlreader::Span const & text)164cdf0e10cSrcweir bool parseBoolean(xmlreader::Span const & text) {
165cdf0e10cSrcweir OSL_ASSERT(text.is());
166cdf0e10cSrcweir if (text.equals(RTL_CONSTASCII_STRINGPARAM("true"))) {
167cdf0e10cSrcweir return true;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir if (text.equals(RTL_CONSTASCII_STRINGPARAM("false"))) {
170cdf0e10cSrcweir return false;
171cdf0e10cSrcweir }
172cdf0e10cSrcweir throw css::uno::RuntimeException(
173cdf0e10cSrcweir (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("invalid boolean ")) +
174cdf0e10cSrcweir text.convertFromUtf8()),
175cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >());
176cdf0e10cSrcweir }
177cdf0e10cSrcweir
parseTemplateReference(rtl::OUString const & component,bool hasNodeType,rtl::OUString const & nodeType,rtl::OUString const * defaultTemplateName)178cdf0e10cSrcweir rtl::OUString parseTemplateReference(
179cdf0e10cSrcweir rtl::OUString const & component, bool hasNodeType,
180cdf0e10cSrcweir rtl::OUString const & nodeType, rtl::OUString const * defaultTemplateName)
181cdf0e10cSrcweir {
182cdf0e10cSrcweir if (!hasNodeType) {
183cdf0e10cSrcweir if (defaultTemplateName != 0) {
184cdf0e10cSrcweir return *defaultTemplateName;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir throw css::uno::RuntimeException(
187cdf0e10cSrcweir rtl::OUString(
188cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM("missing node-type attribute")),
189cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface >());
190cdf0e10cSrcweir }
191cdf0e10cSrcweir return Data::fullTemplateName(component, nodeType);
192cdf0e10cSrcweir }
193cdf0e10cSrcweir
194cdf0e10cSrcweir }
195cdf0e10cSrcweir
196cdf0e10cSrcweir }
197