You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2013/06/25 15:09:08 UTC

svn commit: r1496458 - in /poi/trunk: src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java test-data/document/Bug55142.docx

Author: nick
Date: Tue Jun 25 13:09:08 2013
New Revision: 1496458

URL: http://svn.apache.org/r1496458
Log:
Patch from Tim Allison from bug #55142 - Not all XWPF SDT block
s need newlines

Added:
    poi/trunk/test-data/document/Bug55142.docx   (with props)
Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java?rev=1496458&r1=1496457&r2=1496458&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFSDTContent.java Tue Jun 25 13:09:08 2013
@@ -83,18 +83,23 @@ public class XWPFSDTContent  {
 
     public String getText(){
         StringBuilder text = new StringBuilder();
+        boolean addNewLine = false;
         for (int i = 0; i < bodyElements.size(); i++){
             Object o = bodyElements.get(i);
             if (o instanceof XWPFParagraph){
                 text.append(((XWPFParagraph)o).getText());
+                addNewLine = true;
             } else if (o instanceof XWPFTable){
                 text.append(((XWPFTable)o).getText());
+                addNewLine = true;
             } else if (o instanceof XWPFSDT){
                 text.append(((XWPFSDT)o).getContent().getText());
+                addNewLine = true;
             } else if (o instanceof XWPFRun){
                 text.append(((XWPFRun)o).toString());
+                addNewLine = false;
             }
-            if (i < bodyElements.size()-1){
+            if (addNewLine == true && i < bodyElements.size()-1){
                 text.append("\n");
             }
         }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java?rev=1496458&r1=1496457&r2=1496458&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java Tue Jun 25 13:09:08 2013
@@ -93,6 +93,31 @@ public final class TestXWPFSDT extends T
         }
         assertEquals("SDT as cell known failure", false, found);
     }
+    
+    /**
+     * POI-55142 and Tika 1130
+     */
+    public void testNewLinesBetweenRuns() throws Exception{
+       XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug55142.docx");
+       List<XWPFSDT> sdts = extractAllSDTs(doc);
+       List<String> targs = new ArrayList<String>();
+       //these test newlines and tabs in paragraphs/body elements
+       targs.add("Rich-text1 abcdefghi");
+       targs.add("Rich-text2 abcd\t\tefgh");
+       targs.add("Rich-text3 abcd\nefg");
+       targs.add("Rich-text4 abcdefg");
+       targs.add("Rich-text5 abcdefg\nhijk");
+       targs.add("Plain-text1 abcdefg");
+       targs.add("Plain-text2 abcdefg\nhijk\nlmnop");
+       //this tests consecutive runs within a cell (not a paragraph)
+       //this test case was triggered by Tika-1130
+       targs.add("sdt_incell2 abcdefg");
+       
+       for (int i = 0; i < sdts.size(); i++){
+          XWPFSDT sdt = sdts.get(i);
+          assertEquals(targs.get(i), targs.get(i), sdt.getContent().getText());
+       }
+    }
 
     private List<XWPFSDT> extractAllSDTs(XWPFDocument doc){
 

Added: poi/trunk/test-data/document/Bug55142.docx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/document/Bug55142.docx?rev=1496458&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/document/Bug55142.docx
------------------------------------------------------------------------------
    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