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 ListItem
s. */
- 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 ListItem
s.
*/
- 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 extends Element> 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 extends Element> 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 extends Element> 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 Row
s. */
- 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