Package com.itextpdf.xmp.impl
Class XMPNodeUtils
java.lang.Object
com.itextpdf.xmp.impl.XMPNodeUtils
- All Implemented Interfaces:
XMPConst
Utilities for
XMPNode
.- Since:
- Aug 28, 2006
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
(package private) static final int
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 -
Method Summary
Modifier and TypeMethodDescription(package private) static void
appendLangItem
(XMPNode arrayNode, String itemLang, String itemValue) Appends a language item to an alt text array.(package private) static Object[]
chooseLocalizedText
(XMPNode arrayNode, String genericLang, String specificLang) Look for an exact match with the specific language.(package private) static void
deleteNode
(XMPNode node) Deletes the the given node and its children from its parent.(package private) static void
detectAltText
(XMPNode arrayNode) See if an array is an alt-text array.(package private) static XMPNode
findChildNode
(XMPNode parent, String childName, boolean createNodes) Find or create a child node under a given parent node.private static int
findIndexedItem
(XMPNode arrayNode, String segment, boolean createNodes) (package private) static XMPNode
findNode
(XMPNode xmpTree, XMPPath xpath, boolean createNodes, PropertyOptions leafOptions) Follow an expanded path expression to find or create a node.private static XMPNode
findQualifierNode
(XMPNode parent, String qualName, boolean createNodes) Find or create a qualifier node under a given parent node.(package private) static XMPNode
findSchemaNode
(XMPNode tree, String namespaceURI, boolean createNodes) Find or create a schema node ifcreateNodes
is false and(package private) static XMPNode
findSchemaNode
(XMPNode tree, String namespaceURI, String suggestedPrefix, boolean createNodes) Find or create a schema node ifcreateNodes
is true.private static XMPNode
followXPathStep
(XMPNode parentNode, XMPPathSegment nextStep, boolean createNodes) After processing by ExpandXPath, a step can be of these forms: qualName - A top level property or struct field.private static int
lookupFieldSelector
(XMPNode arrayNode, String fieldName, String fieldValue) Searches for a field selector in a node: [fieldName="value] - an element in an array of structs, chosen by a field value.(package private) static int
lookupLanguageItem
(XMPNode arrayNode, String language) Looks for the appropriate language item in a text alternative array.itemprivate static int
lookupQualSelector
(XMPNode arrayNode, String qualName, String qualValue, int aliasForm) Searches for a qualifier selector in a node: [?qualName="value"] - an element in an array, chosen by a qualifier value.(package private) static void
normalizeLangArray
(XMPNode arrayNode) Make sure the x-default item is first.(package private) static String
serializeNodeValue
(Object value) Converts the node value to String, apply special conversions for defined types in XMP.(package private) static void
setNodeValue
(XMPNode node, Object value) This is setting the value of a leaf node.(package private) static PropertyOptions
verifySetOptions
(PropertyOptions options, Object itemValue) Verifies the PropertyOptions for consistancy and updates them as needed.
-
Field Details
-
CLT_NO_VALUES
static final int CLT_NO_VALUES- See Also:
-
CLT_SPECIFIC_MATCH
static final int CLT_SPECIFIC_MATCH- See Also:
-
CLT_SINGLE_GENERIC
static final int CLT_SINGLE_GENERIC- See Also:
-
CLT_MULTIPLE_GENERIC
static final int CLT_MULTIPLE_GENERIC- See Also:
-
CLT_XDEFAULT
static final int CLT_XDEFAULT- See Also:
-
CLT_FIRST_ITEM
static final int CLT_FIRST_ITEM- See Also:
-
-
Constructor Details
-
XMPNodeUtils
private XMPNodeUtils()Private Constructor
-
-
Method Details
-
findSchemaNode
static XMPNode findSchemaNode(XMPNode tree, String namespaceURI, boolean createNodes) throws XMPException Find or create a schema node ifcreateNodes
is false and- Parameters:
tree
- the root of the xmp tree.namespaceURI
- a namespacecreateNodes
- a flag indicating if the node shall be created if not found. Note: The namespace must be registered prior to this call.- Returns:
- Returns the schema node if found,
null
otherwise. Note: IfcreateNodes
istrue
, it is always returned a valid node. - Throws:
XMPException
- An exception is only thrown if an error occurred, not if a node was not found.
-
findSchemaNode
static XMPNode findSchemaNode(XMPNode tree, String namespaceURI, String suggestedPrefix, boolean createNodes) throws XMPException Find or create a schema node ifcreateNodes
is true.- Parameters:
tree
- the root of the xmp tree.namespaceURI
- a namespacesuggestedPrefix
- If a prefix is suggested, the namespace is allowed to be registered.createNodes
- a flag indicating if the node shall be created if not found. Note: The namespace must be registered prior to this call.- Returns:
- Returns the schema node if found,
null
otherwise. Note: IfcreateNodes
istrue
, it is always returned a valid node. - Throws:
XMPException
- An exception is only thrown if an error occurred, not if a node was not found.
-
findChildNode
static XMPNode findChildNode(XMPNode parent, String childName, boolean createNodes) throws XMPException Find or create a child node under a given parent node. If the parent node is no Returns the found or created child node.- Parameters:
parent
- the parent nodechildName
- the node name to findcreateNodes
- flag, if new nodes shall be created.- Returns:
- Returns the found or created node or
null
. - Throws:
XMPException
- Thrown if
-
findNode
static XMPNode findNode(XMPNode xmpTree, XMPPath xpath, boolean createNodes, PropertyOptions leafOptions) throws XMPException Follow an expanded path expression to find or create a node.- Parameters:
xmpTree
- the node to begin the search.xpath
- the complete xpathcreateNodes
- flag if nodes shall be created (when called bysetProperty()
)leafOptions
- the options for the created leaf nodes (only whencreateNodes == true
).- Returns:
- Returns the node if found or created or
null
. - Throws:
XMPException
- An exception is only thrown if an error occurred, not if a node was not found.
-
deleteNode
Deletes the the given node and its children from its parent. Takes care about adjusting the flags.- Parameters:
node
- the top-most node to delete.
-
setNodeValue
This is setting the value of a leaf node.- Parameters:
node
- an XMPNodevalue
- a value
-
verifySetOptions
static PropertyOptions verifySetOptions(PropertyOptions options, Object itemValue) throws XMPException Verifies the PropertyOptions for consistancy and updates them as needed. If options arenull
they are created with default values.- Parameters:
options
- thePropertyOptions
itemValue
- the node value to set- Returns:
- Returns the updated options.
- Throws:
XMPException
- If the options are not consistant.
-
serializeNodeValue
Converts the node value to String, apply special conversions for defined types in XMP.- Parameters:
value
- the node value to set- Returns:
- Returns the String representation of the node value.
-
followXPathStep
private static XMPNode followXPathStep(XMPNode parentNode, XMPPathSegment nextStep, boolean createNodes) throws XMPException After processing by ExpandXPath, a step can be of these forms:- qualName - A top level property or struct field.
- [index] - An element of an array.
- [last()] - The last element of an array.
- [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.
- ?qualName - A general qualifier.
- Parameters:
parentNode
- the node to start to start fromnextStep
- the xpath segmentcreateNodes
-- Returns:
- returns the found or created XMPPath node
- Throws:
XMPException
-
findQualifierNode
private static XMPNode findQualifierNode(XMPNode parent, String qualName, boolean createNodes) throws XMPException Find or create a qualifier node under a given parent node. Returns a pointer to the qualifier node, and optionally an iterator for the node's position in the parent's vector of qualifiers. The iterator is unchanged if no qualifier node (null) is returned. Note: On entry, the qualName parameter must not have the leading '?' from the XMPPath step.- Parameters:
parent
- the parent XMPNodequalName
- the qualifier namecreateNodes
- flag if nodes shall be created- Returns:
- Returns the qualifier node if found or created,
null
otherwise. - Throws:
XMPException
-
findIndexedItem
private static int findIndexedItem(XMPNode arrayNode, String segment, boolean createNodes) throws XMPException - Parameters:
arrayNode
- an array nodesegment
- the segment containing the array indexcreateNodes
- flag if new nodes are allowed to be created.- Returns:
- Returns the index or index = -1 if not found
- Throws:
XMPException
- Throws Exceptions
-
lookupFieldSelector
private static int lookupFieldSelector(XMPNode arrayNode, String fieldName, String fieldValue) throws XMPException Searches for a field selector in a node: [fieldName="value] - an element in an array of structs, chosen by a field value. No implicit nodes are created by field selectors.- Parameters:
arrayNode
-fieldName
-fieldValue
-- Returns:
- Returns the index of the field if found, otherwise -1.
- Throws:
XMPException
-
lookupQualSelector
private static int lookupQualSelector(XMPNode arrayNode, String qualName, String qualValue, int aliasForm) throws XMPException Searches for a qualifier selector in a node: [?qualName="value"] - an element in an array, chosen by a qualifier value. No implicit nodes are created for qualifier selectors, except for an alias to an x-default item.- Parameters:
arrayNode
- an array nodequalName
- the qualifier namequalValue
- the qualifier valuealiasForm
- in case the qual selector results from an alias, an x-default node is created if there has not been one.- Returns:
- Returns the index of th
- Throws:
XMPException
-
normalizeLangArray
Make sure the x-default item is first. Touch up "single value" arrays that have a default plus one real language. This case should have the same value for both items. Older Adobe apps were hardwired to only use the "x-default" item, so we copy that value to the other item.- Parameters:
arrayNode
- an alt text array node
-
detectAltText
See if an array is an alt-text array. If so, make sure the x-default item is first.- Parameters:
arrayNode
- the array node to check if its an alt-text array
-
appendLangItem
static void appendLangItem(XMPNode arrayNode, String itemLang, String itemValue) throws XMPException Appends a language item to an alt text array.- Parameters:
arrayNode
- the language arrayitemLang
- the language of the itemitemValue
- the content of the item- Throws:
XMPException
- Thrown if a duplicate property is added
-
chooseLocalizedText
static Object[] chooseLocalizedText(XMPNode arrayNode, String genericLang, String specificLang) throws XMPException - Look for an exact match with the specific language.
- If a generic language is given, look for partial matches.
- Look for an "x-default"-item.
- Choose the first item.
- Parameters:
arrayNode
- the alt text array nodegenericLang
- the generic languagespecificLang
- the specific language- Returns:
- Returns the kind of match as an Integer and the found node in an array.
- Throws:
XMPException
-
lookupLanguageItem
Looks for the appropriate language item in a text alternative array.item- Parameters:
arrayNode
- an array nodelanguage
- the requested language- Returns:
- Returns the index if the language has been found, -1 otherwise.
- Throws:
XMPException
-