KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > parsers > AbstractDOMParser


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2004 The Apache Software Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 1999, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57
58 package com.sun.org.apache.xerces.internal.parsers;
59
60 import java.util.Locale JavaDoc;
61 import java.util.Stack JavaDoc;
62
63 import com.sun.org.apache.xerces.internal.dom.AttrImpl;
64 import com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl;
65 import com.sun.org.apache.xerces.internal.dom.DOMErrorImpl;
66 import com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl;
67 import com.sun.org.apache.xerces.internal.dom.DocumentImpl;
68 import com.sun.org.apache.xerces.internal.dom.DocumentTypeImpl;
69 import com.sun.org.apache.xerces.internal.dom.DOMMessageFormatter;
70 import com.sun.org.apache.xerces.internal.dom.ElementDefinitionImpl;
71 import com.sun.org.apache.xerces.internal.dom.ElementImpl;
72 import com.sun.org.apache.xerces.internal.dom.EntityImpl;
73 import com.sun.org.apache.xerces.internal.dom.EntityReferenceImpl;
74 import com.sun.org.apache.xerces.internal.dom.NodeImpl;
75 import com.sun.org.apache.xerces.internal.dom.NotationImpl;
76 import com.sun.org.apache.xerces.internal.dom.PSVIAttrNSImpl;
77 import com.sun.org.apache.xerces.internal.dom.PSVIDocumentImpl;
78 import com.sun.org.apache.xerces.internal.dom.PSVIElementNSImpl;
79 import com.sun.org.apache.xerces.internal.dom.TextImpl;
80 import com.sun.org.apache.xerces.internal.impl.Constants;
81 import com.sun.org.apache.xerces.internal.xs.XSTypeDefinition;
82 import com.sun.org.apache.xerces.internal.util.DOMErrorHandlerWrapper;
83 import com.sun.org.apache.xerces.internal.util.TypeInfoImpl;
84 import com.sun.org.apache.xerces.internal.xni.Augmentations;
85 import com.sun.org.apache.xerces.internal.xni.NamespaceContext;
86 import com.sun.org.apache.xerces.internal.xni.QName;
87 import com.sun.org.apache.xerces.internal.xni.XMLAttributes;
88 import com.sun.org.apache.xerces.internal.xni.XMLLocator;
89 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier;
90 import com.sun.org.apache.xerces.internal.xni.XMLString;
91 import com.sun.org.apache.xerces.internal.xni.XNIException;
92 import com.sun.org.apache.xerces.internal.xni.parser.XMLParserConfiguration;
93 import com.sun.org.apache.xerces.internal.xs.AttributePSVI;
94 import com.sun.org.apache.xerces.internal.xs.ElementPSVI;
95 import org.w3c.dom.Attr JavaDoc;
96 import org.w3c.dom.CDATASection JavaDoc;
97 import org.w3c.dom.Comment JavaDoc;
98 import org.w3c.dom.DOMError JavaDoc;
99 import org.w3c.dom.Document JavaDoc;
100 import org.w3c.dom.DocumentType JavaDoc;
101 import org.w3c.dom.Element JavaDoc;
102 import org.w3c.dom.EntityReference JavaDoc;
103 import org.w3c.dom.NamedNodeMap JavaDoc;
104 import org.w3c.dom.Node JavaDoc;
105 import org.w3c.dom.NodeList JavaDoc;
106 import org.w3c.dom.ProcessingInstruction JavaDoc;
107 import org.w3c.dom.Text JavaDoc;
108 import org.w3c.dom.TypeInfo JavaDoc;
109 import org.w3c.dom.ls.LSParserFilter JavaDoc;
110 import org.w3c.dom.traversal.NodeFilter;
111
112 /**
113  * This is the base class of all DOM parsers. It implements the XNI
114  * callback methods to create the DOM tree. After a successful parse of
115  * an XML document, the DOM Document object can be queried using the
116  * <code>getDocument</code> method. The actual pipeline is defined in
117  * parser configuration.
118  *
119  * @author Arnaud Le Hors, IBM
120  * @author Andy Clark, IBM
121  * @author Elena Litani, IBM
122  *
123  * @version $Id: AbstractDOMParser.java,v 1.108 2004/02/17 07:14:48 neeraj Exp $
124  */

