Rough protection against too long workspaces name (causes trouble with PostgreSQL)
authorMathieu Baudier <mbaudier@argeo.org>
Sun, 26 Jan 2014 12:21:12 +0000 (12:21 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sun, 26 Jan 2014 12:21:12 +0000 (12:21 +0000)
git-svn-id: https://svn.argeo.org/slc/trunk@6765 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/CreateWorkspace.java

index 09694af5e12ecbe72a4aa2e3aa0799c21b467383..dc279d30467f7699e0e84edc7bce63e545c52f75 100644 (file)
@@ -25,7 +25,7 @@ import javax.jcr.security.Privilege;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.ErrorFeedback;
 import org.argeo.jcr.JcrUtils;
 import org.argeo.slc.client.ui.dist.DistPlugin;
 import org.argeo.slc.client.ui.dist.utils.CommandHelpers;
@@ -77,10 +77,32 @@ public class CreateWorkspace extends AbstractHandler {
                                        .getActiveWorkbenchWindow(event).getShell(),
                                        "Workspace name?",
                                        "Choose a name for the workspace to create",
-                                       prefix == null ? "" : prefix + "-", null);
+                                       prefix == null ? "" : prefix + "_", null);
                        int result = inputDialog.open();
 
-                       String workspaceName = inputDialog.getValue();
+                       String enteredName = inputDialog.getValue();
+
+                       final String legalChars = "ABCDEFGHIJKLMNOPQRSTUVWXZY0123456789_";
+                       char[] arr = enteredName.toUpperCase().toCharArray();
+                       int count = 0;
+                       for (int i = 0; i < arr.length; i++) {
+                               if (legalChars.indexOf(arr[i]) == -1)
+                                       count = count + 7;
+                               else
+                                       count++;
+                       }
+
+                       if (log.isDebugEnabled())
+                               log.debug("Count " + count);
+
+                       if (count > 60) {
+                               ErrorFeedback.show("Workspace name '" + enteredName
+                                               + "' is too long or contains"
+                                               + " too many special characters such as '.' or '-'.");
+                               return null;
+                       }
+
+                       String workspaceName = enteredName;
 
                        // Canceled by user
                        if (result == Dialog.CANCEL || workspaceName == null
@@ -98,7 +120,7 @@ public class CreateWorkspace extends AbstractHandler {
                                log.trace("WORKSPACE " + workspaceName + " CREATED");
 
                } catch (RepositoryException re) {
-                       throw new ArgeoException(
+                       ErrorFeedback.show(
                                        "Unexpected error while creating the new workspace.", re);
                } finally {
                        JcrUtils.logoutQuietly(session);