xref: /aoo4110/main/xml2cmp/source/xcd/xmlelem.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 
25 #include <xmlelem.hxx>
26 
27 
28 // NOT FULLY DEFINED SERVICES
29 #include <parse.hxx>
30 #include <cr_html.hxx>
31 
XmlElement(const char * i_sName)32 XmlElement::XmlElement( const char * i_sName )
33 	: sName(i_sName)
34 {
35 }
36 
37 void
Insert2Index(Index &) const38 XmlElement::Insert2Index( Index & ) const
39 {
40 	//  Default version. Does nothing.
41 }
42 
43 XmlElement *
FindChild(const Simstr & i_sChildName)44 MultipleElement::FindChild( const Simstr & i_sChildName )
45 {
46 	unsigned i_max = aChildren.size();
47 	for ( unsigned i = 0; i < i_max; ++i )
48 	{
49 		if ( aChildren[i]->Name() == i_sChildName )
50 			return aChildren[i];
51 	}
52 
53 	return 0;
54 }
55 
~MultipleElement()56 MultipleElement::~MultipleElement()
57 {
58 }
59 
MultipleElement(const char * i_sName)60 MultipleElement::MultipleElement( const char * i_sName )
61 	:	XmlElement(i_sName)
62 {
63 }
64 
65 void
AddChild(XmlElement & let_drElement)66 MultipleElement::AddChild( XmlElement &	let_drElement )
67 {
68 	aChildren.push_back(&let_drElement);
69 }
70 
71 void
Parse(X2CParser & io_rParser)72 SequenceElement::Parse( X2CParser & io_rParser )
73 {
74 	io_rParser.Parse_Sequence( Children(), Name() );
75 }
76 
77 void
Write2Html(HtmlCreator & io_rHC) const78 SequenceElement::Write2Html( HtmlCreator & io_rHC ) const
79 {
80 	io_rHC.StartTable();
81 
82 	Children()[nIndexNameElement]->Write2Html(io_rHC);
83 	for ( unsigned i = 0; i < Children().size(); ++i )
84 	{
85 		if (i != nIndexNameElement)
86 		{
87 			Children()[i]->Write2Html(io_rHC);
88 		}
89 	}  // end for
90 
91 	io_rHC.FinishTable();
92 }
93 
94 
SequenceElement(const char * i_sName,unsigned i_nIndexNameElement)95 SequenceElement::SequenceElement( const char * i_sName,
96 								  unsigned     i_nIndexNameElement )
97 	:	MultipleElement(i_sName),
98 		nIndexNameElement(i_nIndexNameElement)
99 {
100 }
101 
FreeChoiceElement()102 FreeChoiceElement::FreeChoiceElement()
103 	:	MultipleElement("")
104 {
105 }
106 
107 void
Parse(X2CParser & io_rParser)108 FreeChoiceElement::Parse( X2CParser & io_rParser )
109 {
110 	io_rParser.Parse_FreeChoice(Children());
111 }
112 
113 void
Write2Html(HtmlCreator & io_rHC) const114 FreeChoiceElement::Write2Html( HtmlCreator & io_rHC ) const
115 {
116 	for ( unsigned i = 0; i < Children().size(); ++i )
117 	{
118 		Children()[i]->Write2Html(io_rHC);
119 	}  // end for
120 }
121 
ListElement(const char * i_sElementsName,F_CREATE i_fCreateNewElement)122 ListElement::ListElement( const char * i_sElementsName,
123 						  F_CREATE     i_fCreateNewElement )
124 	:	MultipleElement(i_sElementsName),
125 		fCreateNewElement(i_fCreateNewElement)
126 {
127 }
128 
129 void
Parse(X2CParser & io_rParser)130 ListElement::Parse( X2CParser &	io_rParser )
131 {
132 	io_rParser.Parse_List(	*this );
133 }
134 
135 void
Write2Html(HtmlCreator & io_rHC) const136 ListElement::Write2Html( HtmlCreator & io_rHC ) const
137 {
138 	for ( unsigned i = 0; i < Children().size(); ++i )
139 	{
140 		Children()[i]->Write2Html(io_rHC);
141 	}  // end for
142 }
143 
144 XmlElement *
Create_and_Add_NewElement()145 ListElement::Create_and_Add_NewElement()
146 {
147 	XmlElement * pNew = (*fCreateNewElement)(Name());
148 	Children().push_back( pNew );
149     return pNew;
150 }
151 
TextElement(const char * i_sName,E_LinkType i_eLinkType,bool i_bReverseName)152 TextElement::TextElement( const char *		i_sName,
153 						  E_LinkType		i_eLinkType,
154 						  bool				i_bReverseName )
155 	:	XmlElement(i_sName),
156 		eLinkType(i_eLinkType),
157 		bReverseName(i_bReverseName)
158 {
159 }
160 
SglTextElement(const char * i_sName,E_LinkType i_eLinkType,bool i_bReverseName)161 SglTextElement::SglTextElement( const char *		i_sName,
162 								E_LinkType			i_eLinkType,
163 								bool				i_bReverseName )
164 	:	TextElement(i_sName, i_eLinkType, i_bReverseName)
165 {
166 }
167 
168 void
Parse(X2CParser & io_rParser)169 SglTextElement::Parse( X2CParser & io_rParser )
170 {
171 	io_rParser.Parse_Text(sContent, Name(), IsReversedName());
172 }
173 
174 void
Write2Html(HtmlCreator & io_rHC) const175 SglTextElement::Write2Html(	HtmlCreator & io_rHC ) const
176 {
177 	if ( !sContent.is_no_text() )
178 		io_rHC.Write_SglTextElement( *this );
179 }
180 
MultipleTextElement(const char * i_sName,E_LinkType i_eLinkType,bool i_bReverseName)181 MultipleTextElement::MultipleTextElement( const char *		i_sName,
182 										  E_LinkType		i_eLinkType,
183 										  bool				i_bReverseName )
184 	:	TextElement(i_sName, i_eLinkType, i_bReverseName)
185 {
186 }
187 
188 void
Parse(X2CParser & io_rParser)189 MultipleTextElement::Parse( X2CParser & io_rParser )
190 {
191 	io_rParser.Parse_MultipleText(aContent, Name(), IsReversedName());
192 }
193 
194 void
Write2Html(HtmlCreator & io_rHC) const195 MultipleTextElement::Write2Html(	HtmlCreator & io_rHC ) const
196 {
197 	if (Size() > 0)
198 		io_rHC.Write_MultiTextElement( *this );
199 }
200 
201 const Simstr &
Data(unsigned i_nNr) const202 MultipleTextElement::Data( unsigned i_nNr ) const
203 {
204 	static const Simstr sNull_;
205 
206 	if (aContent.is_valid_index(i_nNr))
207 		return aContent[i_nNr];
208 	return sNull_;
209 }
210 
EmptyElement(const char * i_sName)211 EmptyElement::EmptyElement( const char * i_sName )
212 	:	XmlElement(i_sName)
213 {
214 }
215 
SglAttrElement(const char * i_sName,const char * i_sAttrName)216 SglAttrElement::SglAttrElement( const char *		i_sName,
217 								const char *		i_sAttrName )
218 	:	EmptyElement(i_sName),
219 		sAttrName(i_sAttrName)
220 {
221 }
222 
223 void
Parse(X2CParser & io_rParser)224 SglAttrElement::Parse( X2CParser & io_rParser )
225 {
226 	io_rParser.Parse_SglAttr(sAttrValue, Name(), sAttrName);
227 }
228 
229 void
Write2Html(HtmlCreator & io_rHC) const230 SglAttrElement::Write2Html(	HtmlCreator & io_rHC ) const
231 {
232 	io_rHC.Write_SglText( Name(), sAttrValue );
233 }
234 
MultipleAttrElement(const char * i_sName,const char ** i_sAttrNames,unsigned i_nSize)235 MultipleAttrElement::MultipleAttrElement( const char *		i_sName,
236 										  const char **		i_sAttrNames,
237 										  unsigned			i_nSize )
238 	:	EmptyElement(i_sName)
239 {
240 	for ( unsigned i = 0; i < i_nSize; ++i )
241 	{
242 		aAttrNames.push_back(Simstr(i_sAttrNames[i]));
243 		aAttrValues.push_back(Simstr(""));
244 	}
245 }
246 
247 void
Parse(X2CParser & io_rParser)248 MultipleAttrElement::Parse(	X2CParser &	io_rParser )
249 {
250 	io_rParser.Parse_MultipleAttr(aAttrValues, Name(), aAttrNames);
251 }
252 
253 void
Write2Html(HtmlCreator & io_rHC) const254 MultipleAttrElement::Write2Html(	HtmlCreator & io_rHC ) const
255 {
256 	if ( ! aAttrValues[0].is_no_text() )
257 		io_rHC.Write_ReferenceDocu( Name(), aAttrValues[0], aAttrValues[1], aAttrValues[2] );
258 }
259 
260 
261