Package com.itextpdf.kernel.pdf
Class GenericNameTree
- java.lang.Object
-
- com.itextpdf.kernel.pdf.GenericNameTree
-
- All Implemented Interfaces:
IPdfNameTreeAccess
- Direct Known Subclasses:
PdfNameTree
,PdfStructIdTree
public class GenericNameTree extends java.lang.Object implements IPdfNameTreeAccess
Abstract representation of a name tree structure, as used in PDF for various purposes such as the Dests tree, the ID tree of structure elements and the embedded file tree.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
GenericNameTree(PdfDocument pdfDoc)
Creates a name tree structure in the current document.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEntry(PdfString key, PdfObject value)
Add an entry to the name tree.protected void
addEntry(PdfString key, PdfObject value, java.util.function.Consumer<PdfDocument> onErrorAction)
Add an entry to the name tree.void
addEntry(java.lang.String key, PdfObject value)
Add an entry to the name tree.PdfDictionary
buildTree()
Build aPdfDictionary
containing the name tree.private PdfDictionary[]
constructLeafArr(PdfString[] names)
private PdfDictionary
formatNodeWithLimits(PdfString[] names, int lower, int upper)
PdfObject
getEntry(PdfString key)
Retrieve an entry from the name tree.PdfObject
getEntry(java.lang.String key)
Retrieve an entry from the name tree.protected java.util.LinkedHashMap<PdfString,PdfObject>
getItems()
java.util.Set<PdfString>
getKeys()
Retrieve the set of keys in the name tree.boolean
isModified()
Check if the tree is modified.private static PdfString
iterateItems(PdfDictionary dictionary, java.util.Map<PdfString,PdfObject> items, PdfString leftOver)
private static PdfString
iterateLeafNode(PdfArray names, java.util.Map<PdfString,PdfObject> items, PdfString leftOver)
protected static java.util.LinkedHashMap<PdfString,PdfObject>
readTree(PdfDictionary dictionary)
Read the entries in a name tree structure from a dictionary object into a linked hash map with fixed order.private PdfDictionary
reduceTree(PdfString[] names, PdfDictionary[] topLayer, int topLayerLen, int curNodeSpan)
void
removeEntry(PdfString key)
Remove an entry from the name tree.protected void
setItems(java.util.LinkedHashMap<PdfString,PdfObject> items)
void
setModified()
Sets the modified flag to true.
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
NODE_SIZE
private static final int NODE_SIZE
- See Also:
- Constant Field Values
-
pdfDoc
private final PdfDocument pdfDoc
-
modified
private boolean modified
-
-
Constructor Detail
-
GenericNameTree
protected GenericNameTree(PdfDocument pdfDoc)
Creates a name tree structure in the current document.- Parameters:
pdfDoc
- the document in which the name tree lives
-
-
Method Detail
-
addEntry
public void addEntry(PdfString key, PdfObject value)
Add an entry to the name tree.- Parameters:
key
- key of the entryvalue
- object to add
-
addEntry
public void addEntry(java.lang.String key, PdfObject value)
Add an entry to the name tree.- Parameters:
key
- key of the entryvalue
- object to add
-
removeEntry
public void removeEntry(PdfString key)
Remove an entry from the name tree.- Parameters:
key
- key of the entry
-
getEntry
public PdfObject getEntry(PdfString key)
Retrieve an entry from the name tree.- Specified by:
getEntry
in interfaceIPdfNameTreeAccess
- Parameters:
key
- key of entry to retrieve- Returns:
- retrieved entry or
null
if absent
-
getEntry
public PdfObject getEntry(java.lang.String key)
Retrieve an entry from the name tree.- Specified by:
getEntry
in interfaceIPdfNameTreeAccess
- Parameters:
key
- key of entry to retrieve- Returns:
- retrieved entry or
null
if absent
-
getKeys
public java.util.Set<PdfString> getKeys()
Description copied from interface:IPdfNameTreeAccess
Retrieve the set of keys in the name tree.- Specified by:
getKeys
in interfaceIPdfNameTreeAccess
- Returns:
- set of all keys in the name tree
-
isModified
public boolean isModified()
Check if the tree is modified.- Returns:
- True if the object has been modified, false otherwise.
-
setModified
public void setModified()
Sets the modified flag to true. It means that the object has been modified.
-
buildTree
public PdfDictionary buildTree()
Build aPdfDictionary
containing the name tree.- Returns:
PdfDictionary
containing the name tree
-
addEntry
protected void addEntry(PdfString key, PdfObject value, java.util.function.Consumer<PdfDocument> onErrorAction)
Add an entry to the name tree.- Parameters:
key
- key of the entryvalue
- object to addonErrorAction
- action to perform if such entry exists
-
readTree
protected static java.util.LinkedHashMap<PdfString,PdfObject> readTree(PdfDictionary dictionary)
Read the entries in a name tree structure from a dictionary object into a linked hash map with fixed order.- Parameters:
dictionary
- a dictionary object- Returns:
- a map containing the entries in the tree
-
formatNodeWithLimits
private PdfDictionary formatNodeWithLimits(PdfString[] names, int lower, int upper)
-
reduceTree
private PdfDictionary reduceTree(PdfString[] names, PdfDictionary[] topLayer, int topLayerLen, int curNodeSpan)
-
constructLeafArr
private PdfDictionary[] constructLeafArr(PdfString[] names)
-
iterateItems
private static PdfString iterateItems(PdfDictionary dictionary, java.util.Map<PdfString,PdfObject> items, PdfString leftOver)
-
-