Class Parser2

java.lang.Object
com.sun.xml.rpc.sp.Parser2

public final class Parser2 extends Object
This implements a fast non-validating top down parser. This one always processes external parsed entities, strictly adheres to the XML 1.0 specification, and provides useful diagnostics. It supports an optimization allowing faster processing of valid standalone XML documents. For multi-language applications (such as web servers using XML processing to create dynamic content), a method supports choosing a locale for parser diagnostics which is both understood by the message recipient and supported by the parser.
Author:
David Brownell, Zhenghua Li, JAX-RPC RI Development Team
  • Constructor Details

    • Parser2

      public Parser2(InputStream in, boolean coalescing, boolean namespaceAware)
      Create a new parser with the specified input stream and the coalescing property.
      Parameters:
      in - the input stream.
      coalescing - the parser will coalesce character data if, and only if, this parameter is true
      namespaceAware - the parser will support namespaces if, and only if, this parameter is true
    • Parser2

      public Parser2(InputStream in, boolean coalescing, boolean namespaceAware, boolean rejectDTDs)
      Create a new parser with the specified input stream and the coalescing property.
      Parameters:
      in - the input stream.
      coalescing - the parser will coalesce character data if, and only if, this parameter is true
      namespaceAware - the parser will support namespaces if, and only if, this parameter is true
      rejectDTDs - the parser will throw an exception if the document contains a Document Type Declaration
    • Parser2

      public Parser2(InputStream in)
      Create a new non-coalescing parser with the specified input stream.
      Parameters:
      in - the input stream.
    • Parser2

      public Parser2(File file, boolean coalescing, boolean namespaceAware) throws IOException
      Create a new parser with the specified input file. and the coalescing property.
      Parameters:
      file - the input file.
      coalescing - the parser will coalesce character data if, and only if, this parameter is true
      namespaceAware - the parser will support namespaces if, and only if, this parameter is true
      Throws:
      IOException
    • Parser2

      public Parser2(File file, boolean coalescing, boolean namespaceAware, boolean rejectDTDs) throws IOException
      Create a new parser with the specified input file.
      Parameters:
      file - the input file.
      coalescing - the parser will coalesce character data if, and only if, this parameter is true
      namespaceAware - the parser will support namespaces if, and only if, this parameter is true
      rejectDTDs - the parser will throw an exception if the document contains a Document Type Declaration
      Throws:
      IOException
    • Parser2

      public Parser2(File file) throws IOException
      Create a new non-coalescing parser with the specified input file.
      Parameters:
      file - the input file.
      Throws:
      IOException
  • Method Details

    • setLocale

      public void setLocale(Locale l) throws ParseException
      Used by applications to request locale for diagnostics.
      Parameters:
      l - The locale to use, or null to use system defaults (which may include only message IDs).
      Throws:
      ParseException - If no diagnostic messages are available in that locale.
    • getLocale

      public Locale getLocale()
      Returns the diagnostic locale.
    • getCurName

      public String getCurName()
    • getCurURI

      public String getCurURI()
    • getCurValue

      public String getCurValue()
    • getNamespaceSupport

      public NamespaceSupport getNamespaceSupport()
    • getAttributes

      public AttributesEx getAttributes()
    • getLineNumber

      public int getLineNumber()
    • getColumnNumber

      public int getColumnNumber()
    • getPublicId

      public String getPublicId()
    • getSystemId

      public String getSystemId()
    • chooseLocale

      public Locale chooseLocale(String[] languages) throws ParseException
      Chooses a client locale to use for diagnostics, using the first language specified in the list that is supported by this parser. That locale is then set using setLocale(). Such a list could be provided by a variety of user preference mechanisms, including the HTTP Accept-Language header field.
      Parameters:
      languages - Array of language specifiers, ordered with the most preferable one at the front. For example, "en-ca" then "fr-ca", followed by "zh_CN". Both RFC 1766 and Java styles are supported.
      Returns:
      The chosen locale, or null.
      Throws:
      ParseException
      See Also:
    • setEntityResolver

      public void setEntityResolver(EntityResolver r)
      Lets applications control entity resolution.
    • getEntityResolver

      public EntityResolver getEntityResolver()
      Returns the object used to resolve entities
    • setFastStandalone

      public void setFastStandalone(boolean value)
      Setting this flag enables faster processing of valid standalone documents: external DTD information is not processed, and no attribute normalization or defaulting is done. This optimization is only permitted in non-validating parsers; for validating parsers, this mode is silently disabled.

      For documents which are declared as standalone, but which are not valid, a fatal error may be reported for references to externally defined entities. That could happen in any nonvalidating parser which did not read externally defined entities. Also, if any attribute values need normalization or defaulting, it will not be done.

    • isFastStandalone

      public boolean isFastStandalone()
      Returns true if standalone documents skip processing of all external DTD information.
    • parse

      public int parse() throws ParseException, IOException
      Parse and return the next parsing state. This is the entry point for higher level parsers like the StreamingParser.
      Throws:
      ParseException
      IOException