44921 - allow Ptg.writeBytes() to be called on relative ref Ptgs (RefN* and AreaN*)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@652934 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-05-02 22:36:49 +00:00
parent 45095a5d06
commit 9e6f2816c3
12 changed files with 70 additions and 102 deletions

View File

@ -37,6 +37,7 @@
<!-- Don't forget to update status.xml too! -->
<release version="3.1-beta2" date="2008-05-??">
<action dev="POI-DEVELOPERS" type="fix">44921 - allow Ptg.writeBytes() to be called on relative ref Ptgs (RefN* and AreaN*)</action>
<action dev="POI-DEVELOPERS" type="fix">44914 - Fix/suppress warning message "WARN. Unread n bytes of record 0xNN"</action>
<action dev="POI-DEVELOPERS" type="fix">44892 - made HSSFWorkbook.getSheet(String) case insensitive</action>
<action dev="POI-DEVELOPERS" type="fix">44886] - Correctly process PICT metafile in EscherMetafileBlip</action>

View File

@ -34,6 +34,7 @@
<!-- Don't forget to update changes.xml too! -->
<changes>
<release version="3.1-beta2" date="2008-05-??">
<action dev="POI-DEVELOPERS" type="fix">44921 - allow Ptg.writeBytes() to be called on relative ref Ptgs (RefN* and AreaN*)</action>
<action dev="POI-DEVELOPERS" type="fix">44914 - Fix/suppress warning message "WARN. Unread n bytes of record 0xNN"</action>
<action dev="POI-DEVELOPERS" type="fix">44892 - made HSSFWorkbook.getSheet(String) case insensitive</action>
<action dev="POI-DEVELOPERS" type="fix">44886] - Correctly process PICT metafile in EscherMetafileBlip</action>

View File

