summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2014-11-05 22:26:00 +0000
committerDominik Stadler <centic@apache.org>2014-11-05 22:26:00 +0000
commitac57e34264305add6076f18173876135f3da1ed0 (patch)
tree484d50efba549ae8dd55808fb98297dc403a449c
parent9bb00e4228d77656c651fa0b7bd10a4e56f07d08 (diff)
downloadpoi-ac57e34264305add6076f18173876135f3da1ed0.tar.gz
poi-ac57e34264305add6076f18173876135f3da1ed0.zip
github-7 - Form check box extraction with XWPFWordExtractor
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1636990 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java49
-rw-r--r--src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java13
-rw-r--r--test-data/document/checkboxes.docxbin0 -> 20800 bytes
3 files changed, 31 insertions, 31 deletions
diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
index dc09b43d46..9234d18506 100644
--- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
+++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFRun.java
@@ -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 ISDTContents, IRunElement{
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");
diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java b/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
index d63bd642de..00408829df 100644
--- a/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
+++ b/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java
@@ -397,4 +397,17 @@ public class TestXWPFWordExtractor extends TestCase {
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();
+ }
}
diff --git a/test-data/document/checkboxes.docx b/test-data/document/checkboxes.docx
new file mode 100644
index 0000000000..c35b71598f
--- /dev/null
+++ b/test-data/document/checkboxes.docx
Binary files differ