Class InvisibleXml

java.lang.Object
org.nineml.coffeefilter.InvisibleXml

public class InvisibleXml extends Object
A static class for constructing instances of Invisible XML grammars.
  • Field Details

  • Constructor Details

    • InvisibleXml

      public InvisibleXml()
      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.

      Throws:
      IxmlException - if the Invisible XML parser for Invisible XML cannot be loaded
    • InvisibleXml

      public InvisibleXml(ParserOptions options)
      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.

      Parameters:
      options - the parser options
      Throws:
      IxmlException - if the Invisible XML parser for Invisible XML cannot be loaded
  • Method Details

    • knownPragmas

      public static List<String> knownPragmas()
      The known pragma names.
      Returns:
      the list of pragma names known to the processor
    • knownStates

      public static List<String> knownStates()
      The known states.
      Returns:
      the list of states known to the processor.
    • satisfiesVersion10

      public static boolean satisfiesVersion10(String version)
      Is this version a valid "1.0" version?

      The valid 1.0 versions are "1.0" and "1.0-nineml".

      Parameters:
      version - the version string
      Returns:
      true if this is a 1.0 version
    • satisfiesVersion11

      public static boolean satisfiesVersion11(String version)
      Is this version a valid "1.1" version?

      The valid 1.1 versions are "1.1" and "1.1-nineml".

      Parameters:
      version - the version string
      Returns:
      true if this is a 1.1 version
    • getOptions

      public ParserOptions getOptions()
      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.

      Returns:
      the current options
    • getParser

      public InvisibleXmlParser getParser()
      The parser for ixml grammars.
      Returns:
      A parser for the ixml specification grammar.
    • getParser

      public InvisibleXmlParser getParser(URI source) throws IOException
      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.

      Parameters:
      source - the grammar source.
      Returns:
      a parser for that grammar
      Throws:
      IOException - if attempting to open or read the source fails
      IxmlException - if the source cannot be identified or is not a valid grammar
    • getParser

      public InvisibleXmlParser getParser(File source) throws IOException
      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.

      Parameters:
      source - the grammar source.
      Returns:
      a parser for that grammar
      Throws:
      IOException - if attempting to open or read the source fails
      IxmlException - if the source cannot be identified or is not a valid grammar
    • getParser

      public InvisibleXmlParser getParser(URI source, String encoding) throws IOException
      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.

      Parameters:
      source - the grammar source.
      encoding - the character encoding.
      Returns:
      a parser for that grammar
      Throws:
      IOException - if attempting to open or read the source fails
      IxmlException - if the source cannot be identified or is not a valid grammar
    • getParser

      public InvisibleXmlParser getParser(File source, String encoding) throws IOException
      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.

      Parameters:
      source - the grammar source.
      encoding - the encoding
      Returns:
      a parser for that grammar
      Throws:
      IOException - if attempting to open or read the source fails
      IxmlException - if the source cannot be identified or is not a valid grammar
    • getParser

      public InvisibleXmlParser getParser(InputStream stream, String systemId) throws IOException
      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.

      Parameters:
      stream - the grammar source
      systemId - the system identifier (for XML grammars)
      Returns:
      a parser for that grammar
      Throws:
      IOException - if attempting to read the source fails
      IxmlException - if the source cannot be identified or is not a valid grammar
    • getParser

      public InvisibleXmlParser getParser(InputStream stream, String systemId, String encoding) throws IOException
      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.

      Parameters:
      stream - the grammar source
      systemId - the system identifier (for XML grammars)
      encoding - the character encoding.
      Returns:
      a parser for that grammar
      Throws:
      IOException - if attempting to open or read the source fails
      IxmlException - if the source cannot be identified or is not a valid grammar
    • getParserFromVxml

      public InvisibleXmlParser getParserFromVxml(InputStream stream, String systemId) throws IOException
      Construct a parser from an XML representation (vxml) of an ixml grammar
      Parameters:
      stream - the input stream
      systemId - The system ID of an XML document containing an Invisible XML vxml grammar.
      Returns:
      A parser for that grammar.
      Throws:
      IOException - if the input cannot be read
      IxmlException - if the input is not an ixml grammar
    • getParserFromIxml

      public InvisibleXmlParser getParserFromIxml(InputStream stream, String charset) throws IOException
      Constructs a parser from an ixml grammar.
      Parameters:
      stream - A stream returning an ixml grammar.
      charset - The character set of the grammar file.
      Returns:
      A parser for the grammar.
      Throws:
      IOException - If an error occurs reading the stream or if the character set is unsupported.
      IxmlException - if the input is not an ixml grammar
    • getParserFromIxml

      public InvisibleXmlParser getParserFromIxml(String input)
      Constructs a parser from an ixml grammar.
      Parameters:
      input - An input string that contains an ixml grammar.
      Returns:
      A parser for the grammar.
      Throws:
      IxmlException - if the input is not an ixml grammar