1 /*
   2  * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package org.xml.sax.ptests;
  24 
  25 import java.io.FileInputStream;
  26 import java.io.IOException;
  27 import javax.xml.parsers.ParserConfigurationException;
  28 import javax.xml.parsers.SAXParserFactory;
  29 import static jaxp.library.JAXPTestUtilities.failUnexpected;
  30 import static org.testng.Assert.assertFalse;
  31 import static org.testng.Assert.assertNotNull;
  32 import static org.testng.Assert.assertNull;
  33 import static org.testng.Assert.assertTrue;
  34 import org.testng.annotations.Test;
  35 import org.xml.sax.InputSource;
  36 import org.xml.sax.SAXException;
  37 import org.xml.sax.SAXNotRecognizedException;
  38 import org.xml.sax.SAXNotSupportedException;
  39 import org.xml.sax.XMLReader;
  40 import org.xml.sax.ext.DeclHandler;
  41 import org.xml.sax.ext.LexicalHandler;
  42 import org.xml.sax.helpers.XMLFilterImpl;
  43 import static org.xml.sax.ptests.SAXTestConst.XML_DIR;
  44 
  45 /**
  46  * Class containing the test cases for SAXParser API
  47  */
  48 public class XMLReaderTest {
  49     /**
  50      * XML namespaces.
  51      */
  52     private static final String NAMESPACES =
  53                 "http://xml.org/sax/features/namespaces";
  54 
  55     /**
  56      * XML namespaces prefixes.
  57      */
  58     private static final String NAMESPACE_PREFIXES =
  59                 "http://xml.org/sax/features/namespace-prefixes";
  60 
  61     /**
  62      * A string intern name.
  63      */
  64     private static final String STRING_INTERNING =
  65                 "http://xml.org/sax/features/string-interning";
  66 
  67     /**
  68      * Validation name.
  69      */
  70     private static final String VALIDATION =
  71                 "http://xml.org/sax/features/validation";
  72 
  73     /**
  74      * A general external entities name
  75      */
  76     private static final String EXTERNAL_G_ENTITIES =
  77                 "http://xml.org/sax/features/external-general-entities";
  78 
  79     /**
  80      * A external parameter entities name
  81      */
  82     private static final String EXTERNAL_P_ENTITIES =
  83                 "http://xml.org/sax/features/external-parameter-entities";
  84 
  85     /**
  86      * XML DOM node name.
  87      */
  88     private static final String DOM_NODE = "http://xml.org/sax/properties/dom-node";
  89 
  90     /**
  91      * XML String name.
  92      */
  93     private static final String XML_STRING = "http://xml.org/sax/properties/xml-string";
  94 
  95     /**
  96      * Declare handler name
  97      */
  98     private static final String DECL_HANDLER =
  99                         "http://xml.org/sax/properties/declaration-handler";
 100 
 101     /**
 102      * Lexical handler name
 103      */
 104     private static final String LEXICAL_HANDLER =
 105                         "http://xml.org/sax/properties/lexical-handler";
 106 
 107     /**
 108      * According to the SAX2 specs, All XMLReaders are required to recognize the
 109      * http://xml.org/sax/features/namespaces feature names.
 110      * This test case is to test this.
 111      */
 112     @Test
 113     public void featureNS01() {
 114         try {
 115             SAXParserFactory spf = SAXParserFactory.newInstance();
 116             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 117             assertFalse(xmlReader.getFeature(NAMESPACES));
 118         } catch (ParserConfigurationException | SAXException ex) {
 119             failUnexpected(ex);
 120         }
 121     }
 122 
 123     /**
 124      * According to the SAX2 specs, All XMLReaders are required to recognize the
 125      * http://xml.org/sax/features/namespaces feature names.
 126      * This test case is to test this.
 127      */
 128     @Test
 129     public void featureNS02() {
 130         try {
 131             SAXParserFactory spf = SAXParserFactory.newInstance();
 132             spf.setNamespaceAware(true);
 133             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 134             assertTrue(xmlReader.getFeature(NAMESPACES));
 135         } catch (ParserConfigurationException | SAXException ex) {
 136             failUnexpected(ex);
 137         }
 138     }
 139 
 140     /**
 141      * Obtain http://xml.org/sax/features/namespaces feature name after it's
 142      * just set. Expect it's same as set value.
 143      */
 144     @Test
 145     public void featureNS03() {
 146         try {
 147             SAXParserFactory spf = SAXParserFactory.newInstance();
 148             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 149             xmlReader.setFeature(NAMESPACES, true);
 150             assertTrue(xmlReader.getFeature(NAMESPACES));
 151             xmlReader.setFeature(NAMESPACES, false);
 152             assertFalse(xmlReader.getFeature(NAMESPACES));
 153         } catch (ParserConfigurationException | SAXException ex) {
 154             failUnexpected(ex);
 155         }
 156     }
 157 
 158     /**
 159      * According to the SAX2 specs, All XMLReaders are required to recognize the
 160      * http://xml.org/sax/features/namespace-prefixes feature names.
 161      * This test case is to test this.
 162      */
 163     @Test
 164     public void featureNSP01() {
 165         try {
 166             SAXParserFactory spf = SAXParserFactory.newInstance();
 167             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 168             assertTrue(xmlReader.getFeature(NAMESPACE_PREFIXES));
 169 
 170         } catch (ParserConfigurationException | SAXException ex) {
 171             failUnexpected(ex);
 172         }
 173     }
 174 
 175     /**
 176      * According to the SAX2 specs, All XMLReaders are required to recognize the
 177      * http://xml.org/sax/features/namespace-prefixes feature names.
 178      * This test case is to test this.
 179      */
 180     @Test
 181     public void featureNSP02() {
 182         try {
 183             SAXParserFactory spf = SAXParserFactory.newInstance();
 184             spf.setNamespaceAware(true);
 185             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 186             assertFalse(xmlReader.getFeature(NAMESPACE_PREFIXES));
 187         } catch (ParserConfigurationException | SAXException ex) {
 188             failUnexpected(ex);
 189         }
 190     }
 191 
 192     /**
 193      * Obtain http://xml.org/sax/features/namespaces-prefixes feature name after
 194      * it's just set. Expect it's same as set value.
 195      */
 196     @Test
 197     public void featureNSP03() {
 198         try {
 199             SAXParserFactory spf = SAXParserFactory.newInstance();
 200             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 201             xmlReader.setFeature(NAMESPACE_PREFIXES, true);
 202             assertTrue(xmlReader.getFeature(NAMESPACE_PREFIXES));
 203             xmlReader.setFeature(NAMESPACE_PREFIXES, false);
 204             assertFalse(xmlReader.getFeature(NAMESPACE_PREFIXES));
 205         } catch (ParserConfigurationException | SAXException ex) {
 206             failUnexpected(ex);
 207         }
 208     }
 209 
 210     /**
 211      * getFeature returns true if a feature has not been preset when namespace
 212      * awareness is set.
 213      */
 214     @Test
 215     public void featureSI01() {
 216         try {
 217             SAXParserFactory spf = SAXParserFactory.newInstance();
 218             spf.setNamespaceAware(true);
 219             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 220             assertTrue(xmlReader.getFeature(STRING_INTERNING));
 221         } catch (SAXException | ParserConfigurationException ex) {
 222             failUnexpected(ex);
 223         }
 224     }
 225 
 226     /**
 227      * getFeature with validation feature name returns the value that
 228      * setValidation set.
 229      */
 230     @Test
 231     public void featureV01() {
 232         try {
 233             SAXParserFactory spf = SAXParserFactory.newInstance();
 234             assertFalse(spf.newSAXParser().getXMLReader().getFeature(VALIDATION));
 235             spf.setValidating(true);
 236             assertTrue(spf.newSAXParser().getXMLReader().getFeature(VALIDATION));
 237         } catch (SAXException | ParserConfigurationException ex) {
 238             failUnexpected(ex);
 239         }
 240     }
 241 
 242     /**
 243      * getFeature returns the value that a feature has been preset as  when
 244      * namespace awareness is set.
 245      */
 246     @Test
 247     public void featureV02() {
 248         try {
 249             SAXParserFactory spf = SAXParserFactory.newInstance();
 250             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 251 
 252             xmlReader.setFeature(VALIDATION, true);
 253             assertTrue(xmlReader.getFeature(VALIDATION));
 254 
 255             xmlReader.setFeature(VALIDATION, false);
 256             assertFalse(xmlReader.getFeature(VALIDATION));
 257         } catch (SAXException | ParserConfigurationException ex) {
 258             failUnexpected(ex);
 259         }
 260     }
 261 
 262     /**
 263      * getFeature returns true if a feature has not been preset when namespace
 264      * awareness is set.
 265      */
 266     @Test
 267     public void featureEGE01() {
 268         try {
 269             SAXParserFactory spf = SAXParserFactory.newInstance();
 270             spf.setNamespaceAware(true);
 271             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 272             assertTrue(xmlReader.getFeature(EXTERNAL_G_ENTITIES));
 273         } catch (SAXException | ParserConfigurationException ex) {
 274             failUnexpected(ex);
 275         }
 276     }
 277 
 278     /**
 279      * getFeature returns false if a feature has been preset as false  when
 280      * namespace awareness is set.
 281      */
 282     @Test
 283     public void featureEGE02() {
 284         try {
 285             SAXParserFactory spf = SAXParserFactory.newInstance();
 286             spf.setNamespaceAware(true);
 287             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 288             xmlReader.setFeature(EXTERNAL_G_ENTITIES, false);
 289             assertFalse(xmlReader.getFeature(EXTERNAL_G_ENTITIES));
 290         } catch (SAXException | ParserConfigurationException ex) {
 291             failUnexpected(ex);
 292         }
 293     }
 294 
 295     /**
 296      * getFeature returns true if a feature has not been preset when namespace
 297      * awareness is set.
 298      */
 299     @Test
 300     public void featureEPE01() {
 301         try {
 302             SAXParserFactory spf = SAXParserFactory.newInstance();
 303             spf.setNamespaceAware(true);
 304             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 305             assertTrue(xmlReader.getFeature(EXTERNAL_P_ENTITIES));
 306         } catch (SAXException | ParserConfigurationException ex) {
 307             failUnexpected(ex);
 308         }
 309     }
 310 
 311     /**
 312      * getFeature returns false if a feature has been preset as false  when
 313      * namespace awareness is set.
 314      */
 315     @Test
 316     public void featureEPE02() {
 317         try {
 318             SAXParserFactory spf = SAXParserFactory.newInstance();
 319             spf.setNamespaceAware(true);
 320             XMLReader xmlReader = spf.newSAXParser().getXMLReader();
 321             xmlReader.setFeature(EXTERNAL_P_ENTITIES, false);
 322             assertFalse(xmlReader.getFeature(EXTERNAL_P_ENTITIES));
 323         } catch (SAXException | ParserConfigurationException ex) {
 324             failUnexpected(ex);
 325         }
 326     }
 327 
 328     /**
 329      * getFeature with a unknown feature name throws SAXNotRecognizedException.
 330      * @throws SAXNotRecognizedException If the feature value can't be assigned
 331      *                                   or retrieved.
 332      */
 333     @Test(expectedExceptions = SAXNotRecognizedException.class)
 334     public void featureNE01() throws SAXNotRecognizedException  {
 335         try {
 336             SAXParserFactory spf = SAXParserFactory.newInstance();
 337             spf.setNamespaceAware(true);
 338             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 339             boolean noMeaningFeature = xmlReader.getFeature("no-meaning-feature");
 340         } catch(SAXNotRecognizedException ex) {
 341             throw ex;
 342         } catch (SAXException | ParserConfigurationException ex) {
 343             failUnexpected(ex);
 344         }
 345     }
 346 
 347     /**
 348      * No exception expected when set entity resolver as simple entity resolver.
 349      */
 350     @Test
 351     public void entity01() {
 352         try {
 353             SAXParserFactory spf = SAXParserFactory.newInstance();
 354             spf.setNamespaceAware(true);
 355             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 356             XMLFilterImpl xmlFilter = new XMLFilterImpl();
 357             xmlReader.setEntityResolver(xmlFilter);
 358             assertNotNull(xmlReader.getEntityResolver());
 359         } catch (SAXException | ParserConfigurationException ex) {
 360             failUnexpected(ex);
 361         }
 362     }
 363 
 364     /**
 365      * No NPE expected when set entity resolver as null.
 366      */
 367     @Test
 368     public void entity02() {
 369         try {
 370             SAXParserFactory spf = SAXParserFactory.newInstance();
 371             spf.setNamespaceAware(true);
 372             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 373             xmlReader.setEntityResolver(null);
 374         } catch (SAXException | ParserConfigurationException ex) {
 375             failUnexpected(ex);
 376         }
 377     }
 378 
 379     /**
 380      * No exception expected when set DTD handler as simple DTD handler.
 381      */
 382     @Test
 383     public void dtdhandler01() {
 384         try {
 385             SAXParserFactory spf = SAXParserFactory.newInstance();
 386             spf.setNamespaceAware(true);
 387             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 388             XMLFilterImpl xmlFilter = new XMLFilterImpl();
 389             xmlReader.setDTDHandler(xmlFilter);
 390             assertNotNull(xmlReader.getDTDHandler());
 391         } catch (SAXException | ParserConfigurationException ex) {
 392             failUnexpected(ex);
 393         }
 394     }
 395 
 396     /**
 397      * No NPE expected when set DTD handler as null.
 398      */
 399     @Test
 400     public void dtdhandler02() {
 401         try {
 402             SAXParserFactory spf = SAXParserFactory.newInstance();
 403             spf.setNamespaceAware(true);
 404             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 405             xmlReader.setDTDHandler(null);
 406         } catch (SAXException | ParserConfigurationException ex) {
 407             failUnexpected(ex);
 408         }
 409     }
 410 
 411     /**
 412      * No exception expected when set content handler as simple content handler.
 413      */
 414     @Test
 415     public void contenthandler01() {
 416         try {
 417             SAXParserFactory spf = SAXParserFactory.newInstance();
 418             spf.setNamespaceAware(true);
 419             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 420             XMLFilterImpl xmlFilter = new XMLFilterImpl();
 421             xmlReader.setContentHandler(xmlFilter);
 422             assertNotNull(xmlReader.getContentHandler());
 423         } catch (SAXException | ParserConfigurationException ex) {
 424             failUnexpected(ex);
 425         }
 426     }
 427 
 428     /**
 429      * No NPE expected when set content handler as null.
 430      */
 431     @Test
 432     public void contenthandler02() {
 433         try {
 434             SAXParserFactory spf = SAXParserFactory.newInstance();
 435             spf.setNamespaceAware(true);
 436             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 437             xmlReader.setContentHandler(null);
 438         } catch (SAXException | ParserConfigurationException ex) {
 439             failUnexpected(ex);
 440         }
 441     }
 442 
 443     /**
 444      * No exception expected when set content handler as simple error handler.
 445      */
 446     @Test
 447     public void errorhandler01() {
 448         try {
 449             SAXParserFactory spf = SAXParserFactory.newInstance();
 450             spf.setNamespaceAware(true);
 451             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 452             xmlReader.setErrorHandler(new XMLFilterImpl());
 453             assertNotNull(xmlReader.getErrorHandler());
 454         } catch (SAXException | ParserConfigurationException ex) {
 455             failUnexpected(ex);
 456         }
 457     }
 458 
 459     /**
 460      * No NPE expected when set error handler as null.
 461      */
 462     @Test
 463     public void errorhandler02() {
 464         try {
 465             SAXParserFactory spf = SAXParserFactory.newInstance();
 466             spf.setNamespaceAware(true);
 467             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 468             xmlReader.setErrorHandler(null);
 469         } catch (SAXException | ParserConfigurationException ex) {
 470             failUnexpected(ex);
 471         }
 472     }
 473 
 474     /**
 475      * Parse a null input source throw NPE.
 476      */
 477     @Test(expectedExceptions = NullPointerException.class)
 478     public void parse01() {
 479         try {
 480             SAXParserFactory spf = SAXParserFactory.newInstance();
 481             spf.setNamespaceAware(true);
 482             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 483             xmlReader.parse((InputSource)null);
 484         } catch (SAXException | ParserConfigurationException | IOException ex) {
 485             failUnexpected(ex);
 486         }
 487     }
 488 
 489     /**
 490      * Unit test for parse a error-formatted file. SAXException is expected.
 491      * @throws org.xml.sax.SAXException parsing failed.
 492      */
 493     @Test(expectedExceptions = SAXException.class)
 494     public void parse02() throws SAXException {
 495         try (FileInputStream fis = new FileInputStream(XML_DIR + "invalid.xml")){
 496             SAXParserFactory spf = SAXParserFactory.newInstance();
 497             spf.setNamespaceAware(true);
 498             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 499             InputSource is = new InputSource(fis);
 500             xmlReader.parse(is);
 501         } catch (ParserConfigurationException | IOException ex) {
 502             failUnexpected(ex);
 503         }
 504     }
 505 
 506     /**
 507      * Unit test for parse a well-formatted file. No exception is expected.
 508      */
 509     @Test
 510     public void parse03(){
 511         try (FileInputStream fis = new FileInputStream(XML_DIR + "correct2.xml")) {
 512             SAXParserFactory spf = SAXParserFactory.newInstance();
 513             spf.setNamespaceAware(true);
 514             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 515             InputSource is = new InputSource(fis);
 516             xmlReader.parse(is);
 517         } catch (IOException | SAXException | ParserConfigurationException ex) {
 518             failUnexpected(ex);
 519         }
 520     }
 521 
 522     /**
 523      * Modified by IBM
 524      * Xerces does not support this feature and it is not mandatory
 525      * @throws org.xml.sax.SAXNotSupportedException
 526      */
 527     @Test(expectedExceptions = SAXNotSupportedException.class)
 528     public void xrProperty01() throws SAXNotSupportedException  {
 529         try {
 530             SAXParserFactory spf = SAXParserFactory.newInstance();
 531             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 532             xmlReader.getProperty(XML_STRING);
 533         } catch(SAXNotSupportedException ex) {
 534             throw ex;
 535         } catch (SAXException | ParserConfigurationException ex){
 536             failUnexpected(ex);
 537         }
 538     }
 539 
 540     /**
 541      * SAXNotSupportedException thrown if property name is known but no value
 542      * assigned to this property.
 543      * @throws org.xml.sax.SAXNotSupportedException when XMLReader recognizes
 544      * the property name but cannot determine its value at this time.
 545      */
 546     @Test(expectedExceptions = SAXNotSupportedException.class)
 547     public void xrProperty02() throws SAXNotSupportedException {
 548         try {
 549             SAXParserFactory spf = SAXParserFactory.newInstance();
 550             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 551             assertNull(xmlReader.getProperty(DOM_NODE));
 552         } catch (SAXNotSupportedException ex) {
 553             throw ex;
 554         } catch (SAXException | ParserConfigurationException ex){
 555             failUnexpected(ex);
 556         }
 557     }
 558 
 559 
 560     /**
 561      * XMLReader.getProperty returns null if LEXICAL_HANDLER wasn't set.
 562      */
 563     @Test
 564     public void xrProperty03() {
 565         try {
 566             SAXParserFactory spf = SAXParserFactory.newInstance();
 567             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 568             assertNull(xmlReader.getProperty(LEXICAL_HANDLER));
 569         } catch (SAXException | ParserConfigurationException ex){
 570             failUnexpected(ex);
 571         }
 572     }
 573 
 574     /**
 575      * XMLReader.getProperty returns null if DECL_HANDLER wasn't set.
 576      */
 577     @Test
 578     public void xrProperty04() {
 579         try {
 580             SAXParserFactory spf = SAXParserFactory.newInstance();
 581             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 582             assertNull(xmlReader.getProperty(DECL_HANDLER));
 583         } catch (SAXException | ParserConfigurationException ex){
 584             failUnexpected(ex);
 585         }
 586     }
 587 
 588     /**
 589      * XMLReader.setProperty/getProperty for LEXICAL_HANDLER unit test.
 590      */
 591     @Test
 592     public void xrProperty05() {
 593         try {
 594             SAXParserFactory spf = SAXParserFactory.newInstance();
 595             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 596             MyLexicalHandler myLexicalHandler = new MyLexicalHandler();
 597             xmlReader.setProperty(LEXICAL_HANDLER, myLexicalHandler);
 598             assertNotNull(xmlReader.getProperty(LEXICAL_HANDLER));
 599         } catch (SAXException | ParserConfigurationException ex){
 600             failUnexpected(ex);
 601         }
 602     }
 603 
 604     /**
 605      * XMLReader.setProperty/getProperty for DECL_HANDLER unit test.
 606      */
 607     @Test
 608     public void xrProperty06() {
 609         try {
 610             SAXParserFactory spf = SAXParserFactory.newInstance();
 611             XMLReader xmlReader =  spf.newSAXParser().getXMLReader();
 612             MyDeclHandler myDeclHandler = new MyDeclHandler();
 613             xmlReader.setProperty(DECL_HANDLER, myDeclHandler);
 614             assertNotNull(xmlReader.getProperty(DECL_HANDLER));
 615         } catch (ParserConfigurationException | SAXException ex){
 616             failUnexpected(ex);
 617         }
 618     }
 619 }
 620 
 621 /**
 622  * Simple LexicalHandler that skips every lexical event.
 623  */
 624 class MyLexicalHandler implements LexicalHandler {
 625     /**
 626      * Report an XML comment anywhere in the document.
 627      *
 628      * @param ch An array holding the characters in the comment.
 629      * @param start The starting position in the array.
 630      * @param length The number of characters to use from the array.
 631      */
 632     @Override
 633     public void comment(char[] ch, int start, int length) {
 634     }
 635 
 636     /**
 637      * Report the end of a CDATA section.
 638      */
 639     @Override
 640     public void endCDATA() {
 641     }
 642 
 643     /**
 644      * Report the end of DTD declarations.
 645      */
 646     @Override
 647     public void endDTD() {
 648     }
 649 
 650     /**
 651      * Report the end of an entity.
 652      *
 653      * @param name The name of the entity that is ending.
 654      */
 655     @Override
 656     public void endEntity(String name) {
 657     }
 658 
 659     /**
 660      * Report the start of a CDATA section.
 661      */
 662     @Override
 663     public void startCDATA() {
 664     }
 665 
 666     /**
 667      * Report the start of DTD declarations, if any.
 668      *
 669      * @param name The document type name.
 670      * @param publicId The declared public identifier for the external DTD subset.
 671      * @param systemId The declared system identifier for the external DTD subset.
 672      */
 673     @Override
 674     public void startDTD(String name, String publicId, String systemId) {
 675     }
 676 
 677     /**
 678      * Report the beginning of some internal and external XML entities.
 679      *
 680      * @param name The name of the entity.
 681      */
 682     @Override
 683     public void startEntity(String name) {
 684     }
 685 }
 686 
 687 /**
 688  * Simple DeclHandler that skips every DTD declaration event.
 689  */
 690 class MyDeclHandler implements DeclHandler {
 691     /**
 692      * Report an attribute type declaration.
 693      * @param eName The name of the associated element.
 694      * @param aName The name of the attribute.
 695      * @param type A string representing the attribute type.
 696      * @param mode A string representing the attribute defaulting mode
 697      *        ("#IMPLIED", "#REQUIRED", or "#FIXED") or null if
 698      *        none of these applies.
 699      * @param value A string representing the attribute's default value,
 700      *        or null if there is none.
 701      */
 702     @Override
 703     public void attributeDecl(String eName, String aName, String type,
 704             String valueDefault, String value) {
 705     }
 706 
 707     /**
 708      * Report an element type declaration.
 709      * @param name The element type name.
 710      * @param model The content model as a normalized string.
 711      */
 712     @Override
 713     public void elementDecl(String name, String model) {
 714     }
 715 
 716     /**
 717      * Report a parsed external entity declaration.
 718      * @param name The name of the entity.  If it is a parameter
 719      *        entity, the name will begin with '%'.
 720      * @param publicId The entity's public identifier, or null if none
 721      *        was given.
 722      * @param systemId The entity's system identifier.
 723      */
 724     @Override
 725     public void externalEntityDecl(String name, String publicId,
 726             String systemId) {
 727     }
 728 
 729     /**
 730      * Report an internal entity declaration.
 731      * @param name The name of the entity.  If it is a parameter
 732      *        entity, the name will begin with '%'.
 733      * @param value The replacement text of the entity.
 734      */
 735     @Override
 736     public void internalEntityDecl(String name, String value) {
 737     }
 738 }