poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1578921 - in /poi/trunk/src/ooxml: java/org/apache/poi/xwpf/usermodel/XWPFRun.java testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
Date Tue, 18 Mar 2014 14:26:28 GMT
Author: nick
Date: Tue Mar 18 14:26:28 2014
New Revision: 1578921

URL: http://svn.apache.org/r1578921
Log:
Support adding tabs to a XWPFRun, and add unit tests on toString() for addTab and addCarriageReturn

Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java?rev=1578921&r1=1578920&r2=1578921&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java Tue Mar 18 14:26:28
2014
@@ -713,6 +713,18 @@ public class XWPFRun implements ISDTCont
     }
 
     /**
+     * Specifies that a tab shall be placed at the current location in 
+     *  the run content.
+     */
+    public void addTab() {
+        run.addNewTab();
+    }
+
+    public void removeTab() {
+        //TODO
+    }    
+
+    /**
      * Specifies that a carriage return shall be placed at the
      * current location in the run content.
      * A carriage return is used to end the current line of text in
@@ -897,13 +909,13 @@ public class XWPFRun implements ISDTCont
                 // This bit works around it, and replicates the above
                 //  rules for that case
                 String tagName = o.getDomNode().getNodeName();
-                if ("w:tab".equals(tagName)) {
+                if ("w:tab".equals(tagName) || "tab".equals(tagName)) {
                     text.append("\t");
                 }
-                if ("w:br".equals(tagName)) {
+                if ("w:br".equals(tagName) || "br".equals(tagName)) {
                     text.append("\n");
                 }
-                if ("w:cr".equals(tagName)) {
+                if ("w:cr".equals(tagName) || "cr".equals(tagName)) {
                     text.append("\n");
                 }
             }

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java?rev=1578921&r1=1578920&r2=1578921&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java Tue Mar 18
14:26:28 2014
@@ -181,6 +181,29 @@ public class TestXWPFRun extends TestCas
         run.setText("T2");
         run.addCarriageReturn();
         assertEquals(3, run.getCTR().getCrList().size());
+        
+        assertEquals("T1\n\nT2\n", run.toString());
+    }
+    
+    public void testAddTabsAndLineBreaks() {
+        ctRun.addNewT().setStringValue("TEST STRING");
+        ctRun.addNewCr();
+        ctRun.addNewT().setStringValue("TEST2 STRING");
+        ctRun.addNewTab();
+        ctRun.addNewT().setStringValue("TEST3 STRING");
+        assertEquals(1, ctRun.sizeOfCrArray());
+        assertEquals(1, ctRun.sizeOfTabArray());
+
+        XWPFRun run = new XWPFRun(CTR.Factory.newInstance(), p);
+        run.setText("T1");
+        run.addCarriageReturn();
+        run.setText("T2");
+        run.addTab();
+        run.setText("T3");
+        assertEquals(1, run.getCTR().getCrList().size());
+        assertEquals(1, run.getCTR().getTabList().size());
+        
+        assertEquals("T1\nT2\tT3", run.toString());
     }
 
     public void testAddPageBreak() {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message