Author: norman
Date: Sun Aug 23 13:09:40 2009
New Revision: 806964

URL: http://svn.apache.org/viewvc?rev=806964&view=rev
Log:
move validators to extra package

Added:
    labs/hupa/src/main/java/org/apache/hupa/client/validation/
    
labs/hupa/src/main/java/org/apache/hupa/client/validation/NotEmptyValidator.java
    
labs/hupa/src/main/java/org/apache/hupa/client/validation/RegexValidator.java
Modified:
    labs/hupa/src/main/java/org/apache/hupa/client/mvp/MessageSendPresenter.java

Modified: 
labs/hupa/src/main/java/org/apache/hupa/client/mvp/MessageSendPresenter.java
URL: 
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/client/mvp/MessageSendPresenter.java?rev=806964&r1=806963&r2=806964&view=diff
==============================================================================
--- 
labs/hupa/src/main/java/org/apache/hupa/client/mvp/MessageSendPresenter.java 
(original)
+++ 
labs/hupa/src/main/java/org/apache/hupa/client/mvp/MessageSendPresenter.java 
Sun Aug 23 13:09:40 2009
@@ -19,17 +19,6 @@
 
 package org.apache.hupa.client.mvp;
 
-import eu.maydu.gwt.validation.client.DefaultValidationProcessor;
-import eu.maydu.gwt.validation.client.ValidationAction;
-import eu.maydu.gwt.validation.client.ValidationProcessor;
-import eu.maydu.gwt.validation.client.ValidationResult;
-import eu.maydu.gwt.validation.client.Validator;
-import eu.maydu.gwt.validation.client.actions.FocusAction;
-import eu.maydu.gwt.validation.client.actions.StyleAction;
-import eu.maydu.gwt.validation.client.i18n.ValidationMessages;
-import gwtupload.client.IUploader;
-import gwtupload.client.Uploader;
-
 import java.util.ArrayList;
 
 import net.customware.gwt.dispatch.client.DispatchAsync;
@@ -40,6 +29,8 @@
 import net.customware.gwt.presenter.client.widget.WidgetPresenter;
 
 import org.apache.hupa.client.MyAsyncCallback;
+import org.apache.hupa.client.validation.NotEmptyValidator;
+import org.apache.hupa.client.validation.RegexValidator;
 import org.apache.hupa.client.widgets.HasEnable;
 import org.apache.hupa.shared.data.IMAPFolder;
 import org.apache.hupa.shared.data.IMAPMessage;
@@ -67,6 +58,14 @@
 import com.google.gwt.user.client.ui.HasText;
 import com.google.inject.Inject;
 
+import eu.maydu.gwt.validation.client.DefaultValidationProcessor;
+import eu.maydu.gwt.validation.client.ValidationProcessor;
+import eu.maydu.gwt.validation.client.actions.FocusAction;
+import eu.maydu.gwt.validation.client.actions.StyleAction;
+import eu.maydu.gwt.validation.client.i18n.ValidationMessages;
+import gwtupload.client.IUploader;
+import gwtupload.client.Uploader;
+
 public class MessageSendPresenter extends 
WidgetPresenter<MessageSendPresenter.Display>{
 
        private User user;
@@ -209,17 +208,17 @@
                
                        
                }));
-               
+               String emailRegex = 
"^[a-za-z0-9._%+...@[a-za-z0-9.-]+\\.[a-za-z]{2,}$";
                FocusAction fAction = new FocusAction();
