xref: /AOO41X/main/configmgr/source/xcsparser.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 <cstddef>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "com/sun/star/uno/Any.hxx"
34*cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
35*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
36*cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
37*cdf0e10cSrcweir #include "osl/diagnose.h"
38*cdf0e10cSrcweir #include "rtl/ref.hxx"
39*cdf0e10cSrcweir #include "rtl/strbuf.hxx"
40*cdf0e10cSrcweir #include "rtl/string.h"
41*cdf0e10cSrcweir #include "rtl/string.hxx"
42*cdf0e10cSrcweir #include "rtl/ustring.h"
43*cdf0e10cSrcweir #include "rtl/ustring.hxx"
44*cdf0e10cSrcweir #include "xmlreader/span.hxx"
45*cdf0e10cSrcweir #include "xmlreader/xmlreader.hxx"
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #include "data.hxx"
48*cdf0e10cSrcweir #include "localizedpropertynode.hxx"
49*cdf0e10cSrcweir #include "groupnode.hxx"
50*cdf0e10cSrcweir #include "node.hxx"
51*cdf0e10cSrcweir #include "nodemap.hxx"
52*cdf0e10cSrcweir #include "parsemanager.hxx"
53*cdf0e10cSrcweir #include "propertynode.hxx"
54*cdf0e10cSrcweir #include "setnode.hxx"
55*cdf0e10cSrcweir #include "xcsparser.hxx"
56*cdf0e10cSrcweir #include "xmldata.hxx"
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir namespace configmgr {
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir namespace {
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir namespace css = com::sun::star;
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir // Conservatively merge a template or component (and its recursive parts) into
65*cdf0e10cSrcweir // an existing instance:
66*cdf0e10cSrcweir void merge(
67*cdf0e10cSrcweir     rtl::Reference< Node > const & original,
68*cdf0e10cSrcweir     rtl::Reference< Node > const & update)
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir     OSL_ASSERT(
71*cdf0e10cSrcweir         original.is() && update.is() && original->kind() == update->kind() &&
72*cdf0e10cSrcweir         update->getFinalized() == Data::NO_LAYER);
73*cdf0e10cSrcweir     if (update->getLayer() >= original->getLayer() &&
74*cdf0e10cSrcweir         update->getLayer() <= original->getFinalized())
75*cdf0e10cSrcweir     {
76*cdf0e10cSrcweir         switch (original->kind()) {
77*cdf0e10cSrcweir         case Node::KIND_PROPERTY:
78*cdf0e10cSrcweir         case Node::KIND_LOCALIZED_PROPERTY:
79*cdf0e10cSrcweir         case Node::KIND_LOCALIZED_VALUE:
80*cdf0e10cSrcweir             break; //TODO: merge certain parts?
81*cdf0e10cSrcweir         case Node::KIND_GROUP:
82*cdf0e10cSrcweir             for (NodeMap::iterator i2(update->getMembers().begin());
83*cdf0e10cSrcweir                  i2 != update->getMembers().end(); ++i2)
84*cdf0e10cSrcweir             {
85*cdf0e10cSrcweir                 NodeMap::iterator i1(original->getMembers().find(i2->first));
86*cdf0e10cSrcweir                 if (i1 == original->getMembers().end()) {
87*cdf0e10cSrcweir                     if (i2->second->kind() == Node::KIND_PROPERTY &&
88*cdf0e10cSrcweir                         dynamic_cast< GroupNode * >(
89*cdf0e10cSrcweir                             original.get())->isExtensible())
90*cdf0e10cSrcweir                     {
91*cdf0e10cSrcweir                         original->getMembers().insert(*i2);
92*cdf0e10cSrcweir                     }
93*cdf0e10cSrcweir                 } else if (i2->second->kind() == i1->second->kind()) {
94*cdf0e10cSrcweir                     merge(i1->second, i2->second);
95*cdf0e10cSrcweir                 }
96*cdf0e10cSrcweir             }
97*cdf0e10cSrcweir             break;
98*cdf0e10cSrcweir         case Node::KIND_SET:
99*cdf0e10cSrcweir             for (NodeMap::iterator i2(update->getMembers().begin());
100*cdf0e10cSrcweir                  i2 != update->getMembers().end(); ++i2)
101*cdf0e10cSrcweir             {
102*cdf0e10cSrcweir                 NodeMap::iterator i1(original->getMembers().find(i2->first));
103*cdf0e10cSrcweir                 if (i1 == original->getMembers().end()) {
104*cdf0e10cSrcweir                     if (dynamic_cast< SetNode * >(original.get())->
105*cdf0e10cSrcweir                         isValidTemplate(i2->second->getTemplateName()))
106*cdf0e10cSrcweir                     {
107*cdf0e10cSrcweir                         original->getMembers().insert(*i2);
108*cdf0e10cSrcweir                     }
109*cdf0e10cSrcweir                 } else if (i2->second->kind() == i1->second->kind() &&
110*cdf0e10cSrcweir                            (i2->second->getTemplateName() ==
111*cdf0e10cSrcweir                             i1->second->getTemplateName()))
112*cdf0e10cSrcweir                 {
113*cdf0e10cSrcweir                     merge(i1->second, i2->second);
114*cdf0e10cSrcweir                 }
115*cdf0e10cSrcweir             }
116*cdf0e10cSrcweir             break;
117*cdf0e10cSrcweir         }
118*cdf0e10cSrcweir     }
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir }
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir XcsParser::XcsParser(int layer, Data & data):
124*cdf0e10cSrcweir     valueParser_(layer), data_(data), state_(STATE_START)
125*cdf0e10cSrcweir {}
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir XcsParser::~XcsParser() {}
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir xmlreader::XmlReader::Text XcsParser::getTextMode() {
130*cdf0e10cSrcweir     return valueParser_.getTextMode();
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir bool XcsParser::startElement(
134*cdf0e10cSrcweir     xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name)
135*cdf0e10cSrcweir {
136*cdf0e10cSrcweir     if (valueParser_.startElement(reader, nsId, name)) {
137*cdf0e10cSrcweir         return true;
138*cdf0e10cSrcweir     }
139*cdf0e10cSrcweir     if (state_ == STATE_START) {
140*cdf0e10cSrcweir         if (nsId == ParseManager::NAMESPACE_OOR &&
141*cdf0e10cSrcweir             name.equals(RTL_CONSTASCII_STRINGPARAM("component-schema"))) {
142*cdf0e10cSrcweir             handleComponentSchema(reader);
143*cdf0e10cSrcweir             state_ = STATE_COMPONENT_SCHEMA;
144*cdf0e10cSrcweir             ignoring_ = 0;
145*cdf0e10cSrcweir             return true;
146*cdf0e10cSrcweir         }
147*cdf0e10cSrcweir     } else {
148*cdf0e10cSrcweir         //TODO: ignoring component-schema import, component-schema uses, and
149*cdf0e10cSrcweir         // prop constraints; accepting all four at illegal places (and with
150*cdf0e10cSrcweir         // illegal content):
151*cdf0e10cSrcweir         if (ignoring_ > 0 ||
152*cdf0e10cSrcweir             (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
153*cdf0e10cSrcweir              (name.equals(RTL_CONSTASCII_STRINGPARAM("info")) ||
154*cdf0e10cSrcweir               name.equals(RTL_CONSTASCII_STRINGPARAM("import")) ||
155*cdf0e10cSrcweir               name.equals(RTL_CONSTASCII_STRINGPARAM("uses")) ||
156*cdf0e10cSrcweir               name.equals(RTL_CONSTASCII_STRINGPARAM("constraints")))))
157*cdf0e10cSrcweir         {
158*cdf0e10cSrcweir             OSL_ASSERT(ignoring_ < LONG_MAX);
159*cdf0e10cSrcweir             ++ignoring_;
160*cdf0e10cSrcweir             return true;
161*cdf0e10cSrcweir         }
162*cdf0e10cSrcweir         switch (state_) {
163*cdf0e10cSrcweir         case STATE_COMPONENT_SCHEMA:
164*cdf0e10cSrcweir             if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
165*cdf0e10cSrcweir                 name.equals(RTL_CONSTASCII_STRINGPARAM("templates")))
166*cdf0e10cSrcweir             {
167*cdf0e10cSrcweir                 state_ = STATE_TEMPLATES;
168*cdf0e10cSrcweir                 return true;
169*cdf0e10cSrcweir             }
170*cdf0e10cSrcweir             // fall through
171*cdf0e10cSrcweir         case STATE_TEMPLATES_DONE:
172*cdf0e10cSrcweir             if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
173*cdf0e10cSrcweir                 name.equals(RTL_CONSTASCII_STRINGPARAM("component")))
174*cdf0e10cSrcweir             {
175*cdf0e10cSrcweir                 state_ = STATE_COMPONENT;
176*cdf0e10cSrcweir                 OSL_ASSERT(elements_.empty());
177*cdf0e10cSrcweir                 elements_.push(
178*cdf0e10cSrcweir                     Element(
179*cdf0e10cSrcweir                         new GroupNode(
180*cdf0e10cSrcweir                             valueParser_.getLayer(), false, rtl::OUString()),
181*cdf0e10cSrcweir                         componentName_));
182*cdf0e10cSrcweir                 return true;
183*cdf0e10cSrcweir             }
184*cdf0e10cSrcweir             break;
185*cdf0e10cSrcweir         case STATE_TEMPLATES:
186*cdf0e10cSrcweir             if (elements_.empty()) {
187*cdf0e10cSrcweir                 if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
188*cdf0e10cSrcweir                     name.equals(RTL_CONSTASCII_STRINGPARAM("group")))
189*cdf0e10cSrcweir                 {
190*cdf0e10cSrcweir                     handleGroup(reader, true);
191*cdf0e10cSrcweir                     return true;
192*cdf0e10cSrcweir                 }
193*cdf0e10cSrcweir                 if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
194*cdf0e10cSrcweir                     name.equals(RTL_CONSTASCII_STRINGPARAM("set")))
195*cdf0e10cSrcweir                 {
196*cdf0e10cSrcweir                     handleSet(reader, true);
197*cdf0e10cSrcweir                     return true;
198*cdf0e10cSrcweir                 }
199*cdf0e10cSrcweir                 break;
200*cdf0e10cSrcweir             }
201*cdf0e10cSrcweir             // fall through
202*cdf0e10cSrcweir         case STATE_COMPONENT:
203*cdf0e10cSrcweir             OSL_ASSERT(!elements_.empty());
204*cdf0e10cSrcweir             switch (elements_.top().node->kind()) {
205*cdf0e10cSrcweir             case Node::KIND_PROPERTY:
206*cdf0e10cSrcweir             case Node::KIND_LOCALIZED_PROPERTY:
207*cdf0e10cSrcweir                 if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
208*cdf0e10cSrcweir                     name.equals(RTL_CONSTASCII_STRINGPARAM("value")))
209*cdf0e10cSrcweir                 {
210*cdf0e10cSrcweir                     handlePropValue(reader, elements_.top().node);
211*cdf0e10cSrcweir                     return true;
212*cdf0e10cSrcweir                 }
213*cdf0e10cSrcweir                 break;
214*cdf0e10cSrcweir             case Node::KIND_GROUP:
215*cdf0e10cSrcweir                 if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
216*cdf0e10cSrcweir                     name.equals(RTL_CONSTASCII_STRINGPARAM("prop")))
217*cdf0e10cSrcweir                 {
218*cdf0e10cSrcweir                     handleProp(reader);
219*cdf0e10cSrcweir                     return true;
220*cdf0e10cSrcweir                 }
221*cdf0e10cSrcweir                 if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
222*cdf0e10cSrcweir                     name.equals(RTL_CONSTASCII_STRINGPARAM("node-ref")))
223*cdf0e10cSrcweir                 {
224*cdf0e10cSrcweir                     handleNodeRef(reader);
225*cdf0e10cSrcweir                     return true;
226*cdf0e10cSrcweir                 }
227*cdf0e10cSrcweir                 if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
228*cdf0e10cSrcweir                     name.equals(RTL_CONSTASCII_STRINGPARAM("group")))
229*cdf0e10cSrcweir                 {
230*cdf0e10cSrcweir                     handleGroup(reader, false);
231*cdf0e10cSrcweir                     return true;
232*cdf0e10cSrcweir                 }
233*cdf0e10cSrcweir                 if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
234*cdf0e10cSrcweir                     name.equals(RTL_CONSTASCII_STRINGPARAM("set")))
235*cdf0e10cSrcweir                 {
236*cdf0e10cSrcweir                     handleSet(reader, false);
237*cdf0e10cSrcweir                     return true;
238*cdf0e10cSrcweir                 }
239*cdf0e10cSrcweir                 break;
240*cdf0e10cSrcweir             case Node::KIND_SET:
241*cdf0e10cSrcweir                 if (nsId == xmlreader::XmlReader::NAMESPACE_NONE &&
242*cdf0e10cSrcweir                     name.equals(RTL_CONSTASCII_STRINGPARAM("item")))
243*cdf0e10cSrcweir                 {
244*cdf0e10cSrcweir                     handleSetItem(
245*cdf0e10cSrcweir                         reader,
246*cdf0e10cSrcweir                         dynamic_cast< SetNode * >(elements_.top().node.get()));
247*cdf0e10cSrcweir                     return true;
248*cdf0e10cSrcweir                 }
249*cdf0e10cSrcweir                 break;
250*cdf0e10cSrcweir             default: // Node::KIND_LOCALIZED_VALUE
251*cdf0e10cSrcweir                 OSL_ASSERT(false); // this cannot happen
252*cdf0e10cSrcweir                 break;
253*cdf0e10cSrcweir             }
254*cdf0e10cSrcweir             break;
255*cdf0e10cSrcweir         case STATE_COMPONENT_DONE:
256*cdf0e10cSrcweir             break;
257*cdf0e10cSrcweir         default: // STATE_START
258*cdf0e10cSrcweir             OSL_ASSERT(false); // this cannot happen
259*cdf0e10cSrcweir             break;
260*cdf0e10cSrcweir         }
261*cdf0e10cSrcweir     }
262*cdf0e10cSrcweir     throw css::uno::RuntimeException(
263*cdf0e10cSrcweir         (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bad member <")) +
264*cdf0e10cSrcweir          name.convertFromUtf8() +
265*cdf0e10cSrcweir          rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("> in ")) + reader.getUrl()),
266*cdf0e10cSrcweir         css::uno::Reference< css::uno::XInterface >());
267*cdf0e10cSrcweir }
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir void XcsParser::endElement(xmlreader::XmlReader const & reader) {
270*cdf0e10cSrcweir     if (valueParser_.endElement()) {
271*cdf0e10cSrcweir         return;
272*cdf0e10cSrcweir     }
273*cdf0e10cSrcweir     if (ignoring_ > 0) {
274*cdf0e10cSrcweir         --ignoring_;
275*cdf0e10cSrcweir     } else if (!elements_.empty()) {
276*cdf0e10cSrcweir         Element top(elements_.top());
277*cdf0e10cSrcweir         elements_.pop();
278*cdf0e10cSrcweir         if (top.node.is()) {
279*cdf0e10cSrcweir             if (elements_.empty()) {
280*cdf0e10cSrcweir                 switch (state_) {
281*cdf0e10cSrcweir                 case STATE_TEMPLATES:
282*cdf0e10cSrcweir                     {
283*cdf0e10cSrcweir                         NodeMap::iterator i(data_.templates.find(top.name));
284*cdf0e10cSrcweir                         if (i == data_.templates.end()) {
285*cdf0e10cSrcweir                             data_.templates.insert(
286*cdf0e10cSrcweir                                 NodeMap::value_type(top.name, top.node));
287*cdf0e10cSrcweir                         } else {
288*cdf0e10cSrcweir                             merge(i->second, top.node);
289*cdf0e10cSrcweir                         }
290*cdf0e10cSrcweir                     }
291*cdf0e10cSrcweir                     break;
292*cdf0e10cSrcweir                 case STATE_COMPONENT:
293*cdf0e10cSrcweir                     {
294*cdf0e10cSrcweir                         NodeMap::iterator i(data_.components.find(top.name));
295*cdf0e10cSrcweir                         if (i == data_.components.end()) {
296*cdf0e10cSrcweir                             data_.components.insert(
297*cdf0e10cSrcweir                                 NodeMap::value_type(top.name, top.node));
298*cdf0e10cSrcweir                         } else {
299*cdf0e10cSrcweir                             merge(i->second, top.node);
300*cdf0e10cSrcweir                         }
301*cdf0e10cSrcweir                         state_ = STATE_COMPONENT_DONE;
302*cdf0e10cSrcweir                     }
303*cdf0e10cSrcweir                     break;
304*cdf0e10cSrcweir                 default:
305*cdf0e10cSrcweir                     OSL_ASSERT(false);
306*cdf0e10cSrcweir                     throw css::uno::RuntimeException(
307*cdf0e10cSrcweir                         rtl::OUString(
308*cdf0e10cSrcweir                             RTL_CONSTASCII_USTRINGPARAM("this cannot happen")),
309*cdf0e10cSrcweir                         css::uno::Reference< css::uno::XInterface >());
310*cdf0e10cSrcweir                 }
311*cdf0e10cSrcweir             } else if (!elements_.top().node->getMembers().insert(
312*cdf0e10cSrcweir                            NodeMap::value_type(top.name, top.node)).second)
313*cdf0e10cSrcweir             {
314*cdf0e10cSrcweir                 throw css::uno::RuntimeException(
315*cdf0e10cSrcweir                     (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("duplicate ")) +
316*cdf0e10cSrcweir                      top.name +
317*cdf0e10cSrcweir                      rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" in ")) +
318*cdf0e10cSrcweir                      reader.getUrl()),
319*cdf0e10cSrcweir                     css::uno::Reference< css::uno::XInterface >());
320*cdf0e10cSrcweir             }
321*cdf0e10cSrcweir         }
322*cdf0e10cSrcweir     } else {
323*cdf0e10cSrcweir         switch (state_) {
324*cdf0e10cSrcweir         case STATE_COMPONENT_SCHEMA:
325*cdf0e10cSrcweir             // To support old, broken extensions with .xcs files that contain
326*cdf0e10cSrcweir             // empty <component-schema> elements:
327*cdf0e10cSrcweir             state_ = STATE_COMPONENT_DONE;
328*cdf0e10cSrcweir             break;
329*cdf0e10cSrcweir         case STATE_TEMPLATES:
330*cdf0e10cSrcweir             state_ = STATE_TEMPLATES_DONE;
331*cdf0e10cSrcweir             break;
332*cdf0e10cSrcweir         case STATE_TEMPLATES_DONE:
333*cdf0e10cSrcweir             throw css::uno::RuntimeException(
334*cdf0e10cSrcweir                 (rtl::OUString(
335*cdf0e10cSrcweir                     RTL_CONSTASCII_USTRINGPARAM("no component element in ")) +
336*cdf0e10cSrcweir                  reader.getUrl()),
337*cdf0e10cSrcweir                 css::uno::Reference< css::uno::XInterface >());
338*cdf0e10cSrcweir         case STATE_COMPONENT_DONE:
339*cdf0e10cSrcweir             break;
340*cdf0e10cSrcweir         default:
341*cdf0e10cSrcweir             OSL_ASSERT(false); // this cannot happen
342*cdf0e10cSrcweir         }
343*cdf0e10cSrcweir     }
344*cdf0e10cSrcweir }
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir void XcsParser::characters(xmlreader::Span const & text) {
347*cdf0e10cSrcweir     valueParser_.characters(text);
348*cdf0e10cSrcweir }
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir void XcsParser::handleComponentSchema(xmlreader::XmlReader & reader) {
351*cdf0e10cSrcweir     //TODO: oor:version, xml:lang attributes
352*cdf0e10cSrcweir     rtl::OStringBuffer buf;
353*cdf0e10cSrcweir     buf.append('.');
354*cdf0e10cSrcweir     bool hasPackage = false;
355*cdf0e10cSrcweir     bool hasName = false;
356*cdf0e10cSrcweir     for (;;) {
357*cdf0e10cSrcweir         int attrNsId;
358*cdf0e10cSrcweir         xmlreader::Span attrLn;
359*cdf0e10cSrcweir         if (!reader.nextAttribute(&attrNsId, &attrLn)) {
360*cdf0e10cSrcweir             break;
361*cdf0e10cSrcweir         }
362*cdf0e10cSrcweir         if (attrNsId == ParseManager::NAMESPACE_OOR &&
363*cdf0e10cSrcweir             attrLn.equals(RTL_CONSTASCII_STRINGPARAM("package")))
364*cdf0e10cSrcweir         {
365*cdf0e10cSrcweir             if (hasPackage) {
366*cdf0e10cSrcweir                 throw css::uno::RuntimeException(
367*cdf0e10cSrcweir                     (rtl::OUString(
368*cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM(
369*cdf0e10cSrcweir                             "multiple component-schema package attributes"
370*cdf0e10cSrcweir                             " in ")) +
371*cdf0e10cSrcweir                      reader.getUrl()),
372*cdf0e10cSrcweir                     css::uno::Reference< css::uno::XInterface >());
373*cdf0e10cSrcweir             }
374*cdf0e10cSrcweir             hasPackage = true;
375*cdf0e10cSrcweir             xmlreader::Span s(reader.getAttributeValue(false));
376*cdf0e10cSrcweir             buf.insert(0, s.begin, s.length);
377*cdf0e10cSrcweir         } else if (attrNsId == ParseManager::NAMESPACE_OOR &&
378*cdf0e10cSrcweir                    attrLn.equals(RTL_CONSTASCII_STRINGPARAM("name")))
379*cdf0e10cSrcweir         {
380*cdf0e10cSrcweir             if (hasName) {
381*cdf0e10cSrcweir                 throw css::uno::RuntimeException(
382*cdf0e10cSrcweir                     (rtl::OUString(
383*cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM(
384*cdf0e10cSrcweir                             "multiple component-schema name attributes in ")) +
385*cdf0e10cSrcweir                      reader.getUrl()),
386*cdf0e10cSrcweir                     css::uno::Reference< css::uno::XInterface >());
387*cdf0e10cSrcweir             }
388*cdf0e10cSrcweir             hasName = true;
389*cdf0e10cSrcweir             xmlreader::Span s(reader.getAttributeValue(false));
390*cdf0e10cSrcweir             buf.append(s.begin, s.length);
391*cdf0e10cSrcweir         }
392*cdf0e10cSrcweir     }
393*cdf0e10cSrcweir     if (!hasPackage) {
394*cdf0e10cSrcweir         throw css::uno::RuntimeException(
395*cdf0e10cSrcweir             (rtl::OUString(
396*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
397*cdf0e10cSrcweir                     "no component-schema package attribute in ")) +
398*cdf0e10cSrcweir              reader.getUrl()),
399*cdf0e10cSrcweir             css::uno::Reference< css::uno::XInterface >());
400*cdf0e10cSrcweir     }
401*cdf0e10cSrcweir     if (!hasName) {
402*cdf0e10cSrcweir         throw css::uno::RuntimeException(
403*cdf0e10cSrcweir             (rtl::OUString(
404*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
405*cdf0e10cSrcweir                     "no component-schema name attribute in ")) +
406*cdf0e10cSrcweir              reader.getUrl()),
407*cdf0e10cSrcweir             css::uno::Reference< css::uno::XInterface >());
408*cdf0e10cSrcweir     }
409*cdf0e10cSrcweir     componentName_ = xmlreader::Span(buf.getStr(), buf.getLength()).
410*cdf0e10cSrcweir         convertFromUtf8();
411*cdf0e10cSrcweir }
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir void XcsParser::handleNodeRef(xmlreader::XmlReader & reader) {
414*cdf0e10cSrcweir     bool hasName = false;
415*cdf0e10cSrcweir     rtl::OUString name;
416*cdf0e10cSrcweir     rtl::OUString component(componentName_);
417*cdf0e10cSrcweir     bool hasNodeType = false;
418*cdf0e10cSrcweir     rtl::OUString nodeType;
419*cdf0e10cSrcweir     for (;;) {
420*cdf0e10cSrcweir         int attrNsId;
421*cdf0e10cSrcweir         xmlreader::Span attrLn;
422*cdf0e10cSrcweir         if (!reader.nextAttribute(&attrNsId, &attrLn)) {
423*cdf0e10cSrcweir             break;
424*cdf0e10cSrcweir         }
425*cdf0e10cSrcweir         if (attrNsId == ParseManager::NAMESPACE_OOR &&
426*cdf0e10cSrcweir             attrLn.equals(RTL_CONSTASCII_STRINGPARAM("name")))
427*cdf0e10cSrcweir         {
428*cdf0e10cSrcweir             hasName = true;
429*cdf0e10cSrcweir             name = reader.getAttributeValue(false).convertFromUtf8();
430*cdf0e10cSrcweir         } else if (attrNsId == ParseManager::NAMESPACE_OOR &&
431*cdf0e10cSrcweir                    attrLn.equals(RTL_CONSTASCII_STRINGPARAM("component")))
432*cdf0e10cSrcweir         {
433*cdf0e10cSrcweir             component = reader.getAttributeValue(false).convertFromUtf8();
434*cdf0e10cSrcweir         } else if (attrNsId == ParseManager::NAMESPACE_OOR &&
435*cdf0e10cSrcweir                    attrLn.equals(RTL_CONSTASCII_STRINGPARAM("node-type")))
436*cdf0e10cSrcweir         {
437*cdf0e10cSrcweir             hasNodeType = true;
438*cdf0e10cSrcweir             nodeType = reader.getAttributeValue(false).convertFromUtf8();
439*cdf0e10cSrcweir         }
440*cdf0e10cSrcweir     }
441*cdf0e10cSrcweir     if (!hasName) {
442*cdf0e10cSrcweir         throw css::uno::RuntimeException(
443*cdf0e10cSrcweir             (rtl::OUString(
444*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM("no node-ref name attribute in ")) +
445*cdf0e10cSrcweir              reader.getUrl()),
446*cdf0e10cSrcweir             css::uno::Reference< css::uno::XInterface >());
447*cdf0e10cSrcweir     }
448*cdf0e10cSrcweir     rtl::Reference< Node > tmpl(
449*cdf0e10cSrcweir         data_.getTemplate(
450*cdf0e10cSrcweir             valueParser_.getLayer(),
451*cdf0e10cSrcweir             xmldata::parseTemplateReference(
452*cdf0e10cSrcweir                 component, hasNodeType, nodeType, 0)));
453*cdf0e10cSrcweir     if (!tmpl.is()) {
454*cdf0e10cSrcweir         //TODO: this can erroneously happen as long as import/uses attributes
455*cdf0e10cSrcweir         // are not correctly processed
456*cdf0e10cSrcweir         throw css::uno::RuntimeException(
457*cdf0e10cSrcweir             (rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("unknown node-ref ")) +
458*cdf0e10cSrcweir              name + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" in ")) +
459*cdf0e10cSrcweir              reader.getUrl()),
460*cdf0e10cSrcweir             css::uno::Reference< css::uno::XInterface >());
461*cdf0e10cSrcweir     }
462*cdf0e10cSrcweir     rtl::Reference< Node > node(tmpl->clone(false));
463*cdf0e10cSrcweir     node->setLayer(valueParser_.getLayer());
464*cdf0e10cSrcweir     elements_.push(Element(node, name));
465*cdf0e10cSrcweir }
466*cdf0e10cSrcweir 
467*cdf0e10cSrcweir void XcsParser::handleProp(xmlreader::XmlReader & reader) {
468*cdf0e10cSrcweir     bool hasName = false;
469*cdf0e10cSrcweir     rtl::OUString name;
470*cdf0e10cSrcweir     valueParser_.type_ = TYPE_ERROR;
471*cdf0e10cSrcweir     bool localized = false;
472*cdf0e10cSrcweir     bool nillable = true;
473*cdf0e10cSrcweir     for (;;) {
474*cdf0e10cSrcweir         int attrNsId;
475*cdf0e10cSrcweir         xmlreader::Span attrLn;
476*cdf0e10cSrcweir         if (!reader.nextAttribute(&attrNsId, &attrLn)) {
477*cdf0e10cSrcweir             break;
478*cdf0e10cSrcweir         }
479*cdf0e10cSrcweir         if (attrNsId == ParseManager::NAMESPACE_OOR &&
480*cdf0e10cSrcweir             attrLn.equals(RTL_CONSTASCII_STRINGPARAM("name")))
481*cdf0e10cSrcweir         {
482*cdf0e10cSrcweir             hasName = true;
483*cdf0e10cSrcweir             name = reader.getAttributeValue(false).convertFromUtf8();
484*cdf0e10cSrcweir         } else if (attrNsId == ParseManager::NAMESPACE_OOR &&
485*cdf0e10cSrcweir                    attrLn.equals(RTL_CONSTASCII_STRINGPARAM("type")))
486*cdf0e10cSrcweir         {
487*cdf0e10cSrcweir             valueParser_.type_ = xmldata::parseType(
488*cdf0e10cSrcweir                 reader, reader.getAttributeValue(true));
489*cdf0e10cSrcweir         } else if (attrNsId == ParseManager::NAMESPACE_OOR &&
490*cdf0e10cSrcweir                    attrLn.equals(RTL_CONSTASCII_STRINGPARAM("localized")))
491*cdf0e10cSrcweir         {
492*cdf0e10cSrcweir             localized = xmldata::parseBoolean(reader.getAttributeValue(true));
493*cdf0e10cSrcweir         } else if (attrNsId == ParseManager::NAMESPACE_OOR &&
494*cdf0e10cSrcweir                    attrLn.equals(RTL_CONSTASCII_STRINGPARAM("nillable")))
495*cdf0e10cSrcweir         {
496*cdf0e10cSrcweir             nillable = xmldata::parseBoolean(reader.getAttributeValue(true));
497*cdf0e10cSrcweir         }
498*cdf0e10cSrcweir     }
499*cdf0e10cSrcweir     if (!hasName) {
500*cdf0e10cSrcweir         throw css::uno::RuntimeException(
501*cdf0e10cSrcweir             (rtl::OUString(
502*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM("no prop name attribute in ")) +
503*cdf0e10cSrcweir              reader.getUrl()),
504*cdf0e10cSrcweir             css::uno::Reference< css::uno::XInterface >());
505*cdf0e10cSrcweir     }
506*cdf0e10cSrcweir     if (valueParser_.type_ == TYPE_ERROR) {
507*cdf0e10cSrcweir         throw css::uno::RuntimeException(
508*cdf0e10cSrcweir             (rtl::OUString(
509*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM("no prop type attribute in ")) +
510*cdf0e10cSrcweir              reader.getUrl()),
511*cdf0e10cSrcweir             css::uno::Reference< css::uno::XInterface >());
512*cdf0e10cSrcweir     }
513*cdf0e10cSrcweir     elements_.push(
514*cdf0e10cSrcweir         Element(
515*cdf0e10cSrcweir             (localized
516*cdf0e10cSrcweir              ? rtl::Reference< Node >(
517*cdf0e10cSrcweir                  new LocalizedPropertyNode(
518*cdf0e10cSrcweir                      valueParser_.getLayer(), valueParser_.type_, nillable))
519*cdf0e10cSrcweir              : rtl::Reference< Node >(
520*cdf0e10cSrcweir                  new PropertyNode(
521*cdf0e10cSrcweir                      valueParser_.getLayer(), valueParser_.type_, nillable,
522*cdf0e10cSrcweir                      css::uno::Any(), false))),
523*cdf0e10cSrcweir             name));
524*cdf0e10cSrcweir }
525*cdf0e10cSrcweir 
526*cdf0e10cSrcweir void XcsParser::handlePropValue(
527*cdf0e10cSrcweir     xmlreader::XmlReader & reader, rtl::Reference< Node > const & property)
528*cdf0e10cSrcweir {
529*cdf0e10cSrcweir     xmlreader::Span attrSeparator;
530*cdf0e10cSrcweir     for (;;) {
531*cdf0e10cSrcweir         int attrNsId;
532*cdf0e10cSrcweir         xmlreader::Span attrLn;
533*cdf0e10cSrcweir         if (!reader.nextAttribute(&attrNsId, &attrLn)) {
534*cdf0e10cSrcweir             break;
535*cdf0e10cSrcweir         }
536*cdf0e10cSrcweir         if (attrNsId == ParseManager::NAMESPACE_OOR &&
537*cdf0e10cSrcweir             attrLn.equals(RTL_CONSTASCII_STRINGPARAM("separator")))
538*cdf0e10cSrcweir         {
539*cdf0e10cSrcweir             attrSeparator = reader.getAttributeValue(false);
540*cdf0e10cSrcweir             if (attrSeparator.length == 0) {
541*cdf0e10cSrcweir                 throw css::uno::RuntimeException(
542*cdf0e10cSrcweir                     (rtl::OUString(
543*cdf0e10cSrcweir                         RTL_CONSTASCII_USTRINGPARAM(
544*cdf0e10cSrcweir                             "bad oor:separator attribute in ")) +
545*cdf0e10cSrcweir                      reader.getUrl()),
546*cdf0e10cSrcweir                     css::uno::Reference< css::uno::XInterface >());
547*cdf0e10cSrcweir             }
548*cdf0e10cSrcweir         }
549*cdf0e10cSrcweir     }
550*cdf0e10cSrcweir     valueParser_.separator_ = rtl::OString(
551*cdf0e10cSrcweir         attrSeparator.begin, attrSeparator.length);
552*cdf0e10cSrcweir     valueParser_.start(property);
553*cdf0e10cSrcweir }
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir void XcsParser::handleGroup(xmlreader::XmlReader & reader, bool isTemplate) {
556*cdf0e10cSrcweir     bool hasName = false;
557*cdf0e10cSrcweir     rtl::OUString name;
558*cdf0e10cSrcweir     bool extensible = false;
559*cdf0e10cSrcweir     for (;;) {
560*cdf0e10cSrcweir         int attrNsId;
561*cdf0e10cSrcweir         xmlreader::Span attrLn;
562*cdf0e10cSrcweir         if (!reader.nextAttribute(&attrNsId, &attrLn)) {
563*cdf0e10cSrcweir             break;
564*cdf0e10cSrcweir         }
565*cdf0e10cSrcweir         if (attrNsId == ParseManager::NAMESPACE_OOR &&
566*cdf0e10cSrcweir             attrLn.equals(RTL_CONSTASCII_STRINGPARAM("name")))
567*cdf0e10cSrcweir         {
568*cdf0e10cSrcweir             hasName = true;
569*cdf0e10cSrcweir             name = reader.getAttributeValue(false).convertFromUtf8();
570*cdf0e10cSrcweir         } else if (attrNsId == ParseManager::NAMESPACE_OOR &&
571*cdf0e10cSrcweir                    attrLn.equals(RTL_CONSTASCII_STRINGPARAM("extensible")))
572*cdf0e10cSrcweir         {
573*cdf0e10cSrcweir             extensible = xmldata::parseBoolean(reader.getAttributeValue(true));
574*cdf0e10cSrcweir         }
575*cdf0e10cSrcweir     }
576*cdf0e10cSrcweir     if (!hasName) {
577*cdf0e10cSrcweir         throw css::uno::RuntimeException(
578*cdf0e10cSrcweir             (rtl::OUString(
579*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM("no group name attribute in ")) +
580*cdf0e10cSrcweir              reader.getUrl()),
581*cdf0e10cSrcweir             css::uno::Reference< css::uno::XInterface >());
582*cdf0e10cSrcweir     }
583*cdf0e10cSrcweir     if (isTemplate) {
584*cdf0e10cSrcweir         name = Data::fullTemplateName(componentName_, name);
585*cdf0e10cSrcweir     }
586*cdf0e10cSrcweir     elements_.push(
587*cdf0e10cSrcweir         Element(
588*cdf0e10cSrcweir             new GroupNode(
589*cdf0e10cSrcweir                 valueParser_.getLayer(), extensible,
590*cdf0e10cSrcweir                 isTemplate ? name : rtl::OUString()),
591*cdf0e10cSrcweir             name));
592*cdf0e10cSrcweir }
593*cdf0e10cSrcweir 
594*cdf0e10cSrcweir void XcsParser::handleSet(xmlreader::XmlReader & reader, bool isTemplate) {
595*cdf0e10cSrcweir     bool hasName = false;
596*cdf0e10cSrcweir     rtl::OUString name;
597*cdf0e10cSrcweir     rtl::OUString component(componentName_);
598*cdf0e10cSrcweir     bool hasNodeType = false;
599*cdf0e10cSrcweir     rtl::OUString nodeType;
600*cdf0e10cSrcweir     for (;;) {
601*cdf0e10cSrcweir         int attrNsId;
602*cdf0e10cSrcweir         xmlreader::Span attrLn;
603*cdf0e10cSrcweir         if (!reader.nextAttribute(&attrNsId, &attrLn)) {
604*cdf0e10cSrcweir             break;
605*cdf0e10cSrcweir         }
606*cdf0e10cSrcweir         if (attrNsId == ParseManager::NAMESPACE_OOR &&
607*cdf0e10cSrcweir             attrLn.equals(RTL_CONSTASCII_STRINGPARAM("name")))
608*cdf0e10cSrcweir         {
609*cdf0e10cSrcweir             hasName = true;
610*cdf0e10cSrcweir             name = reader.getAttributeValue(false).convertFromUtf8();
611*cdf0e10cSrcweir         } else if (attrNsId == ParseManager::NAMESPACE_OOR &&
612*cdf0e10cSrcweir                    attrLn.equals(RTL_CONSTASCII_STRINGPARAM("component")))
613*cdf0e10cSrcweir         {
614*cdf0e10cSrcweir             component = reader.getAttributeValue(false).convertFromUtf8();
615*cdf0e10cSrcweir         } else if (attrNsId == ParseManager::NAMESPACE_OOR &&
616*cdf0e10cSrcweir                    attrLn.equals(RTL_CONSTASCII_STRINGPARAM("node-type")))
617*cdf0e10cSrcweir         {
618*cdf0e10cSrcweir             hasNodeType = true;
619*cdf0e10cSrcweir             nodeType = reader.getAttributeValue(false).convertFromUtf8();
620*cdf0e10cSrcweir         }
621*cdf0e10cSrcweir     }
622*cdf0e10cSrcweir     if (!hasName) {
623*cdf0e10cSrcweir         throw css::uno::RuntimeException(
624*cdf0e10cSrcweir             (rtl::OUString(
625*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM("no set name attribute in ")) +
626*cdf0e10cSrcweir              reader.getUrl()),
627*cdf0e10cSrcweir             css::uno::Reference< css::uno::XInterface >());
628*cdf0e10cSrcweir     }
629*cdf0e10cSrcweir     if (isTemplate) {
630*cdf0e10cSrcweir         name = Data::fullTemplateName(componentName_, name);
631*cdf0e10cSrcweir     }
632*cdf0e10cSrcweir     elements_.push(
633*cdf0e10cSrcweir         Element(
634*cdf0e10cSrcweir             new SetNode(
635*cdf0e10cSrcweir                 valueParser_.getLayer(),
636*cdf0e10cSrcweir                 xmldata::parseTemplateReference(
637*cdf0e10cSrcweir                     component, hasNodeType, nodeType, 0),
638*cdf0e10cSrcweir                 isTemplate ? name : rtl::OUString()),
639*cdf0e10cSrcweir             name));
640*cdf0e10cSrcweir }
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir void XcsParser::handleSetItem(xmlreader::XmlReader & reader, SetNode * set) {
643*cdf0e10cSrcweir     rtl::OUString component(componentName_);
644*cdf0e10cSrcweir     bool hasNodeType = false;
645*cdf0e10cSrcweir     rtl::OUString nodeType;
646*cdf0e10cSrcweir     for (;;) {
647*cdf0e10cSrcweir         int attrNsId;
648*cdf0e10cSrcweir         xmlreader::Span attrLn;
649*cdf0e10cSrcweir         if (!reader.nextAttribute(&attrNsId, &attrLn)) {
650*cdf0e10cSrcweir             break;
651*cdf0e10cSrcweir         }
652*cdf0e10cSrcweir         if (attrNsId == ParseManager::NAMESPACE_OOR &&
653*cdf0e10cSrcweir             attrLn.equals(RTL_CONSTASCII_STRINGPARAM("component")))
654*cdf0e10cSrcweir         {
655*cdf0e10cSrcweir             component = reader.getAttributeValue(false).convertFromUtf8();
656*cdf0e10cSrcweir         } else if (attrNsId == ParseManager::NAMESPACE_OOR &&
657*cdf0e10cSrcweir                    attrLn.equals(RTL_CONSTASCII_STRINGPARAM("node-type")))
658*cdf0e10cSrcweir         {
659*cdf0e10cSrcweir             hasNodeType = true;
660*cdf0e10cSrcweir             nodeType = reader.getAttributeValue(false).convertFromUtf8();
661*cdf0e10cSrcweir         }
662*cdf0e10cSrcweir     }
663*cdf0e10cSrcweir     set->getAdditionalTemplateNames().push_back(
664*cdf0e10cSrcweir         xmldata::parseTemplateReference(component, hasNodeType, nodeType, 0));
665*cdf0e10cSrcweir     elements_.push(Element(rtl::Reference< Node >(), rtl::OUString()));
666*cdf0e10cSrcweir }
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir }
669