diff --git a/.gitignore b/.gitignore index 3bd75a1e4..69b49890a 100644 --- a/.gitignore +++ b/.gitignore @@ -179,3 +179,5 @@ buildNumber.properties ### Custom *.rtf *.html + +*.pdf diff --git a/README.md b/README.md index 687580ba5..e5781dbea 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,8 @@ OpenPDF is a Java library for creating and editing PDF files with a LGPL and MPL [![Build Status](https://travis-ci.org/LibrePDF/OpenPDF.svg?branch=master)](https://travis-ci.org/LibrePDF/OpenPDF) [![Join the chat at https://gitter.im/LibrePDF/OpenPDF](https://badges.gitter.im/LibrePDF/OpenPDF.svg)](https://gitter.im/LibrePDF/OpenPDF) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.github.librepdf/openpdf/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.github.librepdf/openpdf) [![License (LGPL version 3.0)](https://img.shields.io/badge/license-GNU%20LGPL%20version%203.0-blue.svg?style=flat-square)](http://opensource.org/licenses/LGPL-3.0) [![License (MPL)](https://img.shields.io/badge/license-Mozilla%20Public%20License-yellow.svg?style=flat-square)](http://opensource.org/licenses/MPL-2.0) -## OpenPDF version 1.2.20 released 2019-06-13 ## -Get version 1.2.20 here - https://github.com/LibrePDF/OpenPDF/releases/tag/1.2.20 +## OpenPDF version 1.2.21 released 2019-06-24 ## +Get version 1.2.21 here - https://github.com/LibrePDF/OpenPDF/releases/tag/1.2.21 - [Previous releases](https://github.com/LibrePDF/OpenPDF/releases) @@ -16,7 +16,7 @@ Add this to your pom.xml file to use the latest version of OpenPDF: com.github.librepdf openpdf - 1.2.20 + 1.2.21 ## License ## @@ -93,7 +93,8 @@ Significant [Contributors to OpenPDF](https://github.com/LibrePDF/OpenPDF/graphs [@MartinKocour](https://github.com/MartinKocour) [@jokimaki](https://github.com/jokimaki) [@sullis](https://github.com/sullis) - [@lapo-luchini](https://github.com/lapo-luchini) - [@jeffrey-easyesi](https://github.com/jeffrey-easyesi) + [@lapo-luchini](https://github.com/lapo-luchini) + [@jeffrey-easyesi](https://github.com/jeffrey-easyesi) + [@V-F](https://github.com/V-F) Also, a very special thanks to the iText developers ;) diff --git a/openpdf/pom.xml b/openpdf/pom.xml index bb66eedde..895a808ec 100644 --- a/openpdf/pom.xml +++ b/openpdf/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 1.2.21-SNAPSHOT + 1.3.0-SNAPSHOT openpdf diff --git a/openpdf/src/main/java/com/lowagie/bouncycastle/BouncyCastleHelper.java b/openpdf/src/main/java/com/lowagie/bouncycastle/BouncyCastleHelper.java index 4b13e5da0..b87a747e9 100644 --- a/openpdf/src/main/java/com/lowagie/bouncycastle/BouncyCastleHelper.java +++ b/openpdf/src/main/java/com/lowagie/bouncycastle/BouncyCastleHelper.java @@ -22,13 +22,14 @@ public class BouncyCastleHelper { public static void checkCertificateEncodingOrThrowException(Certificate certificate) { // OJO... try { - X509CertificateHolder certificateHolder = new X509CertificateHolder(certificate.getEncoded()); + new X509CertificateHolder(certificate.getEncoded()); } catch (CertificateEncodingException | IOException f) { throw new ExceptionConverter(f); } // ****************************************************************************** } + @SuppressWarnings("unchecked") public static byte[] getEnvelopedData(PdfArray recipients, List strings, Certificate certificate, Key certificateKey, String certificateKeyProvider) { byte[] envelopedData = null; for (PdfObject recipient : recipients.getElements()) { diff --git a/openpdf/src/main/java/com/lowagie/text/Anchor.java b/openpdf/src/main/java/com/lowagie/text/Anchor.java index 0f9eab26b..dc64c4e39 100644 --- a/openpdf/src/main/java/com/lowagie/text/Anchor.java +++ b/openpdf/src/main/java/com/lowagie/text/Anchor.java @@ -218,14 +218,14 @@ public boolean process(ElementListener listener) { * * @return an ArrayList */ - public ArrayList getChunks() { - ArrayList tmp = new ArrayList<>(); + public java.util.List getChunks() { + java.util.List tmp = new ArrayList<>(); Chunk chunk; - Iterator i = iterator(); + Iterator i = iterator(); boolean localDestination = (reference != null && reference.startsWith("#")); boolean notGotoOK = true; while (i.hasNext()) { - chunk = i.next(); + chunk = (Chunk) i.next(); if (name != null && notGotoOK && !chunk.isEmpty()) { chunk.setLocalDestination(name); notGotoOK = false; diff --git a/openpdf/src/main/java/com/lowagie/text/Cell.java b/openpdf/src/main/java/com/lowagie/text/Cell.java index bb8b464fb..4f7fcee8d 100644 --- a/openpdf/src/main/java/com/lowagie/text/Cell.java +++ b/openpdf/src/main/java/com/lowagie/text/Cell.java @@ -95,7 +95,7 @@ * @see Row */ -public class Cell extends Rectangle implements TextElementArray, WithHorizontalAlignment, WithVerticalAlignment { +public class Cell extends TableRectangle implements TextElementArray, WithHorizontalAlignment, WithVerticalAlignment { // membervariables @@ -103,7 +103,7 @@ public class Cell extends Rectangle implements TextElementArray, WithHorizontalA * The ArrayList of Elements * that are part of the content of the Cell. */ - protected ArrayList arrayList = null; + protected java.util.List arrayList = null; /** The horizontal alignment of the cell content. */ protected int horizontalAlignment = Element.ALIGN_UNDEFINED; @@ -178,7 +178,7 @@ public Cell() { setBorder(UNDEFINED); setBorderWidth(0.5f); // initializes the arraylist - arrayList = new ArrayList(); + arrayList = new ArrayList<>(); } /** @@ -253,10 +253,10 @@ public int type() { * * @return an ArrayList */ - public ArrayList getChunks() { - ArrayList tmp = new ArrayList(); - for (Object o : arrayList) { - tmp.addAll(((Element) o).getChunks()); + public java.util.List getChunks() { + java.util.List tmp = new ArrayList<>(); + for (Element o : arrayList) { + tmp.addAll(o.getChunks()); } return tmp; } @@ -572,7 +572,7 @@ public boolean isEmpty() { case 0: return true; case 1: - Element element = (Element) arrayList.get(0); + Element element = arrayList.get(0); switch (element.type()) { case Element.CHUNK: return ((Chunk) element).isEmpty(); @@ -605,7 +605,7 @@ void fill() { */ public boolean isTable() { return (size() == 1) - && (((Element)arrayList.get(0)).type() == Element.TABLE); + && (arrayList.get(0).type() == Element.TABLE); } /** @@ -679,7 +679,7 @@ public void addElement(Element element) throws BadElementException { tmp = new Cell(); tmp.setBorder(NO_BORDER); tmp.setColspan(3); - for (Object o : arrayList) { + for (Element o : arrayList) { tmp.add(o); } table.addCell(tmp); @@ -706,9 +706,9 @@ public void addElement(Element element) throws BadElementException { * @param o the object to add * @return always true */ - public boolean add(Object o) { + public boolean add(Element o) { try { - this.addElement((Element) o); + this.addElement(o); return true; } catch(ClassCastException cce) { diff --git a/openpdf/src/main/java/com/lowagie/text/DocWriter.java b/openpdf/src/main/java/com/lowagie/text/DocWriter.java index 16a5bb72b..655535193 100644 --- a/openpdf/src/main/java/com/lowagie/text/DocWriter.java +++ b/openpdf/src/main/java/com/lowagie/text/DocWriter.java @@ -281,6 +281,9 @@ public void setPageCount(int pageN) { */ public void close() { + if (!open) { + return; + } open = false; try { os.flush(); diff --git a/openpdf/src/main/java/com/lowagie/text/Element.java b/openpdf/src/main/java/com/lowagie/text/Element.java index 045dab735..4eefa1731 100644 --- a/openpdf/src/main/java/com/lowagie/text/Element.java +++ b/openpdf/src/main/java/com/lowagie/text/Element.java @@ -49,8 +49,6 @@ package com.lowagie.text; -import java.util.ArrayList; - /** * Interface for a text element. *

