View | Details | Raw Unified | Return to bug 49446
Collapse All | Expand All

(-)src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java (-1 / +8 lines)
Lines 54-59 Link Here
54
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLineSpacingRule;
54
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STLineSpacingRule;
55
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
55
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STOnOff;
56
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
56
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STTextAlignment;
57
import org.w3c.dom.Node;
57
import org.w3c.dom.NodeList;
58
import org.w3c.dom.NodeList;
58
import org.w3c.dom.Text;
59
import org.w3c.dom.Text;
59
60
Lines 133-139 Link Here
133
          while (c.toNextSelection()) {
134
          while (c.toNextSelection()) {
134
              XmlObject o = c.getObject();
135
              XmlObject o = c.getObject();
135
              if (o instanceof CTText) {
136
              if (o instanceof CTText) {
136
                  text.append(((CTText) o).getStringValue());
137
            	  String tagName = o.getDomNode().getNodeName();
138
            	  // field codes (w:instrText, defined in spec sec. 17.16.23)
139
            	  // come up as instances of CTText, but they only 
140
            	  // pollute the output
141
            	  if (!tagName.equals("w:instrText")) {
142
        			  text.append(((CTText) o).getStringValue());
143
            	 }
137
              }
144
              }
138
              if (o instanceof CTPTab) {
145
              if (o instanceof CTPTab) {
139
                  text.append("\t");
146
                  text.append("\t");
(-)src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java (+13 lines)
Lines 237-240 Link Here
237
       // Now check the first paragraph in total
237
       // Now check the first paragraph in total
238
       assertTrue(extractor.getText().contains("a\tb\n"));
238
       assertTrue(extractor.getText().contains("a\tb\n"));
239
    }
239
    }
240
    
241
    /**
242
     * The output should not contain field codes, e.g. those specified in the
243
     * w:instrText tag (spec sec. 17.16.23)
244
     */
245
    public void testNoFieldCodes() {
246
        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("FieldCodes.docx");
247
        XWPFWordExtractor extractor = new XWPFWordExtractor(doc);
248
        String text = extractor.getText();
249
        assertTrue(text.length() > 0);
250
        assertFalse(text.contains("AUTHOR"));
251
        assertFalse(text.contains("CREATEDATE"));
252
    }
240
}
253
}

Return to bug 49446