You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2014/11/05 23:26:01 UTC

svn commit: r1636990 - in /poi/trunk: src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java test-data/document/checkboxes.docx

Author: centic
Date: Wed Nov  5 22:26:00 2014
New Revision: 1636990

URL: http://svn.apache.org/r1636990
Log:
github-7 - Form check box extraction with XWPFWordExtractor

Added:
    poi/trunk/test-data/document/checkboxes.docx
Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.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=1636990&r1=1636989&r2=1636990&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 Wed Nov  5 22:26:00 2014
@@ -34,42 +34,13 @@ import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlString;
 import org.apache.xmlbeans.XmlToken;
 import org.apache.xmlbeans.impl.values.XmlAnyTypeImpl;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTBlip;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObjectData;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualPictureProperties;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
-import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType;
+import org.openxmlformats.schemas.drawingml.x2006.main.*;
 import org.openxmlformats.schemas.drawingml.x2006.picture.CTPicture;
 import org.openxmlformats.schemas.drawingml.x2006.picture.CTPictureNonVisual;
 import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor;
 import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTInline;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTColor;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTEmpty;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdnRef;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHpsMeasure;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTOnOff;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPTab;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSignedHpsMeasure;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTUnderline;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalAlignRun;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrClear;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrType;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STUnderline;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalAlignRun;
 import org.w3c.dom.NodeList;
 import org.w3c.dom.Text;
 
@@ -894,6 +865,22 @@ public class XWPFRun implements ISDTCont
                     text.append(((CTText) o).getStringValue());
                 }
             }
+            
+            // Complex type evaluation (currently only for extraction of check boxes)
+            if(o instanceof CTFldChar) {
+                CTFldChar ctfldChar = ((CTFldChar)o);
+                    if(ctfldChar.getFldCharType() == STFldCharType.BEGIN) {
+                        if(ctfldChar.getFfData() != null) {
+                            for(CTFFCheckBox checkBox : ctfldChar.getFfData().getCheckBoxList()) {
+                                if(checkBox.getDefault().getVal() == STOnOff.X_1) {
+                                    text.append("|X|");
+                                } else {
+                                    text.append("|_|");
+                                }
+                            }
+                        }
+                }
+            }
 
             if (o instanceof CTPTab) {
                 text.append("\t");

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java?rev=1636990&r1=1636989&r2=1636990&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java Wed Nov  5 22:26:00 2014
@@ -397,4 +397,17 @@ public class TestXWPFWordExtractor exten
         extractor.getText();
         extractor.close();
     }
+    
+    public void testCheckboxes() throws IOException  {
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("checkboxes.docx");
+        System.out.println(doc);
+        XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
+        
+        assertEquals("This is a small test for checkboxes \nunchecked: |_| \n" +
+                     "Or checked: |X|\n\n\n\n\n" +
+                     "Test a checkbox within a textbox: |_| -> |X|\n\n\n" +
+                     "In Table:\n|_|\t|X|\n\n\n" +
+                     "In Sequence:\n|X||_||X|\n", extractor.getText());
+        extractor.close();
+    }
 }

Added: poi/trunk/test-data/document/checkboxes.docx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/document/checkboxes.docx?rev=1636990&view=auto
==============================================================================
Files poi/trunk/test-data/document/checkboxes.docx (added) and poi/trunk/test-data/document/checkboxes.docx Wed Nov  5 22:26:00 2014 differ



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