01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17:
18: package org.apache.poi.hssf.record;
19:
20: import org.apache.poi.util.LittleEndian;
21:
22: /**
23: * Title: File Pass Record<P>
24: * Description: Indicates that the record after this record are encrypted. HSSF does not support encrypted excel workbooks
25: * and the presence of this record will cause processing to be aborted.<p>
26: * REFERENCE: PG 420 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
27: * @author Jason Height (jheight at chariot dot net dot au)
28: * @version 3.0-pre
29: */
30:
31: public class FilePassRecord extends Record {
32: public final static short sid = 0x2F;
33: private int field_1_encryptedpassword;
34:
35: public FilePassRecord() {
36: }
37:
38: /**
39: * Constructs a FILEPASS record and sets its fields appropriately.
40: * @param in the RecordInputstream to read the record from
41: */
42:
43: public FilePassRecord(RecordInputStream in) {
44: super (in);
45: }
46:
47: protected void validateSid(short id) {
48: if (id != sid) {
49: throw new RecordFormatException("NOT A FILEPASS RECORD");
50: }
51: }
52:
53: protected void fillFields(RecordInputStream in) {
54: field_1_encryptedpassword = in.readInt();
55:
56: //Whilst i have read in the password, HSSF currently has no plans to support/decrypt the remainder
57: //of this workbook
58: throw new RecordFormatException(
59: "HSSF does not currently support encrypted workbooks");
60: }
61:
62: public String toString() {
63: StringBuffer buffer = new StringBuffer();
64:
65: buffer.append("[FILEPASS]\n");
66: buffer.append(" .password = ").append(
67: field_1_encryptedpassword).append("\n");
68: buffer.append("[/FILEPASS]\n");
69: return buffer.toString();
70: }
71:
72: public int serialize(int offset, byte[] data) {
73: LittleEndian.putShort(data, 0 + offset, sid);
74: LittleEndian.putShort(data, 2 + offset, (short) 0x4);
75: LittleEndian.putInt(data, 4 + offset,
76: (short) field_1_encryptedpassword);
77: return getRecordSize();
78: }
79:
80: public int getRecordSize() {
81: return 8;
82: }
83:
84: public short getSid() {
85: return sid;
86: }
87:
88: public Object clone() {
89: FilePassRecord rec = new FilePassRecord();
90: rec.field_1_encryptedpassword = field_1_encryptedpassword;
91: return rec;
92: }
93: }
|