X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=unused%2Fxml%2Fsax%2Fdemo%2FCharacterStreamDemo.java;fp=unused%2Fxml%2Fsax%2Fdemo%2FCharacterStreamDemo.java;h=8d97f0fbe9a2e8feb21d686150f266007cd596b3;hb=ec8f3cedf60fb1feed6d34de6b49f6bfa78b9dd8;hp=0000000000000000000000000000000000000000;hpb=056dad85a910551cc95e44d451a61f6b8c4dd35d;p=jalview.git diff --git a/unused/xml/sax/demo/CharacterStreamDemo.java b/unused/xml/sax/demo/CharacterStreamDemo.java new file mode 100644 index 0000000..8d97f0f --- /dev/null +++ b/unused/xml/sax/demo/CharacterStreamDemo.java @@ -0,0 +1,88 @@ +package org.xml.sax.demo; +// SAX demonstration for parsing from a UTF-16 character stream. +// No warranty; no copyright -- use this as you will. +// $Id: CharacterStreamDemo.java,v 1.3 1998/05/01 20:44:33 david Exp $ + +import org.xml.sax.Parser; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import org.xml.sax.helpers.ParserFactory; + +import java.io.StringReader; + + +/** + * Demonstrate parsing from a UTF-16 character stream. + * + *

Usage: java -Dorg.xml.sax.parser=CLASSNAME + * CharacterStreamDemo

+ * + *

The SAX parser will read the document from a character + * stream connected to an internal string.

+ * + *

Note that the Java implementation of SAX represents a + * character stream using a Reader.

+ * + * @see DemoHandler + * @see org.xml.org.xml.sax.parser + * @see org.xml.sax.InputSource + * @see org.xml.sax.helpers.ParserFactory + * @see java.io.StringReader + */ +public class CharacterStreamDemo { + + // This is the document, in all its glory. + // In a read-world application, this + // could come from a database, a text + // field, or just about anywhere. + final static String doc = "" + + "\n" + + "Hello\n" + + "Hello, world!\n" + + "\n"; + + /** + * Main entry point for an application. + */ + public static void main (String args[]) + throws Exception + { + DemoHandler handler; + InputSource source; + Parser parser; + StringReader reader; + + // First, check the command-line + // arguments. + if (args.length != 0) { + System.err.println("Usage: java CharTest"); + System.exit(2); + } + + // Allocate a SAX Parser object, using + // the class name provided in the + // org.xml.sax.parser property (you could + // also specify a classname here). + parser = ParserFactory.makeParser(); + + // Allocate an event handler, and register + // it with the SAX parser for all four + // types of events (we could use a + // separate object for each). + handler = new DemoHandler(); + parser.setEntityResolver(handler); + parser.setDTDHandler(handler); + parser.setDocumentHandler(handler); + parser.setErrorHandler(handler); + + // Create a Java-specific StringReader + // for the internal document. + reader = new StringReader(doc); + + // Parse the document from the + // character stream. + parser.parse(new InputSource(reader)); + } + +}