You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by le...@apache.org on 2012/04/15 19:26:09 UTC

svn commit: r1326383 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: cos/COSName.java pdmodel/fdf/FDFDictionary.java

Author: lehmi
Date: Sun Apr 15 17:26:08 2012
New Revision: 1326383

URL: http://svn.apache.org/viewvc?rev=1326383&view=rev
Log:
PDFBOX-1281: fixed the parsing of FDF fields as proposed by Ilya Sazonov

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDictionary.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java?rev=1326383&r1=1326382&r2=1326383&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java Sun Apr 15 17:26:08 2012
@@ -462,6 +462,11 @@ public final class COSName extends COSBa
     /**
      * A common COSName value.
      */
+    public static final COSName EMBEDDED_FDFS = new COSName( "EmbeddedFDFs" );
+    
+    /**
+     * A common COSName value.
+     */
     public static final COSName ENCODE = new COSName( "Encode" );
     /**
      * A common COSName value.
@@ -1138,6 +1143,10 @@ public final class COSName extends COSBa
     /**
      * A common COSName value.
      */
+    public static final COSName STATUS = new COSName( "Status" );
+    /**
+     * A common COSName value.
+     */
     public static final COSName STD_CF = new COSName( "StdCF" );
     /**
      * A common COSName value.
@@ -1190,6 +1199,11 @@ public final class COSName extends COSBa
     /**
      * A common COSName value.
      */
+    public static final COSName TARGET = new COSName("Target");
+
+    /**
+     * A common COSName value.
+     */
     public static final COSName THREADS = new COSName("Threads");
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDictionary.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDictionary.java?rev=1326383&r1=1326382&r2=1326383&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDictionary.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFDictionary.java Sun Apr 15 17:26:08 2012
@@ -24,6 +24,7 @@ import java.util.List;
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
+import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.cos.COSString;
 
@@ -97,11 +98,19 @@ public class FDFDictionary implements CO
                 }
                 else if( child.getTagName().equals( "fields" ) )
                 {
-                    NodeList fields = child.getElementsByTagName( "field" );
+                    NodeList fields = child.getChildNodes();
                     List fieldList = new ArrayList();
                     for( int f=0; f<fields.getLength(); f++ )
                     {
                         fieldList.add( new FDFField( (Element)fields.item( f ) ) );
+                        Node currentNode = fields.item( f );
+                        if (currentNode instanceof Element) 
+                        {
+                            if (((Element)currentNode).getTagName().equals("field")) 
+                            {
+                                fieldList.add( new FDFField( (Element)fields.item( f ) ) );
+                            }
+                        }
                     }
                     setFields( fieldList );
                 }
