poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject cvs commit: jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel TestCloneSheet.java
Date Mon, 27 Oct 2003 02:01:22 GMT
avik        2003/10/26 18:01:21

  Modified:    src/java/org/apache/poi/hssf/record BoundSheetRecord.java
               src/java/org/apache/poi/hssf/usermodel HSSFWorkbook.java
               src/testcases/org/apache/poi/hssf/record
                        TestBoundSheetRecord.java
               src/testcases/org/apache/poi/hssf/usermodel
                        TestCloneSheet.java
  Log:
  fix for 13921, sync from branch
  
  Revision  Changes    Path
  1.10      +12 -0     jakarta-poi/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java
  
  Index: BoundSheetRecord.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- BoundSheetRecord.java	19 Aug 2003 14:07:40 -0000	1.9
  +++ BoundSheetRecord.java	27 Oct 2003 02:01:21 -0000	1.10
  @@ -194,10 +194,22 @@
       /**
        * Set the sheetname for this sheet.  (this appears in the tabs at the bottom)
        * @param sheetname the name of the sheet
  +     * @thows IllegalArgumentException if sheet name will cause excel to crash. 
        */
   
       public void setSheetname( String sheetname )
       {
  +        
  +        if ((sheetname == null) || (sheetname.length()==0)
  +                || (sheetname.length()>31)
  +                || (sheetname.indexOf("/") > -1)
  +                || (sheetname.indexOf("\\") > -1)
  +                || (sheetname.indexOf("?") > -1)
  +                || (sheetname.indexOf("*") > -1)
  +                || (sheetname.indexOf("]") > -1)
  +                || (sheetname.indexOf("[") > -1) ){
  +                    throw new IllegalArgumentException("Sheet name cannot be blank, greater
than 31 chars, or contain any of /\\*?[]");
  +        }
           field_5_sheetname = sheetname;
       }
   
  
  
  
  1.29      +8 -2      jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
  
  Index: HSSFWorkbook.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- HSSFWorkbook.java	26 Sep 2003 02:34:42 -0000	1.28
  +++ HSSFWorkbook.java	27 Oct 2003 02:01:21 -0000	1.29
  @@ -270,7 +270,9 @@
       
        
       /**
  -     * set the sheet name.
  +     * set the sheet name. 
  +     * Will throw IllegalArgumentException if the name is greater than 31 chars
  +     * or contains /\?*[]
        * @param sheet number (0 based)
        * @param sheet name
        */
  @@ -371,7 +373,11 @@
           windowTwo.setPaged(sheets.size() == 1);
   
           sheets.add(clonedSheet);
  -        workbook.setSheetName(sheets.size()-1, srcName+"[1]");
  +        if (srcName.length()<28) {
  +            workbook.setSheetName(sheets.size()-1, srcName+"(2)");
  +        }else {
  +            workbook.setSheetName(sheets.size()-1,srcName.substring(0,28)+"(2)");
  +        }
           return clonedSheet;
         }
         return null;
  
  
  
  1.3       +20 -0     jakarta-poi/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java
  
  Index: TestBoundSheetRecord.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/record/TestBoundSheetRecord.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestBoundSheetRecord.java	30 Apr 2003 04:39:04 -0000	1.2
  +++ TestBoundSheetRecord.java	27 Oct 2003 02:01:21 -0000	1.3
  @@ -92,5 +92,25 @@
   
           assertEquals(" 2  +  2  +  4  +   2   +    1     +    1    + len(str) * 2", 24,
record.getRecordSize());
       }
  +    
  +    public void testName() {
  +        BoundSheetRecord record = new BoundSheetRecord();
  +        record.setSheetname("1234567890223456789032345678904");
  +        assertTrue("Success", true);
  +        try {
  +            record.setSheetname("12345678902234567890323456789042");
  +            assertTrue("Should have thrown IllegalArgumentException, but didnt", false);
  +        } catch (IllegalArgumentException e) {
  +            assertTrue("succefully threw exception",true);
  +        }
  +        
  +        try {
  +            record.setSheetname("s//*s");
  +            assertTrue("Should have thrown IllegalArgumentException, but didnt", false);
  +        } catch (IllegalArgumentException e) {
  +            assertTrue("succefully threw exception",true);
  +        }
  +            
  +    }
   
   }
  
  
  
  1.3       +1 -1      jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java
  
  Index: TestCloneSheet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-poi/src/testcases/org/apache/poi/hssf/usermodel/TestCloneSheet.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TestCloneSheet.java	30 Apr 2003 04:38:58 -0000	1.2
  +++ TestCloneSheet.java	27 Oct 2003 02:01:21 -0000	1.3
  @@ -79,7 +79,7 @@
   			s.addMergedRegion(new Region((short)0,(short)0,(short)1,(short)1));
   			b.cloneSheet(0);
   		}
  -		catch(Exception e){fail(e.getMessage());}
  +		catch(Exception e){e.printStackTrace();fail(e.getMessage());}
   	}
   
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: poi-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: poi-dev-help@jakarta.apache.org


Mime
View raw message