[jboss-svn-commits] JBL Code SVN: r20162 - in labs/jbossrules/trunk/drools-jbrms/src: test/java/org/drools/brms/server and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun May 25 21:45:49 EDT 2008


Author: jervisliu
Date: 2008-05-25 21:45:49 -0400 (Sun, 25 May 2008)
New Revision: 20162

Modified:
   labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/NewAssetWizard.java
   labs/jbossrules/trunk/drools-jbrms/src/test/java/org/drools/brms/server/ServiceImplementationTest.java
Log:
JBRULES-1290(BRMS does not allow rule names to contain an apostrophe character ( ' )): we pre-validate names inputted by users, make sure the name is consistent with JSR-170. 


Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/NewAssetWizard.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/NewAssetWizard.java	2008-05-26 01:21:35 UTC (rev 20161)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/NewAssetWizard.java	2008-05-26 01:45:49 UTC (rev 20162)
@@ -52,6 +52,8 @@
     private boolean showCats;
     private String format;
 
+
+
     /** This is used when creating a new rule. */
     public NewAssetWizard(EditItemEvent afterCreate, boolean showCats, String format, String title) {
         super("images/new_wiz.gif", title);
@@ -144,13 +146,17 @@
     void ok() {
 
         if (this.showCats && this.initialCategory == null) {
-            Window.alert( "You have to pick an initial category." );
-            return;
-        } else if (this.name.getText() == null || "".equals( this.name.getText() )) {
-            Window.alert( "Asset must have a name" );
-            return;
-        }
-
+			Window.alert("You have to pick an initial category.");
+			return;
+		} else {
+			try {
+				validatePathPerJSR170(this.name.getText());
+			} catch (IllegalArgumentException e) {
+				Window.alert(e.getMessage());
+				return;
+			}
+		} 
+        
         GenericCallback cb = new GenericCallback() {
             public void onSuccess(Object result) {
             		String uuid = (String) result;
@@ -188,5 +194,41 @@
         afterCreate.open( uuid );
     }
 
+    /**
+	 * Validate name per JSR-170. Only following characters are valid: char ::=
+	 * nonspace | ' ' nonspace ::= (* Any Unicode character except: '/', ':',
+	 * '[', ']', '*', ''', '"', '|' or any whitespace character *)
+	 * 
+	 * @param jsrPath
+	 */
+	public static void validatePathPerJSR170(String jsrPath)
+			throws IllegalArgumentException {
+		int len = jsrPath == null ? 0 : jsrPath.length();
 
+		if (len == 0) {
+			throw new IllegalArgumentException("empty name is not allowed");
+		}
+
+		int pos = 0;
+
+		while (pos < len) {
+			char c = jsrPath.charAt(pos);
+			pos++;
+
+			switch (c) {
+			case '/':
+			case ':':
+			case '[':
+			case ']':
+			case '*':
+			case '\'':
+			case '\"':
+				throw new IllegalArgumentException("'" + jsrPath
+						+ "' is not valid. '" + c
+						+ "' is not a valid name character");
+			default:
+			}
+		}
+	}
+
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-jbrms/src/test/java/org/drools/brms/server/ServiceImplementationTest.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/test/java/org/drools/brms/server/ServiceImplementationTest.java	2008-05-26 01:21:35 UTC (rev 20161)
+++ labs/jbossrules/trunk/drools-jbrms/src/test/java/org/drools/brms/server/ServiceImplementationTest.java	2008-05-26 01:45:49 UTC (rev 20162)
@@ -222,6 +222,27 @@
 		assertEquals(dtItem.getDescription(), "an initial desc");
 	}
 	
+	public void testCreateNewRuleContainsApostrophe() throws Exception {
+		ServiceImplementation impl = getService();
+		impl.repository.createPackage("testCreateNewRuleContainsApostrophe",
+				"desc");
+		impl.createCategory("", "testCreateNewRuleContainsApostrophe",
+				"this is a cat");
+
+		try {
+			impl.createNewRule("testCreateNewRuleContains' character",
+					"an initial desc", "testCreateNewRuleContainsApostrophe",
+					"testCreateNewRuleContainsApostrophe",
+					AssetFormats.DSL_TEMPLATE_RULE);
+			fail("did not get expected exception");
+		} catch (SerializableException e) {
+			assertTrue(e
+					.getMessage()
+					.indexOf(
+							"'testCreateNewRuleContains' character' is not a valid path. ''' not a valid name character") >= 0);
+		}
+	}
+	
 	public void testRuleTableLoad() throws Exception {
 		ServiceImplementation impl = getService();
 		TableConfig conf = impl




More information about the jboss-svn-commits mailing list