Search in sources :

Example 6 with FileResourceStream

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

the class FileResourceStreamReference method getReference.

@Override
public FileResourceStream getReference() {
    FileResourceStream fileResourceStream = new FileResourceStream(new File(fileName));
    restoreResourceStream(fileResourceStream);
    return fileResourceStream;
}
Also used : FileResourceStream(org.apache.wicket.util.resource.FileResourceStream) File(org.apache.wicket.util.file.File)

Example 7 with FileResourceStream

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

the class CachingResourceStreamLocator method updateCache.

private void updateCache(CacheKey key, IResourceStream stream) {
    if (null == stream) {
        cache.put(key, NullResourceStreamReference.INSTANCE);
    } else if (stream instanceof FileResourceStream) {
        FileResourceStream fileResourceStream = (FileResourceStream) stream;
        cache.put(key, new FileResourceStreamReference(fileResourceStream));
    } else if (stream instanceof UrlResourceStream) {
        UrlResourceStream urlResourceStream = (UrlResourceStream) stream;
        cache.put(key, new UrlResourceStreamReference(urlResourceStream));
    }
}
Also used : UrlResourceStream(org.apache.wicket.core.util.resource.UrlResourceStream) FileResourceStream(org.apache.wicket.util.resource.FileResourceStream)

Example 8 with FileResourceStream

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

the class DownloadLink method onClick.

@Override
public void onClick() {
    final File file = getModelObject();
    if (file == null) {
        throw new IllegalStateException(getClass().getName() + " failed to retrieve a File object from model");
    }
    String fileName = fileNameModel != null ? fileNameModel.getObject() : null;
    if (Strings.isEmpty(fileName)) {
        fileName = file.getName();
    }
    IResourceStream resourceStream = new FileResourceStream(new org.apache.wicket.util.file.File(file));
    getRequestCycle().scheduleRequestHandlerAfterCurrent(new ResourceStreamRequestHandler(resourceStream) {

        @Override
        public void respond(IRequestCycle requestCycle) {
            super.respond(requestCycle);
            if (deleteAfter) {
                Files.remove(file);
            }
        }
    }.setFileName(fileName).setContentDisposition(contentDisposition).setCacheDuration(cacheDuration));
}
Also used : FileResourceStream(org.apache.wicket.util.resource.FileResourceStream) IResourceStream(org.apache.wicket.util.resource.IResourceStream) File(java.io.File) ResourceStreamRequestHandler(org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler) IRequestCycle(org.apache.wicket.request.IRequestCycle)

Example 9 with FileResourceStream

use of org.apache.wicket.util.resource.FileResourceStream in project ocvn by devgateway.

the class FolderContentResource method respond.

public void respond(final Attributes attributes) {
    PageParameters parameters = attributes.getParameters();
    String fileName = parameters.get(PARAM_FILE_NAME).toString();
    // we use FilenameUtils to prevent "security tricks", only a file name
    // without path is allowed
    File file = new File(rootFolder, FilenameUtils.getName(fileName));
    FileResourceStream fileResourceStream = new FileResourceStream(file);
    ResourceStreamResource resource = new ResourceStreamResource(fileResourceStream);
    resource.respond(attributes);
}
Also used : FileResourceStream(org.apache.wicket.util.resource.FileResourceStream) ResourceStreamResource(org.apache.wicket.request.resource.ResourceStreamResource) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) File(java.io.File)

Example 10 with FileResourceStream

use of org.apache.wicket.util.resource.FileResourceStream in project oc-explorer by devgateway.

the class FolderContentResource method respond.

public void respond(final Attributes attributes) {
    PageParameters parameters = attributes.getParameters();
    String fileName = parameters.get(PARAM_FILE_NAME).toString();
    // we use FilenameUtils to prevent "security tricks", only a file name
    // without path is allowed
    File file = new File(rootFolder, FilenameUtils.getName(fileName));
    FileResourceStream fileResourceStream = new FileResourceStream(file);
    ResourceStreamResource resource = new ResourceStreamResource(fileResourceStream);
    resource.respond(attributes);
}
Also used : FileResourceStream(org.apache.wicket.util.resource.FileResourceStream) ResourceStreamResource(org.apache.wicket.request.resource.ResourceStreamResource) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) File(java.io.File)

Aggregations

FileResourceStream (org.apache.wicket.util.resource.FileResourceStream)18 File (java.io.File)13 IOException (java.io.IOException)4 CachingResourceStreamLocator (org.apache.wicket.core.util.resource.locator.caching.CachingResourceStreamLocator)4 FileOutputStream (java.io.FileOutputStream)3 OutputStream (java.io.OutputStream)3 ResourceStreamRequestHandler (org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler)3 ResourceStreamResource (org.apache.wicket.request.resource.ResourceStreamResource)3 IResourceStream (org.apache.wicket.util.resource.IResourceStream)3 Test (org.junit.jupiter.api.Test)3 ExportedTag (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTag)2 ExportedTagSet (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedTagSet)2 Tag (de.tudarmstadt.ukp.clarin.webanno.model.Tag)2 TagSet (de.tudarmstadt.ukp.clarin.webanno.model.TagSet)2 BufferedWriter (java.io.BufferedWriter)2 FileNotFoundException (java.io.FileNotFoundException)2 OutputStreamWriter (java.io.OutputStreamWriter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ArrayList (java.util.ArrayList)2 NonResettingRestartException (org.apache.wicket.NonResettingRestartException)2