Top Description Fields Constructors Methods
org.jdom2

public final Class Verifier

extends Object
Class Inheritance
Imports
java.util.*

A utility class to handle well-formedness checks on names, data, and other verification tasks for JDOM. The class is final and may not be subclassed.
Authors
Brett McLaughlin, Elliotte Rusty Harold, Jason Hunter, Bradley S. Huffman, Rolf Lear, Wilfried Middleton

Field Summary

Modifier and TypeField and Description
private static final int
CHARCNT

The number of characters in Java.

private static final byte[]
CHARFLAGS

An array of byte where each byte represents the roles that the corresponding character can play.

private static final int[]
LENCONST

The seed array used with VALCONST to populate CHARFLAGS.

private static final byte
MASKURICHAR

Mask used to test for isURICharacter(char)

private static final byte
private static final byte
private static final byte
MASKXMLDIGIT

Mask used to test for isXMLDigit(char)

private static final byte
MASKXMLLETTER

Mask used to test for isXMLLetter(char)

private static final byte
private static final byte
private static final byte
private static final byte[]
VALCONST

The seed array used with LENCONST to populate CHARFLAGS.

Constructor Summary

AccessConstructor and Description
private
Verifier()

Ensure instantiation cannot occur.

Method Summary

Modifier and TypeMethod and Description
private static final byte[]

Returns:

the CHARFLAGS array.
buildBitFlags
()

Convert the two compressed arrays in to th CHARFLAGS array.

public static String

Returns:

String reason name is illegal, or null if name is OK.
checkAttributeName
(final String
String name to check.
name
)

This will check the supplied name to see if it is legal for use as a JDOM Attribute name.

public static String

Returns:

String reason data is illegal, or null is name is OK.
checkCDATASection
(final String
String data to check.
data
)

This will check the supplied data to see if it is legal for use as JDOM CDATA.

public static String

Returns:

String reason name is illegal, or null if name is OK.
checkCharacterData
(final String
String value to check.
text
)

This will check the supplied string to see if it only contains characters allowed by the XML 1.0 specification.

public static String

Returns:

String reason data is illegal, or null if data is OK.
checkCommentData
(final String
String data to check.
data
)

This will check the supplied data to see if it is legal for use as JDOM Comment data.

public static String

Returns:

String reason name is illegal, or null if name is OK.
checkElementName
(final String
String name to check.
name
)

This will check the supplied name to see if it is legal for use as a JDOM Element name.

private static final String
checkJDOMName(final String name)

public static String

Returns:

String reason for collision, or null if no collision.
checkNamespaceCollision
(final Namespace
Namespace to check.
namespace
,
final Namespace
Namespace to check against.
other
)

Check if two namespaces collide.

public static String

Returns:

String reason for collision, or null if no collision.
checkNamespaceCollision
(final Attribute
Attribute to check.
attribute
,
final Element
Element to check against.
element
)

Check if Attribute's namespace collides with a Element's namespace.

public static String

Returns:

String reason for collision, or null if no collision.
checkNamespaceCollision
(final Attribute
Attribute to check.
attribute
,
final Element
Element to check against.
element
,
final int
Ignore a specific Attribute (if it exists) when calculating any collisions (used when replacing one attribute with another).
ignoreatt
)

Check if Attribute's namespace collides with a Element's namespace.

public static String

Returns:

String reason for collision, or null if no collision.
checkNamespaceCollision
(final Namespace
Namespace to check.
namespace
,
final Element
Element to check against.
element
)

Check if a Namespace collides with a Element's namespace.

public static String

Returns:

String reason for collision, or null if no collision.
checkNamespaceCollision
(final Namespace
Namespace to check.
namespace
,
final Element
Element to check against.
element
,
final int
Ignore a specific Attribute (if it exists) when calculating any collisions (used when replacing one attribute with another).
ignoreatt
)

Check if a Namespace collides with a Element's namespace.

public static String

Returns:

