Class AbstractParser

java.lang.Object
org.apache.batik.parser.AbstractParser
All Implemented Interfaces:
Localizable, Parser
Direct Known Subclasses:
LengthParser, NumberParser, PreserveAspectRatioParser, TimingParser

public abstract class AbstractParser extends Object implements Parser
This class is the superclass of all parsers. It provides localization and error handling methods.
  • Field Details

    • BUNDLE_CLASSNAME

      public static final String BUNDLE_CLASSNAME
      The default resource bundle base name.
      See Also:
    • errorHandler

      protected ErrorHandler errorHandler
      The error handler.
    • localizableSupport

      protected LocalizableSupport localizableSupport
      The localizable support.
    • reader

      protected NormalizingReader reader
      The normalizing reader.
    • current

      protected int current
      The current character.
  • Constructor Details

    • AbstractParser

      public AbstractParser()
  • Method Details

    • getCurrent

      public int getCurrent()
      Returns the current character value.
    • setLocale

      public void setLocale(Locale l)
      Specified by:
      setLocale in interface Localizable
      Parameters:
      l - The locale to set.
    • getLocale

      public Locale getLocale()
      Specified by:
      getLocale in interface Localizable
    • formatMessage

      public String formatMessage(String key, Object[] args) throws MissingResourceException
      Specified by:
      formatMessage in interface Localizable
      Parameters:
      key - The key used to retreive the message from the resource bundle.
      args - The objects that compose the message.
      Throws:
      MissingResourceException - if the key is not in the bundle.
    • setErrorHandler

      public void setErrorHandler(ErrorHandler handler)
      Allow an application to register an error event handler.

      If the application does not register an error event handler, all error events reported by the parser will cause an exception to be thrown.

      Applications may register a new or different handler in the middle of a parse, and the parser must begin using the new handler immediately.

      Specified by:
      setErrorHandler in interface Parser
      Parameters:
      handler - The error handler.
    • parse

      public void parse(Reader r) throws ParseException
      Parses the given reader
      Specified by:
      parse in interface Parser
      Throws:
      ParseException
    • parse

      public void parse(InputStream is, String enc) throws ParseException
      Parses the given input stream. If the encoding is null, ISO-8859-1 is used.
      Throws:
      ParseException
    • parse

      public void parse(String s) throws ParseException
      Parses the given string.
      Specified by:
      parse in interface Parser
      Throws:
      ParseException
    • doParse

      protected abstract void doParse() throws ParseException, IOException
      Method responsible for actually parsing data after AbstractParser has initialized itself.
      Throws:
      ParseException
      IOException
    • reportError

      protected void reportError(String key, Object[] args) throws ParseException
      Signals an error to the error handler.
      Parameters:
      key - The message key in the resource bundle.
      args - The message arguments.
      Throws:
      ParseException
    • reportCharacterExpectedError

      protected void reportCharacterExpectedError(char expectedChar, int currentChar)
      simple api to call often reported error. Just a wrapper for reportError().
      Parameters:
      expectedChar - what caller expected
      currentChar - what caller found
    • reportUnexpectedCharacterError

      protected void reportUnexpectedCharacterError(int currentChar)
      simple api to call often reported error. Just a wrapper for reportError().
      Parameters:
      currentChar - what the caller found and didnt expect
    • createErrorMessage

      protected String createErrorMessage(String key, Object[] args)
      Returns a localized error message.
      Parameters:
      key - The message key in the resource bundle.
      args - The message arguments.
    • getBundleClassName

      protected String getBundleClassName()
      Returns the resource bundle base name.
      Returns:
      BUNDLE_CLASSNAME.
    • skipSpaces

      protected void skipSpaces() throws IOException
      Skips the whitespaces in the current reader.
      Throws:
      IOException
    • skipCommaSpaces

      protected void skipCommaSpaces() throws IOException
      Skips the whitespaces and an optional comma.
      Throws:
      IOException