@ -186,6 +186,16 @@ public final class SharedFormulaRecord extends Record {
* counter part
*/
protected static Stack convertSharedFormulas(Stack ptgs, int formulaRow, int formulaColumn) {
if(false) {
/*
* TODO - (May-2008) Stop converting relative ref Ptgs in shared formula records.
* If/when POI writes out the workbook, this conversion makes an unnecessary diff in the BIFF records.
* Disabling this code breaks one existing junit.
* Some fix-up will be required to make Ptg.toFormulaString(HSSFWorkbook) work properly.
* That method will need 2 extra params: rowIx and colIx.
*/
return ptgs;
}
Stack newPtgStack = new Stack();
if (ptgs != null)

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -16,19 +15,9 @@
limitations under the License.
==================================================================== */
/*
* AreaPtg.java
*
* Created on November 17, 2001, 9:30 PM
*/
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.BitField;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
@ -36,8 +25,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
* @author Jason Height (jheight at chariot dot net dot au)
*/
public class AreaNAPtg
extends AreaPtg
public final class AreaNAPtg extends AreaPtg
{
public final static short sid = 0x6D;
@ -50,20 +38,16 @@ public class AreaNAPtg
super(in);
}
public void writeBytes(byte [] array, int offset) {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}
public String getAreaPtgName() {
return "AreaNAPtg";
}
public String toFormulaString(HSSFWorkbook book)
{
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
throw notImplemented();
}
public Object clone() {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
throw notImplemented();
}
}

View File

@ -36,8 +36,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
* @author Jason Height (jheight at chariot dot net dot au)
*/
public class AreaNPtg
extends AreaPtg
public final class AreaNPtg extends AreaPtg
{
public final static short sid = 0x2D;
@ -50,23 +49,16 @@ public class AreaNPtg
super(in);
}
public void writeBytes(byte [] array, int offset) {
super.writeBytes(array,offset);
//this should be a warning...there doesn't seem to be any rationale to throwing an exception here...
//this excpeiton appears to break user defined named ranges...
//throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}
public String getAreaPtgName() {
return "AreaNPtg";
}
public String toFormulaString(HSSFWorkbook book)
{
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
throw notImplemented();
}
public Object clone() {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
throw notImplemented();
}
}

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -16,19 +15,9 @@
limitations under the License.
==================================================================== */
/*
* AreaPtg.java
*
* Created on November 17, 2001, 9:30 PM
*/
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.BitField;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
@ -36,10 +25,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
* @author andy
* @author Jason Height (jheight at chariot dot net dot au)
*/
public class AreaNVPtg
extends AreaPtg
{
public final class AreaNVPtg extends AreaPtg {
public final static short sid = 0x4D;
protected AreaNVPtg() {
@ -51,20 +37,16 @@ public class AreaNVPtg
super(in);
}
public void writeBytes(byte [] array, int offset) {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}
public String getAreaPtgName() {
return "AreaNVPtg";
}
public String toFormulaString(HSSFWorkbook book)
{
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
throw notImplemented();
}
public Object clone() {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
throw notImplemented();
}
}

View File

@ -15,7 +15,6 @@
limitations under the License.
==================================================================== */
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
@ -32,10 +31,15 @@ import org.apache.poi.hssf.record.RecordInputStream;
* @author andy
* @author Jason Height (jheight at chariot dot net dot au)
*/
public class AreaPtg extends Ptg implements AreaI {
/**
* TODO - (May-2008) fix subclasses of AreaPtg 'AreaN~' which are used in shared formulas.
* see similar comment in ReferencePtg
*/
protected final RuntimeException notImplemented() {
return new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}
public class AreaPtg
extends Ptg implements AreaI
{
public final static short sid = 0x25;
private final static int SIZE = 9;
/** zero based, unsigned 16 bit */

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -16,26 +15,16 @@
limitations under the License.
==================================================================== */
/*
* ValueReferencePtg.java
*
* Created on November 21, 2001, 5:27 PM
*/
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.BitField;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
* RefNAPtg
* @author Jason Height (jheight at chariot dot net dot au)
*/
public class RefNAPtg extends ReferencePtg
public final class RefNAPtg extends ReferencePtg
{
public final static byte sid = 0x6C;
@ -48,21 +37,16 @@ public class RefNAPtg extends ReferencePtg
super(in);
}
public void writeBytes(byte [] array, int offset)
{
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}
public String getRefPtgName() {
return "RefNAPtg";
}
public String toFormulaString(HSSFWorkbook book)
{
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
throw notImplemented();
}
public Object clone() {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
throw notImplemented();
}
}

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -16,25 +15,16 @@
limitations under the License.
==================================================================== */
/*
* RefNPtg.java
*
*/
package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.BitField;
import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
* RefNPtg
* @author Jason Height (jheight at apache dot com)
*/
public class RefNPtg extends ReferencePtg
public final class RefNPtg extends ReferencePtg
{
public final static byte sid = 0x2C;
@ -49,21 +39,16 @@ public class RefNPtg extends ReferencePtg
super(in);
}
public void writeBytes(byte [] array, int offset)
{
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}
public String getRefPtgName() {
return "RefNPtg";
}
public String toFormulaString(HSSFWorkbook book)
{
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
throw notImplemented();
}
public Object clone() {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
throw notImplemented();
}
}

View File

@ -30,8 +30,20 @@ import org.apache.poi.hssf.record.RecordInputStream;
* @author Andrew C. Oliver (acoliver@apache.org)
* @author Jason Height (jheight at chariot dot net dot au)
*/
public class ReferencePtg extends Ptg {
/**
* TODO - (May-2008) fix subclasses of ReferencePtg 'RefN~' which are used in shared formulas.
* (See bugzilla 44921)
* The 'RefN~' instances do not work properly, and are expected to be converted by
* SharedFormulaRecord.convertSharedFormulas().
* This conversion currently does not take place for formulas of named ranges, conditional
* format rules and data validation rules.
* Furthermore, conversion is probably not appropriate in those instances.
*/
protected final RuntimeException notImplemented() {
return new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}
private final static int SIZE = 5;
public final static byte sid = 0x24;
private final static int MAX_ROW_NUMBER = 65536;

View File

@ -1,4 +1,3 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
@ -18,20 +17,22 @@
package org.apache.poi.hssf.record.formula;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/**
* Tests for {@link ReferencePtg}.
*/
public class TestReferencePtg extends AbstractPtgTestCase
{
public final class TestReferencePtg extends TestCase {
/**
* Tests reading a file containing this ptg.
*/
public void testReading() throws Exception
{
HSSFWorkbook workbook = loadWorkbook("ReferencePtg.xls");
public void testReading() {
HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ReferencePtg.xls");
HSSFSheet sheet = workbook.getSheetAt(0);
// First row
@ -72,6 +73,18 @@ public class TestReferencePtg extends AbstractPtgTestCase
assertEquals("Wrong formula string for reference", "A32770",
sheet.getRow(32769).getCell((short) 1).getCellFormula());
}
public void testBug44921() {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex44921-21902.xls");
try {
HSSFTestDataSamples.writeOutAndReadBack(wb);
} catch (RuntimeException e) {
if(e.getMessage().equals("Coding Error: This method should never be called. This ptg should be converted")) {
throw new AssertionFailedError("Identified bug 44921");
}
throw e;
}
}
}