This class represents a dictionary where name/value pairs reside.
Method from org.apache.pdfbox.cos.COSDictionary Detail: |
public Object accept(ICOSVisitor visitor) throws COSVisitorException {
return visitor.visitFromDictionary(this);
}
visitor pattern double dispatch method. |
public void addAll(COSDictionary dic) {
for( Map.Entry< COSName, COSBase > entry : dic.entrySet() )
{
/*
* If we're at a second trailer, we have a linearized
* pdf file, meaning that the first Size entry represents
* all of the objects so we don't need to grab the second.
*/
if(!entry.getKey().getName().equals("Size")
|| !items.containsKey(COSName.getPDFName("Size")))
{
setItem( entry.getKey(), entry.getValue() );
}
}
}
This will add all of the dictionarys keys/values to this dictionary.
Only called when adding keys to a trailer that already exists. |
public void clear() {
items.clear();
}
This will clear all items in the map. |
public boolean containsValue(Object value) {
boolean contains = items.containsValue( value );
if( !contains && value instanceof COSObject )
{
contains = items.containsValue( ((COSObject)value).getObject());
}
return contains;
}
|
public Set<COSName, COSBase> entrySet() {
return items.entrySet();
}
Returns the name-value entries in this dictionary. The returned
set is in the order the entries were added to the dictionary. |
public boolean getBoolean(String key,
boolean defaultValue) {
return getBoolean( COSName.getPDFName( key ), defaultValue );
}
This is a convenience method that will get the dictionary object that
is expected to be a cos boolean and convert it to a primitive boolean. |
public boolean getBoolean(COSName key,
boolean defaultValue) {
boolean retval = defaultValue;
COSBase bool = getDictionaryObject( key );
if( bool != null && bool instanceof COSBoolean)
{
retval = ((COSBoolean)bool).getValue();
}
return retval;
}
This is a convenience method that will get the dictionary object that
is expected to be a COSBoolean and convert it to a primitive boolean. |
public Calendar getDate(String key) throws IOException {
return getDate( COSName.getPDFName( key ) );
}
This is a convenience method that will get the dictionary object that
is expected to be a name and convert it to a string. Null is returned
if the entry does not exist in the dictionary. |
public Calendar getDate(COSName key) throws IOException {
COSString date = (COSString)getDictionaryObject( key );
return DateConverter.toCalendar( date );
}
This is a convenience method that will get the dictionary object that
is expected to be a name and convert it to a string. Null is returned
if the entry does not exist in the dictionary. |
public Calendar getDate(String key,
Calendar defaultValue) throws IOException {
return getDate( COSName.getPDFName( key ), defaultValue );
}
This is a convenience method that will get the dictionary object that
is expected to be a date. Null is returned
if the entry does not exist in the dictionary. |
public Calendar getDate(COSName key,
Calendar defaultValue) throws IOException {
Calendar retval = getDate( key );
if( retval == null )
{
retval = defaultValue;
}
return retval;
}
This is a convenience method that will get the dictionary object that
is expected to be a date. Null is returned
if the entry does not exist in the dictionary. |
public COSBase getDictionaryObject(String key) {
return getDictionaryObject( COSName.getPDFName( key ) );
}
This will get an object from this dictionary. If the object is a reference then it will
dereference it and get it from the document. If the object is COSNull then
null will be returned. |
public COSBase getDictionaryObject(String[] keyList) {
COSBase retval = null;
for( int i=0; i< keyList.length && retval == null; i++ )
{
retval = getDictionaryObject( COSName.getPDFName( keyList[i] ) );
}
return retval;
}
This is a special case of getDictionaryObject that takes multiple keys, it will handle
the situation where multiple keys could get the same value, ie if either CS or ColorSpace
is used to get the colorspace.
This will get an object from this dictionary. If the object is a reference then it will
dereference it and get it from the document. If the object is COSNull then
null will be returned. |
public COSBase getDictionaryObject(COSName key) {
COSBase retval = items.get( key );
if( retval instanceof COSObject )
{
retval = ((COSObject)retval).getObject();
}
if( retval instanceof COSNull )
{
retval = null;
}
return retval;
}
This will get an object from this dictionary. If the object is a reference then it will
dereference it and get it from the document. If the object is COSNull then
null will be returned. |
public COSBase getDictionaryObject(String firstKey,
String secondKey) {
COSBase retval = getDictionaryObject( COSName.getPDFName( firstKey ) );
if( retval == null )
{
retval = getDictionaryObject( COSName.getPDFName( secondKey ) );
}
return retval;
}
This is a special case of getDictionaryObject that takes multiple keys, it will handle
the situation where multiple keys could get the same value, ie if either CS or ColorSpace
is used to get the colorspace.
This will get an object from this dictionary. If the object is a reference then it will
dereference it and get it from the document. If the object is COSNull then
null will be returned. |
public Calendar getEmbeddedDate(String embedded,
String key) throws IOException {
return getEmbeddedDate( embedded, COSName.getPDFName( key ), null );
}
This is a convenience method that will get the dictionary object that
is expected to be a name and convert it to a string. Null is returned
if the entry does not exist in the dictionary. |
public Calendar getEmbeddedDate(String embedded,
COSName key) throws IOException {
return getEmbeddedDate( embedded, key, null );
}
This is a convenience method that will get the dictionary object that
is expected to be a name and convert it to a string. Null is returned
if the entry does not exist in the dictionary. |
public Calendar getEmbeddedDate(String embedded,
String key,
Calendar defaultValue) throws IOException {
return getEmbeddedDate( embedded, COSName.getPDFName( key ), defaultValue );
}
This is a convenience method that will get the dictionary object that
is expected to be a date. Null is returned
if the entry does not exist in the dictionary. |
public Calendar getEmbeddedDate(String embedded,
COSName key,
Calendar defaultValue) throws IOException {
Calendar retval = defaultValue;
COSDictionary eDic = (COSDictionary)getDictionaryObject( embedded );
if( eDic != null )
{
retval = eDic.getDate( key, defaultValue );
}
return retval;
}
This is a convenience method that will get the dictionary object that
is expected to be a date. Null is returned
if the entry does not exist in the dictionary. |
public int getEmbeddedInt(String embeddedDictionary,
String key) {
return getEmbeddedInt( embeddedDictionary, COSName.getPDFName( key ) );
}
Get an integer from an embedded dictionary. Useful for 1-1 mappings. default:-1 |
public int getEmbeddedInt(String embeddedDictionary,
COSName key) {
return getEmbeddedInt( embeddedDictionary, key, -1 );
}
Get an integer from an embedded dictionary. Useful for 1-1 mappings. default:-1 |
public int getEmbeddedInt(String embeddedDictionary,
String key,
int defaultValue) {
return getEmbeddedInt( embeddedDictionary, COSName.getPDFName( key ), defaultValue );
}
Get an integer from an embedded dictionary. Useful for 1-1 mappings. |
public int getEmbeddedInt(String embeddedDictionary,
COSName key,
int defaultValue) {
int retval = defaultValue;
COSDictionary embedded = (COSDictionary)getDictionaryObject( embeddedDictionary );
if( embedded != null )
{
retval = embedded.getInt( key, defaultValue );
}
return retval;
}
Get an integer from an embedded dictionary. Useful for 1-1 mappings. |
public String getEmbeddedString(String embedded,
String key) {
return getEmbeddedString( embedded, COSName.getPDFName( key ), null );
}
This is a convenience method that will get the dictionary object that
is expected to be a name and convert it to a string. Null is returned
if the entry does not exist in the dictionary. |
public String getEmbeddedString(String embedded,
COSName key) {
return getEmbeddedString( embedded, key, null );
}
This is a convenience method that will get the dictionary object that
is expected to be a name and convert it to a string. Null is returned
if the entry does not exist in the dictionary. |
public String getEmbeddedString(String embedded,
String key,
String defaultValue) {
return getEmbeddedString( embedded, COSName.getPDFName( key ), defaultValue );
}
This is a convenience method that will get the dictionary object that
is expected to be a name and convert it to a string. Null is returned
if the entry does not exist in the dictionary. |
public String getEmbeddedString(String embedded,
COSName key,
String defaultValue) {
String retval = defaultValue;
COSDictionary dic = (COSDictionary)getDictionaryObject( embedded );
if( dic != null )
{
retval = dic.getString( key, defaultValue );
}
return retval;
}
This is a convenience method that will get the dictionary object that
is expected to be a name and convert it to a string. Null is returned
if the entry does not exist in the dictionary. |
public float getFloat(String key) {
return getFloat( COSName.getPDFName( key ), -1 );
}
This is a convenience method that will get the dictionary object that
is expected to be an float. -1 is returned if there is no value. |
public float getFloat(COSName key) {
return getFloat( key, -1 );
}
This is a convenience method that will get the dictionary object that
is expected to be an float. -1 is returned if there is no value. |
public float getFloat(String key,
float defaultValue) {
return getFloat( COSName.getPDFName( key ), defaultValue );
}
This is a convenience method that will get the dictionary object that
is expected to be a float. If the dictionary value is null then the
default Value will be returned. |
public float getFloat(COSName key,
float defaultValue) {
float retval = defaultValue;
COSBase obj = getDictionaryObject( key );
if( obj != null && obj instanceof COSNumber)
{
retval = ((COSNumber)obj).floatValue();
}
return retval;
}
This is a convenience method that will get the dictionary object that
is expected to be an float. If the dictionary value is null then the
default Value will be returned. |
public int getInt(String key) {
return getInt( COSName.getPDFName( key ), -1 );
}
This is a convenience method that will get the dictionary object that
is expected to be an int. -1 is returned if there is no value. |
public int getInt(COSName key) {
return getInt( key, -1 );
}
This is a convenience method that will get the dictionary object that
is expected to be an int. -1 is returned if there is no value. |
public int getInt(String[] keyList,
int defaultValue) {
int retval = defaultValue;
COSBase obj = getDictionaryObject( keyList );
if( obj != null && obj instanceof COSNumber)
{
retval = ((COSNumber)obj).intValue();
}
return retval;
}
This is a convenience method that will get the dictionary object that
is expected to be an integer. If the dictionary value is null then the
default Value will be returned. |
public int getInt(String key,
int defaultValue) {
return getInt( COSName.getPDFName( key ), defaultValue );
}
This is a convenience method that will get the dictionary object that
is expected to be an integer. If the dictionary value is null then the
default Value will be returned. |
public int getInt(COSName key,
int defaultValue) {
int retval = defaultValue;
COSBase obj = getDictionaryObject( key );
if( obj != null && obj instanceof COSNumber)
{
retval = ((COSNumber)obj).intValue();
}
return retval;
}
This is a convenience method that will get the dictionary object that
is expected to be an integer. If the dictionary value is null then the
default Value will be returned. |
public COSBase getItem(COSName key) {
return items.get( key );
}
This will do a lookup into the dictionary. |
public COSName getKeyForValue(Object value) {
for( Map.Entry< COSName, COSBase > entry : items.entrySet() )
{
Object nextValue = entry.getValue();
if( nextValue.equals( value ) ||
(nextValue instanceof COSObject &&
((COSObject)nextValue).getObject().equals( value))
)
{
return entry.getKey();
}
}
return null;
}
Search in the map for the value that matches the parameter
and return the first key that maps to that value. |
public long getLong(String key) {
return getLong( COSName.getPDFName( key ), -1L );
}
This is a convenience method that will get the dictionary object that
is expected to be an long. -1 is returned if there is no value. |
public long getLong(COSName key) {
return getLong( key, -1L );
}
This is a convenience method that will get the dictionary object that
is expected to be an long. -1 is returned if there is no value. |
public long getLong(String[] keyList,
long defaultValue) {
long retval = defaultValue;
COSBase obj = getDictionaryObject( keyList );
if( obj != null && obj instanceof COSNumber)
{
retval = ((COSNumber)obj).longValue();
}
return retval;
}
This is a convenience method that will get the dictionary object that
is expected to be an long. If the dictionary value is null then the
default Value will be returned. |
public long getLong(String key,
long defaultValue) {
return getLong( COSName.getPDFName( key ), defaultValue );
}
This is a convenience method that will get the dictionary object that
is expected to be an integer. If the dictionary value is null then the
default Value will be returned. |
public long getLong(COSName key,
long defaultValue) {
long retval = defaultValue;
COSBase obj = getDictionaryObject( key );
if( obj != null && obj instanceof COSNumber)
{
retval = ((COSNumber)obj).longValue();
}
return retval;
}
This is a convenience method that will get the dictionary object that
is expected to be an integer. If the dictionary value is null then the
default Value will be returned. |
public String getNameAsString(String key) {
return getNameAsString( COSName.getPDFName( key ) );
}
This is a convenience method that will get the dictionary object that
is expected to be a name and convert it to a string. Null is returned
if the entry does not exist in the dictionary. |
public String getNameAsString(COSName key) {
String retval = null;
COSBase name = getDictionaryObject( key );
if( name != null )
{
if ( name instanceof COSName)
{
retval = ((COSName)name).getName();
}
else if ( name instanceof COSString)
{
retval = ((COSString)name).getString();
}
}
return retval;
}
This is a convenience method that will get the dictionary object that
is expected to be a name and convert it to a string. Null is returned
if the entry does not exist in the dictionary. |
public String getNameAsString(String key,
String defaultValue) {
return getNameAsString( COSName.getPDFName( key ), defaultValue );
}
This is a convenience method that will get the dictionary object that
is expected to be a name and convert it to a string. Null is returned
if the entry does not exist in the dictionary. |
public String getNameAsString(COSName key,
String defaultValue) {
String retval = getNameAsString( key );
if( retval == null )
{
retval = defaultValue;
}
return retval;
}
This is a convenience method that will get the dictionary object that
is expected to be a name and convert it to a string. Null is returned
if the entry does not exist in the dictionary. |
public COSBase getObjectFromPath(String objPath) {
COSBase retval = null;
String[] path = objPath.split(PATH_SEPARATOR);
retval = this;
for (int i = 0; i < path.length; i++)
{
if(retval instanceof COSArray)
{
int idx = new Integer(path[i].replaceAll("\\[","").replaceAll("\\]","")).intValue();
retval = ((COSArray)retval).getObject(idx);
}
else if (retval instanceof COSDictionary)
{
retval = ((COSDictionary)retval).getDictionaryObject( path[i] );
}
}
return retval;
}
Nice method, gives you every object you want
Arrays works properly too. Try "P/Annots/[k]/Rect"
where k means the index of the Annotsarray. |
public String getString(String key) {
return getString( COSName.getPDFName( key ) );
}
This is a convenience method that will get the dictionary object that
is expected to be a name and convert it to a string. Null is returned
if the entry does not exist in the dictionary. |
public String getString(COSName key) {
String retval = null;
COSBase value = getDictionaryObject( key );
if( value != null && value instanceof COSString)
{
retval = ((COSString)value).getString();
}
return retval;
}
This is a convenience method that will get the dictionary object that
is expected to be a name and convert it to a string. Null is returned
if the entry does not exist in the dictionary. |
public String getString(String key,
String defaultValue) {
return getString( COSName.getPDFName( key ), defaultValue );
}
This is a convenience method that will get the dictionary object that
is expected to be a name and convert it to a string. Null is returned
if the entry does not exist in the dictionary. |
public String getString(COSName key,
String defaultValue) {
String retval = getString( key );
if( retval == null )
{
retval = defaultValue;
}
return retval;
}
This is a convenience method that will get the dictionary object that
is expected to be a name and convert it to a string. Null is returned
if the entry does not exist in the dictionary. |
public Collection<COSBase> getValues() {
return items.values();
}
This will get all of the values for the dictionary. |
public List<COSName> keyList() {
return new ArrayList< COSName >(items.keySet());
} Deprecated! Use - the #entrySet() method instead.
This will get the keys for all objects in the dictionary in the sequence that
they were added. |
public Set<COSName> keySet() {
return items.keySet();
}
Returns the names of the entries in this dictionary. The returned
set is in the order the entries were added to the dictionary. |
public void mergeInto(COSDictionary dic) {
for( Map.Entry< COSName, COSBase > entry : dic.entrySet() )
{
if( getItem( entry.getKey() ) == null )
{
setItem( entry.getKey(), entry.getValue() );
}
}
}
This will add all of the dictionarys keys/values to this dictionary, but only
if they don't already exist. If a key already exists in this dictionary then
nothing is changed. |
public void removeItem(COSName key) {
items.remove( key );
}
This will remove an item for the dictionary. This
will do nothing of the object does not exist. |
public void setBoolean(String key,
boolean value) {
setItem( COSName.getPDFName( key ), COSBoolean.getBoolean( value ) );
}
This will set an item in the dictionary. |
public void setBoolean(COSName key,
boolean value) {
setItem( key , COSBoolean.getBoolean( value ) );
}
This will set an item in the dictionary. |
public void setDate(String key,
Calendar date) {
setDate( COSName.getPDFName( key ), date );
}
Set the value of a date entry in the dictionary. |
public void setDate(COSName key,
Calendar date) {
setString( key, DateConverter.toString( date ) );
}
|
public void setEmbeddedDate(String embedded,
String key,
Calendar date) {
setEmbeddedDate( embedded, COSName.getPDFName( key ), date );
}
Set the value of a date entry in the dictionary. |
public void setEmbeddedDate(String embedded,
COSName key,
Calendar date) {
COSDictionary dic = (COSDictionary)getDictionaryObject( embedded );
if( dic == null && date != null )
{
dic = new COSDictionary();
setItem( embedded, dic );
}
if( dic != null )
{
dic.setDate( key, date );
}
}
|
public void setEmbeddedInt(String embeddedDictionary,
String key,
int value) {
setEmbeddedInt( embeddedDictionary, COSName.getPDFName( key ), value );
}
This is a convenience method that will convert the value to a COSInteger
object. |
public void setEmbeddedInt(String embeddedDictionary,
COSName key,
int value) {
COSDictionary embedded = (COSDictionary)getDictionaryObject( embeddedDictionary );
if( embedded == null )
{
embedded = new COSDictionary();
setItem( embeddedDictionary, embedded );
}
embedded.setInt( key, value );
}
This is a convenience method that will convert the value to a COSInteger
object. |
public void setEmbeddedString(String embedded,
String key,
String value) {
setEmbeddedString( embedded, COSName.getPDFName( key ), value );
}
This is a convenience method that will convert the value to a COSString
object. If it is null then the object will be removed. |
public void setEmbeddedString(String embedded,
COSName key,
String value) {
COSDictionary dic = (COSDictionary)getDictionaryObject( embedded );
if( dic == null && value != null )
{
dic = new COSDictionary();
setItem( embedded, dic );
}
if( dic != null )
{
dic.setString( key, value );
}
}
This is a convenience method that will convert the value to a COSString
object. If it is null then the object will be removed. |
public void setFloat(String key,
float value) {
setFloat( COSName.getPDFName( key ), value );
}
This is a convenience method that will convert the value to a COSFloat
object. |
public void setFloat(COSName key,
float value) {
COSFloat fltVal = new COSFloat( value );
setItem( key, fltVal );
}
This is a convenience method that will convert the value to a COSFloat
object. |
public void setInt(String key,
int value) {
setInt( COSName.getPDFName( key ), value );
}
This is a convenience method that will convert the value to a COSInteger
object. |
public void setInt(COSName key,
int value) {
setItem( key, COSInteger.get(value) );
}
This is a convenience method that will convert the value to a COSInteger
object. |
public void setItem(COSName key,
COSBase value) {
if( value == null )
{
removeItem( key );
}
else
{
items.put( key, value );
}
}
This will set an item in the dictionary. If value is null then the result
will be the same as removeItem( key ). |
public void setItem(COSName key,
COSObjectable value) {
COSBase base = null;
if( value != null )
{
base = value.getCOSObject();
}
setItem( key, base );
}
This will set an item in the dictionary. If value is null then the result
will be the same as removeItem( key ). |
public void setItem(String key,
COSObjectable value) {
setItem( COSName.getPDFName( key ), value );
}
This will set an item in the dictionary. If value is null then the result
will be the same as removeItem( key ). |
public void setItem(String key,
COSBase value) {
setItem( COSName.getPDFName( key ), value );
}
This will set an item in the dictionary. If value is null then the result
will be the same as removeItem( key ). |
public void setLong(String key,
long value) {
setLong( COSName.getPDFName( key ), value );
}
This is a convenience method that will convert the value to a COSInteger
object. |
public void setLong(COSName key,
long value) {
COSInteger intVal = null;
intVal = COSInteger.get(value);
setItem( key, intVal );
}
This is a convenience method that will convert the value to a COSInteger
object. |
public void setName(String key,
String value) {
setName( COSName.getPDFName( key ), value );
}
This is a convenience method that will convert the value to a COSName
object. If it is null then the object will be removed. |
public void setName(COSName key,
String value) {
COSName name = null;
if( value != null )
{
name = COSName.getPDFName( value );
}
setItem( key, name );
}
This is a convenience method that will convert the value to a COSName
object. If it is null then the object will be removed. |
public void setString(String key,
String value) {
setString( COSName.getPDFName( key ), value );
}
This is a convenience method that will convert the value to a COSString
object. If it is null then the object will be removed. |
public void setString(COSName key,
String value) {
COSString name = null;
if( value != null )
{
name = new COSString( value );
}
setItem( key, name );
}
This is a convenience method that will convert the value to a COSString
object. If it is null then the object will be removed. |
public int size() {
return items.size();
}
This will return the number of elements in this dictionary. |
public String toString() {
StringBuilder retVal = new StringBuilder("COSDictionary{");
for( COSName key : items.keySet() )
{
retVal.append("(" + key + ":" + getDictionaryObject(key).toString() + ") ");
}
retVal.append("}");
return retVal.toString();
}
|