1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <udm/xml/xmlitem.hxx>
32 // NOT FULLY DECLARED SERVICES
33 #include <cosv/file.hxx>
41 char cReplacable
[256] =
43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 49
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, // ", &
47 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
49 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 50 - 99
50 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, // <, >
51 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
52 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
53 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
55 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 100 - 149
56 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
57 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
58 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
59 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
61 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
62 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
63 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
64 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
65 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
67 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
68 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
69 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
70 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
71 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
73 0, 0, 0, 0, 0, 1 //
77 class MultiItem
: public Item
84 DYN Item
* let_dpDatum
)
85 { csv_assert( let_dpDatum
!= 0 );
86 aItems
.push_back(let_dpDatum
); }
87 void Erase() { aItems
.erase_all(); }
90 virtual void do_WriteOut(
91 csv::bostream
& io_aFile
) const;
98 Dyn
< Item
> & o_rContent
,
99 DYN Item
* let_dpItem
);
101 StreamOut( AttrList
& o_rAttrs
,
102 DYN Attribute
* let_dpAttr
)
104 csv_assert( let_dpAttr
!= 0 );
105 o_rAttrs
.push_back( let_dpAttr
);
110 Impl_SetContent( Dyn
< Item
> & o_rContent
,
111 DYN Item
* let_dpItem
)
113 o_rContent
= let_dpItem
;
117 //********************* Attribute ****************************//
119 const String
attrValueBegin("=\"");
120 const String
attrValueEnd("\"");
123 Attribute::WriteOut( csv::bostream
& io_aFile
) const
125 io_aFile
.write( Name() );
126 if ( Value().length() > 0 )
128 io_aFile
.write( attrValueBegin
);
129 io_aFile
.write( Value() );
130 io_aFile
.write( attrValueEnd
);
136 //************************ Element ****************************//
138 const String
newline("\n");
139 const String
space(" ");
140 const String
beginTagBegin("<");
141 const String
endTagBegin("</");
142 const String
tagEnd(">");
143 const String
emptyTagEnd("/>");
146 Element::do_WriteOut( csv::bostream
& io_aFile
) const
148 io_aFile
.write( beginTagBegin
);
149 io_aFile
.write( inq_TagName() );
151 const AttrList
* pAttrs
= inq_Attrs();
154 for ( AttrList::iterator it
= pAttrs
->begin();
159 io_aFile
.write( space
);
160 (*it
)->WriteOut( io_aFile
);
164 const Item
* pContent
= inq_Content();
166 io_aFile
.write( tagEnd
);
169 if (FinishEmptyTag_XmlStyle())
170 io_aFile
.write( emptyTagEnd
);
173 io_aFile
.write( tagEnd
);
174 io_aFile
.write( endTagBegin
);
175 io_aFile
.write( inq_TagName() );
176 io_aFile
.write( tagEnd
);
179 if ( LineBreakAfterBeginTag() )
180 io_aFile
.write( newline
);
184 pContent
->WriteOut( io_aFile
);
185 io_aFile
.write( endTagBegin
);
186 io_aFile
.write( inq_TagName() );
187 io_aFile
.write( tagEnd
);
188 if ( LineBreakAfterEndTag() )
189 io_aFile
.write( newline
);
193 Element::FinishEmptyTag_XmlStyle() const
199 Element::LineBreakAfterBeginTag() const
205 Element::LineBreakAfterEndTag() const
207 return LineBreakAfterBeginTag();
211 //************************ EmptyElement ****************************//
214 EmptyElement::op_streamout( DYN Item
* )
220 EmptyElement::op_streamout( DYN Attribute
* let_dpAttr
)
222 StreamOut( inq_RefAttrs(), let_dpAttr
);
226 EmptyElement::do_SetContent( DYN Item
* )
232 EmptyElement::inq_Content() const
238 EmptyElement::inq_Attrs() const
240 return & const_cast< EmptyElement
* >(this)->inq_RefAttrs();
244 //************************ PureElement ****************************//
247 PureElement::op_streamout( DYN Item
* let_dpItem
)
249 StreamOut( inq_RefContent(), let_dpItem
);
253 PureElement::op_streamout( DYN Attribute
* )
259 PureElement::do_SetContent( DYN Item
* let_dpItem
)
261 Impl_SetContent( inq_RefContent(), let_dpItem
);
265 PureElement::inq_Content() const
267 return const_cast< PureElement
* >(this)->inq_RefContent().Ptr();
271 PureElement::inq_Attrs() const
277 //*************************** SglTag **************************//
280 SglTag::op_streamout( DYN Item
* )
286 SglTag::op_streamout( DYN Attribute
* )
292 SglTag::do_SetContent( DYN Item
*)
298 SglTag::inq_Content() const
304 SglTag::inq_Attrs() const
310 //*************************** AnElement **************************//
312 AnElement::AnElement( const char * i_sTagName
)
313 : sTagName( i_sTagName
)
319 AnElement::~AnElement()
324 AnElement::op_streamout( DYN Item
* let_dpItem
)
326 StreamOut( pContent
, let_dpItem
);
330 AnElement::op_streamout( DYN Attribute
* let_dpAttr
)
332 StreamOut( aAttrs
, let_dpAttr
);
336 AnElement::do_SetContent( DYN Item
* let_dpItem
)
338 Impl_SetContent( pContent
, let_dpItem
);
342 AnElement::inq_TagName() const
348 AnElement::inq_Content() const
350 return pContent
.Ptr();
354 AnElement::inq_Attrs() const
359 //*************************** APureElement **************************//
361 APureElement::APureElement( const char * i_sTagName
)
362 : sTagName( i_sTagName
)
367 APureElement::~APureElement()
372 APureElement::inq_TagName() const
378 APureElement::inq_RefContent()
383 //*************************** AnAttribute **************************//
384 AnAttribute::AnAttribute( const String
& i_sName
,
385 const String
& i_sValue
)
391 AnAttribute::AnAttribute( const char * i_sName
,
392 const char * i_sValue
)
398 AnAttribute::~AnAttribute()
403 AnAttribute::inq_Name() const
409 AnAttribute::inq_Value() const
416 //*************************** Text **************************//
418 Text::Text( const String
& i_sText
)
423 Text::Text( const char * i_sText
)
433 Text::do_WriteOut( csv::bostream
& io_aFile
) const
435 const unsigned char *
436 pStart
= reinterpret_cast< const unsigned char* >(sText
.c_str());
437 const unsigned char *
440 for ( ; *pOut
!= '\0'; ++pOut
)
442 if ( cReplacable
[*pOut
] )
444 if ( pOut
!= pStart
)
446 io_aFile
.write( pStart
, pOut
-pStart
);
451 case '<': io_aFile
.write("<"); break;
452 case '>': io_aFile
.write(">"); break;
453 case '"': io_aFile
.write("""); break;
454 case '&': io_aFile
.write("&"); break;
455 case 255: io_aFile
.write(" "); break;
459 } // endif (cReplacable[*pOut])
462 if ( pOut
!= pStart
)
464 io_aFile
.write( pStart
, pOut
-pStart
);
469 //*************************** XmlCode **************************//
471 XmlCode::XmlCode( const String
& i_sText
)
476 XmlCode::XmlCode( const char * i_sText
)
486 XmlCode::do_WriteOut( csv::bostream
& io_aFile
) const
488 io_aFile
.write(sText
);
492 //*************************** MultiItem **************************//
494 MultiItem::MultiItem()
498 MultiItem::~MultiItem()
503 MultiItem::do_WriteOut( csv::bostream
& io_aFile
) const
505 ItemList::iterator itEnd
= aItems
.end();
507 for ( ItemList::iterator it
= aItems
.begin();
511 (*it
)->WriteOut( io_aFile
);
518 //*************************** Helpers **************************//
521 StreamOut( Dyn
< Item
> & o_rContent
,
522 DYN Item
* let_dpItem
)
524 MultiItem
* pContent
= 0;
525 if ( bool(o_rContent
) )
527 pContent
= static_cast< MultiItem
* >( o_rContent
.MutablePtr() );
528 csv_assert( dynamic_cast< MultiItem
* >( o_rContent
.MutablePtr() ) != 0 );
532 pContent
= new MultiItem
;
533 o_rContent
= pContent
;
536 csv_assert( let_dpItem
!= 0 );
537 pContent
->Add( let_dpItem
);
546 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */