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