String reason for collision, or null if no collision.
checkNamespaceCollision
(final Namespace
Namespace to check.
namespace
,
final Attribute
Attribute to check against.
attribute
)

Check if a Namespace collides with a Attribute's namespace.

public static String

Returns:

String reason for collision, or null if no collision.
checkNamespaceCollision
(final Namespace
Namespace to check.
namespace
,
final List<?>
List to check against.
list
)

Check if a Namespace collides with any namespace from a list of objects.

public static String

Returns:

String reason for collision, or null if no collision.
checkNamespaceCollision
(final Namespace
Namespace to check.
namespace
,
final List<?>
List to check against.
list
,
final int
Ignore a specific Attribute (if it exists) when calculating any collisions (used when replacing one attribute with another).
ignoreatt
)

Check if a Namespace collides with any namespace from a list of objects.

public static String

Returns:

String reason name is illegal, or null if name is OK.
checkNamespacePrefix
(final String
String prefix to check.
prefix
)

This will check the supplied name to see if it is legal for use as a JDOM Namespace prefix.

public static String

Returns:

String reason name is illegal, or null if name is OK.
checkNamespaceURI
(final String
String URI to check.
uri
)

This will check the supplied name to see if it is legal for use as a JDOM Namespace URI.

public static String

Returns:

String reason data is illegal, or null if data is OK.
checkProcessingInstructionData
(final String
String data to check.
data
)

This will check the supplied data to see if it is legal for use as ProcessingInstruction data.

public static String

Returns:

String reason target is illegal, or null if target is OK.
checkProcessingInstructionTarget
(final String
String target to check.
target
)

This will check the supplied data to see if it is legal for use as a JDOM ProcessingInstruction target.

public static String

Returns:

String reason public ID is illegal, or null if public ID is OK.
checkPublicID
(final String
String public ID to check.
publicID
)

This will ensure that the data for a public identifier is legal.

public static String

Returns:

String reason system literal is illegal, or null if system literal is OK.
checkSystemLiteral
(final String
String system literal to check.
systemLiteral
)

This will ensure that the data for a system literal is legal.

public static String

Returns:

String reason the URI is illegal, or null if OK.
checkURI
(final String
String to check.
uri
)

Checks a string to see if it is a legal RFC 2396 URI.

public static String

Returns:

String reason the name is illegal, or null if OK.
checkXMLName
(final String
String to check for XML name compliance.
name
)

This is a utility function for sharing the base process of checking any XML name.

public static int

Returns:

decoded character
decodeSurrogatePair
(final char
high 16 bits
high
,
final char
low 16 bits
low
)

This is a utility function to decode a non-BMP UTF-16 surrogate pair.

public static final boolean

Returns:

true if all characters in the input value are all whitespace (or the string is the empty-string).
isAllXMLWhitespace
(final String
The value to inspect
value
)

This is a utility function for determining whether a specified String is a whitespace character according to production 3 of the XML 1.0 specification.

public static boolean

Returns:

true if it's allowed, false otherwise.
isHexDigit
(final char
to check for hex digit.
c
)

This is a utility function for determining whether a specified Unicode character is a hexadecimal digit as defined in RFC 2396; that is, one of the ASCII characters 0-9, a-f, or A-F.

public static boolean

Returns:

true if the character is a high surrogate, false otherwise
isHighSurrogate
(final char
character to check
ch
)

This is a function for determining whether the specified character is the high 16 bits in a UTF-16 surrogate pair.

public static boolean

Returns:

true if the character is a low surrogate, false otherwise.
isLowSurrogate
(final char
character to check
ch
)

This is a function for determining whether the specified character is the low 16 bits in a UTF-16 surrogate pair.

public static boolean

Returns:

true if it's allowed, false otherwise.
isURICharacter
(final char
char to check for URI reference compliance.
c
)

This is a utility function for determining whether a specified Unicode character is legal in URI references as determined by RFC 2396.

public static boolean

Returns:

boolean true if it's a character, false otherwise
isXMLCharacter
(final int
char to check for XML compliance
c
)

