avik        2003/08/23 11:54:28

  Modified:    src/java/org/apache/poi/hssf/model Tag: REL_2_BRANCH
                        Sheet.java
               src/java/org/apache/poi/hssf/record Tag: REL_2_BRANCH
                        ProtectRecord.java ProtectionRev4Record.java
               src/java/org/apache/poi/hssf/usermodel Tag: REL_2_BRANCH
                        HSSFSheet.java
               src/testcases/org/apache/poi/hssf/usermodel Tag:
                        REL_2_BRANCH TestBugs.java TestHSSFSheet.java
  Log:
  Bug id 21722: Protect record to Sheets
  Submitted by Rick Berman..Thanks.
  
  Revision  Changes    Path
  No                   revision
  No                   revision
  1.31.2.6  +28 -0     jakarta-poi/src/java/org/apache/poi/hssf/model/Sheet.java
  
  Index: Sheet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/model/Sheet.java,v
  retrieving revision 1.31.2.5
  retrieving revision 1.31.2.6
  diff -u -r1.31.2.5 -r1.31.2.6
  --- Sheet.java        25 Jul 2003 14:28:51 -0000      1.31.2.5
  +++ Sheet.java        23 Aug 2003 18:54:28 -0000      1.31.2.6
  @@ -122,6 +122,7 @@
       private Iterator                    valueRecIterator = null;
       private Iterator                    rowRecIterator   = null;
       protected int                       eofLoc           = 0;
  +     protected ProtectRecord             protect          = null;
   
       public static final byte PANE_LOWER_RIGHT = (byte)0;
       public static final byte PANE_UPPER_RIGHT = (byte)1;
  @@ -287,6 +288,10 @@
               {
                   retval.windowTwo = (WindowTwoRecord) rec;
               }
  +                     else if ( rec.getSid() == ProtectRecord.sid )
  +                     {
  +                             retval.protect = (ProtectRecord) rec;
  +                     }
   
               if (rec != null)
               {
  @@ -418,6 +423,8 @@
           retval.selection = 
                   (SelectionRecord) retval.createSelection();
           records.add(retval.selection);
  +             retval.protect = (ProtectRecord) retval.createProtect();
  +             records.add(retval.protect);
           records.add(retval.createEOF());
           retval.records = records;
           log.log(log.DEBUG, "Sheet createsheet from scratch exit");
  @@ -2524,6 +2531,27 @@
       {
           this.selection = selection;
       }
  +       /**
  +        * creates a Protect record with protect set to false.
  +        * @see org.apache.poi.hssf.record.ProtectRecord
  +        * @see org.apache.poi.hssf.record.Record
  +        * @return a ProtectRecord
  +        */
  +
  +       protected Record createProtect()
  +       {
  +               log.log(log.DEBUG, "create protect record with protection disabled");
  +               ProtectRecord retval = new ProtectRecord();
  +
  +               retval.setProtect(false);
  +               // by default even when we support encryption we won't
  +               return retval;
  +       }
  +
  +       public ProtectRecord getProtect()
  +       {
  +               return protect;
  +     }
   
       /**
        * Sets whether the gridlines are shown in a viewer.
  
  
  
  No                   revision
  No                   revision
  1.5.2.1   +5 -5      
jakarta-poi/src/java/org/apache/poi/hssf/record/ProtectRecord.java
  
  Index: ProtectRecord.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/record/ProtectRecord.java,v
  retrieving revision 1.5
  retrieving revision 1.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- ProtectRecord.java        30 Apr 2003 04:38:47 -0000      1.5
  +++ ProtectRecord.java        23 Aug 2003 18:54:28 -0000      1.5.2.1
  @@ -139,9 +139,9 @@
        * @return whether to protect the sheet or not
        */
   
  -    public short getProtect()
  +    public boolean getProtect()
       {
  -        return field_1_protect;
  +        return (field_1_protect == 1);
       }
   
       public String toString()
  @@ -149,8 +149,8 @@
           StringBuffer buffer = new StringBuffer();
   
           buffer.append("[PROTECT]\n");
  -        buffer.append("    .protected      = ")
  -            .append(Integer.toHexString(getProtect())).append("\n");
  +         buffer.append("    .protect         = ").append(getProtect())
  +            .append("\n");
           buffer.append("[/PROTECT]\n");
           return buffer.toString();
       }
  @@ -160,7 +160,7 @@
           LittleEndian.putShort(data, 0 + offset, sid);
           LittleEndian.putShort(data, 2 + offset,
                                 (( short ) 0x02));   // 2 bytes (6 total)
  -        LittleEndian.putShort(data, 4 + offset, getProtect());
  +        LittleEndian.putShort(data, 4 + offset, field_1_protect);
           return getRecordSize();
       }
   
  
  
  
  1.4.2.1   +7 -7      
