1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44:
45: import ;
46: import ;
47: import ;
48:
49: import ;
50: import ;
51:
52:
53:
74: public class Consumer extends DomConsumer
75: {
76:
80:
81: public Consumer ()
82: throws SAXException
83: {
84: super (DomDocument.class);
85: setHandler (new Backdoor (this));
86: }
87:
88:
92:
93: public Consumer (EventConsumer next)
94: throws SAXException
95: {
96: super (DomDocument.class, next);
97: setHandler (new Backdoor (this));
98: }
99:
100:
106: public static class Backdoor extends DomConsumer.Handler
107: {
108:
114: protected Backdoor (DomConsumer consumer)
115: throws SAXException
116: { super (consumer); }
117:
118:
119: private DomDoctype getDoctype ()
120: throws SAXException
121: {
122: DomDocument doc = (DomDocument) getDocument ();
123: DocumentType dt = doc.getDoctype ();
124:
125: if (dt == null)
126: throw new SAXException ("doctype missing!");
127: return (DomDoctype) dt;
128: }
129:
130:
131: public void startDTD (String name, String publicId, String systemId)
132: throws SAXException
133: {
134: DomDocument doc = (DomDocument) getDocument ();
135:
136: super.startDTD (name, publicId, systemId);
137:
138: DomDoctype dt = new DomDoctype (doc, name, publicId, systemId);
139: doc.appendChild (dt);
140: }
141:
142:
143: public void endDTD ()
144: throws SAXException
145: {
146: super.endDTD ();
147:
148: getDoctype ().makeReadonly ();
149: }
150:
151:
152: public void notationDecl (
153: String name,
154: String publicId, String systemId
155: ) throws SAXException
156: {
157:
158: getDoctype ().declareNotation (name, publicId, systemId);
159: }
160:
161:
162: public void unparsedEntityDecl (
163: String name,
164: String publicId, String systemId,
165: String notationName
166: ) throws SAXException
167: {
168:
169: getDoctype ().declareEntity (name, publicId, systemId,
170: notationName);
171: }
172:
173:
174: public void internalEntityDecl (String name, String value)
175: throws SAXException
176: {
177:
178:
179:
180: getDoctype ().declareEntity (name, null, null, null);
181: }
182:
183:
184: public void externalEntityDecl (
185: String name,
186: String publicId,
187: String systemId
188: ) throws SAXException
189: {
190:
191:
192:
193: getDoctype ().declareEntity (name, publicId, systemId, null);
194: }
195:
196:
197: public void startElement (
198: String uri,
199: String localName,
200: String qName,
201: Attributes atts
202: ) throws SAXException
203: {
204: Node top;
205:
206: super.startElement (uri, localName, qName, atts);
207:
208:
209: top = getTop ();
210: if (!top.hasAttributes () || !(atts instanceof Attributes2))
211: return;
212:
213:
214: DomNamedNodeMap map = (DomNamedNodeMap) top.getAttributes ();
215: Attributes2 attrs = (Attributes2) atts;
216: int length = atts.getLength ();
217:
218:
219: for (int i = 0; i < length; i++) {
220: if (attrs.isSpecified (i))
221: continue;
222:
223:
224: String temp = attrs.getQName (i);
225: DomAttr attr;
226:
227: if ("".equals (temp))
228: attr = (DomAttr) map.getNamedItemNS (attrs.getURI (i),
229: atts.getLocalName (i));
230: else
231: attr = (DomAttr) map.getNamedItem (temp);
232:
233:
234: attr.setSpecified (false);
235: }
236: }
237:
238: public void endElement (
239: String uri,
240: String localName,
241: String qName
242: ) throws SAXException
243: {
244: DomNode top = (DomNode) getTop ();
245: top.compact ();
246: super.endElement (uri, localName, qName);
247: }
248:
249: protected Text createText (
250: boolean isCDATA,
251: char buf [],
252: int off,
253: int len
254: ) {
255: DomDocument doc = (DomDocument) getDocument ();
256:
257: if (isCDATA)
258: return doc.createCDATASection (buf, off, len);
259: else
260: return doc.createTextNode (buf, off, len);
261: }
262:
263: public void elementDecl(String name, String model)
264: throws SAXException
265: {
266: getDoctype().elementDecl(name, model);
267: }
268:
269: public void attributeDecl (
270: String ename,
271: String aname,
272: String type,
273: String mode,
274: String value
275: ) throws SAXException
276: {
277: getDoctype().attributeDecl(ename, aname, type, mode, value);
278:
290:
291: }
292:
293:
294:
295: public void startDocument () throws SAXException
296: {
297: super.startDocument ();
298:
299: DomDocument doc = (DomDocument) getDocument ();
300: doc.setStrictErrorChecking(false);
301: doc.setBuilding(true);
302: }
303:
304: public void endDocument ()
305: throws SAXException
306: {
307: DomDocument doc = (DomDocument) getDocument ();
308: doc.setStrictErrorChecking(true);
309: doc.setBuilding(false);
310: doc.compact ();
311: DomDoctype doctype = (DomDoctype) doc.getDoctype();
312: if (doctype != null)
313: {
314: doctype.makeReadonly();
315: }
316: super.endDocument ();
317: }
318:
319:
320:
321:
322: public boolean canPopulateEntityRefs ()
323: { return true; }
324:
325: public void startEntity (String name)
326: throws SAXException
327: {
328: if (name.charAt (0) == '%' || "[dtd]".equals (name))
329: return;
330: super.startEntity (name);
331:
332: DomNode top = (DomNode) getTop ();
333:
334: if (top.getNodeType () == Node.ENTITY_REFERENCE_NODE)
335: top.readonly = false;
336: }
337:
338: public void endEntity (String name)
339: throws SAXException
340: {
341: if (name.charAt (0) == '%' || "[dtd]".equals (name))
342: return;
343: DomNode top = (DomNode) getTop ();
344:
345: if (top.getNodeType () == Node.ENTITY_REFERENCE_NODE) {
346: top.compact ();
347: top.makeReadonly ();
348: }
349: super.endEntity (name);
350: }
351: }
352: }