This is a utility function for determining whether a specified character is a character according to production 2 of the XML 1.0 specification.

public static boolean

Returns:

boolean true if it's a combining character, false otherwise.
isXMLCombiningChar
(final char
char to check.
c
)

This is a utility function for determining whether a specified character is a combining character according to production 87 of the XML 1.0 specification.

public static boolean

Returns:

boolean true if it's a digit, false otherwise
isXMLDigit
(final char
char to check for XML digit compliance
c
)

This is a utility function for determining whether a specified Unicode character is a digit according to production 88 of the XML 1.0 specification.

public static boolean

Returns:

String true if it's an extender, false otherwise.
isXMLExtender
(final char
char to check.
c
)

This is a utility function for determining whether a specified character is an extender according to production 88 of the XML 1.0 specification.

public static boolean

Returns:

String true if it's a letter, false otherwise.
isXMLLetter
(final char
char to check for XML name compliance.
c
)

This is a utility function for determining whether a specified character is a letter according to production 84 of the XML 1.0 specification.

public static boolean

Returns:

boolean true if it's letter or digit, false otherwise.
isXMLLetterOrDigit
(final char
char to check.
c
)

This is a utility function for determining whether a specified character is a letter or digit according to productions 84 and 88 of the XML 1.0 specification.

public static boolean

Returns:

boolean true if it's a name character, false otherwise.
isXMLNameCharacter
(final char
char to check for XML name compliance.
c
)

This is a utility function for determining whether a specified character is a name character according to production 4 of the XML 1.0 specification.

public static boolean

Returns:

boolean true if it's a name start character, false otherwise.
isXMLNameStartCharacter
(final char
char to check for XML name start compliance.
c
)

This is a utility function for determining whether a specified character is a legal name start character according to production 5 of the XML 1.0 specification.

public static boolean

Returns:

String reason c is illegal, or null if c is OK.
isXMLPublicIDCharacter
(final char
the character to validate
c
)

This will check the supplied data to see if it is legal for use as PublicID (in a DocType or EntityRef).

public static boolean

Returns:

boolean true if it's a whitespace, false otherwise
isXMLWhitespace
(final char
char to check for XML whitespace compliance
c
)

This is a utility function for determining whether a specified Unicode character is a whitespace character according to production 3 of the XML 1.0 specification.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CHARCNTback to summary
private static final int CHARCNT

The number of characters in Java.

CHARFLAGSback to summary
private static final byte[] CHARFLAGS

An array of byte where each byte represents the roles that the corresponding character can play. Use the bit mask values to access each character's role.

LENCONSTback to summary
private static final int[] LENCONST

The seed array used with VALCONST to populate CHARFLAGS.

MASKURICHARback to summary
private static final byte MASKURICHAR

Mask used to test for isURICharacter(char)

MASKXMLCHARACTERback to summary
private static final byte MASKXMLCHARACTER

Mask used to test for isXMLCharacter(int)

MASKXMLCOMBININGback to summary
private static final byte MASKXMLCOMBINING

Mask used to test for isXMLCombiningChar(char)

MASKXMLDIGITback to summary
private static final byte MASKXMLDIGIT

Mask used to test for isXMLDigit(char)

MASKXMLLETTERback to summary
private static final byte MASKXMLLETTER

Mask used to test for isXMLLetter(char)

MASKXMLLETTERORDIGITback to summary
private static final byte MASKXMLLETTERORDIGIT

Mask used to test for isXMLLetterOrDigit(char)

MASKXMLNAMECHARback to summary
private static final byte MASKXMLNAMECHAR

Mask used to test for isXMLNameCharacter(char)

MASKXMLSTARTCHARback to summary
private static final byte MASKXMLSTARTCHAR

Mask used to test for isXMLNameStartCharacter(char)

VALCONSTback to summary
private static final byte[] VALCONST

The seed array used with LENCONST to populate CHARFLAGS.

Constructor Detail

Verifierback to summary
private Verifier()

Ensure instantiation cannot occur.

Method Detail

