KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > layout > XMLLE


1 package jimm.datavision.layout;
2 import jimm.datavision.*;
3 import jimm.datavision.field.*;
4 import jimm.util.XMLWriter;
5
6 /**
7  * An XML layout engine.
8  *
9  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
10  */

11 public class XMLLE extends SortedLayoutEngine {
12
13 protected XMLWriter iout;
14 protected String JavaDoc encoding;
15
16 /**
17  * Constructor.
18  *
19  * @param out an indent writer
20  */

21 public XMLLE(XMLWriter out) {
22     this(out, Report.XML_ENCODING_ATTRIBUTE);
23 }
24
25 /**
26  * Constructor. Optionally specify the encoding string to write to the
27  * XML file. This string is written as the XMLDecl encoding attribute.
28  * Use legal XML values like "UTF-8", not Java values like "UTF8".
29  *
30  * @param out an indent writer
31  * @param enc an XML encoding string; if <code>null</code>, uses
32  * {@link Report}<code>.XML_ENCODING_ATTRIBUTE</code>
33  */

34 public XMLLE(XMLWriter out, String JavaDoc enc) {
35     super(out);
36     iout = out;
37     encoding = (enc == null ? Report.XML_ENCODING_ATTRIBUTE : enc);
38 }
39
40 protected void doStart() {
41     iout.xmlDecl(encoding);
42     iout.comment("Generated by DataVision version " + info.Version);
43     iout.comment(info.URL);
44     iout.startElement("report");
45 }
46
47 protected void doEnd() {
48     iout.endElement();
49     iout.flush();
50 }
51
52 protected void doStartPage() {
53     iout.comment("============== Page " + pageNumber()
54          + " ==============");
55     iout.startElement("newpage");
56     iout.attr("number", pageNumber());
57     iout.endElement();
58 }
59
60 protected void doOutputSection(Section s) {
61     iout.startElement("section");
62     iout.attr("type", currentSectionTypeAsString());
63     super.doOutputSection(s);
64     iout.endElement();
65 }
66
67 protected void doOutputField(Field field) {
68     iout.startElement("field");
69     iout.attr("id", field.getId());
70     iout.attr("type", field.typeString());
71     if (field instanceof SpecialField)
72     iout.attr("value", field.getValue());
73     else if (field instanceof ColumnField)
74     iout.attr(" column", ((ColumnField)field).getColumn().fullName());
75     else if (field instanceof AggregateField) {
76     AggregateField sf = (AggregateField)field;
77     if (sf.getGroup() != null)
78         iout.attr("group", sf.getGroup().getSelectable().getDisplayName());
79     }
80
81     iout.cdata(field.toString());
82     iout.endElement();
83 }
84
85 protected void doOutputImage(ImageField image) {
86     doOutputField(image);
87 }
88
89 protected void doOutputLine(Line l) {
90     l.writeXML(iout);
91 }
92
93 }
94
95
Popular Tags