]> source.dussan.org Git - poi.git/commitdiff
Added explicit RecordFormatException when a FilePass record (indicating that the...
authorJason Height <jheight@apache.org>
Sun, 27 Aug 2006 12:00:36 +0000 (12:00 +0000)
committerJason Height <jheight@apache.org>
Sun, 27 Aug 2006 12:00:36 +0000 (12:00 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@437370 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/dev/BiffViewer.java
src/java/org/apache/poi/hssf/eventmodel/EventRecordFactory.java
src/java/org/apache/poi/hssf/record/FilePassRecord.java [new file with mode: 0644]
src/java/org/apache/poi/hssf/record/RecordFactory.java
src/java/org/apache/poi/hssf/record/UnknownRecord.java
src/java/org/apache/poi/hssf/record/WriteProtectRecord.java [new file with mode: 0644]

index df62f7c6dc830a9e648d83c392710652882fe89b..4867ad56865c0adca89571b0cf93bdba57690937 100644 (file)
@@ -502,6 +502,12 @@ public class BiffViewer {
             case VerticalPageBreakRecord.sid:
                 retval = new VerticalPageBreakRecord( in);
                 break;
+            case WriteProtectRecord.sid:
+               retval = new WriteProtectRecord( in);
+               break;
+            case FilePassRecord.sid:
+               retval = new FilePassRecord(in);
+               break;
             default:
                 retval = new UnknownRecord( in );
         }
index 2532ad72fbf294f50a1b25b3e384074571b23f4c..526b8b8ffccfa54bddf1aaea896368aab57ed9de 100644 (file)
@@ -103,6 +103,8 @@ import org.apache.poi.hssf.record.WindowOneRecord;
 import org.apache.poi.hssf.record.WindowProtectRecord;
 import org.apache.poi.hssf.record.WindowTwoRecord;
 import org.apache.poi.hssf.record.WriteAccessRecord;
+import org.apache.poi.hssf.record.WriteProtectRecord;
+import org.apache.poi.hssf.record.FilePassRecord;
 
 
 /**
@@ -153,7 +155,8 @@ public class EventRecordFactory
                 BoolErrRecord.class, ExternSheetRecord.class, NameRecord.class,
                 LeftMarginRecord.class, RightMarginRecord.class,
                 TopMarginRecord.class, BottomMarginRecord.class,
-                PaletteRecord.class, StringRecord.class, SharedFormulaRecord.class
+                PaletteRecord.class, StringRecord.class, SharedFormulaRecord.class, 
+                WriteProtectRecord.class, FilePassRecord.class
             };
        
     }
diff --git a/src/java/org/apache/poi/hssf/record/FilePassRecord.java b/src/java/org/apache/poi/hssf/record/FilePassRecord.java
new file mode 100644 (file)
index 0000000..b4ac4d0
--- /dev/null
@@ -0,0 +1,106 @@
+\r
+/* ====================================================================\r
+   Copyright 2002-2004   Apache Software Foundation\r
+\r
+   Licensed under the Apache License, Version 2.0 (the "License");\r
+   you may not use this file except in compliance with the License.\r
+   You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+        \r
+\r
+package org.apache.poi.hssf.record;\r
+\r
+import org.apache.poi.util.LittleEndian;\r
+\r
+/**\r
+ * Title:        File Pass Record<P>\r
+ * Description:  Indicates that the record after this record are encrypted. HSSF does not support encrypted excel workbooks\r
+ * and the presence of this record will cause processing to be aborted.<p>\r
+ * REFERENCE:  PG 420 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>\r
+ * @author Jason Height (jheight at chariot dot net dot au)\r
+ * @version 3.0-pre\r
+ */\r
+\r
+public class FilePassRecord\r
+    extends Record\r
+{\r
+    public final static short sid = 0x2F;\r
+    private int             field_1_encryptedpassword;\r
+\r
+    public FilePassRecord()\r
+    {\r
+    }\r
+\r
+    /**\r
+     * Constructs a FILEPASS record and sets its fields appropriately.\r
+     *\r
+     * @param id     id must be 0x84 or an exception will be throw upon validation\r
+     * @param size  the size of the data area of the record\r
+     * @param data  data of the record (should not contain sid/len)\r
+     */\r
+\r
+    public FilePassRecord(RecordInputStream in)\r
+    {\r
+        super(in);\r
+    }\r
+\r
+    protected void validateSid(short id)\r
+    {\r
+        if (id != sid)\r
+        {\r
+            throw new RecordFormatException("NOT A FILEPASS RECORD");\r
+        }\r
+    }\r
+\r
+    protected void fillFields(RecordInputStream in)\r
+    {\r
+        field_1_encryptedpassword = in.readInt();\r
+        \r
+        //Whilst i have read in the password, HSSF currently has no plans to support/decrypt the remainder\r
+        //of this workbook\r
+        throw new RecordFormatException("HSSF does not currently support encrypted workbooks");\r
+    }\r
+\r
+    public String toString()\r
+    {\r
+        StringBuffer buffer = new StringBuffer();\r
+\r
+        buffer.append("[FILEPASS]\n");\r
+        buffer.append("    .password        = ").append(field_1_encryptedpassword)\r
+            .append("\n");\r
+        buffer.append("[/FILEPASS]\n");\r
+        return buffer.toString();\r
+    }\r
+\r
+    public int serialize(int offset, byte [] data)\r
+    {\r
+        LittleEndian.putShort(data, 0 + offset, sid);\r
+        LittleEndian.putShort(data, 2 + offset, ( short ) 0x4);\r
+        LittleEndian.putInt(data, 4 + offset, ( short ) field_1_encryptedpassword);\r
+        return getRecordSize();\r
+    }\r
+\r
+    public int getRecordSize()\r
+    {\r
+        return 8;\r
+    }\r
+\r
+    public short getSid()\r
+    {\r
+        return sid;\r
+    }\r
+\r
+    public Object clone() {\r
+      FilePassRecord rec = new FilePassRecord();\r
+      rec.field_1_encryptedpassword = field_1_encryptedpassword;\r
+      return rec;\r
+    }\r
+}\r
index 9f5901c050ea4955311df61174cb68ead82b630d..5224f3bbc94d2ab07e4d92778268b3853dad23a1 100644 (file)
@@ -72,7 +72,8 @@ public class RecordFactory
                 DrawingRecord.class, DrawingGroupRecord.class, DrawingSelectionRecord.class,
                 ObjRecord.class, TextObjectRecord.class,
                 PaletteRecord.class, StringRecord.class, RecalcIdRecord.class, SharedFormulaRecord.class,
-                HorizontalPageBreakRecord.class, VerticalPageBreakRecord.class
+                HorizontalPageBreakRecord.class, VerticalPageBreakRecord.class, 
+                WriteProtectRecord.class, FilePassRecord.class
             };
         } else {
             records = new Class[]
@@ -106,7 +107,8 @@ public class RecordFactory
                 PaletteRecord.class, StringRecord.class, RecalcIdRecord.class, SharedFormulaRecord.class,
                 DrawingRecord.class, DrawingGroupRecord.class, DrawingSelectionRecord.class,
                 ObjRecord.class, TextObjectRecord.class,
-                HorizontalPageBreakRecord.class, VerticalPageBreakRecord.class
+                HorizontalPageBreakRecord.class, VerticalPageBreakRecord.class, 
+                WriteProtectRecord.class, FilePassRecord.class
             };
 
         }
