[gatein-commits] gatein SVN: r7774 - in portal/trunk: component/web/server/src/main/java/org/exoplatform/web/handler and 5 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Oct 19 01:02:16 EDT 2011


Author: haint
Date: 2011-10-19 01:02:16 -0400 (Wed, 19 Oct 2011)
New Revision: 7774

Added:
   portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/webui/UIUploadInput.js
   portal/trunk/web/portal/src/main/webapp/groovy/webui/form/UIUploadInput.gtmpl
   portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/input/UIUploadInput.java
Modified:
   portal/trunk/component/web/server/src/main/java/org/exoplatform/upload/UploadService.java
   portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java
   portal/trunk/testsuite/webuibasedsamples/src/main/java/org/exoplatform/sample/webui/component/UISampleDownloadUpload.java
   portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/webui/UIUpload.js
   portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_cs.properties
   portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_de.properties
   portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_en.properties
   portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_es.properties
   portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_fr.properties
   portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_it.properties
   portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ja.properties
   portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ne.properties
   portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_nl.properties
   portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_pt_BR.properties
   portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ru.properties
   portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_uk.properties
   portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_vi.properties
Log:
GTNPORTAL-2183 Build a new UIFormUploadInput component and difine limit size unit for UploadService

Modified: portal/trunk/component/web/server/src/main/java/org/exoplatform/upload/UploadService.java
===================================================================
--- portal/trunk/component/web/server/src/main/java/org/exoplatform/upload/UploadService.java	2011-10-19 04:41:43 UTC (rev 7773)
+++ portal/trunk/component/web/server/src/main/java/org/exoplatform/upload/UploadService.java	2011-10-19 05:02:16 UTC (rev 7774)
@@ -32,6 +32,9 @@
 import org.gatein.common.text.EntityEncoder;
 
 import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
@@ -53,19 +56,24 @@
 
    private String uploadLocation_;
 
-   private int defaultUploadLimitMB_;
+   private UploadLimit defaultUploadLimitMB_;
 
-   private Map<String, Integer> uploadLimitsMB_ = new LinkedHashMap<String, Integer>();
+   private Map<String, UploadLimit> uploadLimits = new LinkedHashMap<String, UploadLimit>();
    
    public static String UPLOAD_RESOURCES_STACK = "uploadResourcesStack";
-
+   
+   public static enum UploadUnit 
+   {
+      KB, MB, GB
+   };
+   
    public UploadService(PortalContainerInfo pinfo, InitParams params) throws Exception
    {
       String tmpDir = System.getProperty("java.io.tmpdir");
       if (params == null || params.getValueParam("upload.limit.size") == null)
-         defaultUploadLimitMB_ = 0; // 0 means unlimited
+         defaultUploadLimitMB_ = new UploadLimit(0, UploadUnit.MB); // 0 means unlimited
       else
-         defaultUploadLimitMB_ = Integer.parseInt(params.getValueParam("upload.limit.size").getValue());
+         defaultUploadLimitMB_ = new UploadLimit(Integer.parseInt(params.getValueParam("upload.limit.size").getValue()), UploadUnit.MB);
       uploadLocation_ = tmpDir + "/" + pinfo.getContainerName() + "/eXoUpload";
       File uploadDir = new File(uploadLocation_);
       if (!uploadDir.exists())
@@ -112,6 +120,7 @@
       if (itemList == null || itemList.size() != 1 || itemList.get(0).isFormField())
       {
          log.debug("Please upload 1 file per request");
+         removeUploadResource(uploadId);
          return;
       }
 
@@ -120,13 +129,23 @@
       if (fileName == null)
          fileName = uploadId;
       fileName = fileName.substring(fileName.lastIndexOf('\\') + 1);
-      fileName = EntityEncoder.FULL.encode(fileName);
       String storeLocation = uploadLocation_ + "/" + uploadId + "." + fileName;
 
       
       // 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));
+      File fileStore = new File(storeLocation);
+      if (!fileStore.exists())
+         try
+         {
+            fileStore.createNewFile();
+         }
+         catch (IOException e)
+         {
+            throw new RuntimeException(e);
+         }
+      
 
       upResource.setFileName(fileName);
       upResource.setMimeType(fileItem.getContentType());
@@ -140,6 +159,49 @@
       upResource.setStatus(UploadResource.UPLOADED_STATUS);
    }
 
+   /**
+    * @deprecated use {@link #createUploadResource(String, javax.servlet.http.HttpServletRequest)}  instead
+    *
+    */
+   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);
+      uploadResources.put(upResource.getUploadId(), upResource);
+      if (isLimited(upResource, contentLength))
+      {
+         upResource.setStatus(UploadResource.FAILED_STATUS);
+         return;
+      }
+      
+      Map<String, String> headers = reader.parseHeaders(inputStream, encoding);
+
+      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);      
+      File fileStore = new File(upResource.getStoreLocation());
+      if (!fileStore.exists())
+         fileStore.createNewFile();
+      FileOutputStream output = new FileOutputStream(fileStore);
+      reader.readBodyData(inputStream, contentType, output);
+
+      if (upResource.getStatus() == UploadResource.UPLOADING_STATUS)
+      {
+         upResource.setStatus(UploadResource.UPLOADED_STATUS);
+         return;
+      }
+
+      uploadResources.remove(uploadId);
+      fileStore.delete();
+   }
+
    @SuppressWarnings("unchecked")
    private void putToStackInSession(HttpSession session, String uploadId)
    {
@@ -178,7 +240,7 @@
          for (String id : uploadIds)
          {
             removeUploadResource(id);
-            uploadLimitsMB_.remove(id);
+            uploadLimits.remove(id);
          }
       }
    }
