merge the formfield patch from ooo-build
[ooovba.git] / xml2cmp / source / xcd / xmlelem.cxx
blob284b1c82b532d9d72e866d53c44db2010d8a1ab1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xmlelem.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 #include <xmlelem.hxx>
35 // NOT FULLY DEFINED SERVICES
36 #include <parse.hxx>
37 #include <cr_html.hxx>
39 #if OSL_DEBUG_LEVEL == 0
40 # ifndef NDEBUG
41 # define NDEBUG
42 # endif
43 #endif
44 #include <assert.h>
48 XmlElement::XmlElement( const char * i_sName )
49 : sName(i_sName)
53 void
54 XmlElement::Insert2Index( Index & ) const
56 // Default version. Does nothing.
59 XmlElement *
60 MultipleElement::FindChild( const Simstr & i_sChildName )
62 unsigned i_max = aChildren.size();
63 for ( unsigned i = 0; i < i_max; ++i )
65 if ( aChildren[i]->Name() == i_sChildName )
66 return aChildren[i];
69 return 0;
72 MultipleElement::~MultipleElement()
76 MultipleElement::MultipleElement( const char * i_sName )
77 : XmlElement(i_sName)
81 void
82 MultipleElement::AddChild( XmlElement & let_drElement )
84 aChildren.push_back(&let_drElement);
87 void
88 SequenceElement::Parse( X2CParser & io_rParser )
90 io_rParser.Parse_Sequence( Children(), Name() );
93 void
94 SequenceElement::Write2Html( HtmlCreator & io_rHC ) const
96 io_rHC.StartTable();
98 Children()[nIndexNameElement]->Write2Html(io_rHC);
99 for ( unsigned i = 0; i < Children().size(); ++i )
101 if (i != nIndexNameElement)
103 Children()[i]->Write2Html(io_rHC);
105 } // end for
107 io_rHC.FinishTable();
111 SequenceElement::SequenceElement( const char * i_sName,
112 unsigned i_nIndexNameElement )
113 : MultipleElement(i_sName),
114 nIndexNameElement(i_nIndexNameElement)
118 FreeChoiceElement::FreeChoiceElement()
119 : MultipleElement("")
123 void
124 FreeChoiceElement::Parse( X2CParser & io_rParser )
126 io_rParser.Parse_FreeChoice(Children());
129 void
130 FreeChoiceElement::Write2Html( HtmlCreator & io_rHC ) const
132 for ( unsigned i = 0; i < Children().size(); ++i )
134 Children()[i]->Write2Html(io_rHC);
135 } // end for
138 ListElement::ListElement( const char * i_sElementsName,
139 F_CREATE i_fCreateNewElement )
140 : MultipleElement(i_sElementsName),
141 fCreateNewElement(i_fCreateNewElement)
145 void
146 ListElement::Parse( X2CParser & io_rParser )
148 io_rParser.Parse_List( *this );
151 void
152 ListElement::Write2Html( HtmlCreator & io_rHC ) const
154 for ( unsigned i = 0; i < Children().size(); ++i )
156 Children()[i]->Write2Html(io_rHC);
157 } // end for
160 XmlElement *
161 ListElement::Create_and_Add_NewElement()
163 assert(fCreateNewElement != 0);
164 XmlElement * pNew = (*fCreateNewElement)(Name());
165 Children().push_back( pNew );
166 return pNew;
169 TextElement::TextElement( const char * i_sName,
170 E_LinkType i_eLinkType,
171 bool i_bReverseName )
172 : XmlElement(i_sName),
173 eLinkType(i_eLinkType),
174 bReverseName(i_bReverseName)
178 SglTextElement::SglTextElement( const char * i_sName,
179 E_LinkType i_eLinkType,
180 bool i_bReverseName )
181 : TextElement(i_sName, i_eLinkType, i_bReverseName)
185 void
186 SglTextElement::Parse( X2CParser & io_rParser )
188 io_rParser.Parse_Text(sContent, Name(), IsReversedName());
191 void
192 SglTextElement::Write2Html( HtmlCreator & io_rHC ) const
194 if ( !sContent.is_no_text() )
195 io_rHC.Write_SglTextElement( *this );
198 MultipleTextElement::MultipleTextElement( const char * i_sName,
199 E_LinkType i_eLinkType,
200 bool i_bReverseName )
201 : TextElement(i_sName, i_eLinkType, i_bReverseName)
205 void
206 MultipleTextElement::Parse( X2CParser & io_rParser )
208 io_rParser.Parse_MultipleText(aContent, Name(), IsReversedName());
211 void
212 MultipleTextElement::Write2Html( HtmlCreator & io_rHC ) const
214 if (Size() > 0)
215 io_rHC.Write_MultiTextElement( *this );
218 const Simstr &
219 MultipleTextElement::Data( unsigned i_nNr ) const
221 static const Simstr sNull_;
223 if (aContent.is_valid_index(i_nNr))
224 return aContent[i_nNr];
225 return sNull_;
228 EmptyElement::EmptyElement( const char * i_sName )
229 : XmlElement(i_sName)
233 SglAttrElement::SglAttrElement( const char * i_sName,
234 const char * i_sAttrName )
235 : EmptyElement(i_sName),
236 sAttrName(i_sAttrName)
240 void
241 SglAttrElement::Parse( X2CParser & io_rParser )
243 io_rParser.Parse_SglAttr(sAttrValue, Name(), sAttrName);
246 void
247 SglAttrElement::Write2Html( HtmlCreator & io_rHC ) const
249 io_rHC.Write_SglText( Name(), sAttrValue );
252 MultipleAttrElement::MultipleAttrElement( const char * i_sName,
253 const char ** i_sAttrNames,
254 unsigned i_nSize )
255 : EmptyElement(i_sName)
257 for ( unsigned i = 0; i < i_nSize; ++i )
259 aAttrNames.push_back(Simstr(i_sAttrNames[i]));
260 aAttrValues.push_back(Simstr(""));
264 void
265 MultipleAttrElement::Parse( X2CParser & io_rParser )
267 io_rParser.Parse_MultipleAttr(aAttrValues, Name(), aAttrNames);
270 void
271 MultipleAttrElement::Write2Html( HtmlCreator & io_rHC ) const
273 if ( ! aAttrValues[0].is_no_text() )
274 io_rHC.Write_ReferenceDocu( Name(), aAttrValues[0], aAttrValues[1], aAttrValues[2] );