index e61bc76e3267f1bcfeb37920969e3c86972ad85f..37b2f9646bfea29ca90bf473ddf371bb63d22bc2 100644 (file)
@@ -66,6 +66,8 @@ public class UnknownRecord
     {
         sid     = in.getSid();
         thedata = in.readRemainder();
+        
+        //System.out.println("UnknownRecord: 0x"+Integer.toHexString(sid));
     }
 
     /**
diff --git a/src/java/org/apache/poi/hssf/record/WriteProtectRecord.java b/src/java/org/apache/poi/hssf/record/WriteProtectRecord.java
new file mode 100644 (file)
index 0000000..4830e39
--- /dev/null
@@ -0,0 +1,91 @@
+\r
+/* ====================================================================\r
+   Copyright 2002-2004   Apache Software Foundation\r
+\r
+   Licensed under the Apache License, Version 2.0 (the "License");\r
+   you may not use this file except in compliance with the License.\r
+   You may obtain a copy of the License at\r
+\r
+       http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+==================================================================== */\r
+        \r
+\r
+package org.apache.poi.hssf.record;\r
+\r
+import org.apache.poi.util.LittleEndian;\r
+import org.apache.poi.util.StringUtil;\r
+\r
+/**\r
+ * Title:        Write Protect Record<P>\r
+ * Description:  Indicated that the sheet/workbook is write protected. \r
+ * REFERENCE:  PG 425 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>\r
+ * @version 3.0-pre\r
+ */\r
+\r
+public class WriteProtectRecord\r
+    extends Record\r
+{\r
+    public final static short sid = 0x86;\r
+\r
+    public WriteProtectRecord()\r
+    {\r
+    }\r
+\r
+    /**\r
+     * Constructs a WriteAccess record and sets its fields appropriately.\r
+     *\r
+     * @param id     id must be 0x5c or an exception will be throw upon validation\r
+     * @param size  the size of the data area of the record\r
+     * @param data  data of the record (should not contain sid/len)\r
+     */\r
+\r
+    public WriteProtectRecord(RecordInputStream in)\r
+    {\r
+        super(in);\r
+    }\r
+\r
+    protected void validateSid(short id)\r
+    {\r
+        if (id != sid)\r
+        {\r
+            throw new RecordFormatException("NOT A WRITEPROTECT RECORD");\r
+        }\r
+    }\r
+\r
+    protected void fillFields(RecordInputStream in)\r
+    {\r
+    }\r
+\r
+    public String toString()\r
+    {\r
+        StringBuffer buffer = new StringBuffer();\r
+\r
+        buffer.append("[WRITEPROTECT]\n");\r
+        buffer.append("[/WRITEPROTECT]\n");\r
+        return buffer.toString();\r
+    }\r
+\r
+    public int serialize(int offset, byte [] data)\r
+    {\r
+        LittleEndian.putShort(data, 0 + offset, sid);\r
+        LittleEndian.putShort(data, 2 + offset, (short)0);\r
+\r
+        return getRecordSize();\r
+    }\r
+\r
+    public int getRecordSize()\r
+    {\r
+        return 4;\r
+    }\r
+\r
+    public short getSid()\r
+    {\r
+        return sid;\r
+    }\r
+}\r