@@ -229,10 +291,23 @@
     */
    public void addUploadLimit(String uploadId, Integer limitMB)
    {
-      if (limitMB == null)
-         uploadLimitsMB_.put(uploadId, Integer.valueOf(defaultUploadLimitMB_));
+      addUploadLimit(uploadId, limitMB, UploadUnit.MB);
+   }
+   
+   public void addUploadLimit(String uploadId, Integer limit, UploadUnit unit) 
+   {
+      if (limit == null)
+      {
+         uploadLimits.put(uploadId, defaultUploadLimitMB_);
+      }
+      else if(unit == null)
+      {
+         uploadLimits.put(uploadId, new UploadLimit(limit, UploadUnit.MB));
+      }
       else
-         uploadLimitsMB_.put(uploadId, limitMB);
+      {
+         uploadLimits.put(uploadId, new UploadLimit(limit, unit));
+      }
    }
 
    /**
@@ -240,9 +315,9 @@
     * 
     * @return all upload limit sizes
     */
-   public Map<String, Integer> getUploadLimitsMB()
+   public Map<String, UploadLimit> getUploadLimits()
    {
-      return uploadLimitsMB_;
+      return uploadLimits;
    }
 
    private ServletFileUpload makeServletFileUpload(final UploadResource upResource)
@@ -273,26 +348,61 @@
    private boolean isLimited(UploadResource upResource, double contentLength)
    {
       // by default, use the limit set in the service
-      int limitMB = defaultUploadLimitMB_;
+      UploadLimit limit = 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()))
+      if (uploadLimits.containsKey(upResource.getUploadId()))
       {
-         limitMB = uploadLimitsMB_.get(upResource.getUploadId()).intValue();
+         limit = uploadLimits.get(upResource.getUploadId());
       }
 
-      int estimatedSizeMB = (int)((contentLength / 1024) / 1024);
-      if (limitMB > 0 && estimatedSizeMB > limitMB)
+      double estimatedSize = contentLength / limit.division;
+      if (limit.getLimit() > 0 && estimatedSize > limit.getLimit())
       { // a limit set to 0 means unlimited         
          if (log.isDebugEnabled())
          {
-            log.debug("Upload cancelled because file bigger than size limit : " + estimatedSizeMB + " MB > " + limitMB
-               + " MB");
+            log.debug("Upload cancelled because file bigger than size limit : " + estimatedSize + " " + limit.unit + " > " + limit.getLimit()
+               + " " + limit.unit);
          }
          return true;
       }
       return false;
    }
 
-   
+   public static class UploadLimit
+   {
+      private int limit;
+      
+      private int division;
+      
+      private UploadUnit unit;
+      
+      public UploadLimit(int limit, UploadUnit unit)
+      {
+         this.limit = limit;
+         this.unit = unit;
+         if(unit == UploadUnit.KB) 
+         {
+            division = 1024;
+         }
+         else if(unit == UploadUnit.MB)
+         {
+            division = 1024 * 1024;
+         }
+         else if(unit == UploadUnit.GB)
+         {
+            division = 1024 * 1024 * 1024;
+         }
+      }
+      
+      public int getLimit()
+      {
+         return limit;
+      }
+      
+      public String getUnit()
+      {
+         return unit.toString();
+      }
+   }
 }

Modified: portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java
===================================================================
--- portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java	2011-10-19 04:41:43 UTC (rev 7773)
+++ portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java	2011-10-19 05:02:16 UTC (rev 7774)
@@ -24,6 +24,7 @@
 import org.exoplatform.container.ExoContainerContext;
 import org.exoplatform.upload.UploadResource;
 import org.exoplatform.upload.UploadService;
+import org.exoplatform.upload.UploadService.UploadLimit;
 import org.exoplatform.web.ControllerContext;
 import org.exoplatform.web.WebAppController;
 import org.exoplatform.web.WebRequestHandler;
@@ -66,7 +67,7 @@
       String[] uploadIds = req.getParameterValues("uploadId");
       
       res.setHeader("Cache-Control", "no-cache");
-
+      
       ExoContainer container = ExoContainerContext.getCurrentContainer();
       UploadService service = (UploadService)container.getComponentInstanceOfType(UploadService.class);
       if (action == null || action.length() < 1)
@@ -87,10 +88,11 @@
                continue;
             if (upResource.getStatus() == UploadResource.FAILED_STATUS)
             {
-               int limitMB = service.getUploadLimitsMB().get(uploadIds[i]).intValue();
+               UploadLimit limit = service.getUploadLimits().get(uploadIds[i]);
                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      \"size\":").append('\"').append(limit.getLimit()).append("\",");
+               value.append("\n      \"unit\":").append('\"').append(limit.getUnit()).append("\"");
                value.append("\n    }");
                continue;
             }
@@ -101,7 +103,8 @@
             }
             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()))
+            String fileName = EntityEncoder.FULL.encode(upResource.getFileName());
+            value.append("\n      \"fileName\":").append('\"').append(encodeName(fileName))
                .append("\"");
             value.append("\n    }");
             if (i < uploadIds.length - 1)

Modified: portal/trunk/testsuite/webuibasedsamples/src/main/java/org/exoplatform/sample/webui/component/UISampleDownloadUpload.java
===================================================================
--- portal/trunk/testsuite/webuibasedsamples/src/main/java/org/exoplatform/sample/webui/component/UISampleDownloadUpload.java	2011-10-19 04:41:43 UTC (rev 7773)
+++ portal/trunk/testsuite/webuibasedsamples/src/main/java/org/exoplatform/sample/webui/component/UISampleDownloadUpload.java	2011-10-19 05:02:16 UTC (rev 7774)
@@ -1,12 +1,17 @@
 package org.exoplatform.sample.webui.component;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.exoplatform.download.DownloadResource;
 import org.exoplatform.download.DownloadService;
 import org.exoplatform.download.InputStreamDownloadResource;
 import org.exoplatform.upload.UploadResource;
+import org.exoplatform.upload.UploadService.UploadUnit;
 import org.exoplatform.webui.config.annotation.ComponentConfig;
 import org.exoplatform.webui.config.annotation.EventConfig;
 import org.exoplatform.webui.core.lifecycle.UIFormLifecycle;
@@ -14,6 +19,7 @@
 import org.exoplatform.webui.event.EventListener;
 import org.exoplatform.webui.form.UIForm;
 import org.exoplatform.webui.form.UIFormUploadInput;
