1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 package org.apache.pdfbox.pdmodel.interactive.action.type; 18 19 import java.io.IOException; 20 21 import org.apache.pdfbox.cos.COSDictionary; 22 23 import org.apache.pdfbox.pdmodel.common.filespecification.PDFileSpecification; 24 25 /** 26 * This represents a launch action that can be executed in a PDF document. 27 * 28 * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a> 29 * @author Panagiotis Toumasis (ptoumasis@mail.gr) 30 * @version $Revision: 1.5 $ 31 */ 32 public class PDActionLaunch extends PDAction 33 { 34 35 /** 36 * This type of action this object represents. 37 */ 38 public static final String SUB_TYPE = "Launch"; 39 40 /** 41 * Default constructor. 42 */ 43 public PDActionLaunch() 44 { 45 super(); 46 setSubType( SUB_TYPE ); 47 } 48 49 /** 50 * Constructor. 51 * 52 * @param a The action dictionary. 53 */ 54 public PDActionLaunch( COSDictionary a ) 55 { 56 super( a ); 57 } 58 59 /** 60 * This will get the application to be launched or the document 61 * to be opened or printed. It is required if none of the entries 62 * Win, Mac or Unix is present. If this entry is absent and the 63 * viewer application does not understand any of the alternative 64 * entries it should do nothing. 65 * 66 * @return The F entry of the specific launch action dictionary. 67 * 68 * @throws IOException If there is an error creating the file spec. 69 */ 70 public PDFileSpecification getFile() throws IOException 71 { 72 return PDFileSpecification.createFS( getCOSDictionary().getDictionaryObject( "F" ) ); 73 } 74 75 /** 76 * This will set the application to be launched or the document 77 * to be opened or printed. It is required if none of the entries 78 * Win, Mac or Unix is present. If this entry is absent and the 79 * viewer application does not understand any of the alternative 80 * entries it should do nothing. 81 * 82 * @param fs The file specification. 83 */ 84 public void setFile( PDFileSpecification fs ) 85 { 86 getCOSDictionary().setItem( "F", fs ); 87 } 88 89 /** 90 * This will get a dictionary containing Windows-specific launch parameters. 91 * 92 * @return The Win entry of of the specific launch action dictionary. 93 */ 94 public PDWindowsLaunchParams getWinLaunchParams() 95 { 96 COSDictionary win = (COSDictionary)action.getDictionaryObject( "Win" ); 97 PDWindowsLaunchParams retval = null; 98 if( win != null ) 99 { 100 retval = new PDWindowsLaunchParams( win ); 101 } 102 return retval; 103 } 104 105 /** 106 * This will set a dictionary containing Windows-specific launch parameters. 107 * 108 * @param win The action to be performed. 109 */ 110 public void setWinLaunchParams( PDWindowsLaunchParams win ) 111 { 112 action.setItem( "Win", win ); 113 } 114 115 /** 116 * This will get the file name to be launched or the document to be opened 117 * or printed, in standard Windows pathname format. If the name string includes 118 * a backslash character (\), the backslash must itself be preceded by a backslash. 119 * This value must be a single string; it is not a file specification. 120 * 121 * @return The F entry of the specific Windows launch parameter dictionary. 122 */ 123 public String getF() 124 { 125 return action.getString( "F" ); 126 } 127 128 /** 129 * This will set the file name to be launched or the document to be opened 130 * or printed, in standard Windows pathname format. If the name string includes 131 * a backslash character (\), the backslash must itself be preceded by a backslash. 132 * This value must be a single string; it is not a file specification. 133 * 134 * @param f The file name to be launched. 135 */ 136 public void setF( String f ) 137 { 138 action.setString( "F", f ); 139 } 140 141 /** 142 * This will get the string specifying the default directory in standard DOS syntax. 143 * 144 * @return The D entry of the specific Windows launch parameter dictionary. 145 */ 146 public String getD() 147 { 148 return action.getString( "D" ); 149 } 150 151 /** 152 * This will set the string specifying the default directory in standard DOS syntax. 153 * 154 * @param d The default directory. 155 */ 156 public void setD( String d ) 157 { 158 action.setString( "D", d ); 159 } 160 161 /** 162 * This will get the string specifying the operation to perform: 163 * open to open a document 164 * print to print a document 165 * If the F entry designates an application instead of a document, this entry 166 * is ignored and the application is launched. Default value: open. 167 * 168 * @return The O entry of the specific Windows launch parameter dictionary. 169 */ 170 public String getO() 171 { 172 return action.getString( "O" ); 173 } 174 175 /** 176 * This will set the string specifying the operation to perform: 177 * open to open a document 178 * print to print a document 179 * If the F entry designates an application instead of a document, this entry 180 * is ignored and the application is launched. Default value: open. 181 * 182 * @param o The operation to perform. 183 */ 184 public void setO( String o ) 185 { 186 action.setString( "O", o ); 187 } 188 189 /** 190 * This will get a parameter string to be passed to the application designated by the F entry. 191 * This entry should be omitted if F designates a document. 192 * 193 * @return The P entry of the specific Windows launch parameter dictionary. 194 */ 195 public String getP() 196 { 197 return action.getString( "P" ); 198 } 199 200 /** 201 * This will set a parameter string to be passed to the application designated by the F entry. 202 * This entry should be omitted if F designates a document. 203 * 204 * @param p The parameter string. 205 */ 206 public void setP( String p ) 207 { 208 action.setString( "P", p ); 209 } 210 211 /** 212 * This will specify whether to open the destination document in a new window. 213 * If this flag is false, the destination document will replace the current 214 * document in the same window. If this entry is absent, the viewer application 215 * should behave in accordance with the current user preference. This entry is 216 * ignored if the file designated by the F entry is not a PDF document. 217 * 218 * @return A flag specifying whether to open the destination document in a new window. 219 */ 220 public boolean shouldOpenInNewWindow() 221 { 222 return action.getBoolean( "NewWindow", true ); 223 } 224 225 /** 226 * This will specify the destination document to open in a new window. 227 * 228 * @param value The flag value. 229 */ 230 public void setOpenInNewWindow( boolean value ) 231 { 232 action.setBoolean( "NewWindow", value ); 233 } 234 }