org.icepdf.core.util
Class Library

java.lang.Object
  extended by org.icepdf.core.util.Library

public class Library
extends java.lang.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
           
 StateManager stateManager
           
 
Constructor Summary
Library()
          Creates a new instance of a Library.
 
Method Summary
 void addObject(java.lang.Object object, Reference objectReference)
          Adds a PDF object and its respective object reference to the library.
 void dispose()
          Dispose the library's resources.
 void disposeFontResources()
          Utility/demo functionality to clear all font and font descriptor resources.
 java.lang.Boolean getBoolean(java.util.Hashtable dictionaryEntries, java.lang.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.
 java.util.Hashtable getDictionary(java.util.Hashtable dictionaryEntries, java.lang.String key)
          Gets a dictionary specified by the key in the dictionary entries.
 float getFloat(java.util.Hashtable dictionaryEntries, java.lang.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(java.util.Hashtable dictionaryEntries, java.lang.String key)
          Gets an int specified by the key in the dictionary entries.
 long getLong(java.util.Hashtable dictionaryEntries, java.lang.String key)
          Gets a float specified by the key in the dictionary entries.
 java.lang.String getName(java.util.Hashtable dictionaryEntries, java.lang.String key)
          Gets a Name specified by the key in the dictionary entries.
 java.lang.Number getNumber(java.util.Hashtable dictionaryEntries, java.lang.String key)
          Gets a Number specified by the key in the dictionary entries.
 java.lang.Object getObject(java.util.Hashtable dictionaryEntries, java.lang.String key)
          Gets the PDF object specified by the key in the dictionary entries.
 java.lang.Object getObject(java.lang.Object referenceObject)
          Gets the PDF object that the referenceObject references.
 java.lang.Object getObject(Reference reference)
          Gets the object specified by the reference.
 Reference getObjectReference(java.util.Hashtable dictionaryEntries, java.lang.String key)
          Gets the PDF object specified by the key in the dictionary entries.
 java.awt.geom.Rectangle2D.Float getRectangle(java.util.Hashtable dictionaryEntries, java.lang.String key)
          Gets a rectangle specified by the key.
 Reference getReference(java.util.Hashtable dictionaryEntries, java.lang.String key)
          Gets the reference association of the key if any.
 Resources getResources(java.util.Hashtable dictionaryEntries, java.lang.String key)
           
 Resources getResources(Reference reference)
           
 SecurityManager getSecurityManager()
          Gets the document's security manger.
 StateManager getStateManager()
          Gets the state manager class which keeps track of changes PDF objects.
 PTrailer getTrailerByFilePosition(long position)
          Gets the document's trailer.
 boolean isEncrypted()
          Indicates that document is encrypted using Adobe Standard Encryption.
 boolean isLinearTraversal()
          There are several implications from using linear traversal, which affect how we parse the PDF objects, and maintain them in memory, so those sections of code need to check this flag here.
 boolean isReference(java.util.Hashtable dictionaryEntries, java.lang.String key)
          Test to see if the given key is a reference and not an inline dictinary
 boolean isValidEntry(java.util.Hashtable dictionaryEntries, java.lang.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 removeObject(Reference objetReference)
          Removes an object from from the library.
 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.
 void setLinearTraversal()
          When we fail to load the required xref tables or streams that are needed to access the objects in the PDF, then we simply go to the beginning of the file and read in all of the objects into memory, which we call linear traversal.
 void setStateManager(StateManager stateManager)
          Sets the document state manager so that all object can access the state manager via the central library instance.
 
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

stateManager

public StateManager stateManager
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 java.lang.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 java.lang.Object getObject(java.util.Hashtable dictionaryEntries,
                                  java.lang.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)

isReference

public boolean isReference(java.util.Hashtable dictionaryEntries,
                           java.lang.String key)
Test to see if the given key is a reference and not an inline dictinary

Parameters:
dictionaryEntries - dictionary to test
key - dictionary key
Returns:
true if the key value exists and is a reference, false if the dictionaryEntries are null or the key references an inline dictionary

getReference

public Reference getReference(java.util.Hashtable dictionaryEntries,
                              java.lang.String key)
Gets the reference association of the key if any. This method is usual used in combination with #isReference to get and assign the Reference for a given PObject.

Parameters:
dictionaryEntries - dictionary to search in.
key - key to search for in dictionary.
Returns:
reference of the object that key points if any. Null if the key points to an inline dictionary and not a reference.

getStateManager

public StateManager getStateManager()
Gets the state manager class which keeps track of changes PDF objects.

Returns:
document state manager

setStateManager

public void setStateManager(StateManager stateManager)
Sets the document state manager so that all object can access the state manager via the central library instance.

Parameters:
stateManager -

getObject

public java.lang.Object getObject(java.lang.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(java.util.Hashtable dictionaryEntries,
                            java.lang.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 java.lang.Number getNumber(java.util.Hashtable dictionaryEntries,
                                  java.lang.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 java.lang.Boolean getBoolean(java.util.Hashtable dictionaryEntries,
                                    java.lang.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(java.util.Hashtable dictionaryEntries,
                      java.lang.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(java.util.Hashtable dictionaryEntries,
                  java.lang.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(java.util.Hashtable dictionaryEntries,
                    java.lang.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 java.lang.String getName(java.util.Hashtable dictionaryEntries,
                                java.lang.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 java.util.Hashtable getDictionary(java.util.Hashtable dictionaryEntries,
                                         java.lang.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 java.awt.geom.Rectangle2D.Float getRectangle(java.util.Hashtable dictionaryEntries,
                                                    java.lang.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(java.util.Hashtable dictionaryEntries,
                              java.lang.String key)

getResources

public Resources getResources(Reference reference)

addObject

public void addObject(java.lang.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.

removeObject

public void removeObject(Reference objetReference)
Removes an object from from the library.

Parameters:
objetReference -

getObjectReference

public Reference getObjectReference(java.util.Hashtable dictionaryEntries,
                                    java.lang.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.

setLinearTraversal

public void setLinearTraversal()
When we fail to load the required xref tables or streams that are needed to access the objects in the PDF, then we simply go to the beginning of the file and read in all of the objects into memory, which we call linear traversal.


isLinearTraversal

public boolean isLinearTraversal()
There are several implications from using linear traversal, which affect how we parse the PDF objects, and maintain them in memory, so those sections of code need to check this flag here.

Returns:
If PDF was parsed via linear traversal

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.

disposeFontResources

public void disposeFontResources()
Utility/demo functionality to clear all font and font descriptor resources. The library will re-fetch the font resources in question when needed again.


dispose

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