[gatein-commits] gatein SVN: r3692 - in portal/trunk: component/web/src/main/java/org/exoplatform/web/command/handler and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Jul 23 04:38:05 EDT 2010


Author: julien_viet
Date: 2010-07-23 04:38:04 -0400 (Fri, 23 Jul 2010)
New Revision: 3692

Added:
   portal/trunk/component/web/src/main/java/org/exoplatform/web/command/handler/
   portal/trunk/component/web/src/main/java/org/exoplatform/web/command/handler/DownloadHandler.java
   portal/trunk/component/web/src/main/java/org/exoplatform/web/command/handler/UploadHandler.java
Removed:
   portal/trunk/webui/eXo/src/main/java/org/exoplatform/web/command/handler/DownloadHandler.java
   portal/trunk/webui/eXo/src/main/java/org/exoplatform/web/command/handler/UploadHandler.java
Log:
moving UploadHandler and DownloadHandler to the component.web module


Copied: portal/trunk/component/web/src/main/java/org/exoplatform/web/command/handler/DownloadHandler.java (from rev 3689, portal/trunk/webui/eXo/src/main/java/org/exoplatform/web/command/handler/DownloadHandler.java)
===================================================================
--- portal/trunk/component/web/src/main/java/org/exoplatform/web/command/handler/DownloadHandler.java	                        (rev 0)
+++ portal/trunk/component/web/src/main/java/org/exoplatform/web/command/handler/DownloadHandler.java	2010-07-23 08:38:04 UTC (rev 3692)
@@ -0,0 +1,109 @@
+/**
+ * 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.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.download.DownloadResource;
+import org.exoplatform.download.DownloadService;
+import org.exoplatform.web.WebAppController;
+import org.exoplatform.web.command.Command;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URLEncoder;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Created by The eXo Platform SARL
+ * Author : LeBienThuy  
+ *          thuy.le at exoplatform.com
+ * Dec 9, 2006  
+ */
+public class DownloadHandler extends Command
+{
+
+   private String resourceId;
+
+   @SuppressWarnings("unused")
+   public void execute(WebAppController controller, HttpServletRequest req, HttpServletResponse res) throws Exception
+   {
+      res.setHeader("Cache-Control", "private max-age=600, s-maxage=120");
+      ExoContainer container = ExoContainerContext.getCurrentContainer();
+      DownloadService dservice = (DownloadService)container.getComponentInstanceOfType(DownloadService.class);
+      DownloadResource dresource = dservice.getDownloadResource(resourceId);
+      if (dresource == null)
+      {
+         res.setContentType("text/plain");
+         res.getWriter().write("NO DOWNDLOAD RESOURCE CONTENT  OR YOU DO NOT HAVE THE RIGHT TO ACCESS THE CONTENT");
+         return;
+      }
+      String userAgent = req.getHeader("User-Agent");
+      if (dresource.getDownloadName() != null)
+      {
+         if (userAgent != null && userAgent.contains("MSIE"))
+         {
+            res.setHeader("Content-Disposition", "attachment;filename=\""
+               + URLEncoder.encode(dresource.getDownloadName(), "UTF-8") + "\"");
+         }
+         else
+         {
+            res.setHeader("Content-Disposition", "attachment; filename*=utf-8''"
+               + URLEncoder.encode(dresource.getDownloadName(), "UTF-8") + "");
+         }
+      }
+      res.setContentType(dresource.getResourceMimeType());
+      InputStream is = dresource.getInputStream();
+      try
+      {
+         optimalRead(is, res.getOutputStream());
+      }
+      catch (Exception ex)
+      {
+         ex.printStackTrace();
+      }
+      finally
+      {
+         is.close();
+      }
+   }
+
+   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
+      int readLength = 0;
+      while (readLength > -1)
+      {
+         byte[] chunk = new byte[bufferLength];
+         readLength = is.read(chunk);
+         if (readLength > 0)
+         {
+            os.write(chunk, 0, readLength);
+         }
+      }
+   }
+}
\ No newline at end of file

