1 | /* | |
2 | * $Id: PdfSignatureAppearance.java 4065 2009-09-16 23:09:11Z psoares33 $ | |
3 | * | |
4 | * Copyright 2004-2006 by Paulo Soares. | |
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 | package com.lowagie.text.pdf; | |
50 | ||
51 | import java.io.EOFException; | |
52 | import java.io.File; | |
53 | import java.io.IOException; | |
54 | import java.io.InputStream; | |
55 | import java.io.OutputStream; | |
56 | import java.io.RandomAccessFile; | |
57 | import java.security.PrivateKey; | |
58 | import java.security.cert.CRL; | |
59 | import java.security.cert.Certificate; | |
60 | import java.security.cert.X509Certificate; | |
61 | import java.text.SimpleDateFormat; | |
62 | import java.util.Arrays; | |
63 | import java.util.Calendar; | |
64 | import java.util.GregorianCalendar; | |
65 | import java.util.HashMap; | |
66 | import java.util.Map; | |
67 | ||
68 | import com.lowagie.text.Chunk; | |
69 | import com.lowagie.text.DocumentException; | |
70 | import com.lowagie.text.Element; | |
71 | ||
72 | import com.lowagie.text.Font; | |
73 | import com.lowagie.text.Image; | |
74 | import com.lowagie.text.Paragraph; | |
75 | import com.lowagie.text.Phrase; | |
76 | import com.lowagie.text.Rectangle; | |
77 | import com.lowagie.text.error_messages.MessageLocalization; | |
78 | import com.lowagie.text.ExceptionConverter; | |
79 | ||
80 | /** | |
81 | * This class takes care of the cryptographic options and appearances that form | |
82 | * a signature. | |
83 | */ | |
84 | public class PdfSignatureAppearance { | |
85 | ||
86 | /** | |
87 | * The rendering mode is just the description | |
88 | */ | |
89 | public static final int SignatureRenderDescription = 0; | |
90 | /** | |
91 | * The rendering mode is the name of the signer and the description | |
92 | */ | |
93 | public static final int SignatureRenderNameAndDescription = 1; | |
94 | /** | |
95 | * The rendering mode is an image and the description | |
96 | */ | |
97 | public static final int SignatureRenderGraphicAndDescription = 2; | |
98 | ||
99 | /** | |
100 | * The self signed filter. | |
101 | */ | |
102 | public static final PdfName SELF_SIGNED = PdfName.ADOBE_PPKLITE; | |
103 | /** | |
104 | * The VeriSign filter. | |
105 | */ | |
106 | public static final PdfName VERISIGN_SIGNED = PdfName.VERISIGN_PPKVS; | |
107 | /** | |
108 | * The Windows Certificate Security. | |
109 | */ | |
110 | public static final PdfName WINCER_SIGNED = PdfName.ADOBE_PPKMS; | |
111 | ||
112 | public static final int NOT_CERTIFIED = 0; | |
113 | public static final int CERTIFIED_NO_CHANGES_ALLOWED = 1; | |
114 | public static final int CERTIFIED_FORM_FILLING = 2; | |
115 | public static final int CERTIFIED_FORM_FILLING_AND_ANNOTATIONS = 3; | |
116 | ||
117 | private static final float TOP_SECTION = 0.3f; | |
118 | private static final float MARGIN = 2; | |
119 | private Rectangle rect; | |
120 | private Rectangle pageRect; | |
121 | private final PdfTemplate[] app = new PdfTemplate[5]; | |
122 | private PdfTemplate frm; | |
123 | private final PdfStamperImp writer; | |
124 | private String layer2Text; | |
125 | private String reason; | |
126 | private String location; | |
127 | private Calendar signDate; | |
128 | private String provider; | |
129 | private int page = 1; | |
130 | private String fieldName; | |
131 | private PrivateKey privKey; | |
132 | private CRL[] crlList; | |
133 | private PdfName filter; | |
134 | private boolean newField; | |
135 | private ByteBuffer sigout; | |
136 | private OutputStream originalout; | |
137 | private File tempFile; | |
138 | private PdfDictionary cryptoDictionary; | |
139 | private PdfStamper stamper; | |
140 | private boolean preClosed = false; | |
141 | private PdfSigGenericPKCS sigStandard; | |
142 | private int[] range; | |
143 | private RandomAccessFile raf; | |
144 | private byte[] bout; | |
145 | private int boutLen; | |
146 | private byte[] externalDigest; | |
147 | private byte[] externalRSAdata; | |
148 | private String digestEncryptionAlgorithm; | |
149 | private HashMap exclusionLocations; | |
150 | ||
151 | private Certificate[] certChain; | |
152 | ||
153 | // ****************************************************************************** | |
154 | ||
155 | PdfSignatureAppearance(PdfStamperImp writer) { | |
156 | this.writer = writer; | |
157 | signDate = new GregorianCalendar(); | |
158 | fieldName = getNewSigName(); | |
159 | } | |
160 | ||
161 | private int render = SignatureRenderDescription; | |
162 | ||
163 | /** | |
164 | * Gets the rendering mode for this signature. | |
165 | * | |
166 | * @return the rendering mode for this signature | |
167 | */ | |
168 | public int getRender() { | |
169 | return render; | |
170 | } | |
171 | ||
172 | /** | |
173 | * Sets the rendering mode for this signature. The rendering modes can be the | |
174 | * constants <CODE>SignatureRenderDescription</CODE>, | |
175 | * <CODE>SignatureRenderNameAndDescription</CODE> or | |
176 | * <CODE>SignatureRenderGraphicAndDescription</CODE>. The two last modes | |
177 | * should be used with Acrobat 6 layer type. | |
178 | * | |
179 | * @param render | |
180 | * the render mode | |
181 | */ | |
182 | public void setRender(int render) { | |
183 | this.render = render; | |
184 | } | |
185 | ||
186 | private Image signatureGraphic = null; | |
187 | ||
188 | /** | |
189 | * Gets the Image object to render. | |
190 | * | |
191 | * @return the image | |
192 | */ | |
193 | public Image getSignatureGraphic() { | |
194 | return signatureGraphic; | |
195 | } | |
196 | ||
197 | /** | |
198 | * Sets the Image object to render when Render is set to | |
199 | * <CODE>SignatureRenderGraphicAndDescription</CODE> | |
200 | * | |
201 | * @param signatureGraphic | |
202 | * image rendered. If <CODE>null</CODE> the mode is defaulted to | |
203 | * <CODE>SignatureRenderDescription</CODE> | |
204 | */ | |
205 | public void setSignatureGraphic(Image signatureGraphic) { | |
206 | this.signatureGraphic = signatureGraphic; | |
207 | } | |
208 | ||
209 | /** | |
210 | * Sets the signature text identifying the signer. | |
211 | * | |
212 | * @param text | |
213 | * the signature text identifying the signer. If <CODE>null</CODE> or | |
214 | * not set a standard description will be used | |
215 | */ | |
216 | public void setLayer2Text(String text) { | |
217 | layer2Text = text; | |
218 | } | |
219 | ||
220 | /** | |
221 | * Gets the signature text identifying the signer if set by setLayer2Text(). | |
222 | * | |
223 | * @return the signature text identifying the signer | |
224 | */ | |
225 | public String getLayer2Text() { | |
226 | return layer2Text; | |
227 | } | |
228 | ||
229 | /** | |
230 | * Sets the text identifying the signature status. | |
231 | * | |
232 | * @param text | |
233 | * the text identifying the signature status. If <CODE>null</CODE> or | |
234 | * not set the description "Signature Not Verified" will be used | |
235 | */ | |
236 | public void setLayer4Text(String text) { | |
237 | layer4Text = text; | |
238 | } | |
239 | ||
240 | /** | |
241 | * Gets the text identifying the signature status if set by setLayer4Text(). | |
242 | * | |
243 | * @return the text identifying the signature status | |
244 | */ | |
245 | public String getLayer4Text() { | |
246 | return layer4Text; | |
247 | } | |
248 | ||
249 | /** | |
250 | * Gets the rectangle representing the signature dimensions. | |
251 | * | |
252 | * @return the rectangle representing the signature dimensions. It may be | |
253 | * <CODE>null</CODE> or have zero width or height for invisible | |
254 | * signatures | |
255 | */ | |
256 | public Rectangle getRect() { | |
257 | return rect; | |
258 | } | |
259 | ||
260 | /** | |
261 | * Gets the visibility status of the signature. | |
262 | * | |
263 | * @return the visibility status of the signature | |
264 | */ | |
265 | public boolean isInvisible() { | |
266 |
4
1. isInvisible : negated conditional → NO_COVERAGE 2. isInvisible : negated conditional → NO_COVERAGE 3. isInvisible : negated conditional → NO_COVERAGE 4. isInvisible : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (rect == null || rect.getWidth() == 0 || rect.getHeight() == 0); |
267 | } | |
268 | ||
269 | /** | |
270 | * Sets the cryptographic parameters. | |
271 | * | |
272 | * @param privKey | |
273 | * the private key | |
274 | * @param certificate | |
275 | * the certificate | |
276 | * @param crl | |
277 | * the certificate revocation list. It may be <CODE>null</CODE> | |
278 | * @param filter | |
279 | * the cryptographic filter type. It can be SELF_SIGNED, | |
280 | * VERISIGN_SIGNED or WINCER_SIGNED | |
281 | */ | |
282 | public void setCrypto(PrivateKey privKey, X509Certificate certificate, | |
283 | CRL crl, PdfName filter) { | |
284 | this.privKey = privKey; | |
285 |
1
1. setCrypto : negated conditional → NO_COVERAGE |
if (certificate == null) |
286 | throw new IllegalArgumentException("Null certificate not allowed"); | |
287 | this.certChain = new Certificate[1]; | |
288 | this.certChain[0] = certificate; | |
289 |
1
1. setCrypto : negated conditional → NO_COVERAGE |
if (crl != null) { |
290 | this.crlList = new CRL[1]; | |
291 | this.crlList[0] = crl; | |
292 | } | |
293 | this.filter = filter; | |
294 | } | |
295 | ||
296 | /** | |
297 | * Sets the cryptographic parameters. | |
298 | */ | |
299 | public void setCrypto(PrivateKey privKey, Certificate[] certChain, CRL[] crlList, PdfName filter) { | |
300 | this.privKey = privKey; | |
301 | this.certChain = certChain; | |
302 | this.crlList = crlList; | |
303 | this.filter = filter; | |
304 | } | |
305 | ||
306 | // OJO... Modificacion de | |
307 | // flopez------------------------------------------------- | |
308 | public void setVisibleSignature(Rectangle pageRect, int page) { | |
309 |
1
1. setVisibleSignature : removed call to com/lowagie/text/pdf/PdfSignatureAppearance::setVisibleSignature → NO_COVERAGE |
setVisibleSignature(pageRect, page, getNewSigName()); |
310 | } | |
311 | ||
312 | // ****************************************************************************** | |
313 | ||
314 | /** | |
315 | * Sets the signature to be visible. It creates a new visible signature field. | |
316 | * | |
317 | * @param pageRect | |
318 | * the position and dimension of the field in the page | |
319 | * @param page | |
320 | * the page to place the field. The fist page is 1 | |
321 | * @param fieldName | |
322 | * the field name or <CODE>null</CODE> to generate automatically a | |
323 | * new field name | |
324 | */ | |
325 | public void setVisibleSignature(Rectangle pageRect, int page, String fieldName) { | |
326 |
1
1. setVisibleSignature : negated conditional → NO_COVERAGE |
if (fieldName != null) { |
327 |
2
1. setVisibleSignature : changed conditional boundary → NO_COVERAGE 2. setVisibleSignature : negated conditional → NO_COVERAGE |
if (fieldName.indexOf('.') >= 0) |
328 | throw new IllegalArgumentException( | |
329 | MessageLocalization | |
330 | .getComposedMessage("field.names.cannot.contain.a.dot")); | |
331 | AcroFields af = writer.getAcroFields(); | |
332 | AcroFields.Item item = af.getFieldItem(fieldName); | |
333 |
1
1. setVisibleSignature : negated conditional → NO_COVERAGE |
if (item != null) |
334 | throw new IllegalArgumentException( | |
335 | MessageLocalization.getComposedMessage( | |
336 | "the.field.1.already.exists", fieldName)); | |
337 | this.fieldName = fieldName; | |
338 | } | |
339 | // OJO... Modificacion de | |
340 | // flopez-------------------------------------------------- | |
341 | // if (page < 1 || page > writer.reader.getNumberOfPages()) | |
342 |
4
1. setVisibleSignature : changed conditional boundary → NO_COVERAGE 2. setVisibleSignature : changed conditional boundary → NO_COVERAGE 3. setVisibleSignature : negated conditional → NO_COVERAGE 4. setVisibleSignature : negated conditional → NO_COVERAGE |
if (page < 0 || page > writer.reader.getNumberOfPages()) |
343 | throw new IllegalArgumentException( | |
344 | MessageLocalization.getComposedMessage("invalid.page.number.1", page)); | |
345 | // ****************************************************************************** | |
346 | this.pageRect = new Rectangle(pageRect); | |
347 |
1
1. setVisibleSignature : removed call to com/lowagie/text/Rectangle::normalize → NO_COVERAGE |
this.pageRect.normalize(); |
348 | rect = new Rectangle(this.pageRect.getWidth(), this.pageRect.getHeight()); | |
349 | this.page = page; | |
350 | newField = true; | |
351 | } | |
352 | ||
353 | /** | |
354 | * Sets the signature to be visible. An empty signature field with the same | |
355 | * name must already exist. | |
356 | * | |
357 | * @param fieldName | |
358 | * the existing empty signature field name | |
359 | */ | |
360 | public void setVisibleSignature(String fieldName) { | |
361 | AcroFields af = writer.getAcroFields(); | |
362 | AcroFields.Item item = af.getFieldItem(fieldName); | |
363 |
1
1. setVisibleSignature : negated conditional → NO_COVERAGE |
if (item == null) |
364 | throw new IllegalArgumentException( | |
365 | MessageLocalization.getComposedMessage("the.field.1.does.not.exist", | |
366 | fieldName)); | |
367 | PdfDictionary merged = item.getMerged(0); | |
368 |
1
1. setVisibleSignature : negated conditional → NO_COVERAGE |
if (!PdfName.SIG.equals(PdfReader.getPdfObject(merged.get(PdfName.FT)))) |
369 | throw new IllegalArgumentException( | |
370 | MessageLocalization.getComposedMessage( | |
371 | "the.field.1.is.not.a.signature.field", fieldName)); | |
372 | this.fieldName = fieldName; | |
373 | PdfArray r = merged.getAsArray(PdfName.RECT); | |
374 | float llx = r.getAsNumber(0).floatValue(); | |
375 | float lly = r.getAsNumber(1).floatValue(); | |
376 | float urx = r.getAsNumber(2).floatValue(); | |
377 | float ury = r.getAsNumber(3).floatValue(); | |
378 | pageRect = new Rectangle(llx, lly, urx, ury); | |
379 |
1
1. setVisibleSignature : removed call to com/lowagie/text/Rectangle::normalize → NO_COVERAGE |
pageRect.normalize(); |
380 | page = item.getPage(0); | |
381 | int rotation = writer.reader.getPageRotation(page); | |
382 | Rectangle pageSize = writer.reader.getPageSizeWithRotation(page); | |
383 | switch (rotation) { | |
384 | case 90: | |
385 | pageRect = new Rectangle(pageRect.getBottom(), pageSize.getTop() | |
386 |
1
1. setVisibleSignature : Replaced float subtraction with addition → NO_COVERAGE |
- pageRect.getLeft(), pageRect.getTop(), pageSize.getTop() |
387 |
1
1. setVisibleSignature : Replaced float subtraction with addition → NO_COVERAGE |
- pageRect.getRight()); |
388 | break; | |
389 | case 180: | |
390 |
1
1. setVisibleSignature : Replaced float subtraction with addition → NO_COVERAGE |
pageRect = new Rectangle(pageSize.getRight() - pageRect.getLeft(), |
391 |
1
1. setVisibleSignature : Replaced float subtraction with addition → NO_COVERAGE |
pageSize.getTop() - pageRect.getBottom(), pageSize.getRight() |
392 |
2
1. setVisibleSignature : Replaced float subtraction with addition → NO_COVERAGE 2. setVisibleSignature : Replaced float subtraction with addition → NO_COVERAGE |
- pageRect.getRight(), pageSize.getTop() - pageRect.getTop()); |
393 | break; | |
394 | case 270: | |
395 |
1
1. setVisibleSignature : Replaced float subtraction with addition → NO_COVERAGE |
pageRect = new Rectangle(pageSize.getRight() - pageRect.getBottom(), |
396 |
1
1. setVisibleSignature : Replaced float subtraction with addition → NO_COVERAGE |
pageRect.getLeft(), pageSize.getRight() - pageRect.getTop(), |
397 | pageRect.getRight()); | |
398 | break; | |
399 | } | |
400 |
1
1. setVisibleSignature : negated conditional → NO_COVERAGE |
if (rotation != 0) |
401 |
1
1. setVisibleSignature : removed call to com/lowagie/text/Rectangle::normalize → NO_COVERAGE |
pageRect.normalize(); |
402 | rect = new Rectangle(this.pageRect.getWidth(), this.pageRect.getHeight()); | |
403 | } | |
404 | ||
405 | /** | |
406 | * Gets a template layer to create a signature appearance. The layers can go | |
407 | * from 0 to 4. | |
408 | * <p> | |
409 | * Consult <A | |
410 | * HREF="http://partners.adobe.com/asn/developer/pdfs/tn/PPKAppearances.pdf" | |
411 | * >PPKAppearances.pdf</A> for further details. | |
412 | * | |
413 | * @param layer | |
414 | * the layer | |
415 | * @return a template | |
416 | */ | |
417 | public PdfTemplate getLayer(int layer) { | |
418 |
4
1. getLayer : changed conditional boundary → NO_COVERAGE 2. getLayer : changed conditional boundary → NO_COVERAGE 3. getLayer : negated conditional → NO_COVERAGE 4. getLayer : negated conditional → NO_COVERAGE |
if (layer < 0 || layer >= app.length) |
419 |
1
1. getLayer : mutated return of Object value for com/lowagie/text/pdf/PdfSignatureAppearance::getLayer to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
420 | PdfTemplate t = app[layer]; | |
421 |
1
1. getLayer : negated conditional → NO_COVERAGE |
if (t == null) { |
422 | t = app[layer] = new PdfTemplate(writer); | |
423 |
1
1. getLayer : removed call to com/lowagie/text/pdf/PdfTemplate::setBoundingBox → NO_COVERAGE |
t.setBoundingBox(rect); |
424 | writer.addDirectTemplateSimple(t, new PdfName("n" + layer)); | |
425 | } | |
426 |
1
1. getLayer : mutated return of Object value for com/lowagie/text/pdf/PdfSignatureAppearance::getLayer to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return t; |
427 | } | |
428 | ||
429 | /** | |
430 | * Gets the template that aggregates all appearance layers. This corresponds | |
431 | * to the /FRM resource. | |
432 | * <p> | |
433 | * Consult <A | |
434 | * HREF="http://partners.adobe.com/asn/developer/pdfs/tn/PPKAppearances.pdf" | |
435 | * >PPKAppearances.pdf</A> for further details. | |
436 | * | |
437 | * @return the template that aggregates all appearance layers | |
438 | */ | |
439 | public PdfTemplate getTopLayer() { | |
440 |
1
1. getTopLayer : negated conditional → NO_COVERAGE |
if (frm == null) { |
441 | frm = new PdfTemplate(writer); | |
442 |
1
1. getTopLayer : removed call to com/lowagie/text/pdf/PdfTemplate::setBoundingBox → NO_COVERAGE |
frm.setBoundingBox(rect); |
443 | writer.addDirectTemplateSimple(frm, new PdfName("FRM")); | |
444 | } | |
445 |
1
1. getTopLayer : mutated return of Object value for com/lowagie/text/pdf/PdfSignatureAppearance::getTopLayer to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return frm; |
446 | } | |
447 | ||
448 | /** | |
449 | * Gets the main appearance layer. | |
450 | * <p> | |
451 | * Consult <A | |
452 | * HREF="http://partners.adobe.com/asn/developer/pdfs/tn/PPKAppearances.pdf" | |
453 | * >PPKAppearances.pdf</A> for further details. | |
454 | * | |
455 | * @return the main appearance layer | |
456 | * @throws DocumentException | |
457 | * on error | |
458 | */ | |
459 | public PdfTemplate getAppearance() throws DocumentException { | |
460 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
if (isInvisible()) { |
461 | PdfTemplate t = new PdfTemplate(writer); | |
462 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::setBoundingBox → NO_COVERAGE |
t.setBoundingBox(new Rectangle(0, 0)); |
463 | writer.addDirectTemplateSimple(t, null); | |
464 |
1
1. getAppearance : mutated return of Object value for com/lowagie/text/pdf/PdfSignatureAppearance::getAppearance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return t; |
465 | } | |
466 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
if (app[0] == null) { |
467 | PdfTemplate t = app[0] = new PdfTemplate(writer); | |
468 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::setBoundingBox → NO_COVERAGE |
t.setBoundingBox(new Rectangle(100, 100)); |
469 | writer.addDirectTemplateSimple(t, new PdfName("n0")); | |
470 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::setLiteral → NO_COVERAGE |
t.setLiteral("% DSBlank\n"); |
471 | } | |
472 |
2
1. getAppearance : negated conditional → NO_COVERAGE 2. getAppearance : negated conditional → NO_COVERAGE |
if (app[1] == null && !acro6Layers) { |
473 | PdfTemplate t = app[1] = new PdfTemplate(writer); | |
474 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::setBoundingBox → NO_COVERAGE |
t.setBoundingBox(new Rectangle(100, 100)); |
475 | writer.addDirectTemplateSimple(t, new PdfName("n1")); | |
476 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::setLiteral → NO_COVERAGE |
t.setLiteral(questionMark); |
477 | } | |
478 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
if (app[2] == null) { |
479 | String text; | |
480 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
if (layer2Text == null) { |
481 | StringBuilder buf = new StringBuilder(); | |
482 | buf.append("Digitally signed by ") | |
483 | .append(PdfPKCS7.getSubjectFields((X509Certificate) certChain[0]).getField("CN")) | |
484 | .append('\n'); | |
485 | SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss z"); | |
486 | buf.append("Date: ").append(sd.format(signDate.getTime())); | |
487 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
if (reason != null) |
488 | buf.append('\n').append("Reason: ").append(reason); | |
489 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
if (location != null) |
490 | buf.append('\n').append("Location: ").append(location); | |
491 | text = buf.toString(); | |
492 | } else | |
493 | text = layer2Text; | |
494 | PdfTemplate t = app[2] = new PdfTemplate(writer); | |
495 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::setBoundingBox → NO_COVERAGE |
t.setBoundingBox(rect); |
496 | writer.addDirectTemplateSimple(t, new PdfName("n2")); | |
497 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
if (image != null) { |
498 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
if (imageScale == 0) { |
499 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::addImage → NO_COVERAGE |
t.addImage(image, rect.getWidth(), 0, 0, rect.getHeight(), 0, 0); |
500 | } else { | |
501 | float usableScale = imageScale; | |
502 |
2
1. getAppearance : changed conditional boundary → NO_COVERAGE 2. getAppearance : negated conditional → NO_COVERAGE |
if (imageScale < 0) |
503 |
1
1. getAppearance : Replaced float division with multiplication → NO_COVERAGE |
usableScale = Math.min(rect.getWidth() / image.getWidth(), |
504 |
1
1. getAppearance : Replaced float division with multiplication → NO_COVERAGE |
rect.getHeight() / image.getHeight()); |
505 |
1
1. getAppearance : Replaced float multiplication with division → NO_COVERAGE |
float w = image.getWidth() * usableScale; |
506 |
1
1. getAppearance : Replaced float multiplication with division → NO_COVERAGE |
float h = image.getHeight() * usableScale; |
507 |
2
1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE 2. getAppearance : Replaced float division with multiplication → NO_COVERAGE |
float x = (rect.getWidth() - w) / 2; |
508 |
2
1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE 2. getAppearance : Replaced float division with multiplication → NO_COVERAGE |
float y = (rect.getHeight() - h) / 2; |
509 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::addImage → NO_COVERAGE |
t.addImage(image, w, 0, 0, h, x, y); |
510 | } | |
511 | } | |
512 | Font font; | |
513 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
if (layer2Font == null) |
514 | font = new Font(); | |
515 | else | |
516 | font = new Font(layer2Font); | |
517 | float size = font.getSize(); | |
518 | ||
519 | Rectangle dataRect = null; | |
520 | Rectangle signatureRect = null; | |
521 | ||
522 |
3
1. getAppearance : negated conditional → NO_COVERAGE 2. getAppearance : negated conditional → NO_COVERAGE 3. getAppearance : negated conditional → NO_COVERAGE |
if (render == SignatureRenderNameAndDescription |
523 | || (render == SignatureRenderGraphicAndDescription && this.signatureGraphic != null)) { | |
524 | // origin is the bottom-left | |
525 |
2
1. getAppearance : Replaced float division with multiplication → NO_COVERAGE 2. getAppearance : Replaced float subtraction with addition → NO_COVERAGE |
signatureRect = new Rectangle(MARGIN, MARGIN, rect.getWidth() / 2 |
526 |
1
1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE |
- MARGIN, rect.getHeight() - MARGIN); |
527 |
2
1. getAppearance : Replaced float division with multiplication → NO_COVERAGE 2. getAppearance : Replaced float addition with subtraction → NO_COVERAGE |
dataRect = new Rectangle(rect.getWidth() / 2 + MARGIN / 2, MARGIN, |
528 |
2
1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE 2. getAppearance : Replaced float subtraction with addition → NO_COVERAGE |
rect.getWidth() - MARGIN / 2, rect.getHeight() - MARGIN); |
529 | ||
530 |
2
1. getAppearance : changed conditional boundary → NO_COVERAGE 2. getAppearance : negated conditional → NO_COVERAGE |
if (rect.getHeight() > rect.getWidth()) { |
531 |
1
1. getAppearance : Replaced float division with multiplication → NO_COVERAGE |
signatureRect = new Rectangle(MARGIN, rect.getHeight() / 2, |
532 |
1
1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE |
rect.getWidth() - MARGIN, rect.getHeight()); |
533 |
1
1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE |
dataRect = new Rectangle(MARGIN, MARGIN, rect.getWidth() - MARGIN, |
534 |
2
1. getAppearance : Replaced float division with multiplication → NO_COVERAGE 2. getAppearance : Replaced float subtraction with addition → NO_COVERAGE |
rect.getHeight() / 2 - MARGIN); |
535 | } | |
536 | } else { | |
537 |
1
1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE |
dataRect = new Rectangle(MARGIN, MARGIN, rect.getWidth() - MARGIN, |
538 |
2
1. getAppearance : Replaced float multiplication with division → NO_COVERAGE 2. getAppearance : Replaced float subtraction with addition → NO_COVERAGE |
rect.getHeight() * (1 - TOP_SECTION) - MARGIN); |
539 | } | |
540 | ||
541 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
if (render == SignatureRenderNameAndDescription) { |
542 | String signedBy = PdfPKCS7.getSubjectFields((X509Certificate) certChain[0]).getField("CN"); | |
543 |
1
1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE |
Rectangle sr2 = new Rectangle(signatureRect.getWidth() - MARGIN, |
544 |
1
1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE |
signatureRect.getHeight() - MARGIN); |
545 | float signedSize = fitText(font, signedBy, sr2, -1, runDirection); | |
546 | ||
547 | ColumnText ct2 = new ColumnText(t); | |
548 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/ColumnText::setRunDirection → NO_COVERAGE |
ct2.setRunDirection(runDirection); |
549 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/ColumnText::setSimpleColumn → NO_COVERAGE |
ct2.setSimpleColumn(new Phrase(signedBy, font), |
550 | signatureRect.getLeft(), signatureRect.getBottom(), | |
551 | signatureRect.getRight(), signatureRect.getTop(), signedSize, | |
552 | Element.ALIGN_LEFT); | |
553 | ||
554 | ct2.go(); | |
555 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
} else if (render == SignatureRenderGraphicAndDescription) { |
556 | ColumnText ct2 = new ColumnText(t); | |
557 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/ColumnText::setRunDirection → NO_COVERAGE |
ct2.setRunDirection(runDirection); |
558 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/ColumnText::setSimpleColumn → NO_COVERAGE |
ct2.setSimpleColumn(signatureRect.getLeft(), signatureRect.getBottom(), |
559 | signatureRect.getRight(), signatureRect.getTop(), 0, | |
560 | Element.ALIGN_RIGHT); | |
561 | ||
562 | Image im = Image.getInstance(signatureGraphic); | |
563 |
1
1. getAppearance : removed call to com/lowagie/text/Image::scaleToFit → NO_COVERAGE |
im.scaleToFit(signatureRect.getWidth(), signatureRect.getHeight()); |
564 | ||
565 | Paragraph p = new Paragraph(); | |
566 | // must calculate the point to draw from to make image appear in middle | |
567 | // of column | |
568 | float x = 0; | |
569 | // experimentation found this magic number to counteract Adobe's | |
570 | // signature graphic, which | |
571 | // offsets the y co-ordinate by 15 units | |
572 |
2
1. getAppearance : removed negation → NO_COVERAGE 2. getAppearance : Replaced float addition with subtraction → NO_COVERAGE |
float y = -im.getScaledHeight() + 15; |
573 | ||
574 |
3
1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE 2. getAppearance : Replaced float division with multiplication → NO_COVERAGE 3. getAppearance : Replaced float addition with subtraction → NO_COVERAGE |
x = x + (signatureRect.getWidth() - im.getScaledWidth()) / 2; |
575 |
3
1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE 2. getAppearance : Replaced float division with multiplication → NO_COVERAGE 3. getAppearance : Replaced float subtraction with addition → NO_COVERAGE |
y = y - (signatureRect.getHeight() - im.getScaledHeight()) / 2; |
576 | p.add(new Chunk(im, x | |
577 |
3
1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE 2. getAppearance : Replaced float division with multiplication → NO_COVERAGE 3. getAppearance : Replaced float addition with subtraction → NO_COVERAGE |
+ (signatureRect.getWidth() - im.getScaledWidth()) / 2, y, false)); |
578 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/ColumnText::addElement → NO_COVERAGE |
ct2.addElement(p); |
579 | ct2.go(); | |
580 | } | |
581 | ||
582 |
2
1. getAppearance : changed conditional boundary → NO_COVERAGE 2. getAppearance : negated conditional → NO_COVERAGE |
if (size <= 0) { |
583 | Rectangle sr = new Rectangle(dataRect.getWidth(), dataRect.getHeight()); | |
584 | size = fitText(font, text, sr, 12, runDirection); | |
585 | } | |
586 | ColumnText ct = new ColumnText(t); | |
587 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/ColumnText::setRunDirection → NO_COVERAGE |
ct.setRunDirection(runDirection); |
588 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/ColumnText::setSimpleColumn → NO_COVERAGE |
ct.setSimpleColumn(new Phrase(text, font), dataRect.getLeft(), |
589 | dataRect.getBottom(), dataRect.getRight(), dataRect.getTop(), size, | |
590 | Element.ALIGN_LEFT); | |
591 | ct.go(); | |
592 | } | |
593 |
2
1. getAppearance : negated conditional → NO_COVERAGE 2. getAppearance : negated conditional → NO_COVERAGE |
if (app[3] == null && !acro6Layers) { |
594 | PdfTemplate t = app[3] = new PdfTemplate(writer); | |
595 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::setBoundingBox → NO_COVERAGE |
t.setBoundingBox(new Rectangle(100, 100)); |
596 | writer.addDirectTemplateSimple(t, new PdfName("n3")); | |
597 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::setLiteral → NO_COVERAGE |
t.setLiteral("% DSBlank\n"); |
598 | } | |
599 |
2
1. getAppearance : negated conditional → NO_COVERAGE 2. getAppearance : negated conditional → NO_COVERAGE |
if (app[4] == null && !acro6Layers) { |
600 | PdfTemplate t = app[4] = new PdfTemplate(writer); | |
601 |
2
1. getAppearance : Replaced float multiplication with division → NO_COVERAGE 2. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::setBoundingBox → NO_COVERAGE |
t.setBoundingBox(new Rectangle(0, rect.getHeight() * (1 - TOP_SECTION), |
602 | rect.getRight(), rect.getTop())); | |
603 | writer.addDirectTemplateSimple(t, new PdfName("n4")); | |
604 | Font font; | |
605 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
if (layer2Font == null) |
606 | font = new Font(); | |
607 | else | |
608 | font = new Font(layer2Font); | |
609 | float size = font.getSize(); | |
610 | String text = "Signature Not Verified"; | |
611 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
if (layer4Text != null) |
612 | text = layer4Text; | |
613 |
1
1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE |
Rectangle sr = new Rectangle(rect.getWidth() - 2 * MARGIN, |
614 |
2
1. getAppearance : Replaced float multiplication with division → NO_COVERAGE 2. getAppearance : Replaced float subtraction with addition → NO_COVERAGE |
rect.getHeight() * TOP_SECTION - 2 * MARGIN); |
615 | size = fitText(font, text, sr, 15, runDirection); | |
616 | ColumnText ct = new ColumnText(t); | |
617 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/ColumnText::setRunDirection → NO_COVERAGE |
ct.setRunDirection(runDirection); |
618 |
2
1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE 2. getAppearance : removed call to com/lowagie/text/pdf/ColumnText::setSimpleColumn → NO_COVERAGE |
ct.setSimpleColumn(new Phrase(text, font), MARGIN, 0, rect.getWidth() |
619 |
1
1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE |
- MARGIN, rect.getHeight() - MARGIN, size, Element.ALIGN_LEFT); |
620 | ct.go(); | |
621 | } | |
622 | int rotation = writer.reader.getPageRotation(page); | |
623 | Rectangle rotated = new Rectangle(rect); | |
624 | int n = rotation; | |
625 |
2
1. getAppearance : changed conditional boundary → NO_COVERAGE 2. getAppearance : negated conditional → NO_COVERAGE |
while (n > 0) { |
626 | rotated = rotated.rotate(); | |
627 |
1
1. getAppearance : Changed increment from -90 to 90 → NO_COVERAGE |
n -= 90; |
628 | } | |
629 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
if (frm == null) { |
630 | frm = new PdfTemplate(writer); | |
631 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::setBoundingBox → NO_COVERAGE |
frm.setBoundingBox(rotated); |
632 | writer.addDirectTemplateSimple(frm, new PdfName("FRM")); | |
633 |
1
1. getAppearance : Replaced float multiplication with division → NO_COVERAGE |
float scale = Math.min(rect.getWidth(), rect.getHeight()) * 0.9f; |
634 |
2
1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE 2. getAppearance : Replaced float division with multiplication → NO_COVERAGE |
float x = (rect.getWidth() - scale) / 2; |
635 |
2
1. getAppearance : Replaced float subtraction with addition → NO_COVERAGE 2. getAppearance : Replaced float division with multiplication → NO_COVERAGE |
float y = (rect.getHeight() - scale) / 2; |
636 |
1
1. getAppearance : Replaced float division with multiplication → NO_COVERAGE |
scale /= 100; |
637 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
if (rotation == 90) |
638 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::concatCTM → NO_COVERAGE |
frm.concatCTM(0, 1, -1, 0, rect.getHeight(), 0); |
639 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
else if (rotation == 180) |
640 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::concatCTM → NO_COVERAGE |
frm.concatCTM(-1, 0, 0, -1, rect.getWidth(), rect.getHeight()); |
641 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
else if (rotation == 270) |
642 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::concatCTM → NO_COVERAGE |
frm.concatCTM(0, -1, 1, 0, 0, rect.getWidth()); |
643 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::addTemplate → NO_COVERAGE |
frm.addTemplate(app[0], 0, 0); |
644 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
if (!acro6Layers) |
645 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::addTemplate → NO_COVERAGE |
frm.addTemplate(app[1], scale, 0, 0, scale, x, y); |
646 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::addTemplate → NO_COVERAGE |
frm.addTemplate(app[2], 0, 0); |
647 |
1
1. getAppearance : negated conditional → NO_COVERAGE |
if (!acro6Layers) { |
648 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::addTemplate → NO_COVERAGE |
frm.addTemplate(app[3], scale, 0, 0, scale, x, y); |
649 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::addTemplate → NO_COVERAGE |
frm.addTemplate(app[4], 0, 0); |
650 | } | |
651 | } | |
652 | PdfTemplate napp = new PdfTemplate(writer); | |
653 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::setBoundingBox → NO_COVERAGE |
napp.setBoundingBox(rotated); |
654 | writer.addDirectTemplateSimple(napp, null); | |
655 |
1
1. getAppearance : removed call to com/lowagie/text/pdf/PdfTemplate::addTemplate → NO_COVERAGE |
napp.addTemplate(frm, 0, 0); |
656 |
1
1. getAppearance : mutated return of Object value for com/lowagie/text/pdf/PdfSignatureAppearance::getAppearance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return napp; |
657 | } | |
658 | ||
659 | /** | |
660 | * Fits the text to some rectangle adjusting the font size as needed. | |
661 | * | |
662 | * @param font | |
663 | * the font to use | |
664 | * @param text | |
665 | * the text | |
666 | * @param rect | |
667 | * the rectangle where the text must fit | |
668 | * @param maxFontSize | |
669 | * the maximum font size | |
670 | * @param runDirection | |
671 | * the run direction | |
672 | * @return the calculated font size that makes the text fit | |
673 | */ | |
674 | public static float fitText(Font font, String text, Rectangle rect, | |
675 | float maxFontSize, int runDirection) { | |
676 | try { | |
677 | ColumnText ct = null; | |
678 | int status = 0; | |
679 |
2
1. fitText : changed conditional boundary → NO_COVERAGE 2. fitText : negated conditional → NO_COVERAGE |
if (maxFontSize <= 0) { |
680 | int cr = 0; | |
681 | int lf = 0; | |
682 | char[] t = text.toCharArray(); | |
683 | for (char c : t) { | |
684 |
1
1. fitText : negated conditional → NO_COVERAGE |
if (c == '\n') |
685 |
1
1. fitText : Changed increment from 1 to -1 → NO_COVERAGE |
++lf; |
686 |
1
1. fitText : negated conditional → NO_COVERAGE |
else if (c == '\r') |
687 |
1
1. fitText : Changed increment from 1 to -1 → NO_COVERAGE |
++cr; |
688 | } | |
689 |
1
1. fitText : Replaced integer addition with subtraction → NO_COVERAGE |
int minLines = Math.max(cr, lf) + 1; |
690 |
2
1. fitText : Replaced float division with multiplication → NO_COVERAGE 2. fitText : Replaced float subtraction with addition → NO_COVERAGE |
maxFontSize = Math.abs(rect.getHeight()) / minLines - 0.001f; |
691 | } | |
692 |
1
1. fitText : removed call to com/lowagie/text/Font::setSize → NO_COVERAGE |
font.setSize(maxFontSize); |
693 | Phrase ph = new Phrase(text, font); | |
694 | ct = new ColumnText(null); | |
695 |
1
1. fitText : removed call to com/lowagie/text/pdf/ColumnText::setSimpleColumn → NO_COVERAGE |
ct.setSimpleColumn(ph, rect.getLeft(), rect.getBottom(), rect.getRight(), |
696 | rect.getTop(), maxFontSize, Element.ALIGN_LEFT); | |
697 |
1
1. fitText : removed call to com/lowagie/text/pdf/ColumnText::setRunDirection → NO_COVERAGE |
ct.setRunDirection(runDirection); |
698 | status = ct.go(true); | |
699 |
2
1. fitText : Replaced bitwise AND with OR → NO_COVERAGE 2. fitText : negated conditional → NO_COVERAGE |
if ((status & ColumnText.NO_MORE_TEXT) != 0) |
700 |
1
1. fitText : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/PdfSignatureAppearance::fitText → NO_COVERAGE |
return maxFontSize; |
701 | float precision = 0.1f; | |
702 | float min = 0; | |
703 | float max = maxFontSize; | |
704 | float size = maxFontSize; | |
705 |
2
1. fitText : changed conditional boundary → NO_COVERAGE 2. fitText : negated conditional → NO_COVERAGE |
for (int k = 0; k < 50; ++k) { // just in case it doesn't converge |
706 |
2
1. fitText : Replaced float addition with subtraction → NO_COVERAGE 2. fitText : Replaced float division with multiplication → NO_COVERAGE |
size = (min + max) / 2; |
707 | ct = new ColumnText(null); | |
708 |
1
1. fitText : removed call to com/lowagie/text/Font::setSize → NO_COVERAGE |
font.setSize(size); |
709 |
1
1. fitText : removed call to com/lowagie/text/pdf/ColumnText::setSimpleColumn → NO_COVERAGE |
ct.setSimpleColumn(new Phrase(text, font), rect.getLeft(), |
710 | rect.getBottom(), rect.getRight(), rect.getTop(), size, | |
711 | Element.ALIGN_LEFT); | |
712 |
1
1. fitText : removed call to com/lowagie/text/pdf/ColumnText::setRunDirection → NO_COVERAGE |
ct.setRunDirection(runDirection); |
713 | status = ct.go(true); | |
714 |
2
1. fitText : Replaced bitwise AND with OR → NO_COVERAGE 2. fitText : negated conditional → NO_COVERAGE |
if ((status & ColumnText.NO_MORE_TEXT) != 0) { |
715 |
4
1. fitText : changed conditional boundary → NO_COVERAGE 2. fitText : Replaced float subtraction with addition → NO_COVERAGE 3. fitText : Replaced float multiplication with division → NO_COVERAGE 4. fitText : negated conditional → NO_COVERAGE |
if (max - min < size * precision) |
716 |
1
1. fitText : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/PdfSignatureAppearance::fitText → NO_COVERAGE |
return size; |
717 | min = size; | |
718 | } else | |
719 | max = size; | |
720 | } | |
721 |
1
1. fitText : replaced return of float value with -(x + 1) for com/lowagie/text/pdf/PdfSignatureAppearance::fitText → NO_COVERAGE |
return size; |
722 | } catch (Exception e) { | |
723 | throw new ExceptionConverter(e); | |
724 | } | |
725 | } | |
726 | ||
727 | /** | |
728 | * Sets the digest/signature to an external calculated value. | |
729 | * | |
730 | * @param digest | |
731 | * the digest. This is the actual signature | |
732 | * @param RSAdata | |
733 | * the extra data that goes into the data tag in PKCS#7 | |
734 | * @param digestEncryptionAlgorithm | |
735 | * the encryption algorithm. It may must be <CODE>null</CODE> if the | |
736 | * <CODE>digest</CODE> is also <CODE>null</CODE>. If the | |
737 | * <CODE>digest</CODE> is not <CODE>null</CODE> then it may be "RSA" | |
738 | * or "DSA" | |
739 | */ | |
740 | public void setExternalDigest(byte[] digest, byte[] RSAdata, | |
741 | String digestEncryptionAlgorithm) { | |
742 | externalDigest = digest; | |
743 | externalRSAdata = RSAdata; | |
744 | this.digestEncryptionAlgorithm = digestEncryptionAlgorithm; | |
745 | } | |
746 | ||
747 | /** | |
748 | * Gets the signing reason. | |
749 | * | |
750 | * @return the signing reason | |
751 | */ | |
752 | public String getReason() { | |
753 | return this.reason; | |
754 | } | |
755 | ||
756 | /** | |
757 | * Sets the signing reason. | |
758 | * | |
759 | * @param reason | |
760 | * the signing reason | |
761 | */ | |
762 | public void setReason(String reason) { | |
763 | this.reason = reason; | |
764 | } | |
765 | ||
766 | /** | |
767 | * Gets the signing location. | |
768 | * | |
769 | * @return the signing location | |
770 | */ | |
771 | public String getLocation() { | |
772 | return this.location; | |
773 | } | |
774 | ||
775 | /** | |
776 | * Sets the signing location. | |
777 | * | |
778 | * @param location | |
779 | * the signing location | |
780 | */ | |
781 | public void setLocation(String location) { | |
782 | this.location = location; | |
783 | } | |
784 | ||
785 | /** | |
786 | * Returns the Cryptographic Service Provider that will sign the document. | |
787 | * | |
788 | * @return provider the name of the provider, for example "SUN", or | |
789 | * <code>null</code> to use the default provider. | |
790 | */ | |
791 | public String getProvider() { | |
792 | return this.provider; | |
793 | } | |
794 | ||
795 | /** | |
796 | * Sets the Cryptographic Service Provider that will sign the document. | |
797 | * | |
798 | * @param provider | |
799 | * the name of the provider, for example "SUN", or <code>null</code> | |
800 | * to use the default provider. | |
801 | */ | |
802 | public void setProvider(String provider) { | |
803 | this.provider = provider; | |
804 | } | |
805 | ||
806 | /** | |
807 | * Gets the private key. | |
808 | * | |
809 | * @return the private key | |
810 | */ | |
811 | public java.security.PrivateKey getPrivKey() { | |
812 | return privKey; | |
813 | } | |
814 | ||
815 | /** | |
816 | * Gets the certificate revocation list. | |
817 | * | |
818 | * @return the certificate revocation list | |
819 | */ | |
820 | public java.security.cert.CRL[] getCrlList() { | |
821 | return this.crlList; | |
822 | } | |
823 | ||
824 | /** | |
825 | * Gets the filter used to sign the document. | |
826 | * | |
827 | * @return the filter used to sign the document | |
828 | */ | |
829 | public com.lowagie.text.pdf.PdfName getFilter() { | |
830 | return filter; | |
831 | } | |
832 | ||
833 | /** | |
834 | * Checks if a new field was created. | |
835 | * | |
836 | * @return <CODE>true</CODE> if a new field was created, <CODE>false</CODE> if | |
837 | * signing an existing field or if the signature is invisible | |
838 | */ | |
839 | public boolean isNewField() { | |
840 | return this.newField; | |
841 | } | |
842 | ||
843 | /** | |
844 | * Gets the page number of the field. | |
845 | * | |
846 | * @return the page number of the field | |
847 | */ | |
848 | public int getPage() { | |
849 | return page; | |
850 | } | |
851 | ||
852 | /** | |
853 | * Gets the field name. | |
854 | * | |
855 | * @return the field name | |
856 | */ | |
857 | public java.lang.String getFieldName() { | |
858 | return fieldName; | |
859 | } | |
860 | ||
861 | /** | |
862 | * Gets the rectangle that represent the position and dimension of the | |
863 | * signature in the page. | |
864 | * | |
865 | * @return the rectangle that represent the position and dimension of the | |
866 | * signature in the page | |
867 | */ | |
868 | public com.lowagie.text.Rectangle getPageRect() { | |
869 | return pageRect; | |
870 | } | |
871 | ||
872 | /** | |
873 | * Gets the signature date. | |
874 | * | |
875 | * @return the signature date | |
876 | */ | |
877 | public java.util.Calendar getSignDate() { | |
878 | return signDate; | |
879 | } | |
880 | ||
881 | /** | |
882 | * Sets the signature date. | |
883 | * | |
884 | * @param signDate | |
885 | * the signature date | |
886 | */ | |
887 | public void setSignDate(java.util.Calendar signDate) { | |
888 | this.signDate = signDate; | |
889 | } | |
890 | ||
891 | com.lowagie.text.pdf.ByteBuffer getSigout() { | |
892 | return sigout; | |
893 | } | |
894 | ||
895 | void setSigout(com.lowagie.text.pdf.ByteBuffer sigout) { | |
896 | this.sigout = sigout; | |
897 | } | |
898 | ||
899 | java.io.OutputStream getOriginalout() { | |
900 | return originalout; | |
901 | } | |
902 | ||
903 | void setOriginalout(java.io.OutputStream originalout) { | |
904 | this.originalout = originalout; | |
905 | } | |
906 | ||
907 | /** | |
908 | * Gets the temporary file. | |
909 | * | |
910 | * @return the temporary file or <CODE>null</CODE> is the document is created | |
911 | * in memory | |
912 | */ | |
913 | public java.io.File getTempFile() { | |
914 | return tempFile; | |
915 | } | |
916 | ||
917 | void setTempFile(java.io.File tempFile) { | |
918 | this.tempFile = tempFile; | |
919 | } | |
920 | ||
921 | /** | |
922 | * Gets a new signature fied name that doesn't clash with any existing name. | |
923 | * | |
924 | * @return a new signature fied name | |
925 | */ | |
926 | public final String getNewSigName() { | |
927 | AcroFields af = writer.getAcroFields(); | |
928 | String name = "Signature"; | |
929 | int step = 0; | |
930 | boolean found = false; | |
931 |
1
1. getNewSigName : negated conditional → NO_COVERAGE |
while (!found) { |
932 |
1
1. getNewSigName : Changed increment from 1 to -1 → NO_COVERAGE |
++step; |
933 | String n1 = name + step; | |
934 |
1
1. getNewSigName : negated conditional → NO_COVERAGE |
if (af.getFieldItem(n1) != null) |
935 | continue; | |
936 | n1 += "."; | |
937 | found = true; | |
938 | for (Object o : af.getFields().keySet()) { | |
939 | String fn = (String) o; | |
940 |
1
1. getNewSigName : negated conditional → NO_COVERAGE |
if (fn.startsWith(n1)) { |
941 | found = false; | |
942 | break; | |
943 | } | |
944 | } | |
945 | } | |
946 | name += step; | |
947 |
1
1. getNewSigName : mutated return of Object value for com/lowagie/text/pdf/PdfSignatureAppearance::getNewSigName to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return name; |
948 | } | |
949 | ||
950 | /** | |
951 | * This is the first method to be called when using external signatures. The | |
952 | * general sequence is: preClose(), getDocumentBytes() and close(). | |
953 | * <p> | |
954 | * If calling preClose() <B>dont't</B> call PdfStamper.close(). | |
955 | * <p> | |
956 | * No external signatures are allowed if this method is called. | |
957 | * | |
958 | * @throws IOException | |
959 | * on error | |
960 | * @throws DocumentException | |
961 | * on error | |
962 | */ | |
963 | public void preClose() throws IOException, DocumentException { | |
964 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfSignatureAppearance::preClose → NO_COVERAGE |
preClose(null); |
965 | } | |
966 | ||
967 | /** | |
968 | * This is the first method to be called when using external signatures. The | |
969 | * general sequence is: preClose(), getDocumentBytes() and close(). | |
970 | * <p> | |
971 | * If calling preClose() <B>dont't</B> call PdfStamper.close(). | |
972 | * <p> | |
973 | * If using an external signature <CODE>exclusionSizes</CODE> must contain at | |
974 | * least the <CODE>PdfName.CONTENTS</CODE> key with the size that it will take | |
975 | * in the document. Note that due to the hex string coding this size should be | |
976 | * byte_size*2+2. | |
977 | * | |
978 | * @param exclusionSizes | |
979 | * a <CODE>HashMap</CODE> with names and sizes to be excluded in the | |
980 | * signature calculation. The key is a <CODE>PdfName</CODE> and the | |
981 | * value an <CODE>Integer</CODE>. At least the | |
982 | * <CODE>PdfName.CONTENTS</CODE> must be present | |
983 | * @throws IOException | |
984 | * on error | |
985 | * @throws DocumentException | |
986 | * on error | |
987 | */ | |
988 | public void preClose(HashMap exclusionSizes) throws IOException, | |
989 | DocumentException { | |
990 |
1
1. preClose : negated conditional → NO_COVERAGE |
if (preClosed) |
991 | throw new DocumentException( | |
992 | MessageLocalization.getComposedMessage("document.already.pre.closed")); | |
993 | preClosed = true; | |
994 | AcroFields af = writer.getAcroFields(); | |
995 | String name = getFieldName(); | |
996 |
2
1. preClose : negated conditional → NO_COVERAGE 2. preClose : negated conditional → NO_COVERAGE |
boolean fieldExists = !(isInvisible() || isNewField()); |
997 | PdfIndirectReference refSig = writer.getPdfIndirectReference(); | |
998 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfStamperImp::setSigFlags → NO_COVERAGE |
writer.setSigFlags(3); |
999 |
1
1. preClose : negated conditional → NO_COVERAGE |
if (fieldExists) { |
1000 | PdfDictionary widget = af.getFieldItem(name).getWidget(0); | |
1001 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfStamperImp::markUsed → NO_COVERAGE |
writer.markUsed(widget); |
1002 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
widget.put(PdfName.P, writer.getPageReference(getPage())); |
1003 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
widget.put(PdfName.V, refSig); |
1004 | PdfObject obj = PdfReader.getPdfObjectRelease(widget.get(PdfName.F)); | |
1005 | int flags = 0; | |
1006 |
2
1. preClose : negated conditional → NO_COVERAGE 2. preClose : negated conditional → NO_COVERAGE |
if (obj != null && obj.isNumber()) |
1007 | flags = ((PdfNumber) obj).intValue(); | |
1008 |
1
1. preClose : Replaced bitwise OR with AND → NO_COVERAGE |
flags |= PdfAnnotation.FLAGS_LOCKED; |
1009 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
widget.put(PdfName.F, new PdfNumber(flags)); |
1010 | PdfDictionary ap = new PdfDictionary(); | |
1011 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
ap.put(PdfName.N, getAppearance().getIndirectReference()); |
1012 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
widget.put(PdfName.AP, ap); |
1013 | } else { | |
1014 | PdfFormField sigField = PdfFormField.createSignature(writer); | |
1015 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfFormField::setFieldName → NO_COVERAGE |
sigField.setFieldName(name); |
1016 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfFormField::put → NO_COVERAGE |
sigField.put(PdfName.V, refSig); |
1017 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfFormField::setFlags → NO_COVERAGE |
sigField.setFlags(PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_LOCKED); |
1018 | ||
1019 | int pagen = getPage(); | |
1020 | // OJO... Modificacion de | |
1021 | // flopez----------------------------------------------------- | |
1022 | // if (!isInvisible()) | |
1023 | // sigField.setWidget(getPageRect(), null); | |
1024 | // else | |
1025 | // sigField.setWidget(new Rectangle(0, 0), null); | |
1026 |
2
1. preClose : negated conditional → NO_COVERAGE 2. preClose : negated conditional → NO_COVERAGE |
if ((!isInvisible()) && (pagen == 0)) { // Si pagina en cero tonces firma |
1027 | // en todas las paginas | |
1028 | int pages = writer.reader.getNumberOfPages(); | |
1029 |
3
1. preClose : changed conditional boundary → NO_COVERAGE 2. preClose : Changed increment from 1 to -1 → NO_COVERAGE 3. preClose : negated conditional → NO_COVERAGE |
for (int i = 1; i <= pages; i++) { |
1030 | PdfFormField field = PdfFormField.createEmpty(writer); | |
1031 | this.page = i; | |
1032 | pagen = i; | |
1033 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfFormField::setWidget → NO_COVERAGE |
field.setWidget(getPageRect(), null); |
1034 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfFormField::setAppearance → NO_COVERAGE |
field.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, getAppearance()); |
1035 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfFormField::setPlaceInPage → NO_COVERAGE |
field.setPlaceInPage(i); |
1036 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfFormField::setPage → NO_COVERAGE |
field.setPage(i); |
1037 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfFormField::setFlags → NO_COVERAGE |
field.setFlags(PdfAnnotation.FLAGS_PRINT); |
1038 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfFormField::addKid → NO_COVERAGE |
sigField.addKid(field); |
1039 | field = null; | |
1040 | } | |
1041 |
1
1. preClose : negated conditional → NO_COVERAGE |
} else if (!isInvisible()) // Si es una pagina especifica |
1042 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfFormField::setWidget → NO_COVERAGE |
sigField.setWidget(getPageRect(), null); |
1043 | else | |
1044 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfFormField::setWidget → NO_COVERAGE |
sigField.setWidget(new Rectangle(0, 0), null); |
1045 | // ****************************************************************************** | |
1046 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfFormField::setAppearance → NO_COVERAGE |
sigField.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, getAppearance()); |
1047 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfFormField::setPage → NO_COVERAGE |
sigField.setPage(pagen); |
1048 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfStamperImp::addAnnotation → NO_COVERAGE |
writer.addAnnotation(sigField, pagen); |
1049 | } | |
1050 | ||
1051 | exclusionLocations = new HashMap(); | |
1052 |
1
1. preClose : negated conditional → NO_COVERAGE |
if (cryptoDictionary == null) { |
1053 |
1
1. preClose : negated conditional → NO_COVERAGE |
if (PdfName.ADOBE_PPKLITE.equals(getFilter())) |
1054 | sigStandard = new PdfSigGenericPKCS.PPKLite(getProvider()); | |
1055 |
1
1. preClose : negated conditional → NO_COVERAGE |
else if (PdfName.ADOBE_PPKMS.equals(getFilter())) |
1056 | sigStandard = new PdfSigGenericPKCS.PPKMS(getProvider()); | |
1057 |
1
1. preClose : negated conditional → NO_COVERAGE |
else if (PdfName.VERISIGN_PPKVS.equals(getFilter())) |
1058 | sigStandard = new PdfSigGenericPKCS.VeriSign(getProvider()); | |
1059 | else | |
1060 | throw new IllegalArgumentException( | |
1061 | MessageLocalization.getComposedMessage("unknown.filter.1", | |
1062 | getFilter())); | |
1063 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfSigGenericPKCS::setExternalDigest → NO_COVERAGE |
sigStandard.setExternalDigest(externalDigest, externalRSAdata, |
1064 | digestEncryptionAlgorithm); | |
1065 |
1
1. preClose : negated conditional → NO_COVERAGE |
if (getReason() != null) |
1066 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfSigGenericPKCS::setReason → NO_COVERAGE |
sigStandard.setReason(getReason()); |
1067 |
1
1. preClose : negated conditional → NO_COVERAGE |
if (getLocation() != null) |
1068 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfSigGenericPKCS::setLocation → NO_COVERAGE |
sigStandard.setLocation(getLocation()); |
1069 |
1
1. preClose : negated conditional → NO_COVERAGE |
if (getContact() != null) |
1070 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfSigGenericPKCS::setContact → NO_COVERAGE |
sigStandard.setContact(getContact()); |
1071 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfSigGenericPKCS::put → NO_COVERAGE |
sigStandard.put(PdfName.M, new PdfDate(getSignDate())); |
1072 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfSigGenericPKCS::setSignInfo → NO_COVERAGE |
sigStandard.setSignInfo(getPrivKey(), certChain, crlList); |
1073 | // ****************************************************************************** | |
1074 | PdfString contents = (PdfString) sigStandard.get(PdfName.CONTENTS); | |
1075 | PdfLiteral lit = new PdfLiteral( | |
1076 | (contents.toString().length() + (PdfName.ADOBE_PPKLITE | |
1077 |
4
1. preClose : Replaced integer addition with subtraction → NO_COVERAGE 2. preClose : Replaced integer multiplication with division → NO_COVERAGE 3. preClose : Replaced integer addition with subtraction → NO_COVERAGE 4. preClose : negated conditional → NO_COVERAGE |
.equals(getFilter()) ? 0 : 64)) * 2 + 2); |
1078 | exclusionLocations.put(PdfName.CONTENTS, lit); | |
1079 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfSigGenericPKCS::put → NO_COVERAGE |
sigStandard.put(PdfName.CONTENTS, lit); |
1080 | lit = new PdfLiteral(80); | |
1081 | exclusionLocations.put(PdfName.BYTERANGE, lit); | |
1082 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfSigGenericPKCS::put → NO_COVERAGE |
sigStandard.put(PdfName.BYTERANGE, lit); |
1083 |
2
1. preClose : changed conditional boundary → NO_COVERAGE 2. preClose : negated conditional → NO_COVERAGE |
if (certificationLevel > 0) { |
1084 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfSignatureAppearance::addDocMDP → NO_COVERAGE |
addDocMDP(sigStandard); |
1085 | } | |
1086 |
1
1. preClose : negated conditional → NO_COVERAGE |
if (signatureEvent != null) |
1087 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfSignatureAppearance$SignatureEvent::getSignatureDictionary → NO_COVERAGE |
signatureEvent.getSignatureDictionary(sigStandard); |
1088 | writer.addToBody(sigStandard, refSig, false); | |
1089 | } else { | |
1090 | PdfLiteral lit = new PdfLiteral(80); | |
1091 | exclusionLocations.put(PdfName.BYTERANGE, lit); | |
1092 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
cryptoDictionary.put(PdfName.BYTERANGE, lit); |
1093 | for (Object o : exclusionSizes.entrySet()) { | |
1094 | Map.Entry entry = (Map.Entry) o; | |
1095 | PdfName key = (PdfName) entry.getKey(); | |
1096 | Integer v = (Integer) entry.getValue(); | |
1097 | lit = new PdfLiteral(v); | |
1098 | exclusionLocations.put(key, lit); | |
1099 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
cryptoDictionary.put(key, lit); |
1100 | } | |
1101 |
2
1. preClose : changed conditional boundary → NO_COVERAGE 2. preClose : negated conditional → NO_COVERAGE |
if (certificationLevel > 0) |
1102 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfSignatureAppearance::addDocMDP → NO_COVERAGE |
addDocMDP(cryptoDictionary); |
1103 |
1
1. preClose : negated conditional → NO_COVERAGE |
if (signatureEvent != null) |
1104 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfSignatureAppearance$SignatureEvent::getSignatureDictionary → NO_COVERAGE |
signatureEvent.getSignatureDictionary(cryptoDictionary); |
1105 | writer.addToBody(cryptoDictionary, refSig, false); | |
1106 | } | |
1107 |
2
1. preClose : changed conditional boundary → NO_COVERAGE 2. preClose : negated conditional → NO_COVERAGE |
if (certificationLevel > 0) { |
1108 | // add DocMDP entry to root | |
1109 | PdfDictionary docmdp = new PdfDictionary(); | |
1110 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
docmdp.put(new PdfName("DocMDP"), refSig); |
1111 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
writer.reader.getCatalog().put(new PdfName("Perms"), docmdp); |
1112 | } | |
1113 |
1
1. preClose : removed call to com/lowagie/text/pdf/PdfStamperImp::close → NO_COVERAGE |
writer.close(stamper.getMoreInfo()); |
1114 | ||
1115 |
1
1. preClose : Replaced integer multiplication with division → NO_COVERAGE |
range = new int[exclusionLocations.size() * 2]; |
1116 | int byteRangePosition = ((PdfLiteral) exclusionLocations | |
1117 | .get(PdfName.BYTERANGE)).getPosition(); | |
1118 | exclusionLocations.remove(PdfName.BYTERANGE); | |
1119 | int idx = 1; | |
1120 | for (Object o : exclusionLocations.values()) { | |
1121 | PdfLiteral lit = (PdfLiteral) o; | |
1122 | int n = lit.getPosition(); | |
1123 |
1
1. preClose : Changed increment from 1 to -1 → NO_COVERAGE |
range[idx++] = n; |
1124 |
2
1. preClose : Changed increment from 1 to -1 → NO_COVERAGE 2. preClose : Replaced integer addition with subtraction → NO_COVERAGE |
range[idx++] = lit.getPosLength() + n; |
1125 | } | |
1126 |
2
1. preClose : Replaced integer subtraction with addition → NO_COVERAGE 2. preClose : removed call to java/util/Arrays::sort → NO_COVERAGE |
Arrays.sort(range, 1, range.length - 1); |
1127 |
4
1. preClose : changed conditional boundary → NO_COVERAGE 2. preClose : Changed increment from 2 to -2 → NO_COVERAGE 3. preClose : Replaced integer subtraction with addition → NO_COVERAGE 4. preClose : negated conditional → NO_COVERAGE |
for (int k = 3; k < range.length - 2; k += 2) |
1128 |
2
1. preClose : Replaced integer subtraction with addition → NO_COVERAGE 2. preClose : Replaced integer subtraction with addition → NO_COVERAGE |
range[k] -= range[k - 1]; |
1129 | ||
1130 |
1
1. preClose : negated conditional → NO_COVERAGE |
if (tempFile == null) { |
1131 | bout = sigout.getBuffer(); | |
1132 | boutLen = sigout.size(); | |
1133 |
3
1. preClose : Replaced integer subtraction with addition → NO_COVERAGE 2. preClose : Replaced integer subtraction with addition → NO_COVERAGE 3. preClose : Replaced integer subtraction with addition → NO_COVERAGE |
range[range.length - 1] = boutLen - range[range.length - 2]; |
1134 | ByteBuffer bf = new ByteBuffer(); | |
1135 | bf.append('['); | |
1136 | for (int i : range) bf.append(i).append(' '); | |
1137 | bf.append(']'); | |
1138 |
1
1. preClose : removed call to java/lang/System::arraycopy → NO_COVERAGE |
System.arraycopy(bf.getBuffer(), 0, bout, byteRangePosition, bf.size()); |
1139 | } else { | |
1140 | try { | |
1141 | raf = new RandomAccessFile(tempFile, "rw"); | |
1142 | int boutL = (int) raf.length(); | |
1143 |
3
1. preClose : Replaced integer subtraction with addition → NO_COVERAGE 2. preClose : Replaced integer subtraction with addition → NO_COVERAGE 3. preClose : Replaced integer subtraction with addition → NO_COVERAGE |
range[range.length - 1] = boutL - range[range.length - 2]; |
1144 | ByteBuffer bf = new ByteBuffer(); | |
1145 | bf.append('['); | |
1146 | for (int i : range) bf.append(i).append(' '); | |
1147 | bf.append(']'); | |
1148 |
1
1. preClose : removed call to java/io/RandomAccessFile::seek → NO_COVERAGE |
raf.seek(byteRangePosition); |
1149 |
1
1. preClose : removed call to java/io/RandomAccessFile::write → NO_COVERAGE |
raf.write(bf.getBuffer(), 0, bf.size()); |
1150 | } catch (IOException e) { | |
1151 | try { | |
1152 |
1
1. preClose : removed call to java/io/RandomAccessFile::close → NO_COVERAGE |
raf.close(); |
1153 | } catch (Exception ee) { | |
1154 | } | |
1155 | try { | |
1156 | tempFile.delete(); | |
1157 | } catch (Exception ee) { | |
1158 | } | |
1159 | throw e; | |
1160 | } | |
1161 | } | |
1162 | } | |
1163 | ||
1164 | /** | |
1165 | * This is the last method to be called when using external signatures. The | |
1166 | * general sequence is: preClose(), getDocumentBytes() and close(). | |
1167 | * <p> | |
1168 | * <CODE>update</CODE> is a <CODE>PdfDictionary</CODE> that must have exactly | |
1169 | * the same keys as the ones provided in {@link #preClose(HashMap)}. | |
1170 | * | |
1171 | * @param update | |
1172 | * a <CODE>PdfDictionary</CODE> with the key/value that will fill the | |
1173 | * holes defined in {@link #preClose(HashMap)} | |
1174 | * @throws DocumentException | |
1175 | * on error | |
1176 | * @throws IOException | |
1177 | * on error | |
1178 | */ | |
1179 | public void close(PdfDictionary update) throws IOException, DocumentException { | |
1180 | try { | |
1181 |
1
1. close : negated conditional → NO_COVERAGE |
if (!preClosed) |
1182 | throw new DocumentException( | |
1183 | MessageLocalization | |
1184 | .getComposedMessage("preclose.must.be.called.first")); | |
1185 | ByteBuffer bf = new ByteBuffer(); | |
1186 | for (PdfName key : update.getKeys()) { | |
1187 | PdfObject obj = update.get(key); | |
1188 | PdfLiteral lit = (PdfLiteral) exclusionLocations.get(key); | |
1189 |
1
1. close : negated conditional → NO_COVERAGE |
if (lit == null) |
1190 | throw new IllegalArgumentException( | |
1191 | MessageLocalization.getComposedMessage( | |
1192 | "the.key.1.didn.t.reserve.space.in.preclose", key.toString())); | |
1193 |
1
1. close : removed call to com/lowagie/text/pdf/ByteBuffer::reset → NO_COVERAGE |
bf.reset(); |
1194 |
1
1. close : removed call to com/lowagie/text/pdf/PdfObject::toPdf → NO_COVERAGE |
obj.toPdf(null, bf); |
1195 |
2
1. close : changed conditional boundary → NO_COVERAGE 2. close : negated conditional → NO_COVERAGE |
if (bf.size() > lit.getPosLength()) |
1196 | throw new IllegalArgumentException( | |
1197 | MessageLocalization.getComposedMessage( | |
1198 | "the.key.1.is.too.big.is.2.reserved.3", key.toString(), | |
1199 | String.valueOf(bf.size()), String.valueOf(lit.getPosLength()))); | |
1200 |
1
1. close : negated conditional → NO_COVERAGE |
if (tempFile == null) |
1201 |
1
1. close : removed call to java/lang/System::arraycopy → NO_COVERAGE |
System.arraycopy(bf.getBuffer(), 0, bout, lit.getPosition(), |
1202 | bf.size()); | |
1203 | else { | |
1204 |
1
1. close : removed call to java/io/RandomAccessFile::seek → NO_COVERAGE |
raf.seek(lit.getPosition()); |
1205 |
1
1. close : removed call to java/io/RandomAccessFile::write → NO_COVERAGE |
raf.write(bf.getBuffer(), 0, bf.size()); |
1206 | } | |
1207 | } | |
1208 |
1
1. close : negated conditional → NO_COVERAGE |
if (update.size() != exclusionLocations.size()) |
1209 | throw new IllegalArgumentException( | |
1210 | MessageLocalization | |
1211 | .getComposedMessage("the.update.dictionary.has.less.keys.than.required")); | |
1212 |
1
1. close : negated conditional → NO_COVERAGE |
if (tempFile == null) { |
1213 |
1
1. close : removed call to java/io/OutputStream::write → NO_COVERAGE |
originalout.write(bout, 0, boutLen); |
1214 | } else { | |
1215 |
1
1. close : negated conditional → NO_COVERAGE |
if (originalout != null) { |
1216 |
1
1. close : removed call to java/io/RandomAccessFile::seek → NO_COVERAGE |
raf.seek(0); |
1217 | int length = (int) raf.length(); | |
1218 | byte[] buf = new byte[8192]; | |
1219 |
2
1. close : changed conditional boundary → NO_COVERAGE 2. close : negated conditional → NO_COVERAGE |
while (length > 0) { |
1220 | int r = raf.read(buf, 0, Math.min(buf.length, length)); | |
1221 |
2
1. close : changed conditional boundary → NO_COVERAGE 2. close : negated conditional → NO_COVERAGE |
if (r < 0) |
1222 | throw new EOFException( | |
1223 | MessageLocalization.getComposedMessage("unexpected.eof")); | |
1224 |
1
1. close : removed call to java/io/OutputStream::write → NO_COVERAGE |
originalout.write(buf, 0, r); |
1225 |
1
1. close : Replaced integer subtraction with addition → NO_COVERAGE |
length -= r; |
1226 | } | |
1227 | } | |
1228 | } | |
1229 | } finally { | |
1230 |
1
1. close : negated conditional → NO_COVERAGE |
if (tempFile != null) { |
1231 | try { | |
1232 |
1
1. close : removed call to java/io/RandomAccessFile::close → NO_COVERAGE |
raf.close(); |
1233 | } catch (Exception ee) { | |
1234 | } | |
1235 |
1
1. close : negated conditional → NO_COVERAGE |
if (originalout != null) |
1236 | try { | |
1237 | tempFile.delete(); | |
1238 | } catch (Exception ee) { | |
1239 | } | |
1240 | } | |
1241 |
1
1. close : negated conditional → NO_COVERAGE |
if (originalout != null) |
1242 | try { | |
1243 |
1
1. close : removed call to java/io/OutputStream::close → NO_COVERAGE |
originalout.close(); |
1244 | } catch (Exception e) { | |
1245 | } | |
1246 | } | |
1247 | } | |
1248 | ||
1249 | private void addDocMDP(PdfDictionary crypto) { | |
1250 | PdfDictionary reference = new PdfDictionary(); | |
1251 | PdfDictionary transformParams = new PdfDictionary(); | |
1252 |
1
1. addDocMDP : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
transformParams.put(PdfName.P, new PdfNumber(certificationLevel)); |
1253 |
1
1. addDocMDP : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
transformParams.put(PdfName.V, new PdfName("1.2")); |
1254 |
1
1. addDocMDP : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
transformParams.put(PdfName.TYPE, PdfName.TRANSFORMPARAMS); |
1255 |
1
1. addDocMDP : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
reference.put(PdfName.TRANSFORMMETHOD, PdfName.DOCMDP); |
1256 |
1
1. addDocMDP : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
reference.put(PdfName.TYPE, PdfName.SIGREF); |
1257 |
1
1. addDocMDP : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
reference.put(PdfName.TRANSFORMPARAMS, transformParams); |
1258 |
1
1. addDocMDP : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
reference.put(new PdfName("DigestValue"), new PdfString("aa")); |
1259 | PdfArray loc = new PdfArray(); | |
1260 | loc.add(new PdfNumber(0)); | |
1261 | loc.add(new PdfNumber(0)); | |
1262 |
1
1. addDocMDP : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
reference.put(new PdfName("DigestLocation"), loc); |
1263 |
1
1. addDocMDP : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
reference.put(new PdfName("DigestMethod"), new PdfName("MD5")); |
1264 |
1
1. addDocMDP : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
reference.put(PdfName.DATA, writer.reader.getTrailer().get(PdfName.ROOT)); |
1265 | PdfArray types = new PdfArray(); | |
1266 | types.add(reference); | |
1267 |
1
1. addDocMDP : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
crypto.put(PdfName.REFERENCE, types); |
1268 | } | |
1269 | ||
1270 | /** | |
1271 | * Gets the document bytes that are hashable when using external signatures. | |
1272 | * The general sequence is: preClose(), getRangeStream() and close(). | |
1273 | * <p> | |
1274 | * | |
1275 | * @return the document bytes that are hashable | |
1276 | */ | |
1277 | public InputStream getRangeStream() { | |
1278 |
1
1. getRangeStream : mutated return of Object value for com/lowagie/text/pdf/PdfSignatureAppearance::getRangeStream to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new PdfSignatureAppearance.RangeStream(raf, bout, range); |
1279 | } | |
1280 | ||
1281 | /** | |
1282 | * Gets the user made signature dictionary. This is the dictionary at the /V | |
1283 | * key. | |
1284 | * | |
1285 | * @return the user made signature dictionary | |
1286 | */ | |
1287 | public com.lowagie.text.pdf.PdfDictionary getCryptoDictionary() { | |
1288 | return cryptoDictionary; | |
1289 | } | |
1290 | ||
1291 | /** | |
1292 | * Sets a user made signature dictionary. This is the dictionary at the /V | |
1293 | * key. | |
1294 | * | |
1295 | * @param cryptoDictionary | |
1296 | * a user made signature dictionary | |
1297 | */ | |
1298 | public void setCryptoDictionary( | |
1299 | com.lowagie.text.pdf.PdfDictionary cryptoDictionary) { | |
1300 | this.cryptoDictionary = cryptoDictionary; | |
1301 | } | |
1302 | ||
1303 | /** | |
1304 | * Gets the <CODE>PdfStamper</CODE> associated with this instance. | |
1305 | * | |
1306 | * @return the <CODE>PdfStamper</CODE> associated with this instance | |
1307 | */ | |
1308 | public com.lowagie.text.pdf.PdfStamper getStamper() { | |
1309 | return stamper; | |
1310 | } | |
1311 | ||
1312 | void setStamper(com.lowagie.text.pdf.PdfStamper stamper) { | |
1313 | this.stamper = stamper; | |
1314 | } | |
1315 | ||
1316 | /** | |
1317 | * Checks if the document is in the process of closing. | |
1318 | * | |
1319 | * @return <CODE>true</CODE> if the document is in the process of closing, | |
1320 | * <CODE>false</CODE> otherwise | |
1321 | */ | |
1322 | public boolean isPreClosed() { | |
1323 | return preClosed; | |
1324 | } | |
1325 | ||
1326 | /** | |
1327 | * Gets the instance of the standard signature dictionary. This instance is | |
1328 | * only available after pre close. | |
1329 | * <p> | |
1330 | * The main use is to insert external signatures. | |
1331 | * | |
1332 | * @return the instance of the standard signature dictionary | |
1333 | */ | |
1334 | public com.lowagie.text.pdf.PdfSigGenericPKCS getSigStandard() { | |
1335 | return sigStandard; | |
1336 | } | |
1337 | ||
1338 | /** | |
1339 | * Gets the signing contact. | |
1340 | * | |
1341 | * @return the signing contact | |
1342 | */ | |
1343 | public String getContact() { | |
1344 | return this.contact; | |
1345 | } | |
1346 | ||
1347 | /** | |
1348 | * Sets the signing contact. | |
1349 | * | |
1350 | * @param contact | |
1351 | * the signing contact | |
1352 | */ | |
1353 | public void setContact(String contact) { | |
1354 | this.contact = contact; | |
1355 | } | |
1356 | ||
1357 | /** | |
1358 | * Gets the n2 and n4 layer font. | |
1359 | * | |
1360 | * @return the n2 and n4 layer font | |
1361 | */ | |
1362 | public Font getLayer2Font() { | |
1363 | return this.layer2Font; | |
1364 | } | |
1365 | ||
1366 | /** | |
1367 | * Sets the n2 and n4 layer font. If the font size is zero, auto-fit will be | |
1368 | * used. | |
1369 | * | |
1370 | * @param layer2Font | |
1371 | * the n2 and n4 font | |
1372 | */ | |
1373 | public void setLayer2Font(Font layer2Font) { | |
1374 | this.layer2Font = layer2Font; | |
1375 | } | |
1376 | ||
1377 | /** | |
1378 | * Gets the Acrobat 6.0 layer mode. | |
1379 | * | |
1380 | * @return the Acrobat 6.0 layer mode | |
1381 | */ | |
1382 | public boolean isAcro6Layers() { | |
1383 | return this.acro6Layers; | |
1384 | } | |
1385 | ||
1386 | /** | |
1387 | * Acrobat 6.0 and higher recommends that only layer n2 and n4 be present. | |
1388 | * This method sets that mode. | |
1389 | * | |
1390 | * @param acro6Layers | |
1391 | * if <code>true</code> only the layers n2 and n4 will be present | |
1392 | */ | |
1393 | public void setAcro6Layers(boolean acro6Layers) { | |
1394 | this.acro6Layers = acro6Layers; | |
1395 | } | |
1396 | ||
1397 | /** | |
1398 | * Sets the run direction in the n2 and n4 layer. | |
1399 | * | |
1400 | * @param runDirection | |
1401 | * the run direction | |
1402 | */ | |
1403 | public void setRunDirection(int runDirection) { | |
1404 |
4
1. setRunDirection : changed conditional boundary → NO_COVERAGE 2. setRunDirection : changed conditional boundary → NO_COVERAGE 3. setRunDirection : negated conditional → NO_COVERAGE 4. setRunDirection : negated conditional → NO_COVERAGE |
if (runDirection < PdfWriter.RUN_DIRECTION_DEFAULT |
1405 | || runDirection > PdfWriter.RUN_DIRECTION_RTL) | |
1406 | throw new RuntimeException(MessageLocalization.getComposedMessage( | |
1407 | "invalid.run.direction.1", runDirection)); | |
1408 | this.runDirection = runDirection; | |
1409 | } | |
1410 | ||
1411 | /** | |
1412 | * Gets the run direction. | |
1413 | * | |
1414 | * @return the run direction | |
1415 | */ | |
1416 | public int getRunDirection() { | |
1417 | return runDirection; | |
1418 | } | |
1419 | ||
1420 | /** | |
1421 | * Getter for property signatureEvent. | |
1422 | * | |
1423 | * @return Value of property signatureEvent. | |
1424 | */ | |
1425 | public SignatureEvent getSignatureEvent() { | |
1426 | return this.signatureEvent; | |
1427 | } | |
1428 | ||
1429 | /** | |
1430 | * Sets the signature event to allow modification of the signature dictionary. | |
1431 | * | |
1432 | * @param signatureEvent | |
1433 | * the signature event | |
1434 | */ | |
1435 | public void setSignatureEvent(SignatureEvent signatureEvent) { | |
1436 | this.signatureEvent = signatureEvent; | |
1437 | } | |
1438 | ||
1439 | /** | |
1440 | * Gets the background image for the layer 2. | |
1441 | * | |
1442 | * @return the background image for the layer 2 | |
1443 | */ | |
1444 | public Image getImage() { | |
1445 | return this.image; | |
1446 | } | |
1447 | ||
1448 | /** | |
1449 | * Sets the background image for the layer 2. | |
1450 | * | |
1451 | * @param image | |
1452 | * the background image for the layer 2 | |
1453 | */ | |
1454 | public void setImage(Image image) { | |
1455 | this.image = image; | |
1456 | } | |
1457 | ||
1458 | /** | |
1459 | * Gets the scaling to be applied to the background image. | |
1460 | * | |
1461 | * @return the scaling to be applied to the background image | |
1462 | */ | |
1463 | public float getImageScale() { | |
1464 | return this.imageScale; | |
1465 | } | |
1466 | ||
1467 | /** | |
1468 | * Sets the scaling to be applied to the background image. If it's zero the | |
1469 | * image will fully fill the rectangle. If it's less than zero the image will | |
1470 | * fill the rectangle but will keep the proportions. If it's greater than zero | |
1471 | * that scaling will be applied. In any of the cases the image will always be | |
1472 | * centered. It's zero by default. | |
1473 | * | |
1474 | * @param imageScale | |
1475 | * the scaling to be applied to the background image | |
1476 | */ | |
1477 | public void setImageScale(float imageScale) { | |
1478 | this.imageScale = imageScale; | |
1479 | } | |
1480 | ||
1481 | /** | |
1482 | * Commands to draw a yellow question mark in a stream content | |
1483 | */ | |
1484 | public static final String questionMark = "% DSUnknown\n" + "q\n" + "1 G\n" | |
1485 | + "1 g\n" + "0.1 0 0 0.1 9 0 cm\n" + "0 J 0 j 4 M []0 d\n" + "1 i \n" | |
1486 | + "0 g\n" + "313 292 m\n" + "313 404 325 453 432 529 c\n" | |
1487 | + "478 561 504 597 504 645 c\n" + "504 736 440 760 391 760 c\n" | |
1488 | + "286 760 271 681 265 626 c\n" + "265 625 l\n" + "100 625 l\n" | |
1489 | + "100 828 253 898 381 898 c\n" + "451 898 679 878 679 650 c\n" | |
1490 | + "679 555 628 499 538 435 c\n" + "488 399 467 376 467 292 c\n" | |
1491 | + "313 292 l\n" + "h\n" + "308 214 170 -164 re\n" + "f\n" + "0.44 G\n" | |
1492 | + "1.2 w\n" + "1 1 0.4 rg\n" + "287 318 m\n" | |
1493 | + "287 430 299 479 406 555 c\n" + "451 587 478 623 478 671 c\n" | |
1494 | + "478 762 414 786 365 786 c\n" + "260 786 245 707 239 652 c\n" | |
1495 | + "239 651 l\n" + "74 651 l\n" + "74 854 227 924 355 924 c\n" | |
1496 | + "425 924 653 904 653 676 c\n" + "653 581 602 525 512 461 c\n" | |
1497 | + "462 425 441 402 441 318 c\n" + "287 318 l\n" + "h\n" | |
1498 | + "282 240 170 -164 re\n" + "B\n" + "Q\n"; | |
1499 | ||
1500 | /** | |
1501 | * Holds value of property contact. | |
1502 | */ | |
1503 | private String contact; | |
1504 | ||
1505 | /** | |
1506 | * Holds value of property layer2Font. | |
1507 | */ | |
1508 | private Font layer2Font; | |
1509 | ||
1510 | /** | |
1511 | * Holds value of property layer4Text. | |
1512 | */ | |
1513 | private String layer4Text; | |
1514 | ||
1515 | /** | |
1516 | * Holds value of property acro6Layers. | |
1517 | */ | |
1518 | private boolean acro6Layers; | |
1519 | ||
1520 | /** | |
1521 | * Holds value of property runDirection. | |
1522 | */ | |
1523 | private int runDirection = PdfWriter.RUN_DIRECTION_NO_BIDI; | |
1524 | ||
1525 | /** | |
1526 | * Holds value of property signatureEvent. | |
1527 | */ | |
1528 | private SignatureEvent signatureEvent; | |
1529 | ||
1530 | /** | |
1531 | * Holds value of property image. | |
1532 | */ | |
1533 | private Image image; | |
1534 | ||
1535 | /** | |
1536 | * Holds value of property imageScale. | |
1537 | */ | |
1538 | private float imageScale; | |
1539 | ||
1540 | /** | |
1541 | * | |
1542 | */ | |
1543 | private static class RangeStream extends InputStream { | |
1544 | private final byte[] b = new byte[1]; | |
1545 | private final RandomAccessFile raf; | |
1546 | private final byte[] bout; | |
1547 | private final int[] range; | |
1548 | private int rangePosition = 0; | |
1549 | ||
1550 | private RangeStream(RandomAccessFile raf, byte[] bout, int[] range) { | |
1551 | this.raf = raf; | |
1552 | this.bout = bout; | |
1553 | this.range = range; | |
1554 | } | |
1555 | ||
1556 | /** | |
1557 | * @see java.io.InputStream#read() | |
1558 | */ | |
1559 | @Override | |
1560 | public int read() throws IOException { | |
1561 | int n = read(b); | |
1562 |
1
1. read : negated conditional → NO_COVERAGE |
if (n != 1) |
1563 |
1
1. read : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return -1; |
1564 |
2
1. read : Replaced bitwise AND with OR → NO_COVERAGE 2. read : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return b[0] & 0xff; |
1565 | } | |
1566 | ||
1567 | /** | |
1568 | * @see java.io.InputStream#read(byte[], int, int) | |
1569 | */ | |
1570 | @Override | |
1571 | public int read(byte[] b, int off, int len) throws IOException { | |
1572 |
1
1. read : negated conditional → NO_COVERAGE |
if (b == null) { |
1573 | throw new NullPointerException(); | |
1574 |
12
1. read : changed conditional boundary → NO_COVERAGE 2. read : changed conditional boundary → NO_COVERAGE 3. read : changed conditional boundary → NO_COVERAGE 4. read : changed conditional boundary → NO_COVERAGE 5. read : changed conditional boundary → NO_COVERAGE 6. read : Replaced integer addition with subtraction → NO_COVERAGE 7. read : Replaced integer addition with subtraction → NO_COVERAGE 8. read : negated conditional → NO_COVERAGE 9. read : negated conditional → NO_COVERAGE 10. read : negated conditional → NO_COVERAGE 11. read : negated conditional → NO_COVERAGE 12. read : negated conditional → NO_COVERAGE |
} else if ((off < 0) || (off > b.length) || (len < 0) |
1575 | || ((off + len) > b.length) || ((off + len) < 0)) { | |
1576 | throw new IndexOutOfBoundsException(); | |
1577 |
1
1. read : negated conditional → NO_COVERAGE |
} else if (len == 0) { |
1578 |
1
1. read : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return 0; |
1579 | } | |
1580 |
5
1. read : changed conditional boundary → NO_COVERAGE 2. read : Replaced integer subtraction with addition → NO_COVERAGE 3. read : Replaced integer subtraction with addition → NO_COVERAGE 4. read : Replaced integer addition with subtraction → NO_COVERAGE 5. read : negated conditional → NO_COVERAGE |
if (rangePosition >= range[range.length - 2] + range[range.length - 1]) { |
1581 |
1
1. read : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return -1; |
1582 | } | |
1583 |
3
1. read : changed conditional boundary → NO_COVERAGE 2. read : Changed increment from 2 to -2 → NO_COVERAGE 3. read : negated conditional → NO_COVERAGE |
for (int k = 0; k < range.length; k += 2) { |
1584 | int start = range[k]; | |
1585 |
2
1. read : Replaced integer addition with subtraction → NO_COVERAGE 2. read : Replaced integer addition with subtraction → NO_COVERAGE |
int end = start + range[k + 1]; |
1586 |
2
1. read : changed conditional boundary → NO_COVERAGE 2. read : negated conditional → NO_COVERAGE |
if (rangePosition < start) |
1587 | rangePosition = start; | |
1588 |
4
1. read : changed conditional boundary → NO_COVERAGE 2. read : changed conditional boundary → NO_COVERAGE 3. read : negated conditional → NO_COVERAGE 4. read : negated conditional → NO_COVERAGE |
if (rangePosition >= start && rangePosition < end) { |
1589 |
1
1. read : Replaced integer subtraction with addition → NO_COVERAGE |
int lenf = Math.min(len, end - rangePosition); |
1590 |
1
1. read : negated conditional → NO_COVERAGE |
if (raf == null) |
1591 |
1
1. read : removed call to java/lang/System::arraycopy → NO_COVERAGE |
System.arraycopy(bout, rangePosition, b, off, lenf); |
1592 | else { | |
1593 |
1
1. read : removed call to java/io/RandomAccessFile::seek → NO_COVERAGE |
raf.seek(rangePosition); |
1594 |
1
1. read : removed call to java/io/RandomAccessFile::readFully → NO_COVERAGE |
raf.readFully(b, off, lenf); |
1595 | } | |
1596 |
1
1. read : Replaced integer addition with subtraction → NO_COVERAGE |
rangePosition += lenf; |
1597 |
1
1. read : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return lenf; |
1598 | } | |
1599 | } | |
1600 |
1
1. read : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return -1; |
1601 | } | |
1602 | } | |
1603 | ||
1604 | /** | |
1605 | * An interface to retrieve the signature dictionary for modification. | |
1606 | */ | |
1607 | public interface SignatureEvent { | |
1608 | /** | |
1609 | * Allows modification of the signature dictionary. | |
1610 | * | |
1611 | * @param sig | |
1612 | * the signature dictionary | |
1613 | */ | |
1614 | void getSignatureDictionary(PdfDictionary sig); | |
1615 | } | |
1616 | ||
1617 | private int certificationLevel = NOT_CERTIFIED; | |
1618 | ||
1619 | /** | |
1620 | * Gets the certified status of this document. | |
1621 | * | |
1622 | * @return the certified status | |
1623 | */ | |
1624 | public int getCertificationLevel() { | |
1625 | return this.certificationLevel; | |
1626 | } | |
1627 | ||
1628 | /** | |
1629 | * Sets the document type to certified instead of simply signed. | |
1630 | * | |
1631 | * @param certificationLevel | |
1632 | * the values can be: <code>NOT_CERTIFIED</code>, | |
1633 | * <code>CERTIFIED_NO_CHANGES_ALLOWED</code>, | |
1634 | * <code>CERTIFIED_FORM_FILLING</code> and | |
1635 | * <code>CERTIFIED_FORM_FILLING_AND_ANNOTATIONS</code> | |
1636 | */ | |
1637 | public void setCertificationLevel(int certificationLevel) { | |
1638 | this.certificationLevel = certificationLevel; | |
1639 | } | |
1640 | } | |
Mutations | ||
266 |
1.1 2.2 3.3 4.4 |
|
285 |
1.1 |
|
289 |
1.1 |
|
309 |
1.1 |
|
326 |
1.1 |
|
327 |
1.1 2.2 |
|
333 |
1.1 |
|
342 |
1.1 2.2 3.3 4.4 |
|
347 |
1.1 |
|
363 |
1.1 |
|
368 |
1.1 |
|
379 |
1.1 |
|
386 |
1.1 |
|
387 |
1.1 |
|
390 |
1.1 |
|
391 |
1.1 |
|
392 |
1.1 2.2 |
|
395 |
1.1 |
|
396 |
1.1 |
|
400 |
1.1 |
|
401 |
1.1 |
|
418 |
1.1 2.2 3.3 4.4 |
|
419 |
1.1 |
|
421 |
1.1 |
|
423 |
1.1 |
|
426 |
1.1 |
|
440 |
1.1 |
|
442 |
1.1 |
|
445 |
1.1 |
|
460 |
1.1 |
|
462 |
1.1 |
|
464 |
1.1 |
|
466 |
1.1 |
|
468 |
1.1 |
|
470 |
1.1 |
|
472 |
1.1 2.2 |
|
474 |
1.1 |
|
476 |
1.1 |
|
478 |
1.1 |
|
480 |
1.1 |
|
487 |
1.1 |
|
489 |
1.1 |
|
495 |
1.1 |
|
497 |
1.1 |
|
498 |
1.1 |
|
499 |
1.1 |
|
502 |
1.1 2.2 |
|
503 |
1.1 |
|
504 |
1.1 |
|
505 |
1.1 |
|
506 |
1.1 |
|
507 |
1.1 2.2 |
|
508 |
1.1 2.2 |
|
509 |
1.1 |
|
513 |
1.1 |
|
522 |
1.1 2.2 3.3 |
|
525 |
1.1 2.2 |
|
526 |
1.1 |
|
527 |
1.1 2.2 |
|
528 |
1.1 2.2 |
|
530 |
1.1 2.2 |
|
531 |
1.1 |
|
532 |
1.1 |
|
533 |
1.1 |
|
534 |
1.1 2.2 |
|
537 |
1.1 |
|
538 |
1.1 2.2 |
|
541 |
1.1 |
|
543 |
1.1 |
|
544 |
1.1 |
|
548 |
1.1 |
|
549 |
1.1 |
|
555 |
1.1 |
|
557 |
1.1 |
|
558 |
1.1 |
|
563 |
1.1 |
|
572 |
1.1 2.2 |
|
574 |
1.1 2.2 3.3 |
|
575 |
1.1 2.2 3.3 |
|
577 |
1.1 2.2 3.3 |
|
578 |
1.1 |
|
582 |
1.1 2.2 |
|
587 |
1.1 |
|
588 |
1.1 |
|
593 |
1.1 2.2 |
|
595 |
1.1 |
|
597 |
1.1 |
|
599 |
1.1 2.2 |
|
601 |
1.1 2.2 |
|
605 |
1.1 |
|
611 |
1.1 |
|
613 |
1.1 |
|
614 |
1.1 2.2 |
|
617 |
1.1 |
|
618 |
1.1 2.2 |
|
619 |
1.1 |
|
625 |
1.1 2.2 |
|
627 |
1.1 |
|
629 |
1.1 |
|
631 |
1.1 |
|
633 |
1.1 |
|
634 |
1.1 2.2 |
|
635 |
1.1 2.2 |
|
636 |
1.1 |
|
637 |
1.1 |
|
638 |
1.1 |
|
639 |
1.1 |
|
640 |
1.1 |
|
641 |
1.1 |
|
642 |
1.1 |
|
643 |
1.1 |
|
644 |
1.1 |
|
645 |
1.1 |
|
646 |
1.1 |
|
647 |
1.1 |
|
648 |
1.1 |
|
649 |
1.1 |
|
653 |
1.1 |
|
655 |
1.1 |
|
656 |
1.1 |
|
679 |
1.1 2.2 |
|
684 |
1.1 |
|
685 |
1.1 |
|
686 |
1.1 |
|
687 |
1.1 |
|
689 |
1.1 |
|
690 |
1.1 2.2 |
|
692 |
1.1 |
|
695 |
1.1 |
|
697 |
1.1 |
|
699 |
1.1 2.2 |
|
700 |
1.1 |
|
705 |
1.1 2.2 |
|
706 |
1.1 2.2 |
|
708 |
1.1 |
|
709 |
1.1 |
|
712 |
1.1 |
|
714 |
1.1 2.2 |
|
715 |
1.1 2.2 3.3 4.4 |
|
716 |
1.1 |
|
721 |
1.1 |
|
931 |
1.1 |
|
932 |
1.1 |
|
934 |
1.1 |
|
940 |
1.1 |
|
947 |
1.1 |
|
964 |
1.1 |
|
990 |
1.1 |
|
996 |
1.1 2.2 |
|
998 |
1.1 |
|
999 |
1.1 |
|
1001 |
1.1 |
|
1002 |
1.1 |
|
1003 |
1.1 |
|
1006 |
1.1 2.2 |
|
1008 |
1.1 |
|
1009 |
1.1 |
|
1011 |
1.1 |
|
1012 |
1.1 |
|
1015 |
1.1 |
|
1016 |
1.1 |
|
1017 |
1.1 |
|
1026 |
1.1 2.2 |
|
1029 |
1.1 2.2 3.3 |
|
1033 |
1.1 |
|
1034 |
1.1 |
|
1035 |
1.1 |
|
1036 |
1.1 |
|
1037 |
1.1 |
|
1038 |
1.1 |
|
1041 |
1.1 |
|
1042 |
1.1 |
|
1044 |
1.1 |
|
1046 |
1.1 |
|
1047 |
1.1 |
|
1048 |
1.1 |
|
1052 |
1.1 |
|
1053 |
1.1 |
|
1055 |
1.1 |
|
1057 |
1.1 |
|
1063 |
1.1 |
|
1065 |
1.1 |
|
1066 |
1.1 |
|
1067 |
1.1 |
|
1068 |
1.1 |
|
1069 |
1.1 |
|
1070 |
1.1 |
|
1071 |
1.1 |
|
1072 |
1.1 |
|
1077 |
1.1 2.2 3.3 4.4 |
|
1079 |
1.1 |
|
1082 |
1.1 |
|
1083 |
1.1 2.2 |
|
1084 |
1.1 |
|
1086 |
1.1 |
|
1087 |
1.1 |
|
1092 |
1.1 |
|
1099 |
1.1 |
|
1101 |
1.1 2.2 |
|
1102 |
1.1 |
|
1103 |
1.1 |
|
1104 |
1.1 |
|
1107 |
1.1 2.2 |
|
1110 |
1.1 |
|
1111 |
1.1 |
|
1113 |
1.1 |
|
1115 |
1.1 |
|
1123 |
1.1 |
|
1124 |
1.1 2.2 |
|
1126 |
1.1 2.2 |
|
1127 |
1.1 2.2 3.3 4.4 |
|
1128 |
1.1 2.2 |
|
1130 |
1.1 |
|
1133 |
1.1 2.2 3.3 |
|
1138 |
1.1 |
|
1143 |
1.1 2.2 3.3 |
|
1148 |
1.1 |
|
1149 |
1.1 |
|
1152 |
1.1 |
|
1181 |
1.1 |
|
1189 |
1.1 |
|
1193 |
1.1 |
|
1194 |
1.1 |
|
1195 |
1.1 2.2 |
|
1200 |
1.1 |
|
1201 |
1.1 |
|
1204 |
1.1 |
|
1205 |
1.1 |
|
1208 |
1.1 |
|
1212 |
1.1 |
|
1213 |
1.1 |
|
1215 |
1.1 |
|
1216 |
1.1 |
|
1219 |
1.1 2.2 |
|
1221 |
1.1 2.2 |
|
1224 |
1.1 |
|
1225 |
1.1 |
|
1230 |
1.1 |
|
1232 |
1.1 |
|
1235 |
1.1 |
|
1241 |
1.1 |
|
1243 |
1.1 |
|
1252 |
1.1 |
|
1253 |
1.1 |
|
1254 |
1.1 |
|
1255 |
1.1 |
|
1256 |
1.1 |
|
1257 |
1.1 |
|
1258 |
1.1 |
|
1262 |
1.1 |
|
1263 |
1.1 |
|
1264 |
1.1 |
|
1267 |
1.1 |
|
1278 |
1.1 |
|
1404 |
1.1 2.2 3.3 4.4 |
|
1562 |
1.1 |
|
1563 |
1.1 |
|
1564 |
1.1 2.2 |
|
1572 |
1.1 |
|
1574 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.10 11.11 12.12 |
|
1577 |
1.1 |
|
1578 |
1.1 |
|
1580 |
1.1 2.2 3.3 4.4 5.5 |
|
1581 |
1.1 |
|
1583 |
1.1 2.2 3.3 |
|
1585 |
1.1 2.2 |
|
1586 |
1.1 2.2 |
|
1588 |
1.1 2.2 3.3 4.4 |
|
1589 |
1.1 |
|
1590 |
1.1 |
|
1591 |
1.1 |
|
1593 |
1.1 |
|
1594 |
1.1 |
|
1596 |
1.1 |
|
1597 |
1.1 |
|
1600 |
1.1 |