@@ -195,7 +204,7 @@ public class FDFDictionary implements CO
      */
     public PDFileSpecification getFile() throws IOException
     {
-        return PDFileSpecification.createFS( fdf.getDictionaryObject( "F" ) );
+        return PDFileSpecification.createFS( fdf.getDictionaryObject( COSName.F ) );
     }
 
     /**
@@ -205,7 +214,7 @@ public class FDFDictionary implements CO
      */
     public void setFile( PDFileSpecification fs )
     {
-        fdf.setItem( "F", fs );
+        fdf.setItem( COSName.F, fs );
     }
 
     /**
@@ -215,7 +224,7 @@ public class FDFDictionary implements CO
      */
     public COSArray getID()
     {
-        return (COSArray)fdf.getDictionaryObject( "ID" );
+        return (COSArray)fdf.getDictionaryObject( COSName.ID );
     }
 
     /**
@@ -225,7 +234,7 @@ public class FDFDictionary implements CO
      */
     public void setID( COSArray id )
     {
-        fdf.setItem( "ID", id );
+        fdf.setItem( COSName.ID, id );
     }
 
     /**
@@ -237,10 +246,10 @@ public class FDFDictionary implements CO
     public List getFields()
     {
         List retval = null;
-        COSArray fieldArray = (COSArray)fdf.getDictionaryObject( "Fields" );
+        COSArray fieldArray = (COSArray)fdf.getDictionaryObject( COSName.FIELDS );
         if( fieldArray != null )
         {
-            List fields = new ArrayList();
+            List<FDFField> fields = new ArrayList<FDFField>();
             for( int i=0; i<fieldArray.size(); i++ )
             {
                 fields.add( new FDFField( (COSDictionary)fieldArray.getObject( i ) ) );
@@ -257,7 +266,7 @@ public class FDFDictionary implements CO
      */
     public void setFields( List fields )
     {
-        fdf.setItem( "Fields", COSArrayList.converterToCOSArray( fields ) );
+        fdf.setItem( COSName.FIELDS, COSArrayList.converterToCOSArray( fields ) );
     }
 
     /**
@@ -268,7 +277,7 @@ public class FDFDictionary implements CO
      */
     public String getStatus()
     {
-        return fdf.getString( "Status" );
+        return fdf.getString( COSName.STATUS );
     }
 
     /**
@@ -278,7 +287,7 @@ public class FDFDictionary implements CO
      */
     public void setStatus( String status )
     {
-        fdf.setString( "Status", status );
+        fdf.setString( COSName.STATUS, status );
     }
 
     /**
@@ -289,10 +298,10 @@ public class FDFDictionary implements CO
     public List getPages()
     {
         List retval = null;
-        COSArray pageArray = (COSArray)fdf.getDictionaryObject( "Pages" );
+        COSArray pageArray = (COSArray)fdf.getDictionaryObject( COSName.PAGES );
         if( pageArray != null )
         {
-            List pages = new ArrayList();
+            List<FDFPage> pages = new ArrayList<FDFPage>();
             for( int i=0; i<pageArray.size(); i++ )
             {
                 pages.add( new FDFPage( (COSDictionary)pageArray.get( i ) ) );
@@ -310,7 +319,7 @@ public class FDFDictionary implements CO
      */
     public void setPages( List pages )
     {
-        fdf.setItem( "Pages", COSArrayList.converterToCOSArray( pages ) );
+        fdf.setItem( COSName.PAGES, COSArrayList.converterToCOSArray( pages ) );
     }
 
     /**
@@ -321,7 +330,7 @@ public class FDFDictionary implements CO
      */
     public String getEncoding()
     {
-        String encoding = fdf.getNameAsString( "Encoding" );
+        String encoding = fdf.getNameAsString( COSName.ENCODING );
         if( encoding == null )
         {
             encoding = "PDFDocEncoding";
@@ -337,7 +346,7 @@ public class FDFDictionary implements CO
      */
     public void setEncoding( String encoding )
     {
-        fdf.setName( "Encoding", encoding );
+        fdf.setName( COSName.ENCODING, encoding );
     }
 
     /**
@@ -351,10 +360,10 @@ public class FDFDictionary implements CO
     public List getAnnotations() throws IOException
     {
         List retval = null;
-        COSArray annotArray = (COSArray)fdf.getDictionaryObject( "Annots" );
+        COSArray annotArray = (COSArray)fdf.getDictionaryObject( COSName.ANNOTS );
         if( annotArray != null )
         {
-            List annots = new ArrayList();
+            List<FDFAnnotation> annots = new ArrayList<FDFAnnotation>();
             for( int i=0; i<annotArray.size(); i++ )
             {
                 annots.add( FDFAnnotation.create( (COSDictionary)annotArray.getObject( i ) ) );
@@ -372,7 +381,7 @@ public class FDFDictionary implements CO
      */
     public void setAnnotations( List annots )
     {
-        fdf.setItem( "Annots", COSArrayList.converterToCOSArray( annots ) );
+        fdf.setItem( COSName.ANNOTS, COSArrayList.converterToCOSArray( annots ) );
     }
 
     /**
@@ -382,7 +391,7 @@ public class FDFDictionary implements CO
      */
     public COSStream getDifferences()
     {
-        return (COSStream)fdf.getDictionaryObject( "Differences" );
+        return (COSStream)fdf.getDictionaryObject( COSName.DIFFERENCES );
     }
 
     /**
@@ -392,7 +401,7 @@ public class FDFDictionary implements CO
      */
     public void setDifferences( COSStream diff )
     {
-        fdf.setItem( "Differences", diff );
+        fdf.setItem( COSName.DIFFERENCES, diff );
     }
 
     /**
@@ -402,7 +411,7 @@ public class FDFDictionary implements CO
      */
     public String getTarget()
     {
-        return fdf.getString( "Target" );
+        return fdf.getString( COSName.TARGET );
     }
 
     /**
@@ -412,7 +421,7 @@ public class FDFDictionary implements CO
      */
     public void setTarget( String target )
     {
-        fdf.setString( "Target", target );
+        fdf.setString( COSName.TARGET, target );
     }
 
     /**
@@ -426,10 +435,10 @@ public class FDFDictionary implements CO
     public List getEmbeddedFDFs() throws IOException
     {
         List retval = null;
-        COSArray embeddedArray = (COSArray)fdf.getDictionaryObject( "EmbeddedFDFs" );
+        COSArray embeddedArray = (COSArray)fdf.getDictionaryObject( COSName.EMBEDDED_FDFS );
         if( embeddedArray != null )
         {
-            List embedded = new ArrayList();
+            List<PDFileSpecification> embedded = new ArrayList<PDFileSpecification>();
             for( int i=0; i<embeddedArray.size(); i++ )
             {
                 embedded.add( PDFileSpecification.createFS( embeddedArray.get( i ) ) );
@@ -448,7 +457,7 @@ public class FDFDictionary implements CO
      */
     public void setEmbeddedFDFs( List embedded )
     {
-        fdf.setItem( "EmbeddedFDFs", COSArrayList.converterToCOSArray( embedded ) );
+        fdf.setItem( COSName.EMBEDDED_FDFS, COSArrayList.converterToCOSArray( embedded ) );
     }
 
     /**
@@ -459,7 +468,7 @@ public class FDFDictionary implements CO
     public FDFJavaScript getJavaScript()
     {
         FDFJavaScript fs = null;
-        COSDictionary dic = (COSDictionary)fdf.getDictionaryObject( "JavaScript" );
+        COSDictionary dic = (COSDictionary)fdf.getDictionaryObject( COSName.JAVA_SCRIPT );
         if( dic != null )
         {
             fs = new FDFJavaScript( dic );
@@ -474,7 +483,7 @@ public class FDFDictionary implements CO
      */
     public void setJavaScript( FDFJavaScript js )
     {
-        fdf.setItem( "JavaScript", js );
+        fdf.setItem( COSName.JAVA_SCRIPT, js );
     }
 
 }