sonar fixes

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1705814 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2015-09-29 08:31:15 +00:00
parent c56977e6d2
commit ffd1f4333e
9 changed files with 29 additions and 63 deletions

View File

@ -185,10 +185,6 @@ public class XLSX2CSV {
// with a special style or format // with a special style or format
int styleIndex = Integer.parseInt(cellStyleStr); int styleIndex = Integer.parseInt(cellStyleStr);
XSSFCellStyle style = stylesTable.getStyleAt(styleIndex); XSSFCellStyle style = stylesTable.getStyleAt(styleIndex);
if (style == null && stylesTable.getNumCellStyles() > 0) {
style = stylesTable.getStyleAt(0);
}
if (style != null) {
this.formatIndex = style.getDataFormat(); this.formatIndex = style.getDataFormat();
this.formatString = style.getDataFormatString(); this.formatString = style.getDataFormatString();
if (this.formatString == null) { if (this.formatString == null) {
@ -196,7 +192,6 @@ public class XLSX2CSV {
} }
} }
} }
}
} }

View File

@ -447,12 +447,12 @@ public class Section
public String getPIDString(final long pid) public String getPIDString(final long pid)
{ {
String s = null; String s = null;
if (dictionary != null) if (dictionary != null) {
s = dictionary.get(Long.valueOf(pid)); s = dictionary.get(Long.valueOf(pid));
if (s == null) }
if (s == null) {
s = SectionIDMap.getPIDString(getFormatID().getBytes(), pid); s = SectionIDMap.getPIDString(getFormatID().getBytes(), pid);
if (s == null) }
s = SectionIDMap.UNDEFINED;
return s; return s;
} }

View File

@ -359,17 +359,10 @@ public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.p
break; break;
case HSSFCell.CELL_TYPE_NUMERIC: case HSSFCell.CELL_TYPE_NUMERIC:
HSSFCellStyle style = cell.getCellStyle(); HSSFCellStyle style = cell.getCellStyle();
if(style == null) { double nVal = cell.getNumericCellValue();
text.append( cell.getNumericCellValue() ); short df = style.getDataFormat();
} else { String dfs = style.getDataFormatString();
text.append( text.append(_formatter.formatRawCellContents(nVal, df, dfs));
_formatter.formatRawCellContents(
cell.getNumericCellValue(),
style.getDataFormat(),
style.getDataFormatString()
)
);
}
break; break;
case HSSFCell.CELL_TYPE_BOOLEAN: case HSSFCell.CELL_TYPE_BOOLEAN:
text.append(cell.getBooleanCellValue()); text.append(cell.getBooleanCellValue());

View File

@ -107,9 +107,6 @@ public final class XSLFPictureData extends POIXMLDocumentPart implements Picture
*/ */
public String getFileName() { public String getFileName() {
String name = getPackagePart().getPartName().getName(); String name = getPackagePart().getPartName().getName();
if (name == null) {
return null;
}
return name.substring(name.lastIndexOf('/') + 1); return name.substring(name.lastIndexOf('/') + 1);
} }

View File

