com.icesoft.pdf.util
Class Library

java.lang.Object
  extended bycom.icesoft.pdf.util.Library

public class Library
extends Object

The Library class acts a central repository for the access of PDF objects in a document. The Library class has many utility methods which are designed to access PDF objects as easily as possible. The Library class has direct access to the PDF file and loads the needed objects from the file system when needed.

Since:
1.0

Field Summary
 CacheManager cacheManager
           
 MemoryManager memoryManager
           
 SecurityManager securityManager
           
 
Constructor Summary
Library()
          Creates a new instance of a Library.
 
Method Summary
 void addObject(Object object, Reference objectReference)
          Adds a PDF object and its respective object reference to the library.
 void dispose()
          Dispose the library's resources.
 Boolean getBoolean(Hashtable dictionaryEntries, String key)
          Gets a Boolean specified by the key in the dictionary entries.
 CacheManager getCacheManager()
          Gets the library cache manager.
 Catalog getCatalog()
          Gets the document's catalog.
 Hashtable getDictionary(Hashtable dictionaryEntries, String key)
          Gets a dictionary specified by the key in the dictionary entries.
 float getFloat(Hashtable dictionaryEntries, String key)
          Gets a float specified by the key in the dictionary entries.
 ICCBased getICCBased(Reference ref)
          The Reference is to the Stream from which the ICC color space data is to be parsed.
 int getInt(Hashtable dictionaryEntries, String key)
          Gets an int specified by the key in the dictionary entries.
 long getLong(Hashtable dictionaryEntries, String key)
          Gets a float specified by the key in the dictionary entries.
 String getName(Hashtable dictionaryEntries, String key)
          Gets a Name specified by the key in the dictionary entries.
 Number getNumber(Hashtable dictionaryEntries, String key)
          Gets a Number specified by the key in the dictionary entries.
 Object getObject(Hashtable dictionaryEntries, String key)
          Gets the PDF object specified by the key in the dictionary entries.
 Object getObject(Object referenceObject)
          Gets the PDF object that the referenceObject references.
 Object getObject(Reference reference)
          Gets the object specified by the reference.
 Reference getObjectReference(Hashtable dictionaryEntries, String key)
          Gets the PDF object specified by the key in the dictionary entries.
 Rectangle2D.Float getRectangle(Hashtable dictionaryEntries, String key)
          Gets a rectangle specified by the key.
 Resources getResources(Hashtable dictionaryEntries, String key)
           
 Resources getResources(Reference reference)
           
 SecurityManager getSecurityManager()
          Gets the document's security manger.
 PTrailer getTrailerByFilePosition(long position)
          Gets the document's trailer.
 boolean isEncrypted()
          Indicates that document is encrypted using Adobe Standard Encryption.
 boolean isValidEntry(Hashtable dictionaryEntries, String key)
          Tests if the given key will return a non-null PDF object from the specified dictionary entries.
 boolean isValidEntry(Reference reference)
          Tests if there exists a cross-reference entry for this reference.
 void setCatalog(Catalog c)
          Sets the document's catalog.
 void setEncrypted(boolean flag)
          Set the document is encrypted flag.
 void setLazyObjectLoader(LazyObjectLoader lol)
          Sets a document loader for the library.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

memoryManager

public MemoryManager memoryManager

cacheManager

public CacheManager cacheManager

securityManager

public SecurityManager securityManager
Constructor Detail

Library

public Library()
Creates a new instance of a Library.

Method Detail

setLazyObjectLoader

public void setLazyObjectLoader(LazyObjectLoader lol)
Sets a document loader for the library.

Parameters:
lol - loader object.

getTrailerByFilePosition

public PTrailer getTrailerByFilePosition(long position)
Gets the document's trailer.

Parameters:
position - byte offset of the trailer in the PDF file.
Returns:
trailer dictionary

getObject

public Object getObject(Reference reference)
Gets the object specified by the reference.

Parameters:
reference - reference to a PDF object in the document structure.
Returns:
PDF object dictionary that the reference refers to. Null if the object reference can not be found.

getObject

public Object getObject(Hashtable dictionaryEntries,
                        String key)
Gets the PDF object specified by the key in the dictionary entries. If the key value is a reference, the object that the reference points to is returned.

Parameters:
dictionaryEntries - the dictionary entries to look up the key in.
key - string value representing the dictionary key.
Returns:
PDF object that the key references.
See Also:
getObjectReference(java.util.Hashtable, String)

getObject

public Object getObject(Object referenceObject)
Gets the PDF object that the referenceObject references.

Parameters:
referenceObject - reference object.
Returns:
PDF object that referenceObject references. If referenceObject is not an instance of a Reference, the origional referenceObject is returned.

isValidEntry

public boolean isValidEntry(Hashtable dictionaryEntries,
                            String key)
Tests if the given key will return a non-null PDF object from the specified dictionary entries. A null PDF object would result if no PDF object could be found with the specified key.

Parameters:
dictionaryEntries - dictionary entries
key - dictionary key
Returns:
true, if the key's value is non-null PDF object; false, otherwise.

isValidEntry

public boolean isValidEntry(Reference reference)
Tests if there exists a cross-reference entry for this reference.