+import org.exoplatform.webui.form.input.UIUploadInput;
 
 @ComponentConfig(lifecycle = UIFormLifecycle.class, template = "app:/groovy/webui/component/UISampleDownloadUpload.gtmpl", events = {@EventConfig(listeners = UISampleDownloadUpload.SubmitActionListener.class)})
 public class UISampleDownloadUpload extends UIForm
@@ -30,8 +36,13 @@
    public UISampleDownloadUpload() throws Exception
    {
       addUIFormInput(new UIFormUploadInput("name0", "value0"));
-      addUIFormInput(new UIFormUploadInput("name1", "value1", 100));
+      addUIFormInput(new UIFormUploadInput("name1", "value1", 1));
       addUIFormInput(new UIFormUploadInput("name2", "value2", 200));
+      
+      addUIFormInput(new UIUploadInput("name3", "name3", 2, 300, UploadUnit.KB));
+      UIUploadInput input = new UIUploadInput("name4", "name4", 2, 300);
+      input.setAutoUpload(false);
+      addUIFormInput(input);
    }
 
    public void setDownloadLink(String[] downloadLink)
@@ -71,9 +82,9 @@
       {
          UISampleDownloadUpload uiForm = event.getSource();
          DownloadService dservice = uiForm.getApplicationComponent(DownloadService.class);
-         String[] downloadLink = new String[3];
-         String[] fileName = new String[3];
-         String[] inputName = new String[3];
+         List<String> downloadLink = new ArrayList<String>();
+         List<String> fileName = new ArrayList<String>();
+         List<String> inputName = new ArrayList<String>();
          for (int index = 0; index <= 2; index++)
          {
             UIFormUploadInput input = uiForm.getChildById("name" + index);
@@ -83,15 +94,28 @@
                DownloadResource dresource =
                   new InputStreamDownloadResource(input.getUploadDataAsStream(), uploadResource.getMimeType());
                dresource.setDownloadName(uploadResource.getFileName());
-               downloadLink[index] = dservice.getDownloadLink(dservice.addDownloadResource(dresource));
-               fileName[index] = uploadResource.getFileName();
-               inputName[index] = "name" + index;
+               downloadLink.add(dservice.getDownloadLink(dservice.addDownloadResource(dresource)));
+               fileName.add(uploadResource.getFileName());
+               inputName.add("name" + index);
             }
          }
 
-         uiForm.setDownloadLink(downloadLink);
-         uiForm.setFileName(fileName);
-         uiForm.setInputName(inputName);
+         for(int index = 3; index < 5; index++) {
+            UIUploadInput input = uiForm.getChildById("name" + index);
+            UploadResource[] uploadResources = input.getUploadResources();
+            for(UploadResource uploadResource : uploadResources) {
+            DownloadResource dresource =
+            new InputStreamDownloadResource(new FileInputStream(new File(uploadResource.getStoreLocation())), uploadResource.getMimeType());
+            dresource.setDownloadName(uploadResource.getFileName());
+            downloadLink.add(dservice.getDownloadLink(dservice.addDownloadResource(dresource)));
+            fileName.add(uploadResource.getFileName());
+            inputName.add("name" + index);
+            }
+        }
+         
+         uiForm.setDownloadLink(downloadLink.toArray(new String[downloadLink.size()]));
+         uiForm.setFileName(fileName.toArray(new String[fileName.size()]));
+         uiForm.setInputName(inputName.toArray(new String[inputName.size()]));
 
          event.getRequestContext().addUIComponentToUpdateByAjax(uiForm.getParent());
       }

Modified: portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/webui/UIUpload.js
===================================================================
--- portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/webui/UIUpload.js	2011-10-19 04:41:43 UTC (rev 7773)
+++ portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/webui/UIUpload.js	2011-10-19 05:02:16 UTC (rev 7774)
@@ -92,7 +92,7 @@
  * Refresh progress bar to update state of upload progress
  * @param {String} elementId identifier of upload bar frame
  */
