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