Copied: portal/trunk/component/web/src/main/java/org/exoplatform/web/command/handler/UploadHandler.java (from rev 3689, portal/trunk/webui/eXo/src/main/java/org/exoplatform/web/command/handler/UploadHandler.java)
===================================================================
--- portal/trunk/component/web/src/main/java/org/exoplatform/web/command/handler/UploadHandler.java	                        (rev 0)
+++ portal/trunk/component/web/src/main/java/org/exoplatform/web/command/handler/UploadHandler.java	2010-07-23 08:38:04 UTC (rev 3692)
@@ -0,0 +1,138 @@
+/**
+ * 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.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.upload.UploadResource;
+import org.exoplatform.upload.UploadService;
+import org.exoplatform.web.WebAppController;
+import org.exoplatform.web.command.Command;
+
+import java.io.Writer;
+import java.net.URLEncoder;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Created by The eXo Platform SARL
+ * Author : Nhu Dinh Thuan
+ *          nhudinhthuan at exoplatform.com
+ * Dec 9, 2006  
+ */
+public class UploadHandler extends Command
+{
+
+   static enum UploadServiceAction {
+      PROGRESS, UPLOAD, DELETE, ABORT
+   }
+
+   private String action;
+
+   private String[] uploadId;
+
+   public void setAction(String action)
+   {
+      this.action = action;
+   }
+
+   public void setUploadId(String[] uploadId)
+   {
+      this.uploadId = uploadId;
+   }
+
+   @SuppressWarnings("unused")
+   public void execute(WebAppController controller, HttpServletRequest req, HttpServletResponse res) throws Exception
+   {
+      res.setHeader("Cache-Control", "no-cache");
+
+      ExoContainer container = ExoContainerContext.getCurrentContainer();
+      UploadService service = (UploadService)container.getComponentInstanceOfType(UploadService.class);
+      if (action == null || action.length() < 1)
+         return;
+
+      UploadServiceAction uploadActionService = UploadServiceAction.valueOf(action.toUpperCase());
+      if (uploadActionService == UploadServiceAction.PROGRESS)
+      {
+         Writer writer = res.getWriter();
+         if (uploadId == null)
+            return;
+         StringBuilder value = new StringBuilder();
+         value.append("{\n  upload : {");
+         for (int i = 0; i < uploadId.length; i++)
+         {
+            UploadResource upResource = service.getUploadResource(uploadId[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("\": {");
+               value.append("\n      \"status\":").append('\"').append("failed").append("\",");
+               value.append("\n      \"size\":").append('\"').append(limitMB).append("\"");
+               value.append("\n    }");
+               continue;
+            }
+            double percent = 100;
+            if (upResource.getStatus() == UploadResource.UPLOADING_STATUS)
+            {
+               percent = (upResource.getUploadedSize() * 100) / upResource.getEstimatedSize();
+            }
+            value.append("\n    \"").append(uploadId[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)
+               value.append(',');
+         }
+         value.append("\n  }\n}");
+         writer.append(value);
+      }
+      else if (uploadActionService == UploadServiceAction.UPLOAD)
+      {
+         service.createUploadResource(req);
+      }
+      else if (uploadActionService == UploadServiceAction.DELETE)
+      {
+         service.removeUpload(uploadId[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]);
+      }
+   }
+
+   public String encodeName(String name) throws Exception
+   {
+      String[] arr = name.split(" ");
+      String str = "";
+      for (int i = 0; i < arr.length; i++)
+      {
+         str += " " + URLEncoder.encode(arr[i], "UTF-8");
+      }
+      return str;
+   }
+
+}
\ No newline at end of file

Deleted: portal/trunk/webui/eXo/src/main/java/org/exoplatform/web/command/handler/DownloadHandler.java
===================================================================
--- portal/trunk/webui/eXo/src/main/java/org/exoplatform/web/command/handler/DownloadHandler.java	2010-07-23 08:16:26 UTC (rev 3691)
+++ portal/trunk/webui/eXo/src/main/java/org/exoplatform/web/command/handler/DownloadHandler.java	2010-07-23 08:38:04 UTC (rev 3692)
@@ -1,109 +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.container.ExoContainer;
-import org.exoplatform.container.ExoContainerContext;
-import org.exoplatform.download.DownloadResource;
-import org.exoplatform.download.DownloadService;
-import org.exoplatform.web.WebAppController;
-import org.exoplatform.web.command.Command;
-
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URLEncoder;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * Created by The eXo Platform SARL
- * Author : LeBienThuy  
- *          thuy.le at exoplatform.com
- * Dec 9, 2006  
- */
-public class DownloadHandler extends Command
-{
-
-   private String resourceId;
-
-   @SuppressWarnings("unused")
-   public void execute(WebAppController controller, HttpServletRequest req, HttpServletResponse res) throws Exception
-   {
-      res.setHeader("Cache-Control", "private max-age=600, s-maxage=120");
-      ExoContainer container = ExoContainerContext.getCurrentContainer();
-      DownloadService dservice = (DownloadService)container.getComponentInstanceOfType(DownloadService.class);
-      DownloadResource dresource = dservice.getDownloadResource(resourceId);
-      if (dresource == null)
-      {
-         res.setContentType("text/plain");
-         res.getWriter().write("NO DOWNDLOAD RESOURCE CONTENT  OR YOU DO NOT HAVE THE RIGHT TO ACCESS THE CONTENT");
-         return;
-      }
-      String userAgent = req.getHeader("User-Agent");
-      if (dresource.getDownloadName() != null)
-      {
-         if (userAgent != null && userAgent.contains("MSIE"))
-         {
-            res.setHeader("Content-Disposition", "attachment;filename=\""
-               + URLEncoder.encode(dresource.getDownloadName(), "UTF-8") + "\"");
-         }
-         else
-         {
-            res.setHeader("Content-Disposition", "attachment; filename*=utf-8''"
-               + URLEncoder.encode(dresource.getDownloadName(), "UTF-8") + "");
-         }
-      }
-      res.setContentType(dresource.getResourceMimeType());
-      InputStream is = dresource.getInputStream();
-      try
-      {
-         optimalRead(is, res.getOutputStream());
-      }
-      catch (Exception ex)
-      {
-         ex.printStackTrace();
-      }
-      finally
-      {
-         is.close();
-      }
-   }
-
-   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
-      int readLength = 0;
-      while (readLength > -1)
-      {
-         byte[] chunk = new byte[bufferLength];
-         readLength = is.read(chunk);
-         if (readLength > 0)
-         {
-            os.write(chunk, 0, readLength);
-         }
-      }
-   }
-}
\ No newline at end of file

Deleted: portal/trunk/webui/eXo/src/main/java/org/exoplatform/web/command/handler/UploadHandler.java
===================================================================
--- portal/trunk/webui/eXo/src/main/java/org/exoplatform/web/command/handler/UploadHandler.java	2010-07-23 08:16:26 UTC (rev 3691)
+++ portal/trunk/webui/eXo/src/main/java/org/exoplatform/web/command/handler/UploadHandler.java	2010-07-23 08:38:04 UTC (rev 3692)
@@ -1,138 +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.container.ExoContainer;
-import org.exoplatform.container.ExoContainerContext;
-import org.exoplatform.upload.UploadResource;
-import org.exoplatform.upload.UploadService;
-import org.exoplatform.web.WebAppController;
-import org.exoplatform.web.command.Command;
-
-import java.io.Writer;
-import java.net.URLEncoder;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * Created by The eXo Platform SARL
- * Author : Nhu Dinh Thuan
- *          nhudinhthuan at exoplatform.com
- * Dec 9, 2006  
- */
-public class UploadHandler extends Command
-{
-
-   static enum UploadServiceAction {
-      PROGRESS, UPLOAD, DELETE, ABORT
-   }
-
-   private String action;
-
-   private String[] uploadId;
-
-   public void setAction(String action)
-   {
-      this.action = action;
-   }
-
-   public void setUploadId(String[] uploadId)
-   {
-      this.uploadId = uploadId;
-   }
-
-   @SuppressWarnings("unused")
-   public void execute(WebAppController controller, HttpServletRequest req, HttpServletResponse res) throws Exception
-   {
-      res.setHeader("Cache-Control", "no-cache");
-
-      ExoContainer container = ExoContainerContext.getCurrentContainer();
-      UploadService service = (UploadService)container.getComponentInstanceOfType(UploadService.class);
-      if (action == null || action.length() < 1)
-         return;
-
-      UploadServiceAction uploadActionService = UploadServiceAction.valueOf(action.toUpperCase());
-      if (uploadActionService == UploadServiceAction.PROGRESS)
-      {
-         Writer writer = res.getWriter();
-         if (uploadId == null)
-            return;
-         StringBuilder value = new StringBuilder();
-         value.append("{\n  upload : {");
-         for (int i = 0; i < uploadId.length; i++)
-         {
-            UploadResource upResource = service.getUploadResource(uploadId[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("\": {");
-               value.append("\n      \"status\":").append('\"').append("failed").append("\",");
-               value.append("\n      \"size\":").append('\"').append(limitMB).append("\"");
-               value.append("\n    }");
-               continue;
-            }
-            double percent = 100;
-            if (upResource.getStatus() == UploadResource.UPLOADING_STATUS)
-            {
-               percent = (upResource.getUploadedSize() * 100) / upResource.getEstimatedSize();
-            }
-            value.append("\n    \"").append(uploadId[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)
-               value.append(',');
-         }
-         value.append("\n  }\n}");
-         writer.append(value);
-      }
-      else if (uploadActionService == UploadServiceAction.UPLOAD)
-      {
-         service.createUploadResource(req);
-      }
-      else if (uploadActionService == UploadServiceAction.DELETE)
-      {
-         service.removeUpload(uploadId[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]);
-      }
-   }
-
-   public String encodeName(String name) throws Exception
-   {
-      String[] arr = name.split(" ");
-      String str = "";
-      for (int i = 0; i < arr.length; i++)
-      {
-         str += " " + URLEncoder.encode(arr[i], "UTF-8");
-      }
-      return str;
-   }
-
-}
\ No newline at end of file



More information about the gatein-commits mailing list