本文整理汇总了Java中org.apache.wicket.util.resource.FileResourceStream类的典型用法代码示例。如果您正苦于以下问题:Java FileResourceStream类的具体用法?Java FileResourceStream怎么用?Java FileResourceStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileResourceStream类属于org.apache.wicket.util.resource包,在下文中一共展示了FileResourceStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onRequest
import org.apache.wicket.util.resource.FileResourceStream; //导入依赖的package包/类
public void onRequest() {
final File file = initFile();
IResourceStream resourceStream = new FileResourceStream(new File(file));
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(
new ResourceStreamRequestHandler(resourceStream) {
@Override
public void respond(IRequestCycle requestCycle) {
try {
super.respond(requestCycle);
} finally {
if (removeFile) {
LOGGER.debug("Removing file '{}'.", new Object[]{file.getAbsolutePath()});
Files.remove(file);
}
}
}
}.setFileName(file.getName()).setContentDisposition(ContentDisposition.ATTACHMENT)
.setCacheDuration(Duration.ONE_SECOND));
}
示例2: addExportButton
import org.apache.wicket.util.resource.FileResourceStream; //导入依赖的package包/类
/**
* Add a button for exporting the dependencies of the given event type.
*/
private void addExportButton() {
final AjaxButton exportButton = new AjaxButton("exportButton") {
private static final long serialVersionUID = 1L;
@Override
public void onSubmit(final AjaxRequestTarget target, final Form form) {
final AJAXDownload jsonDownload = new AJAXDownload() {
@Override
protected IResourceStream getResourceStream() {
final File csv = JsonExporter.generateExportFileWithDependencies(selectedEventType);
return new FileResourceStream(new org.apache.wicket.util.file.File(csv));
}
@Override
protected String getFileName() {
return selectedEventType.getTypeName() + "-dependencies.json";
}
};
ExportImportDependenciesPanel.this.add(jsonDownload);
jsonDownload.initiate(target);
ExportImportDependenciesPanel.this.page.getFeedbackPanel().success("Json created.");
target.add(ExportImportDependenciesPanel.this.page.getFeedbackPanel());
}
};
exportForm.add(exportButton);
}
示例3: onRequest
import org.apache.wicket.util.resource.FileResourceStream; //导入依赖的package包/类
public void onRequest() {
final File file = initFile();
IResourceStream resourceStream = new FileResourceStream(new File(file));
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(
new ResourceStreamRequestHandler(resourceStream) {
@Override
public void respond(IRequestCycle requestCycle) {
try {
super.respond(requestCycle);
} finally {
if (removeFile) {
LOGGER.debug("Removing file '{}'.", new Object[]{file.getAbsolutePath()});
Files.remove(file);
}
}
}
}.setFileName(file.getName()).setContentDisposition(ContentDisposition.ATTACHMENT)
.setCacheDuration(Duration.ONE_SECOND));
}
示例4: makeZipLogStream
import org.apache.wicket.util.resource.FileResourceStream; //导入依赖的package包/类
@Nonnull
private ResourceStreamResource makeZipLogStream(IModel<URI> logPath) {
return new ResourceStreamResource() {
@Override
protected IResourceStream getResourceStream() {
try {
return new FileResourceStream(new File(makeZip(logPath)));
} catch (IOException ex) {
getLogger().error(ex.getMessage(), ex);
}
return null;
}
};
}
示例5: addExportValuesButton
import org.apache.wicket.util.resource.FileResourceStream; //导入依赖的package包/类
/**
* Add a button to export the input values given via input fields.
*/
private void addExportValuesButton() {
final AjaxLink exportButton = new AjaxLink<Void>("exportValuesButton") {
@Override
public void onClick(AjaxRequestTarget target) {
layoutForm.modelChanged();
final AJAXDownload jsonDownload = new AJAXDownload() {
@Override
protected IResourceStream getResourceStream() {
JSONArray valuesForExport = new JSONArray();
for (AttributeInput input : attributeInputs) {
valuesForExport.put(input.toJson());
}
final File json = JsonExporter
.generateExportFileWithValues(selectedEventType, valuesForExport, eventCount, scaleFactor, eventTimestamps);
if (json == null) {
return null;
}
return new FileResourceStream(new org.apache.wicket.util.file.File(json));
}
@Override
protected String getFileName() {
return selectedEventType.getTypeName() + "-values.json";
}
};
GeneratePanel.this.add(jsonDownload);
jsonDownload.initiate(target);
GeneratePanel.this.page.getFeedbackPanel().success("Json created.");
target.add(GeneratePanel.this.page.getFeedbackPanel());
}
};
layoutForm.add(exportButton);
}
示例6: getResourceStream
import org.apache.wicket.util.resource.FileResourceStream; //导入依赖的package包/类
protected IResourceStream getResourceStream() {
File file = tempFileModel.getObject();
if (file != null && file.exists() && file.canRead() && file.isFile()) {
return new FileResourceStream(file);
}
throw new IllegalStateException();
}
示例7: OfferDownloadConfig
import org.apache.wicket.util.resource.FileResourceStream; //导入依赖的package包/类
/**
* If it is more than one file, it will package it into a zip. If it is just one file, it will directly offer that
* one.
*/
public OfferDownloadConfig(final List<File> files, final String packagedFileName) throws IOException {
if (files.size() > 1) {
final File tempFile = zipFiles(files, packagedFileName);
this.fileName = tempFile.getName();
this.resourceStream = new FileResourceStream(tempFile);
} else if (files.size() == 1) {
final File file = files.get(0);
this.fileName = file.getName();
this.resourceStream = new FileResourceStream(file);
} else {
throw new IllegalArgumentException("Please provide something to download");
}
}
示例8: respond
import org.apache.wicket.util.resource.FileResourceStream; //导入依赖的package包/类
@Override
public void respond(Attributes attributes)
{
FileResourceStream fileResourceStream = new FileResourceStream(file);
ResourceStreamResource resource = new ResourceStreamResource(fileResourceStream);
resource.respond(attributes);
}
示例9: commonInit
import org.apache.wicket.util.resource.FileResourceStream; //导入依赖的package包/类
void commonInit()
{
downloadBehavior = new AbstractAjaxBehavior()
{
private static final long serialVersionUID = 3472918725573624819L;
@Override
public void onRequest()
{
String name = filename != null ? filename.getObject() : null;
// If no filename has been set explicitly, try to get it from the resource
IResourceStream is = AjaxDownloadLink.this.getModelObject();
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);
}
示例10: export
import org.apache.wicket.util.resource.FileResourceStream; //导入依赖的package包/类
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));
// This will cause the open dialog to pop up again, but at least
// the error feedback message will be visible. With the
// RestartResponseException the feedback message only flashes.
throw new NonResettingRestartException(getPage().getPageClass());
}
return new FileResourceStream(downloadFile);
}
示例11: GuidelinesDialogContent
import org.apache.wicket.util.resource.FileResourceStream; //导入依赖的package包/类
public GuidelinesDialogContent(String aId, final ModalWindow modalWindow,
final IModel<AnnotatorState> aModel)
{
super(aId);
// Overall progress by Projects
RepeatingView guidelineRepeater = new RepeatingView("guidelineRepeater");
add(guidelineRepeater);
for (String guidelineFileName : projectService
.listGuidelines(aModel.getObject().getProject())) {
AbstractItem item = new AbstractItem(guidelineRepeater.newChildId());
guidelineRepeater.add(item);
// Add a popup window link to display annotation guidelines
PopupSettings popupSettings = new PopupSettings(
PopupSettings.RESIZABLE | PopupSettings.SCROLLBARS).setHeight(500)
.setWidth(700);
IResourceStream stream = new FileResourceStream(projectService
.getGuideline(aModel.getObject().getProject(), guidelineFileName));
ResourceStreamResource resource = new ResourceStreamResource(stream);
ResourceLink<Void> rlink = new ResourceLink<>("guideine", resource);
rlink.setPopupSettings(popupSettings);
item.add(new Label("guidelineName", guidelineFileName));
item.add(rlink);
}
add(new LambdaAjaxLink("cancel", (target) -> modalWindow.close(target)));
}
示例12: updateCache
import org.apache.wicket.util.resource.FileResourceStream; //导入依赖的package包/类
private void updateCache(Key key, IResourceStream stream) {
if (null == stream) {
cache.put(key, DMDNullResourceStreamReference.INSTANCE);
} else if (stream instanceof FileResourceStream) {
FileResourceStream fileResourceStream = (FileResourceStream) stream;
cache.put(key, new DMDFileResourceStreamReference(fileResourceStream));
} else if (stream instanceof UrlResourceStream) {
UrlResourceStream urlResourceStream = (UrlResourceStream) stream;
cache.put(key, new DMDUrlResourceStreamReference(urlResourceStream));
}
}
示例13: onClick
import org.apache.wicket.util.resource.FileResourceStream; //导入依赖的package包/类
@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 = encodedFileName();
final IResourceStream resourceStream = new FileResourceStream(
new org.apache.wicket.util.file.File(file)) {
private static final long serialVersionUID = 1L;
@Override
public String getContentType() {
return "application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml";
}
};
getRequestCycle().scheduleRequestHandlerAfterCurrent(
new ResourceStreamRequestHandler(resourceStream)
{
@Override
public void respond(IRequestCycle requestCycle)
{
super.respond(requestCycle);
Files.remove(file);
}
}.setFileName(fileName)
.setContentDisposition(ContentDisposition.ATTACHMENT));
}
示例14: respond
import org.apache.wicket.util.resource.FileResourceStream; //导入依赖的package包/类
@Override
public void respond(final Attributes attributes) {
final FileResourceStream fileResourceStream = new FileResourceStream(file);
final ResourceStreamResource resource = new ResourceStreamResource(fileResourceStream);
resource.respond(attributes);
}
示例15: DMDFileResourceStreamReference
import org.apache.wicket.util.resource.FileResourceStream; //导入依赖的package包/类
DMDFileResourceStreamReference(final FileResourceStream fileResourceStream) {
fileName = fileResourceStream.getFile().getAbsolutePath();
saveResourceStream(fileResourceStream);
}