pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r915098 - in /pdfbox/trunk/src/main/java/org/apache/pdfbox: cos/ encryption/ pdfparser/ pdfwriter/ pdmodel/
Date Mon, 22 Feb 2010 22:30:16 GMT
Author: jukka
Date: Mon Feb 22 22:30:15 2010
New Revision: 915098

URL: http://svn.apache.org/viewvc?rev=915098&view=rev
Log:
PDFBOX-626: Reduce the memory impact of the COS object model

Add and use more COSName constants.

Modified:
    pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSDocument.java
    pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSName.java
    pdfbox/trunk/src/main/java/org/apache/pdfbox/encryption/DocumentEncryption.java
    pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfparser/PDFXrefStreamParser.java
    pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
    pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/PDDestinationNameTreeNode.java
    pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentCatalog.java
    pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentNameDictionary.java

Modified: pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSDocument.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSDocument.java?rev=915098&r1=915097&r2=915098&view=diff
==============================================================================
--- pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSDocument.java (original)
+++ pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSDocument.java Mon Feb 22 22:30:15
2010
@@ -44,6 +44,8 @@
 public class COSDocument extends COSBase
 {
 
+    private static final COSName ENCRYPT = COSName.getPDFName("Encrypt");
+
     /**
      * Log instance.
      */
@@ -263,7 +265,7 @@
         boolean encrypted = false;
         if( trailer != null )
         {
-            encrypted = trailer.getDictionaryObject( "Encrypt" ) != null;
+            encrypted = trailer.getDictionaryObject( ENCRYPT ) != null;
         }
         return encrypted;
     }
@@ -276,7 +278,7 @@
      */
     public COSDictionary getEncryptionDictionary()
     {
-        return (COSDictionary)trailer.getDictionaryObject( COSName.getPDFName( "Encrypt"
) );
+        return (COSDictionary)trailer.getDictionaryObject( ENCRYPT );
     }
 
     /**
@@ -287,7 +289,7 @@
      */
     public void setEncryptionDictionary( COSDictionary encDictionary )
     {
-        trailer.setItem( COSName.getPDFName( "Encrypt" ), encDictionary );
+        trailer.setItem( ENCRYPT, encDictionary );
     }
 
     /**

Modified: pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSName.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSName.java?rev=915098&r1=915097&r2=915098&view=diff
==============================================================================
--- pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSName.java (original)
+++ pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSName.java Mon Feb 22 22:30:15 2010
@@ -162,6 +162,10 @@
      * A common COSName value.
      */
     public static final COSName CROP_BOX = new COSName(  "CropBox" );
+
+    /** "D" */
+    public static final String D = "D";
+
     /**
      * A common COSName value.
      */
@@ -178,6 +182,10 @@
      * A common COSName value.
      */
     public static final COSName DEST = new COSName(  "Dest" );
+
+    /** "Dests" */
+    public static final COSName DESTS = new COSName( "Dests" );
+
     /**
     * A common COSName value.
     */
@@ -206,6 +214,10 @@
     * A common COSName value.
     */
     public static final COSName DW = new COSName( "DW" );
+
+    /** "EmbeddedFiles" */
+    public static final COSName EMBEDDED_FILES = new COSName( "EmbeddedFiles" );
+
     /**
     * A common COSName value.
     */
@@ -226,6 +238,10 @@
      * A common COSName value.
      */
     public static final COSName ENCODING_ETEN_B5_V = new COSName( "ETen?B5?V" );
+
+    /** "Encrypt" */
+    public static final COSName ENCRYPT = new COSName("Encrypt");
+
     /**
      * A common COSName value.
      */
@@ -306,6 +322,10 @@
     * A common COSName value.
     */
     public static final COSName ICCBASED = new COSName( "ICCBased" );
+
+    /** "ID" */
+    public static final COSName ID = new COSName("ID");
+
     /**
     * A common COSName value.
     */
@@ -314,6 +334,10 @@
     * A common COSName value.
     */
     public static final COSName IMAGE = new COSName( "Image" );
+
+    /** "Index" */
+    public static final COSName INDEX = new COSName( "Index" );
+
     /**
     * A common COSName value.
     */
@@ -322,6 +346,10 @@
      * A common COSName value.
      */
     public static final COSName INFO = new COSName( "Info" );
+
+    /** "JavaScript" */
+    public static final COSName JAVA_SCRIPT = new COSName( "JavaScript" );
+
     /**
     * A common COSName value.
     */
