[jboss-svn-commits] JBL Code SVN: r5092 - in labs/jbossforums/trunk/forums/src: main/org/jboss/portlet/forums/ui resources/portal-forums-war/WEB-INF resources/portal-forums-war/views/topics

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Jul 13 23:11:48 EDT 2006


Author: sohil.shah at jboss.com
Date: 2006-07-13 23:11:44 -0400 (Thu, 13 Jul 2006)
New Revision: 5092

Added:
   labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/DownloadFilter.java
   labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/Util.java
Modified:
   labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/BaseController.java
   labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml
   labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/web.xml
   labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/attachmentsview.xhtml
   labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml
   labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_poll_ballot.xhtml
   labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_poll_result.xhtml
Log:
Enabled Attachment Downloading from topic posts - http://jira.jboss.com/jira/browse/JBFORUMS-98

Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/BaseController.java
===================================================================
--- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/BaseController.java	2006-07-14 01:26:35 UTC (rev 5091)
+++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/BaseController.java	2006-07-14 03:11:44 UTC (rev 5092)
@@ -105,8 +105,5 @@
             BaseController.singleton = (ForumsModule)new InitialContext().lookup("java:portal/ForumsModule");
         }
         return BaseController.singleton;
-    } 
-    
-    //user preferences-------------------------------------------------------------------------------------------------------------------------
-    
+    }     
 }

Added: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/DownloadFilter.java
===================================================================
--- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/DownloadFilter.java	2006-07-14 01:26:35 UTC (rev 5091)
+++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/DownloadFilter.java	2006-07-14 03:11:44 UTC (rev 5092)
@@ -0,0 +1,116 @@
+/*****************************************
+ *                                       *
+ *  JBoss Portal: The OpenSource Portal  *
+ *                                       *
+ *   Distributable under LGPL license.   *
+ *   See terms of license at gnu.org.    *
+ *                                       *
+ *****************************************/
+package org.jboss.portlet.forums.ui;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.portlet.forums.model.Attachment;
+
+import javax.naming.InitialContext;
+import javax.transaction.UserTransaction;
+
+
+/**
+ * @author sohil shah
+ */
+public class DownloadFilter implements Filter 
+{
+    /**
+     * 
+     */
+    private final static String WRONG_REQ_RESP  = "Error accessing the requested resource.";
+    
+    private InitialContext ctx = null;
+    
+    
+    /**
+     * 
+     */
+    public void init(FilterConfig conf) 
+    {
+        try{this.ctx = new InitialContext();}catch(Exception e){e.printStackTrace();this.destroy();}
+    }
+
+    /**
+     * 
+     */
+    public void doFilter(ServletRequest request, ServletResponse response,
+            FilterChain chain) throws IOException 
+    { 
+    	try
+    	{
+	        if ((request instanceof HttpServletRequest)
+	                && (response instanceof HttpServletResponse)) 
+	        {
+	            HttpServletResponse httpResponse = (HttpServletResponse) response;
+	            HttpServletRequest httpRequest = (HttpServletRequest)request;	            
+	            UserTransaction transaction = null;
+	            try
+	            {
+	                transaction = (UserTransaction) ctx.lookup("java:comp/UserTransaction");
+	                transaction.begin();
+	                
+	                //get this attachment data
+	                int attachmentId = Integer.parseInt(request.getParameter("id"));
+	                Attachment attachment = BaseController.getForumsModule().findFindAttachmentById(new Integer(attachmentId));
+	 	       	 	       
+		 	       //set the attachment headers
+		           httpResponse.setContentLength((int)attachment.getFile().getSize());
+		           httpResponse.setContentType(attachment.getFile().getContentType());
+		           httpResponse.setHeader("Content-Disposition", "attachment; filename=" + attachment.getFile().getName());
+		 	       
+		 	       //now send the actual content down
+		 	       InputStream is = attachment.getFile().getContent().getBinaryStream();
+		 	       OutputStream os = httpResponse.getOutputStream();
+		 	       Util.transferBytes(is,os);
+		 	       os.flush();
+		 	       
+		 	       //cleanup
+		 	       if(is!=null)
+		 	       {
+		 	           is.close();
+		 	       }
+	            }
+	            finally
+	            {
+	                if(transaction!=null)
+	                {
+	                    transaction.rollback(); //since this is only a read-only operation..nothing to committ here
+	                }
+	            }
+	        } 
+	        else 
+	        {
+	            response.setContentType("text/html");
+	            response.getWriter().write(WRONG_REQ_RESP);
+	        }
+    	}    	
+    	catch(Exception e)
+    	{            
+    		e.printStackTrace();
+    	}
+    }
+
+    /**
+     * 
+     */
+    public void destroy() 
+    {
+    }
+}

