fix for bug 9908, gracefully warn and write back for unknown ptg in namerecord

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@352704 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Avik Sengupta 2002-06-17 17:20:16 +00:00
parent c5285fb57e
commit 70c6ad8bce

View File

@ -89,6 +89,7 @@ public class NameRecord extends Record {
private byte field_11_compressed_unicode_flag; // not documented
private String field_12_name_text;
private Stack field_13_name_definition;
private byte[] field_13_raw_name_definition = null; // raw data
private String field_14_custom_menu_text;
private String field_15_description_text;
private String field_16_help_topic_text;
@ -319,9 +320,9 @@ public class NameRecord extends Record {
}
/** gets the definition, reference (Formula)
* @return definition
* @return definition -- can be null if we cant parse ptgs
*/
public List getNameDefinition() {
protected List getNameDefinition() {
return ( List ) field_13_name_definition;
}
@ -392,7 +393,12 @@ public class NameRecord extends Record {
StringUtil.putCompressedUnicode(getNameText(), data , 19 + offset);
int start_of_name_definition = 19 + field_3_length_name_text;
serializePtgs(data, start_of_name_definition + offset);
if (this.field_13_name_definition != null) {
serializePtgs(data, start_of_name_definition + offset);
} else {
System.arraycopy(field_13_raw_name_definition,0,data
,start_of_name_definition + offset,field_13_raw_name_definition.length);
}
int start_of_custom_menu_text = start_of_name_definition + field_4_length_name_definition;
StringUtil.putCompressedUnicode(getCustomMenuText(), data , start_of_custom_menu_text + offset);
@ -449,6 +455,7 @@ public class NameRecord extends Record {
* @return extern sheet index
*/
public short getExternSheetNumber(){
if (field_13_name_definition == null) return 0;
Ptg ptg = (Ptg) field_13_name_definition.peek();
short result = 0;
@ -468,7 +475,8 @@ public class NameRecord extends Record {
public void setExternSheetNumber(short externSheetNumber){
Ptg ptg;
if (field_13_name_definition.isEmpty()){
if (field_13_name_definition == null || field_13_name_definition.isEmpty()){
field_13_name_definition = new Stack();
ptg = createNewPtg();
} else {
ptg = (Ptg) field_13_name_definition.peek();
@ -494,6 +502,7 @@ public class NameRecord extends Record {
* @return area reference
*/
public String getAreaReference(){
if (field_13_name_definition == null) return "#REF!";
Ptg ptg = (Ptg) field_13_name_definition.peek();
String result = "";
@ -516,7 +525,8 @@ public class NameRecord extends Record {
Ptg oldPtg;
Ptg ptg;
if (field_13_name_definition.isEmpty()){
if (field_13_name_definition==null ||field_13_name_definition.isEmpty()){
field_13_name_definition = new Stack();
oldPtg = createNewPtg();
} else {
//Trying to find extern sheet index
@ -599,13 +609,20 @@ public class NameRecord extends Record {
Stack stack = new Stack();
int pos = start_of_expression + offset;
int sizeCounter = 0;
try {
while (sizeCounter < size) {
Ptg ptg = Ptg.createPtg(data, pos);
while (sizeCounter < size) {
Ptg ptg = Ptg.createPtg(data, pos);
pos += ptg.getSize();
sizeCounter += ptg.getSize();
stack.push(ptg);
pos += ptg.getSize();
sizeCounter += ptg.getSize();
stack.push(ptg);
}
} catch (java.lang.UnsupportedOperationException uoe) {
System.err.println("[WARNING] Unknown Ptg "
+ uoe.getMessage() );
field_13_raw_name_definition=new byte[size];
System.arraycopy(data,offset,field_13_raw_name_definition,0,size);
return null;
}
return stack;
}