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

(-)a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java (-3 / +3 lines)
Lines 98-104 public class XWPFDocument extends POIXMLDocument { Link Here
98
98
99
            // Get any tables
99
            // Get any tables
100
            for(CTTbl table : body.getTblArray()) {
100
            for(CTTbl table : body.getTblArray()) {
101
                tables.add(new XWPFTable(table));
101
                tables.add(new XWPFTable(this, table));
102
            }
102
            }
103
103
104
            // Sort out headers and footers
104
            // Sort out headers and footers
Lines 337-343 public class XWPFDocument extends POIXMLDocument { Link Here
337
     * @return a new table
337
     * @return a new table
338
     */
338
     */
339
    public XWPFTable createTable(){
339
    public XWPFTable createTable(){
340
        return new XWPFTable(ctDocument.getBody().addNewTbl());
340
        return new XWPFTable(this, ctDocument.getBody().addNewTbl());
341
    }
341
    }
342
    
342
    
343
    /**
343
    /**
Lines 347-353 public class XWPFDocument extends POIXMLDocument { Link Here
347
     * @return table
347
     * @return table
348
     */
348
     */
349
    public XWPFTable createTable(int rows, int cols) {
349
    public XWPFTable createTable(int rows, int cols) {
350
	return new XWPFTable(ctDocument.getBody().addNewTbl(), rows, cols);
350
	return new XWPFTable(this, ctDocument.getBody().addNewTbl(), rows, cols);
351
    }
351
    }
352
}
352
}
353
353
(-)a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java (-1 / +1 lines)
Lines 64-70 public abstract class XWPFHeaderFooter { Link Here
64
		XWPFTable[] tables = 
64
		XWPFTable[] tables = 
65
			new XWPFTable[headerFooter.getTblArray().length];
65
			new XWPFTable[headerFooter.getTblArray().length];
66
		for(int i=0; i<tables.length; i++) {
66
		for(int i=0; i<tables.length; i++) {
67
			tables[i] = new XWPFTable(
67
			tables[i] = new XWPFTable(null, 
68
					headerFooter.getTblArray(i)
68
					headerFooter.getTblArray(i)
69
			);
69
			);
70
		}
70
		}
(-)a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTable.java (-4 / +4 lines)
Lines 42-49 public class XWPFTable { Link Here
42
    private CTTbl ctTbl;
42
    private CTTbl ctTbl;
43
43
44
44
45
    public XWPFTable(CTTbl table, int row, int col) {
45
    public XWPFTable(XWPFDocument doc, CTTbl table, int row, int col) {
46
        this(table);
46
        this(doc, table);
47
        for (int i = 0; i < row; i++) {
47
        for (int i = 0; i < row; i++) {
48
            XWPFTableRow tabRow = (getRow(i) == null) ? createRow() : getRow(i);
48
            XWPFTableRow tabRow = (getRow(i) == null) ? createRow() : getRow(i);
49
            for (int k = 0; k < col; k++) {
49
            for (int k = 0; k < col; k++) {
Lines 54-60 public class XWPFTable { Link Here
54
    }
54
    }
55
55
56
56
57
    public XWPFTable(CTTbl table) {
57
    public XWPFTable(XWPFDocument doc, CTTbl table) {
58
        this.ctTbl = table;
58
        this.ctTbl = table;
59
59
60
        // is an empty table: I add one row and one column as default
60
        // is an empty table: I add one row and one column as default
Lines 65-71 public class XWPFTable { Link Here
65
            StringBuffer rowText = new StringBuffer();
65
            StringBuffer rowText = new StringBuffer();
66
            for (CTTc cell : row.getTcArray()) {
66
            for (CTTc cell : row.getTcArray()) {
67
                for (CTP ctp : cell.getPArray()) {
67
                for (CTP ctp : cell.getPArray()) {
68
                    XWPFParagraph p = new XWPFParagraph(ctp, null);
68
                    XWPFParagraph p = new XWPFParagraph(ctp, doc);
69
                    if (rowText.length() > 0) {
69
                    if (rowText.length() > 0) {
70
                        rowText.append('\t');
70
                        rowText.append('\t');
71
                    }
71
                    }
(-)a/src/ooxml/testcases/org/apache/poi/xwpf/extractor/TestXWPFWordExtractor.java (+21 lines)
Lines 60-65 public class TestXWPFWordExtractor extends TestCase { Link Here
60
        private XWPFDocument xmlFootnotes;
60
        private XWPFDocument xmlFootnotes;
61
        private File fileFootnotes;
61
        private File fileFootnotes;
62
62
63
        /**
64
         * File with footnote in table
65
        */
66
        private XWPFDocument xmlFootnotes2;
67
        private File fileFootnotes2;
68
63
	protected void setUp() throws Exception {
69
	protected void setUp() throws Exception {
64
		super.setUp();
70
		super.setUp();
65
		
71
		
Lines 87-92 public class TestXWPFWordExtractor extends TestCase { Link Here
87
                                System.getProperty("HWPF.testdata.path") +
93
                                System.getProperty("HWPF.testdata.path") +
88
                                File.separator + "snoska.docx"
94
                                File.separator + "snoska.docx"
89
                );
95
                );
96
                fileFootnotes2 = new File(
97
                                System.getProperty("HWPF.testdata.path") +
98
                                File.separator + "Table.docx"
99
                );
90
100
91
		assertTrue(fileA.exists());
101
		assertTrue(fileA.exists());
92
		assertTrue(fileB.exists());
102
		assertTrue(fileB.exists());
Lines 94-99 public class TestXWPFWordExtractor extends TestCase { Link Here
94
		assertTrue(fileD.exists());
104
		assertTrue(fileD.exists());
95
		assertTrue(fileE.exists());
105
		assertTrue(fileE.exists());
96
                assertTrue(fileFootnotes.exists());
106
                assertTrue(fileFootnotes.exists());
107
                assertTrue(fileFootnotes2.exists());
97
108
98
		xmlA = new XWPFDocument(POIXMLDocument.openPackage(fileA.toString()));
109
		xmlA = new XWPFDocument(POIXMLDocument.openPackage(fileA.toString()));
99
		xmlB = new XWPFDocument(POIXMLDocument.openPackage(fileB.toString()));
110
		xmlB = new XWPFDocument(POIXMLDocument.openPackage(fileB.toString()));
Lines 101-106 public class TestXWPFWordExtractor extends TestCase { Link Here
101
		xmlD = new XWPFDocument(POIXMLDocument.openPackage(fileD.toString()));
112
		xmlD = new XWPFDocument(POIXMLDocument.openPackage(fileD.toString()));
102
		xmlE = new XWPFDocument(POIXMLDocument.openPackage(fileE.toString()));
113
		xmlE = new XWPFDocument(POIXMLDocument.openPackage(fileE.toString()));
103
                xmlFootnotes = new XWPFDocument(POIXMLDocument.openPackage(fileFootnotes.toString()));
114
                xmlFootnotes = new XWPFDocument(POIXMLDocument.openPackage(fileFootnotes.toString()));
115
                xmlFootnotes2 = new XWPFDocument(POIXMLDocument.openPackage(fileFootnotes2.toString()));
104
	}
116
	}
105
117
106
	/**
118
	/**
Lines 246-249 public class TestXWPFWordExtractor extends TestCase { Link Here
246
258
247
                assertTrue(extractor.getText().contains("snoska"));
259
                assertTrue(extractor.getText().contains("snoska"));
248
        }
260
        }
261
262
        public void testFootnotes2() throws Exception {
263
                XWPFWordExtractor extractor =
264
                        new XWPFWordExtractor(xmlFootnotes2);
265
                extractor.getText();
266
267
                assertTrue(extractor.getText().contains("snoska"));
268
        }
269
249
}
270
}
(-)a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTable.java (-6 / +6 lines)
Lines 43-56 public class TestXWPFTable extends TestCase { Link Here
43
43
44
    public void testConstructor() {
44
    public void testConstructor() {
45
	CTTbl ctTable=CTTbl.Factory.newInstance();
45
	CTTbl ctTable=CTTbl.Factory.newInstance();
46
	XWPFTable xtab=new XWPFTable(ctTable);
46
	XWPFTable xtab=new XWPFTable(null, ctTable);
47
	assertNotNull(xtab);
47
	assertNotNull(xtab);
48
	assertEquals(1,ctTable.sizeOfTrArray());
48
	assertEquals(1,ctTable.sizeOfTrArray());
49
	assertEquals(1,ctTable.getTrArray(0).sizeOfTcArray());
49
	assertEquals(1,ctTable.getTrArray(0).sizeOfTcArray());
50
	assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
50
	assertNotNull(ctTable.getTrArray(0).getTcArray(0).getPArray(0));
51
	
51
	
52
	ctTable=CTTbl.Factory.newInstance();
52
	ctTable=CTTbl.Factory.newInstance();
53
	xtab=new XWPFTable(ctTable, 3,2);
53
	xtab=new XWPFTable(null, ctTable, 3,2);
54
	assertNotNull(xtab);
54
	assertNotNull(xtab);
55
	assertEquals(3,ctTable.sizeOfTrArray());
55
	assertEquals(3,ctTable.sizeOfTrArray());
56
	assertEquals(2,ctTable.getTrArray(0).sizeOfTcArray());
56
	assertEquals(2,ctTable.getTrArray(0).sizeOfTcArray());
Lines 67-73 public class TestXWPFTable extends TestCase { Link Here
67
	CTText text=run.addNewT();
67
	CTText text=run.addNewT();
68
	text.setStringValue("finally I can write!");
68
	text.setStringValue("finally I can write!");
69
	
69
	
70
	XWPFTable xtab=new XWPFTable(table);
70
	XWPFTable xtab=new XWPFTable(null, table);
71
    	assertEquals("finally I can write!\n",xtab.getText());
71
    	assertEquals("finally I can write!\n",xtab.getText());
72
    }
72
    }
73
    
73
    
Lines 84-90 public class TestXWPFTable extends TestCase { Link Here
84
	r3.addNewTc().addNewP();
84
	r3.addNewTc().addNewP();
85
	r3.addNewTc().addNewP();
85
	r3.addNewTc().addNewP();
86
	
86
	
87
	XWPFTable xtab=new XWPFTable(table);
87
	XWPFTable xtab=new XWPFTable(null, table);
88
    	assertEquals(3,xtab.getNumberOfRows());
88
    	assertEquals(3,xtab.getNumberOfRows());
89
    	assertNotNull(xtab.getRow(2));
89
    	assertNotNull(xtab.getRow(2));
90
    	
90
    	
Lines 95-101 public class TestXWPFTable extends TestCase { Link Here
95
    	assertEquals(2,table.getTrArray(0).sizeOfTcArray());
95
    	assertEquals(2,table.getTrArray(0).sizeOfTcArray());
96
    	    	
96
    	    	
97
    	//check creation of first row
97
    	//check creation of first row
98
	xtab=new XWPFTable(CTTbl.Factory.newInstance());
98
	xtab=new XWPFTable(null, CTTbl.Factory.newInstance());
99
    	assertEquals(1,xtab.getCTTbl().getTrArray(0).sizeOfTcArray());
99
    	assertEquals(1,xtab.getCTTbl().getTrArray(0).sizeOfTcArray());
100
    }
100
    }
101
    
101
    
Lines 104-110 public class TestXWPFTable extends TestCase { Link Here
104
	CTTbl table = CTTbl.Factory.newInstance();
104
	CTTbl table = CTTbl.Factory.newInstance();
105
	table.addNewTblPr().addNewTblW().setW(new BigInteger("1000"));
105
	table.addNewTblPr().addNewTblW().setW(new BigInteger("1000"));
106
	
106
	
107
	XWPFTable xtab=new XWPFTable(table);
107
	XWPFTable xtab=new XWPFTable(null, table);
108
	
108
	
109
	assertEquals(1000,xtab.getWidth());
109
	assertEquals(1000,xtab.getWidth());
110
	
110
	

Return to bug 45556