Fields Summary |
---|
protected static final String | NAMESPACES_FEATURE_IDNamespaces feature id (http://xml.org/sax/features/namespaces). |
protected static final String | VALIDATION_FEATURE_IDValidation feature id (http://xml.org/sax/features/validation). |
protected static final String | SCHEMA_VALIDATION_FEATURE_IDSchema validation feature id (http://apache.org/xml/features/validation/schema). |
protected static final String | SCHEMA_FULL_CHECKING_FEATURE_IDSchema full checking feature id (http://apache.org/xml/features/validation/schema-full-checking). |
protected static final String | DEFAULT_PARSER_NAMEDefault parser name. |
protected static final boolean | DEFAULT_NAMESPACESDefault namespaces support (true). |
protected static final boolean | DEFAULT_VALIDATIONDefault validation support (false). |
protected static final boolean | DEFAULT_SCHEMA_VALIDATIONDefault Schema validation support (false). |
protected static final boolean | DEFAULT_SCHEMA_FULL_CHECKINGDefault Schema full checking support (false). |
protected PrintWriter | fOutPrint writer. |
Methods Summary |
---|
public void | endElement(java.lang.String uri, java.lang.String localpart, java.lang.String rawname)End element.
System.out.println(")"+rawname);
|
public void | error(org.xml.sax.SAXParseException ex)Error.
printError("Error", ex);
|
public void | fatalError(org.xml.sax.SAXParseException ex)Fatal error.
printError("Fatal Error", ex);
throw ex;
|
public static void | main(java.lang.String[] argv)Main program entry point.
// is there anything to do?
if (argv.length == 0) {
printUsage();
System.exit(1);
}
// variables
DefaultHandler handler = new DelayedInput();
XMLReader parser = null;
boolean namespaces = DEFAULT_NAMESPACES;
boolean validation = DEFAULT_VALIDATION;
boolean schemaValidation = DEFAULT_SCHEMA_VALIDATION;
boolean schemaFullChecking = DEFAULT_SCHEMA_FULL_CHECKING;
// process arguments
for (int i = 0; i < argv.length; i++) {
String arg = argv[i];
if (arg.startsWith("-")) {
String option = arg.substring(1);
if (option.equals("p")) {
// get parser name
if (++i == argv.length) {
System.err.println("error: Missing argument to -p option.");
}
String parserName = argv[i];
// create parser
try {
parser = XMLReaderFactory.createXMLReader(parserName);
}
catch (Exception e) {
try {
Parser sax1Parser = ParserFactory.makeParser(parserName);
parser = new ParserAdapter(sax1Parser);
System.err.println("warning: Features and properties not supported on SAX1 parsers.");
}
catch (Exception ex) {
parser = null;
System.err.println("error: Unable to instantiate parser ("+DEFAULT_PARSER_NAME+")");
}
}
continue;
}
if (option.equalsIgnoreCase("n")) {
namespaces = option.equals("n");
continue;
}
if (option.equalsIgnoreCase("v")) {
validation = option.equals("v");
continue;
}
if (option.equalsIgnoreCase("s")) {
schemaValidation = option.equals("s");
continue;
}
if (option.equalsIgnoreCase("f")) {
schemaFullChecking = option.equals("f");
continue;
}
if (option.equals("h")) {
printUsage();
continue;
}
}
// use default parser?
if (parser == null) {
// create parser
try {
parser = XMLReaderFactory.createXMLReader(DEFAULT_PARSER_NAME);
}
catch (Exception e) {
System.err.println("error: Unable to instantiate parser ("+DEFAULT_PARSER_NAME+")");
continue;
}
}
// set parser features
try {
parser.setFeature(NAMESPACES_FEATURE_ID, namespaces);
}
catch (SAXException e) {
System.err.println("warning: Parser does not support feature ("+NAMESPACES_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(SCHEMA_VALIDATION_FEATURE_ID, schemaValidation);
}
catch (SAXException e) {
System.err.println("warning: Parser does not support feature ("+SCHEMA_VALIDATION_FEATURE_ID+")");
}
try {
parser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, schemaFullChecking);
}
catch (SAXException e) {
System.err.println("warning: Parser does not support feature ("+SCHEMA_FULL_CHECKING_FEATURE_ID+")");
}
// parse file
parser.setContentHandler(handler);
parser.setErrorHandler(handler);
try {
System.out.println("# filename: "+arg);
InputStream stream = new DelayedInputStream(new FileInputStream(arg));
InputSource source = new InputSource(stream);
source.setSystemId(arg);
parser.parse(source);
}
catch (SAXParseException e) {
// ignore
}
catch (Exception e) {
System.err.println("error: Parse error occurred - "+e.getMessage());
if (e instanceof SAXException) {
e = ((SAXException)e).getException();
}
e.printStackTrace(System.err);
}
}
|
protected void | printError(java.lang.String type, org.xml.sax.SAXParseException ex)Prints the error message.
System.err.print("[");
System.err.print(type);
System.err.print("] ");
String systemId = ex.getSystemId();
if (systemId != null) {
int index = systemId.lastIndexOf('/");
if (index != -1)
systemId = systemId.substring(index + 1);
System.err.print(systemId);
}
System.err.print(':");
System.err.print(ex.getLineNumber());
System.err.print(':");
System.err.print(ex.getColumnNumber());
System.err.print(": ");
System.err.print(ex.getMessage());
System.err.println();
System.err.flush();
|
private static void | printUsage()Prints the usage.
System.err.println("usage: java socket.DelayedInput (options) filename ...");
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();
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(" Validation: ");
System.err.println(DEFAULT_VALIDATION ? "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");
|
public void | startElement(java.lang.String uri, java.lang.String localpart, java.lang.String rawname, org.xml.sax.Attributes attrs)Start element.
System.out.println("("+rawname);
int length = attrs != null ? attrs.getLength() : 0;
for (int i = 0; i < length; i++) {
System.out.println("A"+attrs.getQName(i)+' "+attrs.getValue(i));
}
|
public void | warning(org.xml.sax.SAXParseException ex)Warning.
printError("Warning", ex);
|