pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jahew...@apache.org
Subject svn commit: r1679299 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox: cos/ pdmodel/ pdmodel/common/ pdmodel/fdf/ pdmodel/interactive/action/ pdmodel/interactive/annotation/ pdmodel/interactive/form/
Date Wed, 13 May 2015 23:55:00 GMT
Author: jahewson
Date: Wed May 13 23:54:59 2015
New Revision: 1679299

URL: http://svn.apache.org/r1679299
Log:
PDFBOX-2798: Replace PDTextStream with String

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSName.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDJavascriptNameTreeNode.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSArrayList.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFField.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFJavaScript.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionJavaScript.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationMarkup.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGenerator.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDVariableText.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=1679299&r1=1679298&r2=1679299&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 Wed May 13 23:54:59
2015
@@ -291,6 +291,7 @@ public final class COSName extends COSBa
     public static final COSName JBIG2_DECODE = new COSName("JBIG2Decode");
     public static final COSName JBIG2_GLOBALS = new COSName("JBIG2Globals");
     public static final COSName JPX_DECODE = new COSName("JPXDecode");
+    public static final COSName JS = new COSName("JS");
     // K
     public static final COSName K = new COSName("K");
     public static final COSName KEYWORDS = new COSName("Keywords");

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java?rev=1679299&r1=1679298&r2=1679299&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/cos/COSStream.java Wed May 13 23:54:59
2015
@@ -19,6 +19,7 @@ package org.apache.pdfbox.cos;
 import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.Closeable;
 import java.io.File;
 import java.io.IOException;
@@ -493,6 +494,30 @@ public class COSStream extends COSDictio
     }
 
     /**
+     * Returns the contents of the stream as a text string.
+     */
+    public String getString()
+    {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        InputStream input = null;
+        try
+        {
+            input = getUnfilteredStream();
+            IOUtils.copy(input, out);
+        }
+        catch (IOException e)
+        {
+            return "";
+        }
+        finally
+        {
+            IOUtils.closeQuietly(input);
+        }
+        COSString string = new COSString(out.toByteArray());
+        return string.getString();
+    }
+    
+    /**
      * This will create a new stream for which filtered byte should be
      * written to.  You probably don't want this but want to use the
      * createUnfilteredStream, which is used to write raw bytes to.

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDJavascriptNameTreeNode.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDJavascriptNameTreeNode.java?rev=1679299&r1=1679298&r2=1679299&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDJavascriptNameTreeNode.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/PDJavascriptNameTreeNode.java
Wed May 13 23:54:59 2015
@@ -17,14 +17,12 @@
 package org.apache.pdfbox.pdmodel;
 
 import java.io.IOException;
-
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
-import org.apache.pdfbox.cos.COSStream;
-import org.apache.pdfbox.cos.COSString;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
 import org.apache.pdfbox.pdmodel.common.PDNameTreeNode;
-import org.apache.pdfbox.pdmodel.common.PDTextStream;
+import org.apache.pdfbox.pdmodel.interactive.action.PDActionFactory;
+import org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript;
 
 /**
  * This class holds all of the name trees that are available at the document level.
@@ -38,7 +36,7 @@ public class PDJavascriptNameTreeNode ex
      */
     public PDJavascriptNameTreeNode()
     {
-        super( PDTextStream.class );
+        super( PDActionJavaScript.class );
     }
 
     /**
@@ -48,7 +46,7 @@ public class PDJavascriptNameTreeNode ex
      */
     public PDJavascriptNameTreeNode( COSDictionary dic )
     {
-        super( dic, PDTextStream.class );
+        super( dic, PDActionJavaScript.class );
     }
 
     /**
@@ -56,21 +54,11 @@ public class PDJavascriptNameTreeNode ex
      */
     protected COSObjectable convertCOSToPD( COSBase base ) throws IOException
     {
-        PDTextStream stream = null;
-        if( base instanceof COSString )
-        {
-            stream = new PDTextStream((COSString)base);
-        }
-        else if( base instanceof COSStream )
-        {
-            stream = new PDTextStream((COSStream)base);
-        }
-        else
+        if (!(base instanceof COSDictionary))
         {
-            throw new IOException( "Error creating Javascript object, expected either COSString
or COSStream and not " 
-                    + base );
+            throw new IOException( "Error creating Javascript object, expected a COSDictionary
and not " + base);
         }
-        return stream;
+        return PDActionFactory.createAction((COSDictionary) base);
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSArrayList.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSArrayList.java?rev=1679299&r1=1679298&r2=1679299&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSArrayList.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSArrayList.java Wed
May 13 23:54:59 2015
@@ -168,12 +168,6 @@ public class COSArrayList<E> implements
         {
             array.add( new COSString( (String)o ) );
         }
-        else if( o instanceof DualCOSObjectable )
-        {
-            DualCOSObjectable dual = (DualCOSObjectable)o;
-            array.add( dual.getFirstCOSObject() );
-            array.add( dual.getSecondCOSObject() );
-        }
         else
         {
             if(array != null)
@@ -248,14 +242,7 @@ public class COSArrayList<E> implements
             parentDict = null;
         }
 
-        if( c.size() >0 && c.toArray()[0] instanceof DualCOSObjectable )
-        {
-            array.addAll( index*2, toCOSObjectList( c ) );
-        }
-        else
-        {
-            array.addAll( index, toCOSObjectList( c ) );
-        }
+        array.addAll( index, toCOSObjectList( c ) );
         return actual.addAll( index, c );
     }
 
@@ -438,12 +425,6 @@ public class COSArrayList<E> implements
                         COSObjectable object = (COSObjectable)next;
                         array.add( object.getCOSObject() );
                     }
