Package org.apache.fop.util
Class XMLUtil
- java.lang.Object
-
- org.apache.fop.util.XMLUtil
-
- All Implemented Interfaces:
XMLConstants
public final class XMLUtil extends java.lang.Object implements XMLConstants
A collection of utility method for XML handling.
-
-
Field Summary
-
Fields inherited from interface org.apache.fop.util.XMLConstants
CDATA, XLINK_HREF, XLINK_NAMESPACE, XLINK_PREFIX, XML_NAMESPACE, XML_PREFIX, XML_SPACE, XMLNS_NAMESPACE_URI, XMLNS_PREFIX
-
-
Constructor Summary
Constructors Modifier Constructor Description private
XMLUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addAttribute(org.xml.sax.helpers.AttributesImpl atts, java.lang.String localName, java.lang.String value)
Adds an attribute to a givenAttributesImpl
instance.static void
addAttribute(org.xml.sax.helpers.AttributesImpl atts, org.apache.xmlgraphics.util.QName attribute, java.lang.String value)
Adds an attribute to a givenAttributesImpl
instance.static int[][]
decodePositionAdjustments(java.lang.String value)
Decode a string as a glyph position adjustments array, where the string shall adhere to the syntax specified byencodePositionAdjustments(int[][], int)
.private static void
encodeAdjustment(java.lang.StringBuffer sb, int a)
private static void
encodeNextAdjustment(java.lang.StringBuffer sb, int nz, int a)
static java.lang.String
encodePositionAdjustments(int[][] dp)
Encode a glyph position adjustments array as a string, where the string value adheres to the following syntax: count ( 'Z' repeat | number ) where each token is separated by whitespace, except that 'Z' followed by repeat are considered to be a single token with no intervening whitespace.static java.lang.String
encodePositionAdjustments(int[][] dp, int paCount)
Encode a glyph position adjustments array as a string, where the string value adheres to the following syntax: count ( 'Z' repeat | number ) where each token is separated by whitespace, except that 'Z' followed by repeat are considered to be a single token with no intervening whitespace, and where 'Z' repeat encodes repeated zeroes.private static void
encodeZeroes(java.lang.StringBuffer sb, int nz)
static java.lang.String
escape(java.lang.String unescaped)
Escape '<', '>' and '&' using NCRs.static boolean
getAttributeAsBoolean(org.xml.sax.Attributes attributes, java.lang.String name, boolean defaultValue)
Returns an attribute value as a boolean value.static int
getAttributeAsInt(org.xml.sax.Attributes attributes, java.lang.String name)
Returns an attribute value as a int value.static int
getAttributeAsInt(org.xml.sax.Attributes attributes, java.lang.String name, int defaultValue)
Returns an attribute value as a int value.static int[]
getAttributeAsIntArray(org.xml.sax.Attributes attributes, java.lang.String name)
Returns an attribute value as a integer array.static java.lang.Integer
getAttributeAsInteger(org.xml.sax.Attributes attributes, java.lang.String name)
Returns an attribute value as a Integer value.static int[][]
getAttributeAsPositionAdjustments(org.xml.sax.Attributes attributes, java.lang.String name)
Returns an attribute value as a glyph position adjustments array.static java.awt.Rectangle
getAttributeAsRectangle(org.xml.sax.Attributes attributes, java.lang.String name)
Returns an attribute value as a Rectangle value.static java.awt.geom.Rectangle2D
getAttributeAsRectangle2D(org.xml.sax.Attributes attributes, java.lang.String name)
Returns an attribute value as a Rectangle2D value.
-
-
-
Method Detail
-
getAttributeAsBoolean
public static boolean getAttributeAsBoolean(org.xml.sax.Attributes attributes, java.lang.String name, boolean defaultValue)
Returns an attribute value as a boolean value.- Parameters:
attributes
- the Attributes objectname
- the name of the attributedefaultValue
- the default value if the attribute is not specified- Returns:
- the attribute value as a boolean
-
getAttributeAsInt
public static int getAttributeAsInt(org.xml.sax.Attributes attributes, java.lang.String name, int defaultValue)
Returns an attribute value as a int value.- Parameters:
attributes
- the Attributes objectname
- the name of the attributedefaultValue
- the default value if the attribute is not specified- Returns:
- the attribute value as an int
-
getAttributeAsInt
public static int getAttributeAsInt(org.xml.sax.Attributes attributes, java.lang.String name) throws org.xml.sax.SAXException
Returns an attribute value as a int value.- Parameters:
attributes
- the Attributes objectname
- the name of the attribute- Returns:
- the attribute value as an int
- Throws:
org.xml.sax.SAXException
- if the attribute is missing
-
getAttributeAsInteger
public static java.lang.Integer getAttributeAsInteger(org.xml.sax.Attributes attributes, java.lang.String name)
Returns an attribute value as a Integer value.- Parameters:
attributes
- the Attributes objectname
- the name of the attribute- Returns:
- the attribute value as an Integer or null if the attribute is missing
-
getAttributeAsRectangle2D
public static java.awt.geom.Rectangle2D getAttributeAsRectangle2D(org.xml.sax.Attributes attributes, java.lang.String name)
Returns an attribute value as a Rectangle2D value. The string value is expected as 4 double-precision numbers separated by whitespace.- Parameters:
attributes
- the Attributes objectname
- the name of the attribute- Returns:
- the attribute value as an Rectangle2D
-
getAttributeAsRectangle
public static java.awt.Rectangle getAttributeAsRectangle(org.xml.sax.Attributes attributes, java.lang.String name)
Returns an attribute value as a Rectangle value. The string value is expected as 4 integer numbers separated by whitespace.- Parameters:
attributes
- the Attributes objectname
- the name of the attribute- Returns:
- the attribute value as an Rectangle
-
getAttributeAsIntArray
public static int[] getAttributeAsIntArray(org.xml.sax.Attributes attributes, java.lang.String name)
Returns an attribute value as a integer array. The string value is expected as 4 integer numbers separated by whitespace.- Parameters:
attributes
- the Attributes objectname
- the name of the attribute- Returns:
- the attribute value as an int array
-
addAttribute
public static void addAttribute(org.xml.sax.helpers.AttributesImpl atts, org.apache.xmlgraphics.util.QName attribute, java.lang.String value)
Adds an attribute to a givenAttributesImpl
instance.- Parameters:
atts
- the attributes collectionattribute
- the attribute to addvalue
- the attribute's CDATA value
-
addAttribute
public static void addAttribute(org.xml.sax.helpers.AttributesImpl atts, java.lang.String localName, java.lang.String value)
Adds an attribute to a givenAttributesImpl
instance. The attribute will be added in the default namespace.- Parameters:
atts
- the attributes collectionlocalName
- the local name of the attributevalue
- the attribute's CDATA value
-
encodePositionAdjustments
public static java.lang.String encodePositionAdjustments(int[][] dp, int paCount)
Encode a glyph position adjustments array as a string, where the string value adheres to the following syntax: count ( 'Z' repeat | number ) where each token is separated by whitespace, except that 'Z' followed by repeat are considered to be a single token with no intervening whitespace, and where 'Z' repeat encodes repeated zeroes.- Parameters:
dp
- the adjustments arraypaCount
- the number of entries to encode from adjustments array- Returns:
- the encoded value
-
encodePositionAdjustments
public static java.lang.String encodePositionAdjustments(int[][] dp)
Encode a glyph position adjustments array as a string, where the string value adheres to the following syntax: count ( 'Z' repeat | number ) where each token is separated by whitespace, except that 'Z' followed by repeat are considered to be a single token with no intervening whitespace.- Parameters:
dp
- the adjustments array- Returns:
- the encoded value
-
encodeNextAdjustment
private static void encodeNextAdjustment(java.lang.StringBuffer sb, int nz, int a)
-
encodeZeroes
private static void encodeZeroes(java.lang.StringBuffer sb, int nz)
-
encodeAdjustment
private static void encodeAdjustment(java.lang.StringBuffer sb, int a)
-
decodePositionAdjustments
public static int[][] decodePositionAdjustments(java.lang.String value)
Decode a string as a glyph position adjustments array, where the string shall adhere to the syntax specified byencodePositionAdjustments(int[][], int)
.- Parameters:
value
- the encoded value- Returns:
- the position adjustments array
-
getAttributeAsPositionAdjustments
public static int[][] getAttributeAsPositionAdjustments(org.xml.sax.Attributes attributes, java.lang.String name)
Returns an attribute value as a glyph position adjustments array. The string value is expected to be a non-empty sequence of either Z<repeat> or <number>, where the former encodes a repeat count (of zeroes) and the latter encodes a integer number, and where each item is separated by whitespace.- Parameters:
attributes
- the Attributes objectname
- the name of the attribute- Returns:
- the position adjustments array
-
escape
public static java.lang.String escape(java.lang.String unescaped)
Escape '<', '>' and '&' using NCRs.- Parameters:
unescaped
- string- Returns:
- escaped string
-
-