This class represends a PDF Name tree. See the PDF Reference 1.5 section 3.8.5
for more details.
Method from org.apache.pdfbox.pdmodel.common.PDNameTreeNode Detail: |
protected Object convertCOSToPD(COSBase base) throws IOException {
Object retval = null;
try
{
Constructor ctor = valueType.getConstructor( new Class[] { base.getClass() } );
retval = ctor.newInstance( new Object[] { base } );
}
catch( Throwable t )
{
throw new IOException( "Error while trying to create value in named tree:" + t.getMessage());
}
return retval;
}
Method to convert the COS value in the name tree to the PD Model object. The
default implementation will simply use reflection to create the correct object
type. Subclasses can do whatever they want. |
protected PDNameTreeNode createChildNode(COSDictionary dic) {
return new PDNameTreeNode(dic,valueType);
}
Create a child node object. |
public COSDictionary getCOSDictionary() {
return node;
}
Convert this standard java object to a COS object. |
public COSBase getCOSObject() {
return node;
}
Convert this standard java object to a COS object. |
public List getKids() {
List retval = null;
COSArray kids = (COSArray)node.getDictionaryObject( COSName.KIDS );
if( kids != null )
{
List pdObjects = new ArrayList();
for( int i=0; i< kids.size(); i++ )
{
pdObjects.add( createChildNode( (COSDictionary)kids.getObject(i) ) );
}
retval = new COSArrayList(pdObjects,kids);
}
return retval;
}
Return the children of this node. This list will contain PDNameTreeNode objects. |
public String getLowerLimit() {
String retval = null;
COSArray arr = (COSArray)node.getDictionaryObject( COSName.LIMITS );
if( arr != null )
{
retval = arr.getString( 0 );
}
return retval;
}
Get the lowest value for a key in the name map. |
public Map getNames() throws IOException {
Map names = null;
COSArray namesArray = (COSArray)node.getDictionaryObject( COSName.NAMES );
if( namesArray != null )
{
names = new HashMap();
for( int i=0; i< namesArray.size(); i+=2 )
{
COSString key = (COSString)namesArray.getObject(i);
COSBase cosValue = namesArray.getObject( i+1 );
Object pdValue = convertCOSToPD( cosValue );
names.put( key.getString(), pdValue );
}
names = Collections.unmodifiableMap(names);
}
return names;
}
This will return a map of names. The key will be a java.lang.String the value will
depend on where this class is being used. |
public String getUpperLimit() {
String retval = null;
COSArray arr = (COSArray)node.getDictionaryObject( COSName.LIMITS );
if( arr != null )
{
retval = arr.getString( 1 );
}
return retval;
}
Get the highest value for a key in the name map. |
public Object getValue(String name) throws IOException {
Object retval = null;
Map names = getNames();
if( names != null )
{
retval = names.get( name );
}
else
{
List kids = getKids();
for( int i=0; i< kids.size() && retval == null; i++ )
{
PDNameTreeNode childNode = (PDNameTreeNode)kids.get( i );
if( childNode.getLowerLimit().compareTo( name ) < = 0 &&
childNode.getUpperLimit().compareTo( name ) >= 0 )
{
retval = childNode.getValue( name );
}
}
}
return retval;
}
|
public void setKids(List kids) {
node.setItem( "Kids", COSArrayList.converterToCOSArray( kids ) );
}
Set the children of this named tree. |
public void setNames(Map names) {
if( names == null )
{
node.setItem( "Names", (COSObjectable)null );
node.setItem( COSName.LIMITS, (COSObjectable)null);
}
else
{
List keys = new ArrayList( names.keySet() );
Collections.sort( keys );
COSArray array = new COSArray();
for( int i=0; i< keys.size(); i++ )
{
String key = (String)keys.get(i);
array.add( new COSString( key ) );
COSObjectable obj = (COSObjectable)names.get( key );
array.add( obj );
}
String lower = null;
String upper = null;
if( keys.size() > 0 )
{
lower = (String)keys.get( 0 );
upper = (String)keys.get( keys.size()-1 );
}
setUpperLimit( upper );
setLowerLimit( lower );
node.setItem( "Names", array );
}
}
Set the names of for this node. The keys should be java.lang.String and the
values must be a COSObjectable. This method will set the appropriate upper and lower
limits based on the keys in the map. |