1
2
3
4
5
6
7
8
9
10
11
12
13
14 package org.overturetool.api.xml;
15
16
17
18
19
20 import jp.co.csk.vdm.toolbox.VDM.*;
21 import java.util.*;
22
23
24
25
26 public abstract class XmlFileOutputVisitor extends XmlVisitor {
27
28
29 static UTIL.VDMCompare vdmComp = new UTIL.VDMCompare();
30
31
32
33 private String encoding = null;
34
35
36
37 private Long indentCount = null;
38
39
40
41 private static final String INDENT = new String(" ");
42
43
44
45
46 private void vdm_init_XmlFileOutputVisitor () throws CGException {
47 try {
48
49 encoding = new String("");
50 indentCount = new Long(0);
51 }
52 catch (Exception e){
53
54 e.printStackTrace(System.out);
55 System.out.println(e.getMessage());
56 }
57 }
58
59
60
61
62 public XmlFileOutputVisitor () throws CGException {
63 vdm_init_XmlFileOutputVisitor();
64 }
65
66
67
68
69 public void setEncoding (final String encodingType) throws CGException {
70 encoding = UTIL.ConvertToString(UTIL.clone(encodingType));
71 }
72
73
74
75
76 abstract protected void print (final String text) throws CGException ;
77
78
79
80
81 private void printData (final String pval) throws CGException {
82 print(pval);
83 }
84
85
86
87
88 private void printAttribute (final String pval) throws CGException {
89
90 String tmpArg_v_3 = null;
91 String var1_4 = null;
92 var1_4 = new String("\"").concat(pval);
93 tmpArg_v_3 = var1_4.concat(new String("\""));
94 print(tmpArg_v_3);
95 }
96
97
98
99
100 public XmlFileOutputVisitor (final String var_1_1) throws CGException {
101 vdm_init_XmlFileOutputVisitor();
102 }
103
104
105
106
107 public void VisitXmlDocument (final XmlDocument pxmld) throws CGException {
108
109 Boolean cont = null;
110 XmlEntityList obj_2 = null;
111 obj_2 = pxmld.entities;
112 cont = obj_2.First();
113 if ((new Long(encoding.length()).intValue() == new Long(0).intValue()))
114 print(new String("<?xml version=\"1.0\"?>\n"));
115 else {
116
117 String tmpArg_v_9 = null;
118 String var1_10 = null;
119 var1_10 = new String("<?xml version=\"1.0\" encoding=\"").concat(encoding);
120 tmpArg_v_9 = var1_10.concat(new String("\"?>\n"));
121 print(tmpArg_v_9);
122 }
123 while ( cont.booleanValue()){
124
125 XmlEntity ent = null;
126 XmlEntityList obj_17 = null;
127 obj_17 = pxmld.entities;
128 ent = (XmlEntity) obj_17.getEntity();
129 ent.accept((XmlVisitor) this);
130 Boolean rhs_21 = null;
131 XmlEntityList obj_22 = null;
132 obj_22 = pxmld.entities;
133 rhs_21 = obj_22.Next();
134 cont = (Boolean) UTIL.clone(rhs_21);
135 }
136 }
137
138
139
140
141 public void VisitXmlEntity (final XmlEntity pxmle) throws CGException {
142
143 Boolean cont = null;
144 XmlAttributeList obj_2 = null;
145 obj_2 = pxmle.attributes;
146 cont = obj_2.First();
147 indentCount = UTIL.NumberToLong(UTIL.clone(new Long(indentCount.intValue() + new Long(1).intValue())));
148 String tmpArg_v_8 = null;
149 String var1_9 = null;
150 var1_9 = GetIndent().concat(new String("<"));
151 String var2_12 = null;
152 var2_12 = pxmle.name;
153 tmpArg_v_8 = var1_9.concat(var2_12);
154 print(tmpArg_v_8);
155 while ( cont.booleanValue()){
156
157 XmlAttribute attr = null;
158 XmlAttributeList obj_15 = null;
159 obj_15 = pxmle.attributes;
160 attr = (XmlAttribute) obj_15.getAttribute();
161 attr.accept((XmlVisitor) this);
162 Boolean rhs_19 = null;
163 XmlAttributeList obj_20 = null;
164 obj_20 = pxmle.attributes;
165 rhs_19 = obj_20.Next();
166 cont = (Boolean) UTIL.clone(rhs_19);
167 }
168 Boolean cond_22 = null;
169 Long var1_23 = null;
170 XmlEntityList obj_24 = null;
171 obj_24 = pxmle.entities;
172 var1_23 = obj_24.Length();
173 cond_22 = new Boolean((var1_23.intValue()) > (new Long(0).intValue()));
174 if (cond_22.booleanValue()) {
175
176 print(new String(">\n"));
177 Boolean rhs_50 = null;
178 XmlEntityList obj_51 = null;
179 obj_51 = pxmle.entities;
180 rhs_50 = obj_51.First();
181 cont = (Boolean) UTIL.clone(rhs_50);
182 while ( cont.booleanValue()){
183
184 XmlEntity ent = null;
185 XmlEntityList obj_54 = null;
186 obj_54 = pxmle.entities;
187 ent = (XmlEntity) obj_54.getEntity();
188 ent.accept((XmlVisitor) this);
189 Boolean rhs_58 = null;
190 XmlEntityList obj_59 = null;
191 obj_59 = pxmle.entities;
192 rhs_58 = obj_59.Next();
193 cont = (Boolean) UTIL.clone(rhs_58);
194 }
195 String tmpArg_v_62 = null;
196 String var1_63 = null;
197 String var1_64 = null;
198 var1_64 = GetIndent().concat(new String("</"));
199 String var2_67 = null;
200 var2_67 = pxmle.name;
201 var1_63 = var1_64.concat(var2_67);
202 tmpArg_v_62 = var1_63.concat(new String(">\n"));
203 print(tmpArg_v_62);
204 }
205 else {
206
207 Boolean cond_42 = null;
208 XmlData var1_43 = null;
209 var1_43 = pxmle.data;
210 cond_42 = new Boolean(UTIL.equals(var1_43, null));
211 if (cond_42.booleanValue())
212 print(new String("/>\n"));
213 else {
214
215 print(new String(">"));
216 XmlData obj_30 = null;
217 obj_30 = pxmle.data;
218 obj_30.accept((XmlVisitor) this);
219 String tmpArg_v_34 = null;
220 String var1_35 = null;
221 String var1_36 = null;
222 var1_36 = GetIndent().concat(new String("</"));
223 String var2_39 = null;
224 var2_39 = pxmle.name;
225 var1_35 = var1_36.concat(var2_39);
226 tmpArg_v_34 = var1_35.concat(new String(">\n"));
227 print(tmpArg_v_34);
228 }
229 }
230 indentCount = UTIL.NumberToLong(UTIL.clone(new Long(indentCount.intValue() - new Long(1).intValue())));
231 }
232
233
234
235
236 public void VisitXmlAttribute (final XmlAttribute pattr) throws CGException {
237
238 String tmpArg_v_3 = null;
239 String var1_4 = null;
240 String var2_6 = null;
241 var2_6 = pattr.name;
242 var1_4 = new String(" ").concat(var2_6);
243 tmpArg_v_3 = var1_4.concat(new String("="));
244 print(tmpArg_v_3);
245 String tmpArg_v_10 = null;
246 tmpArg_v_10 = pattr.val;
247 printAttribute(tmpArg_v_10);
248 }
249
250
251
252
253 public void VisitXmlData (final XmlData pdata) throws CGException {
254
255 String tmpArg_v_3 = null;
256 tmpArg_v_3 = pdata.data;
257 printData(tmpArg_v_3);
258 }
259
260
261
262
263 private String GetIndent () throws CGException {
264
265 String ind = new String("");
266 Long i = new Long(0);
267 while ( ((i.intValue()) < (indentCount.intValue()))){
268
269 i = UTIL.NumberToLong(UTIL.clone(new Long(i.intValue() + new Long(1).intValue())));
270 String rhs_7 = null;
271 rhs_7 = ind.concat(INDENT);
272 ind = UTIL.ConvertToString(UTIL.clone(rhs_7));
273 }
274 return ind;
275 }
276
277
278 }
279 ;