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));
|
||||
InputStream stream =
|
||||
fs.createDocumentInputStream("Workbook");
|
||||
Record[] records = createRecords(stream, dump);
|
||||
createRecords(stream, dump);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@ -128,17 +128,18 @@ public class BiffViewer {
|
||||
public static Record[] createRecords(InputStream in, boolean dump)
|
||||
throws RecordFormatException {
|
||||
ArrayList records = new ArrayList();
|
||||
Record last_record = null;
|
||||
// Record last_record = null;
|
||||
int loc = 0;
|
||||
|
||||
RecordDetails activeRecord = null;
|
||||
|
||||
try {
|
||||
// long offset = 0;
|
||||
short rectype = 0;
|
||||
|
||||
do {
|
||||
rectype = LittleEndian.readShort(in);
|
||||
System.out.println("============================================");
|
||||
System.out.println("Offset 0x" + Integer.toHexString(loc) + " (" + loc + ")");
|
||||
int startloc = loc;
|
||||
loc += 2;
|
||||
if (rectype != 0) {
|
||||
short recsize = LittleEndian.readShort(in);
|
||||
@ -147,36 +148,27 @@ public class BiffViewer {
|
||||
byte[] data = new byte[(int) recsize];
|
||||
|
||||
in.read(data);
|
||||
if ((rectype == WSBoolRecord.sid) && (recsize == 0)) {
|
||||
System.out.println(loc);
|
||||
}
|
||||
loc += recsize;
|
||||
// offset += 4 + recsize;
|
||||
Record record = createRecord(rectype, recsize, data );
|
||||
if (record.getSid() != ContinueRecord.sid)
|
||||
{
|
||||
records.add(record);
|
||||
if (activeRecord != null)
|
||||
activeRecord.dump();
|
||||
activeRecord = new RecordDetails(rectype, recsize, startloc, data, record);
|
||||
}
|
||||
else
|
||||
{
|
||||
activeRecord.getRecord().processContinueRecord(data);
|
||||
}
|
||||
if (dump) {
|
||||
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);
|
||||
}
|
||||
dumpRaw(rectype, recsize, data);
|
||||
}
|
||||
}
|
||||
} while (rectype != 0);
|
||||
|
||||
activeRecord.dump();
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RecordFormatException("Error reading bytes");
|
||||
}
|
||||
@ -186,15 +178,14 @@ public class BiffViewer {
|
||||
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 {
|
||||
if (last_record == null) {
|
||||
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 {
|
||||
// record hex dump it!
|
||||
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
|
||||
// .println("fixing to recordize the following");
|
||||
System.out.println("============================================");
|
||||
System.out.print( "rectype = 0x"
|
||||
+ Integer.toHexString( rectype ) );
|
||||
System.out.println( ", recsize = 0x"
|
||||
@ -275,19 +261,12 @@ public class BiffViewer {
|
||||
* Essentially a duplicate of RecordFactory. Kept seperate as not to screw
|
||||
* 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 )
|
||||
{
|
||||
Record retval = null;
|
||||
Record[] realretval = null;
|
||||
|
||||
// int irectype = rectype;
|
||||
switch ( rectype )
|
||||
{
|
||||
|
||||
@ -429,6 +408,15 @@ public class BiffViewer {
|
||||
case GridsetRecord.sid:
|
||||
retval = new GridsetRecord( rectype, size, data );
|
||||
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:
|
||||
retval = new GutsRecord( rectype, size, data );
|
||||
break;
|
||||
@ -633,25 +621,22 @@ public class BiffViewer {
|
||||
case SharedFormulaRecord.sid:
|
||||
retval = new SharedFormulaRecord( rectype, size, data);
|
||||
break;
|
||||
case ObjRecord.sid:
|
||||
retval = new ObjRecord( rectype, size, data);
|
||||
break;
|
||||
case TextObjectRecord.sid:
|
||||
retval = new TextObjectRecord( rectype, size, data);
|
||||
break;
|
||||
case HorizontalPageBreakRecord.sid:
|
||||
retval = new HorizontalPageBreakRecord( rectype, size, data);
|
||||
break;
|
||||
case VerticalPageBreakRecord.sid:
|
||||
retval = new VerticalPageBreakRecord( rectype, size, data);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
retval = new UnknownRecord( rectype, size, data );
|
||||
}
|
||||
if ( realretval == null )
|
||||
{
|
||||
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;
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
@ -682,6 +667,7 @@ public class BiffViewer {
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
System.setProperty("poi.deserialize.escher", "true");
|
||||
BiffViewer viewer = new BiffViewer(args);
|
||||
|
||||
if ((args.length > 1) && args[1].equals("on")) {
|
||||
@ -704,4 +690,51 @@ public class BiffViewer {
|
||||
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