You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by fa...@apache.org on 2021/05/22 20:56:49 UTC
svn commit: r1890120 [12/43] - in /poi/trunk/poi/src:
main/java/org/apache/poi/ main/java/org/apache/poi/ddf/
main/java/org/apache/poi/extractor/ main/java/org/apache/poi/hpsf/
main/java/org/apache/poi/hssf/ main/java/org/apache/poi/hssf/dev/
main/java...
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/cont/UnknownLengthRecordOutput.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/cont/UnknownLengthRecordOutput.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/cont/UnknownLengthRecordOutput.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/cont/UnknownLengthRecordOutput.java Sat May 22 20:56:44 2021
@@ -27,86 +27,86 @@ import org.apache.poi.util.LittleEndianO
* class updates the 'ushort size' with its final value.
*/
final class UnknownLengthRecordOutput implements LittleEndianOutput {
- private static final int MAX_DATA_SIZE = RecordInputStream.MAX_RECORD_DATA_SIZE;
+ private static final int MAX_DATA_SIZE = RecordInputStream.MAX_RECORD_DATA_SIZE;
- private final LittleEndianOutput _originalOut;
- /** for writing the 'ushort size' field once its value is known */
- private final LittleEndianOutput _dataSizeOutput;
- private final byte[] _byteBuffer;
- private LittleEndianOutput _out;
- private int _size;
+ private final LittleEndianOutput _originalOut;
+ /** for writing the 'ushort size' field once its value is known */
+ private final LittleEndianOutput _dataSizeOutput;
+ private final byte[] _byteBuffer;
+ private LittleEndianOutput _out;
+ private int _size;
- public UnknownLengthRecordOutput(LittleEndianOutput out, int sid) {
- _originalOut = out;
- out.writeShort(sid);
- if (out instanceof DelayableLittleEndianOutput) {
- // optimisation
- DelayableLittleEndianOutput dleo = (DelayableLittleEndianOutput) out;
- _dataSizeOutput = dleo.createDelayedOutput(2);
- _byteBuffer = null;
- _out = out;
- } else {
- // otherwise temporarily write all subsequent data to a buffer
- _dataSizeOutput = out;
- _byteBuffer = new byte[RecordInputStream.MAX_RECORD_DATA_SIZE];
- _out = new LittleEndianByteArrayOutputStream(_byteBuffer, 0);
- }
- }
- /**
- * includes 4 byte header
- */
- public int getTotalSize() {
- return 4 + _size;
- }
- public int getAvailableSpace() {
- if (_out == null) {
- throw new IllegalStateException("Record already terminated");
- }
- return MAX_DATA_SIZE - _size;
- }
- /**
- * Finishes writing the current record and updates 'ushort size' field.<br>
- * After this method is called, only {@link #getTotalSize()} may be called.
- */
- public void terminate() {
- if (_out == null) {
- throw new IllegalStateException("Record already terminated");
- }
- _dataSizeOutput.writeShort(_size);
- if (_byteBuffer != null) {
- _originalOut.write(_byteBuffer, 0, _size);
- _out = null;
- return;
- }
- _out = null;
- }
+ public UnknownLengthRecordOutput(LittleEndianOutput out, int sid) {
+ _originalOut = out;
+ out.writeShort(sid);
+ if (out instanceof DelayableLittleEndianOutput) {
+ // optimisation
+ DelayableLittleEndianOutput dleo = (DelayableLittleEndianOutput) out;
+ _dataSizeOutput = dleo.createDelayedOutput(2);
+ _byteBuffer = null;
+ _out = out;
+ } else {
+ // otherwise temporarily write all subsequent data to a buffer
+ _dataSizeOutput = out;
+ _byteBuffer = new byte[RecordInputStream.MAX_RECORD_DATA_SIZE];
+ _out = new LittleEndianByteArrayOutputStream(_byteBuffer, 0);
+ }
+ }
+ /**
+ * includes 4 byte header
+ */
+ public int getTotalSize() {
+ return 4 + _size;
+ }
+ public int getAvailableSpace() {
+ if (_out == null) {
+ throw new IllegalStateException("Record already terminated");
+ }
+ return MAX_DATA_SIZE - _size;
+ }
+ /**
+ * Finishes writing the current record and updates 'ushort size' field.<br>
+ * After this method is called, only {@link #getTotalSize()} may be called.
+ */
+ public void terminate() {
+ if (_out == null) {
+ throw new IllegalStateException("Record already terminated");
+ }
+ _dataSizeOutput.writeShort(_size);
+ if (_byteBuffer != null) {
+ _originalOut.write(_byteBuffer, 0, _size);
+ _out = null;
+ return;
+ }
+ _out = null;
+ }
- public void write(byte[] b) {
- _out.write(b);
- _size += b.length;
- }
- public void write(byte[] b, int offset, int len) {
- _out.write(b, offset, len);
- _size += len;
- }
- public void writeByte(int v) {
- _out.writeByte(v);
- _size += 1;
- }
- public void writeDouble(double v) {
- _out.writeDouble(v);
- _size += 8;
- }
- public void writeInt(int v) {
- _out.writeInt(v);
- _size += 4;
- }
- public void writeLong(long v) {
- _out.writeLong(v);
- _size += 8;
- }
- public void writeShort(int v) {
- _out.writeShort(v);
- _size += 2;
- }
+ public void write(byte[] b) {
+ _out.write(b);
+ _size += b.length;
+ }
+ public void write(byte[] b, int offset, int len) {
+ _out.write(b, offset, len);
+ _size += len;
+ }
+ public void writeByte(int v) {
+ _out.writeByte(v);
+ _size += 1;
+ }
+ public void writeDouble(double v) {
+ _out.writeDouble(v);
+ _size += 8;
+ }
+ public void writeInt(int v) {
+ _out.writeInt(v);
+ _size += 4;
+ }
+ public void writeLong(long v) {
+ _out.writeLong(v);
+ _size += 8;
+ }
+ public void writeShort(int v) {
+ _out.writeShort(v);
+ _size += 2;
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/crypto/Biff8DecryptingStream.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/crypto/Biff8DecryptingStream.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/crypto/Biff8DecryptingStream.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/crypto/Biff8DecryptingStream.java Sat May 22 20:56:44 2021
@@ -44,16 +44,16 @@ public final class Biff8DecryptingStream
private final byte[] buffer = new byte[LittleEndianConsts.LONG_SIZE];
private boolean shouldSkipEncryptionOnCurrentRecord;
- public Biff8DecryptingStream(InputStream in, int initialOffset, EncryptionInfo info) throws RecordFormatException {
+ public Biff8DecryptingStream(InputStream in, int initialOffset, EncryptionInfo info) throws RecordFormatException {
try {
byte[] initialBuf = IOUtils.safelyAllocate(initialOffset, MAX_RECORD_LENGTH);
- InputStream stream;
- if (initialOffset == 0) {
- stream = in;
- } else {
- stream = new PushbackInputStream(in, initialOffset);
- ((PushbackInputStream)stream).unread(initialBuf);
- }
+ InputStream stream;
+ if (initialOffset == 0) {
+ stream = in;
+ } else {
+ stream = new PushbackInputStream(in, initialOffset);
+ ((PushbackInputStream)stream).unread(initialBuf);
+ }
Decryptor dec = info.getDecryptor();
dec.setChunkSize(RC4_REKEYING_INTERVAL);
@@ -65,67 +65,67 @@ public final class Biff8DecryptingStream
} catch (Exception e) {
throw new RecordFormatException(e);
}
- }
+ }
- @Override
+ @Override
@SuppressForbidden("just delegating")
public int available() {
- return ccis.available();
- }
+ return ccis.available();
+ }
- /**
- * Reads an unsigned short value without decrypting
- */
- @Override
+ /**
+ * Reads an unsigned short value without decrypting
+ */
+ @Override
public int readRecordSID() {
- readPlain(buffer, 0, LittleEndianConsts.SHORT_SIZE);
- int sid = LittleEndian.getUShort(buffer, 0);
- shouldSkipEncryptionOnCurrentRecord = isNeverEncryptedRecord(sid);
- return sid;
- }
-
- /**
- * Reads an unsigned short value without decrypting
- */
- @Override
+ readPlain(buffer, 0, LittleEndianConsts.SHORT_SIZE);
+ int sid = LittleEndian.getUShort(buffer, 0);
+ shouldSkipEncryptionOnCurrentRecord = isNeverEncryptedRecord(sid);
+ return sid;
+ }
+
+ /**
+ * Reads an unsigned short value without decrypting
+ */
+ @Override
public int readDataSize() {
readPlain(buffer, 0, LittleEndianConsts.SHORT_SIZE);
int dataSize = LittleEndian.getUShort(buffer, 0);
ccis.setNextRecordSize(dataSize);
- return dataSize;
- }
+ return dataSize;
+ }
- @Override
+ @Override
public double readDouble() {
- long valueLongBits = readLong();
- double result = Double.longBitsToDouble(valueLongBits);
- if (Double.isNaN(result)) {
- // (Because Excel typically doesn't write NaN
- throw new RuntimeException("Did not expect to read NaN");
- }
- return result;
- }
+ long valueLongBits = readLong();
+ double result = Double.longBitsToDouble(valueLongBits);
+ if (Double.isNaN(result)) {
+ // (Because Excel typically doesn't write NaN
+ throw new RuntimeException("Did not expect to read NaN");
+ }
+ return result;
+ }
- @Override
+ @Override
public void readFully(byte[] buf) {
- readFully(buf, 0, buf.length);
- }
+ readFully(buf, 0, buf.length);
+ }
- @Override
+ @Override
public void readFully(byte[] buf, int off, int len) {
if (shouldSkipEncryptionOnCurrentRecord) {
readPlain(buf, off, buf.length);
} else {
ccis.readFully(buf, off, len);
}
- }
+ }
- @Override
+ @Override
public int readUByte() {
- return readByte() & 0xFF;
- }
+ return readByte() & 0xFF;
+ }
- @Override
+ @Override
public byte readByte() {
if (shouldSkipEncryptionOnCurrentRecord) {
readPlain(buffer, 0, LittleEndianConsts.BYTE_SIZE);
@@ -133,14 +133,14 @@ public final class Biff8DecryptingStream
} else {
return ccis.readByte();
}
- }
+ }
- @Override
+ @Override
public int readUShort() {
- return readShort() & 0xFFFF;
- }
+ return readShort() & 0xFFFF;
+ }
- @Override
+ @Override
public short readShort() {
if (shouldSkipEncryptionOnCurrentRecord) {
readPlain(buffer, 0, LittleEndianConsts.SHORT_SIZE);
@@ -148,9 +148,9 @@ public final class Biff8DecryptingStream
} else {
return ccis.readShort();
}
- }
+ }
- @Override
+ @Override
public int readInt() {
if (shouldSkipEncryptionOnCurrentRecord) {
readPlain(buffer, 0, LittleEndianConsts.INT_SIZE);
@@ -158,9 +158,9 @@ public final class Biff8DecryptingStream
} else {
return ccis.readInt();
}
- }
+ }
- @Override
+ @Override
public long readLong() {
if (shouldSkipEncryptionOnCurrentRecord) {
readPlain(buffer, 0, LittleEndianConsts.LONG_SIZE);
@@ -168,14 +168,14 @@ public final class Biff8DecryptingStream
} else {
return ccis.readLong();
}
- }
+ }
- /**
- * @return the absolute position in the stream
- */
- public long getPosition() {
- return ccis.getPos();
- }
+ /**
+ * @return the absolute position in the stream
+ */
+ public long getPosition() {
+ return ccis.getPos();
+ }
/**
* TODO: Additionally, the lbPlyPos (position_of_BOF) field of the BoundSheet8 record MUST NOT be encrypted.
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/crypto/Biff8EncryptionKey.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/crypto/Biff8EncryptionKey.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/crypto/Biff8EncryptionKey.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/crypto/Biff8EncryptionKey.java Sat May 22 20:56:44 2021
@@ -19,31 +19,31 @@ package org.apache.poi.hssf.record.crypt
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public final class Biff8EncryptionKey {
- /**
- * Stores the BIFF8 encryption/decryption password for the current thread. This has been done
- * using a {@link ThreadLocal} in order to avoid further overloading the various public APIs
- * (e.g. {@link HSSFWorkbook}) that need this functionality.
- */
- private static final ThreadLocal<String> _userPasswordTLS = new ThreadLocal<>();
+ /**
+ * Stores the BIFF8 encryption/decryption password for the current thread. This has been done
+ * using a {@link ThreadLocal} in order to avoid further overloading the various public APIs
+ * (e.g. {@link HSSFWorkbook}) that need this functionality.
+ */
+ private static final ThreadLocal<String> _userPasswordTLS = new ThreadLocal<>();
- /**
- * Sets the BIFF8 encryption/decryption password for the current thread.
- *
- * @param password pass <code>null</code> to clear user password (and use default)
- */
- public static void setCurrentUserPassword(String password) {
- if (password == null) {
- _userPasswordTLS.remove();
- } else {
- _userPasswordTLS.set(password);
- }
- }
+ /**
+ * Sets the BIFF8 encryption/decryption password for the current thread.
+ *
+ * @param password pass <code>null</code> to clear user password (and use default)
+ */
+ public static void setCurrentUserPassword(String password) {
+ if (password == null) {
+ _userPasswordTLS.remove();
+ } else {
+ _userPasswordTLS.set(password);
+ }
+ }
- /**
- * @return the BIFF8 encryption/decryption password for the current thread.
- * <code>null</code> if it is currently unset.
- */
- public static String getCurrentUserPassword() {
- return _userPasswordTLS.get();
- }
+ /**
+ * @return the BIFF8 encryption/decryption password for the current thread.
+ * <code>null</code> if it is currently unset.
+ */
+ public static String getCurrentUserPassword() {
+ return _userPasswordTLS.get();
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/DataItemRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/DataItemRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/DataItemRecord.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/DataItemRecord.java Sat May 22 20:56:44 2021
@@ -31,80 +31,80 @@ import org.apache.poi.util.StringUtil;
* SXDI - Data Item (0x00C5)
*/
public final class DataItemRecord extends StandardRecord {
- public static final short sid = 0x00C5;
+ public static final short sid = 0x00C5;
- private int isxvdData;
- private int iiftab;
- private int df;
- private int isxvd;
- private int isxvi;
- private int ifmt;
- private String name;
-
- public DataItemRecord(DataItemRecord other) {
- super(other);
- isxvdData = other.isxvdData;
- iiftab = other.iiftab;
- df = other.df;
- isxvd = other.isxvd;
- isxvi = other.isxvi;
- ifmt = other.ifmt;
- name = other.name;
- }
-
- public DataItemRecord(RecordInputStream in) {
- isxvdData = in.readUShort();
- iiftab = in.readUShort();
- df = in.readUShort();
- isxvd = in.readUShort();
- isxvi = in.readUShort();
- ifmt = in.readUShort();
-
- name = in.readString();
- }
-
- @Override
- protected void serialize(LittleEndianOutput out) {
-
- out.writeShort(isxvdData);
- out.writeShort(iiftab);
- out.writeShort(df);
- out.writeShort(isxvd);
- out.writeShort(isxvi);
- out.writeShort(ifmt);
-
- StringUtil.writeUnicodeString(out, name);
- }
-
- @Override
- protected int getDataSize() {
- return 2 + 2 + 2 + 2 + 2 + 2 + StringUtil.getEncodedSize(name);
- }
-
- @Override
- public short getSid() {
- return sid;
- }
-
- @Override
- public DataItemRecord copy() {
- return new DataItemRecord(this);
- }
-
- @Override
- public HSSFRecordTypes getGenericRecordType() {
- return HSSFRecordTypes.DATA_ITEM;
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return GenericRecordUtil.getGenericProperties(
- "isxvdData", () -> isxvdData,
- "iiftab", () -> iiftab,
- "df", () -> df,
- "isxvd", () -> isxvd,
- "isxvi", () -> isxvi,
- "ifmt", () -> ifmt
- );
- }
+ private int isxvdData;
+ private int iiftab;
+ private int df;
+ private int isxvd;
+ private int isxvi;
+ private int ifmt;
+ private String name;
+
+ public DataItemRecord(DataItemRecord other) {
+ super(other);
+ isxvdData = other.isxvdData;
+ iiftab = other.iiftab;
+ df = other.df;
+ isxvd = other.isxvd;
+ isxvi = other.isxvi;
+ ifmt = other.ifmt;
+ name = other.name;
+ }
+
+ public DataItemRecord(RecordInputStream in) {
+ isxvdData = in.readUShort();
+ iiftab = in.readUShort();
+ df = in.readUShort();
+ isxvd = in.readUShort();
+ isxvi = in.readUShort();
+ ifmt = in.readUShort();
+
+ name = in.readString();
+ }
+
+ @Override
+ protected void serialize(LittleEndianOutput out) {
+
+ out.writeShort(isxvdData);
+ out.writeShort(iiftab);
+ out.writeShort(df);
+ out.writeShort(isxvd);
+ out.writeShort(isxvi);
+ out.writeShort(ifmt);
+
+ StringUtil.writeUnicodeString(out, name);
+ }
+
+ @Override
+ protected int getDataSize() {
+ return 2 + 2 + 2 + 2 + 2 + 2 + StringUtil.getEncodedSize(name);
+ }
+
+ @Override
+ public short getSid() {
+ return sid;
+ }
+
+ @Override
+ public DataItemRecord copy() {
+ return new DataItemRecord(this);
+ }
+
+ @Override
+ public HSSFRecordTypes getGenericRecordType() {
+ return HSSFRecordTypes.DATA_ITEM;
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return GenericRecordUtil.getGenericProperties(
+ "isxvdData", () -> isxvdData,
+ "iiftab", () -> iiftab,
+ "df", () -> df,
+ "isxvd", () -> isxvd,
+ "isxvi", () -> isxvi,
+ "ifmt", () -> ifmt
+ );
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/ExtendedPivotTableViewFieldsRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/ExtendedPivotTableViewFieldsRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/ExtendedPivotTableViewFieldsRecord.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/ExtendedPivotTableViewFieldsRecord.java Sat May 22 20:56:44 2021
@@ -32,115 +32,115 @@ import org.apache.poi.util.StringUtil;
* SXVDEX - Extended PivotTable View Fields (0x0100)
*/
public final class ExtendedPivotTableViewFieldsRecord extends StandardRecord {
- public static final short sid = 0x0100;
+ public static final short sid = 0x0100;
- /** the value of the subname length when the {@link #_subtotalName} is not present */
- private static final int STRING_NOT_PRESENT_LEN = 0xFFFF;
+ /** the value of the subname length when the {@link #_subtotalName} is not present */
+ private static final int STRING_NOT_PRESENT_LEN = 0xFFFF;
- private int _grbit1;
- private int _grbit2;
- private int _citmShow;
- private int _isxdiSort;
- private int _isxdiShow;
- private int _reserved1;
- private int _reserved2;
- /** custom sub-total name */
- private String _subtotalName;
-
- public ExtendedPivotTableViewFieldsRecord(ExtendedPivotTableViewFieldsRecord other) {
- super(other);
- _grbit1 = other._grbit1;
- _grbit2 = other._grbit2;
- _citmShow = other._citmShow;
- _isxdiSort = other._isxdiSort;
- _isxdiShow = other._isxdiShow;
- _reserved1 = other._reserved1;
- _reserved2 = other._reserved2;
- _subtotalName = other._subtotalName;
- }
-
- public ExtendedPivotTableViewFieldsRecord(RecordInputStream in) {
- _grbit1 = in.readInt();
- _grbit2 = in.readUByte();
- _citmShow = in.readUByte();
- _isxdiSort = in.readUShort();
- _isxdiShow = in.readUShort();
- // This record seems to have different valid encodings
- switch (in.remaining()) {
- case 0:
- // as per "Microsoft Excel Developer's Kit" book
- // older version of SXVDEX - doesn't seem to have a sub-total name
- _reserved1 = 0;
- _reserved2 = 0;
- _subtotalName = null;
- return;
- case 10:
- // as per "MICROSOFT OFFICE EXCEL 97-2007 BINARY FILE FORMAT SPECIFICATION" pdf
- break;
- default:
- throw new RecordFormatException("Unexpected remaining size (" + in.remaining() + ")");
- }
- int cchSubName = in.readUShort();
- _reserved1 = in.readInt();
- _reserved2 = in.readInt();
- if (cchSubName != STRING_NOT_PRESENT_LEN) {
- _subtotalName = in.readUnicodeLEString(cchSubName);
- }
- }
-
- @Override
- protected void serialize(LittleEndianOutput out) {
-
- out.writeInt(_grbit1);
- out.writeByte(_grbit2);
- out.writeByte(_citmShow);
- out.writeShort(_isxdiSort);
- out.writeShort(_isxdiShow);
-
- if (_subtotalName == null) {
- out.writeShort(STRING_NOT_PRESENT_LEN);
- } else {
- out.writeShort(_subtotalName.length());
- }
-
- out.writeInt(_reserved1);
- out.writeInt(_reserved2);
- if (_subtotalName != null) {
- StringUtil.putUnicodeLE(_subtotalName, out);
- }
- }
-
- @Override
- protected int getDataSize() {
-
- return 4 + 1 + 1 + 2 + 2 + 2 + 4 + 4 +
- (_subtotalName == null ? 0 : (2*_subtotalName.length())); // in unicode
- }
-
- @Override
- public short getSid() {
- return sid;
- }
-
- @Override
- public ExtendedPivotTableViewFieldsRecord copy() {
- return new ExtendedPivotTableViewFieldsRecord(this);
- }
-
- @Override
- public HSSFRecordTypes getGenericRecordType() {
- return HSSFRecordTypes.EXTENDED_PIVOT_TABLE_VIEW_FIELDS;
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return GenericRecordUtil.getGenericProperties(
- "grbit1", () -> _grbit1,
- "grbit2", () -> _grbit2,
- "citmShow", () -> _citmShow,
- "isxdiSort", () -> _isxdiSort,
- "isxdiShow", () -> _isxdiShow,
- "subtotalName", () -> _subtotalName
- );
- }
+ private int _grbit1;
+ private int _grbit2;
+ private int _citmShow;
+ private int _isxdiSort;
+ private int _isxdiShow;
+ private int _reserved1;
+ private int _reserved2;
+ /** custom sub-total name */
+ private String _subtotalName;
+
+ public ExtendedPivotTableViewFieldsRecord(ExtendedPivotTableViewFieldsRecord other) {
+ super(other);
+ _grbit1 = other._grbit1;
+ _grbit2 = other._grbit2;
+ _citmShow = other._citmShow;
+ _isxdiSort = other._isxdiSort;
+ _isxdiShow = other._isxdiShow;
+ _reserved1 = other._reserved1;
+ _reserved2 = other._reserved2;
+ _subtotalName = other._subtotalName;
+ }
+
+ public ExtendedPivotTableViewFieldsRecord(RecordInputStream in) {
+ _grbit1 = in.readInt();
+ _grbit2 = in.readUByte();
+ _citmShow = in.readUByte();
+ _isxdiSort = in.readUShort();
+ _isxdiShow = in.readUShort();
+ // This record seems to have different valid encodings
+ switch (in.remaining()) {
+ case 0:
+ // as per "Microsoft Excel Developer's Kit" book
+ // older version of SXVDEX - doesn't seem to have a sub-total name
+ _reserved1 = 0;
+ _reserved2 = 0;
+ _subtotalName = null;
+ return;
+ case 10:
+ // as per "MICROSOFT OFFICE EXCEL 97-2007 BINARY FILE FORMAT SPECIFICATION" pdf
+ break;
+ default:
+ throw new RecordFormatException("Unexpected remaining size (" + in.remaining() + ")");
+ }
+ int cchSubName = in.readUShort();
+ _reserved1 = in.readInt();
+ _reserved2 = in.readInt();
+ if (cchSubName != STRING_NOT_PRESENT_LEN) {
+ _subtotalName = in.readUnicodeLEString(cchSubName);
+ }
+ }
+
+ @Override
+ protected void serialize(LittleEndianOutput out) {
+
+ out.writeInt(_grbit1);
+ out.writeByte(_grbit2);
+ out.writeByte(_citmShow);
+ out.writeShort(_isxdiSort);
+ out.writeShort(_isxdiShow);
+
+ if (_subtotalName == null) {
+ out.writeShort(STRING_NOT_PRESENT_LEN);
+ } else {
+ out.writeShort(_subtotalName.length());
+ }
+
+ out.writeInt(_reserved1);
+ out.writeInt(_reserved2);
+ if (_subtotalName != null) {
+ StringUtil.putUnicodeLE(_subtotalName, out);
+ }
+ }
+
+ @Override
+ protected int getDataSize() {
+
+ return 4 + 1 + 1 + 2 + 2 + 2 + 4 + 4 +
+ (_subtotalName == null ? 0 : (2*_subtotalName.length())); // in unicode
+ }
+
+ @Override
+ public short getSid() {
+ return sid;
+ }
+
+ @Override
+ public ExtendedPivotTableViewFieldsRecord copy() {
+ return new ExtendedPivotTableViewFieldsRecord(this);
+ }
+
+ @Override
+ public HSSFRecordTypes getGenericRecordType() {
+ return HSSFRecordTypes.EXTENDED_PIVOT_TABLE_VIEW_FIELDS;
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return GenericRecordUtil.getGenericProperties(
+ "grbit1", () -> _grbit1,
+ "grbit2", () -> _grbit2,
+ "citmShow", () -> _citmShow,
+ "isxdiSort", () -> _isxdiSort,
+ "isxdiShow", () -> _isxdiShow,
+ "subtotalName", () -> _subtotalName
+ );
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/PageItemRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/PageItemRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/PageItemRecord.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/PageItemRecord.java Sat May 22 20:56:44 2021
@@ -33,96 +33,96 @@ import org.apache.poi.util.RecordFormatE
* SXPI - Page Item (0x00B6)
*/
public final class PageItemRecord extends StandardRecord {
- public static final short sid = 0x00B6;
+ public static final short sid = 0x00B6;
- private static final class FieldInfo implements GenericRecord {
- public static final int ENCODED_SIZE = 6;
- /** Index to the View Item SXVI(0x00B2) record */
- private int _isxvi;
- /** Index to the {@link ViewFieldsRecord} SXVD(0x00B1) record */
- private int _isxvd;
- /** Object ID for the drop-down arrow */
- private int _idObj;
-
- public FieldInfo(FieldInfo other) {
- _isxvi = other._isxvi;
- _isxvd = other._isxvd;
- _idObj = other._idObj;
- }
-
- public FieldInfo(RecordInputStream in) {
- _isxvi = in.readShort();
- _isxvd = in.readShort();
- _idObj = in.readShort();
- }
-
- private void serialize(LittleEndianOutput out) {
- out.writeShort(_isxvi);
- out.writeShort(_isxvd);
- out.writeShort(_idObj);
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return GenericRecordUtil.getGenericProperties(
- "isxvi", () -> _isxvi,
- "isxvd", () -> _isxvd,
- "idObj", () -> _idObj
- );
- }
- }
-
- private final FieldInfo[] _fieldInfos;
-
- public PageItemRecord(PageItemRecord other) {
- super(other);
- _fieldInfos = Stream.of(other._fieldInfos).map(FieldInfo::new).toArray(FieldInfo[]::new);
- }
-
- public PageItemRecord(RecordInputStream in) {
- int dataSize = in.remaining();
- if (dataSize % FieldInfo.ENCODED_SIZE != 0) {
- throw new RecordFormatException("Bad data size " + dataSize);
- }
-
- int nItems = dataSize / FieldInfo.ENCODED_SIZE;
-
- FieldInfo[] fis = new FieldInfo[nItems];
- for (int i = 0; i < fis.length; i++) {
- fis[i] = new FieldInfo(in);
- }
- _fieldInfos = fis;
- }
-
- @Override
- protected void serialize(LittleEndianOutput out) {
- for (FieldInfo fieldInfo : _fieldInfos) {
- fieldInfo.serialize(out);
- }
- }
-
- @Override
- protected int getDataSize() {
- return _fieldInfos.length * FieldInfo.ENCODED_SIZE;
- }
-
- @Override
- public short getSid() {
- return sid;
- }
-
- @Override
- public PageItemRecord copy() {
- return new PageItemRecord(this);
- }
-
- @Override
- public HSSFRecordTypes getGenericRecordType() {
- return HSSFRecordTypes.PAGE_ITEM;
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return GenericRecordUtil.getGenericProperties("fieldInfos", () -> _fieldInfos);
- }
+ private static final class FieldInfo implements GenericRecord {
+ public static final int ENCODED_SIZE = 6;
+ /** Index to the View Item SXVI(0x00B2) record */
+ private int _isxvi;
+ /** Index to the {@link ViewFieldsRecord} SXVD(0x00B1) record */
+ private int _isxvd;
+ /** Object ID for the drop-down arrow */
+ private int _idObj;
+
+ public FieldInfo(FieldInfo other) {
+ _isxvi = other._isxvi;
+ _isxvd = other._isxvd;
+ _idObj = other._idObj;
+ }
+
+ public FieldInfo(RecordInputStream in) {
+ _isxvi = in.readShort();
+ _isxvd = in.readShort();
+ _idObj = in.readShort();
+ }
+
+ private void serialize(LittleEndianOutput out) {
+ out.writeShort(_isxvi);
+ out.writeShort(_isxvd);
+ out.writeShort(_idObj);
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return GenericRecordUtil.getGenericProperties(
+ "isxvi", () -> _isxvi,
+ "isxvd", () -> _isxvd,
+ "idObj", () -> _idObj
+ );
+ }
+ }
+
+ private final FieldInfo[] _fieldInfos;
+
+ public PageItemRecord(PageItemRecord other) {
+ super(other);
+ _fieldInfos = Stream.of(other._fieldInfos).map(FieldInfo::new).toArray(FieldInfo[]::new);
+ }
+
+ public PageItemRecord(RecordInputStream in) {
+ int dataSize = in.remaining();
+ if (dataSize % FieldInfo.ENCODED_SIZE != 0) {
+ throw new RecordFormatException("Bad data size " + dataSize);
+ }
+
+ int nItems = dataSize / FieldInfo.ENCODED_SIZE;
+
+ FieldInfo[] fis = new FieldInfo[nItems];
+ for (int i = 0; i < fis.length; i++) {
+ fis[i] = new FieldInfo(in);
+ }
+ _fieldInfos = fis;
+ }
+
+ @Override
+ protected void serialize(LittleEndianOutput out) {
+ for (FieldInfo fieldInfo : _fieldInfos) {
+ fieldInfo.serialize(out);
+ }
+ }
+
+ @Override
+ protected int getDataSize() {
+ return _fieldInfos.length * FieldInfo.ENCODED_SIZE;
+ }
+
+ @Override
+ public short getSid() {
+ return sid;
+ }
+
+ @Override
+ public PageItemRecord copy() {
+ return new PageItemRecord(this);
+ }
+
+ @Override
+ public HSSFRecordTypes getGenericRecordType() {
+ return HSSFRecordTypes.PAGE_ITEM;
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return GenericRecordUtil.getGenericProperties("fieldInfos", () -> _fieldInfos);
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/StreamIDRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/StreamIDRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/StreamIDRecord.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/StreamIDRecord.java Sat May 22 20:56:44 2021
@@ -30,46 +30,46 @@ import org.apache.poi.util.LittleEndianO
* SXIDSTM - Stream ID (0x00D5)
*/
public final class StreamIDRecord extends StandardRecord {
- public static final short sid = 0x00D5;
+ public static final short sid = 0x00D5;
- private int idstm;
+ private int idstm;
- public StreamIDRecord(StreamIDRecord other) {
- super(other);
- idstm = other.idstm;
- }
-
- public StreamIDRecord(RecordInputStream in) {
- idstm = in.readShort();
- }
-
- @Override
- protected void serialize(LittleEndianOutput out) {
- out.writeShort(idstm);
- }
-
- @Override
- protected int getDataSize() {
- return 2;
- }
-
- @Override
- public short getSid() {
- return sid;
- }
-
- @Override
- public StreamIDRecord copy() {
- return new StreamIDRecord(this);
- }
-
- @Override
- public HSSFRecordTypes getGenericRecordType() {
- return HSSFRecordTypes.STREAM_ID;
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return GenericRecordUtil.getGenericProperties("idstm", () -> idstm);
- }
+ public StreamIDRecord(StreamIDRecord other) {
+ super(other);
+ idstm = other.idstm;
+ }
+
+ public StreamIDRecord(RecordInputStream in) {
+ idstm = in.readShort();
+ }
+
+ @Override
+ protected void serialize(LittleEndianOutput out) {
+ out.writeShort(idstm);
+ }
+
+ @Override
+ protected int getDataSize() {
+ return 2;
+ }
+
+ @Override
+ public short getSid() {
+ return sid;
+ }
+
+ @Override
+ public StreamIDRecord copy() {
+ return new StreamIDRecord(this);
+ }
+
+ @Override
+ public HSSFRecordTypes getGenericRecordType() {
+ return HSSFRecordTypes.STREAM_ID;
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return GenericRecordUtil.getGenericProperties("idstm", () -> idstm);
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/ViewDefinitionRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/ViewDefinitionRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/ViewDefinitionRecord.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/ViewDefinitionRecord.java Sat May 22 20:56:44 2021
@@ -32,168 +32,168 @@ import org.apache.poi.util.StringUtil;
* SXVIEW - View Definition (0x00B0)<br>
*/
public final class ViewDefinitionRecord extends StandardRecord {
- public static final short sid = 0x00B0;
+ public static final short sid = 0x00B0;
- private int rwFirst;
- private int rwLast;
- private int colFirst;
- private int colLast;
- private int rwFirstHead;
- private int rwFirstData;
- private int colFirstData;
- private int iCache;
- private int reserved;
-
- private int sxaxis4Data;
- private int ipos4Data;
- private int cDim;
-
- private int cDimRw;
-
- private int cDimCol;
- private int cDimPg;
-
- private int cDimData;
- private int cRw;
- private int cCol;
- private int grbit;
- private int itblAutoFmt;
-
- private String dataField;
- private String name;
-
-
- public ViewDefinitionRecord(ViewDefinitionRecord other) {
- super(other);
- rwFirst = other.rwFirst;
- rwLast = other.rwLast;
- colFirst = other.colFirst;
- colLast = other.colLast;
- rwFirstHead = other.rwFirstHead;
- rwFirstData = other.rwFirstData;
- colFirstData = other.colFirstData;
- iCache = other.iCache;
- reserved = other.reserved;
- sxaxis4Data = other.sxaxis4Data;
- ipos4Data = other.ipos4Data;
- cDim = other.cDim;
- cDimRw = other.cDimRw;
- cDimCol = other.cDimCol;
- cDimPg = other.cDimPg;
- cDimData = other.cDimData;
- cRw = other.cRw;
- cCol = other.cCol;
- grbit = other.grbit;
- itblAutoFmt = other.itblAutoFmt;
- name = other.name;
- dataField = other.dataField;
- }
-
- public ViewDefinitionRecord(RecordInputStream in) {
- rwFirst = in.readUShort();
- rwLast = in.readUShort();
- colFirst = in.readUShort();
- colLast = in.readUShort();
- rwFirstHead = in.readUShort();
- rwFirstData = in.readUShort();
- colFirstData = in.readUShort();
- iCache = in.readUShort();
- reserved = in.readUShort();
- sxaxis4Data = in.readUShort();
- ipos4Data = in.readUShort();
- cDim = in.readUShort();
- cDimRw = in.readUShort();
- cDimCol = in.readUShort();
- cDimPg = in.readUShort();
- cDimData = in.readUShort();
- cRw = in.readUShort();
- cCol = in.readUShort();
- grbit = in.readUShort();
- itblAutoFmt = in.readUShort();
- int cchName = in.readUShort();
- int cchData = in.readUShort();
-
- name = StringUtil.readUnicodeString(in, cchName);
- dataField = StringUtil.readUnicodeString(in, cchData);
- }
-
- @Override
- protected void serialize(LittleEndianOutput out) {
- out.writeShort(rwFirst);
- out.writeShort(rwLast);
- out.writeShort(colFirst);
- out.writeShort(colLast);
- out.writeShort(rwFirstHead);
- out.writeShort(rwFirstData);
- out.writeShort(colFirstData);
- out.writeShort(iCache);
- out.writeShort(reserved);
- out.writeShort(sxaxis4Data);
- out.writeShort(ipos4Data);
- out.writeShort(cDim);
- out.writeShort(cDimRw);
- out.writeShort(cDimCol);
- out.writeShort(cDimPg);
- out.writeShort(cDimData);
- out.writeShort(cRw);
- out.writeShort(cCol);
- out.writeShort(grbit);
- out.writeShort(itblAutoFmt);
- out.writeShort(name.length());
- out.writeShort(dataField.length());
-
- StringUtil.writeUnicodeStringFlagAndData(out, name);
- StringUtil.writeUnicodeStringFlagAndData(out, dataField);
- }
-
- @Override
- protected int getDataSize() {
- return 40 + // 20 short fields (rwFirst ... itblAutoFmt)
- StringUtil.getEncodedSize(name) + StringUtil.getEncodedSize(dataField) ;
- }
-
- @Override
- public short getSid() {
- return sid;
- }
-
- @Override
- public ViewDefinitionRecord copy() {
- return new ViewDefinitionRecord(this);
- }
-
- @Override
- public HSSFRecordTypes getGenericRecordType() {
- return HSSFRecordTypes.VIEW_DEFINITION;
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- final Map<String,Supplier<?>> m = new LinkedHashMap<>();
-
- m.put("rwFirst", () -> rwFirst);
- m.put("rwLast", () -> rwLast);
- m.put("colFirst", () -> colFirst);
- m.put("colLast", () -> colLast);
- m.put("rwFirstHead", () -> rwFirstHead);
- m.put("rwFirstData", () -> rwFirstData);
- m.put("colFirstData", () -> colFirstData);
- m.put("iCache", () -> iCache);
- m.put("reserved", () -> reserved);
- m.put("sxaxis4Data", () -> sxaxis4Data);
- m.put("ipos4Data", () -> ipos4Data);
- m.put("cDim", () -> cDim);
- m.put("cDimRw", () -> cDimRw);
- m.put("cDimCol", () -> cDimCol);
- m.put("cDimPg", () -> cDimPg);
- m.put("cDimData", () -> cDimData);
- m.put("cRw", () -> cRw);
- m.put("cCol", () -> cCol);
- m.put("grbit", () -> grbit);
- m.put("itblAutoFmt", () -> itblAutoFmt);
- m.put("name", () -> name);
- m.put("dataField", () -> dataField);
+ private int rwFirst;
+ private int rwLast;
+ private int colFirst;
+ private int colLast;
+ private int rwFirstHead;
+ private int rwFirstData;
+ private int colFirstData;
+ private int iCache;
+ private int reserved;
+
+ private int sxaxis4Data;
+ private int ipos4Data;
+ private int cDim;
+
+ private int cDimRw;
+
+ private int cDimCol;
+ private int cDimPg;
+
+ private int cDimData;
+ private int cRw;
+ private int cCol;
+ private int grbit;
+ private int itblAutoFmt;
+
+ private String dataField;
+ private String name;
+
+
+ public ViewDefinitionRecord(ViewDefinitionRecord other) {
+ super(other);
+ rwFirst = other.rwFirst;
+ rwLast = other.rwLast;
+ colFirst = other.colFirst;
+ colLast = other.colLast;
+ rwFirstHead = other.rwFirstHead;
+ rwFirstData = other.rwFirstData;
+ colFirstData = other.colFirstData;
+ iCache = other.iCache;
+ reserved = other.reserved;
+ sxaxis4Data = other.sxaxis4Data;
+ ipos4Data = other.ipos4Data;
+ cDim = other.cDim;
+ cDimRw = other.cDimRw;
+ cDimCol = other.cDimCol;
+ cDimPg = other.cDimPg;
+ cDimData = other.cDimData;
+ cRw = other.cRw;
+ cCol = other.cCol;
+ grbit = other.grbit;
+ itblAutoFmt = other.itblAutoFmt;
+ name = other.name;
+ dataField = other.dataField;
+ }
+
+ public ViewDefinitionRecord(RecordInputStream in) {
+ rwFirst = in.readUShort();
+ rwLast = in.readUShort();
+ colFirst = in.readUShort();
+ colLast = in.readUShort();
+ rwFirstHead = in.readUShort();
+ rwFirstData = in.readUShort();
+ colFirstData = in.readUShort();
+ iCache = in.readUShort();
+ reserved = in.readUShort();
+ sxaxis4Data = in.readUShort();
+ ipos4Data = in.readUShort();
+ cDim = in.readUShort();
+ cDimRw = in.readUShort();
+ cDimCol = in.readUShort();
+ cDimPg = in.readUShort();
+ cDimData = in.readUShort();
+ cRw = in.readUShort();
+ cCol = in.readUShort();
+ grbit = in.readUShort();
+ itblAutoFmt = in.readUShort();
+ int cchName = in.readUShort();
+ int cchData = in.readUShort();
+
+ name = StringUtil.readUnicodeString(in, cchName);
+ dataField = StringUtil.readUnicodeString(in, cchData);
+ }
+
+ @Override
+ protected void serialize(LittleEndianOutput out) {
+ out.writeShort(rwFirst);
+ out.writeShort(rwLast);
+ out.writeShort(colFirst);
+ out.writeShort(colLast);
+ out.writeShort(rwFirstHead);
+ out.writeShort(rwFirstData);
+ out.writeShort(colFirstData);
+ out.writeShort(iCache);
+ out.writeShort(reserved);
+ out.writeShort(sxaxis4Data);
+ out.writeShort(ipos4Data);
+ out.writeShort(cDim);
+ out.writeShort(cDimRw);
+ out.writeShort(cDimCol);
+ out.writeShort(cDimPg);
+ out.writeShort(cDimData);
+ out.writeShort(cRw);
+ out.writeShort(cCol);
+ out.writeShort(grbit);
+ out.writeShort(itblAutoFmt);
+ out.writeShort(name.length());
+ out.writeShort(dataField.length());
+
+ StringUtil.writeUnicodeStringFlagAndData(out, name);
+ StringUtil.writeUnicodeStringFlagAndData(out, dataField);
+ }
+
+ @Override
+ protected int getDataSize() {
+ return 40 + // 20 short fields (rwFirst ... itblAutoFmt)
+ StringUtil.getEncodedSize(name) + StringUtil.getEncodedSize(dataField) ;
+ }
+
+ @Override
+ public short getSid() {
+ return sid;
+ }
+
+ @Override
+ public ViewDefinitionRecord copy() {
+ return new ViewDefinitionRecord(this);
+ }
+
+ @Override
+ public HSSFRecordTypes getGenericRecordType() {
+ return HSSFRecordTypes.VIEW_DEFINITION;
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ final Map<String,Supplier<?>> m = new LinkedHashMap<>();
+
+ m.put("rwFirst", () -> rwFirst);
+ m.put("rwLast", () -> rwLast);
+ m.put("colFirst", () -> colFirst);
+ m.put("colLast", () -> colLast);
+ m.put("rwFirstHead", () -> rwFirstHead);
+ m.put("rwFirstData", () -> rwFirstData);
+ m.put("colFirstData", () -> colFirstData);
+ m.put("iCache", () -> iCache);
+ m.put("reserved", () -> reserved);
+ m.put("sxaxis4Data", () -> sxaxis4Data);
+ m.put("ipos4Data", () -> ipos4Data);
+ m.put("cDim", () -> cDim);
+ m.put("cDimRw", () -> cDimRw);
+ m.put("cDimCol", () -> cDimCol);
+ m.put("cDimPg", () -> cDimPg);
+ m.put("cDimData", () -> cDimData);
+ m.put("cRw", () -> cRw);
+ m.put("cCol", () -> cCol);
+ m.put("grbit", () -> grbit);
+ m.put("itblAutoFmt", () -> itblAutoFmt);
+ m.put("name", () -> name);
+ m.put("dataField", () -> dataField);
- return Collections.unmodifiableMap(m);
- }
+ return Collections.unmodifiableMap(m);
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/ViewFieldsRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/ViewFieldsRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/ViewFieldsRecord.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/ViewFieldsRecord.java Sat May 22 20:56:44 2021
@@ -31,109 +31,109 @@ import org.apache.poi.util.StringUtil;
* SXVD - View Fields (0x00B1)
*/
public final class ViewFieldsRecord extends StandardRecord {
- public static final short sid = 0x00B1;
+ public static final short sid = 0x00B1;
- /** the value of the {@code cchName} field when the {@link #_name} is not present */
- private static final int STRING_NOT_PRESENT_LEN = 0xFFFF;
- /** 5 shorts */
- private static final int BASE_SIZE = 10;
-
- private final int _sxaxis;
- private final int _cSub;
- private final int _grbitSub;
- private final int _cItm;
-
- private String _name;
-
- /**
- * values for the {@link ViewFieldsRecord#_sxaxis} field
- */
- private enum Axis {
- NO_AXIS(0),
- ROW(1),
- COLUMN(2),
- PAGE(4),
- DATA(8);
- final int id;
- Axis(int id) {
- this.id = id;
- }
- }
-
- public ViewFieldsRecord(ViewFieldsRecord other) {
- super(other);
- _sxaxis = other._sxaxis;
- _cSub = other._cSub;
- _grbitSub = other._grbitSub;
- _cItm = other._cItm;
- _name = other._name;
- }
-
- public ViewFieldsRecord(RecordInputStream in) {
- _sxaxis = in.readShort();
- _cSub = in.readShort();
- _grbitSub = in.readShort();
- _cItm = in.readShort();
-
- int cchName = in.readUShort();
- if (cchName != STRING_NOT_PRESENT_LEN) {
- int flag = in.readByte();
- if ((flag & 0x01) != 0) {
- _name = in.readUnicodeLEString(cchName);
- } else {
- _name = in.readCompressedUnicode(cchName);
- }
- }
- }
-
- @Override
- protected void serialize(LittleEndianOutput out) {
-
- out.writeShort(_sxaxis);
- out.writeShort(_cSub);
- out.writeShort(_grbitSub);
- out.writeShort(_cItm);
-
- if (_name != null) {
- StringUtil.writeUnicodeString(out, _name);
- } else {
- out.writeShort(STRING_NOT_PRESENT_LEN);
- }
- }
-
- @Override
- protected int getDataSize() {
- if (_name == null) {
- return BASE_SIZE;
- }
- return BASE_SIZE
- + 1 // unicode flag
- + _name.length() * (StringUtil.hasMultibyte(_name) ? 2 : 1);
- }
-
- @Override
- public short getSid() {
- return sid;
- }
-
- @Override
- public ViewFieldsRecord copy() {
- return new ViewFieldsRecord(this);
- }
-
- @Override
- public HSSFRecordTypes getGenericRecordType() {
- return HSSFRecordTypes.VIEW_FIELDS;
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return GenericRecordUtil.getGenericProperties(
- "sxaxis", () -> _sxaxis,
- "cSub", () -> _cSub,
- "grbitSub", () -> _grbitSub,
- "cItm", () -> _cItm,
- "name", () -> _name
- );
- }
+ /** the value of the {@code cchName} field when the {@link #_name} is not present */
+ private static final int STRING_NOT_PRESENT_LEN = 0xFFFF;
+ /** 5 shorts */
+ private static final int BASE_SIZE = 10;
+
+ private final int _sxaxis;
+ private final int _cSub;
+ private final int _grbitSub;
+ private final int _cItm;
+
+ private String _name;
+
+ /**
+ * values for the {@link ViewFieldsRecord#_sxaxis} field
+ */
+ private enum Axis {
+ NO_AXIS(0),
+ ROW(1),
+ COLUMN(2),
+ PAGE(4),
+ DATA(8);
+ final int id;
+ Axis(int id) {
+ this.id = id;
+ }
+ }
+
+ public ViewFieldsRecord(ViewFieldsRecord other) {
+ super(other);
+ _sxaxis = other._sxaxis;
+ _cSub = other._cSub;
+ _grbitSub = other._grbitSub;
+ _cItm = other._cItm;
+ _name = other._name;
+ }
+
+ public ViewFieldsRecord(RecordInputStream in) {
+ _sxaxis = in.readShort();
+ _cSub = in.readShort();
+ _grbitSub = in.readShort();
+ _cItm = in.readShort();
+
+ int cchName = in.readUShort();
+ if (cchName != STRING_NOT_PRESENT_LEN) {
+ int flag = in.readByte();
+ if ((flag & 0x01) != 0) {
+ _name = in.readUnicodeLEString(cchName);
+ } else {
+ _name = in.readCompressedUnicode(cchName);
+ }
+ }
+ }
+
+ @Override
+ protected void serialize(LittleEndianOutput out) {
+
+ out.writeShort(_sxaxis);
+ out.writeShort(_cSub);
+ out.writeShort(_grbitSub);
+ out.writeShort(_cItm);
+
+ if (_name != null) {
+ StringUtil.writeUnicodeString(out, _name);
+ } else {
+ out.writeShort(STRING_NOT_PRESENT_LEN);
+ }
+ }
+
+ @Override
+ protected int getDataSize() {
+ if (_name == null) {
+ return BASE_SIZE;
+ }
+ return BASE_SIZE
+ + 1 // unicode flag
+ + _name.length() * (StringUtil.hasMultibyte(_name) ? 2 : 1);
+ }
+
+ @Override
+ public short getSid() {
+ return sid;
+ }
+
+ @Override
+ public ViewFieldsRecord copy() {
+ return new ViewFieldsRecord(this);
+ }
+
+ @Override
+ public HSSFRecordTypes getGenericRecordType() {
+ return HSSFRecordTypes.VIEW_FIELDS;
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return GenericRecordUtil.getGenericProperties(
+ "sxaxis", () -> _sxaxis,
+ "cSub", () -> _cSub,
+ "grbitSub", () -> _grbitSub,
+ "cItm", () -> _cItm,
+ "name", () -> _name
+ );
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/ViewSourceRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/ViewSourceRecord.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/ViewSourceRecord.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/record/pivottable/ViewSourceRecord.java Sat May 22 20:56:44 2021
@@ -30,46 +30,46 @@ import org.apache.poi.util.LittleEndianO
* SXVS - View Source (0x00E3)<br>
*/
public final class ViewSourceRecord extends StandardRecord {
- public static final short sid = 0x00E3;
+ public static final short sid = 0x00E3;
- private int vs;
+ private int vs;
- public ViewSourceRecord(ViewSourceRecord other) {
- super(other);
- vs = other.vs;
- }
-
- public ViewSourceRecord(RecordInputStream in) {
- vs = in.readShort();
- }
-
- @Override
- protected void serialize(LittleEndianOutput out) {
- out.writeShort(vs);
- }
-
- @Override
- protected int getDataSize() {
- return 2;
- }
-
- @Override
- public short getSid() {
- return sid;
- }
-
- @Override
- public ViewSourceRecord copy() {
- return new ViewSourceRecord(this);
- }
-
- @Override
- public HSSFRecordTypes getGenericRecordType() {
- return HSSFRecordTypes.VIEW_SOURCE;
- }
-
- @Override
- public Map<String, Supplier<?>> getGenericProperties() {
- return GenericRecordUtil.getGenericProperties("vs", () -> vs);
- }
+ public ViewSourceRecord(ViewSourceRecord other) {
+ super(other);
+ vs = other.vs;
+ }
+
+ public ViewSourceRecord(RecordInputStream in) {
+ vs = in.readShort();
+ }
+
+ @Override
+ protected void serialize(LittleEndianOutput out) {
+ out.writeShort(vs);
+ }
+
+ @Override
+ protected int getDataSize() {
+ return 2;
+ }
+
+ @Override
+ public short getSid() {
+ return sid;
+ }
+
+ @Override
+ public ViewSourceRecord copy() {
+ return new ViewSourceRecord(this);
+ }
+
+ @Override
+ public HSSFRecordTypes getGenericRecordType() {
+ return HSSFRecordTypes.VIEW_SOURCE;
+ }
+
+ @Override
+ public Map<String, Supplier<?>> getGenericProperties() {
+ return GenericRecordUtil.getGenericProperties("vs", () -> vs);
+ }
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/DVConstraint.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/DVConstraint.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/DVConstraint.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/DVConstraint.java Sat May 22 20:56:44 2021
@@ -38,414 +38,414 @@ import org.apache.poi.util.LocaleUtil;
* Data Validation Constraint
*/
public class DVConstraint implements DataValidationConstraint {
- /* package */ static final class FormulaPair {
+ /* package */ static final class FormulaPair {
- private final Ptg[] _formula1;
- private final Ptg[] _formula2;
+ private final Ptg[] _formula1;
+ private final Ptg[] _formula2;
- FormulaPair(Ptg[] formula1, Ptg[] formula2) {
- _formula1 = (formula1 == null) ? null : formula1.clone();
- _formula2 = (formula2 == null) ? null : formula2.clone();
- }
- public Ptg[] getFormula1() {
- return _formula1;
- }
- public Ptg[] getFormula2() {
- return _formula2;
- }
-
- }
-
- private final int _validationType;
- private int _operator;
- private String[] _explicitListValues;
-
- private String _formula1;
- private String _formula2;
- private Double _value1;
- private Double _value2;
-
-
- private DVConstraint(int validationType, int comparisonOperator, String formulaA,
- String formulaB, Double value1, Double value2, String[] explicitListValues) {
- _validationType = validationType;
- _operator = comparisonOperator;
- _formula1 = formulaA;
- _formula2 = formulaB;
- _value1 = value1;
- _value2 = value2;
- _explicitListValues = (explicitListValues == null) ? null : explicitListValues.clone();
- }
-
-
- /**
- * Creates a list constraint
- */
- private DVConstraint(String listFormula, String[] explicitListValues) {
- this(ValidationType.LIST, OperatorType.IGNORED,
- listFormula, null, null, null, explicitListValues);
- }
-
- /**
- * Creates a number based data validation constraint. The text values entered for expr1 and expr2
- * can be either standard Excel formulas or formatted number values. If the expression starts
- * with '=' it is parsed as a formula, otherwise it is parsed as a formatted number.
- *
- * @param validationType one of {@link org.apache.poi.ss.usermodel.DataValidationConstraint.ValidationType#ANY},
+ FormulaPair(Ptg[] formula1, Ptg[] formula2) {
+ _formula1 = (formula1 == null) ? null : formula1.clone();
+ _formula2 = (formula2 == null) ? null : formula2.clone();
+ }
+ public Ptg[] getFormula1() {
+ return _formula1;
+ }
+ public Ptg[] getFormula2() {
+ return _formula2;
+ }
+
+ }
+
+ private final int _validationType;
+ private int _operator;
+ private String[] _explicitListValues;
+
+ private String _formula1;
+ private String _formula2;
+ private Double _value1;
+ private Double _value2;
+
+
+ private DVConstraint(int validationType, int comparisonOperator, String formulaA,
+ String formulaB, Double value1, Double value2, String[] explicitListValues) {
+ _validationType = validationType;
+ _operator = comparisonOperator;
+ _formula1 = formulaA;
+ _formula2 = formulaB;
+ _value1 = value1;
+ _value2 = value2;
+ _explicitListValues = (explicitListValues == null) ? null : explicitListValues.clone();
+ }
+
+
+ /**
+ * Creates a list constraint
+ */
+ private DVConstraint(String listFormula, String[] explicitListValues) {
+ this(ValidationType.LIST, OperatorType.IGNORED,
+ listFormula, null, null, null, explicitListValues);
+ }
+
+ /**
+ * Creates a number based data validation constraint. The text values entered for expr1 and expr2
+ * can be either standard Excel formulas or formatted number values. If the expression starts
+ * with '=' it is parsed as a formula, otherwise it is parsed as a formatted number.
+ *
+ * @param validationType one of {@link org.apache.poi.ss.usermodel.DataValidationConstraint.ValidationType#ANY},
* {@link org.apache.poi.ss.usermodel.DataValidationConstraint.ValidationType#DECIMAL},
* {@link org.apache.poi.ss.usermodel.DataValidationConstraint.ValidationType#INTEGER},
* {@link org.apache.poi.ss.usermodel.DataValidationConstraint.ValidationType#TEXT_LENGTH}
- * @param comparisonOperator any constant from {@link org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType} enum
- * @param expr1 date formula (when first char is '=') or formatted number value
- * @param expr2 date formula (when first char is '=') or formatted number value
- */
- public static DVConstraint createNumericConstraint(int validationType, int comparisonOperator,
- String expr1, String expr2) {
- switch (validationType) {
- case ValidationType.ANY:
- if (expr1 != null || expr2 != null) {
- throw new IllegalArgumentException("expr1 and expr2 must be null for validation type 'any'");
- }
- break;
- case ValidationType.DECIMAL:
- case ValidationType.INTEGER:
- case ValidationType.TEXT_LENGTH:
- if (expr1 == null) {
- throw new IllegalArgumentException("expr1 must be supplied");
- }
- OperatorType.validateSecondArg(comparisonOperator, expr2);
- break;
- default:
- throw new IllegalArgumentException("Validation Type ("
- + validationType + ") not supported with this method");
- }
- // formula1 and value1 are mutually exclusive
- String formula1 = getFormulaFromTextExpression(expr1);
- Double value1 = formula1 == null ? convertNumber(expr1) : null;
- // formula2 and value2 are mutually exclusive
- String formula2 = getFormulaFromTextExpression(expr2);
- Double value2 = formula2 == null ? convertNumber(expr2) : null;
- return new DVConstraint(validationType, comparisonOperator, formula1, formula2, value1, value2, null);
- }
-
- public static DVConstraint createFormulaListConstraint(String listFormula) {
- return new DVConstraint(listFormula, null);
- }
- public static DVConstraint createExplicitListConstraint(String[] explicitListValues) {
- return new DVConstraint(null, explicitListValues);
- }
-
-
- /**
- * Creates a time based data validation constraint. The text values entered for expr1 and expr2
- * can be either standard Excel formulas or formatted time values. If the expression starts
- * with '=' it is parsed as a formula, otherwise it is parsed as a formatted time. To parse
- * formatted times, two formats are supported: "HH:MM" or "HH:MM:SS". This is contrary to
- * Excel which uses the default time format from the OS.
- *
- * @param comparisonOperator constant from {@link org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType} enum
- * @param expr1 date formula (when first char is '=') or formatted time value
- * @param expr2 date formula (when first char is '=') or formatted time value
- */
- public static DVConstraint createTimeConstraint(int comparisonOperator, String expr1, String expr2) {
- if (expr1 == null) {
- throw new IllegalArgumentException("expr1 must be supplied");
- }
- OperatorType.validateSecondArg(comparisonOperator, expr1);
-
- // formula1 and value1 are mutually exclusive
- String formula1 = getFormulaFromTextExpression(expr1);
- Double value1 = formula1 == null ? convertTime(expr1) : null;
- // formula2 and value2 are mutually exclusive
- String formula2 = getFormulaFromTextExpression(expr2);
- Double value2 = formula2 == null ? convertTime(expr2) : null;
- return new DVConstraint(ValidationType.TIME, comparisonOperator, formula1, formula2, value1, value2, null);
- }
-
- /**
- * Creates a date based data validation constraint. The text values entered for expr1 and expr2
- * can be either standard Excel formulas or formatted date values. If the expression starts
- * with '=' it is parsed as a formula, otherwise it is parsed as a formatted date (Excel uses
- * the same convention). To parse formatted dates, a date format needs to be specified. This
- * is contrary to Excel which uses the default short date format from the OS.
- *
- * @param comparisonOperator constant from {@link org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType} enum
- * @param expr1 date formula (when first char is '=') or formatted date value
- * @param expr2 date formula (when first char is '=') or formatted date value
- * @param dateFormat ignored if both expr1 and expr2 are formulas. Default value is "YYYY/MM/DD"
- * otherwise any other valid argument for {@code SimpleDateFormat} can be used
- * @see <a href='http://java.sun.com/j2se/1.5.0/docs/api/java/text/DateFormat.html'>SimpleDateFormat</a>
- */
- public static DVConstraint createDateConstraint(int comparisonOperator, String expr1, String expr2, String dateFormat) {
- if (expr1 == null) {
- throw new IllegalArgumentException("expr1 must be supplied");
- }
- OperatorType.validateSecondArg(comparisonOperator, expr2);
- SimpleDateFormat df = null;
- if (dateFormat != null) {
- df = new SimpleDateFormat(dateFormat, LocaleUtil.getUserLocale());
- df.setTimeZone(LocaleUtil.getUserTimeZone());
- }
-
- // formula1 and value1 are mutually exclusive
- String formula1 = getFormulaFromTextExpression(expr1);
- Double value1 = formula1 == null ? convertDate(expr1, df) : null;
- // formula2 and value2 are mutually exclusive
- String formula2 = getFormulaFromTextExpression(expr2);
- Double value2 = formula2 == null ? convertDate(expr2, df) : null;
- return new DVConstraint(ValidationType.DATE, comparisonOperator, formula1, formula2, value1, value2, null);
- }
-
- /**
- * Distinguishes formula expressions from simple value expressions. This logic is only
- * required by a few factory methods in this class that create data validation constraints
- * from more or less the same parameters that would have been entered in the Excel UI. The
- * data validation dialog box uses the convention that formulas begin with '='. Other methods
- * in this class follow the POI convention (formulas and values are distinct), so the '='
- * convention is not used there.
- *
- * @param textExpr a formula or value expression
- * @return all text after '=' if textExpr begins with '='. Otherwise {@code null} if textExpr does not begin with '='
- */
- private static String getFormulaFromTextExpression(String textExpr) {
- if (textExpr == null) {
- return null;
- }
- if (textExpr.length() < 1) {
- throw new IllegalArgumentException("Empty string is not a valid formula/value expression");
- }
- if (textExpr.charAt(0) == '=') {
- return textExpr.substring(1);
- }
- return null;
- }
-
-
- /**
- * @return {@code null} if numberStr is {@code null}
- */
- private static Double convertNumber(String numberStr) {
- if (numberStr == null) {
- return null;
- }
- try {
- return Double.valueOf(numberStr);
- } catch (NumberFormatException e) {
- throw new RuntimeException("The supplied text '" + numberStr
- + "' could not be parsed as a number");
- }
- }
-
- /**
- * @return {@code null} if timeStr is {@code null}
- */
- private static Double convertTime(String timeStr) {
- if (timeStr == null) {
- return null;
- }
- return DateUtil.convertTime(timeStr);
- }
- /**
- * @param dateFormat pass {@code null} for default YYYYMMDD
- * @return {@code null} if timeStr is {@code null}
- */
- private static Double convertDate(String dateStr, SimpleDateFormat dateFormat) {
- if (dateStr == null) {
- return null;
- }
- Date dateVal;
- if (dateFormat == null) {
- dateVal = DateUtil.parseYYYYMMDDDate(dateStr);
- } else {
- try {
- dateVal = dateFormat.parse(dateStr);
- } catch (ParseException e) {
- throw new RuntimeException("Failed to parse date '" + dateStr
- + "' using specified format '" + dateFormat + "'", e);
- }
- }
- return DateUtil.getExcelDate(dateVal);
- }
-
- public static DVConstraint createCustomFormulaConstraint(String formula) {
- if (formula == null) {
- throw new IllegalArgumentException("formula must be supplied");
- }
- return new DVConstraint(ValidationType.FORMULA, OperatorType.IGNORED, formula, null, null, null, null);
- }
-
- /* (non-Javadoc)
- * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#getValidationType()
- */
- @Override
- public int getValidationType() {
- return _validationType;
- }
- /**
- * Convenience method
- * @return {@code true} if this constraint is a 'list' validation
- */
- public boolean isListValidationType() {
- return _validationType == ValidationType.LIST;
- }
- /**
- * Convenience method
- * @return {@code true} if this constraint is a 'list' validation with explicit values
- */
- public boolean isExplicitList() {
- return _validationType == ValidationType.LIST && _explicitListValues != null;
- }
- /* (non-Javadoc)
- * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#getOperator()
- */
- @Override
- public int getOperator() {
- return _operator;
- }
- /* (non-Javadoc)
- * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#setOperator(int)
- */
- @Override
- public void setOperator(int operator) {
- _operator = operator;
- }
-
- /* (non-Javadoc)
- * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#getExplicitListValues()
- */
- @Override
- public String[] getExplicitListValues() {
- return _explicitListValues;
- }
- /* (non-Javadoc)
- * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#setExplicitListValues(java.lang.String[])
- */
- @Override
- public void setExplicitListValues(String[] explicitListValues) {
- if (_validationType != ValidationType.LIST) {
- throw new RuntimeException("Cannot setExplicitListValues on non-list constraint");
- }
- _formula1 = null;
- _explicitListValues = explicitListValues;
- }
-
- /* (non-Javadoc)
- * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#getFormula1()
- */
- @Override
- public String getFormula1() {
- return _formula1;
- }
- /* (non-Javadoc)
- * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#setFormula1(java.lang.String)
- */
- @Override
- public void setFormula1(String formula1) {
- _value1 = null;
- _explicitListValues = null;
- _formula1 = formula1;
- }
-
- /* (non-Javadoc)
- * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#getFormula2()
- */
- @Override
- public String getFormula2() {
- return _formula2;
- }
- /* (non-Javadoc)
- * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#setFormula2(java.lang.String)
- */
- @Override
- public void setFormula2(String formula2) {
- _value2 = null;
- _formula2 = formula2;
- }
-
- /**
- * @return the numeric value for expression 1. May be {@code null}
- */
- public Double getValue1() {
- return _value1;
- }
- /**
- * Sets a numeric value for expression 1.
- */
- public void setValue1(double value1) {
- _formula1 = null;
- _value1 = value1;
- }
-
- /**
- * @return the numeric value for expression 2. May be {@code null}
- */
- public Double getValue2() {
- return _value2;
- }
- /**
- * Sets a numeric value for expression 2.
- */
- public void setValue2(double value2) {
- _formula2 = null;
- _value2 = value2;
- }
-
- /**
- * @return both parsed formulas (for expression 1 and 2).
- */
- /* package */ FormulaPair createFormulas(HSSFSheet sheet) {
- Ptg[] formula1;
- Ptg[] formula2;
- if (isListValidationType()) {
- formula1 = createListFormula(sheet);
- formula2 = Ptg.EMPTY_PTG_ARRAY;
- } else {
- formula1 = convertDoubleFormula(_formula1, _value1, sheet);
- formula2 = convertDoubleFormula(_formula2, _value2, sheet);
- }
- return new FormulaPair(formula1, formula2);
- }
+ * @param comparisonOperator any constant from {@link org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType} enum
+ * @param expr1 date formula (when first char is '=') or formatted number value
+ * @param expr2 date formula (when first char is '=') or formatted number value
+ */
+ public static DVConstraint createNumericConstraint(int validationType, int comparisonOperator,
+ String expr1, String expr2) {
+ switch (validationType) {
+ case ValidationType.ANY:
+ if (expr1 != null || expr2 != null) {
+ throw new IllegalArgumentException("expr1 and expr2 must be null for validation type 'any'");
+ }
+ break;
+ case ValidationType.DECIMAL:
+ case ValidationType.INTEGER:
+ case ValidationType.TEXT_LENGTH:
+ if (expr1 == null) {
+ throw new IllegalArgumentException("expr1 must be supplied");
+ }
+ OperatorType.validateSecondArg(comparisonOperator, expr2);
+ break;
+ default:
+ throw new IllegalArgumentException("Validation Type ("
+ + validationType + ") not supported with this method");
+ }
+ // formula1 and value1 are mutually exclusive
+ String formula1 = getFormulaFromTextExpression(expr1);
+ Double value1 = formula1 == null ? convertNumber(expr1) : null;
+ // formula2 and value2 are mutually exclusive
+ String formula2 = getFormulaFromTextExpression(expr2);
+ Double value2 = formula2 == null ? convertNumber(expr2) : null;
+ return new DVConstraint(validationType, comparisonOperator, formula1, formula2, value1, value2, null);
+ }
+
+ public static DVConstraint createFormulaListConstraint(String listFormula) {
+ return new DVConstraint(listFormula, null);
+ }
+ public static DVConstraint createExplicitListConstraint(String[] explicitListValues) {
+ return new DVConstraint(null, explicitListValues);
+ }
+
+
+ /**
+ * Creates a time based data validation constraint. The text values entered for expr1 and expr2
+ * can be either standard Excel formulas or formatted time values. If the expression starts
+ * with '=' it is parsed as a formula, otherwise it is parsed as a formatted time. To parse
+ * formatted times, two formats are supported: "HH:MM" or "HH:MM:SS". This is contrary to
+ * Excel which uses the default time format from the OS.
+ *
+ * @param comparisonOperator constant from {@link org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType} enum
+ * @param expr1 date formula (when first char is '=') or formatted time value
+ * @param expr2 date formula (when first char is '=') or formatted time value
+ */
+ public static DVConstraint createTimeConstraint(int comparisonOperator, String expr1, String expr2) {
+ if (expr1 == null) {
+ throw new IllegalArgumentException("expr1 must be supplied");
+ }
+ OperatorType.validateSecondArg(comparisonOperator, expr1);
+
+ // formula1 and value1 are mutually exclusive
+ String formula1 = getFormulaFromTextExpression(expr1);
+ Double value1 = formula1 == null ? convertTime(expr1) : null;
+ // formula2 and value2 are mutually exclusive
+ String formula2 = getFormulaFromTextExpression(expr2);
+ Double value2 = formula2 == null ? convertTime(expr2) : null;
+ return new DVConstraint(ValidationType.TIME, comparisonOperator, formula1, formula2, value1, value2, null);
+ }
+
+ /**
+ * Creates a date based data validation constraint. The text values entered for expr1 and expr2
+ * can be either standard Excel formulas or formatted date values. If the expression starts
+ * with '=' it is parsed as a formula, otherwise it is parsed as a formatted date (Excel uses
+ * the same convention). To parse formatted dates, a date format needs to be specified. This
+ * is contrary to Excel which uses the default short date format from the OS.
+ *
+ * @param comparisonOperator constant from {@link org.apache.poi.ss.usermodel.DataValidationConstraint.OperatorType} enum
+ * @param expr1 date formula (when first char is '=') or formatted date value
+ * @param expr2 date formula (when first char is '=') or formatted date value
+ * @param dateFormat ignored if both expr1 and expr2 are formulas. Default value is "YYYY/MM/DD"
+ * otherwise any other valid argument for {@code SimpleDateFormat} can be used
+ * @see <a href='http://java.sun.com/j2se/1.5.0/docs/api/java/text/DateFormat.html'>SimpleDateFormat</a>
+ */
+ public static DVConstraint createDateConstraint(int comparisonOperator, String expr1, String expr2, String dateFormat) {
+ if (expr1 == null) {
+ throw new IllegalArgumentException("expr1 must be supplied");
+ }
+ OperatorType.validateSecondArg(comparisonOperator, expr2);
+ SimpleDateFormat df = null;
+ if (dateFormat != null) {
+ df = new SimpleDateFormat(dateFormat, LocaleUtil.getUserLocale());
+ df.setTimeZone(LocaleUtil.getUserTimeZone());
+ }
+
+ // formula1 and value1 are mutually exclusive
+ String formula1 = getFormulaFromTextExpression(expr1);
+ Double value1 = formula1 == null ? convertDate(expr1, df) : null;
+ // formula2 and value2 are mutually exclusive
+ String formula2 = getFormulaFromTextExpression(expr2);
+ Double value2 = formula2 == null ? convertDate(expr2, df) : null;
+ return new DVConstraint(ValidationType.DATE, comparisonOperator, formula1, formula2, value1, value2, null);
+ }
+
+ /**
+ * Distinguishes formula expressions from simple value expressions. This logic is only
+ * required by a few factory methods in this class that create data validation constraints
+ * from more or less the same parameters that would have been entered in the Excel UI. The
+ * data validation dialog box uses the convention that formulas begin with '='. Other methods
+ * in this class follow the POI convention (formulas and values are distinct), so the '='
+ * convention is not used there.
+ *
+ * @param textExpr a formula or value expression
+ * @return all text after '=' if textExpr begins with '='. Otherwise {@code null} if textExpr does not begin with '='
+ */
+ private static String getFormulaFromTextExpression(String textExpr) {
+ if (textExpr == null) {
+ return null;
+ }
+ if (textExpr.length() < 1) {
+ throw new IllegalArgumentException("Empty string is not a valid formula/value expression");
+ }
+ if (textExpr.charAt(0) == '=') {
+ return textExpr.substring(1);
+ }
+ return null;
+ }
+
+
+ /**
+ * @return {@code null} if numberStr is {@code null}
+ */
+ private static Double convertNumber(String numberStr) {
+ if (numberStr == null) {
+ return null;
+ }
+ try {
+ return Double.valueOf(numberStr);
+ } catch (NumberFormatException e) {
+ throw new RuntimeException("The supplied text '" + numberStr
+ + "' could not be parsed as a number");
+ }
+ }
+
+ /**
+ * @return {@code null} if timeStr is {@code null}
+ */
+ private static Double convertTime(String timeStr) {
+ if (timeStr == null) {
+ return null;
+ }
+ return DateUtil.convertTime(timeStr);
+ }
+ /**
+ * @param dateFormat pass {@code null} for default YYYYMMDD
+ * @return {@code null} if timeStr is {@code null}
+ */
+ private static Double convertDate(String dateStr, SimpleDateFormat dateFormat) {
+ if (dateStr == null) {
+ return null;
+ }
+ Date dateVal;
+ if (dateFormat == null) {
+ dateVal = DateUtil.parseYYYYMMDDDate(dateStr);
+ } else {
+ try {
+ dateVal = dateFormat.parse(dateStr);
+ } catch (ParseException e) {
+ throw new RuntimeException("Failed to parse date '" + dateStr
+ + "' using specified format '" + dateFormat + "'", e);
+ }
+ }
+ return DateUtil.getExcelDate(dateVal);
+ }
+
+ public static DVConstraint createCustomFormulaConstraint(String formula) {
+ if (formula == null) {
+ throw new IllegalArgumentException("formula must be supplied");
+ }
+ return new DVConstraint(ValidationType.FORMULA, OperatorType.IGNORED, formula, null, null, null, null);
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#getValidationType()
+ */
+ @Override
+ public int getValidationType() {
+ return _validationType;
+ }
+ /**
+ * Convenience method
+ * @return {@code true} if this constraint is a 'list' validation
+ */
+ public boolean isListValidationType() {
+ return _validationType == ValidationType.LIST;
+ }
+ /**
+ * Convenience method
+ * @return {@code true} if this constraint is a 'list' validation with explicit values
+ */
+ public boolean isExplicitList() {
+ return _validationType == ValidationType.LIST && _explicitListValues != null;
+ }
+ /* (non-Javadoc)
+ * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#getOperator()
+ */
+ @Override
+ public int getOperator() {
+ return _operator;
+ }
+ /* (non-Javadoc)
+ * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#setOperator(int)
+ */
+ @Override
+ public void setOperator(int operator) {
+ _operator = operator;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#getExplicitListValues()
+ */
+ @Override
+ public String[] getExplicitListValues() {
+ return _explicitListValues;
+ }
+ /* (non-Javadoc)
+ * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#setExplicitListValues(java.lang.String[])
+ */
+ @Override
+ public void setExplicitListValues(String[] explicitListValues) {
+ if (_validationType != ValidationType.LIST) {
+ throw new RuntimeException("Cannot setExplicitListValues on non-list constraint");
+ }
+ _formula1 = null;
+ _explicitListValues = explicitListValues;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#getFormula1()
+ */
+ @Override
+ public String getFormula1() {
+ return _formula1;
+ }
+ /* (non-Javadoc)
+ * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#setFormula1(java.lang.String)
+ */
+ @Override
+ public void setFormula1(String formula1) {
+ _value1 = null;
+ _explicitListValues = null;
+ _formula1 = formula1;
+ }
+
+ /* (non-Javadoc)
+ * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#getFormula2()
+ */
+ @Override
+ public String getFormula2() {
+ return _formula2;
+ }
+ /* (non-Javadoc)
+ * @see org.apache.poi.hssf.usermodel.DataValidationConstraint#setFormula2(java.lang.String)
+ */
+ @Override
+ public void setFormula2(String formula2) {
+ _value2 = null;
+ _formula2 = formula2;
+ }
+
+ /**
+ * @return the numeric value for expression 1. May be {@code null}
+ */
+ public Double getValue1() {
+ return _value1;
+ }
+ /**
+ * Sets a numeric value for expression 1.
+ */
+ public void setValue1(double value1) {
+ _formula1 = null;
+ _value1 = value1;
+ }
+
+ /**
+ * @return the numeric value for expression 2. May be {@code null}
+ */
+ public Double getValue2() {
+ return _value2;
+ }
+ /**
+ * Sets a numeric value for expression 2.
+ */
+ public void setValue2(double value2) {
+ _formula2 = null;
+ _value2 = value2;
+ }
+
+ /**
+ * @return both parsed formulas (for expression 1 and 2).
+ */
+ /* package */ FormulaPair createFormulas(HSSFSheet sheet) {
+ Ptg[] formula1;
+ Ptg[] formula2;
+ if (isListValidationType()) {
+ formula1 = createListFormula(sheet);
+ formula2 = Ptg.EMPTY_PTG_ARRAY;
+ } else {
+ formula1 = convertDoubleFormula(_formula1, _value1, sheet);
+ formula2 = convertDoubleFormula(_formula2, _value2, sheet);
+ }
+ return new FormulaPair(formula1, formula2);
+ }
@SuppressWarnings("resource")
private Ptg[] createListFormula(HSSFSheet sheet) {
- if (_explicitListValues == null) {
+ if (_explicitListValues == null) {
HSSFWorkbook wb = sheet.getWorkbook();
// formula is parsed with slightly different RVA rules: (root node type must be 'reference')
- return HSSFFormulaParser.parse(_formula1, wb, FormulaType.DATAVALIDATION_LIST, wb.getSheetIndex(sheet));
- // To do: Excel places restrictions on the available operations within a list formula.
- // Some things like union and intersection are not allowed.
- }
- // explicit list was provided
- StringBuilder sb = new StringBuilder(_explicitListValues.length * 16);
- for (int i = 0; i < _explicitListValues.length; i++) {
- if (i > 0) {
- sb.append('\0'); // list delimiter is the nul char
- }
- sb.append(_explicitListValues[i]);
-
- }
- return new Ptg[] { new StringPtg(sb.toString()), };
- }
-
- /**
- * @return The parsed token array representing the formula or value specified.
- * Empty array if both formula and value are {@code null}
- */
+ return HSSFFormulaParser.parse(_formula1, wb, FormulaType.DATAVALIDATION_LIST, wb.getSheetIndex(sheet));
+ // To do: Excel places restrictions on the available operations within a list formula.
+ // Some things like union and intersection are not allowed.
+ }
+ // explicit list was provided
+ StringBuilder sb = new StringBuilder(_explicitListValues.length * 16);
+ for (int i = 0; i < _explicitListValues.length; i++) {
+ if (i > 0) {
+ sb.append('\0'); // list delimiter is the nul char
+ }
+ sb.append(_explicitListValues[i]);
+
+ }
+ return new Ptg[] { new StringPtg(sb.toString()), };
+ }
+
+ /**
+ * @return The parsed token array representing the formula or value specified.
+ * Empty array if both formula and value are {@code null}
+ */
@SuppressWarnings("resource")
- private static Ptg[] convertDoubleFormula(String formula, Double value, HSSFSheet sheet) {
- if (formula == null) {
- if (value == null) {
- return Ptg.EMPTY_PTG_ARRAY;
- }
- return new Ptg[] { new NumberPtg(value), };
- }
- if (value != null) {
- throw new IllegalStateException("Both formula and value cannot be present");
- }
+ private static Ptg[] convertDoubleFormula(String formula, Double value, HSSFSheet sheet) {
+ if (formula == null) {
+ if (value == null) {
+ return Ptg.EMPTY_PTG_ARRAY;
+ }
+ return new Ptg[] { new NumberPtg(value), };
+ }
+ if (value != null) {
+ throw new IllegalStateException("Both formula and value cannot be present");
+ }
HSSFWorkbook wb = sheet.getWorkbook();
- return HSSFFormulaParser.parse(formula, wb, FormulaType.CELL, wb.getSheetIndex(sheet));
- }
+ return HSSFFormulaParser.parse(formula, wb, FormulaType.CELL, wb.getSheetIndex(sheet));
+ }
static DVConstraint createDVConstraint(DVRecord dvRecord, FormulaRenderingWorkbook book) {
switch (dvRecord.getDataType()) {
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/EscherGraphics.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/EscherGraphics.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/EscherGraphics.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/EscherGraphics.java Sat May 22 20:56:44 2021
@@ -159,7 +159,7 @@ public class EscherGraphics extends Grap
@Override
@NotImplemented
public void drawArc(int x, int y, int width, int height,
- int startAngle, int arcAngle)
+ int startAngle, int arcAngle)
{
LOG.atWarn().log("drawArc not supported");
}
@@ -167,10 +167,10 @@ public class EscherGraphics extends Grap
@Override
@NotImplemented
public boolean drawImage(Image img,
- int dx1, int dy1, int dx2, int dy2,
- int sx1, int sy1, int sx2, int sy2,
- Color bgcolor,
- ImageObserver observer)
+ int dx1, int dy1, int dx2, int dy2,
+ int sx1, int sy1, int sx2, int sy2,
+ Color bgcolor,
+ ImageObserver observer)
{
LOG.atWarn().log("drawImage not supported");
@@ -180,9 +180,9 @@ public class EscherGraphics extends Grap
@Override
@NotImplemented
public boolean drawImage(Image img,
- int dx1, int dy1, int dx2, int dy2,
- int sx1, int sy1, int sx2, int sy2,
- ImageObserver observer)
+ int dx1, int dy1, int dx2, int dy2,
+ int sx1, int sy1, int sx2, int sy2,
+ ImageObserver observer)
{
LOG.atWarn().log("drawImage not supported");
return true;
@@ -278,7 +278,7 @@ public class EscherGraphics extends Grap
@Override
@NotImplemented
public void drawRoundRect(int x, int y, int width, int height,
- int arcWidth, int arcHeight)
+ int arcWidth, int arcHeight)
{
LOG.atWarn().log("drawRoundRect not supported");
}
@@ -353,7 +353,7 @@ public class EscherGraphics extends Grap
@Override
public void fillArc(int x, int y, int width, int height,
- int startAngle, int arcAngle)
+ int startAngle, int arcAngle)
{
LOG.atWarn().log("fillArc not supported");
}
@@ -435,7 +435,7 @@ public class EscherGraphics extends Grap
@Override
public void fillRoundRect(int x, int y, int width, int height,
- int arcWidth, int arcHeight)
+ int arcWidth, int arcHeight)
{
LOG.atWarn().log("fillRoundRect not supported");
}
Modified: poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/EscherGraphics2d.java
URL: http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/EscherGraphics2d.java?rev=1890120&r1=1890119&r2=1890120&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/EscherGraphics2d.java (original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/EscherGraphics2d.java Sat May 22 20:56:44 2021
@@ -127,7 +127,7 @@ public final class EscherGraphics2d exte
@Override
public void copyArea(int x, int y, int width, int height,
- int dx, int dy)
+ int dx, int dy)
{
getG2D().copyArea(x,y,width,height,dx,dy);
}
@@ -168,7 +168,7 @@ public final class EscherGraphics2d exte
@Override
public void drawArc(int x, int y, int width, int height,
- int startAngle, int arcAngle)
+ int startAngle, int arcAngle)
{
draw(new Arc2D.Float(x, y, width, height, startAngle, arcAngle, 0));
}
@@ -203,8 +203,8 @@ public final class EscherGraphics2d exte
@Override
public boolean drawImage(Image img, int x, int y,
- int width, int height,
- ImageObserver observer)
+ int width, int height,
+ ImageObserver observer)
{
return drawImage(img, x,y,width,height, null, observer);
}
@@ -387,7 +387,7 @@ public final class EscherGraphics2d exte
@Override
public void fillRoundRect(int x, int y, int width, int height,
- int arcWidth, int arcHeight)
+ int arcWidth, int arcHeight)
{
fill(new RoundRectangle2D.Float(x, y, width, height, arcWidth, arcHeight));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org