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 32 XmlElement::XmlElement( const char * i_sName ) 33 : sName(i_sName) 34 { 35 } 36 37 void 38 XmlElement::Insert2Index( Index & ) const 39 { 40 // Default version. Does nothing. 41 } 42 43 XmlElement * 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 56 MultipleElement::~MultipleElement() 57 { 58 } 59 60 MultipleElement::MultipleElement( const char * i_sName ) 61 : XmlElement(i_sName) 62 { 63 } 64 65 void 66 MultipleElement::AddChild( XmlElement & let_drElement ) 67 { 68 aChildren.push_back(&let_drElement); 69 } 70 71 void 72 SequenceElement::Parse( X2CParser & io_rParser ) 73 { 74 io_rParser.Parse_Sequence( Children(), Name() ); 75 } 76 77 void 78 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 95 SequenceElement::SequenceElement( const char * i_sName, 96 unsigned i_nIndexNameElement ) 97 : MultipleElement(i_sName), 98 nIndexNameElement(i_nIndexNameElement) 99 { 100 } 101 102 FreeChoiceElement::FreeChoiceElement() 103 : MultipleElement("") 104 { 105 } 106 107 void 108 FreeChoiceElement::Parse( X2CParser & io_rParser ) 109 { 110 io_rParser.Parse_FreeChoice(Children()); 111 } 112 113 void 114 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 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 130 ListElement::Parse( X2CParser & io_rParser ) 131 { 132 io_rParser.Parse_List( *this ); 133 } 134 135 void 136 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 * 145 ListElement::Create_and_Add_NewElement() 146 { 147 XmlElement * pNew = (*fCreateNewElement)(Name()); 148 Children().push_back( pNew ); 149 return pNew; 150 } 151 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 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 169 SglTextElement::Parse( X2CParser & io_rParser ) 170 { 171 io_rParser.Parse_Text(sContent, Name(), IsReversedName()); 172 } 173 174 void 175 SglTextElement::Write2Html( HtmlCreator & io_rHC ) const 176 { 177 if ( !sContent.is_no_text() ) 178 io_rHC.Write_SglTextElement( *this ); 179 } 180 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 189 MultipleTextElement::Parse( X2CParser & io_rParser ) 190 { 191 io_rParser.Parse_MultipleText(aContent, Name(), IsReversedName()); 192 } 193 194 void 195 MultipleTextElement::Write2Html( HtmlCreator & io_rHC ) const 196 { 197 if (Size() > 0) 198 io_rHC.Write_MultiTextElement( *this ); 199 } 200 201 const Simstr & 202 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 211 EmptyElement::EmptyElement( const char * i_sName ) 212 : XmlElement(i_sName) 213 { 214 } 215 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 224 SglAttrElement::Parse( X2CParser & io_rParser ) 225 { 226 io_rParser.Parse_SglAttr(sAttrValue, Name(), sAttrName); 227 } 228 229 void 230 SglAttrElement::Write2Html( HtmlCreator & io_rHC ) const 231 { 232 io_rHC.Write_SglText( Name(), sAttrValue ); 233 } 234 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 248 MultipleAttrElement::Parse( X2CParser & io_rParser ) 249 { 250 io_rParser.Parse_MultipleAttr(aAttrValues, Name(), aAttrNames); 251 } 252 253 void 254 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