incubator-aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From z..@apache.org
Subject svn commit: r922950 - in /incubator/aries/trunk/samples/blog/blog-web/src/main/java/org/apache/aries/samples/blog/web: EditAuthor.java EditAuthorForm.java util/FormatChecker.java
Date Sun, 14 Mar 2010 20:28:05 GMT
Author: zoe
Date: Sun Mar 14 20:28:05 2010
New Revision: 922950

URL: http://svn.apache.org/viewvc?rev=922950&view=rev
Log:
ARIES-236 added a format checker

Added:
    incubator/aries/trunk/samples/blog/blog-web/src/main/java/org/apache/aries/samples/blog/web/util/FormatChecker.java
Modified:
    incubator/aries/trunk/samples/blog/blog-web/src/main/java/org/apache/aries/samples/blog/web/EditAuthor.java
    incubator/aries/trunk/samples/blog/blog-web/src/main/java/org/apache/aries/samples/blog/web/EditAuthorForm.java

Modified: incubator/aries/trunk/samples/blog/blog-web/src/main/java/org/apache/aries/samples/blog/web/EditAuthor.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog/blog-web/src/main/java/org/apache/aries/samples/blog/web/EditAuthor.java?rev=922950&r1=922949&r2=922950&view=diff
==============================================================================
--- incubator/aries/trunk/samples/blog/blog-web/src/main/java/org/apache/aries/samples/blog/web/EditAuthor.java
(original)
+++ incubator/aries/trunk/samples/blog/blog-web/src/main/java/org/apache/aries/samples/blog/web/EditAuthor.java
Sun Mar 14 20:28:05 2010
@@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletRes
 
 import org.apache.aries.samples.blog.api.BloggingService;
 import org.apache.aries.samples.blog.web.util.FormServlet;
+import org.apache.aries.samples.blog.web.util.FormatChecker;
 import org.apache.aries.samples.blog.web.util.JNDIHelper;
 
 public class EditAuthor extends HttpServlet
@@ -67,7 +68,13 @@ public class EditAuthor extends HttpServ
       FormServlet.addError(req, "The email field is required.");
       resp.sendRedirect("EditAuthorForm");
       
-    }else if (checkEmail(email) == null) {
+    }else if (!FormatChecker.isValidEmail(email)) {
+    	storeParam(req, "email", email);
+        storeParam(req, "nickName", nickName);
+        storeParam(req, "name", name);
+        storeParam(req, "bio", bio);
+        storeParam(req, "dob", dob);
+        
     	FormServlet.addError(req, "The email field is not properly formatted");
         resp.sendRedirect("EditAuthorForm");	
     } else {
@@ -89,10 +96,4 @@ public class EditAuthor extends HttpServ
   {
     FormServlet.storeParam(req, EditAuthorForm.ID, param, value);
   }
-    
-    private String checkEmail(String parameter)
-    {
-      if (parameter != null && parameter.matches("^(?:[a-zA-Z0-9_'^&/+-])+(?:\\.(?:[a-zA-Z0-9_'^&/+-])+)*@(?:(?:\\[?(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\\.){3}(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\]?)|(?:[a-zA-Z0-9-]+\\.)+(?:[a-zA-Z]){2,}\\.?)$"))
return parameter;
-      return null;
-    }
 }
\ No newline at end of file

Modified: incubator/aries/trunk/samples/blog/blog-web/src/main/java/org/apache/aries/samples/blog/web/EditAuthorForm.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog/blog-web/src/main/java/org/apache/aries/samples/blog/web/EditAuthorForm.java?rev=922950&r1=922949&r2=922950&view=diff
==============================================================================
--- incubator/aries/trunk/samples/blog/blog-web/src/main/java/org/apache/aries/samples/blog/web/EditAuthorForm.java
(original)
+++ incubator/aries/trunk/samples/blog/blog-web/src/main/java/org/apache/aries/samples/blog/web/EditAuthorForm.java
Sun Mar 14 20:28:05 2010
@@ -26,6 +26,7 @@ import javax.servlet.http.HttpServletReq
 import org.apache.aries.samples.blog.api.BlogAuthor;
 import org.apache.aries.samples.blog.api.BloggingService;
 import org.apache.aries.samples.blog.web.util.FormServlet;
+import org.apache.aries.samples.blog.web.util.FormatChecker;
 import org.apache.aries.samples.blog.web.util.HTMLOutput;
 import org.apache.aries.samples.blog.web.util.JNDIHelper;
 
@@ -67,10 +68,14 @@ public class EditAuthorForm extends Form
   private String getEmail(HttpServletRequest req)
   {
     String email = retrieveOrEmpty(req, "email");
+    
     if ("".equals(email)) {
       email = req.getParameter("email");
     }
-    return checkEmail(email);
+    if(FormatChecker.isValidEmail(email))
+    	return email;
+    else 
+    	return null;
   }
   
   @Override

Added: incubator/aries/trunk/samples/blog/blog-web/src/main/java/org/apache/aries/samples/blog/web/util/FormatChecker.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/samples/blog/blog-web/src/main/java/org/apache/aries/samples/blog/web/util/FormatChecker.java?rev=922950&view=auto
==============================================================================
--- incubator/aries/trunk/samples/blog/blog-web/src/main/java/org/apache/aries/samples/blog/web/util/FormatChecker.java
(added)
+++ incubator/aries/trunk/samples/blog/blog-web/src/main/java/org/apache/aries/samples/blog/web/util/FormatChecker.java
Sun Mar 14 20:28:05 2010
@@ -0,0 +1,27 @@
+/**
+ * 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.aries.samples.blog.web.util;
+
+
+public class FormatChecker {
+	public static boolean isValidEmail(String email) {
+		if (email != null && email.matches("^(?:[a-zA-Z0-9_'^&/+-])+(?:\\.(?:[a-zA-Z0-9_'^&/+-])+)*@(?:(?:\\[?(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))\\.){3}(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\]?)|(?:[a-zA-Z0-9-]+\\.)+(?:[a-zA-Z]){2,}\\.?)$"))
return true;
+		return false;
+	}
+}



Mime
View raw message