Class PDOutlineNode
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.common.PDDictionaryWrapper
-
- org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineNode
-
- All Implemented Interfaces:
COSObjectable
- Direct Known Subclasses:
PDDocumentOutline
,PDOutlineItem
public abstract class PDOutlineNode extends PDDictionaryWrapper
Base class for a node in the outline of a PDF document.
-
-
Constructor Summary
Constructors Constructor Description PDOutlineNode()
Default Constructor.PDOutlineNode(COSDictionary dict)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFirst(PDOutlineItem newChild)
Adds the given node to the top of the children list.void
addLast(PDOutlineItem newChild)
Adds the given node to the bottom of the children list.private void
append(PDOutlineItem newChild)
Appends the child to the linked list of children.java.lang.Iterable<PDOutlineItem>
children()
void
closeNode()
Close this node.PDOutlineItem
getFirstChild()
PDOutlineItem
getLastChild()
int
getOpenCount()
Get the number of open nodes or a negative number if this node is closed.(package private) PDOutlineItem
getOutlineItem(COSName name)
(package private) PDOutlineNode
getParent()
boolean
hasChildren()
boolean
isNodeOpen()
void
openNode()
This will set this node to be open when it is shown in the viewer.private void
prepend(PDOutlineItem newChild)
Prepends the child to the linked list of children.(package private) void
requireSingleNode(PDOutlineItem node)
(package private) void
setFirstChild(PDOutlineNode outlineNode)
Set the first child, this will be maintained by this class.(package private) void
setLastChild(PDOutlineNode outlineNode)
Set the last child, this will be maintained by this class.(package private) void
setOpenCount(int openCount)
Set the open count.(package private) void
setParent(PDOutlineNode parent)
private void
switchNodeCount()
(package private) void
updateParentOpenCount(int delta)
The count parameter needs to be updated when you add, remove, open or close outline items.(package private) void
updateParentOpenCountForAddedChild(PDOutlineItem newChild)
-
Methods inherited from class org.apache.pdfbox.pdmodel.common.PDDictionaryWrapper
equals, getCOSObject, hashCode
-
-
-
-
Constructor Detail
-
PDOutlineNode
public PDOutlineNode()
Default Constructor.
-
PDOutlineNode
public PDOutlineNode(COSDictionary dict)
- Parameters:
dict
- The dictionary storage.
-
-
Method Detail
-
getParent
PDOutlineNode getParent()
- Returns:
- The parent of this node or null if there is no parent.
-
setParent
void setParent(PDOutlineNode parent)
-
addLast
public void addLast(PDOutlineItem newChild)
Adds the given node to the bottom of the children list.- Parameters:
newChild
- The node to add.- Throws:
java.lang.IllegalArgumentException
- if the given node is part of a list (i.e. if it has a previous or a next sibling)
-
addFirst
public void addFirst(PDOutlineItem newChild)
Adds the given node to the top of the children list.- Parameters:
newChild
- The node to add.- Throws:
java.lang.IllegalArgumentException
- if the given node is part of a list (i.e. if it has a previous or a next sibling)
-
requireSingleNode
void requireSingleNode(PDOutlineItem node)
- Parameters:
node
-- Throws:
java.lang.IllegalArgumentException
- if the given node is part of a list (i.e. if it has a previous or a next sibling)
-
append
private void append(PDOutlineItem newChild)
Appends the child to the linked list of children. This method only adjust pointers but doesn't take care of the Count key in the parent hierarchy.- Parameters:
newChild
-
-
prepend
private void prepend(PDOutlineItem newChild)
Prepends the child to the linked list of children. This method only adjust pointers but doesn't take care of the Count key in the parent hierarchy.- Parameters:
newChild
-
-
updateParentOpenCountForAddedChild
void updateParentOpenCountForAddedChild(PDOutlineItem newChild)
-
hasChildren
public boolean hasChildren()
- Returns:
- true if the node has at least one child
-
getOutlineItem
PDOutlineItem getOutlineItem(COSName name)
-
getFirstChild
public PDOutlineItem getFirstChild()
- Returns:
- The first child or null if there is no child.
-
setFirstChild
void setFirstChild(PDOutlineNode outlineNode)
Set the first child, this will be maintained by this class.- Parameters:
outlineNode
- The new first child.
-
getLastChild
public PDOutlineItem getLastChild()
- Returns:
- The last child or null if there is no child.
-
setLastChild
void setLastChild(PDOutlineNode outlineNode)
Set the last child, this will be maintained by this class.- Parameters:
outlineNode
- The new last child.
-
getOpenCount
public int getOpenCount()
Get the number of open nodes or a negative number if this node is closed. See PDF Reference 32000-1:2008 table 152 and 153 for more details. This value is updated as you append children and siblings.- Returns:
- The Count attribute of the outline dictionary.
-
setOpenCount
void setOpenCount(int openCount)
Set the open count. This number is automatically managed for you when you add items to the outline.- Parameters:
openCount
- The new open count.
-
openNode
public void openNode()
This will set this node to be open when it is shown in the viewer. By default, when a new node is created it will be closed. This will do nothing if the node is already open.
-
closeNode
public void closeNode()
Close this node.
-
switchNodeCount
private void switchNodeCount()
-
isNodeOpen
public boolean isNodeOpen()
- Returns:
- true if this node count is greater than zero, false otherwise.
-
updateParentOpenCount
void updateParentOpenCount(int delta)
The count parameter needs to be updated when you add, remove, open or close outline items.- Parameters:
delta
- The amount to update by.
-
children
public java.lang.Iterable<PDOutlineItem> children()
- Returns:
- An
Iterable
view of the items children
-
-