Chapter 4. Invisible XML
4.1. InvisibleXml
The org.nineml.coffeefilter.InvisibleXml class.
4.1.1. Field summary
Public fields for the org.nineml.coffeefilter.InvisibleXml class.
public static final String logcategory ="InvisibleXml"The category name used for InvisibleXml log messages.
public static final String IXML_10 ="1.0"public static final String IXML_10_NINEML ="1.0-nineml"public static final String IXML_11 ="1.1"public static final String IXML_11_NINEML ="1.1-nineml"public static final String XMLNS_ATTRIBUTE ="https://coffeefilter.nineml.org/attr/xmlns"The internal name for the xmlns parser attribute.
public static final String NAME_ATTRIBUTE ="https://coffeefilter.nineml.org/attr/name"The internal name for the name parser attribute.
public static final String MARK_ATTRIBUTE ="https://coffeefilter.nineml.org/attr/mark"The internal name for the mark parser attribute.
public static final String TMARK_ATTRIBUTE ="https://coffeefilter.nineml.org/attr/tmark"The internal name for the tmark parser attribute.
public static final String INSERTION_ATTRIBUTE ="https://coffeefilter.nineml.org/attr/insertion"The internal name for the insertion parser attribute.
public static final String DISCARD_ATTRIBUTE ="https://coffeefilter.nineml.org/attr/discard"The internal name for the discard parser attribute.
public static final String ixml_prefix ="ixml"The namespace prefix for the Invisilble XML namespace.
public static final String ixml_ns ="http://invisiblexml.org/NS"The Invisible XML namespace URI.
public static final String nineml_prefix ="n"The namespace prefix for the NineML namespace.
public static final String nineml_ns ="https://nineml.org/ns/"THe NineML namespace URI.
public static final String AMBIGUOUS ="ambiguous"The iXML “ambiguous” state .
public static final String VERSION_MISMATCH ="version-mismatch"The iXML “version-mismatch” state.
4.1.2. Constructor summary
Public constructors for the org.nineml.coffeefilter.InvisibleXml class.
public InvisibleXml()- throws
IxmlExceptionif the Invisible XML parser for Invisible XML cannot be loaded Creates a new InvisibleXml object (with default options) from which parsers can be constructed.
Attempts to load the Invisible XML parser for Invisible XML from resources. This constructor uses default options.
public InvisibleXml(ParserOptions options)- throws
IxmlExceptionif the Invisible XML parser for Invisible XML cannot be loaded Creates a new InvisibleXml object (with custom options) from which parsers can be constructed.
Attempts to load the Invisible XML parser for Invisible XML from resources.
4.1.3. Method summary
Public methods on the org.nineml.coffeefilter.InvisibleXml class.
publicParserOptionsgetOptions()Get the parser options currently being used to construct parsers.
Changing properties on the options will only effect subsequently constructed parsers. Each parser gets its own copy of the options.
publicInvisibleXmlParsergetParser()The parser for ixml grammars.
publicInvisibleXmlParsergetParser(File source)- throws
IOExceptionif attempting to open or read the source fails - throws
IxmlExceptionif the source cannot be identified or is not a valid grammar Get a parser from a file.
Sniffs the first 4095 bytes of the input to identify the input as an ixml grammar, a vxml grammar, or a compiled grammar. Assumes the input is in UTF-8.
publicInvisibleXmlParsergetParser(File source String encoding)- throws
IOExceptionif attempting to open or read the source fails - throws
IxmlExceptionif the source cannot be identified or is not a valid grammar Get a parser from a file with an explicit encoding.
Sniffs the first 4095 bytes of the input to identify the input as an ixml grammar, a vxml grammar, or a compiled grammar.The encoding is irrelevant for vxml or compiled grammars.
publicInvisibleXmlParsergetParser(InputStream stream String systemId)- throws
IOExceptionif attempting to read the source fails - throws
IxmlExceptionif the source cannot be identified or is not a valid grammar Get a parser from an input stream.
Sniffs the first 4095 bytes of the input stream to identify the input as an ixml grammar, a vxml grammar, or a compiled grammar. Assumes the input is in UTF-8.
publicInvisibleXmlParsergetParser(InputStream stream String systemId String encoding)- throws
IOExceptionif attempting to open or read the source fails - throws
IxmlExceptionif the source cannot be identified or is not a valid grammar Get a parser from an input stream with an explicit encoding.
Sniffs the first 4095 bytes of the input stream to identify the input as an ixml grammar, a vxml grammar, or a compiled grammar. The encoding is irrelevant for vxml or compiled grammars.
publicInvisibleXmlParsergetParser(URI source)- throws
IOExceptionif attempting to open or read the source fails - throws
IxmlExceptionif the source cannot be identified or is not a valid grammar Get a parser from a URI.
Attempts to read from the URI with
source.toURL().openConnection(). Sniffs the first 4095 bytes of the input to identify the input as an ixml grammar, a vxml grammar, or a compiled grammar. Assumes the input is in UTF-8.publicInvisibleXmlParsergetParser(URI source String encoding)- throws
IOExceptionif attempting to open or read the source fails - throws
IxmlExceptionif the source cannot be identified or is not a valid grammar Get a parser from a URI with an explicit encoding.
Attempts to read from the URI with
source.toURL().openConnection(). Sniffs the first 4095 bytes of the input to identify the input as an ixml grammar, a vxml grammar, or a compiled grammar. The encoding is irrelevant for vxml or compiled grammars.publicInvisibleXmlParsergetParserFromIxml(InputStream stream String charset)- throws
IOExceptionIf an error occurs reading the stream or if the character set is unsupported. - throws
IxmlExceptionif the input is not an ixml grammar Constructs a parser from an ixml grammar.
publicInvisibleXmlParsergetParserFromIxml(String input)- throws
IxmlExceptionif the input is not an ixml grammar Constructs a parser from an ixml grammar.
publicInvisibleXmlParsergetParserFromVxml(InputStream stream String systemId)- throws
IOExceptionif the input cannot be read - throws
IxmlExceptionif the input is not an ixml grammar Construct a parser from an XML representation (vxml) of an ixml grammar
publicList<String>knownPragmas()The known pragma names.
publicList<String>knownStates()The known states.
publicbooleansatisfiesVersion10(String version)Is this version a valid “1.0” version?
The valid 1.0 versions are “1.0” and “1.0-nineml”.
publicbooleansatisfiesVersion11(String version)Is this version a valid “1.1” version?
The valid 1.1 versions are “1.1” and “1.1-nineml”.
4.2. InvisibleXmlParser
The org.nineml.coffeefilter.InvisibleXmlParser class.
4.2.1. Field summary
Public fields for the org.nineml.coffeefilter.InvisibleXmlParser class.
public static final String logcategory ="InvisibleXml"
4.2.2. Method summary
Public methods on the org.nineml.coffeefilter.InvisibleXmlParser class.
publicbooleanconstructed()Did the grammar parse succeed?
publicExceptiongetException()Return the exception that caused an attempt to build a parser to fail.
If the attempt was successful, or if failure did not raise an exception,
nullwill be returned.publicInvisibleXmlDocumentgetFailedParse()If the attempt to parse the grammar failed, return a representation of that failure.
publicSourceGrammargetGrammar()- throws
NullPointerExceptionif this parser has no grammar Get the underlying grammar
publicHygieneReportgetHygieneReport()Get the hygiene report for this parser’s grammar
publicStringgetIxmlVersion()publicMap<String, List>getMetadata()Get metadata.
Pragmas in the prolog that aren’t recognized by the processor are returned as “data” pragmas associating a URI with (a list of) values.
publicParserOptionsgetOptions()Get the parser options.
publiclonggetParseTime()Get the time spent parsing the input grammar.
This returns the number of milliseconds of “wall clock time” spent by the processor constructing this parser.
publicInvisibleXmlDocumentparse(File source)- throws
IOExceptionIf the source cannot be read - throws
NullPointerExceptionif this parser has no grammar Get a document from a file.
Assumes the input is in UTF-8.
publicInvisibleXmlDocumentparse(File source String encoding)- throws
IOExceptionIf the stream cannot be read or if the character set is unsupported. - throws
NullPointerExceptionif this parser has no grammar Get a document from a file with an explicit encoding.
publicInvisibleXmlDocumentparse(InputStream stream String encoding)- throws
IOExceptionIf the stream cannot be read or if the character set is unsupported. - throws
NullPointerExceptionif this parser has no grammar Get a document from a stream.
publicInvisibleXmlDocumentparse(String input)- throws
NullPointerExceptionif this parser has no grammar Get a document from a string.
publicInvisibleXmlDocumentparse(URI source)- throws
IOExceptionIf the source cannot be read - throws
NullPointerExceptionif this parser has no grammar Get a document from a URI.
Attempts to read from the URI with
source.toURL().openConnection(). Assumes the input is in UTF-8.publicInvisibleXmlDocumentparse(URI source String encoding)- throws
IOExceptionIf the stream cannot be read or if the character set is unsupported. - throws
NullPointerExceptionif this parser has no grammar Get a document from a URI with an explicit encoding.
Attempts to read from the URI with
source.toURL().openConnection().publicInvisibleXmlDocumentparse(Token[] input)- throws
NullPointerExceptionif this parser has no grammar Get a document from an array of tokens.
publicStringreadInputStream(InputStream stream String charset)
4.3. InvisibleXmlDocument
The org.nineml.coffeefilter.InvisibleXmlDocument class.
From this object, you can obtain the parsed representation(s) of the document. For ambiguous grammars, there may be more than one.
4.3.1. Method summary
Public methods on the org.nineml.coffeefilter.InvisibleXmlDocument class.
publicTreeBuildergetAdapter(ContentHandler handler)Returns an adapter for SAX ContentHandlers.
publicintgetColumnNumber()Get the column number of the last line processed.
If the parse failed, this will be the position of the character in the last line where the error occurred.
publicintgetLineNumber()Get the line number of the last line processed.
If the parse failed, this will be the line on which the error occurred. Lines are counted by occurrence of ’\n’.
publiclonggetNumberOfParses()Return the number of available parses of this document.
Will return 0 if there are no successful parses.
publicintgetOffset()Get the offset of the last character processed.
If the parse failed, this will be the position of the character in the input stream.
publicParserOptionsgetOptions()Get the parser options.
publicParserTypegetParserType()Return the parser type.
publicStringgetParserVersion()Get the parser version.
publicGearleyResultgetResult()Return the underlying GearleyResult result for this parse.
publicStringgetTree()- throws
org.nineml.coffeefilter.exceptions.IxmlExceptionif the parse failed Return an XML representation of the current parse.
public void getTree(PrintStream output)Write an XML representation of the current parse to the stream.
public void getTree(TreeBuilder builder)Process the result with your own TreeBuilder.
This API needs work.
public void getTree(ContentHandler handler)Write an XML representation of the current parse to a SAX ContentHandler.
public void getTree(ContentHandler handler ParserOptions options)Write an XML representation of the current parse to a SAX ContentHandler using a different set of options.
publicbooleanisAmbiguous()Is this document ambiguous?
The return value is arbitrary if the parse did not succeed.
publicbooleanisInfinitelyAmbiguous()Is this document infinitely ambiguous?
The return value is arbitrary if the parse did not succeed.
publiclongparseTime()Returns the amount of time (roughly) spent parsing.
publicbooleansucceeded()Did the parse succeed?