PdfSignatureAppearance.java

Index Score
com.lowagie.text.pdf
iText

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
JAVA0034JAVA0034 Missing braces in if statement
DECL_COMMENTSComments in declarations
SIZESize of the file in bytes
COMPARISONSNumber of comparison operators
OPERANDSNumber of operands
PROGRAM_LENGTHHalstead program length
OPERATORSNumber of operators
LOGICAL_LINESNumber of statements
ELOCEffective lines of code
DOC_COMMENTNumber of javadoc comment lines
CYCLOMATICCyclomatic complexity
UNIQUE_OPERANDSNumber of unique operands
EXITSProcedure exits
RETURNSNumber of return points from functions
LINESNumber of lines in the source file
LOCLines of code
PROGRAM_VOCABHalstead program vocabulary
COMMENTSComment lines
FUNCTIONSNumber of function declarations
JAVA0285JAVA0285 Dereference of potentially null variable
INTERFACE_COMPLEXITYInterface complexity
BLOCKSNumber of blocks
JAVA0067JAVA0067 Array descriptor on identifier name
LOOPSNumber of loops
JAVA0144JAVA0144 Line exceeds maximum M characters
JAVA0076JAVA0076 Use of magic number
JAVA0166JAVA0166 Generic exception caught
PARAMSNumber of formal parameter declarations
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0035JAVA0035 Missing braces in for statement
JAVA0008JAVA0008 Empty catch block
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
UNIQUE_OPERATORSNumber of unique operators
JAVA0177JAVA0177 Variable declaration missing initializer
JAVA0256JAVA0256 Assignment of external collection/array to field
JAVA0078JAVA0078 Floating point values compared with ==
JAVA0116JAVA0116 Missing javadoc: field 'field'
JAVA0117JAVA0117 Missing javadoc: method 'method'
JAVA0115JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0084JAVA0084 Should use compound assignment operator
PROGRAM_VOLUMEHalstead program volume
JAVA0259JAVA0259 Return of collection/array field
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0032JAVA0032 Switch statement missing default
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0179JAVA0179 Local variable hides visible field
LINE_COMMENTNumber of line comments
EXEC_COMMENTSComments in executable code
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0075JAVA0075 Method parameter hides field
WHITESPACENumber of whitespace lines
NEST_DEPTHMaximum nesting depth
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
JAVA0145JAVA0145 Tab character used in source file
/* * $Id: PdfSignatureAppearance.java 3264 2008-04-17 15:28:45Z psoares33 $ * * Copyright 2004-2006 by Paulo Soares. * * The contents of this file are subject to the Mozilla Public License Version 1.1 * (the "License"); you may not use this file except in compliance with the License. * You may obtain a copy of the License at http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the License. * * The Original Code is 'iText, a free JAVA-PDF library'. * * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. * All Rights Reserved. * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. * * Contributor(s): all the names of the contributors are added in the source code * where applicable. * * Alternatively, the contents of this file may be used under the terms of the * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the * provisions of LGPL are applicable instead of those above. If you wish to * allow use of your version of this file only under the terms of the LGPL * License and not to allow others to use your version of this file under * the MPL, indicate your decision by deleting the provisions above and * replace them with the notice and other provisions required by the LGPL. * If you do not delete the provisions above, a recipient may use your version * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. * * This library is free software; you can redistribute it and/or modify it * under the terms of the MPL as stated above or under the terms of the GNU * Library General Public License as published by the Free Software Foundation; * either version 2 of the License, or any later version. * * This library is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more * details. * * If you didn't download this code from the following link, you should check if * you aren't using an obsolete version: * http://www.lowagie.com/iText/ */ package com.lowagie.text.pdf; import java.io.EOFException; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.RandomAccessFile; import java.security.PrivateKey; import java.security.cert.CRL; import java.security.cert.Certificate; import java.security.cert.X509Certificate; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.GregorianCalendar; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import com.lowagie.text.Chunk; import com.lowagie.text.DocumentException; import com.lowagie.text.Element; import com.lowagie.text.ExceptionConverter; import com.lowagie.text.Font; import com.lowagie.text.Image; import com.lowagie.text.Paragraph; import com.lowagie.text.Phrase; import com.lowagie.text.Rectangle; /** * This class takes care of the cryptographic options and appearances that form a signature. */ public class PdfSignatureAppearance { /** * The rendering mode is just the description */ public static final int SignatureRenderDescription = 0; /** * The rendering mode is the name of the signer and the description */ public static final int SignatureRenderNameAndDescription = 1; /** * The rendering mode is an image and the description */ public static final int SignatureRenderGraphicAndDescription = 2; /** * The self signed filter. */ public static final PdfName SELF_SIGNED = PdfName.ADOBE_PPKLITE; /** * The VeriSign filter. */ public static final PdfName VERISIGN_SIGNED = PdfName.VERISIGN_PPKVS; /** * The Windows Certificate Security. */ public static final PdfName WINCER_SIGNED = PdfName.ADOBE_PPKMS; public static final int NOT_CERTIFIED = 0; public static final int CERTIFIED_NO_CHANGES_ALLOWED = 1; public static final int CERTIFIED_FORM_FILLING = 2; public static final int CERTIFIED_FORM_FILLING_AND_ANNOTATIONS = 3; private static final float TOP_SECTION = 0.3f; private static final float MARGIN = 2; private Rectangle rect; private Rectangle pageRect; private PdfTemplate app[] = new PdfTemplate[5]; private PdfTemplate frm; private PdfStamperImp writer; private String layer2Text; private String reason; private String location; private Calendar signDate; private String provider; private int page = 1; private String fieldName; private PrivateKey privKey; private Certificate[] certChain; private CRL[] crlList; private PdfName filter; private boolean newField; private ByteBuffer sigout; private OutputStream originalout; private File tempFile; private PdfDictionary cryptoDictionary; private PdfStamper stamper; private boolean preClosed = false; private PdfSigGenericPKCS sigStandard; private int range[]; private RandomAccessFile raf; private byte bout[]; private int boutLen; private byte externalDigest[]; private byte externalRSAdata[]; private String digestEncryptionAlgorithm; private HashMap exclusionLocations; PdfSignatureAppearance(PdfStamperImp writer) { this.writer = writer; signDate = new GregorianCalendar(); fieldName = getNewSigName(); } private int render = SignatureRenderDescription; /** * Gets the rendering mode for this signature. * @return the rendering mode for this signature */ public int getRender() { return render; } /** * Sets the rendering mode for this signature. * The rendering modes can be the constants <CODE>SignatureRenderDescription</CODE>, * <CODE>SignatureRenderNameAndDescription</CODE> or <CODE>SignatureRenderGraphicAndDescription</CODE>. * The two last modes should be used with Acrobat 6 layer type. * @param render the render mode */ public void setRender(int render) { this.render = render; } private Image signatureGraphic = null; /** * Gets the Image object to render. * @return the image */ public Image getSignatureGraphic() { return signatureGraphic; } /** * Sets the Image object to render when Render is set to <CODE>SignatureRenderGraphicAndDescription</CODE> * @param signatureGraphic image rendered. If <CODE>null</CODE> the mode is defaulted * to <CODE>SignatureRenderDescription</CODE> */ public void setSignatureGraphic(Image signatureGraphic) { this.signatureGraphic = signatureGraphic; } /** * Sets the signature text identifying the signer. * @param text the signature text identifying the signer. If <CODE>null</CODE> or not set * a standard description will be used */ public void setLayer2Text(String text) { layer2Text = text; } /** * Gets the signature text identifying the signer if set by setLayer2Text(). * @return the signature text identifying the signer */ public String getLayer2Text() { return layer2Text; } /** * Sets the text identifying the signature status. * @param text the text identifying the signature status. If <CODE>null</CODE> or not set * the description "Signature Not Verified" will be used */ public void setLayer4Text(String text) { layer4Text = text; } /** * Gets the text identifying the signature status if set by setLayer4Text(). * @return the text identifying the signature status */ public String getLayer4Text() { return layer4Text; } /** * Gets the rectangle representing the signature dimensions. * @return the rectangle representing the signature dimensions. It may be <CODE>null</CODE> * or have zero width or height for invisible signatures */ public Rectangle getRect() { return rect; } /** * Gets the visibility status of the signature. * @return the visibility status of the signature */ public boolean isInvisible() { return (rect == null || rect.getWidth() == 0 || rect.getHeight() == 0); } /** * Sets the cryptographic parameters. * @param privKey the private key * @param certChain the certificate chain * @param crlList the certificate revocation list. It may be <CODE>null</CODE> * @param filter the crytographic filter type. It can be SELF_SIGNED, VERISIGN_SIGNED or WINCER_SIGNED */ public void setCrypto(PrivateKey privKey, Certificate[] certChain, CRL[] crlList, PdfName filter) { this.privKey = privKey; this.certChain = certChain; this.crlList = crlList; this.filter = filter; } /** * Sets the signature to be visible. It creates a new visible signature field. * @param pageRect the position and dimension of the field in the page * @param page the page to place the field. The fist page is 1 * @param fieldName the field name or <CODE>null</CODE> to generate automatically a new field name */ public void setVisibleSignature(Rectangle pageRect, int page, String fieldName) { if (fieldName != null) { if (fieldName.indexOf('.') >= 0) throw new IllegalArgumentException("Field names cannot contain a dot."); AcroFields af = writer.getAcroFields(); AcroFields.Item item = af.getFieldItem(fieldName); if (item != null) throw new IllegalArgumentException("The field " + fieldName + " already exists."); this.fieldName = fieldName; } if (page < 1 || page > writer.reader.getNumberOfPages()) throw new IllegalArgumentException("Invalid page number: " + page); this.pageRect = new Rectangle(pageRect); this.pageRect.normalize(); rect = new Rectangle(this.pageRect.getWidth(), this.pageRect.getHeight()); this.page = page; newField = true; } /** * Sets the signature to be visible. An empty signature field with the same name must already exist. * @param fieldName the existing empty signature field name */ public void setVisibleSignature(String fieldName) { AcroFields af = writer.getAcroFields(); AcroFields.Item item = af.getFieldItem(fieldName); if (item == null) throw new IllegalArgumentException("The field " + fieldName + " does not exist."); PdfDictionary merged = (PdfDictionary)item.merged.get(0); if (!PdfName.SIG.equals(PdfReader.getPdfObject(merged.get(PdfName.FT)))) throw new IllegalArgumentException("The field " + fieldName + " is not a signature field."); this.fieldName = fieldName; PdfArray r = (PdfArray)PdfReader.getPdfObject(merged.get(PdfName.RECT)); ArrayList ar = r.getArrayList(); float llx = ((PdfNumber)PdfReader.getPdfObject((PdfObject)ar.get(0))).floatValue(); float lly = ((PdfNumber)PdfReader.getPdfObject((PdfObject)ar.get(1))).floatValue(); float urx = ((PdfNumber)PdfReader.getPdfObject((PdfObject)ar.get(2))).floatValue(); float ury = ((PdfNumber)PdfReader.getPdfObject((PdfObject)ar.get(3))).floatValue(); pageRect = new Rectangle(llx, lly, urx, ury); pageRect.normalize(); page = ((Integer)item.page.get(0)).intValue(); int rotation = writer.reader.getPageRotation(page); Rectangle pageSize = writer.reader.getPageSizeWithRotation(page); switch (rotation) { case 90: pageRect = new Rectangle( pageRect.getBottom(), pageSize.getTop() - pageRect.getLeft(), pageRect.getTop(), pageSize.getTop() - pageRect.getRight()); break; case 180: pageRect = new Rectangle( pageSize.getRight() - pageRect.getLeft(), pageSize.getTop() - pageRect.getBottom(), pageSize.getRight() - pageRect.getRight(), pageSize.getTop() - pageRect.getTop()); break; case 270: pageRect = new Rectangle( pageSize.getRight() - pageRect.getBottom(), pageRect.getLeft(), pageSize.getRight() - pageRect.getTop(), pageRect.getRight()); break; } if (rotation != 0) pageRect.normalize(); rect = new Rectangle(this.pageRect.getWidth(), this.pageRect.getHeight()); } /** * Gets a template layer to create a signature appearance. The layers can go from 0 to 4. * <p> * Consult <A HREF="http://partners.adobe.com/asn/developer/pdfs/tn/PPKAppearances.pdf">PPKAppearances.pdf</A> * for further details. * @param layer the layer * @return a template */ public PdfTemplate getLayer(int layer) { if (layer < 0 || layer >= app.length) return null; PdfTemplate t = app[layer]; if (t == null) { t = app[layer] = new PdfTemplate(writer); t.setBoundingBox(rect); writer.addDirectTemplateSimple(t, new PdfName("n" + layer)); } return t; } /** * Gets the template that aggregates all appearance layers. This corresponds to the /FRM resource. * <p> * Consult <A HREF="http://partners.adobe.com/asn/developer/pdfs/tn/PPKAppearances.pdf">PPKAppearances.pdf</A> * for further details. * @return the template that aggregates all appearance layers */ public PdfTemplate getTopLayer() { if (frm == null) { frm = new PdfTemplate(writer); frm.setBoundingBox(rect); writer.addDirectTemplateSimple(frm, new PdfName("FRM")); } return frm; } /** * Gets the main appearance layer. * <p> * Consult <A HREF="http://partners.adobe.com/asn/developer/pdfs/tn/PPKAppearances.pdf">PPKAppearances.pdf</A> * for further details. * @return the main appearance layer * @throws DocumentException on error */ public PdfTemplate getAppearance() throws DocumentException { if (isInvisible()) { PdfTemplate t = new PdfTemplate(writer); t.setBoundingBox(new Rectangle(0, 0)); writer.addDirectTemplateSimple(t, null); return t; } if (app[0] == null) { PdfTemplate t = app[0] = new PdfTemplate(writer); t.setBoundingBox(new Rectangle(100, 100)); writer.addDirectTemplateSimple(t, new PdfName("n0")); t.setLiteral("% DSBlank\n"); } if (app[1] == null && !acro6Layers) { PdfTemplate t = app[1] = new PdfTemplate(writer); t.setBoundingBox(new Rectangle(100, 100)); writer.addDirectTemplateSimple(t, new PdfName("n1")); t.setLiteral(questionMark); } if (app[2] == null) { String text; if (layer2Text == null) { StringBuffer buf = new StringBuffer(); buf.append("Digitally signed by ").append(PdfPKCS7.getSubjectFields((X509Certificate)certChain[0]).getField("CN")).append('\n'); SimpleDateFormat sd = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss z"); buf.append("Date: ").append(sd.format(signDate.getTime())); if (reason != null) buf.append('\n').append("Reason: ").append(reason); if (location != null) buf.append('\n').append("Location: ").append(location); text = buf.toString(); } else text = layer2Text; PdfTemplate t = app[2] = new PdfTemplate(writer); t.setBoundingBox(rect); writer.addDirectTemplateSimple(t, new PdfName("n2")); if (image != null) { if (imageScale == 0) { t.addImage(image, rect.getWidth(), 0, 0, rect.getHeight(), 0, 0); } else { float usableScale = imageScale; if (imageScale < 0) usableScale = Math.min(rect.getWidth() / image.getWidth(), rect.getHeight() / image.getHeight()); float w = image.getWidth() * usableScale; float h = image.getHeight() * usableScale; float x = (rect.getWidth() - w) / 2; float y = (rect.getHeight() - h) / 2; t.addImage(image, w, 0, 0, h, x, y); } } Font font; if (layer2Font == null) font = new Font(); else font = new Font(layer2Font); float size = font.getSize(); Rectangle dataRect = null; Rectangle signatureRect = null; if (render == SignatureRenderNameAndDescription || (render == SignatureRenderGraphicAndDescription && this.signatureGraphic != null)) { // origin is the bottom-left signatureRect = new Rectangle( MARGIN, MARGIN, rect.getWidth() / 2 - MARGIN, rect.getHeight() - MARGIN); dataRect = new Rectangle( rect.getWidth() / 2 + MARGIN / 2, MARGIN, rect.getWidth() - MARGIN / 2, rect.getHeight() - MARGIN); if (rect.getHeight() > rect.getWidth()) { signatureRect = new Rectangle( MARGIN, rect.getHeight() / 2, rect.getWidth() - MARGIN, rect.getHeight()); dataRect = new Rectangle( MARGIN, MARGIN, rect.getWidth() - MARGIN, rect.getHeight() / 2 - MARGIN); } } else { dataRect = new Rectangle( MARGIN, MARGIN, rect.getWidth() - MARGIN, rect.getHeight() * (1 - TOP_SECTION) - MARGIN); } if (render == SignatureRenderNameAndDescription) { String signedBy = PdfPKCS7.getSubjectFields((X509Certificate)certChain[0]).getField("CN"); Rectangle sr2 = new Rectangle(signatureRect.getWidth() - MARGIN, signatureRect.getHeight() - MARGIN ); float signedSize = fitText(font, signedBy, sr2, -1, runDirection); ColumnText ct2 = new ColumnText(t); ct2.setRunDirection(runDirection); ct2.setSimpleColumn(new Phrase(signedBy, font), signatureRect.getLeft(), signatureRect.getBottom(), signatureRect.getRight(), signatureRect.getTop(), signedSize, Element.ALIGN_LEFT); ct2.go(); } else if (render == SignatureRenderGraphicAndDescription) { ColumnText ct2 = new ColumnText(t); ct2.setRunDirection(runDirection); ct2.setSimpleColumn(signatureRect.getLeft(), signatureRect.getBottom(), signatureRect.getRight(), signatureRect.getTop(), 0, Element.ALIGN_RIGHT); Image im = Image.getInstance(signatureGraphic); im.scaleToFit(signatureRect.getWidth(), signatureRect.getHeight()); Paragraph p = new Paragraph(); // must calculate the point to draw from to make image appear in middle of column float x = 0; // experimentation found this magic number to counteract Adobe's signature graphic, which // offsets the y co-ordinate by 15 units float y = -im.getScaledHeight() + 15; x = x + (signatureRect.getWidth() - im.getScaledWidth()) / 2; y = y - (signatureRect.getHeight() - im.getScaledHeight()) / 2; p.add(new Chunk(im, x + (signatureRect.getWidth() - im.getScaledWidth()) / 2, y, false)); ct2.addElement(p); ct2.go(); } if (size <= 0) { Rectangle sr = new Rectangle(dataRect.getWidth(), dataRect.getHeight()); size = fitText(font, text, sr, 12, runDirection); } ColumnText ct = new ColumnText(t); ct.setRunDirection(runDirection); ct.setSimpleColumn(new Phrase(text, font), dataRect.getLeft(), dataRect.getBottom(), dataRect.getRight(), dataRect.getTop(), size, Element.ALIGN_LEFT); ct.go(); } if (app[3] == null && !acro6Layers) { PdfTemplate t = app[3] = new PdfTemplate(writer); t.setBoundingBox(new Rectangle(100, 100)); writer.addDirectTemplateSimple(t, new PdfName("n3")); t.setLiteral("% DSBlank\n"); } if (app[4] == null && !acro6Layers) { PdfTemplate t = app[4] = new PdfTemplate(writer); t.setBoundingBox(new Rectangle(0, rect.getHeight() * (1 - TOP_SECTION), rect.getRight(), rect.getTop())); writer.addDirectTemplateSimple(t, new PdfName("n4")); Font font; if (layer2Font == null) font = new Font(); else font = new Font(layer2Font); float size = font.getSize(); String text = "Signature Not Verified"; if (layer4Text != null) text = layer4Text; Rectangle sr = new Rectangle(rect.getWidth() - 2 * MARGIN, rect.getHeight() * TOP_SECTION - 2 * MARGIN); size = fitText(font, text, sr, 15, runDirection); ColumnText ct = new ColumnText(t); ct.setRunDirection(runDirection); ct.setSimpleColumn(new Phrase(text, font), MARGIN, 0, rect.getWidth() - MARGIN, rect.getHeight() - MARGIN, size, Element.ALIGN_LEFT); ct.go(); } int rotation = writer.reader.getPageRotation(page); Rectangle rotated = new Rectangle(rect); int n = rotation; while (n > 0) { rotated = rotated.rotate(); n -= 90; } if (frm == null) { frm = new PdfTemplate(writer); frm.setBoundingBox(rotated); writer.addDirectTemplateSimple(frm, new PdfName("FRM")); float scale = Math.min(rect.getWidth(), rect.getHeight()) * 0.9f; float x = (rect.getWidth() - scale) / 2; float y = (rect.getHeight() - scale) / 2; scale /= 100; if (rotation == 90) frm.concatCTM(0, 1, -1, 0, rect.getHeight(), 0); else if (rotation == 180) frm.concatCTM(-1, 0, 0, -1, rect.getWidth(), rect.getHeight()); else if (rotation == 270) frm.concatCTM(0, -1, 1, 0, 0, rect.getWidth()); frm.addTemplate(app[0], 0, 0); if (!acro6Layers) frm.addTemplate(app[1], scale, 0, 0, scale, x, y); frm.addTemplate(app[2], 0, 0); if (!acro6Layers) { frm.addTemplate(app[3], scale, 0, 0, scale, x, y); frm.addTemplate(app[4], 0, 0); } } PdfTemplate napp = new PdfTemplate(writer); napp.setBoundingBox(rotated); writer.addDirectTemplateSimple(napp, null); napp.addTemplate(frm, 0, 0); return napp; } /** * Fits the text to some rectangle adjusting the font size as needed. * @param font the font to use * @param text the text * @param rect the rectangle where the text must fit * @param maxFontSize the maximum font size * @param runDirection the run direction * @return the calculated font size that makes the text fit */ public static float fitText(Font font, String text, Rectangle rect, float maxFontSize, int runDirection) { try { ColumnText ct = null; int status = 0; if (maxFontSize <= 0) { int cr = 0; int lf = 0; char t[] = text.toCharArray(); for (int k = 0; k < t.length; ++k) { if (t[k] == '\n') ++lf; else if (t[k] == '\r') ++cr; } int minLines = Math.max(cr, lf) + 1; maxFontSize = Math.abs(rect.getHeight()) / minLines - 0.001f; } font.setSize(maxFontSize); Phrase ph = new Phrase(text, font); ct = new ColumnText(null); ct.setSimpleColumn(ph, rect.getLeft(), rect.getBottom(), rect.getRight(), rect.getTop(), maxFontSize, Element.ALIGN_LEFT); ct.setRunDirection(runDirection); status = ct.go(true); if ((status & ColumnText.NO_MORE_TEXT) != 0) return maxFontSize; float precision = 0.1f; float min = 0; float max = maxFontSize; float size = maxFontSize; for (int k = 0; k < 50; ++k) { //just in case it doesn't converge size = (min + max) / 2; ct = new ColumnText(null); font.setSize(size); ct.setSimpleColumn(new Phrase(text, font), rect.getLeft(), rect.getBottom(), rect.getRight(), rect.getTop(), size, Element.ALIGN_LEFT); ct.setRunDirection(runDirection); status = ct.go(true); if ((status & ColumnText.NO_MORE_TEXT) != 0) { if (max - min < size * precision) return size; min = size; } else max = size; } return size; } catch (Exception e) { throw new ExceptionConverter(e); } } /** * Sets the digest/signature to an external calculated value. * @param digest the digest. This is the actual signature * @param RSAdata the extra data that goes into the data tag in PKCS#7 * @param digestEncryptionAlgorithm the encryption algorithm. It may must be <CODE>null</CODE> if the <CODE>digest</CODE> * is also <CODE>null</CODE>. If the <CODE>digest</CODE> is not <CODE>null</CODE> * then it may be "RSA" or "DSA" */ public void setExternalDigest(byte digest[], byte RSAdata[], String digestEncryptionAlgorithm) { externalDigest = digest; externalRSAdata = RSAdata; this.digestEncryptionAlgorithm = digestEncryptionAlgorithm; } /** * Gets the signing reason. * @return the signing reason */ public String getReason() { return this.reason; } /** * Sets the signing reason. * @param reason the signing reason */ public void setReason(String reason) { this.reason = reason; } /** * Gets the signing location. * @return the signing location */ public String getLocation() { return this.location; } /** * Sets the signing location. * @param location the signing location */ public void setLocation(String location) { this.location = location; } /** * Returns the Cryptographic Service Provider that will sign the document. * @return provider the name of the provider, for example "SUN", * or <code>null</code> to use the default provider. */ public String getProvider() { return this.provider; } /** * Sets the Cryptographic Service Provider that will sign the document. * * @param provider the name of the provider, for example "SUN", or * <code>null</code> to use the default provider. */ public void setProvider(String provider) { this.provider = provider; } /** * Gets the private key. * @return the private key */ public java.security.PrivateKey getPrivKey() { return privKey; } /** * Gets the certificate chain. * @return the certificate chain */ public java.security.cert.Certificate[] getCertChain() { return this.certChain; } /** * Gets the certificate revocation list. * @return the certificate revocation list */ public java.security.cert.CRL[] getCrlList() { return this.crlList; } /** * Gets the filter used to sign the document. * @return the filter used to sign the document */ public com.lowagie.text.pdf.PdfName getFilter() { return filter; } /** * Checks if a new field was created. * @return <CODE>true</CODE> if a new field was created, <CODE>false</CODE> if signing * an existing field or if the signature is invisible */ public boolean isNewField() { return this.newField; } /** * Gets the page number of the field. * @return the page number of the field */ public int getPage() { return page; } /** * Gets the field name. * @return the field name */ public java.lang.String getFieldName() { return fieldName; } /** * Gets the rectangle that represent the position and dimension of the signature in the page. * @return the rectangle that represent the position and dimension of the signature in the page */ public com.lowagie.text.Rectangle getPageRect() { return pageRect; } /** * Gets the signature date. * @return the signature date */ public java.util.Calendar getSignDate() { return signDate; } /** * Sets the signature date. * @param signDate the signature date */ public void setSignDate(java.util.Calendar signDate) { this.signDate = signDate; } com.lowagie.text.pdf.ByteBuffer getSigout() { return sigout; } void setSigout(com.lowagie.text.pdf.ByteBuffer sigout) { this.sigout = sigout; } java.io.OutputStream getOriginalout() { return originalout; } void setOriginalout(java.io.OutputStream originalout) { this.originalout = originalout; } /** * Gets the temporary file. * @return the temporary file or <CODE>null</CODE> is the document is created in memory */ public java.io.File getTempFile() { return tempFile; } void setTempFile(java.io.File tempFile) { this.tempFile = tempFile; } /** * Gets a new signature fied name that doesn't clash with any existing name. * @return a new signature fied name */ public String getNewSigName() { AcroFields af = writer.getAcroFields(); String name = "Signature"; int step = 0; boolean found = false; while (!found) { ++step; String n1 = name + step; if (af.getFieldItem(n1) != null) continue; n1 += "."; found = true; for (Iterator it = af.getFields().keySet().iterator(); it.hasNext();) { String fn = (String)it.next(); if (fn.startsWith(n1)) { found = false; break; } } } name += step; return name; } /** * This is the first method to be called when using external signatures. The general sequence is: * preClose(), getDocumentBytes() and close(). * <p> * If calling preClose() <B>dont't</B> call PdfStamper.close(). * <p> * No external signatures are allowed if this method is called. * @throws IOException on error * @throws DocumentException on error */ public void preClose() throws IOException, DocumentException { preClose(null); } /** * This is the first method to be called when using external signatures. The general sequence is: * preClose(), getDocumentBytes() and close(). * <p> * If calling preClose() <B>dont't</B> call PdfStamper.close(). * <p> * If using an external signature <CODE>exclusionSizes</CODE> must contain at least * the <CODE>PdfName.CONTENTS</CODE> key with the size that it will take in the * document. Note that due to the hex string coding this size should be * byte_size*2+2. * @param exclusionSizes a <CODE>HashMap</CODE> with names and sizes to be excluded in the signature * calculation. The key is a <CODE>PdfName</CODE> and the value an * <CODE>Integer</CODE>. At least the <CODE>PdfName.CONTENTS</CODE> must be present * @throws IOException on error * @throws DocumentException on error */ public void preClose(HashMap exclusionSizes) throws IOException, DocumentException { if (preClosed) throw new DocumentException("Document already pre closed."); preClosed = true; AcroFields af = writer.getAcroFields(); String name = getFieldName(); boolean fieldExists = !(isInvisible() || isNewField()); PdfIndirectReference refSig = writer.getPdfIndirectReference(); writer.setSigFlags(3); if (fieldExists) { ArrayList widgets = af.getFieldItem(name).widgets; PdfDictionary widget = (PdfDictionary)widgets.get(0); writer.markUsed(widget); widget.put(PdfName.P, writer.getPageReference(getPage())); widget.put(PdfName.V, refSig); PdfObject obj = PdfReader.getPdfObjectRelease(widget.get(PdfName.F)); int flags = 0; if (obj != null && obj.isNumber()) flags = ((PdfNumber)obj).intValue(); flags |= PdfAnnotation.FLAGS_LOCKED; widget.put(PdfName.F, new PdfNumber(flags)); PdfDictionary ap = new PdfDictionary(); ap.put(PdfName.N, getAppearance().getIndirectReference()); widget.put(PdfName.AP, ap); } else { PdfFormField sigField = PdfFormField.createSignature(writer); sigField.setFieldName(name); sigField.put(PdfName.V, refSig); sigField.setFlags(PdfAnnotation.FLAGS_PRINT | PdfAnnotation.FLAGS_LOCKED); int pagen = getPage(); if (!isInvisible()) sigField.setWidget(getPageRect(), null); else sigField.setWidget(new Rectangle(0, 0), null); sigField.setAppearance(PdfAnnotation.APPEARANCE_NORMAL, getAppearance()); sigField.setPage(pagen); writer.addAnnotation(sigField, pagen); } exclusionLocations = new HashMap(); if (cryptoDictionary == null) { if (PdfName.ADOBE_PPKLITE.equals(getFilter())) sigStandard = new PdfSigGenericPKCS.PPKLite(getProvider()); else if (PdfName.ADOBE_PPKMS.equals(getFilter())) sigStandard = new PdfSigGenericPKCS.PPKMS(getProvider()); else if (PdfName.VERISIGN_PPKVS.equals(getFilter())) sigStandard = new PdfSigGenericPKCS.VeriSign(getProvider()); else throw new IllegalArgumentException("Unknown filter: " + getFilter()); sigStandard.setExternalDigest(externalDigest, externalRSAdata, digestEncryptionAlgorithm); if (getReason() != null) sigStandard.setReason(getReason()); if (getLocation() != null) sigStandard.setLocation(getLocation()); if (getContact() != null) sigStandard.setContact(getContact()); sigStandard.put(PdfName.M, new PdfDate(getSignDate())); sigStandard.setSignInfo(getPrivKey(), getCertChain(), getCrlList()); PdfString contents = (PdfString)sigStandard.get(PdfName.CONTENTS); PdfLiteral lit = new PdfLiteral((contents.toString().length() + (PdfName.ADOBE_PPKLITE.equals(getFilter())?0:64)) * 2 + 2); exclusionLocations.put(PdfName.CONTENTS, lit); sigStandard.put(PdfName.CONTENTS, lit); lit = new PdfLiteral(80); exclusionLocations.put(PdfName.BYTERANGE, lit); sigStandard.put(PdfName.BYTERANGE, lit); if (certificationLevel > 0) { addDocMDP(sigStandard); } if (signatureEvent != null) signatureEvent.getSignatureDictionary(sigStandard); writer.addToBody(sigStandard, refSig, false); } else { PdfLiteral lit = new PdfLiteral(80); exclusionLocations.put(PdfName.BYTERANGE, lit); cryptoDictionary.put(PdfName.BYTERANGE, lit); for (Iterator it = exclusionSizes.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry)it.next(); PdfName key = (PdfName)entry.getKey(); Integer v = (Integer)entry.getValue(); lit = new PdfLiteral(v.intValue()); exclusionLocations.put(key, lit); cryptoDictionary.put(key, lit); } if (certificationLevel > 0) addDocMDP(cryptoDictionary); if (signatureEvent != null) signatureEvent.getSignatureDictionary(cryptoDictionary); writer.addToBody(cryptoDictionary, refSig, false); } if (certificationLevel > 0) { // add DocMDP entry to root PdfDictionary docmdp = new PdfDictionary(); docmdp.put(new PdfName("DocMDP"), refSig); writer.reader.getCatalog().put(new PdfName("Perms"), docmdp); } writer.close(stamper.getMoreInfo()); range = new int[exclusionLocations.size() * 2]; int byteRangePosition = ((PdfLiteral)exclusionLocations.get(PdfName.BYTERANGE)).getPosition(); exclusionLocations.remove(PdfName.BYTERANGE); int idx = 1; for (Iterator it = exclusionLocations.values().iterator(); it.hasNext();) { PdfLiteral lit = (PdfLiteral)it.next(); int n = lit.getPosition(); range[idx++] = n; range[idx++] = lit.getPosLength() + n; } Arrays.sort(range, 1, range.length - 1); for (int k = 3; k < range.length - 2; k += 2) range[k] -= range[k - 1]; if (tempFile == null) { bout = sigout.getBuffer(); boutLen = sigout.size(); range[range.length - 1] = boutLen - range[range.length - 2]; ByteBuffer bf = new ByteBuffer(); bf.append('['); for (int k = 0; k < range.length; ++k) bf.append(range[k]).append(' '); bf.append(']'); System.arraycopy(bf.getBuffer(), 0, bout, byteRangePosition, bf.size()); } else { try { raf = new RandomAccessFile(tempFile, "rw"); int boutLen = (int)raf.length(); range[range.length - 1] = boutLen - range[range.length - 2]; ByteBuffer bf = new ByteBuffer(); bf.append('['); for (int k = 0; k < range.length; ++k) bf.append(range[k]).append(' '); bf.append(']'); raf.seek(byteRangePosition); raf.write(bf.getBuffer(), 0, bf.size()); } catch (IOException e) { try{raf.close();}catch(Exception ee){} try{tempFile.delete();}catch(Exception ee){} throw e; } } } /** * This is the last method to be called when using external signatures. The general sequence is: * preClose(), getDocumentBytes() and close(). * <p> * <CODE>update</CODE> is a <CODE>PdfDictionary</CODE> that must have exactly the * same keys as the ones provided in {@link #preClose(HashMap)}. * @param update a <CODE>PdfDictionary</CODE> with the key/value that will fill the holes defined * in {@link #preClose(HashMap)} * @throws DocumentException on error * @throws IOException on error */ public void close(PdfDictionary update) throws IOException, DocumentException { try { if (!preClosed) throw new DocumentException("preClose() must be called first."); ByteBuffer bf = new ByteBuffer(); for (Iterator it = update.getKeys().iterator(); it.hasNext();) { PdfName key = (PdfName)it.next(); PdfObject obj = update.get(key); PdfLiteral lit = (PdfLiteral)exclusionLocations.get(key); if (lit == null) throw new IllegalArgumentException("The key " + key.toString() + " didn't reserve space in preClose()."); bf.reset(); obj.toPdf(null, bf); if (bf.size() > lit.getPosLength()) throw new IllegalArgumentException("The key " + key.toString() + " is too big. Is " + bf.size() + ", reserved " + lit.getPosLength()); if (tempFile == null) System.arraycopy(bf.getBuffer(), 0, bout, lit.getPosition(), bf.size()); else { raf.seek(lit.getPosition()); raf.write(bf.getBuffer(), 0, bf.size()); } } if (update.size() != exclusionLocations.size()) throw new IllegalArgumentException("The update dictionary has less keys than required."); if (tempFile == null) { originalout.write(bout, 0, boutLen); } else { if (originalout != null) { raf.seek(0); int length = (int)raf.length(); byte buf[] = new byte[8192]; while (length > 0) { int r = raf.read(buf, 0, Math.min(buf.length, length)); if (r < 0) throw new EOFException("Unexpected EOF"); originalout.write(buf, 0, r); length -= r; } } } } finally { if (tempFile != null) { try{raf.close();}catch(Exception ee){} if (originalout != null) try{tempFile.delete();}catch(Exception ee){} } if (originalout != null) try{originalout.close();}catch(Exception e){} } } private void addDocMDP(PdfDictionary crypto) { PdfDictionary reference = new PdfDictionary(); PdfDictionary transformParams = new PdfDictionary(); transformParams.put(PdfName.P, new PdfNumber(certificationLevel)); transformParams.put(PdfName.V, new PdfName("1.2")); transformParams.put(PdfName.TYPE, PdfName.TRANSFORMPARAMS); reference.put(PdfName.TRANSFORMMETHOD, PdfName.DOCMDP); reference.put(PdfName.TYPE, PdfName.SIGREF); reference.put(PdfName.TRANSFORMPARAMS, transformParams); reference.put(new PdfName("DigestValue"), new PdfString("aa")); PdfArray loc = new PdfArray(); loc.add(new PdfNumber(0)); loc.add(new PdfNumber(0)); reference.put(new PdfName("DigestLocation"), loc); reference.put(new PdfName("DigestMethod"), new PdfName("MD5")); reference.put(PdfName.DATA, writer.reader.getTrailer().get(PdfName.ROOT)); PdfArray types = new PdfArray(); types.add(reference); crypto.put(PdfName.REFERENCE, types); } /** * Gets the document bytes that are hashable when using external signatures. The general sequence is: * preClose(), getRangeStream() and close(). * <p> * @return the document bytes that are hashable */ public InputStream getRangeStream() { return new PdfSignatureAppearance.RangeStream(raf, bout, range); } /** * Gets the user made signature dictionary. This is the dictionary at the /V key. * @return the user made signature dictionary */ public com.lowagie.text.pdf.PdfDictionary getCryptoDictionary() { return cryptoDictionary; } /** * Sets a user made signature dictionary. This is the dictionary at the /V key. * @param cryptoDictionary a user made signature dictionary */ public void setCryptoDictionary(com.lowagie.text.pdf.PdfDictionary cryptoDictionary) { this.cryptoDictionary = cryptoDictionary; } /** * Gets the <CODE>PdfStamper</CODE> associated with this instance. * @return the <CODE>PdfStamper</CODE> associated with this instance */ public com.lowagie.text.pdf.PdfStamper getStamper() { return stamper; } void setStamper(com.lowagie.text.pdf.PdfStamper stamper) { this.stamper = stamper; } /** * Checks if the document is in the process of closing. * @return <CODE>true</CODE> if the document is in the process of closing, * <CODE>false</CODE> otherwise */ public boolean isPreClosed() { return preClosed; } /** * Gets the instance of the standard signature dictionary. This instance * is only available after pre close. * <p> * The main use is to insert external signatures. * @return the instance of the standard signature dictionary */ public com.lowagie.text.pdf.PdfSigGenericPKCS getSigStandard() { return sigStandard; } /** * Gets the signing contact. * @return the signing contact */ public String getContact() { return this.contact; } /** * Sets the signing contact. * @param contact the signing contact */ public void setContact(String contact) { this.contact = contact; } /** * Gets the n2 and n4 layer font. * @return the n2 and n4 layer font */ public Font getLayer2Font() { return this.layer2Font; } /** * Sets the n2 and n4 layer font. If the font size is zero, auto-fit will be used. * @param layer2Font the n2 and n4 font */ public void setLayer2Font(Font layer2Font) { this.layer2Font = layer2Font; } /** * Gets the Acrobat 6.0 layer mode. * @return the Acrobat 6.0 layer mode */ public boolean isAcro6Layers() { return this.acro6Layers; } /** * Acrobat 6.0 and higher recommends that only layer n2 and n4 be present. This method sets that mode. * @param acro6Layers if <code>true</code> only the layers n2 and n4 will be present */ public void setAcro6Layers(boolean acro6Layers) { this.acro6Layers = acro6Layers; } /** Sets the run direction in the n2 and n4 layer. * @param runDirection the run direction */ public void setRunDirection(int runDirection) { if (runDirection < PdfWriter.RUN_DIRECTION_DEFAULT || runDirection > PdfWriter.RUN_DIRECTION_RTL) throw new RuntimeException("Invalid run direction: " + runDirection); this.runDirection = runDirection; } /** Gets the run direction. * @return the run direction */ public int getRunDirection() { return runDirection; } /** * Getter for property signatureEvent. * @return Value of property signatureEvent. */ public SignatureEvent getSignatureEvent() { return this.signatureEvent; } /** * Sets the signature event to allow modification of the signature dictionary. * @param signatureEvent the signature event */ public void setSignatureEvent(SignatureEvent signatureEvent) { this.signatureEvent = signatureEvent; } /** * Gets the background image for the layer 2. * @return the background image for the layer 2 */ public Image getImage() { return this.image; } /** * Sets the background image for the layer 2. * @param image the background image for the layer 2 */ public void setImage(Image image) { this.image = image; } /** * Gets the scaling to be applied to the background image. * @return the scaling to be applied to the background image */ public float getImageScale() { return this.imageScale; } /** * Sets the scaling to be applied to the background image. If it's zero the image * will fully fill the rectangle. If it's less than zero the image will fill the rectangle but * will keep the proportions. If it's greater than zero that scaling will be applied. * In any of the cases the image will always be centered. It's zero by default. * @param imageScale the scaling to be applied to the background image */ public void setImageScale(float imageScale) { this.imageScale = imageScale; } /** * Commands to draw a yellow question mark in a stream content */ public static final String questionMark = "% DSUnknown\n" + "q\n" + "1 G\n" + "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" + "0 g\n" + "313 292 m\n" + "313 404 325 453 432 529 c\n" + "478 561 504 597 504 645 c\n" + "504 736 440 760 391 760 c\n" + "286 760 271 681 265 626 c\n" + "265 625 l\n" + "100 625 l\n" + "100 828 253 898 381 898 c\n" + "451 898 679 878 679 650 c\n" + "679 555 628 499 538 435 c\n" + "488 399 467 376 467 292 c\n" + "313 292 l\n" + "h\n" + "308 214 170 -164 re\n" + "f\n" + "0.44 G\n" + "1.2 w\n" + "1 1 0.4 rg\n" + "287 318 m\n" + "287 430 299 479 406 555 c\n" + "451 587 478 623 478 671 c\n" + "478 762 414 786 365 786 c\n" + "260 786 245 707 239 652 c\n" + "239 651 l\n" + "74 651 l\n" + "74 854 227 924 355 924 c\n" + "425 924 653 904 653 676 c\n" + "653 581 602 525 512 461 c\n" + "462 425 441 402 441 318 c\n" + "287 318 l\n" + "h\n" + "282 240 170 -164 re\n" + "B\n" + "Q\n"; /** * Holds value of property contact. */ private String contact; /** * Holds value of property layer2Font. */ private Font layer2Font; /** * Holds value of property layer4Text. */ private String layer4Text; /** * Holds value of property acro6Layers. */ private boolean acro6Layers; /** * Holds value of property runDirection. */ private int runDirection = PdfWriter.RUN_DIRECTION_NO_BIDI; /** * Holds value of property signatureEvent. */ private SignatureEvent signatureEvent; /** * Holds value of property image. */ private Image image; /** * Holds value of property imageScale. */ private float imageScale; /** * */ private static class RangeStream extends InputStream { private byte b[] = new byte[1]; private RandomAccessFile raf; private byte bout[]; private int range[]; private int rangePosition = 0; private RangeStream(RandomAccessFile raf, byte bout[], int range[]) { this.raf = raf; this.bout = bout; this.range = range; } /** * @see java.io.InputStream#read() */ public int read() throws IOException { int n = read(b); if (n != 1) return -1; return b[0] & 0xff; } /** * @see java.io.InputStream#read(byte[], int, int) */ public int read(byte[] b, int off, int len) throws IOException { if (b == null) { throw new NullPointerException(); } else if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) > b.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } if (rangePosition >= range[range.length - 2] + range[range.length - 1]) { return -1; } for (int k = 0; k < range.length; k += 2) { int start = range[k]; int end = start + range[k + 1]; if (rangePosition < start) rangePosition = start; if (rangePosition >= start && rangePosition < end) { int lenf = Math.min(len, end - rangePosition); if (raf == null) System.arraycopy(bout, rangePosition, b, off, lenf); else { raf.seek(rangePosition); raf.readFully(b, off, lenf); } rangePosition += lenf; return lenf; } } return -1; } } /** * An interface to retrieve the signature dictionary for modification. */ public interface SignatureEvent { /** * Allows modification of the signature dictionary. * @param sig the signature dictionary */ public void getSignatureDictionary(PdfDictionary sig); } private int certificationLevel = NOT_CERTIFIED; /** * Gets the certified status of this document. * @return the certified status */ public int getCertificationLevel() { return this.certificationLevel; } /** * Sets the document type to certified instead of simply signed. * @param certificationLevel the values can be: <code>NOT_CERTIFIED</code>, <code>CERTIFIED_NO_CHANGES_ALLOWED</code>, * <code>CERTIFIED_FORM_FILLING</code> and <code>CERTIFIED_FORM_FILLING_AND_ANNOTATIONS</code> */ public void setCertificationLevel(int certificationLevel) { this.certificationLevel = certificationLevel; } }

The table below shows all metrics for PdfSignatureAppearance.java.

MetricValueDescription
BLOCKS141.00Number of blocks
BLOCK_COMMENT48.00Number of block comment lines
COMMENTS430.00Comment lines
COMMENT_DENSITY 0.54Comment density
COMPARISONS166.00Number of comparison operators
CYCLOMATIC192.00Cyclomatic complexity
DECL_COMMENTS83.00Comments in declarations
DOC_COMMENT377.00Number of javadoc comment lines
ELOC790.00Effective lines of code
EXEC_COMMENTS 4.00Comments in executable code
EXITS140.00Procedure exits
FUNCTIONS73.00Number of function declarations
HALSTEAD_DIFFICULTY129.12Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY168.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 0.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 5.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 0.00JAVA0031 Case statement not properly closed
JAVA0032 1.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA003452.00JAVA0034 Missing braces in if statement
JAVA0035 3.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA0049 0.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA006710.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 0.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 1.00JAVA0075 Method parameter hides field
JAVA007618.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 3.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 2.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA0108 0.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 2.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 1.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 1.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 2.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 4.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 0.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 0.00JAVA0119 Control variable changed within body of for loop
JAVA0123 0.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 0.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 1.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 9.00JAVA0144 Line exceeds maximum M characters
JAVA0145 0.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 6.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 0.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 3.00JAVA0177 Variable declaration missing initializer
JAVA0179 1.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 4.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 6.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 2.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 3.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor
JAVA0277 0.00JAVA0277 Iterator.next() implementation does not throw NoSuchElementException
JAVA0278 0.00JAVA0278 Unnecessary use of Boolean constructor
JAVA0279 0.00JAVA0279 Serialization method readObject or readObjectNoData calls an overridable method
JAVA0280 0.00JAVA0280 IllegalMonitorStateException caught
JAVA0281 0.00JAVA0281 Iterator.next() not called in loop
JAVA0282 0.00JAVA0282 Call to Iterator.next() in loop which does not test Iterator.hasNext()
JAVA0283 0.00JAVA0283 Control variable not updated in loop body
JAVA0284 0.00JAVA0284 Explicit garbage collection
JAVA028515.00JAVA0285 Dereference of potentially null variable
JAVA0286 0.00JAVA0286 Dereference of null variable
JAVA0287 0.00JAVA0287 Unnecessary null check
JAVA0288 0.00JAVA0288 Inconsistent null check
LINES1458.00Number of lines in the source file
LINE_COMMENT 5.00Number of line comments
LOC922.00Lines of code
LOGICAL_LINES540.00Number of statements
LOOPS13.00Number of loops
NEST_DEPTH 5.00Maximum nesting depth
OPERANDS2555.00Number of operands
OPERATORS4641.00Number of operators
PARAMS49.00Number of formal parameter declarations
PROGRAM_LENGTH7196.00Halstead program length
PROGRAM_VOCAB719.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS119.00Number of return points from functions
SIZE55426.00Size of the file in bytes
UNIQUE_OPERANDS653.00Number of unique operands
UNIQUE_OPERATORS66.00Number of unique operators
WHITESPACE106.00Number of whitespace lines