WOActionResults results = (WOActionResults) valueForBinding("canceledAction");
return results;
}
public WOActionResults uploadSucceeded() {
AjaxUploadProgress progress = uploadProgress();
try {
boolean deleteFile = true;
if (hasBinding("filePath")) {
setValueForBinding(progress.fileName(), "filePath");
}
if (hasBinding("data")) {
NSData data = new NSData(progress.tempFile().toURI().toURL());
setValueForBinding(data, "data");
}
if (hasBinding("mimeType")) {
String contentType = progress.contentType();
if (contentType != null) {
setValueForBinding(contentType, "mimeType");
}
}
if (hasBinding("inputStream")) {
setValueForBinding(new FileInputStream(progress.tempFile()), "inputStream");
deleteFile = false;
}
if (hasBinding("outputStream")) {
OutputStream outputStream = (OutputStream) valueForBinding("outputStream");
if (outputStream != null) {
ERXFileUtilities.writeInputStreamToOutputStream(new FileInputStream(progress.tempFile()), true, outputStream, true);
}
}
String finalFilePath = progress.tempFile().getAbsolutePath();
if (hasBinding("streamToFilePath")) {
File streamToFile = new File((String) valueForBinding("streamToFilePath"));
boolean renamedFile;
boolean renameFile;
if (streamToFile.exists()) {
boolean overwrite = ERXComponentUtilities.booleanValueForBinding(this, "overwrite");
if (streamToFile.isDirectory()) {
File parentDir = streamToFile;
String fileName = ERXFileUtilities.fileNameFromBrowserSubmittedPath(progress.fileName());
streamToFile = ERXFileUtilities.reserveUniqueFile(new File(parentDir, fileName), overwrite);
renameFile = true;
}
else {
renameFile = overwrite;
}
}
else {
renameFile = true;
}
if (renameFile && !streamToFile.isDirectory()) {
ERXFileUtilities.renameTo(progress.tempFile(), streamToFile);
renamedFile = true;
}
else {
renamedFile = false;
progress.setFailure(new Exception ("Could not rename file."));
return uploadFailed();
}
if (renamedFile) {
finalFilePath = streamToFile.getAbsolutePath();
}
deleteFile = false;
}
else if (hasBinding("keepTempFile") && deleteFile) {
deleteFile = !ERXComponentUtilities.booleanValueForBinding(this, "keepTempFile");
}
if (deleteFile) {
progress.dispose();
}
else if (hasBinding("finalFilePath")) {
setValueForBinding(finalFilePath, "finalFilePath");
}
}
catch (Throwable t) {
t.printStackTrace();
progress.setFailure(t);
return uploadFailed();
}
finally {
uploadFinished();
}