You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/07/19 21:00:38 UTC
svn commit: r1691843 [25/30] - in /poi/branches/common_sl: ./ .settings/
legal/ osgi/ osgi/src/ src/examples/src/org/apache/poi/hpsf/examples/
src/examples/src/org/apache/poi/hssf/usermodel/examples/
src/examples/src/org/apache/poi/ss/examples/ src/exa...
Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFRun.java Sun Jul 19 19:00:32 2015
@@ -20,13 +20,12 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.math.BigInteger;
import java.util.Iterator;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.xwpf.XWPFTestDataSamples;
-import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
+import java.util.List;
+
+import junit.framework.TestCase;
+import org.apache.poi.xwpf.XWPFTestDataSamples;
+import org.apache.poi.xwpf.model.XWPFHeaderFooterPolicy;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTBr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRPr;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBrClear;
@@ -46,28 +45,28 @@ public class TestXWPFRun extends TestCas
p = doc.createParagraph();
this.ctRun = CTR.Factory.newInstance();
- }
-
- public void testSetGetText() {
- ctRun.addNewT().setStringValue("TEST STRING");
- ctRun.addNewT().setStringValue("TEST2 STRING");
- ctRun.addNewT().setStringValue("TEST3 STRING");
-
- assertEquals(3,ctRun.sizeOfTArray());
- XWPFRun run = new XWPFRun(ctRun, p);
-
- assertEquals("TEST2 STRING",run.getText(1));
-
- run.setText("NEW STRING",0);
- assertEquals("NEW STRING",run.getText(0));
-
- //run.setText("xxx",14);
- //fail("Position wrong");
- }
-
- public void testSetGetBold() {
- CTRPr rpr = ctRun.addNewRPr();
- rpr.addNewB().setVal(STOnOff.TRUE);
+ }
+
+ public void testSetGetText() {
+ ctRun.addNewT().setStringValue("TEST STRING");
+ ctRun.addNewT().setStringValue("TEST2 STRING");
+ ctRun.addNewT().setStringValue("TEST3 STRING");
+
+ assertEquals(3, ctRun.sizeOfTArray());
+ XWPFRun run = new XWPFRun(ctRun, p);
+
+ assertEquals("TEST2 STRING", run.getText(1));
+
+ run.setText("NEW STRING", 0);
+ assertEquals("NEW STRING", run.getText(0));
+
+ //run.setText("xxx",14);
+ //fail("Position wrong");
+ }
+
+ public void testSetGetBold() {
+ CTRPr rpr = ctRun.addNewRPr();
+ rpr.addNewB().setVal(STOnOff.TRUE);
XWPFRun run = new XWPFRun(ctRun, p);
assertEquals(true, run.isBold());
@@ -178,16 +177,16 @@ public class TestXWPFRun extends TestCas
run.setText("T1");
run.addCarriageReturn();
run.addCarriageReturn();
- run.setText("T2");
- run.addCarriageReturn();
- assertEquals(3, run.getCTR().sizeOfCrArray());
-
- assertEquals("T1\n\nT2\n", run.toString());
- }
-
- public void testAddTabsAndLineBreaks() {
- ctRun.addNewT().setStringValue("TEST STRING");
- ctRun.addNewCr();
+ run.setText("T2");
+ run.addCarriageReturn();
+ assertEquals(3, run.getCTR().sizeOfCrArray());
+
+ 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");
@@ -199,21 +198,21 @@ public class TestXWPFRun extends TestCas
run.addCarriageReturn();
run.setText("T2");
run.addTab();
- run.setText("T3");
- assertEquals(1, run.getCTR().sizeOfCrArray());
- assertEquals(1, run.getCTR().sizeOfTabArray());
-
- assertEquals("T1\nT2\tT3", run.toString());
- }
-
+ run.setText("T3");
+ assertEquals(1, run.getCTR().sizeOfCrArray());
+ assertEquals(1, run.getCTR().sizeOfTabArray());
+
+ assertEquals("T1\nT2\tT3", run.toString());
+ }
+
public void testAddPageBreak() {
- ctRun.addNewT().setStringValue("TEST STRING");
- ctRun.addNewBr();
- ctRun.addNewT().setStringValue("TEST2 STRING");
- CTBr breac=ctRun.addNewBr();
- breac.setClear(STBrClear.LEFT);
- ctRun.addNewT().setStringValue("TEST3 STRING");
- assertEquals(2, ctRun.sizeOfBrArray());
+ ctRun.addNewT().setStringValue("TEST STRING");
+ ctRun.addNewBr();
+ ctRun.addNewT().setStringValue("TEST2 STRING");
+ CTBr breac = ctRun.addNewBr();
+ breac.setClear(STBrClear.LEFT);
+ ctRun.addNewT().setStringValue("TEST3 STRING");
+ assertEquals(2, ctRun.sizeOfBrArray());
XWPFRun run = new XWPFRun(CTR.Factory.newInstance(), p);
run.setText("TEXT1");
@@ -222,144 +221,145 @@ public class TestXWPFRun extends TestCas
run.addBreak(BreakType.TEXT_WRAPPING);
assertEquals(2, run.getCTR().sizeOfBrArray());
}
-
- /**
- * Test that on an existing document, we do the
- * right thing with it
- * @throws IOException
- */
- public void testExisting() throws IOException {
- XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx");
- XWPFParagraph p;
- XWPFRun run;
-
-
- // First paragraph is simple
- p = doc.getParagraphArray(0);
- assertEquals("This is a test document.", p.getText());
- assertEquals(2, p.getRuns().size());
-
- run = p.getRuns().get(0);
- assertEquals("This is a test document", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrike());
- assertEquals(null, run.getCTR().getRPr());
-
- run = p.getRuns().get(1);
- assertEquals(".", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrike());
- assertEquals(null, run.getCTR().getRPr());
-
-
- // Next paragraph is all in one style, but a different one
- p = doc.getParagraphArray(1);
- assertEquals("This bit is in bold and italic", p.getText());
- assertEquals(1, p.getRuns().size());
-
- run = p.getRuns().get(0);
- assertEquals("This bit is in bold and italic", run.toString());
- assertEquals(true, run.isBold());
- assertEquals(true, run.isItalic());
- assertEquals(false, run.isStrike());
- assertEquals(true, run.getCTR().getRPr().isSetB());
- assertEquals(false, run.getCTR().getRPr().getB().isSetVal());
-
-
- // Back to normal
- p = doc.getParagraphArray(2);
- assertEquals("Back to normal", p.getText());
- assertEquals(1, p.getRuns().size());
-
- run = p.getRuns().get(0);
- assertEquals("Back to normal", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrike());
- assertEquals(null, run.getCTR().getRPr());
-
-
- // Different styles in one paragraph
- p = doc.getParagraphArray(3);
- assertEquals("This contains BOLD, ITALIC and BOTH, as well as RED and YELLOW text.", p.getText());
- assertEquals(11, p.getRuns().size());
-
- run = p.getRuns().get(0);
- assertEquals("This contains ", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrike());
- assertEquals(null, run.getCTR().getRPr());
-
- run = p.getRuns().get(1);
- assertEquals("BOLD", run.toString());
- assertEquals(true, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrike());
-
- run = p.getRuns().get(2);
- assertEquals(", ", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrike());
- assertEquals(null, run.getCTR().getRPr());
-
- run = p.getRuns().get(3);
- assertEquals("ITALIC", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(true, run.isItalic());
- assertEquals(false, run.isStrike());
-
- run = p.getRuns().get(4);
- assertEquals(" and ", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrike());
- assertEquals(null, run.getCTR().getRPr());
-
- run = p.getRuns().get(5);
- assertEquals("BOTH", run.toString());
- assertEquals(true, run.isBold());
- assertEquals(true, run.isItalic());
- assertEquals(false, run.isStrike());
-
- run = p.getRuns().get(6);
- assertEquals(", as well as ", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrike());
- assertEquals(null, run.getCTR().getRPr());
-
- run = p.getRuns().get(7);
- assertEquals("RED", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrike());
-
- run = p.getRuns().get(8);
- assertEquals(" and ", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrike());
- assertEquals(null, run.getCTR().getRPr());
-
- run = p.getRuns().get(9);
- assertEquals("YELLOW", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrike());
-
- run = p.getRuns().get(10);
- assertEquals(" text.", run.toString());
- assertEquals(false, run.isBold());
- assertEquals(false, run.isItalic());
- assertEquals(false, run.isStrike());
- assertEquals(null, run.getCTR().getRPr());
- }
-
- public void testPictureInHeader() throws IOException {
+
+ /**
+ * Test that on an existing document, we do the
+ * right thing with it
+ *
+ * @throws IOException
+ */
+ public void testExisting() throws IOException {
+ XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx");
+ XWPFParagraph p;
+ XWPFRun run;
+
+
+ // First paragraph is simple
+ p = doc.getParagraphArray(0);
+ assertEquals("This is a test document.", p.getText());
+ assertEquals(2, p.getRuns().size());
+
+ run = p.getRuns().get(0);
+ assertEquals("This is a test document", run.toString());
+ assertEquals(false, run.isBold());
+ assertEquals(false, run.isItalic());
+ assertEquals(false, run.isStrike());
+ assertEquals(null, run.getCTR().getRPr());
+
+ run = p.getRuns().get(1);
+ assertEquals(".", run.toString());
+ assertEquals(false, run.isBold());
+ assertEquals(false, run.isItalic());
+ assertEquals(false, run.isStrike());
+ assertEquals(null, run.getCTR().getRPr());
+
+
+ // Next paragraph is all in one style, but a different one
+ p = doc.getParagraphArray(1);
+ assertEquals("This bit is in bold and italic", p.getText());
+ assertEquals(1, p.getRuns().size());
+
+ run = p.getRuns().get(0);
+ assertEquals("This bit is in bold and italic", run.toString());
+ assertEquals(true, run.isBold());
+ assertEquals(true, run.isItalic());
+ assertEquals(false, run.isStrike());
+ assertEquals(true, run.getCTR().getRPr().isSetB());
+ assertEquals(false, run.getCTR().getRPr().getB().isSetVal());
+
+
+ // Back to normal
+ p = doc.getParagraphArray(2);
+ assertEquals("Back to normal", p.getText());
+ assertEquals(1, p.getRuns().size());
+
+ run = p.getRuns().get(0);
+ assertEquals("Back to normal", run.toString());
+ assertEquals(false, run.isBold());
+ assertEquals(false, run.isItalic());
+ assertEquals(false, run.isStrike());
+ assertEquals(null, run.getCTR().getRPr());
+
+
+ // Different styles in one paragraph
+ p = doc.getParagraphArray(3);
+ assertEquals("This contains BOLD, ITALIC and BOTH, as well as RED and YELLOW text.", p.getText());
+ assertEquals(11, p.getRuns().size());
+
+ run = p.getRuns().get(0);
+ assertEquals("This contains ", run.toString());
+ assertEquals(false, run.isBold());
+ assertEquals(false, run.isItalic());
+ assertEquals(false, run.isStrike());
+ assertEquals(null, run.getCTR().getRPr());
+
+ run = p.getRuns().get(1);
+ assertEquals("BOLD", run.toString());
+ assertEquals(true, run.isBold());
+ assertEquals(false, run.isItalic());
+ assertEquals(false, run.isStrike());
+
+ run = p.getRuns().get(2);
+ assertEquals(", ", run.toString());
+ assertEquals(false, run.isBold());
+ assertEquals(false, run.isItalic());
+ assertEquals(false, run.isStrike());
+ assertEquals(null, run.getCTR().getRPr());
+
+ run = p.getRuns().get(3);
+ assertEquals("ITALIC", run.toString());
+ assertEquals(false, run.isBold());
+ assertEquals(true, run.isItalic());
+ assertEquals(false, run.isStrike());
+
+ run = p.getRuns().get(4);
+ assertEquals(" and ", run.toString());
+ assertEquals(false, run.isBold());
+ assertEquals(false, run.isItalic());
+ assertEquals(false, run.isStrike());
+ assertEquals(null, run.getCTR().getRPr());
+
+ run = p.getRuns().get(5);
+ assertEquals("BOTH", run.toString());
+ assertEquals(true, run.isBold());
+ assertEquals(true, run.isItalic());
+ assertEquals(false, run.isStrike());
+
+ run = p.getRuns().get(6);
+ assertEquals(", as well as ", run.toString());
+ assertEquals(false, run.isBold());
+ assertEquals(false, run.isItalic());
+ assertEquals(false, run.isStrike());
+ assertEquals(null, run.getCTR().getRPr());
+
+ run = p.getRuns().get(7);
+ assertEquals("RED", run.toString());
+ assertEquals(false, run.isBold());
+ assertEquals(false, run.isItalic());
+ assertEquals(false, run.isStrike());
+
+ run = p.getRuns().get(8);
+ assertEquals(" and ", run.toString());
+ assertEquals(false, run.isBold());
+ assertEquals(false, run.isItalic());
+ assertEquals(false, run.isStrike());
+ assertEquals(null, run.getCTR().getRPr());
+
+ run = p.getRuns().get(9);
+ assertEquals("YELLOW", run.toString());
+ assertEquals(false, run.isBold());
+ assertEquals(false, run.isItalic());
+ assertEquals(false, run.isStrike());
+
+ run = p.getRuns().get(10);
+ assertEquals(" text.", run.toString());
+ assertEquals(false, run.isBold());
+ assertEquals(false, run.isItalic());
+ assertEquals(false, run.isStrike());
+ assertEquals(null, run.getCTR().getRPr());
+ }
+
+ public void testPictureInHeader() throws IOException {
XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("headerPic.docx");
XWPFHeaderFooterPolicy policy = sampleDoc.getHeaderFooterPolicy();
@@ -373,47 +373,47 @@ public class TestXWPFRun extends TestCas
for (XWPFPicture pic : pictures) {
assertNotNull(pic.getPictureData());
- assertEquals("DOZOR", pic.getDescription());
- }
-
- count+= pictures.size();
- }
- }
-
- assertEquals(1, count);
- }
-
- public void testAddPicture() throws Exception {
- XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx");
- XWPFParagraph p = doc.getParagraphArray(2);
- XWPFRun r = p.getRuns().get(0);
-
- assertEquals(0, doc.getAllPictures().size());
- assertEquals(0, r.getEmbeddedPictures().size());
-
- r.addPicture(new ByteArrayInputStream(new byte[0]), Document.PICTURE_TYPE_JPEG, "test.jpg", 21, 32);
-
- assertEquals(1, doc.getAllPictures().size());
- assertEquals(1, r.getEmbeddedPictures().size());
- }
-
- /**
- * Bugzilla #52288 - setting the font family on the
- * run mustn't NPE
- */
- public void testSetFontFamily_52288() throws Exception {
- XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("52288.docx");
- final Iterator<XWPFParagraph> paragraphs = doc.getParagraphsIterator();
- while (paragraphs.hasNext()) {
- final XWPFParagraph paragraph = paragraphs.next();
- for (final XWPFRun run : paragraph.getRuns()) {
- if (run != null) {
- final String text = run.getText(0);
- if (text != null) {
- run.setFontFamily("Times New Roman");
- }
- }
- }
- }
- }
-}
+ assertEquals("DOZOR", pic.getDescription());
+ }
+
+ count += pictures.size();
+ }
+ }
+
+ assertEquals(1, count);
+ }
+
+ public void testAddPicture() throws Exception {
+ XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("TestDocument.docx");
+ XWPFParagraph p = doc.getParagraphArray(2);
+ XWPFRun r = p.getRuns().get(0);
+
+ assertEquals(0, doc.getAllPictures().size());
+ assertEquals(0, r.getEmbeddedPictures().size());
+
+ r.addPicture(new ByteArrayInputStream(new byte[0]), Document.PICTURE_TYPE_JPEG, "test.jpg", 21, 32);
+
+ assertEquals(1, doc.getAllPictures().size());
+ assertEquals(1, r.getEmbeddedPictures().size());
+ }
+
+ /**
+ * Bugzilla #52288 - setting the font family on the
+ * run mustn't NPE
+ */
+ public void testSetFontFamily_52288() throws Exception {
+ XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("52288.docx");
+ final Iterator<XWPFParagraph> paragraphs = doc.getParagraphsIterator();
+ while (paragraphs.hasNext()) {
+ final XWPFParagraph paragraph = paragraphs.next();
+ for (final XWPFRun run : paragraph.getRuns()) {
+ if (run != null) {
+ final String text = run.getText(0);
+ if (text != null) {
+ run.setFontFamily("Times New Roman");
+ }
+ }
+ }
+ }
+ }
+}
Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSDT.java Sun Jul 19 19:00:32 2015
@@ -15,48 +15,46 @@
limitations under the License.
==================================================================== */
-package org.apache.poi.xwpf.usermodel;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.xwpf.XWPFTestDataSamples;
-
-public final class TestXWPFSDT extends TestCase {
-
- /**
- * Test simple tag and title extraction from SDT
- * @throws Exception
- */
- public void testTagTitle() throws Exception {
- XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx");
- String tag = null;
- String title= null;
- List<AbstractXWPFSDT> sdts = extractAllSDTs(doc);
- for (AbstractXWPFSDT sdt :sdts){
- if (sdt.getContent().toString().equals("Rich_text")){
- tag = "MyTag";
- title = "MyTitle";
- break;
- }
-
- }
- assertEquals("controls size", 13, sdts.size());
-
+package org.apache.poi.xwpf.usermodel;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+import org.apache.poi.xwpf.XWPFTestDataSamples;
+
+public final class TestXWPFSDT extends TestCase {
+
+ /**
+ * Test simple tag and title extraction from SDT
+ *
+ * @throws Exception
+ */
+ public void testTagTitle() throws Exception {
+ XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx");
+ String tag = null;
+ String title = null;
+ List<AbstractXWPFSDT> sdts = extractAllSDTs(doc);
+ for (AbstractXWPFSDT sdt : sdts) {
+ if (sdt.getContent().toString().equals("Rich_text")) {
+ tag = "MyTag";
+ title = "MyTitle";
+ break;
+ }
+
+ }
+ assertEquals("controls size", 13, sdts.size());
+
assertEquals("tag", "MyTag", tag);
assertEquals("title", "MyTitle", title);
- }
-
-
- public void testGetSDTs() throws Exception{
- String[] contents = new String[]{
- "header_rich_text",
- "Rich_text",
+ }
+
+
+ public void testGetSDTs() throws Exception {
+ String[] contents = new String[]{
+ "header_rich_text",
+ "Rich_text",
"Rich_text_pre_table\nRich_text_cell1\t\t\t\n\t\t\t\n\t\t\t\n\nRich_text_post_table",
"Plain_text_no_newlines",
"Plain_text_with_newlines1\nplain_text_with_newlines2",
@@ -72,125 +70,126 @@ public final class TestXWPFSDT extends T
};
XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54849.docx");
List<AbstractXWPFSDT> sdts = extractAllSDTs(doc);
-
- assertEquals("number of sdts", contents.length, sdts.size());
-
- for (int i = 0; i < contents.length; i++){
- AbstractXWPFSDT sdt = sdts.get(i);
- assertEquals(i+ ": " + contents[i], contents[i], sdt.getContent().toString());
- }
- }
- /**
- * POI-54771 and TIKA-1317
- */
+
+ assertEquals("number of sdts", contents.length, sdts.size());
+
+ for (int i = 0; i < contents.length; i++) {
+ AbstractXWPFSDT sdt = sdts.get(i);
+ assertEquals(i + ": " + contents[i], contents[i], sdt.getContent().toString());
+ }
+ }
+
+ /**
+ * POI-54771 and TIKA-1317
+ */
public void testSDTAsCell() throws Exception {
//Bug54771a.docx and Bug54771b.docx test slightly
//different recursion patterns. Keep both!
- XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54771a.docx");
- List<AbstractXWPFSDT> sdts = extractAllSDTs(doc);
- String text = sdts.get(0).getContent().getText();
- assertEquals(2, sdts.size());
- assertTrue(text.indexOf("Test") > -1);
-
- text = sdts.get(1).getContent().getText();
+ XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug54771a.docx");
+ List<AbstractXWPFSDT> sdts = extractAllSDTs(doc);
+ String text = sdts.get(0).getContent().getText();
+ assertEquals(2, sdts.size());
+ assertTrue(text.indexOf("Test") > -1);
+
+ text = sdts.get(1).getContent().getText();
assertTrue(text.indexOf("Test Subtitle") > -1);
assertTrue(text.indexOf("Test User") > -1);
assertTrue(text.indexOf("Test") < text.indexOf("Test Subtitle"));
-
- doc = XWPFTestDataSamples.openSampleDocument("Bug54771b.docx");
- sdts = extractAllSDTs(doc);
- assertEquals(3, sdts.size());
- assertTrue(sdts.get(0).getContent().getText().indexOf("Test") > -1);
-
- assertTrue(sdts.get(1).getContent().getText().indexOf("Test Subtitle") > -1);
- assertTrue(sdts.get(2).getContent().getText().indexOf("Test User") > -1);
-
- }
-
- /**
- * POI-55142 and Tika 1130
- */
- public void testNewLinesBetweenRuns() throws Exception{
- XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug55142.docx");
- List<AbstractXWPFSDT> sdts = extractAllSDTs(doc);
- List<String> targs = new ArrayList<String>();
- //these test newlines and tabs in paragraphs/body elements
- targs.add("Rich-text1 abcdefghi");
- targs.add("Rich-text2 abcd\t\tefgh");
- targs.add("Rich-text3 abcd\nefg");
- targs.add("Rich-text4 abcdefg");
- targs.add("Rich-text5 abcdefg\nhijk");
- targs.add("Plain-text1 abcdefg");
- targs.add("Plain-text2 abcdefg\nhijk\nlmnop");
- //this tests consecutive runs within a cell (not a paragraph)
- //this test case was triggered by Tika-1130
- targs.add("sdt_incell2 abcdefg");
-
- for (int i = 0; i < sdts.size(); i++){
- AbstractXWPFSDT sdt = sdts.get(i);
- assertEquals(targs.get(i), targs.get(i), sdt.getContent().getText());
- }
- }
-
- private List<AbstractXWPFSDT> extractAllSDTs(XWPFDocument doc){
-
- List<AbstractXWPFSDT> sdts = new ArrayList<AbstractXWPFSDT>();
-
- List<XWPFHeader> headers = doc.getHeaderList();
- for (XWPFHeader header : headers){
- sdts.addAll(extractSDTsFromBodyElements(header.getBodyElements()));
- }
- sdts.addAll(extractSDTsFromBodyElements(doc.getBodyElements()));
-
- List<XWPFFooter> footers = doc.getFooterList();
- for (XWPFFooter footer : footers){
- sdts.addAll(extractSDTsFromBodyElements(footer.getBodyElements()));
- }
-
- for (XWPFFootnote footnote : doc.getFootnotes()){
- sdts.addAll(extractSDTsFromBodyElements(footnote.getBodyElements()));
- }
- for (Map.Entry<Integer, XWPFFootnote> e : doc.endnotes.entrySet()){
- sdts.addAll(extractSDTsFromBodyElements(e.getValue().getBodyElements()));
- }
- return sdts;
- }
-
- private List<AbstractXWPFSDT> extractSDTsFromBodyElements(List<IBodyElement> elements){
- List<AbstractXWPFSDT> sdts = new ArrayList<AbstractXWPFSDT>();
- for (IBodyElement e : elements){
- if (e instanceof XWPFSDT){
- XWPFSDT sdt = (XWPFSDT)e;
- sdts.add(sdt);
- } else if (e instanceof XWPFParagraph){
-
- XWPFParagraph p = (XWPFParagraph)e;
- for (IRunElement e2 : p.getIRuns()){
- if (e2 instanceof XWPFSDT){
- XWPFSDT sdt = (XWPFSDT)e2;
- sdts.add(sdt);
- }
- }
- } else if (e instanceof XWPFTable){
- XWPFTable table = (XWPFTable)e;
- sdts.addAll(extractSDTsFromTable(table));
- }
- }
+
+ doc = XWPFTestDataSamples.openSampleDocument("Bug54771b.docx");
+ sdts = extractAllSDTs(doc);
+ assertEquals(3, sdts.size());
+ assertTrue(sdts.get(0).getContent().getText().indexOf("Test") > -1);
+
+ assertTrue(sdts.get(1).getContent().getText().indexOf("Test Subtitle") > -1);
+ assertTrue(sdts.get(2).getContent().getText().indexOf("Test User") > -1);
+
+ }
+
+ /**
+ * POI-55142 and Tika 1130
+ */
+ public void testNewLinesBetweenRuns() throws Exception {
+ XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("Bug55142.docx");
+ List<AbstractXWPFSDT> sdts = extractAllSDTs(doc);
+ List<String> targs = new ArrayList<String>();
+ //these test newlines and tabs in paragraphs/body elements
+ targs.add("Rich-text1 abcdefghi");
+ targs.add("Rich-text2 abcd\t\tefgh");
+ targs.add("Rich-text3 abcd\nefg");
+ targs.add("Rich-text4 abcdefg");
+ targs.add("Rich-text5 abcdefg\nhijk");
+ targs.add("Plain-text1 abcdefg");
+ targs.add("Plain-text2 abcdefg\nhijk\nlmnop");
+ //this tests consecutive runs within a cell (not a paragraph)
+ //this test case was triggered by Tika-1130
+ targs.add("sdt_incell2 abcdefg");
+
+ for (int i = 0; i < sdts.size(); i++) {
+ AbstractXWPFSDT sdt = sdts.get(i);
+ assertEquals(targs.get(i), targs.get(i), sdt.getContent().getText());
+ }
+ }
+
+ private List<AbstractXWPFSDT> extractAllSDTs(XWPFDocument doc) {
+
+ List<AbstractXWPFSDT> sdts = new ArrayList<AbstractXWPFSDT>();
+
+ List<XWPFHeader> headers = doc.getHeaderList();
+ for (XWPFHeader header : headers) {
+ sdts.addAll(extractSDTsFromBodyElements(header.getBodyElements()));
+ }
+ sdts.addAll(extractSDTsFromBodyElements(doc.getBodyElements()));
+
+ List<XWPFFooter> footers = doc.getFooterList();
+ for (XWPFFooter footer : footers) {
+ sdts.addAll(extractSDTsFromBodyElements(footer.getBodyElements()));
+ }
+
+ for (XWPFFootnote footnote : doc.getFootnotes()) {
+ sdts.addAll(extractSDTsFromBodyElements(footnote.getBodyElements()));
+ }
+ for (Map.Entry<Integer, XWPFFootnote> e : doc.endnotes.entrySet()) {
+ sdts.addAll(extractSDTsFromBodyElements(e.getValue().getBodyElements()));
+ }
+ return sdts;
+ }
+
+ private List<AbstractXWPFSDT> extractSDTsFromBodyElements(List<IBodyElement> elements) {
+ List<AbstractXWPFSDT> sdts = new ArrayList<AbstractXWPFSDT>();
+ for (IBodyElement e : elements) {
+ if (e instanceof XWPFSDT) {
+ XWPFSDT sdt = (XWPFSDT) e;
+ sdts.add(sdt);
+ } else if (e instanceof XWPFParagraph) {
+
+ XWPFParagraph p = (XWPFParagraph) e;
+ for (IRunElement e2 : p.getIRuns()) {
+ if (e2 instanceof XWPFSDT) {
+ XWPFSDT sdt = (XWPFSDT) e2;
+ sdts.add(sdt);
+ }
+ }
+ } else if (e instanceof XWPFTable) {
+ XWPFTable table = (XWPFTable) e;
+ sdts.addAll(extractSDTsFromTable(table));
+ }
+ }
return sdts;
}
private List<AbstractXWPFSDT> extractSDTsFromTable(XWPFTable table) {
List<AbstractXWPFSDT> sdts = new ArrayList<AbstractXWPFSDT>();
- for (XWPFTableRow r : table.getRows()) {
- for (ICell c : r.getTableICells()) {
- if (c instanceof XWPFSDTCell) {
- sdts.add((XWPFSDTCell)c);
- } else if (c instanceof XWPFTableCell) {
- sdts.addAll(extractSDTsFromBodyElements(((XWPFTableCell)c).getBodyElements()));
- }
- }
- }
+ for (XWPFTableRow r : table.getRows()) {
+ for (ICell c : r.getTableICells()) {
+ if (c instanceof XWPFSDTCell) {
+ sdts.add((XWPFSDTCell) c);
+ } else if (c instanceof XWPFTableCell) {
+ sdts.addAll(extractSDTsFromBodyElements(((XWPFTableCell) c).getBodyElements()));
+ }
+ }
+ }
return sdts;
}
}
Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFSmartTag.java Sun Jul 19 19:00:32 2015
@@ -19,13 +19,12 @@ package org.apache.poi.xwpf.usermodel;
import java.io.IOException;
import junit.framework.TestCase;
-
import org.apache.poi.xwpf.XWPFTestDataSamples;
/**
* Tests for reading SmartTags from Word docx.
*
- * @author Fabian Lange
+ * @author Fabian Lange
*/
public final class TestXWPFSmartTag extends TestCase {
Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFStyles.java Sun Jul 19 19:00:32 2015
@@ -19,13 +19,12 @@ package org.apache.poi.xwpf.usermodel;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.xwpf.XWPFTestDataSamples;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLatentStyles;
+import java.util.List;
+
+import junit.framework.TestCase;
+import org.apache.poi.xwpf.XWPFTestDataSamples;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFonts;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLatentStyles;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLsdException;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyle;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTStyles;
@@ -33,69 +32,69 @@ import org.openxmlformats.schemas.wordpr
public class TestXWPFStyles extends TestCase {
-// protected void setUp() throws Exception {
-// super.setUp();
-// }
-
- public void testGetUsedStyles() throws IOException{
- XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("Styles.docx");
- List<XWPFStyle> testUsedStyleList = new ArrayList<XWPFStyle>();
- XWPFStyles styles = sampleDoc.getStyles();
- XWPFStyle style = styles.getStyle("berschrift1");
- testUsedStyleList.add(style);
- testUsedStyleList.add(styles.getStyle("Standard"));
- testUsedStyleList.add(styles.getStyle("berschrift1Zchn"));
- testUsedStyleList.add(styles.getStyle("Absatz-Standardschriftart"));
- style.hasSameName(style);
-
- List<XWPFStyle> usedStyleList = styles.getUsedStyleList(style);
- assertEquals(usedStyleList, testUsedStyleList);
-
-
- }
-
- public void testAddStylesToDocument() throws IOException{
- XWPFDocument docOut = new XWPFDocument();
- XWPFStyles styles = docOut.createStyles();
-
- String strStyleId = "headline1";
- CTStyle ctStyle = CTStyle.Factory.newInstance();
-
- ctStyle.setStyleId(strStyleId);
- XWPFStyle s = new XWPFStyle(ctStyle);
- styles.addStyle(s);
-
- assertTrue(styles.styleExist(strStyleId));
-
- XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut);
-
- styles = docIn.getStyles();
- assertTrue(styles.styleExist(strStyleId));
- }
-
- /**
- * Bug #52449 - We should be able to write a file containing
- * both regular and glossary styles without error
- */
- public void test52449() throws Exception {
- XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("52449.docx");
- XWPFStyles styles = doc.getStyles();
- assertNotNull(styles);
-
- XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(doc);
- styles = docIn.getStyles();
- assertNotNull(styles);
- }
-
-
- /**
- * YK: tests below don't make much sense,
- * they exist only to copy xml beans to pi-ooxml-schemas.jar
- */
- public void testLanguages(){
- XWPFDocument docOut = new XWPFDocument();
- XWPFStyles styles = docOut.createStyles();
- styles.setEastAsia("Chinese");
+// protected void setUp() throws Exception {
+// super.setUp();
+// }
+
+ public void testGetUsedStyles() throws IOException {
+ XWPFDocument sampleDoc = XWPFTestDataSamples.openSampleDocument("Styles.docx");
+ List<XWPFStyle> testUsedStyleList = new ArrayList<XWPFStyle>();
+ XWPFStyles styles = sampleDoc.getStyles();
+ XWPFStyle style = styles.getStyle("berschrift1");
+ testUsedStyleList.add(style);
+ testUsedStyleList.add(styles.getStyle("Standard"));
+ testUsedStyleList.add(styles.getStyle("berschrift1Zchn"));
+ testUsedStyleList.add(styles.getStyle("Absatz-Standardschriftart"));
+ style.hasSameName(style);
+
+ List<XWPFStyle> usedStyleList = styles.getUsedStyleList(style);
+ assertEquals(usedStyleList, testUsedStyleList);
+
+
+ }
+
+ public void testAddStylesToDocument() throws IOException {
+ XWPFDocument docOut = new XWPFDocument();
+ XWPFStyles styles = docOut.createStyles();
+
+ String strStyleId = "headline1";
+ CTStyle ctStyle = CTStyle.Factory.newInstance();
+
+ ctStyle.setStyleId(strStyleId);
+ XWPFStyle s = new XWPFStyle(ctStyle);
+ styles.addStyle(s);
+
+ assertTrue(styles.styleExist(strStyleId));
+
+ XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut);
+
+ styles = docIn.getStyles();
+ assertTrue(styles.styleExist(strStyleId));
+ }
+
+ /**
+ * Bug #52449 - We should be able to write a file containing
+ * both regular and glossary styles without error
+ */
+ public void test52449() throws Exception {
+ XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("52449.docx");
+ XWPFStyles styles = doc.getStyles();
+ assertNotNull(styles);
+
+ XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(doc);
+ styles = docIn.getStyles();
+ assertNotNull(styles);
+ }
+
+
+ /**
+ * YK: tests below don't make much sense,
+ * they exist only to copy xml beans to pi-ooxml-schemas.jar
+ */
+ public void testLanguages() {
+ XWPFDocument docOut = new XWPFDocument();
+ XWPFStyles styles = docOut.createStyles();
+ styles.setEastAsia("Chinese");
styles.setSpellingLanguage("English");
@@ -116,26 +115,82 @@ public class TestXWPFStyles extends Test
CTLsdException ex = latentStyles.addNewLsdException();
ex.setName("ex1");
XWPFLatentStyles ls = new XWPFLatentStyles(latentStyles);
- assertEquals(true, ls.isLatentStyle("ex1"));
- assertEquals(false, ls.isLatentStyle("notex1"));
- }
-
- public void testSetStyles_Bug57254() throws IOException {
- XWPFDocument docOut = new XWPFDocument();
- XWPFStyles styles = docOut.createStyles();
+ assertEquals(true, ls.isLatentStyle("ex1"));
+ assertEquals(false, ls.isLatentStyle("notex1"));
+ }
+
+ public void testSetStyles_Bug57254() throws IOException {
+ XWPFDocument docOut = new XWPFDocument();
+ XWPFStyles styles = docOut.createStyles();
CTStyles ctStyles = CTStyles.Factory.newInstance();
String strStyleId = "headline1";
CTStyle ctStyle = ctStyles.addNewStyle();
-
- ctStyle.setStyleId(strStyleId);
- styles.setStyles(ctStyles);
-
- assertTrue(styles.styleExist(strStyleId));
-
- XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut);
-
- styles = docIn.getStyles();
- assertTrue(styles.styleExist(strStyleId));
- }
+
+ ctStyle.setStyleId(strStyleId);
+ styles.setStyles(ctStyles);
+
+ assertTrue(styles.styleExist(strStyleId));
+
+ XWPFDocument docIn = XWPFTestDataSamples.writeOutAndReadBack(docOut);
+
+ styles = docIn.getStyles();
+ assertTrue(styles.styleExist(strStyleId));
+ }
+
+ public void testEasyAccessToStyles() throws IOException {
+ XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("SampleDoc.docx");
+ XWPFStyles styles = doc.getStyles();
+ assertNotNull(styles);
+
+ // Has 3 paragraphs on page one, a break, and 3 on page 2
+ assertEquals(7, doc.getParagraphs().size());
+
+ // Check the first three have no run styles, just default paragraph style
+ for (int i = 0; i < 3; i++) {
+ XWPFParagraph p = doc.getParagraphs().get(i);
+ assertEquals(null, p.getStyle());
+ assertEquals(null, p.getStyleID());
+ assertEquals(1, p.getRuns().size());
+
+ XWPFRun r = p.getRuns().get(0);
+ assertEquals(null, r.getColor());
+ assertEquals(null, r.getFontFamily());
+ assertEquals(null, r.getFontName());
+ assertEquals(-1, r.getFontSize());
+ }
+
+ // On page two, has explicit styles, but on runs not on
+ // the paragraph itself
+ for (int i = 4; i < 7; i++) {
+ XWPFParagraph p = doc.getParagraphs().get(i);
+ assertEquals(null, p.getStyle());
+ assertEquals(null, p.getStyleID());
+ assertEquals(1, p.getRuns().size());
+
+ XWPFRun r = p.getRuns().get(0);
+ assertEquals("Arial Black", r.getFontFamily());
+ assertEquals("Arial Black", r.getFontName());
+ assertEquals(16, r.getFontSize());
+ assertEquals("548DD4", r.getColor());
+ }
+
+ // Check the document styles
+ // Should have a style defined for each type
+ assertEquals(4, styles.getNumberOfStyles());
+ assertNotNull(styles.getStyle("Normal"));
+ assertNotNull(styles.getStyle("DefaultParagraphFont"));
+ assertNotNull(styles.getStyle("TableNormal"));
+ assertNotNull(styles.getStyle("NoList"));
+
+ // We can't do much yet with latent styles
+ assertEquals(137, styles.getLatentStyles().getNumberOfStyles());
+
+ // Check the default styles
+ assertNotNull(styles.getDefaultRunStyle());
+ assertNotNull(styles.getDefaultParagraphStyle());
+
+ assertEquals(11, styles.getDefaultRunStyle().getFontSize());
+ assertEquals(200, styles.getDefaultParagraphStyle().getSpacingAfter());
+ }
}
Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java Sun Jul 19 19:00:32 2015
@@ -17,18 +17,18 @@
package org.apache.poi.xwpf.usermodel;
import java.math.BigInteger;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.xwpf.XWPFTestDataSamples;
-import org.apache.poi.xwpf.usermodel.XWPFTable.XWPFBorderType;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
+import java.util.List;
+
+import junit.framework.TestCase;
+import org.apache.poi.xwpf.XWPFTestDataSamples;
+import org.apache.poi.xwpf.usermodel.XWPFTable.XWPFBorderType;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblBorders;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblCellMar;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTblGrid;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTText;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STBorder;
@@ -64,6 +64,17 @@ public class TestXWPFTable extends TestC
assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
}
+ public void testTblGrid() {
+ XWPFDocument doc = new XWPFDocument();
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ CTTblGrid cttblgrid = ctTable.addNewTblGrid();
+ cttblgrid.addNewGridCol().setW(new BigInteger("123"));
+ cttblgrid.addNewGridCol().setW(new BigInteger("321"));
+
+ XWPFTable xtab = new XWPFTable(ctTable, doc);
+ assertEquals(123, xtab.getCTTbl().getTblGrid().getGridColArray(0).getW().intValue());
+ assertEquals(321, xtab.getCTTbl().getTblGrid().getGridColArray(1).getW().intValue());
+ }
public void testGetText() {
XWPFDocument doc = new XWPFDocument();
@@ -110,13 +121,13 @@ public class TestXWPFTable extends TestC
assertEquals(1, xtab.getCTTbl().getTrArray(0).sizeOfTcArray());
}
-
- public void testSetGetWidth() {
- XWPFDocument doc = new XWPFDocument();
-
- CTTbl table = CTTbl.Factory.newInstance();
- table.addNewTblPr().addNewTblW().setW(new BigInteger("1000"));
-
+
+ public void testSetGetWidth() {
+ XWPFDocument doc = new XWPFDocument();
+
+ CTTbl table = CTTbl.Factory.newInstance();
+ table.addNewTblPr().addNewTblW().setW(new BigInteger("1000"));
+
XWPFTable xtab = new XWPFTable(table, doc);
assertEquals(1000, xtab.getWidth());
@@ -134,20 +145,20 @@ public class TestXWPFTable extends TestC
XWPFTableRow row = xtab.createRow();
row.setHeight(20);
assertEquals(20, row.getHeight());
- }
-
- public void testSetGetMargins() {
- // instantiate the following class so it'll get picked up by
- // the XmlBean process and added to the jar file. it's required
- // for the following XWPFTable methods.
- CTTblCellMar ctm = CTTblCellMar.Factory.newInstance();
- assertNotNull(ctm);
- // create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // set margins
- table.setCellMargins(50, 50, 250, 450);
+ }
+
+ public void testSetGetMargins() {
+ // instantiate the following class so it'll get picked up by
+ // the XmlBean process and added to the jar file. it's required
+ // for the following XWPFTable methods.
+ CTTblCellMar ctm = CTTblCellMar.Factory.newInstance();
+ assertNotNull(ctm);
+ // create a table
+ XWPFDocument doc = new XWPFDocument();
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // set margins
+ table.setCellMargins(50, 50, 250, 450);
// get margin components
int t = table.getCellMarginTop();
assertEquals(50, t);
@@ -157,22 +168,22 @@ public class TestXWPFTable extends TestC
assertEquals(250, b);
int r = table.getCellMarginRight();
assertEquals(450, r);
- }
-
- public void testSetGetHBorders() {
- // instantiate the following classes so they'll get picked up by
- // the XmlBean process and added to the jar file. they are required
- // for the following XWPFTable methods.
- CTTblBorders cttb = CTTblBorders.Factory.newInstance();
- assertNotNull(cttb);
- STBorder stb = STBorder.Factory.newInstance();
- assertNotNull(stb);
- // create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // set inside horizontal border
- table.setInsideHBorder(XWPFBorderType.SINGLE, 4, 0, "FF0000");
+ }
+
+ public void testSetGetHBorders() {
+ // instantiate the following classes so they'll get picked up by
+ // the XmlBean process and added to the jar file. they are required
+ // for the following XWPFTable methods.
+ CTTblBorders cttb = CTTblBorders.Factory.newInstance();
+ assertNotNull(cttb);
+ STBorder stb = STBorder.Factory.newInstance();
+ assertNotNull(stb);
+ // create a table
+ XWPFDocument doc = new XWPFDocument();
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // set inside horizontal border
+ table.setInsideHBorder(XWPFBorderType.SINGLE, 4, 0, "FF0000");
// get inside horizontal border components
int s = table.getInsideHBorderSize();
assertEquals(4, s);
@@ -182,26 +193,26 @@ public class TestXWPFTable extends TestC
assertEquals("FF0000", clr);
XWPFBorderType bt = table.getInsideHBorderType();
assertEquals(XWPFBorderType.SINGLE, bt);
- }
-
- public void testSetGetVBorders() {
- // create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
+ }
+
+ public void testSetGetVBorders() {
+ // create a table
+ XWPFDocument doc = new XWPFDocument();
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
// set inside vertical border
table.setInsideVBorder(XWPFBorderType.DOUBLE, 4, 0, "00FF00");
// get inside vertical border components
XWPFBorderType bt = table.getInsideVBorderType();
assertEquals(XWPFBorderType.DOUBLE, bt);
int sz = table.getInsideVBorderSize();
- assertEquals(4, sz);
- int sp = table.getInsideVBorderSpace();
- assertEquals(0, sp);
- String clr = table.getInsideVBorderColor();
- assertEquals("00FF00", clr);
- }
-
+ assertEquals(4, sz);
+ int sp = table.getInsideVBorderSpace();
+ assertEquals(0, sp);
+ String clr = table.getInsideVBorderColor();
+ assertEquals("00FF00", clr);
+ }
+
public void testSetGetRowBandSize() {
XWPFDocument doc = new XWPFDocument();
CTTbl ctTable = CTTbl.Factory.newInstance();
@@ -218,32 +229,30 @@ public class TestXWPFTable extends TestC
table.setColBandSize(16);
int sz = table.getColBandSize();
assertEquals(16, sz);
- }
-
- public void testCreateTable() throws Exception {
- // open an empty document
- XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
-
- // create a table with 5 rows and 7 columns
- int noRows = 5;
- int noCols = 7;
- XWPFTable table = doc.createTable(noRows,noCols);
-
- // assert the table is empty
- List<XWPFTableRow> rows = table.getRows();
- assertEquals("Table has less rows than requested.", noRows, rows.size());
- for (XWPFTableRow xwpfRow : rows)
- {
- assertNotNull(xwpfRow);
- for (int i = 0 ; i < 7 ; i++)
- {
- XWPFTableCell xwpfCell = xwpfRow.getCell(i);
- assertNotNull(xwpfCell);
- assertEquals("Empty cells should not have one paragraph.",1,xwpfCell.getParagraphs().size());
- xwpfCell = xwpfRow.getCell(i);
- assertEquals("Calling 'getCell' must not modify cells content.",1,xwpfCell.getParagraphs().size());
- }
- }
- doc.getPackage().revert();
- }
+ }
+
+ public void testCreateTable() throws Exception {
+ // open an empty document
+ XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");
+
+ // create a table with 5 rows and 7 columns
+ int noRows = 5;
+ int noCols = 7;
+ XWPFTable table = doc.createTable(noRows, noCols);
+
+ // assert the table is empty
+ List<XWPFTableRow> rows = table.getRows();
+ assertEquals("Table has less rows than requested.", noRows, rows.size());
+ for (XWPFTableRow xwpfRow : rows) {
+ assertNotNull(xwpfRow);
+ for (int i = 0; i < 7; i++) {
+ XWPFTableCell xwpfCell = xwpfRow.getCell(i);
+ assertNotNull(xwpfCell);
+ assertEquals("Empty cells should not have one paragraph.", 1, xwpfCell.getParagraphs().size());
+ xwpfCell = xwpfRow.getCell(i);
+ assertEquals("Calling 'getCell' must not modify cells content.", 1, xwpfCell.getParagraphs().size());
+ }
+ }
+ doc.getPackage().revert();
+ }
}
\ No newline at end of file
Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java Sun Jul 19 19:00:32 2015
@@ -17,71 +17,80 @@
* ====================================================================
*/
-package org.apache.poi.xwpf.usermodel;
-
-import junit.framework.TestCase;
-
-import org.apache.poi.xwpf.usermodel.XWPFTableCell.XWPFVertAlign;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
-
-public class TestXWPFTableCell extends TestCase {
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- public void testSetGetVertAlignment() throws Exception {
- // instantiate the following classes so they'll get picked up by
- // the XmlBean process and added to the jar file. they are required
- // for the following XWPFTableCell methods.
- CTShd ctShd = CTShd.Factory.newInstance();
- assertNotNull(ctShd);
- CTVerticalJc ctVjc = CTVerticalJc.Factory.newInstance();
- assertNotNull(ctVjc);
- STShd stShd = STShd.Factory.newInstance();
- assertNotNull(stShd);
- STVerticalJc stVjc = STVerticalJc.Factory.newInstance();
- assertNotNull(stVjc);
-
- // create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // table has a single row by default; grab it
- XWPFTableRow tr = table.getRow(0);
+package org.apache.poi.xwpf.usermodel;
+
+import junit.framework.TestCase;
+import org.apache.poi.xwpf.usermodel.XWPFTableCell.XWPFVertAlign;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTHMerge;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTShd;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcBorders;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTcPr;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVMerge;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalJc;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STMerge;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STShd;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc;
+
+public class TestXWPFTableCell extends TestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testSetGetVertAlignment() throws Exception {
+ // instantiate the following classes so they'll get picked up by
+ // the XmlBean process and added to the jar file. they are required
+ // for the following XWPFTableCell methods.
+ CTShd ctShd = CTShd.Factory.newInstance();
+ assertNotNull(ctShd);
+ CTVerticalJc ctVjc = CTVerticalJc.Factory.newInstance();
+ assertNotNull(ctVjc);
+ STShd stShd = STShd.Factory.newInstance();
+ assertNotNull(stShd);
+ STVerticalJc stVjc = STVerticalJc.Factory.newInstance();
+ assertNotNull(stVjc);
+
+ // create a table
+ XWPFDocument doc = new XWPFDocument();
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // table has a single row by default; grab it
+ XWPFTableRow tr = table.getRow(0);
assertNotNull(tr);
// row has a single cell by default; grab it
XWPFTableCell cell = tr.getCell(0);
- cell.setVerticalAlignment(XWPFVertAlign.BOTH);
- XWPFVertAlign al = cell.getVerticalAlignment();
- assertEquals(XWPFVertAlign.BOTH, al);
- }
-
- public void testSetGetColor() throws Exception {
- // create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // table has a single row by default; grab it
- XWPFTableRow tr = table.getRow(0);
+ cell.setVerticalAlignment(XWPFVertAlign.BOTH);
+ XWPFVertAlign al = cell.getVerticalAlignment();
+ assertEquals(XWPFVertAlign.BOTH, al);
+ }
+
+ public void testSetGetColor() throws Exception {
+ // create a table
+ XWPFDocument doc = new XWPFDocument();
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // table has a single row by default; grab it
+ XWPFTableRow tr = table.getRow(0);
assertNotNull(tr);
// row has a single cell by default; grab it
XWPFTableCell cell = tr.getCell(0);
- cell.setColor("F0000F");
- String clr = cell.getColor();
- assertEquals("F0000F", clr);
- }
-
- /**
- * ensure that CTHMerge & CTTcBorders go in poi-ooxml.jar
- */
- public void test54099(){
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
+ cell.setColor("F0000F");
+ String clr = cell.getColor();
+ assertEquals("F0000F", clr);
+ }
+
+ /**
+ * ensure that CTHMerge & CTTcBorders go in poi-ooxml.jar
+ */
+ public void test54099() {
+ XWPFDocument doc = new XWPFDocument();
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
XWPFTableRow tr = table.getRow(0);
XWPFTableCell cell = tr.getCell(0);
Modified: poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java (original)
+++ poi/branches/common_sl/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java Sun Jul 19 19:00:32 2015
@@ -15,55 +15,54 @@
limitations under the License.
==================================================================== */
-package org.apache.poi.xwpf.usermodel;
-
-import junit.framework.TestCase;
-
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
-import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
-
-public class TestXWPFTableRow extends TestCase {
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- public void testCreateRow() throws Exception {
- CTRow ctRow = CTRow.Factory.newInstance();
- assertNotNull(ctRow);
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- public void testSetGetCantSplitRow() {
- // create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // table has a single row by default; grab it
- XWPFTableRow tr = table.getRow(0);
- assertNotNull(tr);
-
- tr.setCantSplitRow(true);
- boolean isCant = tr.isCantSplitRow();
- assert(isCant);
- }
-
- public void testSetGetRepeatHeader() {
- // create a table
- XWPFDocument doc = new XWPFDocument();
- CTTbl ctTable = CTTbl.Factory.newInstance();
- XWPFTable table = new XWPFTable(ctTable, doc);
- // table has a single row by default; grab it
- XWPFTableRow tr = table.getRow(0);
- assertNotNull(tr);
-
- tr.setRepeatHeader(true);
- boolean isRpt = tr.isRepeatHeader();
- assert(isRpt);
- }
-}
+package org.apache.poi.xwpf.usermodel;
+
+import junit.framework.TestCase;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;
+
+public class TestXWPFTableRow extends TestCase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testCreateRow() throws Exception {
+ CTRow ctRow = CTRow.Factory.newInstance();
+ assertNotNull(ctRow);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void testSetGetCantSplitRow() {
+ // create a table
+ XWPFDocument doc = new XWPFDocument();
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // table has a single row by default; grab it
+ XWPFTableRow tr = table.getRow(0);
+ assertNotNull(tr);
+
+ tr.setCantSplitRow(true);
+ boolean isCant = tr.isCantSplitRow();
+ assert (isCant);
+ }
+
+ public void testSetGetRepeatHeader() {
+ // create a table
+ XWPFDocument doc = new XWPFDocument();
+ CTTbl ctTable = CTTbl.Factory.newInstance();
+ XWPFTable table = new XWPFTable(ctTable, doc);
+ // table has a single row by default; grab it
+ XWPFTableRow tr = table.getRow(0);
+ assertNotNull(tr);
+
+ tr.setRepeatHeader(true);
+ boolean isRpt = tr.isRepeatHeader();
+ assert (isRpt);
+ }
+}
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdf/event/EventBridge.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdf/event/EventBridge.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdf/event/EventBridge.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdf/event/EventBridge.java Sun Jul 19 19:00:32 2015
@@ -21,10 +21,10 @@ package org.apache.poi.hdf.event;
import org.apache.poi.hdf.model.util.BTreeSet;
import org.apache.poi.hdf.model.util.NumberFormatter;
import org.apache.poi.hdf.model.hdftypes.*;
-
import org.apache.poi.util.LittleEndian;
import java.util.ArrayList;
+import java.util.List;
@Deprecated
public final class EventBridge implements HDFLowLevelParsingListener
@@ -71,11 +71,11 @@ public final class EventBridge implement
BTreeSet _hdrCharacterRuns = new BTreeSet();
int _sectionCounter = 1;
- ArrayList _hdrs = new ArrayList();
+ List<HeaderFooter[]> _hdrs = new ArrayList<HeaderFooter[]>();
private boolean _holdParagraph = false;
private int _endHoldIndex = -1;
- private ArrayList _onHold;
+ private List<PropertyNode> _onHold;
public EventBridge(HDFParsingListener listener)
{
@@ -119,7 +119,7 @@ public final class EventBridge implement
{
for (int x = 1; x < _sectionCounter; x++)
{
- HeaderFooter[] hdrArray = (HeaderFooter[])_hdrs.get(x-1);
+ HeaderFooter[] hdrArray = _hdrs.get(x-1);
HeaderFooter hf = null;
if (!hdrArray[HeaderFooter.HEADER_EVEN - 1].isEmpty())
@@ -210,7 +210,7 @@ public final class EventBridge implement
_holdParagraph = false;
_endHoldIndex = -1;
flushHeldParagraph();
- _onHold = new ArrayList();
+ _onHold = new ArrayList<PropertyNode>();
}
}
@@ -219,7 +219,7 @@ public final class EventBridge implement
CharacterProperties chp = (CharacterProperties)StyleSheet.uncompressProperty(byteChpx, _currentStd.getCHP(), _stsh);
- ArrayList textList = BTreeSet.findProperties(start, end, _text.root);
+ List<PropertyNode> textList = BTreeSet.findProperties(start, end, _text.root);
String text = getTextFromNodes(textList, start, end);
_listener.characterRun(chp, text, start - _fcMin, end - _fcMin);
@@ -241,7 +241,7 @@ public final class EventBridge implement
}
private void flushHeaderProps(int start, int end)
{
- ArrayList list = BTreeSet.findProperties(start, end, _hdrSections.root);
+ List<PropertyNode> list = BTreeSet.findProperties(start, end, _hdrSections.root);
int size = list.size();
for (int x = 0; x < size; x++)
@@ -253,7 +253,7 @@ public final class EventBridge implement
//SepxNode node = new SepxNode(-1, secStart, secEnd, oldNode.getSepx());
//bodySection(node);
- ArrayList parList = BTreeSet.findProperties(secStart, secEnd, _hdrParagraphs.root);
+ List<PropertyNode> parList = BTreeSet.findProperties(secStart, secEnd, _hdrParagraphs.root);
int parSize = parList.size();
for (int y = 0; y < parSize; y++)
@@ -265,7 +265,7 @@ public final class EventBridge implement
PapxNode parNode = new PapxNode(parStart, parEnd, oldParNode.getPapx());
paragraph(parNode);
- ArrayList charList = BTreeSet.findProperties(parStart, parEnd, _hdrCharacterRuns.root);
+ List<PropertyNode> charList = BTreeSet.findProperties(parStart, parEnd, _hdrCharacterRuns.root);
int charSize = charList.size();
for (int z = 0; z < charSize; z++)
@@ -282,7 +282,7 @@ public final class EventBridge implement
}
}
- private String getTextFromNodes(ArrayList list, int start, int end)
+ private String getTextFromNodes(List<PropertyNode> list, int start, int end)
{
int size = list.size();
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdf/extractor/WordDocument.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdf/extractor/WordDocument.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdf/extractor/WordDocument.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdf/extractor/WordDocument.java Sun Jul 19 19:00:32 2015
@@ -114,6 +114,8 @@ public final class WordDocument {
/**
* right now this function takes one parameter: a Word file, and outputs an
* XSL-FO document at c:\test.xml (this is hardcoded)
+ *
+ * @param args The document to read
*/
public static void main(String args[])
{
@@ -175,7 +177,7 @@ public final class WordDocument {
}
else
{
- String sText = new String(_header, start, end-start);
+ String sText = new String(_header, start, end-start, "windows-1252");
out.write(sText);
}
}
@@ -758,7 +760,7 @@ public final class WordDocument {
size = lineHeights.size();
for(int x = 0; x < size; x++)
{
- Integer height = (Integer)lineHeights.get(x);
+ Integer height = lineHeights.get(x);
sum += height.intValue();
}
@@ -1765,7 +1767,7 @@ public final class WordDocument {
for(int x = 0; x < size; x++)
{
StringBuffer rowBuffer = tableBodyBuffer;
- TableRow row = (TableRow)_table.get(x);
+ TableRow row = _table.get(x);
TAP tap = row.getTAP();
ArrayList<String> cells = row.getCells();
@@ -1797,7 +1799,7 @@ public final class WordDocument {
addBorder(rowBuffer, tc._brcBottom, "bottom");
addBorder(rowBuffer, tc._brcRight, "right");
rowBuffer.append(">");
- rowBuffer.append((String)cells.get(y));
+ rowBuffer.append(cells.get(y));
rowBuffer.append("</fo:table-cell>");
}
rowBuffer.append("</fo:table-row>");
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdf/model/util/BTreeSet.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdf/model/util/BTreeSet.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdf/model/util/BTreeSet.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdf/model/util/BTreeSet.java Sun Jul 19 19:00:32 2015
@@ -36,14 +36,14 @@ import org.apache.poi.hdf.model.hdftypes
*
*/
@Deprecated
-public final class BTreeSet extends AbstractSet
+public final class BTreeSet extends AbstractSet<PropertyNode>
{
/*
* Instance Variables
*/
public BTreeNode root;
- private Comparator comparator = null;
+ private Comparator<PropertyNode> comparator = null;
private int order;
int size = 0;
@@ -59,7 +59,7 @@ public final class BTreeSet extends Abst
this(6); // Default order for a BTreeSet is 32
}
- public BTreeSet(Collection c)
+ public BTreeSet(Collection<PropertyNode> c)
{
this(6); // Default order for a BTreeSet is 32
addAll(c);
@@ -70,7 +70,7 @@ public final class BTreeSet extends Abst
this(order, null);
}
- public BTreeSet(int order, Comparator comparator)
+ public BTreeSet(int order, Comparator<PropertyNode> comparator)
{
this.order = order;
this.comparator = comparator;
@@ -81,18 +81,18 @@ public final class BTreeSet extends Abst
/*
* Public Methods
*/
- public boolean add(Object x) throws IllegalArgumentException
+ public boolean add(PropertyNode x) throws IllegalArgumentException
{
if (x == null) throw new IllegalArgumentException();
return root.insert(x, -1);
}
- public boolean contains(Object x)
+ public boolean contains(PropertyNode x)
{
return root.includes(x);
}
- public boolean remove(Object x)
+ public boolean remove(PropertyNode x)
{
if (x == null) return false;
return root.delete(x, -1);
@@ -109,14 +109,14 @@ public final class BTreeSet extends Abst
size = 0;
}
- public java.util.Iterator iterator()
+ public java.util.Iterator<PropertyNode> iterator()
{
return new Iterator();
}
- public static ArrayList findProperties(int start, int end, BTreeSet.BTreeNode root)
+ public static List<PropertyNode> findProperties(int start, int end, BTreeSet.BTreeNode root)
{
- ArrayList results = new ArrayList();
+ List<PropertyNode> results = new ArrayList<PropertyNode>();
BTreeSet.Entry[] entries = root.entries;
for(int x = 0; x < entries.length; x++)
@@ -124,7 +124,7 @@ public final class BTreeSet extends Abst
if(entries[x] != null)
{
BTreeSet.BTreeNode child = entries[x].child;
- PropertyNode xNode = (PropertyNode)entries[x].element;
+ PropertyNode xNode = entries[x].element;
if(xNode != null)
{
int xStart = xNode.getStart();
@@ -135,7 +135,7 @@ public final class BTreeSet extends Abst
{
if(child != null)
{
- ArrayList beforeItems = findProperties(start, end, child);
+ List<PropertyNode> beforeItems = findProperties(start, end, child);
results.addAll(beforeItems);
}
results.add(xNode);
@@ -150,7 +150,7 @@ public final class BTreeSet extends Abst
{
if(child != null)
{
- ArrayList beforeItems = findProperties(start, end, child);
+ List<PropertyNode> beforeItems = findProperties(start, end, child);
results.addAll(beforeItems);
}
break;
@@ -158,7 +158,7 @@ public final class BTreeSet extends Abst
}
else if(child != null)
{
- ArrayList afterItems = findProperties(start, end, child);
+ List<PropertyNode> afterItems = findProperties(start, end, child);
results.addAll(afterItems);
}
}
@@ -172,9 +172,9 @@ public final class BTreeSet extends Abst
/*
* Private methods
*/
- int compare(Object x, Object y)
+ int compare(PropertyNode x, PropertyNode y)
{
- return (comparator == null ? ((Comparable)x).compareTo(y) : comparator.compare(x, y));
+ return (comparator == null ? x.compareTo(y) : comparator.compare(x, y));
}
@@ -192,12 +192,12 @@ public final class BTreeSet extends Abst
* chance of receiving a NullPointerException. The Iterator.delete method is supported.
*/
- private class Iterator implements java.util.Iterator
+ private class Iterator implements java.util.Iterator<PropertyNode>
{
private int index = 0;
- private Stack parentIndex = new Stack(); // Contains all parentIndicies for currentNode
- private Object lastReturned = null;
- private Object next;
+ private Stack<Integer> parentIndex = new Stack<Integer>(); // Contains all parentIndicies for currentNode
+ private PropertyNode lastReturned = null;
+ private PropertyNode next;
private BTreeNode currentNode;
Iterator()
@@ -211,7 +211,7 @@ public final class BTreeSet extends Abst
return next != null;
}
- public Object next()
+ public PropertyNode next()
{
if (next == null) throw new NoSuchElementException();
@@ -241,7 +241,7 @@ public final class BTreeSet extends Abst
return temp;
}
- private Object nextElement()
+ private PropertyNode nextElement()
{
if (currentNode.isLeaf())
{
@@ -250,13 +250,13 @@ public final class BTreeSet extends Abst
else if (!parentIndex.empty())
{ //All elements have been returned, return successor of lastReturned if it exists
currentNode = currentNode.parent;
- index = ((Integer)parentIndex.pop()).intValue();
+ index = parentIndex.pop().intValue();
while (index == currentNode.nrElements)
{
if (parentIndex.empty()) break;
currentNode = currentNode.parent;
- index = ((Integer)parentIndex.pop()).intValue();
+ index = parentIndex.pop().intValue();
}
if (index == currentNode.nrElements) return null; //Reached root and he has no more children
@@ -289,7 +289,7 @@ public final class BTreeSet extends Abst
public static class Entry
{
- public Object element;
+ public PropertyNode element;
public BTreeNode child;
}
@@ -309,11 +309,11 @@ public final class BTreeSet extends Abst
entries[0] = new Entry();
}
- boolean insert(Object x, int parentIndex)
+ boolean insert(PropertyNode x, int parentIndex)
{
if (isFull())
{ // If full, you must split and promote splitNode before inserting
- Object splitNode = entries[nrElements / 2].element;
+ PropertyNode splitNode = entries[nrElements / 2].element;
BTreeNode rightSibling = split();
if (isRoot())
@@ -354,7 +354,7 @@ public final class BTreeSet extends Abst
return false;
}
- boolean includes(Object x)
+ boolean includes(PropertyNode x)
{
int index = childToInsertAt(x, true);
if (index == -1) return true;
@@ -362,7 +362,7 @@ public final class BTreeSet extends Abst
return entries[index].child.includes(x);
}
- boolean delete(Object x, int parentIndex)
+ boolean delete(PropertyNode x, int parentIndex)
{
int i = childToInsertAt(x, true);
int priorParentIndex = parentIndex;
@@ -438,7 +438,7 @@ public final class BTreeSet extends Abst
* Creates a new BTreeSet.root which contains only the splitNode and pointers
* to it's left and right child.
*/
- private void splitRoot(Object splitNode, BTreeNode left, BTreeNode right)
+ private void splitRoot(PropertyNode splitNode, BTreeNode left, BTreeNode right)
{
BTreeNode newRoot = new BTreeNode(null);
newRoot.entries[0].element = splitNode;
@@ -450,7 +450,7 @@ public final class BTreeSet extends Abst
BTreeSet.this.root = newRoot;
}
- private void insertSplitNode(Object splitNode, BTreeNode left, BTreeNode right, int insertAt)
+ private void insertSplitNode(PropertyNode splitNode, BTreeNode left, BTreeNode right, int insertAt)
{
for (int i = nrElements; i >= insertAt; i--) entries[i + 1] = entries[i];
@@ -462,7 +462,7 @@ public final class BTreeSet extends Abst
nrElements++;
}
- private void insertNewElement(Object x, int insertAt)
+ private void insertNewElement(PropertyNode x, int insertAt)
{
for (int i = nrElements; i > insertAt; i--) entries[i] = entries[i - 1];
@@ -482,7 +482,7 @@ public final class BTreeSet extends Abst
* element is contained in the calling BTreeNode than the position of the element
* in entries[] is returned.
*/
- private int childToInsertAt(Object x, boolean position)
+ private int childToInsertAt(PropertyNode x, boolean position)
{
int index = nrElements / 2;
@@ -509,7 +509,7 @@ public final class BTreeSet extends Abst
}
- private void deleteElement(Object x)
+ private void deleteElement(PropertyNode x)
{
int index = childToInsertAt(x, false);
for (; index < (nrElements - 1); index++) entries[index] = entries[index + 1];
@@ -568,12 +568,12 @@ public final class BTreeSet extends Abst
}
}
- private void switchWithSuccessor(Object x)
+ private void switchWithSuccessor(PropertyNode x)
{
int index = childToInsertAt(x, false);
BTreeNode temp = entries[index + 1].child;
while (temp.entries[0] != null && temp.entries[0].child != null) temp = temp.entries[0].child;
- Object successor = temp.entries[0].element;
+ PropertyNode successor = temp.entries[0].element;
temp.entries[0].element = entries[index].element;
entries[index].element = successor;
}
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdgf/dev/VSDDumper.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdgf/dev/VSDDumper.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdgf/dev/VSDDumper.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdgf/dev/VSDDumper.java Sun Jul 19 19:00:32 2015
@@ -17,7 +17,7 @@
package org.apache.poi.hdgf.dev;
-import java.io.FileInputStream;
+import java.io.File;
import org.apache.poi.hdgf.HDGFDiagram;
import org.apache.poi.hdgf.chunks.Chunk;
@@ -26,7 +26,7 @@ import org.apache.poi.hdgf.pointers.Poin
import org.apache.poi.hdgf.streams.ChunkStream;
import org.apache.poi.hdgf.streams.PointerContainingStream;
import org.apache.poi.hdgf.streams.Stream;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
/**
* Developer helper class to dump out the pointer+stream structure
@@ -41,7 +41,7 @@ public final class VSDDumper {
}
HDGFDiagram hdgf = new HDGFDiagram(
- new POIFSFileSystem(new FileInputStream(args[0]))
+ new NPOIFSFileSystem(new File(args[0]))
);
System.out.println("Opened " + args[0]);
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hdgf/extractor/VisioTextExtractor.java Sun Jul 19 19:00:32 2015
@@ -62,7 +62,7 @@ public final class VisioTextExtractor ex
this(new HDGFDiagram(dir, fs));
}
public VisioTextExtractor(InputStream inp) throws IOException {
- this(new POIFSFileSystem(inp));
+ this(new NPOIFSFileSystem(inp));
}
/**
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hmef/extractor/HMEFContentsExtractor.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hmef/extractor/HMEFContentsExtractor.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hmef/extractor/HMEFContentsExtractor.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hmef/extractor/HMEFContentsExtractor.java Sun Jul 19 19:00:32 2015
@@ -22,6 +22,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
import org.apache.poi.hmef.Attachment;
import org.apache.poi.hmef.HMEFMessage;
@@ -70,13 +71,14 @@ public final class HMEFContentsExtractor
* Extracts the RTF message body to the supplied file
*/
public void extractMessageBody(File dest) throws IOException {
- FileOutputStream fout = new FileOutputStream(dest);
-
- MAPIRtfAttribute body = (MAPIRtfAttribute)
- message.getMessageMAPIAttribute(MAPIProperty.RTF_COMPRESSED);
- fout.write(body.getData());
-
- fout.close();
+ OutputStream fout = new FileOutputStream(dest);
+ try {
+ MAPIRtfAttribute body = (MAPIRtfAttribute)
+ message.getMessageMAPIAttribute(MAPIProperty.RTF_COMPRESSED);
+ fout.write(body.getData());
+ } finally {
+ fout.close();
+ }
}
/**
@@ -101,9 +103,12 @@ public final class HMEFContentsExtractor
// Save it
File file = new File(dir, filename);
- FileOutputStream fout = new FileOutputStream(file);
- fout.write( att.getContents() );
- fout.close();
+ OutputStream fout = new FileOutputStream(file);
+ try {
+ fout.write( att.getContents() );
+ } finally {
+ fout.close();
+ }
}
}
}
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hpbf/HPBFDocument.java Sun Jul 19 19:00:32 2015
@@ -51,21 +51,12 @@ public final class HPBFDocument extends
this(fs.getRoot());
}
public HPBFDocument(InputStream inp) throws IOException {
- this(new POIFSFileSystem(inp));
+ this(new NPOIFSFileSystem(inp));
}
/**
* Opens an embedded publisher document,
* at the given directory.
- * @deprecated Use {@link #HPBFDocument(DirectoryNode)} instead
- */
- @Deprecated
- public HPBFDocument(DirectoryNode dir, POIFSFileSystem fs) throws IOException {
- this(dir);
- }
- /**
- * Opens an embedded publisher document,
- * at the given directory.
*/
public HPBFDocument(DirectoryNode dir) throws IOException {
super(dir);
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hpbf/dev/HPBFDumper.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hpbf/dev/HPBFDumper.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hpbf/dev/HPBFDumper.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hpbf/dev/HPBFDumper.java Sun Jul 19 19:00:32 2015
@@ -25,7 +25,7 @@ import org.apache.poi.ddf.DefaultEscherR
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.DocumentEntry;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil;
@@ -35,12 +35,12 @@ import org.apache.poi.util.StringUtil;
* constructed.
*/
public final class HPBFDumper {
- private POIFSFileSystem fs;
- public HPBFDumper(POIFSFileSystem fs) {
+ private NPOIFSFileSystem fs;
+ public HPBFDumper(NPOIFSFileSystem fs) {
this.fs = fs;
}
public HPBFDumper(InputStream inp) throws IOException {
- this(new POIFSFileSystem(inp));
+ this(new NPOIFSFileSystem(inp));
}
private static byte[] getData(DirectoryNode dir, String name) throws IOException {
Modified: poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hpbf/dev/PLCDumper.java
URL: http://svn.apache.org/viewvc/poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hpbf/dev/PLCDumper.java?rev=1691843&r1=1691842&r2=1691843&view=diff
==============================================================================
--- poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hpbf/dev/PLCDumper.java (original)
+++ poi/branches/common_sl/src/scratchpad/src/org/apache/poi/hpbf/dev/PLCDumper.java Sun Jul 19 19:00:32 2015
@@ -24,7 +24,7 @@ import java.io.InputStream;
import org.apache.poi.hpbf.HPBFDocument;
import org.apache.poi.hpbf.model.QuillContents;
import org.apache.poi.hpbf.model.qcbits.QCBit;
-import org.apache.poi.poifs.filesystem.POIFSFileSystem;
+import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
import org.apache.poi.util.HexDump;
/**
@@ -40,11 +40,11 @@ public final class PLCDumper {
doc = hpbfDoc;
qc = doc.getQuillContents();
}
- public PLCDumper(POIFSFileSystem fs) throws IOException {
+ public PLCDumper(NPOIFSFileSystem fs) throws IOException {
this(new HPBFDocument(fs));
}
public PLCDumper(InputStream inp) throws IOException {
- this(new POIFSFileSystem(inp));
+ this(new NPOIFSFileSystem(inp));
}
public static void main(String[] args) throws Exception {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org