xref: /trunk/main/autodoc/inc/udm/xml/xmlitem.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 CSI_XML_XMLITEM_HXX
29 #define CSI_XML_XMLITEM_HXX
30 
31 // USED SERVICES
32 	// BASE CLASSES
33 	// COMPONENTS
34 #include <cosv/tpl/swelist.hxx>
35 #include <cosv/tpl/dyn.hxx>
36 	// PARAMETERS
37 
38 namespace csv
39 {
40 	class bostream;
41 }
42 
43 
44 namespace csi
45 {
46 namespace xml
47 {
48 
49 
50 /*	Basics:
51 	Item, Attribute, Element, TextContext
52 */
53 
54 class Item
55 {
56   public:
57 	virtual				~Item() {}
58 	void				WriteOut(
59 							csv::bostream &		io_aFile ) const;
60   private:
61 	virtual void		do_WriteOut(
62 							csv::bostream &		io_aFile ) const = 0;
63 };
64 
65 typedef csv::SweList_dyn< Item >			ItemList;
66 
67 class Attribute
68 {
69   public:
70 	virtual				~Attribute() {}
71 
72 	void				WriteOut(
73 							csv::bostream &		io_aFile ) const;
74 
75 	const ::csv::String& Name() const;
76 	const ::csv::String& Value() const;
77 
78   private:
79 	virtual const ::csv::String &
80 						inq_Name() const = 0;
81 	virtual const ::csv::String &
82 						inq_Value() const = 0;
83 };
84 
85 typedef csv::SweList_dyn< Attribute >	AttrList;
86 
87 
88 class Element : public Item
89 {
90   public:
91 	Element &			operator<<(				/// For multiple content items.
92 							DYN Item *			let_dpItem );
93 	Element &			operator<<(				/// For multiple content items.
94 							const ::csv::String& let_drText );
95 	Element &			operator<<(				/// For multiple content items.
96 							const char *		let_dpText );
97 	Element &			operator<<(
98 							DYN Attribute *		let_dpAttr );
99 
100 	Element &			operator>>(				/// For multiple content items. @return the child Element.
101 							DYN Element &		let_drElement );
102 
103 
104 	Item *				SetContent(             /// For only one content item.
105 							DYN Item *			let_dpItem );   	/// Replaces previous content. May be 0, then all content is deleted.
106   private:
107 	// Interface Item:
108 	virtual void		do_WriteOut(
109 							csv::bostream &		io_aFile ) const;
110 	// Local
111 	virtual void	  	op_streamout(
112 							DYN Item *			let_dpItem ) = 0;
113 	virtual void	  	op_streamout(
114 							DYN Attribute *		let_dpAttr ) = 0;
115 
116 	virtual void	  	do_SetContent(
117 							DYN Item *			let_dpItem ) = 0;
118 	// Helpers
119 	virtual const ::csv::String &
120 						inq_TagName() const = 0;
121 	virtual const Item *
122 						inq_Content() const = 0;
123 	virtual const AttrList *
124 						inq_Attrs() const = 0;
125 
126 	virtual bool		FinishEmptyTag_XmlStyle() const;    /// Defaulted to: true
127 
128 	virtual bool		LineBreakAfterBeginTag() const;	    /// Defaulted to: false
129 	virtual bool		LineBreakAfterEndTag() const;	    /// Defaulted to: true, if LineBreakAfterBeginTag()
130 };
131 
132 class TextContent : public Item
133 {
134 };
135 
136 
137 /*	Implementation simplifiers:
138 	EmptyElement, PureElement, SglTag
139 */
140 
141 class EmptyElement : public Element
142 {
143   private:
144 	// Interface Element:
145 	virtual void	  	op_streamout(          /// does nothing
146 							DYN Item *			let_dpItem );
147 	virtual void	  	op_streamout(
148 							DYN Attribute *		let_dpAttr );
149 	virtual void	  	do_SetContent(          /// does nothing
150 							DYN Item *			let_dpItem );
151 	virtual const Item *
152 						inq_Content() const;	/// @return 0
153 	virtual const AttrList *
154 						inq_Attrs() const;
155 
156 	// Local
157 	virtual AttrList &	inq_RefAttrs() = 0;
158 };
159 
160 class PureElement : public Element
161 {
162   private:
163 	// Interface Element:
164 	virtual void	  	op_streamout(
165 							DYN Item *			let_dpItem );
166 	virtual void	  	op_streamout(          /// does nothing
167 							DYN Attribute *		let_dpAttr );
168 	virtual void	  	do_SetContent(
169 							DYN Item *			let_dpItem );
170 	virtual const Item *
171 						inq_Content() const;
172 	virtual const AttrList *
173 						inq_Attrs() const;      /// @return 0
174 	// Local
175 	virtual Dyn< Item > &
176 						inq_RefContent() = 0;
177 };
178 
179 class SglTag : public Element
180 {
181   private:
182 	// Interface Element:
183 	virtual void	  	op_streamout(          /// does nothing
184 							DYN Item *			let_dpItem );
185 	virtual void	  	op_streamout(          /// does nothing
186 							DYN Attribute *		let_dpAttr );
187 	virtual void	  	do_SetContent(          /// does nothing
188 							DYN Item *			let_dpItem );
189 	virtual const Item *
190 						inq_Content() const;	/// @return 0
191 	virtual const AttrList *
192 						inq_Attrs() const;      /// @return 0
193 };
194 
195 
196 
197 /* 	Standard Element implementations, if there are not any
198 	specialized ones.
199 */
200 
201 class AnElement : public Element
202 {
203   public:
204 						AnElement(
205 							const ::csv::String& i_sTagName );
206 						AnElement(
207 							const char *         i_sTagName );
208 						~AnElement();
209   private:
210 	// Interface Element
211 	virtual void	  	op_streamout(
212 							DYN Item *			let_dpItem );
213 	virtual void	  	op_streamout(
214 							DYN Attribute *		let_dpAttr );
215 	virtual void	  	do_SetContent(
216 							DYN Item *			let_dpItem );
217 	virtual const ::csv::String &
218 						inq_TagName() const;
219 	virtual const Item *
220 						inq_Content() const;
221 	virtual const AttrList *
222 						inq_Attrs() const;
223 	// DATA
224 	::csv::String       sTagName;
225 	Dyn< Item >			pContent;
226 	AttrList			aAttrs;
227 };
228 
229 
230 class AnEmptyElement : public EmptyElement
231 {
232   public:
233 						AnEmptyElement(
234 							const ::csv::String & i_sTagName );
235 						AnEmptyElement(
236 							const char * i_sTagName );
237 						~AnEmptyElement();
238   private:
239 	// Interface Element:
240 	virtual const ::csv::String &
241 						inq_TagName() const;
242 	// Interface EmptyElement:
243 	virtual AttrList &	inq_RefAttrs();
244 
245 	// DATA
246 	::csv::String	    sTagName;
247 	AttrList			aAttrs;
248 };
249 
250 class APureElement : public PureElement
251 {
252   public:
253 						APureElement(
254 							const ::csv::String &	i_sTagName );
255 						APureElement(
256 							const char *            i_sTagName );
257 						~APureElement();
258   private:
259 	// Interface Element:
260 	virtual const ::csv::String &
261 						inq_TagName() const;
262 	// Interface PureElement:
263 	virtual Dyn< Item > &
264 						inq_RefContent();
265 	// DATA
266 	::csv::String       sTagName;
267 	Dyn< Item >			pContent;
268 };
269 
270 class ASglTag : public SglTag
271 {
272   public:
273 						ASglTag(
274 							const ::csv::String & i_sTagName );
275 						ASglTag(
276 							const char *          i_sTagName );
277 						~ASglTag();
278   private:
279 	// Interface Element:
280 	virtual const ::csv::String &
281 						inq_TagName() const;
282 	// DATA
283 	::csv::String         sTagName;
284 };
285 
286 
287 /* Standard Attribute implementation
288 */
289 class AnAttribute : public Attribute
290 {
291   public:
292 						AnAttribute(
293 							const ::csv::String & i_sName,
294                             const ::csv::String & i_sValue );
295 						AnAttribute(
296 							const char *          i_sName,
297                             const char *          i_sValue );
298 						~AnAttribute();
299   private:
300 	// Interface Attribute:
301 	virtual const ::csv::String &
302 						inq_Name() const;
303 	virtual const ::csv::String &
304 						inq_Value() const;
305 	// DATA
306 	::csv::String         sName;
307 	::csv::String         sValue;
308 };
309 
310 
311 
312 /*	Implementations of TextContent:
313 
314 	Text  		( reserved characters will be replaced and appear unchanged )
315 	XmlCode		( reserved characters stay and are interpreted
316 				  by the XML-viewer )
317 */
318 class Text : public TextContent
319 {
320   public:
321 						Text(
322 							const ::csv::String & i_sText );
323 						Text(
324 							const char *		i_sText );
325 						~Text();
326   private:
327 	virtual void		do_WriteOut(
328 							csv::bostream &		io_aFile ) const;
329 	// DATA
330 	::csv::String         sText;
331 };
332 
333 
334 class XmlCode : public TextContent
335 {
336   public:
337 						XmlCode(
338 							const ::csv::String & i_sText );
339 						XmlCode(
340 							const char *          i_sText );
341 						~XmlCode();
342   private:
343 	virtual void		do_WriteOut(
344 							csv::bostream &		io_aFile ) const;
345 	// DATA
346 	::csv::String         sText;
347 };
348 
349 
350 
351 // IMPLEMENTATION
352 
353 inline void
354 Item::WriteOut( csv::bostream &	io_aFile ) const
355 	{ do_WriteOut(io_aFile); }
356 
357 inline const ::csv::String &
358 Attribute::Name() const
359 	{ return inq_Name(); }
360 inline const ::csv::String &
361 Attribute::Value() const
362 	{ return inq_Value(); }
363 
364 inline Element &
365 Element::operator<<( DYN Item *	let_dpItem )
366 	{ op_streamout(let_dpItem); return *this; }
367 inline Element &
368 Element::operator<<( const ::csv::String & let_drText )
369 	{ op_streamout( new Text(let_drText) ); return *this; }
370 inline Element &
371 Element::operator<<( const char * let_drText )
372 	{ op_streamout( new Text(let_drText) ); return *this; }
373 inline Element &
374 Element::operator<<( DYN Attribute * let_dpAttr )
375 	{ op_streamout(let_dpAttr); return *this; }
376 inline Element &
377 Element::operator>>( DYN Element & let_drElement )
378 	{ op_streamout(&let_drElement); return let_drElement; }
379 inline Item *
380 Element::SetContent( DYN Item *	let_dpItem )
381 	{ do_SetContent(let_dpItem); return let_dpItem; }
382 
383 
384 }   // namespace xml
385 }   // namespace csi
386 
387 #endif
388