bug 59264: type safety: check if border code is a valid BorderStyle enum for setBorderX(short)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1737886 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-04-05 21:38:55 +00:00
parent 5752c4bb7e
commit e2399abbe9

View File

@ -790,33 +790,11 @@ public class XSSFCellStyle implements CellStyle {
* Set the type of border to use for the bottom border of the cell * Set the type of border to use for the bottom border of the cell
* *
* @param border the type of border to use * @param border the type of border to use
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_NONE * @deprecated 3.15 beta 1. Use {@link #setBorderBottom(BorderStyle)}
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_THIN
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASHED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DOTTED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_THICK
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DOUBLE
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_HAIR
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASHED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/ */
@Override @Override
public void setBorderBottom(short border) { public void setBorderBottom(short border) {
CTBorder ct = getCTBorder(); setBorderBottom(BorderStyle.valueOf(border));
CTBorderPr pr = ct.isSetBottom() ? ct.getBottom() : ct.addNewBottom();
if(border == BORDER_NONE) ct.unsetBottom();
else pr.setStyle(STBorderStyle.Enum.forInt(border + 1));
int idx = _stylesSource.putBorder(new XSSFCellBorder(ct, _theme));
_cellXf.setBorderId(idx);
_cellXf.setApplyBorder(true);
} }
/** /**
@ -827,34 +805,10 @@ public class XSSFCellStyle implements CellStyle {
*/ */
@Override @Override
public void setBorderBottom(BorderStyle border) { public void setBorderBottom(BorderStyle border) {
setBorderBottom(border.getCode());
}
/**
* Set the type of border to use for the left border of the cell
* @param border the type of border to use
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_NONE
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_THIN
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASHED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DOTTED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_THICK
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DOUBLE
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_HAIR
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASHED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/
@Override
public void setBorderLeft(short border) {
CTBorder ct = getCTBorder(); CTBorder ct = getCTBorder();
CTBorderPr pr = ct.isSetLeft() ? ct.getLeft() : ct.addNewLeft(); CTBorderPr pr = ct.isSetBottom() ? ct.getBottom() : ct.addNewBottom();
if(border == BORDER_NONE) ct.unsetLeft(); if(border == BorderStyle.NONE) ct.unsetBottom();
else pr.setStyle(STBorderStyle.Enum.forInt(border + 1)); else pr.setStyle(STBorderStyle.Enum.forInt(border.getCode() + 1));
int idx = _stylesSource.putBorder(new XSSFCellBorder(ct, _theme)); int idx = _stylesSource.putBorder(new XSSFCellBorder(ct, _theme));
@ -862,6 +816,16 @@ public class XSSFCellStyle implements CellStyle {
_cellXf.setApplyBorder(true); _cellXf.setApplyBorder(true);
} }
/**
* Set the type of border to use for the left border of the cell
* @param border the type of border to use
* @deprecated 3.15 beta 1. Use {@link #setBorderLeft(BorderStyle)}
*/
@Override
public void setBorderLeft(short border) {
setBorderLeft(BorderStyle.valueOf(border));
}
/** /**
* Set the type of border to use for the left border of the cell * Set the type of border to use for the left border of the cell
* *
@ -869,40 +833,26 @@ public class XSSFCellStyle implements CellStyle {
*/ */
@Override @Override
public void setBorderLeft(BorderStyle border) { public void setBorderLeft(BorderStyle border) {
setBorderLeft(border.getCode()); CTBorder ct = getCTBorder();
CTBorderPr pr = ct.isSetLeft() ? ct.getLeft() : ct.addNewLeft();
if(border == BorderStyle.NONE) ct.unsetLeft();
else pr.setStyle(STBorderStyle.Enum.forInt(border.getCode() + 1));
int idx = _stylesSource.putBorder(new XSSFCellBorder(ct, _theme));
_cellXf.setBorderId(idx);
_cellXf.setApplyBorder(true);
} }
/** /**
* Set the type of border to use for the right border of the cell * Set the type of border to use for the right border of the cell
* *
* @param border the type of border to use * @param border the type of border to use
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_NONE * @deprecated 3.15 beta 1. Use {@link #setBorderRight(BorderStyle)}
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_THIN
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASHED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DOTTED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_THICK
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DOUBLE
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_HAIR
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASHED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/ */
@Override @Override
public void setBorderRight(short border) { public void setBorderRight(short border) {
CTBorder ct = getCTBorder(); setBorderRight(BorderStyle.valueOf(border));
CTBorderPr pr = ct.isSetRight() ? ct.getRight() : ct.addNewRight();
if(border == BORDER_NONE) ct.unsetRight();
else pr.setStyle(STBorderStyle.Enum.forInt(border + 1));
int idx = _stylesSource.putBorder(new XSSFCellBorder(ct, _theme));
_cellXf.setBorderId(idx);
_cellXf.setApplyBorder(true);
} }
/** /**
@ -912,35 +862,10 @@ public class XSSFCellStyle implements CellStyle {
*/ */
@Override @Override
public void setBorderRight(BorderStyle border) { public void setBorderRight(BorderStyle border) {
setBorderRight(border.getCode());
}
/**
* Set the type of border to use for the top border of the cell
*
* @param border the type of border to use
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_NONE
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_THIN
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASHED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DOTTED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_THICK
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DOUBLE
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_HAIR
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASHED
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_MEDIUM_DASH_DOT_DOT
* @see org.apache.poi.ss.usermodel.CellStyle#BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 1
*/
@Override
public void setBorderTop(short border) {
CTBorder ct = getCTBorder(); CTBorder ct = getCTBorder();
CTBorderPr pr = ct.isSetTop() ? ct.getTop() : ct.addNewTop(); CTBorderPr pr = ct.isSetRight() ? ct.getRight() : ct.addNewRight();
if(border == BORDER_NONE) ct.unsetTop(); if(border == BorderStyle.NONE) ct.unsetRight();
else pr.setStyle(STBorderStyle.Enum.forInt(border + 1)); else pr.setStyle(STBorderStyle.Enum.forInt(border.getCode() + 1));
int idx = _stylesSource.putBorder(new XSSFCellBorder(ct, _theme)); int idx = _stylesSource.putBorder(new XSSFCellBorder(ct, _theme));
@ -948,6 +873,17 @@ public class XSSFCellStyle implements CellStyle {
_cellXf.setApplyBorder(true); _cellXf.setApplyBorder(true);
} }
/**
* Set the type of border to use for the top border of the cell
*
* @param border the type of border to use
* @deprecated 3.15 beta 1. Use {@link #setBorderTop(BorderStyle)}
*/
@Override
public void setBorderTop(short border) {
setBorderTop(BorderStyle.valueOf(border));
}
/** /**
* Set the type of border to use for the top border of the cell * Set the type of border to use for the top border of the cell
* *
@ -955,7 +891,15 @@ public class XSSFCellStyle implements CellStyle {
*/ */
@Override @Override
public void setBorderTop(BorderStyle border) { public void setBorderTop(BorderStyle border) {
setBorderTop(border.getCode()); CTBorder ct = getCTBorder();
CTBorderPr pr = ct.isSetTop() ? ct.getTop() : ct.addNewTop();
if(border == BorderStyle.NONE) ct.unsetTop();
else pr.setStyle(STBorderStyle.Enum.forInt(border.getCode() + 1));
int idx = _stylesSource.putBorder(new XSSFCellBorder(ct, _theme));
_cellXf.setBorderId(idx);
_cellXf.setApplyBorder(true);
} }
/** /**