@@ -334,6 +362,10 @@
     * A common COSName value.
     */
     public static final COSName LAB = new COSName( "Lab" );
+
+    /** "Lang" */
+    public static final COSName LANG = new COSName("Lang");
+
     /**
     * A common COSName value.
     */
@@ -358,6 +390,10 @@
     * A common COSName value.
     */
     public static final COSName MAC_ROMAN_ENCODING = new COSName( "MacRomanEncoding" );
+
+    /** "MarkInfo" */
+    public static final COSName MARK_INFO = new COSName("MarkInfo");
+
     /**
     * A common COSName value.
     */
@@ -382,6 +418,16 @@
     * A common COSName value.
     */
     public static final COSName NAME = new COSName( "Name" );
+
+    /** "Names" */
+    public static final COSName NAMES = new COSName("Names");
+
+    /** "Outlines" */
+    public static final COSName OUTLINES = new COSName("Outlines");
+
+    /** "OpenAction" */
+    public static final COSName OPEN_ACTION = new COSName("OpenAction");
+
     /**
     * A common COSName value.
     */
@@ -390,6 +436,16 @@
     * A common COSName value.
     */
     public static final COSName PAGE = new COSName( "Page" );
+
+    /** "PageLabels" */
+    public static final COSName PAGE_LABELS = new COSName("PageLabels");
+
+    /** "PageLayout" */
+    public static final COSName PAGE_LAYOUT = new COSName("PageLayout");
+
+    /** "PageMode" */
+    public static final COSName PAGE_MODE = new COSName("PageMode");
+
     /**
     * A common COSName value.
     */
@@ -438,14 +494,26 @@
     * A common COSName value.
     */
     public static final COSName SEPARATION = new COSName( "Separation" );
+
+    /** "Size" */
+    public static final COSName SIZE = new COSName( "Size" );
+
     /**
     * A common COSName value.
     */
     public static final COSName STANDARD_ENCODING = new COSName( "StandardEncoding" );
+
+    /** "StructTreeRoot" */
+    public static final COSName STRUCT_TREE_ROOT = new COSName("StructTreeRoot");
+
     /**
     * A common COSName value.
     */
     public static final COSName SUBTYPE = new COSName( "Subtype" );
+
+    /** "Threads" */
+    public static final COSName THREADS = new COSName("Threads");
+
     /**
      * A common COSName value.
      */
@@ -474,6 +542,10 @@
     * A common COSName value.
     */
     public static final COSName TYPE3 = new COSName(  "Type3" );
+
+    /** "URI" */
+    public static final COSName URI = new COSName("URI");
+
     /**
     * A common COSName value.
     */
@@ -481,7 +553,11 @@
     /**
      * A common COSName value.
      */
-     public static final COSName VERSION = new COSName( "Version" );
+    public static final COSName VERSION = new COSName( "Version" );
+
+    /** "ViewerPreferences" */
+    public static final COSName VIEWER_PREFERENCES = new COSName("ViewerPreferences");
+
     /**
      * A common COSName value.
      */

