Author: konstantin.mishin
Date: 2010-11-30 13:51:54 -0500 (Tue, 30 Nov 2010)
New Revision: 20242
Modified:
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/context/FileUploadPartialViewContextFactory.java
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/request/MultipartRequest.java
Log:
RF-9497
Modified:
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java
===================================================================
---
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java 2010-11-30
16:45:23 UTC (rev 20241)
+++
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/component/AbstractFileUpload.java 2010-11-30
18:51:54 UTC (rev 20242)
@@ -37,6 +37,7 @@
import org.richfaces.cdk.annotations.JsfComponent;
import org.richfaces.cdk.annotations.JsfRenderer;
import org.richfaces.cdk.annotations.Tag;
+import org.richfaces.context.FileUploadPartialViewContextFactory;
import org.richfaces.event.FileUploadListener;
import org.richfaces.event.UploadEvent;
import org.richfaces.request.MultipartRequest;
@@ -46,13 +47,20 @@
*
*/
@JsfComponent(tag = @Tag(handler =
"org.richfaces.view.facelets.FileUploadHandler"),
- renderer = @JsfRenderer(type = "org.richfaces.FileUploadRenderer"))
+ renderer = @JsfRenderer(type = "org.richfaces.FileUploadRenderer"),
+ attributes = {"events-props.xml", "core-props.xml",
"i18n-props.xml"})
@ListenerFor(systemEventClass = PostAddToViewEvent.class)
public abstract class AbstractFileUpload extends UIComponentBase implements
ComponentSystemEventListener {
+ @Attribute
+ public abstract String getAcceptedTypes();
+
@Attribute(defaultValue = "true")
public abstract boolean isEnabled();
+ @Attribute(defaultValue = "false")
+ public abstract boolean isNoDuplicate();
+
@Attribute(events = @EventName("filesubmit"))
public abstract String getOnfilesubmit();
@@ -68,21 +76,23 @@
}
}
- public boolean isListenerForSource(Object source) {
- return true;
- }
-
public void processEvent(ComponentSystemEvent event) throws AbortProcessingException
{
+ FacesContext context = getFacesContext();
Map<String, UIComponent> facets = getFacets();
UIComponent component = facets.get("progress");
if (component == null) {
- FacesContext context = getFacesContext();
- UIComponent pb = context.getApplication().createComponent(context,
AbstractProgressBar.COMPONENT_TYPE,
+ component = context.getApplication().createComponent(context,
AbstractProgressBar.COMPONENT_TYPE,
"org.richfaces.ProgressBarRenderer");
- pb.setId(getId() + "_pb");
- facets.put("progress", pb);
+ component.setId(getId() + "_pb");
+ facets.put("progress", component);
}
+ component.setValueExpression("value",
context.getApplication().getExpressionFactory()
+ .createValueExpression(context.getELContext(),
+ "#{" + MultipartRequest.PERCENT_BEAN_NAME +
"[param['"
+ + FileUploadPartialViewContextFactory.UID_KEY + "']]}",
Integer.class));
+
}
+
/**
* <p>Add a new {@link FileUploadListener} to the set of listeners
* interested in being notified when {@link UploadEvent}s occur.</p>
@@ -95,7 +105,6 @@
addFacesListener(listener);
}
-
/**
* <p>Return the set of registered {@link FileUploadListener}s for this
* {@link AbstractFileUpload} instance. If there are no registered listeners,
@@ -105,7 +114,6 @@
return (FileUploadListener[]) getFacesListeners(FileUploadListener.class);
}
-
/**
* <p>Remove an existing {@link FileUploadListener} (if any) from the
* set of listeners interested in being notified when
Modified:
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/context/FileUploadPartialViewContextFactory.java
===================================================================
---
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/context/FileUploadPartialViewContextFactory.java 2010-11-30
16:45:23 UTC (rev 20241)
+++
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/context/FileUploadPartialViewContextFactory.java 2010-11-30
18:51:54 UTC (rev 20242)
@@ -48,6 +48,8 @@
*/
public class FileUploadPartialViewContextFactory extends PartialViewContextFactory {
+ public static final String UID_KEY = "rf_fu_uid";
+
private static enum ResponseState {
size_exceeded, stopped, server_error
};
@@ -56,12 +58,10 @@
private static final Pattern AMPERSAND = Pattern.compile("&+");
- private static final String UID_KEY = "rf_fu_uid";
-
private PartialViewContextFactory parentFactory;
/** Flag indicating whether a temporary file should be used to cache the uploaded
file */
- private boolean createTempFiles = false;
+ private boolean createTempFiles = true;
private String tempFilesDirectory;
@@ -74,12 +74,8 @@
String param = context.getInitParameter("createTempFiles");
if (param != null) {
this.createTempFiles = Boolean.parseBoolean(param);
- } else {
- this.createTempFiles = true;
}
-
this.tempFilesDirectory =
context.getInitParameter("tempFilesDirectory");
-
param = context.getInitParameter("maxRequestSize");
if (param != null) {
this.maxRequestSize = Integer.parseInt(param);
Modified:
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/request/MultipartRequest.java
===================================================================
---
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/request/MultipartRequest.java 2010-11-30
16:45:23 UTC (rev 20241)
+++
sandbox/trunk/ui/fileupload/ui/src/main/java/org/richfaces/request/MultipartRequest.java 2010-11-30
18:51:54 UTC (rev 20242)
@@ -53,6 +53,9 @@
public static final String TEXT_HTML = "text/html";
+ /** Session bean name where progress bar's percent map will be stored */
+ public static final String PERCENT_BEAN_NAME =
"_richfaces_upload_percents";
+
private static final BytesHandler NOOP_HANDLER = new BytesHandler() {
public void handle(byte[] bytes, int length) {
// do nothing
@@ -62,9 +65,6 @@
/** Session bean name where request size will be stored */
private static final String REQUEST_SIZE_BEAN_NAME =
"_richfaces_request_size";
- /** Session bean name where progress bar's percent map will be stored */
- private static final String PERCENT_BEAN_NAME =
"_richfaces_upload_percents";
-
private static final String PARAM_NAME = "name";
private static final String PARAM_FILENAME = "filename";
private static final String PARAM_CONTENT_TYPE = "Content-Type";
@@ -77,8 +77,8 @@
private static final byte CR = 0x0d;
private static final byte LF = 0x0a;
- private static final byte[] CR_LF = { CR, LF };
- private static final byte[] HYPHENS = { 0x2d, 0x2d }; // '--'
+ private static final byte[] CR_LF = {CR, LF};
+ private static final byte[] HYPHENS = {0x2d, 0x2d}; // '--'
private static final Pattern PARAM_VALUE_PATTERN =
Pattern.compile("^\\s*([^\\s=]+)\\s*[=:]\\s*(.+)\\s*$");
@@ -592,7 +592,7 @@
vals.toArray(values);
return values;
} else {
- return new String[] { (String) vp.getValue() };
+ return new String[] {(String) vp.getValue()};
}
} else {
return super.getParameterValues(name);