buildBitFlagsback to summary
private static final byte[] buildBitFlags()

Convert the two compressed arrays in to th CHARFLAGS array.

Returns:byte[]

the CHARFLAGS array.

checkAttributeNameback to summary
public static String checkAttributeName(final String name)

This will check the supplied name to see if it is legal for use as a JDOM Attribute name.

Parameters
name:String

String name to check.

Returns:String

String reason name is illegal, or null if name is OK.

checkCDATASectionback to summary
public static String checkCDATASection(final String data)

This will check the supplied data to see if it is legal for use as JDOM CDATA.

Parameters
data:String

String data to check.

Returns:String

String reason data is illegal, or null is name is OK.

checkCharacterDataback to summary
public static String checkCharacterData(final String text)

This will check the supplied string to see if it only contains characters allowed by the XML 1.0 specification. The C0 controls (e.g. null, vertical tab, form-feed, etc.) are specifically excluded except for carriage return, line-feed, and the horizontal tab. Surrogates are also excluded.

This method is useful for checking element content and attribute values. Note that characters like " and < are allowed in attribute values and element content. They will simply be escaped as " or < when the value is serialized.

Parameters
text:String

String value to check.

Returns:String

String reason name is illegal, or null if name is OK.

checkCommentDataback to summary
public static String checkCommentData(final String data)

This will check the supplied data to see if it is legal for use as JDOM Comment data.

Parameters
data:String

String data to check.

Returns:String

String reason data is illegal, or null if data is OK.

checkElementNameback to summary
public static String checkElementName(final String name)

This will check the supplied name to see if it is legal for use as a JDOM Element name.

Parameters
name:String

String name to check.

Returns:String

String reason name is illegal, or null if name is OK.

checkJDOMNameback to summary
private static final String checkJDOMName(final String name)
checkNamespaceCollisionback to summary
public static String checkNamespaceCollision(final Namespace namespace, final Namespace other)

Check if two namespaces collide.

Parameters
namespace:Namespace

Namespace to check.

other:Namespace

Namespace to check against.

Returns:String

String reason for collision, or null if no collision.

checkNamespaceCollisionback to summary
public static String checkNamespaceCollision(final Attribute attribute, final Element element)

Check if Attribute's namespace collides with a Element's namespace.

Parameters
attribute:Attribute

Attribute to check.

element:Element

Element to check against.

Returns:String

String reason for collision, or null if no collision.

checkNamespaceCollisionback to summary
public static String checkNamespaceCollision(final Attribute attribute, final Element element, final int ignoreatt)

Check if Attribute's namespace collides with a Element's namespace.

Parameters
attribute:Attribute

Attribute to check.

element:Element

Element to check against.

ignoreatt:int

Ignore a specific Attribute (if it exists) when calculating any collisions (used when replacing one attribute with another).

Returns:String

String reason for collision, or null if no collision.

checkNamespaceCollisionback to summary
public static String checkNamespaceCollision(final Namespace namespace, final Element element)

Check if a Namespace collides with a Element's namespace.

Parameters
namespace:Namespace

Namespace to check.

element:Element

Element to check against.

Returns:String

String reason for collision, or null if no collision.

checkNamespaceCollisionback to summary
public static String checkNamespaceCollision(final Namespace namespace, final Element element, final int ignoreatt)

Check if a Namespace collides with a Element's namespace.

Parameters
namespace:Namespace

Namespace to check.

element:Element

Element to check against.

ignoreatt:int

Ignore a specific Attribute (if it exists) when calculating any collisions (used when replacing one attribute with another).

Returns:String

String reason for collision, or null if no collision.

checkNamespaceCollisionback to summary
public static String checkNamespaceCollision(final Namespace namespace, final Attribute attribute)

Check if a Namespace collides with a Attribute's namespace.

Parameters
namespace:Namespace

Namespace to check.

attribute:Attribute

Attribute to check against.

Returns:String

String reason for collision, or null if no collision.

checkNamespaceCollisionback to summary
public static String checkNamespaceCollision(final Namespace namespace, final List<?> list)

