/* * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * "The contents of this file are subject to the Mozilla Public License * Version 1.1 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations under * the License. * * The Original Code is ICEfaces 1.5 open source software code, released * November 5, 2006. The Initial Developer of the Original Code is ICEsoft * Technologies Canada, Corp. Portions created by ICEsoft are Copyright (C) * 2004-2006 ICEsoft Technologies Canada, Corp. All Rights Reserved. * * Contributor(s): _____________________. * * Alternatively, the contents of this file may be used under the terms of * the GNU Lesser General Public License Version 2.1 or later (the "LGPL" * License), in which case the provisions of the LGPL License are * applicable instead of those above. If you wish to allow use of your * version of this file only under the terms of the LGPL License and not to * allow others to use your version of this file under the MPL, indicate * your decision by deleting the provisions above and replace them with * the notice and other provisions required by the LGPL License. If you do * not delete the provisions above, a recipient may use your version of * this file under either the MPL or the LGPL License." * */ package com.icesoft.faces.component.inputfile; import com.icesoft.faces.component.CSS_DEFAULT; import com.icesoft.faces.component.ext.taglib.Util; import com.icesoft.faces.component.style.OutputStyle; import com.icesoft.faces.context.BridgeFacesContext; import com.icesoft.faces.renderkit.dom_html_basic.DomBasicRenderer; import com.icesoft.faces.utils.MessageUtils; import com.icesoft.faces.webapp.http.servlet.FileUploadComponent; import com.icesoft.faces.webapp.xmlhttp.PersistentFacesState; import java.util.ArrayList; import org.apache.commons.fileupload.FileItemStream; import org.apache.commons.fileupload.FileUploadBase; import org.apache.commons.fileupload.util.Streams; import javax.faces.component.UICommand; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.context.ExternalContext; import javax.faces.el.MethodBinding; import javax.faces.el.ValueBinding; import javax.faces.event.ActionEvent; import javax.faces.event.ActionListener; import javax.faces.event.FacesListener; import javax.servlet.http.HttpServletRequest; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.Serializable; import java.io.Writer; import java.util.EventObject; import java.util.Iterator; /** * InputFile is a JSF component class representing an ICEfaces inputFile. */ public class InputFile extends UICommand implements Serializable, FileUploadComponent { public static final int DEFAULT = 0; public static final int UPLOADING = 1; public static final int SAVED = 2; public static final int INVALID = 3; public static final int SIZE_LIMIT_EXCEEDED = 4; public static final int UNKNOWN_SIZE = 5; public static final int INVALID_NAME_PATTERN = 6; public static final String INVALID_FILE_MESSAGE_ID = "com.icesoft.faces.component.inputfile.INVALID_FILE"; public static final String INVALID_NAME_PATTERN_MESSAGE_ID = "com.icesoft.faces.component.inputfile.INVALID_NAME_PATTERN"; public static final String SIZE_LIMIT_EXCEEDED_MESSAGE_ID = "com.icesoft.faces.component.inputfile.SIZE_LIMIT_EXCEEDED"; public static final String UNKNOWN_SIZE_MESSAGE_ID = "com.icesoft.faces.component.inputfile.UNKNOWN_SIZE"; public static final String FILE_UPLOAD_PREFIX = "fileUpload"; private Boolean disabled; private String style; private String styleClass; private String label; private String enabledOnUserRole; private String renderedOnUserRole; private String title; private int height = 30; private int width = 500; private int inputTextSize = 35; private String inputTextClass; private String fileNamePattern; private boolean uniqueFolder = true; private String downloadFolder; private Throwable uploadException; private int status = DEFAULT; private FileInfo fileInfo = new FileInfo(); private int progress = 0; private File file; private long sizeMax; private MethodBinding progressListener; /** *
Return the value of the COMPONENT_TYPE
of this
* component.
Return the value of the RENDERER_TYPE
of this
* component.
Return the value of the COMPONENT_FAMILY
of this
* component.
label
property.
*/
public void setLabel(String label) {
this.label = label;
}
/**
*
* Set the value of the uniqueFolder
property.
*/
public void setUniqueFolder(boolean uniqueFolder) {
if (uniqueFolder != this.uniqueFolder) {
this.uniqueFolder = uniqueFolder;
}
}
/**
*
* Return the value of the uniqueFolder
property.
*/
public boolean isUniqueFolder() {
ValueBinding vb = getValueBinding("uniqueFolder");
if (vb != null) {
return (Boolean.TRUE.equals(vb.getValue(getFacesContext())));
}
return true;
}
/**
*
* Return the value of the label
property.
*/
public String getLabel() {
if (label != null) {
return label;
}
ValueBinding vb = getValueBinding("label");
return vb != null ? (String) vb.getValue(getFacesContext()) : "Upload";
}
/**
* Return the value of the disabled
property.
Set the value of the disabled
property.
Set the value of the enabledOnUserRole
property.
Return the value of the enabledOnUserRole
property.
Set the value of the renderedOnUserRole
property.
Return the value of the renderedOnUserRole
property.
Return the value of the rendered
property.
Set the value of the style
property.
Return the value of the style
property.
Set the value of the styleClass
property.
Return the value of the styleClass
property.
Gets the state of the instance as a Serializable
* Object.
Perform any processing required to restore the state from the entries * in the state Object.
*/ public void restoreState(FacesContext context, Object state) { Object values[] = (Object[]) state; super.restoreState(context, values[0]); disabled = (Boolean) values[6]; style = (String) values[8]; styleClass = (String) values[9]; label = (String) values[10]; enabledOnUserRole = (String) values[13]; renderedOnUserRole = (String) values[14]; } /** *Set the value of the title
property.
Return the value of the title
property.
Set the value of the size
property.
Return the value of the size
property.
fileInfo
property.
*/
public FileInfo getFileInfo() {
return fileInfo;
}
void setFileInfo(FileInfo fileInfo) {
//do nothing
}
/**
*
* Return the value of the file
property.
*/
public File getFile() {
return file;
}
/**
*
* Set the value of the file property.
*/
public void setFile(File file) {
//do nothing
}
public int getStatus() {
return status;
}
/**
* Return the value of the fileName
property.
*
* @deprecated use getFileInfo().getFileName() instead.
*/
public String getFilename() {
return fileInfo.getFileName();
}
/**
* Set the value of the fileName
property.
*
* @deprecated use getFileInfo().setFileName() instead.
*/
public void setFilename(String filename) {
fileInfo.setFileName(filename);
}
/**
* Return the value of the size
property.
*
* @deprecated use getFileInfo().getSize() instead.
*/
public long getFilesize() {
return fileInfo.getSize();
}
/**
* Set the value of the size
property.
*
*/
public void setFilesize(long filesize) {
fileInfo.setSize(filesize);
}
public long getSizeMax() {
return sizeMax;
}
public MethodBinding getProgressListener() {
return progressListener;
}
public void setProgressListener(MethodBinding binding) {
progressListener = binding;
}
public int getProgress(){
return progress;
}
public void setProgress(int i){
progress = i;
fileInfo.setPercent(i);
if( getProgressListener() != null )
getProgressListener().invoke(FacesContext.getCurrentInstance(), new Object[] {new EventObject(this)});
}
public String getCssFile() {
return null;
}
private String getDisabled() {
return null;
}
private String getStyleClassString() {
return null;
}
private String getStyleString() {
return null;
}
private String getStyleInfo() {
return null;
}
private String getInputTextClassString() {
return null;
}
private String getButtonClassString() {
return null;
}
private String getTitleAsString(){
return null;
}
}