@@ -346,7 +344,7 @@ public interface Element { * @return an ArrayList */ - ArrayList getChunks(); + java.util.List getChunks(); /** * Gets the content of the text element. diff --git a/openpdf/src/main/java/com/lowagie/text/List.java b/openpdf/src/main/java/com/lowagie/text/List.java index 469ed46f5..224681f55 100644 --- a/openpdf/src/main/java/com/lowagie/text/List.java +++ b/openpdf/src/main/java/com/lowagie/text/List.java @@ -118,7 +118,7 @@ public class List implements TextElementArray { // member variables /** This is the ArrayList containing the different ListItems. */ - protected ArrayList list = new ArrayList(); + protected java.util.List list = new ArrayList<>(); /** Indicates if the list has to be numbered. */ protected boolean numbered = false; @@ -250,10 +250,10 @@ public int type() { * * @return an ArrayList */ - public ArrayList getChunks() { - ArrayList tmp = new ArrayList(); - for (Object o : list) { - tmp.addAll(((Element) o).getChunks()); + public java.util.List getChunks() { + java.util.List tmp = new ArrayList<>(); + for (Element o : list) { + tmp.addAll(o.getChunks()); } return tmp; } @@ -266,7 +266,7 @@ public ArrayList getChunks() { * @param o the object to add. * @return true if adding the object succeeded */ - public boolean add(Object o) { + public boolean add(Element o) { if (o instanceof ListItem) { ListItem item = (ListItem) o; if (numbered || lettered) { @@ -286,19 +286,20 @@ public boolean add(Object o) { item.setIndentationRight(0); return list.add(item); } - else if (o instanceof List) { - List nested = (List) o; - nested.setIndentationLeft(nested.getIndentationLeft() + symbolIndent); - first--; - return list.add(nested); - } - else if (o instanceof String) { - return this.add(new ListItem((String) o)); - } return false; } - - // extra methods + + public boolean add(List nested) { + nested.setIndentationLeft(nested.getIndentationLeft() + symbolIndent); + first--; + return list.add(nested); + } + + public boolean add(String o) { + return this.add(new ListItem(o)); + } + + // extra methods /** Makes sure all the items in the list have the same indentation. */ public void normalizeIndentation() { @@ -415,7 +416,7 @@ public void setSymbolIndent(float symbolIndent) { * * @return an ArrayList containing ListItems. */ - public ArrayList getItems() { + public java.util.List getItems() { return list; } diff --git a/openpdf/src/main/java/com/lowagie/text/MarkedObject.java b/openpdf/src/main/java/com/lowagie/text/MarkedObject.java index a32aaaedb..96fba6f54 100644 --- a/openpdf/src/main/java/com/lowagie/text/MarkedObject.java +++ b/openpdf/src/main/java/com/lowagie/text/MarkedObject.java @@ -49,7 +49,6 @@ package com.lowagie.text; -import java.util.ArrayList; import java.util.Properties; /** @@ -87,7 +86,7 @@ public MarkedObject(Element element) { * * @return an ArrayList */ - public ArrayList getChunks() { + public java.util.List getChunks() { return element.getChunks(); } diff --git a/openpdf/src/main/java/com/lowagie/text/MarkedSection.java b/openpdf/src/main/java/com/lowagie/text/MarkedSection.java index ec3089ea3..f2c94710a 100644 --- a/openpdf/src/main/java/com/lowagie/text/MarkedSection.java +++ b/openpdf/src/main/java/com/lowagie/text/MarkedSection.java @@ -85,7 +85,7 @@ public MarkedSection(Section section) { * @param o an object of type Paragraph, List or Table= * @throws ClassCastException if the object is not a Paragraph, List or Table */ - public void add(int index, Object o) { + public void add(int index, Element o) { ((Section)element).add(index, o); } @@ -97,7 +97,7 @@ public void add(int index, Object o) { * @return a boolean * @throws ClassCastException if the object is not a Paragraph, List, Table or Section */ - public boolean add(Object o) { + public boolean add(Element o) { return ((Section)element).add(o); } @@ -130,7 +130,7 @@ public boolean process(ElementListener listener) { * @return true if the action succeeded, false if not. * @throws ClassCastException if one of the objects isn't a Paragraph, List, Table */ - public boolean addAll(Collection collection) { + public boolean addAll(Collection collection) { return ((Section)element).addAll(collection); } diff --git a/openpdf/src/main/java/com/lowagie/text/Paragraph.java b/openpdf/src/main/java/com/lowagie/text/Paragraph.java index 9db8df911..35a27cba2 100644 --- a/openpdf/src/main/java/com/lowagie/text/Paragraph.java +++ b/openpdf/src/main/java/com/lowagie/text/Paragraph.java @@ -224,7 +224,7 @@ public int type() { * @param o object the object to add. * @return true is adding the object succeeded */ - public boolean add(Object o) { + public boolean add(Element o) { if (o instanceof List) { List list = (List) o; list.setIndentationLeft(list.getIndentationLeft() + indentationLeft); diff --git a/openpdf/src/main/java/com/lowagie/text/Phrase.java b/openpdf/src/main/java/com/lowagie/text/Phrase.java index a9dfdac80..ec0517ca1 100644 --- a/openpdf/src/main/java/com/lowagie/text/Phrase.java +++ b/openpdf/src/main/java/com/lowagie/text/Phrase.java @@ -83,7 +83,7 @@ * @see Anchor */ -public class Phrase extends ArrayList implements TextElementArray { +public class Phrase extends java.util.ArrayList implements TextElementArray { // constants private static final long serialVersionUID = 2643594602455068231L; @@ -236,10 +236,10 @@ public int type() { * * @return an ArrayList */ - public ArrayList getChunks() { - ArrayList tmp = new ArrayList(); - for (Object o : this) { - tmp.addAll(((Element) o).getChunks()); + public java.util.List getChunks() { + java.util.List tmp = new ArrayList<>(); + for (Element element : this) { + tmp.addAll(element.getChunks()); } return tmp; } @@ -267,13 +267,12 @@ public boolean isNestable() { * to this Phrase. * * @param index index at which the specified element is to be inserted - * @param o an object of type Chunk, Anchor or Phrase + * @param element an object of type Chunk, Anchor or Phrase * @throws ClassCastException when you try to add something that isn't a Chunk, Anchor or Phrase */ - public void add(int index, Object o) { - if (o == null) return; + public void add(int index, Element element) { + if (element == null) return; try { - Element element = (Element) o; if (element.type() == Element.CHUNK) { Chunk chunk = (Chunk) element; if (!font.isStandardFont()) { @@ -309,22 +308,22 @@ else if (element.type() == Element.PHRASE || * @return a boolean * @throws ClassCastException when you try to add something that isn't a Chunk, Anchor or Phrase */ - public boolean add(Object o) { + public boolean add(String o) { if (o == null) return false; - if (o instanceof String) { - return super.add(new Chunk((String) o, font)); - } - if (o instanceof RtfElementInterface) { - return super.add(o); + return super.add(new Chunk(o, font)); + } + public boolean add(Element element) { + if (element == null) return false; + if (element instanceof RtfElementInterface) { + return super.add(element); } try { - Element element = (Element) o; switch(element.type()) { case Element.CHUNK: - return addChunk((Chunk) o); + return addChunk((Chunk) element); case Element.PHRASE: case Element.PARAGRAPH: - Phrase phrase = (Phrase) o; + Phrase phrase = (Phrase) element; boolean success = true; Element e; for (Object o1 : phrase) { @@ -345,7 +344,7 @@ public boolean add(Object o) { // This will only work for PDF!!! Not for RTF/HTML case Element.LIST: case Element.YMARK: - return super.add(o); + return super.add(element); default: throw new ClassCastException(String.valueOf(element.type())); } @@ -363,8 +362,8 @@ public boolean add(Object o) { * @return true if the action succeeded, false if not. * @throws ClassCastException when you try to add something that isn't a Chunk, Anchor or Phrase */ - public boolean addAll(Collection collection) { - for (Object o : collection) { + public boolean addAll(Collection collection) { + for (Element o : collection) { this.add(o); } return true; @@ -413,7 +412,7 @@ protected boolean addChunk(Chunk chunk) { * @param object the object to add. */ protected void addSpecial(Object object) { - super.add(object); + super.add((Element) object); } // other methods that change the member variables @@ -491,7 +490,7 @@ public boolean isEmpty() { case 0: return true; case 1: - Element element = (Element) get(0); + Element element = get(0); return element.type() == Element.CHUNK && ((Chunk) element).isEmpty(); default: return false; diff --git a/openpdf/src/main/java/com/lowagie/text/Rectangle.java b/openpdf/src/main/java/com/lowagie/text/Rectangle.java index 2c209d8c4..d9baa9426 100644 --- a/openpdf/src/main/java/com/lowagie/text/Rectangle.java +++ b/openpdf/src/main/java/com/lowagie/text/Rectangle.java @@ -283,8 +283,8 @@ public int type() { * @return an ArrayList */ @Override - public ArrayList getChunks() { - return new ArrayList(); + public java.util.List getChunks() { + return new ArrayList<>(); } /** diff --git a/openpdf/src/main/java/com/lowagie/text/Row.java b/openpdf/src/main/java/com/lowagie/text/Row.java index c7e42dad1..93e1f9f0d 100644 --- a/openpdf/src/main/java/com/lowagie/text/Row.java +++ b/openpdf/src/main/java/com/lowagie/text/Row.java @@ -95,7 +95,7 @@ public class Row implements Element, WithHorizontalAlignment { protected boolean[] reserved; /** This is the array of Objects (Cell or Table). */ - protected Object[] cells; + protected TableRectangle[] cells; /** This is the vertical alignment. */ protected int horizontalAlignment; @@ -110,7 +110,7 @@ public class Row implements Element, WithHorizontalAlignment { protected Row(int columns) { this.columns = columns; reserved = new boolean[columns]; - cells = new Object[columns]; + cells = new TableRectangle[columns]; currentColumn = 0; } @@ -146,8 +146,8 @@ public int type() { * * @return an ArrayList */ - public ArrayList getChunks() { - return new ArrayList(); + public java.util.List getChunks() { + return new ArrayList<>(); } /** @@ -180,7 +180,7 @@ void deleteColumn(int column) { } columns--; boolean[] newReserved = new boolean[columns]; - Object[] newCells = new Cell[columns]; + TableRectangle[] newCells = new Cell[columns]; for (int i = 0; i < column; i++) { newReserved[i] = reserved[i]; @@ -210,7 +210,7 @@ void deleteColumn(int column) { * @return the column position the Cell was added, * or -1 if the element couldn't be added. */ - int addElement(Object element) { + int addElement(TableRectangle element) { return addElement(element, currentColumn); } @@ -222,7 +222,7 @@ int addElement(Object element) { * @return the column position the Cell was added, * or -1 if the Cell couldn't be added. */ - int addElement(Object element, int column) { + int addElement(TableRectangle element, int column) { if (element == null) throw new NullPointerException(MessageLocalization.getComposedMessage("addcell.null.argument")); if ((column < 0) || (column > columns)) throw new IndexOutOfBoundsException(MessageLocalization.getComposedMessage("addcell.illegal.column.argument")); if ( !((getObjectID(element) == CELL) || (getObjectID(element) == TABLE)) ) throw new IllegalArgumentException(MessageLocalization.getComposedMessage("addcell.only.cells.or.tables.allowed")); @@ -245,7 +245,7 @@ int addElement(Object element, int column) { * @param aElement the cell to add. * @param column the position where to add the cell. */ - void setElement(Object aElement, int column) { + void setElement(TableRectangle aElement, int column) { if (reserved[column]) throw new IllegalArgumentException(MessageLocalization.getComposedMessage("setelement.position.already.taken")); cells[column] = aElement; @@ -335,7 +335,7 @@ int getObjectID(Object element) { * @return the Cell,Table or Object if the column was * reserved or null if empty. */ - public Object getCell(int column) { + public TableRectangle getCell(int column) { if ((column < 0) || (column > columns)) { throw new IndexOutOfBoundsException(MessageLocalization.getComposedMessage("getcell.at.illegal.index.1.max.is.2", String.valueOf(column), String.valueOf(columns))); } diff --git a/openpdf/src/main/java/com/lowagie/text/Section.java b/openpdf/src/main/java/com/lowagie/text/Section.java index 69e664b97..25272f413 100644 --- a/openpdf/src/main/java/com/lowagie/text/Section.java +++ b/openpdf/src/main/java/com/lowagie/text/Section.java @@ -81,7 +81,7 @@ * */ -public class Section extends ArrayList implements TextElementArray, LargeElement { +public class Section extends java.util.ArrayList implements TextElementArray, LargeElement { // constant /** * A possible number style. The default number style: "1.2.3." @@ -133,7 +133,7 @@ public class Section extends ArrayList implements TextElementArray, LargeElement protected int subsections = 0; /** This is the complete list of sectionnumbers of this section and the parents of this section. */ - protected ArrayList numbers = null; + protected java.util.List numbers = null; /** * Indicates if the Section will be complete once added to the document. @@ -231,10 +231,10 @@ public boolean isSection() { * * @return an ArrayList */ - public ArrayList getChunks() { - ArrayList tmp = new ArrayList(); - for (Object o : this) { - tmp.addAll(((Element) o).getChunks()); + public java.util.List getChunks() { + java.util.List tmp = new ArrayList<>(); + for (Element o : this) { + tmp.addAll(o.getChunks()); } return tmp; } @@ -265,12 +265,12 @@ public boolean isNestable() { * @param o an object of type Paragraph, List or Table= * @throws ClassCastException if the object is not a Paragraph, List or Table */ - public void add(int index, Object o) { + public void add(int index, Element o) { if (isAddedCompletely()) { throw new IllegalStateException(MessageLocalization.getComposedMessage("this.largeelement.has.already.been.added.to.the.document")); } try { - Element element = (Element) o; + Element element = o; if (element.isNestable()) { super.add(index, element); } @@ -291,12 +291,12 @@ public void add(int index, Object o) { * @return a boolean * @throws ClassCastException if the object is not a Paragraph, List, Table or Section */ - public boolean add(Object o) { + public boolean add(Element o) { if (isAddedCompletely()) { throw new IllegalStateException(MessageLocalization.getComposedMessage("this.largeelement.has.already.been.added.to.the.document")); } try { - Element element = (Element) o; + Element element = o; if (element.type() == Element.SECTION) { Section section = (Section) o; section.setNumbers(++subsections, numbers); @@ -328,8 +328,8 @@ else if (element.isNestable()) { * @return true if the action succeeded, false if not. * @throws ClassCastException if one of the objects isn't a Paragraph, List, Table */ - public boolean addAll(Collection collection) { - for (Object o : collection) { + public boolean addAll(Collection collection) { + for (Element o : collection) { this.add(o); } return true; @@ -469,7 +469,7 @@ public Paragraph getTitle() { * @return a Paragraph object * @since iText 2.0.8 */ - public static Paragraph constructTitle(Paragraph title, ArrayList numbers, int numberDepth, int numberStyle) { + public static Paragraph constructTitle(Paragraph title, java.util.List numbers, int numberDepth, int numberStyle) { if (title == null) { return null; } @@ -481,7 +481,7 @@ public static Paragraph constructTitle(Paragraph title, ArrayList numbers, int n StringBuilder buf = new StringBuilder(" "); for (int i = 0; i < depth; i++) { buf.insert(0, "."); - buf.insert(0, ((Integer) numbers.get(i)).intValue()); + buf.insert(0, numbers.get(i).intValue()); } if (numberStyle == NUMBERSTYLE_DOTTED_WITHOUT_FINAL_DOT) { buf.deleteCharAt(buf.length() - 2); @@ -669,8 +669,8 @@ public int getDepth() { * @param number the number of this section * @param numbers an ArrayList, containing the numbers of the Parent */ - private void setNumbers(int number, ArrayList numbers) { - this.numbers = new ArrayList(); + private void setNumbers(int number, java.util.List numbers) { + this.numbers = new ArrayList<>(); this.numbers.add(number); this.numbers.addAll(numbers); } diff --git a/openpdf/src/main/java/com/lowagie/text/SimpleCell.java b/openpdf/src/main/java/com/lowagie/text/SimpleCell.java index bd501fb09..34fcc83fe 100644 --- a/openpdf/src/main/java/com/lowagie/text/SimpleCell.java +++ b/openpdf/src/main/java/com/lowagie/text/SimpleCell.java @@ -49,7 +49,10 @@ package com.lowagie.text; import java.util.ArrayList; +import java.util.Optional; +import com.lowagie.text.alignment.HorizontalAlignment; +import com.lowagie.text.alignment.VerticalAlignment; import com.lowagie.text.error_messages.MessageLocalization; import com.lowagie.text.ExceptionConverter; @@ -73,7 +76,7 @@ public class SimpleCell extends Rectangle implements PdfPCellEvent, TextElementA // member variables /** the content of the Cell. */ - private ArrayList content = new ArrayList(); + private java.util.List content = new ArrayList<>(); /** the width of the Cell. */ private float width = 0f; /** the widthpercentage of the Cell. */ @@ -174,8 +177,10 @@ public Cell createCell(SimpleCell rowAttributes) throws BadElementException { cell.cloneNonPositionParameters(rowAttributes); cell.softCloneNonPositionParameters(this); cell.setColspan(colspan); - cell.setHorizontalAlignment(horizontalAlignment); - cell.setVerticalAlignment(verticalAlignment); + Optional hAlignment = HorizontalAlignment.of(horizontalAlignment); + cell.setHorizontalAlignment(hAlignment.orElse(HorizontalAlignment.UNDEFINED)); + Optional vAlignment = VerticalAlignment.of(verticalAlignment); + cell.setVerticalAlignment(vAlignment.orElse(VerticalAlignment.UNDEFINED)); cell.setUseAscender(useAscender); cell.setUseBorderPadding(useBorderPadding); cell.setUseDescender(useDescender); @@ -508,16 +513,16 @@ public void setUseDescender(boolean useDescender) { /** * @return Returns the content. */ - ArrayList getContent() { + java.util.List getContent() { return content; } /** - * @see com.lowagie.text.TextElementArray#add(java.lang.Object) + * @see com.lowagie.text.TextElementArray#add(Element) */ - public boolean add(Object o) { + public boolean add(Element o) { try { - addElement((Element)o); + addElement(o); return true; } catch(ClassCastException e) { diff --git a/openpdf/src/main/java/com/lowagie/text/SimpleTable.java b/openpdf/src/main/java/com/lowagie/text/SimpleTable.java index 8b5dc77c8..8d1a4c641 100644 --- a/openpdf/src/main/java/com/lowagie/text/SimpleTable.java +++ b/openpdf/src/main/java/com/lowagie/text/SimpleTable.java @@ -49,7 +49,9 @@ package com.lowagie.text; import java.util.ArrayList; +import java.util.Optional; +import com.lowagie.text.alignment.HorizontalAlignment; import com.lowagie.text.error_messages.MessageLocalization; import com.lowagie.text.ExceptionConverter; @@ -65,7 +67,7 @@ public class SimpleTable extends Rectangle implements PdfPTableEvent, TextElementArray { /** the content of a Table. */ - private ArrayList content = new ArrayList(); + private java.util.List content = new ArrayList<>(); /** the width of the Table. */ private float width = 0f; /** the widthpercentage of the Table. */ @@ -116,7 +118,8 @@ public Table createTable() throws BadElementException { float[] widths = new float[columns]; float[] widthpercentages = new float[columns]; Table table = new Table(columns); - table.setAlignment(alignment); + final Optional of = HorizontalAlignment.of(alignment); + table.setHorizontalAlignment(of.orElse(HorizontalAlignment.UNDEFINED)); table.setSpacing(cellspacing); table.setPadding(cellpadding); table.cloneNonPositionParameters(this); @@ -340,9 +343,9 @@ public boolean isNestable() { } /** - * @see com.lowagie.text.TextElementArray#add(java.lang.Object) + * @see com.lowagie.text.TextElementArray#add(Element) */ - public boolean add(Object o) { + public boolean add(Element o) { try { addElement((SimpleCell)o); return true; diff --git a/openpdf/src/main/java/com/lowagie/text/Table.java b/openpdf/src/main/java/com/lowagie/text/Table.java index 4d91d0b5f..685a839c0 100644 --- a/openpdf/src/main/java/com/lowagie/text/Table.java +++ b/openpdf/src/main/java/com/lowagie/text/Table.java @@ -53,11 +53,14 @@ package com.lowagie.text; import com.lowagie.text.alignment.HorizontalAlignment; +import com.lowagie.text.alignment.VerticalAlignment; import com.lowagie.text.alignment.WithHorizontalAlignment; import java.awt.Dimension; import java.awt.Point; import java.util.ArrayList; import java.util.Iterator; +import java.util.Optional; + import com.lowagie.text.error_messages.MessageLocalization; import com.lowagie.text.pdf.PdfPCell; @@ -154,7 +157,7 @@ * @see Cell */ -public class Table extends Rectangle implements LargeElement, WithHorizontalAlignment { +public class Table extends TableRectangle implements LargeElement, WithHorizontalAlignment { // membervariables @@ -162,7 +165,7 @@ public class Table extends Rectangle implements LargeElement, WithHorizontalAlig private int columns; /** This is the list of Rows. */ - private ArrayList rows = new ArrayList(); + private ArrayList rows = new ArrayList<>(); /** The current Position in the table. */ private Point curPosition = new Point(0, 0); @@ -327,8 +330,8 @@ public int type() { * @return an ArrayList */ - public ArrayList getChunks() { - return new ArrayList(); + public java.util.List getChunks() { + return new ArrayList<>(); } /** @@ -770,8 +773,10 @@ public void addCell(Phrase content, Point location) throws BadElementException { cell.setBorderWidth(defaultCell.getBorderWidth()); cell.setBorderColor(defaultCell.getBorderColor()); cell.setBackgroundColor(defaultCell.getBackgroundColor()); - cell.setHorizontalAlignment(defaultCell.getHorizontalAlignment()); - cell.setVerticalAlignment(defaultCell.getVerticalAlignment()); + Optional optionalHorizontalAlignment = HorizontalAlignment.of(defaultCell.getHorizontalAlignment()); + cell.setHorizontalAlignment(optionalHorizontalAlignment.orElse(HorizontalAlignment.UNDEFINED)); + Optional optionalVerticalAlignment = VerticalAlignment.of(defaultCell.getVerticalAlignment()); + cell.setVerticalAlignment(optionalVerticalAlignment.orElse(VerticalAlignment.UNDEFINED)); cell.setColspan(defaultCell.getColspan()); cell.setRowspan(defaultCell.getRowspan()); addCell(cell, location); @@ -855,7 +860,7 @@ public void insertTable(Table aTable, Point aLocation) { } } - ((Row) rows.get(aLocation.x)).setElement(aTable,aLocation.y); + rows.get(aLocation.x).setElement(aTable,aLocation.y); setCurrentLocationToNextValidPosition(aLocation); } @@ -866,14 +871,14 @@ public void insertTable(Table aTable, Point aLocation) { * @param aColumns the number of columns to add */ public void addColumns(int aColumns) { - ArrayList newRows = new ArrayList(rows.size()); + ArrayList newRows = new ArrayList<>(rows.size()); int newColumns = columns + aColumns; Row row; for (int i = 0; i < rows.size(); i++) { row = new Row(newColumns); for (int j = 0; j < columns; j++) { - row.setElement(((Row) rows.get(i)).getCell(j) ,j); + row.setElement(rows.get(i).getCell(j) ,j); } for (int j = columns; j < newColumns && i < curPosition.x; j++) { row.setElement(null, j); @@ -907,7 +912,7 @@ public void deleteColumn(int column) throws BadElementException { Row row; int size = rows.size(); for (int i = 0; i < size; i++) { - row = (Row) rows.get(i); + row = rows.get(i); row.deleteColumn(column); rows.set(i, row); } @@ -975,25 +980,25 @@ public void complete() { * @return dimension * @since 2.1.0 (was made private in 2.0.3) */ - public Object getElement(int row, int column) { - return ((Row) rows.get(row)).getCell(column); + public TableRectangle getElement(int row, int column) { + return rows.get(row).getCell(column); } /** * Integrates all added tables and recalculates column widths. */ private void mergeInsertedTables() { - int i=0, j=0; - float [] lNewWidths = null; + int i, j; + float [] lNewWidths; int [] lDummyWidths = new int[columns]; // to keep track in how many new cols this one will be split float[][] lDummyColumnWidths = new float[columns][]; // bugfix Tony Copping int [] lDummyHeights = new int[rows.size()]; // to keep track in how many new rows this one will be split - ArrayList newRows = null; + ArrayList newRows; boolean isTable=false; int lTotalRows = 0, lTotalColumns = 0; - int lNewMaxRows = 0, lNewMaxColumns = 0; + int lNewMaxRows, lNewMaxColumns; - Table lDummyTable = null; + Table lDummyTable; // first we'll add new columns when needed // check one column at a time, find maximum needed nr of cols @@ -1002,9 +1007,9 @@ private void mergeInsertedTables() { lNewMaxColumns = 1; // value to hold in how many columns the current one will be split float [] tmpWidths = null; for (i=0; i < rows.size(); i++) { - if (((Row) rows.get(i)).getCell(j) instanceof Table) { + if (rows.get(i).getCell(j) instanceof Table) { isTable=true; - lDummyTable = ((Table) ((Row) rows.get(i)).getCell(j)); + lDummyTable = ((Table) rows.get(i).getCell(j)); if( tmpWidths == null) { tmpWidths = lDummyTable.widths; lNewMaxColumns=tmpWidths.length; @@ -1069,9 +1074,9 @@ else if(btI lNewMaxRows ) { lNewMaxRows = lDummyTable.getDimension().height; } @@ -1108,19 +1113,18 @@ else if(btI(lTotalRows); for (i = 0; i < lTotalRows; i++) { newRows.add(new Row(lTotalColumns)); } - int lDummyRow = 0, lDummyColumn = 0; // to remember where we are in the new, larger table - Object lDummyElement = null; + int lDummyRow = 0, lDummyColumn; // to remember where we are in the new, larger table + TableRectangle lDummyElement; for (i=0; i < rows.size(); i++) { lDummyColumn = 0; - lNewMaxRows = 1; for (j=0; j < columns; j++) { - if (((Row) rows.get(i)).getCell(j) instanceof Table) // copy values from embedded table + if (rows.get(i).getCell(j) instanceof Table) // copy values from embedded table { - lDummyTable = (Table) ((Row) rows.get(i)).getCell(j); + lDummyTable = (Table) rows.get(i).getCell(j); // Work out where columns in table table correspond to columns in current table int[] colMap = new int[lDummyTable.widths.length + 1]; @@ -1156,20 +1160,20 @@ else if(btI of = HorizontalAlignment.of(defaultCell.getHorizontalAlignment()); + aCell.setHorizontalAlignment(of.orElse(HorizontalAlignment.UNDEFINED)); } if (aCell.getVerticalAlignment() == Element.ALIGN_UNDEFINED) { - aCell.setVerticalAlignment(defaultCell.getVerticalAlignment()); + final Optional of = VerticalAlignment.of(defaultCell.getVerticalAlignment()); + aCell.setVerticalAlignment(of.orElse(VerticalAlignment.UNDEFINED)); } } @@ -1275,9 +1281,9 @@ private void assumeTableDefaults(Cell aCell) { * @param aCell the cell that has to be inserted * @param aPosition the position where the cell has to be placed */ - private void placeCell(ArrayList someRows, Cell aCell, Point aPosition) { + private void placeCell(ArrayList someRows, Cell aCell, Point aPosition) { int i; - Row row = null; + Row row; int rowCount = aPosition.x + aCell.getRowspan() - someRows.size(); assumeTableDefaults(aCell); if ( (aPosition.x + aCell.getRowspan()) > someRows.size() ) { @@ -1289,13 +1295,13 @@ private void placeCell(ArrayList someRows, Cell aCell, Point aPosition) { // reserve cell in rows below for (i = aPosition.x + 1; i < (aPosition.x + aCell.getRowspan()); i++) { - if ( !((Row) someRows.get(i)).reserve(aPosition.y, aCell.getColspan())) { + if ( !someRows.get(i).reserve(aPosition.y, aCell.getColspan())) { // should be impossible to come here :-) throw new RuntimeException(MessageLocalization.getComposedMessage("addcell.error.in.reserve")); } } - row = (Row) someRows.get(aPosition.x); + row = someRows.get(aPosition.x); row.addElement(aCell, aPosition.y); } @@ -1319,7 +1325,7 @@ private void setCurrentLocationToNextValidPosition(Point aLocation) { } } while ( - (i < rows.size()) && (j < columns) && (((Row) rows.get(i)).isReserved(j)) + (i < rows.size()) && (j < columns) && (rows.get(i).isReserved(j)) ); curPosition = new Point(i, j); } @@ -1418,7 +1424,7 @@ public PdfPTable createPdfPTable() throws BadElementException { Element cell; PdfPCell pcell; for (int i = 0; i < row.getColumns(); i++) { - if ((cell = (Element)row.getCell(i)) != null) { + if ((cell = row.getCell(i)) != null) { if (cell instanceof Table) { pcell = new PdfPCell(((Table)cell).createPdfPTable()); } @@ -1465,11 +1471,11 @@ public void setNotAddedYet(boolean notAddedYet) { */ public void flushContent() { this.setNotAddedYet(false); - ArrayList headerrows = new ArrayList(); + ArrayList headerRows = new ArrayList<>(); for (int i = 0; i < getLastHeaderRow() + 1; i++) { - headerrows.add(rows.get(i)); + headerRows.add(rows.get(i)); } - rows = headerrows; + rows = headerRows; } /** diff --git a/openpdf/src/main/java/com/lowagie/text/TableRectangle.java b/openpdf/src/main/java/com/lowagie/text/TableRectangle.java new file mode 100644 index 000000000..26557eca6 --- /dev/null +++ b/openpdf/src/main/java/com/lowagie/text/TableRectangle.java @@ -0,0 +1,23 @@ +package com.lowagie.text; + +public class TableRectangle extends Rectangle { + public TableRectangle(float llx, float lly, float urx, float ury) { + super(llx, lly, urx, ury); + } + + public TableRectangle(float urx, float ury) { + super(urx, ury); + } + + public TableRectangle(float llx, float lly, float urx, float ury, int rotation) { + super(llx, lly, urx, ury, rotation); + } + + public TableRectangle(float urx, float ury, int rotation) { + super(urx, ury, rotation); + } + + public TableRectangle(Rectangle rect) { + super(rect); + } +} diff --git a/openpdf/src/main/java/com/lowagie/text/TextElementArray.java b/openpdf/src/main/java/com/lowagie/text/TextElementArray.java index dede1e1bb..3a8747980 100644 --- a/openpdf/src/main/java/com/lowagie/text/TextElementArray.java +++ b/openpdf/src/main/java/com/lowagie/text/TextElementArray.java @@ -69,5 +69,5 @@ public interface TextElementArray extends Element { * @param o an object that has to be added * @return true if the addition succeeded; false otherwise */ - boolean add(Object o); + boolean add(Element o); } \ No newline at end of file diff --git a/openpdf/src/main/java/com/lowagie/text/error_messages/MessageLocalization.java b/openpdf/src/main/java/com/lowagie/text/error_messages/MessageLocalization.java index 56e9ee369..bbccea623 100644 --- a/openpdf/src/main/java/com/lowagie/text/error_messages/MessageLocalization.java +++ b/openpdf/src/main/java/com/lowagie/text/error_messages/MessageLocalization.java @@ -56,6 +56,7 @@ import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.util.HashMap; +import java.util.Map; /** * Localizes error messages. The messages are located in the package @@ -65,8 +66,8 @@ * @author Paulo Soares (psoares@glintt.com) */ public final class MessageLocalization { - private static HashMap defaultLanguage = new HashMap(); - private static HashMap currentLanguage; + private static Map defaultLanguage = new HashMap<>(); + private static Map currentLanguage; private static final String BASE_PATH = "com/lowagie/text/error_messages/"; private MessageLocalization() { @@ -79,7 +80,7 @@ private MessageLocalization() { // do nothing } if (defaultLanguage == null) - defaultLanguage = new HashMap(); + defaultLanguage = new HashMap<>(); } /** @@ -88,15 +89,15 @@ private MessageLocalization() { * @return the message */ public static String getMessage(String key) { - HashMap cl = currentLanguage; + Map cl = currentLanguage; String val; if (cl != null) { - val = (String)cl.get(key); + val = cl.get(key); if (val != null) return val; } cl = defaultLanguage; - val = (String)cl.get(key); + val = cl.get(key); if (val != null) return val; return "No message found for " + key; @@ -195,7 +196,7 @@ public static String getComposedMessage(String key, Object p1, Object p2, Object * @throws IOException on error */ public static boolean setLanguage(String language, String country) throws IOException { - HashMap lang = getLanguageMessages(language, country); + Map lang = getLanguageMessages(language, country); if (lang == null) return false; currentLanguage = lang; @@ -211,7 +212,7 @@ public static void setMessages(Reader r) throws IOException { currentLanguage = readLanguageStream(r); } - private static HashMap getLanguageMessages(String language, String country) throws IOException { + private static Map getLanguageMessages(String language, String country) throws IOException { if (language == null) throw new IllegalArgumentException("The language cannot be null."); InputStream is = null; @@ -242,12 +243,12 @@ private static HashMap getLanguageMessages(String language, String country) thro } } - private static HashMap readLanguageStream(InputStream is) throws IOException { + private static Map readLanguageStream(InputStream is) throws IOException { return readLanguageStream(new InputStreamReader(is, StandardCharsets.UTF_8)); } - private static HashMap readLanguageStream(Reader r) throws IOException { - HashMap lang = new HashMap(); + private static Map readLanguageStream(Reader r) throws IOException { + Map lang = new HashMap<>(); BufferedReader br = new BufferedReader(r); String line; while ((line = br.readLine()) != null) { diff --git a/openpdf/src/main/java/com/lowagie/text/factories/ElementFactory.java b/openpdf/src/main/java/com/lowagie/text/factories/ElementFactory.java index 4f7ae72b7..0595f22fc 100644 --- a/openpdf/src/main/java/com/lowagie/text/factories/ElementFactory.java +++ b/openpdf/src/main/java/com/lowagie/text/factories/ElementFactory.java @@ -57,6 +57,9 @@ import java.util.ArrayList; import java.util.Properties; import java.util.StringTokenizer; + +import com.lowagie.text.alignment.HorizontalAlignment; +import com.lowagie.text.alignment.VerticalAlignment; import com.lowagie.text.error_messages.MessageLocalization; import com.lowagie.text.Anchor; @@ -288,10 +291,26 @@ public static Cell getCell(Properties attributes) { Cell cell = new Cell(); String value; - cell.setHorizontalAlignment(attributes - .getProperty(ElementTags.HORIZONTALALIGN)); - cell.setVerticalAlignment(attributes - .getProperty(ElementTags.VERTICALALIGN)); + try { + if (attributes.getProperty(ElementTags.HORIZONTALALIGN) != null) { + final HorizontalAlignment horizontalAlignment = HorizontalAlignment.valueOf(attributes.getProperty(ElementTags.HORIZONTALALIGN)); + cell.setHorizontalAlignment(horizontalAlignment); + } else { + cell.setHorizontalAlignment(HorizontalAlignment.UNDEFINED); + } + } catch (IllegalArgumentException exc) { + cell.setHorizontalAlignment(HorizontalAlignment.UNDEFINED); + } + try { + if (attributes.getProperty(ElementTags.VERTICALALIGN) != null) { + final VerticalAlignment verticalAlignment = VerticalAlignment.valueOf(attributes.getProperty(ElementTags.VERTICALALIGN)); + cell.setVerticalAlignment(verticalAlignment); + } else { + cell.setVerticalAlignment(VerticalAlignment.UNDEFINED); + } + } catch (IllegalArgumentException exc) { + cell.setVerticalAlignment(VerticalAlignment.UNDEFINED); + } value = attributes.getProperty(ElementTags.WIDTH); if (value != null) { @@ -331,14 +350,14 @@ public static Table getTable(Properties attributes) { value = attributes.getProperty(ElementTags.WIDTHS); if (value != null) { StringTokenizer widthTokens = new StringTokenizer(value, ";"); - ArrayList values = new ArrayList(); + java.util.List values = new ArrayList<>(); while (widthTokens.hasMoreTokens()) { values.add(widthTokens.nextToken()); } table = new Table(values.size()); float[] widths = new float[table.getColumns()]; for (int i = 0; i < values.size(); i++) { - value = (String) values.get(i); + value = values.get(i); widths[i] = Float.parseFloat(value + "f"); } table.setWidths(widths); @@ -361,7 +380,12 @@ public static Table getTable(Properties attributes) { } value = attributes.getProperty(ElementTags.ALIGN); if (value != null) { - table.setAlignment(value); + try { + final HorizontalAlignment horizontalAlignment = HorizontalAlignment.valueOf(value); + table.setHorizontalAlignment(horizontalAlignment); + } catch (IllegalArgumentException exc) { + table.setHorizontalAlignment(HorizontalAlignment.UNDEFINED); + } } value = attributes.getProperty(ElementTags.CELLSPACING); if (value != null) { diff --git a/openpdf/src/main/java/com/lowagie/text/html/HtmlTagMap.java b/openpdf/src/main/java/com/lowagie/text/html/HtmlTagMap.java index fea01fa44..ffe502367 100644 --- a/openpdf/src/main/java/com/lowagie/text/html/HtmlTagMap.java +++ b/openpdf/src/main/java/com/lowagie/text/html/HtmlTagMap.java @@ -61,7 +61,7 @@ * The Tags-class maps several XHTML-tags to iText-objects. */ -public class HtmlTagMap extends HashMap { +public class HtmlTagMap extends HashMap { private static final long serialVersionUID = 5287430058473705350L; diff --git a/openpdf/src/main/java/com/lowagie/text/html/HtmlWriter.java b/openpdf/src/main/java/com/lowagie/text/html/HtmlWriter.java index 6d2b5eb8a..716d79911 100644 --- a/openpdf/src/main/java/com/lowagie/text/html/HtmlWriter.java +++ b/openpdf/src/main/java/com/lowagie/text/html/HtmlWriter.java @@ -870,7 +870,7 @@ protected void write(Element element, int indent) throws IOException { // contents Element cell; for (int i = 0; i < row.getColumns(); i++) { - if ((cell = (Element) row.getCell(i)) != null) { + if ((cell = row.getCell(i)) != null) { write(cell, indent + 1); } } diff --git a/openpdf/src/main/java/com/lowagie/text/html/WebColors.java b/openpdf/src/main/java/com/lowagie/text/html/WebColors.java index 2743824b5..d5f37d078 100644 --- a/openpdf/src/main/java/com/lowagie/text/html/WebColors.java +++ b/openpdf/src/main/java/com/lowagie/text/html/WebColors.java @@ -62,7 +62,7 @@ * * @author blowagie */ -public class WebColors extends HashMap { +public class WebColors extends HashMap { private static final long serialVersionUID = 3542523100813372896L; /** HashMap containing all the names and corresponding color values. */ @@ -258,7 +258,7 @@ else if (c[k] > 255) if (!NAMES.containsKey(name)) throw new IllegalArgumentException("Color '" + name + "' not found."); - c = (int[]) NAMES.get(name); + c = NAMES.get(name); return new Color(c[0], c[1], c[2], c[3]); } } diff --git a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/ChainedProperties.java b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/ChainedProperties.java index 0d8e61cc2..33750c95b 100755 --- a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/ChainedProperties.java +++ b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/ChainedProperties.java @@ -122,7 +122,11 @@ public boolean hasProperty(String key) { return false; } + /** + * @deprecated use {@link ChainedProperties#addToChain(String, Map)} + */ @Deprecated + @SuppressWarnings("unchecked") public void addToChain(String key, HashMap prop) { addToChain(key, (Map) prop); } diff --git a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/FactoryProperties.java b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/FactoryProperties.java index a52526182..f4e4ec29b 100755 --- a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/FactoryProperties.java +++ b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/FactoryProperties.java @@ -79,7 +79,7 @@ */ public class FactoryProperties { - public static HashMap followTags = new HashMap(); + public static Map followTags = new HashMap<>(); static { followTags.put("i", "i"); @@ -230,9 +230,17 @@ public static HyphenationEvent getHyphenation(@Nullable String s) { * * @param h a HashMap that should have at least a key named * style. After this method is invoked, more keys could be added. + * + * @deprecated use {@link FactoryProperties#insertStyle(Map)} instead. (since 1.2.22) */ + @SuppressWarnings("unchecked") + @Deprecated public static void insertStyle(HashMap h) { - String style = (String) h.get("style"); + insertStyle((Map) h); + } + + public static void insertStyle(Map h) { + String style = h.get("style"); if (style == null) return; Properties prop = Markup.parseAttributes(style); diff --git a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/HTMLWorker.java b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/HTMLWorker.java index 0d1676a56..fca1d3aab 100755 --- a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/HTMLWorker.java +++ b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/HTMLWorker.java @@ -90,7 +90,7 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { public static final String tagsSupportedString = "ol ul li a pre font span br p div body table td th tr i b u sub sup em strong s strike" + " h1 h2 h3 h4 h5 h6 img hr"; - public static final HashMap tagsSupported = new HashMap(); + public static final Map tagsSupported = new HashMap<>(); static { StringTokenizer tok = new StringTokenizer(tagsSupportedString); @@ -98,19 +98,19 @@ public class HTMLWorker implements SimpleXMLDocHandler, DocListener { tagsSupported.put(tok.nextToken(), null); } - protected ArrayList objectList; + protected List objectList; protected DocListener document; private Paragraph currentParagraph; private ChainedProperties cprops = new ChainedProperties(); - private Stack stack = new Stack(); + private Stack stack = new Stack<>(); private boolean pendingTR = false; private boolean pendingTD = false; private boolean pendingLI = false; private StyleSheet style = new StyleSheet(); private boolean isPRE = false; - private Stack tableState = new Stack(); + private Stack tableState = new Stack<>(); private boolean skipText = false; - private HashMap interfaceProps; + private Map interfaceProps; private FactoryProperties factoryProperties = new FactoryProperties(); /** @@ -122,11 +122,22 @@ public HTMLWorker(DocListener document) { this.document = document; } - public static ArrayList parseToList(Reader reader, StyleSheet style) throws IOException { - return parseToList(reader, style, null); + public static List parseToList(Reader reader, StyleSheet style) throws IOException { + Map interfaceProps = null; + return parseToList(reader, style, interfaceProps); } - public static ArrayList parseToList(Reader reader, @Nullable StyleSheet style, HashMap interfaceProps) + /** + * @deprecated use {@link HTMLWorker#parseToList(Reader, StyleSheet, Map)} since 1.2.22 + */ + @Deprecated + @SuppressWarnings("unchecked") + public static List parseToList(Reader reader, @Nullable StyleSheet style, HashMap interfaceProps) + throws IOException { + return parseToList(reader, style, (Map) interfaceProps); + } + + public static List parseToList(Reader reader, @Nullable StyleSheet style, Map interfaceProps) throws IOException { HTMLWorker worker = new HTMLWorker(null); if (style != null) { @@ -134,7 +145,7 @@ public static ArrayList parseToList(Reader reader, @Nullable StyleSheet style, H } worker.document = worker; worker.setInterfaceProps(interfaceProps); - worker.objectList = new ArrayList(); + worker.objectList = new ArrayList<>(); worker.parse(reader); return worker.objectList; } @@ -147,11 +158,21 @@ public void setStyleSheet(StyleSheet style) { this.style = style; } - public HashMap getInterfaceProps() { + public Map getInterfaceProps() { return interfaceProps; } + /** + * + * @deprecated use {@link HTMLWorker#setInterfaceProps(Map)} since 1.2.22 + */ + @SuppressWarnings("unchecked") + @Deprecated public void setInterfaceProps(HashMap interfaceProps) { + setInterfaceProps((Map) interfaceProps); + } + + public void setInterfaceProps(Map interfaceProps) { this.interfaceProps = interfaceProps; FontProvider ff = null; if (interfaceProps != null) @@ -182,7 +203,11 @@ public void startDocument() { cprops.addToChain("body", h); } + /** + * @deprecated use {@link HTMLWorker#startElement(String, Map)} } since 1.2.22 + */ @Deprecated + @SuppressWarnings("unchecked") public void startElement(String tag, HashMap h) { startElement(tag, (Map) h); } @@ -193,7 +218,7 @@ public void startElement(String tag, Map style) { } try { this.style.applyStyle(tag, style); - String follow = (String) FactoryProperties.followTags.get(tag); + String follow = FactoryProperties.followTags.get(tag); if (follow != null) { Map prop = new HashMap<>(); prop.put(follow, null); @@ -284,7 +309,7 @@ public void startElement(String tag, Map style) { img = ip.getImage(src, (HashMap) style, cprops, document); } if (img == null) { - HashMap images = (HashMap) interfaceProps.get("img_static"); + Map images = (HashMap) interfaceProps.get("img_static"); if (images != null) { Image tim = (Image) images.get(src); if (tim != null) { @@ -462,7 +487,7 @@ public void endElement(String tag) { if (!tagsSupported.containsKey(tag)) return; try { - String follow = (String) FactoryProperties.followTags.get(tag); + String follow = FactoryProperties.followTags.get(tag); if (follow != null) { cprops.removeChain(follow); return; @@ -483,8 +508,8 @@ public void endElement(String tag) { } if (!skip) { cprops.findProperty("href").ifPresent(href -> { - ArrayList chunks = currentParagraph.getChunks(); - for (Object chunk : chunks) { + List chunks = currentParagraph.getChunks(); + for (Element chunk : chunks) { Chunk ck = (Chunk) chunk; ck.setAnchor(href); } @@ -530,7 +555,7 @@ public void endElement(String tag) { if (stack.empty()) document.add((Element) obj); else - ((TextElementArray) stack.peek()).add(obj); + ((TextElementArray) stack.peek()).add((Element) obj); return; } if (tag.equals(HtmlTags.LISTITEM)) { @@ -555,7 +580,7 @@ public void endElement(String tag) { } ListItem item = (ListItem) obj; ((com.lowagie.text.List) list).add(item); - ArrayList cks = item.getChunks(); + List cks = item.getChunks(); if (!cks.isEmpty()) item.getListSymbol() .setFont(((Chunk) cks.get(0)).getFont()); diff --git a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/IncCell.java b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/IncCell.java index 1444040b1..dc7b8d85f 100755 --- a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/IncCell.java +++ b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/IncCell.java @@ -56,6 +56,7 @@ import com.lowagie.text.utils.NumberUtilities; import java.util.ArrayList; +import java.util.List; /** * @author psoares @@ -63,7 +64,7 @@ public class IncCell implements TextElementArray { private final PdfPCell cell; - private ArrayList chunks = new ArrayList(); + private List chunks = new ArrayList<>(); /** * Creates a new instance of IncCell @@ -115,15 +116,13 @@ else if ("justify".equalsIgnoreCase(align)) } @Override - public boolean add(Object o) { - if (!(o instanceof Element)) - return false; - cell.addElement((Element) o); + public boolean add(Element o) { + cell.addElement(o); return true; } @Override - public ArrayList getChunks() { + public List getChunks() { return chunks; } diff --git a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/IncTable.java b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/IncTable.java index 54c18e758..191095081 100755 --- a/openpdf/src/main/java/com/lowagie/text/html/simpleparser/IncTable.java +++ b/openpdf/src/main/java/com/lowagie/text/html/simpleparser/IncTable.java @@ -47,15 +47,15 @@ package com.lowagie.text.html.simpleparser; +import com.lowagie.text.pdf.PdfPCell; +import com.lowagie.text.pdf.PdfPTable; + import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; -import com.lowagie.text.pdf.PdfPCell; -import com.lowagie.text.pdf.PdfPTable; - /** * * @author psoares @@ -67,6 +67,7 @@ public class IncTable { /** Creates a new instance of IncTable */ @Deprecated + @SuppressWarnings("unchecked") public IncTable(HashMap props) { this.props.putAll(props); } @@ -82,9 +83,10 @@ public void addCol(PdfPCell cell) { } @Deprecated + @SuppressWarnings("unchecked") public void addCols(ArrayList ncols) { if (cols == null) - cols = new ArrayList<>(ncols); + cols = (List)ncols; else cols.addAll(ncols); } diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/ColumnText.java b/openpdf/src/main/java/com/lowagie/text/pdf/ColumnText.java index d8925ed62..94d70ad83 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/ColumnText.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/ColumnText.java @@ -48,23 +48,24 @@ */ package com.lowagie.text.pdf; -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.Stack; -import com.lowagie.text.error_messages.MessageLocalization; import com.lowagie.text.Chunk; import com.lowagie.text.DocumentException; import com.lowagie.text.Element; - +import com.lowagie.text.ExceptionConverter; import com.lowagie.text.Image; import com.lowagie.text.ListItem; import com.lowagie.text.Paragraph; import com.lowagie.text.Phrase; import com.lowagie.text.SimpleTable; -import com.lowagie.text.ExceptionConverter; +import com.lowagie.text.error_messages.MessageLocalization; import com.lowagie.text.pdf.draw.DrawInterface; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Stack; + /** * Formats text in a columnwise form. The text is bound * on the left and on the right by a sequence of lines. This allows the column @@ -176,10 +177,10 @@ public class ColumnText { protected int alignment = Element.ALIGN_LEFT; /** The left column bound. */ - protected ArrayList leftWall; + protected List leftWall; /** The right column bound. */ - protected ArrayList rightWall; + protected List rightWall; /** The chunks that form the text. */ // protected ArrayList chunks = new ArrayList(); @@ -241,7 +242,7 @@ public class ColumnText { protected ColumnText compositeColumn; - protected LinkedList compositeElements; + protected LinkedList compositeElements; protected int listIdx = 0; @@ -298,10 +299,10 @@ protected void setSimpleVars(ColumnText org) { alignment = org.alignment; leftWall = null; if (org.leftWall != null) - leftWall = new ArrayList(org.leftWall); + leftWall = new ArrayList<>(org.leftWall); rightWall = null; if (org.rightWall != null) - rightWall = new ArrayList(org.rightWall); + rightWall = new ArrayList<>(org.rightWall); yLine = org.yLine; currentLeading = org.currentLeading; fixedLeading = org.fixedLeading; @@ -324,7 +325,7 @@ protected void setSimpleVars(ColumnText org) { composite = org.composite; splittedRow = org.splittedRow; if (org.composite) { - compositeElements = new LinkedList(org.compositeElements); + compositeElements = new LinkedList<>(org.compositeElements); if (splittedRow) { PdfPTable table = (PdfPTable)compositeElements.getFirst(); compositeElements.set(0, new PdfPTable(table)); @@ -461,7 +462,7 @@ else if (element.type() != Element.PARAGRAPH && element.type() != Element.LIST & throw new IllegalArgumentException(MessageLocalization.getComposedMessage("element.not.allowed")); if (!composite) { composite = true; - compositeElements = new LinkedList(); + compositeElements = new LinkedList<>(); bidiLine = null; waitPhrase = null; } @@ -478,10 +479,10 @@ else if (element.type() != Element.PARAGRAPH && element.type() != Element.LIST & * @param cLine the column array * @return the converted array */ - protected ArrayList convertColumn(float[] cLine) { + protected List convertColumn(float[] cLine) { if (cLine.length < 4) throw new RuntimeException(MessageLocalization.getComposedMessage("no.valid.column.line.found")); - ArrayList cc = new ArrayList(); + List cc = new ArrayList<>(); for (int k = 0; k < cLine.length - 2; k += 2) { float x1 = cLine[k]; float y1 = cLine[k + 1]; @@ -513,7 +514,7 @@ protected ArrayList convertColumn(float[] cLine) { * @param wall the column to intersect * @return the x coordinate of the intersection */ - protected float findLimitsPoint(ArrayList wall) { + protected float findLimitsPoint(List wall) { lineStatus = LINE_STATUS_OK; if (yLine < minY || yLine > maxY) { lineStatus = LINE_STATUS_OFFLIMITS; @@ -1154,7 +1155,7 @@ protected int goComposite(boolean simulate) throws DocumentException { while (true) { if (compositeElements.isEmpty()) return NO_MORE_TEXT; - Element element = (Element)compositeElements.getFirst(); + Element element = compositeElements.getFirst(); if (element.type() == Element.PARAGRAPH) { Paragraph para = (Paragraph)element; int status = 0; @@ -1216,11 +1217,11 @@ protected int goComposite(boolean simulate) throws DocumentException { } else if (element.type() == Element.LIST) { com.lowagie.text.List list = (com.lowagie.text.List)element; - ArrayList items = list.getItems(); + java.util.List items = list.getItems(); ListItem item = null; float listIndentation = list.getIndentationLeft(); int count = 0; - Stack stack = new Stack(); + Stack stack = new Stack<>(); for (int k = 0; k < items.size(); ++k) { Object obj = items.get(k); if (obj instanceof ListItem) { @@ -1240,7 +1241,7 @@ else if (obj instanceof com.lowagie.text.List) { } if (k == items.size() - 1) { if (!stack.isEmpty()) { - Object[] objs = (Object[]) stack.pop(); + Object[] objs = stack.pop(); list = (com.lowagie.text.List)objs[0]; items = list.getItems(); k = (Integer) objs[1]; @@ -1393,7 +1394,7 @@ else if (element.type() == Element.PTABLE) { splittedRow = true; table = new PdfPTable(table); compositeElements.set(0, table); - ArrayList rows = table.getRows(); + List rows = table.getRows(); for (int i = headerRows; i < listIdx; ++i) rows.set(i, null); } @@ -1432,7 +1433,7 @@ else if (k == listIdx && !firstPass && (!table.isSplitRows() || table.isSplitLat } // copy the rows that fit on the page in a new table nt PdfPTable nt = PdfPTable.shallowCopy(table); - ArrayList sub = nt.getRows(); + List sub = nt.getRows(); // first we add the real header rows (if necessary) if (!skipHeader && realHeaderRows > 0) { @@ -1459,7 +1460,7 @@ else if (k == listIdx && !firstPass && (!table.isSplitRows() || table.isSplitLat float rowHeight = 0; int index = sub.size() - 1; if (showFooter) index -= footerRows; - PdfPRow last = (PdfPRow)sub.get(index); + PdfPRow last = sub.get(index); if (table.isExtendLastRow(newPageFollows)) { rowHeight = last.getMaxHeights(); last.setMaxHeights(yTemp - minY + rowHeight); @@ -1488,7 +1489,7 @@ else if (table.isExtendLastRow() && minY > PdfPRow.BOTTOM_LIMIT) } else { if (splittedRow) { - ArrayList rows = table.getRows(); + List rows = table.getRows(); for (int i = listIdx; i < k; ++i) rows.set(i, null); } @@ -1559,7 +1560,7 @@ public PdfContentByte[] getCanvases() { * @since 2.1.2 */ public boolean zeroHeightElement() { - return composite && !compositeElements.isEmpty() && ((Element)compositeElements.getFirst()).type() == Element.YMARK; + return composite && !compositeElements.isEmpty() && compositeElements.getFirst().type() == Element.YMARK; } /** diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfCell.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfCell.java index 320fc0f84..aa172b991 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfCell.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfCell.java @@ -88,7 +88,7 @@ public class PdfCell extends Rectangle { /** * These are the PdfLines in the Cell. */ - private ArrayList lines; + private java.util.List lines; /** * These are the PdfLines in the Cell. @@ -98,7 +98,7 @@ public class PdfCell extends Rectangle { /** * These are the Images in the Cell. */ - private ArrayList images; + private java.util.List images; /** * This is the leading of the lines. @@ -187,8 +187,8 @@ public PdfCell(Cell cell, int rownumber, float left, float right, float top, flo PdfChunk chunk; Element element; PdfChunk overflow; - lines = new ArrayList(); - images = new ArrayList(); + lines = new ArrayList<>(); + images = new ArrayList<>(); leading = cell.getLeading(); int alignment = cell.getHorizontalAlignment(); left += cellspacing + cellpadding; @@ -202,7 +202,7 @@ public PdfCell(Cell cell, int rownumber, float left, float right, float top, flo rowspan = cell.getRowspan(); - ArrayList allActions; + java.util.List allActions; int aCounter; // we loop over all the elements of the cell for (Iterator i = cell.getElements(); i.hasNext();) { @@ -227,7 +227,7 @@ public PdfCell(Cell cell, int rownumber, float left, float right, float top, flo break; // if the element is something else default: - allActions = new ArrayList(); + allActions = new ArrayList<>(); processActions(element, null, allActions); aCounter = 0; @@ -246,7 +246,7 @@ public PdfCell(Cell cell, int rownumber, float left, float right, float top, flo line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading); } // we loop over the chunks - ArrayList chunks = element.getChunks(); + java.util.List chunks = element.getChunks(); if (chunks.isEmpty()) { addLine(line); // add empty line - all cells need some lines even if they are empty line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading); @@ -254,7 +254,7 @@ public PdfCell(Cell cell, int rownumber, float left, float right, float top, flo else { for (Object chunk1 : chunks) { Chunk c = (Chunk) chunk1; - chunk = new PdfChunk(c, (PdfAction) (allActions.get(aCounter++))); + chunk = new PdfChunk(c, (allActions.get(aCounter++))); while ((overflow = line.add(chunk)) != null) { addLine(line); line = new PdfLine(currentLeft, currentRight, alignment, currentLineLeading); @@ -281,7 +281,7 @@ public PdfCell(Cell cell, int rownumber, float left, float right, float top, flo String more = cell.getShowTruncation(); if (more != null && more.length() > 0) { // Denote that the content has been truncated - lastLine = (PdfLine) lines.get(lines.size() - 1); + lastLine = lines.get(lines.size() - 1); if (lastLine.size() >= 0) { PdfChunk lastChunk = lastLine.getChunk(lastLine.size() - 1); float moreWidth = new PdfChunk(more, lastChunk).width(); @@ -303,7 +303,7 @@ public PdfCell(Cell cell, int rownumber, float left, float right, float top, flo // adjust first line height so that it touches the top if (!lines.isEmpty()) { - firstLine = (PdfLine) lines.get(0); + firstLine = lines.get(0); float firstLineRealHeight = firstLineRealHeight(); contentHeight -= firstLine.height(); firstLine.height = firstLineRealHeight; @@ -320,7 +320,7 @@ public PdfCell(Cell cell, int rownumber, float left, float right, float top, flo private void addList(List list, float left, float right, int alignment) { PdfChunk chunk; PdfChunk overflow; - ArrayList allActions = new ArrayList(); + java.util.List allActions = new ArrayList<>(); processActions(list, null, allActions); int aCounter = 0; for (Object o1 : list.getItems()) { @@ -331,7 +331,7 @@ private void addList(List list, float left, float right, int alignment) { line = new PdfLine(left + item.getIndentationLeft(), right, alignment, item.getLeading()); line.setListItem(item); for (Object o : item.getChunks()) { - chunk = new PdfChunk((Chunk) o, (PdfAction) (allActions.get(aCounter++))); + chunk = new PdfChunk((Chunk) o, allActions.get(aCounter++)); while ((overflow = line.add(chunk)) != null) { addLine(line); line = new PdfLine(left + item.getIndentationLeft(), right, alignment, item.getLeading()); @@ -437,11 +437,11 @@ private void addLine(PdfLine line) { } private PdfLine removeLine(int index) { - PdfLine oldLine = (PdfLine) lines.remove(index); + PdfLine oldLine = lines.remove(index); contentHeight -= oldLine.height(); if (index == 0) { if (!lines.isEmpty()) { - firstLine = (PdfLine) lines.get(0); + firstLine = lines.get(0); float firstLineRealHeight = firstLineRealHeight(); contentHeight -= firstLine.height(); firstLine.height = firstLineRealHeight; @@ -562,11 +562,11 @@ private float addImage(Image i, float left, float right, float extraHeight, int * @return an ArrayList of PdfLines */ - public ArrayList getLines(float top, float bottom) { + public java.util.List getLines(float top, float bottom) { float lineHeight; float currentPosition = Math.min(getTop(), top); setTop(currentPosition + cellspacing); - ArrayList result = new ArrayList(); + java.util.List result = new ArrayList<>(); // if the bottom of the page is higher than the top of the cell: do nothing if (getTop() < bottom) { @@ -577,7 +577,7 @@ public ArrayList getLines(float top, float bottom) { int size = lines.size(); boolean aboveBottom = true; for (int i = 0; i < size && aboveBottom; i++) { - line = (PdfLine) lines.get(i); + line = lines.get(i); lineHeight = line.height(); currentPosition -= lineHeight; // if the currentPosition is higher than the bottom, we add the line to the result @@ -591,7 +591,7 @@ public ArrayList getLines(float top, float bottom) { float difference = 0f; if (!header) { if (aboveBottom) { - lines = new ArrayList(); + lines = new ArrayList<>(); contentHeight = 0f; } else { size = result.size(); @@ -602,9 +602,7 @@ public ArrayList getLines(float top, float bottom) { } } if (difference > 0) { - Image image; - for (Object image1 : images) { - image = (Image) image1; + for (Image image : images) { image.setAbsolutePosition(image.getAbsoluteX(), image.getAbsoluteY() - difference - leading); } } @@ -621,20 +619,20 @@ public ArrayList getLines(float top, float bottom) { * @return an ArrayList of Images */ - public ArrayList getImages(float top, float bottom) { + public java.util.List getImages(float top, float bottom) { // if the bottom of the page is higher than the top of the cell: do nothing if (getTop() < bottom) { - return new ArrayList(); + return new ArrayList<>(); } top = Math.min(getTop(), top); // initializations Image image; float height; - ArrayList result = new ArrayList(); + java.util.List result = new ArrayList<>(); // we loop over the images - for (Iterator i = images.iterator(); i.hasNext() && !header;) { - image = (Image) i.next(); + for (Iterator i = images.iterator(); i.hasNext() && !header;) { + image = i.next(); height = image.getAbsoluteY(); // if the currentPosition is higher than the bottom, we add the line to the result if (top - height > (bottom + cellpadding)) { @@ -778,7 +776,7 @@ public float cellpadding() { * @param allActions */ - protected void processActions(Element element, PdfAction action, ArrayList allActions) { + protected void processActions(Element element, PdfAction action, java.util.List allActions) { if (element.type() == Element.ANCHOR) { String url = ((Anchor) element).getReference(); if (url != null) { diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfDocument.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfDocument.java index 87954b4dd..0fcc87952 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfDocument.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfDocument.java @@ -58,11 +58,8 @@ import com.lowagie.text.Element; import com.lowagie.text.ExceptionConverter; import com.lowagie.text.Font; -import com.lowagie.text.Font; import com.lowagie.text.HeaderFooter; import com.lowagie.text.Image; -import com.lowagie.text.Image; -import com.lowagie.text.List; import com.lowagie.text.List; import com.lowagie.text.ListItem; import com.lowagie.text.MarkedObject; @@ -71,7 +68,6 @@ import com.lowagie.text.Paragraph; import com.lowagie.text.Phrase; import com.lowagie.text.Rectangle; -import com.lowagie.text.Rectangle; import com.lowagie.text.Section; import com.lowagie.text.SimpleTable; import com.lowagie.text.Table; @@ -267,7 +263,7 @@ static class PdfCatalog extends PdfDictionary { * @param documentFileAttachment the attached files * @param writer the writer the catalog applies to */ - void addNames(TreeMap localDestinations, HashMap documentLevelJS, HashMap documentFileAttachment, PdfWriter writer) { + void addNames(TreeMap localDestinations, Map documentLevelJS, Map documentFileAttachment, PdfWriter writer) { if (localDestinations.isEmpty() && documentLevelJS.isEmpty() && documentFileAttachment.isEmpty()) return; try { @@ -1208,7 +1204,7 @@ protected void initPage() throws DocumentException { protected PdfLine line = null; /** The lines that are written until now. */ - protected ArrayList lines = new ArrayList<>(); + protected java.util.List lines = new ArrayList<>(); /** * Adds the current line to the list of lines and also adds an empty line. @@ -1342,7 +1338,7 @@ protected float flushLines() throws DocumentException { text.moveText(-moveTextX, 0); } - lines = new ArrayList(); + lines = new ArrayList<>(); return displacement; } @@ -2559,7 +2555,8 @@ protected static class RenderingContext { Map rowspanMap = new HashMap<>(); // Possible keys and values are Set or Integer. Really? - Map pageMap = new HashMap<>(); + Map pageMap = new HashMap<>(); + Map> pageCellSetMap = new HashMap<>(); /** * A PdfPTable @@ -2605,7 +2602,7 @@ public int currentRowspan(PdfCell c) { } public int cellRendered(PdfCell cell, int pageNumber) { - Integer i = (Integer) pageMap.get(cell); + Integer i = pageMap.get(cell); if (i == null) { i = 1; } else { @@ -2614,20 +2611,14 @@ public int cellRendered(PdfCell cell, int pageNumber) { pageMap.put(cell, i); Integer pageInteger = pageNumber; - Set set = (Set) pageMap.get(pageInteger); - - if (set == null) { - set = new HashSet(); - pageMap.put(pageInteger, set); - } - + Set set = pageCellSetMap.computeIfAbsent(pageInteger, k -> new HashSet<>()); set.add(cell); return i; } public int numCellRendered(PdfCell cell) { - Integer i = (Integer) pageMap.get(cell); + Integer i = pageMap.get(cell); if (i == null) { i = 0; } @@ -2636,7 +2627,7 @@ public int numCellRendered(PdfCell cell) { public boolean isCellRenderedOnPage(PdfCell cell, int pageNumber) { Integer pageInteger = pageNumber; - Set set = (Set) pageMap.get(pageInteger); + Set set = pageCellSetMap.get(pageInteger); if (set != null) { return set.contains(cell); @@ -2668,9 +2659,9 @@ private void addPdfTable(Table t) throws DocumentException { PdfCell cell; // drawing the table - ArrayList headercells = table.getHeaderCells(); - ArrayList cells = table.getCells(); - ArrayList rows = extractRows(cells, ctx); + java.util.List headerCells = table.getHeaderCells(); + java.util.List cells = table.getCells(); + java.util.List> rows = extractRows(cells, ctx); boolean isContinue = false; while (!cells.isEmpty()) { // initialization of some extra parameters; @@ -2680,11 +2671,11 @@ private void addPdfTable(Table t) throws DocumentException { boolean cellsShown = false; // draw the cells (line by line) - Iterator iterator = rows.iterator(); + Iterator> iterator = rows.iterator(); boolean atLeastOneFits = false; while (iterator.hasNext()) { - ArrayList row = (ArrayList) iterator.next(); + java.util.List row = iterator.next(); analyzeRow(rows, ctx); renderCells(ctx, row, table.hasToFitPageCells() & atLeastOneFits); @@ -2776,14 +2767,14 @@ private void addPdfTable(Table t) throws DocumentException { } // this part repeats the table headers (if any) - int size = headercells.size(); + int size = headerCells.size(); if (size > 0) { // this is the top of the headersection - cell = (PdfCell) headercells.get(0); + cell = headerCells.get(0); float oldTop = cell.getTop(0); // loop over all the cells of the table header for (int i = 0; i < size; i++) { - cell = (PdfCell) headercells.get(i); + cell = headerCells.get(i); // calculation of the new cellpositions cell.setTop(indentTop() - oldTop + cell.getTop(0)); cell.setBottom(indentTop() - oldTop + cell.getBottom(0)); @@ -2791,7 +2782,7 @@ private void addPdfTable(Table t) throws DocumentException { // we paint the borders of the cell ctx.cellGraphics.rectangle(cell.rectangle(indentTop(), indentBottom())); // we write the text of the cell - ArrayList images = cell.getImages(indentTop(), indentBottom()); + java.util.List images = cell.getImages(indentTop(), indentBottom()); for (Object image1 : images) { cellsShown = true; Image image = (Image) image1; @@ -2819,7 +2810,7 @@ private void addPdfTable(Table t) throws DocumentException { size = Math.min(cells.size(), table.columns()); int i = 0; while (i < size) { - cell = (PdfCell) cells.get(i); + cell = cells.get(i); if (cell.getTop(-table.cellspacing()) > ctx.lostTableBottom) { float newBottom = ctx.pagetop - difference + cell.getBottom(); float neededHeight = cell.remainingHeight(); @@ -2833,7 +2824,7 @@ private void addPdfTable(Table t) throws DocumentException { table.setTop(indentTop()); table.setBottom(ctx.pagetop - difference + table.getBottom(table.cellspacing())); for (i = 0; i < size; i++) { - cell = (PdfCell) cells.get(i); + cell = cells.get(i); float newBottom = ctx.pagetop - difference + cell.getBottom(); float newTop = ctx.pagetop - difference + cell.getTop(-table.cellspacing()); if (newTop > indentTop() - currentHeight) { @@ -2860,17 +2851,17 @@ private void addPdfTable(Table t) throws DocumentException { pageEmpty = false; } - protected void analyzeRow(ArrayList rows, RenderingContext ctx) { + protected void analyzeRow(java.util.List> rows, RenderingContext ctx) { ctx.maxCellBottom = indentBottom(); // determine whether row(index) is in a rowspan int rowIndex = 0; - ArrayList row = (ArrayList) rows.get(rowIndex); + java.util.List row = rows.get(rowIndex); int maxRowspan = 1; - Iterator iterator = row.iterator(); + Iterator iterator = row.iterator(); while (iterator.hasNext()) { - PdfCell cell = (PdfCell) iterator.next(); + PdfCell cell = iterator.next(); maxRowspan = Math.max(ctx.currentRowspan(cell), maxRowspan); } rowIndex += maxRowspan; @@ -2883,10 +2874,10 @@ protected void analyzeRow(ArrayList rows, RenderingContext ctx) { if (rowIndex < 0 || rowIndex >= rows.size()) return; - row = (ArrayList) rows.get(rowIndex); + row = rows.get(rowIndex); iterator = row.iterator(); while (iterator.hasNext()) { - PdfCell cell = (PdfCell) iterator.next(); + PdfCell cell = iterator.next(); Rectangle cellRect = cell.rectangle(ctx.pagetop, indentBottom()); if (useTop) { ctx.maxCellBottom = Math.max(ctx.maxCellBottom, cellRect.getTop()); @@ -2898,33 +2889,32 @@ protected void analyzeRow(ArrayList rows, RenderingContext ctx) { } } - protected boolean mayBeRemoved(ArrayList row) { - Iterator iterator = row.iterator(); + protected boolean mayBeRemoved(java.util.List row) { + Iterator iterator = row.iterator(); boolean mayBeRemoved = true; while (iterator.hasNext()) { - PdfCell cell = (PdfCell) iterator.next(); + PdfCell cell = iterator.next(); mayBeRemoved &= cell.mayBeRemoved(); } return mayBeRemoved; } - protected void consumeRowspan(ArrayList row, RenderingContext ctx) { - for (Object o : row) { - PdfCell c = (PdfCell) o; + protected void consumeRowspan(java.util.List row, RenderingContext ctx) { + for (PdfCell c : row) { ctx.consumeRowspan(c); } } - protected ArrayList extractRows(ArrayList cells, RenderingContext ctx) { + protected java.util.List> extractRows(java.util.List cells, RenderingContext ctx) { PdfCell cell; PdfCell previousCell = null; - ArrayList rows = new ArrayList(); + java.util.List> rows = new ArrayList<>(); java.util.List rowCells = new ArrayList<>(); - Iterator iterator = cells.iterator(); + Iterator iterator = cells.iterator(); while (iterator.hasNext()) { - cell = (PdfCell) iterator.next(); + cell = iterator.next(); boolean isAdded = false; @@ -2949,7 +2939,7 @@ protected ArrayList extractRows(ArrayList cells, RenderingContext ctx) { } // start a new list for next line - rowCells = new ArrayList(); + rowCells = new ArrayList<>(); } if (!isAdded) { @@ -2965,14 +2955,14 @@ protected ArrayList extractRows(ArrayList cells, RenderingContext ctx) { // fill row information with rowspan cells to get complete "scan lines" for (int i = rows.size() - 1; i >= 0; i--) { - ArrayList row = (ArrayList) rows.get(i); + java.util.List row = rows.get(i); // iterator through row for (int j = 0; j < row.size(); j++) { - PdfCell c = (PdfCell) row.get(j); + PdfCell c = row.get(j); int rowspan = c.rowspan(); // fill in missing rowspan cells to complete "scan line" for (int k = 1; k < rowspan && rows.size() < i+k; k++) { - ArrayList spannedRow = ((ArrayList) rows.get(i + k)); + java.util.List spannedRow = rows.get(i + k); if (spannedRow.size() > j) spannedRow.add(j, c); } @@ -3034,7 +3024,7 @@ protected void renderCells(RenderingContext ctx, java.util.List cells, boolean h } // and additional graphics - ArrayList images = cell.getImages(ctx.pagetop, indentBottom()); + java.util.List images = cell.getImages(ctx.pagetop, indentBottom()); for (Object image1 : images) { Image image = (Image) image1; graphics.addImage(image); diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfGraphics2D.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfGraphics2D.java index 9ee6b15b1..f2f61a6c2 100755 --- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfGraphics2D.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfGraphics2D.java @@ -97,6 +97,7 @@ import java.util.HashMap; import java.util.Hashtable; import java.util.Map; +import java.util.Objects; import java.util.Set; import com.lowagie.text.pdf.internal.PolylineShape; @@ -377,29 +378,32 @@ public void drawString(String s, float x, float y) { cb.beginText(); cb.setFontAndSize(baseFont, fontSize); // Check if we need to simulate an italic font. - // When there are different fonts for italic, bold, italic bold - // the font.getName() will be different from the font.getFontName() - // value. When they are the same value then we are normally dealing - // with a single font that has been made into an italic or bold - // font. - if (font.isItalic() && font.getFontName().equals(font.getName())) { - float angle = baseFont.getFontDescriptor(BaseFont.ITALICANGLE, 1000); - float angle2 = font.getItalicAngle(); - // We don't have an italic version of this font so we need - // to set the font angle ourselves to produce an italic font. - if (angle2 == 0) { - // The JavaVM didn't have an angle setting for making - // the font an italic font so use a default of - // italic angle of 15 degrees. - angle2 = 15.0f; - } else { - // This sign of the angle for Java and PDF seams - // seams to be reversed. - angle2 = -angle2; - } - if (angle == 0) { - mx[2] = angle2 / 100.0f; - } + if (font.isItalic()) { + float angle = baseFont.getFontDescriptor(BaseFont.ITALICANGLE, 1000); + float angle2 = font.getItalicAngle(); + // When there are different fonts for italic, bold, italic bold + // the font.getName() will be different from the font.getFontName() + // value. When they are the same value then we are normally dealing + // with a single font that has been made into an italic or bold + // font. When there are only a plain and a bold font available, + // we need to enter this logic too. + if (Objects.equals(font.getFontName(), font.getName()) || (angle == 0f && angle2 == 0f)) { + // We don't have an italic version of this font so we need + // to set the font angle ourselves to produce an italic font. + if (angle2 == 0) { + // The JavaVM didn't have an angle setting for making + // the font an italic font so use a default of + // italic angle of 15 degrees. + angle2 = 15.0f; + } else { + // This sign of the angle for Java and PDF seams + // seams to be reversed. + angle2 = -angle2; + } + if (angle == 0) { + mx[2] = angle2 / 100.0f; + } + } } cb.setTextMatrix((float)mx[0], (float)mx[1], (float)mx[2], (float)mx[3], (float)mx[4], (float)mx[5]); Float fontTextAttributeWidth = (Float)font.getAttributes().get(TextAttribute.WIDTH); diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfIndirectReference.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfIndirectReference.java index c4b81a54b..5e2e7a810 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfIndirectReference.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfIndirectReference.java @@ -88,7 +88,7 @@ protected PdfIndirectReference() { */ PdfIndirectReference(int type, int number, int generation) { - super(0, new StringBuffer().append(number).append(" ").append(generation).append(" R").toString()); + super(0, number + " " + generation + " R"); this.number = number; this.generation = generation; } diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/PdfNameTree.java b/openpdf/src/main/java/com/lowagie/text/pdf/PdfNameTree.java index 8f2955bdf..117de818f 100755 --- a/openpdf/src/main/java/com/lowagie/text/pdf/PdfNameTree.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/PdfNameTree.java @@ -49,6 +49,7 @@ import java.io.IOException; import java.util.Arrays; import java.util.HashMap; +import java.util.Map; /** * Creates a name tree. @@ -69,19 +70,18 @@ public class PdfNameTree { * @return the dictionary with the name tree. This dictionary is the one generally pointed to by the key /Dests, for example * @throws IOException on error */ - public static PdfDictionary writeTree(HashMap items, PdfWriter writer) throws IOException { + public static PdfDictionary writeTree(Map items, PdfWriter writer) throws IOException { if (items.isEmpty()) { return null; } - String[] names = new String[items.size()]; - names = (String[]) items.keySet().toArray(names); + String[] names = items.keySet().toArray(new String[0]); Arrays.sort(names); if (names.length <= leafSize) { PdfDictionary dic = new PdfDictionary(); PdfArray ar = new PdfArray(); for (String name : names) { ar.add(new PdfString(name, null)); - ar.add((PdfObject) items.get(name)); + ar.add(items.get(name)); } dic.put(PdfName.NAMES, ar); return dic; @@ -99,7 +99,7 @@ public static PdfDictionary writeTree(HashMap items, PdfWriter writer) throws IO arr = new PdfArray(); for (; offset < end; ++offset) { arr.add(new PdfString(names[offset], null)); - arr.add((PdfObject) items.get(names[offset])); + arr.add(items.get(names[offset])); } dic.put(PdfName.NAMES, arr); kids[k] = writer.addToBody(dic).getIndirectReference(); diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/codec/wmf/MetaState.java b/openpdf/src/main/java/com/lowagie/text/pdf/codec/wmf/MetaState.java index 634f3596c..415ce75bb 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/codec/wmf/MetaState.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/codec/wmf/MetaState.java @@ -52,6 +52,7 @@ import java.awt.Color; import java.awt.Point; import java.util.ArrayList; +import java.util.List; import java.util.Stack; import com.lowagie.text.pdf.PdfContentByte; @@ -73,8 +74,8 @@ public class MetaState { public static final int ALTERNATE = 1; public static final int WINDING = 2; - public Stack savedStates; - public ArrayList MetaObjects; + public Stack savedStates; + public List MetaObjects; public Point currentPoint; public MetaPen currentPen; public MetaBrush currentBrush; @@ -95,8 +96,8 @@ public class MetaState { /** Creates new MetaState */ public MetaState() { - savedStates = new Stack(); - MetaObjects = new ArrayList(); + savedStates = new Stack<>(); + MetaObjects = new ArrayList<>(); currentPoint = new Point(0, 0); currentPen = new MetaPen(); currentBrush = new MetaBrush(); @@ -213,7 +214,7 @@ public void restoreState(int index, PdfContentByte cb) { MetaState state = null; while (pops-- != 0) { cb.restoreState(); - state = (MetaState)savedStates.pop(); + state = savedStates.pop(); } setMetaState(state); } diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/crypto/AESCipher.java b/openpdf/src/main/java/com/lowagie/text/pdf/crypto/AESCipher.java index ae45c6139..d48008f6e 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/crypto/AESCipher.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/crypto/AESCipher.java @@ -49,7 +49,7 @@ package com.lowagie.text.pdf.crypto; import org.bouncycastle.crypto.BlockCipher; -import org.bouncycastle.crypto.engines.AESFastEngine; +import org.bouncycastle.crypto.engines.AESEngine; import org.bouncycastle.crypto.modes.CBCBlockCipher; import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher; import org.bouncycastle.crypto.params.KeyParameter; @@ -65,7 +65,7 @@ public class AESCipher { /** Creates a new instance of AESCipher */ public AESCipher(boolean forEncryption, byte[] key, byte[] iv) { - BlockCipher aes = new AESFastEngine(); + BlockCipher aes = new AESEngine(); BlockCipher cbc = new CBCBlockCipher(aes); bp = new PaddedBufferedBlockCipher(cbc); KeyParameter kp = new KeyParameter(key); diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/events/FieldPositioningEvents.java b/openpdf/src/main/java/com/lowagie/text/pdf/events/FieldPositioningEvents.java index 6d43f6bb3..6f5377431 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/events/FieldPositioningEvents.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/events/FieldPositioningEvents.java @@ -48,6 +48,8 @@ import java.io.IOException; import java.util.HashMap; +import java.util.Map; + import com.lowagie.text.error_messages.MessageLocalization; import com.lowagie.text.Document; @@ -73,7 +75,7 @@ public class FieldPositioningEvents extends PdfPageEventHelper implements PdfPCe /** * Keeps a map with fields that are to be positioned in inGenericTag. */ - protected HashMap genericChunkFields = new HashMap(); + protected Map genericChunkFields = new HashMap<>(); /** * Keeps the form field that is to be positioned in a cellLayout event. @@ -153,7 +155,7 @@ public void setParent(PdfFormField parent) { public void onGenericTag(PdfWriter writer, Document document, Rectangle rect, String text) { rect.setBottom(rect.getBottom() - 3); - PdfFormField field = (PdfFormField) genericChunkFields.get(text); + PdfFormField field = genericChunkFields.get(text); if (field == null) { TextField tf = new TextField(writer, new Rectangle(rect.getLeft(padding), rect.getBottom(padding), rect.getRight(padding), rect.getTop(padding)), text); tf.setFontSize(14); diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/events/IndexEvents.java b/openpdf/src/main/java/com/lowagie/text/pdf/events/IndexEvents.java index 49d709ade..9f3e1a942 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/events/IndexEvents.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/events/IndexEvents.java @@ -69,7 +69,7 @@ public class IndexEvents extends PdfPageEventHelper { /** * keeps the indextag with the pagenumber */ - private Map indextag = new TreeMap(); + private Map indextag = new TreeMap<>(); /** * All the text that is passed to this event, gets registered in the indexentry. @@ -92,7 +92,7 @@ public void onGenericTag(PdfWriter writer, Document document, /** * the list for the index entry */ - private List indexentry = new ArrayList(); + private List indexentry = new ArrayList<>(); /** * Create an index entry. @@ -180,9 +180,7 @@ public void create(final Chunk text, final String in1, final String in2) { /** * Comparator for sorting the index */ - private Comparator comparator = (arg0, arg1) -> { - Entry en1 = (Entry) arg0; - Entry en2 = (Entry) arg1; + private Comparator comparator = (en1, en2) -> { int rt = 0; if (en1.getIn1() != null && en2.getIn1() != null) { @@ -207,7 +205,7 @@ public void create(final Chunk text, final String in1, final String in2) { * Set the comparator. * @param aComparator The comparator to set. */ - public void setComparator(Comparator aComparator) { + public void setComparator(Comparator aComparator) { comparator = aComparator; } @@ -215,15 +213,14 @@ public void setComparator(Comparator aComparator) { * Returns the sorted list with the entries and the collected page numbers. * @return Returns the sorted list with the entries and the collected page numbers. */ - public List getSortedEntries() { + public List getSortedEntries() { - Map grouped = new HashMap(); + Map grouped = new HashMap<>(); - for (Object o : indexentry) { - Entry e = (Entry) o; + for (Entry e : indexentry) { String key = e.getKey(); - Entry master = (Entry) grouped.get(key); + Entry master = grouped.get(key); if (master != null) { master.addPageNumberAndTag(e.getPageNumber(), e.getTag()); } else { @@ -233,7 +230,7 @@ public List getSortedEntries() { } // copy to a list and sort it - List sorted = new ArrayList(grouped.values()); + List sorted = new ArrayList<>(grouped.values()); sorted.sort(comparator); return sorted; } @@ -271,12 +268,12 @@ public class Entry { /** * the list of all page numbers. */ - private List pagenumbers = new ArrayList(); + private List pagenumbers = new ArrayList<>(); /** * the list of all tags. */ - private List tags = new ArrayList(); + private List tags = new ArrayList<>(); /** * Create a new object. @@ -331,7 +328,7 @@ public String getTag() { */ public int getPageNumber() { int rt = -1; - Integer i = (Integer) indextag.get(tag); + Integer i = indextag.get(tag); if (i != null) { rt = i; } diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/events/PdfPCellEventForwarder.java b/openpdf/src/main/java/com/lowagie/text/pdf/events/PdfPCellEventForwarder.java index dec23c9c3..e9e7a1f73 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/events/PdfPCellEventForwarder.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/events/PdfPCellEventForwarder.java @@ -50,6 +50,7 @@ package com.lowagie.text.pdf.events; import java.util.ArrayList; +import java.util.List; import com.lowagie.text.Rectangle; import com.lowagie.text.pdf.PdfContentByte; @@ -66,7 +67,7 @@ public class PdfPCellEventForwarder implements PdfPCellEvent { /** ArrayList containing all the PageEvents that have to be executed. */ - protected ArrayList events = new ArrayList(); + protected List events = new ArrayList<>(); /** * Add a page event to the forwarder. diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/events/PdfPTableEventForwarder.java b/openpdf/src/main/java/com/lowagie/text/pdf/events/PdfPTableEventForwarder.java index b8ba1daf4..d55194df9 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/events/PdfPTableEventForwarder.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/events/PdfPTableEventForwarder.java @@ -50,6 +50,7 @@ package com.lowagie.text.pdf.events; import java.util.ArrayList; +import java.util.List; import com.lowagie.text.pdf.PdfContentByte; import com.lowagie.text.pdf.PdfPTable; @@ -65,7 +66,7 @@ public class PdfPTableEventForwarder implements PdfPTableEvent { /** ArrayList containing all the PageEvents that have to be executed. */ - protected ArrayList events = new ArrayList(); + protected List events = new ArrayList<>(); /** * Add a page event to the forwarder. diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/events/PdfPageEventForwarder.java b/openpdf/src/main/java/com/lowagie/text/pdf/events/PdfPageEventForwarder.java index c692bc1ff..a62e3ddd7 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/events/PdfPageEventForwarder.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/events/PdfPageEventForwarder.java @@ -50,6 +50,7 @@ package com.lowagie.text.pdf.events; import java.util.ArrayList; +import java.util.List; import com.lowagie.text.Document; import com.lowagie.text.Paragraph; @@ -67,7 +68,7 @@ public class PdfPageEventForwarder implements PdfPageEvent { /** ArrayList containing all the PageEvents that have to be executed. */ - protected ArrayList events = new ArrayList(); + protected List events = new ArrayList<>(); /** * Add a page event to the forwarder. diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/fonts/cmaps/CMap.java b/openpdf/src/main/java/com/lowagie/text/pdf/fonts/cmaps/CMap.java index 4c362a19b..f61828649 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/fonts/cmaps/CMap.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/fonts/cmaps/CMap.java @@ -46,9 +46,9 @@ */ public class CMap { - private List codeSpaceRanges = new ArrayList(); - private Map singleByteMappings = new HashMap(); - private Map doubleByteMappings = new HashMap(); + private List codeSpaceRanges = new ArrayList<>(); + private Map singleByteMappings = new HashMap<>(); + private Map doubleByteMappings = new HashMap<>(); /** * Creates a new instance of CMap. @@ -90,10 +90,10 @@ public String lookup(char code) { String result = null; if (hasTwoByteMappings()) { - result = (String) doubleByteMappings.get((int) code); + result = doubleByteMappings.get((int) code); } if (result == null && code <= 0xff && hasOneByteMappings()) { - result = (String) singleByteMappings.get(code & 0xff); + result = singleByteMappings.get(code & 0xff); } return result; } @@ -116,7 +116,7 @@ public String lookup( byte[] code, int offset, int length ) { key = code[offset] & 0xff; - result = (String)singleByteMappings.get( key ); + result = singleByteMappings.get( key ); } else if( length == 2 ) { @@ -125,7 +125,7 @@ else if( length == 2 ) intKey += code[offset+1] & 0xff; key = intKey; - result = (String)doubleByteMappings.get( key ); + result = doubleByteMappings.get( key ); } return result; diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/fonts/cmaps/CMapParser.java b/openpdf/src/main/java/com/lowagie/text/pdf/fonts/cmaps/CMapParser.java index 2068f6ed9..740b87c76 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/fonts/cmaps/CMapParser.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/fonts/cmaps/CMapParser.java @@ -217,7 +217,7 @@ private Object parseNextToken( PushbackInputStream is ) throws IOException } case '[': { - List list = new ArrayList(); + List list = new ArrayList<>(); Object nextToken = parseNextToken( is ); while( nextToken != MARK_END_OF_ARRAY ) @@ -233,7 +233,7 @@ private Object parseNextToken( PushbackInputStream is ) throws IOException int theNextByte = is.read(); if( theNextByte == '<' ) { - Map result = new HashMap(); + Map result = new HashMap<>(); //we are reading a dictionary Object key = parseNextToken( is ); while( key instanceof LiteralName && key != MARK_END_OF_DICTIONARY ) diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/HyphenationTree.java b/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/HyphenationTree.java index 3696df4eb..008f04f1e 100755 --- a/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/HyphenationTree.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/HyphenationTree.java @@ -21,6 +21,8 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.util.Map; /** * This tree structure stores the hyphenation patterns in an efficient @@ -42,7 +44,7 @@ public class HyphenationTree extends TernaryTree /** * This map stores hyphenation exceptions */ - protected HashMap stoplist; + protected Map stoplist; /** * This map stores the character classes @@ -55,7 +57,7 @@ public class HyphenationTree extends TernaryTree private transient TernaryTree ivalues; public HyphenationTree() { - stoplist = new HashMap(23); // usually a small table + stoplist = new HashMap<>(23); // usually a small table classmap = new TernaryTree(); vspace = new ByteVector(); vspace.alloc(1); // this reserves index 0, which we don't use diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/Hyphenator.java b/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/Hyphenator.java index c5f2328cc..25b8d4393 100755 --- a/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/Hyphenator.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/Hyphenator.java @@ -20,6 +20,7 @@ import java.io.FileInputStream; import java.io.InputStream; import java.util.Hashtable; +import java.util.Map; import com.lowagie.text.pdf.BaseFont; @@ -32,7 +33,7 @@ public class Hyphenator { /** TODO: Don't use statics */ - private static Hashtable hyphenTrees = new Hashtable(); + private static Map hyphenTrees = new Hashtable<>(); private HyphenationTree hyphenTree = null; private int remainCharCount = 2; @@ -69,10 +70,10 @@ public static HyphenationTree getHyphenationTree(String lang, } // first try to find it in the cache if (hyphenTrees.containsKey(key)) { - return (HyphenationTree)hyphenTrees.get(key); + return hyphenTrees.get(key); } if (hyphenTrees.containsKey(lang)) { - return (HyphenationTree)hyphenTrees.get(lang); + return hyphenTrees.get(lang); } HyphenationTree hTree = getResourceHyphenationTree(key); diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/SimplePatternParser.java b/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/SimplePatternParser.java index 258d87043..c83afbcee 100644 --- a/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/SimplePatternParser.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/SimplePatternParser.java @@ -60,6 +60,7 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.StringTokenizer; @@ -75,7 +76,7 @@ public class SimplePatternParser implements SimpleXMLDocHandler, StringBuffer token; - ArrayList exception; + List exception; char hyphenChar; @@ -120,8 +121,8 @@ protected static String getPattern(String word) { return pat.toString(); } - protected ArrayList normalizeException(ArrayList ex) { - ArrayList res = new ArrayList(); + protected List normalizeException(List ex) { + List res = new ArrayList<>(); for (Object item : ex) { if (item instanceof String) { String str = (String) item; @@ -150,7 +151,7 @@ protected ArrayList normalizeException(ArrayList ex) { return res; } - protected String getExceptionWord(ArrayList ex) { + protected String getExceptionWord(List ex) { StringBuilder res = new StringBuilder(); for (Object item : ex) { if (item instanceof String) { @@ -194,7 +195,7 @@ public void endElement(String tag) { exception.add(word); exception = normalizeException(exception); consumer.addException(getExceptionWord(exception), - (ArrayList) exception.clone()); + (ArrayList) ((ArrayList) exception).clone()); break; case ELEM_PATTERNS: consumer.addPattern(getPattern(word), @@ -224,6 +225,7 @@ public void startDocument() { */ @Override @Deprecated + @SuppressWarnings("unchecked") public void startElement(String tag, HashMap h) { startElement(tag, ((Map) h)); } @@ -245,7 +247,7 @@ public void startElement(String tag, Map h) { break; case "exceptions": currElement = ELEM_EXCEPTIONS; - exception = new ArrayList(); + exception = new ArrayList<>(); break; case "hyphen": if (token.length() > 0) { @@ -271,7 +273,7 @@ public void text(String str) { exception.add(word); exception = normalizeException(exception); consumer.addException(getExceptionWord(exception), - (ArrayList) exception.clone()); + (ArrayList)((ArrayList) exception).clone()); exception.clear(); break; case ELEM_PATTERNS: diff --git a/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/TernaryTree.java b/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/TernaryTree.java index ed276cd7c..b5e851da0 100755 --- a/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/TernaryTree.java +++ b/openpdf/src/main/java/com/lowagie/text/pdf/hyphenation/TernaryTree.java @@ -492,7 +492,7 @@ public Object clone() { /** * Node stack */ - Stack ns; + Stack ns; /** * key stack implemented with a StringBuffer @@ -501,7 +501,7 @@ public Object clone() { public Iterator() { cur = -1; - ns = new Stack(); + ns = new Stack<>(); ks = new StringBuffer(); rewind(); } @@ -549,17 +549,17 @@ private int up() { boolean climb = true; while (climb) { - i = (Item)ns.pop(); + i = ns.pop(); i.child++; switch (i.child) { case 1: if (sc[i.parent] != 0) { res = eq[i.parent]; - ns.push(i.clone()); + ns.push((Item)i.clone()); ks.append(sc[i.parent]); } else { i.child++; - ns.push(i.clone()); + ns.push((Item)i.clone()); res = hi[i.parent]; } climb = false; @@ -567,7 +567,7 @@ private int up() { case 2: res = hi[i.parent]; - ns.push(i.clone()); + ns.push((Item)i.clone()); if (ks.length() > 0) { ks.setLength(ks.length() - 1); // pop } diff --git a/openpdf/src/main/java/com/lowagie/text/xml/TagMap.java b/openpdf/src/main/java/com/lowagie/text/xml/TagMap.java index 96c1e1eb9..24ab3b167 100644 --- a/openpdf/src/main/java/com/lowagie/text/xml/TagMap.java +++ b/openpdf/src/main/java/com/lowagie/text/xml/TagMap.java @@ -67,7 +67,7 @@ * The Tags-class maps several XHTML-tags to iText-objects. */ -public class TagMap extends HashMap { +public class TagMap extends HashMap { private static final long serialVersionUID = -6809383366554350820L; @@ -155,6 +155,7 @@ class AttributeHandler extends DefaultHandler { * @param tagMap A Hashmap containing XmlPeer-objects */ @Deprecated + @SuppressWarnings("unchecked") public AttributeHandler(HashMap tagMap) { this.tagMap = tagMap; } diff --git a/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/IanaEncodings.java b/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/IanaEncodings.java index fa1030ac0..cb76670b1 100644 --- a/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/IanaEncodings.java +++ b/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/IanaEncodings.java @@ -68,6 +68,7 @@ package com.lowagie.text.xml.simpleparser; import java.util.HashMap; +import java.util.Map; /** * Translates a IANA encoding name to a Java encoding. @@ -76,7 +77,7 @@ public class IanaEncodings { /** The object that maps IANA to Java encodings. */ - private static final HashMap map = new HashMap(); + private static final Map map = new HashMap<>(); static { // add IANA to Java encoding mappings. @@ -279,7 +280,7 @@ public class IanaEncodings { */ public static String getJavaEncoding(String iana) { String IANA = iana.toUpperCase(); - String jdec = (String)map.get(IANA); + String jdec = map.get(IANA); if (jdec == null) jdec = iana; return jdec; diff --git a/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/SimpleXMLParser.java b/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/SimpleXMLParser.java index ee123c32d..220cb432d 100644 --- a/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/SimpleXMLParser.java +++ b/openpdf/src/main/java/com/lowagie/text/xml/simpleparser/SimpleXMLParser.java @@ -72,7 +72,6 @@ * *

*/ -@Deprecated public final class SimpleXMLParser { /** possible states */ private final static int UNKNOWN = 0; @@ -92,7 +91,7 @@ public final class SimpleXMLParser { private final static int ATTRIBUTE_VALUE = 14; /** the state stack */ - Stack stack; + Stack stack; /** The current character. */ int character = 0; /** The previous character. */ @@ -121,7 +120,7 @@ public final class SimpleXMLParser { /** current tagname */ String tag = null; /** current attributes */ - HashMap attributes = null; + Map attributes = null; /** The handler to which we are going to forward document content */ SimpleXMLDocHandler doc; /** The handler to which we are going to forward comments. */ @@ -143,7 +142,7 @@ private SimpleXMLParser(SimpleXMLDocHandler doc, SimpleXMLDocHandlerComment comm this.doc = doc; this.comment = comment; this.html = html; - stack = new Stack(); + stack = new Stack<>(); state = html ? TEXT : UNKNOWN; } @@ -462,7 +461,7 @@ else if(character == quoteCharacter) { */ private int restoreState() { if(!stack.empty()) - return (Integer) stack.pop(); + return stack.pop(); else return UNKNOWN; } @@ -499,7 +498,7 @@ private void flush() { case QUOTE: case ATTRIBUTE_VALUE: attributevalue = text.toString(); - attributes.put(attributekey,attributevalue); + attributes.put(attributekey, attributevalue); break; default: // do nothing @@ -511,7 +510,7 @@ private void flush() { */ private void initTag() { tag = null; - attributes = new HashMap(); + attributes = new HashMap<>(); } /** Sets the name of the tag. */ private void doTag() { @@ -528,7 +527,7 @@ private void doTag() { private void processTag(boolean start) { if (start) { nested++; - doc.startElement(tag, (Map) attributes); + doc.startElement(tag, attributes); } else { nested--; diff --git a/openpdf/src/test/java/com/lowagie/text/pdf/SimplePdfTest.java b/openpdf/src/test/java/com/lowagie/text/pdf/SimplePdfTest.java index e5b508a8a..917882c40 100644 --- a/openpdf/src/test/java/com/lowagie/text/pdf/SimplePdfTest.java +++ b/openpdf/src/test/java/com/lowagie/text/pdf/SimplePdfTest.java @@ -1,5 +1,8 @@ package com.lowagie.text.pdf; +import java.io.File; +import java.io.FileOutputStream; + import com.lowagie.text.Annotation; import com.lowagie.text.Document; import com.lowagie.text.Rectangle; @@ -27,4 +30,19 @@ void testSimplePdf() throws Exception { } + @Test + void testTryWithResources() throws Exception { + try (PdfReader reader = new PdfReader("./src/test/resources/HelloWorldMeta.pdf"); + Document document = new Document(); + FileOutputStream os = new FileOutputStream(File.createTempFile("temp-file-name", ".pdf")); + PdfWriter writer = PdfWriter.getInstance(document, os) + ) { + document.open(); + final PdfContentByte cb = writer.getDirectContent(); + + document.newPage(); + PdfImportedPage page = writer.getImportedPage(reader, 1); + cb.addTemplate(page, 1, 0, 0, 1, 0, 0); + } + } } diff --git a/openpdf/src/test/java/com/lowagie/text/pdf/sign/ExtractCertificatesTest.java b/openpdf/src/test/java/com/lowagie/text/pdf/sign/ExtractCertificatesTest.java index ca95a4925..3128c0a38 100644 --- a/openpdf/src/test/java/com/lowagie/text/pdf/sign/ExtractCertificatesTest.java +++ b/openpdf/src/test/java/com/lowagie/text/pdf/sign/ExtractCertificatesTest.java @@ -15,62 +15,58 @@ public class ExtractCertificatesTest { - public ExtractCertificatesTest() { - super(); - } - - - @Test - public void testSha1() throws Exception { - extract("src/test/resources/sample_signed-sha1.pdf"); - } - - @Test - public void testSha512() throws Exception { - extract("src/test/resources/sample_signed-sha512.pdf"); - } - - private void extract(String pdf) throws Exception { - - // Based in : https://github.com/iromu/pdf-signature-itext/blob/master/src/main/java/crypto/PDFSignature.java - - List certificates = new ArrayList(); - System.out.println("pdf name: " + pdf); - - KeyStore kall = PdfPKCS7.loadCacertsKeyStore(); - - // Cargar pdf - try (PdfReader reader = new PdfReader(pdf)) { - AcroFields fields = reader.getAcroFields(); - - ArrayList signatures = fields.getSignatureNames(); - System.out.println("Signs: " + signatures.size()); - for (String signature : signatures) { - - System.out.println("Signature name: " + signature); - System.out.println("Signature covers whole document: " + fields.signatureCoversWholeDocument(signature)); - System.out.println( - "Document revision: " + fields.getRevision(signature) + " of " + fields.getTotalRevisions()); - - PdfPKCS7 pk = fields.verifySignature(signature); - Calendar cal = pk.getSignDate(); - Certificate pkc[] = pk.getCertificates(); - X509Certificate certificate = pk.getSigningCertificate(); - certificates.add(certificate); - System.out.println("sign date:" + cal.getTime()); - System.out.println("Subject: " + PdfPKCS7.getSubjectFields(certificate)); - System.out.println("Document modified: " + !pk.verify()); - - Object fails[] = PdfPKCS7.verifyCertificates(pkc, kall, null, cal); - if (fails == null) { - System.out.println("Certificates verified against the KeyStore"); - } - else { - System.out.println("Certificate failed: " + fails[1]); - } - - } - } - - } + public ExtractCertificatesTest() { + super(); + } + + + @Test + public void testSha1() throws Exception { + extract("src/test/resources/sample_signed-sha1.pdf"); + } + + @Test + public void testSha512() throws Exception { + extract("src/test/resources/sample_signed-sha512.pdf"); + } + + private void extract(String pdf) throws Exception { + + List certificates = new ArrayList(); + System.out.println("pdf name: " + pdf); + + KeyStore kall = PdfPKCS7.loadCacertsKeyStore(); + + try (PdfReader reader = new PdfReader(pdf)) { + AcroFields fields = reader.getAcroFields(); + + ArrayList signatures = fields.getSignatureNames(); + System.out.println("Signs: " + signatures.size()); + for (String signature : signatures) { + + System.out.println("Signature name: " + signature); + System.out.println("Signature covers whole document: " + fields.signatureCoversWholeDocument(signature)); + System.out.println( + "Document revision: " + fields.getRevision(signature) + " of " + fields.getTotalRevisions()); + + PdfPKCS7 pk = fields.verifySignature(signature); + Calendar cal = pk.getSignDate(); + Certificate[] pkc = pk.getCertificates(); + X509Certificate certificate = pk.getSigningCertificate(); + certificates.add(certificate); + System.out.println("sign date:" + cal.getTime()); + System.out.println("Subject: " + PdfPKCS7.getSubjectFields(certificate)); + System.out.println("Document modified: " + !pk.verify()); + + Object[] fails = PdfPKCS7.verifyCertificates(pkc, kall, null, cal); + if (fails == null) { + System.out.println("Certificates verified against the KeyStore"); + } else { + System.out.println("Certificate failed: " + fails[1]); + } + + } + } + + } } diff --git a/pdf-swing/pom.xml b/pdf-swing/pom.xml index 3bfacc957..2570ca0de 100644 --- a/pdf-swing/pom.xml +++ b/pdf-swing/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 1.2.21-SNAPSHOT + 1.3.0-SNAPSHOT pdf-swing diff --git a/pdf-toolbox/pom.xml b/pdf-toolbox/pom.xml index df8a01da1..e160bf561 100644 --- a/pdf-toolbox/pom.xml +++ b/pdf-toolbox/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent - 1.2.21-SNAPSHOT + 1.3.0-SNAPSHOT pdf-toolbox diff --git a/pdf-toolbox/src/test/java/com/lowagie/examples/RunAll.java b/pdf-toolbox/src/test/java/com/lowagie/examples/RunAll.java new file mode 100644 index 000000000..c8507f180 --- /dev/null +++ b/pdf-toolbox/src/test/java/com/lowagie/examples/RunAll.java @@ -0,0 +1,87 @@ +package com.lowagie.examples; + +import com.lowagie.examples.directcontent.Layers; +import com.lowagie.examples.directcontent.TemplateImages; +import com.lowagie.examples.directcontent.Templates; +import com.lowagie.examples.directcontent.colors.Groups; +import com.lowagie.examples.directcontent.colors.Pattern; +import com.lowagie.examples.directcontent.colors.Patterns; +import com.lowagie.examples.directcontent.colors.Shading; +import com.lowagie.examples.directcontent.colors.ShadingPattern; +import com.lowagie.examples.directcontent.colors.SoftMask; +import com.lowagie.examples.directcontent.colors.SpotColors; +import com.lowagie.examples.directcontent.colors.Transparency; +import com.lowagie.examples.directcontent.coordinates.AffineTransformation; +import com.lowagie.examples.directcontent.coordinates.TransformImage; +import com.lowagie.examples.directcontent.coordinates.Transformations; +import com.lowagie.examples.directcontent.coordinates.UpsideDown; +import com.lowagie.examples.directcontent.coordinates.XandYcoordinates; +import com.lowagie.examples.directcontent.graphics.Circles; +import com.lowagie.examples.directcontent.graphics.GState; +import com.lowagie.examples.directcontent.graphics.Literal; +import com.lowagie.examples.directcontent.graphics.Shapes; +import com.lowagie.examples.directcontent.graphics.State; +import com.lowagie.examples.directcontent.graphics2D.ArabicText; +import com.lowagie.examples.directcontent.graphics2D.G2D; +import com.lowagie.examples.directcontent.graphics2D.JFreeChartExample; +import com.lowagie.examples.directcontent.optionalcontent.Automatic; +import com.lowagie.examples.directcontent.optionalcontent.ContentGroups; +import com.lowagie.examples.directcontent.optionalcontent.NestedLayers; +import com.lowagie.examples.directcontent.optionalcontent.OptionalContent; +import com.lowagie.examples.directcontent.optionalcontent.OrderedLayers; +import com.lowagie.examples.directcontent.pageevents.Bookmarks; +import com.lowagie.examples.directcontent.pageevents.EndPage; +import com.lowagie.examples.directcontent.pageevents.Events; +import com.lowagie.examples.directcontent.pageevents.PageNumbersWatermark; +import com.lowagie.examples.directcontent.text.Logo; +import com.lowagie.examples.directcontent.text.Text; + +public class RunAll { + + public static void main(String[] args) { + // directcontent + Layers.main(args); + TemplateImages.main(args); + Templates.main(args); + // colors + Groups.main(args); + Pattern.main(args); + Patterns.main(args); + Shading.main(args); + ShadingPattern.main(args); + SoftMask.main(args); + SpotColors.main(args); + Transparency.main(args); + // coordinates + AffineTransformation.main(args); + Transformations.main(args); + TransformImage.main(args); + UpsideDown.main(args); + XandYcoordinates.main(args); + // graphics + Circles.main(args); + GState.main(args); + Literal.main(args); + Shapes.main(args); + State.main(args); + // graphics2D + ArabicText.main(args); + G2D.main(args); + JFreeChartExample.main(args); + // optionalcontent + Automatic.main(args); + ContentGroups.main(args); + com.lowagie.examples.directcontent.optionalcontent.Layers.main(args); + NestedLayers.main(args); + OptionalContent.main(args); + OrderedLayers.main(args); + // pageevents + Bookmarks.main(args); + EndPage.main(args); + Events.main(args); + PageNumbersWatermark.main(args); + // text + Logo.main(args); + Text.main(args); + } +} diff --git a/pom.xml b/pom.xml index 5c7a9f518..9723372d3 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.librepdf openpdf-parent pom - 1.2.21-SNAPSHOT + 1.3.0-SNAPSHOT