[jboss-svn-commits] JBL Code SVN: r9480 - labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Feb 13 18:15:39 EST 2007


Author: unibrew
Date: 2007-02-13 18:15:38 -0500 (Tue, 13 Feb 2007)
New Revision: 9480

Added:
   labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/MessageValidationException.java
   labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/PollValidationException.java
Modified:
   labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/EditPost.java
   labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/NewTopic.java
   labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/PostAction.java
   labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/ReplyTopic.java
Log:
[JBFORUMS-161] Rewriting validation of polls and messages to kill one of GPL dependencies.

Modified: labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/EditPost.java
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/EditPost.java	2007-02-13 23:15:23 UTC (rev 9479)
+++ labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/EditPost.java	2007-02-13 23:15:38 UTC (rev 9480)
@@ -33,8 +33,6 @@
 import org.jboss.portlet.forums.ui.ForumUtil;
 import org.jboss.portlet.forums.ui.JSFUtil;
 import org.jboss.portlet.forums.ui.PortalUtil;
-import org.jboss.portlet.forums.commands.ValidationException;
-import org.jboss.portlet.forums.commands.post.PostTools;
 import org.jboss.portlet.forums.model.Poll;
 import org.jboss.portlet.forums.model.PollOption;
 import org.jboss.portlet.forums.model.Message;
@@ -213,7 +211,7 @@
                     poll.setTitle(this.question);
                     poll.setLength(this.activeDuration);
                     poll.setOptions(localPollOptions);
-                    PostTools.validate(poll);
+                    validatePoll(poll);
                     BaseController.getForumsModule().addPollToTopic(topic,poll);
                 }
             }
@@ -333,19 +331,16 @@
 	        
 	        success = true;
         }
+        catch (PollValidationException e)
+        {
+//          handle proper validation error with a proper message...not just a generic message..
+            //just use generic error page for the proof of concept
+            //set the custom exception such that e.toString() results in the proper message
+            JSFUtil.handleException(e);
+        }
         catch(Exception e)
         {
-            if(e instanceof ValidationException)
-            {
-                //handle proper validation error with a proper message...not just a generic message..
-                //just use generic error page for the proof of concept
-                //set the custom exception such that e.toString() results in the proper message
-                JSFUtil.handleException(e);
-            }
-            else
-            {
-                JSFUtil.handleException(e);
-            }
+            JSFUtil.handleException(e);
         }
         finally
         {

Copied: labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/MessageValidationException.java (from rev 9478, labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/action/MessageValidationException.java)
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/MessageValidationException.java	                        (rev 0)
+++ labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/MessageValidationException.java	2007-02-13 23:15:38 UTC (rev 9480)
@@ -0,0 +1,58 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.jboss.portlet.forums.ui.action;
+
+/**
+ * 
+ * @author <a href="mailto:ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
+ *
+ */
+public class MessageValidationException extends Exception
+{
+    
+    public static final int INVALID = 0;
+    public static final int INVALID_POST_SUBJECT = 1;
+    public static final int INVALID_POST_TEXT = 2;
+    
+    private int type;
+    
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 1L;
+
+    public MessageValidationException (int type) {
+        super();
+        this.type = type;
+        if ( type != INVALID_POST_SUBJECT  &&
+             type != INVALID_POST_TEXT)
+        {
+            this.type = INVALID;
+        }
+    }
+    
+    public int getType() {
+        return type;
+    }
+    
+}
\ No newline at end of file

Modified: labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/NewTopic.java
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/NewTopic.java	2007-02-13 23:15:23 UTC (rev 9479)
+++ labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/NewTopic.java	2007-02-13 23:15:38 UTC (rev 9480)
@@ -37,8 +37,6 @@
 import org.jboss.portlet.forums.model.Poll;
 import org.jboss.portlet.forums.model.PollOption;
 import org.jboss.portlet.forums.model.Post;
-import org.jboss.portlet.forums.commands.ValidationException;
-import org.jboss.portlet.forums.commands.post.PostTools;
 
 //myfaces
 
@@ -117,7 +115,7 @@
            
            //perform domain level validation of information here....ui level validation should have already passed
            //whether done using javascript or JSF validators
-           PostTools.validate(message);
+           validateMessage(message);
            
            //setup the forum and the corresponding poster
            Forum forum = BaseController.getForumsModule().findForumById(new Integer(this.forumId));
@@ -139,7 +137,7 @@
                    pollOptions.add(pollOption);
                }
                poll.setOptions(pollOptions);
