01: package simpleorm.simplewebapp.requestlet;
02:
03: import simpleorm.simplewebapp.core.*;
04:
05: /**
06: * Output fields as XML
07: */
08: public class WXmlRenderer extends WPageRenderer {
09:
10: @Override
11: protected void doPage() throws Exception {
12: response.setContentType("text/xml"); // "text/requestlet;charset=utf-8"
13: outRaw("<?xml version=\"1.0\"?>");
14: outRaw("<page name='");
15: outEscaped(page.getPageName());
16: outRaw("'>\n");
17: outRaw(" <errors>\n");
18: for (WValidationException ex : page.getErrors()) {
19: outRaw("<error value='");
20: outEscaped(ex + "");
21: outRaw("'>\n");
22: }
23: outRaw(" </errors>\n");
24: for (WPagelet pl : page.getPageStructure().getPagelets()
25: .values())
26: doPagelet(pl);
27: outRaw("</page>\n");
28: }
29:
30: void doPagelet(WPagelet pagelet) throws Exception {
31: page.getPageStructure().setCurrentPagelet(pagelet); // not strictly necessary
32: outRaw(" <pagelet name='");
33: outEscaped(pagelet.getName());
34: outRaw("'>\n");
35: for (WFieldGroup fg : pagelet.getFieldGroupsValues())
36: doFieldGroup(fg);
37: outRaw(" </pagelet>\n");
38: }
39:
40: void doFieldGroup(WFieldGroup group) throws Exception {
41: outRaw(" <field-group name='");
42: outEscaped(group.getName());
43: outRaw("'>\n");
44: if (group instanceof WFieldGroupList) {
45: WPageletList pl = (WPageletList) group.getPagelet();
46: while (pl.doListRow())
47: doRow(group, pl.getRowIndex());
48: } else
49: doRow(group, 1);
50: outRaw(" </field-group>\n");
51: }
52:
53: void doRow(WFieldGroup group, int index) throws Exception {
54: outRaw(" <row index='");
55: outEscaped(index + "");
56: outRaw("'>\n");
57: for (WField fld : group.getValues())
58: doField(fld);
59: outRaw(" </row>\n");
60: }
61:
62: void doField(WField field) throws Exception {
63: outRaw(" <field name='");
64: outEscaped(field.getName());
65: outRaw("' value='");
66: outEscaped(field.getText());
67: outRaw("'/>\n");
68: }
69:
70: }
|