-               validator.addValidators("cc", new 
EmailListValidator(display.getCcText())
+               validator.addValidators("cc", new 
RegexValidator(display.getCcText(), emailRegex)
                                .addActionForFailure(
                                                new 
StyleAction("hupa-validationErrorBorder"))
                                .addActionForFailure(fAction));
-               validator.addValidators("bcc", new 
EmailListValidator(display.getBccText())
+               validator.addValidators("bcc", new 
RegexValidator(display.getBccText(), emailRegex)
                                .addActionForFailure(
                                                new 
StyleAction("hupa-validationErrorBorder"))
                                .addActionForFailure(fAction));
-               validator.addValidators("to", new 
EmailListValidator(display.getToText())
+               validator.addValidators("to", new 
RegexValidator(display.getToText(), emailRegex)
                                .addActionForFailure(
                                                new 
StyleAction("hupa-validationErrorBorder"))
                                .addActionForFailure(fAction), new 
NotEmptyValidator(display.getToText())
@@ -353,71 +352,4 @@
                bind(user,null,null,type);
        }
        
-       private class NotEmptyValidator extends Validator<NotEmptyValidator> {
-               private HasText text;
-
-               public NotEmptyValidator(HasText text) {
-                       this.text = text;
-               }
-               @Override
-               public void invokeActions(ValidationResult result) {
-                       for (ValidationAction<HasText> action : 
getFailureActions())
-                               action.invoke(result, text);
-               }
-
-               @Override
-               public <V extends ValidationMessages> ValidationResult validate(
-                               V messages) {
-                       if (text.getText().trim().length() < 1) {
-                               return new ValidationResult();
-                       }
-                       return null;
-               }
-               
-       }
-       private class EmailListValidator extends Validator<EmailListValidator> {
-               private HasText text;
-
-               public EmailListValidator(HasText text) {
-                       this.text = text;
-               }
-
-               @Override
-               public void invokeActions(ValidationResult result) {
-                       for (ValidationAction<HasText> action : 
getFailureActions())
-                               action.invoke(result, text);
-               }
-
-               @Override
-               public <V extends ValidationMessages> ValidationResult validate(
-                               V messages) {
-                       if (isValidAddressList(text.getText()) == false) {
-                               return new ValidationResult();
-                       }
-                       return null;
-               }
-
-               private boolean isValidAddressList(String text) {
-                       if (text.length() > 0) {
-                               String[] addresses = text.split(",");
-                               if (addresses == null || addresses.length == 0) 
{
-                                       return isValidAddress(text);
-                               } else {
-                                       for (int i = 0; i < addresses.length; 
i++) {
-                                               if 
(isValidAddress(addresses[i]) == false) {
-                                                       return false;
-                                               }
-                                       }
-                               }
-                       }
-                       return true;
-               }
-
-               private boolean isValidAddress(String email) {
-                       return email
-                                       
.matches("^[a-za-z0-9._%+...@[a-za-z0-9.-]+\\.[a-za-z]{2,}$");
-               }
-
-       }
-       
 }

Added: 
labs/hupa/src/main/java/org/apache/hupa/client/validation/NotEmptyValidator.java
URL: 
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/client/validation/NotEmptyValidator.java?rev=806964&view=auto
==============================================================================
--- 
labs/hupa/src/main/java/org/apache/hupa/client/validation/NotEmptyValidator.java
 (added)
+++ 
labs/hupa/src/main/java/org/apache/hupa/client/validation/NotEmptyValidator.java
 Sun Aug 23 13:09:40 2009
@@ -0,0 +1,51 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.hupa.client.validation;
+
+
+import com.google.gwt.user.client.ui.HasText;
+
+import eu.maydu.gwt.validation.client.ValidationAction;
+import eu.maydu.gwt.validation.client.ValidationResult;
+import eu.maydu.gwt.validation.client.Validator;
+import eu.maydu.gwt.validation.client.i18n.ValidationMessages;
+
+public class NotEmptyValidator extends Validator<NotEmptyValidator> {
+       private HasText text;
+
+       public NotEmptyValidator(HasText text) {
+               this.text = text;
+       }
+       @Override
+       public void invokeActions(ValidationResult result) {
+               for (ValidationAction<HasText> action : getFailureActions())
+                       action.invoke(result, text);
+       }
+
+       @Override
+       public <V extends ValidationMessages> ValidationResult validate(
+                       V messages) {
+               if (text.getText().trim().length() < 1) {
+                       return new ValidationResult();
+               }
+               return null;
+       }
+       
+}

Added: 
labs/hupa/src/main/java/org/apache/hupa/client/validation/RegexValidator.java
URL: 
http://svn.apache.org/viewvc/labs/hupa/src/main/java/org/apache/hupa/client/validation/RegexValidator.java?rev=806964&view=auto
==============================================================================
--- 
labs/hupa/src/main/java/org/apache/hupa/client/validation/RegexValidator.java 
(added)
+++ 
labs/hupa/src/main/java/org/apache/hupa/client/validation/RegexValidator.java 
Sun Aug 23 13:09:40 2009
@@ -0,0 +1,70 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.hupa.client.validation;
+
+import com.google.gwt.user.client.ui.HasText;
+
+import eu.maydu.gwt.validation.client.ValidationAction;
+import eu.maydu.gwt.validation.client.ValidationResult;
+import eu.maydu.gwt.validation.client.Validator;
+import eu.maydu.gwt.validation.client.i18n.ValidationMessages;
+
+public class RegexValidator extends Validator<RegexValidator>{
+       private HasText text;
+       private String regex;
+       public RegexValidator(HasText text, String regex) {
+               this.text = text;
+       }
+
+       @Override
+       public void invokeActions(ValidationResult result) {
+               for (ValidationAction<HasText> action : getFailureActions())
+                       action.invoke(result, text);
+       }
+
+       @Override
+       public <V extends ValidationMessages> ValidationResult validate(
+                       V messages) {
+               if (isValidAddressList(text.getText()) == false) {
+                       return new ValidationResult();
+               }
+               return null;
+       }
+
+       private boolean isValidAddressList(String text) {
+               if (text.length() > 0) {
+                       String[] addresses = text.split(",");
+                       if (addresses == null || addresses.length == 0) {
+                               return isValidAddress(text);
+                       } else {
+                               for (int i = 0; i < addresses.length; i++) {
+                                       if (isValidAddress(addresses[i]) == 
false) {
+                                               return false;
+                                       }
+                               }
+                       }
+               }
+               return true;
+       }
+
+       private boolean isValidAddress(String email) {
+               return email.matches(regex);
+       }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to