-               PostTools.validate(poll);
+               validatePoll(poll);
            }
                                  
            //actually create the topic in this forum
@@ -161,19 +159,23 @@
            
            success = true;
        }
+       catch (MessageValidationException e) 
+       {
+           //handle proper validation error with a proper message...not just a generic message..
+           //just use generic error page for the proof of concept
+           //set the custom exception such that e.toString() results in the proper message
+           JSFUtil.handleException(e);
+       }
+       catch (PollValidationException e) 
+       {
+           //handle proper validation error with a proper message...not just a generic message..
+           //just use generic error page for the proof of concept
+           //set the custom exception such that e.toString() results in the proper message
+           JSFUtil.handleException(e);
+       }
        catch(Exception e)
        {
-           if(e instanceof ValidationException)
-           {
-               //handle proper validation error with a proper message...not just a generic message..
-               //just use generic error page for the proof of concept
-               //set the custom exception such that e.toString() results in the proper message
-               JSFUtil.handleException(e);
-           }
-           else
-           {
-               JSFUtil.handleException(e);
-           }
+           JSFUtil.handleException(e);
        }
        finally
        {

Copied: labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/PollValidationException.java (from rev 9478, labs/jbossforums/branches/forums26/forums/src/main/org/jboss/portlet/forums/ui/action/PollValidationException.java)
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/PollValidationException.java	                        (rev 0)
+++ labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/PollValidationException.java	2007-02-13 23:15:38 UTC (rev 9480)
@@ -0,0 +1,62 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+
+package org.jboss.portlet.forums.ui.action;
+
+/**
+ * 
+ * @author <a href="mailto:ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
+ *
+ */
+public class PollValidationException extends Exception
+{
+
+    public static final int INVALID = 0;
+    public static final int INVALID_POLL_OPTION = 1;
+    public static final int TOO_FEW_POLL_OPTION = 2;
+    public static final int TOO_MANY_POLL_OPTION = 3;
+    public static final int INVALID_POLL_TITLE = 4;
+    
+    private int type;
+    
+    /**
+     * 
+     */
+    private static final long serialVersionUID = 1L;
+
+    public PollValidationException (int type) {
+        super();
+        this.type = type;
+        if ( type != INVALID_POLL_OPTION  &&
+             type != INVALID_POLL_TITLE   &&
+             type != TOO_FEW_POLL_OPTION &&
+             type != TOO_MANY_POLL_OPTION  )
+        {
+            this.type = INVALID;
+        }
+    }
+    
+    public int getType() {
+        return type;
+    }
+    
+}

Modified: labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/PostAction.java
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/PostAction.java	2007-02-13 23:15:23 UTC (rev 9479)
+++ labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/PostAction.java	2007-02-13 23:15:38 UTC (rev 9480)
@@ -42,6 +42,7 @@
 import org.jboss.portlet.forums.model.Poll;
 import org.jboss.portlet.forums.model.PollOption;
 import org.jboss.portlet.forums.model.Post;
+import org.jboss.portlet.forums.model.Message;
 
 //myfaces
 import org.apache.myfaces.custom.fileupload.UploadedFile;
@@ -517,7 +518,50 @@
         return navState;
     }
     