@ -259,8 +259,7 @@ public final class XSSFCell implements Cell {
*/ */
@Override @Override
public String getStringCellValue() { public String getStringCellValue() {
XSSFRichTextString str = getRichStringCellValue(); return getRichStringCellValue().getString();
return str == null ? null : str.getString();
} }
/** /**

View File

@ -112,9 +112,6 @@ public class XWPFPictureData extends POIXMLDocumentPart {
*/ */
public String getFileName() { public String getFileName() {
String name = getPackagePart().getPartName().getName(); String name = getPackagePart().getPartName().getName();
if (name == null) {
return null;
}
return name.substring(name.lastIndexOf('/') + 1); return name.substring(name.lastIndexOf('/') + 1);
} }

View File

@ -139,14 +139,10 @@ public abstract class AbstractExcelConverter
break; break;
case HSSFCell.CELL_TYPE_NUMERIC: case HSSFCell.CELL_TYPE_NUMERIC:
HSSFCellStyle style = cell.getCellStyle(); HSSFCellStyle style = cell.getCellStyle();
if ( style == null ) double nval = cell.getNumericCellValue();
{ short df = style.getDataFormat();
return false; String dfs = style.getDataFormatString();
} value = _formatter.formatRawCellContents(nval, df, dfs);
value = ( _formatter.formatRawCellContents(
cell.getNumericCellValue(), style.getDataFormat(),
style.getDataFormatString() ) );
break; break;
case HSSFCell.CELL_TYPE_BOOLEAN: case HSSFCell.CELL_TYPE_BOOLEAN:
value = String.valueOf( cell.getBooleanCellValue() ); value = String.valueOf( cell.getBooleanCellValue() );

View File

@ -228,13 +228,9 @@ public class ExcelToFoConverter extends AbstractExcelConverter
break; break;
case HSSFCell.CELL_TYPE_NUMERIC: case HSSFCell.CELL_TYPE_NUMERIC:
double nValue = cell.getNumericCellValue(); double nValue = cell.getNumericCellValue();
if ( cellStyle == null ) {
value = Double.toString( nValue );
} else {
short df = cellStyle.getDataFormat(); short df = cellStyle.getDataFormat();
String dfs = cellStyle.getDataFormatString(); String dfs = cellStyle.getDataFormatString();
value = _formatter.formatRawCellContents(nValue, df, dfs ); value = _formatter.formatRawCellContents(nValue, df, dfs );
}
break; break;
case HSSFCell.CELL_TYPE_BOOLEAN: case HSSFCell.CELL_TYPE_BOOLEAN:
value = Boolean.toString( cell.getBooleanCellValue() ); value = Boolean.toString( cell.getBooleanCellValue() );
@ -270,7 +266,7 @@ public class ExcelToFoConverter extends AbstractExcelConverter
} }
final boolean noText = ExcelToHtmlUtils.isEmpty( value ); final boolean noText = ExcelToHtmlUtils.isEmpty( value );
final boolean wrapInDivs = !noText && (cellStyle == null || !cellStyle.getWrapText()); final boolean wrapInDivs = !noText && !cellStyle.getWrapText();
final boolean emptyStyle = isEmptyStyle( cellStyle ); final boolean emptyStyle = isEmptyStyle( cellStyle );
if ( !emptyStyle && noText ) { if ( !emptyStyle && noText ) {

View File

@ -313,13 +313,9 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
break; break;
case HSSFCell.CELL_TYPE_NUMERIC: case HSSFCell.CELL_TYPE_NUMERIC:
double nValue = cell.getNumericCellValue(); double nValue = cell.getNumericCellValue();
if ( cellStyle == null ) {
value = Double.toString(nValue);
} else {
short df = cellStyle.getDataFormat(); short df = cellStyle.getDataFormat();
String dfs = cellStyle.getDataFormatString(); String dfs = cellStyle.getDataFormatString();
value = _formatter.formatRawCellContents(nValue, df, dfs); value = _formatter.formatRawCellContents(nValue, df, dfs);
}
break; break;
case HSSFCell.CELL_TYPE_BOOLEAN: case HSSFCell.CELL_TYPE_BOOLEAN:
value = String.valueOf( cell.getBooleanCellValue() ); value = String.valueOf( cell.getBooleanCellValue() );
@ -355,10 +351,9 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
} }
final boolean noText = ExcelToHtmlUtils.isEmpty( value ); final boolean noText = ExcelToHtmlUtils.isEmpty( value );
final boolean wrapInDivs = !noText && isUseDivsToSpan() final boolean wrapInDivs = !noText && isUseDivsToSpan() && !cellStyle.getWrapText();
&& (cellStyle == null || !cellStyle.getWrapText());
if ( cellStyle != null && cellStyle.getIndex() != 0 ) if ( cellStyle.getIndex() != 0 )
{ {
@SuppressWarnings("resource") @SuppressWarnings("resource")
HSSFWorkbook workbook = cell.getRow().getSheet().getWorkbook(); HSSFWorkbook workbook = cell.getRow().getSheet().getWorkbook();
@ -418,9 +413,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
innerDivStyle.append( "overflow:hidden;max-height:" ); innerDivStyle.append( "overflow:hidden;max-height:" );
innerDivStyle.append( normalHeightPt ); innerDivStyle.append( normalHeightPt );
innerDivStyle.append( "pt;white-space:nowrap;" ); innerDivStyle.append( "pt;white-space:nowrap;" );
if (cellStyle != null) {
ExcelToHtmlUtils.appendAlign( innerDivStyle, cellStyle.getAlignment() ); ExcelToHtmlUtils.appendAlign( innerDivStyle, cellStyle.getAlignment() );
}
htmlDocumentFacade.addStyleClass( outerDiv, cssClassPrefixDiv, htmlDocumentFacade.addStyleClass( outerDiv, cssClassPrefixDiv,
innerDivStyle.toString() ); innerDivStyle.toString() );
@ -433,7 +426,7 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
tableCellElement.appendChild( text ); tableCellElement.appendChild( text );
} }
return ExcelToHtmlUtils.isEmpty( value ) && (cellStyle == null || cellStyle.getIndex() == 0); return ExcelToHtmlUtils.isEmpty( value ) && (cellStyle.getIndex() == 0);
} }
protected void processColumnHeaders( HSSFSheet sheet, int maxSheetColumns, protected void processColumnHeaders( HSSFSheet sheet, int maxSheetColumns,