small refactor of XSSFReader

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896259 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-12-22 03:51:51 +00:00
parent 0b871a08c5
commit fe4a3b7596
3 changed files with 8 additions and 8 deletions

View File

@ -27,7 +27,7 @@ import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackageAccess;
import org.apache.poi.util.XMLHelper;
import org.apache.poi.xssf.eventusermodel.XSSFReader;
import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.xssf.model.SharedStrings;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
@ -45,7 +45,7 @@ public class FromHowTo {
public void processFirstSheet(String filename) throws Exception {
try (OPCPackage pkg = OPCPackage.open(filename, PackageAccess.READ)) {
XSSFReader r = new XSSFReader(pkg);
SharedStringsTable sst = r.getSharedStringsTable();
SharedStrings sst = r.getSharedStringsTable();
XMLReader parser = fetchSheetParser(sst);
@ -60,7 +60,7 @@ public class FromHowTo {
public void processAllSheets(String filename) throws Exception {
try (OPCPackage pkg = OPCPackage.open(filename, PackageAccess.READ)) {
XSSFReader r = new XSSFReader(pkg);
SharedStringsTable sst = r.getSharedStringsTable();
SharedStrings sst = r.getSharedStringsTable();
XMLReader parser = fetchSheetParser(sst);
@ -76,7 +76,7 @@ public class FromHowTo {
}
}
public XMLReader fetchSheetParser(SharedStringsTable sst) throws SAXException, ParserConfigurationException {
public XMLReader fetchSheetParser(SharedStrings sst) throws SAXException, ParserConfigurationException {
XMLReader parser = XMLHelper.newXMLReader();
ContentHandler handler = new SheetHandler(sst);
parser.setContentHandler(handler);
@ -87,7 +87,7 @@ public class FromHowTo {
* See org.xml.sax.helpers.DefaultHandler javadocs
*/
private static class SheetHandler extends DefaultHandler {
private final SharedStringsTable sst;
private final SharedStrings sst;
private String lastContents;
private boolean nextIsString;
private boolean inlineStr;
@ -107,7 +107,7 @@ public class FromHowTo {
}
}
private SheetHandler(SharedStringsTable sst) {
private SheetHandler(SharedStrings sst) {
this.sst = sst;
}

View File

@ -120,7 +120,7 @@ public class XSSFReader {
* returns a handy object for working with
* shared strings.
*/
public SharedStringsTable getSharedStringsTable() throws IOException, InvalidFormatException {
public SharedStrings getSharedStringsTable() throws IOException, InvalidFormatException {
ArrayList<PackagePart> parts = pkg.getPartsByContentType(XSSFRelation.SHARED_STRINGS.getContentType());
return parts.size() == 0 ? null : new SharedStringsTable(parts.get(0));
}

View File

@ -102,7 +102,7 @@ public final class TestXSSFReader {
XSSFReader r = new XSSFReader(pkg);
assertEquals(11, r.getSharedStringsTable().getSharedStringItems().size());
assertEquals(11, r.getSharedStringsTable().getCount());
assertEquals("Test spreadsheet", r.getSharedStringsTable().getItemAt(0).toString());
}
}