xref: /AOO41X/main/configmgr/source/xmldata.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir *
3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir *
5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir *
7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir *
9*cdf0e10cSrcweir * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir *
11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir *
15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir *
21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir *
26*cdf0e10cSrcweir ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "precompiled_configmgr.hxx"
29*cdf0e10cSrcweir #include "sal/config.h"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <climits>
32*cdf0e10cSrcweir #include <stack>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #include "com/sun/star/uno/Any.hxx"
35*cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
36*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
37*cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
38*cdf0e10cSrcweir #include "osl/diagnose.h"
39*cdf0e10cSrcweir #include "osl/file.hxx"
40*cdf0e10cSrcweir #include "rtl/ref.hxx"
41*cdf0e10cSrcweir #include "rtl/strbuf.hxx"
42*cdf0e10cSrcweir #include "rtl/string.h"
43*cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
44*cdf0e10cSrcweir #include "rtl/ustring.h"
45*cdf0e10cSrcweir #include "rtl/ustring.hxx"
46*cdf0e10cSrcweir #include "sal/types.h"
47*cdf0e10cSrcweir #include "xmlreader/span.hxx"
48*cdf0e10cSrcweir #include "xmlreader/xmlreader.hxx"
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include "data.hxx"
51*cdf0e10cSrcweir #include "groupnode.hxx"
52*cdf0e10cSrcweir #include "localizedpropertynode.hxx"
53*cdf0e10cSrcweir #include "localizedvaluenode.hxx"
54*cdf0e10cSrcweir #include "node.hxx"
55*cdf0e10cSrcweir #include "nodemap.hxx"
56*cdf0e10cSrcweir #include "parsemanager.hxx"
57*cdf0e10cSrcweir #include "parser.hxx"
58*cdf0e10cSrcweir #include "propertynode.hxx"
59*cdf0e10cSrcweir #include "setnode.hxx"
60*cdf0e10cSrcweir #include "type.hxx"
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir namespace configmgr {
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir namespace xmldata {
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir namespace {
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir namespace css = com::sun::star;
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir }
71*cdf0e10cSrcweir 
72*cdf0e10cSrcweir Type parseType(
73*cdf0e10cSrcweir     xmlreader::XmlReader const & reader, xmlreader::Span const & text)
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir     OSL_ASSERT(text.is());
76*cdf0e10cSrcweir     sal_Int32 i = rtl_str_indexOfChar_WithLength(text.begin, text.length, ':');
77*cdf0e10cSrcweir     if (i >= 0) {
78*cdf0e10cSrcweir         switch (reader.getNamespaceId(xmlreader::Span(text.begin, i))) {
79*cdf0e10cSrcweir         case ParseManager::NAMESPACE_OOR:
80*cdf0e10cSrcweir             if (xmlreader::Span(text.begin + i + 1, text.length - (i + 1)).
81*cdf0e10cSrcweir                 equals(RTL_CONSTASCII_STRINGPARAM("any")))
82*cdf0e10cSrcweir             {
83*cdf0e10cSrcweir                 return TYPE_ANY;
84*cdf0e10cSrcweir             } else if (xmlreader::Span(
85*cdf0e10cSrcweir                            text.begin + i + 1, text.length - (i + 1)).
86*cdf0e10cSrcweir                        equals(RTL_CONSTASCII_STRINGPARAM("boolean-list")))
87*cdf0e10cSrcweir             {
88*cdf0e10cSrcweir                 return TYPE_BOOLEAN_LIST;
89*cdf0e10cSrcweir             } else if (xmlreader::Span(
90*cdf0e10cSrcweir                            text.begin + i + 1, text.length - (i + 1)).
91*cdf0e10cSrcweir                        equals(RTL_CONSTASCII_STRINGPARAM("short-list")))
92*cdf0e10cSrcweir             {
93*cdf0e10cSrcweir                 return TYPE_SHORT_LIST;
94*cdf0e10cSrcweir             } else if (xmlreader::Span(
95*cdf0e10cSrcweir                            text.begin + i + 1, text.length - (i + 1)).
96*cdf0e10cSrcweir                        equals(RTL_CONSTASCII_STRINGPARAM("int-list")))
97*cdf0e10cSrcweir             {
98*cdf0e10cSrcweir                 return TYPE_INT_LIST;
99*cdf0e10cSrcweir             } else if (xmlreader::Span(
100*cdf0e10cSrcweir                            text.begin + i + 1, text.length - (i + 1)).
101*cdf0e10cSrcweir                        equals(RTL_CONSTASCII_STRINGPARAM("long-list")))
102*cdf0e10cSrcweir             {
103*cdf0e10cSrcweir                 return TYPE_LONG_LIST;
104*cdf0e10cSrcweir             } else if (xmlreader::Span(
105*cdf0e10cSrcweir                            text.begin + i + 1, text.length - (i + 1)).
106*cdf0e10cSrcweir                        equals(RTL_CONSTASCII_STRINGPARAM("double-list")))
107*cdf0e10cSrcweir             {
108*cdf0e10cSrcweir                 return TYPE_DOUBLE_LIST;
109*cdf0e10cSrcweir             } else if (xmlreader::Span(
110*cdf0e10cSrcweir                            text.begin + i + 1, text.length - (i + 1)).
111*cdf0e10cSrcweir                        equals(RTL_CONSTASCII_STRINGPARAM("string-list")))
112*cdf0e10cSrcweir             {
113*cdf0e10cSrcweir                 return TYPE_STRING_LIST;
114*cdf0e10cSrcweir             } else if (xmlreader::Span(
115*cdf0e10cSrcweir                            text.begin + i + 1, text.length - (i + 1)).
116*cdf0e10cSrcweir                        equals(RTL_CONSTASCII_STRINGPARAM("hexBinary-list")))
117*cdf0e10cSrcweir             {
118*cdf0e10cSrcweir                 return TYPE_HEXBINARY_LIST;
119*cdf0e10cSrcweir             }
120*cdf0e10cSrcweir             break;
121*cdf0e10cSrcweir         case ParseManager::NAMESPACE_XS:
122*cdf0e10cSrcweir             if (xmlreader::Span(text.begin + i + 1, text.length - (i + 1)).
123*cdf0e10cSrcweir                 equals(RTL_CONSTASCII_STRINGPARAM("boolean")))
124*cdf0e10cSrcweir             {
125*cdf0e10cSrcweir                 return TYPE_BOOLEAN;
126*cdf0e10cSrcweir             } else if (xmlreader::Span(
127*cdf0e10cSrcweir                            text.begin + i + 1, text.length - (i + 1)).
128*cdf0e10cSrcweir                        equals(RTL_CONSTASCII_STRINGPARAM("short")))
129*cdf0e10cSrcweir             {
130*cdf0e10cSrcweir                 return TYPE_SHORT;
131*cdf0e10cSrcweir             } else if (xmlreader::Span(
132*cdf0e10cSrcweir                            text.begin + i + 1, text.length - (i + 1)).
133*cdf0e10cSrcweir                        equals(RTL_CONSTASCII_STRINGPARAM("int")))
134*cdf0e10cSrcweir             {
135*cdf0e10cSrcweir                 return TYPE_INT;
136*cdf0e10cSrcweir             } else if (xmlreader::Span(
137*cdf0e10cSrcweir                            text.begin + i + 1, text.length - (i + 1)).
138*cdf0e10cSrcweir                        equals(RTL_CONSTASCII_STRINGPARAM("long")))
139*cdf0e10cSrcweir             {
140*cdf0e10cSrcweir                 return TYPE_LONG;
141*cdf0e10cSrcweir             } else if (xmlreader::Span(
142*cdf0e10cSrcweir                            text.begin + i + 1, text.length - (i + 1)).
143*cdf0e10cSrcweir                        equals(RTL_CONSTASCII_STRINGPARAM("double")))
144*cdf0e10cSrcweir             {
145*cdf0e10cSrcweir                 return TYPE_DOUBLE;
146*cdf0e10cSrcweir             } else if (xmlreader::Span(
147*cdf0e10cSrcweir                            text.begin + i + 1, text.length - (i + 1)).
148*cdf0e10cSrcweir                        equals(RTL_CONSTASCII_STRINGPARAM("string")))
149*cdf0e10cSrcweir             {
150*cdf0e10cSrcweir                 return TYPE_STRING;
151*cdf0e10cSrcweir             } else if (xmlreader::Span(
152*cdf0e10cSrcweir                            text.begin + i + 1, text.length - (i + 1)).
153*cdf0e10cSrcweir                        equals(RTL_CONSTASCII_STRINGPARAM("hexBinary")))
154*cdf0e10cSrcweir             {
155*cdf0e10cSrcweir                 return TYPE_HEXBINARY;
156*cdf0e10cSrcweir             }
157*cdf0e10cSrcweir             break;
158*cdf0e10cSrcweir         default:
159*cdf0e10cSrcweir             break;
160*cdf0e10cSrcweir         }
161*cdf0e10cSrcweir     }
162*cdf0e10cSrcweir     throw css::uno::RuntimeException(
163*cdf0e10cSrcweir         (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("invalid type ")) +
164*cdf0e10cSrcweir          text.convertFromUtf8()),
165*cdf0e10cSrcweir         css::uno::Reference< css::uno::XInterface >());
166*cdf0e10cSrcweir }
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir bool parseBoolean(xmlreader::Span const & text) {
169*cdf0e10cSrcweir     OSL_ASSERT(text.is());
170*cdf0e10cSrcweir     if (text.equals(RTL_CONSTASCII_STRINGPARAM("true"))) {
171*cdf0e10cSrcweir         return true;
172*cdf0e10cSrcweir     }
173*cdf0e10cSrcweir     if (text.equals(RTL_CONSTASCII_STRINGPARAM("false"))) {
174*cdf0e10cSrcweir         return false;
175*cdf0e10cSrcweir     }
176*cdf0e10cSrcweir     throw css::uno::RuntimeException(
177*cdf0e10cSrcweir         (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("invalid boolean ")) +
178*cdf0e10cSrcweir          text.convertFromUtf8()),
179*cdf0e10cSrcweir         css::uno::Reference< css::uno::XInterface >());
180*cdf0e10cSrcweir }
181*cdf0e10cSrcweir 
182*cdf0e10cSrcweir rtl::OUString parseTemplateReference(
183*cdf0e10cSrcweir     rtl::OUString const & component, bool hasNodeType,
184*cdf0e10cSrcweir     rtl::OUString const & nodeType, rtl::OUString const * defaultTemplateName)
185*cdf0e10cSrcweir {
186*cdf0e10cSrcweir     if (!hasNodeType) {
187*cdf0e10cSrcweir         if (defaultTemplateName != 0) {
188*cdf0e10cSrcweir             return *defaultTemplateName;
189*cdf0e10cSrcweir         }
190*cdf0e10cSrcweir         throw css::uno::RuntimeException(
191*cdf0e10cSrcweir             rtl::OUString(
192*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM("missing node-type attribute")),
193*cdf0e10cSrcweir             css::uno::Reference< css::uno::XInterface >());
194*cdf0e10cSrcweir     }
195*cdf0e10cSrcweir     return Data::fullTemplateName(component, nodeType);
196*cdf0e10cSrcweir }
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir }
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir }
201