mirror of https://github.com/apache/poi.git
Re-enable the XWPF test for adding paragraphs, and fix it up to work properly
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1100022 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
27732b7287
commit
9a0997290e
|
@ -0,0 +1,27 @@
|
||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||||
|
<!--
|
||||||
|
====================================================================
|
||||||
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
contributor license agreements. See the NOTICE file distributed with
|
||||||
|
this work for additional information regarding copyright ownership.
|
||||||
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
||||||
|
(the "License"); you may not use this file except in compliance with
|
||||||
|
the License. You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
====================================================================
|
||||||
|
-->
|
||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<p>This package contains classes for handling Microsoft .docx
|
||||||
|
Word Processing files, known in POI as XWPF (XML Word Processing
|
||||||
|
Format).
|
||||||
|
</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -649,7 +649,9 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
|
||||||
* @return a new paragraph
|
* @return a new paragraph
|
||||||
*/
|
*/
|
||||||
public XWPFParagraph createParagraph(){
|
public XWPFParagraph createParagraph(){
|
||||||
return new XWPFParagraph(ctDocument.getBody().addNewP(), this);
|
XWPFParagraph p = new XWPFParagraph(ctDocument.getBody().addNewP(), this);
|
||||||
|
paragraphs.add(p);
|
||||||
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -24,7 +24,10 @@ import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||||
import org.apache.poi.openxml4j.opc.PackagePart;
|
import org.apache.poi.openxml4j.opc.PackagePart;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||||
|
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||||
import org.apache.poi.xwpf.usermodel.XWPFRelation;
|
import org.apache.poi.xwpf.usermodel.XWPFRelation;
|
||||||
|
import org.apache.xmlbeans.XmlCursor;
|
||||||
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
|
||||||
|
|
||||||
public final class TestXWPFDocument extends TestCase {
|
public final class TestXWPFDocument extends TestCase {
|
||||||
|
|
||||||
|
@ -95,20 +98,22 @@ public final class TestXWPFDocument extends TestCase {
|
||||||
assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
|
assertEquals("Apache POI", props.getExtendedProperties().getUnderlyingProperties().getApplication());
|
||||||
}
|
}
|
||||||
|
|
||||||
// public void testAddParagraph(){
|
public void testAddParagraph(){
|
||||||
// XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
|
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
|
||||||
// int pLength = doc.getParagraphs().length;
|
assertEquals(3, doc.getParagraphs().size());
|
||||||
// XWPFParagraph p = doc.insertNewParagraph(3);
|
|
||||||
// assertTrue(p == doc.getParagraphs()[3]);
|
XWPFParagraph p = doc.createParagraph();
|
||||||
// assertTrue(++pLength == doc.getParagraphs().length);
|
assertEquals(p, doc.getParagraphs().get(3));
|
||||||
// CTP ctp = p.getCTP();
|
assertEquals(4, doc.getParagraphs().size());
|
||||||
// XWPFParagraph newP = doc.getParagraph(ctp);
|
|
||||||
// assertSame(p, newP);
|
CTP ctp = p.getCTP();
|
||||||
// XmlCursor cursor = doc.getDocument().getBody().getPArray(0).newCursor();
|
XWPFParagraph newP = doc.getParagraph(ctp);
|
||||||
// XWPFParagraph cP = doc.insertNewParagraph(cursor);
|
assertSame(p, newP);
|
||||||
// assertSame(cP, doc.getParagraphs()[0]);
|
XmlCursor cursor = doc.getDocument().getBody().getPArray(0).newCursor();
|
||||||
// assertTrue(++pLength == doc.getParagraphs().length);
|
XWPFParagraph cP = doc.insertNewParagraph(cursor);
|
||||||
// }
|
assertSame(cP, doc.getParagraphs().get(0));
|
||||||
|
assertEquals(5, doc.getParagraphs().size());
|
||||||
|
}
|
||||||
|
|
||||||
public void testAddPicture(){
|
public void testAddPicture(){
|
||||||
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
|
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
|
||||||
|
|
Loading…
Reference in New Issue