Search in sources :

Example 1 with WOActionResults

use of com.webobjects.appserver.WOActionResults in project wonder-slim by undur.

the class AjaxFileUpload method uploadSucceeded.

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")) {
            try (OutputStream outputStream = (OutputStream) valueForBinding("outputStream")) {
                if (outputStream != null) {
                    try (InputStream inputStream = new FileInputStream(progress.tempFile())) {
                        inputStream.transferTo(outputStream);
                    }
                }
            }
        }
        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 = fileNameFromBrowserSubmittedPath(progress.fileName());
                    streamToFile = reserveUniqueFile(new File(parentDir, fileName), overwrite);
                    renameFile = true;
                } else {
                    renameFile = overwrite;
                }
            } else {
                renameFile = true;
            }
            if (renameFile && !streamToFile.isDirectory()) {
                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();
    }
    WOActionResults results = (WOActionResults) valueForBinding("succeededAction");
    return results;
}
Also used : NSData(com.webobjects.foundation.NSData) WOActionResults(com.webobjects.appserver.WOActionResults) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 2 with WOActionResults

use of com.webobjects.appserver.WOActionResults in project wonder-slim by undur.

the class AjaxFlexibleFileUpload method clearFileResults.

/**
 * Action called by the clear button, resets the uploader for a new file selection
 *
 * @return results of action
 */
public WOActionResults clearFileResults() {
    clearUploadProgress();
    WOActionResults results = (WOActionResults) valueForBinding("clearedAction");
    return results;
}
Also used : WOActionResults(com.webobjects.appserver.WOActionResults)

Example 3 with WOActionResults

use of com.webobjects.appserver.WOActionResults in project wonder-slim by undur.

the class AjaxFlexibleFileUpload method uploadSucceeded.

/**
 * Hook for add-in action called when an upload succeeds.
 */
@Override
public WOActionResults uploadSucceeded() {
    WOActionResults result = super.uploadSucceeded();
    clearUploadProgress();
    return result;
}
Also used : WOActionResults(com.webobjects.appserver.WOActionResults)

Example 4 with WOActionResults

use of com.webobjects.appserver.WOActionResults in project wonder-slim by undur.

the class AjaxHyperlink method handleRequest.

@Override
public WOActionResults handleRequest(WORequest request, WOContext context) {
    WOComponent component = context.component();
    WOActionResults results = (WOActionResults) valueForBinding("action", component);
    if (results == null) {
        String script = (String) valueForBinding("onClickServer", component);
        if (script != null) {
            WOResponse response = AjaxUtils.createResponse(request, context);
            AjaxUtils.appendScriptHeader(response);
            response.appendContentString(script);
            AjaxUtils.appendScriptFooter(response);
            results = response;
        }
    }
    return results;
}
Also used : WOActionResults(com.webobjects.appserver.WOActionResults) WOComponent(com.webobjects.appserver.WOComponent) WOResponse(com.webobjects.appserver.WOResponse)

Example 5 with WOActionResults

use of com.webobjects.appserver.WOActionResults in project wonder-slim by undur.

the class AjaxInPlace method invokeAction.

@Override
public WOActionResults invokeAction(WORequest aRequest, WOContext aContext) {
    _alreadyInForm = context().isInForm();
    WOActionResults results = super.invokeAction(aRequest, aContext);
    // MS: see appendToResponse
    _id = null;
    return results;
}
Also used : WOActionResults(com.webobjects.appserver.WOActionResults)

Aggregations

WOActionResults (com.webobjects.appserver.WOActionResults)31 WOComponent (com.webobjects.appserver.WOComponent)11 WOResponse (com.webobjects.appserver.WOResponse)6 WOElement (com.webobjects.appserver.WOElement)2 WOApplication (com.webobjects.appserver.WOApplication)1 WOContext (com.webobjects.appserver.WOContext)1 WORequest (com.webobjects.appserver.WORequest)1 WOForm (com.webobjects.appserver._private.WOForm)1 WONoContentElement (com.webobjects.appserver._private.WONoContentElement)1 NSArray (com.webobjects.foundation.NSArray)1 NSData (com.webobjects.foundation.NSData)1 NSMutableArray (com.webobjects.foundation.NSMutableArray)1 NSMutableDictionary (com.webobjects.foundation.NSMutableDictionary)1 NSRange (com.webobjects.foundation.NSRange)1 ERXWOContext (er.extensions.appserver.ERXWOContext)1 ERXWOForm (er.extensions.components._private.ERXWOForm)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1