You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by gl...@apache.org on 2004/02/10 23:01:31 UTC

cvs commit: jakarta-poi/src/java/org/apache/poi/hssf/dev BiffViewer.java

glens       2004/02/10 14:01:31

  Modified:    src/java/org/apache/poi/hssf/dev Tag: REL_2_BRANCH
                        BiffViewer.java
  Log:
  Biff viewer changes for office drawing support
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.31.2.2  +94 -61    jakarta-poi/src/java/org/apache/poi/hssf/dev/BiffViewer.java
  
  Index: BiffViewer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/dev/BiffViewer.java,v
  retrieving revision 1.31.2.1
  retrieving revision 1.31.2.2
  diff -u -r1.31.2.1 -r1.31.2.2
  --- BiffViewer.java	9 Feb 2004 22:41:27 -0000	1.31.2.1
  +++ BiffViewer.java	10 Feb 2004 22:01:31 -0000	1.31.2.2
  @@ -107,7 +107,7 @@
                       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 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 @@
                       byte[] data = new byte[(int) recsize];
   
                       in.read(data);
  -                    if ((rectype == WSBoolRecord.sid) && (recsize == 0)) {
  -                        System.out.println(loc);
  -                    }
                       loc += recsize;
  -//                    offset += 4 + recsize;
  -                    if (dump) {
  -                        dump(rectype, recsize, data);
  +                    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);
                       }
  -                    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);
  +                    else
  +                    {
  +                        activeRecord.getRecord().processContinueRecord(data);
                       }
  -                    if (record != null) {
  -                        if (rectype == ContinueRecord.sid) {
  -                            dumpContinueRecord(last_record, dump, data);
  -                        } else {
  -                            last_record = record;
  -                            records.add(record);
  -                        }
  +                    if (dump) {
  +                        dumpRaw(rectype, recsize, data);
                       }
                   }
               } while (rectype != 0);
  +
  +            activeRecord.dump();
  +
           } catch (IOException e) {
               throw new RecordFormatException("Error reading bytes");
           }
  @@ -186,15 +178,14 @@
           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 @@
       }
   
   
  -    /**
  -     *  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 @@
       }
   
   
  -    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 @@
        *  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 @@
               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 @@
               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 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 @@
               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);
  +        }
  +    }
  +
   }
  +
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-dev-help@jakarta.apache.org