[richfaces-svn-commits] JBoss Rich Faces SVN: r5747 - in trunk/sandbox/ui/fileUpload: src/main/config/component and 8 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Jan 31 09:18:58 EST 2008


Author: andrei_exadel
Date: 2008-01-31 09:18:58 -0500 (Thu, 31 Jan 2008)
New Revision: 5747

Added:
   trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/FileItem.java
   trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/bg_ProgressBar_perm.gif
   trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/bg_header.png
   trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/bg_press.png
   trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/ico_add.gif
   trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/ico_clear.gif
   trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/ico_start.gif
   trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/ico_stop.gif
   trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/
   trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js
   trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload2.jspx
   trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload3.jspx
Removed:
   trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/bg_button.png
   trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/bg_uploaded.png
   trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/ico_delete.gif
Modified:
   trunk/sandbox/ui/fileUpload/pom.xml
   trunk/sandbox/ui/fileUpload/src/main/config/component/fileUpload.xml
   trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/UIFileUpload.java
   trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/renderkit/FileUploadRendererBase.java
   trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartFilter.java
   trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartRequest.java
   trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/css/fileUpload.xcss
   trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx
Log:
Upload file initial version

Modified: trunk/sandbox/ui/fileUpload/pom.xml
===================================================================
--- trunk/sandbox/ui/fileUpload/pom.xml	2008-01-31 13:11:16 UTC (rev 5746)
+++ trunk/sandbox/ui/fileUpload/pom.xml	2008-01-31 14:18:58 UTC (rev 5747)
@@ -1,11 +1,11 @@
-<?xml version="1.0"?><project>
+<?xml version="1.0" encoding="UTF-8"?><project>
   <parent>
     <artifactId>ui</artifactId>
     <groupId>org.richfaces.sandbox</groupId>
     <version>3.2.0-SNAPSHOT</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>
-  <groupId>org.richfaces.ui</groupId>
+  <groupId>org.richfaces.sandbox.ui</groupId>
   <artifactId>fileUpload</artifactId>
   <name>fileUpload</name>
   <version>3.2.0-SNAPSHOT</version>
@@ -23,7 +23,7 @@
             </goals>
           </execution>
           <execution>
-		<id>generate-test-sources</id>
+            <id>generate-test-sources</id>
             <phase>generate-test-sources</phase>
             <goals>
               <goal>generate-tests</goal>
@@ -53,5 +53,10 @@
       <artifactId>richfaces-impl</artifactId>
       <version>3.2.0-SNAPSHOT</version>
     </dependency>
-  </dependencies>
+	 <dependency>
+      <groupId>org.richfaces.sandbox.ui</groupId>
+      <artifactId>progressBar</artifactId>
+      <version>3.2.0-SNAPSHOT</version>
+    </dependency>
+   </dependencies>
 </project>
\ No newline at end of file

Modified: trunk/sandbox/ui/fileUpload/src/main/config/component/fileUpload.xml
===================================================================
--- trunk/sandbox/ui/fileUpload/src/main/config/component/fileUpload.xml	2008-01-31 13:11:16 UTC (rev 5746)
+++ trunk/sandbox/ui/fileUpload/src/main/config/component/fileUpload.xml	2008-01-31 14:18:58 UTC (rev 5747)
@@ -7,7 +7,8 @@
 		<classname>org.richfaces.component.html.HtmlFileUpload</classname>
 		<superclass>org.richfaces.org.jboss.seam.ui.component.UIFileUpload</superclass>
 		<description>
-			<![CDATA[Renders a file upload control. This control must be used within a form with an encoding type of multipart/form-data, i.e:
+			<![CDATA[
+Renders a file upload control. This control must be used within a form with an encoding type of multipart/form-data, i.e:
 
 <h:form enctype="multipart/form-data">
                                     
@@ -33,7 +34,8 @@
 <component class="org.jboss.seam.servlet.MultipartConfig">
     <property name="createTempFiles">true</property>
     <property name="maxRequestSize">1000000</property>
-</component>]]>
+</component>
+]]>
 		</description>
 		<test>
 			<classname>org.richfaces.component.html.HtmlFileUploadComponentTestCase</classname>
@@ -41,7 +43,7 @@
 		</test>
 		<renderer generate="true" override="true">
 			<name>org.richfaces.renderkit.html.FileUploadRenderer</name> 
-			<template>org/richfaces/fileUpload.jspx</template>
+			<template>org/richfaces/fileUpload3.jspx</template>
 		</renderer>
 		<tag>
 			<name>fileUpload</name>

Added: trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/FileItem.java
===================================================================
--- trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/FileItem.java	                        (rev 0)
+++ trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/FileItem.java	2008-01-31 14:18:58 UTC (rev 5747)
@@ -0,0 +1,116 @@
+/*
+ * FileItem.java		Date created: 03.01.2008
+ * Last modified by: $Author$
+ * $Revision$	$Date$
+ */
+
+package org.richfaces.org.jboss.seam.ui.component;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * Class provides an entity for file item in file upload list   
+ * @author "Andrey Markavtsov"
+ *
+ */
+public class FileItem {
+    
+    /** Defines list of statuses available */
+    public static enum Status {ADDED, MARKED_4_UPLOAD, IN_PROGRESS, UPLOADED};
+    
+    /** Pattern to search file name in full file name string */
+    private static final Pattern pattern = Pattern.compile
+				(".*\\\\+(.*)");
+    
+    /** Current status */
+    private Status status;
+    
+    /** File name */
+    private String fileName;
+    
+    /** File size */
+    private Integer fileSize;
+    
+
+    /**
+     * TODO Description goes here.
+     */
+    public FileItem() {
+	super();
+	// TODO Auto-generated constructor stub
+    }
+    
+  
+
+    /**
+     * TODO Description goes here.
+     * @param fileName
+     */
+    public FileItem(String fileName) {
+	super();
+	this.fileName = fileName;
+	this.status = Status.ADDED;
+    }
+
+    /**
+     * @return the fileName
+     */
+    public String getFileName() {
+	Matcher matcher = pattern.matcher(fileName);
+	if (matcher.matches()) {
+	    return matcher.group(1);
+	}
+        return fileName;
+    }
+    
+    /**
+     * @return the fileName
+     */
+    public String getFullFileName() {
+        return fileName;
+    }
+
+
+    /**
+     * @param fileName the fileName to set
+     */
+    public void setFileName(String fileName) {
+        this.fileName = fileName;
+    }
+
+    /**
+     * @return the fileSize
+     */
+    public Integer getFileSize() {
+        return (Integer)fileSize/1000;
+    }
+
+    /**
+     * @param fileSize the fileSize to set
+     */
+    public void setFileSize(Integer fileSize) {
+        this.fileSize = fileSize;
+    }
+
+
+
+    /**
+     * @return the status
+     */
+    public Status getStatus() {
+        return status;
+    }
+
+
+
+    /**
+     * @param status the status to set
+     */
+    public void setStatus(Status status) {
+        this.status = status;
+    }
+    
+    
+
+}

Modified: trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/UIFileUpload.java
===================================================================
--- trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/UIFileUpload.java	2008-01-31 13:11:16 UTC (rev 5746)
+++ trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/component/UIFileUpload.java	2008-01-31 14:18:58 UTC (rev 5747)
@@ -3,142 +3,223 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
 
-
 import javax.el.ValueExpression;
+import javax.faces.component.UIComponent;
 import javax.faces.component.UIInput;
 import javax.faces.context.FacesContext;
 
+import org.richfaces.component.UIProgressBar;
+
 /**
  * JSF component class
  * 
  */
