mirror of https://github.com/apache/poi.git
Fix bug 59322: NullPointerException when converting a certain Word document to HTML
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1866185 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
df64598b12
commit
42005812c4
|
@ -18,97 +18,132 @@
|
||||||
package org.apache.poi.hwpf.usermodel;
|
package org.apache.poi.hwpf.usermodel;
|
||||||
|
|
||||||
public final class TableCell
|
public final class TableCell
|
||||||
extends Range
|
extends Range {
|
||||||
{
|
|
||||||
private int _levelNum;
|
private int _levelNum;
|
||||||
private TableCellDescriptor _tcd;
|
private TableCellDescriptor _tcd;
|
||||||
private int _leftEdge;
|
private int _leftEdge;
|
||||||
private int _width;
|
private int _width;
|
||||||
|
|
||||||
public TableCell( int startIdxInclusive, int endIdxExclusive,
|
public TableCell(int startIdxInclusive, int endIdxExclusive,
|
||||||
TableRow parent, int levelNum, TableCellDescriptor tcd,
|
TableRow parent, int levelNum, TableCellDescriptor tcd,
|
||||||
int leftEdge, int width )
|
int leftEdge, int width) {
|
||||||
{
|
super(startIdxInclusive, endIdxExclusive, parent);
|
||||||
super( startIdxInclusive, endIdxExclusive, parent );
|
_tcd = tcd;
|
||||||
_tcd = tcd;
|
_leftEdge = leftEdge;
|
||||||
_leftEdge = leftEdge;
|
_width = width;
|
||||||
_width = width;
|
_levelNum = levelNum;
|
||||||
_levelNum = levelNum;
|
}
|
||||||
|
|
||||||
|
public boolean isFirstMerged() {
|
||||||
|
if (_tcd == null) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFirstMerged()
|
|
||||||
{
|
|
||||||
return _tcd.isFFirstMerged();
|
return _tcd.isFFirstMerged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isMerged()
|
public boolean isMerged() {
|
||||||
{
|
if (_tcd == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return _tcd.isFMerged();
|
return _tcd.isFMerged();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVertical()
|
public boolean isVertical() {
|
||||||
{
|
if (_tcd == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return _tcd.isFVertical();
|
return _tcd.isFVertical();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isBackward()
|
public boolean isBackward() {
|
||||||
{
|
if (_tcd == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return _tcd.isFBackward();
|
return _tcd.isFBackward();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRotateFont()
|
public boolean isRotateFont() {
|
||||||
{
|
if (_tcd == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return _tcd.isFRotateFont();
|
return _tcd.isFRotateFont();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isVerticallyMerged()
|
public boolean isVerticallyMerged() {
|
||||||
{
|
if (_tcd == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return _tcd.isFVertMerge();
|
return _tcd.isFVertMerge();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFirstVerticallyMerged()
|
public boolean isFirstVerticallyMerged() {
|
||||||
{
|
if (_tcd == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return _tcd.isFVertRestart();
|
return _tcd.isFVertRestart();
|
||||||
}
|
}
|
||||||
|
|
||||||
public byte getVertAlign()
|
public byte getVertAlign() {
|
||||||
{
|
if (_tcd == null) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return _tcd.getVertAlign();
|
return _tcd.getVertAlign();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BorderCode getBrcTop()
|
public BorderCode getBrcTop() {
|
||||||
{
|
if (_tcd == null) {
|
||||||
|
return new BorderCode();
|
||||||
|
}
|
||||||
|
|
||||||
return _tcd.getBrcTop();
|
return _tcd.getBrcTop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BorderCode getBrcBottom()
|
public BorderCode getBrcBottom() {
|
||||||
{
|
if (_tcd == null) {
|
||||||
|
return new BorderCode();
|
||||||
|
}
|
||||||
|
|
||||||
return _tcd.getBrcBottom();
|
return _tcd.getBrcBottom();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BorderCode getBrcLeft()
|
public BorderCode getBrcLeft() {
|
||||||
{
|
if (_tcd == null) {
|
||||||
|
return new BorderCode();
|
||||||
|
}
|
||||||
|
|
||||||
return _tcd.getBrcLeft();
|
return _tcd.getBrcLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
public BorderCode getBrcRight()
|
public BorderCode getBrcRight() {
|
||||||
{
|
if (_tcd == null) {
|
||||||
|
return new BorderCode();
|
||||||
|
}
|
||||||
|
|
||||||
return _tcd.getBrcRight();
|
return _tcd.getBrcRight();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getLeftEdge() // twips
|
// twips
|
||||||
{
|
public int getLeftEdge() {
|
||||||
return _leftEdge;
|
return _leftEdge;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getWidth() // twips
|
// twips
|
||||||
{
|
public int getWidth() {
|
||||||
return _width;
|
return _width;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the TableCellDescriptor for this cell.*/
|
/**
|
||||||
public TableCellDescriptor getDescriptor(){
|
* Returns the TableCellDescriptor for this cell.
|
||||||
return _tcd;
|
*/
|
||||||
|
public TableCellDescriptor getDescriptor() {
|
||||||
|
return _tcd;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,19 +24,23 @@ import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.apache.poi.POIDataSamples;
|
import org.apache.poi.POIDataSamples;
|
||||||
import org.apache.poi.hwpf.HWPFDocument;
|
import org.apache.poi.hwpf.HWPFDocument;
|
||||||
|
import org.apache.poi.hwpf.HWPFDocumentCore;
|
||||||
import org.apache.poi.hwpf.HWPFOldDocument;
|
import org.apache.poi.hwpf.HWPFOldDocument;
|
||||||
import org.apache.poi.hwpf.HWPFTestDataSamples;
|
import org.apache.poi.hwpf.HWPFTestDataSamples;
|
||||||
import org.apache.poi.hwpf.converter.AbstractWordUtils;
|
import org.apache.poi.hwpf.converter.AbstractWordUtils;
|
||||||
|
import org.apache.poi.hwpf.converter.WordToHtmlConverter;
|
||||||
import org.apache.poi.hwpf.converter.WordToTextConverter;
|
import org.apache.poi.hwpf.converter.WordToTextConverter;
|
||||||
import org.apache.poi.hwpf.extractor.Word6Extractor;
|
import org.apache.poi.hwpf.extractor.Word6Extractor;
|
||||||
import org.apache.poi.hwpf.extractor.WordExtractor;
|
import org.apache.poi.hwpf.extractor.WordExtractor;
|
||||||
|
@ -50,6 +54,9 @@ import org.apache.poi.util.IOUtils;
|
||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.apache.poi.util.POILogger;
|
import org.apache.poi.util.POILogger;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Node;
|
||||||
|
import org.w3c.dom.NodeList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test different problems reported in the Apache Bugzilla
|
* Test different problems reported in the Apache Bugzilla
|
||||||
|
@ -892,4 +899,29 @@ public class TestBugs{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test60217() throws Exception {
|
||||||
|
File file = new File("/tmp/word-doc-with-revised-table.doc");
|
||||||
|
FileInputStream fileInputStream = new FileInputStream(file);
|
||||||
|
Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
|
||||||
|
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(document);
|
||||||
|
HWPFDocumentCore hwpfDocumentCore = new HWPFDocument(HWPFDocumentCore.verifyAndBuildPOIFS(fileInputStream));
|
||||||
|
wordToHtmlConverter.processDocument(hwpfDocumentCore);
|
||||||
|
System.out.println(document);
|
||||||
|
|
||||||
|
System.out.println(document.getNodeName() + " -> " + document.getNodeValue());
|
||||||
|
|
||||||
|
printNode(document, " ");
|
||||||
|
|
||||||
|
System.out.println("Process Complete");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void printNode(Node rootNode, String spacer) {
|
||||||
|
System.out.println(spacer + rootNode.getNodeName() + " -> " + rootNode.getNodeValue());
|
||||||
|
NodeList nl = rootNode.getChildNodes();
|
||||||
|
for (int i = 0; i < nl.getLength(); i++)
|
||||||
|
printNode(nl.item(i), spacer + " ");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue