Author: nick
Date: Mon Dec 13 05:07:19 2010
New Revision: 1045020

URL: http://svn.apache.org/viewvc?rev=1045020&view=rev
Log:
Added XSSF EventModel support for inline strings. Adds unit test for this for 
the event model extractor, and another for the usermodel extractor which 
already supported it

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    
poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFSheetXMLHandler.java
    
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFEventBasedExcelExtractor.java
    
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1045020&r1=1045019&r2=1045020&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Mon Dec 13 05:07:19 
2010
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta1" date="2010-??-??">
+           <action dev="POI-DEVELOPERS" type="add">Added inline string support 
to XSSF EventModel</action>
            <action dev="POI-DEVELOPERS" type="fix">50246 - Properly position 
GutsRecord when reading HSSF workbooks</action>
            <action dev="POI-DEVELOPERS" type="add">48539 - Added 
implementation for MROUND(), VAR() and VARP()</action>
            <action dev="POI-DEVELOPERS" type="add">50446 - Code cleanup and 
optimizations to keep some IDE quiet</action>

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=1045020&r1=1045019&r2=1045020&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
 Mon Dec 13 05:07:19 2010
@@ -61,6 +61,8 @@ public class XSSFSheetXMLHandler extends
    private boolean vIsOpen;
    // Set when F start element is seen
    private boolean fIsOpen;
+   // Set when an Inline String "is" is seen
+   private boolean isIsOpen;
    // Set when a header/footer element is seen
    private boolean hfIsOpen;
 
@@ -113,13 +115,33 @@ public class XSSFSheetXMLHandler extends
        this(styles, strings, sheetContentsHandler, new DataFormatter(), 
formulasNotResults);
    }
 
+   private boolean isTextTag(String name) {
+      if("v".equals(name)) {
+         // Easy, normal v text tag
+         return true;
+      }
+      if("inlineStr".equals(name)) {
+         // Easy inline string
+         return true;
+      }
+      if("t".equals(name) && isIsOpen) {
+         // Inline string <is><t>...</t></is> pair
+         return true;
+      }
+      // It isn't a text tag
+      return false;
+   }
+   
    public void startElement(String uri, String localName, String name,
                             Attributes attributes) throws SAXException {
 
-       if ("inlineStr".equals(name) || "v".equals(name)) {
+       if (isTextTag(name)) {
            vIsOpen = true;
            // Clear contents cache
            value.setLength(0);
+       } else if ("is".equals(name)) {
+          // Inline string outer tag
+          isIsOpen = true;
        } else if ("f".equals(name)) {
           // Clear contents cache
           formula.setLength(0);
@@ -202,7 +224,7 @@ public class XSSFSheetXMLHandler extends
        String thisStr = null;
 
        // v => contents of a cell
-       if ("v".equals(name)) {
+       if (isTextTag(name)) {
            vIsOpen = false;
            
            // Process the value contents as required, now we have it all
@@ -225,7 +247,7 @@ public class XSSFSheetXMLHandler extends
                    break;
 
                case INLINE_STRING:
-                   // TODO: have seen an example of this, so it's untested.
+                   // TODO: Can these ever have formatting on them?
                    XSSFRichTextString rtsi = new 
XSSFRichTextString(value.toString());
                    thisStr = rtsi.toString();
                    break;
@@ -259,6 +281,8 @@ public class XSSFSheetXMLHandler extends
            output.cell(cellRef, thisStr);
        } else if ("f".equals(name)) {
           fIsOpen = false;
+       } else if ("is".equals(name)) {
+          isIsOpen = false;
        } else if ("row".equals(name)) {
           output.endRow();
        }

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=1045020&r1=1045019&r2=1045020&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
 Mon Dec 13 05:07:19 2010
@@ -114,6 +114,28 @@ public final class TestXSSFEventBasedExc
                ));
        }
        
+   public void testInlineStrings() throws Exception {
+      XSSFEventBasedExcelExtractor extractor = 
getExtractor("InlineStrings.xlsx");
+      extractor.setFormulasNotResults(true);
+      String text = extractor.getText();
+
+      // Numbers
+      assertTrue("Unable to find expected word in text\n" + text, 
text.contains("43"));
+      assertTrue("Unable to find expected word in text\n" + text, 
text.contains("22"));
+      
+      // Strings
+      assertTrue("Unable to find expected word in text\n" + text, 
text.contains("ABCDE"));
+      assertTrue("Unable to find expected word in text\n" + text, 
text.contains("Long Text"));
+      
+      // Inline Strings
+      assertTrue("Unable to find expected word in text\n" + text, 
text.contains("1st Inline String"));
+      assertTrue("Unable to find expected word in text\n" + text, 
text.contains("And More"));
+      
+      // Formulas
+      assertTrue("Unable to find expected word in text\n" + text, 
text.contains("A2"));
+      assertTrue("Unable to find expected word in text\n" + text, 
text.contains("A5-A$2"));
+   }
+   
        /**
         * Test that we return pretty much the same as
         *  ExcelExtractor does, when we're both passed

Modified: 
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java?rev=1045020&r1=1045019&r2=1045020&view=diff
==============================================================================
--- 
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java
 (original)
+++ 
poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExcelExtractor.java
 Mon Dec 13 05:07:19 2010
@@ -174,4 +174,26 @@ public final class TestXSSFExcelExtracto
                assertTrue("Unable to find expected word in text\n" + text, 
text.contains("testdoc"));
                assertTrue("Unable to find expected word in text\n" + text, 
text.contains("test phrase"));
        }
+       
+       public void testInlineStrings() {
+      XSSFExcelExtractor extractor = getExtractor("InlineStrings.xlsx");
+      extractor.setFormulasNotResults(true);
+      String text = extractor.getText();
+
+      // Numbers
+      assertTrue("Unable to find expected word in text\n" + text, 
text.contains("43"));
+      assertTrue("Unable to find expected word in text\n" + text, 
text.contains("22"));
+      
+      // Strings
+      assertTrue("Unable to find expected word in text\n" + text, 
text.contains("ABCDE"));
+      assertTrue("Unable to find expected word in text\n" + text, 
text.contains("Long Text"));
+      
+      // Inline Strings
+      assertTrue("Unable to find expected word in text\n" + text, 
text.contains("1st Inline String"));
+      assertTrue("Unable to find expected word in text\n" + text, 
text.contains("And More"));
+      
+      // Formulas
+      assertTrue("Unable to find expected word in text\n" + text, 
text.contains("A2"));
+      assertTrue("Unable to find expected word in text\n" + text, 
text.contains("A5-A$2"));
+       }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to