mrglavas 2003/11/29 08:19:24
Modified: java/samples/sax Counter.java DocumentTracer.java
Writer.java
Log:
Add namespace-prefixes, load external DTD and dynamic
validation options to SAX samples.
Revision Changes Path
1.11 +2 -2 xml-xerces/java/samples/sax/Counter.java
Index: Counter.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/samples/sax/Counter.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Counter.java 24 Mar 2003 21:56:14 -0000 1.10
+++ Counter.java 29 Nov 2003 16:19:24 -0000 1.11
@@ -595,7 +595,7 @@
System.err.println(" -f | -F Turn on/off Schema full checking.");
System.err.println(" NOTE: Requires use of -s and not
supported by all parsers.");
System.err.println(" -dv | -DV Turn on/off dynamic validation.");
- System.err.println(" NOTE: Requires use of -v and not
supported by all parsers.");
+ System.err.println(" NOTE: Not supported by all parsers.");
System.err.println(" -m | -M Turn on/off memory usage report");
System.err.println(" -t | -T Turn on/off \"tagginess\" report.");
System.err.println(" --rem text Output user defined comment before next
parse.");
1.10 +80 -11 xml-xerces/java/samples/sax/DocumentTracer.java
Index: DocumentTracer.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/samples/sax/DocumentTracer.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- DocumentTracer.java 23 Sep 2003 17:47:52 -0000 1.9
+++ DocumentTracer.java 29 Nov 2003 16:19:24 -0000 1.10
@@ -108,6 +108,9 @@
/** Namespaces feature id (http://xml.org/sax/features/namespaces). */
protected static final String NAMESPACES_FEATURE_ID =
"http://xml.org/sax/features/namespaces";
+
+ /** Namespace prefixes feature id
(http://xml.org/sax/features/namespace-prefixes). */
+ protected static final String NAMESPACE_PREFIXES_FEATURE_ID =
"http://xml.org/sax/features/namespace-prefixes";
/** Validation feature id (http://xml.org/sax/features/validation). */
protected static final String VALIDATION_FEATURE_ID =
"http://xml.org/sax/features/validation";
@@ -117,6 +120,12 @@
/** Schema full checking feature id
(http://apache.org/xml/features/validation/schema-full-checking). */
protected static final String SCHEMA_FULL_CHECKING_FEATURE_ID =
"http://apache.org/xml/features/validation/schema-full-checking";
+
+ /** Dynamic validation feature id
(http://apache.org/xml/features/validation/dynamic). */
+ protected static final String DYNAMIC_VALIDATION_FEATURE_ID =
"http://apache.org/xml/features/validation/dynamic";
+
+ /** Load external DTD feature id
(http://apache.org/xml/features/nonvalidating/load-external-dtd). */
+ protected static final String LOAD_EXTERNAL_DTD_FEATURE_ID =
"http://apache.org/xml/features/nonvalidating/load-external-dtd";
// property ids
@@ -130,15 +139,24 @@
/** Default namespaces support (true). */
protected static final boolean DEFAULT_NAMESPACES = true;
+
+ /** Default namespace prefixes (false). */
+ protected static final boolean DEFAULT_NAMESPACE_PREFIXES = false;
/** Default validation support (false). */
protected static final boolean DEFAULT_VALIDATION = false;
+
+ /** Default load external DTD (true). */
+ protected static final boolean DEFAULT_LOAD_EXTERNAL_DTD = true;
/** Default Schema validation support (false). */
protected static final boolean DEFAULT_SCHEMA_VALIDATION = false;
/** Default Schema full checking support (false). */
protected static final boolean DEFAULT_SCHEMA_FULL_CHECKING = false;
+
+ /** Default dynamic validation support (false). */
+ protected static final boolean DEFAULT_DYNAMIC_VALIDATION = false;
//
// Data
@@ -794,9 +812,12 @@
PrintWriter out = new PrintWriter(System.out);
XMLReader parser = null;
boolean namespaces = DEFAULT_NAMESPACES;
+ boolean namespacePrefixes = DEFAULT_NAMESPACE_PREFIXES;
boolean validation = DEFAULT_VALIDATION;
+ boolean externalDTD = DEFAULT_LOAD_EXTERNAL_DTD;
boolean schemaValidation = DEFAULT_SCHEMA_VALIDATION;
boolean schemaFullChecking = DEFAULT_SCHEMA_FULL_CHECKING;
+ boolean dynamicValidation = DEFAULT_DYNAMIC_VALIDATION;
// process arguments
for (int i = 0; i < argv.length; i++) {
@@ -831,10 +852,18 @@
namespaces = option.equals("n");
continue;
}
+ if (option.equalsIgnoreCase("np")) {
+ namespacePrefixes = option.equals("np");
+ continue;
+ }
if (option.equalsIgnoreCase("v")) {
validation = option.equals("v");
continue;
}
+ if (option.equalsIgnoreCase("xd")) {
+ externalDTD = option.equals("xd");
+ continue;
+ }
if (option.equalsIgnoreCase("s")) {
schemaValidation = option.equals("s");
continue;
@@ -843,6 +872,10 @@
schemaFullChecking = option.equals("f");
continue;
}
+ if (option.equalsIgnoreCase("dv")) {
+ dynamicValidation = option.equals("dv");
+ continue;
+ }
if (option.equals("h")) {
printUsage();
continue;
@@ -870,16 +903,31 @@
System.err.println("warning: Parser does not support feature
("+NAMESPACES_FEATURE_ID+")");
}
try {
+ parser.setFeature(NAMESPACE_PREFIXES_FEATURE_ID, namespacePrefixes);
+ }
+ catch (SAXException e) {
+ System.err.println("warning: Parser does not support feature
("+NAMESPACE_PREFIXES_FEATURE_ID+")");
+ }
+ try {
parser.setFeature(VALIDATION_FEATURE_ID, validation);
}
catch (SAXException e) {
System.err.println("warning: Parser does not support feature
("+VALIDATION_FEATURE_ID+")");
}
try {
+ parser.setFeature(LOAD_EXTERNAL_DTD_FEATURE_ID, externalDTD);
+ }
+ catch (SAXNotRecognizedException e) {
+ System.err.println("warning: Parser does not recognize feature
("+LOAD_EXTERNAL_DTD_FEATURE_ID+")");
+ }
+ catch (SAXNotSupportedException e) {
+ System.err.println("warning: Parser does not support feature
("+LOAD_EXTERNAL_DTD_FEATURE_ID+")");
+ }
+ try {
parser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, schemaValidation);
}
catch (SAXNotRecognizedException e) {
- // ignore
+ System.err.println("warning: Parser does not recognize feature
("+SCHEMA_VALIDATION_FEATURE_ID+")");
}
catch (SAXNotSupportedException e) {
System.err.println("warning: Parser does not support feature
("+SCHEMA_VALIDATION_FEATURE_ID+")");
@@ -888,11 +936,20 @@
parser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID,
schemaFullChecking);
}
catch (SAXNotRecognizedException e) {
- // ignore
+ System.err.println("warning: Parser does not recognize feature
("+SCHEMA_FULL_CHECKING_FEATURE_ID+")");
}
catch (SAXNotSupportedException e) {
System.err.println("warning: Parser does not support feature
("+SCHEMA_FULL_CHECKING_FEATURE_ID+")");
}
+ try {
+ parser.setFeature(DYNAMIC_VALIDATION_FEATURE_ID, dynamicValidation);
+ }
+ catch (SAXNotRecognizedException e) {
+ System.err.println("warning: Parser does not recognize feature
("+DYNAMIC_VALIDATION_FEATURE_ID+")");
+ }
+ catch (SAXNotSupportedException e) {
+ System.err.println("warning: Parser does not support feature
("+DYNAMIC_VALIDATION_FEATURE_ID+")");
+ }
// set handlers
parser.setDTDHandler(tracer);
@@ -948,26 +1005,38 @@
System.err.println();
System.err.println("options:");
- System.err.println(" -p name Select parser by name.");
- System.err.println(" -n | -N Turn on/off namespace processing.");
- System.err.println(" -v | -V Turn on/off validation.");
- System.err.println(" -s | -S Turn on/off Schema validation support.");
- System.err.println(" NOTE: Not supported by all parsers.");
- System.err.println(" -f | -F Turn on/off Schema full checking.");
- System.err.println(" NOTE: Requires use of -s and not supported
by all parsers.");
- System.err.println(" -h This help screen.");
+ System.err.println(" -p name Select parser by name.");
+ System.err.println(" -n | -N Turn on/off namespace processing.");
+ System.err.println(" -np | -NP Turn on/off namespace prefixes.");
+ System.err.println(" NOTE: Requires use of -n.");
+ System.err.println(" -v | -V Turn on/off validation.");
+ System.err.println(" -xd | -XD Turn on/off loading of external DTDs.");
+ System.err.println(" NOTE: Always on when -v in use and not
supported by all parsers.");
+ System.err.println(" -s | -S Turn on/off Schema validation support.");
+ System.err.println(" NOTE: Not supported by all parsers.");
+ System.err.println(" -f | -F Turn on/off Schema full checking.");
+ System.err.println(" NOTE: Requires use of -s and not
supported by all parsers.");
+ System.err.println(" -dv | -DV Turn on/off dynamic validation.");
+ System.err.println(" NOTE: Not supported by all parsers.");
+ System.err.println(" -h This help screen.");
System.err.println();
System.err.println("defaults:");
System.err.println(" Parser: "+DEFAULT_PARSER_NAME);
System.err.print(" Namespaces: ");
System.err.println(DEFAULT_NAMESPACES ? "on" : "off");
+ System.err.print(" Prefixes: ");
+ System.err.println(DEFAULT_NAMESPACE_PREFIXES ? "on" : "off");
System.err.print(" Validation: ");
System.err.println(DEFAULT_VALIDATION ? "on" : "off");
+ System.err.print(" Load External DTD: ");
+ System.err.println(DEFAULT_LOAD_EXTERNAL_DTD ? "on" : "off");
System.err.print(" Schema: ");
System.err.println(DEFAULT_SCHEMA_VALIDATION ? "on" : "off");
System.err.print(" Schema full checking: ");
System.err.println(DEFAULT_SCHEMA_FULL_CHECKING ? "on" : "off");
+ System.err.print(" Dynamic: ");
+ System.err.println(DEFAULT_DYNAMIC_VALIDATION ? "on" : "off");
} // printUsage()
1.10 +83 -14 xml-xerces/java/samples/sax/Writer.java
Index: Writer.java
===================================================================
RCS file: /home/cvs/xml-xerces/java/samples/sax/Writer.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- Writer.java 23 Sep 2003 17:47:52 -0000 1.9
+++ Writer.java 29 Nov 2003 16:19:24 -0000 1.10
@@ -102,6 +102,9 @@
/** Namespaces feature id (http://xml.org/sax/features/namespaces). */
protected static final String NAMESPACES_FEATURE_ID =
"http://xml.org/sax/features/namespaces";
+ /** Namespace prefixes feature id
(http://xml.org/sax/features/namespace-prefixes). */
+ protected static final String NAMESPACE_PREFIXES_FEATURE_ID =
"http://xml.org/sax/features/namespace-prefixes";
+
/** Validation feature id (http://xml.org/sax/features/validation). */
protected static final String VALIDATION_FEATURE_ID =
"http://xml.org/sax/features/validation";
@@ -111,6 +114,12 @@
/** Schema full checking feature id
(http://apache.org/xml/features/validation/schema-full-checking). */
protected static final String SCHEMA_FULL_CHECKING_FEATURE_ID =
"http://apache.org/xml/features/validation/schema-full-checking";
+ /** Dynamic validation feature id
(http://apache.org/xml/features/validation/dynamic). */
+ protected static final String DYNAMIC_VALIDATION_FEATURE_ID =
"http://apache.org/xml/features/validation/dynamic";
+
+ /** Load external DTD feature id
(http://apache.org/xml/features/nonvalidating/load-external-dtd). */
+ protected static final String LOAD_EXTERNAL_DTD_FEATURE_ID =
"http://apache.org/xml/features/nonvalidating/load-external-dtd";
+
// property ids
/** Lexical handler property id
(http://xml.org/sax/properties/lexical-handler). */
@@ -123,15 +132,24 @@
/** Default namespaces support (true). */
protected static final boolean DEFAULT_NAMESPACES = true;
+
+ /** Default namespace prefixes (false). */
+ protected static final boolean DEFAULT_NAMESPACE_PREFIXES = false;
/** Default validation support (false). */
protected static final boolean DEFAULT_VALIDATION = false;
+
+ /** Default load external DTD (true). */
+ protected static final boolean DEFAULT_LOAD_EXTERNAL_DTD = true;
/** Default Schema validation support (false). */
protected static final boolean DEFAULT_SCHEMA_VALIDATION = false;
/** Default Schema full checking support (false). */
protected static final boolean DEFAULT_SCHEMA_FULL_CHECKING = false;
+
+ /** Default dynamic validation support (false). */
+ protected static final boolean DEFAULT_DYNAMIC_VALIDATION = false;
/** Default canonical output (false). */
protected static final boolean DEFAULT_CANONICAL = false;
@@ -554,9 +572,12 @@
Writer writer = null;
XMLReader parser = null;
boolean namespaces = DEFAULT_NAMESPACES;
+ boolean namespacePrefixes = DEFAULT_NAMESPACE_PREFIXES;
boolean validation = DEFAULT_VALIDATION;
+ boolean externalDTD = DEFAULT_LOAD_EXTERNAL_DTD;
boolean schemaValidation = DEFAULT_SCHEMA_VALIDATION;
boolean schemaFullChecking = DEFAULT_SCHEMA_FULL_CHECKING;
+ boolean dynamicValidation = DEFAULT_DYNAMIC_VALIDATION;
boolean canonical = DEFAULT_CANONICAL;
// process arguments
@@ -593,10 +614,18 @@
namespaces = option.equals("n");
continue;
}
+ if (option.equalsIgnoreCase("np")) {
+ namespacePrefixes = option.equals("np");
+ continue;
+ }
if (option.equalsIgnoreCase("v")) {
validation = option.equals("v");
continue;
}
+ if (option.equalsIgnoreCase("xd")) {
+ externalDTD = option.equals("xd");
+ continue;
+ }
if (option.equalsIgnoreCase("s")) {
schemaValidation = option.equals("s");
continue;
@@ -605,6 +634,10 @@
schemaFullChecking = option.equals("f");
continue;
}
+ if (option.equalsIgnoreCase("dv")) {
+ dynamicValidation = option.equals("dv");
+ continue;
+ }
if (option.equalsIgnoreCase("c")) {
canonical = option.equals("c");
continue;
@@ -637,16 +670,31 @@
System.err.println("warning: Parser does not support feature
("+NAMESPACES_FEATURE_ID+")");
}
try {
+ parser.setFeature(NAMESPACE_PREFIXES_FEATURE_ID, namespacePrefixes);
+ }
+ catch (SAXException e) {
+ System.err.println("warning: Parser does not support feature
("+NAMESPACE_PREFIXES_FEATURE_ID+")");
+ }
+ try {
parser.setFeature(VALIDATION_FEATURE_ID, validation);
}
catch (SAXException e) {
System.err.println("warning: Parser does not support feature
("+VALIDATION_FEATURE_ID+")");
}
try {
+ parser.setFeature(LOAD_EXTERNAL_DTD_FEATURE_ID, externalDTD);
+ }
+ catch (SAXNotRecognizedException e) {
+ System.err.println("warning: Parser does not recognize feature
("+LOAD_EXTERNAL_DTD_FEATURE_ID+")");
+ }
+ catch (SAXNotSupportedException e) {
+ System.err.println("warning: Parser does not support feature
("+LOAD_EXTERNAL_DTD_FEATURE_ID+")");
+ }
+ try {
parser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, schemaValidation);
}
catch (SAXNotRecognizedException e) {
- // ignore
+ System.err.println("warning: Parser does not recognize feature
("+SCHEMA_VALIDATION_FEATURE_ID+")");
}
catch (SAXNotSupportedException e) {
System.err.println("warning: Parser does not support feature
("+SCHEMA_VALIDATION_FEATURE_ID+")");
@@ -655,12 +703,21 @@
parser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID,
schemaFullChecking);
}
catch (SAXNotRecognizedException e) {
- // ignore
+ System.err.println("warning: Parser does not recognize feature
("+SCHEMA_FULL_CHECKING_FEATURE_ID+")");
}
catch (SAXNotSupportedException e) {
System.err.println("warning: Parser does not support feature
("+SCHEMA_FULL_CHECKING_FEATURE_ID+")");
}
-
+ try {
+ parser.setFeature(DYNAMIC_VALIDATION_FEATURE_ID, dynamicValidation);
+ }
+ catch (SAXNotRecognizedException e) {
+ System.err.println("warning: Parser does not recognize feature
("+DYNAMIC_VALIDATION_FEATURE_ID+")");
+ }
+ catch (SAXNotSupportedException e) {
+ System.err.println("warning: Parser does not support feature
("+DYNAMIC_VALIDATION_FEATURE_ID+")");
+ }
+
// setup writer
if (writer == null) {
writer = new Writer();
@@ -716,28 +773,40 @@
System.err.println();
System.err.println("options:");
- System.err.println(" -p name Select parser by name.");
- System.err.println(" -n | -N Turn on/off namespace processing.");
- System.err.println(" -v | -V Turn on/off validation.");
- System.err.println(" -s | -S Turn on/off Schema validation support.");
- System.err.println(" NOTE: Not supported by all parsers.");
- System.err.println(" -f | -F Turn on/off Schema full checking.");
- System.err.println(" NOTE: Requires use of -s and not supported
by all parsers.");
- System.err.println(" -c | -C Turn on/off Canonical XML output.");
- System.err.println(" NOTE: This is not W3C canonical output.");
- System.err.println(" -h This help screen.");
+ System.err.println(" -p name Select parser by name.");
+ System.err.println(" -n | -N Turn on/off namespace processing.");
+ System.err.println(" -np | -NP Turn on/off namespace prefixes.");
+ System.err.println(" NOTE: Requires use of -n.");
+ System.err.println(" -v | -V Turn on/off validation.");
+ System.err.println(" -xd | -XD Turn on/off loading of external DTDs.");
+ System.err.println(" NOTE: Always on when -v in use and not
supported by all parsers.");
+ System.err.println(" -s | -S Turn on/off Schema validation support.");
+ System.err.println(" NOTE: Not supported by all parsers.");
+ System.err.println(" -f | -F Turn on/off Schema full checking.");
+ System.err.println(" NOTE: Requires use of -s and not
supported by all parsers.");
+ System.err.println(" -dv | -DV Turn on/off dynamic validation.");
+ System.err.println(" NOTE: Not supported by all parsers.");
+ System.err.println(" -c | -C Turn on/off Canonical XML output.");
+ System.err.println(" NOTE: This is not W3C canonical output.");
+ System.err.println(" -h This help screen.");
System.err.println();
System.err.println("defaults:");
System.err.println(" Parser: "+DEFAULT_PARSER_NAME);
System.err.print(" Namespaces: ");
System.err.println(DEFAULT_NAMESPACES ? "on" : "off");
+ System.err.print(" Prefixes: ");
+ System.err.println(DEFAULT_NAMESPACE_PREFIXES ? "on" : "off");
System.err.print(" Validation: ");
System.err.println(DEFAULT_VALIDATION ? "on" : "off");
+ System.err.print(" Load External DTD: ");
+ System.err.println(DEFAULT_LOAD_EXTERNAL_DTD ? "on" : "off");
System.err.print(" Schema: ");
System.err.println(DEFAULT_SCHEMA_VALIDATION ? "on" : "off");
System.err.print(" Schema full checking: ");
System.err.println(DEFAULT_SCHEMA_FULL_CHECKING ? "on" : "off");
+ System.err.print(" Dynamic: ");
+ System.err.println(DEFAULT_DYNAMIC_VALIDATION ? "on" : "off");
System.err.print(" Canonical: ");
System.err.println(DEFAULT_CANONICAL ? "on" : "off");
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]