Check if a Namespace collides with any namespace from a list of objects.

Parameters
namespace:Namespace

Namespace to check.

list:List<?>

List to check against.

Returns:String

String reason for collision, or null if no collision.

checkNamespaceCollisionback to summary
public static String checkNamespaceCollision(final Namespace namespace, final List<?> list, final int ignoreatt)

Check if a Namespace collides with any namespace from a list of objects.

Parameters
namespace:Namespace

Namespace to check.

list:List<?>

List to check against.

ignoreatt:int

Ignore a specific Attribute (if it exists) when calculating any collisions (used when replacing one attribute with another).

Returns:String

String reason for collision, or null if no collision.

checkNamespacePrefixback to summary
public static String checkNamespacePrefix(final String prefix)

This will check the supplied name to see if it is legal for use as a JDOM Namespace prefix.

Parameters
prefix:String

String prefix to check.

Returns:String

String reason name is illegal, or null if name is OK.

checkNamespaceURIback to summary
public static String checkNamespaceURI(final String uri)

This will check the supplied name to see if it is legal for use as a JDOM Namespace URI.

This is a 'light' test of URI's designed to filter out only the worst illegal URIs. It tests only to ensure the first character is valid. A comprehensive URI validation process would be impractical.

Parameters
uri:String

String URI to check.

Returns:String

String reason name is illegal, or null if name is OK.

checkProcessingInstructionDataback to summary
public static String checkProcessingInstructionData(final String data)

This will check the supplied data to see if it is legal for use as ProcessingInstruction data. Besides checking that all the characters are allowed in XML, this also checks that the data does not contain the PI end-string "?>".

Parameters
data:String

String data to check.

Returns:String

String reason data is illegal, or null if data is OK.

checkProcessingInstructionTargetback to summary
public static String checkProcessingInstructionTarget(final String target)

This will check the supplied data to see if it is legal for use as a JDOM ProcessingInstruction target.

Parameters
target:String

String target to check.

Returns:String

String reason target is illegal, or null if target is OK.

checkPublicIDback to summary
public static String checkPublicID(final String publicID)

This will ensure that the data for a public identifier is legal.

Parameters
publicID:String

String public ID to check.

Returns:String

String reason public ID is illegal, or null if public ID is OK.

checkSystemLiteralback to summary
public static String checkSystemLiteral(final String systemLiteral)

This will ensure that the data for a system literal is legal.

Parameters
systemLiteral:String

String system literal to check.

Returns:String

String reason system literal is illegal, or null if system literal is OK.

checkURIback to summary
public static String checkURI(final String uri)

Checks a string to see if it is a legal RFC 2396 URI. Both absolute and relative URIs are supported.

Parameters
uri:String

String to check.

Returns:String

String reason the URI is illegal, or null if OK.

checkXMLNameback to summary
public static String checkXMLName(final String name)

This is a utility function for sharing the base process of checking any XML name.

Parameters
name:String

String to check for XML name compliance.

Returns:String

String reason the name is illegal, or null if OK.

decodeSurrogatePairback to summary
public static int decodeSurrogatePair(final char high, final char low)

This is a utility function to decode a non-BMP UTF-16 surrogate pair.

Parameters
high:char

high 16 bits

low:char

low 16 bits

Returns:int

decoded character

isAllXMLWhitespaceback to summary
public static final boolean isAllXMLWhitespace(final String value)

This is a utility function for determining whether a specified String is a whitespace character according to production 3 of the XML 1.0 specification.

This method delegates the individual calls for each character to isXMLWhitespace(char).

Parameters
value:String

The value to inspect

Returns:boolean

true if all characters in the input value are all whitespace (or the string is the empty-string).

Since
JDOM2
isHexDigitback to summary
public static boolean isHexDigit(final char c)

This is a utility function for determining whether a specified Unicode character is a hexadecimal digit as defined in RFC 2396; that is, one of the ASCII characters 0-9, a-f, or A-F.

Parameters
c:char

