1 31 package org.pdfbox.pdmodel.interactive.action.type; 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 40 import org.pdfbox.pdmodel.common.COSArrayList; 41 import org.pdfbox.pdmodel.common.PDDestinationOrAction; 42 import org.pdfbox.pdmodel.interactive.action.PDActionFactory; 43 44 51 public abstract class PDAction implements PDDestinationOrAction 52 { 53 56 public static final String TYPE = "Action"; 57 58 61 protected COSDictionary action; 62 63 66 public PDAction() 67 { 68 action = new COSDictionary(); 69 setType( TYPE ); 70 } 71 72 77 public PDAction( COSDictionary a ) 78 { 79 action = a; 80 } 81 82 87 public COSBase getCOSObject() 88 { 89 return action; 90 } 91 92 97 public COSDictionary getCOSDictionary() 98 { 99 return action; 100 } 101 102 108 public String getType() 109 { 110 return action.getNameAsString( "Type" ); 111 } 112 113 119 public void setType( String type ) 120 { 121 action.setName( "Type", type ); 122 } 123 124 130 public String getSubType() 131 { 132 return action.getNameAsString( "S" ); 133 } 134 135 141 public void setSubType( String s ) 142 { 143 action.setName( "S", s ); 144 } 145 146 153 public List getNext() 154 { 155 List retval = null; 156 COSBase next = action.getDictionaryObject( "Next" ); 157 if( next instanceof COSDictionary ) 158 { 159 PDAction pdAction = PDActionFactory.createAction( (COSDictionary) next ); 160 retval = new COSArrayList(pdAction, next, action, "Next" ); 161 } 162 else if( next instanceof COSArray ) 163 { 164 COSArray array = (COSArray)next; 165 List actions = new ArrayList (); 166 for( int i=0; i<array.size(); i++ ) 167 { 168 actions.add( PDActionFactory.createAction( (COSDictionary) array.getObject( i ))); 169 } 170 retval = new COSArrayList( actions, array ); 171 } 172 173 return retval; 174 } 175 176 183 public void setNext( List next ) 184 { 185 action.setItem( "Next", COSArrayList.converterToCOSArray( next ) ); 186 } 187 } | Popular Tags |