poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ye...@apache.org
Subject svn commit: r992629 - in /poi/trunk/src: documentation/content/xdocs/ java/org/apache/poi/hssf/record/ java/org/apache/poi/ss/util/ ooxml/java/org/apache/poi/xssf/usermodel/ testcases/org/apache/poi/ss/usermodel/
Date Sat, 04 Sep 2010 15:56:29 GMT
Author: yegor
Date: Sat Sep  4 15:56:29 2010
New Revision: 992629

URL: http://svn.apache.org/viewvc?rev=992629&view=rev
Log:
fixed  XSSFWorkbook.createSheet to throw exception if sheet name begins or ends with a single
quote ('), see Bugzilla 49875

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java
    poi/trunk/src/java/org/apache/poi/ss/util/WorkbookUtil.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=992629&r1=992628&r2=992629&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Sat Sep  4 15:56:29 2010
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.7-beta3" date="2010-??-??">
+           <action dev="poi-developers" type="fix">49875 - fixed  XSSFWorkbook.createSheet
to throw exception if sheet name begins or ends with a single quote (')</action>
            <action dev="poi-developers" type="fix">49873 - fixed  XSSFFormulaEvaluator
to support blank cells</action>
            <action dev="poi-developers" type="fix">49850 - added a getter for _iStartAt
in ListFormatOverrideLevel</action>
            <action dev="poi-developers" type="fix">49761 - change cell type to error
when setting Double.NaN or Infinities</action>

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java?rev=992629&r1=992628&r2=992629&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/BoundSheetRecord.java Sat Sep  4 15:56:29
2010
@@ -26,6 +26,7 @@ import org.apache.poi.util.BitFieldFacto
 import org.apache.poi.util.HexDump;
 import org.apache.poi.util.LittleEndianOutput;
 import org.apache.poi.util.StringUtil;
+import org.apache.poi.ss.util.WorkbookUtil;
 
 /**
  * Title:        Bound Sheet Record (aka BundleSheet) (0x0085)<P>
@@ -90,42 +91,11 @@ public final class BoundSheetRecord exte
 	 */
 	public void setSheetname(String sheetName) {
 
-		validateSheetName(sheetName);
+		WorkbookUtil.validateSheetName(sheetName);
 		field_5_sheetname = sheetName;
 		field_4_isMultibyteUnicode = StringUtil.hasMultibyte(sheetName) ?  1 : 0;
 	}
 
-	private static void validateSheetName(String sheetName) {
-		if (sheetName == null) {
-			throw new IllegalArgumentException("sheetName must not be null");
-		}
-		int len = sheetName.length();
-		if (len < 1) {
-			throw new IllegalArgumentException("sheetName must not be empty string");
-		}
-		for (int i=0; i<len; i++) {
-			char ch = sheetName.charAt(i);
-			switch (ch) {
-				case '/':
-				case '\\':
-				case '?':
-				case '*':
-				case ']':
-				case '[':
-					break;
-				default:
-					// all other chars OK
-					continue;
-			}
-			throw new IllegalArgumentException("Invalid char (" + ch
-					+ ") found at index (" + i + ") in sheet name '" + sheetName + "'");
-		}
-		if (sheetName.charAt(0) == '\'' || sheetName.charAt(len-1) == '\'') {
-			throw new IllegalArgumentException("Invalid sheet name '" + sheetName
-					+ "'. Sheet names must not begin or end with (').");
-		}
-	}
-
 	/**
 	 * get the offset in bytes of the Beginning of File Marker within the HSSF Stream part of
the POIFS file
 	 *

Modified: poi/trunk/src/java/org/apache/poi/ss/util/WorkbookUtil.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/util/WorkbookUtil.java?rev=992629&r1=992628&r2=992629&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/util/WorkbookUtil.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/util/WorkbookUtil.java Sat Sep  4 15:56:29 2010
@@ -74,4 +74,59 @@ public class WorkbookUtil {
 		}
 		return result.toString();
 	}
+
+    /**
+     * Validates sheet name.
+     *
+     * <p>
+     * The character count <tt>MUST</tt> be greater than or equal to 1 and less
than or equal to 31.
+     * The string MUST NOT contain the any of the following characters:
+     * <ul>
+     * <li> 0x0000 </li>
+     * <li> 0x0003 </li>
+     * <li> colon (:) </li>
+     * <li> backslash (\) </li>
+     * <li> asterisk (*) </li>
+     * <li> question mark (?) </li>
+     * <li> forward slash (/) </li>
+     * <li> opening square bracket ([) </li>
+     * <li> closing square bracket (]) </li>
+     * </ul>
+     * The string MUST NOT begin or end with the single quote (') character.
+     * </p>
+     *
+     * @param sheetName the name to validate
+     */
+    public static void validateSheetName(String sheetName) {
+        if (sheetName == null) {
+            throw new IllegalArgumentException("sheetName must not be null");
+        }
+        int len = sheetName.length();
+        if (len < 1) {
+            throw new IllegalArgumentException("sheetName must not be empty string");
+        }
+        for (int i=0; i<len; i++) {
+            char ch = sheetName.charAt(i);
+            switch (ch) {
+                case '/':
+                case '\\':
+                case '?':
+                case '*':
+                case ']':
+                case '[':
+                case ':':
+                    break;
+                default:
+                    // all other chars OK
+                    continue;
+            }
+            throw new IllegalArgumentException("Invalid char (" + ch
+                    + ") found at index (" + i + ") in sheet name '" + sheetName + "'");
+        }
+        if (sheetName.charAt(0) == '\'' || sheetName.charAt(len-1) == '\'') {
+            throw new IllegalArgumentException("Invalid sheet name '" + sheetName
+                    + "'. Sheet names must not begin or end with (').");
+        }
+    }
+
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=992629&r1=992628&r2=992629&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Sat Sep  4 15:56:29
2010
@@ -51,6 +51,7 @@ import org.apache.poi.ss.usermodel.Sheet
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
 import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.ss.util.WorkbookUtil;
 import org.apache.poi.util.*;
 import org.apache.poi.xssf.model.CalculationChain;
 import org.apache.poi.xssf.model.MapInfo;
@@ -511,7 +512,7 @@ public class XSSFWorkbook extends POIXML
     }
 
     private CTSheet addSheet(String sheetname) {
-        validateSheetName(sheetname);
+        WorkbookUtil.validateSheetName(sheetname);
 
         CTSheet sheet = workbook.getSheets().addNewSheet();
         sheet.setName(sheetname);
@@ -1099,11 +1100,10 @@ public class XSSFWorkbook extends POIXML
      * or contains /\?*[]
      *
      * @param sheet number (0 based)
-     * @see #validateSheetName(String)
      */
     public void setSheetName(int sheet, String name) {
         validateSheetIndex(sheet);
-        validateSheetName(name);
+        WorkbookUtil.validateSheetName(name);
         if (containsSheet(name, sheet ))
             throw new IllegalArgumentException( "The workbook already contains a sheet of
this name" );
         workbook.getSheets().getSheetArray(sheet).setName(name);
@@ -1233,56 +1233,6 @@ public class XSSFWorkbook extends POIXML
     }
 
     /**
-     * Validates sheet name.
-     *
-     * <p>
-     * The character count <tt>MUST</tt> be greater than or equal to 1 and less
than or equal to 31.
-     * The string MUST NOT contain the any of the following characters:
-     * <ul>
-     * <li> 0x0000 </li>
-     * <li> 0x0003 </li>
-     * <li> colon (:) </li>
-     * <li> backslash (\) </li>
-     * <li> asterisk (*) </li>
-     * <li> question mark (?) </li>
-     * <li> forward slash (/) </li>
-     * <li> opening square bracket ([) </li>
-     * <li> closing square bracket (]) </li>
-     * </ul>
-     * The string MUST NOT begin or end with the single quote (') character.
-     * </p>
-     *
-     * @param sheetName the name to validate
-     */
-    private static void validateSheetName(String sheetName) {
-        if (sheetName == null) {
-            throw new IllegalArgumentException("sheetName must not be null");
-        }
-        int len = sheetName.length();
-        if (len < 1 || len > 31) {
-            throw new IllegalArgumentException("sheetName '" + sheetName
-                    + "' is invalid - must be 1-30 characters long");
-        }
-        for (int i=0; i<len; i++) {
-            char ch = sheetName.charAt(i);
-            switch (ch) {
-                case '/':
-                case '\\':
-                case '?':
-                case '*':
-                case ']':
-                case '[':
-                    break;
-                default:
-                    // all other chars OK
-                    continue;
-            }
-            throw new IllegalArgumentException("Invalid char (" + ch
-                    + ") found at index (" + i + ") in sheet name '" + sheetName + "'");
-        }
-     }
-
-    /**
      * Gets a boolean value that indicates whether the date systems used in the workbook
starts in 1904.
      * <p>
      * The default value is false, meaning that the workbook uses the 1900 date system,

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java?rev=992629&r1=992628&r2=992629&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java Sat Sep  4 15:56:29
2010
@@ -72,7 +72,8 @@ public abstract class BaseTestWorkbook e
 
         //names cannot be blank or contain any of /\*?[]
         String[] invalidNames = {"", "Sheet/", "Sheet\\",
-                "Sheet?", "Sheet*", "Sheet[", "Sheet]"};
+                "Sheet?", "Sheet*", "Sheet[", "Sheet]", "'Sheet'",
+                "My:Sheet"};
         for (String sheetName : invalidNames) {
             try {
                 wb.createSheet(sheetName);



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


Mime
View raw message