SVG has a number of microsyntaxes that are used within attribute values,
such as the transform attribute on
SVGTransformable elements, and the path data d
attribute on path elements. Since these are not trivial to
parse, this functionality has been factored out into a separate package
that can be used by other SVG-processing applications if needed.
In the parser module, each microsyntax is supported by a pair of classes:
a parser and a handler. The parser is a class that implements the
Parser
interface, which has methods to parse values from a
Reader
or a
String.
The handler is an interface specific to the microsyntax that will have
its methods called whenever the corresponding element in the input is
parsed. For those handler interfaces that have more than one method,
adapter classes are provided (named Default*).
Parsers can also have an error handler associated with them, whose
single method error will be called when there is a
problem parsing the input. If an error handler is not associated with
a parser, a
ParseException
will be thrown if an error occurs.
The microsyntaxes supported by the parser module are:
Implemented by
AngleParser,
handled with
AngleHandler.
This parser is used for parsing angles formed by a floating point
number followed by deg, grad or
rad. It is not currently used by the rest of the Batik
codebase.
Implemented by ClockParser, handled with ClockHandler. This parser is used for parsing SMIL clock values.
Implemented by FragmentIdentifierParser, handled with FragmentIdentifierHandler. This parser is used for parsing the various formats of fragment identifier that SVG allows.
Implemented by LengthParser, handled with LengthHandler. This parser is used for parsing SVG length values.
Implemented by LengthListParser, handled with LengthListHandler. This parser is used for parsing lists of comma or space separated SVG lengths.
Implemented by NumberListParser, handled with NumberListHandler. This parser is used for parsing SVG number values.
Implemented by NumberListParser, handled with NumberListHandler. This parser is used for parsing lists of comma or space separated SVG numbers.
Implemented by
PathParser,
handled with
PathHandler.
This parser is used for parsing SVG path data, as found in
path element d attributes.
Implemented by
PointsParser,
handled with
PointsHandler.
This parser is used for parsing point lists, as found in
polygon element points attributes.
Implemented by
PreserveAspectRatioParser,
handled with
PreserveAspectRatioHandler.
This parser is used for parsing the values found in the
preserveAspectRatio attribute of svg
elements.
Implemented by
TransformListParser,
handled with
TransformListHandler.
This parser is used for parsing transform lists, as found in the
transform attribute of any transformable element.
Some microsyntaxes also have a corresponding producer class, which is an implementation of the handler interface that generates an object while parsing.
The following example code demonstrates how to use the parser classes to parse a list of points:
This example uses the AWTTransformProducer class to generate an AffineTransform object from an SVG transform list: