[jboss-cvs] jboss-portal/forums/src/main/org/jboss/portlet/forums ...
Boleslaw Dawidowicz
bdaw at o2.pl
Wed Aug 23 09:11:47 EDT 2006
User: bdaw
Date: 06/08/23 09:11:47
Modified: forums/src/main/org/jboss/portlet/forums Tag:
JBoss_Portal_Branch_2_4 Context.java
Log:
correct form/mutipart handling in Forums Portlet
Revision Changes Path
No revision
No revision
1.13.2.1 +46 -8 jboss-portal/forums/src/main/org/jboss/portlet/forums/Context.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Context.java
===================================================================
RCS file: /cvsroot/jboss/jboss-portal/forums/src/main/org/jboss/portlet/forums/Context.java,v
retrieving revision 1.13
retrieving revision 1.13.2.1
diff -u -b -r1.13 -r1.13.2.1
--- Context.java 21 Feb 2006 14:29:41 -0000 1.13
+++ Context.java 23 Aug 2006 13:11:46 -0000 1.13.2.1
@@ -11,6 +11,8 @@
package org.jboss.portlet.forums;
import org.jboss.portal.core.modules.ModuleException;
+import org.jboss.portal.portlet.impl.jsr168.PortletRequestImpl;
+import org.jboss.portal.portlet.Parameters;
import org.jboss.portlet.JBossActionRequest;
import org.jboss.portlet.JBossActionResponse;
import org.jboss.portlet.forums.action.*;
@@ -37,12 +39,13 @@
import java.util.Map;
import java.util.HashMap;
import java.util.List;
+import java.lang.reflect.Field;
/**
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
* @author <a href="mailto:boleslaw.dawidowicz at jboss.com">Boleslaw Dawidowicz</a>
- * @version $Revision: 1.13 $
+ * @version $Revision: 1.13.2.1 $
*/
public class Context
{
@@ -193,6 +196,11 @@
public void update(JBossActionRequest req,
JBossActionResponse resp)
{
+
+ //We need to have new map to which we collect request parameters from multipart - we'll inject it little later
+ Map newParams = new HashMap();
+ newParams.putAll(req.getParameterMap());
+
//So because posting form is probably multipart at the beggining we must parse form fields
try
{
@@ -211,14 +219,13 @@
{
//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()});
+ newParams.put(item.getFieldName(), new String[]{item.getString()});
}
else
{
if (item.getSize() != 0)
{
files.put(item.getName(), new UploadedFileImpl(item.getContentType(), item.get(), item.getName(), item.getSize()));
-
}
}
}
@@ -226,11 +233,36 @@
}
catch (FileUploadException e)
{
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ e.printStackTrace();
//TODO:Some nice error message
}
+
+ //we need to hack the request class and inject newly created Parameters map using reflection as this are
+ //protected fields
+ try
+ {
+ Class requestClass = PortletRequestImpl.class;
+ Field field = requestClass.getDeclaredField("parameters");
+ field.setAccessible(true);
+ field.set(req, new Parameters(newParams));
+
+ //the second dummy field need to be set to null to force lazy initialization
+ requestClass = JBossActionRequest.class;
+ field = requestClass.getDeclaredField("blah");
+ field.setAccessible(true);
+ field.set(req, null);
+ }
+ catch (NoSuchFieldException e)
+ {
+ e.printStackTrace();
+ }
+ catch (IllegalAccessException e)
+ {
+ e.printStackTrace();
+ }
+
//if we started editing post, already stored attachs in sessions should be cleaned.
- if (req.getParameters().get("editPostInit","none").equals("true"))
+ if (req.getParameters().get("editPostInit", "none").equals("true"))
{
//clear stored files from session
req.getPortletSession().setAttribute(ForumsConstants.DISK_PERSISTED_ATTACHEMENTS, null);
@@ -464,13 +496,13 @@
if (isStored)
{
int index = Integer.parseInt(s);
- String newComment = req.getParameters().get("attach_comment[stored_attach_"+ s +"]","");
+ String newComment = req.getParameters().get("attach_comment[stored_attach_" + s + "]", "");
attachmentsManager.getUpdatedAttachments().put(new Integer(index), newComment);
}
//if this is previously uploaded file update comment in binding in Manager
else
{
- attachmentsManager.updateBindingComment(s, req.getParameters().get("attach_comment["+ s +"]",""));
+ attachmentsManager.updateBindingComment(s, req.getParameters().get("attach_comment[" + s + "]", ""));
}
session_attachment_deleted = true;
break;
@@ -483,7 +515,6 @@
//[Map]indexes of attachments and new comments that should be updated in DB
p_updated_attachments = attachmentsManager.getUpdatedAttachments();
-
// Are we refreshing the page ?
boolean c_refresh = p_preview;
c_refresh |= p_poll_delete;
@@ -763,6 +794,7 @@
/**
* Simply adds new TempFileBinding
+ *
* @param tmp
*/
public void addBinding(TempFileBinding tmp)
@@ -772,6 +804,7 @@
/**
* Removes Binding of id such as in argument
+ *
* @param id
*/
public void removeBinding(String id)
@@ -790,6 +823,7 @@
/**
* Updates comment for attachment
+ *
* @param id
* @param comment
*/
@@ -812,6 +846,7 @@
/**
* If object removed from session we do clean up and removes every file stored to disk
+ *
* @param httpSessionBindingEvent
*/
public void valueUnbound(HttpSessionBindingEvent httpSessionBindingEvent)
@@ -835,6 +870,7 @@
/**
* Stores indexes of persisted attachments which should be deleted
+ *
* @return
*/
public List getDeletedAttachments()
@@ -849,6 +885,7 @@
/**
* Stores indexes of persisted attachments and their new comments.
+ *
* @return
*/
public Map getUpdatedAttachments()
@@ -864,6 +901,7 @@
/**
* provides session unique integer value
+ *
* @param req
* @return
*/
More information about the jboss-cvs-commits
mailing list