* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
-
package eu.etaxonomy.cdm.common;
import java.io.FileNotFoundException;
import java.util.Map;
import org.apache.log4j.Logger;
-import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDataFormatter;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
/**
* @author n.hoffmann
* @since 18.11.2008
- * @version 1.0
*/
public class ExcelUtils {
private static final Logger logger = Logger.getLogger(ExcelUtils.class);
return parseXLS(uri, null);
}
-
/** Reads all rows of an Excel worksheet */
public static List<Map<String, String>> parseXLS(URI uri, String worksheetName) throws FileNotFoundException {
try {
ioe.printStackTrace();
throw new RuntimeException(message);
}
-
}
/** Reads all rows of an Excel worksheet */
recordList.add(headers);
}
}
-
} catch(Exception ioe) {
logger.error("Error reading the Excel file.");
ioe.printStackTrace();
return recordList;
}
-
public static String getCellValue(Cell cell) {
try {
- if (cell.getCellType() == HSSFCell.CELL_TYPE_STRING ){
+ if (cell.getCellType() == Cell.CELL_TYPE_STRING ){
return cell.getStringCellValue();
- }else if (cell.getCellType() == HSSFCell.CELL_TYPE_BLANK){
+ }else if (cell.getCellType() == Cell.CELL_TYPE_BLANK){
return "";
- }else if (cell.getCellType() == HSSFCell.CELL_TYPE_NUMERIC){
+ }else if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC){
return getNumericCellValue(cell);
- }else if (cell.getCellType() == HSSFCell.CELL_TYPE_BOOLEAN){
+ }else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN){
Boolean cellValue = cell.getBooleanCellValue();
String value = String.valueOf(cellValue);
return value;
- }else if (cell.getCellType() == HSSFCell.CELL_TYPE_ERROR){
+ }else if (cell.getCellType() == Cell.CELL_TYPE_ERROR){
return "-error-";
- }else if (cell.getCellType() == HSSFCell.CELL_TYPE_FORMULA){
+ }else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA){
try {
String strValue = cell.getStringCellValue();
if ("".equals(strValue)){
private static String getExcelColString(int colNr){
int first = colNr / 26;
int second = colNr % 26;
-// char a = Integer.valueOf(first).shortValue();
String firstStr = String.valueOf((first > 0 ? (char)(first +64) :""));
String secondStr = String.valueOf((char)(second + 64));
return firstStr + secondStr;
}
-
/**
* Returns the numeric cell value. In case the cell is formatted as
* a date it returns a date (using the dates toString() method.
- * @param cell
- * @return
*/
private static String getNumericCellValue(Cell cell) {
Double number = cell.getNumericCellValue();
return result;
}
-// System.out.println(d);
if (number.intValue() == number){
return String.valueOf(number.intValue());
}
}
-
/**
* Returns false, if row is null or has no values
- * @param row
- * @param notEmpty
- * @return
*/
private static boolean checkIsEmptyRow(Row row) {
if (row == null){
* @author a.mueller\r
* @since 11.05.2009\r
*/\r
-public abstract class IoStateBase<CONFIG extends IIoConfigurator, IO extends ICdmIO, RESULT extends IoResultBase> {\r
+public abstract class IoStateBase<CONFIG\r
+ extends IIoConfigurator, IO extends ICdmIO, RESULT extends IoResultBase> {\r
\r
@SuppressWarnings("unused")\r
private static final Logger logger = Logger.getLogger(IoStateBase.class);\r
\r
private RESULT result;\r
\r
-\r
-\r
//TODO config not necessary ones it it implemented in constructor for IOs too.\r
public void initialize(CONFIG config){\r
this.config = config;\r
return currentIO;\r
}\r
\r
-\r
public RESULT getResult() {\r
return result;\r
}\r
this.result = result;\r
}\r
\r
-\r
// public IProgressMonitor getCurrentMonitor() {\r
// return currentMonitor;\r
// }\r
// public void setCurrentMonitor(IProgressMonitor currentMonitor) {\r
// this.currentMonitor = currentMonitor;\r
// }\r
-\r
-\r
-\r
}\r
configurator = state.getConfig();
NomenclaturalCode nc = getConfigurator().getNomenclaturalCode();
- if (nc == null && needsNomenclaturalCode()) {
+ if (nc == null && requiresNomenclaturalCode()) {
logger.error("Nomenclatural code could not be determined. Skip invoke.");
state.setUnsuccessfull();
return;
byte[] data = null;
// read and save all rows of the excel worksheet
- if ((state.getConfig() instanceof NormalExplicitImportConfigurator || state.getConfig() instanceof ExcelDistributionUpdateConfigurator || state.getConfig() instanceof TaxonListImportConfigurator) &&
- (state.getConfig().getStream() != null || state.getConfig().getStream() != null)){
+ if ((state.getConfig() instanceof NormalExplicitImportConfigurator
+ || state.getConfig() instanceof ExcelDistributionUpdateConfigurator
+ || state.getConfig() instanceof TaxonListImportConfigurator) && (state.getConfig().getStream() != null
+ || state.getConfig().getStream() != null)){
data = state.getConfig().getStream();
} else{
source = state.getConfig().getSource();
return;
}
- protected boolean needsNomenclaturalCode() {
+ protected boolean requiresNomenclaturalCode() {
return true;
}