Added: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/Util.java
===================================================================
--- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/Util.java	2006-07-14 01:26:35 UTC (rev 5091)
+++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/Util.java	2006-07-14 03:11:44 UTC (rev 5092)
@@ -0,0 +1,65 @@
+/*
+* 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;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.IOException;
+
+/*
+ * Created on Jul 13, 2006
+ *
+ * @author <a href="mailto:sohil.shah at jboss.com">Sohil Shah</a>
+ */
+public class Util 
+{
+    /**
+     * 
+     * @param srcStream
+     * @param destStream
+     * @throws IOException
+     */
+    public static void transferBytes(InputStream srcStream,OutputStream destStream) 
+    throws IOException
+    { 
+        try
+        {            
+            byte[] buffer = new byte[1024];
+            int read = -1;
+            while((read=srcStream.read(buffer))!=-1)
+            {
+                destStream.write(buffer,0,read);
+            }
+        }
+        finally
+        {
+            if(srcStream!=null)
+            {
+                srcStream.close();
+            }
+            if(destStream!=null)
+            {
+                destStream.close();
+            }
+        }
+    }
+}

Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml
===================================================================
--- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml	2006-07-14 01:26:35 UTC (rev 5091)
+++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml	2006-07-14 03:11:44 UTC (rev 5092)
@@ -8,11 +8,11 @@
 	<!-- general application configuration -->
 	<application>
 	    <!-- jbossportal-facelets integration -->
-	    <!--property-resolver>org.jboss.portal.faces.el.DelegatingPropertyResolver</property-resolver>
-	    <view-handler>com.sun.facelets.FaceletPortletViewHandler</view-handler-->
+	    <property-resolver>org.jboss.portal.faces.el.DelegatingPropertyResolver</property-resolver>
+	    <view-handler>com.sun.facelets.FaceletPortletViewHandler</view-handler>
 	    
 	    <!-- standalone facelets integration -->
-    	<view-handler>com.sun.facelets.FaceletViewHandler</view-handler> 
+    	<!--view-handler>com.sun.facelets.FaceletViewHandler</view-handler--> 
     	
     	<!-- custom action listener with integrated authorization checking -->
     	<action-listener>org.jboss.portlet.forums.auth.AuthorizationListener</action-listener>
@@ -28,10 +28,10 @@
     
     <!-- phase listeners -->
     <!-- remove this in portal-environment -->
-    <lifecycle>    	
+    <!--lifecycle>    	
     	<phase-listener>org.jboss.portlet.forums.ui.event.BeginTransactionListener</phase-listener>    	
     	<phase-listener>org.jboss.portlet.forums.ui.event.EndTransactionListener</phase-listener>    	
-    </lifecycle>
+    </lifecycle-->
         
     	
 	<!-- configuration for the shared EmptyController -->
@@ -506,5 +506,5 @@
                 <from-outcome>updateWatch</from-outcome>
                 <to-view-id>/views/watches/forumWatch.xhtml</to-view-id>
             </navigation-case>
-     </navigation-rule>
+     </navigation-rule>     
 </faces-config>
\ No newline at end of file

Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/web.xml
===================================================================
--- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/web.xml	2006-07-14 01:26:35 UTC (rev 5091)
+++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/web.xml	2006-07-14 03:11:44 UTC (rev 5092)
@@ -68,6 +68,16 @@
       <servlet-name>FacesServlet</servlet-name>      
    </filter-mapping>
    
+   <!-- Download Attachment filter -->
+   <filter>
+		<filter-name>DownloadFilter</filter-name>
+		<filter-class>org.jboss.portlet.forums.ui.DownloadFilter</filter-class>	    
+   </filter>
+   <filter-mapping>
+      <filter-name>DownloadFilter</filter-name>
+      <url-pattern>/downloadAttachment</url-pattern>      
+   </filter-mapping>
+   
    <!-- URL filter -->
        
     <!-- Faces Servlet -->   

Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/attachmentsview.xhtml
===================================================================
--- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/attachmentsview.xhtml	2006-07-14 01:26:35 UTC (rev 5091)
+++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/attachmentsview.xhtml	2006-07-14 03:11:44 UTC (rev 5092)
@@ -31,16 +31,41 @@
       xmlns:forums="http://www.jboss.com/products/jbossportal/forums"
       class="bb"
 >
