1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <udm/xml/xmlitem.hxx>
23 // NOT FULLY DECLARED SERVICES
24 #include <cosv/file.hxx>
32 char cReplacable
[256] =
34 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 49
35 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
36 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
37 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, // ", &
38 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 50 - 99
41 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, // <, >
42 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 100 - 149
47 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
48 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
49 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
50 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,
54 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
55 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
56 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,
60 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,
64 0, 0, 0, 0, 0, 1 //
68 class MultiItem
: public Item
75 DYN Item
* let_dpDatum
)
76 { csv_assert( let_dpDatum
!= 0 );
77 aItems
.push_back(let_dpDatum
); }
78 void Erase() { aItems
.erase_all(); }
81 virtual void do_WriteOut(
82 csv::bostream
& io_aFile
) const;
89 Dyn
< Item
> & o_rContent
,
90 DYN Item
* let_dpItem
);
92 StreamOut( AttrList
& o_rAttrs
,
93 DYN Attribute
* let_dpAttr
)
95 csv_assert( let_dpAttr
!= 0 );
96 o_rAttrs
.push_back( let_dpAttr
);
101 Impl_SetContent( Dyn
< Item
> & o_rContent
,
102 DYN Item
* let_dpItem
)
104 o_rContent
= let_dpItem
;
108 //********************* Attribute ****************************//
110 const String
attrValueBegin("=\"");
111 const String
attrValueEnd("\"");
114 Attribute::WriteOut( csv::bostream
& io_aFile
) const
116 io_aFile
.write( Name() );
117 if ( Value().length() > 0 )
119 io_aFile
.write( attrValueBegin
);
120 io_aFile
.write( Value() );
121 io_aFile
.write( attrValueEnd
);
127 //************************ Element ****************************//
129 const String
newline("\n");
130 const String
space(" ");
131 const String
beginTagBegin("<");
132 const String
endTagBegin("</");
133 const String
tagEnd(">");
134 const String
emptyTagEnd("/>");
137 Element::do_WriteOut( csv::bostream
& io_aFile
) const
139 io_aFile
.write( beginTagBegin
);
140 io_aFile
.write( inq_TagName() );
142 const AttrList
* pAttrs
= inq_Attrs();
145 for ( AttrList::iterator it
= pAttrs
->begin();
150 io_aFile
.write( space
);
151 (*it
)->WriteOut( io_aFile
);
155 const Item
* pContent
= inq_Content();
157 io_aFile
.write( tagEnd
);
160 if (FinishEmptyTag_XmlStyle())
161 io_aFile
.write( emptyTagEnd
);
164 io_aFile
.write( tagEnd
);
165 io_aFile
.write( endTagBegin
);
166 io_aFile
.write( inq_TagName() );
167 io_aFile
.write( tagEnd
);
170 if ( LineBreakAfterBeginTag() )
171 io_aFile
.write( newline
);
175 pContent
->WriteOut( io_aFile
);
176 io_aFile
.write( endTagBegin
);
177 io_aFile
.write( inq_TagName() );
178 io_aFile
.write( tagEnd
);
179 if ( LineBreakAfterEndTag() )
180 io_aFile
.write( newline
);
184 Element::FinishEmptyTag_XmlStyle() const
190 Element::LineBreakAfterBeginTag() const
196 Element::LineBreakAfterEndTag() const
198 return LineBreakAfterBeginTag();
202 //************************ EmptyElement ****************************//
205 EmptyElement::op_streamout( DYN Item
* )
211 EmptyElement::op_streamout( DYN Attribute
* let_dpAttr
)
213 StreamOut( inq_RefAttrs(), let_dpAttr
);
217 EmptyElement::do_SetContent( DYN Item
* )
223 EmptyElement::inq_Content() const
229 EmptyElement::inq_Attrs() const
231 return & const_cast< EmptyElement
* >(this)->inq_RefAttrs();
235 //************************ PureElement ****************************//
238 PureElement::op_streamout( DYN Item
* let_dpItem
)
240 StreamOut( inq_RefContent(), let_dpItem
);
244 PureElement::op_streamout( DYN Attribute
* )
250 PureElement::do_SetContent( DYN Item
* let_dpItem
)
252 Impl_SetContent( inq_RefContent(), let_dpItem
);
256 PureElement::inq_Content() const
258 return const_cast< PureElement
* >(this)->inq_RefContent().Ptr();
262 PureElement::inq_Attrs() const
268 //*************************** SglTag **************************//
271 SglTag::op_streamout( DYN Item
* )
277 SglTag::op_streamout( DYN Attribute
* )
283 SglTag::do_SetContent( DYN Item
*)
289 SglTag::inq_Content() const
295 SglTag::inq_Attrs() const
301 //*************************** AnElement **************************//
303 AnElement::AnElement( const char * i_sTagName
)
304 : sTagName( i_sTagName
)
310 AnElement::~AnElement()
315 AnElement::op_streamout( DYN Item
* let_dpItem
)
317 StreamOut( pContent
, let_dpItem
);
321 AnElement::op_streamout( DYN Attribute
* let_dpAttr
)
323 StreamOut( aAttrs
, let_dpAttr
);
327 AnElement::do_SetContent( DYN Item
* let_dpItem
)
329 Impl_SetContent( pContent
, let_dpItem
);
333 AnElement::inq_TagName() const
339 AnElement::inq_Content() const
341 return pContent
.Ptr();
345 AnElement::inq_Attrs() const
350 //*************************** APureElement **************************//
352 APureElement::APureElement( const char * i_sTagName
)
353 : sTagName( i_sTagName
)
358 APureElement::~APureElement()
363 APureElement::inq_TagName() const
369 APureElement::inq_RefContent()
374 //*************************** AnAttribute **************************//
375 AnAttribute::AnAttribute( const String
& i_sName
,
376 const String
& i_sValue
)
382 AnAttribute::AnAttribute( const char * i_sName
,
383 const char * i_sValue
)
389 AnAttribute::~AnAttribute()
394 AnAttribute::inq_Name() const
400 AnAttribute::inq_Value() const
407 //*************************** Text **************************//
409 Text::Text( const String
& i_sText
)
414 Text::Text( const char * i_sText
)
424 Text::do_WriteOut( csv::bostream
& io_aFile
) const
426 const unsigned char *
427 pStart
= reinterpret_cast< const unsigned char* >(sText
.c_str());
428 const unsigned char *
431 for ( ; *pOut
!= '\0'; ++pOut
)
433 if ( cReplacable
[*pOut
] )
435 if ( pOut
!= pStart
)
437 io_aFile
.write( pStart
, pOut
-pStart
);
442 case '<': io_aFile
.write("<"); break;
443 case '>': io_aFile
.write(">"); break;
444 case '"': io_aFile
.write("""); break;
445 case '&': io_aFile
.write("&"); break;
446 case 255: io_aFile
.write(" "); break;
450 } // endif (cReplacable[*pOut])
453 if ( pOut
!= pStart
)
455 io_aFile
.write( pStart
, pOut
-pStart
);
460 //*************************** XmlCode **************************//
462 XmlCode::XmlCode( const String
& i_sText
)
467 XmlCode::XmlCode( const char * i_sText
)
477 XmlCode::do_WriteOut( csv::bostream
& io_aFile
) const
479 io_aFile
.write(sText
);
483 //*************************** MultiItem **************************//
485 MultiItem::MultiItem()
489 MultiItem::~MultiItem()
494 MultiItem::do_WriteOut( csv::bostream
& io_aFile
) const
496 ItemList::iterator itEnd
= aItems
.end();
498 for ( ItemList::iterator it
= aItems
.begin();
502 (*it
)->WriteOut( io_aFile
);
509 //*************************** Helpers **************************//
512 StreamOut( Dyn
< Item
> & o_rContent
,
513 DYN Item
* let_dpItem
)
515 MultiItem
* pContent
= 0;
516 if ( bool(o_rContent
) )
518 pContent
= static_cast< MultiItem
* >( o_rContent
.MutablePtr() );
519 csv_assert( dynamic_cast< MultiItem
* >( o_rContent
.MutablePtr() ) != 0 );
523 pContent
= new MultiItem
;
524 o_rContent
= pContent
;
527 csv_assert( let_dpItem
!= 0 );
528 pContent
->Add( let_dpItem
);
537 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */