1
2 package eu.simuline.util.sgml;
3
4 import java.util.List;
5 import java.util.ArrayList;
6
7 import org.xml.sax.ContentHandler;
8 import org.xml.sax.Locator;
9 import org.xml.sax.SAXException;
10 import org.xml.sax.Attributes;
11
12
13
14
15
16
17
18 public final class SavingHandler
19 implements ContentHandler, ParseExceptionHandler {
20
21
22
23
24
25 public static final String START_OF_DOCUMENT = "start of document";
26 public static final String END_OF_DOCUMENT = "end of document";
27
28
29
30
31
32
33
34
35 private List<String> events;
36
37
38
39
40 private boolean strict;
41
42
43
44
45
46
47
48
49
50
51
52
53 public SavingHandler(boolean strict) {
54 this.events = new ArrayList<String>();
55 this.strict = strict;
56 }
57
58
59
60
61 public SavingHandler() {
62 this(true);
63 }
64
65
66
67
68
69
70
71
72
73
74
75
76 public List<String> getEvents() {
77 return this.events;
78 }
79
80
81
82
83
84 public void setDocumentLocator(Locator locator) {
85
86 }
87
88 public void startDocument() throws SAXException {
89 this.events.add(START_OF_DOCUMENT);
90 }
91
92 public void endDocument() throws SAXException {
93 this.events.add(END_OF_DOCUMENT);
94 }
95
96 public void startPrefixMapping(String prefix,
97 String uri)
98 throws SAXException {
99
100 }
101
102 public void endPrefixMapping(String prefix)
103 throws SAXException {
104
105 }
106
107 public void startElement(String namespaceURI,
108 String localName,
109 String qName,
110 Attributes atts)
111 throws SAXException {
112 this.events.add("TS<" + qName + ">");
113 }
114
115 public void endElement(String namespaceURI,
116 String localName,
117 String qName)
118 throws SAXException {
119 this.events.add("TE</" + qName + ">");
120 }
121
122 public void characters(char[] chr,
123 int start,
124 int length)
125 throws SAXException {
126
127 }
128
129 public void ignorableWhitespace(char[] chr,
130 int start,
131 int length)
132 throws SAXException {
133
134 }
135
136 public void processingInstruction(String target,
137 String data)
138 throws SAXException {
139 if (this.strict) {
140 this.events.add("PI<!" + target + ", " + data + ">");
141 }
142
143 }
144
145 public void skippedEntity(String name)
146 throws SAXException {
147
148 }
149
150
151
152
153
154 public void foundMultipleAttribute(String attrName,
155 Object oldAttrValue) {
156 StringBuilder buf = new StringBuilder();
157 buf.append("Found second value for attribute \"");
158 buf.append(attrName);
159 buf.append("\"; overwritten ");
160 if (oldAttrValue == AttributesImpl.NO_VALUE) {
161 buf.append("no value. ");
162 } else {
163 buf.append("old value \"");
164 buf.append(oldAttrValue);
165 buf.append('\"');
166 }
167
168 this.events.add(buf.toString());
169 }
170
171
172 public void foundIllegalCharInTag(char chr) {
173 this.events.add("exc: ill letter in tag: " + chr);
174 }
175
176 public void foundCharAfterEndOfEndTag(char chr) {
177 this.events.add("exc: etter after eo EndTag: " + chr);
178 }
179
180 public void foundUnexpectedEndOfDocument() {
181
182 }
183 }
184