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);
}
use of org.apache.wicket.util.resource.FileResourceStream in project wicket by apache.
the class CachingResourceStreamLocatorTest method fileResource.
/**
* Tests FileResourceStreamReference
*/
@Test
public void fileResource() {
IResourceStreamLocator resourceStreamLocator = mock(IResourceStreamLocator.class);
FileResourceStream frs = new FileResourceStream(new File("."));
when(resourceStreamLocator.locate(String.class, "path", "style", "variation", null, "extension", true)).thenReturn(frs);
CachingResourceStreamLocator cachingLocator = new CachingResourceStreamLocator(resourceStreamLocator);
cachingLocator.locate(String.class, "path", "style", "variation", null, "extension", true);
cachingLocator.locate(String.class, "path", "style", "variation", null, "extension", true);
// there is a file resource with that Key so expect just one call to the delegate
verify(resourceStreamLocator, times(1)).locate(String.class, "path", "style", "variation", null, "extension", true);
}
use of org.apache.wicket.util.resource.FileResourceStream in project wicket by apache.
the class CachingResourceStreamLocatorTest method fileResourceDifferentExtensions.
/**
* Tests two FileResourceStreamReferences with different extensions
*/
@Test
public void fileResourceDifferentExtensions() {
IResourceStreamLocator resourceStreamLocator = mock(IResourceStreamLocator.class);
FileResourceStream frs = new FileResourceStream(new File("."));
when(resourceStreamLocator.locate(String.class, "path", "style", "variation", null, "extension", true)).thenReturn(frs);
CachingResourceStreamLocator cachingLocator = new CachingResourceStreamLocator(resourceStreamLocator);
cachingLocator.locate(String.class, "path", "style", "variation", null, "extension", true);
cachingLocator.locate(String.class, "path", "style", "variation", null, "extension", true);
cachingLocator.locate(String.class, "path", "style", "variation", null, "extension2", true);
// there is a file resource with that Key so expect just one call to the delegate
verify(resourceStreamLocator, times(1)).locate(String.class, "path", "style", "variation", null, "extension", true);
verify(resourceStreamLocator, times(1)).locate(String.class, "path", "style", "variation", null, "extension2", true);
}
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.ATTACHMENT).setCacheDuration(cacheDuration));
}
use of org.apache.wicket.util.resource.FileResourceStream in project webanno by webanno.
the class ExportDocumentDialogContent method export.
private FileResourceStream export() {
File downloadFile = null;
String username = state.getObject().getMode().equals(Mode.AUTOMATION) && preferences.getObject().documentType.equals(SELECTEXPORT.AUTOMATED.toString()) ? "CORRECTION_USER" : SecurityContextHolder.getContext().getAuthentication().getName();
try {
downloadFile = importExportService.exportAnnotationDocument(state.getObject().getDocument(), username, importExportService.getWritableFormats().get(importExportService.getWritableFormatId(preferences.getObject().format)), state.getObject().getDocument().getName(), state.getObject().getMode());
} catch (Exception e) {
LOG.error("Export failed", e);
error("Export failed:" + ExceptionUtils.getRootCauseMessage(e));
// RestartResponseException the feedback message only flashes.
throw new NonResettingRestartException(getPage().getPageClass());
}
return new FileResourceStream(downloadFile);
}
Aggregations