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