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 protectedGenericNameTree(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 voidaddEntry(PdfString key, PdfObject value)Add an entry to the name tree.protected voidaddEntry(PdfString key, PdfObject value, java.util.function.Consumer<PdfDocument> onErrorAction)Add an entry to the name tree.voidaddEntry(java.lang.String key, PdfObject value)Add an entry to the name tree.PdfDictionarybuildTree()Build aPdfDictionarycontaining the name tree.private PdfDictionary[]constructLeafArr(PdfString[] names)private PdfDictionaryformatNodeWithLimits(PdfString[] names, int lower, int upper)PdfObjectgetEntry(PdfString key)Retrieve an entry from the name tree.PdfObjectgetEntry(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.booleanisModified()Check if the tree is modified.private static PdfStringiterateItems(PdfDictionary dictionary, java.util.Map<PdfString,PdfObject> items, PdfString leftOver)private static PdfStringiterateLeafNode(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 PdfDictionaryreduceTree(PdfString[] names, PdfDictionary[] topLayer, int topLayerLen, int curNodeSpan)voidremoveEntry(PdfString key)Remove an entry from the name tree.protected voidsetItems(java.util.LinkedHashMap<PdfString,PdfObject> items)voidsetModified()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:
getEntryin interfaceIPdfNameTreeAccess- Parameters:
key- key of entry to retrieve- Returns:
- retrieved entry or
nullif absent
-
getEntry
public PdfObject getEntry(java.lang.String key)
Retrieve an entry from the name tree.- Specified by:
getEntryin interfaceIPdfNameTreeAccess- Parameters:
key- key of entry to retrieve- Returns:
- retrieved entry or
nullif absent
-
getKeys
public java.util.Set<PdfString> getKeys()
Description copied from interface:IPdfNameTreeAccessRetrieve the set of keys in the name tree.- Specified by:
getKeysin 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 aPdfDictionarycontaining the name tree.- Returns:
PdfDictionarycontaining 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)
-
-