From: Josh Micich Date: Wed, 5 Nov 2008 05:52:35 +0000 (+0000) Subject: Converted SupBookRecord to use plain Strings instead of UnicodeStrings X-Git-Tag: trunk_20081106~8 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b4bfe8192c88c3184bc1d9abeebf11eb69c2b892;p=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 --- diff --git a/src/java/org/apache/poi/hssf/model/LinkTable.java b/src/java/org/apache/poi/hssf/model/LinkTable.java index 998712e5e8..f587f5e375 100755 --- a/src/java/org/apache/poi/hssf/model/LinkTable.java +++ b/src/java/org/apache/poi/hssf/model/LinkTable.java @@ -29,8 +29,9 @@ import org.apache.poi.hssf.record.ExternalNameRecord; import org.apache.poi.hssf.record.NameRecord; import org.apache.poi.hssf.record.Record; 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.Ref3DPtg; /** * Link Table (OOO pdf reference: 4.10.3 )

@@ -311,10 +312,10 @@ final class LinkTable { return null; } int shIx = _externSheetRecord.getFirstSheetIndexFromRefIndex(extRefIndex); - UnicodeString usSheetName = ebr.getSheetNames()[shIx]; + String usSheetName = ebr.getSheetNames()[shIx]; return new String[] { ebr.getURL(), - usSheetName.getString(), + usSheetName, }; } @@ -345,9 +346,9 @@ final class LinkTable { 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++) { - if (sheetNames[i].getString().equals(sheetName)) { + if (sheetNames[i].equals(sheetName)) { return i; } diff --git a/src/java/org/apache/poi/hssf/record/RecordInputStream.java b/src/java/org/apache/poi/hssf/record/RecordInputStream.java index b66bf0e96d..2f275ed928 100755 --- a/src/java/org/apache/poi/hssf/record/RecordInputStream.java +++ b/src/java/org/apache/poi/hssf/record/RecordInputStream.java @@ -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. - * Note: Unicode strings differ from normal 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. * * @return The remaining bytes of the current record. diff --git a/src/java/org/apache/poi/hssf/record/SupBookRecord.java b/src/java/org/apache/poi/hssf/record/SupBookRecord.java index a58c5c8c97..5cbfd42d6a 100644 --- a/src/java/org/apache/poi/hssf/record/SupBookRecord.java +++ b/src/java/org/apache/poi/hssf/record/SupBookRecord.java @@ -17,11 +17,12 @@ package org.apache.poi.hssf.record; -import org.apache.poi.hssf.record.UnicodeString.UnicodeRecordStats; -import org.apache.poi.util.LittleEndian; +import org.apache.poi.util.LittleEndianByteArrayOutputStream; +import org.apache.poi.util.LittleEndianOutput; +import org.apache.poi.util.StringUtil; /** - * Title: Sup Book (EXTERNALBOOK)

+ * Title: Sup Book - EXTERNALBOOK (0x01AE)

* Description: A External Workbook Description (Supplemental Book) * Its only a dummy record for making new ExternSheet Record

* REFERENCE: 5.38

@@ -31,25 +32,25 @@ import org.apache.poi.util.LittleEndian; */ 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 TAG_INTERNAL_REFERENCES = 0x0401; private static final short TAG_ADD_IN_FUNCTIONS = 0x3A01; - private short field_1_number_of_sheets; - private UnicodeString field_2_encoded_url; - private UnicodeString[] field_3_sheet_names; - private boolean _isAddInFunctions; + private short field_1_number_of_sheets; + private String field_2_encoded_url; + private String[] field_3_sheet_names; + private boolean _isAddInFunctions; + - public static SupBookRecord createInternalReferences(short numberOfSheets) { return new SupBookRecord(false, numberOfSheets); } public static SupBookRecord createAddInFunctions() { 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); } private SupBookRecord(boolean isAddInFuncs, short numberOfSheets) { @@ -59,7 +60,7 @@ public final class SupBookRecord extends Record { field_3_sheet_names = null; _isAddInFunctions = isAddInFuncs; } - public SupBookRecord(UnicodeString url, UnicodeString[] sheetNames) { + public SupBookRecord(String url, String[] sheetNames) { field_1_number_of_sheets = (short) sheetNames.length; field_2_encoded_url = url; field_3_sheet_names = sheetNames; @@ -84,18 +85,18 @@ public final class SupBookRecord extends Record { * @param offset of the record's data (provided a big array of the file) */ public SupBookRecord(RecordInputStream in) { - int recLen = in.remaining(); - + int recLen = in.remaining(); + field_1_number_of_sheets = in.readShort(); - + if(recLen > SMALL_RECORD_SIZE) { // 5.38.1 External References _isAddInFunctions = false; - field_2_encoded_url = in.readUnicodeString(); - UnicodeString[] sheetNames = new UnicodeString[field_1_number_of_sheets]; + field_2_encoded_url = in.readString(); + String[] sheetNames = new String[field_1_number_of_sheets]; for (int i = 0; i < sheetNames.length; i++) { - sheetNames[i] = in.readUnicodeString(); + sheetNames[i] = in.readString(); } field_3_sheet_names = sheetNames; return; @@ -103,7 +104,7 @@ public final class SupBookRecord extends Record { // else not 'External References' field_2_encoded_url = null; field_3_sheet_names = null; - + short nextShort = in.readShort(); if(nextShort == TAG_INTERNAL_REFERENCES) { // 5.38.2 'Internal References' @@ -116,7 +117,7 @@ public final class SupBookRecord extends Record { + field_1_number_of_sheets + ")"); } } else { - throw new RuntimeException("invalid EXTERNALBOOK code (" + throw new RuntimeException("invalid EXTERNALBOOK code (" + Integer.toHexString(nextShort) + ")"); } } @@ -124,7 +125,7 @@ public final class SupBookRecord extends Record { public String toString() { StringBuffer sb = new StringBuffer(); sb.append(getClass().getName()).append(" [SUPBOOK "); - + if(isExternalReferences()) { sb.append("External References"); sb.append(" nSheets=").append(field_1_number_of_sheets); @@ -143,18 +144,14 @@ public final class SupBookRecord extends Record { return SMALL_RECORD_SIZE; } int sum = 2; // u16 number of sheets - UnicodeRecordStats urs = new UnicodeRecordStats(); - field_2_encoded_url.getRecordSize(urs); - sum += urs.recordSize; - + + sum += StringUtil.getEncodedSize(field_2_encoded_url); + for(int i=0; i