-public abstract class UIFileUpload extends UIInput
-{
+public abstract class UIFileUpload extends UIInput {
+    
+    public static final String READY = "ready";
+    
+    public static final String UPLOADING = "uploading";
+    
+    private String uploadStatus = READY;
 
-   private String localContentType;
+    private String localContentType;
 
-   private String localFileName;
+    private String localFileName;
 
-   private Integer localFileSize;
+    private Integer localFileSize;
 
-   private InputStream localInputStream;
+    private InputStream localInputStream;
 
-   @Override
-   public void processUpdates(FacesContext context)
-   {
-      ValueExpression dataBinding = getValueExpression("data");
-      if (dataBinding != null)
-      {
-         Class clazz = dataBinding.getType(context.getELContext());
-         if (clazz.isAssignableFrom(InputStream.class))
-         {
-            dataBinding.setValue(context.getELContext(), getLocalInputStream());
-         }
-         else if (clazz.isAssignableFrom(byte[].class))
-         {
-            byte[] bytes = null;
-            if (getLocalInputStream() != null)
-            {
-               ByteArrayOutputStream bos = new ByteArrayOutputStream();
-               try
-               {                  
-                  byte[] buffer = new byte[512];
-                  int read = getLocalInputStream().read(buffer);
-                  while (read != -1)
-                  {
-                     bos.write(buffer, 0, read);
-                     read = getLocalInputStream().read(buffer);
-                  }
-                  bytes = bos.toByteArray();              
-               }
-               catch (IOException e)
-               {
-                  throw new RuntimeException(e);
-               }
-            }
-            dataBinding.setValue(context.getELContext(), bytes);
-         }
-         
-         if (getLocalContentType() != null)
-         {
-            ValueExpression valueExpression = getValueExpression("contentType");
-            if (valueExpression != null) 
-            {
-               valueExpression.setValue(context.getELContext(), getLocalContentType());
-            }
-         }
+    private List<FileItem> fileItems;
+    
+    private UIComponent progressBar;
+    
+    
+    @Override
+    public void processUpdates(FacesContext context) {
+	ValueExpression dataBinding = getValueExpression("data");
+	if (dataBinding != null) {
+	    Class clazz = dataBinding.getType(context.getELContext());
+	    if (clazz.isAssignableFrom(InputStream.class)) {
+		dataBinding.setValue(context.getELContext(),
+			getLocalInputStream());
+	    } else if (clazz.isAssignableFrom(byte[].class)) {
+		byte[] bytes = null;
+		if (getLocalInputStream() != null) {
+		    ByteArrayOutputStream bos = new ByteArrayOutputStream();
+		    try {
+			byte[] buffer = new byte[512];
+			int read = getLocalInputStream().read(buffer);
+			while (read != -1) {
+			    bos.write(buffer, 0, read);
+			    read = getLocalInputStream().read(buffer);
+			}
+			bytes = bos.toByteArray();
+		    } catch (IOException e) {
+			throw new RuntimeException(e);
+		    }
+		}
+		dataBinding.setValue(context.getELContext(), bytes);
+	    }
 
-         if (getLocalFileName() != null)
-         {
-            ValueExpression valueExpression = getValueExpression("fileName");
-            if (valueExpression != null)
-            {
-               valueExpression.setValue(context.getELContext(), getLocalFileName());
-            }
-         }
+	    if (getLocalContentType() != null) {
+		ValueExpression valueExpression = getValueExpression("contentType");
+		if (valueExpression != null) {
+		    valueExpression.setValue(context.getELContext(),
+			    getLocalContentType());
+		}
+	    }
 
-         if (getLocalFileSize() != null)
-         {
-            ValueExpression valueExpression = getValueExpression("fileSize");
-            if (valueExpression != null)
-            {
-               valueExpression.setValue(context.getELContext(), getLocalFileSize());
-            }
-         }
-      }    
-   }
+	    if (getLocalFileName() != null) {
+		ValueExpression valueExpression = getValueExpression("fileName");
+		if (valueExpression != null) {
+		    valueExpression.setValue(context.getELContext(),
+			    getLocalFileName());
+		}
+	    }
 
-   public String getLocalContentType()
-   {
-      return localContentType;
-   }
+	    if (getLocalFileSize() != null) {
+		ValueExpression valueExpression = getValueExpression("fileSize");
+		if (valueExpression != null) {
+		    valueExpression.setValue(context.getELContext(),
+			    getLocalFileSize());
+		}
+	    }
+	}
+    }
 
-   public void setLocalContentType(String localContentType)
-   {
-      this.localContentType = localContentType;
-   }
+    public String getLocalContentType() {
+	return localContentType;
+    }
 
-   public String getLocalFileName()
-   {
-      return localFileName;
-   }
+    public void setLocalContentType(String localContentType) {
+	this.localContentType = localContentType;
+    }
 
-   public void setLocalFileName(String localFileName)
-   {
-      this.localFileName = localFileName;
-   }
+    public String getLocalFileName() {
+	return localFileName;
+    }
 
-   public Integer getLocalFileSize()
-   {
-      return localFileSize;
-   }
+    public void setLocalFileName(String localFileName) {
+	this.localFileName = localFileName;
+    }
 
-   public void setLocalFileSize(Integer localFileSize)
-   {
-      this.localFileSize = localFileSize;
-   }
+    public Integer getLocalFileSize() {
+	return localFileSize;
+    }
 
-   public InputStream getLocalInputStream()
-   {
-      return localInputStream;
-   }
+    public void setLocalFileSize(Integer localFileSize) {
+	this.localFileSize = localFileSize;
+    }
 
-   public void setLocalInputStream(InputStream localInputStream)
-   {
-      this.localInputStream = localInputStream;
-   }
-   
-   public abstract void setAccept(String accept);
-   
-   public abstract String getAccept();
-   
-   public abstract String getStyleClass();
+    public InputStream getLocalInputStream() {
+	return localInputStream;
+    }
 
-   public abstract String getStyle();
+    public void setLocalInputStream(InputStream localInputStream) {
+	this.localInputStream = localInputStream;
+    }
+
+    public abstract void setAccept(String accept);
+
+    public abstract String getAccept();
+
+    public abstract String getStyleClass();
+
+    public abstract String getStyle();
+
+    public abstract void setStyleClass(String styleClass);
+
+    public abstract void setStyle(String style);
+
+    /**
+     * @return the fileItems
+     */
+    public List<FileItem> getFileItems() {
+	if (fileItems == null) {
+	    fileItems = new ArrayList<FileItem>();
+	}
+	return fileItems;
+    }
+
    
-   public abstract void setStyleClass(String styleClass);
-   
-   public abstract void setStyle(String style);
 
+    /**
+     * @return the uploadStatus
+     */
+    public String getUploadStatus() {
+        return uploadStatus;
+    }
+
+    /**
+     * @param uploadStatus the uploadStatus to set
+     */
+    public void setUploadStatus(String uploadStatus) {
+        this.uploadStatus = uploadStatus;
+    }
+
+    /**
+     * @param fileItems
+     *                the fileItems to set
+     */
+    public void setFileItems(List<FileItem> fileItems) {
+	this.fileItems = fileItems;
+    }
+    
+    
+
+    private Object[] values;
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.faces.component.UIInput#saveState(javax.faces.context.FacesContext)
+     */
+    @Override
+    public Object saveState(FacesContext context) {
+	if (values == null) {
+	    values = new Object[4];
+	}
+	values[0] = super.saveState(context);
+	values[1] = fileItems;
+	values[2] = uploadStatus;
+	values[3] = progressBar;
+	return values;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see javax.faces.component.UIInput#restoreState(javax.faces.context.FacesContext,
+     *      java.lang.Object)
+     */
+    @Override
+    public void restoreState(FacesContext context, Object state) {
+	values = (Object[]) state;
+	super.restoreState(context, values[0]);
+	fileItems = (List<FileItem>) values[1];
+	uploadStatus = (String) values[2];
+	if (values[3] != null) {
+	    progressBar = (UIComponent)values[3];
+	}
+
+    }
+
+    /**
+     * @return the progressBar
+     */
+    public UIComponent getProgressBar() {
+        return progressBar;
+    }
+
+    /**
+     * @param progressBar the progressBar to set
+     */
+    public void setProgressBar(UIComponent progressBar) {
+        this.progressBar = progressBar;
+    }
+
 }

Modified: trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/renderkit/FileUploadRendererBase.java
===================================================================
--- trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/renderkit/FileUploadRendererBase.java	2008-01-31 13:11:16 UTC (rev 5746)
+++ trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/ui/renderkit/FileUploadRendererBase.java	2008-01-31 14:18:58 UTC (rev 5747)
@@ -1,90 +1,710 @@
 package org.richfaces.org.jboss.seam.ui.renderkit;
 
-
+import java.io.IOException;
+import java.io.Writer;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
+import javax.el.ValueExpression;
 import javax.faces.component.UIComponent;
 import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
 import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpSession;
 
-import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
+import org.ajax4jsf.context.AjaxContext;
+import org.ajax4jsf.context.AjaxContextImpl;
+import org.ajax4jsf.event.AjaxEvent;
+import org.ajax4jsf.javascript.JSFunction;
+import org.ajax4jsf.javascript.JSFunctionDefinition;
+import org.ajax4jsf.renderkit.AjaxRendererUtils;
+import org.ajax4jsf.renderkit.ComponentVariables;
+import org.ajax4jsf.renderkit.ComponentsVariableResolver;
+import org.ajax4jsf.renderkit.RendererUtils;
+import org.richfaces.component.UIProgressBar;
+import org.richfaces.org.jboss.seam.ui.component.FileItem;
 import org.richfaces.org.jboss.seam.ui.component.UIFileUpload;
 import org.richfaces.org.jboss.seam.web.MultipartRequest;
+import org.richfaces.renderkit.TemplateEncoderRendererBase;
 
-public abstract class FileUploadRendererBase extends HeaderResourcesRendererBase
-{
-   @Override
-   protected void doDecode(FacesContext context, UIComponent component)
-   {
-      UIFileUpload fileUpload = (UIFileUpload) component;
-      ServletRequest request = (ServletRequest) context.getExternalContext().getRequest();
+public abstract class FileUploadRendererBase extends
+	TemplateEncoderRendererBase {
 
-      if (!(request instanceof MultipartRequest))
-      {
-         request = unwrapMultipartRequest(request);
-      }
+    private static final String ACTION_ADD_FILE = "add";
 
-      if (request instanceof MultipartRequest)
-      {
-         MultipartRequest multipartRequest = (MultipartRequest) request;
+    private static final String ACTION_UPLOAD_ALL = "uploadall";
 
-         String clientId = component.getClientId(context) + ":1";
-         fileUpload.setLocalInputStream(multipartRequest.getFileInputStream(clientId));
-         fileUpload.setLocalContentType(multipartRequest.getFileContentType(clientId));
-         fileUpload.setLocalFileName(multipartRequest.getFileName(clientId));
-         fileUpload.setLocalFileSize(multipartRequest.getFileSize(clientId));
-      }
-   }
+    private static final String ACTION_UPLOAD = "upload";
 
-   /**
-    * Finds an instance of MultipartRequest wrapped within a request or its
-    * (recursively) wrapped requests.
-    */
-   private static ServletRequest unwrapMultipartRequest(ServletRequest request)
-   {
-      while (!(request instanceof MultipartRequest))
-      {
-         boolean found = false;
+    private static final String ACTION_CLEAR_FILE = "clear";
 
-         for (Method m : request.getClass().getMethods())
-         {
-            if (ServletRequest.class.isAssignableFrom(m.getReturnType())
-                     && m.getParameterTypes().length == 0)
-            {
-               try
-               {
-                  request = (ServletRequest) m.invoke(request);
-                  found = true;
-                  break;
-               }
-               catch (Exception ex)
-               { /* Ignore, try the next one */
-               }
-            }
-         }
+    private static final String ACTION_CLEAR_ALL = "clearall";
 
-         if (!found)
-         {
-            for (Field f : request.getClass().getDeclaredFields())
-            {
-               if (ServletRequest.class.isAssignableFrom(f.getType()))
-               {
-                  try
-                  {
-                     request = (ServletRequest) f.get(request);
-                  }
-                  catch (Exception ex)
-                  { /* Ignore */
-                  }
-               }
-            }
-         }
+    private static final String FILE_NAME_PARAMETER = "fileName";
 
-         if (!found) break;
-      }
+    public static final String _percentBeanName = "__percentValue$";
 
-      return request;
-   }
+    @Override
+    protected void doDecode(FacesContext context, UIComponent component) {
+	UIFileUpload fileUpload = (UIFileUpload) component;
+	ServletRequest request = (ServletRequest) context.getExternalContext()
+		.getRequest();
 
+	String clientId = component.getClientId(context);
+	Map<String, String[]> params = context.getExternalContext()
+		.getRequestParameterValuesMap();
+	
+	if (params.containsKey(getProgressBarParameterName(fileUpload))) {
+	    new AjaxEvent(fileUpload.getProgressBar());
+	}
+	if (params.containsKey(getActionParameterName(clientId))) {
+	    processEvents(context, component, clientId);
+	    AjaxContext ajaxContext = AjaxContextImpl
+		    .getCurrentInstance(context);
+	    ajaxContext.addComponentToAjaxRender(component);
+	}
+	if (!(request instanceof MultipartRequest)) {
+	    request = unwrapMultipartRequest(request);
+	}
+
+	if (request instanceof MultipartRequest) {
+	    MultipartRequest multipartRequest = (MultipartRequest) request;
+	    clientId = clientId + ":1";
+	    fileUpload.setLocalInputStream(multipartRequest
+		    .getFileInputStream(clientId));
+	    fileUpload.setLocalContentType(multipartRequest
+		    .getFileContentType(clientId));
+	    fileUpload.setLocalFileName(multipartRequest.getFileName(clientId));
+	    fileUpload.setLocalFileSize(multipartRequest.getFileSize(clientId));
+	    onUploadComplete(context, multipartRequest.getFileName(clientId),
+		    fileUpload);
+	}
+
+    }
+
+    public void encodeControlsMarkup(FacesContext context, UIComponent component)
+	    throws IOException {
+	UIComponent header = component.getFacet("header");
+	if (header != null) {
+	    writeScriptBody(context, header, true);
+	}
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.ajax4jsf.renderkit.RendererBase#encodeBegin(javax.faces.context.FacesContext,
+     *      javax.faces.component.UIComponent)
+     */
+    @Override
+    public void encodeBegin(FacesContext context, UIComponent component)
+	    throws IOException {
+	// Map<String, String[]> params = context.getExternalContext()
+	// .getRequestParameterValuesMap();
+	// ServletRequest request = (ServletRequest)
+	// context.getExternalContext()
+	// .getRequest();
+	//	
+	// if (!params.containsKey("action")
+	// && !(request instanceof MultipartRequest)) {
+	// return;
+	// }
+	//	
+	// super.encodeBegin(context, component);
+	// UIFileUpload fileUpload = (UIFileUpload) component;
+	// String status = fileUpload.getUploadStatus();
+	// boolean isAll2reRender = true;
+	// if ("ADD".equals(action)) {
+	// isAll2reRender = false;
+	// } else if ("CLEARALL".equals(action)) {
+	// if (UIFileUpload.UPLOADING.equals(status)) {
+	// isAll2reRender = true;
+	// } else {
+	// isAll2reRender = false;
+	// }
+	// } else if ("UPLOAD".equals(action)) {
+	// isAll2reRender = false;
+	// } else if ("CLEAR".equals(action)) {
+	// isAll2reRender = false;
+	// } else if ("UPDATE".equals(action)) {
+	// isAll2reRender = false;
+	// }
+	//	
+	AjaxContext ajaxContext = AjaxContextImpl.getCurrentInstance();
+	ajaxContext.removeRenderedArea(component.getClientId(context));
+	ajaxContext.addRenderedArea(component.getClientId(context)
+		+ ":fileItems");
+
+    }
+
+    public String encodeStatus(UIFileUpload fileUpload) {
+	return fileUpload.getUploadStatus();
+    }
+
+    private void onUploadComplete(FacesContext context, String fileName,
+	    UIFileUpload fileUpload) {
+	Iterator<FileItem> it = fileUpload.getFileItems().iterator();
+	while (it.hasNext()) {
+	    FileItem item = it.next();
+	    if (FileItem.Status.IN_PROGRESS == item.getStatus()) {
+		item.setStatus(FileItem.Status.UPLOADED);
+		break;
+	    }
+	}
+	fileUpload.setUploadStatus(UIFileUpload.READY);
+    }
+
+    private FileItem getFileByName(UIFileUpload fileUpload, String name) {
+	Iterator<FileItem> it = fileUpload.getFileItems().iterator();
+	while (it.hasNext()) {
+	    FileItem item = it.next();
+	    if (item.getFileName().equals(name)) {
+		return item;
+	    }
+	}
+	return null;
+    }
+
+    // public String getFile2Upload(FacesContext context, UIComponent component)
+    // {
+    // UIFileUpload fileUpload = (UIFileUpload) component;
+    // if (UIFileUpload.UPLOADING.equals(fileUpload.getUploadStatus())) {
+    // Iterator<FileItem> it = fileUpload.getFileItems().iterator();
+    // while (it.hasNext()) {
+    // FileItem item = it.next();
+    // if (item.getStatus() == FileItem.Status.IN_PROGRESS) {
+    // return item.getFullFileName();
+    // }
+    // }
+    // }
+    // return "";
+    // }
+
+    public String getActionUrl(FacesContext context) {
+	AjaxContext ajaxContext = AjaxContextImpl.getCurrentInstance(context);
+	return ajaxContext.getAjaxActionURL(context);
+    }
+
+    public void encodeFileItemStatus(FacesContext context,
+	    UIComponent component, FileItem item) {
+	ResponseWriter writer = context.getResponseWriter();
+	if (item.getStatus() == FileItem.Status.IN_PROGRESS
+		|| item.getStatus() == FileItem.Status.UPLOADED) {
+	    UIComponent progressBar = getProgressBar(context, component);
+	    try {
+		if (item.getStatus() == FileItem.Status.IN_PROGRESS) {
+		    HttpSession session = (HttpSession) context
+			    .getExternalContext().getSession(false);
+
+		    if (progressBar != null) {
+			String exprStr = "#{" + _percentBeanName + "}";
+			ValueExpression ex = context.getApplication()
+				.getExpressionFactory().createValueExpression(
+					context.getELContext(), exprStr,
+					Integer.class);
+			progressBar.setValueExpression("value", ex);
+			progressBar.setId("bar");
+			renderChild(context, progressBar);
+		    }
+
+		} else if (item.getStatus() == FileItem.Status.UPLOADED) {
+		    UIComponent completed = progressBar.getFacet("complete");
+		    renderChild(context, completed);
+		}
+	    } catch (Exception e) {
+		e.getMessage();
+	    }
+
+	}
+
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.ajax4jsf.renderkit.RendererBase#getComponentClass()
+     */
+    @Override
+    protected Class<? extends UIComponent> getComponentClass() {
+	// TODO Auto-generated method stub
+	return null;
+    }
+
+    private void processEvents(FacesContext context, UIComponent component,
+	    String clientId) {
+	Map<String, String[]> params = context.getExternalContext()
+		.getRequestParameterValuesMap();
+	UIFileUpload fileUpload = (UIFileUpload) component;
+	String action = params.get(getActionParameterName(clientId))[0];
+	if (ACTION_ADD_FILE.equals(action)) {
+	    processAddFileAction(context, fileUpload, params);
+	} else if (ACTION_UPLOAD_ALL.equals(action)) {
+	    processUploadAllAction(context, fileUpload);
+	} else if (ACTION_CLEAR_ALL.equals(action)) {
+	    fileUpload.getFileItems().clear();
+	} else if (ACTION_CLEAR_FILE.equals(action)) {
+	    processClearAction(context, fileUpload, params);
+	} else if (ACTION_UPLOAD.equals(action)) {
+	    processUploadAction(context, fileUpload);
+	}
+
+    }
+
+    private void processClearAction(FacesContext context,
+	    UIFileUpload fileUpload, Map<String, String[]> params) {
+	if (params.containsKey(ACTION_CLEAR_FILE)) {
+	    String[] fileNames = params.get(ACTION_CLEAR_FILE);
+	    for (String name : fileNames) {
+		removeFileItem(name, fileUpload);
+	    }
+	}
+    }
+
+    // private UIComponent getProgressBar(FacesContext context,
+    // UIComponent fileUpload) {
+    // // return fileUpload.getFacet("progress");
+    // UIComponent progressBar = fileUpload.getFacet("progress");
+    // if (progressBar != null) {
+    // String exprStr = "#{" + _percentBeanName + "}";
+    // ValueExpression ex = context.getApplication()
+    // .getExpressionFactory().createValueExpression(
+    // context.getELContext(), exprStr, Integer.class);
+    // progressBar.setValueExpression("value", ex);
+    // progressBar.setId("progressBar");
+    // }
+    // return progressBar;
+    // }
+
+    private void removeFileItem(String name, UIFileUpload fileUpload) {
+	Iterator<FileItem> it = fileUpload.getFileItems().iterator();
+	while (it.hasNext()) {
+	    FileItem item = it.next();
+	    if (name.equalsIgnoreCase(item.getFullFileName())) {
+		fileUpload.getFileItems().remove(item);
+		return;
+	    }
+	}
+    }
+
+    private void processUploadAction(FacesContext context,
+	    UIFileUpload fileUpload) {
+	if (UIFileUpload.READY.equals(fileUpload.getUploadStatus())) {
+	    Iterator<FileItem> it = fileUpload.getFileItems().iterator();
+	    while (it.hasNext()) {
+		FileItem item = it.next();
+		if (item.getStatus() == FileItem.Status.MARKED_4_UPLOAD) {
+		    item.setStatus(FileItem.Status.IN_PROGRESS);
+		    break;
+		}
+	    }
+	    getSession(context).setAttribute(_percentBeanName, 0);
+	    fileUpload.setUploadStatus(UIFileUpload.UPLOADING);
+	}
+    }
+
+    private void processUploadAllAction(FacesContext context,
+	    UIFileUpload fileUpload) {
+	if (UIFileUpload.READY.equals(fileUpload.getUploadStatus())) {
+
+	    Iterator<FileItem> it = fileUpload.getFileItems().iterator();
+	    FileItem toUpload = null;
+	    while (it.hasNext()) {
+		FileItem item = it.next();
+		item.setStatus(FileItem.Status.MARKED_4_UPLOAD);
+		if (toUpload == null) {
+		    toUpload = item;
+		}
+	    }
+
+	    if (toUpload != null) {
+		toUpload.setStatus(FileItem.Status.IN_PROGRESS);
+		getSession(context).setAttribute(_percentBeanName, 0);
+	    }
+
+	}
+    }
+
+    private void processAddFileAction(FacesContext context,
+	    UIFileUpload fileUpload, Map<String, String[]> params) {
+	if (params.containsKey(FILE_NAME_PARAMETER)) {
+	    String[] fileNames = params.get(FILE_NAME_PARAMETER);
+	    for (String filename : fileNames) {
+		FileItem fileItem = new FileItem(filename);
+		fileUpload.getFileItems().add(fileItem);
+	    }
+	}
+    }
+
+    private String getActionParameterName(String clientId) {
+	return clientId + "_action";
+    }
+
+    private String getProgressBarParameterName(UIComponent fileUpload) {
+	UIComponent form = AjaxRendererUtils.getNestingForm(fileUpload);
+	String formId = null;
+	if (form != null) {
+	    formId = form.getId();
+	    return formId + ":progressBar_percent";
+	}
+	return "progressBar_percent";
+    }
+
+    private HttpSession getSession(FacesContext context) {
+	if (context.getExternalContext() != null) {
+	    return (HttpSession) context.getExternalContext().getSession(false);
+	}
+	return null;
+    }
+
+    public void encodeDate(FacesContext context, UIComponent component)
+	    throws IOException {
+	ResponseWriter writer = context.getResponseWriter();
+	writer.write(new Date().toString());
+    }
+
+    public String convertFileName(String name) {
+	return name.replaceAll("[\\\\]{1}", "\\\\\\\\");
+    }
+
+    public void encodeInitialScript(FacesContext context, UIComponent component)
+	    throws IOException {
+	Writer writer = context.getResponseWriter();
+	String clientId = component.getClientId(context);
+	StringBuffer current = new StringBuffer();
+	StringBuffer script = new StringBuffer("\n");
+	current.append("FileUpload.Uploaders['");
+	current.append(clientId);
+	current.append("']");
+
+	UIComponent container = (UIComponent) AjaxRendererUtils
+		.findAjaxContainer(context, component);
+	UIComponent form = (UIComponent) AjaxRendererUtils
+		.getNestingForm(component);
+	String containerId = container.getId();
+	String formId = form.getId();
+	String actionUrl = AjaxContextImpl.getCurrentInstance(context)
+		.getAjaxActionURL(context);
+
+	script.append(current);
+	script.append(" = {};\n");
+	script.append(current).append("['containerId'] = '")
+		.append(containerId).append("';\n");
+	script.append(current).append("['formId'] = '").append(formId).append(
+		"';\n");
+	script.append(current).append("['actionUrl'] = '").append(actionUrl)
+		.append("';\n");
+	script.append("new FileUpload().init('");
+	script.append(clientId);
+	script.append("');\n");
+
+	writer.write(script.toString());
+    }
+
+    public void encodeUploadScript(FacesContext context, UIComponent component)
+	    throws IOException {
+	UIFileUpload fileUpload = (UIFileUpload) component;
+	String cliendId = fileUpload.getClientId(context);
+	Writer writer = context.getResponseWriter();
+	boolean found = false;
+	if (!UIFileUpload.UPLOADING.equals(fileUpload.getUploadStatus())) {
+	    List<FileItem> items = fileUpload.getFileItems();
+	    Iterator<FileItem> it = items.iterator();
+	    while (it.hasNext()) {
+		FileItem item = it.next();
+		if (item.getStatus() == FileItem.Status.IN_PROGRESS) {
+		    found = true;
+		    StringBuffer buffer = new StringBuffer();
+		    buffer.append("new FileUpload('");
+		    buffer.append(cliendId);
+		    buffer.append("').upload('");
+		    buffer.append(convertFileName(item.getFullFileName()));
+		    buffer.append("');");
+		    writer.write(buffer.toString());
+		    fileUpload.setUploadStatus(UIFileUpload.UPLOADING);
+		    return; // Only one file can be in progress status
+		}
+	    }
+	} else {
+	    StringBuffer buffer = new StringBuffer();
+	    buffer.append("A4J.AJAX.StopPoll(FileUpload.Uploaders['");
+	    buffer.append(cliendId);
+	    buffer.append("']['formId'] + ':progressBar');\n");
+	    writer.write(buffer.toString());
+	}
+    }
+
+    /**
+     * Finds an instance of MultipartRequest wrapped within a request or its
+     * (recursively) wrapped requests.
+     */
+    private static ServletRequest unwrapMultipartRequest(ServletRequest request) {
+	while (!(request instanceof MultipartRequest)) {
+	    boolean found = false;
+
+	    for (Method m : request.getClass().getMethods()) {
+		if (ServletRequest.class.isAssignableFrom(m.getReturnType())
+			&& m.getParameterTypes().length == 0) {
+		    try {
+			request = (ServletRequest) m.invoke(request);
+			found = true;
+			break;
+		    } catch (Exception ex) { /* Ignore, try the next one */
+		    }
+		}
+	    }
+
+	    if (!found) {
+		for (Field f : request.getClass().getDeclaredFields()) {
+		    if (ServletRequest.class.isAssignableFrom(f.getType())) {
+			try {
+			    request = (ServletRequest) f.get(request);
+			} catch (Exception ex) { /* Ignore */
+			}
+		    }
+		}
+	    }
+
+	    if (!found)
+		break;
+	}
+
+	return request;
+    }
+
+    public void renderLabel(FacesContext context, UIComponent component,
+	    FileItem item) throws IOException {
+	Writer writer = context.getResponseWriter();
+	if (item.getStatus() == FileItem.Status.UPLOADED) {
+	    writer.write("Done");
+	} else if (item.getStatus() == FileItem.Status.IN_PROGRESS) {
+	    writer.write("In progress....");
+	}
+    }
+
+    public void renderProgress(FacesContext context, UIComponent component,
+	    FileItem item) throws IOException {
+	if (item.getStatus() == FileItem.Status.IN_PROGRESS) {
+	    UIComponent progressBar = getProgressBar(context, component);
+	    renderChild(context, progressBar);
+	}
+    }
+
+    private UIComponent findProgressBar(UIFileUpload fileUpload) {
+	UIComponent progressBar = null;
+	for (UIComponent child : fileUpload.getChildren()) {
+	    if (child instanceof UIFileUpload) {
+		progressBar = child;
+		break;
+	    }
+	}
+	return progressBar;
+    }
+    
+    private void addComponentToReRender(FacesContext context, UIComponent component) {
+	AjaxContext ajaxContext = AjaxContextImpl.getCurrentInstance(context);
+	ajaxContext.addComponentToAjaxRender(component);
+    }
+
+    private UIComponent getProgressBar(FacesContext context,
+	    UIComponent component) {
+	UIFileUpload fileUpload = (UIFileUpload) component;
+	UIComponent progressBar = fileUpload.getProgressBar();
+	if (progressBar == null) {
+	    progressBar = context.getApplication().createComponent(
+		    UIProgressBar.COMPONENT_TYPE);
+	    String exprStr = "#{" + _percentBeanName + "}";
+	    ValueExpression ex = context.getApplication()
+		    .getExpressionFactory().createValueExpression(
+			    context.getELContext(), exprStr, Integer.class);
+	    progressBar.setValueExpression("value", ex);
+	    progressBar.setId("progressBar");
+	    progressBar.setParent(fileUpload);
+	    fileUpload.setProgressBar(progressBar);
+	    /*fileUpload.getChildren().add(progressBar);
+	    addComponentToReRender(context, progressBar);*/
+	}
+	return progressBar;
+    }
+
+    public String getUploadAllClick(FacesContext context, UIComponent component) {
+	String clientId = component.getClientId(context);
+
+	Map parameters = new HashMap();
+	parameters.put(getActionParameterName(clientId), ACTION_UPLOAD_ALL);
+
+	return getOnClick(context, component, clientId, parameters, null);
+
+    }
+
+    public String getClearFileClick(FacesContext context, UIComponent component) {
+	String clientId = component.getClientId(context);
+
+	ComponentVariables variables = ComponentsVariableResolver.getVariables(
+		this, component);
+	String fileName = (String) variables.getVariable("fullFileName");
+
+	StringBuffer body = new StringBuffer();
+	body.append("new FileUpload('");
+	body.append(clientId);
+	body.append("').clear('");
+	body.append(convertFileName(fileName));
+	body.append("');");
+
+	Object oncomplete = getOnComplete(context, component, body);
+	Map parameters = new HashMap();
+	parameters.put(getActionParameterName(clientId), ACTION_CLEAR_FILE);
+	parameters.put(ACTION_CLEAR_FILE, fileName);
+
+	return getOnClick(context, component, clientId, parameters, oncomplete);
+
+    }
+
+    public String getAddFileClick(FacesContext context, UIComponent component) {
+	String clientId = component.getClientId(context);
+
+	StringBuffer body = new StringBuffer();
+	body.append("new FileUpload('");
+	body.append(clientId);
+	body.append("').addFile();");
+
+	Object oncomplete = getOnComplete(context, component, body);
+	Map parameters = new HashMap();
+	parameters.put(getActionParameterName(clientId), ACTION_ADD_FILE);
+
+	return getOnClick(context, component, clientId, parameters, oncomplete);
+
+    }
+
+    private String getOnClick(FacesContext context, UIComponent component,
+	    String clientId, Map parameters, Object oncomplete) {
+	StringBuffer script = new StringBuffer();
+	JSFunction function = AjaxRendererUtils.buildAjaxFunction(component,
+		context);
+	Map options = AjaxRendererUtils.buildEventOptions(context, component);
+
+	Map p = (Map) options.get("parameters");
+	p.putAll(parameters);
+
+	if (oncomplete != null) {
+	    options.put("oncomplete", oncomplete);
+	}
+
+	function.addParameter(options);
+	function.appendScript(script);
+	return script.toString();
+    }
+
+    public JSFunctionDefinition getOnComplete(FacesContext context,
+	    UIComponent component, Object body) {
+	JSFunctionDefinition oncomplete = new JSFunctionDefinition();
+	oncomplete.addParameter("request");
+	oncomplete.addParameter("event");
+	oncomplete.addParameter("data");
+	oncomplete.addToBody(body);
+	return oncomplete;
+    }
+
+    // public void encodeAddControl(FacesContext context, UIComponent component)
+    // throws IOException {
+    // ResponseWriter writer = context.getResponseWriter();
+    // StringBuffer buffer = new StringBuffer();
+    // buffer.append("<div class='upload_button_border' style=' float:left'><div
+    // class='upload_button upload_font'
+    // onmouseover=\\\"this.className='upload_button_light upload_font'\\\"
+    // onmousedown=\\\"this.className='upload_button_press upload_font'\\\"
+    // onmouseup=\\\"this.className='upload_button upload_font'\\\"
+    // onmouseout=\\\"this.className='upload_button upload_font'\\\"
+    // style='position: relative; overflow: hidden; direction: rtl;
+    // width:70px'><div class='upload_button_content upload_font upload_ico
+    // upload_ico_add'>Add...</div><input type='file' ");
+    // buffer.append("onchange=\\\"");
+    // buffer.append(getActionOnClick(context, component, "ADD", "false"));
+    // buffer.append("\\\"");
+    // buffer.append(" style='cursor: pointer; z-index: 3; width: 0px; height:
+    // 22px; left: 0px; top: 0px; position: absolute'
+    // class='hidden'/></div></div>");
+    // writer.write(buffer.toString());
+    // }
+    //
+    // public void encodeUploadControl(FacesContext context, UIComponent
+    // component)
+    // throws IOException {
+    // ResponseWriter writer = context.getResponseWriter();
+    // StringBuffer buffer = new StringBuffer();
+    // String clientId = component.getClientId(context);
+    // buffer.append("<div class='upload_button_border' style='
+    // float:left;'><div class='upload_button upload_font'
+    // onmouseover=\\\"this.className='upload_button_light upload_font'\\\"
+    // onmousedown=\\\"this.className='upload_button_press upload_font'\\\"
+    // onmouseup=\\\"this.className='upload_button upload_font'\\\"
+    // onmouseout=\\\"this.className='upload_button upload_font'\\\"><a href='#'
+    // class='upload_button_selection'><div class='upload_button_content
+    // upload_font upload_ico
+    // upload_ico_start'><b>Upload</b></div></a></div></div>");
+    // writer.write(buffer.toString());
+    // }
+    //
+    // public void encodeCleanControl(FacesContext context, UIComponent
+    // component)
+    // throws IOException {
+    // ResponseWriter writer = context.getResponseWriter();
+    // StringBuffer buffer = new StringBuffer();
+    // String clientId = component.getClientId(context);
+    // buffer.append("<div class='upload_button_border' style='
+    // float:right'><div class='upload_button upload_font'
+    // onmouseover=\\\"this.className='upload_button_light upload_font'\\\"
+    // onmousedown=\\\"this.className='upload_button_press upload_font'\\\"
+    // onmouseup=\\\"this.className='upload_button upload_font'\\\"
+    // onmouseout=\\\"this.className='upload_button upload_font'\\\"><a href='#'
+    // class='upload_button_selection'><div class='upload_button_content
+    // upload_font upload_ico upload_ico_clear'>Clear
+    // All</div></a></div></div>");
+    // writer.write(buffer.toString());
+    // }
+
+    // private String convertToString(Object obj) {
+    // return (obj == null ? "" : obj.toString());
+    // }
+    //
+    // private String convertToString(boolean b) {
+    // return String.valueOf(b);
+    // }
+    //
+    // private String convertToString(int b) {
+    // return b != Integer.MIN_VALUE ? String.valueOf(b) : "";
+    // }
+    //
+    // private String convertToString(long b) {
+    // return b != Long.MIN_VALUE ? String.valueOf(b) : "";
+    // }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.richfaces.renderkit.TemplateEncoderRendererBase#encodeChildren(javax.faces.context.FacesContext,
+     *      javax.faces.component.UIComponent)
+     */
+    @Override
+    public void encodeChildren(FacesContext context, UIComponent component)
+	    throws IOException {
+	; // We should not render children
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.ajax4jsf.renderkit.RendererBase#doEncodeChildren(javax.faces.context.ResponseWriter,
+     *      javax.faces.context.FacesContext, javax.faces.component.UIComponent)
+     */
+    @Override
+    public void doEncodeChildren(ResponseWriter writer, FacesContext context,
+	    UIComponent component) throws IOException {
+	; // We should not render children
+    }
+
 }

Modified: trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartFilter.java
===================================================================
--- trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartFilter.java	2008-01-31 13:11:16 UTC (rev 5746)
+++ trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartFilter.java	2008-01-31 14:18:58 UTC (rev 5747)
@@ -67,9 +67,9 @@
       }
 
       HttpServletRequest httpRequest = (HttpServletRequest) request;
-
       if (isMultipartRequest(httpRequest))
       {
+	 System.out.println("Request content length" + httpRequest.getContentLength());
          chain.doFilter(new MultipartRequest(httpRequest, createTempFiles, 
                   maxRequestSize), response);
       }
@@ -106,7 +106,10 @@
 }
 
 public void init(FilterConfig filterConfig) throws ServletException {
-	// TODO Auto-generated method stub
+	String param = filterConfig.getInitParameter("createTempFiles");
+	if (param != null) {
+	    this.createTempFiles = Boolean.parseBoolean(param);
+	}
 	
 }
 }