jakarta-poi/src/java/org/apache/poi/hssf/record/ProtectionRev4Record.java
  
  Index: ProtectionRev4Record.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/record/ProtectionRev4Record.java,v
  retrieving revision 1.4
  retrieving revision 1.4.2.1
  diff -u -r1.4 -r1.4.2.1
  --- ProtectionRev4Record.java 30 Apr 2003 04:38:48 -0000      1.4
  +++ ProtectionRev4Record.java 23 Aug 2003 18:54:28 -0000      1.4.2.1
  @@ -139,18 +139,18 @@
        * @return whether to protect the workbook or not
        */
   
  -    public short getProtect()
  -    {
  -        return field_1_protect;
  -    }
  +     public boolean getProtect()
  +     {
  +             return (field_1_protect == 1);
  +     }
   
       public String toString()
       {
           StringBuffer buffer = new StringBuffer();
   
           buffer.append("[PROT4REV]\n");
  -        buffer.append("    .rowheight      = ")
  -            .append(Integer.toHexString(getProtect())).append("\n");
  +         buffer.append("    .protect         = ").append(getProtect())
  +            .append("\n");
           buffer.append("[/PROT4REV]\n");
           return buffer.toString();
       }
  @@ -160,7 +160,7 @@
           LittleEndian.putShort(data, 0 + offset, sid);
           LittleEndian.putShort(data, 2 + offset,
                                 (( short ) 0x02));   // 2 bytes (6 total)
  -        LittleEndian.putShort(data, 4 + offset, getProtect());
  +        LittleEndian.putShort(data, 4 + offset, field_1_protect);
           return getRecordSize();
       }
   
  
  
  
  No                   revision
  No                   revision
  1.21.2.3  +17 -1     
jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
  
  Index: HSSFSheet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java,v
  retrieving revision 1.21.2.2
  retrieving revision 1.21.2.3
  diff -u -r1.21.2.2 -r1.21.2.3
  --- HSSFSheet.java    25 Jul 2003 14:28:51 -0000      1.21.2.2
  +++ HSSFSheet.java    23 Aug 2003 18:54:28 -0000      1.21.2.3
  @@ -873,6 +873,22 @@
       {
           getSheet().setMargin( margin, size );
       }
  +    
  +     /**
  +      * Answer whether protection is enabled or disabled
  +      * @return true => protection enabled; false => protection disabled
  +      */
  +     public boolean getProtect() {
  +             return getSheet().getProtect().getProtect();            
  +     }
  +
  +     /**
  +      * Sets the protection on enabled or disabled
  +      * @param protect true => protection enabled; false => protection disabled
  +      */
  +     public void setProtect(boolean protect) {
  +             getSheet().getProtect().setProtect(protect);            
  +     }
   
       /**
        * Sets the zoom magnication for the sheet.  The zoom is expressed as a
  @@ -916,7 +932,7 @@
                         //dont check if it's not within the shifted area
                         if (! (inStart && inEnd)) continue;
                        
  -                      //only shift if the region outside the shifted rows is not 
merged too                                  
  +                      //only shift if the region outside the shifted rows is not 
merged too                                  
                         if (!merged.contains(startRow-1, (short)0) && 
!merged.contains(endRow+1, (short)0)){
                                 merged.setRowFrom(merged.getRowFrom()+n);             
                         
                                 merged.setRowTo(merged.getRowTo()+n);
  
  
  
  No                   revision
  No                   revision
  1.1.2.3   +1 -0      
jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
  
  Index: TestBugs.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java,v
  retrieving revision 1.1.2.2
  retrieving revision 1.1.2.3
  diff -u -r1.1.2.2 -r1.1.2.3
  --- TestBugs.java     31 Jul 2003 19:59:49 -0000      1.1.2.2
  +++ TestBugs.java     23 Aug 2003 18:54:28 -0000      1.1.2.3
  @@ -109,6 +109,7 @@
             assertTrue("File Should Exist", file.exists());
               
       }
  +                 
             
             
       
  
  
  
  1.12.2.5  +22 -0     
jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java
  
  Index: TestHSSFSheet.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java,v
  retrieving revision 1.12.2.4
  retrieving revision 1.12.2.5
  diff -u -r1.12.2.4 -r1.12.2.5
  --- TestHSSFSheet.java        25 Jul 2003 14:28:52 -0000      1.12.2.4
  +++ TestHSSFSheet.java        23 Aug 2003 18:54:28 -0000      1.12.2.5
  @@ -62,6 +62,7 @@
   
   import org.apache.poi.hssf.model.Sheet;
   import org.apache.poi.hssf.record.HCenterRecord;
  +import org.apache.poi.hssf.record.ProtectRecord;
   import org.apache.poi.hssf.record.SCLRecord;
   import org.apache.poi.hssf.record.VCenterRecord;
   import org.apache.poi.hssf.record.WSBoolRecord;
  @@ -238,6 +239,27 @@
           cell.setCellValue("Difference Check");
           
assertEquals(cloned.getRow((short)0).getCell((short)0).getStringCellValue(), 
"clone_test");
       }
  +    
  +     /**
  +      * Test that the ProtectRecord is included when creating or cloning a sheet
  +      */
  +     public void testProtect() {
  +             HSSFWorkbook workbook = new HSSFWorkbook();
  +             HSSFSheet hssfSheet = workbook.createSheet();
  +             Sheet sheet = hssfSheet.getSheet();
  +             ProtectRecord protect = sheet.getProtect();
  +     
  +             assertFalse(protect.getProtect());
  +
  +             // This will tell us that cloneSheet, and by extension,
  +             // the list forms of createSheet leave us with an accessible
  +             // ProtectRecord.
  +             hssfSheet.setProtect(true);
  +             Sheet cloned = sheet.cloneSheet();
  +             assertNotNull(cloned.getProtect());
  +             assertTrue(hssfSheet.getProtect());
  +     }
  +
   
       public void testZoom()
               throws Exception
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to