to check for hex digit.

Returns:boolean

true if it's allowed, false otherwise.

isHighSurrogateback to summary
public static boolean isHighSurrogate(final char ch)

This is a function for determining whether the specified character is the high 16 bits in a UTF-16 surrogate pair.

Parameters
ch:char

character to check

Returns:boolean

true if the character is a high surrogate, false otherwise

isLowSurrogateback to summary
public static boolean isLowSurrogate(final char ch)

This is a function for determining whether the specified character is the low 16 bits in a UTF-16 surrogate pair.

Parameters
ch:char

character to check

Returns:boolean

true if the character is a low surrogate, false otherwise.

isURICharacterback to summary
public static boolean isURICharacter(final char c)

This is a utility function for determining whether a specified Unicode character is legal in URI references as determined by RFC 2396.

Parameters
c:char

char to check for URI reference compliance.

Returns:boolean

true if it's allowed, false otherwise.

isXMLCharacterback to summary
public static boolean isXMLCharacter(final int c)

This is a utility function for determining whether a specified character is a character according to production 2 of the XML 1.0 specification.

Parameters
c:int

char to check for XML compliance

Returns:boolean

boolean true if it's a character, false otherwise

isXMLCombiningCharback to summary
public static boolean isXMLCombiningChar(final char c)

This is a utility function for determining whether a specified character is a combining character according to production 87 of the XML 1.0 specification.

Parameters
c:char

char to check.

Returns:boolean

boolean true if it's a combining character, false otherwise.

isXMLDigitback to summary
public static boolean isXMLDigit(final char c)

This is a utility function for determining whether a specified Unicode character is a digit according to production 88 of the XML 1.0 specification.

Parameters
c:char

char to check for XML digit compliance

Returns:boolean

boolean true if it's a digit, false otherwise

isXMLExtenderback to summary
public static boolean isXMLExtender(final char c)

This is a utility function for determining whether a specified character is an extender according to production 88 of the XML 1.0 specification.

Parameters
c:char

char to check.

Returns:boolean

String true if it's an extender, false otherwise.

isXMLLetterback to summary
public static boolean isXMLLetter(final char c)

This is a utility function for determining whether a specified character is a letter according to production 84 of the XML 1.0 specification.

Parameters
c:char

char to check for XML name compliance.

Returns:boolean

String true if it's a letter, false otherwise.

isXMLLetterOrDigitback to summary
public static boolean isXMLLetterOrDigit(final char c)

This is a utility function for determining whether a specified character is a letter or digit according to productions 84 and 88 of the XML 1.0 specification.

Parameters
c:char

char to check.

Returns:boolean

boolean true if it's letter or digit, false otherwise.

isXMLNameCharacterback to summary
public static boolean isXMLNameCharacter(final char c)

This is a utility function for determining whether a specified character is a name character according to production 4 of the XML 1.0 specification.

Parameters
c:char

char to check for XML name compliance.

Returns:boolean

boolean true if it's a name character, false otherwise.

isXMLNameStartCharacterback to summary
public static boolean isXMLNameStartCharacter(final char c)

This is a utility function for determining whether a specified character is a legal name start character according to production 5 of the XML 1.0 specification. This production does allow names to begin with colons which the Namespaces in XML Recommendation disallows.

Parameters
c:char

char to check for XML name start compliance.

Returns:boolean

boolean true if it's a name start character, false otherwise.

isXMLPublicIDCharacterback to summary
public static boolean isXMLPublicIDCharacter(final char c)

This will check the supplied data to see if it is legal for use as PublicID (in a DocType or EntityRef).

Parameters
c:char

the character to validate

Returns:boolean

String reason c is illegal, or null if c is OK.

isXMLWhitespaceback to summary
public static boolean isXMLWhitespace(final char c)

This is a utility function for determining whether a specified Unicode character is a whitespace character according to production 3 of the XML 1.0 specification.

Parameters
c:char

char to check for XML whitespace compliance

Returns:boolean

boolean true if it's a whitespace, false otherwise