Package com.itextpdf.xmp.impl
Class XMPNode
- java.lang.Object
-
- com.itextpdf.xmp.impl.XMPNode
-
- All Implemented Interfaces:
java.lang.Comparable
class XMPNode extends java.lang.Object implements java.lang.ComparableA node in the internally XMP tree, which can be a schema node, a property node, an array node, an array item, a struct node or a qualifier node (without '?'). Possible improvements: 1. The kind Node of node might be better represented by a class-hierarchy of different nodes. 2. The array type should be an enum 3. isImplicitNode should be removed completely and replaced by return values of fi. 4. hasLanguage, hasType should be automatically maintained by XMPNode- Since:
- 21.02.2006
-
-
Field Summary
Fields Modifier and Type Field Description private booleanaliasflag if the node is an aliasprivate java.util.Listchildrenlist of child nodes, lazy initializedprivate booleanhasAliasesflag if the node has aliasesprivate booleanhasValueChildflag if the node has an "rdf:value" child node.private booleanimplicitflag if the node is implicitly createdprivate java.lang.Stringnamename of the node, contains different information depending of the node kindprivate PropertyOptionsoptionsoptions describing the kind of the nodeprivate XMPNodeparentlink to the parent nodeprivate java.util.Listqualifierlist of qualifier of the node, lazy initializedprivate java.lang.Stringvaluevalue of the node, contains different information depending of the node kind
-
Constructor Summary
Constructors Constructor Description XMPNode(java.lang.String name, PropertyOptions options)Constructor for the node without value.XMPNode(java.lang.String name, java.lang.String value, PropertyOptions options)Creates anXMPNodewith initial values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(int index, XMPNode node)Adds a node as child to this node.voidaddChild(XMPNode node)Adds a node as child to this node.voidaddQualifier(XMPNode qualNode)Appends a qualifier to the qualifier list and sets respective options.private voidassertChildNotExisting(java.lang.String childName)Checks that a node name is not existing on the same level, except for array items.private voidassertQualifierNotExisting(java.lang.String qualifierName)Checks that a qualifier name is not existing on the same level.protected voidcleanupChildren()Removes the children list if this node has no children anymore; checks if the provided node is a schema node and doesn't have any children anymore, its deleted.voidclear()Resets the node.java.lang.Objectclone()Performs a deep clone of the node and the complete subtree.voidcloneSubtree(XMPNode destination)Performs a deep clone of the complete subtree (children and qualifier )into and add it to the destination node.intcompareTo(java.lang.Object xmpNode)java.lang.StringdumpNode(boolean recursive)Renders this node and the tree unter this node in a human readable form.private voiddumpNode(java.lang.StringBuffer result, boolean recursive, int indent, int index)Dumps this node and its qualifier and children recursively.private XMPNodefind(java.util.List list, java.lang.String expr)Internal find.XMPNodefindChildByName(java.lang.String expr)XMPNodefindQualifierByName(java.lang.String expr)XMPNodegetChild(int index)private java.util.ListgetChildren()Note: This method should always be called when accessing 'children' to be sure that its initialized.intgetChildrenLength()booleangetHasAliases()booleangetHasValueChild()java.lang.StringgetName()PropertyOptionsgetOptions()XMPNodegetParent()private java.util.ListgetQualifier()XMPNodegetQualifier(int index)intgetQualifierLength()java.util.ListgetUnmodifiableChildren()java.lang.StringgetValue()booleanhasChildren()booleanhasQualifier()booleanisAlias()booleanisImplicit()private booleanisLanguageNode()private booleanisTypeNode()java.util.IteratoriterateChildren()java.util.IteratoriterateQualifier()voidremoveChild(int itemIndex)Removes a child at the requested index.voidremoveChild(XMPNode node)Removes a child node.voidremoveChildren()Removes all children from the node.voidremoveQualifier(XMPNode qualNode)Removes one qualifier node and fixes the options.voidremoveQualifiers()Removes all qualifiers from the node and sets the options appropriate.voidreplaceChild(int index, XMPNode node)Replaces a node with another one.voidsetAlias(boolean alias)voidsetHasAliases(boolean hasAliases)voidsetHasValueChild(boolean hasValueChild)voidsetImplicit(boolean implicit)voidsetName(java.lang.String name)voidsetOptions(PropertyOptions options)Updates the options of the node.protected voidsetParent(XMPNode parent)Sets the parent node, this is solely done byaddChild(...)andaddQualifier().voidsetValue(java.lang.String value)voidsort()Sorts the complete datamodel according to the following rules: Nodes at one level are sorted by name, that is prefix + local name Starting at the root node the children and qualifier are sorted recursively, which the following exceptions.
-
-
-
Field Detail
-
name
private java.lang.String name
name of the node, contains different information depending of the node kind
-
value
private java.lang.String value
value of the node, contains different information depending of the node kind
-
parent
private XMPNode parent
link to the parent node
-
children
private java.util.List children
list of child nodes, lazy initialized
-
qualifier
private java.util.List qualifier
list of qualifier of the node, lazy initialized
-
options
private PropertyOptions options
options describing the kind of the node
-
implicit
private boolean implicit
flag if the node is implicitly created
-
hasAliases
private boolean hasAliases
flag if the node has aliases
-
alias
private boolean alias
flag if the node is an alias
-
hasValueChild
private boolean hasValueChild
flag if the node has an "rdf:value" child node.
-
-
Constructor Detail
-
XMPNode
public XMPNode(java.lang.String name, java.lang.String value, PropertyOptions options)Creates anXMPNodewith initial values.- Parameters:
name- the name of the nodevalue- the value of the nodeoptions- the options of the node
-
XMPNode
public XMPNode(java.lang.String name, PropertyOptions options)Constructor for the node without value.- Parameters:
name- the name of the nodeoptions- the options of the node
-
-
Method Detail
-
clear
public void clear()
Resets the node.
-
getParent
public XMPNode getParent()
- Returns:
- Returns the parent node.
-
getChild
public XMPNode getChild(int index)
- Parameters:
index- an index [1..size]- Returns:
- Returns the child with the requested index.
-
addChild
public void addChild(XMPNode node) throws XMPException
Adds a node as child to this node.- Parameters:
node- an XMPNode- Throws:
XMPException
-
addChild
public void addChild(int index, XMPNode node) throws XMPExceptionAdds a node as child to this node.- Parameters:
index- the index of the node before which the new one is inserted. Note: The node children are indexed from [1..size]! An index of size + 1 appends a node.node- an XMPNode- Throws:
XMPException
-
replaceChild
public void replaceChild(int index, XMPNode node)Replaces a node with another one.- Parameters:
index- the index of the node that will be replaced. Note: The node children are indexed from [1..size]!node- the replacement XMPNode
-
removeChild
public void removeChild(int itemIndex)
Removes a child at the requested index.- Parameters:
itemIndex- the index to remove [1..size]
-
removeChild
public void removeChild(XMPNode node)
Removes a child node. If its a schema node and doesn't have any children anymore, its deleted.- Parameters:
node- the child node to delete.
-
cleanupChildren
protected void cleanupChildren()
Removes the children list if this node has no children anymore; checks if the provided node is a schema node and doesn't have any children anymore, its deleted.
-
removeChildren
public void removeChildren()
Removes all children from the node.
-
getChildrenLength
public int getChildrenLength()
- Returns:
- Returns the number of children without neccessarily creating a list.
-
findChildByName
public XMPNode findChildByName(java.lang.String expr)
- Parameters:
expr- child node name to look for- Returns:
- Returns an
XMPNodeif node has been found,nullotherwise.
-
getQualifier
public XMPNode getQualifier(int index)
- Parameters:
index- an index [1..size]- Returns:
- Returns the qualifier with the requested index.
-
getQualifierLength
public int getQualifierLength()
- Returns:
- Returns the number of qualifier without neccessarily creating a list.
-
addQualifier
public void addQualifier(XMPNode qualNode) throws XMPException
Appends a qualifier to the qualifier list and sets respective options.- Parameters:
qualNode- a qualifier node.- Throws:
XMPException
-
removeQualifier
public void removeQualifier(XMPNode qualNode)
Removes one qualifier node and fixes the options.- Parameters:
qualNode- qualifier to remove
-
removeQualifiers
public void removeQualifiers()
Removes all qualifiers from the node and sets the options appropriate.
-
findQualifierByName
public XMPNode findQualifierByName(java.lang.String expr)
- Parameters:
expr- qualifier node name to look for- Returns:
- Returns a qualifier
XMPNodeif node has been found,nullotherwise.
-
hasChildren
public boolean hasChildren()
- Returns:
- Returns whether the node has children.
-
iterateChildren
public java.util.Iterator iterateChildren()
- Returns:
- Returns an iterator for the children. Note: take care to use it.remove(), as the flag are not adjusted in that case.
-
hasQualifier
public boolean hasQualifier()
- Returns:
- Returns whether the node has qualifier attached.
-
iterateQualifier
public java.util.Iterator iterateQualifier()
- Returns:
- Returns an iterator for the qualifier. Note: take care to use it.remove(), as the flag are not adjusted in that case.
-
clone
public java.lang.Object clone()
Performs a deep clone of the node and the complete subtree.- Overrides:
clonein classjava.lang.Object- See Also:
Object.clone()
-
cloneSubtree
public void cloneSubtree(XMPNode destination)
Performs a deep clone of the complete subtree (children and qualifier )into and add it to the destination node.- Parameters:
destination- the node to add the cloned subtree
-
dumpNode
public java.lang.String dumpNode(boolean recursive)
Renders this node and the tree unter this node in a human readable form.- Parameters:
recursive- Flag is qualifier and child nodes shall be rendered too- Returns:
- Returns a multiline string containing the dump.
-
compareTo
public int compareTo(java.lang.Object xmpNode)
- Specified by:
compareToin interfacejava.lang.Comparable- See Also:
Comparable.compareTo(Object)
-
getName
public java.lang.String getName()
- Returns:
- Returns the name.
-
setName
public void setName(java.lang.String name)
- Parameters:
name- The name to set.
-
getValue
public java.lang.String getValue()
- Returns:
- Returns the value.
-
setValue
public void setValue(java.lang.String value)
- Parameters:
value- The value to set.
-
getOptions
public PropertyOptions getOptions()
- Returns:
- Returns the options.
-
setOptions
public void setOptions(PropertyOptions options)
Updates the options of the node.- Parameters:
options- the options to set.
-
isImplicit
public boolean isImplicit()
- Returns:
- Returns the implicit flag
-
setImplicit
public void setImplicit(boolean implicit)
- Parameters:
implicit- Sets the implicit node flag
-
getHasAliases
public boolean getHasAliases()
- Returns:
- Returns if the node contains aliases (applies only to schema nodes)
-
setHasAliases
public void setHasAliases(boolean hasAliases)
- Parameters:
hasAliases- sets the flag that the node contains aliases
-
isAlias
public boolean isAlias()
- Returns:
- Returns if the node contains aliases (applies only to schema nodes)
-
setAlias
public void setAlias(boolean alias)
- Parameters:
alias- sets the flag that the node is an alias
-
getHasValueChild
public boolean getHasValueChild()
- Returns:
- the hasValueChild
-
setHasValueChild
public void setHasValueChild(boolean hasValueChild)
- Parameters:
hasValueChild- the hasValueChild to set
-
sort
public void sort()
Sorts the complete datamodel according to the following rules:- Nodes at one level are sorted by name, that is prefix + local name
- Starting at the root node the children and qualifier are sorted recursively, which the following exceptions.
- Sorting will not be used for arrays.
- Within qualifier "xml:lang" and/or "rdf:type" stay at the top in that order, all others are sorted.
-
dumpNode
private void dumpNode(java.lang.StringBuffer result, boolean recursive, int indent, int index)Dumps this node and its qualifier and children recursively. Note: It creats empty options on every node.- Parameters:
result- the buffer to append the dump.recursive- Flag is qualifier and child nodes shall be rendered tooindent- the current indent level.index- the index within the parent node (important for arrays)
-
isLanguageNode
private boolean isLanguageNode()
- Returns:
- Returns whether this node is a language qualifier.
-
isTypeNode
private boolean isTypeNode()
- Returns:
- Returns whether this node is a type qualifier.
-
getChildren
private java.util.List getChildren()
Note: This method should always be called when accessing 'children' to be sure that its initialized.- Returns:
- Returns list of children that is lazy initialized.
-
getUnmodifiableChildren
public java.util.List getUnmodifiableChildren()
- Returns:
- Returns a read-only copy of child nodes list.
-
getQualifier
private java.util.List getQualifier()
- Returns:
- Returns list of qualifier that is lazy initialized.
-
setParent
protected void setParent(XMPNode parent)
Sets the parent node, this is solely done byaddChild(...)andaddQualifier().- Parameters:
parent- Sets the parent node.
-
find
private XMPNode find(java.util.List list, java.lang.String expr)
Internal find.- Parameters:
list- the list to search inexpr- the search expression- Returns:
- Returns the found node or
nulls.
-
assertChildNotExisting
private void assertChildNotExisting(java.lang.String childName) throws XMPExceptionChecks that a node name is not existing on the same level, except for array items.- Parameters:
childName- the node name to check- Throws:
XMPException- Thrown if a node with the same name is existing.
-
assertQualifierNotExisting
private void assertQualifierNotExisting(java.lang.String qualifierName) throws XMPExceptionChecks that a qualifier name is not existing on the same level.- Parameters:
qualifierName- the new qualifier name- Throws:
XMPException- Thrown if a node with the same name is existing.
-
-