[jboss-svn-commits] JBL Code SVN: r5125 - in labs/jbossforums/trunk/forums/src: main/org/jboss/portlet/forums/ui/action resources/portal-forums-war/views/moderator

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jul 17 18:20:38 EDT 2006


Author: unibrew
Date: 2006-07-17 18:20:34 -0400 (Mon, 17 Jul 2006)
New Revision: 5125

Modified:
   labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/SplitTopic.java
   labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_split.xhtml
Log:
[JBFORUMS-54] Security checks improvement, clearing the code, optimizing.

Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/SplitTopic.java
===================================================================
--- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/SplitTopic.java	2006-07-17 21:44:54 UTC (rev 5124)
+++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/SplitTopic.java	2006-07-17 22:20:34 UTC (rev 5125)
@@ -107,33 +107,25 @@
         
         // Checking whether topic has only one post, so it can't be splitted
         if (topic.getPosts().size()==1) {
-            message = bundle.getString("ERR_SPLIT_ONE_POST_TOPIC");
-            FacesContext.getCurrentInstance().addMessage("message",
-            new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate"));
+            setWarnBundleMessage("ERR_SPLIT_ONE_POST_TOPIC");
             return "";
         }
         
         // Checking if user selected anything.
         if (checkboxes.size()==0) {
-            message = bundle.getString("ERR_NO_POST_SELECTED");
-            FacesContext.getCurrentInstance().addMessage("message",
-            new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate"));
+            setWarnBundleMessage("ERR_NO_POST_SELECTED");
             return "";
         }
         
         // User can't select more than one post for this action.
         if (checkboxes.size()!=1) {
-            message = bundle.getString("Too_many_error");
-            FacesContext.getCurrentInstance().addMessage("message",
-            new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate"));
+            setWarnBundleMessage("Too_many_error");
             return "";
         }
         
         //check if user selected first post
         if (topic.getFirstPost().getId().equals((Integer)(checkboxes.keySet().iterator().next()))) {
-            message = bundle.getString("ERR_SPLIT_ALL");
-            FacesContext.getCurrentInstance().addMessage("message",
-            new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate"));            
+            setWarnBundleMessage("ERR_SPLIT_ALL");            
             return "";
         }
         
@@ -142,9 +134,7 @@
         if (toForumId == null || 
             toForumId.trim().compareToIgnoreCase("-1")==0 || 
             toForumId.trim().length()==0) {
-            message = bundle.getString("ERR_DEST_FORUM");
-            FacesContext.getCurrentInstance().addMessage("message",
-            new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate"));     
+            setWarnBundleMessage("ERR_DEST_FORUM");
             return "";
         }
         
@@ -152,9 +142,7 @@
         if (newTopicTitle == null || 
             newTopicTitle.trim().compareToIgnoreCase("-1")==0 || 
             newTopicTitle.trim().length()==0) {
-            message = bundle.getString("ERR_NO_SUBJECT_GIVEN");
-            FacesContext.getCurrentInstance().addMessage("message",
-            new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate"));     
+            setWarnBundleMessage("ERR_NO_SUBJECT_GIVEN");
             return "";
         }
         
@@ -174,12 +162,10 @@
             Post tempPost = null;
             while( it.hasNext() )
             {
-                System.out.println("JESTEM W WHILEu");
                 tempPost = (Post)it.next();
                 // searching for post to split after
                 if (tempPost.getId().equals(selectedPostId))
                 {
-                    System.out.println("JESTEM W IFIE");
                    break;
                 }
             }
@@ -196,16 +182,12 @@
             newTopic.setLastPostDate(newTopic.getLastPost().getCreateDate());
         } catch (Exception e) {
             e.printStackTrace();
-            message = bundle.getString("ERR_INTERNAL");
-            FacesContext.getCurrentInstance().addMessage("message",
-            new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate"));
+            setWarnBundleMessage("ERR_INTERNAL");
             return "";
         }
         
         // Setting message that everything went smooth.
-        message = bundle.getString("SUCC_TOPIC_SPLITTED");
-        FacesContext.getCurrentInstance().addMessage("message",
-        new FacesMessage(FacesMessage.SEVERITY_INFO,message, "moderate"));     
+        setInfoBundleMessage("SUCC_TOPIC_SPLITTED");
         return "splitted";
     }
     
@@ -231,25 +213,19 @@
         
         // Checking whether topic has only one post, so it can't be splitted
         if (topic.getPosts().size()==1) {
-            message = bundle.getString("ERR_SPLIT_ONE_POST_TOPIC");
-            FacesContext.getCurrentInstance().addMessage("message",
-            new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate"));
+            setWarnBundleMessage("ERR_SPLIT_ONE_POST_TOPIC");
             return "";
         }
         
         // Checking if user selected anything.
         if (checkboxes.size()==0) {
-            message = bundle.getString("ERR_NO_POST_SELECTED");
-            FacesContext.getCurrentInstance().addMessage("message",
-            new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate"));
+            setWarnBundleMessage("ERR_NO_POST_SELECTED");
             return "";
         }
         
         // Checking if user didn't select all posts.
         if (checkboxes.size()==topic.getPosts().size()) {
-            message = bundle.getString("ERR_SPLIT_ALL");
-            FacesContext.getCurrentInstance().addMessage("message",
-            new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate"));            
+            setWarnBundleMessage("ERR_SPLIT_ALL");         
             return "";
         }
  
@@ -258,9 +234,7 @@
         if (toForumId == null || 
             toForumId.trim().compareToIgnoreCase("-1")==0 || 
             toForumId.trim().length()==0) {
-            message = bundle.getString("ERR_DEST_FORUM");
-            FacesContext.getCurrentInstance().addMessage("message",
-            new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate"));     
+            setWarnBundleMessage("ERR_DEST_FORUM");     
             return "";
         }
         
@@ -268,9 +242,7 @@
         if (newTopicTitle == null || 
             newTopicTitle.trim().compareToIgnoreCase("-1")==0 || 
             newTopicTitle.trim().length()==0) {
-            message = bundle.getString("ERR_NO_SUBJECT_GIVEN");
-            FacesContext.getCurrentInstance().addMessage("message",
-            new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate"));     
+            setWarnBundleMessage("ERR_NO_SUBJECT_GIVEN");
             return "";
         }
         try {
@@ -292,16 +264,12 @@
             newTopic.setLastPostDate(newTopic.getLastPost().getCreateDate());
         } catch (Exception e) {
             e.printStackTrace();
-            message = bundle.getString("ERR_INTERNAL");
-            FacesContext.getCurrentInstance().addMessage("message",
-            new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate"));
+            setWarnBundleMessage("ERR_INTERNAL");
             return "";
         }
         
         // Setting message that everything went smooth.
-        message = bundle.getString("SUCC_TOPIC_SPLITTED");
-        FacesContext.getCurrentInstance().addMessage("message",
-        new FacesMessage(FacesMessage.SEVERITY_INFO,message, "moderate"));     
+        setInfoBundleMessage("SUCC_TOPIC_SPLITTED");
         return "splitted";
     }
     
@@ -358,4 +326,16 @@
         }
     }
     
+    private void setWarnBundleMessage(String bundleKey) {
+        String message = bundle.getString(bundleKey);
+        FacesContext.getCurrentInstance().addMessage("message",
+        new FacesMessage(FacesMessage.SEVERITY_WARN,message, "moderate"));
+    }
+    
+    private void setInfoBundleMessage(String bundleKey) {
+        String message = bundle.getString(bundleKey);
+        FacesContext.getCurrentInstance().addMessage("message",
+        new FacesMessage(FacesMessage.SEVERITY_INFO,message, "moderate"));
+    }
+    
 }

Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_split.xhtml
===================================================================
--- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_split.xhtml	2006-07-17 21:44:54 UTC (rev 5124)
+++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/moderator/modcp_split.xhtml	2006-07-17 22:20:34 UTC (rev 5125)
@@ -31,8 +31,14 @@
      
 <ui:composition template="/views/common/common.xhtml">
 <ui:define name="mainContent">
-<c:if test="#{splitTopic.initialized &amp;&amp; splitTopic.topic!=null &amp;&amp; splitTopic.topic.id!=-1}">
-<forums:isAllowed fragment="acl://moderateForum" contextData="#{splitTopic.topic.forum}">
+
+<c:choose> 
+<c:when test="#{splitTopic.initialized &amp;&amp; splitTopic.topic!=null &amp;&amp; splitTopic.topic.id!=-1}">
+
+<isAllowedChoose>
+
+<isAllowedWhen fragment="acl://moderateForum" contextData="#{splitTopic.topic.forum}">
+
 <h:messages layout="table" infoStyle="color:green" warnStyle="color:red"/>
 
 <h:form>
@@ -204,13 +210,59 @@
    <tr>
        <!-- integrate jumpbox here -->
        <td align="right" valign="top" nowrap="nowrap">
-        <!--   <ui:include src="/views/jumpbox.xhtml"/> -->
+           <ui:include src="/views/jumpbox.xhtml"/>
        </td>
    </tr>
 </table>
 
-</forums:isAllowed>
-</c:if>
+</isAllowedWhen>
+
+<isAllowedOtherwise>
+    <table class="forumline" width="100%" cellspacing="1" cellpadding="4" border="0">
+       <tr>
+          <td>
+             <table width="100%" cellspacing="0" cellpadding="1" border="0">
+                <tr>
+                   <td>&amp;nbsp;</td>
+                </tr>
+                <tr>
+                   <td align="center">
+                            <span class="gen">${resource.Not_Moderator}</span>
+                   </td>
+                </tr>
+                <tr>
+                   <td>&amp;nbsp;</td>
+                </tr>
+             </table>
+          </td>
+       </tr>
+   </table>
+</isAllowedOtherwise>
+
+</isAllowedChoose>
+</c:when>
+<c:otherwise>
+    <table class="forumline" width="100%" cellspacing="1" cellpadding="4" border="0">
+           <tr>
+              <td>
+                 <table width="100%" cellspacing="0" cellpadding="1" border="0">
+                    <tr>
+                       <td>&amp;nbsp;</td>
+                    </tr>
+                    <tr>
+                       <td align="center">
+                                <span class="gen">${resource.No_posts_topic}</span>
+                       </td>
+                    </tr>
+                    <tr>
+                       <td>&amp;nbsp;</td>
+                    </tr>
+                 </table>
+              </td>
+           </tr>
+     </table>
+</c:otherwise>
+</c:choose>
 </ui:define>
 </ui:composition>
 </div>
\ No newline at end of file




More information about the jboss-svn-commits mailing list