## org.jfree.xml
Class ParserUtil

    java.lang.Object
      org.jfree.xml.ParserUtil

    public class ParserUtil

extends java.lang.Object

Basic helper functions to ease up the process of parsing.

Author:
  Thomas Morgner

Constructor Summary
`ParserUtil()`

Method Summary
`static java.awt.geom.Rectangle2D` `getElementPosition(org.xml.sax.Attributes atts)` Parses an element position.
`static boolean` `parseBoolean(java.lang.String text, boolean defaultVal)` Parses a boolean.
`static java.awt.Color` `parseColor(java.lang.String color)` Parses a color entry.
`static java.awt.Color` `parseColor(java.lang.String color, java.awt.Color defaultValue)` Parses a color entry.
`static float` `parseFloat(java.lang.String text, float defaultVal)` Parses the string `text` into an float.
`static float` `parseFloat(java.lang.String text, java.lang.String message)` Parses the string `text` into an float.
`static int` `parseInt(java.lang.String text, int defaultVal)` Parses an integer.
`static int` `parseInt(java.lang.String text, java.lang.String message)` Parses the string `text` into an int.
`static float` `parseRelativeFloat(java.lang.String value, java.lang.String exceptionMessage)` Parses a position of an element.
`static java.lang.String` `parseString(java.lang.String text, java.lang.String defaultVal)` Parses a string.
`static java.awt.Stroke` `parseStroke(java.lang.String weight)` Creates a basic stroke given the width contained as float in the given string.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ParserUtil

    public ParserUtil()

Method Detail

### parseInt

    public static int parseInt(java.lang.String text,
                               java.lang.String message)
                        throws org.xml.sax.SAXException

  Parses the string `text` into an int. If text is null or does not contain a parsable value, the message given in `message` is used to throw a SAXException.

  Parameters:
    `text` - the text to parse.
    `message` - the error message if parsing fails.
  Returns:
    the int value.
  Throws:
    `org.xml.sax.SAXException` - if there is a problem with the parsing.

### parseInt

    public static int parseInt(java.lang.String text,
                               int defaultVal)

  Parses an integer.

  Parameters:
    `text` - the text to parse.
    `defaultVal` - the default value.
  Returns:
    the integer.

### parseFloat

    public static float parseFloat(java.lang.String text,
                                   java.lang.String message)
                            throws org.xml.sax.SAXException

  Parses the string `text` into an float. If text is null or does not contain a parsable value, the message given in `message` is used to throw a SAXException.

  Parameters:
    `text` - the text to parse.
    `message` - the error message if parsing fails.
  Returns:
    the float value.
  Throws:
    `org.xml.sax.SAXException` - if there is a problem with the parsing.

### parseFloat

    public static float parseFloat(java.lang.String text,
                                   float defaultVal)

  Parses the string `text` into an float. If text is null or does not contain a parsable value, the message given in `message` is used to throw a SAXException.

  Parameters:
    `text` - the text to parse.
    `defaultVal` - the defaultValue returned if parsing fails.
  Returns:
    the float value.

### parseBoolean

    public static boolean parseBoolean(java.lang.String text,
                                       boolean defaultVal)

  Parses a boolean. If the string `text` contains the value of "true", the true value is returned, else false is returned.

  Parameters:
    `text` - the text to parse.
    `defaultVal` - the default value.
  Returns:
    a boolean.

### parseString

    public static java.lang.String parseString(java.lang.String text,
                                               java.lang.String defaultVal)

  Parses a string. If the `text` is null, defaultval is returned.

  Parameters:
    `text` - the text to parse.
    `defaultVal` - the default value.
  Returns:
    a string.

### parseStroke

    public static java.awt.Stroke parseStroke(java.lang.String weight)

  Creates a basic stroke given the width contained as float in the given string. If the string could not be parsed into a float, a basic stroke with the width of 1 is returned.

  Parameters:
    `weight` - a string containing a number (the stroke weight).
  Returns:
    the stroke.

### parseColor

    public static java.awt.Color parseColor(java.lang.String color)

  Parses a color entry. If the entry is in hexadecimal or ocal notation, the color is created using Color.decode(). If the string denotes a constant name of on of the color constants defined in java.awt.Color, this constant is used.

  As fallback the color black is returned if no color can be parsed.

  Parameters:
    `color` - the color (as a string).
  Returns:
    the paint.

### parseColor

    public static java.awt.Color parseColor(java.lang.String color,
                                            java.awt.Color defaultValue)

  Parses a color entry. If the entry is in hexadecimal or octal notation, the color is created using Color.decode(). If the string denotes a constant name of one of the color constants defined in java.awt.Color, this constant is used.

  As fallback the supplied default value is returned if no color can be parsed.

  Parameters:
    `color` - the color (as a string).
    `defaultValue` - the default value (returned if no color can be parsed).
  Returns:
    the paint.

### parseRelativeFloat

    public static float parseRelativeFloat(java.lang.String value,
                                           java.lang.String exceptionMessage)
                                    throws org.xml.sax.SAXException

  Parses a position of an element. If a relative postion is given, the returnvalue is a negative number between 0 and -100.

  Parameters:
    `value` - the value.
    `exceptionMessage` - the exception message.
  Returns:
    the float value.
  Throws:
    `org.xml.sax.SAXException` - if there is a problem parsing the string.

### getElementPosition

    public static java.awt.geom.Rectangle2D getElementPosition(org.xml.sax.Attributes atts)
                                                        throws org.xml.sax.SAXException

  Parses an element position. The position is stored in the attributes "x", "y", "width" and "height". The attributes are allowed to have relative notion.

  Parameters:
    `atts` - the attributes.
  Returns:
    the element position.
  Throws:
    `org.xml.sax.SAXException` - if there is a problem getting the element position.