-UIUpload.prototype.refeshProgress = function(elementId) {
+UIUpload.prototype.refreshProgress = function(elementId) {
   var list =  eXo.webui.UIUpload.listUpload;
   if(list.length < 1) return;
   var url = eXo.env.server.context + "/upload?" ;
@@ -103,7 +103,7 @@
   }
   var responseText = ajaxAsyncGetRequest(url, false);
   if(list.length > 0) {
-    setTimeout("eXo.webui.UIUpload.refeshProgress('" + elementId + "');", 1000); 
+    setTimeout("eXo.webui.UIUpload.refreshProgress('" + elementId + "');", 1000); 
   }
     
   var response;
@@ -119,6 +119,9 @@
   	if (response.upload[id].status == "failed") {
   		this.abortUpload(id);
   		var message = eXo.core.DOMUtil.findFirstChildByClass(container, "div", "LimitMessage").innerHTML ;
+  		message = message.replace("{0}", response.upload[id].size);
+  		message = message.replace("{1}", response.upload[id].unit);
+  		alert(message);
   		continue;
   	}
     var element = document.getElementById(id+"ProgressIframe");
@@ -271,7 +274,7 @@
   var list = eXo.webui.UIUpload.listUpload;
   if(list.length == 0) {
     eXo.webui.UIUpload.listUpload.push(form.id);
-    setTimeout("eXo.webui.UIUpload.refeshProgress('" + id + "');", 1000);
+    setTimeout("eXo.webui.UIUpload.refreshProgress('" + id + "');", 1000);
   } else {
     eXo.webui.UIUpload.listUpload.push(form.id);  
   }

Added: portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/webui/UIUploadInput.js
===================================================================
--- portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/webui/UIUploadInput.js	                        (rev 0)
+++ portal/trunk/web/eXoResources/src/main/webapp/javascript/eXo/webui/UIUploadInput.js	2011-10-19 05:02:16 UTC (rev 7774)
@@ -0,0 +1,249 @@
+/**
+ * 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.
+ */
+
+function UIUploadInput() {
+  this.listUpload = new Array();
+  this.refreshTime = 1000;
+  this.delayTime = 5000;
+  this.progressURL = eXo.env.server.context + "/upload?action=progress&uploadId=";
+  this.uploadURL = eXo.env.server.context + "/upload?action=upload&uploadId=" ;
+  this.abortURL = eXo.env.server.context + "/upload?action=abort&uploadId=" ;
+  this.deleteURL = eXo.env.server.context + "/upload?action=delete&uploadId=" ;
+};
+
+/**
+ * Initialize upload and create a upload request to server
+ * @param {String} uploadId identifier upload
+ * @param {boolean} isAutoUpload auto upload or none
+ */
+UIUploadInput.prototype.initUploadEntry = function(uploadId, isAutoUpload) {
+  for(var i = 0; i < uploadId.length; i++) {
+    var url = this.progressURL + uploadId[i] ;
+	var responseText = ajaxAsyncGetRequest(url, false);
+	
+	var response;
+    try {
+      eval("response = "+responseText);
+    } catch(err) {
+      return;  
+    }
+
+	  if(response.upload[uploadId[i]] == undefined || response.upload[uploadId[i]].percent == undefined) {
+		  this.createEntryUpload(uploadId[i], isAutoUpload);
+	  } else if(response.upload[uploadId[i]].percent == 100)  {
+		  this.showUploaded(uploadId[i], response.upload[uploadId[i]].fileName);
+	  } 
+  }
+};
+
+UIUploadInput.prototype.createEntryUpload = function(id, isAutoUpload) {
+  var div = document.getElementById('UploadInput' + id);
+    
+  var inputHTML = "<input id='file" +id+ "' class='file' name='file' type='file' onkeypress='return false;'";
+
+  if(isAutoUpload) {
+    inputHTML += " onchange='eXo.webui.UIUploadInput.upload(\"" +id+ "\", " +isAutoUpload+ ");' >";    
+  } else {
+    inputHTML += " >"
+  }
+  
+  div.style.display = 'block';
+  div.innerHTML = inputHTML; 
+
+	if(!isAutoUpload) {
+		var prefixId = id.substring(0, id.indexOf('-'));
+		var img = document.getElementById('IconUpload' + prefixId + '-0');
+		img.style.display = 'block';
+	}
+};
+
+UIUploadInput.prototype.displayUploadButton = function(id) {
+	var flag = true;
+	if(id instanceof Array) {
+		var img = document.getElementById('IconUpload' + id[0]);
+		for(var i = 0; i < id.length; i++) {
+			var input = document.getElementById('file' + id[i]);
+			if(input == null) flag = true;
+			else if(input.value == null || input.value == '') flag = false;
+		}
+		if(flag) img.style.display = 'none';
+	} else return;
+};
+
+UIUploadInput.prototype.showUploaded = function(id, fileName) {
+  this.listUpload.remove(id);
+  var container = parent.document.getElementById('UploadInputContainer' + id);
+  var element = document.getElementById('ProgressIframe' + id);
+  element.innerHTML =  "<span></span>";
+  
+  var UploadInput = eXo.core.DOMUtil.findDescendantById(container, 'UploadInput' + id);
+  UploadInput.style.display = "none";
+
+  var progressIframe = eXo.core.DOMUtil.findDescendantById(container, 'ProgressIframe' + id);
+  progressIframe.style.display = "none";
+    
+  var selectFileFrame = eXo.core.DOMUtil.findFirstDescendantByClass(container, "div", "SelectFileFrame") ;
+  selectFileFrame.style.display = "block" ;
+
+  var fileNameLabel = eXo.core.DOMUtil.findFirstDescendantByClass(selectFileFrame, "div", "FileNameLabel") ;
+  if(fileName != null) fileNameLabel.innerHTML = decodeURIComponent(fileName);
+
+  var progressBarFrame = eXo.core.DOMUtil.findFirstDescendantByClass(container, "div", "ProgressBarFrame") ;
+  progressBarFrame.style.display = "none" ;
+};
+
+UIUploadInput.prototype.refreshProgress = function(uploadId, isAutoUpload) {
+  var list =  this.listUpload;
+  if(list.length < 1) return;
+  var url = this.progressURL;
+
+  for(var i = 0; i < list.length; i++){
+    url = url + "&uploadId=" + list[i];
+  }
+  var responseText = ajaxAsyncGetRequest(url, false);
+  if(this.listUpload.length > 0) {
+    setTimeout("eXo.webui.UIUploadInput.refreshProgress('" +uploadId+ "', " +isAutoUpload+ ");", this.refreshTime); 
+  }
+    
+  var response;
+  try {
+    eval("response = "+responseText);
+  } catch(err) {
+    return;  
+  }
+  
+  for(id in response.upload) {
+    var container = parent.document.getElementById('UploadInputContainer' + id);
+  	if (response.upload[id].status == "failed") {
+  		this.abortUpload(id, isAutoUpload);
+  		var message = eXo.core.DOMUtil.findFirstChildByClass(container, "div", "LimitMessage").innerHTML ;
+  		message = message.replace("{0}", response.upload[id].size);
+  		message = message.replace("{1}", response.upload[id].unit);
+  		alert(message);
+  		continue;
+  	}
+    var element = document.getElementById('ProgressIframe' + id);
+    var percent = response.upload[id].percent;
+    var progressBarMiddle = eXo.core.DOMUtil.findFirstDescendantByClass(container, "div", "ProgressBarMiddle") ;
+    var blueProgressBar = eXo.core.DOMUtil.findFirstChildByClass(progressBarMiddle, "div", "BlueProgressBar") ;
+    var progressBarLabel = eXo.core.DOMUtil.findFirstChildByClass(blueProgressBar, "div", "ProgressBarLabel") ;
+    blueProgressBar.style.width = percent + "%" ;
+    progressBarLabel.innerHTML = percent + "%" ;
+    
+    if(percent == 100) {
+       this.showUploaded(id, response.upload[id].fileName);
+    }
+  }
+  
+  if(this.listUpload.length < 1) return;
+
+  if (element) {
+    element.innerHTML = "Uploaded "+ percent + "% " +
+                        "<span onclick='parent.eXo.webui.UIUploadInput.abortUpload("+uploadId+", "+isAutoUpload+")'>Abort</span>";
+  }
+};
+
+UIUploadInput.prototype.deleteUpload = function(id, isAutoUpload) {
+  var url = this.deleteURL + id;
+  var request =  eXo.core.Browser.createHttpRequest();
+  request.open('GET', url, false);
+  request.setRequestHeader("Cache-Control", "max-age=86400");
+  request.send(null);
+
+  var container = parent.document.getElementById('UploadInputContainer' + id);
+  var selectFileFrame = eXo.core.DOMUtil.findFirstDescendantByClass(container, "div", "SelectFileFrame") ;
+  selectFileFrame.style.display = "none" ;
+
+  this.createEntryUpload(id, isAutoUpload);
+};
+
+UIUploadInput.prototype.abortUpload = function(id, isAutoUpload) {
+  this.listUpload.remove(id);
+  var url = this.abortURL + id;
+  var request =  eXo.core.Browser.createHttpRequest();
+  request.open('GET', url, false);
+  request.setRequestHeader("Cache-Control", "max-age=86400");
+  request.send(null);
+  
+  var container = parent.document.getElementById('UploadInputContainer' + id);
+  var progressIframe = eXo.core.DOMUtil.findDescendantById(container, 'ProgressIframe' + id);
+  progressIframe.style.display = "none";
+
+  var progressBarFrame = eXo.core.DOMUtil.findFirstDescendantByClass(container, "div", "ProgressBarFrame") ;
+  progressBarFrame.style.display = "none" ;
+
+  this.createEntryUpload(id, isAutoUpload);
+};
+
+/**
+ * Start upload file
+ * @param {Object} clickEle
+ * @param {String} id
+ */
+
+UIUploadInput.prototype.doUpload = function(id, isAutoUpload) {
+  var DOMUtil = eXo.core.DOMUtil;  
+  var container = parent.document.getElementById('UploadInputContainer' + id);  
+  this.displayUploadButton(id);
+  if(id instanceof Array) {
+    for(var i = 0; i < id.length; i++) {
+      this.doUpload(id[i], isAutoUpload);    
+    }
+  } else {
+    var file = document.getElementById('file' + id);
+    if (file == null || file == undefined) return;
+    if (file.value == null || file.value == '') return;
+    var temp = file.value;
+
+    var progressBarFrame = DOMUtil.findFirstDescendantByClass(container, "div", "ProgressBarFrame");
+    progressBarFrame.style.display = "block";
+  
+    var progressBarMiddle = DOMUtil.findFirstDescendantByClass(container, "div", "ProgressBarMiddle");
+    var blueProgressBar = DOMUtil.findFirstChildByClass(progressBarMiddle, "div", "BlueProgressBar");
+    var progressBarLabel = DOMUtil.findFirstChildByClass(blueProgressBar, "div", "ProgressBarLabel");
+    blueProgressBar.style.width = "0%";
+    progressBarLabel.innerHTML = "0%";
+  
+    var uploadAction = this.uploadURL + id; 
+    var formHTML = "<form id='form" +id+ "' class='UIUploadForm' style='margin: 0px; padding: 0px' action='" 
+		+ uploadAction + "' enctype='multipart/form-data' target='UploadIFrame" + id + "' method='post'></form>";   
+    var div = document.createElement("div");
+    div.innerHTML = formHTML;
+    var form = div.firstChild;      
+    
+    form.appendChild(file);
+    document.body.appendChild(div);
+    form.submit();
+    document.body.removeChild(div);
+    
+    if(this.listUpload.length == 0) {
+      this.listUpload.push(id);
+      setTimeout("eXo.webui.UIUploadInput.refreshProgress('" + id + "', " + isAutoUpload + ");", this.refreshTime);
+    } else {
+      this.listUpload.push(id);
+    }
+  }
+};
+
+UIUploadInput.prototype.upload = function(id, isAutoUpload) {
+  if(isAutoUpload) setTimeout("eXo.webui.UIUploadInput.doUpload('" + id + "', " + isAutoUpload + ")", this.delayTime);  
+  else this.doUpload(id, isAutoUpload);
+};
+
+eXo.webui.UIUploadInput = new UIUploadInput();

Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_cs.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_cs.properties	2011-10-19 04:41:43 UTC (rev 7773)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_cs.properties	2011-10-19 05:02:16 UTC (rev 7774)
@@ -446,7 +446,7 @@
 UIFormUploadInput.label.Cancel=Zru\u0161it
 UIFormUploadInput.label.Uploaded=Nahr\u00E1no
 UIFormUploadInput.label.remove=Odstranit nahran\u00E9
-UIFormUploadInput.msg.limit=Soubor mus\u00ED b\u00FDt men\u0161\u00ED ne\u017E {0} MB.
+UIFormUploadInput.msg.limit=Soubor mus\u00ED b\u00FDt men\u0161\u00ED ne\u017E {0} {1}.
 
 UIGadget.tooltip.Maximize=Maximalizovat
 UIGadget.tooltip.Minimize=Minimalizovat
@@ -1526,7 +1526,7 @@
 UIFormUploadInput.label.Cancel=Zru\u0161it
 UIFormUploadInput.label.Uploaded=Nahr\u00e1no
 UIFormUploadInput.label.remove=Odstranit nahran\u00e9
-UIFormUploadInput.msg.limit=Soubor mus\u00ed b\u00fdt men\u0161\u00ed ne\u017e {0} MB.
+UIFormUploadInput.msg.limit=Soubor mus\u00ed b\u00fdt men\u0161\u00ed ne\u017e {0} {1}.
 
 UIGadget.tooltip.Maximize=Maximalizovat
 UIGadget.tooltip.Minimize=Minimalizovat

Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_de.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_de.properties	2011-10-19 04:41:43 UTC (rev 7773)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_de.properties	2011-10-19 05:02:16 UTC (rev 7774)
@@ -989,7 +989,7 @@
 UIFormUploadInput.label.Uploaded=Hochgeladen
 UIFormUploadInput.label.remove=L\u00f6schen
 UIFormUploadInput.label.Cancel=#{word.cancel}
-UIFormUploadInput.msg.limit=Die Datei muss weniger als {0} MB gro\u00df sein.
+UIFormUploadInput.msg.limit=Die Datei muss weniger als {0} {1} gro\u00df sein.
 
   ###############################################################################
   #  org.exoplatform.portal.webui.component.customization.UIPageNodeSelector    #

Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_en.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_en.properties	2011-10-19 04:41:43 UTC (rev 7773)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_en.properties	2011-10-19 05:02:16 UTC (rev 7774)
@@ -1080,7 +1080,7 @@
 UIFormUploadInput.label.Uploaded=Uploaded
 UIFormUploadInput.label.remove=Remove Uploaded
 UIFormUploadInput.label.Cancel=Cancel
-UIFormUploadInput.msg.limit=The file must be less than {0} MB.
+UIFormUploadInput.msg.limit=The file must be less than {0} {1}.
 
   ###############################################################################
   #  org.exoplatform.portal.webui.component.customization.UIPageNodeSelector    #

Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_es.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_es.properties	2011-10-19 04:41:43 UTC (rev 7773)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_es.properties	2011-10-19 05:02:16 UTC (rev 7774)
@@ -966,7 +966,7 @@
 UIFormUploadInput.label.Uploaded=Subida
 UIFormUploadInput.label.remove=Elinimar Subida
 UIFormUploadInput.label.Cancel=Cancelar
-UIFormUploadInput.msg.limit=El tama\u00f1o del fichero debe ser inferior a {0} MB.
+UIFormUploadInput.msg.limit=El tama\u00f1o del fichero debe ser inferior a {0} {1}.
 
   ###############################################################################
   #  org.exoplatform.portal.webui.component.customization.UIPageNodeSelector    #

Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_fr.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_fr.properties	2011-10-19 04:41:43 UTC (rev 7773)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_fr.properties	2011-10-19 05:02:16 UTC (rev 7774)
@@ -985,7 +985,7 @@
 UIFormUploadInput.label.Uploaded=Envoyé
 UIFormUploadInput.label.remove=Supprimer
 UIFormUploadInput.label.Cancel=#{word.cancel}
-UIFormUploadInput.msg.limit=Le fichier doit faire moins de {0} MB.
+UIFormUploadInput.msg.limit=Le fichier doit faire moins de {0} {1}.
 
 
   ###############################################################################

Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_it.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_it.properties	2011-10-19 04:41:43 UTC (rev 7773)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_it.properties	2011-10-19 05:02:16 UTC (rev 7774)
@@ -1028,7 +1028,7 @@
 UIFormUploadInput.label.Uploaded=Aggiornato
 UIFormUploadInput.label.remove=Rimuovi l'Aggiornamento
 UIFormUploadInput.label.Cancel=Annulla
-UIFormUploadInput.msg.limit=Il file deve essere minore di {0} MB.
+UIFormUploadInput.msg.limit=Il file deve essere minore di {0} {1}.
 
   ###############################################################################
   #  org.exoplatform.portal.webui.component.customization.UIPageNodeSelector    #

Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ja.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ja.properties	2011-10-19 04:41:43 UTC (rev 7773)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ja.properties	2011-10-19 05:02:16 UTC (rev 7774)
@@ -994,7 +994,7 @@
 UIFormUploadInput.label.Uploaded=\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9
 UIFormUploadInput.label.remove=\u30a2\u30c3\u30d7\u30ed\u30fc\u30c9\u3092\u9664\u53bb
 UIFormUploadInput.label.Cancel=\u30ad\u30e3\u30f3\u30bb\u30eb
-UIFormUploadInput.msg.limit=\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u306f {0} MB\u4ee5\u4e0b\u3067\u3042\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
+UIFormUploadInput.msg.limit=\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u306f {0} {1}\u4ee5\u4e0b\u3067\u3042\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002
 
   ###############################################################################
   #  org.exoplatform.portal.webui.component.customization.UIPageNodeSelector    #

Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ne.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ne.properties	2011-10-19 04:41:43 UTC (rev 7773)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ne.properties	2011-10-19 05:02:16 UTC (rev 7774)
@@ -992,7 +992,7 @@
 UIFormUploadInput.label.Uploaded=\u0905\u092a\u094d\u0932\u094b\u0921 \u0917\u0930\u0947\u0915\u094b
 UIFormUploadInput.label.remove=\u0905\u092a\u094d\u0932\u094b\u0921 \u0917\u0930\u0947\u0915\u094b \u0939\u091f\u093e\u0909\u0928\u0941\u0939\u094b\u0938\u094d 
 UIFormUploadInput.label.Cancel=\u0930\u0926\u094d\u0926 \u0917\u0930\u094d\u0928\u0941\u0939\u094b\u0938\u094d 
-UIFormUploadInput.msg.limit=\u092b\u093e\u0907\u0932 {0} MB \u092d\u0928\u094d\u0926\u093e \u0938\u093e\u0928\u094b \u0939\u0941\u0928\u0941\u092a\u0930\u094d\u091b\u0964 
+UIFormUploadInput.msg.limit=\u092b\u093e\u0907\u0932 {0} {1} \u092d\u0928\u094d\u0926\u093e \u0938\u093e\u0928\u094b \u0939\u0941\u0928\u0941\u092a\u0930\u094d\u091b\u0964 
 
   ###############################################################################
   #  org.exoplatform.portal.webui.component.customization.UIPageNodeSelector    #

Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_nl.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_nl.properties	2011-10-19 04:41:43 UTC (rev 7773)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_nl.properties	2011-10-19 05:02:16 UTC (rev 7774)
@@ -967,7 +967,7 @@
 UIFormUploadInput.label.Uploaded=Ge\u00FCpload
 UIFormUploadInput.label.remove=#{word.remove}
 UIFormUploadInput.label.Cancel=#{word.cancel}
-UIFormUploadInput.msg.limit=Het bestand moet kleiner zijn dan {0} MB.
+UIFormUploadInput.msg.limit=Het bestand moet kleiner zijn dan {0} {1}.
 
 ###############################################################################
 #  org.exoplatform.portal.webui.component.customization.UIPageNodeSelector    #

Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_pt_BR.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_pt_BR.properties	2011-10-19 04:41:43 UTC (rev 7773)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_pt_BR.properties	2011-10-19 05:02:16 UTC (rev 7774)
@@ -986,7 +986,7 @@
 UIFormUploadInput.label.Uploaded=Enviado
 UIFormUploadInput.label.remove=Remover Arquivo
 UIFormUploadInput.label.Cancel=Cancelar
-UIFormUploadInput.msg.limit=Arquivo deve possuir menos de {0} MB.
+UIFormUploadInput.msg.limit=Arquivo deve possuir menos de {0} {1}.
 
   ###############################################################################
   #  org.exoplatform.portal.webui.component.customization.UIPageNodeSelector    #

Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ru.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ru.properties	2011-10-19 04:41:43 UTC (rev 7773)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_ru.properties	2011-10-19 05:02:16 UTC (rev 7774)
@@ -951,7 +951,7 @@
 UIFormUploadInput.label.Uploaded=Загружено
 UIFormUploadInput.label.remove=Удалить загрузки
 UIFormUploadInput.label.Cancel=Отменить
-UIFormUploadInput.msg.limit=Максимальный размер файла {0} MiB.
+UIFormUploadInput.msg.limit=Максимальный размер файла {0} {1}.
 
 
   ###############################################################################

Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_uk.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_uk.properties	2011-10-19 04:41:43 UTC (rev 7773)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_uk.properties	2011-10-19 05:02:16 UTC (rev 7774)
@@ -942,7 +942,7 @@
 UIFormUploadInput.label.Uploaded=Завантажено
 UIFormUploadInput.label.remove=Вилучити завантажене
 UIFormUploadInput.label.Cancel=Скасувати
-UIFormUploadInput.msg.limit=Файл повинен бути меншим, ніж {0} MB.
+UIFormUploadInput.msg.limit=Файл повинен бути меншим, ніж {0} {1}.
 
 
   ###############################################################################

Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_vi.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_vi.properties	2011-10-19 04:41:43 UTC (rev 7773)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_vi.properties	2011-10-19 05:02:16 UTC (rev 7774)
@@ -1020,7 +1020,7 @@
 UIFormUploadInput.label.Uploaded=Tải tệp tin
 UIFormUploadInput.label.remove=Xóa tệp tin đã tải
 UIFormUploadInput.label.Cancel=Loại bỏ
-UIFormUploadInput.msg.limit=Dung lượng tệp tin không được lớn hơn {0} MB.
+UIFormUploadInput.msg.limit=Dung lượng tệp tin không được lớn hơn {0} {1}.
 
   ###############################################################################
   #  org.exoplatform.portal.webui.component.customization.UIPageNodeSelector    #

Added: portal/trunk/web/portal/src/main/webapp/groovy/webui/form/UIUploadInput.gtmpl
===================================================================
--- portal/trunk/web/portal/src/main/webapp/groovy/webui/form/UIUploadInput.gtmpl	                        (rev 0)
+++ portal/trunk/web/portal/src/main/webapp/groovy/webui/form/UIUploadInput.gtmpl	2011-10-19 05:02:16 UTC (rev 7774)
@@ -0,0 +1,53 @@
+<%
+	String[] uploadId = uicomponent.getUploadId();
+	boolean isAutoUpload = uicomponent.isAutoUpload();
+	int limitFile = uicomponent.getLimitFile();
+	def rcontext = _ctx.getRequestContext();
+	rcontext.getJavascriptManager().importJavascript('eXo.webui.UIUploadInput');
+	StringBuilder b = new StringBuilder();
+	b.append("[") ;
+	for(int i = 0; i < uploadId.length; i++) {
+		b.append("\'").append(uploadId[i]).append("\'") ;
+		if(i < uploadId.length - 1) b.append(",");
+	}
+	b.append("]");
+	rcontext.getJavascriptManager().addCustomizedOnLoadScript("eXo.webui.UIUploadInput.initUploadEntry("+b.toString()+","+isAutoUpload+");");
+%>
+<%for(int i = 0; i < uploadId.length; i++) {%>
+<div class="UIUploadInput" id="UploadInputContainer<%=uploadId[i];%>">
+	<div class="LimitMessage" style="display: none;"><%= _ctx.appRes("UIFormUploadInput.msg.limit"); %></div>
+	<div id="UploadInput<%=uploadId[i];%>" class="UploadInput">		
+	</div>
+	<div id="ProgressIframe<%=uploadId[i];%>" class="ProgressIframe" style="display: none;"></div>			
+	<div class="ProgressBarFrame" style="display: none;">
+		<div class="ProgressBar">
+			<div class="ProgressBarLeft">
+				<div class="ProgressBarMiddle">
+					<div class="BlueProgressBar">
+						<div class="ProgressBarLabel">0%</div>
+					</div>
+				</div>
+			</div>
+		</div>
+		<div class="DeleteFileFrame">
+			<div class="DeleteFileLable" onclick="eXo.webui.UIUploadInput.abortUpload('<%=uploadId[i];%>', <%=isAutoUpload;%>);"><%=_ctx.appRes("UIFormUploadInput.label.Cancel")%></div>
+		</div>
+	</div>
+	<div class="SelectFileFrame" style="display: none;">
+		<div class="FileName">
+			<div class="FileNameLabel"><span></span></div>
+		</div>
+		<div class="RemoveFile" title="<%= _ctx.appRes("UIFormUploadInput.label.remove"); %>" onclick="eXo.webui.UIUploadInput.deleteUpload('<%=uploadId[i];%>', <%=isAutoUpload;%>);"></div>
+	</div>
+	<iframe height="0" width="0" name="UploadIFrame<%=uploadId[i];%>" id="UploadIFrame<%=uploadId[i];%>" style="display: none;">
+		<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
+		<html xmlns='http://www.w3.org/1999/xhtml'>
+			<head></head>
+			<body></body>
+		</html>
+	</iframe>
+</div>
+<%}%>
+<%if(!isAutoUpload) {%>
+<img id="IconUpload<%=uploadId[0]%>" class="UploadButton" style="width : 20px; height: 20px; float: left; cursor: pointer; vertical-align: bottom; background: url('/eXoResources/skin/DefaultSkin/webui/component/UIUpload/background/UpArrow16x16.gif') no-repeat left;" onclick="eXo.webui.UIUploadInput.upload(<%=b.toString();%>, <%=isAutoUpload;%>)" alt='' src='/eXoResources/skin/sharedImages/Blank.gif'/>
+<%}%>

Added: portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/input/UIUploadInput.java
===================================================================
--- portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/input/UIUploadInput.java	                        (rev 0)
+++ portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/input/UIUploadInput.java	2011-10-19 05:02:16 UTC (rev 7774)
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2003-2011 eXo Platform SAS.
+ *
+ * This program 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 3
+ * of the License, or (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see<http://www.gnu.org/licenses/>.
+ */
+package org.exoplatform.webui.form.input;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.exoplatform.upload.UploadResource;
+import org.exoplatform.upload.UploadService;
+import org.exoplatform.upload.UploadService.UploadUnit;
+import org.exoplatform.webui.application.WebuiRequestContext;
+import org.exoplatform.webui.config.annotation.ComponentConfig;
+import org.exoplatform.webui.form.UIFormInputBase;
+
+
+
+/**
+ * @author <a href="mailto:haint at exoplatform.com">Nguyen Thanh Hai</a>
+ *
+ * @datJul 19, 2011
+ */
+
+ at ComponentConfig(template = "system:/groovy/webui/form/UIUploadInput.gtmpl")
+public class UIUploadInput extends UIFormInputBase<String>
+{
+   private String[] uploadId;
+   
+   private boolean isAutoUpload = true;
+   
+   private int limitFile = 1;
+   
+   public UIUploadInput(String name, String bindingExpression, int limitFile)
+   {
+      super(name, bindingExpression, String.class);
+      if(limitFile > 1) this.limitFile = limitFile ;
+      uploadId = new String[this.limitFile] ;
+      for(int i = 0; i < uploadId.length; i++) 
+      {
+         uploadId[i] = new StringBuffer().append(Math.abs(hashCode())).append('-').append(i).toString();
+      }
+      UploadService service = getApplicationComponent(UploadService.class);
+      for(int i = 0; i < uploadId.length; i++)
+      {
+         service.addUploadLimit(uploadId[i], null); // Use the limit set by the service. Warning, the service can allow no size limit (value to 0)
+      }
+      setComponentConfig(UIUploadInput.class, null);
+   }
+
+   public UIUploadInput(String name, String bindingExpression,int limitFile, int limitSize)
+   {
+      this(name, bindingExpression, limitFile, limitSize, UploadUnit.MB);
+   }
+   
+   public UIUploadInput(String name, String bindingExpression, int limitFile, int limitSize, UploadUnit unit)
+   {
+      super(name, bindingExpression, String.class);
+      if(limitFile > 1) this.limitFile = limitFile ;
+      uploadId = new String[this.limitFile] ;
+      for(int i = 0; i < uploadId.length; i++) 
+      {
+         uploadId[i] = new StringBuffer().append(Math.abs(hashCode())).append('-').append(i).toString();
+      }
+      UploadService service = getApplicationComponent(UploadService.class);
+      for(int i = 0; i < uploadId.length; i++)
+      {
+         service.addUploadLimit(uploadId[i], Integer.valueOf(limitSize), unit);
+      }
+      setComponentConfig(UIUploadInput.class, null);
+   }
+   
+   public String[] getUploadId()
+   {
+      return uploadId;
+   }
+   
+   public void setAutoUpload(boolean isAutoUpload)
+   {
+      this.isAutoUpload = isAutoUpload;
+   }
+   
+   public boolean isAutoUpload()
+   {
+      return isAutoUpload;
+   }
+   
+   public int getLimitFile() 
+   {
+      return limitFile;
+   }
+   
+   public UploadResource[] getUploadResources() {
+      List<UploadResource> holder = new ArrayList<UploadResource>();
+      UploadService service = getApplicationComponent(UploadService.class);
+      for(int i = 0; i < uploadId.length; i++)
+      {
+         UploadResource uploadResource = service.getUploadResource(uploadId[i]);
+         if(uploadResource == null) continue;
+         holder.add(uploadResource) ;
+      }
+      return holder.toArray(new UploadResource[holder.size()]);
+   }
+   
+   public UploadResource getUploadResource(String uploadId) {
+      UploadService service = getApplicationComponent(UploadService.class);
+      return service.getUploadResource(uploadId);
+   }
+   
+   public InputStream[] getUploadDataAsStreams() throws FileNotFoundException 
+   {
+      List<InputStream> holder = new ArrayList<InputStream>();
+      UploadService service = getApplicationComponent(UploadService.class);
+      for(int i = 0; i < uploadId.length; i++)
+      {
+         UploadResource uploadResource = service.getUploadResource(uploadId[i]);
+         if(uploadResource == null) continue;
+         File file = new File(uploadResource.getStoreLocation());
+         holder.add(new FileInputStream(file));
+      }
+      return holder.toArray(new InputStream[holder.size()]);
+   }
+   
+   public InputStream getUploadDataAsStream(String uploadId) throws FileNotFoundException
+   {
+      UploadService service = getApplicationComponent(UploadService.class);
+      UploadResource uploadResource = service.getUploadResource(uploadId);
+      if(uploadResource == null) return null;
+      else return new FileInputStream(new File(uploadResource.getStoreLocation()));
+   }
+
+   public void decode(Object input, WebuiRequestContext context) throws Exception
+   {
+   }
+}



More information about the gatein-commits mailing list