Author: andrei_exadel
Date: 2008-03-03 08:28:14 -0500 (Mon, 03 Mar 2008)
New Revision: 6485
Added:
trunk/framework/api/src/main/java/org/richfaces/model/UploadItem.java
Modified:
trunk/framework/api/src/main/java/org/richfaces/event/UploadEvent.java
Log:
Add UploadItem class; UploadEvent refactoring
Modified: trunk/framework/api/src/main/java/org/richfaces/event/UploadEvent.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/event/UploadEvent.java 2008-03-03
11:26:10 UTC (rev 6484)
+++ trunk/framework/api/src/main/java/org/richfaces/event/UploadEvent.java 2008-03-03
13:28:14 UTC (rev 6485)
@@ -20,42 +20,24 @@
*/
package org.richfaces.event;
-import java.io.File;
-
import javax.faces.component.UIComponent;
import javax.faces.event.FacesEvent;
import javax.faces.event.FacesListener;
+import org.richfaces.model.UploadItem;
+
public class UploadEvent extends FacesEvent{
private static final long serialVersionUID = -7645197191376210068L;
- private File file = null;
- private byte [] data= null;
- private String fileName = null;
+ private UploadItem uploadItem = null;
- public UploadEvent(UIComponent component, Object file, String fileName) {
+ public UploadEvent(UIComponent component, UploadItem uploadItem) {
super(component);
- this.fileName = fileName;
- init(file);
+ this.uploadItem = uploadItem;
}
- private void init (Object file) {
- if (null == file) {
- return;
- }
- if (file.getClass().isAssignableFrom(File.class)) {
- this.file = (File)file;
- }else if (file.getClass().isAssignableFrom(byte[].class)) {
- this.data = (byte[])file;
- }
- }
- public boolean isFile () {
- return (null != file);
- }
-
-
public boolean isAppropriateListener(FacesListener listener) {
return false;
}
@@ -65,20 +47,10 @@
}
-
- public File getFile() {
- return file;
- }
-
- public String getFileName() {
- return fileName;
- }
-
/**
- * @return the fileData
+ * @return the uploadItem
*/
- public byte[] getData() {
- return data;
+ public UploadItem getUploadItem() {
+ return uploadItem;
}
-
}
Added: trunk/framework/api/src/main/java/org/richfaces/model/UploadItem.java
===================================================================
--- trunk/framework/api/src/main/java/org/richfaces/model/UploadItem.java
(rev 0)
+++ trunk/framework/api/src/main/java/org/richfaces/model/UploadItem.java 2008-03-03
13:28:14 UTC (rev 6485)
@@ -0,0 +1,74 @@
+/*
+ * UploadItem.java Date created: 03.03.2008
+ * Last modified by: $Author$
+ * $Revision$ $Date$
+ */
+
+package org.richfaces.model;
+
+import java.io.File;
+
+/**
+ * Class provides object holder for file uploaded.
+ * Instance of this type will be returned by UploadEvent after appropriate listener
called after uploading has been completed.
+ * @author "Andrey Markavtsov"
+ *
+ */
+public class UploadItem {
+
+ /** Users file name */
+ private String fileName;
+
+ /** java.io.File instance */
+ private File file;
+
+ /** File byte content */
+ private byte [] bytes;
+
+ /**
+ * Constructor for the UploadItem
+ */
+ public UploadItem(String fileName, Object file) {
+ this.fileName = fileName;
+ if (null != file) {
+ if (file.getClass().isAssignableFrom(File.class)) {
+ this.file = (File)file;
+ }
+ }else if (file.getClass().isAssignableFrom(byte[].class)) {
+ this.bytes = (byte [])file;
+ }
+ }
+
+ /**
+ * Return true if file is holding as java.io.File type.
+ * If true getFile method should be invoked to get file uploaded.
+ * In another case getData method should be invoked to get file's bytes.
+ * @return
+ */
+ public boolean isFile () {
+ return (null != file);
+ }
+
+ /**
+ * @return the file
+ */
+ public File getFile() {
+ return file;
+ }
+
+ /**
+ * @return the bytes
+ */
+ public byte[] getData() {
+ return bytes;
+ }
+
+ /**
+ * @return the fileName
+ */
+ public String getFileName() {
+ return fileName;
+ }
+
+
+}
Show replies by date