View | Details | Raw Unified | Return to bug 21722
Collapse All | Expand All

(-)jakarta-poi/src/java/org/apache/poi/hssf/model/Sheet.java (+28 lines)
Lines 120-125 Link Here
120
    private Iterator                    valueRecIterator = null;
120
    private Iterator                    valueRecIterator = null;
121
    private Iterator                    rowRecIterator   = null;
121
    private Iterator                    rowRecIterator   = null;
122
    protected int                       eofLoc           = 0;
122
    protected int                       eofLoc           = 0;
123
	protected ProtectRecord             protect          = null;
123
124
124
    public static final byte PANE_LOWER_RIGHT = (byte)0;
125
    public static final byte PANE_LOWER_RIGHT = (byte)0;
125
    public static final byte PANE_UPPER_RIGHT = (byte)1;
126
    public static final byte PANE_UPPER_RIGHT = (byte)1;
Lines 265-270 Link Here
265
            {
266
            {
266
                retval.selection = (SelectionRecord) rec;
267
                retval.selection = (SelectionRecord) rec;
267
            }
268
            }
269
			else if ( rec.getSid() == ProtectRecord.sid )
270
			{
271
				retval.protect = (ProtectRecord) rec;
272
			}
268
273
269
            if (rec != null)
274
            if (rec != null)
270
            {
275
            {
Lines 396-401 Link Here
396
        retval.selection = 
401
        retval.selection = 
397
                (SelectionRecord) retval.createSelection();
402
                (SelectionRecord) retval.createSelection();
398
        records.add(retval.selection);
403
        records.add(retval.selection);
404
		retval.protect = (ProtectRecord) retval.createProtect();
405
		records.add(retval.protect);
399
        records.add(retval.createEOF());
406
        records.add(retval.createEOF());
400
        retval.records = records;
407
        retval.records = records;
401
        log.log(log.DEBUG, "Sheet createsheet from scratch exit");
408
        log.log(log.DEBUG, "Sheet createsheet from scratch exit");
Lines 2529-2532 Link Here
2529
        this.selection = selection;
2536
        this.selection = selection;
2530
    }
2537
    }
2531
2538
2539
	/**
2540
	 * creates a Protect record with protect set to false.
2541
	 * @see org.apache.poi.hssf.record.ProtectRecord
2542
	 * @see org.apache.poi.hssf.record.Record
2543
	 * @return a ProtectRecord
2544
	 */
2545
2546
	protected Record createProtect()
2547
	{
2548
		log.log(log.DEBUG, "create protect record with protection disabled");
2549
		ProtectRecord retval = new ProtectRecord();
2550
2551
		retval.setProtect(false);
2552
		// by default even when we support encryption we won't
2553
		return retval; // want to default to be protected
2554
	}
2555
	
2556
	public ProtectRecord getProtect()
2557
	{
2558
		return protect;
2559
	}
2532
}
2560
}
(-)jakarta-poi/src/java/org/apache/poi/hssf/record/ProtectRecord.java (-5 / +5 lines)
Lines 139-147 Link Here
139
     * @return whether to protect the sheet or not
139
     * @return whether to protect the sheet or not
140
     */
140
     */
141
141
142
    public short getProtect()
142
    public boolean getProtect()
143
    {
143
    {
144
        return field_1_protect;
144
        return (field_1_protect == 1);
145
    }
145
    }
146
146
147
    public String toString()
147
    public String toString()
Lines 149-156 Link Here
149
        StringBuffer buffer = new StringBuffer();
149
        StringBuffer buffer = new StringBuffer();
150
150
151
        buffer.append("[PROTECT]\n");
151
        buffer.append("[PROTECT]\n");
152
        buffer.append("    .protected      = ")
152
		buffer.append("    .protect         = ").append(getProtect())
153
            .append(Integer.toHexString(getProtect())).append("\n");
153
            .append("\n");
154
        buffer.append("[/PROTECT]\n");
154
        buffer.append("[/PROTECT]\n");
155
        return buffer.toString();
155
        return buffer.toString();
156
    }
156
    }
Lines 160-166 Link Here
160
        LittleEndian.putShort(data, 0 + offset, sid);
160
        LittleEndian.putShort(data, 0 + offset, sid);
161
        LittleEndian.putShort(data, 2 + offset,
161
        LittleEndian.putShort(data, 2 + offset,
162
                              (( short ) 0x02));   // 2 bytes (6 total)
162
                              (( short ) 0x02));   // 2 bytes (6 total)
163
        LittleEndian.putShort(data, 4 + offset, getProtect());
163
        LittleEndian.putShort(data, 4 + offset, field_1_protect);
164
        return getRecordSize();
164
        return getRecordSize();
165
    }
165
    }
