Author: nbelaevski
Date: 2009-03-12 12:53:32 -0400 (Thu, 12 Mar 2009)
New Revision: 12937
Added:
trunk/framework/impl/src/main/java/org/ajax4jsf/request/MultipartRequestRegistry.java
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/request/MultipartRequest.java
trunk/framework/impl/src/main/java/org/richfaces/component/FileUploadConstants.java
Log:
https://jira.jboss.org/jira/browse/RF-4761
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/request/MultipartRequest.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/request/MultipartRequest.java 2009-03-12
16:41:45 UTC (rev 12936)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/request/MultipartRequest.java 2009-03-12
16:53:32 UTC (rev 12937)
@@ -81,8 +81,14 @@
private Map<String, Object> percentMap = null;
- private Map<String, MultipartRequest> requestsMap = null;
-
+ private Map<String, Integer> requestSizeMap = null;
+
+ private Map<String, String> requestKeysMap = null;
+
+ private String requestKey = null;
+
+ private MultipartRequestRegistry requestRegistry;
+
private List<String> keys = new ArrayList<String>();
private enum ReadState {
@@ -613,9 +619,28 @@
}
}
+ public static MultipartRequest lookupRequest(FacesContext context, String uploadId) {
+ Map<String, Object> sessionMap = context.getExternalContext().getSessionMap();
+ Map<String, String> requestKeys = (Map<String, String>)
sessionMap.get(FileUploadConstants.REQUEST_KEYS_BEAN_NAME);
+ if (requestKeys != null) {
+ String requestKey = requestKeys.get(uploadId);
+ if (requestKey != null) {
+ MultipartRequestRegistry requestRegistry =
MultipartRequestRegistry.getInstance(context);
+ if (requestRegistry != null) {
+ MultipartRequest request = requestRegistry.getRequest(requestKey);
+ if (request != null) {
+ return request;
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
@SuppressWarnings("unchecked")
private void setupProgressData() {
- if (percentMap == null || requestsMap == null) {
+ if (percentMap == null || requestSizeMap == null || requestKeysMap == null) {
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext != null) {
ExternalContext externalContext = facesContext.getExternalContext();
@@ -631,18 +656,34 @@
percentMap = new ConcurrentHashMap<String, Object>();
sessionMap.put(FileUploadConstants.PERCENT_BEAN_NAME, percentMap);
}
- percentMap.put(uploadId, Double.valueOf(0));
}
- if (requestsMap == null) {
- requestsMap = (Map<String, MultipartRequest>)
sessionMap.get(FileUploadConstants.REQUESTS_SESSIONS_BEAN_NAME);
- if (requestsMap == null) {
- requestsMap = new ConcurrentHashMap<String, MultipartRequest>();
- sessionMap.put(FileUploadConstants.REQUESTS_SESSIONS_BEAN_NAME, requestsMap);
+ if (requestSizeMap == null) {
+ requestSizeMap = (Map<String, Integer>)
sessionMap.get(FileUploadConstants.REQUEST_SIZE_BEAN_NAME);
+ if (requestSizeMap == null) {
+ requestSizeMap = new ConcurrentHashMap<String, Integer>();
+ sessionMap.put(FileUploadConstants.REQUEST_SIZE_BEAN_NAME, requestSizeMap);
}
- requestsMap.put(uploadId, this);
}
+
+ if (requestKeysMap == null) {
+ requestKeysMap = (Map<String, String>)
sessionMap.get(FileUploadConstants.REQUEST_KEYS_BEAN_NAME);
+ if (requestKeysMap == null) {
+ requestKeysMap = new ConcurrentHashMap<String, String>();
+ sessionMap.put(FileUploadConstants.REQUEST_KEYS_BEAN_NAME, requestKeysMap);
+ }
+
+ }
}
+
+ percentMap.put(uploadId, Double.valueOf(0));
+
+ requestSizeMap.put(uploadId, getSize());
+
+ requestRegistry = MultipartRequestRegistry.getInstance(facesContext);
+ requestKey = requestRegistry.registerRequest(this);
+ requestKeysMap.put(uploadId, requestKey);
+
}
}
}
@@ -916,8 +957,16 @@
percentMap.remove(uploadId);
}
- if (requestsMap != null) {
- requestsMap.remove(uploadId);
+ if (requestSizeMap != null) {
+ requestSizeMap.remove(uploadId);
}
+
+ if (requestKeysMap != null) {
+ requestKeysMap.remove(uploadId);
+ }
+
+ if (requestRegistry != null) {
+ requestRegistry.removeRequest(requestKey);
+ }
}
}
Added:
trunk/framework/impl/src/main/java/org/ajax4jsf/request/MultipartRequestRegistry.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/request/MultipartRequestRegistry.java
(rev 0)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/request/MultipartRequestRegistry.java 2009-03-12
16:53:32 UTC (rev 12937)
@@ -0,0 +1,80 @@
+/**
+ * License Agreement.
+ *
+ * JBoss RichFaces - Ajax4jsf Component Library
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.ajax4jsf.request;
+
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.faces.context.FacesContext;
+
+/**
+ * @author Nick Belaevski
+ * @since 3.3.1
+ */
+
+public class MultipartRequestRegistry {
+
+ private AtomicInteger atomicInteger = new AtomicInteger(0);
+
+ private String registryId = UUID.randomUUID().toString();
+
+ private Map<String, MultipartRequest> requestsMap = new
ConcurrentHashMap<String, MultipartRequest>();
+
+ private static final String REGISTRY_ATTRIBUTE_NAME =
MultipartRequestRegistry.class.getName();
+
+ private MultipartRequestRegistry() {
+
+ }
+
+ public static MultipartRequestRegistry getInstance(FacesContext context) {
+ Map<String, Object> applicationMap =
context.getExternalContext().getApplicationMap();
+ MultipartRequestRegistry requestRegistry = (MultipartRequestRegistry)
applicationMap.get(REGISTRY_ATTRIBUTE_NAME);
+ if (requestRegistry == null) {
+ synchronized (applicationMap) {
+ requestRegistry = (MultipartRequestRegistry)
applicationMap.get(REGISTRY_ATTRIBUTE_NAME);
+ if (requestRegistry == null) {
+ requestRegistry = new MultipartRequestRegistry();
+ applicationMap.put(REGISTRY_ATTRIBUTE_NAME, requestRegistry);
+ }
+ }
+ }
+
+ return requestRegistry;
+ }
+
+ public String registerRequest(MultipartRequest request) {
+ String key = registryId + ":" + atomicInteger.incrementAndGet();
+ requestsMap.put(key, request);
+
+ return key;
+ }
+
+ public void removeRequest(String key) {
+ requestsMap.remove(key);
+ }
+
+ public MultipartRequest getRequest(String key) {
+ return requestsMap.get(key);
+ }
+}
Modified:
trunk/framework/impl/src/main/java/org/richfaces/component/FileUploadConstants.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/component/FileUploadConstants.java 2009-03-12
16:41:45 UTC (rev 12936)
+++
trunk/framework/impl/src/main/java/org/richfaces/component/FileUploadConstants.java 2009-03-12
16:53:32 UTC (rev 12937)
@@ -40,12 +40,17 @@
/** Request parameter name indicated that file was uploaded by RF component */
public static final String FILE_UPLOAD_INDICATOR =
"_richfaces_upload_file_indicator";
- /** Session bean name where multipart requests map will be stored */
- public static final String REQUESTS_SESSIONS_BEAN_NAME =
"_richfaces_upload_sessions";
+ /** Session bean name where request size will be stored */
+ public static final String REQUEST_SIZE_BEAN_NAME =
"_richfaces_request_size";
/** Session bean name where progress bar's percent map will be stored */
public static final String PERCENT_BEAN_NAME = "_richfaces_upload_percents";
+ /** Session bean name where stop keys will be stored */
+ public static final String REQUEST_KEYS_BEAN_NAME =
"_richfaces_request_keys";
+
+ public static final String FILE_UPLOAD_ACTION_STOP =
"richfaces_file_upload_action_stop";
+
private FileUploadConstants() {
//private constructor
}