Modified: pdfbox/trunk/src/main/java/org/apache/pdfbox/encryption/DocumentEncryption.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/src/main/java/org/apache/pdfbox/encryption/DocumentEncryption.java?rev=915098&r1=915097&r2=915098&view=diff
==============================================================================
--- pdfbox/trunk/src/main/java/org/apache/pdfbox/encryption/DocumentEncryption.java (original)
+++ pdfbox/trunk/src/main/java/org/apache/pdfbox/encryption/DocumentEncryption.java Mon Feb
22 22:30:15 2010
@@ -251,12 +251,12 @@
     private void addDictionaryAndSubDictionary( Set set, COSDictionary dic )
     {
         set.add( dic );
-        COSArray kids = (COSArray)dic.getDictionaryObject( "Kids" );
+        COSArray kids = (COSArray)dic.getDictionaryObject( COSName.KIDS );
         for( int i=0; kids != null && i<kids.size(); i++ )
         {
             addDictionaryAndSubDictionary( set, (COSDictionary)kids.getObject( i ) );
         }
-        COSBase value = dic.getDictionaryObject( "V" );
+        COSBase value = dic.getDictionaryObject( COSName.V );
         if( value instanceof COSDictionary )
         {
             addDictionaryAndSubDictionary( set, (COSDictionary)value );

Modified: pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfparser/PDFXrefStreamParser.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfparser/PDFXrefStreamParser.java?rev=915098&r1=915097&r2=915098&view=diff
==============================================================================
--- pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfparser/PDFXrefStreamParser.java (original)
+++ pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfparser/PDFXrefStreamParser.java Mon Feb
22 22:30:15 2010
@@ -24,6 +24,7 @@
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSDocument;
 import org.apache.pdfbox.cos.COSInteger;
+import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.persistence.util.COSObjectKey;
@@ -62,8 +63,8 @@
     {
         try
         {
-            COSArray xrefFormat = (COSArray)stream.getDictionaryObject("W");
-            COSArray indexArray = (COSArray)stream.getDictionaryObject("Index");
+            COSArray xrefFormat = (COSArray)stream.getDictionaryObject(COSName.W);
+            COSArray indexArray = (COSArray)stream.getDictionaryObject(COSName.INDEX);
             /*
              * If Index doesn't exist, we will use the default values. 
              */
@@ -71,7 +72,7 @@
             {
                 indexArray = new COSArray();
                 indexArray.add(COSNumber.ZERO);
-                indexArray.add(stream.getDictionaryObject("Size"));
+                indexArray.add(stream.getDictionaryObject(COSName.SIZE));
             }
             
             ArrayList objNums = new ArrayList();

Modified: pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java?rev=915098&r1=915097&r2=915098&view=diff
==============================================================================
--- pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java (original)
+++ pdfbox/trunk/src/main/java/org/apache/pdfbox/pdfwriter/COSWriter.java Mon Feb 22 22:30:15
2010
@@ -343,8 +343,8 @@
     {
         COSDictionary trailer = doc.getTrailer();
         COSDictionary root = (COSDictionary)trailer.getDictionaryObject( COSName.ROOT );
-        COSDictionary info = (COSDictionary)trailer.getDictionaryObject( COSName.getPDFName(
"Info" ) );
-        COSDictionary encrypt = (COSDictionary)trailer.getDictionaryObject( COSName.getPDFName(
"Encrypt" ) );
+        COSDictionary info = (COSDictionary)trailer.getDictionaryObject( COSName.INFO );
+        COSDictionary encrypt = (COSDictionary)trailer.getDictionaryObject( COSName.ENCRYPT
);
         if( root != null )
         {
             addObjectToWrite( root );
@@ -1001,7 +1001,7 @@
             // don't try to decrypt a document which is not encrypted
             COSDocument cosDoc = doc.getDocument();
             COSDictionary trailer = cosDoc.getTrailer();
-            trailer.removeItem(COSName.getPDFName("Encrypt"));
+            trailer.removeItem(COSName.ENCRYPT);
         }
         else
         {
@@ -1030,7 +1030,7 @@
 
         COSDocument cosDoc = document.getDocument();
         COSDictionary trailer = cosDoc.getTrailer();
-        COSArray idArray = (COSArray)trailer.getDictionaryObject( "ID" );
+        COSArray idArray = (COSArray)trailer.getDictionaryObject( COSName.ID );
         if( idArray == null )
         {
             try
@@ -1040,7 +1040,7 @@
                 //the id.  We don't have path or size, so do the best we can
                 MessageDigest md = MessageDigest.getInstance( "MD5" );
                 md.update( Long.toString( System.currentTimeMillis()).getBytes() );
-                COSDictionary info = (COSDictionary)trailer.getDictionaryObject( "Info" );
+                COSDictionary info = (COSDictionary)trailer.getDictionaryObject( COSName.INFO
);
                 if( info != null )
                 {
                     Iterator values = info.getValues().iterator();
@@ -1053,7 +1053,7 @@
                 COSString id = new COSString( md.digest() );
                 idArray.add( id );
                 idArray.add( id );
-                trailer.setItem( "ID", idArray );
+                trailer.setItem( COSName.ID, idArray );
             }
             catch( NoSuchAlgorithmException e )
             {

Modified: pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/PDDestinationNameTreeNode.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/PDDestinationNameTreeNode.java?rev=915098&r1=915097&r2=915098&view=diff
==============================================================================
--- pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/PDDestinationNameTreeNode.java (original)
+++ pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/PDDestinationNameTreeNode.java Mon
Feb 22 22:30:15 2010
@@ -20,6 +20,7 @@
 
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.common.PDNameTreeNode;
 import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDDestination;
 import org.apache.pdfbox.pdmodel.interactive.documentnavigation.destination.PDPageDestination;
@@ -32,6 +33,7 @@
  */
 public class PDDestinationNameTreeNode extends PDNameTreeNode
 {
+
     /**
      * Constructor.
      */
@@ -61,7 +63,7 @@
             //the destination is sometimes stored in the D dictionary
             //entry instead of being directly an array, so just dereference
             //it for now
-            destination = ((COSDictionary)base).getDictionaryObject( "D" );
+            destination = ((COSDictionary)base).getDictionaryObject( COSName.D );
         }
         return PDDestination.create( destination );
     }

Modified: pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentCatalog.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentCatalog.java?rev=915098&r1=915097&r2=915098&view=diff
==============================================================================
--- pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentCatalog.java (original)
+++ pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentCatalog.java Mon Feb 22
22:30:15 2010
@@ -223,7 +223,7 @@
     public PDViewerPreferences getViewerPreferences()
     {
         PDViewerPreferences retval = null;
-        COSDictionary dict = (COSDictionary)root.getDictionaryObject( "ViewerPreferences"
);
+        COSDictionary dict = (COSDictionary)root.getDictionaryObject( COSName.VIEWER_PREFERENCES
);
         if( dict != null )
         {
             retval = new PDViewerPreferences( dict );
@@ -239,7 +239,7 @@
      */
     public void setViewerPreferences( PDViewerPreferences prefs )
     {
-        root.setItem( "ViewerPreferences", prefs );
+        root.setItem( COSName.VIEWER_PREFERENCES, prefs );
     }
 
     /**
@@ -251,7 +251,7 @@
     public PDDocumentOutline getDocumentOutline()
     {
         PDDocumentOutline retval = null;
-        COSDictionary dict = (COSDictionary)root.getDictionaryObject( "Outlines" );
+        COSDictionary dict = (COSDictionary)root.getDictionaryObject( COSName.OUTLINES );
         if( dict != null )
         {
             retval = new PDDocumentOutline( dict );
@@ -267,7 +267,7 @@
      */
     public void setDocumentOutline( PDDocumentOutline outlines )
     {
-        root.setItem( "Outlines", outlines );
+        root.setItem( COSName.OUTLINES, outlines );
     }
 
     /**
@@ -277,11 +277,11 @@
      */
     public List getThreads()
     {
-        COSArray array = (COSArray)root.getDictionaryObject( "Threads" );
+        COSArray array = (COSArray)root.getDictionaryObject( COSName.THREADS );
         if( array == null )
         {
             array = new COSArray();
-            root.setItem( "Threads", array );
+            root.setItem( COSName.THREADS, array );
         }
         List pdObjects = new ArrayList();
         for( int i=0; i<array.size(); i++ )
@@ -298,7 +298,7 @@
      */
     public void setThreads( List threads )
     {
-        root.setItem( "Threads", COSArrayList.converterToCOSArray( threads ) );
+        root.setItem( COSName.THREADS, COSArrayList.converterToCOSArray( threads ) );
     }
 
     /**
@@ -310,7 +310,7 @@
     public PDMetadata getMetadata()
     {
         PDMetadata retval = null;
-        COSStream stream = (COSStream)root.getDictionaryObject( "Metadata" );
+        COSStream stream = (COSStream)root.getDictionaryObject( COSName.METADATA );
         if( stream != null )
         {
             retval = new PDMetadata( stream );
@@ -325,7 +325,7 @@
      */
     public void setMetadata( PDMetadata meta )
     {
-        root.setItem( "Metadata", meta );
+        root.setItem( COSName.METADATA, meta );
     }
 
     /**
@@ -335,7 +335,7 @@
      */
     public void setOpenAction( PDDestinationOrAction action )
     {
-        root.setItem( COSName.getPDFName("OpenAction"), action );
+        root.setItem( COSName.OPEN_ACTION, action );
     }
 
     /**
@@ -349,7 +349,7 @@
     public PDDestinationOrAction getOpenAction() throws IOException
     {
         PDDestinationOrAction action = null;
-        COSBase actionObj = root.getDictionaryObject("OpenAction");
+        COSBase actionObj = root.getDictionaryObject(COSName.OPEN_ACTION);
 
         if( actionObj == null )
         {
@@ -375,11 +375,11 @@
      */
     public PDDocumentCatalogAdditionalActions getActions()
     {
-        COSDictionary addAct = (COSDictionary) root.getDictionaryObject("AA");
+        COSDictionary addAct = (COSDictionary) root.getDictionaryObject( COSName.AA );
         if (addAct == null)
         {
             addAct = new COSDictionary();
-            root.setItem("AA", addAct);
+            root.setItem(COSName.AA, addAct);
         }
         return new PDDocumentCatalogAdditionalActions(addAct);
     }
@@ -391,7 +391,7 @@
      */
     public void setActions( PDDocumentCatalogAdditionalActions actions )
     {
-        root.setItem("AA", actions );
+        root.setItem(COSName.AA, actions );
     }
 
     /**
@@ -400,7 +400,7 @@
     public PDDocumentNameDictionary getNames()
     {
         PDDocumentNameDictionary nameDic = null;
-        COSDictionary names = (COSDictionary) root.getDictionaryObject("Names");
+        COSDictionary names = (COSDictionary) root.getDictionaryObject(COSName.NAMES);
         if(names != null)
         {
             nameDic = new PDDocumentNameDictionary(this,names);
@@ -415,7 +415,7 @@
      */
     public void setNames( PDDocumentNameDictionary names )
     {
-        root.setItem("Names", names );
+        root.setItem(COSName.NAMES, names );
     }
 
     /**
@@ -427,7 +427,7 @@
     public PDMarkInfo getMarkInfo()
     {
         PDMarkInfo retval = null;
-        COSDictionary dic = (COSDictionary)root.getDictionaryObject( "MarkInfo" );
+        COSDictionary dic = (COSDictionary)root.getDictionaryObject( COSName.MARK_INFO );
         if( dic != null )
         {
             retval = new PDMarkInfo( dic );
@@ -442,7 +442,7 @@
      */
     public void setMarkInfo( PDMarkInfo markInfo )
     {
-        root.setItem( "MarkInfo", markInfo );
+        root.setItem( COSName.MARK_INFO, markInfo );
     }
 
     /**
@@ -451,7 +451,7 @@
      */
     public String getPageMode()
     {
-        return root.getNameAsString( "PageMode", PAGE_MODE_USE_NONE );
+        return root.getNameAsString( COSName.PAGE_MODE, PAGE_MODE_USE_NONE );
     }
 
     /**
@@ -460,7 +460,7 @@
      */
     public void setPageMode( String mode )
     {
-        root.setName( "PageMode", mode );
+        root.setName( COSName.PAGE_MODE, mode );
     }
 
     /**
@@ -469,7 +469,7 @@
      */
     public String getPageLayout()
     {
-        return root.getNameAsString( "PageLayout", PAGE_LAYOUT_SINGLE_PAGE );
+        return root.getNameAsString( COSName.PAGE_LAYOUT, PAGE_LAYOUT_SINGLE_PAGE );
     }
 
     /**
@@ -478,7 +478,7 @@
      */
     public void setPageLayout( String layout )
     {
-        root.setName( "PageLayout", layout );
+        root.setName( COSName.PAGE_LAYOUT, layout );
     }
 
     /**
@@ -488,7 +488,7 @@
     public PDURIDictionary getURI()
     {
         PDURIDictionary retval = null;
-        COSDictionary uri = (COSDictionary)root.getDictionaryObject( "URI" );
+        COSDictionary uri = (COSDictionary)root.getDictionaryObject( COSName.URI );
         if( uri != null )
         {
             retval = new PDURIDictionary( uri );
@@ -502,7 +502,7 @@
      */
     public void setURI( PDURIDictionary uri )
     {
-        root.setItem( "URI", uri );
+        root.setItem( COSName.URI, uri );
     }
 
     /**
@@ -513,7 +513,7 @@
     public PDStructureTreeRoot getStructureTreeRoot()
     {
         PDStructureTreeRoot treeRoot = null;
-        COSDictionary dic = (COSDictionary)root.getDictionaryObject( "StructTreeRoot" );
+        COSDictionary dic = (COSDictionary)root.getDictionaryObject( COSName.STRUCT_TREE_ROOT
);
         if( dic != null )
         {
             treeRoot = new PDStructureTreeRoot( dic );
@@ -528,7 +528,7 @@
      */
     public void setStructureTreeRoot( PDStructureTreeRoot treeRoot )
     {
-        root.setItem( "StructTreeRoot", treeRoot );
+        root.setItem( COSName.STRUCT_TREE_ROOT, treeRoot );
     }
 
     /**
@@ -538,7 +538,7 @@
      */
     public String getLanguage()
     {
-        return root.getString( "Lang" );
+        return root.getString( COSName.LANG );
     }
 
     /**
@@ -548,7 +548,7 @@
      */
     public void setLanguage( String language )
     {
-        root.setString( "Lang", language );
+        root.setString( COSName.LANG, language );
     }
 
     /**
@@ -561,7 +561,7 @@
     public PDPageLabels getPageLabels() throws IOException 
     {
         PDPageLabels labels = null;
-        COSDictionary dict = (COSDictionary) root.getDictionaryObject("PageLabels");
+        COSDictionary dict = (COSDictionary) root.getDictionaryObject(COSName.PAGE_LABELS);
         if (dict != null) 
         {
             labels = new PDPageLabels(document, dict);
@@ -576,7 +576,7 @@
      */
     public void setPageLabels(PDPageLabels labels) 
     {
-        root.setItem("PageLabels", labels);
+        root.setItem(COSName.PAGE_LABELS, labels);
     }
 
 }

Modified: pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentNameDictionary.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentNameDictionary.java?rev=915098&r1=915097&r2=915098&view=diff
==============================================================================
--- pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentNameDictionary.java (original)
+++ pdfbox/trunk/src/main/java/org/apache/pdfbox/pdmodel/PDDocumentNameDictionary.java Mon
Feb 22 22:30:15 2010
@@ -18,6 +18,7 @@
 
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
 
 /**
@@ -84,13 +85,13 @@
     {
         PDDestinationNameTreeNode dests = null;
 
-        COSDictionary dic = (COSDictionary)nameDictionary.getDictionaryObject( "Dests" );
+        COSDictionary dic = (COSDictionary)nameDictionary.getDictionaryObject( COSName.DESTS
);
 
         //The document catalog also contains the Dests entry sometimes
         //so check there as well.
         if( dic == null )
         {
-            dic = (COSDictionary)catalog.getCOSDictionary().getDictionaryObject( "Dests"
);
+            dic = (COSDictionary)catalog.getCOSDictionary().getDictionaryObject( COSName.DESTS
);
         }
 
         if( dic != null )
@@ -109,13 +110,13 @@
      */
     public void setDests( PDDestinationNameTreeNode dests )
     {
-        nameDictionary.setItem( "Dests", dests );
+        nameDictionary.setItem( COSName.DESTS, dests );
         //The dests can either be in the document catalog or in the
         //names dictionary, PDFBox will just maintain the one in the
         //names dictionary for now unless there is a reason to do
         //something else.
         //clear the potentially out of date Dests reference.
-        catalog.getCOSDictionary().setItem( "Dests", (COSObjectable)null);
+        catalog.getCOSDictionary().setItem( COSName.DESTS, (COSObjectable)null);
     }
 
     /**
@@ -128,7 +129,7 @@
     {
         PDEmbeddedFilesNameTreeNode retval = null;
 
-        COSDictionary dic = (COSDictionary)nameDictionary.getDictionaryObject( "EmbeddedFiles"
);
+        COSDictionary dic = (COSDictionary)nameDictionary.getDictionaryObject( COSName.EMBEDDED_FILES
);
 
         if( dic != null )
         {
@@ -145,7 +146,7 @@
      */
     public void setEmbeddedFiles( PDEmbeddedFilesNameTreeNode ef )
     {
-        nameDictionary.setItem( "EmbeddedFiles", ef );
+        nameDictionary.setItem( COSName.EMBEDDED_FILES, ef );
     }
 
     /**
@@ -157,7 +158,7 @@
     {
         PDJavascriptNameTreeNode retval = null;
 
-        COSDictionary dic = (COSDictionary)nameDictionary.getDictionaryObject( "JavaScript"
);
+        COSDictionary dic = (COSDictionary)nameDictionary.getDictionaryObject( COSName.JAVA_SCRIPT
);
 
         if( dic != null )
         {
@@ -174,6 +175,6 @@
      */
     public void setJavascript( PDJavascriptNameTreeNode js )
     {
-        nameDictionary.setItem( "JavaScript", js );
+        nameDictionary.setItem( COSName.JAVA_SCRIPT, js );
     }
 }



Mime
View raw message