21 * questions. 22 */ 23 24 package stream.XMLStreamReaderTest; 25 26 import java.io.File; 27 import java.io.FileInputStream; 28 import java.io.StringReader; 29 import java.util.List; 30 31 import javax.xml.stream.XMLEventReader; 32 import javax.xml.stream.XMLInputFactory; 33 import javax.xml.stream.XMLStreamConstants; 34 import javax.xml.stream.events.Characters; 35 import javax.xml.stream.events.DTD; 36 import javax.xml.stream.events.EntityDeclaration; 37 import javax.xml.stream.events.EntityReference; 38 import javax.xml.stream.events.XMLEvent; 39 40 import org.testng.Assert; 41 import org.testng.annotations.Test; 42 43 /* 44 * @summary Test SUPPORT_DTD and IS_REPLACING_ENTITY_REFERENCES. 45 */ 46 47 /** 48 * 49 * SUPPORT_DTD behavior: 50 * Regardless of supportDTD, always report a DTD event () and throw an 51 * exception if an entity reference is found when supportDTD is false 52 * 53 * The behavior is related to property IS_REPLACING_ENTITY_REFERENCES. 54 * 55 * SUPPORT_DTD Replace Entity DTD ENTITY_REFERENCE 56 * true (default) true (default) yes, has entities no, return Characters 57 * true (default) false yes, has entities yes, can print entity name 58 * false true (default) yes, but no entity Exception: Undeclared general entity 59 * false false yes, but no entity yes, can print entity name 60 * 61 * Two patches related: 62 * sjsxp issue 9: XMLDocumentScannerImpl.java rev 1.6 63 * If the supportDTD property is set to FALSE, external and internal subsets 64 * are now ignored, rather than an error being reported. In particular, with 65 * this property set to FALSE, no error is reported if an external subset cannot 66 * be found. Note that the internal subset is still parsed (and errors could be 67 * reported here) but no events are returned by the parser. This fixes SJSXP 68 * issue 9 from Java.net. 69 * Note: SAX and DOM report fatal errors: 70 * If either SAX or DOM is used, turning on http://apache.org/xml/features/disallow-doctype-decl [1] effectively disables DTD, 71 * according to the spec: A fatal error is thrown if the incoming document contains a DOCTYPE declaration. 72 * The current jaxp implementation actually throws a nullpointexception. A better error message could be used. 73 * 74 */ 75 public class SupportDTDTest { 76 final boolean DEBUG = false; 77 final String _file = "ExternalDTD.xml"; 78 final String XML = "<?xml version='1.0' ?>" + "<!DOCTYPE root [\n" + "<!ENTITY intEnt 'internal entity'>\n" + "<!ENTITY extParsedEnt SYSTEM 'url:dummy'>\n" 79 + "<!NOTATION notation PUBLIC 'notation-public-id'>\n" + "<!NOTATION notation2 SYSTEM 'url:dummy'>\n" 80 + "<!ENTITY extUnparsedEnt SYSTEM 'url:dummy2' NDATA notation>\n" + "]>" + "<root>&intEnt;</root>"; 81 82 final String XML1 = "<?xml version='1.0' encoding ='utf-8'?>" + "<!DOCTYPE document SYSTEM \"" + this.getClass().getResource("ExternalDTD.dtd").getFile() 83 + "\">" + "<document>" + "<name>&mkm;</name>" + "</document>"; 84 85 // final String XML1 = "<?xml version='1.0' encoding ='utf-8'?>" + "<!DOCTYPE document SYSTEM \"/home/oracle/repo/xmlwork/dev/jdk/test/javax/xml/jaxp/unittest/javax/xml/stream/XMLStreamReaderTest/ExternalDTD.dtd\">" + "<document>" 86 // + "<name>&mkm;</name>" + "</document>"; 87 88 final int ENTITY_INTERNAL_ONLY = 1; 89 final int ENTITY_EXTERNAL_ONLY = 2; 90 final int ENTITY_BOTH = 3; 91 92 boolean _DTDReturned = false; 93 boolean _EntityEventReturned = false; 94 boolean _hasEntityDelaration = false; | 21 * questions. 22 */ 23 24 package stream.XMLStreamReaderTest; 25 26 import java.io.File; 27 import java.io.FileInputStream; 28 import java.io.StringReader; 29 import java.util.List; 30 31 import javax.xml.stream.XMLEventReader; 32 import javax.xml.stream.XMLInputFactory; 33 import javax.xml.stream.XMLStreamConstants; 34 import javax.xml.stream.events.Characters; 35 import javax.xml.stream.events.DTD; 36 import javax.xml.stream.events.EntityDeclaration; 37 import javax.xml.stream.events.EntityReference; 38 import javax.xml.stream.events.XMLEvent; 39 40 import org.testng.Assert; 41 import org.testng.annotations.Listeners; 42 import org.testng.annotations.Test; 43 44 /* 45 * @summary Test SUPPORT_DTD and IS_REPLACING_ENTITY_REFERENCES. 46 */ 47 48 /** 49 * 50 * SUPPORT_DTD behavior: 51 * Regardless of supportDTD, always report a DTD event () and throw an 52 * exception if an entity reference is found when supportDTD is false 53 * 54 * The behavior is related to property IS_REPLACING_ENTITY_REFERENCES. 55 * 56 * SUPPORT_DTD Replace Entity DTD ENTITY_REFERENCE 57 * true (default) true (default) yes, has entities no, return Characters 58 * true (default) false yes, has entities yes, can print entity name 59 * false true (default) yes, but no entity Exception: Undeclared general entity 60 * false false yes, but no entity yes, can print entity name 61 * 62 * Two patches related: 63 * sjsxp issue 9: XMLDocumentScannerImpl.java rev 1.6 64 * If the supportDTD property is set to FALSE, external and internal subsets 65 * are now ignored, rather than an error being reported. In particular, with 66 * this property set to FALSE, no error is reported if an external subset cannot 67 * be found. Note that the internal subset is still parsed (and errors could be 68 * reported here) but no events are returned by the parser. This fixes SJSXP 69 * issue 9 from Java.net. 70 * Note: SAX and DOM report fatal errors: 71 * If either SAX or DOM is used, turning on http://apache.org/xml/features/disallow-doctype-decl [1] effectively disables DTD, 72 * according to the spec: A fatal error is thrown if the incoming document contains a DOCTYPE declaration. 73 * The current jaxp implementation actually throws a nullpointexception. A better error message could be used. 74 * 75 */ 76 @Listeners({jaxp.library.FilePolicy.class}) 77 public class SupportDTDTest { 78 final boolean DEBUG = false; 79 final String _file = "ExternalDTD.xml"; 80 final String XML = "<?xml version='1.0' ?>" + "<!DOCTYPE root [\n" + "<!ENTITY intEnt 'internal entity'>\n" + "<!ENTITY extParsedEnt SYSTEM 'url:dummy'>\n" 81 + "<!NOTATION notation PUBLIC 'notation-public-id'>\n" + "<!NOTATION notation2 SYSTEM 'url:dummy'>\n" 82 + "<!ENTITY extUnparsedEnt SYSTEM 'url:dummy2' NDATA notation>\n" + "]>" + "<root>&intEnt;</root>"; 83 84 final String XML1 = "<?xml version='1.0' encoding ='utf-8'?>" + "<!DOCTYPE document SYSTEM \"" + this.getClass().getResource("ExternalDTD.dtd").getFile() 85 + "\">" + "<document>" + "<name>&mkm;</name>" + "</document>"; 86 87 // final String XML1 = "<?xml version='1.0' encoding ='utf-8'?>" + "<!DOCTYPE document SYSTEM \"/home/oracle/repo/xmlwork/dev/jdk/test/javax/xml/jaxp/unittest/javax/xml/stream/XMLStreamReaderTest/ExternalDTD.dtd\">" + "<document>" 88 // + "<name>&mkm;</name>" + "</document>"; 89 90 final int ENTITY_INTERNAL_ONLY = 1; 91 final int ENTITY_EXTERNAL_ONLY = 2; 92 final int ENTITY_BOTH = 3; 93 94 boolean _DTDReturned = false; 95 boolean _EntityEventReturned = false; 96 boolean _hasEntityDelaration = false; |