166
166
(-)jakarta-poi/src/java/org/apache/poi/hssf/record/ProtectionRev4Record.java (-7 / +7 lines)
Lines 139-156 Link Here
139
     * @return whether to protect the workbook or not
139
     * @return whether to protect the workbook or not
140
     */
140
     */
141
141
142
    public short getProtect()
142
	public boolean getProtect()
143
    {
143
	{
144
        return field_1_protect;
144
		return (field_1_protect == 1);
145
    }
145
	}
146
146
147
    public String toString()
147
    public String toString()
148
    {
148
    {
149
        StringBuffer buffer = new StringBuffer();
149
        StringBuffer buffer = new StringBuffer();
150
150
151
        buffer.append("[PROT4REV]\n");
151
        buffer.append("[PROT4REV]\n");
152
        buffer.append("    .rowheight      = ")
152
		buffer.append("    .protect         = ").append(getProtect())
153
            .append(Integer.toHexString(getProtect())).append("\n");
153
            .append("\n");
154
        buffer.append("[/PROT4REV]\n");
154
        buffer.append("[/PROT4REV]\n");
155
        return buffer.toString();
155
        return buffer.toString();
156
    }
156
    }
Lines 160-166 Link Here
160
        LittleEndian.putShort(data, 0 + offset, sid);
160
        LittleEndian.putShort(data, 0 + offset, sid);
161
        LittleEndian.putShort(data, 2 + offset,
161
        LittleEndian.putShort(data, 2 + offset,
162
                              (( short ) 0x02));   // 2 bytes (6 total)
162
                              (( short ) 0x02));   // 2 bytes (6 total)
163
        LittleEndian.putShort(data, 4 + offset, getProtect());
163
        LittleEndian.putShort(data, 4 + offset, field_1_protect);
164
        return getRecordSize();
164
        return getRecordSize();
165
    }
165
    }
166
166
(-)jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java (+16 lines)
Lines 873-878 Link Here
873
    {
873
    {
874
        getSheet().setMargin( margin, size );
874
        getSheet().setMargin( margin, size );
875
    }
875
    }
876
    
877
	/**
878
	 * Answer whether protection is enabled or disabled
879
	 * @return true => protection enabled; false => protection disabled
880
	 */
881
	public boolean getProtect() {
882
		return getSheet().getProtect().getProtect();		
883
	}
884
885
	/**
886
	 * Sets the protection on enabled or disabled
887
	 * @param protect true => protection enabled; false => protection disabled
888
	 */
889
	public void setProtect(boolean protect) {
890
		getSheet().getProtect().setProtect(protect);		
891
	}
876
892
877
    /**
893
    /**
878
     * Sets the zoom magnication for the sheet.  The zoom is expressed as a
894
     * Sets the zoom magnication for the sheet.  The zoom is expressed as a
(-)jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java (+22 lines)
Lines 62-67 Link Here
62
62
63
import org.apache.poi.hssf.model.Sheet;
63
import org.apache.poi.hssf.model.Sheet;
64
import org.apache.poi.hssf.record.HCenterRecord;
64
import org.apache.poi.hssf.record.HCenterRecord;
65
import org.apache.poi.hssf.record.ProtectRecord;
65
import org.apache.poi.hssf.record.SCLRecord;
66
import org.apache.poi.hssf.record.SCLRecord;
66
import org.apache.poi.hssf.record.VCenterRecord;
67
import org.apache.poi.hssf.record.VCenterRecord;
67
import org.apache.poi.hssf.record.WSBoolRecord;
68
import org.apache.poi.hssf.record.WSBoolRecord;
Lines 238-243 Link Here
238
        cell.setCellValue("Difference Check");
239
        cell.setCellValue("Difference Check");
239
        assertEquals(cloned.getRow((short)0).getCell((short)0).getStringCellValue(), "clone_test");
240
        assertEquals(cloned.getRow((short)0).getCell((short)0).getStringCellValue(), "clone_test");
240
    }
241
    }
242
    
243
	/**
244
	 * Test that the ProtectRecord is included when creating or cloning a sheet
245
	 */
246
	public void testProtect() {
247
		HSSFWorkbook workbook = new HSSFWorkbook();
248
		HSSFSheet hssfSheet = workbook.createSheet();
249
		Sheet sheet = hssfSheet.getSheet();
250
		ProtectRecord protect = sheet.getProtect();
251
   	
252
		assertFalse(protect.getProtect());
253
254
		// This will tell us that cloneSheet, and by extension,
255
		// the list forms of createSheet leave us with an accessible
256
		// ProtectRecord.
257
		hssfSheet.setProtect(true);
258
		Sheet cloned = sheet.cloneSheet();
259
		assertNotNull(cloned.getProtect());
260
		assertTrue(hssfSheet.getProtect());
261
	}
262
241
263
242
    public void testZoom()
264
    public void testZoom()
243
            throws Exception
265
            throws Exception

Return to bug 21722