Node copy;
// #
if (node != null) {
// Prepend the div's id with the id of the form for uniqueness. This
// has to match that above.
copy = node.cloneNode(true);
((Element) copy).setAttribute("id", "fileUploadForm" +
NamingContainer.SEPARATOR_CHAR + ((Element)copy).getAttribute("id") );
String divAsString = DOMUtils.nodeToString( copy );
if (log.isDebugEnabled()) {
log.debug("State saving view contents: " + divAsString);
}
writer.write(divAsString);
}
writer.write("");
writer.write("");
}
private String getUploadServletPath(BridgeFacesContext context) {
String requestContextPath = null;
if (context != null) {
ExternalContext externalContext = context.getExternalContext();
if (externalContext != null) {
requestContextPath = externalContext.getRequestContextPath();
}
}
if (requestContextPath == null || requestContextPath.length() == 0)
return "./uploadHtml";
else
return requestContextPath + "/uploadHtml";
}
/**
* @deprecated use getFileInfo().getException() instead.
*/
public Throwable getUploadException() {
return fileInfo.getException();
}
/**
*
* Set the value of the
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;
}
this.uniqueFolderSet = true;
}
/**
*
* Return the value of the
uniqueFolder property.
*/
public boolean isUniqueFolder() {
if (this.uniqueFolderSet) {
return (this.uniqueFolder);
}
ValueBinding vb = getValueBinding("uniqueFolder");
if (vb != null) {
return (Boolean.TRUE.equals(vb.getValue(getFacesContext())));
}
return true;
}
/**
* This is for internal use, so we can tell when this property has not been
* set on the component.
*/
protected Boolean getUniqueFolder() {
if (this.uniqueFolderSet) {
return Boolean.valueOf(this.uniqueFolder);
}
ValueBinding vb = getValueBinding("uniqueFolder");
if (vb != null) {
return (Boolean) vb.getValue(getFacesContext());
}
return null;
}
/**
*
* 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.
*/
public boolean isDisabled() {
if (!Util.isEnabledOnUserRole(this)) {
return true;
} else {
if (disabled != null) {
return disabled.booleanValue();
}
ValueBinding vb = getValueBinding("disabled");
Boolean boolVal = vb != null ?
(Boolean) vb.getValue(getFacesContext()) : null;
return boolVal != null ? boolVal.booleanValue() : false;
}
}
/**
*
Set the value of the disabled property.
*/
public void setDisabled(boolean disabled) {
this.disabled = Boolean.valueOf(disabled);
}
/**
*
Set the value of the enabledOnUserRole property.
*/
public void setEnabledOnUserRole(String enabledOnUserRole) {
this.enabledOnUserRole = enabledOnUserRole;
}
/**
*
Return the value of the enabledOnUserRole property.
*/
public String getEnabledOnUserRole() {
if (enabledOnUserRole != null) {
return enabledOnUserRole;
}
ValueBinding vb = getValueBinding("enabledOnUserRole");
return vb != null ? (String) vb.getValue(getFacesContext()) : null;
}
public void setUploadDirectory(String uploadDirectory) {
this.uploadDirectory = uploadDirectory;
}
public String getUploadDirectory() {
if (uploadDirectory != null) {
return uploadDirectory;
}
ValueBinding vb = getValueBinding("uploadDirectory");
return vb != null ? (String) vb.getValue(getFacesContext()) : null;
}
public void setUploadDirectoryAbsolute(Boolean uploadDirectoryAbsolute) {
this.uploadDirectoryAbsolute = uploadDirectoryAbsolute;
}
public Boolean getUploadDirectoryAbsolute() {
if (uploadDirectoryAbsolute != null) {
return uploadDirectoryAbsolute;
}
ValueBinding vb = getValueBinding("uploadDirectoryAbsolute");
return vb != null ? (Boolean) vb.getValue(getFacesContext()) : null;
}
public void setProgressRender(Boolean progressRender) {
this.progressRender = progressRender;
}
public Boolean getProgressRender() {
if (progressRender != null) {
return progressRender;
}
ValueBinding vb = getValueBinding("progressRender");
return vb != null ? (Boolean) vb.getValue(getFacesContext()) : null;
}
public boolean renderOnProgress() {
Boolean progRend = getProgressRender();
return (progRend != null) ? progRend.booleanValue() : true;
}
public void setSubmitOnUpload(String submitOnUpload) {
this.submitOnUpload = submitOnUpload;
}
public String getSubmitOnUpload() {
if (submitOnUpload != null) {
return submitOnUpload;
}
ValueBinding vb = getValueBinding("submitOnUpload");
return vb != null ? (String) vb.getValue(getFacesContext()) : null;
}
public String getValidatedSubmitOnUpload() {
String sol = getSubmitOnUpload();
if (sol == null || sol.length() == 0) {
sol = SUBMIT_NONE;
}
else {
if (!sol.equals(SUBMIT_NONE) &&
!sol.equals(SUBMIT_PRE_UPLOAD) &&
!sol.equals(SUBMIT_POST_UPLOAD) &&
!sol.equals(SUBMIT_PRE_POST_UPLOAD)) {
throw new FacesException( new IllegalArgumentException(
"Invalid value for ice:inputFile's submitOnUpload property: " + sol) );
}
}
return sol;
}
/**
*
Set the value of the renderedOnUserRole property.
*/
public void setRenderedOnUserRole(String renderedOnUserRole) {
this.renderedOnUserRole = renderedOnUserRole;
}
/**
*
Return the value of the renderedOnUserRole property.
*/
public String getRenderedOnUserRole() {
if (renderedOnUserRole != null) {
return renderedOnUserRole;
}
ValueBinding vb = getValueBinding("renderedOnUserRole");
return vb != null ? (String) vb.getValue(getFacesContext()) : null;
}
/**
*
Return the value of the rendered property.
*/
public boolean isRendered() {
if (!Util.isRenderedOnUserRole(this)) {
return false;
}
return super.isRendered();
}
/**
*
Set the value of the style property.
*/
public void setStyle(String style) {
this.style = style;
}
/**
*
Return the value of the style property.
*/
public String getStyle() {
if (style != null) {
return style;
}
ValueBinding vb = getValueBinding("style");
return vb != null ? (String) vb.getValue(getFacesContext()) :
"border-collapse:collapse; border-spacing:0px; padding:0px;";
}
/**
*
Set the value of the styleClass property.
*/
public void setStyleClass(String styleClass) {
this.styleClass = styleClass;
}
/**
*
Return the value of the styleClass property.
*/
public String getStyleClass() {
return Util.getQualifiedStyleClass(this,
styleClass,
CSS_DEFAULT.ICE_FILE_UPLOAD_BASE_CLASS,
"styleClass",
isDisabled());
}
/**
*
Gets the state of the instance as a Serializable
* Object.
*/
public Object saveState(FacesContext context) {
Object values[] = new Object[30];
values[0] = super.saveState(context);
values[1] = disabled;
values[2] = style;
values[3] = styleClass;
values[4] = label;
values[5] = enabledOnUserRole;
values[6] = renderedOnUserRole;
values[7] = title;
values[8] = new Integer(height);
values[9] = new Integer(width);
values[10] = new Integer(inputTextSize);
values[11] = inputTextClass;
values[12] = fileNamePattern;
values[13] = uniqueFolder ? Boolean.TRUE : Boolean.FALSE;
values[14] = uniqueFolderSet ? Boolean.TRUE : Boolean.FALSE;
values[15] = uploadDirectory;
values[16] = uploadDirectoryAbsolute;
if (log.isDebugEnabled())
log.debug("#### InputFile.saveState() fileInfo: " + fileInfo);
values[17] = fileInfo;
values[18] = new Long(sizeMax);
values[19] = saveAttachedState(context, progressListener);
values[20] = progressRender;
values[21] = submitOnUpload;
values[22] = tabindex;
values[23] = onchange;
values[24] = accesskey;
values[25] = onfocus;
values[26] = accept;
values[27] = onblur;
values[28] = buttonClass;
values[29] = size;
return ((Object) (values));
}
/**
*
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[1];
style = (String) values[2];
styleClass = (String) values[3];
label = (String) values[4];
enabledOnUserRole = (String) values[5];
renderedOnUserRole = (String) values[6];
title = (String) values[7];
height = ((Integer) values[8]).intValue();
width = ((Integer) values[9]).intValue();
inputTextSize = ((Integer) values[10]).intValue();
inputTextClass = (String) values[11];
fileNamePattern = (String) values[12];
uniqueFolder = ((Boolean) values[13]).booleanValue();
uniqueFolderSet = ((Boolean) values[14]).booleanValue();
uploadDirectory = (String) values[15];
uploadDirectoryAbsolute = (Boolean) values[16];
fileInfo = (FileInfo) values[17];
if (log.isDebugEnabled())
log.debug("#### InputFile.restoreState() fileInfo: " + fileInfo);
sizeMax = ((Long) values[18]).longValue();
progressListener = (MethodBinding) restoreAttachedState(context, values[19]);
progressRender = (Boolean) values[20];
submitOnUpload = (String) values[21];
tabindex = (String)values[22];
onchange = (String)values[23];
accesskey = (String)values[24];
onfocus = (String)values[25];
accept = (String)values[26];
onblur = (String)values[27];
buttonClass = (String)values[28];
size = (String) values[29];
}
/**
*
Set the value of the title property.
*/
public void setTitle(String title) {
this.title = title;
}
/**
*
Return the value of the title property.
*/
public String getTitle() {
if (title != null) {
return title;
}
ValueBinding vb = getValueBinding("title");
return vb != null ? (String) vb.getValue(getFacesContext()) : null;
}
// size
private String size = null;
/**
*
Set the value of the size property.
*/
public void setSize(String size) {
this.size = size;
}
/**
*
Return the value of the size property.
*/
public String getSize() {
if (size != null) {
return size;
}
ValueBinding vb = getValueBinding("size");
return vb != null ? (String) vb.getValue(getFacesContext()) : null;
}
public int getHeight() {
ValueBinding vb = getValueBinding("height");
if (vb != null) {
Integer value = (Integer) vb.getValue(getFacesContext());
if (null == value) {
return height;
}
return (value.intValue());
} else {
return (this.height);
}
}
public void setHeight(int height) {
this.height = height;
}
public int getWidth() {
ValueBinding vb = getValueBinding("width");
if (vb != null) {
Integer value = (Integer) vb.getValue(getFacesContext());
if (null == value) {
return width;
}
return (value.intValue());
} else {
return (this.width);
}
}
public void setWidth(int width) {
this.width = width;
}
public int getInputTextSize() {
ValueBinding vb = getValueBinding("inputTextSize");
if (vb != null) {
Integer value = (Integer) vb.getValue(getFacesContext());
if (null == value) {
return inputTextSize;
}
return (value.intValue());
} else {
return (this.inputTextSize);
}
}
public void setInputTextSize(int inputTextSize) {
this.inputTextSize = inputTextSize;
}
public String getFileNamePattern() {
if (fileNamePattern != null) {
return fileNamePattern;
}
ValueBinding vb = getValueBinding("fileNamePattern");
return vb != null ? (String) vb.getValue(getFacesContext()) : ".+";
}
public void setFileNamePattern(String fileNamePattern) {
this.fileNamePattern = fileNamePattern;
}
public void setInputTextClass(String inputTextClass) {
this.inputTextClass = inputTextClass;
}
public String getInputTextClass() {
return Util.getQualifiedStyleClass(this,
inputTextClass,
CSS_DEFAULT.ICE_FILE_UPLOAD_DEFAULT_INPUT_TEXT_CLASS,
"inputTextClass",
isDisabled());
}
private String buttonClass = null;
public void setButtonClass(String buttonClass) {
this.buttonClass = buttonClass;
}
public String getButtonClass() {
return Util.getQualifiedStyleClass(this,
buttonClass,
CSS_DEFAULT.ICE_FILE_UPLOAD_DEFAULT_BUTTON_CLASS,
"buttonClass",
isDisabled());
}
boolean isRegister() {
return false;
}
public void setRegister(FacesContext facesContext) {
//do nothing
}
/**
*
* Return the value of the
fileInfo property.
*/
public FileInfo getFileInfo() {
return (FileInfo) fileInfo.clone();
}
/**
* Not to be called by applications. Used internally between the
* UploadServer, InputFile and InputFileRenderer.
*/
void setFileInfo(FileInfo fileInfo) {
if (log.isDebugEnabled())
log.debug("#### InputFile.setFileInfo() fileInfo: " + fileInfo);
this.fileInfo = fileInfo;
}
/**
* This is the configuration, as represented by the values specified on
* this InputFile component. Some of the values take precedence over
* context-params, if they're non-null here, the combination of which
* will produce a final configuration for the UploadServer to use.
*
* Not intended for use by application use.
*/
public UploadConfig getComponentUploadConfig() {
FacesContext context = FacesContext.getCurrentInstance();
String clientId = getClientId(context);
UIComponent form = DomBasicRenderer.findForm(this);
String formClientId = (form != null) ? form.getClientId(context) : null;
Long sizeMax = null; //TODO Make an attrib on InputFile. UploadServer uses before gets this UploadConfig though
String fileNamePattern = getFileNamePattern();
Boolean uniqueFolder = getUniqueFolder();
String uploadDirectory = getUploadDirectory();
Boolean uploadDirectoryAbsolute = getUploadDirectoryAbsolute();
boolean progressRender = renderOnProgress();
boolean progressListener = (getProgressListener() != null);
UploadConfig uploadConfig = new UploadConfig(
clientId,
formClientId,
sizeMax,
fileNamePattern,
uniqueFolder,
uploadDirectory,
uploadDirectoryAbsolute,
progressRender,
progressListener);
return uploadConfig;
}
/**
*
* Return the value of the
file property.
* @deprecated use getFileInfo().getFile() instead.
*/
public File getFile() {
return fileInfo.getFile();
}
/**
*
* Set the value of the
file property.
* @deprecated This should be a read-only property
*/
public void setFile(File file) {
//do nothing
}
/**
* In the 1.5.3 codebase, there was a writeable ValueBinding named "file"
* that would be updated when a new file was saved. This provides
* backwards compatibility with that.
*/
protected void updateFileValueBinding() {
try {
ValueBinding vb = getValueBinding("file");
if (vb != null)
vb.setValue(FacesContext.getCurrentInstance(), getFile());
}
catch (Exception e) {
log.warn("The InputFile's file attribute has a ValueBinding, whose value could not be set", e);
}
}
/**
* @return DEFAULT, UPLOADING, SAVED, or one of the error statuses.
* @deprecated use getFileInfo().getStatus() instead.
*/
public int getStatus() {
return fileInfo.getStatus();
}
/**
* 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 This should be a read-only property
*/
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.
* @deprecated This should be a read-only 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 fileInfo.getPercent();
}
/**
* @deprecated This is not used internally any more, and it's hard to
* imagine a valid scenario for the application to call this method.
* Potentially applications, written before the addition of the
* reset() method, may use this?
*/
public void setProgress(int i) {
fileInfo.setPercent(i);
if (getProgressListener() != null)
getProgressListener().invoke(FacesContext.getCurrentInstance(), new Object[]{new InputFileProgressEvent(this)});
}
void setPreUpload(boolean p) {
fileInfo.setPreUpload(p);
}
void setPostUpload(boolean p) {
fileInfo.setPostUpload(p);
}
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;
}
private static ArrayList findOutputStyleComponents(UIComponent parent) {
ArrayList returnValue = null;
if (parent.getChildCount() == 0) return returnValue;
Iterator children = parent.getChildren().iterator();
UIComponent childComponent = null;
while (children.hasNext()) {
childComponent = (UIComponent) children.next();
if (childComponent instanceof OutputStyle) {
if (returnValue == null) {
returnValue = new ArrayList();
}
returnValue.add(childComponent);
} else {
ArrayList outputStyleComponents = findOutputStyleComponents(childComponent);
if (outputStyleComponents != null) {
if (returnValue == null) {
returnValue = outputStyleComponents;
} else {
returnValue.addAll(outputStyleComponents);
}
}
}
}
return returnValue;
}
private String onfocus;
public void setOnfocus(String onfocus) {
this.onfocus = onfocus;
}
public String getOnfocus() {
if (onfocus != null) {
return onfocus;
}
ValueBinding vb = getValueBinding("onfocus");
return vb != null ? (String) vb.getValue(getFacesContext()) : null;
}
private String onchange;
public void setOnchange(String onchange) {
this.onchange = onchange;
}
public String getOnchange() {
if (onchange != null) {
return onchange;
}
ValueBinding vb = getValueBinding("onchange");
return vb != null ? (String) vb.getValue(getFacesContext()) : null;
}
private String accept;
public void setAccept(String accept) {
this.accept = accept;
}
public String getAccept() {
if (accept != null) {
return accept;
}
ValueBinding vb = getValueBinding("accept");
return vb != null ? (String) vb.getValue(getFacesContext()) : null;
}
private String accesskey;
public void setAccesskey(String accesskey) {
this.accesskey = accesskey;
}
public String getAccesskey() {
if (accesskey != null) {
return accesskey;
}
ValueBinding vb = getValueBinding("accesskey");
return vb != null ? (String) vb.getValue(getFacesContext()) : null;
}
private String onblur;
public void setOnblur(String onblur) {
this.onblur = onblur;
}
public String getOnblur() {
if (onblur != null) {
return onblur;
}
ValueBinding vb = getValueBinding("onblur");
return vb != null ? (String) vb.getValue(getFacesContext()) : null;
}
private String tabindex;
public void setTabindex(String tabindex) {
this.tabindex = tabindex;
}
public String getTabindex() {
if (tabindex != null) {
return tabindex;
}
ValueBinding vb = getValueBinding("tabindex");
return vb != null ? (String) vb.getValue(getFacesContext()) : null;
}
public void reset() {
fileInfo = new FileInfo();
FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext != null) {
String clientId = getClientId(facesContext);
Iterator msgs = facesContext.getMessages(clientId);
if (msgs != null) {
while (msgs.hasNext()) {
FacesMessage msg = (FacesMessage) msgs.next();
msgs.remove();
}
}
}
}
//TODO Remove this method
public void processDecodes(FacesContext context) {
if (log.isDebugEnabled())
log.debug("InputFile.processDecode() clientId: " + getClientId(context));
super.processDecodes(context);
}
//TODO Remove this method
public void processUpdates(FacesContext context) {
if (log.isDebugEnabled())
log.debug("InputFile.processUpdates() clientId: " + getClientId(context));
super.processUpdates(context);
}
//TODO Remove this method
public void processValidators(FacesContext context) {
if (log.isDebugEnabled())
log.debug("InputFile.processValidators() clientId: " + getClientId(context));
super.processValidators(context);
}
}