xref: /trunk/main/xml2cmp/source/xcd/xmlelem.hxx (revision dd7bc091)
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 #ifndef X2C_XMLELEM_HXX
25 #define X2C_XMLELEM_HXX
26 
27 
28 
29 // USED SERVICES
30 	// BASE CLASSES
31 	// COMPONENTS
32 #include "../support/sistr.hxx"
33 #include "../support/list.hxx"
34 #include "../support/syshelp.hxx"
35 	// PARAMETERS
36 
37 
38 class X2CParser;
39 class HtmlCreator;
40 class Index;
41 
42 class XmlElement
43 {
44   public:
~XmlElement()45 	virtual				~XmlElement() {}
46 	virtual void        Parse(
47 							X2CParser &			io_rParser ) = 0;
48 	virtual void        Write2Html(
49 							HtmlCreator &		io_rHC ) const = 0;
50 	virtual void        Insert2Index(
51 							Index & 	        o_rIndex ) const;			// Default: Does nothing, but can be overwritten.
52 
53 //	virtual void        Put2Dependy() = 0;
54 
Name() const55 	const Simstr &		Name() const			{ return sName; }
56 
57   protected:
58 						XmlElement(
59 							const char *		i_sName );
60   private:
61 	Simstr 				sName;
62 };
63 
64 
65 class MultipleElement : public XmlElement
66 {
67   public:
68 						~MultipleElement();
69 
70 	virtual XmlElement *
71 						FindChild(
72 							const Simstr &		i_sChildName );
73 
74 
75   protected:
76 	typedef DynamicList<XmlElement>			ChildList;
77 
78 						MultipleElement(
79 							const char *		i_sName );
80 
81 	void				AddChild(
82 							XmlElement &		let_drElement );
83 
Children() const84 	const ChildList &	Children() const		{ return aChildren; }
Children()85 	ChildList &			Children()				{ return aChildren; }
86 
87   private:
88 	ChildList			aChildren;
89 };
90 
91 class SequenceElement : public MultipleElement
92 {
93   public:
94 	virtual void        Parse(
95 							X2CParser &			io_rParser );
96 	virtual void        Write2Html(
97 							HtmlCreator &		io_rHC ) const;
98 
99   protected:
100 						SequenceElement(
101 							const char *		i_sName,
102 							unsigned            i_nIndexNameElement = 0 );
103   private:
104 	unsigned			nIndexNameElement;
105 };
106 
107 class FreeChoiceElement : public MultipleElement
108 {
109   public:
110 						FreeChoiceElement();
111 	using				MultipleElement::AddChild;
112 
113 	virtual void        Parse(
114 							X2CParser &			io_rParser );
115 	virtual void        Write2Html(
116 							HtmlCreator &		io_rHC ) const;
117 };
118 
119 class ListElement : public MultipleElement
120 {
121   public:
122 	typedef XmlElement * (*F_CREATE)(const Simstr &);
123 
124 						ListElement(
125 							const char *		i_sElementsName,
126 							F_CREATE            i_fCreateNewElement );
127 
128 	virtual void        Parse(
129 							X2CParser &			io_rParser );
130 	virtual void        Write2Html(
131 							HtmlCreator &		io_rHC ) const;
132 	virtual XmlElement *
133     					Create_and_Add_NewElement();
134   private:
135 	F_CREATE			fCreateNewElement;
136 };
137 
138 class TextElement : public XmlElement
139 {
140   public:
LinkType() const141 	E_LinkType			LinkType() const		{ return eLinkType; }
IsReversedName() const142 	bool			    IsReversedName() const	{ return bReverseName; }
143   protected:
144 						TextElement(
145 							const char *		i_sName,
146 							E_LinkType			i_eLinkType,
147 							bool				i_bReverseName );
148   private:
149 	E_LinkType			eLinkType;
150 	bool				bReverseName;
151 };
152 
153 class SglTextElement : public TextElement
154 {
155   public:
156 						SglTextElement(
157 							const char *		i_sName,
158 							E_LinkType			i_eLinkType,
159 							bool				i_bReverseName );
160 
161 	virtual void        Parse(
162 							X2CParser &			io_rParser );
163 	virtual void        Write2Html(
164 							HtmlCreator &		io_rHC ) const;
165 	virtual const Simstr &
Data() const166 						Data() const			{ return sContent; }
167   private:
168 	Simstr				sContent;
169 };
170 
171 class MultipleTextElement : public TextElement
172 {
173   public:
174 						MultipleTextElement(
175 							const char *		i_sName,
176 							E_LinkType			i_eLinkType,
177 							bool				i_bReverseName );
178 
179 	virtual void        Parse(
180 							X2CParser &			io_rParser );
181 	virtual void        Write2Html(
182 							HtmlCreator &		io_rHC ) const;
183 	virtual const Simstr &
184 						Data(
185 							unsigned 			i_nNr ) const;
Size() const186 	virtual unsigned	Size() const			{ return aContent.size(); }
187 
188   private:
189 	List<Simstr>		aContent;
190 };
191 
192 class EmptyElement : public XmlElement
193 {
194   protected:
195 						EmptyElement(
196 							const char *		i_sName );
197 };
198 
199 class SglAttrElement : public EmptyElement
200 {
201   public:
202 						SglAttrElement(
203 							const char *		i_sName,
204 							const char *		i_sAttrName );
205 
206 	virtual void        Parse(
207 							X2CParser &			io_rParser );
208 	virtual void        Write2Html(
209 							HtmlCreator &		io_rHC ) const;
210   private:
211 	Simstr				sAttrName;
212 	Simstr				sAttrValue;
213 };
214 
215 
216 class MultipleAttrElement : public EmptyElement
217 {
218   public:
219 						MultipleAttrElement(
220 							const char *		i_sName,
221 							const char **		i_sAttrNames,
222 							unsigned			i_nSize );
223 
224 	virtual void        Parse(
225 							X2CParser &			io_rParser );
226 	virtual void        Write2Html(
227 							HtmlCreator &		io_rHC ) const;
228   private:
229 	List<Simstr>		aAttrNames;
230 	List<Simstr>		aAttrValues;
231 };
232 
233 // IMPLEMENTATION
234 
235 
236 #endif
237 
238