001: /* ====================================================================
002: Licensed to the Apache Software Foundation (ASF) under one or more
003: contributor license agreements. See the NOTICE file distributed with
004: this work for additional information regarding copyright ownership.
005: The ASF licenses this file to You under the Apache License, Version 2.0
006: (the "License"); you may not use this file except in compliance with
007: the License. You may obtain a copy of the License at
008:
009: http://www.apache.org/licenses/LICENSE-2.0
010:
011: Unless required by applicable law or agreed to in writing, software
012: distributed under the License is distributed on an "AS IS" BASIS,
013: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: See the License for the specific language governing permissions and
015: limitations under the License.
016: ==================================================================== */
017:
018: package org.apache.poi.hssf.record;
019:
020: import org.apache.poi.util.LittleEndian;
021:
022: /**
023: * Title: Scenario Protect Record<P>
024: * Description: I have no idea what a Scenario is or why on would want to
025: * protect it with the lamest "security" ever invented. However this record tells
026: * excel "I want to protect my scenarios" (0xAF) with lame security. It appears
027: * in conjunction with the PASSWORD and PROTECT records as well as its object
028: * protect cousin.<P>
029: * REFERENCE: PG 383 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
030: * @author Andrew C. Oliver (acoliver at apache dot org)
031: */
032:
033: public class ScenarioProtectRecord extends Record {
034: public final static short sid = 0xdd;
035: private short field_1_protect;
036:
037: public ScenarioProtectRecord() {
038: }
039:
040: /**
041: * Constructs a Protect record and sets its fields appropriately.
042: * @param in the RecordInputstream to read the record from
043: */
044:
045: public ScenarioProtectRecord(RecordInputStream in) {
046: super (in);
047: }
048:
049: protected void validateSid(short id) {
050: if (id != sid) {
051: throw new RecordFormatException(
052: "NOT A SCENARIOPROTECT RECORD");
053: }
054: }
055:
056: protected void fillFields(RecordInputStream in) {
057: field_1_protect = in.readShort();
058: }
059:
060: /**
061: * set whether the sheet is protected or not
062: * @param protect whether to protect the sheet or not
063: */
064:
065: public void setProtect(boolean protect) {
066: if (protect) {
067: field_1_protect = 1;
068: } else {
069: field_1_protect = 0;
070: }
071: }
072:
073: /**
074: * get whether the sheet is protected or not
075: * @return whether to protect the sheet or not
076: */
077:
078: public boolean getProtect() {
079: return (field_1_protect == 1);
080: }
081:
082: public String toString() {
083: StringBuffer buffer = new StringBuffer();
084:
085: buffer.append("[SCENARIOPROTECT]\n");
086: buffer.append(" .protect = ").append(getProtect())
087: .append("\n");
088: buffer.append("[/SCENARIOPROTECT]\n");
089: return buffer.toString();
090: }
091:
092: public int serialize(int offset, byte[] data) {
093: LittleEndian.putShort(data, 0 + offset, sid);
094: LittleEndian.putShort(data, 2 + offset, ((short) 0x02)); // 2 bytes (6 total)
095: LittleEndian.putShort(data, 4 + offset, field_1_protect);
096: return getRecordSize();
097: }
098:
099: public int getRecordSize() {
100: return 6;
101: }
102:
103: public short getSid() {
104: return sid;
105: }
106:
107: public Object clone() {
108: ScenarioProtectRecord rec = new ScenarioProtectRecord();
109: rec.field_1_protect = field_1_protect;
110: return rec;
111: }
112: }
|