[jboss-svn-commits] JBL Code SVN: r5065 - in labs/jbossforums/trunk/forums/src: main/org/jboss/portlet/forums/ui main/org/jboss/portlet/forums/ui/action resources/portal-forums-war/WEB-INF
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jul 13 03:16:59 EDT 2006
Author: sohil.shah at jboss.com
Date: 2006-07-13 03:16:57 -0400 (Thu, 13 Jul 2006)
New Revision: 5065
Modified:
labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java
labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java
labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/PostAction.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
Log:
Fixed the issue with making attachments in portal environment - http://jira.jboss.com/jira/browse/JBFORUMS-86
Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java
===================================================================
--- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java 2006-07-13 01:01:31 UTC (rev 5064)
+++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/ForumsJSFPortlet.java 2006-07-13 07:16:57 UTC (rev 5065)
@@ -21,9 +21,15 @@
*/
package org.jboss.portlet.forums.ui;
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
+import org.apache.commons.fileupload.portlet.PortletFileUpload;
+
+//myfaces
import org.apache.myfaces.portlet.MyFacesGenericPortlet;
import java.io.IOException;
+import java.util.Iterator;
//portlet api
import javax.portlet.ActionRequest;
@@ -34,7 +40,11 @@
import javax.portlet.PortletSession;
import javax.portlet.PortletMode;
+//jboss portal
+import org.jboss.portlet.forums.helper.TempFileBinding;
+import org.jboss.portlet.forums.ui.PortalUtil;
+
/**
* @author <a href="mailto:sohil.shah at jboss.com">Sohil Shah</a>
*
@@ -49,7 +59,14 @@
{
try
{
- this.setupRenderParameters(request,response);
+ this.setupRenderParameters(request,response);
+
+ //parse and setup any attachments if they are sent in
+ if ((request.getContentType() != null) && request.getContentType().startsWith("multipart/form-data"))
+ {
+ this.processAttachments(request);
+ }
+
super.processAction(request,response);
}
catch(Throwable t)
@@ -81,8 +98,47 @@
throw new PortletException(t);
}
}
-
+
+ //override the render() method from GenericPortlet to detect a
+ // mode change
/**
+ *
+ */
+ public void render(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException
+ {
+ PortletSession session = request.getPortletSession();
+ PortletMode mode = (PortletMode)session.getAttribute("CurrentPortletMode");
+
+ if (mode == null)
+ {
+ mode = request.getPortletMode();
+ }
+
+ if (!mode.equals(request.getPortletMode()))
+ {
+ request.setAttribute("isPortletModeChanged", Boolean.TRUE);
+ }
+ else
+ {
+ request.setAttribute("isPortletModeChanged", Boolean.FALSE);
+ }
+
+ session.setAttribute("CurrentPortletMode", request.getPortletMode());
+ super.render(request, response);
+ }
+ //integrating handling Edit Mode for handling preferences-----------------------------------------------------------------------------------------------
+ /**
+ *
+ */
+ public void doEdit(RenderRequest request, RenderResponse response)
+ throws PortletException, IOException
+ {
+ setPortletRequestFlag(request);
+ nonFacesRequest(request,response,"/views/pref/index.jsf");
+ }
+ //----------------------------------------------------------------------------------------------------------------
+ /**
* Not sure why this needs to be done...
* This method tends to propagate the request parameters over to the JSF layer
* this is a workaround for a bug in either portal or MyFacesGenericPortlet...
@@ -158,43 +214,39 @@
}
}
- //integrating handling Edit Mode for handling preferences-----------------------------------------------------------------------------------------------
- // override the render() method from GenericPortlet to detect a
- // mode change
/**
*
+ *
*/
- public void render(RenderRequest request, RenderResponse response)
- throws PortletException, IOException
+ private void processAttachments(ActionRequest req) throws Exception
{
- PortletSession session = request.getPortletSession();
- PortletMode mode = (PortletMode)session.getAttribute("CurrentPortletMode");
-
- if (mode == null)
- {
- mode = request.getPortletMode();
- }
-
- if (!mode.equals(request.getPortletMode()))
- {
- request.setAttribute("isPortletModeChanged", Boolean.TRUE);
- }
- else
- {
- request.setAttribute("isPortletModeChanged", Boolean.FALSE);
- }
-
- session.setAttribute("CurrentPortletMode", request.getPortletMode());
- super.render(request, response);
- }
-
- /**
- *
- */
- protected void doEdit(RenderRequest request, RenderResponse response)
- throws PortletException, IOException
- {
- setPortletRequestFlag(request);
- nonFacesRequest(request,response,"/views/pref/index.jsf");
- }
+ DiskFileItemFactory factory = new DiskFileItemFactory();
+ PortletFileUpload upload = new PortletFileUpload(factory);
+
+ //Merge with upload fields
+ for (Iterator i = upload.parseRequest(req).iterator(); i.hasNext();)
+ {
+ FileItem item = (FileItem)i.next();
+ if (item.isFormField())
+ {
+ //if it's form field just add it to request params map
+ //TODO:Be aware that this adds single value as we won't have multiply values in new topic form for now...
+ req.getParameterMap().put(item.getFieldName(), new String[]{item.getString()});
+ }
+ else
+ {
+ //create the proper attachment file for the managed bean and put it as a ThreadLocal value
+ //the managed bean should pick this up from the thread
+ TempFileBinding file = new TempFileBinding(
+ item.getContentType(),
+ item.get(),
+ item.getName(),
+ String.valueOf(System.currentTimeMillis()) + "_" + item.getSize() //unique fileId for this collection of files
+ );
+
+ //place it as a ThreadLocal variable
+ PortalUtil.setUploadedAttachment(file);
+ }
+ }
+ }
}
Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java
===================================================================
--- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java 2006-07-13 01:01:31 UTC (rev 5064)
+++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/PortalUtil.java 2006-07-13 07:16:57 UTC (rev 5065)
@@ -73,6 +73,7 @@
import org.jboss.portlet.forums.impl.MessageImpl;
import org.jboss.portlet.forums.model.Topic;
import org.jboss.portlet.forums.model.Forum;
+import org.jboss.portlet.forums.helper.TempFileBinding;
@@ -485,4 +486,31 @@
return isWatchingForum;
}
+
+ /**
+ *
+ * This is for handling attachments in the portal environment
+ * Created on Jul 13, 2006
+ *
+ * @author <a href="mailto:sohil.shah at jboss.com">Sohil Shah</a>
+ */
+ private static ThreadLocal uploadedAttachment = new ThreadLocal();
+
+ /**
+ *
+ *
+ */
+ public static void setUploadedAttachment(TempFileBinding attachment)
+ {
+ PortalUtil.uploadedAttachment.set(attachment);
+ }
+
+ /**
+ *
+ *
+ */
+ public static TempFileBinding getUploadedAttachment()
+ {
+ return (TempFileBinding)PortalUtil.uploadedAttachment.get();
+ }
}
Modified: labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/PostAction.java
===================================================================
--- labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/PostAction.java 2006-07-13 01:01:31 UTC (rev 5064)
+++ labs/jbossforums/trunk/forums/src/main/org/jboss/portlet/forums/ui/action/PostAction.java 2006-07-13 07:16:57 UTC (rev 5065)
@@ -474,21 +474,32 @@
String navState = null;
try
{
- if(this.attachment!=null)
- {
- TempFileBinding file = new TempFileBinding(
+ TempFileBinding file = null;
+
+ if(!JSFUtil.isRunningInPortal() && this.attachment!=null)
+ {
+ file = new TempFileBinding(
this.attachment.getContentType(),
this.attachment.getBytes(),
this.attachment.getName(),
String.valueOf(System.currentTimeMillis()) + "_" + this.attachments.size() //unique fileId for this collection of files
);
- if(this.attachmentComment!=null)
- {
- file.setComment(this.attachmentComment);
- }
- file.setFileId("-1"); //identifies attachments from ui that are not stored in the database yet
- this.attachments.add(file);
- }
+ }
+ else
+ {
+ //grab this from the thread local
+ file = PortalUtil.getUploadedAttachment();
+ }
+
+ if(file!=null)
+ {
+ if(this.attachmentComment!=null)
+ {
+ file.setComment(this.attachmentComment);
+ }
+ file.setFileId("-1"); //identifies attachments from ui that are not stored in the database yet
+ this.attachments.add(file);
+ }
//clear out the attachment related view data
this.setAttachment(null);
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-13 01:01:31 UTC (rev 5064)
+++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/forums-config.xml 2006-07-13 07:16:57 UTC (rev 5065)
@@ -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>
@@ -27,12 +27,11 @@
</application>
<!-- phase listeners -->
- <lifecycle>
- <!-- starts before restoreView -->
- <phase-listener>org.jboss.portlet.forums.ui.event.BeginTransactionListener</phase-listener>
- <!-- starts after renderResponse -->
+ <!-- remove this in portal-environment -->
+ <!--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 -->
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-13 01:01:31 UTC (rev 5064)
+++ labs/jbossforums/trunk/forums/src/resources/portal-forums-war/WEB-INF/web.xml 2006-07-13 07:16:57 UTC (rev 5065)
@@ -9,10 +9,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
- <!--listener>
- <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
- </listener-->
-
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>
@@ -32,13 +28,7 @@
State saving method: "client" or "server" (= default)
See JSF Specification 2.5.2
</description>
- </context-param>
-
- <!-- Special Debug Output for Development -->
- <context-param>
- <param-name>facelets.DEVELOPMENT</param-name>
- <param-value>true</param-value>
- </context-param>
+ </context-param>
<!-- facelets integration -->
<!-- Use Documents Saved as *.xhtml -->
@@ -47,7 +37,13 @@
<param-value>.xhtml</param-value>
</context-param>
+ <!-- Special Debug Output for Development -->
<context-param>
+ <param-name>facelets.DEVELOPMENT</param-name>
+ <param-value>true</param-value>
+ </context-param>
+
+ <context-param>
<param-name>facelets.LIBRARIES</param-name>
<param-value>/WEB-INF/tomahawk.taglib.xml;/WEB-INF/forums.taglib.xml</param-value>
</context-param>
@@ -73,8 +69,7 @@
</filter-mapping>
<!-- URL filter -->
-
-
+
<!-- Faces Servlet -->
<servlet>
<servlet-name>FacesServlet</servlet-name>
@@ -89,7 +84,7 @@
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
- <servlet>
+ <!--servlet>
<servlet-name>DownloadAttachmentsServlet</servlet-name>
<servlet-class>org.jboss.portlet.forums.servlet.DownloadAttachmentsServlet</servlet-class>
<load-on-startup>1</load-on-startup>
@@ -98,7 +93,7 @@
<servlet-mapping>
<servlet-name>DownloadAttachmentsServlet</servlet-name>
<url-pattern>/files</url-pattern>
- </servlet-mapping>
+ </servlet-mapping-->
<!-- error handling -->
<!--error-page>
More information about the jboss-svn-commits
mailing list