-
-<ui:composition template="/views/common/common.xhtml">
-<ui:define name="mainContent">
-
-	<!-- THIS PAGE RECEIVES A java.util.List of Attachments from facelet include param
-	        <ui:param name="attachments" value="#{postrow.attachments}"/>
-	-->
-	<h:outputText value="ATTACHMENTS" />
-
-</ui:define>
-</ui:composition>
-
+   <c:forEach items="#{attachments}" var="attachment">	
+	   <div align="center"><hr width="95%"/></div>
+	
+	   <table width="95%" border="1" cellpadding="2" cellspacing="0" class="attachtable" align="center">
+	      <tr>
+	         <td width="100%" colspan="3" class="attachheader" align="center"><b>
+	         <span class="gen">${attachment.file.name}</span></b></td>
+	      </tr>
+	      <tr>
+	         <td width="15%" class="attachrow"><span class="genmed">&amp;nbsp;Description:</span></td>
+	         <td width="75%" class="attachrow">
+	            <table width="100%" border="0" cellpadding="0" cellspacing="4" align="center">	
+	               <tr>
+	                  <td class="attachrow"><span class="genmed">${attachment.comment}</span></td>
+	               </tr>
+	            </table>
+	         </td>
+	         <td rowspan="4" align="center" width="10%" class="attachrow"><br/>
+	         	<h:outputLink value="/portal-forums/downloadAttachment" styleClass="genmed">
+	         		<f:param name="id" value="${attachment.id}"/>
+	         		<b>Download </b>
+	         	</h:outputLink>
+	         </td>
+	      </tr>
+	      <tr>
+	
+	         <td width="15%" class="attachrow"><span class="genmed">&amp;nbsp;Filename:</span></td>
+	         <td width="75%" class="attachrow"><span class="genmed">&amp;nbsp;${attachment.file.name}</span>
+	         </td>
+	      </tr>
+	      <tr>
+	         <td width="15%" class="attachrow"><span class="genmed">&amp;nbsp;Filesize:</span></td>
+	         <td width="75%" class="attachrow"><span class="genmed">&amp;nbsp;${attachment.file.size}</span></td>
+	      </tr>      
+	   </table>
+	   <div align="center"><hr width="95%"/></div>
+   </c:forEach>
 </div>
\ No newline at end of file

Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml
===================================================================
--- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml	2006-07-14 01:26:35 UTC (rev 5091)
+++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_body.xhtml	2006-07-14 03:11:44 UTC (rev 5092)
@@ -313,7 +313,8 @@
                                     ${postrow.poster.user.signature}
                               </span>
                               
-                              <c:if test="postrow.attachments">-->
+                              <!-- show the attachments of this post here -->
+                              <c:if test="#{postrow.attachments!=null}">
                                  <ui:include src="/views/topics/attachmentsview.xhtml">
                                     <ui:param name="attachments" value="#{postrow.attachments}"/>
                                  </ui:include>

Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_poll_ballot.xhtml
===================================================================
--- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_poll_ballot.xhtml	2006-07-14 01:26:35 UTC (rev 5091)
+++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_poll_ballot.xhtml	2006-07-14 03:11:44 UTC (rev 5092)
@@ -31,10 +31,6 @@
       xmlns:forums="http://www.jboss.com/products/jbossportal/forums"
       class="bb"
 >
-
-<ui:composition template="/views/common/common.xhtml">
-<ui:define name="mainContent">
-
 <tr>
    <td class="row2" colspan="2"><br clear="all"/>
       <h:form>
@@ -85,8 +81,4 @@
       </h:form>
    </td>
 </tr>
-
-</ui:define>
-</ui:composition>
-
 </div>
\ No newline at end of file

Modified: labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_poll_result.xhtml
===================================================================
--- labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_poll_result.xhtml	2006-07-14 01:26:35 UTC (rev 5091)
+++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/views/topics/viewtopic_poll_result.xhtml	2006-07-14 03:11:44 UTC (rev 5092)
@@ -31,10 +31,6 @@
       xmlns:forums="http://www.jboss.com/products/jbossportal/forums"
       class="bb"
 >
-
-<ui:composition template="/views/common/common.xhtml">
-<ui:define name="mainContent">
-
 <tr>
    <td class="row2" colspan="2"><br clear="all"/>
          <table cellspacing="0" cellpadding="4" border="0" align="center">
@@ -106,8 +102,4 @@
          </table>         
    </td>
 </tr>
-
-</ui:define>
-</ui:composition>
-
 </div>
\ No newline at end of file




More information about the jboss-svn-commits mailing list