Author: phuong_vu
Date: 2010-08-02 05:28:30 -0400 (Mon, 02 Aug 2010)
New Revision: 3733
Added:
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/upload/UploadSessionListener.java
Removed:
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/command/
exo/portal/branches/3.1.x/component/web/src/test/java/org/exoplatform/web/command/
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/web/command/handler/GetApplicationHandler.java
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/web/command/handler/HelloJCRHandler.java
Modified:
exo/portal/branches/3.1.x/component/web/src/main/java/conf/portal/configuration.xml
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/download/DownloadService.java
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/upload/UploadService.java
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/WebAppController.java
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/WebRequestHandler.java
exo/portal/branches/3.1.x/examples/portal/war/src/main/webapp/WEB-INF/web.xml
exo/portal/branches/3.1.x/testsuite/webuibasedsamples/src/main/java/org/exoplatform/sample/webui/component/UISampleDownloadUpload.java
exo/portal/branches/3.1.x/web/eXoResources/src/main/webapp/javascript/eXo/webui/UIUpload.js
exo/portal/branches/3.1.x/web/portal/src/main/webapp/WEB-INF/web.xml
exo/portal/branches/3.1.x/webui/core/src/main/java/org/exoplatform/webui/form/UIFormUploadInput.java
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/web/command/handler/DownloadHandler.java
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/web/command/handler/UploadHandler.java
Log:
EXOGTN-3 UploadHandler/DownloadHandler improvements
Modified:
exo/portal/branches/3.1.x/component/web/src/main/java/conf/portal/configuration.xml
===================================================================
---
exo/portal/branches/3.1.x/component/web/src/main/java/conf/portal/configuration.xml 2010-07-31
19:52:13 UTC (rev 3732)
+++
exo/portal/branches/3.1.x/component/web/src/main/java/conf/portal/configuration.xml 2010-08-02
09:28:30 UTC (rev 3733)
@@ -63,4 +63,30 @@
<type>org.exoplatform.web.filter.ExtensibleFilter</type>
</component>
+ <external-component-plugins>
+
<target-component>org.exoplatform.services.listener.ListenerService</target-component>
+ <component-plugin>
+
<name>org.exoplatform.web.GenericHttpListener.sessionDestroyed</name>
+ <set-method>addListener</set-method>
+ <type>org.exoplatform.upload.UploadSessionListener</type>
+ </component-plugin>
+ </external-component-plugins>
+
+ <external-component-plugins>
+
<target-component>org.exoplatform.web.WebAppController</target-component>
+ <component-plugin>
+ <name>UploadHandler</name>
+ <set-method>register</set-method>
+ <type>org.exoplatform.web.command.handler.UploadHandler</type>
+ </component-plugin>
+ </external-component-plugins>
+
+ <external-component-plugins>
+
<target-component>org.exoplatform.web.WebAppController</target-component>
+ <component-plugin>
+ <name>DownloadHandler</name>
+ <set-method>register</set-method>
+ <type>org.exoplatform.web.command.handler.DownloadHandler</type>
+ </component-plugin>
+ </external-component-plugins>
</configuration>
Modified:
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/download/DownloadService.java
===================================================================
---
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/download/DownloadService.java 2010-07-31
19:52:13 UTC (rev 3732)
+++
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/download/DownloadService.java 2010-08-02
09:28:30 UTC (rev 3733)
@@ -41,6 +41,8 @@
private PortalContainerInfo pinfo_;
+ public static final String DOWNLOAD_HANDLER_PATH = "download";
+
public DownloadService(PortalContainerInfo pinfo, InitParams params) throws Exception
{
int maxSize =
Integer.parseInt(params.getValueParam("download.resource.cache.size").getValue());
@@ -82,8 +84,8 @@
public String getDownloadLink(String id)
{
- return "/" + pinfo_.getContainerName() + "/command?"
- +
"type=org.exoplatform.web.command.handler.DownloadHandler&resourceId=" +
id;
+ return "/" + pinfo_.getContainerName() + "/" +
DOWNLOAD_HANDLER_PATH + "?"
+ + "resourceId=" + id;
}
@SuppressWarnings("serial")
@@ -97,7 +99,6 @@
maxSize_ = maxSize;
}
- @SuppressWarnings("unused")
protected boolean removeEldestEntry(Map.Entry<String, DownloadResource>
eldest)
{
return size() > maxSize_;
Modified:
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/upload/UploadService.java
===================================================================
---
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/upload/UploadService.java 2010-07-31
19:52:13 UTC (rev 3732)
+++
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/upload/UploadService.java 2010-08-02
09:28:30 UTC (rev 3733)
@@ -19,29 +19,29 @@
package org.exoplatform.upload;
+import org.apache.commons.fileupload.FileItem;
+import org.apache.commons.fileupload.FileUploadException;
+import org.apache.commons.fileupload.ProgressListener;
+import org.apache.commons.fileupload.disk.DiskFileItem;
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
+import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.exoplatform.container.xml.InitParams;
import org.exoplatform.container.xml.PortalContainerInfo;
import org.gatein.common.logging.Logger;
import org.gatein.common.logging.LoggerFactory;
import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import java.util.HashSet;
import java.util.LinkedHashMap;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
-/**
- * Created by The eXo Platform SARL
- * Author : Tuan Nguyen
- * tuan.nguyen(a)exoplatform.com
- * Dec 8, 2006
- */
public class UploadService
{
-
/** . */
private static final Logger log = LoggerFactory.getLogger(UploadService.class);
@@ -53,6 +53,8 @@
private Map<String, Integer> uploadLimitsMB_ = new LinkedHashMap<String,
Integer>();
+ public static String UPLOAD_RESOURCES_STACK = "uploadResourcesStack";
+
public UploadService(PortalContainerInfo pinfo, InitParams params) throws Exception
{
String tmpDir = System.getProperty("java.io.tmpdir");
@@ -66,127 +68,142 @@
uploadDir.mkdirs();
}
- public void createUploadResource(HttpServletRequest request) throws IOException
+ /**
+ * Create UploadResource for HttpServletRequest
+ *
+ * @param requestow
+ * the webapp's {@link javax.servlet.http.HttpServletRequest}
+ * @throws FileUploadException
+ */
+ @SuppressWarnings("unchecked")
+ public void createUploadResource(HttpServletRequest request) throws
FileUploadException
{
String uploadId = request.getParameter("uploadId");
- // by default, use the limit set in the service
- //int limitMB = defaultUploadLimitMB_;
- // if the limit is set in the request (specific for this upload) then use this
value instead of the default one
- //if (uploadLimitsMB_.containsKey(uploadId)) limitMB =
uploadLimitsMB_.get(uploadId).intValue() ;
- int limitMB = uploadLimitsMB_.get(uploadId).intValue();
+ UploadResource upResource = new UploadResource(uploadId);
+ upResource.setFileName("");// Avoid NPE in UploadHandler
+ uploadResources.put(upResource.getUploadId(), upResource);
+
+ putToStackInSession(request.getSession(true), uploadId);
- UploadResource upResource = new UploadResource(uploadId);
- RequestStreamReader reader = new RequestStreamReader(upResource);
- int estimatedSizeMB = (request.getContentLength() / 1024) / 1024;
- if (limitMB > 0 && estimatedSizeMB > limitMB)
- { // a limit set to 0 means unlimited
+ double contentLength = request.getContentLength();
+ upResource.setEstimatedSize(contentLength);
+ if (isLimited(upResource, contentLength))
+ {
upResource.setStatus(UploadResource.FAILED_STATUS);
- //upResource.setLimitMB(limitMB);
- uploadResources.put(uploadId, upResource);
- log.debug("Upload cancelled because file bigger than size limit : " +
estimatedSizeMB + " MB > "
- + limitMB + " MB");
- // WebuiRequestContext ctx = WebuiRequestContext.getCurrentInstance();
- // UIApplication uiApp = ctx.getUIApplication();
- // uiApp.addMessage(new ApplicationMessage("The file must be <
"+limitMB+" MB.", null, ApplicationMessage.WARNING));
return;
}
- // TODO : display error message, terminate upload correctly
- String headerEncoding = request.getCharacterEncoding();
- Map<String, String> headers = reader.parseHeaders(request.getInputStream(),
headerEncoding);
-
- String fileName = reader.getFileName(headers);
- if (fileName == null)
- fileName = uploadId;
- fileName = fileName.substring(fileName.lastIndexOf('\\') + 1);
-
- upResource.setFileName(fileName);
- upResource.setMimeType(headers.get(RequestStreamReader.CONTENT_TYPE));
- upResource.setStoreLocation(uploadLocation_ + "/" + uploadId +
"." + fileName);
- upResource.setEstimatedSize(request.getContentLength());
-
- uploadResources.put(upResource.getUploadId(), upResource);
-
- File fileStore = new File(upResource.getStoreLocation());
- if (!fileStore.exists())
- fileStore.createNewFile();
- FileOutputStream output = new FileOutputStream(fileStore);
- reader.readBodyData(request, output);
-
- if (upResource.getStatus() == UploadResource.UPLOADING_STATUS)
+ ServletFileUpload servletFileUpload = makeServletFileUpload(upResource);
+ // parse request
+ List<FileItem> itemList = servletFileUpload.parseRequest(request);
+ if (itemList == null || itemList.size() != 1 || itemList.get(0).isFormField())
{
- upResource.setStatus(UploadResource.UPLOADED_STATUS);
+ log.debug("Please upload 1 file per request");
return;
}
- uploadResources.remove(uploadId);
- fileStore.delete();
- }
+ DiskFileItem fileItem = (DiskFileItem)itemList.get(0);
+ String fileName = fileItem.getName();
+ String storeLocation = uploadLocation_ + "/" + uploadId + "." +
fileName;
- public void createUploadResource(String uploadId, String encoding, String contentType,
double contentLength,
- InputStream inputStream) throws Exception
- {
- UploadResource upResource = new UploadResource(uploadId);
- RequestStreamReader reader = new RequestStreamReader(upResource);
- int limitMB = uploadLimitsMB_.get(uploadId).intValue();
- int estimatedSizeMB = (int)contentLength / 1024 / 1024;
- if (limitMB > 0 && estimatedSizeMB > limitMB)
- { // a limit set to 0 means unlimited
- upResource.setStatus(UploadResource.FAILED_STATUS);
- uploadResources.put(uploadId, upResource);
- log.debug("Upload cancelled because file bigger than size limit : " +
estimatedSizeMB + " MB > "
- + limitMB + " MB");
- return;
- }
- Map<String, String> headers = reader.parseHeaders(inputStream, encoding);
+ // commons-fileupload will store the temp file with name *.tmp
+ // we need to rename it to our desired name
+ fileItem.getStoreLocation().renameTo(new File(storeLocation));
- String fileName = reader.getFileName(headers);
- if (fileName == null)
- fileName = uploadId;
- fileName = fileName.substring(fileName.lastIndexOf('\\') + 1);
-
upResource.setFileName(fileName);
- upResource.setMimeType(headers.get(RequestStreamReader.CONTENT_TYPE));
- upResource.setStoreLocation(uploadLocation_ + "/" + uploadId +
"." + fileName);
- upResource.setEstimatedSize(contentLength);
- uploadResources.put(upResource.getUploadId(), upResource);
- File fileStore = new File(upResource.getStoreLocation());
- if (!fileStore.exists())
- fileStore.createNewFile();
- FileOutputStream output = new FileOutputStream(fileStore);
- reader.readBodyData(inputStream, contentType, output);
+ upResource.setMimeType(fileItem.getContentType());
+ upResource.setStoreLocation(storeLocation);
+ upResource.setStatus(UploadResource.UPLOADED_STATUS);
+ }
- if (upResource.getStatus() == UploadResource.UPLOADING_STATUS)
+ @SuppressWarnings("unchecked")
+ private void putToStackInSession(HttpSession session, String uploadId)
+ {
+ Set<String> uploadResouceIds =
(Set<String>)session.getAttribute(UploadService.UPLOAD_RESOURCES_STACK);
+ if (uploadResouceIds == null)
{
- upResource.setStatus(UploadResource.UPLOADED_STATUS);
- return;
+ uploadResouceIds = new HashSet();
}
-
- uploadResources.remove(uploadId);
- fileStore.delete();
+ uploadResouceIds.add(uploadId);
+ session.setAttribute(UploadService.UPLOAD_RESOURCES_STACK, uploadResouceIds);
}
+ /**
+ * Get UploadResource by uploadId
+ *
+ * @param uploadId
+ * uploadId of UploadResource
+ * @return org.exoplatform.upload.UploadResource of uploadId
+ */
public UploadResource getUploadResource(String uploadId)
- {//throws Exception
- UploadResource upResource = uploadResources.get(uploadId);
- return upResource;
+ {
+ return uploadResources.get(uploadId);
}
+ /**
+ * Clean up temporary files that are uploaded in the Session but not removed yet
+ *
+ * @param session
+ */
+ @SuppressWarnings("unchecked")
+ public void cleanUp(HttpSession session)
+ {
+ log.debug("Cleaning up uploaded files for temporariness");
+ Set<String> uploadIds =
(Set<String>)session.getAttribute(UploadService.UPLOAD_RESOURCES_STACK);
+ if (uploadIds != null)
+ {
+ for (String id : uploadIds)
+ {
+ removeUploadResource(id);
+ uploadLimitsMB_.remove(id);
+ }
+ }
+ }
+
+ /**
+ * @deprecated use {@link #removeUploadResource(String)} instead
+ *
+ * @param uploadId
+ */
+ @Deprecated
public void removeUpload(String uploadId)
{
+ removeUploadResource(uploadId);
+ }
+
+ /**
+ * Remove the UploadResource and its temporary file that associated with given
<code>uploadId</code>.
+ * <br/>If <code>uploadId</code> is null or UploadResource is null,
do nothing
+ *
+ * @param uploadId uploadId of UploadResource will be removed
+ */
+ public void removeUploadResource(String uploadId)
+ {
if (uploadId == null)
return;
UploadResource upResource = uploadResources.get(uploadId);
- if (upResource == null)
- return;
- if (upResource.getStoreLocation() == null)
- return;
- File file = new File(upResource.getStoreLocation());
- file.delete();
- uploadResources.remove(uploadId);
- //uploadLimitsMB_.remove(uploadId);
+ if (upResource != null)
+ {
+ uploadResources.remove(uploadId);
+
+ if (upResource.getStoreLocation() != null)
+ {
+ File file = new File(upResource.getStoreLocation());
+ file.delete();
+ }
+ }
+
+ // uploadLimitsMB_.remove(uploadId);
}
+ /**
+ * Registry upload limit size for uploadLimitsMB_. If limitMB is null,
+ * defaultUploadLimitMB_ will be registried
+ *
+ * @param uploadId
+ * @param limitMB
+ * upload limit size
+ */
public void addUploadLimit(String uploadId, Integer limitMB)
{
if (limitMB == null)
@@ -195,8 +212,61 @@
uploadLimitsMB_.put(uploadId, limitMB);
}
+ /**
+ * Get all upload limit sizes
+ *
+ * @return all upload limit sizes
+ */
public Map<String, Integer> getUploadLimitsMB()
{
return uploadLimitsMB_;
}
+
+ private ServletFileUpload makeServletFileUpload(final UploadResource upResource)
+ {
+ // Create a factory for disk-based file items
+ DiskFileItemFactory factory = new DiskFileItemFactory();
+
+ // Set factory constraints
+ factory.setSizeThreshold(0);
+ factory.setRepository(new File(uploadLocation_));
+
+ // Create a new file upload handler
+ ServletFileUpload upload = new ServletFileUpload(factory);
+ ProgressListener listener = new ProgressListener()
+ {
+ public void update(long pBytesRead, long pContentLength, int pItems)
+ {
+ if (pBytesRead == upResource.getUploadedSize())
+ return;
+ upResource.addUploadedBytes(pBytesRead - upResource.getUploadedSize());
+ }
+ };
+ upload.setProgressListener(listener);
+ return upload;
+ }
+
+ private boolean isLimited(UploadResource upResource, double contentLength)
+ {
+ // by default, use the limit set in the service
+ int limitMB = defaultUploadLimitMB_;
+ // if the limit is set in the request (specific for this upload) then use
+ // this value instead of the default one
+ if (uploadLimitsMB_.containsKey(upResource.getUploadId()))
+ {
+ limitMB = uploadLimitsMB_.get(upResource.getUploadId()).intValue();
+ }
+
+ int estimatedSizeMB = (int)((contentLength / 1024) / 1024);
+ if (limitMB > 0 && estimatedSizeMB > limitMB)
+ { // a limit set to 0 means unlimited
+ if (log.isDebugEnabled())
+ {
+ log.debug("Upload cancelled because file bigger than size limit : "
+ estimatedSizeMB + " MB > " + limitMB
+ + " MB");
+ }
+ return true;
+ }
+ return false;
+ }
}
\ No newline at end of file
Added:
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/upload/UploadSessionListener.java
===================================================================
---
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/upload/UploadSessionListener.java
(rev 0)
+++
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/upload/UploadSessionListener.java 2010-08-02
09:28:30 UTC (rev 3733)
@@ -0,0 +1,30 @@
+package org.exoplatform.upload;
+
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionEvent;
+
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.services.listener.Event;
+import org.exoplatform.services.listener.Listener;
+
+/**
+ * This listener for the purpose of cleaning up temporary files that are uploaded to the
server
+ * but not removed by specific actions from user
+ *
+ * The listener is triggered when a session is destroyed
+ *
+ * @author <a href="mailto:trongtt@gmail.com">Tran The Trong</a>
+ * @version $Revision$
+ */
+public class UploadSessionListener extends Listener<PortalContainer,
HttpSessionEvent>
+{
+ @Override
+ public void onEvent(Event<PortalContainer, HttpSessionEvent> event) throws
Exception
+ {
+ PortalContainer container = event.getSource();
+ HttpSession session = event.getData().getSession();
+
+ UploadService uploadService =
(UploadService)container.getComponentInstanceOfType(UploadService.class);
+ uploadService.cleanUp(session);
+ }
+}
Modified:
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/WebAppController.java
===================================================================
---
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/WebAppController.java 2010-07-31
19:52:13 UTC (rev 3732)
+++
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/WebAppController.java 2010-08-02
09:28:30 UTC (rev 3733)
@@ -19,15 +19,6 @@
package org.exoplatform.web;
-import org.exoplatform.container.ExoContainer;
-import org.exoplatform.container.ExoContainerContext;
-import org.exoplatform.container.component.ComponentRequestLifecycle;
-import org.exoplatform.container.component.RequestLifeCycle;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-import org.exoplatform.web.application.Application;
-import org.exoplatform.web.command.CommandHandler;
-
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -35,6 +26,13 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.container.component.RequestLifeCycle;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.web.application.Application;
+
/**
* Created by The eXo Platform SAS
* Mar 21, 2007
@@ -67,10 +65,8 @@
applications_ = new HashMap<String, Application>();
attributes_ = new HashMap<String, Object>();
handlers_ = new HashMap<String, WebRequestHandler>();
- register(new CommandHandler());
}
- @SuppressWarnings("unused")
public Object getAttribute(String name, Object value)
{
return attributes_.get(name);
Modified:
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/WebRequestHandler.java
===================================================================
---
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/WebRequestHandler.java 2010-07-31
19:52:13 UTC (rev 3732)
+++
exo/portal/branches/3.1.x/component/web/src/main/java/org/exoplatform/web/WebRequestHandler.java 2010-08-02
09:28:30 UTC (rev 3733)
@@ -22,6 +22,8 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.exoplatform.container.component.BaseComponentPlugin;
+
/**
* Created by The eXo Platform SAS
* Mar 21, 2007
@@ -31,9 +33,9 @@
* In case of portal the path is /portal but you could return your own from the getPath()
method and hence the
* WebAppController would use your own handler
*
- * The execute method is to be overideen and the buisness logic should be handled here
+ * The execute method is to be overridden and the buisness logic should be handled here
*/
-abstract public class WebRequestHandler
+abstract public class WebRequestHandler extends BaseComponentPlugin
{
public void onInit(WebAppController controller) throws Exception
Modified: exo/portal/branches/3.1.x/examples/portal/war/src/main/webapp/WEB-INF/web.xml
===================================================================
---
exo/portal/branches/3.1.x/examples/portal/war/src/main/webapp/WEB-INF/web.xml 2010-07-31
19:52:13 UTC (rev 3732)
+++
exo/portal/branches/3.1.x/examples/portal/war/src/main/webapp/WEB-INF/web.xml 2010-08-02
09:28:30 UTC (rev 3733)
@@ -220,10 +220,14 @@
<url-pattern>/service</url-pattern>
</servlet-mapping>
<servlet-mapping>
- <servlet-name>portal</servlet-name>
- <url-pattern>/command/*</url-pattern>
+ <servlet-name>portal</servlet-name>
+ <url-pattern>/upload/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
+ <servlet-name>portal</servlet-name>
+ <url-pattern>/download/*</url-pattern>
+ </servlet-mapping>
+ <servlet-mapping>
<servlet-name>RestServer</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
Modified:
exo/portal/branches/3.1.x/testsuite/webuibasedsamples/src/main/java/org/exoplatform/sample/webui/component/UISampleDownloadUpload.java
===================================================================
---
exo/portal/branches/3.1.x/testsuite/webuibasedsamples/src/main/java/org/exoplatform/sample/webui/component/UISampleDownloadUpload.java 2010-07-31
19:52:13 UTC (rev 3732)
+++
exo/portal/branches/3.1.x/testsuite/webuibasedsamples/src/main/java/org/exoplatform/sample/webui/component/UISampleDownloadUpload.java 2010-08-02
09:28:30 UTC (rev 3733)
@@ -30,8 +30,8 @@
public UISampleDownloadUpload() throws Exception
{
addUIFormInput(new UIFormUploadInput("name0", "value0"));
- addUIFormInput(new UIFormUploadInput("name1", "value1"));
- addUIFormInput(new UIFormUploadInput("name2", "value2"));
+ addUIFormInput(new UIFormUploadInput("name1", "value1", 100));
+ addUIFormInput(new UIFormUploadInput("name2", "value2", 200));
}
public void setDownloadLink(String[] downloadLink)
Modified:
exo/portal/branches/3.1.x/web/eXoResources/src/main/webapp/javascript/eXo/webui/UIUpload.js
===================================================================
---
exo/portal/branches/3.1.x/web/eXoResources/src/main/webapp/javascript/eXo/webui/UIUpload.js 2010-07-31
19:52:13 UTC (rev 3732)
+++
exo/portal/branches/3.1.x/web/eXoResources/src/main/webapp/javascript/eXo/webui/UIUpload.js 2010-08-02
09:28:30 UTC (rev 3733)
@@ -28,8 +28,8 @@
* @param {boolean} isAutoUpload auto upload or none
*/
UIUpload.prototype.initUploadEntry = function(uploadId, isAutoUpload) {
- var url = eXo.env.server.context + "/command?" ;
- url +=
"type=org.exoplatform.web.command.handler.UploadHandler&action=progress&uploadId="+uploadId
;
+ var url = eXo.env.server.context + "/upload?" ;
+ url += "action=progress&uploadId="+uploadId ;
var responseText = ajaxAsyncGetRequest(url, false);
var response;
@@ -51,9 +51,8 @@
UIUpload.prototype.createUploadEntry = function(uploadId, isAutoUpload) {
var iframe = document.getElementById(uploadId+'uploadFrame');
var idoc = iframe.contentWindow.document ;
- var uploadAction = eXo.env.server.context + "/command?" ;
- uploadAction += "type=org.exoplatform.web.command.handler.UploadHandler";
- uploadAction += "&uploadId=" + uploadId+"&action=upload" ;
+ var uploadAction = eXo.env.server.context + "/upload?" ;
+ uploadAction += "uploadId=" + uploadId+"&action=upload" ;
idoc.open();
idoc.write("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>");
idoc.write("<html
xmlns='http://www.w3.org/1999/xhtml'
xml:lang='en' lang='" +eXo.core.I18n.lang+ "' dir='"
+eXo.core.I18n.dir+ "'>");
@@ -85,8 +84,8 @@
UIUpload.prototype.refeshProgress = function(elementId) {
var list = eXo.webui.UIUpload.listUpload;
if(list.length < 1) return;
- var url = eXo.env.server.context + "/command?" ;
- url +=
"type=org.exoplatform.web.command.handler.UploadHandler&action=progress" ;
+ var url = eXo.env.server.context + "/upload?" ;
+ url += "action=progress" ;
// var url = eXo.env.server.context + "/upload?action=progress";
for(var i = 0; i < list.length; i++){
url = url + "&uploadId=" + list[i];
@@ -165,8 +164,8 @@
*/
UIUpload.prototype.abortUpload = function(id) {
eXo.webui.UIUpload.listUpload.remove(id);
- var url = eXo.env.server.context + "/command?" ;
- url += "type=org.exoplatform.web.command.handler.UploadHandler&uploadId="
+id+"&action=abort" ;
+ var url = eXo.env.server.context + "/upload?" ;
+ url += "uploadId=" +id+"&action=abort" ;
// var url = eXo.env.server.context + "/upload?uploadId="
+id+"&action=abort" ;
var request = eXo.core.Browser.createHttpRequest();
request.open('GET', url, false);
@@ -197,8 +196,8 @@
* @param {String} id upload identifier
*/
UIUpload.prototype.deleteUpload = function(id) {
- var url = eXo.env.server.context + "/command?";
- url += "type=org.exoplatform.web.command.handler.UploadHandler&uploadId="
+id+"&action=delete" ;
+ var url = eXo.env.server.context + "/upload?";
+ url += "uploadId=" +id+"&action=delete" ;
// var url = eXo.env.server.context + "/upload?uploadId="
+id+"&action=delete" ;
var request = eXo.core.Browser.createHttpRequest();
request.open('GET', url, false);
Modified: exo/portal/branches/3.1.x/web/portal/src/main/webapp/WEB-INF/web.xml
===================================================================
--- exo/portal/branches/3.1.x/web/portal/src/main/webapp/WEB-INF/web.xml 2010-07-31
19:52:13 UTC (rev 3732)
+++ exo/portal/branches/3.1.x/web/portal/src/main/webapp/WEB-INF/web.xml 2010-08-02
09:28:30 UTC (rev 3733)
@@ -267,8 +267,12 @@
</servlet-mapping>
<servlet-mapping>
<servlet-name>portal</servlet-name>
- <url-pattern>/command/*</url-pattern>
+ <url-pattern>/upload/*</url-pattern>
</servlet-mapping>
+ <servlet-mapping>
+ <servlet-name>portal</servlet-name>
+ <url-pattern>/download/*</url-pattern>
+ </servlet-mapping>
<servlet-mapping>
<servlet-name>RestServer</servlet-name>
<url-pattern>/rest/*</url-pattern>
Modified:
exo/portal/branches/3.1.x/webui/core/src/main/java/org/exoplatform/webui/form/UIFormUploadInput.java
===================================================================
---
exo/portal/branches/3.1.x/webui/core/src/main/java/org/exoplatform/webui/form/UIFormUploadInput.java 2010-07-31
19:52:13 UTC (rev 3732)
+++
exo/portal/branches/3.1.x/webui/core/src/main/java/org/exoplatform/webui/form/UIFormUploadInput.java 2010-08-02
09:28:30 UTC (rev 3733)
@@ -54,11 +54,6 @@
*/
private boolean isAutoUpload = false;
- /**
- * The maximum size of the file to upload, in MB
- */
- //private int limitMB_;
-
public UIFormUploadInput(String name, String bindingExpression)
{
super(name, bindingExpression, String.class);
@@ -127,9 +122,8 @@
WebuiRequestContext pcontext =
(WebuiRequestContext)context.getParentAppRequestContext();
if (pcontext == null)
pcontext = context;
- String uploadAction = pcontext.getRequestContextPath() + "/command?";
- uploadAction +=
"type=org.exoplatform.web.command.handler.UploadHandler";
- uploadAction += "&uploadId=" + uploadId_ +
"&action=upload";
+ String uploadAction = pcontext.getRequestContextPath() + "/upload?";
+ uploadAction += "uploadId=" + uploadId_ +
"&action=upload";
return uploadAction;
}
@@ -148,8 +142,4 @@
this.isAutoUpload = isAutoUpload;
}
- // public void setLimit(int size) { limitMB_ = size; }
- //
- // public int getLimit() { return limitMB_; }
-
}
\ No newline at end of file
Modified:
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/web/command/handler/DownloadHandler.java
===================================================================
---
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/web/command/handler/DownloadHandler.java 2010-07-31
19:52:13 UTC (rev 3732)
+++
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/web/command/handler/DownloadHandler.java 2010-08-02
09:28:30 UTC (rev 3733)
@@ -24,7 +24,7 @@
import org.exoplatform.download.DownloadResource;
import org.exoplatform.download.DownloadService;
import org.exoplatform.web.WebAppController;
-import org.exoplatform.web.command.Command;
+import org.exoplatform.web.WebRequestHandler;
import java.io.InputStream;
import java.io.OutputStream;
@@ -39,14 +39,18 @@
* thuy.le(a)exoplatform.com
* Dec 9, 2006
*/
-public class DownloadHandler extends Command
+public class DownloadHandler extends WebRequestHandler
{
- private String resourceId;
+ @Override
+ public String[] getPath()
+ {
+ return new String[]{"/download"};
+ }
- @SuppressWarnings("unused")
public void execute(WebAppController controller, HttpServletRequest req,
HttpServletResponse res) throws Exception
{
+ String resourceId = req.getParameter("resourceId");
res.setHeader("Cache-Control", "private max-age=600,
s-maxage=120");
ExoContainer container = ExoContainerContext.getCurrentContainer();
DownloadService dservice =
(DownloadService)container.getComponentInstanceOfType(DownloadService.class);
@@ -87,11 +91,6 @@
}
}
- public String getResourceId()
- {
- return resourceId;
- }
-
private static void optimalRead(InputStream is, OutputStream os) throws Exception
{
int bufferLength = 1024; //TODO: Better to compute bufferLength in term of -Xms,
-Xmx properties
Deleted:
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/web/command/handler/GetApplicationHandler.java
===================================================================
---
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/web/command/handler/GetApplicationHandler.java 2010-07-31
19:52:13 UTC (rev 3732)
+++
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/web/command/handler/GetApplicationHandler.java 2010-08-02
09:28:30 UTC (rev 3733)
@@ -1,169 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * 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.exoplatform.web.command.handler;
-
-import org.exoplatform.application.registry.Application;
-import org.exoplatform.application.registry.ApplicationCategory;
-import org.exoplatform.application.registry.ApplicationRegistryService;
-import org.exoplatform.container.ExoContainer;
-import org.exoplatform.container.ExoContainerContext;
-import org.exoplatform.json.BeanToJSONPlugin;
-import org.exoplatform.json.JSONService;
-import org.exoplatform.portal.config.model.ApplicationType;
-import org.exoplatform.web.WebAppController;
-import org.exoplatform.web.command.Command;
-
-import java.io.IOException;
-import java.io.Writer;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * Created by The eXo Platform SARL
- * Author : Nhu Dinh Thuan
- * nhudinhthuan(a)exoplatform.com
- * May 31, 2007
- */
-public class GetApplicationHandler extends Command
-{
-
- private ApplicationType<?>[] applicationType;
-
- public void setApplicationTypes(ApplicationType<?>[] type)
- {
- applicationType = type;
- }
-
- @SuppressWarnings("unused")
- public void execute(WebAppController controller, HttpServletRequest req,
HttpServletResponse res) throws Exception
- {
- res.setHeader("Cache-Control", "no-cache");
- Writer writer = res.getWriter();
- try
- {
- writer.append(getApplications(req.getRemoteUser()));
- }
- catch (Exception e)
- {
- e.printStackTrace();
- throw new IOException(e.getMessage());
- }
- }
-
- @SuppressWarnings("unchecked")
- private StringBuilder getApplications(String remoteUser) throws Exception
- {
- ExoContainer container = ExoContainerContext.getCurrentContainer();
- ApplicationRegistryService prService =
-
(ApplicationRegistryService)container.getComponentInstanceOfType(ApplicationRegistryService.class);
-
- if (applicationType == null)
- applicationType = new ApplicationType<?>[0];
- List<ApplicationCategory> appCategories =
prService.getApplicationCategories(remoteUser, applicationType);
- ApplicationCategoryToJSONPlugin toJSON = new ApplicationCategoryToJSONPlugin();
-
- StringBuilder value = new StringBuilder();
- JSONService jsonService = new JSONService();
- jsonService.register(ApplicationCategory.class, toJSON);
-
- if (appCategories.size() < 1)
- return value;
-
- value.append("{\n").append(" applicationRegistry : {\n");
- for (int i = 0; i < appCategories.size(); i++)
- {
- ApplicationCategory category = appCategories.get(i);
- jsonService.toJSONScript(category, value, 1);
- if (i < appCategories.size() - 1)
- value.append(" ,\n");
- }
- value.append(" }\n").append("}\n");
-
- return value;
- }
-
- private class ApplicationCategoryToJSONPlugin extends
BeanToJSONPlugin<ApplicationCategory>
- {
-
- @SuppressWarnings("unchecked")
- public void toJSONScript(ApplicationCategory category, StringBuilder builder, int
indentLevel) throws Exception
- {
- StringBuilder builderPortlet = toJSONScript(category, indentLevel + 2);
- if (builderPortlet.length() < 1)
- return;
-
- appendIndentation(builder, indentLevel);
- builder.append('\'').append(category.getName()).append("' :
{\n");
- appendIndentation(builder, indentLevel + 1);
- builder.append("'name' :
'").append(category.getDisplayName()).append("',\n");
- appendIndentation(builder, indentLevel + 1);
- builder.append("'applications' : {\n");
- builder.append(builderPortlet);
- appendIndentation(builder, indentLevel + 1);
- builder.append("}\n");
- appendIndentation(builder, indentLevel);
- builder.append("}\n");
- }
-
- @SuppressWarnings("unchecked")
- private StringBuilder toJSONScript(ApplicationCategory category, int indentLevel)
throws Exception
- {
- StringBuilder builder = new StringBuilder();
- List<Application> applications = category.getApplications();
-
- for (int j = 0; j < applications.size(); j++)
- {
- toJSONScript(applications.get(j), builder, indentLevel);
- if (j < applications.size() - 1)
- {
- appendIndentation(builder, indentLevel);
- builder.append(",\n");
- }
- }
-
- return builder;
- }
-
- private void toJSONScript(Application application, StringBuilder builder, int
indentLevel)
- {
- appendIndentation(builder, indentLevel);
- builder.append('\'').append(application.getId()).append("'
: {\n");
- appendIndentation(builder, indentLevel + 1);
- //TODO: Tung.Pham modified
- //----------------------------
- //builder.append("'title' :
").append("'").append(application.getApplicationName()).append("',\n");
- builder.append("'name' :
").append("'").append(application.getApplicationName()).append("',\n");
- appendIndentation(builder, indentLevel + 1);
- builder.append("'title' :
").append("'").append(application.getDisplayName()).append("',\n");
- //------------------------------
- appendIndentation(builder, indentLevel + 1);
- builder.append("'des' :
").append("'").append(application.getDescription()).append("',\n");
- appendIndentation(builder, indentLevel + 1);
- builder.append("'id' :
").append("'").append(application.getId()).append("',\n");
- appendIndentation(builder, indentLevel + 1);
- builder.append("'type' :
").append("'").append(application.getType()).append("'\n");
- appendIndentation(builder, indentLevel);
- builder.append("}\n");
- }
- }
-
-}
Deleted:
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/web/command/handler/HelloJCRHandler.java
===================================================================
---
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/web/command/handler/HelloJCRHandler.java 2010-07-31
19:52:13 UTC (rev 3732)
+++
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/web/command/handler/HelloJCRHandler.java 2010-08-02
09:28:30 UTC (rev 3733)
@@ -1,46 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * 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.exoplatform.web.command.handler;
-
-import org.exoplatform.web.WebAppController;
-import org.exoplatform.web.command.Command;
-
-import java.io.PrintWriter;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * Created by The eXo Platform SARL
- * Author : Nguyen Ba Uoc
- * thuy.le(a)exoplatform.com
- * July 24, 2007
- */
-public class HelloJCRHandler extends Command
-{
-
- public void execute(WebAppController controller, HttpServletRequest req,
HttpServletResponse res) throws Exception
- {
- res.setContentType("text/xml");
- PrintWriter out = res.getWriter();
- out.println("Hello from server");
- System.out.println("Client request");
- }
-}
\ No newline at end of file
Modified:
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/web/command/handler/UploadHandler.java
===================================================================
---
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/web/command/handler/UploadHandler.java 2010-07-31
19:52:13 UTC (rev 3732)
+++
exo/portal/branches/3.1.x/webui/eXo/src/main/java/org/exoplatform/web/command/handler/UploadHandler.java 2010-08-02
09:28:30 UTC (rev 3733)
@@ -24,7 +24,7 @@
import org.exoplatform.upload.UploadResource;
import org.exoplatform.upload.UploadService;
import org.exoplatform.web.WebAppController;
-import org.exoplatform.web.command.Command;
+import org.exoplatform.web.WebRequestHandler;
import java.io.Writer;
import java.net.URLEncoder;
@@ -38,30 +38,24 @@
* nhudinhthuan(a)exoplatform.com
* Dec 9, 2006
*/
-public class UploadHandler extends Command
+public class UploadHandler extends WebRequestHandler
{
static enum UploadServiceAction {
PROGRESS, UPLOAD, DELETE, ABORT
}
-
- private String action;
-
- private String[] uploadId;
-
- public void setAction(String action)
+
+ @Override
+ public String[] getPath()
{
- this.action = action;
+ return new String[]{"/upload"};
}
- public void setUploadId(String[] uploadId)
- {
- this.uploadId = uploadId;
- }
-
- @SuppressWarnings("unused")
public void execute(WebAppController controller, HttpServletRequest req,
HttpServletResponse res) throws Exception
{
+ String action = req.getParameter("action");
+ String[] uploadIds = req.getParameterValues("uploadId");
+
res.setHeader("Cache-Control", "no-cache");
ExoContainer container = ExoContainerContext.getCurrentContainer();
@@ -73,19 +67,19 @@
if (uploadActionService == UploadServiceAction.PROGRESS)
{
Writer writer = res.getWriter();
- if (uploadId == null)
+ if (uploadIds == null)
return;
StringBuilder value = new StringBuilder();
value.append("{\n upload : {");
- for (int i = 0; i < uploadId.length; i++)
+ for (int i = 0; i < uploadIds.length; i++)
{
- UploadResource upResource = service.getUploadResource(uploadId[i]);
+ UploadResource upResource = service.getUploadResource(uploadIds[i]);
if (upResource == null)
continue;
if (upResource.getStatus() == UploadResource.FAILED_STATUS)
{
- int limitMB = service.getUploadLimitsMB().get(uploadId[i]).intValue();
- value.append("\n
\"").append(uploadId[i]).append("\": {");
+ int limitMB = service.getUploadLimitsMB().get(uploadIds[i]).intValue();
+ value.append("\n
\"").append(uploadIds[i]).append("\": {");
value.append("\n
\"status\":").append('\"').append("failed").append("\",");
value.append("\n
\"size\":").append('\"').append(limitMB).append("\"");
value.append("\n }");
@@ -96,12 +90,12 @@
{
percent = (upResource.getUploadedSize() * 100) /
upResource.getEstimatedSize();
}
- value.append("\n
\"").append(uploadId[i]).append("\": {");
+ value.append("\n
\"").append(uploadIds[i]).append("\": {");
value.append("\n
\"percent\":").append('\"').append((int)percent).append("\",");
value.append("\n
\"fileName\":").append('\"').append(encodeName(upResource.getFileName()))
.append("\"");
value.append("\n }");
- if (i < uploadId.length - 1)
+ if (i < uploadIds.length - 1)
value.append(',');
}
value.append("\n }\n}");
@@ -113,14 +107,11 @@
}
else if (uploadActionService == UploadServiceAction.DELETE)
{
- service.removeUpload(uploadId[0]);
+ service.removeUploadResource(uploadIds[0]);
}
else if (uploadActionService == UploadServiceAction.ABORT)
{
- //TODO: dang.tung - we don't need 2 statements because it'll show error
when we reload browser
- //UploadResource upResource = service.getUploadResource(uploadId[0]);
- //if(upResource != null) upResource.setStatus(UploadResource.UPLOADED_STATUS) ;
- service.removeUpload(uploadId[0]);
+ service.removeUploadResource(uploadIds[0]);
}
}