本文整理汇总了Java中org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler类的典型用法代码示例。如果您正苦于以下问题:Java ResourceStreamRequestHandler类的具体用法?Java ResourceStreamRequestHandler怎么用?Java ResourceStreamRequestHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ResourceStreamRequestHandler类属于org.apache.wicket.request.handler.resource包,在下文中一共展示了ResourceStreamRequestHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onRequest
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler; //导入依赖的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: onRequest
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler; //导入依赖的package包/类
public void onRequest() {
IResourceStream resourceStream = getResourceStream();
if (resourceStream == null) {
return; // We hope the error was already processed and will be shown.
}
ResourceStreamRequestHandler reqHandler = new ResourceStreamRequestHandler(resourceStream) {
@Override
public void respond(IRequestCycle requestCycle) {
super.respond(requestCycle);
}
}.setContentDisposition(ContentDisposition.ATTACHMENT)
.setCacheDuration(Duration.ONE_SECOND);
if (StringUtils.isNotEmpty(getFileName())){
reqHandler.setFileName(getFileName());
}
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(reqHandler);
}
示例3: createExportButton
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler; //导入依赖的package包/类
private void createExportButton(boolean visible) {
exportLink = new Link("export") {
@Override
public void onClick() {
JsonNode doc = documentService.getDocumentById(docId);
String filename = doc.get("data").get("Title").asText() + ".pdf";
final ByteArrayOutputStream baos = documentService.convertToPdf(doc);
AbstractResourceStreamWriter rstream = new AbstractResourceStreamWriter() {
@Override
public void write(OutputStream output) throws IOException {
output.write(baos.toByteArray());
baos.close();
output.close();
}
};
ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(rstream, filename);
getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
}
};
addComponent(exportLink, visible);
}
示例4: onRequest
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler; //导入依赖的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));
}
示例5: onRequest
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler; //导入依赖的package包/类
public void onRequest() {
IResourceStream resourceStream = getResourceStream();
if (resourceStream == null) {
return; // We hope the error was already processed and will be shown.
}
ResourceStreamRequestHandler reqHandler = new ResourceStreamRequestHandler(resourceStream) {
@Override
public void respond(IRequestCycle requestCycle) {
super.respond(requestCycle);
}
}.setContentDisposition(ContentDisposition.ATTACHMENT)
.setCacheDuration(Duration.ONE_SECOND);
if (StringUtils.isNotEmpty(getFileName())){
reqHandler.setFileName(getFileName());
}
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(reqHandler);
}
示例6: onRequest
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler; //导入依赖的package包/类
@Override
public void onRequest() {
HttpResourceStream stream = getResourceStream();
ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(stream);
String key = StringUtils.isNotBlank(fileKey) ? fileKey + "_" : "";
String ext = "";
if (StringUtils.isNotBlank(mimeType)) {
String extByMimeType = MIME_TYPES_LOADER.getFileExt(mimeType);
ext = StringUtils.isBlank(extByMimeType) ? ".bin" : ("." + extByMimeType);
}
String fileName = key + (stream.getFilename() == null ? name : stream.getFilename()) + ext;
handler.setFileName(fileName);
handler.setContentDisposition(ContentDisposition.ATTACHMENT);
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
}
示例7: onRequest
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler; //导入依赖的package包/类
@Override
public void onRequest() {
IResourceStream resourceStream = new AbstractResourceStreamWriter() {
@Override
public String getContentType() {
return exportAction.getContentType();
}
@Override
public void write(OutputStream output) throws IOException {
exportAction.writeContent(output);
}
};
RequestCycle.get().scheduleRequestHandlerAfterCurrent(new ResourceStreamRequestHandler(resourceStream, exportAction.getFileName()));
}
示例8: onClick
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler; //导入依赖的package包/类
@Override
public void onClick() {
final InputStream stream = getModelObject();
if (stream == null) {
throw new IllegalStateException(getClass().getName() + " failed to retrieve a File object from model");
}
InputStreamResourceStream resourceStream = new InputStreamResourceStream(stream);
// maybe file name and display name should be seperated?
ResourceStreamRequestHandler requestHandler = new ResourceStreamRequestHandler(resourceStream,
String.valueOf(getBody().getObject()));
requestHandler.setContentDisposition(ContentDisposition.ATTACHMENT);
getRequestCycle().scheduleRequestHandlerAfterCurrent(requestHandler);
}
示例9: mapRequest
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler; //导入依赖的package包/类
@Override
public IRequestHandler mapRequest(Request request) {
final Url url = new Url(request.getUrl());
if (!urlStartsWith(url, mountSegments)) {
return null;
}
url.removeLeadingSegments(mountSegments.length);
return new ResourceStreamRequestHandler(new PackageResourceStream(scope, url.getPath()));
}
示例10: onRequest
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler; //导入依赖的package包/类
@Override
public void onRequest() {
final ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(getResourceStream(),
getFileName());
handler.setContentDisposition(ContentDisposition.ATTACHMENT);
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
}
示例11: onRequest
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler; //导入依赖的package包/类
@Override
public void onRequest()
{
ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(
getResourceStream(), getFileName());
handler.setContentDisposition(ContentDisposition.ATTACHMENT);
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
}
示例12: commonInit
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler; //导入依赖的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);
}
示例13: onRequest
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler; //导入依赖的package包/类
@Override
public void onRequest() {
RequestCycle.get().scheduleRequestHandlerAfterCurrent(
new ResourceStreamRequestHandler(getResourceStream())
.setFileName(fileName)
.setContentDisposition(ContentDisposition.ATTACHMENT));
}
示例14: onClick
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler; //导入依赖的package包/类
@Override
public void onClick() {
IResourceStream resourceStream = getResourceStream();
RequestCycle requestCycle = getRequestCycle();
WebResponse response = (WebResponse) requestCycle.getResponse();
response.setHeader("Cache-Control", "no-store");
requestCycle.scheduleRequestHandlerAfterCurrent(
new ResourceStreamRequestHandler(resourceStream)
.setFileName(getFileName())
.setContentDisposition(ContentDisposition.ATTACHMENT));
}
示例15: onRequest
import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler; //导入依赖的package包/类
@Override
public void onRequest() {
try {
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(
new ResourceStreamRequestHandler(getResourceStream(), getFileName()));
} catch (Exception e) {
// cannot be notifies beacause the use of scheduleRequestHandlerAfterCurrent
LOG.error("Error downloading file", e);
}
}