From 14e3827e8c206bd061a6286d0a49776fed4f58a6 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sat, 12 Mar 2016 11:45:34 +0000 Subject: [PATCH] Apply patch to fix bug 57495: getTableArray method can not get 0 pos table git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1734694 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/util/Units.java | 11 +- .../poi/xwpf/usermodel/XWPFDocument.java | 12 +- .../poi/xwpf/usermodel/XWPFFootnote.java | 190 +++++++++--------- .../poi/xwpf/usermodel/XWPFHeaderFooter.java | 9 +- .../poi/xwpf/usermodel/XWPFTableCell.java | 190 +++++++++--------- .../poi/xwpf/usermodel/TestXWPFBugs.java | 36 +++- 6 files changed, 252 insertions(+), 196 deletions(-) diff --git a/src/java/org/apache/poi/util/Units.java b/src/java/org/apache/poi/util/Units.java index 55b6d40f0c..496ca132d3 100644 --- a/src/java/org/apache/poi/util/Units.java +++ b/src/java/org/apache/poi/util/Units.java @@ -48,11 +48,20 @@ public class Units { /** * Converts points to EMUs * @param points points - * @return emus + * @return EMUs */ public static int toEMU(double points){ return (int)Math.rint(EMU_PER_POINT*points); } + + /** + * Converts pixels to EMUs + * @param pixels pixels + * @return EMUs + */ + public static int pixelToEMU(int pixels) { + return pixels*EMU_PER_PIXEL; + } /** * Converts EMUs to points diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java index 82f545c031..e5dd3056c6 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java @@ -335,7 +335,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { */ @Override public XWPFTable getTableArray(int pos) { - if (pos > 0 && pos < tables.size()) { + if (pos >= 0 && pos < tables.size()) { return tables.get(pos); } return null; @@ -349,7 +349,10 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { } public XWPFFooter getFooterArray(int pos) { - return footers.get(pos); + if(pos >=0 && pos < footers.size()) { + return footers.get(pos); + } + return null; } /** @@ -360,7 +363,10 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody { } public XWPFHeader getHeaderArray(int pos) { - return headers.get(pos); + if(pos >=0 && pos < headers.size()) { + return headers.get(pos); + } + return null; } public String getTblStyle(XWPFTable table) { diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java index 741bd4486c..a2f14a7e76 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFFootnote.java @@ -1,32 +1,33 @@ -/* ==================================================================== - 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. -==================================================================== */ -package org.apache.poi.xwpf.usermodel; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.apache.poi.POIXMLDocumentPart; -import org.apache.xmlbeans.XmlCursor; -import org.apache.xmlbeans.XmlObject; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock; +/* ==================================================================== +/* ==================================================================== + 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. +==================================================================== */ +package org.apache.poi.xwpf.usermodel; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.poi.POIXMLDocumentPart; +import org.apache.xmlbeans.XmlCursor; +import org.apache.xmlbeans.XmlObject; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTFtnEdn; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTc; @@ -36,8 +37,8 @@ public class XWPFFootnote implements Iterable, IBody { private List pictures = new ArrayList(); private List bodyElements = new ArrayList(); - private CTFtnEdn ctFtnEdn; - private XWPFFootnotes footnotes; + private CTFtnEdn ctFtnEdn; + private XWPFFootnotes footnotes; private XWPFDocument document; public XWPFFootnote(CTFtnEdn note, XWPFFootnotes xFootnotes) { @@ -85,16 +86,16 @@ public class XWPFFootnote implements Iterable, IBody { return paragraphs.iterator(); } - public List getTables() { - return tables; - } - - public List getPictures() { - return pictures; - } - - public List getBodyElements() { - return bodyElements; + public List getTables() { + return tables; + } + + public List getPictures() { + return pictures; + } + + public List getBodyElements() { + return bodyElements; } public CTFtnEdn getCTFtnEdn() { @@ -106,16 +107,16 @@ public class XWPFFootnote implements Iterable, IBody { } /** - * @param pos in table array - * @return The table at position pos + * @param pos in table array + * @return The table at position pos * @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int) */ public XWPFTable getTableArray(int pos) { - if (pos > 0 && pos < tables.size()) { + if (pos >= 0 && pos < tables.size()) { return tables.get(pos); } return null; - } + } /** * inserts an existing XWPFTable to the arrays bodyElements and tables @@ -123,8 +124,8 @@ public class XWPFFootnote implements Iterable, IBody { * @param pos * @param table * @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int pos, XWPFTable table) - */ - public void insertTable(int pos, XWPFTable table) { + */ + public void insertTable(int pos, XWPFTable table) { bodyElements.add(pos, table); int i = 0; for (CTTbl tbl : ctFtnEdn.getTblArray()) { @@ -132,11 +133,11 @@ public class XWPFFootnote implements Iterable, IBody { break; } i++; - } - tables.add(i, table); - - } - + } + tables.add(i, table); + + } + /** * if there is a corresponding {@link XWPFTable} of the parameter ctTable in the tableList of this header * the method will return this table @@ -153,8 +154,8 @@ public class XWPFFootnote implements Iterable, IBody { return table; } return null; - } - + } + /** * if there is a corresponding {@link XWPFParagraph} of the parameter ctTable in the paragraphList of this header or footer * the method will return this paragraph @@ -171,7 +172,7 @@ public class XWPFFootnote implements Iterable, IBody { return paragraph; } return null; - } + } /** * Returns the paragraph that holds @@ -180,9 +181,11 @@ public class XWPFFootnote implements Iterable, IBody { * @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int pos) */ public XWPFParagraph getParagraphArray(int pos) { - - return paragraphs.get(pos); - } + if(pos >=0 && pos < paragraphs.size()) { + return paragraphs.get(pos); + } + return null; + } /** * get the TableCell which belongs to the TableCell @@ -190,7 +193,7 @@ public class XWPFFootnote implements Iterable, IBody { * @param cell * @see org.apache.poi.xwpf.usermodel.IBody#getTableCell(CTTc cell) */ - public XWPFTableCell getTableCell(CTTc cell) { + public XWPFTableCell getTableCell(CTTc cell) { XmlCursor cursor = cell.newCursor(); cursor.toParent(); XmlObject o = cursor.getObject(); @@ -210,8 +213,11 @@ public class XWPFFootnote implements Iterable, IBody { return null; } XWPFTableRow tableRow = table.getRow(row); + if(tableRow == null){ + return null; + } return tableRow.getTableCell(cell); - } + } /** * verifies that cursor is on the right position @@ -263,12 +269,12 @@ public class XWPFFootnote implements Iterable, IBody { i++; } bodyElements.add(i, newT); - cursor = t.newCursor(); - cursor.toEndToken(); - return newT; - } - return null; - } + cursor = t.newCursor(); + cursor.toEndToken(); + return newT; + } + return null; + } /** * add a new paragraph at position of the cursor @@ -303,12 +309,12 @@ public class XWPFFootnote implements Iterable, IBody { i++; } bodyElements.add(i, newP); - cursor.toCursor(p.newCursor()); - cursor.toEndToken(); - return newP; - } - return null; - } + cursor.toCursor(p.newCursor()); + cursor.toEndToken(); + return newP; + } + return null; + } /** * add a new table to the end of the footnote @@ -316,13 +322,13 @@ public class XWPFFootnote implements Iterable, IBody { * @param table * @return the added XWPFTable */ - public XWPFTable addNewTbl(CTTbl table) { - CTTbl newTable = ctFtnEdn.addNewTbl(); - newTable.set(table); - XWPFTable xTable = new XWPFTable(newTable, this); - tables.add(xTable); - return xTable; - } + public XWPFTable addNewTbl(CTTbl table) { + CTTbl newTable = ctFtnEdn.addNewTbl(); + newTable.set(table); + XWPFTable xTable = new XWPFTable(newTable, this); + tables.add(xTable); + return xTable; + } /** * add a new paragraph to the end of the footnote @@ -330,14 +336,14 @@ public class XWPFFootnote implements Iterable, IBody { * @param paragraph * @return the added XWPFParagraph */ - public XWPFParagraph addNewParagraph(CTP paragraph) { - CTP newPara = ctFtnEdn.addNewP(); - newPara.set(paragraph); - XWPFParagraph xPara = new XWPFParagraph(newPara, this); - paragraphs.add(xPara); - return xPara; - } - + public XWPFParagraph addNewParagraph(CTP paragraph) { + CTP newPara = ctFtnEdn.addNewP(); + newPara.set(paragraph); + XWPFParagraph xPara = new XWPFParagraph(newPara, this); + paragraphs.add(xPara); + return xPara; + } + /** * @see org.apache.poi.xwpf.usermodel.IBody#getXWPFDocument() */ @@ -351,8 +357,8 @@ public class XWPFFootnote implements Iterable, IBody { * @see org.apache.poi.xwpf.usermodel.IBody#getPart() */ public POIXMLDocumentPart getPart() { - return footnotes; - } + return footnotes; + } /** * get the PartType of the body @@ -360,6 +366,6 @@ public class XWPFFootnote implements Iterable, IBody { * @see org.apache.poi.xwpf.usermodel.IBody#getPartType() */ public BodyType getPartType() { - return BodyType.FOOTNOTE; - } -} + return BodyType.FOOTNOTE; + } +} diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java index 068a35c02d..415204aace 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFHeaderFooter.java @@ -212,8 +212,10 @@ public abstract class XWPFHeaderFooter extends POIXMLDocumentPart implements IBo * the text of the header or footer. */ public XWPFParagraph getParagraphArray(int pos) { - - return paragraphs.get(pos); + if(pos >= 0 && pos 0 && pos < tables.size()) { + if (pos >= 0 && pos < tables.size()) { return tables.get(pos); } return null; diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java index dd011e3679..d074e79e01 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java @@ -1,42 +1,42 @@ -/* ==================================================================== - 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. -==================================================================== */ -package org.apache.poi.xwpf.usermodel; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.EnumMap; -import java.util.HashMap; -import java.util.List; - -import org.apache.poi.POIXMLDocumentPart; -import org.apache.poi.util.Internal; -import org.apache.xmlbeans.XmlCursor; -import org.apache.xmlbeans.XmlObject; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtRun; -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.CTTcPr; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalJc; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.STShd; -import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc; +/* ==================================================================== + 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. +==================================================================== */ +package org.apache.poi.xwpf.usermodel; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.List; + +import org.apache.poi.POIXMLDocumentPart; +import org.apache.poi.util.Internal; +import org.apache.xmlbeans.XmlCursor; +import org.apache.xmlbeans.XmlObject; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtBlock; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSdtRun; +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.CTTcPr; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTVerticalJc; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.STShd; +import org.openxmlformats.schemas.wordprocessingml.x2006.main.STVerticalJc; /** * Represents a Cell within a {@link XWPFTable}. The @@ -46,20 +46,20 @@ public class XWPFTableCell implements IBody, ICell { private static EnumMap alignMap; // Create a map from the STVerticalJc.Enum values to the XWPF-level enums private static HashMap stVertAlignTypeMap; - - static { - // populate enum maps - alignMap = new EnumMap(XWPFVertAlign.class); - alignMap.put(XWPFVertAlign.TOP, STVerticalJc.Enum.forInt(STVerticalJc.INT_TOP)); - alignMap.put(XWPFVertAlign.CENTER, STVerticalJc.Enum.forInt(STVerticalJc.INT_CENTER)); - alignMap.put(XWPFVertAlign.BOTH, STVerticalJc.Enum.forInt(STVerticalJc.INT_BOTH)); - alignMap.put(XWPFVertAlign.BOTTOM, STVerticalJc.Enum.forInt(STVerticalJc.INT_BOTTOM)); - - stVertAlignTypeMap = new HashMap(); - stVertAlignTypeMap.put(STVerticalJc.INT_TOP, XWPFVertAlign.TOP); - stVertAlignTypeMap.put(STVerticalJc.INT_CENTER, XWPFVertAlign.CENTER); - stVertAlignTypeMap.put(STVerticalJc.INT_BOTH, XWPFVertAlign.BOTH); - stVertAlignTypeMap.put(STVerticalJc.INT_BOTTOM, XWPFVertAlign.BOTTOM); + + static { + // populate enum maps + alignMap = new EnumMap(XWPFVertAlign.class); + alignMap.put(XWPFVertAlign.TOP, STVerticalJc.Enum.forInt(STVerticalJc.INT_TOP)); + alignMap.put(XWPFVertAlign.CENTER, STVerticalJc.Enum.forInt(STVerticalJc.INT_CENTER)); + alignMap.put(XWPFVertAlign.BOTH, STVerticalJc.Enum.forInt(STVerticalJc.INT_BOTH)); + alignMap.put(XWPFVertAlign.BOTTOM, STVerticalJc.Enum.forInt(STVerticalJc.INT_BOTTOM)); + + stVertAlignTypeMap = new HashMap(); + stVertAlignTypeMap.put(STVerticalJc.INT_TOP, XWPFVertAlign.TOP); + stVertAlignTypeMap.put(STVerticalJc.INT_CENTER, XWPFVertAlign.CENTER); + stVertAlignTypeMap.put(STVerticalJc.INT_BOTH, XWPFVertAlign.BOTH); + stVertAlignTypeMap.put(STVerticalJc.INT_BOTTOM, XWPFVertAlign.BOTTOM); } @@ -75,8 +75,8 @@ public class XWPFTableCell implements IBody, ICell { /** * If a table cell does not include at least one block-level element, then this document shall be considered corrupt */ - public XWPFTableCell(CTTc cell, XWPFTableRow tableRow, IBody part) { - this.ctTc = cell; + public XWPFTableCell(CTTc cell, XWPFTableRow tableRow, IBody part) { + this.ctTc = cell; this.part = part; this.tableRow = tableRow; // NB: If a table cell does not include at least one block-level element, then this document shall be considered corrupt. @@ -84,10 +84,10 @@ public class XWPFTableCell implements IBody, ICell { cell.addNewP(); bodyElements = new ArrayList(); paragraphs = new ArrayList(); - tables = new ArrayList(); - - XmlCursor cursor = ctTc.newCursor(); - cursor.selectPath("./*"); + tables = new ArrayList(); + + XmlCursor cursor = ctTc.newCursor(); + cursor.selectPath("./*"); while (cursor.toNextSelection()) { XmlObject o = cursor.getObject(); if (o instanceof CTP) { @@ -116,7 +116,7 @@ public class XWPFTableCell implements IBody, ICell { @Internal public CTTc getCTTc() { return ctTc; - } + } /** * returns an Iterator with paragraphs and tables @@ -130,10 +130,10 @@ public class XWPFTableCell implements IBody, ICell { public void setParagraph(XWPFParagraph p) { if (ctTc.sizeOfPArray() == 0) { ctTc.addNewP(); - } - ctTc.setPArray(0, p.getCTP()); - } - + } + ctTc.setPArray(0, p.getCTP()); + } + /** * returns a list of paragraphs */ @@ -224,23 +224,23 @@ public class XWPFTableCell implements IBody, ICell { ctshd.setFill(rgbStr); } - /** - * Get the vertical alignment of the cell. - * - * @return the cell alignment enum value or null - * if no vertical alignment is set. - */ - public XWPFVertAlign getVerticalAlignment() { - XWPFVertAlign vAlign = null; - CTTcPr tcpr = ctTc.getTcPr(); - if (tcpr != null) { - CTVerticalJc va = tcpr.getVAlign(); - if (va != null && va.getVal() != null) { - vAlign = stVertAlignTypeMap.get(va.getVal().intValue()); - } - } - return vAlign; - } + /** + * Get the vertical alignment of the cell. + * + * @return the cell alignment enum value or null + * if no vertical alignment is set. + */ + public XWPFVertAlign getVerticalAlignment() { + XWPFVertAlign vAlign = null; + CTTcPr tcpr = ctTc.getTcPr(); + if (tcpr != null) { + CTVerticalJc va = tcpr.getVAlign(); + if (va != null && va.getVal() != null) { + vAlign = stVertAlignTypeMap.get(va.getVal().intValue()); + } + } + return vAlign; + } /** * Set the vertical alignment of the cell. @@ -343,7 +343,7 @@ public class XWPFTableCell implements IBody, ICell { * @see org.apache.poi.xwpf.usermodel.IBody#getParagraphArray(int) */ public XWPFParagraph getParagraphArray(int pos) { - if (pos > 0 && pos < paragraphs.size()) { + if (pos >= 0 && pos < paragraphs.size()) { return paragraphs.get(pos); } return null; @@ -381,7 +381,7 @@ public class XWPFTableCell implements IBody, ICell { * @see org.apache.poi.xwpf.usermodel.IBody#getTableArray(int) */ public XWPFTable getTableArray(int pos) { - if (pos > 0 && pos < tables.size()) { + if(pos >= 0 && pos < tables.size()) { return tables.get(pos); } return null; @@ -399,15 +399,15 @@ public class XWPFTableCell implements IBody, ICell { * * @see org.apache.poi.xwpf.usermodel.IBody#insertTable(int, org.apache.poi.xwpf.usermodel.XWPFTable) */ - public void insertTable(int pos, XWPFTable table) { - bodyElements.add(pos, table); - int i = 0; - for (CTTbl tbl : ctTc.getTblArray()) { - if (tbl == table.getCTTbl()) { - break; - } - i++; - } + public void insertTable(int pos, XWPFTable table) { + bodyElements.add(pos, table); + int i = 0; + for (CTTbl tbl : ctTc.getTblArray()) { + if (tbl == table.getCTTbl()) { + break; + } + i++; + } tables.add(i, table); } @@ -466,9 +466,9 @@ public class XWPFTableCell implements IBody, ICell { text.append('\t'); } } - } - - /** + } + + /** * get the TableCell which belongs to the TableCell */ public XWPFTableCell getTableCell(CTTc cell) { diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java index 6d780e89ff..0e7b2c55b2 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java @@ -21,6 +21,7 @@ import static org.junit.Assert.assertNotNull; import java.io.IOException; +import org.apache.poi.util.Units; import org.apache.poi.openxml4j.exceptions.OpenXML4JException; import org.apache.poi.xwpf.XWPFTestDataSamples; import org.apache.poi.xwpf.usermodel.XWPFRun.FontCharRange; @@ -55,7 +56,6 @@ public class TestXWPFBugs { doc.close(); } - @Test public void bug57312_NullPointException() throws IOException { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("57312.docx"); @@ -82,6 +82,40 @@ public class TestXWPFBugs { } } + @Test + public void bug57495_getTableArrayInDoc() { + XWPFDocument doc =new XWPFDocument(); + //let's create a few tables for the test + for(int i=0;i<3;i++) { + doc.createTable(2, 2); + } + XWPFTable table = doc.getTableArray(0); + assertNotNull(table); + //let's check also that returns the correct table + XWPFTable same = doc.getTables().get(0); + assertEquals(table, same); + } + + @Test + public void bug57495_getParagraphArrayInTableCell() { + XWPFDocument doc =new XWPFDocument(); + //let's create a table for the test + XWPFTable table = doc.createTable(2, 2); + assertNotNull(table); + XWPFParagraph p = table.getRow(0).getCell(0).getParagraphArray(0); + assertNotNull(p); + //let's check also that returns the correct paragraph + XWPFParagraph same = table.getRow(0).getCell(0).getParagraphs().get(0); + assertEquals(p, same); + } + + @Test + public void bug57495_convertPixelsToEMUs() { + int pixels = 100; + int expectedEMU = 952500; + int result = Units.pixelToEMU(pixels); + assertEquals(expectedEMU, result); + } @Test public void test56392() throws IOException, OpenXML4JException { -- 2.39.5