Search in sources :

Example 1 with FileSystemResourceStream

use of org.apache.wicket.util.resource.FileSystemResourceStream in project wicket by apache.

the class FileSystemResourceStreamReference method getReference.

@Override
public FileSystemResourceStream getReference() {
    FileSystemResourceStream fileSystemResourceStream = new FileSystemResourceStream(Paths.get(absolutePath));
    restoreResourceStream(fileSystemResourceStream);
    return fileSystemResourceStream;
}
Also used : FileSystemResourceStream(org.apache.wicket.util.resource.FileSystemResourceStream)

Example 2 with FileSystemResourceStream

use of org.apache.wicket.util.resource.FileSystemResourceStream in project webanno by webanno.

the class AjaxDownloadLink method commonInit.

void commonInit() {
    downloadBehavior = new AbstractAjaxBehavior() {

        private static final long serialVersionUID = 3472918725573624819L;

        @Override
        public void onRequest() {
            IResourceStream is = AjaxDownloadLink.this.getModelObject();
            if (is != null) {
                // If no filename has been set explicitly, try to get it from the resource
                String name = filename != null ? filename.getObject() : null;
                if (name == null) {
                    if (is instanceof FileResourceStream) {
                        name = ((FileResourceStream) is).getFile().getName();
                    } else if (is instanceof FileSystemResourceStream) {
                        name = ((FileSystemResourceStream) is).getPath().getFileName().toString();
                    }
                }
                ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(AjaxDownloadLink.this.getModelObject(), name);
                handler.setContentDisposition(ContentDisposition.ATTACHMENT);
                getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
            }
        }
    };
    add(downloadBehavior);
}
Also used : FileResourceStream(org.apache.wicket.util.resource.FileResourceStream) IResourceStream(org.apache.wicket.util.resource.IResourceStream) FileSystemResourceStream(org.apache.wicket.util.resource.FileSystemResourceStream) ResourceStreamRequestHandler(org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler) AbstractAjaxBehavior(org.apache.wicket.behavior.AbstractAjaxBehavior)

Aggregations

FileSystemResourceStream (org.apache.wicket.util.resource.FileSystemResourceStream)2 AbstractAjaxBehavior (org.apache.wicket.behavior.AbstractAjaxBehavior)1 ResourceStreamRequestHandler (org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler)1 FileResourceStream (org.apache.wicket.util.resource.FileResourceStream)1 IResourceStream (org.apache.wicket.util.resource.IResourceStream)1