Modified: trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartRequest.java
===================================================================
--- trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartRequest.java	2008-01-31 13:11:16 UTC (rev 5746)
+++ trunk/sandbox/ui/fileUpload/src/main/java/org/richfaces/org/jboss/seam/web/MultipartRequest.java	2008-01-31 14:18:58 UTC (rev 5747)
@@ -22,612 +22,573 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequestWrapper;
 
+import org.richfaces.org.jboss.seam.ui.renderkit.FileUploadRendererBase;
+
 /**
  * Request wrapper for supporting multipart requests, used for file uploading.
  * 
  * @author Shane Bryzak
  */
-public class MultipartRequest extends HttpServletRequestWrapper
-{   
-   private static final String PARAM_NAME = "name";
-   private static final String PARAM_FILENAME = "filename";
-   private static final String PARAM_CONTENT_TYPE = "Content-Type";
-   
-   private static final int BUFFER_SIZE = 2048;
-   private static final int CHUNK_SIZE = 512;
-   
-   private boolean createTempFiles;
-   
-   private String encoding = null;
-   
-   private Map<String,Param> parameters = null;
-   
-   private enum ReadState { BOUNDARY, HEADERS, DATA }   
-   
-   private static final byte CR = 0x0d;
-   private static final byte LF = 0x0a;   
-   private static final byte[] CR_LF = {CR,LF};
-         
-   private abstract class Param
-   {
-      private String name;
-      
-      public Param(String name)
-      {
-         this.name = name;
-      }
-      
-      public String getName()
-      {
-         return name;
-      }
-      
-      public abstract void appendData(byte[] data, int start, int length) 
-         throws IOException;
-   }
-   
-   private class ValueParam extends Param
-   {
-      private Object value = null;
-      private ByteArrayOutputStream buf = new ByteArrayOutputStream();      
-      
-      public ValueParam(String name)
-      {
-         super(name);
-      }
-      
-      @Override
-      public void appendData(byte[] data, int start, int length)
-         throws IOException
-      {
-         buf.write(data, start, length);
-      }
-      
-      public void complete()
-         throws UnsupportedEncodingException
-      {
-         String val = encoding == null ? new String(buf.toByteArray()) :
-                                         new String(buf.toByteArray(), encoding);
-         if (value == null)
-         {
-            value = val;
-         }
-         else 
-         {
-            if (!(value instanceof List))
-            {
-               List<String> v = new ArrayList<String>();
-               v.add((String) value);
-               value = v;
-            }
-            
-            ((List) value).add(val);
-         }            
-         buf.reset();
-      }
-      
-      public Object getValue()
-      {
-         return value;
-      }
-   }
-   
-   private class FileParam extends Param
-   {
-      private String filename;
-      private String contentType;
-      private int fileSize;
-           
-      private ByteArrayOutputStream bOut = null;
-      private FileOutputStream fOut = null;
-      private File tempFile = null;
-      
-      public FileParam(String name)
-      {
-         super(name);
-      }      
-      
-      public String getFilename()
-      {
-         return filename;
-      }
-      
-      public void setFilename(String filename)
-      {
-         this.filename = filename;
-      }
-      
-      public String getContentType()
-      {
-         return contentType;
-      }
-      
-      public void setContentType(String contentType)
-      {
-         this.contentType = contentType;
-      }
-      
-      public int getFileSize()
-      {
-         return fileSize;
-      }      
-      
-      public void createTempFile()
-      {
-         try
-         {
-            tempFile = File.createTempFile(new UID().toString().replace(":", "-"), ".upload");
-            tempFile.deleteOnExit();
-            fOut = new FileOutputStream(tempFile);            
-         }
-         catch (IOException ex)
-         {
-            throw new FileUploadException("Could not create temporary file");
-         }
-      }
-      
-      @Override
-      public void appendData(byte[] data, int start, int length)
-         throws IOException
-      {
-         if (fOut != null)
-         {
-            fOut.write(data, start, length);
-            fOut.flush();
-         }
-         else
-         {
-            if (bOut == null) bOut = new ByteArrayOutputStream();
-            bOut.write(data, start, length);
-         }
-         
-         fileSize += length;
-      }
-      
-      public byte[] getData()
-      {
-         if (fOut != null)
-         {
-            try
-            {
-               fOut.close();
-            }
-            catch (IOException ex) {}
-            fOut = null;
-         }
-         
-         if (bOut != null)
-         {
-            return bOut.toByteArray();
-         }
-         else if (tempFile != null)
-         {
-            if (tempFile.exists())
-            {
-               try
-               {
-                  FileInputStream fIn = new FileInputStream(tempFile);
-                  ByteArrayOutputStream bOut = new ByteArrayOutputStream();
-                  byte[] buf = new byte[512];
-                  int read = fIn.read(buf);
-                  while (read != -1)
-                  {
-                     bOut.write(buf, 0, read);
-                     read = fIn.read(buf);
-                  }
-                  bOut.flush();
+public class MultipartRequest extends HttpServletRequestWrapper {
+    private static final String PARAM_NAME = "name";
+    private static final String PARAM_FILENAME = "filename";
+    private static final String PARAM_CONTENT_TYPE = "Content-Type";
 
-                  fIn.close();
-                  tempFile.delete();
-                  return bOut.toByteArray();
-               }
-               catch (IOException ex) { /* too bad? */}
-            }
-         }
-        
-        return null;
-      }
-      
-      public InputStream getInputStream()
-      {
-         if (fOut != null)
-         {
-            try
-            {
-               fOut.close();
-            }
-            catch (IOException ex) {}
-            fOut = null;
-         }
-         
-         if (bOut!=null)
-         {
-            return new ByteArrayInputStream(bOut.toByteArray());
-         }
-         else if (tempFile!=null)
-         {
-            try
-            {
-               return new FileInputStream(tempFile) {
-                  @Override
-                  public void close() throws IOException
-                  {
-                     super.close();
-                     tempFile.delete();
-                  }
-               };
-            }
-            catch (FileNotFoundException ex) { }
-         }
-         
-         return null;
-      }
-   }
-   
-   private HttpServletRequest request;
+    private static final int BUFFER_SIZE = 2048;
+    private static final int CHUNK_SIZE = 512;
 
-   public MultipartRequest(HttpServletRequest request, boolean createTempFiles,
-            int maxRequestSize)
-   {
-      super(request);
-      this.request = request;
-      this.createTempFiles = createTempFiles;
-      
-      String contentLength = request.getHeader("Content-Length");
-      if (contentLength != null && maxRequestSize > 0 && 
-               Integer.parseInt(contentLength) > maxRequestSize)
-      {
-         throw new FileUploadException("Multipart request is larger than allowed size");
-      }
-   }
+    private boolean createTempFiles;
 
-   private void parseRequest()
-   {               
-      byte[] boundaryMarker = getBoundaryMarker(request.getContentType());
-      if (boundaryMarker == null)
-      {
-         throw new FileUploadException("The request was rejected because "
-                  + "no multipart boundary was found");
-      }
-      
-      encoding = request.getCharacterEncoding();    
-      
-      parameters = new HashMap<String,Param>();      
-      
-      try
-      {
-         byte[] buffer = new byte[BUFFER_SIZE];         
-         Map<String,String> headers = new HashMap<String,String>();
-         
-         ReadState readState = ReadState.BOUNDARY;
-         
-         InputStream input = request.getInputStream();
-         int read = input.read(buffer);
-         int pos = 0;
-         
-         Param p = null;
-         
-         while (read != -1)
-         {
-            for (int i = 0; i < read; i++)
-            {
-               switch (readState)
-               {
-                  case BOUNDARY:
-                  {
-                     if (checkSequence(buffer, i, boundaryMarker) && checkSequence(buffer, i + 2, CR_LF))
-                     {
-                        readState = ReadState.HEADERS;
-                        i += 2;
-                        pos = i + 1;
-                     }
-                     break;
-                  }
-                  case HEADERS:
-                  {
-                     if (checkSequence(buffer, i, CR_LF))
-                     {
-                        String param = (encoding == null) ? 
-                                 new String(buffer, pos, i - pos - 1) :
-                                 new String(buffer, pos, i - pos - 1, encoding);                        
-                        parseParams(param, ";", headers);
-                           
-                        if (checkSequence(buffer, i + CR_LF.length, CR_LF))
-                        {
-                           readState = ReadState.DATA;
-                           i += CR_LF.length;
-                           pos = i + 1;
-                           
-                           String paramName = headers.get(PARAM_NAME);
-                           if (paramName != null)
-                           {
-                              if (headers.containsKey(PARAM_FILENAME))
-                              {
-                                 FileParam fp = new FileParam(paramName);
-                                 if (createTempFiles) fp.createTempFile();                                 
-                                 fp.setContentType(headers.get(PARAM_CONTENT_TYPE));
-                                 fp.setFilename(headers.get(PARAM_FILENAME));
-                                 p = fp;                                 
-                              }
-                              else
-                              {
-                                 if (parameters.containsKey(paramName))
-                                 {
-                                    p = parameters.get(paramName);
-                                 }
-                                 else
-                                 {
-                                    p = new ValueParam(paramName);
-                                 }
-                              }
-                              
-                              if (!parameters.containsKey(paramName))
-                              {
-                                 parameters.put(paramName, p);                              
-                              }
-                           }
-                           
-                           headers.clear();
-                        }
-                        else
-                        {
-                           pos = i + 1;
-                        }
-                     }
-                     break;                     
-                  }
-                  case DATA:
-                  {
-                     // If we've encountered another boundary...
-                     if (checkSequence(buffer, i - boundaryMarker.length - CR_LF.length, CR_LF) &&
-                         checkSequence(buffer, i, boundaryMarker))
-                     {
-                        // Write any data before the boundary (that hasn't already been written) to the param
-                        if (pos < i - boundaryMarker.length - CR_LF.length - 1)
-                        {
-                          p.appendData(buffer, pos, i - pos - boundaryMarker.length - CR_LF.length - 1);
-                        }
-                        
-                        if (p instanceof ValueParam) ((ValueParam) p).complete();
-                        
-                        if (checkSequence(buffer, i + CR_LF.length, CR_LF))
-                        {
-                           i += CR_LF.length;
-                           pos = i + 1;
-                        }
-                        else
-                        {
-                           pos = i;
-                        }
-                        
-                        readState = ReadState.HEADERS;
-                     }
-                     // Otherwise write whatever data we have to the param
-                     else if (i > (pos + boundaryMarker.length + CHUNK_SIZE + CR_LF.length))
-                     {
-                        p.appendData(buffer, pos, CHUNK_SIZE);
-                        pos += CHUNK_SIZE;
-                     }
-                     break;                     
-                  }               
-               }
-            }               
-            
-            if (pos < read)
-            {
-               // move the bytes that weren't read to the start of the buffer
-               int bytesNotRead = read - pos;
-               System.arraycopy(buffer, pos, buffer, 0, bytesNotRead);               
-               read = input.read(buffer, bytesNotRead, buffer.length - bytesNotRead);
-               read += bytesNotRead;
-            }
-            else
-            {
-               read = input.read(buffer);
-            }
-            
-            pos = 0;                                    
-         }
-      }
-      catch (IOException ex)
-      {
-         throw new FileUploadException("IO Error parsing multipart request", ex);
-      }
-   }
-   
-   private byte[] getBoundaryMarker(String contentType)
-   {
-      Map<String, Object> params = parseParams(contentType, ";");
-      String boundaryStr = (String) params.get("boundary");
+    private String encoding = null;
 
-      if (boundaryStr == null) return null;
+    private Integer contentLength = 0;
 
-      try
-      {
-         return boundaryStr.getBytes("ISO-8859-1");
-      }
-      catch (UnsupportedEncodingException e)
-      {
-         return boundaryStr.getBytes();
-      }
-   }   
-   
-   /**
-    * Checks if a specified sequence of bytes ends at a specific position
-    * within a byte array.
-    * 
-    * @param data
-    * @param pos
-    * @param seq
-    * @return boolean indicating if the sequence was found at the specified position
-    */
-   private boolean checkSequence(byte[] data, int pos, byte[] seq)
-   {
-      if (pos - seq.length < -1 || pos >= data.length)
-         return false;
-      
-      for (int i = 0; i < seq.length; i++)
-      {
-         if (data[(pos - seq.length) + i + 1] != seq[i])
-            return false;
-      }
-      
-      return true;
-   }
+    private int read = 0;
 
-   private static final Pattern PARAM_VALUE_PATTERN = Pattern
-            .compile("^\\s*([^\\s=]+)\\s*[=:]\\s*(.+)\\s*$");
+    private String beanName;
 
-   private Map parseParams(String paramStr, String separator)
-   {
-      Map<String,String> paramMap = new HashMap<String, String>();
-      parseParams(paramStr, separator, paramMap);
-      return paramMap;
-   }
-   
-   private void parseParams(String paramStr, String separator, Map paramMap)
-   {
-      String[] parts = paramStr.split("[" + separator + "]");
+    private Map<String, Param> parameters = null;
 
-      for (String part : parts)
-      {
-         Matcher m = PARAM_VALUE_PATTERN.matcher(part);
-         if (m.matches())
-         {
-            String key = m.group(1);
-            String value = m.group(2);
-            
-            // Strip double quotes
-            if (value.startsWith("\"") && value.endsWith("\""))
-               value = value.substring(1, value.length() - 1);
-            
-            paramMap.put(key, value);
-         }
-      }    
-   }
+    private enum ReadState {
+	BOUNDARY, HEADERS, DATA
+    }
 
-   private Param getParam(String name)
-   {
-      if (parameters == null) 
-         parseRequest();
-      return parameters.get(name);
-   }
+    private static final byte CR = 0x0d;
+    private static final byte LF = 0x0a;
+    private static final byte[] CR_LF = { CR, LF };
 
-   @Override
-   public Enumeration getParameterNames()
-   {
-      if (parameters == null) 
-         parseRequest();
+    private abstract class Param {
+	private String name;
 
-      return Collections.enumeration(parameters.keySet());
-   }
-   
-   public byte[] getFileBytes(String name)
-   {
-      Param p = getParam(name);
-      return (p != null && p instanceof FileParam) ? 
-               ((FileParam) p).getData() : null;
-   }
-   
-   public InputStream getFileInputStream(String name)
-   {
-      Param p = getParam(name);
-      return (p != null && p instanceof FileParam) ? 
-               ((FileParam) p).getInputStream() : null;      
-   }
-   
-   public String getFileContentType(String name)
-   {
-      Param p = getParam(name);
-      return (p != null && p instanceof FileParam) ? 
-               ((FileParam) p).getContentType() : null;
-   }
-   
-   public String getFileName(String name)
-   {
-      Param p = getParam(name);    
-      return (p != null && p instanceof FileParam) ? 
-               ((FileParam) p).getFilename() : null;
-   }   
-   
-   public int getFileSize(String name)
-   {
-      Param p = getParam(name);    
-      return (p != null && p instanceof FileParam) ? 
-               ((FileParam) p).getFileSize() : -1;      
-   }
-   
-   @Override
-   public String getParameter(String name)
-   {
-      Param p = getParam(name);
-      if (p != null && p instanceof ValueParam)
-      {
-         ValueParam vp = (ValueParam) p;
-         if (vp.getValue() instanceof String) return (String) vp.getValue();
-      }
-      else if (p != null && p instanceof FileParam)
-      {
-         return "---BINARY DATA---";
-      }      
-      else
-      {
-         return super.getParameter(name);
-      }
-      
-      return null;
-   }
+	public Param(String name) {
+	    this.name = name;
+	}
 
-   @Override
-   public String[] getParameterValues(String name)
-   {
-      Param p = getParam(name);
-      if (p != null && p instanceof ValueParam)
-      {
-         ValueParam vp = (ValueParam) p;
-         if (vp.getValue() instanceof List)
-         {
-            List vals = (List) vp.getValue();
-            String[] values = new String[vals.size()];
-            vals.toArray(values);
-            return values;
-         }
-         else
-         {
-            return new String[] {(String) vp.getValue()};
-         }
-      }
-      else
-      {
-         return super.getParameterValues(name);
-      }
-   }
+	public String getName() {
+	    return name;
+	}
 
-   @Override
-   public Map getParameterMap()
-   {
-      if (parameters == null)
-         parseRequest();
+	public abstract void appendData(byte[] data, int start, int length)
+		throws IOException;
 
-      Map<String,Object> params = new HashMap<String,Object>(super.getParameterMap());
-      
-      for (String name : parameters.keySet())
-      {
-         Param p = parameters.get(name);
-         if (p instanceof ValueParam)
-         {
-            ValueParam vp = (ValueParam) p;
-            if (vp.getValue() instanceof String)
-            {
-               params.put(name, vp.getValue());               
-            }
-            else if (vp.getValue() instanceof List)
-            {
-               params.put(name, getParameterValues(name));
-            }               
-         }
-      }
-      
-      return params;
-   }
+    }
+
+    private class ValueParam extends Param {
+	private Object value = null;
+	private ByteArrayOutputStream buf = new ByteArrayOutputStream();
+
+	public ValueParam(String name) {
+	    super(name);
+	}
+
+	@Override
+	public void appendData(byte[] data, int start, int length)
+		throws IOException {
+	    // read += length;
+	    buf.write(data, start, length);
+	}
+
+	public void complete() throws UnsupportedEncodingException {
+	    String val = encoding == null ? new String(buf.toByteArray())
+		    : new String(buf.toByteArray(), encoding);
+	    if (value == null) {
+		value = val;
+	    } else {
+		if (!(value instanceof List)) {
+		    List<String> v = new ArrayList<String>();
+		    v.add((String) value);
+		    value = v;
+		}
+
+		((List) value).add(val);
+	    }
+	    buf.reset();
+	}
+
+	public Object getValue() {
+	    return value;
+	}
+    }
+
+    private class FileParam extends Param {
+	private String filename;
+	private String contentType;
+	private int fileSize;
+
+	private ByteArrayOutputStream bOut = null;
+	private FileOutputStream fOut = null;
+	private File tempFile = null;
+
+	public FileParam(String name) {
+	    super(name);
+	}
+
+	public String getFilename() {
+	    return filename;
+	}
+
+	public void setFilename(String filename) {
+	    this.filename = filename;
+	}
+
+	public String getContentType() {
+	    return contentType;
+	}
+
+	public void setContentType(String contentType) {
+	    this.contentType = contentType;
+	}
+
+	public int getFileSize() {
+	    return fileSize;
+	}
+
+	public void createTempFile() {
+	    try {
+
+		tempFile = File.createTempFile(new UID().toString().replace(
+			":", "-"), ".upload");
+		tempFile.deleteOnExit();
+		fOut = new FileOutputStream(tempFile);
+	    } catch (IOException ex) {
+		throw new FileUploadException("Could not create temporary file");
+	    }
+	}
+
+	@Override
+	public void appendData(byte[] data, int start, int length)
+		throws IOException {
+	    // read += length;
+	    if (fOut != null) {
+		fOut.write(data, start, length);
+		fOut.flush();
+	    } else {
+		if (bOut == null)
+		    bOut = new ByteArrayOutputStream();
+		bOut.write(data, start, length);
+	    }
+
+	    fileSize += length;
+	}
+
+	public byte[] getData() {
+	    if (fOut != null) {
+		try {
+		    fOut.close();
+		} catch (IOException ex) {
+		}
+		fOut = null;
+	    }
+
+	    if (bOut != null) {
+		return bOut.toByteArray();
+	    } else if (tempFile != null) {
+		if (tempFile.exists()) {
+		    try {
+			FileInputStream fIn = new FileInputStream(tempFile);
+			ByteArrayOutputStream bOut = new ByteArrayOutputStream();
+			byte[] buf = new byte[512];
+			int read = fIn.read(buf);
+			while (read != -1) {
+			    bOut.write(buf, 0, read);
+			    read = fIn.read(buf);
+			}
+			bOut.flush();
+
+			fIn.close();
+			tempFile.delete();
+			return bOut.toByteArray();
+		    } catch (IOException ex) { /* too bad? */
+		    }
+		}
+	    }
+
+	    return null;
+	}
+
+	public InputStream getInputStream() {
+	    if (fOut != null) {
+		try {
+		    fOut.close();
+		} catch (IOException ex) {
+		}
+		fOut = null;
+	    }
+
+	    if (bOut != null) {
+		return new ByteArrayInputStream(bOut.toByteArray());
+	    } else if (tempFile != null) {
+		try {
+		    return new FileInputStream(tempFile) {
+			@Override
+			public void close() throws IOException {
+			    super.close();
+			    tempFile.delete();
+			}
+		    };
+		} catch (FileNotFoundException ex) {
+		}
+	    }
+
+	    return null;
+	}
+    }
+
+    private HttpServletRequest request;
+
+    public MultipartRequest(HttpServletRequest request,
+	    boolean createTempFiles, int maxRequestSize) {
+	super(request);
+	this.request = request;
+	this.createTempFiles = createTempFiles;
+
+	String contentLength = request.getHeader("Content-Length");
+	this.contentLength = Integer.parseInt(contentLength);
+	if (contentLength != null && maxRequestSize > 0
+		&& this.contentLength > maxRequestSize) {
+	    throw new FileUploadException(
+		    "Multipart request is larger than allowed size");
+	}
+    }
+
+    private String decodeFileName(String name) {
+	    String fileName = null;
+	    StringBuffer buffer = new StringBuffer();
+	    String[] codes = name.split(";");
+	    if (codes != null) {
+		for (String code : codes) {
+		    if (code.startsWith("&")) {
+			String sCode = code.replaceAll("[&#]*", "");
+			Integer iCode = Integer.parseInt(sCode);
+			buffer.append(Character.toChars(iCode));
+		    }else {
+			buffer.append(code);
+		    }
+		}
+		fileName = buffer.toString();
+	    }
+	return fileName;
+    }
+
+    private void parseRequest() {
+	byte[] boundaryMarker = getBoundaryMarker(request.getContentType());
+	if (boundaryMarker == null) {
+	    throw new FileUploadException("The request was rejected because "
+		    + "no multipart boundary was found");
+	}
+
+	encoding = request.getCharacterEncoding();
+
+	parameters = new HashMap<String, Param>();
+
+	try {
+	    byte[] buffer = new byte[BUFFER_SIZE];
+	    Map<String, String> headers = new HashMap<String, String>();
+
+	    ReadState readState = ReadState.BOUNDARY;
+
+	    InputStream input = request.getInputStream();
+	    int read = input.read(buffer);
+	    int pos = 0;
+
+	    Param p = null;
+
+	    while (read != -1) {
+		for (int i = 0; i < read; i++) {
+		    switch (readState) {
+		    case BOUNDARY: {
+			if (checkSequence(buffer, i, boundaryMarker)
+				&& checkSequence(buffer, i + 2, CR_LF)) {
+			    readState = ReadState.HEADERS;
+			    i += 2;
+			    pos = i + 1;
+
+			}
+			break;
+		    }
+		    case HEADERS: {
+			if (checkSequence(buffer, i, CR_LF)) {
+			    String param = (encoding == null) ? new String(
+				    buffer, pos, i - pos - 1) : new String(
+				    buffer, pos, i - pos - 1, encoding);
+			    parseParams(param, "; ", headers);
+
+			    if (checkSequence(buffer, i + CR_LF.length, CR_LF)) {
+				readState = ReadState.DATA;
+				i += CR_LF.length;
+				pos = i + 1;
+
+				String paramName = headers.get(PARAM_NAME);
+				if (paramName != null) {
+				    if (headers.containsKey(PARAM_FILENAME)) {
+					FileParam fp = new FileParam(paramName);
+					if (createTempFiles)
+					    fp.createTempFile();
+					fp.setContentType(headers
+						.get(PARAM_CONTENT_TYPE));
+					fp.setFilename(decodeFileName(headers
+						.get(PARAM_FILENAME)));
+					p = fp;
+				    } else {
+					if (parameters.containsKey(paramName)) {
+					    p = parameters.get(paramName);
+					} else {
+					    p = new ValueParam(paramName);
+					}
+				    }
+
+				    if (!parameters.containsKey(paramName)) {
+					parameters.put(paramName, p);
+				    }
+				}
+
+				headers.clear();
+			    } else {
+				pos = i + 1;
+			    }
+			}
+			break;
+		    }
+		    case DATA: {
+			// If we've encountered another boundary...
+			if (checkSequence(buffer, i - boundaryMarker.length
+				- CR_LF.length, CR_LF)
+				&& checkSequence(buffer, i, boundaryMarker)) {
+			    // Write any data before the boundary (that hasn't
+			    // already been written) to the param
+			    if (pos < i - boundaryMarker.length - CR_LF.length
+				    - 1) {
+				p.appendData(buffer, pos, i - pos
+					- boundaryMarker.length - CR_LF.length
+					- 1);
+			    }
+
+			    if (p instanceof ValueParam)
+				((ValueParam) p).complete();
+
+			    if (checkSequence(buffer, i + CR_LF.length, CR_LF)) {
+				i += CR_LF.length;
+				pos = i + 1;
+			    } else {
+				pos = i;
+			    }
+
+			    readState = ReadState.HEADERS;
+			}
+			// Otherwise write whatever data we have to the param
+			else if (i > (pos + boundaryMarker.length + CHUNK_SIZE + CR_LF.length)) {
+			    p.appendData(buffer, pos, CHUNK_SIZE);
+			    pos += CHUNK_SIZE;
+
+			}
+			break;
+		    }
+		    }
+		}
+
+		if (pos < read) {
+		    // move the bytes that weren't read to the start of the
+		    // buffer
+		    int bytesNotRead = read - pos;
+		    System.arraycopy(buffer, pos, buffer, 0, bytesNotRead);
+		    read = input.read(buffer, bytesNotRead, buffer.length
+			    - bytesNotRead);
+		    read += bytesNotRead;
+		} else {
+		    read = input.read(buffer);
+		}
+		this.read += pos;
+		pos = 0;
+		getSession().setAttribute(FileUploadRendererBase._percentBeanName,
+			(Double) (100.0 * this.read / this.contentLength));
+
+	    }
+	} catch (IOException ex) {
+	    throw new FileUploadException("IO Error parsing multipart request",
+		    ex);
+	}
+    }
+
+    private byte[] getBoundaryMarker(String contentType) {
+	Map<String, Object> params = parseParams(contentType, ";");
+	String boundaryStr = (String) params.get("boundary");
+
+	if (boundaryStr == null)
+	    return null;
+
+	try {
+	    return boundaryStr.getBytes("ISO-8859-1");
+	} catch (UnsupportedEncodingException e) {
+	    return boundaryStr.getBytes();
+	}
+    }
+
+    /**
+     * Checks if a specified sequence of bytes ends at a specific position
+     * within a byte array.
+     * 
+     * @param data
+     * @param pos
+     * @param seq
+     * @return boolean indicating if the sequence was found at the specified
+     *         position
+     */
+    private boolean checkSequence(byte[] data, int pos, byte[] seq) {
+	if (pos - seq.length < -1 || pos >= data.length)
+	    return false;
+
+	for (int i = 0; i < seq.length; i++) {
+	    if (data[(pos - seq.length) + i + 1] != seq[i])
+		return false;
+	}
+
+	return true;
+    }
+
+    private static final Pattern PARAM_VALUE_PATTERN = Pattern
+	    .compile("^\\s*([^\\s=]+)\\s*[=:]\\s*(.+)\\s*$");
+    
+    private static final Pattern FILE_NAME_PATTERN = Pattern
+    		.compile(".*filename=\"(.*)\"");
+
+    private Map parseParams(String paramStr, String separator) {
+	Map<String, String> paramMap = new HashMap<String, String>();
+	parseParams(paramStr, separator, paramMap);
+	return paramMap;
+    }
+
+    private void parseParams(String paramStr, String separator, Map paramMap) {
+	String[] parts = paramStr.split(separator);
+
+	for (String part : parts) {
+	    Matcher m = PARAM_VALUE_PATTERN.matcher(part);
+	    if (m.matches()) {
+		String key = m.group(1);
+		String value = m.group(2);
+
+		// Strip double quotes
+		if (value.startsWith("\"") && value.endsWith("\""))
+		    value = value.substring(1, value.length() - 1);
+		if (!"filename".equals(key)) {
+		    paramMap.put(key, value);
+		}else {
+		    paramMap.put(key, parseFileName(paramStr));
+		}
+	    }
+	}
+    }
+    
+    private String parseFileName(String parseStr) {
+	Matcher m = FILE_NAME_PATTERN.matcher(parseStr);
+	if (m.matches()) {
+		String name = m.group(1);
+		if (name.startsWith("&")) {
+		    return decodeFileName(name);
+		} else{
+		    return name;
+		}
+	}
+	return null;
+    }
+
+    private Param getParam(String name) {
+	if (parameters == null)
+	    parseRequest();
+	return parameters.get(name);
+    }
+
+    @Override
+    public Enumeration getParameterNames() {
+	if (parameters == null)
+	    parseRequest();
+
+	return Collections.enumeration(parameters.keySet());
+    }
+
+    public byte[] getFileBytes(String name) {
+	Param p = getParam(name);
+	return (p != null && p instanceof FileParam) ? ((FileParam) p)
+		.getData() : null;
+    }
+
+    public InputStream getFileInputStream(String name) {
+	Param p = getParam(name);
+	return (p != null && p instanceof FileParam) ? ((FileParam) p)
+		.getInputStream() : null;
+    }
+
+    public String getFileContentType(String name) {
+	Param p = getParam(name);
+	return (p != null && p instanceof FileParam) ? ((FileParam) p)
+		.getContentType() : null;
+    }
+
+    public String getFileName(String name) {
+	Param p = getParam(name);
+	return (p != null && p instanceof FileParam) ? ((FileParam) p)
+		.getFilename() : null;
+    }
+
+    public int getFileSize(String name) {
+	Param p = getParam(name);
+	return (p != null && p instanceof FileParam) ? ((FileParam) p)
+		.getFileSize() : -1;
+    }
+
+    @Override
+    public String getParameter(String name) {
+	Param p = getParam(name);
+	if (p != null && p instanceof ValueParam) {
+	    ValueParam vp = (ValueParam) p;
+	    if (vp.getValue() instanceof String)
+		return (String) vp.getValue();
+	} else if (p != null && p instanceof FileParam) {
+	    return "---BINARY DATA---";
+	} else {
+	    return super.getParameter(name);
+	}
+
+	return null;
+    }
+
+    @Override
+    public String[] getParameterValues(String name) {
+	Param p = getParam(name);
+	if (p != null && p instanceof ValueParam) {
+	    ValueParam vp = (ValueParam) p;
+	    if (vp.getValue() instanceof List) {
+		List vals = (List) vp.getValue();
+		String[] values = new String[vals.size()];
+		vals.toArray(values);
+		return values;
+	    } else {
+		return new String[] { (String) vp.getValue() };
+	    }
+	} else {
+	    return super.getParameterValues(name);
+	}
+    }
+
+    @Override
+    public Map getParameterMap() {
+	if (parameters == null)
+	    parseRequest();
+
+	Map<String, Object> params = new HashMap<String, Object>(super
+		.getParameterMap());
+
+	for (String name : parameters.keySet()) {
+	    Param p = parameters.get(name);
+	    if (p instanceof ValueParam) {
+		ValueParam vp = (ValueParam) p;
+		if (vp.getValue() instanceof String) {
+		    params.put(name, vp.getValue());
+		} else if (vp.getValue() instanceof List) {
+		    params.put(name, getParameterValues(name));
+		}
+	    }
+	}
+
+	return params;
+    }
 }

Modified: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/css/fileUpload.xcss
===================================================================
--- trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/css/fileUpload.xcss	2008-01-31 13:11:16 UTC (rev 5746)
+++ trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/css/fileUpload.xcss	2008-01-31 14:18:58 UTC (rev 5747)
@@ -3,77 +3,91 @@
     xmlns:f="http://jsf.exadel.com/template"
     xmlns:u="http://jsf.exadel.com/template/util"
     xmlns="http://www.w3.org/1999/xhtml">
-	<f:verbatim>
-		*{
-			font-family: verdana;
-			font-size: 11px;
-		}
-		.file_item{
-			white-space: nowrap;
-		}
-		.file_delete_button{
-			border: 1px solid #CCCCCC;
-			padding: 1px;
-			width: 12px;
-			cursor: pointer;
-			float: left;
-			margin: 1px 2px 1px 7px;
-		}
-		.file_field{
-			float: left;
-			width: 200px;
-			height: 18px;
-			margin-bottom: 5px;
-		}
-		.file_bar_height{
-			height: 16px;
-		}
-		.file_bar_width{
-			width: 200px;
-		}
-		.file_bar_uploaded{
-			width: 99px;
-			overflow: hidden;
-			position: absolute;
-			border: 1px solid #cccccc;
-		}
-		.file_bar_shell{
-			position: relative;
-			margin-bottom: 2px;
-			float: left;
-		}
-		.file_bar_track{
-			background: #F1F1F1;
-			text-align: center;
-			border: 1px solid #cccccc;
-			color: #000000;
-			font-weight: bold;
-			position: absolute;
-		}
-		.file_bar_ststusline{
-			background: #FF9409;
-			text-align: center;
-			color: #FFFFFF;
-			font-weight: bold;
-			background-repeat: repeat-x;
-			position : absolute;
-		}
-		.file_stop_button{
-			border: 1px solid #CCCCCC;
-			padding: 0px 5px 0px 5px;
-			cursor: pointer;
-			float: left;
-			margin: 0px 0px 0px 2px;
-		}
-	</f:verbatim>
-	<u:selector name=".file_bar_ststusline">
-		<u:style name="background-image">
-			<f:resource f:key="/org/richfaces/renderkit/html/images/bg_uploaded.png"/>
-		</u:style>
-	</u:selector>	
-	<u:selector name=".file_stop_button">
-		<u:style name="background-image">
-			<f:resource f:key="/org/richfaces/renderkit/html/images/bg_button.png"/>
-		</u:style>
-	</u:selector>	
+    
+<f:verbatim><![CDATA[
+	
+body{margin : 20px}
+
+.upload_font{font-family : verdana /*generalFamilyFont*/ ; font-size : 11px/*generalSizeFont*/;}
+
+table{width : 100%}
+#upload_table td{border-bottom:1px solid #c0c0c0 /*tableBorderColor*/;white-space : nowrap;}
+
+.upload_list_width{ width:400px;}
+.upload_list_decor{ border:1px solid #c0c0c0 /*tableBorderColor*/; background : #FFFFFF /*tableBackgroundColor*/;}
+.upload_list_overflow{height : 210px; overflow : auto; overflow-x : hidden;}
+.upload_name{ width : 100%;  height : 50px; padding : 2px 10px 2px 10px;}
+.upload_del{ width : 90px; text-align : center; padding-top : 3; padding-bottom : 3;}
+.upload_scroll{ width : 10px; text-align : center;}
+.upload_anc{ color : ##0078D0/*generalLinkColor*/;}
+
+.upload_toolbar_decor{ background : #EAF0F8 /*additionalBackgroundColor*/;border-bottom:1px solid #c0c0c0 /*tableBorderColor*/;border-top:1px solid #FFFFFF /*tableBackgroundColor*/;border-left:1px solid #FFFFFF /*tableBackgroundColor*/;padding : 2px}
+
+
+.upload_bar_exterior{height : 7px;  border : 1px solid #c0c0c0 /*panelBorderColor*/;}
+.upload_bar_uploaded{height : 7px; width : 70%; height : 100%; background : #FF9409 /**/; background-image : url(images/bg_ProgressBar_perm.gif);background-repeat : repeat-x; font-size : 0px;}
+.upload_bar_deleted{height : 7px; width : 40%; height : 100%; background : #FF9409 /**/; background-image : url(images/bg_RegressBar_perm.gif);background-repeat : repeat-x; font-size : 0px;}
+.upload_bar_shell{height : 7px; width : 100%; height : 8; background : #F1F1F1/*tableSubfooterBackgroundColor*/;}
+
+
+.upload_button_border{
+	border : 1px solid #C0C0C0; /*tableBorderColor*/
+	margin : 2px;
+}
+.upload_button{
+	background : url(images/bg_header.png) /*from additionalBackgroundColor to trimColor*/  top left  #C6D6EA /*trimColor*/  repeat-x; 
+	cursor : pointer;  
+	padding : 2px; 
+}
+.upload_button_light{
+	background : url(images/bg_header.png) /*from additionalBackgroundColor to headerGradientColor*/ top left  #C6D6EA /*trimColor*/  repeat-x; 
+	border : 1px solid #E79A00; /*selectControlColor*/
+	cursor : pointer;  
+	padding : 1px; 
+}
+.upload_button_dis{
+	background : #C0C0C0;   /*tableBorderColor*/
+	border : 1px solid #C0C0C0;  /*tableBorderColor*/
+	margin-bottom : 3px;  
+	padding : 1px}
+.upload_button_press{
+	background : url(images/bg_press.png) /*from additionalBackgroundColor to trimColor*/ top left repeat-x #EAF0F8; /* additionalBackgroundColor*/
+	border : 1px solid #E79A00; /*selectControlColor*/
+	padding : 2px 0px 0px 2px;
+}
+a.upload_button_selection{
+	text-decoration : none;
+	color : #000000; /*generalTextColor*/
+	display : block;		
+}
+.upload_button_content{
+	padding : 2px 6px 2px 3px; 
+	text-align : left;
+	white-space : nowrap;
+}
+.upload_ico{
+	vertical-align: middle;
+	margin-right : 3px;
+}
+
+.upload_name_padding{padding : 2px 0px 2px 0px;}
+
+.upload_ico{background-position : 0px 50%; background-repeat : no-repeat; padding-left : 19px}
+.upload_ico_add{background-image : url(images/ico_add.gif)}
+.upload_ico_start{background-image : url(images/ico_start.gif)}
+.upload_ico_stop{background-image : url(images/ico_stop.gif)}
+.upload_ico_clear{background-image : url(images/ico_clear.gif)}
+
+input.hidden {
+	Z-INDEX: 2;
+    FILTER: alpha(opacity: 0);
+    POSITION: relative;
+    TEXT-ALIGN: left;
+    opacity: 0;
+    moz-opacity: 0;
+}
+]]>
+</f:verbatim>
+
+	
 </f:template>

Added: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/bg_ProgressBar_perm.gif
===================================================================
(Binary files differ)


Property changes on: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/bg_ProgressBar_perm.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Deleted: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/bg_button.png
===================================================================
(Binary files differ)

Added: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/bg_header.png
===================================================================
(Binary files differ)


Property changes on: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/bg_header.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/bg_press.png
===================================================================
(Binary files differ)


Property changes on: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/bg_press.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Deleted: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/bg_uploaded.png
===================================================================
(Binary files differ)

Added: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/ico_add.gif
===================================================================
(Binary files differ)


Property changes on: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/ico_add.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/ico_clear.gif
===================================================================
(Binary files differ)


Property changes on: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/ico_clear.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Deleted: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/ico_delete.gif
===================================================================
(Binary files differ)

Added: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/ico_start.gif
===================================================================
(Binary files differ)


Property changes on: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/ico_start.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/ico_stop.gif
===================================================================
(Binary files differ)


Property changes on: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/images/ico_stop.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js
===================================================================
--- trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js	                        (rev 0)
+++ trunk/sandbox/ui/fileUpload/src/main/resources/org/richfaces/renderkit/html/js/FileUpload.js	2008-01-31 14:18:58 UTC (rev 5747)
@@ -0,0 +1,208 @@
+FileUpload = {};
+FileUpload = Class.create();
+FileUpload.Uploaders = {};
+Object.extend(FileUpload.prototype, {
+    initialize: function() {
+    if (arguments.length > 0) {
+    	var id = arguments[0]; 
+			this.id = id;
+			this.f = $(id + ":files");
+			this.fm = $(id + ":f");
+		}
+    },
+    renderControl: function (template, context) {
+    if (!template) {
+    	return;
+    	}
+    	var html = template.invoke('getContent', context).join('');
+    	$(this.id + ":header").innerHTML = html;
+    },
+   	init: function (id) {
+   		this.id = id;
+		this.createForm();
+	},
+	test: function (ev) {
+		alert('Done;');
+	},
+	isUploading: function () {
+		if ($(this.id + ":status").value == "uploading") return true;
+		return false;
+	},
+	addFile: function (){
+		alert($(this.id + ":file"));
+		var o = $(this.id + ":file");
+		var parent = o.parentNode;
+		
+		var clon = o.cloneNode(true);
+		clon.id = this.id + ":file";
+		clon.name = "fileName";
+		
+		o.id = "add";
+		o.name = "add";
+		o.disabled = true;
+		o.style.display = "none";
+		
+		this.f.appendChild(o);
+		
+		parent.appendChild(clon);
+		
+		$(this.id + ":fileName").value = o.value;
+	},
+	addViewState: function () {
+	if (!this.fm['javax.faces.ViewState']) {
+		var d = document.createElement("input");
+		d.type="hidden";
+		d.name = "javax.faces.ViewState";
+		d.value = $("javax.faces.ViewState").value;
+		this.fm.appendChild(d);
+	}
+	},
+	beforeUploadFile: function(name) {
+		$(this.id + ":fileName").value = name;
+	},
+	beforeUploadAll: function() {
+		if (this.getFilesCount() > 0) {
+			$(this.id + ":fileName").value = this.f.childNodes[0].value;
+		}
+	},
+	upload: function (name) {
+		var v = this.findFileByName(name);
+		this.addViewState();
+		if (v) {
+			v.disabled = false;
+			v.name = this.id + ":1";
+			v.id = v.name;
+			this.fm.submit();
+		}
+	},
+	uploadFile: function (name) {
+	if (!this.isUploading()) {
+		this.addViewState();
+		var v = this.findFileByName(name);
+		if (v) {
+			v.disabled = false;
+			v.name = this.id + ":1";
+			v.id = v.name;
+			this.fm.submit();
+		}
+	}
+	},
+	uploadAll: function (name) {
+	if (!this.isUploading()) {
+		this.addViewState();
+		if (!$(this.id + ":1")) {
+			this.mark4upload();
+			if (name) {
+				this.uploadFile(name);
+			}
+
+		}
+	}else {
+		this.mark4upload();
+	}	
+	},
+	findFileToUpload: function () {
+		for (var i = 0; i < this.getFilesCount(); i++) {
+			var v = this.f.childNodes[i];
+			if (v.name == "4upload") return v;
+		}
+		return null;
+	},
+	onFileUploaded: function (ev) {
+		var formId = FileUpload.Uploaders[this.id]['formId'];
+		var containerId = FileUpload.Uploaders[this.id]['containerId'];
+		var actionUrl = FileUpload.Uploaders[this.id]['actionUrl'];
+		var f = {};
+		f[this.id] = this.id;
+		f[this.id + "_action"] = "upload";
+	 	A4J.AJAX.StopPoll(formId + ":progressBar");
+	 	new ProgressBar(this.id + ":progressBar").setValue(100);
+		A4J.AJAX.Submit(containerId,formId,ev,{'parameters':f ,'actionUrl':actionUrl} );
+	},
+	getForm: function () {
+		var p = $(this.id).parentNode;
+		while (p) {
+		if (p) {
+			if (p.tagName.toUpperCase() == "FORM") {
+				return p;
+			}
+		  }
+		  p = p.parentNode;
+		}
+		return null;
+	}, 
+	createForm: function (){
+	if ($(this.id + ":fr")) return;
+		var fr = document.createElement("iframe");
+		fr.id = this.id + ":fr";
+		fr.name = fr.id;
+		fr.style.display="none";
+		fr.src = "about:blank";
+		fr.onload = new Function ("event"," var f = new FileUpload('"+this.id+"'); if (f.getFilesCount() == 0) return;  alert('in onload'); f.onFileUploaded(event);");
+		
+		document.body.appendChild(fr);
+		
+		var f = document.createElement("form");
+		f.enctype = "multipart/form-data";
+		f.action = FileUpload.Uploaders[this.id]['actionUrl'];
+		f.method = "post";
+		f.id = this.id + ":f";
+		f.target = this.id + ":fr";
+		
+		document.body.appendChild(f);
+		
+		var d = document.createElement("div");
+		d.id = this.id + ":files";
+		f.appendChild(d);
+		//--
+		d = document.createElement("input");
+		d.type="hidden";
+		d.name = FileUpload.Uploaders[this.id]['formId'];
+		d.value = d.name;
+		f.appendChild(d);
+			
+			//--			
+
+	},
+	getFilesCount: function () {
+		if (this.f.hasChildNodes()) {
+			return this.f.childNodes.length;
+		}
+		return 0;
+	},
+	clearAll: function() {
+		if (this.f && this.f.hasChildNodes && this.f.removeChild) {
+			while (this.f.hasChildNodes()) {
+				this.f.removeChild(this.f.firstChild);
+			}
+		}
+	},
+	findFileByName: function(name) {
+				for (var i = 0; i < this.getFilesCount(); i++) {
+					var d = this.f.childNodes[i];
+					if (d.value == name)  { return d; }
+				}
+		return null;
+	},
+	clear: function (name) {
+		if (this.getFilesCount() == 0) {
+			return;
+		}
+		var v = this.findFileByName(name);
+		if (v) {
+			this.f.removeChild(v); 
+		}
+		$(this.id + ":fileName").value = name;
+	},
+	mark4upload: function() {
+		if (this.f && this.f.hasChildNodes && this.f.removeChild) {
+			for (var i = 0; i < this.getFilesCount(); i++) {
+				var v = this.f.childNodes[i];
+				if ((v.name != (this.id + ":1")) && (v.name != "done")) {
+					v.name = "4upload";
+					v.id = "4upload";
+				}
+			}
+		}
+	}
+	});

Modified: trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx
===================================================================
--- trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx	2008-01-31 13:11:16 UTC (rev 5746)
+++ trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload.jspx	2008-01-31 14:18:58 UTC (rev 5747)
@@ -9,37 +9,116 @@
 	<h:styles>
 		/org/richfaces/renderkit/html/css/fileUpload.xcss
 	</h:styles>	
+	
 	<h:scripts>
+			new org.ajax4jsf.javascript.PrototypeScript(),
+			new org.ajax4jsf.javascript.AjaxScript(),
+			/org/richfaces/renderkit/html/js/FileUpload.js,
 	</h:scripts>
-	<f:clientId var="clientId" />
-	<div id="#{clientId}">
-		<div>
-			<div class="file_item">
-				<input id="#{clientId}:1" name="#{clientId}:1" type="file" class="file_field">
-					<f:call name="utils.encodePassThruWithExclusions">
-						<f:parameter value="disabled" />
-					</f:call>
-				</input>
-				<f:resource name="/org/richfaces/renderkit/html/images/ico_delete.gif" var="ico_delete"/>
-				<div class="file_delete_button"><img src="#{ico_delete}" width="12" height="12" alt="" border="0" /></div>
-			</div>
-		</div>
-		<div class="file_stop_button file_bar_height">Upload</div>
-		<!-- div class="file_item">
-			<div class="file_bar_height file_bar_width file_bar_shell">
-				<div class="file_bar_height file_bar_width file_bar_track">
-					50%
+	
+	<f:resource
+		name="/org/richfaces/renderkit/html/images/ico_file_32.gif" var="icon" />
+		
+<jsp:scriptlet>
+	<![CDATA[
+		variables.setVariable("url",getActionUrl(context));
+]]>
+</jsp:scriptlet>
+	
+<f:clientId var="clientId" />
+
+<div class="upload_list_width upload_list_decor" id="#{clientId}">
+
+	<input type="hidden" name="fileName" id="#{clientId}:fileName" />
+	<input type="hidden" name="status" id="#{clientId}:status" value="#{this:encodeStatus(component)}" />
+				
+	<div class="upload_list_width upload_list_overflow">
+	<table border="0" cellpadding="0" cellspacing="0" width="100%" id="#{clientId}:upload_table">
+	<jsp:scriptlet>
+	<![CDATA[
+	 	Iterator<org.richfaces.org.jboss.seam.ui.component.FileItem> it = component.getFileItems().iterator();
+	 	while (it.hasNext()) {
+	 	   org.richfaces.org.jboss.seam.ui.component.FileItem item = it.next();
+	 	    String fileName = item.getFullFileName();
+	 	    String fileNameJs = convertFileName(item.getFullFileName());
+	 	   variables.setVariable("fileName",fileName);
+	 	  variables.setVariable("fileNameJs",fileNameJs);
+	 	   ]]>
+	</jsp:scriptlet>
+	<tr>
+				<td>
+					<div class="upload_font upload_icon"><img src="#{icon}" width="32" height="32" alt="" border="0" /></div>
+				</td>
+				<td>
+					<div class="upload_font upload_name">
+						#{fileName}
+					</div>
+					
+					<div class="upload_font upload_name">
+					<jsp:scriptlet>
+					<![CDATA[
+				encodeFileItemStatus(context,component,item);
+					 	   ]]>
+					</jsp:scriptlet>
+					</div>
+
+				</td>
+				<td>	
+					<div class="upload_font upload_del"><a href="#" onclick="new FileUpload('#{clientId}').clear('#{fileNameJs}'); #{this:getActionOnClick(context,component,'CLEAR','false')}; return false;" 
+						 class="upload_anc">Delete</a></div>
+					<div class="upload_font upload_del"><a href="#" class="upload_anc" onclick="new FileUpload('#{clientId}').beforeUploadFile('#{fileNameJs}'); #{this:getActionOnClick(context,component,'UPLOAD','true')}; return false;">Upload</a></div>
+				</td>
+				<td>
+					<div class="upload_font upload_scroll"></div>
+				</td>
+			</tr>	
+	<jsp:scriptlet>
+	<![CDATA[
+	 	}
+	]]>
+	</jsp:scriptlet>
+	</table>
+	</div>
+	<a href="#" onclick="new FileUpload('#{clientId}').test(event);">crack</a>	
+	<div class="upload_list_width upload_footer_decor">
+		<table border="0" cellpadding="0" cellspacing="0" id="upload_footer" style="width: 100%">
+			<tr>
+				<td class="upload_footer_firstcol" style="width: 40px; position: relative; text-align: left;">
+				<div style="overflow: hidden; left: 7px; direction: rtl; position: relative; width: 48px;">
+					<input value="...Add" type="Button" class="upload_btn_over upload_font" onmouseover="this.className='upload_btn_over upload_font'" onmouseout="this.className='upload_btn_over upload_font'" onmousedown="this.className='upload_btn_press upload_font'"
+					style="position: relative; width: 40px; top: 0px" />
+					 <input type="file"
+			        style="cursor: pointer; z-index: 3; left: 0px; height: 30px; position: absolute; top: 0px"
+			        class="hidden"
+			        onchange="new FileUpload('#{clientId}').addFile(this); #{this:getActionOnClick(context,component,'ADD','false')}; return false;" />
 				</div>
-				<div class="file_bar_height file_bar_uploaded">
-					<div class="file_bar_height file_bar_width file_bar_ststusline">
-						50%
+				</td>
+				<td style="position: relative; text-align: left; padding-left: 7px;">
+					<input style="padding-left : 10; padding-right : 10; font-weight : bold" value="Upload" type="Button" class="upload_btn_over upload_font" 
+							onmouseover="this.className='upload_btn_over upload_font'" 
+							onmouseout="this.className='upload_btn_over upload_font'" 
+							onmousedown="this.className='upload_btn_press upload_font'" 
+							onclick="new FileUpload('#{clientId}').uploadAll(); return false;" />
+
+				</td>
+				<td style="position: relative; text-align: right; width: 10px">
+					<div class="upload_font upload_footer_del">
+						<input value="Clear" type="Button" class="upload_btn_over upload_font" onmouseover="this.className='upload_btn_over upload_font'" onmouseout="this.className='upload_btn_over upload_font'" 
+								onmousedown="this.className='upload_btn_press upload_font'"
+								onclick="new FileUpload('#{clientId}').clearAll(); #{this:getActionOnClick(context,component,'CLEARALL','false')}; return false;" />
 					</div>
-				</div>
-			</div>
-			<div class="file_stop_button file_bar_height">Stop</div>
-		</div>
-		Uploaded 200Kb from 500Kb -->
+				</td>
+				<td>
+					<div class="upload_font  upload_scroll">
+					</div>
+				</td>
+			</tr>
+		</table>
 	</div>
+	<script>
+		new FileUpload('#{clientId}').init('#{url}');
+	</script>
+</div>
 </f:root>	
 	
 	

Added: trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload2.jspx
===================================================================
--- trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload2.jspx	                        (rev 0)
+++ trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload2.jspx	2008-01-31 14:18:58 UTC (rev 5747)
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<f:root 
+	xmlns:f="http://ajax4jsf.org/cdk/template" 
+	xmlns:h=" http://ajax4jsf.org/cdk/headers"
+	class="org.richfaces.renderkit.html.FileUploadRenderer"
+	baseclass="org.richfaces.org.jboss.seam.ui.renderkit.FileUploadRendererBase"
+	component="org.richfaces.org.jboss.seam.ui.component.UIFileUpload" 
+	>	
+	<h:styles>
+		/org/richfaces/renderkit/html/css/fileUpload.xcss
+	</h:styles>	
+	
+	<h:scripts>
+			new org.ajax4jsf.javascript.PrototypeScript(),
+			new org.ajax4jsf.javascript.AjaxScript(),
+			/org/richfaces/renderkit/html/scripts/utils.js,
+			/org/richfaces/renderkit/html/scripts/json/json-dom.js,
+			/org/richfaces/renderkit/html/js/FileUpload.js,
+	</h:scripts>
+	
+	<f:clientId var="clientId" />
+	
+<div class="upload_list_width upload_list_decor" id="#{clientId}">
+	<table class="upload_toolbar_decor">
+		<tr>
+			<td id="#{clientId}:header"></td>
+		</tr>
+	</table>
+	<script>
+		
+		new FileUpload('#{clientId}').renderControl(<f:call name="encodeControlsMarkup" />,
+			{'add': "<f:call name='encodeAddControl' />",
+			 'upload': "<f:call name='encodeUploadControl' />",
+			 'clean': "<f:call name='encodeCleanControl' />"});
+	</script>
+	<div class="upload_list_width upload_list_overflow">
+
+		<table border="0" cellpadding="0" cellspacing="0" id="upload_table">
+			<tr>
+				<td class="upload_font upload_name">
+					<div class="upload_name_padding">
+						file_upload.html
+					</div>
+
+						
+					<!--div class="upload_bar_exterior">
+						<div class="upload_bar_shell">
+							<div class="upload_bar_uploaded">
+								
+							</div>
+						</div>
+					</div-->
+
+					<div class="upload_name_padding">
+						<b>Done</b>
+					</div>
+
+					
+				</td>
+				<td>
+					<div class="upload_font upload_del"><a href="#" class="upload_anc">Clear</a></div>
+					<div class="upload_font upload_del"><br /></div>
+				</td>
+				<td>
+					<div class="upload_font upload_scroll"></div>
+				</td>
+			</tr>
+		</table>
+	</div>
+</div>
+	
+	
+</f:root>	
\ No newline at end of file

Added: trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload3.jspx
===================================================================
--- trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload3.jspx	                        (rev 0)
+++ trunk/sandbox/ui/fileUpload/src/main/templates/org/richfaces/fileUpload3.jspx	2008-01-31 14:18:58 UTC (rev 5747)
@@ -0,0 +1,136 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<f:root 
+	xmlns:f="http://ajax4jsf.org/cdk/template" 
+	xmlns:h=" http://ajax4jsf.org/cdk/headers"
+	class="org.richfaces.renderkit.html.FileUploadRenderer"
+	baseclass="org.richfaces.org.jboss.seam.ui.renderkit.FileUploadRendererBase"
+	component="org.richfaces.org.jboss.seam.ui.component.UIFileUpload"
+	>
+	<h:styles>
+		/org/richfaces/renderkit/html/css/fileUpload.xcss,
+		/org/richfaces/renderkit/html/css/progressBar.xcss
+	</h:styles>
+	
+	<h:scripts>
+			new org.ajax4jsf.javascript.PrototypeScript(),
+			new org.ajax4jsf.javascript.AjaxScript(),
+			/org/richfaces/renderkit/html/scripts/utils.js,
+			/org/richfaces/renderkit/html/scripts/json/json-dom.js,
+			/org/richfaces/renderkit/html/js/FileUpload.js,
+			/org/richfaces/renderkit/html/js/progressBar.js,
+	</h:scripts>
+	
+	<f:clientId var="clientId" />
+	
+<div class="upload_list_width upload_list_decor" id="#{clientId}">
+
+	<table class="upload_toolbar_decor">
+		<tr>
+			<td>
+				<div class="upload_button_border" style=" float:left;">
+					<div class="upload_button upload_font" onmouseover="this.className='upload_button_light upload_font'" onmousedown="this.className='upload_button_press upload_font'" onmouseup="this.className='upload_button upload_font'" onmouseout="this.className='upload_button upload_font'"
+						 style="position: relative; overflow: hidden; direction: rtl; width:70px">
+						<div class="upload_button_content upload_font upload_ico upload_ico_add" style="">Add...</div>
+						<input type="file" style="cursor: pointer; z-index: 3; width: 0px; height: 22px; left: 0px; top: 0px; position: absolute" 
+							   class="hidden"
+							   id="#{clientId}:file"
+							   name="fileName"
+							   onchange="#{this:getAddFileClick(context,component)}; return false;"/>
+					</div>
+				</div>
+				<div class="upload_button_border" style=" float:left;">
+					<div class="upload_button upload_font" onmouseover="this.className='upload_button_light upload_font'" onmousedown="this.className='upload_button_press upload_font'" onmouseup="this.className='upload_button upload_font'" 
+						 onmouseout="this.className='upload_button upload_font'"
+						 onclick="javascript: if ((new FileUpload('#{clientId}').getFilesCount()) > 0) { #{this:getUploadAllClick(context, component)} }">
+						<a href="#" class="upload_button_selection">
+							<div class="upload_button_content upload_font upload_ico upload_ico_start"><b>Upload</b>
+							</div>
+						</a>
+					</div>
+				</div>
+				<div class="upload_button_border" style=" float:right">
+					<div class="upload_button upload_font" onmouseover="this.className='upload_button_light upload_font'" onmousedown="this.className='upload_button_press upload_font'" onmouseup="this.className='upload_button upload_font'" onmouseout="this.className='upload_button upload_font'">
+						<a href="#" class="upload_button_selection">
+							<div class="upload_button_content upload_font upload_ico upload_ico_clear">Clear All</div>
+						</a>
+					</div>
+				</div>
+			</td>
+		</tr>
+	</table>
+
+	<div class="upload_list_width upload_list_overflow" id="#{clientId}:fileItems">
+	
+	<jsp:scriptlet>
+	<![CDATA[
+	 	Iterator<org.richfaces.org.jboss.seam.ui.component.FileItem> it = component.getFileItems().iterator();
+	 	while (it.hasNext()) {
+	 	   	org.richfaces.org.jboss.seam.ui.component.FileItem item = it.next();
+	 	    	String fullFileName = item.getFullFileName();
+	 	    	String fileName = item.getFileName();
+	 	   	variables.setVariable("fileName",fileName);
+	 	  	variables.setVariable("fullFileName",fullFileName);
+	 	   ]]>
+	</jsp:scriptlet>
+
+		<table border="0" cellpadding="0" cellspacing="0">
+			<tr>
+				<td class="upload_font upload_name">
+					<div class="upload_name_padding">
+						#{fileName}
+					</div>
+
+					<jsp:scriptlet>
+						<![CDATA[
+					renderProgress(context, component, item);
+						  ]]>
+					</jsp:scriptlet>
+					
+					
+					<div class="upload_name_padding">
+						<b>
+							<jsp:scriptlet>
+								<![CDATA[
+								renderLabel(context, component, item);
+						  		]]>
+							</jsp:scriptlet>
+						</b>
+					</div>
+
+					
+				</td>
+				<td>
+					<div class="upload_font upload_del">
+						<a href="#" class="upload_anc" onclick="#{this:getClearFileClick(context, component)}">Clear</a>
+					</div>
+					<div class="upload_font upload_del"><br /></div>
+				</td>
+				<td>
+					<div class="upload_font upload_scroll"></div>
+				</td>
+			</tr>
+		</table>
+		
+		<span>
+			<script type="text/javascript">
+				<f:call name="encodeUploadScript" />
+			</script>
+		</span>
+		
+		<jsp:scriptlet>
+	<![CDATA[
+	 	}
+	]]>
+	</jsp:scriptlet>
+		
+	</div>
+	
+	<span>
+		<script type="text/javascript">
+			<f:call name="encodeInitialScript" />
+		</script>
+	</span>
+</div>
+	
+	
+</f:root>	
\ No newline at end of file




More information about the richfaces-svn-commits mailing list