-                    else if( next instanceof DualCOSObjectable )
-                    {
-                        DualCOSObjectable object = (DualCOSObjectable)next;
-                        array.add( object.getFirstCOSObject() );
-                        array.add( object.getSecondCOSObject() );
-                    }
                     else if( next == null )
                     {
                         array.add( COSNull.NULL );
@@ -470,12 +451,6 @@ public class COSArrayList<E> implements
             {
                 cosObjects.add( new COSString( (String)next ) );
             }
-            else if( next instanceof DualCOSObjectable )
-            {
-                DualCOSObjectable object = (DualCOSObjectable)next;
-                array.add( object.getFirstCOSObject() );
-                array.add( object.getSecondCOSObject() );
-            }
             else
             {
                 COSObjectable cos = (COSObjectable)next;
@@ -564,12 +539,6 @@ public class COSArrayList<E> implements
             }
             array.set( index, item );
         }
-        else if( element instanceof DualCOSObjectable )
-        {
-            DualCOSObjectable dual = (DualCOSObjectable)element;
-            array.set( index*2, dual.getFirstCOSObject() );
-            array.set( index*2+1, dual.getSecondCOSObject() );
-        }
         else
         {
             if( parentDict != null && index == 0 )
@@ -601,12 +570,6 @@ public class COSArrayList<E> implements
         {
             array.add( index, new COSString( (String)element ) );
         }
-        else if( element instanceof DualCOSObjectable )
-        {
-            DualCOSObjectable dual = (DualCOSObjectable)element;
-            array.add( index*2, dual.getFirstCOSObject() );
-            array.add( index*2+1, dual.getSecondCOSObject() );
-        }
         else
         {
             array.add( index, ((COSObjectable)element).getCOSObject() );
@@ -619,16 +582,7 @@ public class COSArrayList<E> implements
     @Override
     public E remove(int index)
     {
-        if( array.size() > index && array.get( index ) instanceof DualCOSObjectable
)
-        {
-            //remove both objects
-            array.remove( index );
-            array.remove( index );
-        }
-        else
-        {
-            array.remove( index );
-        }
+        array.remove( index );
         return actual.remove( index );
     }
 

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFField.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFField.java?rev=1679299&r1=1679298&r2=1679299&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFField.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFField.java Wed May
13 23:54:59 2015
@@ -18,10 +18,8 @@ package org.apache.pdfbox.pdmodel.fdf;
 
 import java.io.IOException;
 import java.io.Writer;
-
 import java.util.ArrayList;
 import java.util.List;
-
 import org.apache.pdfbox.cos.COSArray;
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
@@ -30,17 +28,12 @@ import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.cos.COSStream;
 import org.apache.pdfbox.cos.COSString;
-
-import org.apache.pdfbox.pdmodel.common.COSObjectable;
 import org.apache.pdfbox.pdmodel.common.COSArrayList;
-import org.apache.pdfbox.pdmodel.common.PDTextStream;
-
+import org.apache.pdfbox.pdmodel.common.COSObjectable;
+import org.apache.pdfbox.pdmodel.interactive.action.PDAction;
 import org.apache.pdfbox.pdmodel.interactive.action.PDActionFactory;
 import org.apache.pdfbox.pdmodel.interactive.action.PDAdditionalActions;
-import org.apache.pdfbox.pdmodel.interactive.action.PDAction;
-
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAppearanceDictionary;
-
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
@@ -96,7 +89,7 @@ public class FDFField implements COSObje
                 }
                 else if( child.getTagName().equals( "value-richtext" ) )
                 {
-                    setRichText( new PDTextStream( XMLUtil.getNodeValue( child ) ) );
+                    setRichText( new COSString( XMLUtil.getNodeValue( child ) ) );
                 }
                 else if( child.getTagName().equals( "field" ) )
                 {
@@ -120,23 +113,23 @@ public class FDFField implements COSObje
      */
     public void writeXML( Writer output ) throws IOException
     {
-        output.write( "<field name=\"" + getPartialFieldName() + "\">\n");
+        output.write("<field name=\"" + getPartialFieldName() + "\">\n");
         Object value = getValue();
         if( value != null)
         {
-            if (value instanceof String)
+            if (value instanceof COSString)
             {
-                output.write( "<value>" + escapeXML((String)value) + "</value>\n"
);
+                output.write( "<value>" + escapeXML(((COSString)value).getString())
+ "</value>\n" );
             }
-            else if (value instanceof PDTextStream)
+            else if (value instanceof COSStream)
             {
-                output.write( "<value>" + escapeXML(((PDTextStream)value).getAsString())
+ "</value>\n" );
+                output.write( "<value>" + escapeXML(((COSStream)value).getString())
+ "</value>\n" );
             }
         }
-        PDTextStream rt = getRichText();
+        String rt = getRichText();
         if( rt != null )
         {
-            output.write( "<value-richtext>" + escapeXML(rt.getAsString()) + "</value-richtext>\n"
);
+            output.write( "<value-richtext>" + escapeXML(rt) + "</value-richtext>\n"
);
         }
         List<FDFField> kids = getKids();
         if( kids != null )
@@ -227,7 +220,7 @@ public class FDFField implements COSObje
     }
 
     /**
-     * This will set the value for the field.  This will return type will either be <br
/>
+     * This will get the value for the field.  This will return type will either be <br
/>
      * String : Checkboxes, Radio Button <br />
      * java.util.List of strings: Choice Field
      * PDTextStream: Textfields
@@ -238,25 +231,27 @@ public class FDFField implements COSObje
      */
     public Object getValue() throws IOException
     {
-        Object retval = null;
         COSBase value = field.getDictionaryObject( COSName.V );
         if( value instanceof COSName )
         {
-            retval = ((COSName)value).getName();
+            return ((COSName)value).getName();
         }
         else if( value instanceof COSArray )
         {
-            retval = COSArrayList.convertCOSStringCOSArrayToList( (COSArray)value );
+            return COSArrayList.convertCOSStringCOSArrayToList((COSArray) value);
         }
         else if( value instanceof COSString || value instanceof COSStream )
         {
-            retval = PDTextStream.createTextStream( value );
+            return value;
         }
         else if( value != null )
         {
             throw new IOException( "Error:Unknown type for field import" + value );
         }
-        return retval;
+        else
+        {
+            return null;
+        }
     }
 
     /**
@@ -272,11 +267,11 @@ public class FDFField implements COSObje
         COSBase cos = null;
         if( value instanceof List )
         {
-            cos = COSArrayList.convertStringListToCOSStringCOSArray( (List)value );
+            cos = COSArrayList.convertStringListToCOSStringCOSArray((List) value);
         }
         else if( value instanceof String )
         {
-            cos = COSName.getPDFName( (String)value );
+            cos = COSName.getPDFName((String) value);
         }
         else if( value instanceof COSObjectable )
         {
@@ -317,9 +312,9 @@ public class FDFField implements COSObje
         COSInteger value = null;
         if( ff != null )
         {
-            value = COSInteger.get( ff );
+            value = COSInteger.get(ff);
         }
-        field.setItem( COSName.FF, value );
+        field.setItem(COSName.FF, value);
     }
 
     /**
@@ -330,7 +325,7 @@ public class FDFField implements COSObje
      */
     public void setFieldFlags( int ff )
     {
-        field.setInt( COSName.FF, ff );
+        field.setInt(COSName.FF, ff);
     }
 
     /**
@@ -361,9 +356,9 @@ public class FDFField implements COSObje
         COSInteger value = null;
         if( ff != null )
         {
-            value = COSInteger.get( ff );
+            value = COSInteger.get(ff);
         }
-        field.setItem( COSName.SET_FF, value );
+        field.setItem(COSName.SET_FF, value);
     }
 
     /**
@@ -374,7 +369,7 @@ public class FDFField implements COSObje
      */
     public void setSetFieldFlags( int ff )
     {
-        field.setInt( COSName.SET_FF, ff );
+        field.setInt(COSName.SET_FF, ff);
     }
 
     /**
@@ -405,9 +400,9 @@ public class FDFField implements COSObje
         COSInteger value = null;
         if( ff != null )
         {
-            value = COSInteger.get( ff );
+            value = COSInteger.get(ff);
         }
-        field.setItem( COSName.CLR_FF, value );
+        field.setItem(COSName.CLR_FF, value);
     }
 
     /**
@@ -418,7 +413,7 @@ public class FDFField implements COSObje
      */
     public void setClearFieldFlags( int ff )
     {
-        field.setInt( COSName.CLR_FF, ff );
+        field.setInt(COSName.CLR_FF, ff);
     }
 
     /**
@@ -449,9 +444,9 @@ public class FDFField implements COSObje
         COSInteger value = null;
         if( f != null )
         {
-            value = COSInteger.get( f );
+            value = COSInteger.get(f);
         }
-        field.setItem( COSName.F, value );
+        field.setItem(COSName.F, value);
     }
 
     /**
@@ -462,7 +457,7 @@ public class FDFField implements COSObje
      */
     public void setWidgetFieldFlags( int f )
     {
-        field.setInt( COSName.F, f );
+        field.setInt(COSName.F, f);
     }
 
     /**
@@ -493,9 +488,9 @@ public class FDFField implements COSObje
         COSInteger value = null;
         if( ff != null )
         {
-            value = COSInteger.get( ff );
+            value = COSInteger.get(ff);
         }
-        field.setItem( COSName.SET_F, value );
+        field.setItem(COSName.SET_F, value);
     }
 
     /**
@@ -506,7 +501,7 @@ public class FDFField implements COSObje
      */
     public void setSetWidgetFieldFlags( int ff )
     {
-        field.setInt( COSName.SET_F, ff );
+        field.setInt(COSName.SET_F, ff);
     }
 
     /**
@@ -537,9 +532,9 @@ public class FDFField implements COSObje
         COSInteger value = null;
         if( ff != null )
         {
-            value = COSInteger.get( ff );
+            value = COSInteger.get(ff);
         }
-        field.setItem( COSName.CLR_F, value );
+        field.setItem(COSName.CLR_F, value);
     }
 
     /**
@@ -550,7 +545,7 @@ public class FDFField implements COSObje
      */
     public void setClearWidgetFieldFlags( int ff )
     {
-        field.setInt( COSName.CLR_F, ff );
+        field.setInt(COSName.CLR_F, ff);
     }
 
     /**
@@ -728,10 +723,31 @@ public class FDFField implements COSObje
      *
      * @return The rich text XHTML stream.
      */
-    public PDTextStream getRichText()
+    public String getRichText()
     {
         COSBase rv = field.getDictionaryObject( COSName.RV );
-        return PDTextStream.createTextStream( rv );
+        if (rv == null)
+        {
+            return null;
+        }
+        else if (rv instanceof COSString)
+        {
+            return ((COSString)rv).getString();
+        }
+        else
+        {
+            return ((COSStream)rv).getString();
+        }
+    }
+
+    /**
+     * This will set the rich text value.
+     *
+     * @param rv The rich text value for the stream.
+     */
+    public void setRichText( COSString rv )
+    {
+        field.setItem( COSName.RV, rv );
     }
 
     /**
@@ -739,7 +755,7 @@ public class FDFField implements COSObje
      *
      * @param rv The rich text value for the stream.
      */
-    public void setRichText( PDTextStream rv )
+    public void setRichText( COSStream rv )
     {
         field.setItem( COSName.RV, rv );
     }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFJavaScript.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFJavaScript.java?rev=1679299&r1=1679298&r2=1679299&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFJavaScript.java (original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/fdf/FDFJavaScript.java Wed
May 13 23:54:59 2015
@@ -16,18 +16,17 @@
  */
 package org.apache.pdfbox.pdmodel.fdf;
 
-import java.util.ArrayList;
-import java.util.List;
-
+import java.util.LinkedHashMap;
+import java.util.Map;
 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;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
-import org.apache.pdfbox.pdmodel.common.COSArrayList;
-import org.apache.pdfbox.pdmodel.common.PDTextStream;
-import org.apache.pdfbox.pdmodel.common.PDNamedTextStream;
+import org.apache.pdfbox.pdmodel.interactive.action.PDActionFactory;
+import org.apache.pdfbox.pdmodel.interactive.action.PDActionJavaScript;
 
 /**
  * This represents an FDF JavaScript dictionary that is part of the FDF document.
@@ -36,14 +35,14 @@ import org.apache.pdfbox.pdmodel.common.
  */
 public class FDFJavaScript implements COSObjectable
 {
-    private COSDictionary js;
+    private final COSDictionary dictionary;
 
     /**
      * Default constructor.
      */
     public FDFJavaScript()
     {
-        js = new COSDictionary();
+        dictionary = new COSDictionary();
     }
 
     /**
@@ -53,7 +52,7 @@ public class FDFJavaScript implements CO
      */
     public FDFJavaScript( COSDictionary javaScript )
     {
-        js = javaScript;
+        dictionary = javaScript;
     }
 
     /**
@@ -63,7 +62,7 @@ public class FDFJavaScript implements CO
      */
     public COSBase getCOSObject()
     {
-        return js;
+        return dictionary;
     }
 
     /**
@@ -73,7 +72,7 @@ public class FDFJavaScript implements CO
      */
     public COSDictionary getCOSDictionary()
     {
-        return js;
+        return dictionary;
     }
 
     /**
@@ -81,9 +80,21 @@ public class FDFJavaScript implements CO
      *
      * @return Some javascript code.
      */
-    public PDTextStream getBefore()
+    public String getBefore()
     {
-        return PDTextStream.createTextStream( js.getDictionaryObject( COSName.BEFORE ) );
+        COSBase base = dictionary.getDictionaryObject( COSName.BEFORE );
+        if (base instanceof COSString)
+        {
+            return ((COSString)base).getString();
+        }
+        else if (base instanceof COSStream)
+        {
+            return ((COSStream)base).getString();
+        }
+        else
+        {
+            return null;
+        }
     }
 
     /**
@@ -91,9 +102,9 @@ public class FDFJavaScript implements CO
      *
      * @param before A reference to some javascript code.
      */
-    public void setBefore( PDTextStream before )
+    public void setBefore( String before )
     {
-        js.setItem( COSName.BEFORE , before );
+        dictionary.setItem(COSName.BEFORE, new COSString(before));
     }
 
     /**
@@ -101,9 +112,21 @@ public class FDFJavaScript implements CO
      *
      * @return Some javascript code.
      */
-    public PDTextStream getAfter()
+    public String getAfter()
     {
-        return PDTextStream.createTextStream( js.getDictionaryObject( COSName.AFTER ) );
+        COSBase base = dictionary.getDictionaryObject( COSName.AFTER );
+        if (base instanceof COSString)
+        {
+            return ((COSString)base).getString();
+        }
+        else if (base instanceof COSStream)
+        {
+            return ((COSStream)base).getString();
+        }
+        else
+        {
+            return null;
+        }
     }
 
     /**
@@ -111,46 +134,45 @@ public class FDFJavaScript implements CO
      *
      * @param after A reference to some javascript code.
      */
-    public void setAfter( PDTextStream after )
+    public void setAfter( String after )
     {
-        js.setItem( COSName.AFTER, after );
+        dictionary.setItem(COSName.AFTER, new COSString(after));
     }
 
     /**
-     * This will return a list of PDNamedTextStream objects.  This is the "Doc"
-     * entry of the pdf document.  These will be added to the PDF documents
-     * javascript name tree.  This will not return null.
-     *
-     * @return A list of all named javascript entries.
+     * Returns the dictionary's "Doc" entry, that is, a map of key value pairs to be added
to
+     * the document's JavaScript name tree.
+     * 
+     * @return Map of named "JavaScript" dictionaries.
      */
-    public List<PDNamedTextStream> getNamedJavaScripts()
+    public Map<String, PDActionJavaScript> getDoc()
     {
-        COSArray array = (COSArray)js.getDictionaryObject( COSName.DOC );
-        List<PDNamedTextStream> namedStreams = new ArrayList<PDNamedTextStream>();
-        if( array == null )
+        Map<String, PDActionJavaScript> map = new LinkedHashMap<String, PDActionJavaScript>();
+        COSArray array = (COSArray) dictionary.getDictionaryObject(COSName.DOC);
+        if (array == null)
         {
-            array = new COSArray();
-            js.setItem( COSName.DOC, array );
+            return null;
         }
-        for( int i=0; i<array.size(); i++ )
+        for (int i = 0; i < array.size(); i++)
         {
-            COSName name = (COSName)array.get( i );
-            i++;
-            COSBase stream = array.get( i );
-            PDNamedTextStream namedStream = new PDNamedTextStream( name, stream );
-            namedStreams.add( namedStream );
+            PDActionFactory.createAction((COSDictionary)array.getObject(i));
         }
-        return new COSArrayList<PDNamedTextStream>( namedStreams, array );
+        return map;
     }
 
     /**
-     * This should be a list of PDNamedTextStream objects.
-     *
-     * @param namedStreams The named streams.
+     * Sets the dictionary's "Doc" entry.
+     * 
+     * @param map Map of named "JavaScript" dictionaries.
      */
-    public void setNamedJavaScripts( List<PDNamedTextStream> namedStreams )
+    public void setDoc(Map<String, PDActionJavaScript> map)
     {
-        COSArray array = COSArrayList.converterToCOSArray( namedStreams );
-        js.setItem( COSName.DOC, array );
+        COSArray array = new COSArray();
+        for (Map.Entry<String, PDActionJavaScript> entry : map.entrySet())
+        {
+            array.add(new COSString(entry.getKey()));
+            array.add(entry.getValue());
+        }
+        dictionary.setItem(COSName.DOC, array);
     }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionJavaScript.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionJavaScript.java?rev=1679299&r1=1679298&r2=1679299&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionJavaScript.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/action/PDActionJavaScript.java
Wed May 13 23:54:59 2015
@@ -16,8 +16,11 @@
  */
 package org.apache.pdfbox.pdmodel.interactive.action;
 
+import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
-import org.apache.pdfbox.pdmodel.common.PDTextStream;
+import org.apache.pdfbox.cos.COSName;
+import org.apache.pdfbox.cos.COSStream;
+import org.apache.pdfbox.cos.COSString;
 
 /**
  * This represents a JavaScript action.
@@ -48,7 +51,7 @@ public class PDActionJavaScript extends
     public PDActionJavaScript( String js )
     {
         this();
-        setAction( js );
+        setAction(js);
     }
 
     /**
@@ -60,15 +63,7 @@ public class PDActionJavaScript extends
     {
         super(a);
     }
-
-    /**
-     * @param sAction The JavaScript.
-     */
-    public void setAction(PDTextStream sAction)
-    {
-        action.setItem("JS", sAction);
-    }
-
+    
     /**
      * @param sAction The JavaScript.
      */
@@ -80,8 +75,20 @@ public class PDActionJavaScript extends
     /**
      * @return The Javascript Code.
      */
-    public PDTextStream getAction()
+    public String getAction()
     {
-        return PDTextStream.createTextStream( action.getDictionaryObject("JS") );
+        COSBase base = action.getDictionaryObject( COSName.JS );
+        if (base instanceof COSString)
+        {
+            return ((COSString)base).getString();
+        }
+        else if (base instanceof COSStream)
+        {
+            return ((COSStream)base).getString();
+        }
+        else
+        {
+            return null;
+        }
     }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationMarkup.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationMarkup.java?rev=1679299&r1=1679298&r2=1679299&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationMarkup.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/annotation/PDAnnotationMarkup.java
Wed May 13 23:54:59 2015
@@ -16,14 +16,13 @@
  */
 package org.apache.pdfbox.pdmodel.interactive.annotation;
 
-import org.apache.pdfbox.cos.COSDictionary;
-
-import org.apache.pdfbox.pdmodel.common.PDTextStream;
-import org.apache.pdfbox.cos.COSBase;
-
 import java.io.IOException;
-
 import java.util.Calendar;
+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;
 
 /**
  * This class represents the additonal fields of a Markup type Annotation.  See
@@ -176,12 +175,16 @@ public class PDAnnotationMarkup extends
      *
      * @return the rich text stream.
      */
-    public PDTextStream getRichContents()
+    public String getRichContents()
     {
-        COSBase rc = getCOSObject().getDictionaryObject( "RC" );
-        if (rc != null)
+        COSBase base = getCOSObject().getDictionaryObject(COSName.RC);
+        if (base instanceof COSString)
+        {
+            return ((COSString)base).getString();
+        }
+        else if (base instanceof COSStream)
         {
-            return PDTextStream.createTextStream( rc );
+            return ((COSStream)base).getString();
         }
         else
         {
@@ -195,9 +198,9 @@ public class PDAnnotationMarkup extends
      * @param rc
      *            the rich text stream.
      */
-    public void setRichContents( PDTextStream rc )
+    public void setRichContents( String rc )
     {
-        getCOSObject().setItem( "RC", rc);
+        getCOSObject().setItem( "RC", new COSString(rc));
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGenerator.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGenerator.java?rev=1679299&r1=1679298&r2=1679299&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGenerator.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/AppearanceGenerator.java
Wed May 13 23:54:59 2015
@@ -17,10 +17,8 @@
 package org.apache.pdfbox.pdmodel.interactive.form;
 
 import java.io.IOException;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.pdfbox.pdmodel.common.PDTextStream;
 
 /**
  * (Re-) Generate the appearance for a field.
@@ -53,16 +51,11 @@ public final class AppearanceGenerator
     
                 
             fieldValue = field.getValue();
-
             
             // TODO: implement the handling for additional values.
             if (fieldValue instanceof String)
             {
                 apHelper.setAppearanceValue((String) fieldValue);
-            } 
-            else if (fieldValue instanceof PDTextStream)
-            {
-                apHelper.setAppearanceValue(((PDTextStream) fieldValue).getAsString());
             }
             else if (fieldValue != null)
             {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java?rev=1679299&r1=1679298&r2=1679299&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java
Wed May 13 23:54:59 2015
@@ -19,14 +19,14 @@ package org.apache.pdfbox.pdmodel.intera
 import java.io.IOException;
 import java.util.ArrayList;
 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;
 import org.apache.pdfbox.pdmodel.common.COSArrayList;
 import org.apache.pdfbox.pdmodel.common.COSObjectable;
-import org.apache.pdfbox.pdmodel.common.PDTextStream;
 import org.apache.pdfbox.pdmodel.fdf.FDFField;
 import org.apache.pdfbox.pdmodel.interactive.action.PDFormFieldAdditionalActions;
 import org.apache.pdfbox.pdmodel.interactive.annotation.PDAnnotationWidget;
@@ -179,32 +179,30 @@ public abstract class PDFieldTreeNode im
      * 
      * Some dictionary entries allow either a text or a text stream.
      * 
-     * @param cosBaseEntry the potential text or text stream
+     * @param base the potential text or text stream
      * @return the text stream
      * @throws IOException if the field dictionary entry is not a text type
      */
-    protected PDTextStream getAsTextStream(COSBase cosBaseEntry) throws IOException
+    protected String valueToString(COSBase base) throws IOException
     {
-        if (cosBaseEntry == null)
+        if (base == null)
         {
             return null;
         }
+        else if (base instanceof COSString)
+        {
+            return ((COSString)base).getString();
+        }
+        else if (base instanceof COSStream)
+        {
+            return ((COSStream)base).getString();
+        }
         else
         {
-            PDTextStream textStream = PDTextStream.createTextStream(cosBaseEntry);
-            // This will happen if the entry was not a COSString or COSStream
-            if (textStream == null)
-            {
-                throw new IOException("Invalid field value. Unexpected type " + cosBaseEntry.getClass().getName());
-            }
-            else
-            {
-                return textStream;
-            }
+            throw new IOException("Unexpected field value of type: " + base.getClass().getName());
         }
     }
     
-    
     /**
      * Get the FT entry of the field. This is a read only field and is set depending on the
actual type. The field type
      * is an inheritable attribute.
@@ -400,13 +398,13 @@ public abstract class PDFieldTreeNode im
 
         if (fieldValue != null)
         {
-            if (fieldValue instanceof String)
+            if (fieldValue instanceof COSString)
             {
-                setValue((String) fieldValue);
+                setValue(((COSString) fieldValue).getString());
             }
-            else if (fieldValue instanceof PDTextStream)
+            else if (fieldValue instanceof COSStream)
             {
-                setValue(((PDTextStream) fieldValue).getAsString());
+                setValue(((COSStream) fieldValue).getString());
             }
             else
             {

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java?rev=1679299&r1=1679298&r2=1679299&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDTextField.java
Wed May 13 23:54:59 2015
@@ -17,12 +17,10 @@
 package org.apache.pdfbox.pdmodel.interactive.form;
 
 import java.io.IOException;
-
 import org.apache.pdfbox.cos.COSBase;
 import org.apache.pdfbox.cos.COSDictionary;
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSString;
-import org.apache.pdfbox.pdmodel.common.PDTextStream;
 
 /**
  * A text field is a box or space for text fill-in data typically entered from a keyboard.
@@ -256,16 +254,11 @@ public final class PDTextField extends P
         return "";
     }    
     
-    
-    
     /**
-     * Set the fields value.
+     * Set the field's value.
      * 
      * The value is stored in the field dictionaries "V" entry.
-     * <p>
-     * For long text it's more efficient to provide the text content as a
-     * text stream {@link #setValue(PDTextStream)}
-     * </p>
+     * 
      * @param value the value
      * @throws IOException if there is an error setting the field value
      */
@@ -287,32 +280,7 @@ public final class PDTextField extends P
     }
     
     /**
-     * Set the fields value.
-     * 
-     * The value is stored in the field dictionaries "V" entry.
-     * 
-     * @param textStream the value
-     * @throws IOException if there is an error setting the field value
-     */
-    public void setValue(PDTextStream textStream) throws IOException
-    {
-        if (textStream != null)
-        {
-            setInheritableAttribute(COSName.V, textStream.getCOSObject());
-        }  
-        else
-        {
-            removeInheritableAttribute(COSName.V);
-        }
-        
-        // TODO move appearance generation out of fields PD model
-        updateFieldAppearances();
-    }
-    
-    
-
-    /**
-     * Get the fields value.
+     * Get the field's value.
      * 
      * The value is stored in the field dictionaries "V" entry.
      * 
@@ -322,25 +290,11 @@ public final class PDTextField extends P
     @Override
     public String getValue() throws IOException
     {
-        PDTextStream textStream = getAsTextStream(getInheritableAttribute(COSName.V));
-
-        if (textStream != null) 
+        String string = valueToString(getInheritableAttribute(COSName.V));
+        if (string != null) 
         {
-            return textStream.getAsString();
+            return string;
         }
         return "";
     }
-    
-    /**
-     * Get the fields value.
-     * 
-     * The value is stored in the field dictionaries "V" entry.
-     * 
-     * @return The value of this entry.
-     * @throws IOException if the field dictionary entry is not a text type
-     */
-    public PDTextStream getValueAsStream() throws IOException
-    {
-        return getAsTextStream(getInheritableAttribute(COSName.V));
-    }
 }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDVariableText.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDVariableText.java?rev=1679299&r1=1679298&r2=1679299&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDVariableText.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDVariableText.java
Wed May 13 23:54:59 2015
@@ -22,7 +22,6 @@ import org.apache.pdfbox.cos.COSDictiona
 import org.apache.pdfbox.cos.COSName;
 import org.apache.pdfbox.cos.COSNumber;
 import org.apache.pdfbox.cos.COSString;
-import org.apache.pdfbox.pdmodel.common.PDTextStream;
 
 /**
  * Base class for fields which use "Variable Text".
@@ -49,7 +48,7 @@ public abstract class PDVariableText ext
     public static final int QUADDING_RIGHT = 2;
 
     /**
-     * @see PDField#PDField(PDAcroForm,COSDictionary)
+     * @see PDField#PDField(PDAcroForm)
      *
      * @param theAcroForm The acroform.
      */
@@ -184,29 +183,15 @@ public abstract class PDVariableText ext
      */
     public String getRichTextValue() throws IOException
     {
-        PDTextStream textStream = getAsTextStream(getInheritableAttribute(COSName.RV));
-        
-        if (textStream != null)
+        String string = valueToString(getInheritableAttribute(COSName.RV));
+        if (string != null)
         {
-            return textStream.getAsString();
+            return string;
         }
         return "";
     }
     
     /**
-     * Get the fields rich text value.
-     * 
-     * The value is stored in the field dictionaries "V" entry.
-     * 
-     * @return The value of this entry.
-     * @throws IOException if the field dictionary entry is not a text type
-     */
-    public PDTextStream getRichTextValueAsStream() throws IOException
-    {
-        return getAsTextStream(getInheritableAttribute(COSName.RV));
-    }
-    
-    /**
      * Set the fields rich text value.
      * 
      * <p>
@@ -216,10 +201,6 @@ public abstract class PDVariableText ext
      * You can set {@link PDAcroForm#setNeedAppearances(Boolean)} to
      * signal a conforming reader to generate the appearance stream.
      * </p>
-     * <p>
-     * For long text it's more efficient to provide the text content as a
-     * text stream {@link #setRichTextValue(PDTextStream)}
-     * </p>
      * 
      * Providing null as the value will remove the default style string.
      * 
@@ -236,30 +217,4 @@ public abstract class PDVariableText ext
             getCOSObject().removeItem(COSName.RV);
         }        
     }
-    
-    
-    /**
-     * Set the fields rich text value.
-     * 
-     * Setting the rich text value will not generate the appearance
-     * for the field.
-     * 
-     * You can set {@link PDAcroForm#setNeedAppearances(Boolean)} to
-     * signal a conforming reader to generate the appearance stream.
-     * 
-     * Providing null as the value will remove the default style string.
-     * 
-     * @param richTextValue a rich text string
-     */
-    public void setRichTextValue(PDTextStream richTextValue)
-    {
-        if (richTextValue != null)
-        {
-            getCOSObject().setItem(COSName.RV, richTextValue.getCOSObject());
-        }
-        else
-        {
-            getCOSObject().removeItem(COSName.RV);
-        }        
-    } 
 }



Mime
View raw message