xref: /trunk/main/xml2cmp/source/xcd/xmlelem.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 
29 #include <xmlelem.hxx>
30 
31 
32 // NOT FULLY DEFINED SERVICES
33 #include <parse.hxx>
34 #include <cr_html.hxx>
35 
36 XmlElement::XmlElement( const char * i_sName )
37     : sName(i_sName)
38 {
39 }
40 
41 void
42 XmlElement::Insert2Index( Index & ) const
43 {
44     //  Default version. Does nothing.
45 }
46 
47 XmlElement *
48 MultipleElement::FindChild( const Simstr & i_sChildName )
49 {
50     unsigned i_max = aChildren.size();
51     for ( unsigned i = 0; i < i_max; ++i )
52     {
53         if ( aChildren[i]->Name() == i_sChildName )
54             return aChildren[i];
55     }
56 
57     return 0;
58 }
59 
60 MultipleElement::~MultipleElement()
61 {
62 }
63 
64 MultipleElement::MultipleElement( const char * i_sName )
65     :   XmlElement(i_sName)
66 {
67 }
68 
69 void
70 MultipleElement::AddChild( XmlElement & let_drElement )
71 {
72     aChildren.push_back(&let_drElement);
73 }
74 
75 void
76 SequenceElement::Parse( X2CParser & io_rParser )
77 {
78     io_rParser.Parse_Sequence( Children(), Name() );
79 }
80 
81 void
82 SequenceElement::Write2Html( HtmlCreator & io_rHC ) const
83 {
84     io_rHC.StartTable();
85 
86     Children()[nIndexNameElement]->Write2Html(io_rHC);
87     for ( unsigned i = 0; i < Children().size(); ++i )
88     {
89         if (i != nIndexNameElement)
90         {
91             Children()[i]->Write2Html(io_rHC);
92         }
93     }  // end for
94 
95     io_rHC.FinishTable();
96 }
97 
98 
99 SequenceElement::SequenceElement( const char * i_sName,
100                                   unsigned     i_nIndexNameElement )
101     :   MultipleElement(i_sName),
102         nIndexNameElement(i_nIndexNameElement)
103 {
104 }
105 
106 FreeChoiceElement::FreeChoiceElement()
107     :   MultipleElement("")
108 {
109 }
110 
111 void
112 FreeChoiceElement::Parse( X2CParser & io_rParser )
113 {
114     io_rParser.Parse_FreeChoice(Children());
115 }
116 
117 void
118 FreeChoiceElement::Write2Html( HtmlCreator & io_rHC ) const
119 {
120     for ( unsigned i = 0; i < Children().size(); ++i )
121     {
122         Children()[i]->Write2Html(io_rHC);
123     }  // end for
124 }
125 
126 ListElement::ListElement( const char * i_sElementsName,
127                           F_CREATE     i_fCreateNewElement )
128     :   MultipleElement(i_sElementsName),
129         fCreateNewElement(i_fCreateNewElement)
130 {
131 }
132 
133 void
134 ListElement::Parse( X2CParser & io_rParser )
135 {
136     io_rParser.Parse_List(  *this );
137 }
138 
139 void
140 ListElement::Write2Html( HtmlCreator & io_rHC ) const
141 {
142     for ( unsigned i = 0; i < Children().size(); ++i )
143     {
144         Children()[i]->Write2Html(io_rHC);
145     }  // end for
146 }
147 
148 XmlElement *
149 ListElement::Create_and_Add_NewElement()
150 {
151     XmlElement * pNew = (*fCreateNewElement)(Name());
152     Children().push_back( pNew );
153     return pNew;
154 }
155 
156 TextElement::TextElement( const char *      i_sName,
157                           E_LinkType        i_eLinkType,
158                           bool              i_bReverseName )
159     :   XmlElement(i_sName),
160         eLinkType(i_eLinkType),
161         bReverseName(i_bReverseName)
162 {
163 }
164 
165 SglTextElement::SglTextElement( const char *        i_sName,
166                                 E_LinkType          i_eLinkType,
167                                 bool                i_bReverseName )
168     :   TextElement(i_sName, i_eLinkType, i_bReverseName)
169 {
170 }
171 
172 void
173 SglTextElement::Parse( X2CParser & io_rParser )
174 {
175     io_rParser.Parse_Text(sContent, Name(), IsReversedName());
176 }
177 
178 void
179 SglTextElement::Write2Html( HtmlCreator & io_rHC ) const
180 {
181     if ( !sContent.is_no_text() )
182         io_rHC.Write_SglTextElement( *this );
183 }
184 
185 MultipleTextElement::MultipleTextElement( const char *      i_sName,
186                                           E_LinkType        i_eLinkType,
187                                           bool              i_bReverseName )
188     :   TextElement(i_sName, i_eLinkType, i_bReverseName)
189 {
190 }
191 
192 void
193 MultipleTextElement::Parse( X2CParser & io_rParser )
194 {
195     io_rParser.Parse_MultipleText(aContent, Name(), IsReversedName());
196 }
197 
198 void
199 MultipleTextElement::Write2Html(    HtmlCreator & io_rHC ) const
200 {
201     if (Size() > 0)
202         io_rHC.Write_MultiTextElement( *this );
203 }
204 
205 const Simstr &
206 MultipleTextElement::Data( unsigned i_nNr ) const
207 {
208     static const Simstr sNull_;
209 
210     if (aContent.is_valid_index(i_nNr))
211         return aContent[i_nNr];
212     return sNull_;
213 }
214 
215 EmptyElement::EmptyElement( const char * i_sName )
216     :   XmlElement(i_sName)
217 {
218 }
219 
220 SglAttrElement::SglAttrElement( const char *        i_sName,
221                                 const char *        i_sAttrName )
222     :   EmptyElement(i_sName),
223         sAttrName(i_sAttrName)
224 {
225 }
226 
227 void
228 SglAttrElement::Parse( X2CParser & io_rParser )
229 {
230     io_rParser.Parse_SglAttr(sAttrValue, Name(), sAttrName);
231 }
232 
233 void
234 SglAttrElement::Write2Html( HtmlCreator & io_rHC ) const
235 {
236     io_rHC.Write_SglText( Name(), sAttrValue );
237 }
238 
239 MultipleAttrElement::MultipleAttrElement( const char *      i_sName,
240                                           const char **     i_sAttrNames,
241                                           unsigned          i_nSize )
242     :   EmptyElement(i_sName)
243 {
244     for ( unsigned i = 0; i < i_nSize; ++i )
245     {
246         aAttrNames.push_back(Simstr(i_sAttrNames[i]));
247         aAttrValues.push_back(Simstr(""));
248     }
249 }
250 
251 void
252 MultipleAttrElement::Parse( X2CParser & io_rParser )
253 {
254     io_rParser.Parse_MultipleAttr(aAttrValues, Name(), aAttrNames);
255 }
256 
257 void
258 MultipleAttrElement::Write2Html(    HtmlCreator & io_rHC ) const
259 {
260     if ( ! aAttrValues[0].is_no_text() )
261         io_rHC.Write_ReferenceDocu( Name(), aAttrValues[0], aAttrValues[1], aAttrValues[2] );
262 }
263 
264 
265