1 | /* | |
2 | * $Id: PdfAction.java 4065 2009-09-16 23:09:11Z psoares33 $ | |
3 | * | |
4 | * Copyright 2000 by Bruno Lowagie. | |
5 | * | |
6 | * The contents of this file are subject to the Mozilla Public License Version 1.1 | |
7 | * (the "License"); you may not use this file except in compliance with the License. | |
8 | * You may obtain a copy of the License at http://www.mozilla.org/MPL/ | |
9 | * | |
10 | * Software distributed under the License is distributed on an "AS IS" basis, | |
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
12 | * for the specific language governing rights and limitations under the License. | |
13 | * | |
14 | * The Original Code is 'iText, a free JAVA-PDF library'. | |
15 | * | |
16 | * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by | |
17 | * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. | |
18 | * All Rights Reserved. | |
19 | * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer | |
20 | * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. | |
21 | * | |
22 | * Contributor(s): all the names of the contributors are added in the source code | |
23 | * where applicable. | |
24 | * | |
25 | * Alternatively, the contents of this file may be used under the terms of the | |
26 | * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the | |
27 | * provisions of LGPL are applicable instead of those above. If you wish to | |
28 | * allow use of your version of this file only under the terms of the LGPL | |
29 | * License and not to allow others to use your version of this file under | |
30 | * the MPL, indicate your decision by deleting the provisions above and | |
31 | * replace them with the notice and other provisions required by the LGPL. | |
32 | * If you do not delete the provisions above, a recipient may use your version | |
33 | * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. | |
34 | * | |
35 | * This library is free software; you can redistribute it and/or modify it | |
36 | * under the terms of the MPL as stated above or under the terms of the GNU | |
37 | * Library General Public License as published by the Free Software Foundation; | |
38 | * either version 2 of the License, or any later version. | |
39 | * | |
40 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
41 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
42 | * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more | |
43 | * details. | |
44 | * | |
45 | * If you didn't download this code from the following link, you should check if | |
46 | * you aren't using an obsolete version: | |
47 | * http://www.lowagie.com/iText/ | |
48 | */ | |
49 | ||
50 | package com.lowagie.text.pdf; | |
51 | ||
52 | import java.io.IOException; | |
53 | import java.net.URL; | |
54 | import java.util.ArrayList; | |
55 | import com.lowagie.text.error_messages.MessageLocalization; | |
56 | ||
57 | import com.lowagie.text.pdf.collection.PdfTargetDictionary; | |
58 | ||
59 | /** | |
60 | * A <CODE>PdfAction</CODE> defines an action that can be triggered from a PDF file. | |
61 | * | |
62 | * @see PdfDictionary | |
63 | */ | |
64 | ||
65 | public class PdfAction extends PdfDictionary { | |
66 | | |
67 | /** A named action to go to the first page. | |
68 | */ | |
69 | public static final int FIRSTPAGE = 1; | |
70 | /** A named action to go to the previous page. | |
71 | */ | |
72 | public static final int PREVPAGE = 2; | |
73 | /** A named action to go to the next page. | |
74 | */ | |
75 | public static final int NEXTPAGE = 3; | |
76 | /** A named action to go to the last page. | |
77 | */ | |
78 | public static final int LASTPAGE = 4; | |
79 | ||
80 | /** A named action to open a print dialog. | |
81 | */ | |
82 | public static final int PRINTDIALOG = 5; | |
83 | ||
84 | /** a possible submitvalue */ | |
85 | public static final int SUBMIT_EXCLUDE = 1; | |
86 | /** a possible submitvalue */ | |
87 | public static final int SUBMIT_INCLUDE_NO_VALUE_FIELDS = 2; | |
88 | /** a possible submitvalue */ | |
89 | public static final int SUBMIT_HTML_FORMAT = 4; | |
90 | /** a possible submitvalue */ | |
91 | public static final int SUBMIT_HTML_GET = 8; | |
92 | /** a possible submitvalue */ | |
93 | public static final int SUBMIT_COORDINATES = 16; | |
94 | /** a possible submitvalue */ | |
95 | public static final int SUBMIT_XFDF = 32; | |
96 | /** a possible submitvalue */ | |
97 | public static final int SUBMIT_INCLUDE_APPEND_SAVES = 64; | |
98 | /** a possible submitvalue */ | |
99 | public static final int SUBMIT_INCLUDE_ANNOTATIONS = 128; | |
100 | /** a possible submitvalue */ | |
101 | public static final int SUBMIT_PDF = 256; | |
102 | /** a possible submitvalue */ | |
103 | public static final int SUBMIT_CANONICAL_FORMAT = 512; | |
104 | /** a possible submitvalue */ | |
105 | public static final int SUBMIT_EXCL_NON_USER_ANNOTS = 1024; | |
106 | /** a possible submitvalue */ | |
107 | public static final int SUBMIT_EXCL_F_KEY = 2048; | |
108 | /** a possible submitvalue */ | |
109 | public static final int SUBMIT_EMBED_FORM = 8196; | |
110 | /** a possible submitvalue */ | |
111 | public static final int RESET_EXCLUDE = 1; | |
112 | ||
113 | // constructors | |
114 | | |
115 | /** Create an empty action. | |
116 | */ | |
117 | public PdfAction() { | |
118 | } | |
119 | | |
120 | /** | |
121 | * Constructs a new <CODE>PdfAction</CODE> of Subtype URI. | |
122 | * | |
123 | * @param url the Url to go to | |
124 | */ | |
125 | | |
126 | public PdfAction(URL url) { | |
127 | this(url.toExternalForm()); | |
128 | } | |
129 | | |
130 | /** | |
131 | * Construct a new <CODE>PdfAction</CODE> of Subtype URI that accepts the x and y coordinate of the position that was clicked. | |
132 | * @param url | |
133 | * @param isMap | |
134 | */ | |
135 | public PdfAction(URL url, boolean isMap) { | |
136 | this(url.toExternalForm(), isMap); | |
137 | } | |
138 | | |
139 | /** | |
140 | * Constructs a new <CODE>PdfAction</CODE> of Subtype URI. | |
141 | * | |
142 | * @param url the url to go to | |
143 | */ | |
144 | | |
145 | public PdfAction(String url) { | |
146 | this(url, false); | |
147 | } | |
148 | | |
149 | /** | |
150 | * Construct a new <CODE>PdfAction</CODE> of Subtype URI that accepts the x and y coordinate of the position that was clicked. | |
151 | * @param url | |
152 | * @param isMap | |
153 | */ | |
154 | | |
155 | public PdfAction(String url, boolean isMap) { | |
156 |
1
1. |
put(PdfName.S, PdfName.URI); |
157 |
1
1. |
put(PdfName.URI, new PdfString(url)); |
158 |
1
1. |
if (isMap) |
159 |
1
1. |
put(PdfName.ISMAP, PdfBoolean.PDFTRUE); |
160 | } | |
161 | | |
162 | /** | |
163 | * Constructs a new <CODE>PdfAction</CODE> of Subtype GoTo. | |
164 | * @param destination the destination to go to | |
165 | */ | |
166 | | |
167 | PdfAction(PdfIndirectReference destination) { | |
168 |
1
1. |
put(PdfName.S, PdfName.GOTO); |
169 |
1
1. |
put(PdfName.D, destination); |
170 | } | |
171 | | |
172 | /** | |
173 | * Constructs a new <CODE>PdfAction</CODE> of Subtype GoToR. | |
174 | * @param filename the file name to go to | |
175 | * @param name the named destination to go to | |
176 | */ | |
177 | | |
178 | public PdfAction(String filename, String name) { | |
179 |
1
1. |
put(PdfName.S, PdfName.GOTOR); |
180 |
1
1. |
put(PdfName.F, new PdfString(filename)); |
181 |
1
1. |
put(PdfName.D, new PdfString(name)); |
182 | } | |
183 | | |
184 | /** | |
185 | * Constructs a new <CODE>PdfAction</CODE> of Subtype GoToR. | |
186 | * @param filename the file name to go to | |
187 | * @param page the page destination to go to | |
188 | */ | |
189 | | |
190 | public PdfAction(String filename, int page) { | |
191 |
1
1. |
put(PdfName.S, PdfName.GOTOR); |
192 |
1
1. |
put(PdfName.F, new PdfString(filename)); |
193 |
2
1. 2. |
put(PdfName.D, new PdfLiteral("[" + (page - 1) + " /FitH 10000]")); |
194 | } | |
195 | | |
196 | /** Implements name actions. The action can be FIRSTPAGE, LASTPAGE, | |
197 | * NEXTPAGE, PREVPAGE and PRINTDIALOG. | |
198 | * @param named the named action | |
199 | */ | |
200 | public PdfAction(int named) { | |
201 |
1
1. |
put(PdfName.S, PdfName.NAMED); |
202 | switch (named) { | |
203 | case FIRSTPAGE: | |
204 |
1
1. |
put(PdfName.N, PdfName.FIRSTPAGE); |
205 | break; | |
206 | case LASTPAGE: | |
207 |
1
1. |
put(PdfName.N, PdfName.LASTPAGE); |
208 | break; | |
209 | case NEXTPAGE: | |
210 |
1
1. |
put(PdfName.N, PdfName.NEXTPAGE); |
211 | break; | |
212 | case PREVPAGE: | |
213 |
1
1. |
put(PdfName.N, PdfName.PREVPAGE); |
214 | break; | |
215 | case PRINTDIALOG: | |
216 |
1
1. |
put(PdfName.S, PdfName.JAVASCRIPT); |
217 |
1
1. |
put(PdfName.JS, new PdfString("this.print(true);\r")); |
218 | break; | |
219 | default: | |
220 | throw new RuntimeException(MessageLocalization.getComposedMessage("invalid.named.action")); | |
221 | } | |
222 | } | |
223 | | |
224 | /** Launches an application or a document. | |
225 | * @param application the application to be launched or the document to be opened or printed. | |
226 | * @param parameters (Windows-specific) A parameter string to be passed to the application. | |
227 | * It can be <CODE>null</CODE>. | |
228 | * @param operation (Windows-specific) the operation to perform: "open" - Open a document, | |
229 | * "print" - Print a document. | |
230 | * It can be <CODE>null</CODE>. | |
231 | * @param defaultDir (Windows-specific) the default directory in standard DOS syntax. | |
232 | * It can be <CODE>null</CODE>. | |
233 | */ | |
234 | public PdfAction(String application, String parameters, String operation, String defaultDir) { | |
235 |
1
1. |
put(PdfName.S, PdfName.LAUNCH); |
236 |
3
1. 2. 3. |
if (parameters == null && operation == null && defaultDir == null) |
237 |
1
1. |
put(PdfName.F, new PdfString(application)); |
238 | else { | |
239 | PdfDictionary dic = new PdfDictionary(); | |
240 |
1
1. |
dic.put(PdfName.F, new PdfString(application)); |
241 |
1
1. |
if (parameters != null) |
242 |
1
1. |
dic.put(PdfName.P, new PdfString(parameters)); |
243 |
1
1. |
if (operation != null) |
244 |
1
1. |
dic.put(PdfName.O, new PdfString(operation)); |
245 |
1
1. |
if (defaultDir != null) |
246 |
1
1. |
dic.put(PdfName.D, new PdfString(defaultDir)); |
247 |
1
1. |
put(PdfName.WIN, dic); |
248 | } | |
249 | } | |
250 | | |
251 | /** Launches an application or a document. | |
252 | * @param application the application to be launched or the document to be opened or printed. | |
253 | * @param parameters (Windows-specific) A parameter string to be passed to the application. | |
254 | * It can be <CODE>null</CODE>. | |
255 | * @param operation (Windows-specific) the operation to perform: "open" - Open a document, | |
256 | * "print" - Print a document. | |
257 | * It can be <CODE>null</CODE>. | |
258 | * @param defaultDir (Windows-specific) the default directory in standard DOS syntax. | |
259 | * It can be <CODE>null</CODE>. | |
260 | * @return a Launch action | |
261 | */ | |
262 | public static PdfAction createLaunch(String application, String parameters, String operation, String defaultDir) { | |
263 |
1
1. createLaunch : mutated return of Object value for com/lowagie/text/pdf/PdfAction::createLaunch to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new PdfAction(application, parameters, operation, defaultDir); |
264 | } | |
265 | | |
266 | /**Creates a Rendition action | |
267 | * @param file | |
268 | * @param fs | |
269 | * @param mimeType | |
270 | * @param ref | |
271 | * @return a Media Clip action | |
272 | * @throws IOException | |
273 | */ | |
274 | public static PdfAction rendition(String file, PdfFileSpecification fs, String mimeType, PdfIndirectReference ref) throws IOException { | |
275 | PdfAction js = new PdfAction(); | |
276 |
1
1. rendition : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
js.put(PdfName.S, PdfName.RENDITION); |
277 |
1
1. rendition : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
js.put(PdfName.R, new PdfRendition(file, fs, mimeType)); |
278 |
1
1. rendition : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
js.put(new PdfName("OP"), new PdfNumber(0)); |
279 |
1
1. rendition : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
js.put(new PdfName("AN"), ref); |
280 |
1
1. rendition : mutated return of Object value for com/lowagie/text/pdf/PdfAction::rendition to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return js; |
281 | } | |
282 | | |
283 | /** Creates a JavaScript action. If the JavaScript is smaller than | |
284 | * 50 characters it will be placed as a string, otherwise it will | |
285 | * be placed as a compressed stream. | |
286 | * @param code the JavaScript code | |
287 | * @param writer the writer for this action | |
288 | * @param unicode select JavaScript unicode. Note that the internal | |
289 | * Acrobat JavaScript engine does not support unicode, | |
290 | * so this may or may not work for you | |
291 | * @return the JavaScript action | |
292 | */ | |
293 | public static PdfAction javaScript(String code, PdfWriter writer, boolean unicode) { | |
294 | PdfAction js = new PdfAction(); | |
295 |
1
1. javaScript : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
js.put(PdfName.S, PdfName.JAVASCRIPT); |
296 |
3
1. javaScript : changed conditional boundary → NO_COVERAGE 2. javaScript : negated conditional → NO_COVERAGE 3. javaScript : negated conditional → NO_COVERAGE |
if (unicode && code.length() < 50) { |
297 |
1
1. javaScript : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
js.put(PdfName.JS, new PdfString(code, PdfObject.TEXT_UNICODE)); |
298 | } | |
299 |
3
1. javaScript : changed conditional boundary → NO_COVERAGE 2. javaScript : negated conditional → NO_COVERAGE 3. javaScript : negated conditional → NO_COVERAGE |
else if (!unicode && code.length() < 100) { |
300 |
1
1. javaScript : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
js.put(PdfName.JS, new PdfString(code)); |
301 | } | |
302 | else { | |
303 | try { | |
304 |
1
1. javaScript : negated conditional → NO_COVERAGE |
byte[] b = PdfEncodings.convertToBytes(code, unicode ? PdfObject.TEXT_UNICODE : PdfObject.TEXT_PDFDOCENCODING); |
305 | PdfStream stream = new PdfStream(b); | |
306 |
1
1. javaScript : removed call to com/lowagie/text/pdf/PdfStream::flateCompress → NO_COVERAGE |
stream.flateCompress(writer.getCompressionLevel()); |
307 |
1
1. javaScript : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
js.put(PdfName.JS, writer.addToBody(stream).getIndirectReference()); |
308 | } | |
309 | catch (Exception e) { | |
310 |
1
1. javaScript : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
js.put(PdfName.JS, new PdfString(code)); |
311 | } | |
312 | } | |
313 |
1
1. javaScript : mutated return of Object value for com/lowagie/text/pdf/PdfAction::javaScript to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return js; |
314 | } | |
315 | ||
316 | /** Creates a JavaScript action. If the JavaScript is smaller than | |
317 | * 50 characters it will be place as a string, otherwise it will | |
318 | * be placed as a compressed stream. | |
319 | * @param code the JavaScript code | |
320 | * @param writer the writer for this action | |
321 | * @return the JavaScript action | |
322 | */ | |
323 | public static PdfAction javaScript(String code, PdfWriter writer) { | |
324 |
1
1. javaScript : mutated return of Object value for com/lowagie/text/pdf/PdfAction::javaScript to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return javaScript(code, writer, false); |
325 | } | |
326 | | |
327 | /** | |
328 | * A Hide action hides or shows an object. | |
329 | * @param obj object to hide or show | |
330 | * @param hide true is hide, false is show | |
331 | * @return a Hide Action | |
332 | */ | |
333 | static PdfAction createHide(PdfObject obj, boolean hide) { | |
334 | PdfAction action = new PdfAction(); | |
335 |
1
1. createHide : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.S, PdfName.HIDE); |
336 |
1
1. createHide : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.T, obj); |
337 |
1
1. createHide : negated conditional → NO_COVERAGE |
if (!hide) |
338 |
1
1. createHide : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.H, PdfBoolean.PDFFALSE); |
339 |
1
1. createHide : mutated return of Object value for com/lowagie/text/pdf/PdfAction::createHide to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return action; |
340 | } | |
341 | | |
342 | /** | |
343 | * A Hide action hides or shows an annotation. | |
344 | * @param annot | |
345 | * @param hide | |
346 | * @return A Hide Action | |
347 | */ | |
348 | public static PdfAction createHide(PdfAnnotation annot, boolean hide) { | |
349 |
1
1. createHide : mutated return of Object value for com/lowagie/text/pdf/PdfAction::createHide to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return createHide(annot.getIndirectReference(), hide); |
350 | } | |
351 | | |
352 | /** | |
353 | * A Hide action hides or shows an annotation. | |
354 | * @param name | |
355 | * @param hide | |
356 | * @return A Hide Action | |
357 | */ | |
358 | public static PdfAction createHide(String name, boolean hide) { | |
359 |
1
1. createHide : mutated return of Object value for com/lowagie/text/pdf/PdfAction::createHide to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return createHide(new PdfString(name), hide); |
360 | } | |
361 | | |
362 | static PdfArray buildArray(Object[] names) { | |
363 | PdfArray array = new PdfArray(); | |
364 | for (Object obj : names) { | |
365 |
1
1. buildArray : negated conditional → NO_COVERAGE |
if (obj instanceof String) |
366 | array.add(new PdfString((String) obj)); | |
367 |
1
1. buildArray : negated conditional → NO_COVERAGE |
else if (obj instanceof PdfAnnotation) |
368 | array.add(((PdfAnnotation) obj).getIndirectReference()); | |
369 | else | |
370 | throw new RuntimeException(MessageLocalization.getComposedMessage("the.array.must.contain.string.or.pdfannotation")); | |
371 | } | |
372 |
1
1. buildArray : mutated return of Object value for com/lowagie/text/pdf/PdfAction::buildArray to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return array; |
373 | } | |
374 | | |
375 | /** | |
376 | * A Hide action hides or shows objects. | |
377 | * @param names | |
378 | * @param hide | |
379 | * @return A Hide Action | |
380 | */ | |
381 | public static PdfAction createHide(Object[] names, boolean hide) { | |
382 |
1
1. createHide : mutated return of Object value for com/lowagie/text/pdf/PdfAction::createHide to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return createHide(buildArray(names), hide); |
383 | } | |
384 | | |
385 | /** | |
386 | * Creates a submit form. | |
387 | * @param file the URI to submit the form to | |
388 | * @param names the objects to submit | |
389 | * @param flags submit properties | |
390 | * @return A PdfAction | |
391 | */ | |
392 | public static PdfAction createSubmitForm(String file, Object[] names, int flags) { | |
393 | PdfAction action = new PdfAction(); | |
394 |
1
1. createSubmitForm : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.S, PdfName.SUBMITFORM); |
395 | PdfDictionary dic = new PdfDictionary(); | |
396 |
1
1. createSubmitForm : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.F, new PdfString(file)); |
397 |
1
1. createSubmitForm : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
dic.put(PdfName.FS, PdfName.URL); |
398 |
1
1. createSubmitForm : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.F, dic); |
399 |
1
1. createSubmitForm : negated conditional → NO_COVERAGE |
if (names != null) |
400 |
1
1. createSubmitForm : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.FIELDS, buildArray(names)); |
401 |
1
1. createSubmitForm : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.FLAGS, new PdfNumber(flags)); |
402 |
1
1. createSubmitForm : mutated return of Object value for com/lowagie/text/pdf/PdfAction::createSubmitForm to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return action; |
403 | } | |
404 | | |
405 | /** | |
406 | * Creates a resetform. | |
407 | * @param names the objects to reset | |
408 | * @param flags submit properties | |
409 | * @return A PdfAction | |
410 | */ | |
411 | public static PdfAction createResetForm(Object[] names, int flags) { | |
412 | PdfAction action = new PdfAction(); | |
413 |
1
1. createResetForm : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.S, PdfName.RESETFORM); |
414 |
1
1. createResetForm : negated conditional → NO_COVERAGE |
if (names != null) |
415 |
1
1. createResetForm : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.FIELDS, buildArray(names)); |
416 |
1
1. createResetForm : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.FLAGS, new PdfNumber(flags)); |
417 |
1
1. createResetForm : mutated return of Object value for com/lowagie/text/pdf/PdfAction::createResetForm to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return action; |
418 | } | |
419 | | |
420 | /** | |
421 | * Creates an Import field. | |
422 | * @param file | |
423 | * @return A PdfAction | |
424 | */ | |
425 | public static PdfAction createImportData(String file) { | |
426 | PdfAction action = new PdfAction(); | |
427 |
1
1. createImportData : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.S, PdfName.IMPORTDATA); |
428 |
1
1. createImportData : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.F, new PdfString(file)); |
429 |
1
1. createImportData : mutated return of Object value for com/lowagie/text/pdf/PdfAction::createImportData to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return action; |
430 | } | |
431 | | |
432 | /** Add a chained action. | |
433 | * @param na the next action | |
434 | */ | |
435 | public void next(PdfAction na) { | |
436 | PdfObject nextAction = get(PdfName.NEXT); | |
437 |
1
1. next : negated conditional → NO_COVERAGE |
if (nextAction == null) |
438 |
1
1. next : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
put(PdfName.NEXT, na); |
439 |
1
1. next : negated conditional → NO_COVERAGE |
else if (nextAction.isDictionary()) { |
440 | PdfArray array = new PdfArray(nextAction); | |
441 | array.add(na); | |
442 |
1
1. next : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
put(PdfName.NEXT, array); |
443 | } | |
444 | else { | |
445 | ((PdfArray)nextAction).add(na); | |
446 | } | |
447 | } | |
448 | | |
449 | /** Creates a GoTo action to an internal page. | |
450 | * @param page the page to go. First page is 1 | |
451 | * @param dest the destination for the page | |
452 | * @param writer the writer for this action | |
453 | * @return a GoTo action | |
454 | */ | |
455 | public static PdfAction gotoLocalPage(int page, PdfDestination dest, PdfWriter writer) { | |
456 | PdfIndirectReference ref = writer.getPageReference(page); | |
457 | dest.addPage(ref); | |
458 | PdfAction action = new PdfAction(); | |
459 |
1
1. gotoLocalPage : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.S, PdfName.GOTO); |
460 |
1
1. gotoLocalPage : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.D, dest); |
461 |
1
1. gotoLocalPage : mutated return of Object value for com/lowagie/text/pdf/PdfAction::gotoLocalPage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return action; |
462 | } | |
463 | ||
464 | /** | |
465 | * Creates a GoTo action to a named destination. | |
466 | * @param dest the named destination | |
467 | * @param isName if true sets the destination as a name, if false sets it as a String | |
468 | * @return a GoTo action | |
469 | */ | |
470 | public static PdfAction gotoLocalPage(String dest, boolean isName) { | |
471 | PdfAction action = new PdfAction(); | |
472 |
1
1. gotoLocalPage : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.S, PdfName.GOTO); |
473 |
1
1. gotoLocalPage : negated conditional → NO_COVERAGE |
if (isName) |
474 |
1
1. gotoLocalPage : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.D, new PdfName(dest)); |
475 | else | |
476 |
1
1. gotoLocalPage : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.D, new PdfString(dest, null)); |
477 |
1
1. gotoLocalPage : mutated return of Object value for com/lowagie/text/pdf/PdfAction::gotoLocalPage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return action; |
478 | } | |
479 | ||
480 | /** | |
481 | * Creates a GoToR action to a named destination. | |
482 | * @param filename the file name to go to | |
483 | * @param dest the destination name | |
484 | * @param isName if true sets the destination as a name, if false sets it as a String | |
485 | * @param newWindow open the document in a new window if <CODE>true</CODE>, if false the current document is replaced by the new document. | |
486 | * @return a GoToR action | |
487 | */ | |
488 | public static PdfAction gotoRemotePage(String filename, String dest, boolean isName, boolean newWindow) { | |
489 | PdfAction action = new PdfAction(); | |
490 |
1
1. gotoRemotePage : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.F, new PdfString(filename)); |
491 |
1
1. gotoRemotePage : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.S, PdfName.GOTOR); |
492 |
1
1. gotoRemotePage : negated conditional → NO_COVERAGE |
if (isName) |
493 |
1
1. gotoRemotePage : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.D, new PdfName(dest)); |
494 | else | |
495 |
1
1. gotoRemotePage : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.D, new PdfString(dest, null)); |
496 |
1
1. gotoRemotePage : negated conditional → NO_COVERAGE |
if (newWindow) |
497 |
1
1. gotoRemotePage : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.NEWWINDOW, PdfBoolean.PDFTRUE); |
498 |
1
1. gotoRemotePage : mutated return of Object value for com/lowagie/text/pdf/PdfAction::gotoRemotePage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return action; |
499 | } | |
500 | ||
501 | /** | |
502 | * Creates a GoToE action to an embedded file. | |
503 | * @param filename the root document of the target (null if the target is in the same document) | |
504 | * @param dest the named destination | |
505 | * @param isName if true sets the destination as a name, if false sets it as a String | |
506 | * @return a GoToE action | |
507 | */ | |
508 | public static PdfAction gotoEmbedded(String filename, PdfTargetDictionary target, String dest, boolean isName, boolean newWindow) { | |
509 |
1
1. gotoEmbedded : negated conditional → NO_COVERAGE |
if (isName) |
510 |
1
1. gotoEmbedded : mutated return of Object value for com/lowagie/text/pdf/PdfAction::gotoEmbedded to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return gotoEmbedded(filename, target, new PdfName(dest), newWindow); |
511 | else | |
512 |
1
1. gotoEmbedded : mutated return of Object value for com/lowagie/text/pdf/PdfAction::gotoEmbedded to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return gotoEmbedded(filename, target, new PdfString(dest, null), newWindow); |
513 | } | |
514 | ||
515 | /** | |
516 | * Creates a GoToE action to an embedded file. | |
517 | * @param filename the root document of the target (null if the target is in the same document) | |
518 | * @param target a path to the target document of this action | |
519 | * @param dest the destination inside the target document, can be of type PdfDestination, PdfName, or PdfString | |
520 | * @param newWindow if true, the destination document should be opened in a new window | |
521 | * @return a GoToE action | |
522 | */ | |
523 | public static PdfAction gotoEmbedded(String filename, PdfTargetDictionary target, PdfObject dest, boolean newWindow) { | |
524 | PdfAction action = new PdfAction(); | |
525 |
1
1. gotoEmbedded : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.S, PdfName.GOTOE); |
526 |
1
1. gotoEmbedded : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.T, target); |
527 |
1
1. gotoEmbedded : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.D, dest); |
528 |
1
1. gotoEmbedded : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.NEWWINDOW, new PdfBoolean(newWindow)); |
529 |
1
1. gotoEmbedded : negated conditional → NO_COVERAGE |
if (filename != null) { |
530 |
1
1. gotoEmbedded : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.F, new PdfString(filename)); |
531 | } | |
532 |
1
1. gotoEmbedded : mutated return of Object value for com/lowagie/text/pdf/PdfAction::gotoEmbedded to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return action; |
533 | } | |
534 | ||
535 | /** | |
536 | * A set-OCG-state action (PDF 1.5) sets the state of one or more optional content | |
537 | * groups. | |
538 | * @param state an array consisting of any number of sequences beginning with a <CODE>PdfName</CODE> | |
539 | * or <CODE>String</CODE> (ON, OFF, or Toggle) followed by one or more optional content group dictionaries | |
540 | * <CODE>PdfLayer</CODE> or a <CODE>PdfIndirectReference</CODE> to a <CODE>PdfLayer</CODE>.<br> | |
541 | * The array elements are processed from left to right; each name is applied | |
542 | * to the subsequent groups until the next name is encountered: | |
543 | * <ul> | |
544 | * <li>ON sets the state of subsequent groups to ON</li> | |
545 | * <li>OFF sets the state of subsequent groups to OFF</li> | |
546 | * <li>Toggle reverses the state of subsequent groups</li> | |
547 | * </ul> | |
548 | * @param preserveRB if <CODE>true</CODE>, indicates that radio-button state relationships between optional | |
549 | * content groups (as specified by the RBGroups entry in the current configuration | |
550 | * dictionary) should be preserved when the states in the | |
551 | * <CODE>state</CODE> array are applied. That is, if a group is set to ON (either by ON or Toggle) during | |
552 | * processing of the <CODE>state</CODE> array, any other groups belong to the same radio-button | |
553 | * group are turned OFF. If a group is set to OFF, there is no effect on other groups.<br> | |
554 | * If <CODE>false</CODE>, radio-button state relationships, if any, are ignored | |
555 | * @return the action | |
556 | */ | |
557 | public static PdfAction setOCGstate(ArrayList state, boolean preserveRB) { | |
558 | PdfAction action = new PdfAction(); | |
559 |
1
1. setOCGstate : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.S, PdfName.SETOCGSTATE); |
560 | PdfArray a = new PdfArray(); | |
561 | for (Object o : state) { | |
562 |
1
1. setOCGstate : negated conditional → NO_COVERAGE |
if (o == null) |
563 | continue; | |
564 |
1
1. setOCGstate : negated conditional → NO_COVERAGE |
if (o instanceof PdfIndirectReference) |
565 | a.add((PdfIndirectReference) o); | |
566 |
1
1. setOCGstate : negated conditional → NO_COVERAGE |
else if (o instanceof PdfLayer) |
567 | a.add(((PdfLayer) o).getRef()); | |
568 |
1
1. setOCGstate : negated conditional → NO_COVERAGE |
else if (o instanceof PdfName) |
569 | a.add((PdfName) o); | |
570 |
1
1. setOCGstate : negated conditional → NO_COVERAGE |
else if (o instanceof String) { |
571 | PdfName name = null; | |
572 | String s = (String) o; | |
573 |
1
1. setOCGstate : negated conditional → NO_COVERAGE |
if (s.equalsIgnoreCase("on")) |
574 | name = PdfName.ON; | |
575 |
1
1. setOCGstate : negated conditional → NO_COVERAGE |
else if (s.equalsIgnoreCase("off")) |
576 | name = PdfName.OFF; | |
577 |
1
1. setOCGstate : negated conditional → NO_COVERAGE |
else if (s.equalsIgnoreCase("toggle")) |
578 | name = PdfName.TOGGLE; | |
579 | else | |
580 | throw new IllegalArgumentException(MessageLocalization.getComposedMessage("a.string.1.was.passed.in.state.only.on.off.and.toggle.are.allowed", s)); | |
581 | a.add(name); | |
582 | } else | |
583 | throw new IllegalArgumentException(MessageLocalization.getComposedMessage("invalid.type.was.passed.in.state.1", o.getClass().getName())); | |
584 | } | |
585 |
1
1. setOCGstate : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.STATE, a); |
586 |
1
1. setOCGstate : negated conditional → NO_COVERAGE |
if (!preserveRB) |
587 |
1
1. setOCGstate : removed call to com/lowagie/text/pdf/PdfAction::put → NO_COVERAGE |
action.put(PdfName.PRESERVERB, PdfBoolean.PDFFALSE); |
588 |
1
1. setOCGstate : mutated return of Object value for com/lowagie/text/pdf/PdfAction::setOCGstate to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return action; |
589 | } | |
590 | } | |
Mutations | ||
156 |
1.1 |
|
157 |
1.1 |
|
158 |
1.1 |
|
159 |
1.1 |
|
168 |
1.1 |
|
169 |
1.1 |
|
179 |
1.1 |
|
180 |
1.1 |
|
181 |
1.1 |
|
191 |
1.1 |
|
192 |
1.1 |
|
193 |
1.1 2.2 |
|
201 |
1.1 |
|
204 |
1.1 |
|
207 |
1.1 |
|
210 |
1.1 |
|
213 |
1.1 |
|
216 |
1.1 |
|
217 |
1.1 |
|
235 |
1.1 |
|
236 |
1.1 2.2 3.3 |
|
237 |
1.1 |
|
240 |
1.1 |
|
241 |
1.1 |
|
242 |
1.1 |
|
243 |
1.1 |
|
244 |
1.1 |
|
245 |
1.1 |
|
246 |
1.1 |
|
247 |
1.1 |
|
263 |
1.1 |
|
276 |
1.1 |
|
277 |
1.1 |
|
278 |
1.1 |
|
279 |
1.1 |
|
280 |
1.1 |
|
295 |
1.1 |
|
296 |
1.1 2.2 3.3 |
|
297 |
1.1 |
|
299 |
1.1 2.2 3.3 |
|
300 |
1.1 |
|
304 |
1.1 |
|
306 |
1.1 |
|
307 |
1.1 |
|
310 |
1.1 |
|
313 |
1.1 |
|
324 |
1.1 |
|
335 |
1.1 |
|
336 |
1.1 |
|
337 |
1.1 |
|
338 |
1.1 |
|
339 |
1.1 |
|
349 |
1.1 |
|
359 |
1.1 |
|
365 |
1.1 |
|
367 |
1.1 |
|
372 |
1.1 |
|
382 |
1.1 |
|
394 |
1.1 |
|
396 |
1.1 |
|
397 |
1.1 |
|
398 |
1.1 |
|
399 |
1.1 |
|
400 |
1.1 |
|
401 |
1.1 |
|
402 |
1.1 |
|
413 |
1.1 |
|
414 |
1.1 |
|
415 |
1.1 |
|
416 |
1.1 |
|
417 |
1.1 |
|
427 |
1.1 |
|
428 |
1.1 |
|
429 |
1.1 |
|
437 |
1.1 |
|
438 |
1.1 |
|
439 |
1.1 |
|
442 |
1.1 |
|
459 |
1.1 |
|
460 |
1.1 |
|
461 |
1.1 |
|
472 |
1.1 |
|
473 |
1.1 |
|
474 |
1.1 |
|
476 |
1.1 |
|
477 |
1.1 |
|
490 |
1.1 |
|
491 |
1.1 |
|
492 |
1.1 |
|
493 |
1.1 |
|
495 |
1.1 |
|
496 |
1.1 |
|
497 |
1.1 |
|
498 |
1.1 |
|
509 |
1.1 |
|
510 |
1.1 |
|
512 |
1.1 |
|
525 |
1.1 |
|
526 |
1.1 |
|
527 |
1.1 |
|
528 |
1.1 |
|
529 |
1.1 |
|
530 |
1.1 |
|
532 |
1.1 |
|
559 |
1.1 |
|
562 |
1.1 |
|
564 |
1.1 |
|
566 |
1.1 |
|
568 |
1.1 |
|
570 |
1.1 |
|
573 |
1.1 |
|
575 |
1.1 |
|
577 |
1.1 |
|
585 |
1.1 |
|
586 |
1.1 |
|
587 |
1.1 |
|
588 |
1.1 |