Biff viewer changes for office drawing support
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/branches/REL_2_BRANCH@353498 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9ef45e5f61
commit
8e27ed87eb
@ -107,7 +107,7 @@ public class BiffViewer {
|
|||||||
new POIFSFileSystem(new FileInputStream(filename));
|
new POIFSFileSystem(new FileInputStream(filename));
|
||||||
InputStream stream =
|
InputStream stream =
|
||||||
fs.createDocumentInputStream("Workbook");
|
fs.createDocumentInputStream("Workbook");
|
||||||
Record[] records = createRecords(stream, dump);
|
createRecords(stream, dump);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -128,17 +128,18 @@ public class BiffViewer {
|
|||||||
public static Record[] createRecords(InputStream in, boolean dump)
|
public static Record[] createRecords(InputStream in, boolean dump)
|
||||||
throws RecordFormatException {
|
throws RecordFormatException {
|
||||||
ArrayList records = new ArrayList();
|
ArrayList records = new ArrayList();
|
||||||
Record last_record = null;
|
// Record last_record = null;
|
||||||
int loc = 0;
|
int loc = 0;
|
||||||
|
|
||||||
|
RecordDetails activeRecord = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// long offset = 0;
|
// long offset = 0;
|
||||||
short rectype = 0;
|
short rectype = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
rectype = LittleEndian.readShort(in);
|
rectype = LittleEndian.readShort(in);
|
||||||
System.out.println("============================================");
|
int startloc = loc;
|
||||||
System.out.println("Offset 0x" + Integer.toHexString(loc) + " (" + loc + ")");
|
|
||||||
loc += 2;
|
loc += 2;
|
||||||
if (rectype != 0) {
|
if (rectype != 0) {
|
||||||
short recsize = LittleEndian.readShort(in);
|
short recsize = LittleEndian.readShort(in);
|
||||||
@ -147,36 +148,27 @@ public class BiffViewer {
|
|||||||
byte[] data = new byte[(int) recsize];
|
byte[] data = new byte[(int) recsize];
|
||||||
|
|
||||||
in.read(data);
|
in.read(data);
|
||||||
if ((rectype == WSBoolRecord.sid) && (recsize == 0)) {
|
|
||||||
System.out.println(loc);
|
|
||||||
}
|
|
||||||
loc += recsize;
|
loc += recsize;
|
||||||
// offset += 4 + recsize;
|
Record record = createRecord(rectype, recsize, data );
|
||||||
if (dump) {
|
if (record.getSid() != ContinueRecord.sid)
|
||||||
dump(rectype, recsize, data);
|
{
|
||||||
}
|
|
||||||
Record[] recs = createRecord(rectype, recsize,
|
|
||||||
data);
|
|
||||||
// handle MulRK records
|
|
||||||
|
|
||||||
Record record = recs[0];
|
|
||||||
|
|
||||||
if ((record instanceof UnknownRecord)
|
|
||||||
&& !dump) {
|
|
||||||
// if we didn't already dump
|
|
||||||
// just cause dump was on and we're hit an unknow
|
|
||||||
dumpUnknownRecord(data);
|
|
||||||
}
|
|
||||||
if (record != null) {
|
|
||||||
if (rectype == ContinueRecord.sid) {
|
|
||||||
dumpContinueRecord(last_record, dump, data);
|
|
||||||
} else {
|
|
||||||
last_record = record;
|
|
||||||
records.add(record);
|
records.add(record);
|
||||||
|
if (activeRecord != null)
|
||||||
|
activeRecord.dump();
|
||||||
|
activeRecord = new RecordDetails(rectype, recsize, startloc, data, record);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
activeRecord.getRecord().processContinueRecord(data);
|
||||||
|
}
|
||||||
|
if (dump) {
|
||||||
|
dumpRaw(rectype, recsize, data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (rectype != 0);
|
} while (rectype != 0);
|
||||||
|
|
||||||
|
activeRecord.dump();
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RecordFormatException("Error reading bytes");
|
throw new RecordFormatException("Error reading bytes");
|
||||||
}
|
}
|
||||||
@ -186,15 +178,14 @@ public class BiffViewer {
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void dumpNormal(Record record, int startloc, short rectype, short recsize)
|
||||||
|
{
|
||||||
|
System.out.println("Offset 0x" + Integer.toHexString(startloc) + " (" + startloc + ")");
|
||||||
|
System.out.println( "recordid = 0x" + Integer.toHexString( rectype ) + ", size = " + recsize );
|
||||||
|
System.out.println( record.toString() );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Description of the Method
|
|
||||||
*
|
|
||||||
*@param last_record Description of the Parameter
|
|
||||||
*@param dump Description of the Parameter
|
|
||||||
*@param data Description of the Parameter
|
|
||||||
*@exception IOException Description of the Exception
|
|
||||||
*/
|
|
||||||
private static void dumpContinueRecord(Record last_record, boolean dump, byte[] data) throws IOException {
|
private static void dumpContinueRecord(Record last_record, boolean dump, byte[] data) throws IOException {
|
||||||
if (last_record == null) {
|
if (last_record == null) {
|
||||||
throw new RecordFormatException(
|
throw new RecordFormatException(
|
||||||
@ -226,12 +217,6 @@ public class BiffViewer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Description of the Method
|
|
||||||
*
|
|
||||||
*@param data Description of the Parameter
|
|
||||||
*@exception IOException Description of the Exception
|
|
||||||
*/
|
|
||||||
private static void dumpUnknownRecord(byte[] data) throws IOException {
|
private static void dumpUnknownRecord(byte[] data) throws IOException {
|
||||||
// record hex dump it!
|
// record hex dump it!
|
||||||
System.out.println(
|
System.out.println(
|
||||||
@ -247,10 +232,11 @@ public class BiffViewer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void dump( short rectype, short recsize, byte[] data ) throws IOException
|
private static void dumpRaw( short rectype, short recsize, byte[] data ) throws IOException
|
||||||
{
|
{
|
||||||
// System.out
|
// System.out
|
||||||
// .println("fixing to recordize the following");
|
// .println("fixing to recordize the following");
|
||||||
|
System.out.println("============================================");
|
||||||
System.out.print( "rectype = 0x"
|
System.out.print( "rectype = 0x"
|
||||||
+ Integer.toHexString( rectype ) );
|
+ Integer.toHexString( rectype ) );
|
||||||
System.out.println( ", recsize = 0x"
|
System.out.println( ", recsize = 0x"
|
||||||
@ -275,19 +261,12 @@ public class BiffViewer {
|
|||||||
* Essentially a duplicate of RecordFactory. Kept seperate as not to screw
|
* Essentially a duplicate of RecordFactory. Kept seperate as not to screw
|
||||||
* up non-debug operations.
|
* up non-debug operations.
|
||||||
*
|
*
|
||||||
*@param rectype Description of the Parameter
|
|
||||||
*@param size Description of the Parameter
|
|
||||||
*@param data Description of the Parameter
|
|
||||||
*@return Description of the Return Value
|
|
||||||
*/
|
*/
|
||||||
|
private static Record createRecord( short rectype, short size,
|
||||||
private static Record[] createRecord( short rectype, short size,
|
|
||||||
byte[] data )
|
byte[] data )
|
||||||
{
|
{
|
||||||
Record retval = null;
|
Record retval = null;
|
||||||
Record[] realretval = null;
|
|
||||||
|
|
||||||
// int irectype = rectype;
|
|
||||||
switch ( rectype )
|
switch ( rectype )
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -429,6 +408,15 @@ public class BiffViewer {
|
|||||||
case GridsetRecord.sid:
|
case GridsetRecord.sid:
|
||||||
retval = new GridsetRecord( rectype, size, data );
|
retval = new GridsetRecord( rectype, size, data );
|
||||||
break;
|
break;
|
||||||
|
case DrawingGroupRecord.sid:
|
||||||
|
retval = new DrawingGroupRecord( rectype, size, data );
|
||||||
|
break;
|
||||||
|
case DrawingRecordForBiffViewer.sid:
|
||||||
|
retval = new DrawingRecordForBiffViewer( rectype, size, data );
|
||||||
|
break;
|
||||||
|
case DrawingSelectionRecord.sid:
|
||||||
|
retval = new DrawingSelectionRecord( rectype, size, data );
|
||||||
|
break;
|
||||||
case GutsRecord.sid:
|
case GutsRecord.sid:
|
||||||
retval = new GutsRecord( rectype, size, data );
|
retval = new GutsRecord( rectype, size, data );
|
||||||
break;
|
break;
|
||||||
@ -633,25 +621,22 @@ public class BiffViewer {
|
|||||||
case SharedFormulaRecord.sid:
|
case SharedFormulaRecord.sid:
|
||||||
retval = new SharedFormulaRecord( rectype, size, data);
|
retval = new SharedFormulaRecord( rectype, size, data);
|
||||||
break;
|
break;
|
||||||
|
case ObjRecord.sid:
|
||||||
|
retval = new ObjRecord( rectype, size, data);
|
||||||
|
break;
|
||||||
|
case TextObjectRecord.sid:
|
||||||
|
retval = new TextObjectRecord( rectype, size, data);
|
||||||
|
break;
|
||||||
case HorizontalPageBreakRecord.sid:
|
case HorizontalPageBreakRecord.sid:
|
||||||
retval = new HorizontalPageBreakRecord( rectype, size, data);
|
retval = new HorizontalPageBreakRecord( rectype, size, data);
|
||||||
break;
|
break;
|
||||||
case VerticalPageBreakRecord.sid:
|
case VerticalPageBreakRecord.sid:
|
||||||
retval = new VerticalPageBreakRecord( rectype, size, data);
|
retval = new VerticalPageBreakRecord( rectype, size, data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
retval = new UnknownRecord( rectype, size, data );
|
retval = new UnknownRecord( rectype, size, data );
|
||||||
}
|
}
|
||||||
if ( realretval == null )
|
return retval;
|
||||||
{
|
|
||||||
realretval = new Record[1];
|
|
||||||
realretval[0] = retval;
|
|
||||||
System.out.println( "recordid = 0x" + Integer.toHexString( rectype ) + ", size =" + size );
|
|
||||||
System.out.println( realretval[0].toString() );
|
|
||||||
}
|
|
||||||
return realretval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -682,6 +667,7 @@ public class BiffViewer {
|
|||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
|
System.setProperty("poi.deserialize.escher", "true");
|
||||||
BiffViewer viewer = new BiffViewer(args);
|
BiffViewer viewer = new BiffViewer(args);
|
||||||
|
|
||||||
if ((args.length > 1) && args[1].equals("on")) {
|
if ((args.length > 1) && args[1].equals("on")) {
|
||||||
@ -704,4 +690,51 @@ public class BiffViewer {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class RecordDetails
|
||||||
|
{
|
||||||
|
short rectype, recsize;
|
||||||
|
int startloc;
|
||||||
|
byte[] data;
|
||||||
|
Record record;
|
||||||
|
|
||||||
|
public RecordDetails( short rectype, short recsize, int startloc, byte[] data, Record record )
|
||||||
|
{
|
||||||
|
this.rectype = rectype;
|
||||||
|
this.recsize = recsize;
|
||||||
|
this.startloc = startloc;
|
||||||
|
this.data = data;
|
||||||
|
this.record = record;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public short getRectype()
|
||||||
|
{
|
||||||
|
return rectype;
|
||||||
|
}
|
||||||
|
|
||||||
|
public short getRecsize()
|
||||||
|
{
|
||||||
|
return recsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getData()
|
||||||
|
{
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Record getRecord()
|
||||||
|
{
|
||||||
|
return record;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dump() throws IOException
|
||||||
|
{
|
||||||
|
if (record instanceof UnknownRecord)
|
||||||
|
dumpUnknownRecord(data);
|
||||||
|
else
|
||||||
|
dumpNormal(record, startloc, rectype, recsize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user