1 31 package org.pdfbox.pdmodel.fdf; 32 33 import java.util.ArrayList ; 34 import java.util.List ; 35 36 import org.pdfbox.cos.COSArray; 37 import org.pdfbox.cos.COSBase; 38 import org.pdfbox.cos.COSDictionary; 39 import org.pdfbox.cos.COSName; 40 41 import org.pdfbox.pdmodel.common.COSObjectable; 42 import org.pdfbox.pdmodel.common.COSArrayList; 43 import org.pdfbox.pdmodel.common.PDTextStream; 44 import org.pdfbox.pdmodel.common.PDNamedTextStream; 45 46 52 public class FDFJavaScript implements COSObjectable 53 { 54 private COSDictionary js; 55 56 59 public FDFJavaScript() 60 { 61 js = new COSDictionary(); 62 } 63 64 69 public FDFJavaScript( COSDictionary javaScript ) 70 { 71 js = javaScript; 72 } 73 74 79 public COSBase getCOSObject() 80 { 81 return js; 82 } 83 84 89 public COSDictionary getCOSDictionary() 90 { 91 return js; 92 } 93 94 99 public PDTextStream getBefore() 100 { 101 return PDTextStream.createTextStream( js.getDictionaryObject( "Before" ) ); 102 } 103 104 109 public void setBefore( PDTextStream before ) 110 { 111 js.setItem( "Before", before ); 112 } 113 114 119 public PDTextStream getAfter() 120 { 121 return PDTextStream.createTextStream( js.getDictionaryObject( "After" ) ); 122 } 123 124 129 public void setAfter( PDTextStream after ) 130 { 131 js.setItem( "After", after ); 132 } 133 134 141 public List getNamedJavaScripts() 142 { 143 COSArray array = (COSArray)js.getDictionaryObject( "Doc" ); 144 List namedStreams = new ArrayList (); 145 if( array == null ) 146 { 147 array = new COSArray(); 148 js.setItem( "Doc", array ); 149 } 150 for( int i=0; i<array.size(); i++ ) 151 { 152 COSName name = (COSName)array.get( i ); 153 i++; 154 COSBase stream = array.get( i ); 155 PDNamedTextStream namedStream = new PDNamedTextStream( name, stream ); 156 namedStreams.add( namedStream ); 157 } 158 return new COSArrayList( namedStreams, array ); 159 } 160 161 166 public void setNamedJavaScripts( List namedStreams ) 167 { 168 COSArray array = COSArrayList.converterToCOSArray( namedStreams ); 169 js.setItem( "Doc", array ); 170 } 171 } | Popular Tags |