xref: /aoo41x/main/configmgr/source/xcuparser.hxx (revision cdf0e10c)
1 /*************************************************************************
2 *
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
6 *
7 * OpenOffice.org - a multi-platform office productivity suite
8 *
9 * This file is part of OpenOffice.org.
10 *
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
14 *
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org.  If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
25 *
26 ************************************************************************/
27 
28 #ifndef INCLUDED_CONFIGMGR_SOURCE_XCUPARSER_HXX
29 #define INCLUDED_CONFIGMGR_SOURCE_XCUPARSER_HXX
30 
31 #include "sal/config.h"
32 
33 #include <stack>
34 
35 #include "rtl/ref.hxx"
36 #include "rtl/ustring.hxx"
37 #include "xmlreader/xmlreader.hxx"
38 
39 #include "additions.hxx"
40 #include "node.hxx"
41 #include "nodemap.hxx"
42 #include "parser.hxx"
43 #include "path.hxx"
44 #include "type.hxx"
45 #include "valueparser.hxx"
46 #include "xmldata.hxx"
47 
48 namespace xmlreader { struct Span; }
49 
50 namespace configmgr {
51 
52 class GroupNode;
53 class LocalizedPropertyNode;
54 class Modifications;
55 class Partial;
56 class PropertyNode;
57 class SetNode;
58 struct Data;
59 
60 class XcuParser: public Parser {
61 public:
62     XcuParser(
63         int layer, Data & data, Partial const * partial,
64         Modifications * broadcastModifications, Additions * additions);
65 
66 private:
67     virtual ~XcuParser();
68 
69     virtual xmlreader::XmlReader::Text getTextMode();
70 
71     virtual bool startElement(
72         xmlreader::XmlReader & reader, int nsId, xmlreader::Span const & name);
73 
74     virtual void endElement(xmlreader::XmlReader const & reader);
75 
76     virtual void characters(xmlreader::Span const & span);
77 
78     enum Operation {
79         OPERATION_MODIFY, OPERATION_REPLACE, OPERATION_FUSE, OPERATION_REMOVE };
80 
81     static Operation parseOperation(xmlreader::Span const & text);
82 
83     void handleComponentData(xmlreader::XmlReader & reader);
84 
85     void handleItem(xmlreader::XmlReader & reader);
86 
87     void handlePropValue(xmlreader::XmlReader & reader, PropertyNode * prop);
88 
89     void handleLocpropValue(
90         xmlreader::XmlReader & reader, LocalizedPropertyNode * locprop);
91 
92     void handleGroupProp(xmlreader::XmlReader & reader, GroupNode * group);
93 
94     void handleUnknownGroupProp(
95         xmlreader::XmlReader const & reader, GroupNode * group,
96         rtl::OUString const & name, Type type, Operation operation,
97         bool finalized);
98 
99     void handlePlainGroupProp(
100         xmlreader::XmlReader const & reader, GroupNode * group,
101         NodeMap::iterator const & propertyIndex, rtl::OUString const & name,
102         Type type, Operation operation, bool finalized);
103 
104     void handleLocalizedGroupProp(
105         xmlreader::XmlReader const & reader, LocalizedPropertyNode * property,
106         rtl::OUString const & name, Type type, Operation operation,
107         bool finalized);
108 
109     void handleGroupNode(
110         xmlreader::XmlReader & reader, rtl::Reference< Node > const & group);
111 
112     void handleSetNode(xmlreader::XmlReader & reader, SetNode * set);
113 
114     void recordModification(bool addition);
115 
116     struct State {
117         rtl::Reference< Node > node; // empty iff ignore or <items>
118         rtl::OUString name; // empty and ignored if !insert
119         bool ignore;
120         bool insert;
121         bool locked;
122         bool pop;
123 
124         inline State(bool thePop):
125             ignore(true), insert(false), locked(false), pop(thePop)
126         {}
127 
128         inline State(rtl::Reference< Node > const & theNode, bool theLocked):
129             node(theNode), ignore(false), insert(false), locked(theLocked),
130             pop(true)
131         {}
132 
133         inline State(
134             rtl::Reference< Node > const & theNode,
135             rtl::OUString const & theName, bool theLocked):
136             node(theNode), name(theName), ignore(false), insert(true),
137             locked(theLocked), pop(true)
138         {}
139     };
140 
141     typedef std::stack< State > StateStack;
142 
143     ValueParser valueParser_;
144     Data & data_;
145     Partial const * partial_;
146     Modifications * broadcastModifications_;
147     Additions * additions_;
148     bool recordModifications_;
149     bool trackPath_;
150     rtl::OUString componentName_;
151     StateStack state_;
152     Path path_;
153 };
154 
155 }
156 
157 #endif
158