01: package jimm.datavision.layout;
02:
03: import jimm.datavision.*;
04: import jimm.datavision.field.*;
05: import jimm.util.XMLWriter;
06:
07: /**
08: * An XML layout engine.
09: *
10: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
11: */
12: public class XMLLE extends SortedLayoutEngine {
13:
14: protected XMLWriter iout;
15: protected String encoding;
16:
17: /**
18: * Constructor.
19: *
20: * @param out an indent writer
21: */
22: public XMLLE(XMLWriter out) {
23: this (out, Report.XML_ENCODING_ATTRIBUTE);
24: }
25:
26: /**
27: * Constructor. Optionally specify the encoding string to write to the
28: * XML file. This string is written as the XMLDecl encoding attribute.
29: * Use legal XML values like "UTF-8", not Java values like "UTF8".
30: *
31: * @param out an indent writer
32: * @param enc an XML encoding string; if <code>null</code>, uses
33: * {@link Report}<code>.XML_ENCODING_ATTRIBUTE</code>
34: */
35: public XMLLE(XMLWriter out, String enc) {
36: super (out);
37: iout = out;
38: encoding = (enc == null ? Report.XML_ENCODING_ATTRIBUTE : enc);
39: }
40:
41: protected void doStart() {
42: iout.xmlDecl(encoding);
43: iout.comment("Generated by DataVision version " + info.Version);
44: iout.comment(info.URL);
45: iout.startElement("report");
46: }
47:
48: protected void doEnd() {
49: iout.endElement();
50: iout.flush();
51: }
52:
53: protected void doStartPage() {
54: iout.comment("============== Page " + pageNumber()
55: + " ==============");
56: iout.startElement("newpage");
57: iout.attr("number", pageNumber());
58: iout.endElement();
59: }
60:
61: protected void doOutputSection(Section s) {
62: iout.startElement("section");
63: iout.attr("type", currentSectionTypeAsString());
64: super .doOutputSection(s);
65: iout.endElement();
66: }
67:
68: protected void doOutputField(Field field) {
69: iout.startElement("field");
70: iout.attr("id", field.getId());
71: iout.attr("type", field.typeString());
72: if (field instanceof SpecialField)
73: iout.attr("value", field.getValue());
74: else if (field instanceof ColumnField)
75: iout.attr(" column", ((ColumnField) field).getColumn()
76: .fullName());
77: else if (field instanceof AggregateField) {
78: AggregateField sf = (AggregateField) field;
79: if (sf.getGroup() != null)
80: iout.attr("group", sf.getGroup().getSelectable()
81: .getDisplayName());
82: }
83:
84: iout.cdata(field.toString());
85: iout.endElement();
86: }
87:
88: protected void doOutputImage(ImageField image) {
89: doOutputField(image);
90: }
91:
92: protected void doOutputLine(Line l) {
93: l.writeXML(iout);
94: }
95:
96: }
|