Package org.apache.batik.parser
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 java.lang.Object implements Parser
This class is the superclass of all parsers. It provides localization and error handling methods.- Version:
- $Id: AbstractParser.java 1802297 2017-07-18 13:58:12Z ssteiner $
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringBUNDLE_CLASSNAMEThe default resource bundle base name.protected intcurrentThe current character.protected ErrorHandlererrorHandlerThe error handler.protected LocalizableSupportlocalizableSupportThe localizable support.protected NormalizingReaderreaderThe normalizing reader.
-
Constructor Summary
Constructors Constructor Description AbstractParser()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringcreateErrorMessage(java.lang.String key, java.lang.Object[] args)Returns a localized error message.protected abstract voiddoParse()Method responsible for actually parsing data after AbstractParser has initialized itself.java.lang.StringformatMessage(java.lang.String key, java.lang.Object[] args)ImplementsLocalizable.formatMessage(String,Object[]).protected java.lang.StringgetBundleClassName()Returns the resource bundle base name.intgetCurrent()Returns the current character value.java.util.LocalegetLocale()ImplementsLocalizable.getLocale().voidparse(java.io.InputStream is, java.lang.String enc)Parses the given input stream.voidparse(java.io.Reader r)Parses the given readervoidparse(java.lang.String s)Parses the given string.protected voidreportCharacterExpectedError(char expectedChar, int currentChar)simple api to call often reported error.protected voidreportError(java.lang.String key, java.lang.Object[] args)Signals an error to the error handler.protected voidreportUnexpectedCharacterError(int currentChar)simple api to call often reported error.voidsetErrorHandler(ErrorHandler handler)Allow an application to register an error event handler.voidsetLocale(java.util.Locale l)ImplementsLocalizable.setLocale(Locale).protected voidskipCommaSpaces()Skips the whitespaces and an optional comma.protected voidskipSpaces()Skips the whitespaces in the current reader.
-
-
-
Field Detail
-
BUNDLE_CLASSNAME
public static final java.lang.String BUNDLE_CLASSNAME
The default resource bundle base name.- See Also:
- Constant Field Values
-
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.
-
-
Method Detail
-
getCurrent
public int getCurrent()
Returns the current character value.
-
setLocale
public void setLocale(java.util.Locale l)
ImplementsLocalizable.setLocale(Locale).- Specified by:
setLocalein interfaceLocalizable- Parameters:
l- The locale to set.
-
getLocale
public java.util.Locale getLocale()
ImplementsLocalizable.getLocale().- Specified by:
getLocalein interfaceLocalizable
-
formatMessage
public java.lang.String formatMessage(java.lang.String key, java.lang.Object[] args) throws java.util.MissingResourceExceptionImplementsLocalizable.formatMessage(String,Object[]).- Specified by:
formatMessagein interfaceLocalizable- Parameters:
key- The key used to retreive the message from the resource bundle.args- The objects that compose the message.- Throws:
java.util.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:
setErrorHandlerin interfaceParser- Parameters:
handler- The error handler.
-
parse
public void parse(java.io.Reader r) throws ParseExceptionParses the given reader- Specified by:
parsein interfaceParser- Throws:
ParseException
-
parse
public void parse(java.io.InputStream is, java.lang.String enc) throws ParseExceptionParses the given input stream. If the encoding is null, ISO-8859-1 is used.- Throws:
ParseException
-
parse
public void parse(java.lang.String s) throws ParseExceptionParses the given string.- Specified by:
parsein interfaceParser- Throws:
ParseException
-
doParse
protected abstract void doParse() throws ParseException, java.io.IOExceptionMethod responsible for actually parsing data after AbstractParser has initialized itself.- Throws:
ParseExceptionjava.io.IOException
-
reportError
protected void reportError(java.lang.String key, java.lang.Object[] args) throws ParseExceptionSignals 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 expectedcurrentChar- 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 java.lang.String createErrorMessage(java.lang.String key, java.lang.Object[] args)Returns a localized error message.- Parameters:
key- The message key in the resource bundle.args- The message arguments.
-
getBundleClassName
protected java.lang.String getBundleClassName()
Returns the resource bundle base name.- Returns:
- BUNDLE_CLASSNAME.
-
skipSpaces
protected void skipSpaces() throws java.io.IOExceptionSkips the whitespaces in the current reader.- Throws:
java.io.IOException
-
skipCommaSpaces
protected void skipCommaSpaces() throws java.io.IOExceptionSkips the whitespaces and an optional comma.- Throws:
java.io.IOException
-
-