package fileUpload;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.richfaces.event.UploadEvent;
import org.richfaces.model.UploadItem;

public class FileUpload {
	private boolean disabled;
	private boolean autoclear;
	private boolean rendered;
	private boolean required;
	private String acceptedTypes;
	private String requiredMessage;
	private String listHeight;
	private String listWidth;
	private List data;
	private Integer maxFilesQuantity;
        
	public FileUpload() { 
		data = new ArrayList();
		disabled = false;
		autoclear = false;
		rendered = true;
		required = false;
		acceptedTypes = "*";
		requiredMessage = "requiredMessage";
		listHeight = "200px";
		listWidth = "150px";
		maxFilesQuantity = 3;
	}

	public void fileUploadListener(UploadEvent event) throws IOException{
		 UploadItem upload = event.getUploadItem();
		if (upload.isFile()) {
	    	File file = upload.getFile();
	    	System.out.println("FileUpload.fileUploadListener()");
	    } else {
	    	ByteArrayOutputStream b = new ByteArrayOutputStream();
	    	b.write(upload.getData());
	    }
		System.out.println("FileUpload.fileUploadListener()");
	}

	public boolean isDisabled() {
		return disabled;
	}

	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}

	public boolean isAutoclear() {
		return autoclear;
	}

	public void setAutoclear(boolean autoclear) {
		this.autoclear = autoclear;
	}

	public boolean isRendered() {
		return rendered;
	}

	public void setRendered(boolean rendered) {
		this.rendered = rendered;
	}

	public boolean isRequired() {
		return required;
	}

	public void setRequired(boolean required) {
		this.required = required;
	}

	public String getRequiredMessage() {
		return requiredMessage;
	}

	public void setRequiredMessage(String requiredMessage) {
		this.requiredMessage = requiredMessage;
	}

	public Integer getMaxFilesQuantity() {
		return maxFilesQuantity;
	}

	public void setMaxFilesQuantity(Integer maxFilesQuantity) {
		this.maxFilesQuantity = maxFilesQuantity;
	}

	public String getListHeight() {
		return listHeight;
	}

	public void setListHeight(String listHeight) {
		this.listHeight = listHeight;
	}

	public String getListWidth() {
		return listWidth;
	}

	public void setListWidth(String listWidth) {
		this.listWidth = listWidth;
	}

	public String getAcceptedTypes() {
		return acceptedTypes;
	}

	public void setAcceptedTypes(String acceptedTypes) {
		this.acceptedTypes = acceptedTypes;
	}

	public List getData() {
		for(int i = 0; i < data.size(); i++)
			System.out.println(data.get(i));
		return data;
	}

	public void setData(List data) {
		this.data = data;
	}
}
