Skip to content

Commit

Permalink
update xssf and casting classes
Browse files Browse the repository at this point in the history
  • Loading branch information
ozlerhakan committed Oct 24, 2017
1 parent 7b3efd0 commit cbd2667
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.poiji.exception.PoijiException;
import com.poiji.internal.PoijiFile;
import com.poiji.internal.PoijiHandler;
import com.poiji.option.PoijiOptions;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
Expand Down Expand Up @@ -40,14 +39,14 @@ final class XSSFUnmarshaller extends Deserializer {
@SuppressWarnings("unchecked")
public <T> List<T> deserialize(Class<T> type) {
try (OPCPackage open = OPCPackage.open(poijiFile.file())) {
ReadOnlySharedStringsTable sst = new ReadOnlySharedStringsTable(open);
ReadOnlySharedStringsTable readOnlySharedStringsTable = new ReadOnlySharedStringsTable(open);
XSSFReader reader = new XSSFReader(open);

XSSFReader xssfReader = new XSSFReader(open);
StylesTable styles = xssfReader.getStylesTable();

InputStream firstSheet = reader.getSheetsData().next();
processSheet(styles, sst, type, firstSheet);
processSheet(styles, readOnlySharedStringsTable, type, firstSheet);
firstSheet.close();

return poijiHandler.getDataset();
Expand All @@ -56,19 +55,20 @@ public <T> List<T> deserialize(Class<T> type) {
}
}

@SuppressWarnings("unchecked")
private <T> void processSheet(StylesTable styles, ReadOnlySharedStringsTable readOnlySharedStringsTable,
Class<T> type, InputStream sheetInputStream) throws IOException, SAXException {
Class<T> type, InputStream sheetInputStream) {

DataFormatter formatter = new DataFormatter();
InputSource sheetSource = new InputSource(sheetInputStream);
try {
XMLReader sheetParser = SAXHelper.newXMLReader();
poijiHandler = new PoijiHandler(readOnlySharedStringsTable, type, options);
poijiHandler = new PoijiHandler(type, options);
ContentHandler contentHandler =
new XSSFSheetXMLHandler(styles, null, readOnlySharedStringsTable, poijiHandler, formatter, false);
sheetParser.setContentHandler(contentHandler);
sheetParser.parse(sheetSource);
} catch (ParserConfigurationException e) {
} catch (ParserConfigurationException | SAXException | IOException e) {
throw new PoijiException("Problem occurred while reading data", e);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/poiji/util/Casting.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,47 @@ public final class Casting {
private Casting() {
}

public static Integer integerValue(String value) {
static Integer integerValue(String value) {
try {
return new Integer(value);
} catch (NumberFormatException nfe) {
return 0;
}
}

public static Long longValue(String value) {
static Long longValue(String value) {
try {
return new Long(value);
} catch (NumberFormatException nfe) {
return 0L;
}
}

public static Short shortValue(String value) {
static Short shortValue(String value) {
try {
return new Short(value);
} catch (NumberFormatException nfe) {
return 0;
}
}

public static Double doubleValue(String value) {
static Double doubleValue(String value) {
try {
return new Double(value);
} catch (NumberFormatException nfe) {
return 0d;
}
}

public static Float floatValue(String value) {
static Float floatValue(String value) {
try {
return new Float(value);
} catch (NumberFormatException nfe) {
return 0f;
}
}

public static Date dateValue(String value, PoijiOptions options) {
static Date dateValue(String value, PoijiOptions options) {
try {
final SimpleDateFormat sdf = new SimpleDateFormat(options.datePattern());
return sdf.parse(value);
Expand Down

0 comments on commit cbd2667

Please sign in to comment.