You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ta...@apache.org on 2016/02/18 02:49:59 UTC
svn commit: r1730992 - in /poi/trunk:
src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java
src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractor.java
test-data/spreadsheet/59021.xlsx
Author: tallison
Date: Thu Feb 18 01:49:59 2016
New Revision: 1730992
URL: http://svn.apache.org/viewvc?rev=1730992&view=rev
Log:
59021 -- fix content extraction from namespaced elements in XSSFEventBasedExcelExtractor
Added:
poi/trunk/test-data/spreadsheet/59021.xlsx (with props)
Modified:
poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractor.java
Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java?rev=1730992&r1=1730991&r2=1730992&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java Thu Feb 18 01:49:59 2016
@@ -41,7 +41,7 @@ import org.xml.sax.helpers.DefaultHandle
*/
public class XSSFSheetXMLHandler extends DefaultHandler {
private static final POILogger logger = POILogFactory.getLogger(XSSFSheetXMLHandler.class);
-
+ static final String SPREADSHEETML_NS = "http://schemas.openxmlformats.org/spreadsheetml/2006/main";
/**
* These are the different kinds of cells we support.
* We keep track of the current one between
@@ -186,17 +186,21 @@ public class XSSFSheetXMLHandler extends
@Override
@SuppressWarnings("unused")
- public void startElement(String uri, String localName, String name,
+ public void startElement(String uri, String localName, String qName,
Attributes attributes) throws SAXException {
- if (isTextTag(name)) {
+ if (uri != null && ! uri.equals(SPREADSHEETML_NS)) {
+ return;
+ }
+
+ if (isTextTag(localName)) {
vIsOpen = true;
// Clear contents cache
value.setLength(0);
- } else if ("is".equals(name)) {
+ } else if ("is".equals(localName)) {
// Inline string outer tag
isIsOpen = true;
- } else if ("f".equals(name)) {
+ } else if ("f".equals(localName)) {
// Clear contents cache
formula.setLength(0);
@@ -231,14 +235,14 @@ public class XSSFSheetXMLHandler extends
fIsOpen = true;
}
}
- else if("oddHeader".equals(name) || "evenHeader".equals(name) ||
- "firstHeader".equals(name) || "firstFooter".equals(name) ||
- "oddFooter".equals(name) || "evenFooter".equals(name)) {
+ else if("oddHeader".equals(localName) || "evenHeader".equals(localName) ||
+ "firstHeader".equals(localName) || "firstFooter".equals(localName) ||
+ "oddFooter".equals(localName) || "evenFooter".equals(localName)) {
hfIsOpen = true;
// Clear contents cache
headerFooter.setLength(0);
}
- else if("row".equals(name)) {
+ else if("row".equals(localName)) {
String rowNumStr = attributes.getValue("r");
if(rowNumStr != null) {
rowNum = Integer.parseInt(rowNumStr) - 1;
@@ -248,7 +252,7 @@ public class XSSFSheetXMLHandler extends
output.startRow(rowNum);
}
// c => cell
- else if ("c".equals(name)) {
+ else if ("c".equals(localName)) {
// Set up defaults.
this.nextDataType = xssfDataType.NUMBER;
this.formatIndex = -1;
@@ -269,11 +273,13 @@ public class XSSFSheetXMLHandler extends
else {
// Number, but almost certainly with a special style or format
XSSFCellStyle style = null;
- if (cellStyleStr != null) {
- int styleIndex = Integer.parseInt(cellStyleStr);
- style = stylesTable.getStyleAt(styleIndex);
- } else if (stylesTable.getNumCellStyles() > 0) {
- style = stylesTable.getStyleAt(0);
+ if (stylesTable != null) {
+ if (cellStyleStr != null) {
+ int styleIndex = Integer.parseInt(cellStyleStr);
+ style = stylesTable.getStyleAt(styleIndex);
+ } else if (stylesTable.getNumCellStyles() > 0) {
+ style = stylesTable.getStyleAt(0);
+ }
}
if (style != null) {
this.formatIndex = style.getDataFormat();
@@ -286,12 +292,17 @@ public class XSSFSheetXMLHandler extends
}
@Override
- public void endElement(String uri, String localName, String name)
+ public void endElement(String uri, String localName, String qName)
throws SAXException {
+
+ if (uri != null && ! uri.equals(SPREADSHEETML_NS)) {
+ return;
+ }
+
String thisStr = null;
// v => contents of a cell
- if (isTextTag(name)) {
+ if (isTextTag(localName)) {
vIsOpen = false;
// Process the value contents as required, now we have it all
@@ -364,11 +375,11 @@ public class XSSFSheetXMLHandler extends
// Output
output.cell(cellRef, thisStr, comment);
- } else if ("f".equals(name)) {
+ } else if ("f".equals(localName)) {
fIsOpen = false;
- } else if ("is".equals(name)) {
+ } else if ("is".equals(localName)) {
isIsOpen = false;
- } else if ("row".equals(name)) {
+ } else if ("row".equals(localName)) {
// Handle any "missing" cells which had comments attached
checkForEmptyCellComments(EmptyCellCommentsCheckType.END_OF_ROW);
@@ -377,19 +388,19 @@ public class XSSFSheetXMLHandler extends
// some sheets do not have rowNum set in the XML, Excel can read them so we should try to read them as well
nextRowNum = rowNum + 1;
- } else if ("sheetData".equals(name)) {
+ } else if ("sheetData".equals(localName)) {
// Handle any "missing" cells which had comments attached
checkForEmptyCellComments(EmptyCellCommentsCheckType.END_OF_SHEET_DATA);
}
- else if("oddHeader".equals(name) || "evenHeader".equals(name) ||
- "firstHeader".equals(name)) {
+ else if("oddHeader".equals(localName) || "evenHeader".equals(localName) ||
+ "firstHeader".equals(localName)) {
hfIsOpen = false;
- output.headerFooter(headerFooter.toString(), true, name);
+ output.headerFooter(headerFooter.toString(), true, localName);
}
- else if("oddFooter".equals(name) || "evenFooter".equals(name) ||
- "firstFooter".equals(name)) {
+ else if("oddFooter".equals(localName) || "evenFooter".equals(localName) ||
+ "firstFooter".equals(localName)) {
hfIsOpen = false;
- output.headerFooter(headerFooter.toString(), false, name);
+ output.headerFooter(headerFooter.toString(), false, localName);
}
}
Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractor.java?rev=1730992&r1=1730991&r2=1730992&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractor.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractor.java Thu Feb 18 01:49:59 2016
@@ -337,4 +337,13 @@ public class TestXSSFEventBasedExcelExtr
extractor.close();
}
}
+
+ public void test59021() throws Exception {
+ XSSFEventBasedExcelExtractor ex =
+ new XSSFEventBasedExcelExtractor(
+ XSSFTestDataSamples.openSamplePackage("59021.xlsx"));
+ String text = ex.getText();
+ assertTrue("can't find Abhkazia", text.contains("Abkhazia - Fixed"));
+ assertTrue("can't find 10/02/2016", text.contains("10/02/2016"));
+ }
}
Added: poi/trunk/test-data/spreadsheet/59021.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/59021.xlsx?rev=1730992&view=auto
==============================================================================
Binary file - no diff available.
Propchange: poi/trunk/test-data/spreadsheet/59021.xlsx
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org