com.itextpdf.text.xml
Class XMLUtil

java.lang.Object
  extended by com.itextpdf.text.xml.XMLUtil

public class XMLUtil
extends Object

Contains utility methods for XML.

Since:
5.0.6
Author:
Balder

Constructor Summary
XMLUtil()
           
 
Method Summary
static String escapeXML(String s, boolean onlyASCII)
          Escapes a string with the appropriated XML codes.
static int findInArray(char needle, char[] haystack, int start)
          Looks for a character in a character array, starting from a certain position
static String getEncodingName(byte[] b4)
          Returns the IANA encoding name that is auto-detected from the bytes specified, with the endian-ness of that encoding where appropriate.
static boolean isValidCharacterValue(int c)
          Checks if a character value should be escaped/unescaped.
static boolean isValidCharacterValue(String s)
          Checks if a character value should be escaped/unescaped.
static int unescape(String s)
          Unescapes 'lt', 'gt', 'apos', 'quote' and 'amp' to the corresponding character values.
static String unescapeXML(String s)
          Unescapes a String, replacing &#nn;, <, >, &, ", and &apos to the corresponding characters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLUtil

public XMLUtil()
Method Detail

escapeXML

public static String escapeXML(String s,
                               boolean onlyASCII)
Escapes a string with the appropriated XML codes.

Parameters:
s - the string to be escaped
onlyASCII - codes above 127 will always be escaped with &#nn; if true
Returns:
the escaped string
Since:
5.0.6

unescapeXML

public static String unescapeXML(String s)
Unescapes a String, replacing &#nn;, <, >, &, ", and &apos to the corresponding characters.

Parameters:
s - a String with entities
Returns:
the unescaped string

unescape

public static int unescape(String s)
Unescapes 'lt', 'gt', 'apos', 'quote' and 'amp' to the corresponding character values.

Parameters:
s - a string representing a character
Returns:
a character value

isValidCharacterValue

public static boolean isValidCharacterValue(String s)
Checks if a character value should be escaped/unescaped.

Parameters:
s - the String representation of an integer
Returns:
true if it's OK to escape or unescape this value

isValidCharacterValue

public static boolean isValidCharacterValue(int c)
Checks if a character value should be escaped/unescaped.

Parameters:
c - a character value
Returns:
true if it's OK to escape or unescape this value

findInArray

public static int findInArray(char needle,
                              char[] haystack,
                              int start)
Looks for a character in a character array, starting from a certain position

Parameters:
needle - the character you're looking for
haystack - the character array
start - the start position
Returns:
the position where the character was found, or -1 if it wasn't found.

getEncodingName

public static String getEncodingName(byte[] b4)
Returns the IANA encoding name that is auto-detected from the bytes specified, with the endian-ness of that encoding where appropriate. (method found in org.apache.xerces.impl.XMLEntityManager, originally published by the Apache Software Foundation under the Apache Software License; now being used in iText under the MPL)

Parameters:
b4 - The first four bytes of the input.
Returns:
an IANA-encoding string
Since:
5.0.6


Copyright © 2013. All Rights Reserved.