125 public class AbstractDOMParser extends AbstractXMLDocumentParser {
126
127     //
128
// Constants
129
//
130
// feature ids
131

132     /** Feature id: namespace. */
133     protected static final String JavaDoc NAMESPACES =
134     Constants.SAX_FEATURE_PREFIX+Constants.NAMESPACES_FEATURE;
135
136     /** Feature id: create entity ref nodes. */
137     protected static final String JavaDoc CREATE_ENTITY_REF_NODES =
138     Constants.XERCES_FEATURE_PREFIX + Constants.CREATE_ENTITY_REF_NODES_FEATURE;
139
140     /** Feature id: include comments. */
141     protected static final String JavaDoc INCLUDE_COMMENTS_FEATURE =
142     Constants.XERCES_FEATURE_PREFIX + Constants.INCLUDE_COMMENTS_FEATURE;
143
144     /** Feature id: create cdata nodes. */
145     protected static final String JavaDoc CREATE_CDATA_NODES_FEATURE =
146     Constants.XERCES_FEATURE_PREFIX + Constants.CREATE_CDATA_NODES_FEATURE;
147
148     /** Feature id: include ignorable whitespace. */
149     protected static final String JavaDoc INCLUDE_IGNORABLE_WHITESPACE =
150     Constants.XERCES_FEATURE_PREFIX + Constants.INCLUDE_IGNORABLE_WHITESPACE;
151
152     /** Feature id: defer node expansion. */
153     protected static final String JavaDoc DEFER_NODE_EXPANSION =
154     Constants.XERCES_FEATURE_PREFIX + Constants.DEFER_NODE_EXPANSION_FEATURE;
155
156
157     /** Recognized features. */
158     private static final String JavaDoc[] RECOGNIZED_FEATURES = {
159         NAMESPACES,
160         CREATE_ENTITY_REF_NODES,
161         INCLUDE_COMMENTS_FEATURE,
162         CREATE_CDATA_NODES_FEATURE,
163         INCLUDE_IGNORABLE_WHITESPACE,
164         DEFER_NODE_EXPANSION
165     };
166
167     // property ids
168

169     /** Property id: document class name. */
170     protected static final String JavaDoc DOCUMENT_CLASS_NAME =
171     Constants.XERCES_PROPERTY_PREFIX + Constants.DOCUMENT_CLASS_NAME_PROPERTY;
172
173     protected static final String JavaDoc CURRENT_ELEMENT_NODE=
174     Constants.XERCES_PROPERTY_PREFIX + Constants.CURRENT_ELEMENT_NODE_PROPERTY;
175
176     // protected static final String GRAMMAR_POOL =
177
// Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY;
178

179     /** Recognized properties. */
180     private static final String JavaDoc[] RECOGNIZED_PROPERTIES = {
181         DOCUMENT_CLASS_NAME,
182         CURRENT_ELEMENT_NODE,
183     };
184
185     // other
186

187     /** Default document class name. */
188     protected static final String JavaDoc DEFAULT_DOCUMENT_CLASS_NAME =
189     "com.sun.org.apache.xerces.internal.dom.DocumentImpl";
190
191     protected static final String JavaDoc CORE_DOCUMENT_CLASS_NAME =
192     "com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl";
193
194     protected static final String JavaDoc PSVI_DOCUMENT_CLASS_NAME =
195     "com.sun.org.apache.xerces.internal.dom.PSVIDocumentImpl";
196
197     /**
198      * If the user stops the process, this exception will be thrown.
199      */

200     public static final RuntimeException JavaDoc abort = new RuntimeException JavaDoc();
201
202     // debugging
203

204     private static final boolean DEBUG_EVENTS = false;
205     private static final boolean DEBUG_BASEURI = false;
206
207     //
208
// Data
209
//
210

211     /** DOM L3 error handler */
212     protected DOMErrorHandlerWrapper fErrorHandler = null;
213
214     /** True if inside DTD. */
215     protected boolean fInDTD;
216
217     // features
218

219     /** Create entity reference nodes. */
220     protected boolean fCreateEntityRefNodes;
221
222     /** Include ignorable whitespace. */
223     protected boolean fIncludeIgnorableWhitespace;
224
225     /** Include Comments. */
226     protected boolean fIncludeComments;
227
228     /** Create cdata nodes. */
229     protected boolean fCreateCDATANodes;
230
231     // dom information
232

233     /** The document. */
234     protected Document JavaDoc fDocument;
235
236     /** The default Xerces document implementation, if used. */
237     protected CoreDocumentImpl fDocumentImpl;
238
239     /** Whether to store PSVI information in DOM tree. */
240     protected boolean fStorePSVI;
241
242     /** The document class name to use. */
243     protected String JavaDoc fDocumentClassName;
244
245     /** The document type node. */
246     protected DocumentType JavaDoc fDocumentType;
247
248     /** Current node. */
249     protected Node JavaDoc fCurrentNode;
250     protected CDATASection JavaDoc fCurrentCDATASection;
251     protected EntityImpl fCurrentEntityDecl;
252     protected int fDeferredEntityDecl;
253
254     /** Character buffer */
255     protected final StringBuffer JavaDoc fStringBuffer = new StringBuffer JavaDoc (50);
256
257     // internal subset
258

259     /** Internal subset buffer. */
260     protected StringBuffer JavaDoc fInternalSubset;
261
262     // deferred expansion data
263

264     protected boolean fDeferNodeExpansion;
265     protected boolean fNamespaceAware;
266     protected DeferredDocumentImpl fDeferredDocumentImpl;
267     protected int fDocumentIndex;
268     protected int fDocumentTypeIndex;
269     protected int fCurrentNodeIndex;
270     protected int fCurrentCDATASectionIndex;
271
272     // state
273

274     /** True if inside DTD external subset. */
275     protected boolean fInDTDExternalSubset;
276
277     /** Root element name */
278     protected QName fRoot = new QName();
279
280     /** True if inside CDATA section. */
281     protected boolean fInCDATASection;
282
283     /** True if saw the first chunk of characters*/
284     protected boolean fFirstChunk = false;
285
286
287     /** LSParserFilter: specifies that element with given QNAME and all its children
288         must be rejected */

289     protected boolean fFilterReject = false;
290
291     // data
292

293     /** Base uri stack*/
294     protected Stack JavaDoc fBaseURIStack = new Stack JavaDoc ();
295
296
297     /** LSParserFilter: the QNAME of rejected element*/
298     protected final QName fRejectedElement = new QName ();
299
300     /** LSParserFilter: store qnames of skipped elements*/
301     protected Stack JavaDoc fSkippedElemStack = null;
302
303     /** LSParserFilter: true if inside entity reference */
304     protected boolean fInEntityRef = false;
305
306     /** Attribute QName. */
307     private QName fAttrQName = new QName ();
308
309     // handlers
310

311     protected LSParserFilter JavaDoc fDOMFilter = null;
312
313     //
314
// Constructors
315
//
316

317     /** Default constructor. */
318     protected AbstractDOMParser (XMLParserConfiguration config) {
319
320         super (config);
321
322
323         // add recognized features
324
fConfiguration.addRecognizedFeatures (RECOGNIZED_FEATURES);
325
326         // set default values
327
fConfiguration.setFeature (CREATE_ENTITY_REF_NODES, true);
328         fConfiguration.setFeature (INCLUDE_IGNORABLE_WHITESPACE, true);
329         fConfiguration.setFeature (DEFER_NODE_EXPANSION, true);
330         fConfiguration.setFeature (INCLUDE_COMMENTS_FEATURE, true);
331         fConfiguration.setFeature (CREATE_CDATA_NODES_FEATURE, true);
332
333         // add recognized properties
334
fConfiguration.addRecognizedProperties (RECOGNIZED_PROPERTIES);
335
336         // set default values
337
fConfiguration.setProperty (DOCUMENT_CLASS_NAME,
338         DEFAULT_DOCUMENT_CLASS_NAME);
339
340     } // <init>(XMLParserConfiguration)
341

342     /**
343      * This method retreives the name of current document class.
344      */

345     protected String JavaDoc getDocumentClassName() {
346         return fDocumentClassName;
347     }
348
349     /**
350      * This method allows the programmer to decide which document
351      * factory to use when constructing the DOM tree. However, doing
352      * so will lose the functionality of the default factory. Also,
353      * a document class other than the default will lose the ability
354      * to defer node expansion on the DOM tree produced.
355      *
356      * @param documentClassName The fully qualified class name of the
357      * document factory to use when constructing
358      * the DOM tree.
359      *
360      * @see #getDocumentClassName
361      * @see #DEFAULT_DOCUMENT_CLASS_NAME
362      */

363     protected void setDocumentClassName (String JavaDoc documentClassName) {
364
365         // normalize class name
366
if (documentClassName == null) {
367             documentClassName = DEFAULT_DOCUMENT_CLASS_NAME;
368         }
369
370         if (!documentClassName.equals(DEFAULT_DOCUMENT_CLASS_NAME) &&
371             !documentClassName.equals(PSVI_DOCUMENT_CLASS_NAME)) {
372             // verify that this class exists and is of the right type
373
try {
374                 Class JavaDoc _class = ObjectFactory.findProviderClass (documentClassName,
375                 ObjectFactory.findClassLoader (), true);
376                 //if (!_class.isAssignableFrom(Document.class)) {
377
if (!Document JavaDoc.class.isAssignableFrom (_class)) {
378                     throw new IllegalArgumentException JavaDoc (
379                         DOMMessageFormatter.formatMessage(
380                         DOMMessageFormatter.DOM_DOMAIN,
381                         "InvalidDocumentClassName", new Object JavaDoc [] {documentClassName}));
382                 }
383             }
384             catch (ClassNotFoundException JavaDoc e) {
385                 throw new IllegalArgumentException JavaDoc (
386                     DOMMessageFormatter.formatMessage(
387                     DOMMessageFormatter.DOM_DOMAIN,
388                     "MissingDocumentClassName", new Object JavaDoc [] {documentClassName}));
389             }
390         }
391
392         // set document class name
393
fDocumentClassName = documentClassName;
394         if (!documentClassName.equals(DEFAULT_DOCUMENT_CLASS_NAME)) {
395             fDeferNodeExpansion = false;
396         }
397
398     } // setDocumentClassName(String)
399

400     //
401
// Public methods
402
//
403

404     /** Returns the DOM document object. */
405     public Document JavaDoc getDocument() {
406         return fDocument;
407     } // getDocument():Document
408

409     //
410
// XMLDocumentParser methods
411
//
412

413     /**
414      * Resets the parser state.
415      *
416      * @throws SAXException Thrown on initialization error.
417      */

418     public void reset () throws XNIException {
419         super.reset ();
420
421
422         // get feature state
423
fCreateEntityRefNodes =
424         fConfiguration.getFeature (CREATE_ENTITY_REF_NODES);
425
426         fIncludeIgnorableWhitespace =
427         fConfiguration.getFeature (INCLUDE_IGNORABLE_WHITESPACE);
428
429         fDeferNodeExpansion =
430         fConfiguration.getFeature (DEFER_NODE_EXPANSION);
431
432         fNamespaceAware = fConfiguration.getFeature (NAMESPACES);
433
434         fIncludeComments = fConfiguration.getFeature (INCLUDE_COMMENTS_FEATURE);
435
436         fCreateCDATANodes = fConfiguration.getFeature (CREATE_CDATA_NODES_FEATURE);
437
438         // get property
439
setDocumentClassName ((String JavaDoc)
440         fConfiguration.getProperty (DOCUMENT_CLASS_NAME));
441
442         // reset dom information
443
fDocument = null;
444         fDocumentImpl = null;
445         fStorePSVI = false;
446         fDocumentType = null;
447         fDocumentTypeIndex = -1;
448         fDeferredDocumentImpl = null;
449         fCurrentNode = null;
450
451         // reset string buffer
452
fStringBuffer.setLength (0);
453
454         // reset state information
455
fRoot.clear();
456         fInDTD = false;
457         fInDTDExternalSubset = false;
458         fInCDATASection = false;
459         fFirstChunk = false;
460         fCurrentCDATASection = null;
461         fCurrentCDATASectionIndex = -1;
462         fBaseURIStack.removeAllElements ();
463
464
465     } // reset()
466

467     /**
468      * Set the locale to use for messages.
469      *
470      * @param locale The locale object to use for localization of messages.
471      *
472      */

473     public void setLocale (Locale JavaDoc locale) {
474         fConfiguration.setLocale (locale);
475
476     } // setLocale(Locale)
477

478     //
479
// XMLDocumentHandler methods
480
//
481

482     /**
483      * This method notifies the start of a general entity.
484      * <p>
485      * <strong>Note:</strong> This method is not called for entity references
486      * appearing as part of attribute values.
487      *
488      * @param name The name of the general entity.
489      * @param identifier The resource identifier.
490      * @param encoding The auto-detected IANA encoding name of the entity
491      * stream. This value will be null in those situations
492      * where the entity encoding is not auto-detected (e.g.
493      * internal entities or a document entity that is
494      * parsed from a java.io.Reader).
495      * @param augs Additional information that may include infoset augmentations
496      *
497      * @exception XNIException Thrown by handler to signal an error.
498      */

499     public void startGeneralEntity(String JavaDoc name,
500                                    XMLResourceIdentifier identifier,
501                                    String JavaDoc encoding, Augmentations augs)
502         throws XNIException {
503         if (DEBUG_EVENTS) {
504             System.out.println("==>startGeneralEntity ("+name+")");
505             if (DEBUG_BASEURI) {
506                 System.out.println(" expandedSystemId( **baseURI): "+identifier.getExpandedSystemId());
507                 System.out.println(" baseURI:"+ identifier.getBaseSystemId());
508             }
509         }
510
511         // Always create entity reference nodes to be able to recreate
512
// entity as a part of doctype
513
if (!fDeferNodeExpansion) {
514              if (fFilterReject) {
515                  return;
516              }
517             setCharacterData(true);
518             EntityReference JavaDoc er = fDocument.createEntityReference(name);
519             if (fDocumentImpl != null) {
520                 // REVISIT: baseURI/actualEncoding
521
// remove dependency on our implementation when DOM L3 is REC
522
//
523
EntityReferenceImpl erImpl =(EntityReferenceImpl)er;
524
525                 // set base uri
526
erImpl.setBaseURI(identifier.getExpandedSystemId());
527                 if (fDocumentType != null) {
528                     // set actual encoding
529
NamedNodeMap JavaDoc entities = fDocumentType.getEntities();
530                     fCurrentEntityDecl = (EntityImpl) entities.getNamedItem(name);
531                     if (fCurrentEntityDecl != null) {
532                         fCurrentEntityDecl.setInputEncoding(encoding);
533                     }
534
535                 }
536                 // we don't need synchronization now, because entity ref will be
537
// expanded anyway. Synch only needed when user creates entityRef node
538
erImpl.needsSyncChildren(false);
539             }
540             fInEntityRef = true;
541             fCurrentNode.appendChild (er);
542             fCurrentNode = er;
543         }
544         else {
545
546             int er =
547                fDeferredDocumentImpl.createDeferredEntityReference(name, identifier.getExpandedSystemId());
548             if (fDocumentTypeIndex != -1) {
549                 // find corresponding Entity decl
550
int node = fDeferredDocumentImpl.getLastChild(fDocumentTypeIndex, false);
551                 while (node != -1) {
552                     short nodeType = fDeferredDocumentImpl.getNodeType(node, false);
553                     if (nodeType == Node.ENTITY_NODE) {
554                         String JavaDoc nodeName =
555                             fDeferredDocumentImpl.getNodeName(node, false);
556                         if (nodeName.equals(name)) {
557                             fDeferredEntityDecl = node;
558                             fDeferredDocumentImpl.setInputEncoding(node, encoding);
559                             break;
560                         }
561                     }
562                     node = fDeferredDocumentImpl.getRealPrevSibling(node, false);
563                 }
564             }
565             fDeferredDocumentImpl.appendChild(fCurrentNodeIndex, er);
566             fCurrentNodeIndex = er;
567         }
568
569     } // startGeneralEntity(String,XMLResourceIdentifier, Augmentations)
570

571     /**
572      * Notifies of the presence of a TextDecl line in an entity. If present,
573      * this method will be called immediately following the startEntity call.
574      * <p>
575      * <strong>Note:</strong> This method will never be called for the
576      * document entity; it is only called for external general entities
577      * referenced in document content.
578      * <p>
579      * <strong>Note:</strong> This method is not called for entity references
580      * appearing as part of attribute values.
581      *
582      * @param version The XML version, or null if not specified.
583      * @param encoding The IANA encoding name of the entity.
584      * @param augs Additional information that may include infoset augmentations
585      *
586      * @throws XNIException Thrown by handler to signal an error.
587      */

588     public void textDecl(String JavaDoc version, String JavaDoc encoding, Augmentations augs) throws XNIException {
589         if (fInDTD){
590             return;
591         }
592         if (!fDeferNodeExpansion) {
593             if (fCurrentEntityDecl != null && !fFilterReject) {
594                 fCurrentEntityDecl.setXmlEncoding(encoding);
595                 if(version != null)
596                     fCurrentEntityDecl.setXmlVersion(version);
597             }
598         }
599         else {
600             if (fDeferredEntityDecl !=-1) {
601                fDeferredDocumentImpl.setEntityInfo(fDeferredEntityDecl, version, encoding);
602             }
603         }
604     } // textDecl(String,String)
605

606     /**
607      * A comment.
608      *
609      * @param text The text in the comment.
610      * @param augs Additional information that may include infoset augmentations
611      *
612      * @throws XNIException Thrown by application to signal an error.
613      */

614     public void comment(XMLString text, Augmentations augs) throws XNIException {
615         if (fInDTD) {
616             if (fInternalSubset != null && !fInDTDExternalSubset) {
617                 fInternalSubset.append("<!-- ");
618                 fInternalSubset.append(text.toString());
619                 fInternalSubset.append(" -->");
620             }
621             return;
622         }
623         if (!fIncludeComments || fFilterReject) {
624               return;
625         }
626         if (!fDeferNodeExpansion) {
627             Comment JavaDoc comment = fDocument.createComment (text.toString ());
628
629             setCharacterData (false);
630             fCurrentNode.appendChild (comment);
631             if (fDOMFilter !=null && !fInEntityRef &&
632             (fDOMFilter.getWhatToShow () & NodeFilter.SHOW_COMMENT)!= 0) {
633                 short code = fDOMFilter.acceptNode (comment);
634                 switch (code) {
635                     case LSParserFilter.FILTER_INTERRUPT:{
636                         throw abort;
637                     }
638                     case LSParserFilter.FILTER_REJECT:{
639                         // REVISIT: the constant FILTER_REJECT should be changed when new
640
// DOM LS specs gets published
641

642                         // fall through to SKIP since comment has no children.
643
}
644                     case LSParserFilter.FILTER_SKIP: {
645                         // REVISIT: the constant FILTER_SKIP should be changed when new
646
// DOM LS specs gets published
647
fCurrentNode.removeChild(comment);
648                         // make sure we don't loose chars if next event is characters()
649
fFirstChunk = true;
650                         return;
651                     }
652
653                     default: {
654                         // accept node
655
}
656                 }
657             }
658
659         }
660         else {
661             int comment =
662                 fDeferredDocumentImpl.createDeferredComment(text.toString());
663             fDeferredDocumentImpl.appendChild(fCurrentNodeIndex, comment);
664         }
665
666     } // comment(XMLString)
667

668     /**
669      * A processing instruction. Processing instructions consist of a
670      * target name and, optionally, text data. The data is only meaningful
671      * to the application.
672      * <p>
673      * Typically, a processing instruction's data will contain a series
674      * of pseudo-attributes. These pseudo-attributes follow the form of
675      * element attributes but are <strong>not</strong> parsed or presented
676      * to the application as anything other than text. The application is
677      * responsible for parsing the data.
678      *
679      * @param target The target.
680      * @param data The data or null if none specified.
681      * @param augs Additional information that may include infoset augmentations
682      *
683      * @throws XNIException Thrown by handler to signal an error.
684      */

685     public void processingInstruction (String JavaDoc target, XMLString data, Augmentations augs)
686     throws XNIException {
687
688         if (fInDTD) {
689             if (fInternalSubset != null && !fInDTDExternalSubset) {
690                 fInternalSubset.append ("<?");
691                 fInternalSubset.append (target.toString ());
692                 fInternalSubset.append (' ');
693                 fInternalSubset.append (data.toString ());
694                 fInternalSubset.append ("?>");
695
696             }
697             return;
698         }
699
700         if (DEBUG_EVENTS) {
701             System.out.println ("==>processingInstruction ("+target+")");
702         }
703         if (!fDeferNodeExpansion) {
704             if (fFilterReject) {
705                 return;
706             }
707             ProcessingInstruction JavaDoc pi =
708             fDocument.createProcessingInstruction (target, data.toString ());
709
710
711             setCharacterData (false);
712             fCurrentNode.appendChild (pi);
713             if (fDOMFilter !=null && !fInEntityRef &&
714             (fDOMFilter.getWhatToShow () & NodeFilter.SHOW_PROCESSING_INSTRUCTION)!= 0) {
715                 short code = fDOMFilter.acceptNode (pi);
716                 switch (code) {
717                     case LSParserFilter.FILTER_INTERRUPT:{
718                         throw abort;
719                     }
720                     case LSParserFilter.FILTER_REJECT:{
721                         // fall through to SKIP since PI has no children.
722
}
723                     case LSParserFilter.FILTER_SKIP: {
724                         fCurrentNode.removeChild(pi);
725                         // fFirstChunk must be set to true so that data
726
// won't be lost in the case where the child before PI is
727
// a text node and the next event is characters.
728
fFirstChunk = true;
729                         return;
730                     }
731                     default: {
732                     }
733                 }
734             }
735         }
736         else {
737             int pi = fDeferredDocumentImpl.
738                 createDeferredProcessingInstruction(target, data.toString());
739             fDeferredDocumentImpl.appendChild(fCurrentNodeIndex, pi);
740         }
741
742     } // processingInstruction(String,XMLString)
743

744     /**
745      * The start of the document.
746      *
747      * @param locator The system identifier of the entity if the entity
748      * is external, null otherwise.
749      * @param encoding The auto-detected IANA encoding name of the entity
750      * stream. This value will be null in those situations
751      * where the entity encoding is not auto-detected (e.g.
752      * internal entities or a document entity that is
753      * parsed from a java.io.Reader).
754      * @param namespaceContext
755      * The namespace context in effect at the
756      * start of this document.
757      * This object represents the current context.
758      * Implementors of this class are responsible
759      * for copying the namespace bindings from the
760      * the current context (and its parent contexts)
761      * if that information is important.
762      * @param augs Additional information that may include infoset augmentations
763      *
764      * @throws XNIException Thrown by handler to signal an error.
765      */

766     public void startDocument (XMLLocator locator, String JavaDoc encoding,
767     NamespaceContext namespaceContext, Augmentations augs)
768     throws XNIException {
769
770         if (!fDeferNodeExpansion) {
771             if (fDocumentClassName.equals (DEFAULT_DOCUMENT_CLASS_NAME)) {
772                 fDocument = new DocumentImpl ();
773                 fDocumentImpl = (CoreDocumentImpl)fDocument;
774                 // REVISIT: when DOM Level 3 is REC rely on Document.support
775
// instead of specific class
776
// set DOM error checking off
777
fDocumentImpl.setStrictErrorChecking (false);
778                 // set actual encoding
779
fDocumentImpl.setInputEncoding (encoding);
780                 // set documentURI
781
fDocumentImpl.setDocumentURI (locator.getExpandedSystemId ());
782             }
783             else if (fDocumentClassName.equals (PSVI_DOCUMENT_CLASS_NAME)) {
784                 fDocument = new PSVIDocumentImpl();
785                 fDocumentImpl = (CoreDocumentImpl)fDocument;
786                 fStorePSVI = true;
787                 // REVISIT: when DOM Level 3 is REC rely on Document.support
788
// instead of specific class
789
// set DOM error checking off
790
fDocumentImpl.setStrictErrorChecking (false);
791                 // set actual encoding
792
fDocumentImpl.setInputEncoding (encoding);
793                 // set documentURI
794
fDocumentImpl.setDocumentURI (locator.getExpandedSystemId ());
795             }
796             else {
797                 // use specified document class
798
try {
799                     ClassLoader JavaDoc cl = ObjectFactory.findClassLoader();
800                     Class JavaDoc documentClass = ObjectFactory.findProviderClass (fDocumentClassName,
801                         cl, true);
802                     fDocument = (Document JavaDoc)documentClass.newInstance ();
803
804                     // if subclass of our own class that's cool too
805
Class JavaDoc defaultDocClass =
806                     ObjectFactory.findProviderClass (CORE_DOCUMENT_CLASS_NAME,
807                         cl, true);
808                     if (defaultDocClass.isAssignableFrom (documentClass)) {
809                         fDocumentImpl = (CoreDocumentImpl)fDocument;
810
811                         Class JavaDoc psviDocClass = ObjectFactory.findProviderClass (PSVI_DOCUMENT_CLASS_NAME,
812                             cl, true);
813                         if (psviDocClass.isAssignableFrom (documentClass)) {
814                             fStorePSVI = true;
815                         }
816
817                         // REVISIT: when DOM Level 3 is REC rely on
818
// Document.support instead of specific class
819
// set DOM error checking off
820
fDocumentImpl.setStrictErrorChecking(false);
821                         // set actual encoding
822
fDocumentImpl.setInputEncoding(encoding);
823                         // set documentURI
824
if (locator != null) {
825                             fDocumentImpl.setDocumentURI(locator.getExpandedSystemId());
826                         }
827                     }
828                 }
829                 catch (ClassNotFoundException JavaDoc e) {
830                     // won't happen we already checked that earlier
831
}
832                 catch (Exception JavaDoc e) {
833                     throw new RuntimeException JavaDoc (
834                         DOMMessageFormatter.formatMessage(
835                         DOMMessageFormatter.DOM_DOMAIN,
836                         "CannotCreateDocumentClass",
837                         new Object JavaDoc [] {fDocumentClassName}));
838                 }
839             }
840             fCurrentNode = fDocument;
841         }
842         else {
843             fDeferredDocumentImpl = new DeferredDocumentImpl(fNamespaceAware);
844             fDocument = fDeferredDocumentImpl;
845             fDocumentIndex = fDeferredDocumentImpl.createDeferredDocument();
846             // REVISIT: strict error checking is not implemented in deferred dom.
847
// Document.support instead of specific class
848

849             // set actual encoding
850
fDeferredDocumentImpl.setInputEncoding(encoding);
851             // set documentURI
852
fDeferredDocumentImpl.setDocumentURI(locator.getExpandedSystemId());
853             fCurrentNodeIndex = fDocumentIndex;
854
855         }
856
857     } // startDocument(String,String)
858

859     /**
860      * Notifies of the presence of an XMLDecl line in the document. If
861      * present, this method will be called immediately following the
862      * startDocument call.
863      *
864      * @param version The XML version.
865      * @param encoding The IANA encoding name of the document, or null if
866      * not specified.
867      * @param standalone The standalone value, or null if not specified.
868      * @param augs Additional information that may include infoset augmentations
869      *
870      * @throws XNIException Thrown by handler to signal an error.
871      */

872     public void xmlDecl(String JavaDoc version, String JavaDoc encoding, String JavaDoc standalone,
873                         Augmentations augs)
874         throws XNIException {
875         if (!fDeferNodeExpansion) {
876             // REVISIT: when DOM Level 3 is REC rely on Document.support
877
// instead of specific class
878
if (fDocumentImpl != null) {
879                 if(version != null)
880                     fDocumentImpl.setXmlVersion(version);
881                 fDocumentImpl.setXmlEncoding(encoding);
882                 fDocumentImpl.setXmlStandalone("yes".equals(standalone));
883             }
884         }
885         else {
886             if(version != null)
887                 fDeferredDocumentImpl.setXmlVersion(version);
888             fDeferredDocumentImpl.setXmlEncoding(encoding);
889             fDeferredDocumentImpl.setXmlStandalone("yes".equals(standalone));
890         }
891     } // xmlDecl(String,String,String)
892

893     /**
894      * Notifies of the presence of the DOCTYPE line in the document.
895      *
896      * @param rootElement The name of the root element.
897      * @param publicId The public identifier if an external DTD or null
898      * if the external DTD is specified using SYSTEM.
899      * @param systemId The system identifier if an external DTD, null
900      * otherwise.
901      * @param augs Additional information that may include infoset augmentations
902      *
903      * @throws XNIException Thrown by handler to signal an error.
904      */

905     public void doctypeDecl (String JavaDoc rootElement,
906     String JavaDoc publicId, String JavaDoc systemId, Augmentations augs)
907     throws XNIException {
908
909         if (!fDeferNodeExpansion) {
910             if (fDocumentImpl != null) {
911                 fDocumentType = fDocumentImpl.createDocumentType(
912                                     rootElement, publicId, systemId);
913                 fCurrentNode.appendChild(fDocumentType);
914             }
915         }
916         else {
917             fDocumentTypeIndex = fDeferredDocumentImpl.
918                 createDeferredDocumentType(rootElement, publicId, systemId);
919             fDeferredDocumentImpl.appendChild(fCurrentNodeIndex, fDocumentTypeIndex);
920         }
921
922     } // doctypeDecl(String,String,String)
923

924     /**
925      * The start of an element. If the document specifies the start element
926      * by using an empty tag, then the startElement method will immediately
927      * be followed by the endElement method, with no intervening methods.
928      *
929      * @param element The name of the element.
930      * @param attributes The element attributes.
931      * @param augs Additional information that may include infoset augmentations
932      *
933      * @throws XNIException Thrown by handler to signal an error.
934      */

935     public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
936         throws XNIException {
937         if (DEBUG_EVENTS) {
938             System.out.println("==>startElement ("+element.rawname+")");
939         }
940         if (!fDeferNodeExpansion) {
941             if (fFilterReject) {
942                 return;
943             }
944             Element JavaDoc el = createElementNode(element);
945             int attrCount = attributes.getLength();
946             for (int i = 0; i < attrCount; i++) {
947                 attributes.getName (i, fAttrQName);
948                 Attr JavaDoc attr = createAttrNode (fAttrQName);
949
950                 String JavaDoc attrValue = attributes.getValue (i);
951
952                  Augmentations aaugs = attributes.getAugmentations(i);
953                  
954                  AttributePSVI attrPSVI =(AttributePSVI) aaugs.getItem(Constants.ATTRIBUTE_PSVI);
955                 if (fStorePSVI && attrPSVI != null){
956                     ((PSVIAttrNSImpl) attr).setPSVI (attrPSVI);
957                 }
958                 attr.setValue(attrValue);
959                 el.setAttributeNode(attr);
960                 // NOTE: The specified value MUST be set after you set
961
// the node value because that turns the "specified"
962
// flag to "true" which may overwrite a "false"
963
// value from the attribute list. -Ac
964
if (fDocumentImpl != null) {
965                     AttrImpl attrImpl = (AttrImpl)attr;
966
967                     attrImpl.setType(getAttributeType(attributes,aaugs,i));
968                 
969                     if (isIdAttribute(attributes,aaugs,i)) {
970                         ((ElementImpl)el).setIdAttributeNode(attr, true);
971                     }
972
973                     attrImpl.setSpecified(attributes.isSpecified(i));
974                     // REVISIT: Handle entities in attribute value.
975
}
976     }
977     setCharacterData (false);
978             ((ElementImpl)el).setType(getElementTypeInfoFromAugs(augs));
979             // filter nodes
980
if (fDOMFilter != null && !fInEntityRef) {
981                 if (fRoot.rawname == null) {
982                     // fill value of the root element
983
fRoot.setValues(element);
984                 } else {
985                     short code = fDOMFilter.startElement(el);
986                     switch (code) {
987                         case LSParserFilter.FILTER_INTERRUPT :
988                             {
989                                 throw abort;
990                             }
991                         case LSParserFilter.FILTER_REJECT :
992                             {
993                                 fFilterReject = true;
994                                 fRejectedElement.setValues(element);
995                                 return;
996                             }
997                         case LSParserFilter.FILTER_SKIP :
998                             {
999                                 fSkippedElemStack.push(new QName(element));
1000                                return;
1001                            }
1002                        default : {}
1003                    }
1004                }
1005            }
1006            fCurrentNode.appendChild (el);
1007            fCurrentNode = el;
1008        }
1009        else {
1010
1011            int el =
1012                fDeferredDocumentImpl.createDeferredElement(fNamespaceAware ?
1013                                                            element.uri : null,
1014                                                            element.rawname,
1015                                                            getElementTypeInfoFromAugs(augs));
1016            int attrCount = attributes.getLength();
1017            for (int i = 0; i < attrCount; i++) {
1018                // set type information
1019
Augmentations aaugs = attributes.getAugmentations(i);
1020
1021                // create attribute
1022
fDeferredDocumentImpl.setDeferredAttribute(
1023                        el,
1024                        attributes.getQName(i),
1025                        attributes.getURI(i),
1026                        attributes.getValue(i),
1027                        attributes.isSpecified(i),
1028                        isIdAttribute(attributes,aaugs,i),
1029                        getAttributeType(attributes,aaugs,i));
1030            }
1031
1032            fDeferredDocumentImpl.appendChild (fCurrentNodeIndex, el);
1033            fCurrentNodeIndex = el;
1034        }
1035    } // startElement(QName,XMLAttributes)
1036

1037    /**
1038     * Returns true if the given attribute is marked as ID.
1039     */

1040    private boolean isIdAttribute(XMLAttributes attributes,Augmentations augs, int index) {
1041        // look for augmentation first.
1042
Object JavaDoc o = augs.getItem(Constants.ID_ATTRIBUTE);
1043        if( o instanceof Boolean JavaDoc )
1044            return ((Boolean JavaDoc)o).booleanValue();
1045        
1046        // otherwise fall back to the DTD mode.
1047
return "ID".equals(attributes.getType(index));
1048    }
1049    
1050    /**
1051     * Returns {@link TypeInfo} for the given attribute.
1052     */

1053    private TypeInfo JavaDoc getAttributeType(XMLAttributes attributes,Augmentations augs, int index) {
1054        // look for augmentation
1055
TypeInfo JavaDoc type = (TypeInfo JavaDoc)augs.getItem(Constants.TYPEINFO);
1056        if(type!=null) return type;
1057        boolean isDeclared = Boolean.TRUE.equals (attributes.getAugmentations (index).getItem (Constants.ATTRIBUTE_DECLARED));
1058        // otherwise fall back to the DTD mode.
1059
if (isDeclared )
1060            return TypeInfoImpl.getDTDTypeInfo(attributes.getType(index));
1061        else
1062            return new TypeInfoImpl();
1063    }
1064    
1065
1066    /**
1067     * Looks for {@link TypeInfo} object for the element in the augmentation.
1068     *
1069     * @return null if not found.
1070     */

1071    private TypeInfo JavaDoc getElementTypeInfoFromAugs( Augmentations augs ) {
1072        //simple fix to handle dtd case.
1073
if (augs == null) return new TypeInfoImpl();
1074        
1075        // if an external validator is used via JAXP, this would be set.
1076
TypeInfo JavaDoc ti = (TypeInfo JavaDoc)augs.getItem(Constants.TYPEINFO);
1077        if(ti!=null) return ti;
1078        
1079        // Xerces native validator would set this.
1080
ElementPSVI elementPSVI = (ElementPSVI)augs.getItem(Constants.ELEMENT_PSVI);
1081        if (elementPSVI == null) return null;
1082        
1083        XSTypeDefinition type = elementPSVI.getMemberTypeDefinition();
1084
1085        if( type!=null ) return type;
1086       
1087        return elementPSVI.getTypeDefinition();
1088    
1089    }
1090    
1091// /**
1092
// * Looks for {@link TypeInfo} object for the attribute in the augmentation.
1093
// */
1094
// private TypeInfo getAttribtueTypeInfoFromAugs( XMLAttributes atts, int idx ) {
1095
// Augmentations augs = atts.getAugmentations(idx);
1096
//
1097
// // if an external validator is used via JAXP, this would be set.
1098
// TypeInfo type = (TypeInfo)augs.getItem(Constants.TYPEINFO);
1099
// if(type!=null) return type;
1100
//
1101
// // look for PSVI
1102
// AttributePSVI attrPSVI =(AttributePSVI) augs.getItem(Constants.ATTRIBUTE_PSVI);
1103
// if (attrPSVI != null) {
1104
// type = attrPSVI.getMemberTypeDefinition();
1105
// if (type == null)
1106
// type = attrPSVI.getTypeDefinition();
1107
//
1108
// return type;
1109
// }
1110
//
1111
// // if everything else fails, fall back to the DTD type.
1112
// String typeName = atts.getType(idx);
1113
// return new TypeInfoImpl(null, typeName);
1114
// }
1115

1116
1117    /**
1118     * An empty element.
1119     *
1120     * @param element The name of the element.
1121     * @param attributes The element attributes.
1122     * @param augs Additional information that may include infoset augmentations
1123     *
1124     * @throws XNIException Thrown by handler to signal an error.
1125     */

1126    public void emptyElement (QName element, XMLAttributes attributes, Augmentations augs)
1127    throws XNIException {
1128
1129        startElement (element, attributes, augs);
1130        endElement (element, augs);
1131
1132    } // emptyElement(QName,XMLAttributes)
1133

1134    /**
1135     * Character content.
1136     *
1137     * @param text The content.
1138     * @param augs Additional information that may include infoset augmentations
1139     *
1140     * @throws XNIException Thrown by handler to signal an error.
1141     */

1142    public void characters (XMLString text, Augmentations augs) throws XNIException {
1143
1144        if (DEBUG_EVENTS) {
1145            System.out.println("==>characters(): "+text.toString());
1146        }
1147
1148        if (!fDeferNodeExpansion) {
1149
1150            if (fFilterReject) {
1151                return;
1152            }
1153            if (fInCDATASection && fCreateCDATANodes) {
1154                if (fCurrentCDATASection == null) {
1155                    fCurrentCDATASection =
1156                        fDocument.createCDATASection(text.toString());
1157                    fCurrentNode.appendChild(fCurrentCDATASection);
1158                    fCurrentNode = fCurrentCDATASection;
1159                }
1160                else {
1161                    fCurrentCDATASection.appendData(text.toString());
1162                }
1163            }
1164            else if (!fInDTD) {
1165                // if type is union (XML Schema) it is possible that we receive
1166
// character call with empty data
1167
if (text.length == 0) {
1168                    return;
1169                }
1170
1171                String JavaDoc value = text.toString ();
1172                Node JavaDoc child = fCurrentNode.getLastChild ();
1173                if (child != null && child.getNodeType () == Node.TEXT_NODE) {
1174                    // collect all the data into the string buffer.
1175
if (fFirstChunk) {
1176                        if (fDocumentImpl != null) {
1177                            fStringBuffer.append(((TextImpl)child).removeData());
1178                        } else {
1179                            fStringBuffer.append(((Text JavaDoc)child).getData());
1180                            ((Text JavaDoc)child).setNodeValue(null);
1181                        }
1182                        fFirstChunk = false;
1183                    }
1184                    fStringBuffer.append(value);
1185                }
1186                else {
1187                   fFirstChunk = true;
1188                   Text JavaDoc textNode = fDocument.createTextNode(value);
1189                   fCurrentNode.appendChild(textNode);
1190                }
1191            }
1192        }
1193        else {
1194            // The Text and CDATASection normalization is taken care of within
1195
// the DOM in the deferred case.
1196
if (fInCDATASection && fCreateCDATANodes) {
1197                if (fCurrentCDATASectionIndex == -1) {
1198                    int cs = fDeferredDocumentImpl.
1199                    createDeferredCDATASection (text.toString ());
1200
1201                    fDeferredDocumentImpl.appendChild (fCurrentNodeIndex, cs);
1202                    fCurrentCDATASectionIndex = cs;
1203                    fCurrentNodeIndex = cs;
1204                }
1205                else {
1206                    int txt = fDeferredDocumentImpl.
1207                        createDeferredTextNode(text.toString(), false);
1208                    fDeferredDocumentImpl.appendChild(fCurrentNodeIndex, txt);
1209                }
1210            } else if (!fInDTD) {
1211                // if type is union (XML Schema) it is possible that we receive
1212
// character call with empty data
1213
if (text.length == 0) {
1214                    return;
1215                }
1216
1217                String JavaDoc value = text.toString ();
1218                int txt = fDeferredDocumentImpl.
1219                createDeferredTextNode (value, false);
1220                fDeferredDocumentImpl.appendChild (fCurrentNodeIndex, txt);
1221
1222            }
1223        }
1224    } // characters(XMLString)
1225

1226    /**
1227     * Ignorable whitespace. For this method to be called, the document
1228     * source must have some way of determining that the text containing
1229     * only whitespace characters should be considered ignorable. For
1230     * example, the validator can determine if a length of whitespace
1231     * characters in the document are ignorable based on the element
1232     * content model.
1233     *
1234     * @param text The ignorable whitespace.
1235     * @param augs Additional information that may include infoset augmentations
1236     *
1237     * @throws XNIException Thrown by handler to signal an error.
1238     */

1239    public void ignorableWhitespace (XMLString text, Augmentations augs) throws XNIException {
1240
1241        if (!fIncludeIgnorableWhitespace || fFilterReject) {
1242            return;
1243        }
1244        if (!fDeferNodeExpansion) {
1245            Node JavaDoc child = fCurrentNode.getLastChild();
1246            if (child != null && child.getNodeType() == Node.TEXT_NODE) {
1247                Text JavaDoc textNode = (Text JavaDoc)child;
1248                textNode.appendData(text.toString());
1249            }
1250            else {
1251                Text JavaDoc textNode = fDocument.createTextNode(text.toString());
1252                if (fDocumentImpl != null) {
1253                    TextImpl textNodeImpl = (TextImpl)textNode;
1254                    textNodeImpl.setIgnorableWhitespace(true);
1255                }
1256                fCurrentNode.appendChild(textNode);
1257            }
1258        }
1259        else {
1260            // The Text normalization is taken care of within the DOM in the
1261
// deferred case.
1262
int txt = fDeferredDocumentImpl.
1263                createDeferredTextNode(text.toString(), true);
1264            fDeferredDocumentImpl.appendChild(fCurrentNodeIndex, txt);
1265        }
1266
1267    } // ignorableWhitespace(XMLString)
1268

1269    /**
1270     * The end of an element.
1271     *
1272     * @param element The name of the element.
1273     * @param augs Additional information that may include infoset augmentations
1274     *
1275     * @throws XNIException Thrown by handler to signal an error.
1276     */

1277    public void endElement(QName element, Augmentations augs) throws XNIException {
1278        if (DEBUG_EVENTS) {
1279            System.out.println("==>endElement ("+element.rawname+")");
1280        }
1281        if (!fDeferNodeExpansion) {
1282
1283            // REVISIT: Should this happen after we call the filter?
1284
if (fStorePSVI && augs != null) {
1285                ElementPSVI elementPSVI = (ElementPSVI)augs.getItem(Constants.ELEMENT_PSVI);
1286                if (elementPSVI != null) {
1287                    ((PSVIElementNSImpl)fCurrentNode).setPSVI(elementPSVI);
1288                }
1289            }
1290
1291            if (fDOMFilter != null) {
1292                if (fFilterReject) {
1293                    if (element.equals(fRejectedElement)) {
1294                     fFilterReject = false;
1295                    }
1296                    return;
1297                }
1298                if (!fSkippedElemStack.isEmpty()) {
1299                    if (fSkippedElemStack.peek().equals(element)) {
1300                        fSkippedElemStack.pop();
1301                        return;
1302                    }
1303                }
1304                setCharacterData (false);
1305                if (!fRoot.equals(element) && !fInEntityRef && (fDOMFilter.getWhatToShow () & NodeFilter.SHOW_ELEMENT)!=0) {
1306                    short code = fDOMFilter.acceptNode (fCurrentNode);
1307                    switch (code) {
1308                        case LSParserFilter.FILTER_INTERRUPT:{
1309                            throw abort;
1310                        }
1311                        case LSParserFilter.FILTER_REJECT:{
1312                            Node JavaDoc parent = fCurrentNode.getParentNode();
1313                            parent.removeChild(fCurrentNode);
1314                            fCurrentNode = parent;
1315                            return;
1316                        }
1317                        case LSParserFilter.FILTER_SKIP: {
1318                            // make sure that if any char data is available
1319
// the fFirstChunk is true, so that if the next event
1320
// is characters(), and the last node is text, we will copy
1321
// the value already in the text node to fStringBuffer
1322
// (not to loose it).
1323
fFirstChunk = true;
1324
1325                            // replace children
1326
Node JavaDoc parent = fCurrentNode.getParentNode ();
1327                            NodeList JavaDoc ls = fCurrentNode.getChildNodes ();
1328                            int length = ls.getLength ();
1329
1330                            for (int i=0;i<length;i++) {
1331                                parent.appendChild(ls.item(0));
1332                            }
1333                            parent.removeChild(fCurrentNode);
1334                            fCurrentNode = parent;
1335
1336                            return;
1337                        }
1338
1339                        default: { }
1340                    }
1341                }
1342                fCurrentNode = fCurrentNode.getParentNode ();
1343
1344            } // end-if DOMFilter
1345
else {
1346                setCharacterData(false);
1347                fCurrentNode = fCurrentNode.getParentNode();
1348            }
1349
1350        }
1351        else {
1352            fCurrentNodeIndex =
1353                fDeferredDocumentImpl.getParentNode(fCurrentNodeIndex, false);
1354        }
1355    } // endElement(QName)
1356

1357
1358    /**
1359     * The start of a CDATA section.
1360     * @param augs Additional information that may include infoset augmentations
1361     *
1362     * @throws XNIException Thrown by handler to signal an error.
1363     */

1364    public void startCDATA (Augmentations augs) throws XNIException {
1365
1366        fInCDATASection = true;
1367        if (!fDeferNodeExpansion) {
1368            if (fFilterReject) {
1369                return;
1370            }
1371            if (fCreateCDATANodes) {
1372                setCharacterData (false);
1373            }
1374        }
1375    } // startCDATA()
1376

1377    /**
1378     * The end of a CDATA section.
1379     * @param augs Additional information that may include infoset augmentations
1380     *
1381     * @throws XNIException Thrown by handler to signal an error.
1382     */

1383    public void endCDATA (Augmentations augs) throws XNIException {
1384
1385        fInCDATASection = false;
1386        if (!fDeferNodeExpansion) {
1387
1388            if (fFilterReject) {
1389                return;
1390            }
1391
1392            if (fCurrentCDATASection !=null) {
1393
1394                if (fDOMFilter !=null && !fInEntityRef &&
1395                (fDOMFilter.getWhatToShow () & NodeFilter.SHOW_CDATA_SECTION)!= 0) {
1396                    short code = fDOMFilter.acceptNode (fCurrentCDATASection);
1397                    switch (code) {
1398                        case LSParserFilter.FILTER_INTERRUPT:{
1399                            throw abort;
1400                        }
1401                        case LSParserFilter.FILTER_REJECT:{
1402                            // fall through to SKIP since CDATA section has no children.
1403
}
1404                        case LSParserFilter.FILTER_SKIP: {
1405                            Node JavaDoc parent = fCurrentNode.getParentNode();
1406                            parent.removeChild(fCurrentCDATASection);
1407                            fCurrentNode = parent;
1408                            return;
1409                        }
1410
1411                        default: {
1412                            // accept node
1413
}
1414                    }
1415                }
1416
1417                fCurrentNode = fCurrentNode.getParentNode ();
1418                fCurrentCDATASection = null;
1419            }
1420        }
1421        else {
1422            if (fCurrentCDATASectionIndex !=-1) {
1423                fCurrentNodeIndex =
1424                fDeferredDocumentImpl.getParentNode(fCurrentNodeIndex, false);
1425                fCurrentCDATASectionIndex = -1;
1426            }
1427        }
1428
1429    } // endCDATA()
1430

1431    /**
1432     * The end of the document.
1433     * @param augs Additional information that may include infoset augmentations
1434     *
1435     * @throws XNIException Thrown by handler to signal an error.
1436     */

1437    public void endDocument (Augmentations augs) throws XNIException {
1438
1439        if (!fDeferNodeExpansion) {
1440            // REVISIT: when DOM Level 3 is REC rely on Document.support
1441
// instead of specific class
1442
// set DOM error checking back on
1443
if (fDocumentImpl != null) {
1444                fDocumentImpl.setStrictErrorChecking(true);
1445            }
1446            fCurrentNode = null;
1447        }
1448        else {
1449            fCurrentNodeIndex = -1;
1450        }
1451
1452    } // endDocument()
1453

1454    /**
1455     * This method notifies the end of a general entity.
1456     * <p>
1457     * <strong>Note:</strong> This method is not called for entity references
1458     * appearing as part of attribute values.
1459     *
1460     * @param name The name of the entity.
1461     * @param augs Additional information that may include infoset augmentations
1462     *
1463     * @exception XNIException
1464     * Thrown by handler to signal an error.
1465     */

1466    public void endGeneralEntity(String JavaDoc name, Augmentations augs) throws XNIException {
1467        if (DEBUG_EVENTS) {
1468            System.out.println("==>endGeneralEntity: ("+name+")");
1469        }
1470        if (!fDeferNodeExpansion) {
1471
1472            if (fFilterReject) {
1473                return;
1474            }
1475            setCharacterData (true);
1476
1477            if (fDocumentType != null) {
1478                // get current entity declaration
1479
NamedNodeMap JavaDoc entities = fDocumentType.getEntities();
1480                fCurrentEntityDecl = (EntityImpl) entities.getNamedItem(name);
1481                if (fCurrentEntityDecl != null) {
1482                    if (fCurrentEntityDecl != null && fCurrentEntityDecl.getFirstChild() == null) {
1483                        fCurrentEntityDecl.setReadOnly(false, true);
1484                        Node JavaDoc child = fCurrentNode.getFirstChild();
1485                        while (child != null) {
1486                            Node JavaDoc copy = child.cloneNode (true);
1487                            fCurrentEntityDecl.appendChild (copy);
1488                            child = child.getNextSibling ();
1489                        }
1490                        fCurrentEntityDecl.setReadOnly (true, true);
1491
1492                        //entities.setNamedItem(fCurrentEntityDecl);
1493
}
1494                    fCurrentEntityDecl = null;
1495                }
1496
1497            }
1498            fInEntityRef = false;
1499            boolean removeEntityRef = false;
1500            if (fCreateEntityRefNodes) {
1501                if (fDocumentImpl != null) {
1502                    // Make entity ref node read only
1503
((NodeImpl)fCurrentNode).setReadOnly(true, true);
1504                }
1505
1506                if (fDOMFilter !=null &&
1507                (fDOMFilter.getWhatToShow () & NodeFilter.SHOW_ENTITY_REFERENCE)!= 0) {
1508                    short code = fDOMFilter.acceptNode (fCurrentNode);
1509                    switch (code) {
1510                        case LSParserFilter.FILTER_INTERRUPT:{
1511                            throw abort;
1512                        }
1513                        case LSParserFilter.FILTER_REJECT:{
1514                            Node JavaDoc parent = fCurrentNode.getParentNode();
1515                            parent.removeChild(fCurrentNode);
1516                            fCurrentNode = parent;
1517                            return;
1518
1519                        }
1520                        case LSParserFilter.FILTER_SKIP: {
1521                            // make sure we don't loose chars if next event is characters()
1522
fFirstChunk = true;
1523                            removeEntityRef = true;
1524                            break;
1525                        }
1526
1527                        default: {
1528                            fCurrentNode = fCurrentNode.getParentNode ();
1529                        }
1530                    }
1531                } else {
1532                    fCurrentNode = fCurrentNode.getParentNode();
1533                }
1534            }
1535
1536            if (!fCreateEntityRefNodes || removeEntityRef) {
1537                // move entity reference children to the list of
1538
// siblings of its parent and remove entity reference
1539
NodeList JavaDoc children = fCurrentNode.getChildNodes();
1540                Node JavaDoc parent = fCurrentNode.getParentNode();
1541                int length = children.getLength();
1542                if (length > 0) {
1543                    // get previous sibling of the entity reference
1544
Node JavaDoc node = fCurrentNode.getPreviousSibling();
1545                    // normalize text nodes
1546
Node JavaDoc child = children.item (0);
1547                    if (node != null && node.getNodeType () == Node.TEXT_NODE &&
1548                    child.getNodeType () == Node.TEXT_NODE) {
1549                        ((Text JavaDoc)node).appendData (child.getNodeValue ());
1550                        fCurrentNode.removeChild (child);
1551
1552                    } else {
1553                        node = parent.insertBefore(child, fCurrentNode);
1554                        handleBaseURI(node);
1555                    }
1556
1557                    for (int i=1;i <length;i++) {
1558                        node = parent.insertBefore(children.item(0), fCurrentNode);
1559                        handleBaseURI(node);
1560                    }
1561                } // length > 0
1562
parent.removeChild(fCurrentNode);
1563                fCurrentNode = parent;
1564            }
1565        }
1566        else {
1567
1568            if (fDocumentTypeIndex != -1) {
1569                // find corresponding Entity decl
1570
int node = fDeferredDocumentImpl.getLastChild(fDocumentTypeIndex, false);
1571                while (node != -1) {
1572                    short nodeType = fDeferredDocumentImpl.getNodeType(node, false);
1573                    if (nodeType == Node.ENTITY_NODE) {
1574                        String JavaDoc nodeName =
1575                            fDeferredDocumentImpl.getNodeName(node, false);
1576                        if (nodeName.equals(name)) {
1577                            fDeferredEntityDecl = node;
1578                            break;
1579                        }
1580                    }
1581                    node = fDeferredDocumentImpl.getRealPrevSibling(node, false);
1582                }
1583            }
1584
1585            if (fDeferredEntityDecl != -1 &&
1586            fDeferredDocumentImpl.getLastChild (fDeferredEntityDecl, false) == -1) {
1587                // entity definition exists and it does not have any children
1588
int prevIndex = -1;
1589                int childIndex = fDeferredDocumentImpl.getLastChild (fCurrentNodeIndex, false);
1590                while (childIndex != -1) {
1591                    int cloneIndex = fDeferredDocumentImpl.cloneNode (childIndex, true);
1592                    fDeferredDocumentImpl.insertBefore (fDeferredEntityDecl, cloneIndex, prevIndex);
1593                    prevIndex = cloneIndex;
1594                    childIndex = fDeferredDocumentImpl.getRealPrevSibling (childIndex, false);
1595                }
1596             }
1597             if (fCreateEntityRefNodes) {
1598                fCurrentNodeIndex =
1599                fDeferredDocumentImpl.getParentNode (fCurrentNodeIndex,
1600                false);
1601            } else { //!fCreateEntityRefNodes
1602
// move children of entity ref before the entity ref.
1603
// remove entity ref.
1604

1605                // holds a child of entity ref
1606
int childIndex = fDeferredDocumentImpl.getLastChild (fCurrentNodeIndex, false);
1607                int parentIndex =
1608                fDeferredDocumentImpl.getParentNode (fCurrentNodeIndex,
1609                false);
1610
1611                int prevIndex = fCurrentNodeIndex;
1612                int lastChild = childIndex;
1613                int sibling = -1;
1614                while (childIndex != -1) {
1615                    handleBaseURI (childIndex);
1616                    sibling = fDeferredDocumentImpl.getRealPrevSibling (childIndex, false);
1617                    fDeferredDocumentImpl.insertBefore (parentIndex, childIndex, prevIndex);
1618                    prevIndex = childIndex;
1619                    childIndex = sibling;
1620                }
1621                if(lastChild != -1)
1622                    fDeferredDocumentImpl.setAsLastChild (parentIndex, lastChild);
1623                else{
1624                    sibling = fDeferredDocumentImpl.getRealPrevSibling (prevIndex, false);
1625                    fDeferredDocumentImpl.setAsLastChild (parentIndex, sibling);
1626                }
1627                fCurrentNodeIndex = parentIndex;
1628            }
1629            fDeferredEntityDecl = -1;
1630        }
1631    } // endGeneralEntity(String, Augmentations)
1632

1633    /**
1634     * Record baseURI information for the Element (by adding xml:base attribute)
1635     * or for the ProcessingInstruction (by setting a baseURI field)
1636     * Non deferred DOM.
1637     *
1638     * @param node
1639     */

1640    protected final void handleBaseURI (Node JavaDoc node){
1641        if (fDocumentImpl != null) {
1642            // REVISIT: remove dependency on our implementation when
1643
// DOM L3 becomes REC
1644
String JavaDoc baseURI = null;
1645            short nodeType = node.getNodeType ();
1646
1647            if (nodeType == Node.ELEMENT_NODE) {
1648                // if an element already has xml:base attribute
1649
// do nothing
1650
if (fNamespaceAware) {
1651                    if (((Element JavaDoc)node).getAttributeNodeNS("http://www.w3.org/XML/1998/namespace","base")!=null) {
1652                        return;
1653                    }
1654                } else if (((Element JavaDoc)node).getAttributeNode("xml:base") != null) {
1655                    return;
1656                }
1657                // retrive the baseURI from the entity reference
1658
baseURI = ((EntityReferenceImpl)fCurrentNode).getBaseURI();
1659                if (baseURI !=null && !baseURI.equals(fDocumentImpl.getDocumentURI())) {
1660                    if (fNamespaceAware) {
1661                        ((Element JavaDoc)node).setAttributeNS("http://www.w3.org/XML/1998/namespace","base", baseURI);
1662                    } else {
1663                        ((Element JavaDoc)node).setAttribute("xml:base", baseURI);
1664                    }
1665                }
1666            }
1667            else if (nodeType == Node.PROCESSING_INSTRUCTION_NODE) {
1668
1669                baseURI = ((EntityReferenceImpl)fCurrentNode).getBaseURI ();
1670                if (baseURI !=null && fErrorHandler != null) {
1671                    DOMErrorImpl error = new DOMErrorImpl ();
1672                    error.fType = "infoset-baseURI";
1673                    error.fRelatedData = baseURI;
1674                    error.fSeverity = DOMError.SEVERITY_WARNING;
1675                    fErrorHandler.getErrorHandler().handleError(error);
1676                }
1677            }
1678        }
1679    }
1680
1681    /**
1682     *
1683     * Record baseURI information for the Element (by adding xml:base attribute)
1684     * or for the ProcessingInstruction (by setting a baseURI field)
1685     * Deferred DOM.
1686     *
1687     * @param node
1688     */

1689    protected final void handleBaseURI (int node){
1690        short nodeType = fDeferredDocumentImpl.getNodeType (node, false);
1691
1692        if (nodeType == Node.ELEMENT_NODE) {
1693            String JavaDoc baseURI = fDeferredDocumentImpl.getNodeValueString(fCurrentNodeIndex, false);
1694            if (baseURI == null) {
1695                baseURI = fDeferredDocumentImpl.getDeferredEntityBaseURI(fDeferredEntityDecl);
1696            }
1697            if (baseURI !=null && !baseURI.equals(fDeferredDocumentImpl.getDocumentURI())) {
1698                fDeferredDocumentImpl.setDeferredAttribute(node,
1699                                                           "xml:base",
1700                                                           "http://www.w3.org/XML/1998/namespace",
1701                                                           baseURI,
1702                                                           true);
1703            }
1704        }
1705        else if (nodeType == Node.PROCESSING_INSTRUCTION_NODE) {
1706
1707
1708            // retrieve baseURI from the entity reference
1709
String JavaDoc baseURI = fDeferredDocumentImpl.getNodeValueString (fCurrentNodeIndex, false);
1710
1711            if (baseURI == null) {
1712                // try baseURI of the entity declaration
1713
baseURI = fDeferredDocumentImpl.getDeferredEntityBaseURI (fDeferredEntityDecl);
1714            }
1715
1716            if (baseURI != null && fErrorHandler != null) {
1717                DOMErrorImpl error = new DOMErrorImpl ();
1718                error.fType = "infoset-baseURI";
1719                error.fRelatedData = baseURI;
1720                error.fSeverity = DOMError.SEVERITY_WARNING;
1721                fErrorHandler.getErrorHandler().handleError(error);
1722            }
1723        }
1724    }
1725
1726
1727    //
1728
// XMLDTDHandler methods
1729
//
1730

1731    /**
1732     * The start of the DTD.
1733     *
1734     * @param locator The document locator, or null if the document
1735     * location cannot be reported during the parsing of
1736     * the document DTD. However, it is <em>strongly</em>
1737     * recommended that a locator be supplied that can
1738     * at least report the base system identifier of the
1739     * DTD.
1740     * @param augs Additional information that may include infoset
1741     * augmentations.
1742     *
1743     * @throws XNIException Thrown by handler to signal an error.
1744     */

1745    public void startDTD(XMLLocator locator, Augmentations augs) throws XNIException {
1746        if (DEBUG_EVENTS) {
1747            System.out.println("==>startDTD");
1748            if (DEBUG_BASEURI) {
1749                System.out.println(" expandedSystemId: "+locator.getExpandedSystemId());
1750                System.out.println(" baseURI:"+ locator.getBaseSystemId());
1751            }
1752        }
1753
1754        fInDTD = true;
1755        if (locator != null) {
1756            fBaseURIStack.push(locator.getBaseSystemId());
1757        }
1758        if (fDeferNodeExpansion || fDocumentImpl != null) {
1759            fInternalSubset = new StringBuffer JavaDoc(1024);
1760        }
1761    } // startDTD(XMLLocator)
1762

1763
1764    /**
1765     * The end of the DTD.
1766     *
1767     * @param augs Additional information that may include infoset
1768     * augmentations.
1769     *
1770     * @throws XNIException Thrown by handler to signal an error.
1771     */

1772    public void endDTD(Augmentations augs) throws XNIException {
1773        if (DEBUG_EVENTS) {
1774            System.out.println("==>endDTD()");
1775        }
1776        fInDTD = false;
1777        if (!fBaseURIStack.isEmpty()) {
1778            fBaseURIStack.pop();
1779        }
1780        String JavaDoc internalSubset = fInternalSubset != null && fInternalSubset.length() > 0
1781                              ? fInternalSubset.toString() : null;
1782        if (fDeferNodeExpansion) {
1783            if (internalSubset != null) {
1784                fDeferredDocumentImpl.setInternalSubset(fDocumentTypeIndex, internalSubset);
1785            }
1786        }
1787        else if (fDocumentImpl != null) {
1788            if (internalSubset != null) {
1789                ((DocumentTypeImpl)fDocumentType).setInternalSubset(internalSubset);
1790            }
1791        }
1792    } // endDTD()
1793

1794    /**
1795     * The start of a conditional section.
1796     *
1797     * @param type The type of the conditional section. This value will
1798     * either be CONDITIONAL_INCLUDE or CONDITIONAL_IGNORE.
1799     * @param augs Additional information that may include infoset
1800     * augmentations.
1801     *
1802     * @throws XNIException Thrown by handler to signal an error.
1803     *
1804     * @see #CONDITIONAL_INCLUDE
1805     * @see #CONDITIONAL_IGNORE
1806     */

1807    public void startConditional(short type, Augmentations augs) throws XNIException {
1808    } // startConditional(short)
1809

1810    /**
1811     * The end of a conditional section.
1812     *
1813     * @param augs Additional information that may include infoset
1814     * augmentations.
1815     *
1816     * @throws XNIException Thrown by handler to signal an error.
1817     */

1818    public void endConditional(Augmentations augs) throws XNIException {
1819    } // endConditional()
1820

1821
1822    /**
1823     * The start of the DTD external subset.
1824     *
1825     * @param augs Additional information that may include infoset
1826     * augmentations.
1827     *
1828     * @throws XNIException Thrown by handler to signal an error.
1829     */

1830    public void startExternalSubset(XMLResourceIdentifier identifier,
1831                                    Augmentations augs) throws XNIException {
1832        if (DEBUG_EVENTS) {
1833            System.out.println("==>startExternalSubset");
1834            if (DEBUG_BASEURI) {
1835                System.out.println(" expandedSystemId: "+identifier.getExpandedSystemId());
1836                System.out.println(" baseURI:"+ identifier.getBaseSystemId());
1837            }
1838        }
1839        fBaseURIStack.push(identifier.getBaseSystemId());
1840        fInDTDExternalSubset = true;
1841    } // startExternalSubset(Augmentations)
1842

1843    /**
1844     * The end of the DTD external subset.
1845     *
1846     * @param augs Additional information that may include infoset
1847     * augmentations.
1848     *
1849     * @throws XNIException Thrown by handler to signal an error.
1850     */

1851    public void endExternalSubset(Augmentations augs) throws XNIException {
1852        fInDTDExternalSubset = false;
1853        fBaseURIStack.pop();
1854    } // endExternalSubset(Augmentations)
1855

1856    /**
1857     * An internal entity declaration.
1858     *
1859     * @param name The name of the entity. Parameter entity names start with
1860     * '%', whereas the name of a general entity is just the
1861     * entity name.
1862     * @param text The value of the entity.
1863     * @param nonNormalizedText The non-normalized value of the entity. This
1864     * value contains the same sequence of characters that was in
1865     * the internal entity declaration, without any entity
1866     * references expanded.
1867     * @param augs Additional information that may include infoset
1868     * augmentations.
1869     *
1870     * @throws XNIException Thrown by handler to signal an error.
1871     */

1872    public void internalEntityDecl (String JavaDoc name, XMLString text,
1873    XMLString nonNormalizedText,
1874    Augmentations augs) throws XNIException {
1875
1876        if (DEBUG_EVENTS) {
1877            System.out.println("==>internalEntityDecl: "+name);
1878            if (DEBUG_BASEURI) {
1879                System.out.println(" baseURI:"+ (String JavaDoc)fBaseURIStack.peek());
1880            }
1881        }
1882        // internal subset string
1883
if (fInternalSubset != null && !fInDTDExternalSubset) {
1884            fInternalSubset.append("<!ENTITY ");
1885            if (name.startsWith("%")) {
1886                fInternalSubset.append("% ");
1887                fInternalSubset.append(name.substring(1));
1888            }
1889            else {
1890                fInternalSubset.append(name);
1891            }
1892            fInternalSubset.append(' ');
1893            String JavaDoc value = nonNormalizedText.toString();
1894            boolean singleQuote = value.indexOf('\'') == -1;
1895            fInternalSubset.append(singleQuote ? '\'' : '"');
1896            fInternalSubset.append(value);
1897            fInternalSubset.append(singleQuote ? '\'' : '"');
1898            fInternalSubset.append(">\n");
1899        }
1900
1901        // NOTE: We only know how to create these nodes for the Xerces
1902
// DOM implementation because DOM Level 2 does not specify
1903
// that functionality. -Ac
1904

1905        // create full node
1906
// don't add parameter entities!
1907
if(name.startsWith("%"))
1908            return;
1909        if (fDocumentType != null) {
1910            NamedNodeMap JavaDoc entities = fDocumentType.getEntities();
1911            EntityImpl entity = (EntityImpl)entities.getNamedItem(name);
1912            if (entity == null) {
1913                entity = (EntityImpl)fDocumentImpl.createEntity(name);
1914                entity.setBaseURI((String JavaDoc)fBaseURIStack.peek());
1915                entities.setNamedItem(entity);
1916            }
1917        }
1918
1919        // create deferred node
1920
if (fDocumentTypeIndex != -1) {
1921            boolean found = false;
1922            int node = fDeferredDocumentImpl.getLastChild(fDocumentTypeIndex, false);
1923            while (node != -1) {
1924                short nodeType = fDeferredDocumentImpl.getNodeType(node, false);
1925                if (nodeType == Node.ENTITY_NODE) {
1926                    String JavaDoc nodeName = fDeferredDocumentImpl.getNodeName(node, false);
1927                    if (nodeName.equals(name)) {
1928                        found = true;
1929                        break;
1930                    }
1931                }
1932                node = fDeferredDocumentImpl.getRealPrevSibling(node, false);
1933            }
1934            if (!found) {
1935                int entityIndex =
1936                    fDeferredDocumentImpl.createDeferredEntity(name, null, null, null, (String JavaDoc)fBaseURIStack.peek());
1937                fDeferredDocumentImpl.appendChild(fDocumentTypeIndex, entityIndex);
1938            }
1939        }
1940
1941    } // internalEntityDecl(String,XMLString,XMLString)
1942

1943    /**
1944     * An external entity declaration.
1945     *
1946     * @param name The name of the entity. Parameter entity names start
1947     * with '%', whereas the name of a general entity is just
1948     * the entity name.
1949     * @param identifier An object containing all location information
1950     * pertinent to this notation.
1951     * @param augs Additional information that may include infoset
1952     * augmentations.
1953     *
1954     * @throws XNIException Thrown by handler to signal an error.
1955     */

1956    public void externalEntityDecl (String JavaDoc name, XMLResourceIdentifier identifier,
1957    Augmentations augs) throws XNIException {
1958
1959
1960        if (DEBUG_EVENTS) {
1961            System.out.println("==>externalEntityDecl: "+name);
1962            if (DEBUG_BASEURI) {
1963                System.out.println(" expandedSystemId:"+ identifier.getExpandedSystemId());
1964                System.out.println(" baseURI:"+ identifier.getBaseSystemId());
1965            }
1966        }
1967        // internal subset string
1968
String JavaDoc publicId = identifier.getPublicId();
1969        String JavaDoc literalSystemId = identifier.getLiteralSystemId();
1970        if (fInternalSubset != null && !fInDTDExternalSubset) {
1971            fInternalSubset.append("<!ENTITY ");
1972            if (name.startsWith("%")) {
1973                fInternalSubset.append("% ");
1974                fInternalSubset.append(name.substring(1));
1975            }
1976            else {
1977                fInternalSubset.append(name);
1978            }
1979            fInternalSubset.append(' ');
1980            if (publicId != null) {
1981                fInternalSubset.append("PUBLIC '");
1982                fInternalSubset.append(publicId);
1983                fInternalSubset.append("' '");
1984            }
1985            else {
1986                fInternalSubset.append("SYSTEM '");
1987            }
1988            fInternalSubset.append(literalSystemId);
1989            fInternalSubset.append("'>\n");
1990        }
1991
1992        // NOTE: We only know how to create these nodes for the Xerces
1993
// DOM implementation because DOM Level 2 does not specify
1994
// that functionality. -Ac
1995

1996        // create full node
1997
// don't add parameter entities!
1998
if(name.startsWith("%"))
1999            return;
2000        if (fDocumentType != null) {
2001            NamedNodeMap JavaDoc entities = fDocumentType.getEntities();
2002            EntityImpl entity = (EntityImpl)entities.getNamedItem(name);
2003            if (entity == null) {
2004                entity = (EntityImpl)fDocumentImpl.createEntity(name);
2005                entity.setPublicId(publicId);
2006                entity.setSystemId(literalSystemId);
2007                entity.setBaseURI(identifier.getBaseSystemId());
2008                entities.setNamedItem(entity);
2009            }
2010        }
2011
2012        // create deferred node
2013
if (fDocumentTypeIndex != -1) {
2014            boolean found = false;
2015            int nodeIndex = fDeferredDocumentImpl.getLastChild(fDocumentTypeIndex, false);
2016            while (nodeIndex != -1) {
2017                short nodeType = fDeferredDocumentImpl.getNodeType(nodeIndex, false);
2018                if (nodeType == Node.ENTITY_NODE) {
2019                    String JavaDoc nodeName = fDeferredDocumentImpl.getNodeName(nodeIndex, false);
2020                    if (nodeName.equals(name)) {
2021                        found = true;
2022                        break;
2023                    }
2024                }
2025                nodeIndex = fDeferredDocumentImpl.getRealPrevSibling(nodeIndex, false);
2026            }
2027            if (!found) {
2028                int entityIndex = fDeferredDocumentImpl.createDeferredEntity(
2029                                    name, publicId, literalSystemId, null, identifier.getBaseSystemId());
2030                fDeferredDocumentImpl.appendChild(fDocumentTypeIndex, entityIndex);
2031            }
2032        }
2033    
2034
2035    } // externalEntityDecl(String,XMLResourceIdentifier, Augmentations)
2036

2037
2038    /**
2039     * This method notifies of the start of a parameter entity. The parameter
2040     * entity name start with a '%' character.
2041     *
2042     * @param name The name of the parameter entity.
2043     * @param identifier The resource identifier.
2044     * @param encoding The auto-detected IANA encoding name of the entity
2045     * stream. This value will be null in those situations
2046     * where the entity encoding is not auto-detected (e.g.
2047     * internal parameter entities).
2048     * @param augs Additional information that may include infoset
2049     * augmentations.
2050     *
2051     * @throws XNIException Thrown by handler to signal an error.
2052     */

2053    public void startParameterEntity(String JavaDoc name,
2054                                     XMLResourceIdentifier identifier,
2055                                     String JavaDoc encoding,
2056                                     Augmentations augs) throws XNIException {
2057        if (DEBUG_EVENTS) {
2058            System.out.println("==>startParameterEntity: "+name);
2059            if (DEBUG_BASEURI) {
2060                System.out.println(" expandedSystemId: "+identifier.getExpandedSystemId());
2061                System.out.println(" baseURI:"+ identifier.getBaseSystemId());
2062            }
2063        }
2064        fBaseURIStack.push(identifier.getExpandedSystemId());
2065    }
2066
2067
2068    /**
2069     * This method notifies the end of a parameter entity. Parameter entity
2070     * names begin with a '%' character.
2071     *
2072     * @param name The name of the parameter entity.
2073     * @param augs Additional information that may include infoset
2074     * augmentations.
2075     *
2076     * @throws XNIException Thrown by handler to signal an error.
2077     */

2078    public void endParameterEntity (String JavaDoc name, Augmentations augs) throws XNIException {
2079
2080        if (DEBUG_EVENTS) {
2081            System.out.println("==>endParameterEntity: "+name);
2082        }
2083        fBaseURIStack.pop();
2084    }
2085
2086    /**
2087     * An unparsed entity declaration.
2088     *
2089     * @param name The name of the entity.
2090     * @param identifier An object containing all location information
2091     * pertinent to this entity.
2092     * @param notation The name of the notation.
2093     * @param augs Additional information that may include infoset
2094     * augmentations.
2095     *
2096     * @throws XNIException Thrown by handler to signal an error.
2097     */

2098    public void unparsedEntityDecl (String JavaDoc name, XMLResourceIdentifier identifier,
2099    String JavaDoc notation, Augmentations augs)
2100    throws XNIException {
2101
2102        if (DEBUG_EVENTS) {
2103            System.out.println("==>unparsedEntityDecl: "+name);
2104            if (DEBUG_BASEURI) {
2105                System.out.println(" expandedSystemId:"+ identifier.getExpandedSystemId());
2106                System.out.println(" baseURI:"+ identifier.getBaseSystemId());
2107            }
2108        }
2109        // internal subset string
2110
String JavaDoc publicId = identifier.getPublicId();
2111        String JavaDoc literalSystemId = identifier.getLiteralSystemId();
2112        if (fInternalSubset != null && !fInDTDExternalSubset) {
2113            fInternalSubset.append("<!ENTITY ");
2114            fInternalSubset.append(name);
2115            fInternalSubset.append(' ');
2116            if (publicId != null) {
2117                fInternalSubset.append("PUBLIC '");
2118                fInternalSubset.append(publicId);
2119                if (literalSystemId != null) {
2120                    fInternalSubset.append("' '");
2121                    fInternalSubset.append(literalSystemId);
2122                }
2123            }
2124            else {
2125                fInternalSubset.append("SYSTEM '");
2126                fInternalSubset.append(literalSystemId);
2127            }
2128            fInternalSubset.append("' NDATA ");
2129            fInternalSubset.append(notation);
2130            fInternalSubset.append(">\n");
2131        }
2132
2133        // NOTE: We only know how to create these nodes for the Xerces
2134
// DOM implementation because DOM Level 2 does not specify
2135
// that functionality. -Ac
2136

2137        // create full node
2138
if (fDocumentType != null) {
2139            NamedNodeMap JavaDoc entities = fDocumentType.getEntities();
2140            EntityImpl entity = (EntityImpl)entities.getNamedItem(name);
2141            if (entity == null) {
2142                entity = (EntityImpl)fDocumentImpl.createEntity(name);
2143                entity.setPublicId(publicId);
2144                entity.setSystemId(literalSystemId);
2145                entity.setNotationName(notation);
2146                entity.setBaseURI(identifier.getBaseSystemId());
2147                entities.setNamedItem(entity);
2148            }
2149        }
2150
2151        // create deferred node
2152
if (fDocumentTypeIndex != -1) {
2153            boolean found = false;
2154            int nodeIndex = fDeferredDocumentImpl.getLastChild(fDocumentTypeIndex, false);
2155            while (nodeIndex != -1) {
2156                short nodeType = fDeferredDocumentImpl.getNodeType(nodeIndex, false);
2157                if (nodeType == Node.ENTITY_NODE) {
2158                    String JavaDoc nodeName = fDeferredDocumentImpl.getNodeName(nodeIndex, false);
2159                    if (nodeName.equals(name)) {
2160                        found = true;
2161                        break;
2162                    }
2163                }
2164                nodeIndex = fDeferredDocumentImpl.getRealPrevSibling(nodeIndex, false);
2165            }
2166            if (!found) {
2167                int entityIndex = fDeferredDocumentImpl.createDeferredEntity(
2168                                    name, publicId, literalSystemId, notation, identifier.getBaseSystemId());
2169                fDeferredDocumentImpl.appendChild(fDocumentTypeIndex, entityIndex);
2170            }
2171        }
2172
2173    } // unparsedEntityDecl(String,XMLResourceIdentifier, String, Augmentations)
2174

2175    /**
2176     * A notation declaration
2177     *
2178     * @param name The name of the notation.
2179     * @param identifier An object containing all location information
2180     * pertinent to this notation.
2181     * @param augs Additional information that may include infoset
2182     * augmentations.
2183     *
2184     * @throws XNIException Thrown by handler to signal an error.
2185     */

2186    public void notationDecl (String JavaDoc name, XMLResourceIdentifier identifier,
2187    Augmentations augs) throws XNIException {
2188
2189        // internal subset string
2190
String JavaDoc publicId = identifier.getPublicId ();
2191        String JavaDoc literalSystemId = identifier.getLiteralSystemId ();
2192        if (fInternalSubset != null && !fInDTDExternalSubset) {
2193            fInternalSubset.append ("<!NOTATION ");
2194            fInternalSubset.append (name);
2195            if (publicId != null) {
2196                fInternalSubset.append (" PUBLIC '");
2197                fInternalSubset.append (publicId);
2198                if (literalSystemId != null) {
2199                    fInternalSubset.append ("' '");
2200                    fInternalSubset.append (literalSystemId);
2201                }
2202            }
2203            else {
2204                fInternalSubset.append (" SYSTEM '");
2205                fInternalSubset.append (literalSystemId);
2206            }
2207            fInternalSubset.append ("'>\n");
2208        }
2209
2210        // NOTE: We only know how to create these nodes for the Xerces
2211
// DOM implementation because DOM Level 2 does not specify
2212
// that functionality. -Ac
2213

2214        // create full node
2215
if (fDocumentImpl !=null && fDocumentType != null) {
2216            NamedNodeMap JavaDoc notations = fDocumentType.getNotations();
2217            if (notations.getNamedItem(name) == null) {
2218                NotationImpl notation = (NotationImpl)fDocumentImpl.createNotation(name);
2219                notation.setPublicId(publicId);
2220                notation.setSystemId(literalSystemId);
2221                notation.setBaseURI(identifier.getBaseSystemId());
2222                notations.setNamedItem(notation);
2223            }
2224        }
2225
2226        // create deferred node
2227
if (fDocumentTypeIndex != -1) {
2228            boolean found = false;
2229            int nodeIndex = fDeferredDocumentImpl.getLastChild(fDocumentTypeIndex, false);
2230            while (nodeIndex != -1) {
2231                short nodeType = fDeferredDocumentImpl.getNodeType(nodeIndex, false);
2232                if (nodeType == Node.NOTATION_NODE) {
2233                    String JavaDoc nodeName = fDeferredDocumentImpl.getNodeName(nodeIndex, false);
2234                    if (nodeName.equals(name)) {
2235                        found = true;
2236                        break;
2237                    }
2238                }
2239                nodeIndex = fDeferredDocumentImpl.getPrevSibling(nodeIndex, false);
2240            }
2241            if (!found) {
2242                int notationIndex = fDeferredDocumentImpl.createDeferredNotation(
2243                                        name, publicId, literalSystemId, identifier.getBaseSystemId());
2244                fDeferredDocumentImpl.appendChild(fDocumentTypeIndex, notationIndex);
2245            }
2246        }
2247
2248    } // notationDecl(String,XMLResourceIdentifier, Augmentations)
2249

2250    /**
2251     * Characters within an IGNORE conditional section.
2252     *
2253     * @param text The ignored text.
2254     * @param augs Additional information that may include infoset
2255     * augmentations.
2256     *
2257     * @throws XNIException Thrown by handler to signal an error.
2258     */

2259    public void ignoredCharacters (XMLString text, Augmentations augs) throws XNIException {
2260    } // ignoredCharacters(XMLString, Augmentations)
2261

2262
2263    /**
2264     * An element declaration.
2265     *
2266     * @param name The name of the element.
2267     * @param contentModel The element content model.
2268     * @param augs Additional information that may include infoset
2269     * augmentations.
2270     *
2271     * @throws XNIException Thrown by handler to signal an error.
2272     */

2273    public void elementDecl (String JavaDoc name, String JavaDoc contentModel, Augmentations augs)
2274    throws XNIException {
2275
2276        // internal subset string
2277
if (fInternalSubset != null && !fInDTDExternalSubset) {
2278            fInternalSubset.append("<!ELEMENT ");
2279            fInternalSubset.append(name);
2280            fInternalSubset.append(' ');
2281            fInternalSubset.append(contentModel);
2282            fInternalSubset.append(">\n");
2283        }
2284
2285    } // elementDecl(String,String)
2286

2287    /**
2288     * An attribute declaration.
2289     *
2290     * @param elementName The name of the element that this attribute
2291     * is associated with.
2292     * @param attributeName The name of the attribute.
2293     * @param type The attribute type. This value will be one of
2294     * the following: "CDATA", "ENTITY", "ENTITIES",
2295     * "ENUMERATION", "ID", "IDREF", "IDREFS",
2296     * "NMTOKEN", "NMTOKENS", or "NOTATION".
2297     * @param enumeration If the type has the value "ENUMERATION" or
2298     * "NOTATION", this array holds the allowed attribute
2299     * values; otherwise, this array is null.
2300     * @param defaultType The attribute default type. This value will be
2301     * one of the following: "#FIXED", "#IMPLIED",
2302     * "#REQUIRED", or null.
2303     * @param defaultValue The attribute default value, or null if no
2304     * default value is specified.
2305     * @param nonNormalizedDefaultValue The attribute default value with no normalization
2306     * performed, or null if no default value is specified.
2307     * @param augs Additional information that may include infoset
2308     * augmentations.
2309     *
2310     * @throws XNIException Thrown by handler to signal an error.
2311     */

2312    public void attributeDecl (String JavaDoc elementName, String JavaDoc attributeName,
2313    String JavaDoc type, String JavaDoc[] enumeration,
2314    String JavaDoc defaultType, XMLString defaultValue,
2315    XMLString nonNormalizedDefaultValue, Augmentations augs) throws XNIException {
2316
2317        // internal subset string
2318
if (fInternalSubset != null && !fInDTDExternalSubset) {
2319            fInternalSubset.append("<!ATTLIST ");
2320            fInternalSubset.append(elementName);
2321            fInternalSubset.append(' ');
2322            fInternalSubset.append(attributeName);
2323            fInternalSubset.append(' ');
2324            if (type.equals("ENUMERATION")) {
2325                fInternalSubset.append('(');
2326                for (int i = 0; i < enumeration.length; i++) {
2327                    if (i > 0) {
2328                        fInternalSubset.append('|');
2329                    }
2330                    fInternalSubset.append(enumeration[i]);
2331                }
2332                fInternalSubset.append(')');
2333            }
2334            else {
2335                fInternalSubset.append(type);
2336            }
2337            if (defaultType != null) {
2338                fInternalSubset.append(' ');
2339                fInternalSubset.append(defaultType);
2340            }
2341            if (defaultValue != null) {
2342                fInternalSubset.append(" '");
2343                for (int i = 0; i < defaultValue.length; i++) {
2344                    char c = defaultValue.ch[defaultValue.offset + i];
2345                    if (c == '\'') {
2346                        fInternalSubset.append("&apos;");
2347                    }
2348                    else {
2349                        fInternalSubset.append(c);
2350                    }
2351                }
2352                fInternalSubset.append('\'');
2353            }
2354            fInternalSubset.append(">\n");
2355        }
2356        // REVISIT: This code applies to the support of domx/grammar-access
2357
// feature in Xerces 1
2358

2359
2360        // deferred expansion
2361
if (fDeferredDocumentImpl != null) {
2362
2363            // get the default value
2364
if (defaultValue != null) {
2365
2366                // get element definition
2367
int elementDefIndex = fDeferredDocumentImpl.lookupElementDefinition (elementName);
2368
2369                // create element definition if not already there
2370
if (elementDefIndex == -1) {
2371                    elementDefIndex = fDeferredDocumentImpl.createDeferredElementDefinition(elementName);
2372                    fDeferredDocumentImpl.appendChild(fDocumentTypeIndex, elementDefIndex);
2373                }
2374                // add default attribute
2375
int attrIndex = fDeferredDocumentImpl.createDeferredAttribute(
2376                                    attributeName, defaultValue.toString(), false);
2377                if ("ID".equals(type)) {
2378                    fDeferredDocumentImpl.setIdAttribute(attrIndex);
2379                }
2380                // REVISIT: set ID type correctly
2381
fDeferredDocumentImpl.appendChild(elementDefIndex, attrIndex);
2382            }
2383
2384        } // if deferred
2385

2386        // full expansion
2387
else if (fDocumentImpl != null) {
2388
2389            // get the default value
2390
if (defaultValue != null) {
2391
2392                // get element definition node
2393
NamedNodeMap JavaDoc elements = ((DocumentTypeImpl)fDocumentType).getElements();
2394                ElementDefinitionImpl elementDef = (ElementDefinitionImpl)elements.getNamedItem(elementName);
2395                if (elementDef == null) {
2396                    elementDef = fDocumentImpl.createElementDefinition(elementName);
2397                    ((DocumentTypeImpl)fDocumentType).getElements().setNamedItem(elementDef);
2398                }
2399
2400                // REVISIT: Check for uniqueness of element name? -Ac
2401

2402                // create attribute and set properties
2403
boolean nsEnabled = fNamespaceAware;
2404                AttrImpl attr;
2405                if (nsEnabled) {
2406                    String JavaDoc namespaceURI = null;
2407                    // DOM Level 2 wants all namespace declaration attributes
2408
// to be bound to "http://www.w3.org/2000/xmlns/"
2409
// So as long as the XML parser doesn't do it, it needs to
2410
// done here.
2411
if (attributeName.startsWith("xmlns:") ||
2412                        attributeName.equals("xmlns")) {
2413                        namespaceURI = NamespaceContext.XMLNS_URI;
2414                    }
2415                    attr = (AttrImpl)fDocumentImpl.createAttributeNS(namespaceURI,
2416                                                                attributeName);
2417                }
2418                else {
2419                    attr = (AttrImpl)fDocumentImpl.createAttribute(attributeName);
2420                }
2421                attr.setValue (defaultValue.toString ());
2422                attr.setSpecified (false);
2423                attr.setIdAttribute ("ID".equals (type));
2424
2425                // add default attribute to element definition
2426
if (nsEnabled){
2427                    elementDef.getAttributes().setNamedItemNS(attr);
2428                }
2429                else {
2430                    elementDef.getAttributes().setNamedItem(attr);
2431                }
2432            }
2433
2434        } // if NOT defer-node-expansion
2435

2436
2437    } // attributeDecl(String,String,String,String[],String,XMLString, XMLString, Augmentations)
2438

2439
2440    /**
2441     * The start of an attribute list.
2442     *
2443     * @param elementName The name of the element that this attribute
2444     * list is associated with.
2445     * @param augs Additional information that may include infoset
2446     * augmentations.
2447     *
2448     * @throws XNIException Thrown by handler to signal an error.
2449     */

2450    public void startAttlist(String JavaDoc elementName, Augmentations augs) throws XNIException {
2451    } // startAttlist(String)
2452

2453
2454    /**
2455     * The end of an attribute list.
2456     *
2457     * @param augs Additional information that may include infoset
2458     * augmentations.
2459     *
2460     * @throws XNIException Thrown by handler to signal an error.
2461     */

2462    public void endAttlist(Augmentations augs) throws XNIException {
2463    } // endAttlist()
2464

2465
2466    // method to create an element node.
2467
// subclasses can override this method to create element nodes in other ways.
2468
protected Element JavaDoc createElementNode(QName element) {
2469        Element JavaDoc el = null;
2470
2471        if (fNamespaceAware) {
2472            // if we are using xerces DOM implementation, call our
2473
// own constructor to reuse the strings we have here.
2474
if (fDocumentImpl != null) {
2475                el = fDocumentImpl.createElementNS(element.uri, element.rawname,
2476                                                   element.localpart);
2477            }
2478            else {
2479                el = fDocument.createElementNS(element.uri, element.rawname);
2480            }
2481        }
2482        else {
2483            el = fDocument.createElement(element.rawname);
2484        }
2485
2486        return el;
2487    }
2488
2489    // method to create an attribute node.
2490
// subclasses can override this method to create attribute nodes in other ways.
2491
protected Attr JavaDoc createAttrNode(QName attrQName) {
2492        Attr JavaDoc attr = null;
2493
2494        if (fNamespaceAware) {
2495            if (fDocumentImpl != null) {
2496                // if we are using xerces DOM implementation, call our
2497
// own constructor to reuse the strings we have here.
2498
attr = fDocumentImpl.createAttributeNS(attrQName.uri,
2499                                                       attrQName.rawname,
2500                                                       attrQName.localpart);
2501            }
2502            else {
2503                attr = fDocument.createAttributeNS(attrQName.uri,
2504                                                   attrQName.rawname);
2505            }
2506        }
2507        else {
2508            attr = fDocument.createAttribute(attrQName.rawname);
2509        }
2510
2511        return attr;
2512    }
2513
2514    /*
2515     * When the first characters() call is received, the data is stored in
2516     * a new Text node. If right after the first characters() we receive another chunk of data,
2517     * the data from the Text node, following the new characters are appended
2518     * to the fStringBuffer and the text node data is set to empty.
2519     *
2520     * This function is called when the state is changed and the
2521     * data must be appended to the current node.
2522     *
2523     * Note: if DOMFilter is set, you must make sure that if Node is skipped,
2524     * or removed fFistChunk must be set to true, otherwise some data can be lost.
2525     *
2526     */

2527
2528    protected void setCharacterData (boolean sawChars){
2529
2530        // handle character data
2531
fFirstChunk = sawChars;
2532        
2533
2534
2535
2536        // if we have data in the buffer we must have created
2537
// a text node already.
2538

2539        Node JavaDoc child = fCurrentNode.getLastChild ();
2540        if (child != null) {
2541            if (fStringBuffer.length () > 0) {
2542                // REVISIT: should this check be performed?
2543
if (child.getNodeType() == Node.TEXT_NODE) {
2544                    if (fDocumentImpl != null) {
2545                        ((TextImpl)child).replaceData(fStringBuffer.toString());
2546                    }
2547                    else {
2548                        ((Text JavaDoc)child).setData(fStringBuffer.toString());
2549                    }
2550                }
2551                // reset string buffer
2552
fStringBuffer.setLength(0);
2553            }
2554
2555            if (fDOMFilter !=null && !fInEntityRef) {
2556                if ( (child.getNodeType () == Node.TEXT_NODE ) &&
2557                ((fDOMFilter.getWhatToShow () & NodeFilter.SHOW_TEXT)!= 0) ) {
2558                    short code = fDOMFilter.acceptNode (child);
2559                    switch (code) {
2560                        case LSParserFilter.FILTER_INTERRUPT:{
2561                            throw abort;
2562                        }
2563                        case LSParserFilter.FILTER_REJECT:{
2564                            // fall through to SKIP since Comment has no children.
2565
}
2566                        case LSParserFilter.FILTER_SKIP: {
2567                            fCurrentNode.removeChild(child);
2568                            return;
2569                        }
2570                        default: {
2571                            // accept node -- do nothing
2572
}
2573                    }
2574                }
2575            } // end-if fDOMFilter !=null
2576

2577        } // end-if child !=null
2578
}
2579
2580
2581    /**
2582     * @see org.w3c.dom.ls.LSParser#abort()
2583     */

2584    public void abort () {
2585        throw abort;
2586    }
2587    
2588
2589} // class AbstractDOMParser
2590
Popular Tags