-    //-----------------attachment related------------------------------------------------------------------------------------------    
+    public void validatePoll(Poll poll) throws PollValidationException
+    {
+        if (poll.getOptions().size() > 10)
+        {
+           throw new PollValidationException(PollValidationException.TOO_MANY_POLL_OPTION);
+        }
+        if (poll.getOptions().size() < 2)
+        {
+           throw new PollValidationException(PollValidationException.TOO_FEW_POLL_OPTION);
+        }
+        if (poll.getTitle()==null || poll.getTitle().trim().length()==0)
+        {
+           throw new PollValidationException(PollValidationException.INVALID_POLL_TITLE);
+        }    
+        for (Iterator i = poll.getOptions().iterator(); i.hasNext();)
+        {
+           PollOption option = (PollOption)i.next();
+           if (option.getQuestion()==null || option.getQuestion().trim().length()==0)
+           {
+              throw new PollValidationException(PollValidationException.INVALID_POLL_OPTION);
+           }
+        }
+    
+    }
+    
+    //-----------------message related------------------------------------------------------------------------------------------    
+    
+    public void validateMessage(Message message) throws MessageValidationException
+    {
+        String subject = message.getSubject();
+        if ( subject==null || subject.trim().length()==0 )
+        {
+           throw new MessageValidationException(MessageValidationException.INVALID_POST_SUBJECT);
+        }
+
+        String text = message.getText();
+        if ( text==null || text.trim().length()==0 )
+        {
+           throw new MessageValidationException(MessageValidationException.INVALID_POST_TEXT);
+        }
+    }
+    
+    //-----------------attachment related------------------------------------------------------------------------------------------
+    
     /**
      * 
      */

Modified: labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/ReplyTopic.java
===================================================================
--- labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/ReplyTopic.java	2007-02-13 23:15:23 UTC (rev 9479)
+++ labs/jbossforums/branches/forums22/forums/src/main/org/jboss/portlet/forums/ui/action/ReplyTopic.java	2007-02-13 23:15:38 UTC (rev 9480)
@@ -37,12 +37,7 @@
 import org.jboss.portlet.forums.model.Message;
 import org.jboss.portlet.forums.model.Post;
 
-import org.jboss.portlet.forums.commands.ValidationException;
-import org.jboss.portlet.forums.commands.post.PostTools;
 
-//myfaces
-
-
 /**
  * @author <a href="mailto:sohil.shah at jboss.com">Sohil Shah</a>
  * @author <a href="mailto:ryszard.kozmik at jboss.com">Ryszard Kozmik</a>
@@ -203,7 +198,7 @@
            
            //perform domain level validation of information here....ui level validation should have already passed
            //whether done using javascript or JSF validators
-           PostTools.validate(message);
+           validateMessage(message);
            
            //setup the forum and the corresponding poster
            Forum forum = BaseController.getForumsModule().findForumById(new Integer(this.forumId));
@@ -233,19 +228,23 @@
            
            success = true;
        }
+       catch (MessageValidationException e) 
+       {
+           //handle proper validation error with a proper message...not just a generic message..
+           //just use generic error page for the proof of concept
+           //set the custom exception such that e.toString() results in the proper message
+           JSFUtil.handleException(e);
+       }
+       catch(PollValidationException e)
+       {
+           //handle proper validation error with a proper message...not just a generic message..
+           //just use generic error page for the proof of concept
+           //set the custom exception such that e.toString() results in the proper message
+           JSFUtil.handleException(e);
+       }
        catch(Exception e)
        {
-           if(e instanceof ValidationException)
-           {
-               //handle proper validation error with a proper message...not just a generic message..
-               //just use generic error page for the proof of concept
-               //set the custom exception such that e.toString() results in the proper message
-               JSFUtil.handleException(e);
-           }
-           else
-           {
-               JSFUtil.handleException(e);
-           }
+           JSFUtil.handleException(e);
        }
        finally
        {




More information about the jboss-svn-commits mailing list