Parameters:
reference - reference to a PDF object in the document structure.
Returns:
true, if a cross-reference entry exists for this reference; false, otherwise.

getNumber

public Number getNumber(Hashtable dictionaryEntries,
                        String key)
Gets a Number specified by the key in the dictionary entries. If the key value is a reference, the Number object that the reference points to is returned.

Parameters:
dictionaryEntries - the dictionary entries to look up the key in.
key - string value representing the dictionary key.
Returns:
Number object if a valid key; null, if the key does not point to Number or is invalid.

getBoolean

public Boolean getBoolean(Hashtable dictionaryEntries,
                          String key)
Gets a Boolean specified by the key in the dictionary entries. If the key value is a reference, the Boolean object that the reference points to is returned.

Parameters:
dictionaryEntries - the dictionary entries to look up the key in.
key - string value representing the dictionary key.
Returns:
Number object if a valid key; null, if the key does not point to Number or is invalid.

getFloat

public float getFloat(Hashtable dictionaryEntries,
                      String key)
Gets a float specified by the key in the dictionary entries. If the key value is a reference, the object that the reference points to is returned.

Parameters:
dictionaryEntries - the dictionary entries to look up the key in.
key - string value representing the dictionary key.
Returns:
float value if a valid key; null, if the key does not point to a float or is invalid.

getInt

public int getInt(Hashtable dictionaryEntries,
                  String key)
Gets an int specified by the key in the dictionary entries. If the key value is a reference, the object that the reference points to is returned.

Parameters:
dictionaryEntries - the dictionary entries to look up the key in.
key - string value representing the dictionary key.
Returns:
int value if a valid key, null if the key does not point to an int or is invalid.

getLong

public long getLong(Hashtable dictionaryEntries,
                    String key)
Gets a float specified by the key in the dictionary entries. If the key value is a reference, the object that the reference points to is returned.

Parameters:
dictionaryEntries - the dictionary entries to look up the key in.
key - string value representing the dictionary key.
Returns:
float value if a valid key; null, if the key does not point to a float or is invalid.

getName

public String getName(Hashtable dictionaryEntries,
                      String key)
Gets a Name specified by the key in the dictionary entries. If the key value is a reference, the Name object that the reference points to is returned.

Parameters:
dictionaryEntries - the dictionary entries to look up the key in.
key - string value representing the dictionary key.
Returns:
Name object if a valid key; null, if the key does not point to Name or is invalid.

getDictionary

public Hashtable getDictionary(Hashtable dictionaryEntries,
                               String key)
Gets a dictionary specified by the key in the dictionary entries. If the key value is a reference, the dictionary object that the reference points to is returned.

Parameters:
dictionaryEntries - the dictionary entries to look up the key in.
key - string value representing the dictionary key.
Returns:
dictionary object if a valid key; null, if the key does not point to dictionary or is invalid.

getRectangle

public Rectangle2D.Float getRectangle(Hashtable dictionaryEntries,
                                      String key)
Gets a rectangle specified by the key. The rectangle is already in the coordinate system of Java2D, and thus must be used carefully.

Parameters:
dictionaryEntries - the dictionary entries to look up the key in.
key - string value representing the dictionary key.
Returns:
rectangle in Java2D coordinate system.

getICCBased

public ICCBased getICCBased(Reference ref)
The Reference is to the Stream from which the ICC color space data is to be parsed. So, without this method, we would be making and initializing a new ICCBased object every time one was needed, since the Reference is not for the ICCBased object itself.

Parameters:
ref - Reference to Stream containing ICC color space data
Returns:
ICCBased color model object for the given reference

getResources

public Resources getResources(Hashtable dictionaryEntries,
                              String key)

getResources

public Resources getResources(Reference reference)

addObject

public void addObject(Object object,
                      Reference objectReference)
Adds a PDF object and its respective object reference to the library.

Parameters:
object - PDF object to add.
objectReference - PDF object reference object.

getObjectReference

public Reference getObjectReference(Hashtable dictionaryEntries,
                                    String key)
Gets the PDF object specified by the key in the dictionary entries. If the key value is a reference it is returned.

Parameters:
dictionaryEntries - the dictionary entries to look up the key in.
key - string value representing the dictionary key.
Returns:
the Reference specified by the PDF key. If the key is invalid or does not reference a Reference object, null is returned.
See Also:
getObject(java.util.Hashtable, String)

isEncrypted

public boolean isEncrypted()
Indicates that document is encrypted using Adobe Standard Encryption.

Returns:
true if the document is encrypted, false otherwise.

getSecurityManager

public SecurityManager getSecurityManager()
Gets the document's security manger.

Returns:
document's security manager if the document is encrypted, null otherwise.

setEncrypted

public void setEncrypted(boolean flag)
Set the document is encrypted flag.

Parameters:
flag - true, if the document is encrypted; false, otherwize.

getCacheManager

public CacheManager getCacheManager()
Gets the library cache manager.

Returns:
cache manager used by library and document.

getCatalog

public Catalog getCatalog()
Gets the document's catalog.

Returns:
document's catalog.

setCatalog

public void setCatalog(Catalog c)
Sets the document's catalog. Normally only accessed by the document's parser.

Parameters:
c - document catalog object.

dispose

public void dispose()
Dispose the library's resources.