fix most alerts reported by LGTM on OOXML

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1843481 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Alain Béarez 2018-10-10 17:49:53 +00:00
parent fbdbfa3fd3
commit 65b7c9e273
16 changed files with 429 additions and 322 deletions

View File

@ -835,7 +835,7 @@ public class SignatureConfig {
* Converts the digest algorithm ur - currently only sha* and ripemd160 is supported. * Converts the digest algorithm ur - currently only sha* and ripemd160 is supported.
* MS Office only supports sha1, sha256, sha384, sha512. * MS Office only supports sha1, sha256, sha384, sha512.
* *
* @param digestAlgo the digest algorithm uri * @param digestMethodUri the digest algorithm uri
* @return the hash algorithm for the given digest * @return the hash algorithm for the given digest
*/ */
private static HashAlgorithm getDigestMethodAlgo(String digestMethodUri) { private static HashAlgorithm getDigestMethodAlgo(String digestMethodUri) {

View File

@ -116,25 +116,28 @@ public class XDGFShape extends XDGFSheet {
_parentPage = parentPage; _parentPage = parentPage;
TextType text = shapeSheet.getText(); TextType text = shapeSheet.getText();
if (text != null) if (text != null) {
_text = new XDGFText(text, this); _text = new XDGFText(text, this);
}
if (shapeSheet.isSetShapes()) { if (shapeSheet.isSetShapes()) {
_shapes = new ArrayList<>(); _shapes = new ArrayList<>();
for (ShapeSheetType shape : shapeSheet.getShapes().getShapeArray()) for (ShapeSheetType shape : shapeSheet.getShapes().getShapeArray()) {
_shapes.add(new XDGFShape(this, shape, parentPage, document)); _shapes.add(new XDGFShape(this, shape, parentPage, document));
} }
}
readProperties(); readProperties();
} }
@Override @Override
public String toString() { public String toString() {
if (_parentPage instanceof XDGFMasterContents) if (_parentPage instanceof XDGFMasterContents) {
return _parentPage + ": <Shape ID=\"" + getID() + "\">"; return _parentPage + ": <Shape ID=\"" + getID() + "\">";
else } else {
return "<Shape ID=\"" + getID() + "\">"; return "<Shape ID=\"" + getID() + "\">";
} }
}
protected void readProperties() { protected void readProperties() {
@ -181,9 +184,10 @@ public class XDGFShape extends XDGFSheet {
if (obj.isSetMaster()) { if (obj.isSetMaster()) {
_master = pageContents.getMasterById(obj.getMaster()); _master = pageContents.getMasterById(obj.getMaster());
if (_master == null) if (_master == null) {
throw XDGFException.error("refers to non-existant master " throw XDGFException.error("refers to non-existant master "
+ obj.getMaster(), this); + obj.getMaster(), this);
}
/* /*
* If a master has one top-level shape, a shape that inherits from * If a master has one top-level shape, a shape that inherits from
@ -209,11 +213,12 @@ public class XDGFShape extends XDGFSheet {
} }
} else if (obj.isSetMasterShape()) { } else if (obj.isSetMasterShape()) {
_masterShape = master.getShapeById(obj.getMasterShape()); _masterShape = (master == null) ? null : master.getShapeById(obj.getMasterShape());
if (_masterShape == null) if (_masterShape == null) {
throw XDGFException.error( throw XDGFException.error(
"refers to non-existant master shape " "refers to non-existant master shape "
+ obj.getMasterShape(), this); + obj.getMasterShape(), this);
}
} }
@ -229,22 +234,25 @@ public class XDGFShape extends XDGFSheet {
protected void setupSectionMasters() { protected void setupSectionMasters() {
if (_masterShape == null) if (_masterShape == null) {
return; return;
}
try { try {
for (Entry<String, XDGFSection> section : _sections.entrySet()) { for (Entry<String, XDGFSection> section : _sections.entrySet()) {
XDGFSection master = _masterShape.getSection(section.getKey()); XDGFSection master = _masterShape.getSection(section.getKey());
if (master != null) if (master != null) {
section.getValue().setupMaster(master); section.getValue().setupMaster(master);
} }
}
for (Entry<Long, GeometrySection> section : _geometry.entrySet()) { for (Entry<Long, GeometrySection> section : _geometry.entrySet()) {
GeometrySection master = _masterShape.getGeometryByIdx(section GeometrySection master = _masterShape.getGeometryByIdx(section
.getKey()); .getKey());
if (master != null) if (master != null) {
section.getValue().setupMaster(master); section.getValue().setupMaster(master);
} }
}
} catch (POIXMLException e) { } catch (POIXMLException e) {
throw XDGFException.wrap(this.toString(), e); throw XDGFException.wrap(this.toString(), e);
} }
@ -266,8 +274,9 @@ public class XDGFShape extends XDGFSheet {
public String getTextAsString() { public String getTextAsString() {
XDGFText text = getText(); XDGFText text = getText();
if (text == null) if (text == null) {
return ""; return "";
}
return text.getTextContent(); return text.getTextContent();
} }
@ -304,28 +313,32 @@ public class XDGFShape extends XDGFSheet {
// unique to this shape on the page? // unique to this shape on the page?
public String getName() { public String getName() {
String name = getXmlObject().getName(); String name = getXmlObject().getName();
if (name == null) if (name == null) {
return ""; return "";
}
return name; return name;
} }
// unique to this shape on the page? // unique to this shape on the page?
public String getShapeType() { public String getShapeType() {
String type = getXmlObject().getType(); String type = getXmlObject().getType();
if (type == null) if (type == null) {
return ""; return "";
}
return type; return type;
} }
// name of the symbol that this was derived from // name of the symbol that this was derived from
public String getSymbolName() { public String getSymbolName() {
if (_master == null) if (_master == null) {
return ""; return "";
}
String name = _master.getName(); String name = _master.getName();
if (name == null) if (name == null) {
return ""; return "";
}
return name; return name;
} }
@ -345,9 +358,10 @@ public class XDGFShape extends XDGFSheet {
XDGFShape top = null; XDGFShape top = null;
if (_parent != null) { if (_parent != null) {
top = _parent.getTopmostParentShape(); top = _parent.getTopmostParentShape();
if (top == null) if (top == null) {
top = _parent; top = _parent;
} }
}
return top; return top;
} }
@ -381,190 +395,223 @@ public class XDGFShape extends XDGFSheet {
} }
public XDGFText getText() { public XDGFText getText() {
if (_text == null && _masterShape != null) if (_text == null && _masterShape != null) {
return _masterShape.getText(); return _masterShape.getText();
}
return _text; return _text;
} }
public Double getPinX() { public Double getPinX() {
if (_pinX == null && _masterShape != null) if (_pinX == null && _masterShape != null) {
return _masterShape.getPinX(); return _masterShape.getPinX();
}
if (_pinX == null) if (_pinX == null) {
throw XDGFException.error("PinX not set!", this); throw XDGFException.error("PinX not set!", this);
}
return _pinX; return _pinX;
} }
public Double getPinY() { public Double getPinY() {
if (_pinY == null && _masterShape != null) if (_pinY == null && _masterShape != null) {
return _masterShape.getPinY(); return _masterShape.getPinY();
}
if (_pinY == null) if (_pinY == null) {
throw XDGFException.error("PinY not specified!", this); throw XDGFException.error("PinY not specified!", this);
}
return _pinY; return _pinY;
} }
public Double getWidth() { public Double getWidth() {
if (_width == null && _masterShape != null) if (_width == null && _masterShape != null) {
return _masterShape.getWidth(); return _masterShape.getWidth();
}
if (_width == null) if (_width == null) {
throw XDGFException.error("Width not specified!", this); throw XDGFException.error("Width not specified!", this);
}
return _width; return _width;
} }
public Double getHeight() { public Double getHeight() {
if (_height == null && _masterShape != null) if (_height == null && _masterShape != null) {
return _masterShape.getHeight(); return _masterShape.getHeight();
}
if (_height == null) if (_height == null) {
throw XDGFException.error("Height not specified!", this); throw XDGFException.error("Height not specified!", this);
}
return _height; return _height;
} }
public Double getLocPinX() { public Double getLocPinX() {
if (_locPinX == null && _masterShape != null) if (_locPinX == null && _masterShape != null) {
return _masterShape.getLocPinX(); return _masterShape.getLocPinX();
}
if (_locPinX == null) if (_locPinX == null) {
throw XDGFException.error("LocPinX not specified!", this); throw XDGFException.error("LocPinX not specified!", this);
}
return _locPinX; return _locPinX;
} }
public Double getLocPinY() { public Double getLocPinY() {
if (_locPinY == null && _masterShape != null) if (_locPinY == null && _masterShape != null) {
return _masterShape.getLocPinY(); return _masterShape.getLocPinY();
}
if (_locPinY == null) if (_locPinY == null) {
throw XDGFException.error("LocPinY not specified!", this); throw XDGFException.error("LocPinY not specified!", this);
}
return _locPinY; return _locPinY;
} }
public Double getBeginX() { public Double getBeginX() {
if (_beginX == null && _masterShape != null) if (_beginX == null && _masterShape != null) {
return _masterShape.getBeginX(); return _masterShape.getBeginX();
}
return _beginX; return _beginX;
} }
public Double getBeginY() { public Double getBeginY() {
if (_beginY == null && _masterShape != null) if (_beginY == null && _masterShape != null) {
return _masterShape.getBeginY(); return _masterShape.getBeginY();
}
return _beginY; return _beginY;
} }
public Double getEndX() { public Double getEndX() {
if (_endX == null && _masterShape != null) if (_endX == null && _masterShape != null) {
return _masterShape.getEndX(); return _masterShape.getEndX();
}
return _endX; return _endX;
} }
public Double getEndY() { public Double getEndY() {
if (_endY == null && _masterShape != null) if (_endY == null && _masterShape != null) {
return _masterShape.getEndY(); return _masterShape.getEndY();
}
return _endY; return _endY;
} }
public Double getAngle() { public Double getAngle() {
if (_angle == null && _masterShape != null) if (_angle == null && _masterShape != null) {
return _masterShape.getAngle(); return _masterShape.getAngle();
}
return _angle; return _angle;
} }
public Boolean getFlipX() { public Boolean getFlipX() {
if (_flipX == null && _masterShape != null) if (_flipX == null && _masterShape != null) {
return _masterShape.getFlipX(); return _masterShape.getFlipX();
}
return _flipX; return _flipX;
} }
public Boolean getFlipY() { public Boolean getFlipY() {
if (_flipY == null && _masterShape != null) if (_flipY == null && _masterShape != null) {
return _masterShape.getFlipY(); return _masterShape.getFlipY();
}
return _flipY; return _flipY;
} }
public Double getTxtPinX() { public Double getTxtPinX() {
if (_txtPinX == null && _masterShape != null if (_txtPinX == null && _masterShape != null
&& _masterShape._txtPinX != null) && _masterShape._txtPinX != null) {
return _masterShape._txtPinX; return _masterShape._txtPinX;
}
if (_txtPinX == null) if (_txtPinX == null) {
return getWidth() * 0.5; return getWidth() * 0.5;
}
return _txtPinX; return _txtPinX;
} }
public Double getTxtPinY() { public Double getTxtPinY() {
if (_txtLocPinY == null && _masterShape != null if (_txtLocPinY == null && _masterShape != null
&& _masterShape._txtLocPinY != null) && _masterShape._txtLocPinY != null) {
return _masterShape._txtLocPinY; return _masterShape._txtLocPinY;
}
if (_txtPinY == null) if (_txtPinY == null) {
return getHeight() * 0.5; return getHeight() * 0.5;
}
return _txtPinY; return _txtPinY;
} }
public Double getTxtLocPinX() { public Double getTxtLocPinX() {
if (_txtLocPinX == null && _masterShape != null if (_txtLocPinX == null && _masterShape != null
&& _masterShape._txtLocPinX != null) && _masterShape._txtLocPinX != null) {
return _masterShape._txtLocPinX; return _masterShape._txtLocPinX;
}
if (_txtLocPinX == null) if (_txtLocPinX == null) {
return getTxtWidth() * 0.5; return getTxtWidth() * 0.5;
}
return _txtLocPinX; return _txtLocPinX;
} }
public Double getTxtLocPinY() { public Double getTxtLocPinY() {
if (_txtLocPinY == null && _masterShape != null if (_txtLocPinY == null && _masterShape != null
&& _masterShape._txtLocPinY != null) && _masterShape._txtLocPinY != null) {
return _masterShape._txtLocPinY; return _masterShape._txtLocPinY;
}
if (_txtLocPinY == null) if (_txtLocPinY == null) {
return getTxtHeight() * 0.5; return getTxtHeight() * 0.5;
}
return _txtLocPinY; return _txtLocPinY;
} }
public Double getTxtAngle() { public Double getTxtAngle() {
if (_txtAngle == null && _masterShape != null) if (_txtAngle == null && _masterShape != null) {
return _masterShape.getTxtAngle(); return _masterShape.getTxtAngle();
}
return _txtAngle; return _txtAngle;
} }
public Double getTxtWidth() { public Double getTxtWidth() {
if (_txtWidth == null && _masterShape != null if (_txtWidth == null && _masterShape != null
&& _masterShape._txtWidth != null) && _masterShape._txtWidth != null) {
return _masterShape._txtWidth; return _masterShape._txtWidth;
}
if (_txtWidth == null) if (_txtWidth == null) {
return getWidth(); return getWidth();
}
return _txtWidth; return _txtWidth;
} }
public Double getTxtHeight() { public Double getTxtHeight() {
if (_txtHeight == null && _masterShape != null if (_txtHeight == null && _masterShape != null
&& _masterShape._txtHeight != null) && _masterShape._txtHeight != null) {
return _masterShape._txtHeight; return _masterShape._txtHeight;
}
if (_txtHeight == null) if (_txtHeight == null) {
return getHeight(); return getHeight();
}
return _txtHeight; return _txtHeight;
} }
@ -573,8 +620,9 @@ public class XDGFShape extends XDGFSheet {
public Integer getLineCap() { public Integer getLineCap() {
Integer lineCap = super.getLineCap(); Integer lineCap = super.getLineCap();
if (lineCap != null) if (lineCap != null) {
return lineCap; return lineCap;
}
// get from master // get from master
if (_masterShape != null) { if (_masterShape != null) {
@ -589,8 +637,9 @@ public class XDGFShape extends XDGFSheet {
public Color getLineColor() { public Color getLineColor() {
Color lineColor = super.getLineColor(); Color lineColor = super.getLineColor();
if (lineColor != null) if (lineColor != null) {
return lineColor; return lineColor;
}
// get from master // get from master
if (_masterShape != null) { if (_masterShape != null) {
@ -605,8 +654,9 @@ public class XDGFShape extends XDGFSheet {
public Integer getLinePattern() { public Integer getLinePattern() {
Integer linePattern = super.getLinePattern(); Integer linePattern = super.getLinePattern();
if (linePattern != null) if (linePattern != null) {
return linePattern; return linePattern;
}
// get from master // get from master
if (_masterShape != null) { if (_masterShape != null) {
@ -621,8 +671,9 @@ public class XDGFShape extends XDGFSheet {
public Double getLineWeight() { public Double getLineWeight() {
Double lineWeight = super.getLineWeight(); Double lineWeight = super.getLineWeight();
if (lineWeight != null) if (lineWeight != null) {
return lineWeight; return lineWeight;
}
// get from master // get from master
if (_masterShape != null) { if (_masterShape != null) {
@ -637,8 +688,9 @@ public class XDGFShape extends XDGFSheet {
public Color getFontColor() { public Color getFontColor() {
Color fontColor = super.getFontColor(); Color fontColor = super.getFontColor();
if (fontColor != null) if (fontColor != null) {
return fontColor; return fontColor;
}
// get from master // get from master
if (_masterShape != null) { if (_masterShape != null) {
@ -653,8 +705,9 @@ public class XDGFShape extends XDGFSheet {
public Double getFontSize() { public Double getFontSize() {
Double fontSize = super.getFontSize(); Double fontSize = super.getFontSize();
if (fontSize != null) if (fontSize != null) {
return fontSize; return fontSize;
}
// get from master // get from master
if (_masterShape != null) { if (_masterShape != null) {
@ -819,8 +872,9 @@ public class XDGFShape extends XDGFSheet {
*/ */
public Path2D.Double getPath() { public Path2D.Double getPath() {
for (GeometrySection geoSection : getGeometrySections()) { for (GeometrySection geoSection : getGeometrySections()) {
if (geoSection.getNoShow()) if (geoSection.getNoShow()) {
continue; continue;
}
return geoSection.getPath(this); return geoSection.getPath(this);
} }
@ -833,9 +887,10 @@ public class XDGFShape extends XDGFSheet {
*/ */
public boolean hasGeometry() { public boolean hasGeometry() {
for (GeometrySection geoSection : getGeometrySections()) { for (GeometrySection geoSection : getGeometrySections()) {
if (!geoSection.getNoShow()) if (!geoSection.getNoShow()) {
return true; return true;
} }
}
return false; return false;
} }
@ -889,8 +944,9 @@ public class XDGFShape extends XDGFSheet {
tr.concatenate(getParentTransform()); tr.concatenate(getParentTransform());
try { try {
if (visitor.accept(this)) if (visitor.accept(this)) {
visitor.visit(this, tr, level); visitor.visit(this, tr, level);
}
if (_shapes != null) { if (_shapes != null) {
for (XDGFShape shape : _shapes) { for (XDGFShape shape : _shapes) {
@ -914,8 +970,9 @@ public class XDGFShape extends XDGFSheet {
public void visitShapes(ShapeVisitor visitor, int level) { public void visitShapes(ShapeVisitor visitor, int level) {
try { try {
if (visitor.accept(this)) if (visitor.accept(this)) {
visitor.visit(this, null, level); visitor.visit(this, null, level);
}
if (_shapes != null) { if (_shapes != null) {
for (XDGFShape shape : _shapes) { for (XDGFShape shape : _shapes) {

View File

@ -82,8 +82,8 @@ public class XDGFText {
public Path2D.Double getBoundsAsPath() { public Path2D.Double getBoundsAsPath() {
Rectangle2D.Double rect = getTextBounds(); Rectangle2D.Double rect = getTextBounds();
Double w = rect.getWidth(); double w = rect.getWidth();
Double h = rect.getHeight(); double h = rect.getHeight();
Path2D.Double bounds = new Path2D.Double(); Path2D.Double bounds = new Path2D.Double();
bounds.moveTo(0, 0); bounds.moveTo(0, 0);
@ -110,8 +110,9 @@ public class XDGFText {
public void draw(Graphics2D graphics) { public void draw(Graphics2D graphics) {
String textContent = getTextContent(); String textContent = getTextContent();
if (textContent.length() == 0) if (textContent.length() == 0) {
return; return;
}
Rectangle2D.Double bounds = getTextBounds(); Rectangle2D.Double bounds = getTextBounds();
@ -140,22 +141,25 @@ public class XDGFText {
} }
Double txtAngle = _parent.getTxtAngle(); Double txtAngle = _parent.getTxtAngle();
if (txtAngle != null && Math.abs(txtAngle) > 0.01) if (txtAngle != null && Math.abs(txtAngle) > 0.01) {
graphics.rotate(txtAngle); graphics.rotate(txtAngle);
}
float nextY = 0; float nextY = 0;
for (String line : lines) { for (String line : lines) {
if (line.length() == 0) if (line.length() == 0) {
continue; continue;
}
TextLayout layout = new TextLayout(line, font, frc); TextLayout layout = new TextLayout(line, font, frc);
if (layout.isLeftToRight()) if (layout.isLeftToRight()) {
layout.draw(graphics, 0, nextY); layout.draw(graphics, 0, nextY);
else } else {
layout.draw(graphics, layout.draw(graphics,
(float) (bounds.width - layout.getAdvance()), nextY); (float) (bounds.width - layout.getAdvance()), nextY);
}
nextY += layout.getAscent() + layout.getDescent() nextY += layout.getAscent() + layout.getDescent()
+ layout.getLeading(); + layout.getLeading();

View File

@ -22,6 +22,7 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
@ -38,17 +39,17 @@ import org.apache.poi.xdgf.usermodel.shape.ShapeVisitor;
public class HierarchyPrinter { public class HierarchyPrinter {
public static void printHierarchy(XDGFPage page, File outDir) public static void printHierarchy(XDGFPage page, File outDir)
throws FileNotFoundException, UnsupportedEncodingException { throws FileNotFoundException, UnsupportedEncodingException, IOException {
File pageFile = new File(outDir, "page" + page.getPageNumber() + "-" File pageFile = new File(outDir, "page" + page.getPageNumber() + "-"
+ Util.sanitizeFilename(page.getName()) + ".txt"); + Util.sanitizeFilename(page.getName()) + ".txt");
try (
OutputStream os = new FileOutputStream(pageFile); OutputStream os = new FileOutputStream(pageFile);
PrintStream pos = new PrintStream(os, false, "utf-8"); PrintStream pos = new PrintStream(os, false, "utf-8")
) {
printHierarchy(page, pos); printHierarchy(page, pos);
}
pos.close();
} }
public static void printHierarchy(XDGFPage page, final PrintStream os) { public static void printHierarchy(XDGFPage page, final PrintStream os) {
@ -71,7 +72,7 @@ public class HierarchyPrinter {
} }
public static void printHierarchy(XmlVisioDocument document, public static void printHierarchy(XmlVisioDocument document,
String outDirname) throws FileNotFoundException, UnsupportedEncodingException { String outDirname) throws FileNotFoundException, UnsupportedEncodingException, IOException {
File outDir = new File(outDirname); File outDir = new File(outDirname);
@ -89,8 +90,9 @@ public class HierarchyPrinter {
String inFilename = args[0]; String inFilename = args[0];
String outDir = args[1]; String outDir = args[1];
XmlVisioDocument doc = new XmlVisioDocument(new FileInputStream( try (FileInputStream is = new FileInputStream(inFilename)) {
inFilename)); XmlVisioDocument doc = new XmlVisioDocument(is);
printHierarchy(doc, outDir); printHierarchy(doc, outDir);
} }
} }
}

View File

@ -21,7 +21,10 @@ import java.awt.Color;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.RenderingHints; import java.awt.RenderingHints;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.*; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
@ -91,11 +94,8 @@ public class VsdxToPng {
graphics.dispose(); graphics.dispose();
OutputStream out = new FileOutputStream(outFile); try (FileOutputStream out = new FileOutputStream(outFile)) {
try {
ImageIO.write(img, "png", out); ImageIO.write(img, "png", out);
} finally {
out.close();
} }
} }
@ -127,8 +127,9 @@ public class VsdxToPng {
renderer = new ShapeDebuggerRenderer(); renderer = new ShapeDebuggerRenderer();
} }
XmlVisioDocument doc = new XmlVisioDocument(new FileInputStream( try (FileInputStream is = new FileInputStream(inFilename)) {
inFilename)); XmlVisioDocument doc = new XmlVisioDocument(is);
renderToPng(doc, pngDir, 2000 / 11.0, renderer); renderToPng(doc, pngDir, 2000 / 11.0, renderer);
} }
} }
}

View File

@ -36,6 +36,7 @@ import org.apache.poi.ooxml.POIXMLDocument;
import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.ooxml.POIXMLException; import org.apache.poi.ooxml.POIXMLException;
import org.apache.poi.ooxml.extractor.POIXMLPropertiesTextExtractor; import org.apache.poi.ooxml.extractor.POIXMLPropertiesTextExtractor;
import org.apache.poi.ooxml.util.PackageHelper;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart; import org.apache.poi.openxml4j.opc.PackagePart;
@ -50,7 +51,6 @@ import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.LittleEndianConsts; import org.apache.poi.util.LittleEndianConsts;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger; import org.apache.poi.util.POILogger;
import org.apache.poi.ooxml.util.PackageHelper;
import org.apache.poi.util.Units; import org.apache.poi.util.Units;
import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlObject;
@ -362,7 +362,7 @@ public class XMLSlideShow extends POIXMLDocument
CTNotesMasterIdListEntry notesMasterId = notesMasterIdList.addNewNotesMasterId(); CTNotesMasterIdListEntry notesMasterId = notesMasterIdList.addNewNotesMasterId();
notesMasterId.setId(rp.getRelationship().getId()); notesMasterId.setId(rp.getRelationship().getId());
Integer themeIndex = 1; int themeIndex = 1;
// TODO: check if that list can be replaced by idx = Math.max(idx,themeIdx) // TODO: check if that list can be replaced by idx = Math.max(idx,themeIdx)
List<Integer> themeIndexList = new ArrayList<>(); List<Integer> themeIndexList = new ArrayList<>();
for (POIXMLDocumentPart p : getRelations()) { for (POIXMLDocumentPart p : getRelations()) {

View File

@ -254,7 +254,7 @@ public class XSLFColor {
* @return true, if this is an integer color value * @return true, if this is an integer color value
*/ */
private static boolean isInt(float f) { private static boolean isInt(float f) {
return Math.abs((f*255f) - Math.rint(f*255f)) < 0.00001f; return Math.abs((f*255d) - Math.rint(f*255d)) < 0.00001;
} }
private int getRawValue(String elem) { private int getRawValue(String elem) {

View File

@ -49,8 +49,6 @@ implements Notes<XSLFShape,XSLFTextParagraph> {
* *
* @param part the package part holding the notes data, * @param part the package part holding the notes data,
* the content type must be <code>application/vnd.openxmlformats-officedocument.notes+xml</code> * the content type must be <code>application/vnd.openxmlformats-officedocument.notes+xml</code>
* @param rel the package relationship holding this notes,
* the relationship type must be http://schemas.openxmlformats.org/officeDocument/2006/relationships/notes
* *
* @since POI 3.14-Beta1 * @since POI 3.14-Beta1
*/ */

View File

@ -92,6 +92,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
return _shape; return _shape;
} }
@Override
public XSLFSheet getSheet() { public XSLFSheet getSheet() {
return _sheet; return _sheet;
} }
@ -132,6 +133,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
this._parent = parent; this._parent = parent;
} }
@Override
public XSLFShapeContainer getParent() { public XSLFShapeContainer getParent() {
return this._parent; return this._parent;
} }
@ -140,6 +142,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
final XSLFTheme theme = getSheet().getTheme(); final XSLFTheme theme = getSheet().getTheme();
final boolean hasPlaceholder = getPlaceholder() != null; final boolean hasPlaceholder = getPlaceholder() != null;
PropertyFetcher<PaintStyle> fetcher = new PropertyFetcher<PaintStyle>() { PropertyFetcher<PaintStyle> fetcher = new PropertyFetcher<PaintStyle>() {
@Override
public boolean fetch(XSLFShape shape) { public boolean fetch(XSLFShape shape) {
XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(shape.getShapeProperties()); XSLFFillProperties fp = XSLFPropertiesDelegate.getFillDelegate(shape.getShapeProperties());
if (fp == null) { if (fp == null) {
@ -268,7 +271,9 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
@SuppressWarnings({"unchecked", "WeakerAccess"}) @SuppressWarnings({"unchecked", "WeakerAccess"})
protected <T extends XmlObject> T selectProperty(Class<T> resultClass, String xquery) { protected <T extends XmlObject> T selectProperty(Class<T> resultClass, String xquery) {
XmlObject[] rs = getXmlObject().selectPath(xquery); XmlObject[] rs = getXmlObject().selectPath(xquery);
if (rs.length == 0) return null; if (rs.length == 0) {
return null;
}
return (resultClass.isInstance(rs[0])) ? (T)rs[0] : null; return (resultClass.isInstance(rs[0])) ? (T)rs[0] : null;
} }
@ -398,6 +403,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
} }
} }
@Override
public InputStream getImageData() { public InputStream getImageData() {
try { try {
return getPart().getInputStream(); return getPart().getInputStream();
@ -406,11 +412,13 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
} }
} }
@Override
public String getContentType() { public String getContentType() {
/* TOOD: map content-type */ /* TOOD: map content-type */
return getPart().getContentType(); return getPart().getContentType();
} }
@Override
public int getAlpha() { public int getAlpha() {
return (blip.sizeOfAlphaModFixArray() > 0) return (blip.sizeOfAlphaModFixArray() > 0)
? blip.getAlphaModFixArray(0).getAmt() ? blip.getAlphaModFixArray(0).getAmt()
@ -426,9 +434,9 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
final CTGradientStop[] gs = gradFill.getGsLst().getGsArray(); final CTGradientStop[] gs = gradFill.getGsLst().getGsArray();
Arrays.sort(gs, (o1, o2) -> { Arrays.sort(gs, (o1, o2) -> {
Integer pos1 = o1.getPos(); int pos1 = o1.getPos();
Integer pos2 = o2.getPos(); int pos2 = o2.getPos();
return pos1.compareTo(pos2); return Integer.compare(pos1, pos2);
}); });
final ColorStyle cs[] = new ColorStyle[gs.length]; final ColorStyle cs[] = new ColorStyle[gs.length];
@ -447,24 +455,29 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
return new GradientPaint() { return new GradientPaint() {
@Override
public double getGradientAngle() { public double getGradientAngle() {
return (gradFill.isSetLin()) return (gradFill.isSetLin())
? gradFill.getLin().getAng() / 60000.d ? gradFill.getLin().getAng() / 60000.d
: 0; : 0;
} }
@Override
public ColorStyle[] getGradientColors() { public ColorStyle[] getGradientColors() {
return cs; return cs;
} }
@Override
public float[] getGradientFractions() { public float[] getGradientFractions() {
return fractions; return fractions;
} }
@Override
public boolean isRotatedWithShape() { public boolean isRotatedWithShape() {
return gradFill.getRotWithShape(); return gradFill.getRotWithShape();
} }
@Override
public GradientType getGradientType() { public GradientType getGradientType() {
if (gradFill.isSetLin()) { if (gradFill.isSetLin()) {
return GradientType.linear; return GradientType.linear;
@ -487,7 +500,9 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
@SuppressWarnings("WeakerAccess") @SuppressWarnings("WeakerAccess")
protected static PaintStyle selectPaint(CTStyleMatrixReference fillRef, final XSLFTheme theme, boolean isLineStyle, boolean hasPlaceholder) { protected static PaintStyle selectPaint(CTStyleMatrixReference fillRef, final XSLFTheme theme, boolean isLineStyle, boolean hasPlaceholder) {
if (fillRef == null) return null; if (fillRef == null) {
return null;
}
// The idx attribute refers to the index of a fill style or // The idx attribute refers to the index of a fill style or
// background fill style within the presentation's style matrix, defined by the fmtScheme element. // background fill style within the presentation's style matrix, defined by the fmtScheme element.

View File

@ -74,13 +74,13 @@ public class PPTX2PNG {
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
if (args[i].startsWith("-")) { if (args[i].startsWith("-")) {
if ("-scale".equals(args[i])) { if ("-scale".equals(args[i])) {
scale = Float.parseFloat(args[++i]); scale = Float.parseFloat(args[++i]); // lgtm[java/index-out-of-bounds]
} else if ("-slide".equals(args[i])) { } else if ("-slide".equals(args[i])) {
slidenumStr = args[++i]; slidenumStr = args[++i]; // lgtm[java/index-out-of-bounds]
} else if ("-format".equals(args[i])) { } else if ("-format".equals(args[i])) {
format = args[++i]; format = args[++i]; // lgtm[java/index-out-of-bounds]
} else if ("-outdir".equals(args[i])) { } else if ("-outdir".equals(args[i])) {
outdir = new File(args[++i]); outdir = new File(args[++i]); // lgtm[java/index-out-of-bounds]
} else if ("-quiet".equals(args[i])) { } else if ("-quiet".equals(args[i])) {
quiet = true; quiet = true;
} }

View File

@ -345,11 +345,12 @@ public class SXSSFRow implements Row, Comparable<SXSSFRow>
@Override @Override
public void setHeightInPoints(float height) public void setHeightInPoints(float height)
{ {
if(height==-1) if(height==-1) {
_height=-1; _height=-1;
else } else {
_height=(short)(height*20); _height=(short)(height*20);
} }
}
/** /**
* Get the row's height measured in twips (1/20th of a point). If the height is not set, the default worksheet value is returned, * Get the row's height measured in twips (1/20th of a point). If the height is not set, the default worksheet value is returned,
@ -392,7 +393,9 @@ public class SXSSFRow implements Row, Comparable<SXSSFRow>
*/ */
@Override @Override
public CellStyle getRowStyle() { public CellStyle getRowStyle() {
if(!isFormatted()) return null; if(!isFormatted()) {
return null;
}
return getSheet().getWorkbook().getCellStyleAt(_style); return getSheet().getWorkbook().getCellStyleAt(_style);
} }
@ -485,11 +488,12 @@ public class SXSSFRow implements Row, Comparable<SXSSFRow>
@Override @Override
public Cell next() throws NoSuchElementException public Cell next() throws NoSuchElementException
{ {
if (hasNext()) if (hasNext()) {
return _cells.get(pos++); return _cells.get(pos++);
else } else {
throw new NoSuchElementException(); throw new NoSuchElementException();
} }
}
@Override @Override
public void remove() public void remove()
{ {
@ -524,9 +528,9 @@ public class SXSSFRow implements Row, Comparable<SXSSFRow>
throw new IllegalArgumentException("The compared rows must belong to the same sheet"); throw new IllegalArgumentException("The compared rows must belong to the same sheet");
} }
Integer thisRow = this.getRowNum(); int thisRow = this.getRowNum();
Integer otherRow = other.getRowNum(); int otherRow = other.getRowNum();
return thisRow.compareTo(otherRow); return Integer.compare(thisRow, otherRow);
} }
@Override @Override

View File

@ -446,7 +446,7 @@ public final class XSSFDrawing extends POIXMLDocumentPart implements Drawing<XSS
XSSFSheet sheet = getSheet(); XSSFSheet sheet = getSheet();
XSSFWorkbook wb = sheet.getWorkbook(); XSSFWorkbook wb = sheet.getWorkbook();
int sheetIndex = wb.getSheetIndex(sheet); int sheetIndex = wb.getSheetIndex(sheet);
long shapeId = (sheetIndex + 1) * 1024 + newShapeId(); long shapeId = (sheetIndex + 1L) * 1024 + newShapeId();
// add reference to OLE part // add reference to OLE part
PackagePartName olePN; PackagePartName olePN;

View File

@ -22,8 +22,8 @@ import java.util.Iterator;
import java.util.Set; import java.util.Set;
import java.util.TreeMap; import java.util.TreeMap;
import org.apache.poi.ss.formula.FormulaShifter;
import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.FormulaShifter;
import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellCopyPolicy; import org.apache.poi.ss.usermodel.CellCopyPolicy;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
@ -158,9 +158,9 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
throw new IllegalArgumentException("The compared rows must belong to the same sheet"); throw new IllegalArgumentException("The compared rows must belong to the same sheet");
} }
Integer thisRow = this.getRowNum(); int thisRow = this.getRowNum();
Integer otherRow = other.getRowNum(); int otherRow = other.getRowNum();
return thisRow.compareTo(otherRow); return Integer.compare(thisRow, otherRow);
} }
@Override @Override
@ -245,7 +245,9 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
*/ */
@Override @Override
public XSSFCell getCell(int cellnum, MissingCellPolicy policy) { public XSSFCell getCell(int cellnum, MissingCellPolicy policy) {
if(cellnum < 0) throw new IllegalArgumentException("Cell index must be >= 0"); if(cellnum < 0) {
throw new IllegalArgumentException("Cell index must be >= 0");
}
// Performance optimization for bug 57840: explicit boxing is slightly faster than auto-unboxing, though may use more memory // Performance optimization for bug 57840: explicit boxing is slightly faster than auto-unboxing, though may use more memory
final Integer colI = Integer.valueOf(cellnum); // NOSONAR final Integer colI = Integer.valueOf(cellnum); // NOSONAR
@ -332,8 +334,12 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
@Override @Override
public void setHeight(short height) { public void setHeight(short height) {
if (height == -1) { if (height == -1) {
if (_row.isSetHt()) _row.unsetHt(); if (_row.isSetHt()) {
if (_row.isSetCustomHeight()) _row.unsetCustomHeight(); _row.unsetHt();
}
if (_row.isSetCustomHeight()) {
_row.unsetCustomHeight();
}
} else { } else {
_row.setHt((double) height / 20); _row.setHt((double) height / 20);
_row.setCustomHeight(true); _row.setCustomHeight(true);
@ -425,7 +431,9 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
*/ */
@Override @Override
public XSSFCellStyle getRowStyle() { public XSSFCellStyle getRowStyle() {
if(!isFormatted()) return null; if(!isFormatted()) {
return null;
}
StylesTable stylesSource = getSheet().getWorkbook().getStylesSource(); StylesTable stylesSource = getSheet().getWorkbook().getStylesSource();
if(stylesSource.getNumCellStyles() > 0) { if(stylesSource.getNumCellStyles() > 0) {
@ -626,11 +634,13 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
*/ */
@Override @Override
public void shiftCellsRight(int firstShiftColumnIndex, int lastShiftColumnIndex, int step) { public void shiftCellsRight(int firstShiftColumnIndex, int lastShiftColumnIndex, int step) {
if(step < 0) if(step < 0) {
throw new IllegalArgumentException("Shifting step may not be negative "); throw new IllegalArgumentException("Shifting step may not be negative ");
if(firstShiftColumnIndex > lastShiftColumnIndex) }
if(firstShiftColumnIndex > lastShiftColumnIndex) {
throw new IllegalArgumentException(String.format(LocaleUtil.getUserLocale(), throw new IllegalArgumentException(String.format(LocaleUtil.getUserLocale(),
"Incorrect shifting range : %d-%d", firstShiftColumnIndex, lastShiftColumnIndex)); "Incorrect shifting range : %d-%d", firstShiftColumnIndex, lastShiftColumnIndex));
}
for (int columnIndex = lastShiftColumnIndex; columnIndex >= firstShiftColumnIndex; columnIndex--){ // process cells backwards, because of shifting for (int columnIndex = lastShiftColumnIndex; columnIndex >= firstShiftColumnIndex; columnIndex--){ // process cells backwards, because of shifting
shiftCell(columnIndex, step); shiftCell(columnIndex, step);
} }
@ -638,10 +648,11 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
{ {
_cells.remove(columnIndex); _cells.remove(columnIndex);
XSSFCell targetCell = getCell(columnIndex); XSSFCell targetCell = getCell(columnIndex);
if(targetCell != null) if(targetCell != null) {
targetCell.getCTCell().set(CTCell.Factory.newInstance()); targetCell.getCTCell().set(CTCell.Factory.newInstance());
} }
} }
}
/** /**
* Shifts column range [firstShiftColumnIndex-lastShiftColumnIndex] step places to the left. * Shifts column range [firstShiftColumnIndex-lastShiftColumnIndex] step places to the left.
* @param firstShiftColumnIndex the column to start shifting * @param firstShiftColumnIndex the column to start shifting
@ -650,26 +661,31 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
*/ */
@Override @Override
public void shiftCellsLeft(int firstShiftColumnIndex, int lastShiftColumnIndex, int step) { public void shiftCellsLeft(int firstShiftColumnIndex, int lastShiftColumnIndex, int step) {
if(step < 0) if(step < 0) {
throw new IllegalArgumentException("Shifting step may not be negative "); throw new IllegalArgumentException("Shifting step may not be negative ");
if(firstShiftColumnIndex > lastShiftColumnIndex) }
if(firstShiftColumnIndex > lastShiftColumnIndex) {
throw new IllegalArgumentException(String.format(LocaleUtil.getUserLocale(), throw new IllegalArgumentException(String.format(LocaleUtil.getUserLocale(),
"Incorrect shifting range : %d-%d", firstShiftColumnIndex, lastShiftColumnIndex)); "Incorrect shifting range : %d-%d", firstShiftColumnIndex, lastShiftColumnIndex));
if(firstShiftColumnIndex - step < 0) }
if(firstShiftColumnIndex - step < 0) {
throw new IllegalStateException("Column index less than zero : " + (Integer.valueOf(firstShiftColumnIndex + step)).toString()); throw new IllegalStateException("Column index less than zero : " + (Integer.valueOf(firstShiftColumnIndex + step)).toString());
}
for (int columnIndex = firstShiftColumnIndex; columnIndex <= lastShiftColumnIndex; columnIndex++){ for (int columnIndex = firstShiftColumnIndex; columnIndex <= lastShiftColumnIndex; columnIndex++){
shiftCell(columnIndex, -step); shiftCell(columnIndex, -step);
} }
for (int columnIndex = lastShiftColumnIndex-step+1; columnIndex <= lastShiftColumnIndex; columnIndex++){ for (int columnIndex = lastShiftColumnIndex-step+1; columnIndex <= lastShiftColumnIndex; columnIndex++){
_cells.remove(columnIndex); _cells.remove(columnIndex);
XSSFCell targetCell = getCell(columnIndex); XSSFCell targetCell = getCell(columnIndex);
if(targetCell != null) if(targetCell != null) {
targetCell.getCTCell().set(CTCell.Factory.newInstance()); targetCell.getCTCell().set(CTCell.Factory.newInstance());
} }
} }
}
private void shiftCell(int columnIndex, int step/*pass negative value for left shift*/){ private void shiftCell(int columnIndex, int step/*pass negative value for left shift*/){
if(columnIndex + step < 0) // only for shifting left if(columnIndex + step < 0) {
throw new IllegalStateException("Column index less than zero : " + (Integer.valueOf(columnIndex + step)).toString()); throw new IllegalStateException("Column index less than zero : " + (Integer.valueOf(columnIndex + step)).toString());
}
XSSFCell currentCell = getCell(columnIndex); XSSFCell currentCell = getCell(columnIndex);
if(currentCell != null){ if(currentCell != null){
@ -679,8 +695,9 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
else { else {
_cells.remove(columnIndex+step); _cells.remove(columnIndex+step);
XSSFCell targetCell = getCell(columnIndex+step); XSSFCell targetCell = getCell(columnIndex+step);
if(targetCell != null) if(targetCell != null) {
targetCell.getCTCell().set(CTCell.Factory.newInstance()); targetCell.getCTCell().set(CTCell.Factory.newInstance());
} }
} }
} }
}

View File

@ -40,16 +40,16 @@ public class XWPFSDTContent implements ISDTContent {
// private final IBody part; // private final IBody part;
// private final XWPFDocument document; // private final XWPFDocument document;
private List<XWPFParagraph> paragraphs = new ArrayList<>(); // private List<XWPFParagraph> paragraphs = new ArrayList<>();
private List<XWPFTable> tables = new ArrayList<>(); // private List<XWPFTable> tables = new ArrayList<>();
private List<XWPFRun> runs = new ArrayList<>(); // private List<XWPFRun> runs = new ArrayList<>();
private List<XWPFSDT> contentControls = new ArrayList<>(); // private List<XWPFSDT> contentControls = new ArrayList<>();
private List<ISDTContents> bodyElements = new ArrayList<>(); private List<ISDTContents> bodyElements = new ArrayList<>();
public XWPFSDTContent(CTSdtContentRun sdtRun, IBody part, IRunBody parent) { public XWPFSDTContent(CTSdtContentRun sdtRun, IBody part, IRunBody parent) {
for (CTR ctr : sdtRun.getRArray()) { for (CTR ctr : sdtRun.getRArray()) {
XWPFRun run = new XWPFRun(ctr, parent); XWPFRun run = new XWPFRun(ctr, parent);
runs.add(run); // runs.add(run);
bodyElements.add(run); bodyElements.add(run);
} }
} }
@ -62,24 +62,25 @@ public class XWPFSDTContent implements ISDTContent {
if (o instanceof CTP) { if (o instanceof CTP) {
XWPFParagraph p = new XWPFParagraph((CTP) o, part); XWPFParagraph p = new XWPFParagraph((CTP) o, part);
bodyElements.add(p); bodyElements.add(p);
paragraphs.add(p); // paragraphs.add(p);
} else if (o instanceof CTTbl) { } else if (o instanceof CTTbl) {
XWPFTable t = new XWPFTable((CTTbl) o, part); XWPFTable t = new XWPFTable((CTTbl) o, part);
bodyElements.add(t); bodyElements.add(t);
tables.add(t); // tables.add(t);
} else if (o instanceof CTSdtBlock) { } else if (o instanceof CTSdtBlock) {
XWPFSDT c = new XWPFSDT(((CTSdtBlock) o), part); XWPFSDT c = new XWPFSDT(((CTSdtBlock) o), part);
bodyElements.add(c); bodyElements.add(c);
contentControls.add(c); // contentControls.add(c);
} else if (o instanceof CTR) { } else if (o instanceof CTR) {
XWPFRun run = new XWPFRun((CTR) o, parent); XWPFRun run = new XWPFRun((CTR) o, parent);
runs.add(run); // runs.add(run);
bodyElements.add(run); bodyElements.add(run);
} }
} }
cursor.dispose(); cursor.dispose();
} }
@Override
public String getText() { public String getText() {
StringBuilder text = new StringBuilder(); StringBuilder text = new StringBuilder();
boolean addNewLine = false; boolean addNewLine = false;
@ -130,6 +131,7 @@ public class XWPFSDTContent implements ISDTContent {
} }
} }
@Override
public String toString() { public String toString() {
return getText(); return getText();
} }

View File

@ -161,8 +161,9 @@ public class XWPFTable implements IBodyElement, ISDTContents {
this.ctTbl = table; this.ctTbl = table;
// is an empty table: I add one row and one column as default // is an empty table: I add one row and one column as default
if (table.sizeOfTrArray() == 0) if (table.sizeOfTrArray() == 0) {
createEmptyTable(table); createEmptyTable(table);
}
for (CTRow row : table.getTrList()) { for (CTRow row : table.getTrList()) {
StringBuilder rowText = new StringBuilder(); StringBuilder rowText = new StringBuilder();
@ -417,7 +418,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
/** /**
* Set table alignment to specified {@link TableRowAlign} * Set table alignment to specified {@link TableRowAlign}
* *
* @param ha {@link TableRowAlign} to set * @param tra {@link TableRowAlign} to set
*/ */
public void setTableAlignment(TableRowAlign tra) { public void setTableAlignment(TableRowAlign tra) {
CTTblPr tPr = getTblPr(true); CTTblPr tPr = getTblPr(true);
@ -1095,10 +1096,12 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* *
* @see org.apache.poi.xwpf.usermodel.IBodyElement#getElementType() * @see org.apache.poi.xwpf.usermodel.IBodyElement#getElementType()
*/ */
@Override
public BodyElementType getElementType() { public BodyElementType getElementType() {
return BodyElementType.TABLE; return BodyElementType.TABLE;
} }
@Override
public IBody getBody() { public IBody getBody() {
return part; return part;
} }
@ -1108,6 +1111,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* *
* @see org.apache.poi.xwpf.usermodel.IBody#getPart() * @see org.apache.poi.xwpf.usermodel.IBody#getPart()
*/ */
@Override
public POIXMLDocumentPart getPart() { public POIXMLDocumentPart getPart() {
if (part != null) { if (part != null) {
return part.getPart(); return part.getPart();
@ -1120,6 +1124,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* *
* @see org.apache.poi.xwpf.usermodel.IBody#getPartType() * @see org.apache.poi.xwpf.usermodel.IBody#getPartType()
*/ */
@Override
public BodyType getPartType() { public BodyType getPartType() {
return part.getPartType(); return part.getPartType();
} }
@ -1130,7 +1135,9 @@ public class XWPFTable implements IBodyElement, ISDTContents {
*/ */
public XWPFTableRow getRow(CTRow row) { public XWPFTableRow getRow(CTRow row) {
for (int i = 0; i < getRows().size(); i++) { for (int i = 0; i < getRows().size(); i++) {
if (getRows().get(i).getCtRow() == row) return getRow(i); if (getRows().get(i).getCtRow() == row) {
return getRow(i);
}
} }
return null; return null;
} }