Summary: Ctors | Methods | Inherited Methods | [Expand All]
public class

# NameTree

extends Object

java.lang.Object
↳ | com.pdftron.sdf.NameTree

## Class Overview

A NameTree is a common data structure in PDF. See section 3.8.5 'Name Trees' in PDF Reference Manual for more details. A name tree serves a similar purpose to a dictionary - associating keys and values - but by different means. NameTrees allow efficient storage of very large association collections (string/Obj* maps). A NameTree can have many more entries than a SDF/Cos dictionary can. NameTree-s use SDF/Cos-style strings (not null-terminated C strings), which may use Unicode encoding etc.

     PDFDoc doc = new PDFDoc("../Data/PDFReference.pdf");
       NameTree dests = NameTree.find(doc.getSDFDoc(), "Dests");
       if (dests.isValid()) {
         // Traversing the NameTree
         for (DictIterator i = dests.getIterator(); i.hasNext(); i.next())
            string key = i.key().getAsPDFText(); // ...

     }

## Summary

Public Constructors
| NameTree(Obj name_tree) Create a high level NameTree wrapper around an existing SDF/Cos NameTree.

Public Methods
static NameTree | create(Doc doc, String name) Retrieves the NameTree inside the '/Root/Names' dictionary with the specified key name, or creates it if it does not exist.
void | erase(DictIterator pos) Removes the NameTree entry pointed by the iterator.
void | erase(byte[] key) Removes the specified object from the tree.
static NameTree | find(Doc doc, String name) Retrieves a name tree, with the given key name, from the '/Root/Names' dictionary of the doc.
NameTreeIterator | getIterator(byte[] key) Search for the specified key in the NameTree.
NameTreeIterator | getIterator() Get the NameTree iterator.
Obj | getSDFObj() Get the SDFObj.
Obj | getValue(byte[] key) Get the value of specified key
boolean | isValid() Checks if NameTree is valid.
void | put(byte[] key, Obj value) Puts a new entry in the name tree.

[Expand] Inherited Methods
From class java.lang.Object
boolean | equals(Object arg0)
final Class<?> | getClass()
int | hashCode()
final void | notify()
final void | notifyAll()
String | toString()
final void | wait(long arg0, int arg1)
final void | wait(long arg0)
final void | wait()

## Public Constructors

#### public NameTree (Obj name_tree)

Create a high level NameTree wrapper around an existing SDF/Cos NameTree. This does not copy the object.

##### Parameters

name_tree | SDF/Cos root of the NameTree object.

## Public Methods

#### public static NameTree create (Doc doc, String name)

Retrieves the NameTree inside the '/Root/Names' dictionary with the specified key name, or creates it if it does not exist.

Note: although it is possible to create a name tree anywhere in the document the convention is that all trees are located under '/Root/Names' dictionary.

##### Parameters

doc | - The document in which the name tree is created.
name | - The name of the NameTree to create.

##### Returns

- The newly created NameTree for the doc or an exising tree with the same key name.

##### Throws

PDFNetException |

#### public void erase (DictIterator pos)

Removes the NameTree entry pointed by the iterator.

##### Parameters

pos | to be deleted NameTree

##### Throws

PDFNetException |

#### public void erase (byte[] key)

Removes the specified object from the tree. Does nothing if no object with that name exists.

##### Parameters

key | data buffer representing the key of the entry to be removed.

##### Throws

PDFNetException |

#### public static NameTree find (Doc doc, String name)

Retrieves a name tree, with the given key name, from the '/Root/Names' dictionary of the doc.

##### Parameters

doc | - The document in which to search for the name.
name | - The name of the name tree to find.

##### Returns

- The requested NameTree. If the requested NameTree exists NameTree.IsValid() will return true, and false otherwise.

##### Throws

PDFNetException |

#### public NameTreeIterator getIterator (byte[] key)

Search for the specified key in the NameTree.

##### Parameters

key | data buffer representing the key to be found.

##### Returns

- If the key is present the function returns a NameTreeIterator the points to the given Key/Value pair. If the key is not found the function returns End() (a non-valid) iterator.

##### Throws

PDFNetException | `NameTreeIterator i = dests.find("MyKey", 5); if (i.hasNext()) { string key = i.getKey().getAsPDFText(); Obj value = i.getValue();` }

#### public NameTreeIterator getIterator ()

Get the NameTree iterator. Example:

     for (NameTreeIterator i = dests.getIterator(); i.hasNext(); i.next()) {
            string key = i.getKey().getAsPDFText();

     }

##### Returns

- an iterator to the first key/value pair (i.e. NNTreeData) in the document. You can use the increment operator on the returned iterator to traverese all entries stored under the NameTree.

##### Throws

PDFNetException |

#### public Obj getSDFObj ()

Get the SDFObj.

##### Returns

- the object to the underlying SDF/Cos object. If the NameTree.IsValid() returns false the SDF/Cos object is NULL.

#### public Obj getValue (byte[] key)

Get the value of specified key

##### Parameters

key | key of the NameTree

##### Returns

- value of the NameTree

##### Throws

PDFNetException |

#### public boolean isValid ()

Checks if NameTree is valid.

##### Returns

- whether this is a valid (non-null) NameTree. If the function returns false the underlying SDF/Cos object is null and the NameTree object should be treated as null as well.

##### Throws

PDFNetException |

#### public void put (byte[] key, Obj value)

Puts a new entry in the name tree. If an entry with this key is already in the tree, it is replaced.

##### Parameters

key | data buffer representing the key of the new entry.
value | the value

##### Throws

PDFNetException |