You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ja...@apache.org on 2014/03/14 20:54:56 UTC

svn commit: r1577683 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java

Author: jahewson
Date: Fri Mar 14 19:54:56 2014
New Revision: 1577683

URL: http://svn.apache.org/r1577683
Log:
PDFBOX-1988: add getName to COSDictionary

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java?rev=1577683&r1=1577682&r2=1577683&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSDictionary.java Fri Mar 14 19:54:56 2014
@@ -585,6 +585,47 @@ public class COSDictionary extends COSBa
         setInt(field, currentFlags);
     }
 
+    /**
+     * This is a convenience method that will get the dictionary object that
+     * is expected to be a name. Null is returned if the entry does not exist in the dictionary.
+     *
+     * @param key The key to the item in the dictionary.
+     * @return The COS name.
+     */
+    public COSName getName( COSName key )
+    {
+        COSBase name = getDictionaryObject( key );
+        if( name != null )
+        {
+            if ( name instanceof COSName )
+            {
+                return (COSName) name;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * This is a convenience method that will get the dictionary object that
+     * is expected to be a name. Default is returned if the entry does not exist in the dictionary.
+     *
+     * @param key The key to the item in the dictionary.
+     * @param defaultValue The value to return if the dictionary item is null.
+     * @return The COS name.
+     */
+    public COSName getName( COSName key, COSName defaultValue )
+    {
+        COSBase name = getDictionaryObject( key );
+        if( name != null )
+        {
+            if ( name instanceof COSName )
+            {
+                return (COSName) name;
+            }
+        }
+        return 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