Package com.itextpdf.xmp.impl
Class Utils
- java.lang.Object
-
- com.itextpdf.xmp.impl.Utils
-
-
Field Summary
Fields Modifier and Type Field Description static intUUID_LENGTHlength of a UUIDstatic intUUID_SEGMENT_COUNTsegments of a UUIDprivate static boolean[]xmlNameCharstable of XML name chars (<= 0xFF)private static boolean[]xmlNameStartCharstable of XML name start chars (<= 0xFF)-
Fields inherited from interface com.itextpdf.xmp.XMPConst
ARRAY_ITEM_NAME, ARRAY_LAST_ITEM, FALSESTR, NS_ADOBESTOCKPHOTO, NS_ASF, NS_BWF, NS_CAMERARAW, NS_CREATOR_ATOM, NS_DC, NS_DC_DEPRECATED, NS_DICOM, NS_DM, NS_EXIF, NS_EXIF_AUX, NS_EXIFX, NS_IPTCCORE, NS_IPTCEXT, NS_IX, NS_JP2K, NS_JPEG, NS_PDF, NS_PDFA_EXTENSION, NS_PDFA_FIELD, NS_PDFA_ID, NS_PDFA_PROPERTY, NS_PDFA_SCHEMA, NS_PDFA_TYPE, NS_PDFUA_ID, NS_PDFX, NS_PDFX_ID, NS_PHOTOSHOP, NS_PLUS, NS_PNG, NS_PSALBUM, NS_RDF, NS_RIFFINFO, NS_SCRIPT, NS_SWF, NS_TIFF, NS_TRANSIENT, NS_TXMP, NS_WAV, NS_X, NS_XML, NS_XMP, NS_XMP_BJ, NS_XMP_MM, NS_XMP_NOTE, NS_XMP_RIGHTS, RDF_TYPE, TAG_XAPMETA, TAG_XMPMETA, TRUESTR, TYPE_DIMENSIONS, TYPE_FONT, TYPE_GRAPHICS, TYPE_IDENTIFIERQUAL, TYPE_IMAGE, TYPE_MANIFESTITEM, TYPE_PAGEDFILE, TYPE_RESOURCEEVENT, TYPE_RESOURCEREF, TYPE_ST_JOB, TYPE_ST_VERSION, TYPE_TEXT, X_DEFAULT, XML_LANG, XMP_PI
-
-
Constructor Summary
Constructors Modifier Constructor Description privateUtils()Private constructor
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static booleancheckUUIDFormat(java.lang.String uuid)Check some requirements for an UUID: Length of the UUID is 32 The Delimiter count is 4 and all the 4 delimiter are on their right position (8,13,18,23)static java.lang.StringescapeXML(java.lang.String value, boolean forAttribute, boolean escapeWhitespaces)Serializes the node value in XML encoding.private static voidinitCharTables()Initializes the char tables for the chars 0x00-0xFF for later use, according to the XML 1.1 specification http://www.w3.org/TR/xml11(package private) static booleanisControlChar(char c)(package private) static booleanisInternalProperty(java.lang.String schema, java.lang.String prop)private static booleanisNameChar(char ch)Simple check if a character is a valid XML name char (every char except the first one), according to the XML Spec 1.1: http://www.w3.org/TR/xml11/#NT-NameCharprivate static booleanisNameStartChar(char ch)Simple check if a character is a valid XML start name char.static booleanisXMLName(java.lang.String name)Simple check for valid XMLNames.static booleanisXMLNameNS(java.lang.String name)Checks if the value is a legal "unqualified" XML name, as defined in the XML Namespaces proposed recommendation.static java.lang.StringnormalizeLangValue(java.lang.String value)Normalize an xml:lang value so that comparisons are effectively case insensitive as required by RFC 3066 (which superceeds RFC 1766).(package private) static java.lang.StringremoveControlChars(java.lang.String value)Replaces the ASCII control chars with a space.(package private) static java.lang.String[]splitNameAndValue(java.lang.String selector)Split the name and value parts for field and qualifier selectors: [qualName="value"] - An element in an array of structs, chosen by a field value.
-
-
-
Field Detail
-
UUID_SEGMENT_COUNT
public static final int UUID_SEGMENT_COUNT
segments of a UUID- See Also:
- Constant Field Values
-
UUID_LENGTH
public static final int UUID_LENGTH
length of a UUID- See Also:
- Constant Field Values
-
xmlNameStartChars
private static boolean[] xmlNameStartChars
table of XML name start chars (<= 0xFF)
-
xmlNameChars
private static boolean[] xmlNameChars
table of XML name chars (<= 0xFF)
-
-
Method Detail
-
normalizeLangValue
public static java.lang.String normalizeLangValue(java.lang.String value)
Normalize an xml:lang value so that comparisons are effectively case insensitive as required by RFC 3066 (which superceeds RFC 1766). The normalization rules:- The primary subtag is lower case, the suggested practice of ISO 639.
- All 2 letter secondary subtags are upper case, the suggested practice of ISO 3166.
- All other subtags are lower case.
- Parameters:
value- raw value- Returns:
- Returns the normalized value.
-
splitNameAndValue
static java.lang.String[] splitNameAndValue(java.lang.String selector)
Split the name and value parts for field and qualifier selectors:- [qualName="value"] - An element in an array of structs, chosen by a field value.
- [?qualName="value"] - An element in an array, chosen by a qualifier value.
- Parameters:
selector- the selector- Returns:
- Returns an array where the first entry contains the name and the second the value.
-
isInternalProperty
static boolean isInternalProperty(java.lang.String schema, java.lang.String prop)- Parameters:
schema- a schema namespaceprop- an XMP Property- Returns:
- Returns true if the property is defined as "Internal Property", see XMP Specification.
-
checkUUIDFormat
static boolean checkUUIDFormat(java.lang.String uuid)
Check some requirements for an UUID:- Length of the UUID is 32
- The Delimiter count is 4 and all the 4 delimiter are on their right position (8,13,18,23)
- Parameters:
uuid- uuid to test- Returns:
- true - this is a well formed UUID, false - UUID has not the expected format
-
isXMLName
public static boolean isXMLName(java.lang.String name)
Simple check for valid XMLNames. Within ASCII range
":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6]
are accepted, above all characters (which is not entirely correct according to the XML Spec.- Parameters:
name- an XML Name- Returns:
- Return
trueif the name is correct.
-
isXMLNameNS
public static boolean isXMLNameNS(java.lang.String name)
Checks if the value is a legal "unqualified" XML name, as defined in the XML Namespaces proposed recommendation. These are XML names, except that they must not contain a colon.- Parameters:
name- the value to check- Returns:
- Returns true if the name is a valid "unqualified" XML name.
-
isControlChar
static boolean isControlChar(char c)
- Parameters:
c- a char- Returns:
- Returns true if the char is an ASCII control char.
-
escapeXML
public static java.lang.String escapeXML(java.lang.String value, boolean forAttribute, boolean escapeWhitespaces)Serializes the node value in XML encoding. Its used for tag bodies and attributes.
Note: The attribute is always limited by quotes, thats why'is never serialized.
Note: Control chars are written unescaped, but if the user uses others than tab, LF and CR the resulting XML will become invalid.- Parameters:
value- a stringforAttribute- flag if string is attribute value (need to additional escape quotes)escapeWhitespaces- Decides if LF, CR and TAB are escaped.- Returns:
- Returns the value ready for XML output.
-
removeControlChars
static java.lang.String removeControlChars(java.lang.String value)
Replaces the ASCII control chars with a space.- Parameters:
value- a node value- Returns:
- Returns the cleaned up value
-
isNameStartChar
private static boolean isNameStartChar(char ch)
Simple check if a character is a valid XML start name char. All characters according to the XML Spec 1.1 are accepted: http://www.w3.org/TR/xml11/#NT-NameStartChar- Parameters:
ch- a character- Returns:
- Returns true if the character is a valid first char of an XML name.
-
isNameChar
private static boolean isNameChar(char ch)
Simple check if a character is a valid XML name char (every char except the first one), according to the XML Spec 1.1: http://www.w3.org/TR/xml11/#NT-NameChar- Parameters:
ch- a character- Returns:
- Returns true if the character is a valid char of an XML name.
-
initCharTables
private static void initCharTables()
Initializes the char tables for the chars 0x00-0xFF for later use, according to the XML 1.1 specification http://www.w3.org/TR/xml11
-
-