mirror of https://github.com/apache/poi.git
Converted SupBookRecord to use plain Strings instead of UnicodeStrings
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@711514 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8282eb0c98
commit
b4bfe8192c
|
@ -29,8 +29,9 @@ import org.apache.poi.hssf.record.ExternalNameRecord;
|
||||||
import org.apache.poi.hssf.record.NameRecord;
|
import org.apache.poi.hssf.record.NameRecord;
|
||||||
import org.apache.poi.hssf.record.Record;
|
import org.apache.poi.hssf.record.Record;
|
||||||
import org.apache.poi.hssf.record.SupBookRecord;
|
import org.apache.poi.hssf.record.SupBookRecord;
|
||||||
import org.apache.poi.hssf.record.UnicodeString;
|
import org.apache.poi.hssf.record.formula.Area3DPtg;
|
||||||
import org.apache.poi.hssf.record.formula.NameXPtg;
|
import org.apache.poi.hssf.record.formula.NameXPtg;
|
||||||
|
import org.apache.poi.hssf.record.formula.Ref3DPtg;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Link Table (OOO pdf reference: 4.10.3 ) <p/>
|
* Link Table (OOO pdf reference: 4.10.3 ) <p/>
|
||||||
|
@ -311,10 +312,10 @@ final class LinkTable {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int shIx = _externSheetRecord.getFirstSheetIndexFromRefIndex(extRefIndex);
|
int shIx = _externSheetRecord.getFirstSheetIndexFromRefIndex(extRefIndex);
|
||||||
UnicodeString usSheetName = ebr.getSheetNames()[shIx];
|
String usSheetName = ebr.getSheetNames()[shIx];
|
||||||
return new String[] {
|
return new String[] {
|
||||||
ebr.getURL(),
|
ebr.getURL(),
|
||||||
usSheetName.getString(),
|
usSheetName,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,9 +346,9 @@ final class LinkTable {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getSheetIndex(UnicodeString[] sheetNames, String sheetName) {
|
private static int getSheetIndex(String[] sheetNames, String sheetName) {
|
||||||
for (int i = 0; i < sheetNames.length; i++) {
|
for (int i = 0; i < sheetNames.length; i++) {
|
||||||
if (sheetNames[i].getString().equals(sheetName)) {
|
if (sheetNames[i].equals(sheetName)) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -320,16 +320,6 @@ public final class RecordInputStream extends InputStream implements LittleEndian
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns an excel style unicode string from the bytes reminaing in the record.
|
|
||||||
* <i>Note:</i> Unicode strings differ from <b>normal</b> strings due to the addition of
|
|
||||||
* formatting information.
|
|
||||||
*
|
|
||||||
* @return The unicode string representation of the remaining bytes.
|
|
||||||
*/
|
|
||||||
public UnicodeString readUnicodeString() {
|
|
||||||
return new UnicodeString(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Returns the remaining bytes for the current record.
|
/** Returns the remaining bytes for the current record.
|
||||||
*
|
*
|
||||||
* @return The remaining bytes of the current record.
|
* @return The remaining bytes of the current record.
|
||||||
|
|
|
@ -17,11 +17,12 @@
|
||||||
|
|
||||||
package org.apache.poi.hssf.record;
|
package org.apache.poi.hssf.record;
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.UnicodeString.UnicodeRecordStats;
|
import org.apache.poi.util.LittleEndianByteArrayOutputStream;
|
||||||
import org.apache.poi.util.LittleEndian;
|
import org.apache.poi.util.LittleEndianOutput;
|
||||||
|
import org.apache.poi.util.StringUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title: Sup Book (EXTERNALBOOK) <P>
|
* Title: Sup Book - EXTERNALBOOK (0x01AE) <p/>
|
||||||
* Description: A External Workbook Description (Supplemental Book)
|
* Description: A External Workbook Description (Supplemental Book)
|
||||||
* Its only a dummy record for making new ExternSheet Record <P>
|
* Its only a dummy record for making new ExternSheet Record <P>
|
||||||
* REFERENCE: 5.38<P>
|
* REFERENCE: 5.38<P>
|
||||||
|
@ -31,16 +32,16 @@ import org.apache.poi.util.LittleEndian;
|
||||||
*/
|
*/
|
||||||
public final class SupBookRecord extends Record {
|
public final class SupBookRecord extends Record {
|
||||||
|
|
||||||
public final static short sid = 0x1AE;
|
public final static short sid = 0x01AE;
|
||||||
|
|
||||||
private static final short SMALL_RECORD_SIZE = 4;
|
private static final short SMALL_RECORD_SIZE = 4;
|
||||||
private static final short TAG_INTERNAL_REFERENCES = 0x0401;
|
private static final short TAG_INTERNAL_REFERENCES = 0x0401;
|
||||||
private static final short TAG_ADD_IN_FUNCTIONS = 0x3A01;
|
private static final short TAG_ADD_IN_FUNCTIONS = 0x3A01;
|
||||||
|
|
||||||
private short field_1_number_of_sheets;
|
private short field_1_number_of_sheets;
|
||||||
private UnicodeString field_2_encoded_url;
|
private String field_2_encoded_url;
|
||||||
private UnicodeString[] field_3_sheet_names;
|
private String[] field_3_sheet_names;
|
||||||
private boolean _isAddInFunctions;
|
private boolean _isAddInFunctions;
|
||||||
|
|
||||||
|
|
||||||
public static SupBookRecord createInternalReferences(short numberOfSheets) {
|
public static SupBookRecord createInternalReferences(short numberOfSheets) {
|
||||||
|
@ -49,7 +50,7 @@ public final class SupBookRecord extends Record {
|
||||||
public static SupBookRecord createAddInFunctions() {
|
public static SupBookRecord createAddInFunctions() {
|
||||||
return new SupBookRecord(true, (short)0);
|
return new SupBookRecord(true, (short)0);
|
||||||
}
|
}
|
||||||
public static SupBookRecord createExternalReferences(UnicodeString url, UnicodeString[] sheetNames) {
|
public static SupBookRecord createExternalReferences(String url, String[] sheetNames) {
|
||||||
return new SupBookRecord(url, sheetNames);
|
return new SupBookRecord(url, sheetNames);
|
||||||
}
|
}
|
||||||
private SupBookRecord(boolean isAddInFuncs, short numberOfSheets) {
|
private SupBookRecord(boolean isAddInFuncs, short numberOfSheets) {
|
||||||
|
@ -59,7 +60,7 @@ public final class SupBookRecord extends Record {
|
||||||
field_3_sheet_names = null;
|
field_3_sheet_names = null;
|
||||||
_isAddInFunctions = isAddInFuncs;
|
_isAddInFunctions = isAddInFuncs;
|
||||||
}
|
}
|
||||||
public SupBookRecord(UnicodeString url, UnicodeString[] sheetNames) {
|
public SupBookRecord(String url, String[] sheetNames) {
|
||||||
field_1_number_of_sheets = (short) sheetNames.length;
|
field_1_number_of_sheets = (short) sheetNames.length;
|
||||||
field_2_encoded_url = url;
|
field_2_encoded_url = url;
|
||||||
field_3_sheet_names = sheetNames;
|
field_3_sheet_names = sheetNames;
|
||||||
|
@ -84,7 +85,7 @@ public final class SupBookRecord extends Record {
|
||||||
* @param offset of the record's data (provided a big array of the file)
|
* @param offset of the record's data (provided a big array of the file)
|
||||||
*/
|
*/
|
||||||
public SupBookRecord(RecordInputStream in) {
|
public SupBookRecord(RecordInputStream in) {
|
||||||
int recLen = in.remaining();
|
int recLen = in.remaining();
|
||||||
|
|
||||||
field_1_number_of_sheets = in.readShort();
|
field_1_number_of_sheets = in.readShort();
|
||||||
|
|
||||||
|
@ -92,10 +93,10 @@ public final class SupBookRecord extends Record {
|
||||||
// 5.38.1 External References
|
// 5.38.1 External References
|
||||||
_isAddInFunctions = false;
|
_isAddInFunctions = false;
|
||||||
|
|
||||||
field_2_encoded_url = in.readUnicodeString();
|
field_2_encoded_url = in.readString();
|
||||||
UnicodeString[] sheetNames = new UnicodeString[field_1_number_of_sheets];
|
String[] sheetNames = new String[field_1_number_of_sheets];
|
||||||
for (int i = 0; i < sheetNames.length; i++) {
|
for (int i = 0; i < sheetNames.length; i++) {
|
||||||
sheetNames[i] = in.readUnicodeString();
|
sheetNames[i] = in.readString();
|
||||||
}
|
}
|
||||||
field_3_sheet_names = sheetNames;
|
field_3_sheet_names = sheetNames;
|
||||||
return;
|
return;
|
||||||
|
@ -143,18 +144,14 @@ public final class SupBookRecord extends Record {
|
||||||
return SMALL_RECORD_SIZE;
|
return SMALL_RECORD_SIZE;
|
||||||
}
|
}
|
||||||
int sum = 2; // u16 number of sheets
|
int sum = 2; // u16 number of sheets
|
||||||
UnicodeRecordStats urs = new UnicodeRecordStats();
|
|
||||||
field_2_encoded_url.getRecordSize(urs);
|
sum += StringUtil.getEncodedSize(field_2_encoded_url);
|
||||||
sum += urs.recordSize;
|
|
||||||
|
|
||||||
for(int i=0; i<field_3_sheet_names.length; i++) {
|
for(int i=0; i<field_3_sheet_names.length; i++) {
|
||||||
urs = new UnicodeRecordStats();
|
sum += StringUtil.getEncodedSize(field_3_sheet_names[i]);
|
||||||
field_3_sheet_names[i].getRecordSize(urs);
|
|
||||||
sum += urs.recordSize;
|
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* called by the class that is responsible for writing this sucker.
|
* called by the class that is responsible for writing this sucker.
|
||||||
* Subclasses should implement this so that their data is passed back in a
|
* Subclasses should implement this so that their data is passed back in a
|
||||||
|
@ -165,29 +162,26 @@ public final class SupBookRecord extends Record {
|
||||||
* @return number of bytes written
|
* @return number of bytes written
|
||||||
*/
|
*/
|
||||||
public int serialize(int offset, byte [] data) {
|
public int serialize(int offset, byte [] data) {
|
||||||
LittleEndian.putShort(data, 0 + offset, sid);
|
|
||||||
int dataSize = getDataSize();
|
int dataSize = getDataSize();
|
||||||
LittleEndian.putShort(data, 2 + offset, (short) dataSize);
|
int recordSize = 4 + dataSize;
|
||||||
LittleEndian.putShort(data, 4 + offset, field_1_number_of_sheets);
|
LittleEndianOutput out = new LittleEndianByteArrayOutputStream(data, offset, recordSize);
|
||||||
|
|
||||||
|
out.writeShort(sid);
|
||||||
|
out.writeShort(dataSize);
|
||||||
|
out.writeShort(field_1_number_of_sheets);
|
||||||
|
|
||||||
if(isExternalReferences()) {
|
if(isExternalReferences()) {
|
||||||
|
StringUtil.writeUnicodeString(out, field_2_encoded_url);
|
||||||
int currentOffset = 6 + offset;
|
|
||||||
UnicodeRecordStats urs = new UnicodeRecordStats();
|
|
||||||
field_2_encoded_url.serialize(urs, currentOffset, data);
|
|
||||||
currentOffset += urs.recordSize;
|
|
||||||
|
|
||||||
for(int i=0; i<field_3_sheet_names.length; i++) {
|
for(int i=0; i<field_3_sheet_names.length; i++) {
|
||||||
urs = new UnicodeRecordStats();
|
StringUtil.writeUnicodeString(out, field_3_sheet_names[i]);
|
||||||
field_3_sheet_names[i].serialize(urs, currentOffset, data);
|
|
||||||
currentOffset += urs.recordSize;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
short field2val = _isAddInFunctions ? TAG_ADD_IN_FUNCTIONS : TAG_INTERNAL_REFERENCES;
|
int field2val = _isAddInFunctions ? TAG_ADD_IN_FUNCTIONS : TAG_INTERNAL_REFERENCES;
|
||||||
|
|
||||||
LittleEndian.putShort(data, 6 + offset, field2val);
|
out.writeShort(field2val);
|
||||||
}
|
}
|
||||||
return dataSize + 4;
|
return recordSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNumberOfSheets(short number){
|
public void setNumberOfSheets(short number){
|
||||||
|
@ -203,7 +197,7 @@ public final class SupBookRecord extends Record {
|
||||||
return sid;
|
return sid;
|
||||||
}
|
}
|
||||||
public String getURL() {
|
public String getURL() {
|
||||||
String encodedUrl = field_2_encoded_url.getString();
|
String encodedUrl = field_2_encoded_url;
|
||||||
switch(encodedUrl.charAt(0)) {
|
switch(encodedUrl.charAt(0)) {
|
||||||
case 0: // Reference to an empty workbook name
|
case 0: // Reference to an empty workbook name
|
||||||
return encodedUrl.substring(1); // will this just be empty string?
|
return encodedUrl.substring(1); // will this just be empty string?
|
||||||
|
@ -230,7 +224,7 @@ public final class SupBookRecord extends Record {
|
||||||
|
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
public UnicodeString[] getSheetNames() {
|
public String[] getSheetNames() {
|
||||||
return (UnicodeString[]) field_3_sheet_names.clone();
|
return (String[]) field_3_sheet_names.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,10 +69,10 @@ public final class TestSupBookRecord extends TestCase {
|
||||||
assertEquals( 34, record.getRecordSize() ); //sid+size+data
|
assertEquals( 34, record.getRecordSize() ); //sid+size+data
|
||||||
|
|
||||||
assertEquals("testURL", record.getURL());
|
assertEquals("testURL", record.getURL());
|
||||||
UnicodeString[] sheetNames = record.getSheetNames();
|
String[] sheetNames = record.getSheetNames();
|
||||||
assertEquals(2, sheetNames.length);
|
assertEquals(2, sheetNames.length);
|
||||||
assertEquals("Sheet1", sheetNames[0].getString());
|
assertEquals("Sheet1", sheetNames[0]);
|
||||||
assertEquals("Sheet2", sheetNames[1].getString());
|
assertEquals("Sheet2", sheetNames[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -97,11 +97,8 @@ public final class TestSupBookRecord extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testStoreER() {
|
public void testStoreER() {
|
||||||
UnicodeString url = new UnicodeString("testURL");
|
String url = "testURL";
|
||||||
UnicodeString[] sheetNames = {
|
String[] sheetNames = { "Sheet1", "Sheet2", };
|
||||||
new UnicodeString("Sheet1"),
|
|
||||||
new UnicodeString("Sheet2"),
|
|
||||||
};
|
|
||||||
SupBookRecord record = SupBookRecord.createExternalReferences(url, sheetNames);
|
SupBookRecord record = SupBookRecord.createExternalReferences(url, sheetNames);
|
||||||
|
|
||||||
TestcaseRecordInputStream.confirmRecordEncoding(0x01AE, dataER, record.serialize());
|
TestcaseRecordInputStream.confirmRecordEncoding(0x01AE, dataER, record.serialize());
|
||||||
|
|
Loading…
Reference in New Issue