sonar fixes

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1832719 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2018-06-01 23:54:19 +00:00
parent a6f20de472
commit 6ecad91893
2 changed files with 339 additions and 389 deletions

View File

@ -692,52 +692,51 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/ */
@Override @Override
public void createFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow) { public void createFreezePane(int colSplit, int rowSplit, int leftmostColumn, int topRow) {
CTSheetView ctView = getDefaultSheetView(); final boolean removeSplit = colSplit == 0 && rowSplit == 0;
final CTSheetView ctView = getDefaultSheetView(!removeSplit);
if (ctView != null) {
ctView.setSelectionArray(null);
}
// If both colSplit and rowSplit are zero then the existing freeze pane is removed // If both colSplit and rowSplit are zero then the existing freeze pane is removed
if(colSplit == 0 && rowSplit == 0){ if (removeSplit) {
if(ctView.isSetPane()) { if (ctView != null && ctView.isSetPane()) {
ctView.unsetPane(); ctView.unsetPane();
} }
ctView.setSelectionArray(null);
return; return;
} }
if (!ctView.isSetPane()) { assert(ctView != null);
ctView.addNewPane(); final CTPane pane = (ctView.isSetPane()) ? ctView.getPane() : ctView.addNewPane();
} assert(pane != null);
CTPane pane = ctView.getPane();
if (colSplit > 0) { if (colSplit > 0) {
pane.setXSplit(colSplit); pane.setXSplit(colSplit);
} else { } else if (pane.isSetXSplit()) {
if(pane.isSetXSplit()) { pane.unsetXSplit();
pane.unsetXSplit();
}
} }
if (rowSplit > 0) { if (rowSplit > 0) {
pane.setYSplit(rowSplit); pane.setYSplit(rowSplit);
} else { } else if(pane.isSetYSplit()) {
if(pane.isSetYSplit()) { pane.unsetYSplit();
pane.unsetYSplit(); }
}
STPane.Enum activePane = STPane.BOTTOM_RIGHT;
int pRow = topRow, pCol = leftmostColumn;
if (rowSplit == 0) {
pRow = 0;
activePane = STPane.TOP_RIGHT;
} else if (colSplit == 0) {
pCol = 0;
activePane = STPane.BOTTOM_LEFT;
} }
pane.setState(STPaneState.FROZEN); pane.setState(STPaneState.FROZEN);
if (rowSplit == 0) { pane.setTopLeftCell(new CellReference(pRow, pCol).formatAsString());
pane.setTopLeftCell(new CellReference(0, leftmostColumn).formatAsString()); pane.setActivePane(activePane);
pane.setActivePane(STPane.TOP_RIGHT);
} else if (colSplit == 0) {
pane.setTopLeftCell(new CellReference(topRow, 0).formatAsString());
pane.setActivePane(STPane.BOTTOM_LEFT);
} else {
pane.setTopLeftCell(new CellReference(topRow, leftmostColumn).formatAsString());
pane.setActivePane(STPane.BOTTOM_RIGHT);
}
ctView.setSelectionArray(null); ctView.addNewSelection().setPane(activePane);
CTSelection sel = ctView.addNewSelection();
sel.setPane(pane.getActivePane());
} }
/** /**
@ -801,8 +800,11 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
@Override @Override
public void createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane) { public void createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane) {
createFreezePane(xSplitPos, ySplitPos, leftmostColumn, topRow); createFreezePane(xSplitPos, ySplitPos, leftmostColumn, topRow);
getPane().setState(STPaneState.SPLIT); if (xSplitPos > 0 || ySplitPos > 0) {
getPane().setActivePane(STPane.Enum.forInt(activePane)); final CTPane pane = getPane(true);
pane.setState(STPaneState.SPLIT);
pane.setActivePane(STPane.Enum.forInt(activePane));
}
} }
/** /**
@ -1011,8 +1013,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/ */
@Override @Override
public void setRightToLeft(boolean value) { public void setRightToLeft(boolean value) {
CTSheetView view = getDefaultSheetView(); final CTSheetView dsv = getDefaultSheetView(true);
view.setRightToLeft(value); assert(dsv != null);
dsv.setRightToLeft(value);
} }
/** /**
@ -1022,8 +1025,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/ */
@Override @Override
public boolean isRightToLeft() { public boolean isRightToLeft() {
CTSheetView view = getDefaultSheetView(); final CTSheetView dsv = getDefaultSheetView(false);
return view != null && view.getRightToLeft(); return (dsv != null && dsv.getRightToLeft());
} }
/** /**
@ -1055,12 +1058,12 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
* Gets the flag indicating whether the window should show 0 (zero) in cells containing zero value. * Gets the flag indicating whether the window should show 0 (zero) in cells containing zero value.
* When false, cells with zero value appear blank instead of showing the number zero. * When false, cells with zero value appear blank instead of showing the number zero.
* *
* @return whether all zero values on the worksheet are displayed * @return whether all zero values on the worksheet are displayed (defaults to true)
*/ */
@Override @Override
public boolean isDisplayZeros(){ public boolean isDisplayZeros(){
CTSheetView view = getDefaultSheetView(); final CTSheetView dsv = getDefaultSheetView(false);
return view == null || view.getShowZeros(); return (dsv != null) ? dsv.getShowZeros() : true;
} }
/** /**
@ -1071,7 +1074,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/ */
@Override @Override
public void setDisplayZeros(boolean value){ public void setDisplayZeros(boolean value){
CTSheetView view = getSheetTypeSheetView(); final CTSheetView view = getDefaultSheetView(true);
assert(view != null);
view.setShowZeros(value); view.setShowZeros(value);
} }
@ -1352,16 +1356,25 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/ */
@Override @Override
public PaneInformation getPaneInformation() { public PaneInformation getPaneInformation() {
CTPane pane = getDefaultSheetView().getPane(); final CTPane pane = getPane(false);
// no pane configured // no pane configured
if(pane == null) { if(pane == null) {
return null; return null;
} }
CellReference cellRef = pane.isSetTopLeftCell() ? new CellReference(pane.getTopLeftCell()) : null; short row = 0, col = 0;
return new PaneInformation((short)pane.getXSplit(), (short)pane.getYSplit(), if (pane.isSetTopLeftCell()) {
(short)(cellRef == null ? 0 : cellRef.getRow()),(cellRef == null ? 0 : cellRef.getCol()), final CellReference cellRef = new CellReference(pane.getTopLeftCell());
(byte)(pane.getActivePane().intValue() - 1), pane.getState() == STPaneState.FROZEN); row = (short)cellRef.getRow();
col = (short)cellRef.getCol();
}
final short x = (short)pane.getXSplit();
final short y = (short)pane.getYSplit();
final byte active = (byte)(pane.getActivePane().intValue() - 1);
final boolean frozen = pane.getState() == STPaneState.FROZEN;
return new PaneInformation(x, y, row, col, active, frozen);
} }
/** /**
@ -1606,12 +1619,12 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/ */
@Override @Override
public short getTopRow() { public short getTopRow() {
String cellRef = getSheetTypeSheetView().getTopLeftCell(); final CTSheetView dsv = getDefaultSheetView(false);
final String cellRef = (dsv == null) ? null : dsv.getTopLeftCell();
if(cellRef == null) { if(cellRef == null) {
return 0; return 0;
} }
CellReference cellReference = new CellReference(cellRef); return (short) new CellReference(cellRef).getRow();
return (short) cellReference.getRow();
} }
/** /**
@ -1745,19 +1758,21 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/ */
@Override @Override
public boolean isDisplayFormulas() { public boolean isDisplayFormulas() {
return getSheetTypeSheetView().getShowFormulas(); final CTSheetView dsv = getDefaultSheetView(false);
return (dsv != null) ? dsv.getShowFormulas() : false;
} }
/** /**
* Gets the flag indicating whether this sheet displays the lines * Gets the flag indicating whether this sheet displays the lines
* between rows and columns to make editing and reading easier. * between rows and columns to make editing and reading easier.
* *
* @return <code>true</code> if this sheet displays gridlines. * @return <code>true</code> (default) if this sheet displays gridlines.
* @see #isPrintGridlines() to check if printing of gridlines is turned on or off * @see #isPrintGridlines() to check if printing of gridlines is turned on or off
*/ */
@Override @Override
public boolean isDisplayGridlines() { public boolean isDisplayGridlines() {
return getSheetTypeSheetView().getShowGridLines(); final CTSheetView dsv = getDefaultSheetView(false);
return (dsv != null) ? dsv.getShowGridLines() : true;
} }
/** /**
@ -1771,7 +1786,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/ */
@Override @Override
public void setDisplayGridlines(boolean show) { public void setDisplayGridlines(boolean show) {
getSheetTypeSheetView().setShowGridLines(show); final CTSheetView dsv = getDefaultSheetView(true);
assert(dsv != null);
dsv.setShowGridLines(show);
} }
/** /**
@ -1783,11 +1800,12 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
* Column heading are the letters or numbers that appear above the columns of the sheet * Column heading are the letters or numbers that appear above the columns of the sheet
* </p> * </p>
* *
* @return <code>true</code> if this sheet should display row and column headings. * @return <code>true</code> (default) if this sheet should display row and column headings.
*/ */
@Override @Override
public boolean isDisplayRowColHeadings() { public boolean isDisplayRowColHeadings() {
return getSheetTypeSheetView().getShowRowColHeaders(); final CTSheetView dsv = getDefaultSheetView(false);
return (dsv != null) ? dsv.getShowRowColHeaders() : true;
} }
/** /**
@ -1803,7 +1821,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/ */
@Override @Override
public void setDisplayRowColHeadings(boolean show) { public void setDisplayRowColHeadings(boolean show) {
getSheetTypeSheetView().setShowRowColHeaders(show); final CTSheetView dsv = getDefaultSheetView(true);
assert(dsv != null);
dsv.setShowRowColHeaders(show);
} }
/** /**
@ -2579,14 +2599,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/ */
@Override @Override
public void setDisplayFormulas(boolean show) { public void setDisplayFormulas(boolean show) {
getSheetTypeSheetView().setShowFormulas(show); final CTSheetView dsv = getDefaultSheetView(true);
} assert(dsv != null);
dsv.setShowFormulas(show);
private CTSheetView getSheetTypeSheetView() {
if (getDefaultSheetView() == null) {
getSheetTypeSheetViews().setSheetViewArray(0, CTSheetView.Factory.newInstance());
}
return getDefaultSheetView();
} }
/** /**
@ -2833,7 +2848,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
if (scale < 10 || scale > 400) { if (scale < 10 || scale > 400) {
throw new IllegalArgumentException("Valid scale values range from 10 to 400"); throw new IllegalArgumentException("Valid scale values range from 10 to 400");
} }
getSheetTypeSheetView().setZoomScale(scale); final CTSheetView dsv = getDefaultSheetView(true);
assert(dsv != null);
dsv.setZoomScale(scale);
} }
@ -3265,9 +3282,11 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/ */
@Override @Override
public void showInPane(int toprow, int leftcol) { public void showInPane(int toprow, int leftcol) {
CellReference cellReference = new CellReference(toprow, leftcol); final CellReference cellReference = new CellReference(toprow, leftcol);
String cellRef = cellReference.formatAsString(); final String cellRef = cellReference.formatAsString();
getPane().setTopLeftCell(cellRef); final CTPane pane = getPane(true);
assert(pane != null);
pane.setTopLeftCell(cellRef);
} }
@Override @Override
@ -3323,12 +3342,17 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
getSheetTypeSheetFormatPr().setOutlineLevelCol(maxLevelCol); getSheetTypeSheetFormatPr().setOutlineLevelCol(maxLevelCol);
} }
private CTSheetViews getSheetTypeSheetViews() { protected CTSheetViews getSheetTypeSheetViews(final boolean create) {
if (worksheet.getSheetViews() == null) { final CTSheetViews views = (worksheet.isSetSheetViews() || !create)
worksheet.setSheetViews(CTSheetViews.Factory.newInstance()); ? worksheet.getSheetViews() : worksheet.addNewSheetViews();
worksheet.getSheetViews().addNewSheetView(); assert(views != null || !create);
if (views == null) {
return null;
} }
return worksheet.getSheetViews(); if (views.sizeOfSheetViewArray() == 0 && create) {
views.addNewSheetView();
}
return views;
} }
/** /**
@ -3343,8 +3367,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/ */
@Override @Override
public boolean isSelected() { public boolean isSelected() {
CTSheetView view = getDefaultSheetView(); final CTSheetView dsv = getDefaultSheetView(false);
return view != null && view.getTabSelected(); return (dsv != null) ? dsv.getTabSelected() : false;
} }
/** /**
@ -3360,7 +3384,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/ */
@Override @Override
public void setSelected(boolean value) { public void setSelected(boolean value) {
CTSheetViews views = getSheetTypeSheetViews(); final CTSheetViews views = getSheetTypeSheetViews(true);
assert(views != null);
for (CTSheetView view : views.getSheetViewArray()) { for (CTSheetView view : views.getSheetViewArray()) {
view.setTabSelected(value); view.setTabSelected(value);
} }
@ -3404,11 +3429,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/ */
@Override @Override
public CellAddress getActiveCell() { public CellAddress getActiveCell() {
String address = getSheetTypeSelection().getActiveCell(); final CTSelection sts = getSheetTypeSelection(false);
if (address == null) { final String address = (sts != null) ? sts.getActiveCell() : null;
return null; return (address != null) ? new CellAddress(address) : null;
}
return new CellAddress(address);
} }
/** /**
@ -3416,8 +3439,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/ */
@Override @Override
public void setActiveCell(CellAddress address) { public void setActiveCell(CellAddress address) {
final CTSelection ctsel = getSheetTypeSelection(true);
assert(ctsel != null);
String ref = address.formatAsString(); String ref = address.formatAsString();
CTSelection ctsel = getSheetTypeSelection();
ctsel.setActiveCell(ref); ctsel.setActiveCell(ref);
ctsel.setSqref(Collections.singletonList(ref)); ctsel.setSqref(Collections.singletonList(ref));
} }
@ -3434,11 +3458,17 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
return sheetComments == null ? 0 : sheetComments.getNumberOfComments(); return sheetComments == null ? 0 : sheetComments.getNumberOfComments();
} }
private CTSelection getSheetTypeSelection() { private CTSelection getSheetTypeSelection(final boolean create) {
if (getSheetTypeSheetView().sizeOfSelectionArray() == 0) { final CTSheetView dsv = getDefaultSheetView(create);
getSheetTypeSheetView().insertNewSelection(0); assert(dsv != null || !create);
if (dsv == null) {
return null;
} }
return getSheetTypeSheetView().getSelectionArray(0); final int sz = dsv.sizeOfSelectionArray();
if (sz == 0) {
return create ? dsv.addNewSelection() : null;
}
return dsv.getSelectionArray(sz - 1);
} }
/** /**
@ -3450,12 +3480,14 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
* When multiple windows are viewing the same sheet, multiple sheetView elements (with corresponding * When multiple windows are viewing the same sheet, multiple sheetView elements (with corresponding
* workbookView entries) are saved." * workbookView entries) are saved."
*/ */
private CTSheetView getDefaultSheetView() { private CTSheetView getDefaultSheetView(final boolean create) {
CTSheetViews views = getSheetTypeSheetViews(); final CTSheetViews views = getSheetTypeSheetViews(create);
assert(views != null || !create);
if (views == null) { if (views == null) {
return null; return null;
} }
int sz = views.sizeOfSheetViewArray(); final int sz = views.sizeOfSheetViewArray();
assert(sz > 0 || !create);
return (sz == 0) ? null : views.getSheetViewArray(sz - 1); return (sz == 0) ? null : views.getSheetViewArray(sz - 1);
} }
@ -3502,11 +3534,13 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
return false; return false;
} }
private CTPane getPane() { private CTPane getPane(final boolean create) {
if (getDefaultSheetView().getPane() == null) { final CTSheetView dsv = getDefaultSheetView(create);
getDefaultSheetView().addNewPane(); assert(dsv != null || !create);
if (dsv == null) {
return null;
} }
return getDefaultSheetView().getPane(); return (dsv.isSetPane() || !create) ? dsv.getPane() : dsv.addNewPane();
} }
/** /**

View File

@ -22,6 +22,9 @@ import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Collections; import java.util.Collections;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.apache.poi.ooxml.POIXMLDocumentPart; import org.apache.poi.ooxml.POIXMLDocumentPart;
import org.apache.poi.util.Internal; import org.apache.poi.util.Internal;
@ -48,10 +51,24 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTblWidth;
* <p>Specifies the contents of a table present in the document. A table is a set * <p>Specifies the contents of a table present in the document. A table is a set
* of paragraphs (and other block-level content) arranged in rows and columns.</p> * of paragraphs (and other block-level content) arranged in rows and columns.</p>
*/ */
@SuppressWarnings("WeakerAccess")
public class XWPFTable implements IBodyElement, ISDTContents { public class XWPFTable implements IBodyElement, ISDTContents {
private static EnumMap<XWPFBorderType, STBorder.Enum> xwpfBorderTypeMap;
// Create a map from this XWPF-level enum to the STBorder.Enum values
public enum XWPFBorderType {
NIL, NONE, SINGLE, THICK, DOUBLE, DOTTED, DASHED, DOT_DASH, DOT_DOT_DASH, TRIPLE,
THIN_THICK_SMALL_GAP, THICK_THIN_SMALL_GAP, THIN_THICK_THIN_SMALL_GAP,
THIN_THICK_MEDIUM_GAP, THICK_THIN_MEDIUM_GAP, THIN_THICK_THIN_MEDIUM_GAP,
THIN_THICK_LARGE_GAP, THICK_THIN_LARGE_GAP, THIN_THICK_THIN_LARGE_GAP,
WAVE, DOUBLE_WAVE, DASH_SMALL_GAP, DASH_DOT_STROKED, THREE_D_EMBOSS, THREE_D_ENGRAVE,
OUTSET, INSET;
}
private enum Border { INSIDE_V, INSIDE_H, LEFT, TOP, BOTTOM, RIGHT }
private static final EnumMap<XWPFBorderType, STBorder.Enum> xwpfBorderTypeMap;
// Create a map from the STBorder.Enum values to the XWPF-level enums // Create a map from the STBorder.Enum values to the XWPF-level enums
private static HashMap<Integer, XWPFBorderType> stBorderTypeMap; private static final HashMap<Integer, XWPFBorderType> stBorderTypeMap;
static { static {
// populate enum maps // populate enum maps
@ -303,7 +320,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* @param force - force creation of CTTblPr element if necessary * @param force - force creation of CTTblPr element if necessary
*/ */
private CTTblPr getTblPr(boolean force) { private CTTblPr getTblPr(boolean force) {
return (ctTbl.getTblPr() != null) ? ctTbl.getTblPr() return (ctTbl.getTblPr() != null) ? ctTbl.getTblPr()
: (force ? ctTbl.addNewTblPr() : null); : (force ? ctTbl.addNewTblPr() : null);
} }
@ -321,97 +338,61 @@ public class XWPFTable implements IBodyElement, ISDTContents {
: force ? tblPr.addNewTblBorders() : force ? tblPr.addNewTblBorders()
: null; : null;
} }
/**
* Return CTBorder object for Inside Vertical border. If force parameter is true,
* will create the element if necessary. If force parameter is false, returns
* null when Inside Vertical border is missing.
*
* @param force - force creation of Inside Vertical border if necessary.
*/
private CTBorder getTblInsideVBorder(boolean force) {
CTTblBorders ctb = getTblBorders(force);
return ctb == null ? null
: ctb.isSetInsideV() ? ctb.getInsideV()
: force ? ctb.addNewInsideV()
: null;
}
/** /**
* Return CTBorder object for Inside Horizontal border. If force parameter is true, * Return CTBorder object for given border. If force parameter is true,
* will create the element if necessary. If force parameter is false, returns * will create the element if necessary. If force parameter is false, returns
* null when Inside Horizontal border is missing. * null when the border element is missing.
* *
* @param force - force creation of Inside Horizontal border if necessary. * @param force - force creation of border if necessary.
*/ */
private CTBorder getTblInsideHBorder(boolean force) { private CTBorder getTblBorder(boolean force, Border border) {
final Function<CTTblBorders,Boolean> isSet;
final Function<CTTblBorders,CTBorder> get;
final Function<CTTblBorders,CTBorder> addNew;
switch (border) {
case INSIDE_V:
isSet = CTTblBorders::isSetInsideV;
get = CTTblBorders::getInsideV;
addNew = CTTblBorders::addNewInsideV;
break;
case INSIDE_H:
isSet = CTTblBorders::isSetInsideH;
get = CTTblBorders::getInsideH;
addNew = CTTblBorders::addNewInsideH;
break;
case LEFT:
isSet = CTTblBorders::isSetLeft;
get = CTTblBorders::getLeft;
addNew = CTTblBorders::addNewLeft;
break;
case TOP:
isSet = CTTblBorders::isSetTop;
get = CTTblBorders::getTop;
addNew = CTTblBorders::addNewTop;
break;
case RIGHT:
isSet = CTTblBorders::isSetRight;
get = CTTblBorders::getRight;
addNew = CTTblBorders::addNewRight;
break;
case BOTTOM:
isSet = CTTblBorders::isSetBottom;
get = CTTblBorders::getBottom;
addNew = CTTblBorders::addNewBottom;
break;
default:
return null;
}
CTTblBorders ctb = getTblBorders(force); CTTblBorders ctb = getTblBorders(force);
return ctb == null ? null return ctb == null ? null
: ctb.isSetInsideH() ? ctb.getInsideH() : isSet.apply(ctb) ? get.apply(ctb)
: force ? ctb.addNewInsideH() : force ? addNew.apply(ctb)
: null; : null;
} }
/**
* Return CTBorder object for Top border. If force parameter is true,
* will create the element if necessary. If force parameter is false, returns
* null when Top border is missing.
*
* @param force - force creation of Top border if necessary.
*/
private CTBorder getTblTopBorder(boolean force) {
CTTblBorders ctb = getTblBorders(force);
return ctb == null ? null
: ctb.isSetTop() ? ctb.getTop()
: force ? ctb.addNewTop()
: null;
}
/**
* Return CTBorder object for Bottom border. If force parameter is true,
* will create the element if necessary. If force parameter is false, returns
* null when Bottom border is missing.
*
* @param force - force creation of Bottom border if necessary.
*/
private CTBorder getTblBottomBorder(boolean force) {
CTTblBorders ctb = getTblBorders(force);
return ctb == null ? null
: ctb.isSetBottom() ? ctb.getBottom()
: force ? ctb.addNewBottom()
: null;
}
/**
* Return CTBorder object for Left border. If force parameter is true,
* will create the element if necessary. If force parameter is false, returns
* null when Left border is missing.
*
* @param force - force creation of Left border if necessary.
*/
private CTBorder getTblLeftBorder(boolean force) {
CTTblBorders ctb = getTblBorders(force);
return ctb == null ? null
: ctb.isSetLeft() ? ctb.getLeft()
: force ? ctb.addNewLeft()
: null;
}
/**
* Return CTBorder object for Right border. If force parameter is true,
* will create the element if necessary. If force parameter is false, returns
* null when Right border is missing.
*
* @param force - force creation of Right border if necessary.
*/
private CTBorder getTblRightBorder(boolean force) {
CTTblBorders ctb = getTblBorders(force);
return ctb == null ? null
: ctb.isSetRight() ? ctb.getRight()
: force ? ctb.addNewRight()
: null;
}
/** /**
* Returns the current table alignment or NULL * Returns the current table alignment or NULL
* *
@ -491,8 +472,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* @return {@link XWPFBorderType} of the inside horizontal borders or null if missing * @return {@link XWPFBorderType} of the inside horizontal borders or null if missing
*/ */
public XWPFBorderType getInsideHBorderType() { public XWPFBorderType getInsideHBorderType() {
CTBorder b = getTblInsideHBorder(false); return getBorderType(Border.INSIDE_H);
return (b != null) ? stBorderTypeMap.get(b.getVal().intValue()) : null;
} }
/** /**
@ -502,10 +482,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* -1 if missing. * -1 if missing.
*/ */
public int getInsideHBorderSize() { public int getInsideHBorderSize() {
CTBorder b = getTblInsideHBorder(false); return getBorderSize(Border.INSIDE_H);
return (b != null)
? (b.isSetSz() ? b.getSz().intValue() : -1)
: -1;
} }
/** /**
@ -515,10 +492,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* -1 if missing. * -1 if missing.
*/ */
public int getInsideHBorderSpace() { public int getInsideHBorderSpace() {
CTBorder b = getTblInsideHBorder(false); return getBorderSpace(Border.INSIDE_H);
return (b != null)
? (b.isSetSpace() ? b.getSpace().intValue() : -1)
: -1;
} }
/** /**
@ -527,10 +501,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* @return The color of the Inside Horizontal borders, null if missing. * @return The color of the Inside Horizontal borders, null if missing.
*/ */
public String getInsideHBorderColor() { public String getInsideHBorderColor() {
CTBorder b = getTblInsideHBorder(false); return getBorderColor(Border.INSIDE_H);
return (b != null)
? (b.isSetColor() ? b.xgetColor().getStringValue() : null)
: null;
} }
/** /**
@ -539,8 +510,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* @return {@link XWPFBorderType} of the inside vertical borders or null if missing * @return {@link XWPFBorderType} of the inside vertical borders or null if missing
*/ */
public XWPFBorderType getInsideVBorderType() { public XWPFBorderType getInsideVBorderType() {
CTBorder b = getTblInsideVBorder(false); return getBorderType(Border.INSIDE_V);
return (b != null) ? stBorderTypeMap.get(b.getVal().intValue()) : null;
} }
/** /**
@ -550,10 +520,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* -1 if missing. * -1 if missing.
*/ */
public int getInsideVBorderSize() { public int getInsideVBorderSize() {
CTBorder b = getTblInsideVBorder(false); return getBorderSize(Border.INSIDE_V);
return (b != null)
? (b.isSetSz() ? b.getSz().intValue() : -1)
: -1;
} }
/** /**
@ -563,10 +530,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* -1 if missing. * -1 if missing.
*/ */
public int getInsideVBorderSpace() { public int getInsideVBorderSpace() {
CTBorder b = getTblInsideVBorder(false); return getBorderSpace(Border.INSIDE_V);
return (b != null)
? (b.isSetSpace() ? b.getSpace().intValue() : -1)
: -1;
} }
/** /**
@ -575,10 +539,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* @return The color of the Inside vertical borders, null if missing. * @return The color of the Inside vertical borders, null if missing.
*/ */
public String getInsideVBorderColor() { public String getInsideVBorderColor() {
CTBorder b = getTblInsideVBorder(false); return getBorderColor(Border.INSIDE_V);
return (b != null)
? (b.isSetColor() ? b.xgetColor().getStringValue() : null)
: null;
} }
/** /**
@ -587,8 +548,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* @return {@link XWPFBorderType} of the top borders or null if missing * @return {@link XWPFBorderType} of the top borders or null if missing
*/ */
public XWPFBorderType getTopBorderType() { public XWPFBorderType getTopBorderType() {
CTBorder b = getTblTopBorder(false); return getBorderType(Border.TOP);
return (b != null) ? stBorderTypeMap.get(b.getVal().intValue()) : null;
} }
/** /**
@ -598,10 +558,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* -1 if missing. * -1 if missing.
*/ */
public int getTopBorderSize() { public int getTopBorderSize() {
CTBorder b = getTblTopBorder(false); return getBorderSize(Border.TOP);
return (b != null)
? (b.isSetSz() ? b.getSz().intValue() : -1)
: -1;
} }
/** /**
@ -611,10 +568,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* -1 if missing. * -1 if missing.
*/ */
public int getTopBorderSpace() { public int getTopBorderSpace() {
CTBorder b = getTblTopBorder(false); return getBorderSpace(Border.TOP);
return (b != null)
? (b.isSetSpace() ? b.getSpace().intValue() : -1)
: -1;
} }
/** /**
@ -623,10 +577,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* @return The color of the top borders, null if missing. * @return The color of the top borders, null if missing.
*/ */
public String getTopBorderColor() { public String getTopBorderColor() {
CTBorder b = getTblTopBorder(false); return getBorderColor(Border.TOP);
return (b != null)
? (b.isSetColor() ? b.xgetColor().getStringValue() : null)
: null;
} }
/** /**
@ -635,8 +586,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* @return {@link XWPFBorderType} of the bottom borders or null if missing * @return {@link XWPFBorderType} of the bottom borders or null if missing
*/ */
public XWPFBorderType getBottomBorderType() { public XWPFBorderType getBottomBorderType() {
CTBorder b = getTblBottomBorder(false); return getBorderType(Border.BOTTOM);
return (b != null) ? stBorderTypeMap.get(b.getVal().intValue()) : null;
} }
/** /**
@ -646,10 +596,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* -1 if missing. * -1 if missing.
*/ */
public int getBottomBorderSize() { public int getBottomBorderSize() {
CTBorder b = getTblBottomBorder(false); return getBorderSize(Border.BOTTOM);
return (b != null)
? (b.isSetSz() ? b.getSz().intValue() : -1)
: -1;
} }
/** /**
@ -659,10 +606,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* -1 if missing. * -1 if missing.
*/ */
public int getBottomBorderSpace() { public int getBottomBorderSpace() {
CTBorder b = getTblBottomBorder(false); return getBorderSpace(Border.BOTTOM);
return (b != null)
? (b.isSetSpace() ? b.getSpace().intValue() : -1)
: -1;
} }
/** /**
@ -671,10 +615,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* @return The color of the bottom borders, null if missing. * @return The color of the bottom borders, null if missing.
*/ */
public String getBottomBorderColor() { public String getBottomBorderColor() {
CTBorder b = getTblBottomBorder(false); return getBorderColor(Border.BOTTOM);
return (b != null)
? (b.isSetColor() ? b.xgetColor().getStringValue() : null)
: null;
} }
/** /**
@ -683,8 +624,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* @return {@link XWPFBorderType} of the Left borders or null if missing * @return {@link XWPFBorderType} of the Left borders or null if missing
*/ */
public XWPFBorderType getLeftBorderType() { public XWPFBorderType getLeftBorderType() {
CTBorder b = getTblLeftBorder(false); return getBorderType(Border.LEFT);
return (b != null) ? stBorderTypeMap.get(b.getVal().intValue()) : null;
} }
/** /**
@ -694,10 +634,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* -1 if missing. * -1 if missing.
*/ */
public int getLeftBorderSize() { public int getLeftBorderSize() {
CTBorder b = getTblLeftBorder(false); return getBorderSize(Border.LEFT);
return (b != null)
? (b.isSetSz() ? b.getSz().intValue() : -1)
: -1;
} }
/** /**
@ -707,10 +644,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* -1 if missing. * -1 if missing.
*/ */
public int getLeftBorderSpace() { public int getLeftBorderSpace() {
CTBorder b = getTblLeftBorder(false); return getBorderSpace(Border.LEFT);
return (b != null)
? (b.isSetSpace() ? b.getSpace().intValue() : -1)
: -1;
} }
/** /**
@ -719,10 +653,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* @return The color of the Left borders, null if missing. * @return The color of the Left borders, null if missing.
*/ */
public String getLeftBorderColor() { public String getLeftBorderColor() {
CTBorder b = getTblLeftBorder(false); return getBorderColor(Border.LEFT);
return (b != null)
? (b.isSetColor() ? b.xgetColor().getStringValue() : null)
: null;
} }
/** /**
@ -731,8 +662,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* @return {@link XWPFBorderType} of the Right borders or null if missing * @return {@link XWPFBorderType} of the Right borders or null if missing
*/ */
public XWPFBorderType getRightBorderType() { public XWPFBorderType getRightBorderType() {
CTBorder b = getTblRightBorder(false); return getBorderType(Border.RIGHT);
return (b != null) ? stBorderTypeMap.get(b.getVal().intValue()) : null;
} }
/** /**
@ -742,10 +672,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* -1 if missing. * -1 if missing.
*/ */
public int getRightBorderSize() { public int getRightBorderSize() {
CTBorder b = getTblRightBorder(false); return getBorderSize(Border.RIGHT);
return (b != null)
? (b.isSetSz() ? b.getSz().intValue() : -1)
: -1;
} }
/** /**
@ -755,10 +682,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* -1 if missing. * -1 if missing.
*/ */
public int getRightBorderSpace() { public int getRightBorderSpace() {
CTBorder b = getTblRightBorder(false); return getBorderSpace(Border.RIGHT);
return (b != null)
? (b.isSetSpace() ? b.getSpace().intValue() : -1)
: -1;
} }
/** /**
@ -767,10 +691,33 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* @return The color of the Right borders, null if missing. * @return The color of the Right borders, null if missing.
*/ */
public String getRightBorderColor() { public String getRightBorderColor() {
CTBorder b = getTblRightBorder(false); return getBorderColor(Border.RIGHT);
return (b != null) }
private XWPFBorderType getBorderType(Border border) {
final CTBorder b = getTblBorder(false, border);
return (b != null) ? stBorderTypeMap.get(b.getVal().intValue()) : null;
}
private int getBorderSize(Border border) {
final CTBorder b = getTblBorder(false, border);
return (b != null)
? (b.isSetSz() ? b.getSz().intValue() : -1)
: -1;
}
private int getBorderSpace(Border border) {
final CTBorder b = getTblBorder(false, border);
return (b != null)
? (b.isSetSpace() ? b.getSpace().intValue() : -1)
: -1;
}
private String getBorderColor(Border border) {
final CTBorder b = getTblBorder(false, border);
return (b != null)
? (b.isSetColor() ? b.xgetColor().getStringValue() : null) ? (b.isSetColor() ? b.xgetColor().getStringValue() : null)
: null; : null;
} }
public int getRowBandSize() { public int getRowBandSize() {
@ -818,11 +765,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* or auto to allow a consumer to automatically determine the border color as appropriate. * or auto to allow a consumer to automatically determine the border color as appropriate.
*/ */
public void setInsideHBorder(XWPFBorderType type, int size, int space, String rgbColor) { public void setInsideHBorder(XWPFBorderType type, int size, int space, String rgbColor) {
CTBorder b = getTblInsideHBorder(true); setBorder(Border.INSIDE_H, type, size, space, rgbColor);
b.setVal(xwpfBorderTypeMap.get(type));
b.setSz(BigInteger.valueOf(size));
b.setSpace(BigInteger.valueOf(space));
b.setColor(rgbColor);
} }
/** /**
@ -838,11 +781,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* or auto to allow a consumer to automatically determine the border color as appropriate. * or auto to allow a consumer to automatically determine the border color as appropriate.
*/ */
public void setInsideVBorder(XWPFBorderType type, int size, int space, String rgbColor) { public void setInsideVBorder(XWPFBorderType type, int size, int space, String rgbColor) {
CTBorder b = getTblInsideVBorder(true); setBorder(Border.INSIDE_V, type, size, space, rgbColor);
b.setVal(xwpfBorderTypeMap.get(type));
b.setSz(BigInteger.valueOf(size));
b.setSpace(BigInteger.valueOf(space));
b.setColor(rgbColor);
} }
/** /**
@ -858,11 +797,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* or auto to allow a consumer to automatically determine the border color as appropriate. * or auto to allow a consumer to automatically determine the border color as appropriate.
*/ */
public void setTopBorder(XWPFBorderType type, int size, int space, String rgbColor) { public void setTopBorder(XWPFBorderType type, int size, int space, String rgbColor) {
CTBorder b = getTblTopBorder(true); setBorder(Border.TOP, type, size, space, rgbColor);
b.setVal(xwpfBorderTypeMap.get(type));
b.setSz(BigInteger.valueOf(size));
b.setSpace(BigInteger.valueOf(space));
b.setColor(rgbColor);
} }
/** /**
@ -878,11 +813,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* or auto to allow a consumer to automatically determine the border color as appropriate. * or auto to allow a consumer to automatically determine the border color as appropriate.
*/ */
public void setBottomBorder(XWPFBorderType type, int size, int space, String rgbColor) { public void setBottomBorder(XWPFBorderType type, int size, int space, String rgbColor) {
CTBorder b = getTblBottomBorder(true); setBorder(Border.BOTTOM, type, size, space, rgbColor);
b.setVal(xwpfBorderTypeMap.get(type));
b.setSz(BigInteger.valueOf(size));
b.setSpace(BigInteger.valueOf(space));
b.setColor(rgbColor);
} }
/** /**
@ -898,11 +829,7 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* or auto to allow a consumer to automatically determine the border color as appropriate. * or auto to allow a consumer to automatically determine the border color as appropriate.
*/ */
public void setLeftBorder(XWPFBorderType type, int size, int space, String rgbColor) { public void setLeftBorder(XWPFBorderType type, int size, int space, String rgbColor) {
CTBorder b = getTblLeftBorder(true); setBorder(Border.LEFT, type, size, space, rgbColor);
b.setVal(xwpfBorderTypeMap.get(type));
b.setSz(BigInteger.valueOf(size));
b.setSpace(BigInteger.valueOf(space));
b.setColor(rgbColor);
} }
/** /**
@ -918,178 +845,177 @@ public class XWPFTable implements IBodyElement, ISDTContents {
* or auto to allow a consumer to automatically determine the border color as appropriate. * or auto to allow a consumer to automatically determine the border color as appropriate.
*/ */
public void setRightBorder(XWPFBorderType type, int size, int space, String rgbColor) { public void setRightBorder(XWPFBorderType type, int size, int space, String rgbColor) {
CTBorder b = getTblRightBorder(true); setBorder(Border.RIGHT, type, size, space, rgbColor);
}
private void setBorder(Border border, XWPFBorderType type, int size, int space, String rgbColor) {
final CTBorder b = getTblBorder(true, border);
assert(b != null);
b.setVal(xwpfBorderTypeMap.get(type)); b.setVal(xwpfBorderTypeMap.get(type));
b.setSz(BigInteger.valueOf(size)); b.setSz(BigInteger.valueOf(size));
b.setSpace(BigInteger.valueOf(space)); b.setSpace(BigInteger.valueOf(space));
b.setColor(rgbColor); b.setColor(rgbColor);
} }
/** /**
* Remove inside horizontal borders for table * Remove inside horizontal borders for table
*/ */
public void removeInsideHBorder() { public void removeInsideHBorder() {
CTBorder b = getTblInsideHBorder(false); removeBorder(Border.INSIDE_H);
if (b != null) {
getTblBorders(false).unsetInsideH();
cleanupTblBorders();
}
} }
/** /**
* Remove inside vertical borders for table * Remove inside vertical borders for table
*/ */
public void removeInsideVBorder() { public void removeInsideVBorder() {
CTBorder b = getTblInsideVBorder(false); removeBorder(Border.INSIDE_V);
if (b != null) {
getTblBorders(false).unsetInsideV();
cleanupTblBorders();
}
} }
/** /**
* Remove top borders for table * Remove top borders for table
*/ */
public void removeTopBorder() { public void removeTopBorder() {
CTBorder b = getTblTopBorder(false); removeBorder(Border.TOP);
if (b != null) {
getTblBorders(false).unsetTop();
cleanupTblBorders();
}
} }
/** /**
* Remove bottom borders for table * Remove bottom borders for table
*/ */
public void removeBottomBorder() { public void removeBottomBorder() {
CTBorder b = getTblBottomBorder(false); removeBorder(Border.BOTTOM);
if (b != null) {
getTblBorders(false).unsetBottom();
cleanupTblBorders();
}
} }
/** /**
* Remove left borders for table * Remove left borders for table
*/ */
public void removeLeftBorder() { public void removeLeftBorder() {
CTBorder b = getTblLeftBorder(false); removeBorder(Border.LEFT);
if (b != null) {
getTblBorders(false).unsetLeft();
cleanupTblBorders();
}
} }
/** /**
* Remove right borders for table * Remove right borders for table
*/ */
public void removeRightBorder() { public void removeRightBorder() {
CTBorder b = getTblRightBorder(false); removeBorder(Border.RIGHT);
if (b != null) {
getTblBorders(false).unsetRight();
cleanupTblBorders();
}
} }
/** /**
* Remove all borders from table * Remove all borders from table
*/ */
public void removeBorders() { public void removeBorders() {
CTTblBorders b = getTblBorders(false); final CTTblPr pr = getTblPr(false);
if (b != null) { if (pr != null && pr.isSetTblBorders()) {
getTblPr(false).unsetTblBorders(); pr.unsetTblBorders();
} }
} }
private void removeBorder(final Border border) {
final Function<CTTblBorders,Boolean> isSet;
final Consumer<CTTblBorders> unSet;
switch (border) {
case INSIDE_H:
isSet = CTTblBorders::isSetInsideH;
unSet = CTTblBorders::unsetInsideH;
break;
case INSIDE_V:
isSet = CTTblBorders::isSetInsideV;
unSet = CTTblBorders::unsetInsideV;
break;
case LEFT:
isSet = CTTblBorders::isSetLeft;
unSet = CTTblBorders::unsetLeft;
break;
case TOP:
isSet = CTTblBorders::isSetTop;
unSet = CTTblBorders::unsetTop;
break;
case RIGHT:
isSet = CTTblBorders::isSetRight;
unSet = CTTblBorders::unsetRight;
break;
case BOTTOM:
isSet = CTTblBorders::isSetBottom;
unSet = CTTblBorders::unsetBottom;
break;
default:
return;
}
final CTTblBorders tbl = getTblBorders(false);
if (tbl != null && isSet.apply(tbl)) {
unSet.accept(tbl);
cleanupTblBorders();
}
}
/** /**
* removes the Borders node from Table properties if there are * removes the Borders node from Table properties if there are
* no border elements * no border elements
*/ */
private void cleanupTblBorders() { private void cleanupTblBorders() {
CTTblBorders b = getTblBorders(false); final CTTblPr pr = getTblPr(false);
if (b != null) { if (pr != null && pr.isSetTblBorders()) {
if (b.getInsideH() == null && final CTTblBorders b = pr.getTblBorders();
b.getInsideV() == null && if (!(b.isSetInsideH() ||
b.getTop() == null && b.isSetInsideV() ||
b.getBottom() == null && b.isSetTop() ||
b.getLeft() == null && b.isSetBottom() ||
b.getRight() == null) { b.isSetLeft() ||
getTblPr(false).unsetTblBorders(); b.isSetRight())) {
pr.unsetTblBorders();
} }
} }
} }
public int getCellMarginTop() { public int getCellMarginTop() {
int margin = 0; return getCellMargin(CTTblCellMar::getTop);
CTTblPr tblPr = getTblPr();
CTTblCellMar tcm = tblPr.getTblCellMar();
if (tcm != null) {
CTTblWidth tw = tcm.getTop();
if (tw != null) {
margin = tw.getW().intValue();
}
}
return margin;
} }
public int getCellMarginLeft() { public int getCellMarginLeft() {
int margin = 0; return getCellMargin(CTTblCellMar::getLeft);
CTTblPr tblPr = getTblPr();
CTTblCellMar tcm = tblPr.getTblCellMar();
if (tcm != null) {
CTTblWidth tw = tcm.getLeft();
if (tw != null) {
margin = tw.getW().intValue();
}
}
return margin;
} }
public int getCellMarginBottom() { public int getCellMarginBottom() {
int margin = 0; return getCellMargin(CTTblCellMar::getBottom);
CTTblPr tblPr = getTblPr();
CTTblCellMar tcm = tblPr.getTblCellMar();
if (tcm != null) {
CTTblWidth tw = tcm.getBottom();
if (tw != null) {
margin = tw.getW().intValue();
}
}
return margin;
} }
public int getCellMarginRight() { public int getCellMarginRight() {
int margin = 0; return getCellMargin(CTTblCellMar::getRight);
}
private int getCellMargin(Function<CTTblCellMar,CTTblWidth> margin) {
CTTblPr tblPr = getTblPr(); CTTblPr tblPr = getTblPr();
CTTblCellMar tcm = tblPr.getTblCellMar(); CTTblCellMar tcm = tblPr.getTblCellMar();
if (tcm != null) { if (tcm != null) {
CTTblWidth tw = tcm.getRight(); CTTblWidth tw = margin.apply(tcm);
if (tw != null) { if (tw != null) {
margin = tw.getW().intValue(); return tw.getW().intValue();
} }
} }
return margin; return 0;
} }
public void setCellMargins(int top, int left, int bottom, int right) { public void setCellMargins(int top, int left, int bottom, int right) {
CTTblPr tblPr = getTblPr(); CTTblPr tblPr = getTblPr();
CTTblCellMar tcm = tblPr.isSetTblCellMar() ? tblPr.getTblCellMar() : tblPr.addNewTblCellMar(); CTTblCellMar tcm = tblPr.isSetTblCellMar() ? tblPr.getTblCellMar() : tblPr.addNewTblCellMar();
CTTblWidth tw = tcm.isSetLeft() ? tcm.getLeft() : tcm.addNewLeft(); setCellMargin(tcm, CTTblCellMar::isSetTop, CTTblCellMar::getTop, CTTblCellMar::addNewTop, CTTblCellMar::unsetTop, top);
tw.setType(STTblWidth.DXA); setCellMargin(tcm, CTTblCellMar::isSetLeft, CTTblCellMar::getLeft, CTTblCellMar::addNewLeft, CTTblCellMar::unsetLeft, left);
tw.setW(BigInteger.valueOf(left)); setCellMargin(tcm, CTTblCellMar::isSetBottom, CTTblCellMar::getBottom, CTTblCellMar::addNewBottom, CTTblCellMar::unsetBottom, bottom);
setCellMargin(tcm, CTTblCellMar::isSetRight, CTTblCellMar::getRight, CTTblCellMar::addNewRight, CTTblCellMar::unsetRight, right);
}
tw = tcm.isSetTop() ? tcm.getTop() : tcm.addNewTop(); private void setCellMargin(CTTblCellMar tcm, Function<CTTblCellMar,Boolean> isSet, Function<CTTblCellMar,CTTblWidth> get, Function<CTTblCellMar,CTTblWidth> addNew, Consumer<CTTblCellMar> unSet, int margin) {
tw.setType(STTblWidth.DXA); if (margin == 0) {
tw.setW(BigInteger.valueOf(top)); if (isSet.apply(tcm)) {
unSet.accept(tcm);
tw = tcm.isSetBottom() ? tcm.getBottom() : tcm.addNewBottom(); }
tw.setType(STTblWidth.DXA); } else {
tw.setW(BigInteger.valueOf(bottom)); CTTblWidth tw = (isSet.apply(tcm) ? get : addNew).apply(tcm);
tw.setType(STTblWidth.DXA);
tw = tcm.isSetRight() ? tcm.getRight() : tcm.addNewRight(); tw.setW(BigInteger.valueOf(margin));
tw.setType(STTblWidth.DXA); }
tw.setW(BigInteger.valueOf(right));
} }
/** /**
@ -1199,14 +1125,4 @@ public class XWPFTable implements IBodyElement, ISDTContents {
} }
return null; return null;
} }
// Create a map from this XWPF-level enum to the STBorder.Enum values
public static enum XWPFBorderType {
NIL, NONE, SINGLE, THICK, DOUBLE, DOTTED, DASHED, DOT_DASH, DOT_DOT_DASH, TRIPLE,
THIN_THICK_SMALL_GAP, THICK_THIN_SMALL_GAP, THIN_THICK_THIN_SMALL_GAP,
THIN_THICK_MEDIUM_GAP, THICK_THIN_MEDIUM_GAP, THIN_THICK_THIN_MEDIUM_GAP,
THIN_THICK_LARGE_GAP, THICK_THIN_LARGE_GAP, THIN_THICK_THIN_LARGE_GAP,
WAVE, DOUBLE_WAVE, DASH_SMALL_GAP, DASH_DOT_STROKED, THREE_D_EMBOSS, THREE_D_ENGRAVE,
OUTSET, INSET;
}
} }