2004-04-09 09:05:39 -04:00
|
|
|
/* ====================================================================
|
2006-12-22 14:18:16 -05:00
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
the License. You may obtain a copy of the License at
|
2004-04-09 09:05:39 -04:00
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
==================================================================== */
|
2009-05-19 15:21:12 -04:00
|
|
|
|
2004-04-09 07:45:38 -04:00
|
|
|
package org.apache.poi.ddf;
|
|
|
|
|
|
|
|
import org.apache.poi.util.HexDump;
|
2005-05-01 07:26:18 -04:00
|
|
|
import org.apache.poi.util.LittleEndian;
|
2004-04-09 07:45:38 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The BSE record is related closely to the <code>EscherBlipRecord</code> and stores
|
2005-05-01 07:26:18 -04:00
|
|
|
* extra information about the blip. A blip record is actually stored inside
|
|
|
|
* the BSE record even though the BSE record isn't actually a container record.
|
2004-04-09 07:45:38 -04:00
|
|
|
*
|
|
|
|
* @author Glen Stampoultzis
|
|
|
|
* @see EscherBlipRecord
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public final class EscherBSERecord extends EscherRecord {
|
2004-04-09 07:45:38 -04:00
|
|
|
public static final short RECORD_ID = (short) 0xF007;
|
|
|
|
public static final String RECORD_DESCRIPTION = "MsofbtBSE";
|
|
|
|
|
|
|
|
public static final byte BT_ERROR = 0;
|
|
|
|
public static final byte BT_UNKNOWN = 1;
|
|
|
|
public static final byte BT_EMF = 2;
|
|
|
|
public static final byte BT_WMF = 3;
|
|
|
|
public static final byte BT_PICT = 4;
|
|
|
|
public static final byte BT_JPEG = 5;
|
|
|
|
public static final byte BT_PNG = 6;
|
|
|
|
public static final byte BT_DIB = 7;
|
|
|
|
|
|
|
|
private byte field_1_blipTypeWin32;
|
|
|
|
private byte field_2_blipTypeMacOS;
|
2015-09-24 01:51:38 -04:00
|
|
|
private final byte[] field_3_uid = new byte[16];
|
2004-04-09 07:45:38 -04:00
|
|
|
private short field_4_tag;
|
|
|
|
private int field_5_size;
|
|
|
|
private int field_6_ref;
|
|
|
|
private int field_7_offset;
|
|
|
|
private byte field_8_usage;
|
|
|
|
private byte field_9_name;
|
|
|
|
private byte field_10_unused2;
|
|
|
|
private byte field_11_unused3;
|
2005-05-01 07:26:18 -04:00
|
|
|
private EscherBlipRecord field_12_blipRecord;
|
2004-04-09 07:45:38 -04:00
|
|
|
|
2015-09-24 01:51:38 -04:00
|
|
|
private byte[] _remainingData = new byte[0];
|
2004-04-09 07:45:38 -04:00
|
|
|
|
2009-05-19 15:21:12 -04:00
|
|
|
public int fillFields(byte[] data, int offset, EscherRecordFactory recordFactory) {
|
2004-04-09 07:45:38 -04:00
|
|
|
int bytesRemaining = readHeader( data, offset );
|
|
|
|
int pos = offset + 8;
|
|
|
|
field_1_blipTypeWin32 = data[pos];
|
|
|
|
field_2_blipTypeMacOS = data[pos + 1];
|
2015-09-23 19:22:46 -04:00
|
|
|
System.arraycopy( data, pos + 2, field_3_uid, 0, 16 );
|
2004-04-09 07:45:38 -04:00
|
|
|
field_4_tag = LittleEndian.getShort( data, pos + 18 );
|
|
|
|
field_5_size = LittleEndian.getInt( data, pos + 20 );
|
|
|
|
field_6_ref = LittleEndian.getInt( data, pos + 24 );
|
|
|
|
field_7_offset = LittleEndian.getInt( data, pos + 28 );
|
|
|
|
field_8_usage = data[pos + 32];
|
|
|
|
field_9_name = data[pos + 33];
|
|
|
|
field_10_unused2 = data[pos + 34];
|
|
|
|
field_11_unused3 = data[pos + 35];
|
|
|
|
bytesRemaining -= 36;
|
2009-05-19 15:21:12 -04:00
|
|
|
|
2005-05-01 07:26:18 -04:00
|
|
|
int bytesRead = 0;
|
2008-08-30 10:47:33 -04:00
|
|
|
if (bytesRemaining > 0) {
|
2009-05-19 15:21:12 -04:00
|
|
|
// Some older escher formats skip this last record
|
2005-05-01 07:26:18 -04:00
|
|
|
field_12_blipRecord = (EscherBlipRecord) recordFactory.createRecord( data, pos + 36 );
|
|
|
|
bytesRead = field_12_blipRecord.fillFields( data, pos + 36, recordFactory );
|
|
|
|
}
|
|
|
|
pos += 36 + bytesRead;
|
|
|
|
bytesRemaining -= bytesRead;
|
2009-05-19 15:21:12 -04:00
|
|
|
|
|
|
|
_remainingData = new byte[bytesRemaining];
|
|
|
|
System.arraycopy( data, pos, _remainingData, 0, bytesRemaining );
|
2005-05-01 07:26:18 -04:00
|
|
|
return bytesRemaining + 8 + 36 + (field_12_blipRecord == null ? 0 : field_12_blipRecord.getRecordSize()) ;
|
2004-04-09 07:45:38 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-05-19 15:21:12 -04:00
|
|
|
public int serialize(int offset, byte[] data, EscherSerializationListener listener) {
|
2004-04-09 07:45:38 -04:00
|
|
|
listener.beforeRecordSerialize( offset, getRecordId(), this );
|
|
|
|
|
2015-09-23 19:22:46 -04:00
|
|
|
if (_remainingData == null) {
|
2009-05-19 15:21:12 -04:00
|
|
|
_remainingData = new byte[0];
|
2015-09-23 19:22:46 -04:00
|
|
|
}
|
2005-05-01 07:26:18 -04:00
|
|
|
|
2004-04-09 07:45:38 -04:00
|
|
|
LittleEndian.putShort( data, offset, getOptions() );
|
|
|
|
LittleEndian.putShort( data, offset + 2, getRecordId() );
|
2005-05-01 07:26:18 -04:00
|
|
|
int blipSize = field_12_blipRecord == null ? 0 : field_12_blipRecord.getRecordSize();
|
2009-05-19 15:21:12 -04:00
|
|
|
int remainingBytes = _remainingData.length + 36 + blipSize;
|
2004-04-09 07:45:38 -04:00
|
|
|
LittleEndian.putInt( data, offset + 4, remainingBytes );
|
|
|
|
|
|
|
|
data[offset + 8] = field_1_blipTypeWin32;
|
|
|
|
data[offset + 9] = field_2_blipTypeMacOS;
|
|
|
|
for ( int i = 0; i < 16; i++ )
|
|
|
|
data[offset + 10 + i] = field_3_uid[i];
|
|
|
|
LittleEndian.putShort( data, offset + 26, field_4_tag );
|
|
|
|
LittleEndian.putInt( data, offset + 28, field_5_size );
|
|
|
|
LittleEndian.putInt( data, offset + 32, field_6_ref );
|
|
|
|
LittleEndian.putInt( data, offset + 36, field_7_offset );
|
|
|
|
data[offset + 40] = field_8_usage;
|
|
|
|
data[offset + 41] = field_9_name;
|
|
|
|
data[offset + 42] = field_10_unused2;
|
|
|
|
data[offset + 43] = field_11_unused3;
|
2005-05-01 07:26:18 -04:00
|
|
|
int bytesWritten = 0;
|
|
|
|
if (field_12_blipRecord != null)
|
|
|
|
{
|
|
|
|
bytesWritten = field_12_blipRecord.serialize( offset + 44, data, new NullEscherSerializationListener() );
|
|
|
|
}
|
2009-05-19 15:21:12 -04:00
|
|
|
System.arraycopy( _remainingData, 0, data, offset + 44 + bytesWritten, _remainingData.length );
|
|
|
|
int pos = offset + 8 + 36 + _remainingData.length + bytesWritten;
|
2004-04-09 07:45:38 -04:00
|
|
|
|
|
|
|
listener.afterRecordSerialize(pos, getRecordId(), pos - offset, this);
|
|
|
|
return pos - offset;
|
|
|
|
}
|
|
|
|
|
2009-05-19 15:21:12 -04:00
|
|
|
public int getRecordSize() {
|
|
|
|
int field_12_size = 0;
|
|
|
|
if(field_12_blipRecord != null) {
|
|
|
|
field_12_size = field_12_blipRecord.getRecordSize();
|
|
|
|
}
|
|
|
|
int remaining_size = 0;
|
|
|
|
if(_remainingData != null) {
|
|
|
|
remaining_size = _remainingData.length;
|
|
|
|
}
|
2008-08-30 10:47:33 -04:00
|
|
|
return 8 + 1 + 1 + 16 + 2 + 4 + 4 + 4 + 1 + 1 +
|
|
|
|
1 + 1 + field_12_size + remaining_size;
|
2004-04-09 07:45:38 -04:00
|
|
|
}
|
|
|
|
|
2009-05-19 15:21:12 -04:00
|
|
|
public String getRecordName() {
|
2004-04-09 07:45:38 -04:00
|
|
|
return "BSE";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The expected blip type under windows (failure to match this blip type will result in
|
|
|
|
* Excel converting to this format).
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public byte getBlipTypeWin32() {
|
2004-04-09 07:45:38 -04:00
|
|
|
return field_1_blipTypeWin32;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the expected win32 blip type
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public void setBlipTypeWin32(byte blipTypeWin32) {
|
|
|
|
field_1_blipTypeWin32 = blipTypeWin32;
|
2004-04-09 07:45:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The expected blip type under MacOS (failure to match this blip type will result in
|
|
|
|
* Excel converting to this format).
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public byte getBlipTypeMacOS() {
|
2004-04-09 07:45:38 -04:00
|
|
|
return field_2_blipTypeMacOS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the expected MacOS blip type
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public void setBlipTypeMacOS(byte blipTypeMacOS) {
|
|
|
|
field_2_blipTypeMacOS = blipTypeMacOS;
|
2004-04-09 07:45:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 16 byte MD4 checksum.
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public byte[] getUid() {
|
2004-04-09 07:45:38 -04:00
|
|
|
return field_3_uid;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 16 byte MD4 checksum.
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public void setUid(byte[] uid) {
|
2015-09-24 01:51:38 -04:00
|
|
|
if (uid == null || uid.length != 16) {
|
|
|
|
throw new IllegalArgumentException("uid must be byte[16]");
|
|
|
|
}
|
|
|
|
System.arraycopy(uid, 0, field_3_uid, 0, field_3_uid.length);
|
2004-04-09 07:45:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* unused
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public short getTag() {
|
2004-04-09 07:45:38 -04:00
|
|
|
return field_4_tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* unused
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public void setTag(short tag) {
|
|
|
|
field_4_tag = tag;
|
2004-04-09 07:45:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Blip size in stream.
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public int getSize() {
|
2004-04-09 07:45:38 -04:00
|
|
|
return field_5_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Blip size in stream.
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public void setSize(int size) {
|
|
|
|
field_5_size = size;
|
2004-04-09 07:45:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The reference count of this blip.
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public int getRef() {
|
2004-04-09 07:45:38 -04:00
|
|
|
return field_6_ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The reference count of this blip.
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public void setRef(int ref) {
|
|
|
|
field_6_ref = ref;
|
2004-04-09 07:45:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* File offset in the delay stream.
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public int getOffset() {
|
2004-04-09 07:45:38 -04:00
|
|
|
return field_7_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* File offset in the delay stream.
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public void setOffset(int offset) {
|
|
|
|
field_7_offset = offset;
|
2004-04-09 07:45:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines the way this blip is used.
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public byte getUsage() {
|
2004-04-09 07:45:38 -04:00
|
|
|
return field_8_usage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines the way this blip is used.
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public void setUsage(byte usage) {
|
|
|
|
field_8_usage = usage;
|
2004-04-09 07:45:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The length in characters of the blip name.
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public byte getName() {
|
2004-04-09 07:45:38 -04:00
|
|
|
return field_9_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The length in characters of the blip name.
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public void setName(byte name) {
|
|
|
|
field_9_name = name;
|
2004-04-09 07:45:38 -04:00
|
|
|
}
|
|
|
|
|
2009-05-19 15:21:12 -04:00
|
|
|
public byte getUnused2() {
|
2004-04-09 07:45:38 -04:00
|
|
|
return field_10_unused2;
|
|
|
|
}
|
|
|
|
|
2009-05-19 15:21:12 -04:00
|
|
|
public void setUnused2(byte unused2) {
|
|
|
|
field_10_unused2 = unused2;
|
2004-04-09 07:45:38 -04:00
|
|
|
}
|
|
|
|
|
2009-05-19 15:21:12 -04:00
|
|
|
public byte getUnused3() {
|
2004-04-09 07:45:38 -04:00
|
|
|
return field_11_unused3;
|
|
|
|
}
|
|
|
|
|
2009-05-19 15:21:12 -04:00
|
|
|
public void setUnused3(byte unused3) {
|
|
|
|
field_11_unused3 = unused3;
|
2004-04-09 07:45:38 -04:00
|
|
|
}
|
|
|
|
|
2009-05-19 15:21:12 -04:00
|
|
|
public EscherBlipRecord getBlipRecord() {
|
2005-05-01 07:26:18 -04:00
|
|
|
return field_12_blipRecord;
|
|
|
|
}
|
|
|
|
|
2009-05-19 15:21:12 -04:00
|
|
|
public void setBlipRecord(EscherBlipRecord blipRecord) {
|
|
|
|
field_12_blipRecord = blipRecord;
|
2005-05-01 07:26:18 -04:00
|
|
|
}
|
|
|
|
|
2004-04-09 07:45:38 -04:00
|
|
|
/**
|
|
|
|
* Any remaining data in this record.
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public byte[] getRemainingData() {
|
|
|
|
return _remainingData;
|
2004-04-09 07:45:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Any remaining data in this record.
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public void setRemainingData(byte[] remainingData) {
|
2015-09-23 19:22:46 -04:00
|
|
|
if (remainingData == null) {
|
2015-09-24 01:51:38 -04:00
|
|
|
_remainingData = new byte[0];
|
2015-09-23 19:22:46 -04:00
|
|
|
} else {
|
|
|
|
_remainingData = remainingData.clone();
|
|
|
|
}
|
2009-05-19 15:21:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public String toString() {
|
2009-06-20 07:17:30 -04:00
|
|
|
String extraData = _remainingData == null ? null : HexDump.toHex(_remainingData, 32);
|
2009-05-19 15:21:12 -04:00
|
|
|
return getClass().getName() + ":" + '\n' +
|
|
|
|
" RecordId: 0x" + HexDump.toHex( RECORD_ID ) + '\n' +
|
2011-08-31 09:14:09 -04:00
|
|
|
" Version: 0x" + HexDump.toHex( getVersion() ) + '\n' +
|
|
|
|
" Instance: 0x" + HexDump.toHex( getInstance() ) + '\n' +
|
2009-05-19 15:21:12 -04:00
|
|
|
" BlipTypeWin32: " + field_1_blipTypeWin32 + '\n' +
|
|
|
|
" BlipTypeMacOS: " + field_2_blipTypeMacOS + '\n' +
|
2009-06-20 07:17:30 -04:00
|
|
|
" SUID: " + (field_3_uid == null ? "" : HexDump.toHex(field_3_uid)) + '\n' +
|
2009-05-19 15:21:12 -04:00
|
|
|
" Tag: " + field_4_tag + '\n' +
|
|
|
|
" Size: " + field_5_size + '\n' +
|
|
|
|
" Ref: " + field_6_ref + '\n' +
|
|
|
|
" Offset: " + field_7_offset + '\n' +
|
|
|
|
" Usage: " + field_8_usage + '\n' +
|
|
|
|
" Name: " + field_9_name + '\n' +
|
|
|
|
" Unused2: " + field_10_unused2 + '\n' +
|
|
|
|
" Unused3: " + field_11_unused3 + '\n' +
|
|
|
|
" blipRecord: " + field_12_blipRecord + '\n' +
|
|
|
|
" Extra Data:" + '\n' + extraData;
|
2004-04-09 07:45:38 -04:00
|
|
|
}
|
|
|
|
|
2012-05-02 10:00:46 -04:00
|
|
|
@Override
|
|
|
|
public String toXml(String tab) {
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance())))
|
|
|
|
.append(tab).append("\t").append("<BlipTypeWin32>").append(field_1_blipTypeWin32).append("</BlipTypeWin32>\n")
|
|
|
|
.append(tab).append("\t").append("<BlipTypeMacOS>").append(field_2_blipTypeMacOS).append("</BlipTypeMacOS>\n")
|
|
|
|
.append(tab).append("\t").append("<SUID>").append(field_3_uid == null ? "" : HexDump.toHex(field_3_uid)).append("</SUID>\n")
|
|
|
|
.append(tab).append("\t").append("<Tag>").append(field_4_tag).append("</Tag>\n")
|
|
|
|
.append(tab).append("\t").append("<Size>").append(field_5_size).append("</Size>\n")
|
|
|
|
.append(tab).append("\t").append("<Ref>").append(field_6_ref).append("</Ref>\n")
|
|
|
|
.append(tab).append("\t").append("<Offset>").append(field_7_offset).append("</Offset>\n")
|
|
|
|
.append(tab).append("\t").append("<Usage>").append(field_8_usage).append("</Usage>\n")
|
|
|
|
.append(tab).append("\t").append("<Name>").append(field_9_name).append("</Name>\n")
|
|
|
|
.append(tab).append("\t").append("<Unused2>").append(field_10_unused2).append("</Unused2>\n")
|
|
|
|
.append(tab).append("\t").append("<Unused3>").append(field_11_unused3).append("</Unused3>\n");
|
|
|
|
builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
|
|
|
|
return builder.toString();
|
|
|
|
}
|
|
|
|
|
2004-04-09 07:45:38 -04:00
|
|
|
/**
|
|
|
|
* Retrieve the string representation given a blip id.
|
|
|
|
*/
|
2009-05-19 15:21:12 -04:00
|
|
|
public static String getBlipType(byte b) {
|
|
|
|
switch (b) {
|
|
|
|
case BT_ERROR: return " ERROR";
|
|
|
|
case BT_UNKNOWN: return " UNKNOWN";
|
|
|
|
case BT_EMF: return " EMF";
|
|
|
|
case BT_WMF: return " WMF";
|
|
|
|
case BT_PICT: return " PICT";
|
|
|
|
case BT_JPEG: return " JPEG";
|
|
|
|
case BT_PNG: return " PNG";
|
|
|
|
case BT_DIB: return " DIB";
|
2004-04-09 07:45:38 -04:00
|
|
|
}
|
2009-05-19 15:21:12 -04:00
|
|
|
if ( b < 32 ) {
|
|
|
|
return " NotKnown";
|
|
|
|
}
|
|
|
|
return " Client";
|
2004-04-09 07:45:38 -04:00
|
|
|
}
|
|
|
|
}
|