|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| package nu.xom; |
|
24 |
| |
|
25 |
| |
|
26 |
| |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| class NonVerifyingHandler extends XOMHandler { |
|
31 |
| |
|
32 |
1079
| NonVerifyingHandler(NodeFactory factory) {
|
|
33 |
1079
| super(factory);
|
|
34 |
| } |
|
35 |
| |
|
36 |
| |
|
37 |
2164210
| public void startElement(String namespaceURI, String localName,
|
|
38 |
| String qualifiedName, org.xml.sax.Attributes attributes) { |
|
39 |
| |
|
40 |
2164210
| flushText();
|
|
41 |
2164210
| Element element = Element.build(qualifiedName, namespaceURI, localName);
|
|
42 |
2164200
| if (parent == document) {
|
|
43 |
22015
| document.setRootElement(element);
|
|
44 |
22015
| inProlog = false;
|
|
45 |
| } |
|
46 |
| |
|
47 |
2164200
| current = element;
|
|
48 |
| |
|
49 |
2164200
| parents.add(element);
|
|
50 |
| |
|
51 |
2164200
| if (parent != document) {
|
|
52 |
| |
|
53 |
2142185
| parent.fastInsertChild(element, parent.getChildCount());
|
|
54 |
| } |
|
55 |
| |
|
56 |
| |
|
57 |
| |
|
58 |
| |
|
59 |
| |
|
60 |
2164200
| String baseURI = locator.getSystemId();
|
|
61 |
2164200
| if (baseURI != null && !baseURI.equals(documentBaseURI)) {
|
|
62 |
6086
| element.setActualBaseURI(baseURI);
|
|
63 |
| } |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
2164200
| int length = attributes.getLength();
|
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| |
|
73 |
| |
|
74 |
| |
|
75 |
2164200
| for (int i = 0; i < length; i++) {
|
|
76 |
2152782
| String qName = attributes.getQName(i);
|
|
77 |
2152782
| if (qName.startsWith("xmlns:") || qName.equals("xmlns")) {
|
|
78 |
2490
| continue;
|
|
79 |
| } |
|
80 |
| else { |
|
81 |
2150292
| String namespace = attributes.getURI(i);
|
|
82 |
2150292
| String value = attributes.getValue(i);
|
|
83 |
2150292
| Attribute attribute = Attribute.build(
|
|
84 |
| qName, |
|
85 |
| namespace, |
|
86 |
| value, |
|
87 |
| convertStringToType(attributes.getType(i)), |
|
88 |
| attributes.getLocalName(i) |
|
89 |
| ); |
|
90 |
2150292
| element.fastAddAttribute(attribute);
|
|
91 |
| } |
|
92 |
| } |
|
93 |
| |
|
94 |
| |
|
95 |
2164200
| for (int i = 0; i < length; i++) {
|
|
96 |
2152771
| String qName = attributes.getQName(i);
|
|
97 |
2152771
| if (qName.startsWith("xmlns:")) {
|
|
98 |
2274
| String namespaceName = attributes.getValue(i);
|
|
99 |
2274
| String namespacePrefix = qName.substring(6);
|
|
100 |
2274
| String currentValue
|
|
101 |
| = element.getNamespaceURI(namespacePrefix); |
|
102 |
2274
| if (!namespaceName.equals(currentValue)) {
|
|
103 |
1156
| element.addNamespaceDeclaration(
|
|
104 |
| namespacePrefix, namespaceName); |
|
105 |
| } |
|
106 |
| } |
|
107 |
2150497
| else if (qName.equals("xmlns")) {
|
|
108 |
213
| String namespaceName = attributes.getValue(i);
|
|
109 |
213
| String namespacePrefix = "";
|
|
110 |
213
| String currentValue
|
|
111 |
| = element.getNamespaceURI(namespacePrefix); |
|
112 |
213
| if (!namespaceName.equals(currentValue)) {
|
|
113 |
26
| element.addNamespaceDeclaration(namespacePrefix,
|
|
114 |
| namespaceName); |
|
115 |
| } |
|
116 |
| } |
|
117 |
| } |
|
118 |
| |
|
119 |
| |
|
120 |
2163972
| parent = element;
|
|
121 |
| } |
|
122 |
| |
|
123 |
| |
|
124 |
2163928
| public void endElement(
|
|
125 |
| String namespaceURI, String localName, String qualifiedName) { |
|
126 |
| |
|
127 |
| |
|
128 |
| |
|
129 |
2163928
| current = (ParentNode) parents.remove(parents.size()-1);
|
|
130 |
2163928
| flushText();
|
|
131 |
| |
|
132 |
2163928
| parent = current.getParent();
|
|
133 |
| |
|
134 |
2163928
| if (parent.isDocument()) {
|
|
135 |
21769
| Document doc = (Document) parent;
|
|
136 |
21769
| doc.setRootElement((Element) current);
|
|
137 |
| } |
|
138 |
| |
|
139 |
| } |
|
140 |
| |
|
141 |
| |
|
142 |
| |
|
143 |
4335025
| private void flushText() {
|
|
144 |
| |
|
145 |
4335025
| if (buffer != null) {
|
|
146 |
52291
| textString = buffer.toString();
|
|
147 |
52291
| buffer = null;
|
|
148 |
| } |
|
149 |
| |
|
150 |
4335025
| if (textString != null) {
|
|
151 |
2389553
| Text result;
|
|
152 |
2389553
| if (!inCDATA) {
|
|
153 |
2389078
| result = Text.build(textString);
|
|
154 |
| } |
|
155 |
| else { |
|
156 |
475
| result = CDATASection.build(textString);
|
|
157 |
| } |
|
158 |
2389553
| parent.fastInsertChild(result, parent.getChildCount());
|
|
159 |
2389553
| textString = null;
|
|
160 |
| } |
|
161 |
4335025
| inCDATA = false;
|
|
162 |
4335025
| finishedCDATA = false;
|
|
163 |
| |
|
164 |
| } |
|
165 |
| |
|
166 |
| |
|
167 |
545
| public void processingInstruction(String target, String data) {
|
|
168 |
| |
|
169 |
| |
|
170 |
| |
|
171 |
377
| if (!inDTD) flushText();
|
|
172 |
6
| else if (!inInternalSubset()) return;
|
|
173 |
| |
|
174 |
539
| ProcessingInstruction result = ProcessingInstruction.build(target, data);
|
|
175 |
| |
|
176 |
539
| if (!inDTD) {
|
|
177 |
377
| if (inProlog) {
|
|
178 |
269
| parent.fastInsertChild(result, position);
|
|
179 |
269
| position++;
|
|
180 |
| } |
|
181 |
| else { |
|
182 |
108
| parent.fastInsertChild(result, parent.getChildCount());
|
|
183 |
| } |
|
184 |
| } |
|
185 |
| else { |
|
186 |
162
| internalDTDSubset.append(" ");
|
|
187 |
162
| internalDTDSubset.append(result.toXML());
|
|
188 |
162
| internalDTDSubset.append("\n");
|
|
189 |
| } |
|
190 |
| |
|
191 |
| } |
|
192 |
| |
|
193 |
| |
|
194 |
| |
|
195 |
2505
| public void startDTD(String rootName, String publicID,
|
|
196 |
| String systemID) { |
|
197 |
| |
|
198 |
2505
| inDTD = true;
|
|
199 |
2505
| DocType doctype = DocType.build(rootName, publicID, systemID);
|
|
200 |
2505
| document.fastInsertChild(doctype, position);
|
|
201 |
2505
| position++;
|
|
202 |
2505
| internalDTDSubset = new StringBuffer();
|
|
203 |
2505
| this.doctype = doctype;
|
|
204 |
| |
|
205 |
| } |
|
206 |
| |
|
207 |
| |
|
208 |
13291
| public void comment(char[] text, int start, int length) {
|
|
209 |
| |
|
210 |
6510
| if (!inDTD) flushText();
|
|
211 |
5812
| else if (!inInternalSubset()) return;
|
|
212 |
| |
|
213 |
7479
| Comment result = Comment.build(new String(text, start, length));
|
|
214 |
| |
|
215 |
7479
| if (!inDTD) {
|
|
216 |
6510
| if (inProlog) {
|
|
217 |
1326
| parent.insertChild(result, position);
|
|
218 |
1326
| position++;
|
|
219 |
| } |
|
220 |
| else { |
|
221 |
5184
| parent.fastInsertChild(result, parent.getChildCount());
|
|
222 |
| } |
|
223 |
| } |
|
224 |
| else { |
|
225 |
969
| internalDTDSubset.append(" ");
|
|
226 |
969
| internalDTDSubset.append(result.toXML());
|
|
227 |
969
| internalDTDSubset.append("\n");
|
|
228 |
| } |
|
229 |
| |
|
230 |
| } |
|
231 |
| |
|
232 |
| } |