fix use of forbidden apis in row shift code

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1822743 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2018-01-31 05:31:31 +00:00
parent 5afe7c20ab
commit 3f2ae2ee4b
2 changed files with 23 additions and 19 deletions

View File

@ -24,13 +24,12 @@ import org.apache.poi.hssf.record.CellValueRecordInterface;
import org.apache.poi.hssf.record.ExtendedFormatRecord;
import org.apache.poi.hssf.record.RowRecord;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.formula.eval.NotImplementedException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.util.Configurator;
import org.apache.poi.util.NotImplemented;
import org.apache.poi.util.LocaleUtil;
/**
* High level representation of a row of a spreadsheet.
@ -720,8 +719,8 @@ public final class HSSFRow implements Row, Comparable<HSSFRow> {
/**
* Shifts column range [firstShiftColumnIndex-lastShiftColumnIndex] step places to the right.
* @param startColumn the column to start shifting
* @param endColumn the column to end shifting
* @param firstShiftColumnIndex the column to start shifting
* @param lastShiftColumnIndex the column to end shifting
* @param step length of the shifting step
*/
@Override
@ -729,7 +728,8 @@ public final class HSSFRow implements Row, Comparable<HSSFRow> {
if(step < 0)
throw new IllegalArgumentException("Shifting step may not be negative ");
if(firstShiftColumnIndex > lastShiftColumnIndex)
throw new IllegalArgumentException(String.format("Incorrect shifting range : %d-%d", firstShiftColumnIndex, lastShiftColumnIndex));
throw new IllegalArgumentException(String.format(LocaleUtil.getUserLocale(),
"Incorrect shifting range : %d-%d", firstShiftColumnIndex, lastShiftColumnIndex));
if(lastShiftColumnIndex + step + 1> cells.length)
extend(lastShiftColumnIndex + step + 1);
for (int columnIndex = lastShiftColumnIndex; columnIndex >= firstShiftColumnIndex; columnIndex--){ // process cells backwards, because of shifting
@ -748,8 +748,8 @@ public final class HSSFRow implements Row, Comparable<HSSFRow> {
}
/**
* Shifts column range [firstShiftColumnIndex-lastShiftColumnIndex] step places to the left.
* @param startColumn the column to start shifting
* @param endColumn the column to end shifting
* @param firstShiftColumnIndex the column to start shifting
* @param lastShiftColumnIndex the column to end shifting
* @param step length of the shifting step
*/
@Override
@ -757,7 +757,8 @@ public final class HSSFRow implements Row, Comparable<HSSFRow> {
if(step < 0)
throw new IllegalArgumentException("Shifting step may not be negative ");
if(firstShiftColumnIndex > lastShiftColumnIndex)
throw new IllegalArgumentException(String.format("Incorrect shifting range : %d-%d", firstShiftColumnIndex, lastShiftColumnIndex));
throw new IllegalArgumentException(String.format(LocaleUtil.getUserLocale(),
"Incorrect shifting range : %d-%d", firstShiftColumnIndex, lastShiftColumnIndex));
if(firstShiftColumnIndex - step < 0)
throw new IllegalStateException("Column index less than zero : " + (Integer.valueOf(firstShiftColumnIndex + step)).toString());
for (int columnIndex = firstShiftColumnIndex; columnIndex <= lastShiftColumnIndex; columnIndex++){

View File

@ -32,6 +32,7 @@ import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.Beta;
import org.apache.poi.util.Internal;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.helpers.XSSFRowShifter;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
@ -641,8 +642,8 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
/**
* Shifts column range [firstShiftColumnIndex-lastShiftColumnIndex] step places to the right.
* @param startColumn the column to start shifting
* @param endColumn the column to end shifting
* @param firstShiftColumnIndex the column to start shifting
* @param lastShiftColumnIndex the column to end shifting
* @param step length of the shifting step
*/
@Override
@ -650,7 +651,8 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
if(step < 0)
throw new IllegalArgumentException("Shifting step may not be negative ");
if(firstShiftColumnIndex > lastShiftColumnIndex)
throw new IllegalArgumentException(String.format("Incorrect shifting range : %d-%d", firstShiftColumnIndex, lastShiftColumnIndex));
throw new IllegalArgumentException(String.format(LocaleUtil.getUserLocale(),
"Incorrect shifting range : %d-%d", firstShiftColumnIndex, lastShiftColumnIndex));
for (int columnIndex = lastShiftColumnIndex; columnIndex >= firstShiftColumnIndex; columnIndex--){ // process cells backwards, because of shifting
shiftCell(columnIndex, step);
}
@ -664,8 +666,8 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
}
/**
* Shifts column range [firstShiftColumnIndex-lastShiftColumnIndex] step places to the left.
* @param startColumn the column to start shifting
* @param endColumn the column to end shifting
* @param firstShiftColumnIndex the column to start shifting
* @param lastShiftColumnIndex the column to end shifting
* @param step length of the shifting step
*/
@Override
@ -673,7 +675,8 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
if(step < 0)
throw new IllegalArgumentException("Shifting step may not be negative ");
if(firstShiftColumnIndex > lastShiftColumnIndex)
throw new IllegalArgumentException(String.format("Incorrect shifting range : %d-%d", firstShiftColumnIndex, lastShiftColumnIndex));
throw new IllegalArgumentException(String.format(LocaleUtil.getUserLocale(),
"Incorrect shifting range : %d-%d", firstShiftColumnIndex, lastShiftColumnIndex));
if(firstShiftColumnIndex - step < 0)
throw new IllegalStateException("Column index less than zero : " + (Integer.valueOf(firstShiftColumnIndex + step)).toString());
for (int columnIndex = firstShiftColumnIndex; columnIndex <= lastShiftColumnIndex; columnIndex++){