PdfStamperImp.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
COMPARISONSNumber of comparison operators
CYCLOMATICCyclomatic complexity
LOOPSNumber of loops
OPERANDSNumber of operands
PROGRAM_LENGTHHalstead program length
LOGICAL_LINESNumber of statements
OPERATORSNumber of operators
EXITSProcedure exits
SIZESize of the file in bytes
ELOCEffective lines of code
LOCLines of code
UNIQUE_OPERANDSNumber of unique operands
RETURNSNumber of return points from functions
PROGRAM_VOCABHalstead program vocabulary
BLOCKSNumber of blocks
INTERFACE_COMPLEXITYInterface complexity
LINESNumber of lines in the source file
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
PARAMSNumber of formal parameter declarations
FUNCTIONSNumber of function declarations
JAVA0177JAVA0177 Variable declaration missing initializer
JAVA0119JAVA0119 Control variable changed within body of for loop
JAVA0049JAVA0049 Nested block at depth N (maximum: M)
DECL_COMMENTSComments in declarations
NEST_DEPTHMaximum nesting depth
JAVA0067JAVA0067 Array descriptor on identifier name
JAVA0032JAVA0032 Switch statement missing default
JAVA0075JAVA0075 Method parameter hides field
JAVA0285JAVA0285 Dereference of potentially null variable
UNIQUE_OPERATORSNumber of unique operators
JAVA0078JAVA0078 Floating point values compared with ==
JAVA0179JAVA0179 Local variable hides visible field
COMMENTSComment lines
JAVA0076JAVA0076 Use of magic number
JAVA0270JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
DOC_COMMENTNumber of javadoc comment lines
JAVA0036JAVA0036 Missing braces in while statement
JAVA0144JAVA0144 Line exceeds maximum M characters
JAVA0166JAVA0166 Generic exception caught
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
JAVA0035JAVA0035 Missing braces in for statement
JAVA0160JAVA0160 Method does not throw specified exception
JAVA0126JAVA0126 Method declares unchecked exception in throws
LINE_COMMENTNumber of line comments
JAVA0173JAVA0173 Unused method parameter
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0130JAVA0130 Non-static method does not use instance fields
EXEC_COMMENTSComments in executable code
/* * Copyright 2003 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.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import com.lowagie.text.DocumentException; import com.lowagie.text.ExceptionConverter; import com.lowagie.text.Image; import com.lowagie.text.Rectangle; import com.lowagie.text.pdf.collection.PdfCollection; import com.lowagie.text.pdf.interfaces.PdfViewerPreferences; import com.lowagie.text.pdf.internal.PdfViewerPreferencesImp; import com.lowagie.text.xml.xmp.XmpReader; class PdfStamperImp extends PdfWriter { HashMap readers2intrefs = new HashMap(); HashMap readers2file = new HashMap(); RandomAccessFileOrArray file; PdfReader reader; IntHashtable myXref = new IntHashtable(); /** Integer(page number) -> PageStamp */ HashMap pagesToContent = new HashMap(); boolean closed = false; /** Holds value of property rotateContents. */ private boolean rotateContents = true; protected AcroFields acroFields; protected boolean flat = false; protected boolean flatFreeText = false; protected int namePtr[] = {0}; protected HashSet partialFlattening = new HashSet(); protected boolean useVp = false; protected PdfViewerPreferencesImp viewerPreferences = new PdfViewerPreferencesImp(); protected HashMap fieldTemplates = new HashMap(); protected boolean fieldsAdded = false; protected int sigFlags = 0; protected boolean append; protected IntHashtable marked; protected int initialXrefSize; protected PdfAction openAction; /** Creates new PdfStamperImp. * @param reader the read PDF * @param os the output destination * @param pdfVersion the new pdf version or '\0' to keep the same version as the original * document * @param append * @throws DocumentException on error * @throws IOException */ PdfStamperImp(PdfReader reader, OutputStream os, char pdfVersion, boolean append) throws DocumentException, IOException { super(new PdfDocument(), os); if (!reader.isOpenedWithFullPermissions()) throw new IllegalArgumentException("PdfReader not opened with owner password"); if (reader.isTampered()) throw new DocumentException("The original document was reused. Read it again from file."); reader.setTampered(true); this.reader = reader; file = reader.getSafeFile(); this.append = append; if (append) { if (reader.isRebuilt()) throw new DocumentException("Append mode requires a document without errors even if recovery was possible."); if (reader.isEncrypted()) crypto = new PdfEncryption(reader.getDecrypt()); pdf_version.setAppendmode(true); file.reOpen(); byte buf[] = new byte[8192]; int n; while ((n = file.read(buf)) > 0) this.os.write(buf, 0, n); file.close(); prevxref = reader.getLastXref(); reader.setAppendable(true); } else { if (pdfVersion == 0) super.setPdfVersion(reader.getPdfVersion()); else super.setPdfVersion(pdfVersion); } super.open(); pdf.addWriter(this); if (append) { body.setRefnum(reader.getXrefSize()); marked = new IntHashtable(); if (reader.isNewXrefType()) fullCompression = true; if (reader.isHybridXref()) fullCompression = false; } initialXrefSize = reader.getXrefSize(); } void close(HashMap moreInfo) throws IOException { if (closed) return; if (useVp) { reader.setViewerPreferences(viewerPreferences); markUsed(reader.getTrailer().get(PdfName.ROOT)); } if (flat) flatFields(); if (flatFreeText) flatFreeTextFields(); addFieldResources(); PdfDictionary catalog = reader.getCatalog(); PdfDictionary acroForm = (PdfDictionary)PdfReader.getPdfObject(catalog.get(PdfName.ACROFORM), reader.getCatalog()); if (acroFields != null && acroFields.getXfa().isChanged()) { markUsed(acroForm); if (!flat) acroFields.getXfa().setXfa(this); } if (sigFlags != 0) { if (acroForm != null) { acroForm.put(PdfName.SIGFLAGS, new PdfNumber(sigFlags)); markUsed(acroForm); markUsed(catalog); } } closed = true; addSharedObjectsToBody(); setOutlines(); setJavaScript(); addFileAttachments(); if (openAction != null) { catalog.put(PdfName.OPENACTION, openAction); } if (pdf.pageLabels != null) catalog.put(PdfName.PAGELABELS, pdf.pageLabels.getDictionary(this)); byte[] altMetadata = null; PdfObject xmpo = PdfReader.getPdfObject(catalog.get(PdfName.METADATA)); if (xmpo != null && xmpo.isStream()) { altMetadata = PdfReader.getStreamBytesRaw((PRStream)xmpo); PdfReader.killIndirect(catalog.get(PdfName.METADATA)); } if (xmpMetadata != null) { altMetadata = xmpMetadata; } // if there is XMP data to add: add it PdfDate date = new PdfDate(); if (altMetadata != null) { XmpReader xmpr = new XmpReader(altMetadata); xmpr.replace("http://ns.adobe.com/xap/1.0/", "ModifyDate", date.getW3CDate()); xmpr.replace("http://ns.adobe.com/xap/1.0/", "MetadataDate", date.getW3CDate()); PdfStream xmp = new PdfStream(xmpr.serializeDoc()); xmp.put(PdfName.TYPE, PdfName.METADATA); xmp.put(PdfName.SUBTYPE, PdfName.XML); if (crypto != null && !crypto.isMetadataEncrypted()) { PdfArray ar = new PdfArray(); ar.add(PdfName.CRYPT); xmp.put(PdfName.FILTER, ar); } if (append && xmpo != null) { body.add(xmp, xmpo.getIndRef()); } else { catalog.put(PdfName.METADATA, body.add(xmp).getIndirectReference()); markUsed(catalog); } } if (!documentOCG.isEmpty()) { fillOCProperties(false); PdfDictionary ocdict = catalog.getAsDict(PdfName.OCPROPERTIES); if (ocdict == null) { reader.getCatalog().put(PdfName.OCPROPERTIES, OCProperties); } else { ocdict.put(PdfName.OCGS, OCProperties.get(PdfName.OCGS)); PdfDictionary ddict = ocdict.getAsDict(PdfName.D); ddict.put(PdfName.ORDER, OCProperties.getAsDict(PdfName.D).get(PdfName.ORDER)); ddict.put(PdfName.RBGROUPS, OCProperties.getAsDict(PdfName.D).get(PdfName.RBGROUPS)); ddict.put(PdfName.OFF, OCProperties.getAsDict(PdfName.D).get(PdfName.OFF)); ddict.put(PdfName.AS, OCProperties.getAsDict(PdfName.D).get(PdfName.AS)); } } PRIndirectReference iInfo = null; try { file.reOpen(); alterContents(); iInfo = (PRIndirectReference)reader.trailer.get(PdfName.INFO); int skip = -1; if (iInfo != null) skip = iInfo.getNumber(); int rootN = ((PRIndirectReference)reader.trailer.get(PdfName.ROOT)).getNumber(); if (append) { int keys[] = marked.getKeys(); for (int k = 0; k < keys.length; ++k) { int j = keys[k]; PdfObject obj = reader.getPdfObjectRelease(j); if (obj != null && skip != j && j < initialXrefSize) { addToBody(obj, j, j != rootN); } } for (int k = initialXrefSize; k < reader.getXrefSize(); ++k) { PdfObject obj = reader.getPdfObject(k); if (obj != null) { addToBody(obj, getNewObjectNumber(reader, k, 0)); } } } else { for (int k = 1; k < reader.getXrefSize(); ++k) { PdfObject obj = reader.getPdfObjectRelease(k); if (obj != null && skip != k) { addToBody(obj, getNewObjectNumber(reader, k, 0), k != rootN); } } } } finally { try { file.close(); } catch (Exception e) { // empty on purpose } } PdfIndirectReference encryption = null; PdfObject fileID = null; if (crypto != null) { if (append) { encryption = reader.getCryptoRef(); } else { PdfIndirectObject encryptionObject = addToBody(crypto.getEncryptionDictionary(), false); encryption = encryptionObject.getIndirectReference(); } fileID = crypto.getFileID(); } else fileID = PdfEncryption.createInfoId(PdfEncryption.createDocumentId()); PRIndirectReference iRoot = (PRIndirectReference)reader.trailer.get(PdfName.ROOT); PdfIndirectReference root = new PdfIndirectReference(0, getNewObjectNumber(reader, iRoot.getNumber(), 0)); PdfIndirectReference info = null; PdfDictionary oldInfo = (PdfDictionary)PdfReader.getPdfObject(iInfo); PdfDictionary newInfo = new PdfDictionary(); if (oldInfo != null) { for (Iterator i = oldInfo.getKeys().iterator(); i.hasNext();) { PdfName key = (PdfName)i.next(); PdfObject value = PdfReader.getPdfObject(oldInfo.get(key)); newInfo.put(key, value); } } if (moreInfo != null) { for (Iterator i = moreInfo.entrySet().iterator(); i.hasNext();) { Map.Entry entry = (Map.Entry) i.next(); String key = (String) entry.getKey(); PdfName keyName = new PdfName(key); String value = (String) entry.getValue(); if (value == null) newInfo.remove(keyName); else newInfo.put(keyName, new PdfString(value, PdfObject.TEXT_UNICODE)); } } newInfo.put(PdfName.MODDATE, date); if (append) { if (iInfo == null) info = addToBody(newInfo, false).getIndirectReference(); else info = addToBody(newInfo, iInfo.getNumber(), false).getIndirectReference(); } else { info = addToBody(newInfo, false).getIndirectReference(); } // write the cross-reference table of the body body.writeCrossReferenceTable(os, root, info, encryption, fileID, prevxref); if (fullCompression) { os.write(getISOBytes("startxref\n")); os.write(getISOBytes(String.valueOf(body.offset()))); os.write(getISOBytes("\n%%EOF\n")); } else { PdfTrailer trailer = new PdfTrailer(body.size(), body.offset(), root, info, encryption, fileID, prevxref); trailer.toPdf(this, os); } os.flush(); if (isCloseStream()) os.close(); reader.close(); } void applyRotation(PdfDictionary pageN, ByteBuffer out) { if (!rotateContents) return; Rectangle page = reader.getPageSizeWithRotation(pageN); int rotation = page.getRotation(); switch (rotation) { case 90: out.append(PdfContents.ROTATE90); out.append(page.getTop()); out.append(' ').append('0').append(PdfContents.ROTATEFINAL); break; case 180: out.append(PdfContents.ROTATE180); out.append(page.getRight()); out.append(' '); out.append(page.getTop()); out.append(PdfContents.ROTATEFINAL); break; case 270: out.append(PdfContents.ROTATE270); out.append('0').append(' '); out.append(page.getRight()); out.append(PdfContents.ROTATEFINAL); break; } } void alterContents() throws IOException { for (Iterator i = pagesToContent.values().iterator(); i.hasNext();) { PageStamp ps = (PageStamp)i.next(); PdfDictionary pageN = ps.pageN; markUsed(pageN); PdfArray ar = null; PdfObject content = PdfReader.getPdfObject(pageN.get(PdfName.CONTENTS), pageN); if (content == null) { ar = new PdfArray(); pageN.put(PdfName.CONTENTS, ar); } else if (content.isArray()) { ar = (PdfArray)content; markUsed(ar); } else if (content.isStream()) { ar = new PdfArray(); ar.add(pageN.get(PdfName.CONTENTS)); pageN.put(PdfName.CONTENTS, ar); } else { ar = new PdfArray(); pageN.put(PdfName.CONTENTS, ar); } ByteBuffer out = new ByteBuffer(); if (ps.under != null) { out.append(PdfContents.SAVESTATE); applyRotation(pageN, out); out.append(ps.under.getInternalBuffer()); out.append(PdfContents.RESTORESTATE); } if (ps.over != null) out.append(PdfContents.SAVESTATE); PdfStream stream = new PdfStream(out.toByteArray()); stream.flateCompress(compressionLevel); ar.addFirst(addToBody(stream).getIndirectReference()); out.reset(); if (ps.over != null) { out.append(' '); out.append(PdfContents.RESTORESTATE); ByteBuffer buf = ps.over.getInternalBuffer(); out.append(buf.getBuffer(), 0, ps.replacePoint); out.append(PdfContents.SAVESTATE); applyRotation(pageN, out); out.append(buf.getBuffer(), ps.replacePoint, buf.size() - ps.replacePoint); out.append(PdfContents.RESTORESTATE); stream = new PdfStream(out.toByteArray()); stream.flateCompress(compressionLevel); ar.add(addToBody(stream).getIndirectReference()); } alterResources(ps); } } void alterResources(PageStamp ps) { ps.pageN.put(PdfName.RESOURCES, ps.pageResources.getResources()); } protected int getNewObjectNumber(PdfReader reader, int number, int generation) { IntHashtable ref = (IntHashtable)readers2intrefs.get(reader); if (ref != null) { int n = ref.get(number); if (n == 0) { n = getIndirectReferenceNumber(); ref.put(number, n); } return n; } if (currentPdfReaderInstance == null) { if (append && number < initialXrefSize) return number; int n = myXref.get(number); if (n == 0) { n = getIndirectReferenceNumber(); myXref.put(number, n); } return n; } else return currentPdfReaderInstance.getNewObjectNumber(number, generation); } RandomAccessFileOrArray getReaderFile(PdfReader reader) { if (readers2intrefs.containsKey(reader)) { RandomAccessFileOrArray raf = (RandomAccessFileOrArray)readers2file.get(reader); if (raf != null) return raf; return reader.getSafeFile(); } if (currentPdfReaderInstance == null) return file; else return currentPdfReaderInstance.getReaderFile(); } /** * @param reader * @param openFile * @throws IOException */ public void registerReader(PdfReader reader, boolean openFile) throws IOException { if (readers2intrefs.containsKey(reader)) return; readers2intrefs.put(reader, new IntHashtable()); if (openFile) { RandomAccessFileOrArray raf = reader.getSafeFile(); readers2file.put(reader, raf); raf.reOpen(); } } /** * @param reader */ public void unRegisterReader(PdfReader reader) { if (!readers2intrefs.containsKey(reader)) return; readers2intrefs.remove(reader); RandomAccessFileOrArray raf = (RandomAccessFileOrArray)readers2file.get(reader); if (raf == null) return; readers2file.remove(reader); try{raf.close();}catch(Exception e){} } static void findAllObjects(PdfReader reader, PdfObject obj, IntHashtable hits) { if (obj == null) return; switch (obj.type()) { case PdfObject.INDIRECT: PRIndirectReference iref = (PRIndirectReference)obj; if (reader != iref.getReader()) return; if (hits.containsKey(iref.getNumber())) return; hits.put(iref.getNumber(), 1); findAllObjects(reader, PdfReader.getPdfObject(obj), hits); return; case PdfObject.ARRAY: ArrayList lst = ((PdfArray)obj).getArrayList(); for (int k = 0; k < lst.size(); ++k) { findAllObjects(reader, (PdfObject)lst.get(k), hits); } return; case PdfObject.DICTIONARY: case PdfObject.STREAM: PdfDictionary dic = (PdfDictionary)obj; for (Iterator it = dic.getKeys().iterator(); it.hasNext();) { PdfName name = (PdfName)it.next(); findAllObjects(reader, dic.get(name), hits); } return; } } /** * @param fdf * @throws IOException */ public void addComments(FdfReader fdf) throws IOException{ if (readers2intrefs.containsKey(fdf)) return; PdfDictionary catalog = fdf.getCatalog(); catalog = (PdfDictionary)PdfReader.getPdfObject(catalog.get(PdfName.FDF)); if (catalog == null) return; PdfArray annots = (PdfArray)PdfReader.getPdfObject(catalog.get(PdfName.ANNOTS)); if (annots == null || annots.size() == 0) return; registerReader(fdf, false); IntHashtable hits = new IntHashtable(); HashMap irt = new HashMap(); ArrayList an = new ArrayList(); ArrayList ar = annots.getArrayList(); for (int k = 0; k < ar.size(); ++k) { PdfObject obj = (PdfObject)ar.get(k); PdfDictionary annot = (PdfDictionary)PdfReader.getPdfObject(obj); PdfNumber page = (PdfNumber)PdfReader.getPdfObject(annot.get(PdfName.PAGE)); if (page == null || page.intValue() >= reader.getNumberOfPages()) continue; findAllObjects(fdf, obj, hits); an.add(obj); if (obj.type() == PdfObject.INDIRECT) { PdfObject nm = PdfReader.getPdfObject(annot.get(PdfName.NM)); if (nm != null && nm.type() == PdfObject.STRING) irt.put(nm.toString(), obj); } } int arhits[] = hits.getKeys(); for (int k = 0; k < arhits.length; ++k) { int n = arhits[k]; PdfObject obj = fdf.getPdfObject(n); if (obj.type() == PdfObject.DICTIONARY) { PdfObject str = PdfReader.getPdfObject(((PdfDictionary)obj).get(PdfName.IRT)); if (str != null && str.type() == PdfObject.STRING) { PdfObject i = (PdfObject)irt.get(str.toString()); if (i != null) { PdfDictionary dic2 = new PdfDictionary(); dic2.merge((PdfDictionary)obj); dic2.put(PdfName.IRT, i); obj = dic2; } } } addToBody(obj, getNewObjectNumber(fdf, n, 0)); } for (int k = 0; k < an.size(); ++k) { PdfObject obj = (PdfObject)an.get(k); PdfDictionary annot = (PdfDictionary)PdfReader.getPdfObject(obj); PdfNumber page = (PdfNumber)PdfReader.getPdfObject(annot.get(PdfName.PAGE)); PdfDictionary dic = reader.getPageN(page.intValue() + 1); PdfArray annotsp = (PdfArray)PdfReader.getPdfObject(dic.get(PdfName.ANNOTS), dic); if (annotsp == null) { annotsp = new PdfArray(); dic.put(PdfName.ANNOTS, annotsp); markUsed(dic); } markUsed(annotsp); annotsp.add(obj); } } PageStamp getPageStamp(int pageNum) { PdfDictionary pageN = reader.getPageN(pageNum); PageStamp ps = (PageStamp)pagesToContent.get(pageN); if (ps == null) { ps = new PageStamp(this, reader, pageN); pagesToContent.put(pageN, ps); } return ps; } PdfContentByte getUnderContent(int pageNum) { if (pageNum < 1 || pageNum > reader.getNumberOfPages()) return null; PageStamp ps = getPageStamp(pageNum); if (ps.under == null) ps.under = new StampContent(this, ps); return ps.under; } PdfContentByte getOverContent(int pageNum) { if (pageNum < 1 || pageNum > reader.getNumberOfPages()) return null; PageStamp ps = getPageStamp(pageNum); if (ps.over == null) ps.over = new StampContent(this, ps); return ps.over; } void correctAcroFieldPages(int page) { if (acroFields == null) return; if (page > reader.getNumberOfPages()) return; HashMap fields = acroFields.getFields(); for (Iterator it = fields.values().iterator(); it.hasNext();) { AcroFields.Item item = (AcroFields.Item)it.next(); ArrayList pages = item.page; for (int k = 0; k < pages.size(); ++k) { int p = ((Integer)pages.get(k)).intValue(); if (p >= page) pages.set(k, new Integer(p + 1)); } } } private static void moveRectangle(PdfDictionary dic2, PdfReader r, int pageImported, PdfName key, String name) { Rectangle m = r.getBoxSize(pageImported, name); if (m == null) dic2.remove(key); else dic2.put(key, new PdfRectangle(m)); } void replacePage(PdfReader r, int pageImported, int pageReplaced) { PdfDictionary pageN = reader.getPageN(pageReplaced); if (pagesToContent.containsKey(pageN)) throw new IllegalStateException("This page cannot be replaced: new content was already added"); PdfImportedPage p = getImportedPage(r, pageImported); PdfDictionary dic2 = reader.getPageNRelease(pageReplaced); dic2.remove(PdfName.RESOURCES); dic2.remove(PdfName.CONTENTS); moveRectangle(dic2, r, pageImported, PdfName.MEDIABOX, "media"); moveRectangle(dic2, r, pageImported, PdfName.CROPBOX, "crop"); moveRectangle(dic2, r, pageImported, PdfName.TRIMBOX, "trim"); moveRectangle(dic2, r, pageImported, PdfName.ARTBOX, "art"); moveRectangle(dic2, r, pageImported, PdfName.BLEEDBOX, "bleed"); dic2.put(PdfName.ROTATE, new PdfNumber(r.getPageRotation(pageImported))); PdfContentByte cb = getOverContent(pageReplaced); cb.addTemplate(p, 0, 0); PageStamp ps = (PageStamp)pagesToContent.get(pageN); ps.replacePoint = ps.over.getInternalBuffer().size(); } void insertPage(int pageNumber, Rectangle mediabox) { Rectangle media = new Rectangle(mediabox); int rotation = media.getRotation() % 360; PdfDictionary page = new PdfDictionary(PdfName.PAGE); PdfDictionary resources = new PdfDictionary(); PdfArray procset = new PdfArray(); procset.add(PdfName.PDF); procset.add(PdfName.TEXT); procset.add(PdfName.IMAGEB); procset.add(PdfName.IMAGEC); procset.add(PdfName.IMAGEI); resources.put(PdfName.PROCSET, procset); page.put(PdfName.RESOURCES, resources); page.put(PdfName.ROTATE, new PdfNumber(rotation)); page.put(PdfName.MEDIABOX, new PdfRectangle(media, rotation)); PRIndirectReference pref = reader.addPdfObject(page); PdfDictionary parent; PRIndirectReference parentRef; if (pageNumber > reader.getNumberOfPages()) { PdfDictionary lastPage = reader.getPageNRelease(reader.getNumberOfPages()); parentRef = (PRIndirectReference)lastPage.get(PdfName.PARENT); parentRef = new PRIndirectReference(reader, parentRef.getNumber()); parent = (PdfDictionary)PdfReader.getPdfObject(parentRef); PdfArray kids = (PdfArray)PdfReader.getPdfObject(parent.get(PdfName.KIDS), parent); kids.add(pref); markUsed(kids); reader.pageRefs.insertPage(pageNumber, pref); } else { if (pageNumber < 1) pageNumber = 1; PdfDictionary firstPage = reader.getPageN(pageNumber); PRIndirectReference firstPageRef = reader.getPageOrigRef(pageNumber); reader.releasePage(pageNumber); parentRef = (PRIndirectReference)firstPage.get(PdfName.PARENT); parentRef = new PRIndirectReference(reader, parentRef.getNumber()); parent = (PdfDictionary)PdfReader.getPdfObject(parentRef); PdfArray kids = (PdfArray)PdfReader.getPdfObject(parent.get(PdfName.KIDS), parent); ArrayList ar = kids.getArrayList(); int len = ar.size(); int num = firstPageRef.getNumber(); for (int k = 0; k < len; ++k) { PRIndirectReference cur = (PRIndirectReference)ar.get(k); if (num == cur.getNumber()) { ar.add(k, pref); break; } } if (len == ar.size()) throw new RuntimeException("Internal inconsistence."); markUsed(kids); reader.pageRefs.insertPage(pageNumber, pref); correctAcroFieldPages(pageNumber); } page.put(PdfName.PARENT, parentRef); while (parent != null) { markUsed(parent); PdfNumber count = (PdfNumber)PdfReader.getPdfObjectRelease(parent.get(PdfName.COUNT)); parent.put(PdfName.COUNT, new PdfNumber(count.intValue() + 1)); parent = (PdfDictionary)PdfReader.getPdfObject(parent.get(PdfName.PARENT)); } } /** Getter for property rotateContents. * @return Value of property rotateContents. * */ boolean isRotateContents() { return this.rotateContents; } /** Setter for property rotateContents. * @param rotateContents New value of property rotateContents. * */ void setRotateContents(boolean rotateContents) { this.rotateContents = rotateContents; } boolean isContentWritten() { return body.size() > 1; } AcroFields getAcroFields() { if (acroFields == null) { acroFields = new AcroFields(reader, this); } return acroFields; } void setFormFlattening(boolean flat) { this.flat = flat; } void setFreeTextFlattening(boolean flat) { this.flatFreeText = flat; } boolean partialFormFlattening(String name) { getAcroFields(); if (acroFields.getXfa().isXfaPresent()) throw new UnsupportedOperationException("Partial form flattening is not supported with XFA forms."); if (!acroFields.getFields().containsKey(name)) return false; partialFlattening.add(name); return true; } void flatFields() { if (append) throw new IllegalArgumentException("Field flattening is not supported in append mode."); getAcroFields(); HashMap fields = acroFields.getFields(); if (fieldsAdded && partialFlattening.isEmpty()) { for (Iterator i = fields.keySet().iterator(); i.hasNext();) { partialFlattening.add(i.next()); } } PdfDictionary acroForm = (PdfDictionary)PdfReader.getPdfObject(reader.getCatalog().get(PdfName.ACROFORM)); ArrayList acroFds = null; if (acroForm != null) { PdfArray array = (PdfArray)PdfReader.getPdfObject(acroForm.get(PdfName.FIELDS), acroForm); if (array != null) acroFds = array.getArrayList(); } for (Iterator i = fields.entrySet().iterator(); i.hasNext();) { Map.Entry entry = (Map.Entry) i.next(); String name = (String) entry.getKey(); if (!partialFlattening.isEmpty() && !partialFlattening.contains(name)) continue; AcroFields.Item item = (AcroFields.Item) entry.getValue(); for (int k = 0; k < item.merged.size(); ++k) { PdfDictionary merged = (PdfDictionary)item.merged.get(k); PdfNumber ff = (PdfNumber)PdfReader.getPdfObject(merged.get(PdfName.F)); int flags = 0; if (ff != null) flags = ff.intValue(); int page = ((Integer)item.page.get(k)).intValue(); PdfDictionary appDic = (PdfDictionary)PdfReader.getPdfObject(merged.get(PdfName.AP)); if (appDic != null && (flags & PdfFormField.FLAGS_PRINT) != 0 && (flags & PdfFormField.FLAGS_HIDDEN) == 0) { PdfObject obj = appDic.get(PdfName.N); PdfAppearance app = null; if (obj != null) { PdfObject objReal = PdfReader.getPdfObject(obj); if (obj instanceof PdfIndirectReference && !obj.isIndirect()) app = new PdfAppearance((PdfIndirectReference)obj); else if (objReal instanceof PdfStream) { ((PdfDictionary)objReal).put(PdfName.SUBTYPE, PdfName.FORM); app = new PdfAppearance((PdfIndirectReference)obj); } else { if (objReal != null && objReal.isDictionary()) { PdfName as = (PdfName)PdfReader.getPdfObject(merged.get(PdfName.AS)); if (as != null) { PdfIndirectReference iref = (PdfIndirectReference)((PdfDictionary)objReal).get(as); if (iref != null) { app = new PdfAppearance(iref); if (iref.isIndirect()) { objReal = PdfReader.getPdfObject(iref); ((PdfDictionary)objReal).put(PdfName.SUBTYPE, PdfName.FORM); } } } } } } if (app != null) { Rectangle box = PdfReader.getNormalizedRectangle((PdfArray)PdfReader.getPdfObject(merged.get(PdfName.RECT))); PdfContentByte cb = getOverContent(page); cb.setLiteral("Q "); cb.addTemplate(app, box.getLeft(), box.getBottom()); cb.setLiteral("q "); } } if (partialFlattening.isEmpty()) continue; PdfDictionary pageDic = reader.getPageN(page); PdfArray annots = (PdfArray)PdfReader.getPdfObject(pageDic.get(PdfName.ANNOTS)); if (annots == null) continue; ArrayList ar = annots.getArrayList(); for (int idx = 0; idx < ar.size(); ++idx) { PdfObject ran = (PdfObject)ar.get(idx); if (!ran.isIndirect()) continue; PdfObject ran2 = (PdfObject)item.widget_refs.get(k); if (!ran2.isIndirect()) continue; if (((PRIndirectReference)ran).getNumber() == ((PRIndirectReference)ran2).getNumber()) { ar.remove(idx--); PRIndirectReference wdref = (PRIndirectReference)ran2; while (true) { PdfDictionary wd = (PdfDictionary)PdfReader.getPdfObject(wdref); PRIndirectReference parentRef = (PRIndirectReference)wd.get(PdfName.PARENT); PdfReader.killIndirect(wdref); if (parentRef == null) { // reached AcroForm for (int fr = 0; fr < acroFds.size(); ++fr) { PdfObject h = (PdfObject)acroFds.get(fr); if (h.isIndirect() && ((PRIndirectReference)h).getNumber() == wdref.getNumber()) { acroFds.remove(fr); --fr; } } break; } PdfDictionary parent = (PdfDictionary)PdfReader.getPdfObject(parentRef); PdfArray kids = (PdfArray)PdfReader.getPdfObject(parent.get(PdfName.KIDS)); ArrayList kar = kids.getArrayList(); for (int fr = 0; fr < kar.size(); ++fr) { PdfObject h = (PdfObject)kar.get(fr); if (h.isIndirect() && ((PRIndirectReference)h).getNumber() == wdref.getNumber()) { kar.remove(fr); --fr; } } if (!kar.isEmpty()) break; wdref = parentRef; } } } if (ar.isEmpty()) { PdfReader.killIndirect(pageDic.get(PdfName.ANNOTS)); pageDic.remove(PdfName.ANNOTS); } } } if (!fieldsAdded && partialFlattening.isEmpty()) { for (int page = 1; page <= reader.getNumberOfPages(); ++page) { PdfDictionary pageDic = reader.getPageN(page); PdfArray annots = (PdfArray)PdfReader.getPdfObject(pageDic.get(PdfName.ANNOTS)); if (annots == null) continue; ArrayList ar = annots.getArrayList(); for (int idx = 0; idx < ar.size(); ++idx) { PdfObject annoto = PdfReader.getPdfObject((PdfObject)ar.get(idx)); if ((annoto instanceof PdfIndirectReference) && !annoto.isIndirect()) continue; if (!annoto.isDictionary() || PdfName.WIDGET.equals(((PdfDictionary)annoto).get(PdfName.SUBTYPE))) { ar.remove(idx); --idx; } } if (ar.isEmpty()) { PdfReader.killIndirect(pageDic.get(PdfName.ANNOTS)); pageDic.remove(PdfName.ANNOTS); } } eliminateAcroformObjects(); } } void eliminateAcroformObjects() { PdfObject acro = reader.getCatalog().get(PdfName.ACROFORM); if (acro == null) return; PdfDictionary acrodic = (PdfDictionary)PdfReader.getPdfObject(acro); reader.killXref(acrodic.get(PdfName.XFA)); acrodic.remove(PdfName.XFA); PdfObject iFields = acrodic.get(PdfName.FIELDS); if (iFields != null) { PdfDictionary kids = new PdfDictionary(); kids.put(PdfName.KIDS, iFields); sweepKids(kids); PdfReader.killIndirect(iFields); acrodic.put(PdfName.FIELDS, new PdfArray()); } // PdfReader.killIndirect(acro); // reader.getCatalog().remove(PdfName.ACROFORM); } void sweepKids(PdfObject obj) { PdfObject oo = PdfReader.killIndirect(obj); if (oo == null || !oo.isDictionary()) return; PdfDictionary dic = (PdfDictionary)oo; PdfArray kids = (PdfArray)PdfReader.killIndirect(dic.get(PdfName.KIDS)); if (kids == null) return; ArrayList ar = kids.getArrayList(); for (int k = 0; k < ar.size(); ++k) { sweepKids((PdfObject)ar.get(k)); } } private void flatFreeTextFields() { if (append) throw new IllegalArgumentException("FreeText flattening is not supported in append mode."); for (int page = 1; page <= reader.getNumberOfPages(); ++page) { PdfDictionary pageDic = reader.getPageN(page); PdfArray annots = (PdfArray)PdfReader.getPdfObject(pageDic.get(PdfName.ANNOTS)); if (annots == null) continue; ArrayList ar = annots.getArrayList(); for (int idx = 0; idx < ar.size(); ++idx) { PdfObject annoto = PdfReader.getPdfObject((PdfObject)ar.get(idx)); if ((annoto instanceof PdfIndirectReference) && !annoto.isIndirect()) continue; PdfDictionary annDic = (PdfDictionary)annoto; if (!((PdfName)annDic.get(PdfName.SUBTYPE)).equals(PdfName.FREETEXT)) continue; PdfNumber ff = (PdfNumber)PdfReader.getPdfObject(annDic.get(PdfName.F)); int flags = (ff != null) ? ff.intValue() : 0; if ( (flags & PdfFormField.FLAGS_PRINT) != 0 && (flags & PdfFormField.FLAGS_HIDDEN) == 0) { PdfObject obj1 = annDic.get(PdfName.AP); if (obj1 == null) continue; PdfDictionary appDic = (obj1 instanceof PdfIndirectReference) ? (PdfDictionary) PdfReader.getPdfObject(obj1) : (PdfDictionary) obj1; PdfObject obj = appDic.get(PdfName.N); PdfAppearance app = null; PdfObject objReal = PdfReader.getPdfObject(obj); if (obj instanceof PdfIndirectReference && !obj.isIndirect()) app = new PdfAppearance((PdfIndirectReference)obj); else if (objReal instanceof PdfStream) { ((PdfDictionary)objReal).put(PdfName.SUBTYPE, PdfName.FORM); app = new PdfAppearance((PdfIndirectReference)obj); } else { if (objReal.isDictionary()) { PdfName as_p = (PdfName)PdfReader.getPdfObject(appDic.get(PdfName.AS)); if (as_p != null) { PdfIndirectReference iref = (PdfIndirectReference)((PdfDictionary)objReal).get(as_p); if (iref != null) { app = new PdfAppearance(iref); if (iref.isIndirect()) { objReal = PdfReader.getPdfObject(iref); ((PdfDictionary)objReal).put(PdfName.SUBTYPE, PdfName.FORM); } } } } } if (app != null) { Rectangle box = PdfReader.getNormalizedRectangle((PdfArray)PdfReader.getPdfObject(annDic.get(PdfName.RECT))); PdfContentByte cb = getOverContent(page); cb.setLiteral("Q "); cb.addTemplate(app, box.getLeft(), box.getBottom()); cb.setLiteral("q "); } } } for (int idx = 0; idx < ar.size(); ++idx) { PdfObject annoto = PdfReader.getPdfObject((PdfObject)ar.get(idx)); if (annoto != null && annoto.isDictionary()) { PdfDictionary annot = (PdfDictionary)annoto; if (PdfName.FREETEXT.equals(annot.get(PdfName.SUBTYPE))) { ar.remove(idx); --idx; } } } if (ar.isEmpty()) { PdfReader.killIndirect(pageDic.get(PdfName.ANNOTS)); pageDic.remove(PdfName.ANNOTS); } } } /** * @see com.lowagie.text.pdf.PdfWriter#getPageReference(int) */ public PdfIndirectReference getPageReference(int page) { PdfIndirectReference ref = reader.getPageOrigRef(page); if (ref == null) throw new IllegalArgumentException("Invalid page number " + page); return ref; } /** * @see com.lowagie.text.pdf.PdfWriter#addAnnotation(com.lowagie.text.pdf.PdfAnnotation) */ public void addAnnotation(PdfAnnotation annot) { throw new RuntimeException("Unsupported in this context. Use PdfStamper.addAnnotation()"); } void addDocumentField(PdfIndirectReference ref) { PdfDictionary catalog = reader.getCatalog(); PdfDictionary acroForm = (PdfDictionary)PdfReader.getPdfObject(catalog.get(PdfName.ACROFORM), catalog); if (acroForm == null) { acroForm = new PdfDictionary(); catalog.put(PdfName.ACROFORM, acroForm); markUsed(catalog); } PdfArray fields = (PdfArray)PdfReader.getPdfObject(acroForm.get(PdfName.FIELDS), acroForm); if (fields == null) { fields = new PdfArray(); acroForm.put(PdfName.FIELDS, fields); markUsed(acroForm); } if (!acroForm.contains(PdfName.DA)) { acroForm.put(PdfName.DA, new PdfString("/Helv 0 Tf 0 g ")); markUsed(acroForm); } fields.add(ref); markUsed(fields); } void addFieldResources() throws IOException { if (fieldTemplates.isEmpty()) return; PdfDictionary catalog = reader.getCatalog(); PdfDictionary acroForm = (PdfDictionary)PdfReader.getPdfObject(catalog.get(PdfName.ACROFORM), catalog); if (acroForm == null) { acroForm = new PdfDictionary(); catalog.put(PdfName.ACROFORM, acroForm); markUsed(catalog); } PdfDictionary dr = (PdfDictionary)PdfReader.getPdfObject(acroForm.get(PdfName.DR), acroForm); if (dr == null) { dr = new PdfDictionary(); acroForm.put(PdfName.DR, dr); markUsed(acroForm); } markUsed(dr); for (Iterator it = fieldTemplates.keySet().iterator(); it.hasNext();) { PdfTemplate template = (PdfTemplate)it.next(); PdfFormField.mergeResources(dr, (PdfDictionary)template.getResources(), this); } if (dr.get(PdfName.ENCODING) == null) dr.put(PdfName.ENCODING, PdfName.WIN_ANSI_ENCODING); PdfDictionary fonts = (PdfDictionary)PdfReader.getPdfObject(dr.get(PdfName.FONT)); if (fonts == null) { fonts = new PdfDictionary(); dr.put(PdfName.FONT, fonts); } if (!fonts.contains(PdfName.HELV)) { PdfDictionary dic = new PdfDictionary(PdfName.FONT); dic.put(PdfName.BASEFONT, PdfName.HELVETICA); dic.put(PdfName.ENCODING, PdfName.WIN_ANSI_ENCODING); dic.put(PdfName.NAME, PdfName.HELV); dic.put(PdfName.SUBTYPE, PdfName.TYPE1); fonts.put(PdfName.HELV, addToBody(dic).getIndirectReference()); } if (!fonts.contains(PdfName.ZADB)) { PdfDictionary dic = new PdfDictionary(PdfName.FONT); dic.put(PdfName.BASEFONT, PdfName.ZAPFDINGBATS); dic.put(PdfName.NAME, PdfName.ZADB); dic.put(PdfName.SUBTYPE, PdfName.TYPE1); fonts.put(PdfName.ZADB, addToBody(dic).getIndirectReference()); } if (acroForm.get(PdfName.DA) == null) { acroForm.put(PdfName.DA, new PdfString("/Helv 0 Tf 0 g ")); markUsed(acroForm); } } void expandFields(PdfFormField field, ArrayList allAnnots) { allAnnots.add(field); ArrayList kids = field.getKids(); if (kids != null) { for (int k = 0; k < kids.size(); ++k) expandFields((PdfFormField)kids.get(k), allAnnots); } } void addAnnotation(PdfAnnotation annot, PdfDictionary pageN) { try { ArrayList allAnnots = new ArrayList(); if (annot.isForm()) { fieldsAdded = true; getAcroFields(); PdfFormField field = (PdfFormField)annot; if (field.getParent() != null) return; expandFields(field, allAnnots); } else allAnnots.add(annot); for (int k = 0; k < allAnnots.size(); ++k) { annot = (PdfAnnotation)allAnnots.get(k); if (annot.getPlaceInPage() > 0) pageN = reader.getPageN(annot.getPlaceInPage()); if (annot.isForm()) { if (!annot.isUsed()) { HashMap templates = annot.getTemplates(); if (templates != null) fieldTemplates.putAll(templates); } PdfFormField field = (PdfFormField)annot; if (field.getParent() == null) addDocumentField(field.getIndirectReference()); } if (annot.isAnnotation()) { PdfObject pdfobj = PdfReader.getPdfObject(pageN.get(PdfName.ANNOTS), pageN); PdfArray annots = null; if (pdfobj == null || !pdfobj.isArray()) { annots = new PdfArray(); pageN.put(PdfName.ANNOTS, annots); markUsed(pageN); } else annots = (PdfArray)pdfobj; annots.add(annot.getIndirectReference()); markUsed(annots); if (!annot.isUsed()) { PdfRectangle rect = (PdfRectangle)annot.get(PdfName.RECT); if (rect != null && (rect.left() != 0 || rect.right() != 0 || rect.top() != 0 || rect.bottom() != 0)) { int rotation = reader.getPageRotation(pageN); Rectangle pageSize = reader.getPageSizeWithRotation(pageN); switch (rotation) { case 90: annot.put(PdfName.RECT, new PdfRectangle( pageSize.getTop() - rect.bottom(), rect.left(), pageSize.getTop() - rect.top(), rect.right())); break; case 180: annot.put(PdfName.RECT, new PdfRectangle( pageSize.getRight() - rect.left(), pageSize.getTop() - rect.bottom(), pageSize.getRight() - rect.right(), pageSize.getTop() - rect.top())); break; case 270: annot.put(PdfName.RECT, new PdfRectangle( rect.bottom(), pageSize.getRight() - rect.left(), rect.top(), pageSize.getRight() - rect.right())); break; } } } } if (!annot.isUsed()) { annot.setUsed(); addToBody(annot, annot.getIndirectReference()); } } } catch (IOException e) { throw new ExceptionConverter(e); } } void addAnnotation(PdfAnnotation annot, int page) { addAnnotation(annot, reader.getPageN(page)); } private void outlineTravel(PRIndirectReference outline) { while (outline != null) { PdfDictionary outlineR = (PdfDictionary)PdfReader.getPdfObjectRelease(outline); PRIndirectReference first = (PRIndirectReference)outlineR.get(PdfName.FIRST); if (first != null) { outlineTravel(first); } PdfReader.killIndirect(outlineR.get(PdfName.DEST)); PdfReader.killIndirect(outlineR.get(PdfName.A)); PdfReader.killIndirect(outline); outline = (PRIndirectReference)outlineR.get(PdfName.NEXT); } } void deleteOutlines() { PdfDictionary catalog = reader.getCatalog(); PRIndirectReference outlines = (PRIndirectReference)catalog.get(PdfName.OUTLINES); if (outlines == null) return; outlineTravel(outlines); PdfReader.killIndirect(outlines); catalog.remove(PdfName.OUTLINES); markUsed(catalog); } void setJavaScript() throws IOException { HashMap djs = pdf.getDocumentLevelJS(); if (djs.isEmpty()) return; PdfDictionary catalog = reader.getCatalog(); PdfDictionary names = (PdfDictionary)PdfReader.getPdfObject(catalog.get(PdfName.NAMES), catalog); if (names == null) { names = new PdfDictionary(); catalog.put(PdfName.NAMES, names); markUsed(catalog); } markUsed(names); PdfDictionary tree = PdfNameTree.writeTree(djs, this); names.put(PdfName.JAVASCRIPT, addToBody(tree).getIndirectReference()); } void addFileAttachments() throws IOException { HashMap fs = pdf.getDocumentFileAttachment(); if (fs.isEmpty()) return; PdfDictionary catalog = reader.getCatalog(); PdfDictionary names = (PdfDictionary)PdfReader.getPdfObject(catalog.get(PdfName.NAMES), catalog); if (names == null) { names = new PdfDictionary(); catalog.put(PdfName.NAMES, names); markUsed(catalog); } markUsed(names); HashMap old = PdfNameTree.readTree((PdfDictionary)PdfReader.getPdfObjectRelease(names.get(PdfName.EMBEDDEDFILES))); for (Iterator it = fs.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); String name = (String) entry.getKey(); int k = 0; String nn = name; while (old.containsKey(nn)) { ++k; nn += " " + k; } old.put(nn, entry.getValue()); } PdfDictionary tree = PdfNameTree.writeTree(old, this); names.put(PdfName.EMBEDDEDFILES, addToBody(tree).getIndirectReference()); } /** * Adds or replaces the Collection Dictionary in the Catalog. * @param collection the new collection dictionary. */ void makePackage( PdfCollection collection ) { PdfDictionary catalog = reader.getCatalog(); catalog.put( PdfName.COLLECTION, collection ); } void setOutlines() throws IOException { if (newBookmarks == null) return; deleteOutlines(); if (newBookmarks.isEmpty()) return; PdfDictionary catalog = reader.getCatalog(); boolean namedAsNames = (catalog.get(PdfName.DESTS) != null); writeOutlines(catalog, namedAsNames); markUsed(catalog); } /** * Sets the viewer preferences. * @param preferences the viewer preferences * @see PdfWriter#setViewerPreferences(int) */ public void setViewerPreferences(int preferences) { useVp = true; this.viewerPreferences.setViewerPreferences(preferences); } /** Adds a viewer preference * @param key a key for a viewer preference * @param value the value for the viewer preference * @see PdfViewerPreferences#addViewerPreference */ public void addViewerPreference(PdfName key, PdfObject value) { useVp = true; this.viewerPreferences.addViewerPreference(key, value); } /** * Set the signature flags. * @param f the flags. This flags are ORed with current ones */ public void setSigFlags(int f) { sigFlags |= f; } /** Always throws an <code>UnsupportedOperationException</code>. * @param actionType ignore * @param action ignore * @throws PdfException ignore * @see PdfStamper#setPageAction(PdfName, PdfAction, int) */ public void setPageAction(PdfName actionType, PdfAction action) throws PdfException { throw new UnsupportedOperationException("Use setPageAction(PdfName actionType, PdfAction action, int page)"); } /** * Sets the open and close page additional action. * @param actionType the action type. It can be <CODE>PdfWriter.PAGE_OPEN</CODE> * or <CODE>PdfWriter.PAGE_CLOSE</CODE> * @param action the action to perform * @param page the page where the action will be applied. The first page is 1 * @throws PdfException if the action type is invalid */ void setPageAction(PdfName actionType, PdfAction action, int page) throws PdfException { if (!actionType.equals(PAGE_OPEN) && !actionType.equals(PAGE_CLOSE)) throw new PdfException("Invalid page additional action type: " + actionType.toString()); PdfDictionary pg = reader.getPageN(page); PdfDictionary aa = (PdfDictionary)PdfReader.getPdfObject(pg.get(PdfName.AA), pg); if (aa == null) { aa = new PdfDictionary(); pg.put(PdfName.AA, aa); markUsed(pg); } aa.put(actionType, action); markUsed(aa); } /** * Always throws an <code>UnsupportedOperationException</code>. * @param seconds ignore */ public void setDuration(int seconds) { throw new UnsupportedOperationException("Use setPageAction(PdfName actionType, PdfAction action, int page)"); } /** * Always throws an <code>UnsupportedOperationException</code>. * @param transition ignore */ public void setTransition(PdfTransition transition) { throw new UnsupportedOperationException("Use setPageAction(PdfName actionType, PdfAction action, int page)"); } /** * Sets the display duration for the page (for presentations) * @param seconds the number of seconds to display the page. A negative value removes the entry * @param page the page where the duration will be applied. The first page is 1 */ void setDuration(int seconds, int page) { PdfDictionary pg = reader.getPageN(page); if (seconds < 0) pg.remove(PdfName.DUR); else pg.put(PdfName.DUR, new PdfNumber(seconds)); markUsed(pg); } /** * Sets the transition for the page * @param transition the transition object. A <code>null</code> removes the transition * @param page the page where the transition will be applied. The first page is 1 */ void setTransition(PdfTransition transition, int page) { PdfDictionary pg = reader.getPageN(page); if (transition == null) pg.remove(PdfName.TRANS); else pg.put(PdfName.TRANS, transition.getTransitionDictionary()); markUsed(pg); } protected void markUsed(PdfObject obj) { if (append && obj != null) { PRIndirectReference ref = null; if (obj.type() == PdfObject.INDIRECT) ref = (PRIndirectReference)obj; else ref = obj.getIndRef(); if (ref != null) marked.put(ref.getNumber(), 1); } } protected void markUsed(int num) { if (append) marked.put(num, 1); } /** * Getter for property append. * @return Value of property append. */ boolean isAppend() { return append; } /** Additional-actions defining the actions to be taken in * response to various trigger events affecting the document * as a whole. The actions types allowed are: <CODE>DOCUMENT_CLOSE</CODE>, * <CODE>WILL_SAVE</CODE>, <CODE>DID_SAVE</CODE>, <CODE>WILL_PRINT</CODE> * and <CODE>DID_PRINT</CODE>. * * @param actionType the action type * @param action the action to execute in response to the trigger * @throws PdfException on invalid action type */ public void setAdditionalAction(PdfName actionType, PdfAction action) throws PdfException { if (!(actionType.equals(DOCUMENT_CLOSE) || actionType.equals(WILL_SAVE) || actionType.equals(DID_SAVE) || actionType.equals(WILL_PRINT) || actionType.equals(DID_PRINT))) { throw new PdfException("Invalid additional action type: " + actionType.toString()); } PdfDictionary aa = (PdfDictionary)PdfReader.getPdfObject(reader.getCatalog().get(PdfName.AA)); if (aa == null) { if (action == null) return; aa = new PdfDictionary(); reader.getCatalog().put(PdfName.AA, aa); } markUsed(aa); if (action == null) aa.remove(actionType); else aa.put(actionType, action); } /** * @see com.lowagie.text.pdf.PdfWriter#setOpenAction(com.lowagie.text.pdf.PdfAction) */ public void setOpenAction(PdfAction action) { openAction = action; } /** * @see com.lowagie.text.pdf.PdfWriter#setOpenAction(java.lang.String) */ public void setOpenAction(String name) { throw new UnsupportedOperationException("Open actions by name are not supported."); } /** * @see com.lowagie.text.pdf.PdfWriter#setThumbnail(com.lowagie.text.Image) */ public void setThumbnail(com.lowagie.text.Image image) { throw new UnsupportedOperationException("Use PdfStamper.setThumbnail()."); } void setThumbnail(Image image, int page) throws PdfException, DocumentException { PdfIndirectReference thumb = getImageReference(addDirectImageSimple(image)); reader.resetReleasePage(); PdfDictionary dic = reader.getPageN(page); dic.put(PdfName.THUMB, thumb); reader.resetReleasePage(); } public PdfContentByte getDirectContentUnder() { throw new UnsupportedOperationException("Use PdfStamper.getUnderContent() or PdfStamper.getOverContent()"); } public PdfContentByte getDirectContent() { throw new UnsupportedOperationException("Use PdfStamper.getUnderContent() or PdfStamper.getOverContent()"); } /** * Reads the OCProperties dictionary from the catalog of the existing document * and fills the documentOCG, documentOCGorder and OCGRadioGroup variables in PdfWriter. * Note that the original OCProperties of the existing document can contain more information. * @since 2.1.2 */ protected void readOCProperties() { if (!documentOCG.isEmpty()) { return; } PdfDictionary dict = reader.getCatalog().getAsDict(PdfName.OCPROPERTIES); if (dict == null) { return; } PdfArray ocgs = dict.getAsArray(PdfName.OCGS); PdfIndirectReference ref; PdfLayer layer; HashMap ocgmap = new HashMap(); for (Iterator i = ocgs.listIterator(); i.hasNext(); ) { ref = (PdfIndirectReference)i.next(); layer = new PdfLayer(null); layer.setRef(ref); layer.setOnPanel(false); layer.merge((PdfDictionary)PdfReader.getPdfObject(ref)); ocgmap.put(ref.toString(), layer); } PdfDictionary d = dict.getAsDict(PdfName.D); PdfArray off = d.getAsArray(PdfName.OFF); if (off != null) { for (Iterator i = off.listIterator(); i.hasNext(); ) { ref = (PdfIndirectReference)i.next(); layer = (PdfLayer)ocgmap.get(ref.toString()); layer.setOn(false); } } PdfArray order = d.getAsArray(PdfName.ORDER); if (order != null) { addOrder(null, order, ocgmap); } documentOCG.addAll(ocgmap.values()); OCGRadioGroup = d.getAsArray(PdfName.RBGROUPS); OCGLocked = d.getAsArray(PdfName.LOCKED); } /** * Recursive method to reconstruct the documentOCGorder variable in the writer. * @param parent a parent PdfLayer (can be null) * @param arr an array possibly containing children for the parent PdfLayer * @param ocgmap a HashMap with indirect reference Strings as keys and PdfLayer objects as values. * @since 2.1.2 */ private void addOrder(PdfLayer parent, PdfArray arr, Map ocgmap) { PdfObject obj; PdfLayer layer; for (int i = 0; i < arr.size(); i++) { obj = arr.getPdfObject(i); if (obj.isIndirect()) { layer = (PdfLayer)ocgmap.get(obj.toString()); layer.setOnPanel(true); registerLayer(layer); if (parent != null) { parent.addChild(layer); } if (arr.size() > i + 1 && arr.getPdfObject(i + 1).isArray()) { i++; addOrder(layer, (PdfArray)arr.getPdfObject(i), ocgmap); } } else if (obj.isArray()) { ArrayList sub = ((PdfArray)obj).getArrayList(); if (sub.isEmpty()) return; obj = (PdfObject)sub.get(0); if (obj.isString()) { layer = new PdfLayer(sub.get(0).toString()); layer.setOnPanel(true); registerLayer(layer); if (parent != null) { parent.addChild(layer); } PdfArray array = new PdfArray(); for (Iterator j = sub.iterator(); j.hasNext(); ) { array.add((PdfObject)j.next()); } addOrder(layer, array, ocgmap); } else { addOrder(parent, (PdfArray)obj, ocgmap); } } } } /** * Gets the PdfLayer objects in an existing document as a Map * with the names/titles of the layers as keys. * @return a Map with all the PdfLayers in the document (and the name/title of the layer as key) * @since 2.1.2 */ public Map getPdfLayers() { if (documentOCG.isEmpty()) { readOCProperties(); } HashMap map = new HashMap(); PdfLayer layer; String key; for (Iterator i = documentOCG.iterator(); i.hasNext(); ) { layer = (PdfLayer)i.next(); if (layer.getTitle() == null) { key = layer.getAsString(PdfName.NAME).toString(); } else { key = layer.getTitle(); } if (map.containsKey(key)) { int seq = 2; String tmp = key + "(" + seq + ")"; while (map.containsKey(tmp)) { seq++; tmp = key + "(" + seq + ")"; } key = tmp; } map.put(key, layer); } return map; } static class PageStamp { PdfDictionary pageN; StampContent under; StampContent over; PageResources pageResources; int replacePoint = 0; PageStamp(PdfStamperImp stamper, PdfReader reader, PdfDictionary pageN) { this.pageN = pageN; pageResources = new PageResources(); PdfDictionary resources = (PdfDictionary)PdfReader.getPdfObject(pageN.get(PdfName.RESOURCES)); pageResources.setOriginalResources(resources, stamper.namePtr); } } }

The table below shows all metrics for PdfStamperImp.java.

MetricValueDescription
BLOCKS236.00Number of blocks
BLOCK_COMMENT46.00Number of block comment lines
COMMENTS180.00Comment lines
COMMENT_DENSITY 0.16Comment density
COMPARISONS281.00Number of comparison operators
CYCLOMATIC358.00Cyclomatic complexity
DECL_COMMENTS29.00Comments in declarations
DOC_COMMENT129.00Number of javadoc comment lines
ELOC1143.00Effective lines of code
EXEC_COMMENTS 5.00Comments in executable code
EXITS227.00Procedure exits
FUNCTIONS65.00Number of function declarations
HALSTEAD_DIFFICULTY142.53Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY240.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 1.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 3.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034100.00JAVA0034 Missing braces in if statement
JAVA0035 1.00JAVA0035 Missing braces in for statement
JAVA0036 1.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 5.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
JAVA0067 4.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 4.00JAVA0075 Method parameter hides field
JAVA0076 6.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 4.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 0.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 1.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 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 0.00JAVA0114 Incorrect javadoc: no @version tag
JAVA0115 0.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 0.00JAVA0116 Missing javadoc: field 'field'
JAVA0117 2.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 6.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 1.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 0.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 2.00JAVA0144 Line exceeds maximum M characters
JAVA0145723.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 1.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 2.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 1.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 9.00JAVA0177 Variable declaration missing initializer
JAVA0179 2.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
JAVA025413.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.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 0.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 2.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
JAVA0285 3.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
LINES1651.00Number of lines in the source file
LINE_COMMENT 5.00Number of line comments
LOC1397.00Lines of code
LOGICAL_LINES841.00Number of statements
LOOPS41.00Number of loops
NEST_DEPTH10.00Maximum nesting depth
OPERANDS4018.00Number of operands
OPERATORS7173.00Number of operators
PARAMS79.00Number of formal parameter declarations
PROGRAM_LENGTH11191.00Halstead program length
PROGRAM_VOCAB951.00Halstead program vocabulary
PROGRAM_VOLUME 0.00Halstead program volume
RETURNS161.00Number of return points from functions
SIZE66856.00Size of the file in bytes
UNIQUE_OPERANDS888.00Number of unique operands
UNIQUE_OPERATORS63.00Number of unique operators
WHITESPACE74.00Number of whitespace lines