本文整理汇总了Java中org.apache.wicket.request.resource.ContentDisposition类的典型用法代码示例。如果您正苦于以下问题:Java ContentDisposition类的具体用法?Java ContentDisposition怎么用?Java ContentDisposition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContentDisposition类属于org.apache.wicket.request.resource包,在下文中一共展示了ContentDisposition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onRequest
import org.apache.wicket.request.resource.ContentDisposition; //导入依赖的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.resource.ContentDisposition; //导入依赖的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: onRequest
import org.apache.wicket.request.resource.ContentDisposition; //导入依赖的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: onRequest
import org.apache.wicket.request.resource.ContentDisposition; //导入依赖的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);
}
示例5: onRequest
import org.apache.wicket.request.resource.ContentDisposition; //导入依赖的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);
}
示例6: onClick
import org.apache.wicket.request.resource.ContentDisposition; //导入依赖的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);
}
示例7: NotificationPanel
import org.apache.wicket.request.resource.ContentDisposition; //导入依赖的package包/类
public NotificationPanel(String id, IModel<Pair<String, String>> model, IModel<RI> requirementModel) {
super(id);
add(new Label("title", model.getObject().getKey()));
add(new FileDownloadLink("export-to-pdf",
getPdfModel(model, requirementModel),
ContentDisposition.INLINE,
model.getObject().getValue() + ".pdf")
);
add(new Label("content", model.getObject().getValue()).setEscapeModelStrings(false));
}
示例8: onRequest
import org.apache.wicket.request.resource.ContentDisposition; //导入依赖的package包/类
@Override
public void onRequest() {
final ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(getResourceStream(),
getFileName());
handler.setContentDisposition(ContentDisposition.ATTACHMENT);
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
}
示例9: onRequest
import org.apache.wicket.request.resource.ContentDisposition; //导入依赖的package包/类
@Override
public void onRequest()
{
ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(
getResourceStream(), getFileName());
handler.setContentDisposition(ContentDisposition.ATTACHMENT);
getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(handler);
}
示例10: commonInit
import org.apache.wicket.request.resource.ContentDisposition; //导入依赖的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);
}
示例11: onRequest
import org.apache.wicket.request.resource.ContentDisposition; //导入依赖的package包/类
@Override
public void onRequest() {
RequestCycle.get().scheduleRequestHandlerAfterCurrent(
new ResourceStreamRequestHandler(getResourceStream())
.setFileName(fileName)
.setContentDisposition(ContentDisposition.ATTACHMENT));
}
示例12: onClick
import org.apache.wicket.request.resource.ContentDisposition; //导入依赖的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));
}
示例13: SAML2SPPanel
import org.apache.wicket.request.resource.ContentDisposition; //导入依赖的package包/类
public SAML2SPPanel(final String id) {
super(id);
add(new Link<Void>("downloadMetadata") {
private static final long serialVersionUID = -4331619903296515985L;
@Override
public void onClick() {
try {
HttpResourceStream stream = new HttpResourceStream(ClientBuilder.newClient().
target(RequestCycle.get().getUrlRenderer().renderFullUrl(Url.parse(
UrlUtils.rewriteToContextRelative("saml2sp/metadata", RequestCycle.get())))).
request().get());
ResourceStreamRequestHandler rsrh = new ResourceStreamRequestHandler(stream);
rsrh.setFileName(stream.getFilename() == null
? SyncopeConsoleSession.get().getDomain() + "-SAML-SP-Metadata.xml"
: stream.getFilename());
rsrh.setContentDisposition(ContentDisposition.ATTACHMENT);
getRequestCycle().scheduleRequestHandlerAfterCurrent(rsrh);
} catch (Exception e) {
LOG.error("While exporting SAML 2.0 SP metadata", e);
SyncopeConsoleSession.get().error(getString(Constants.ERROR) + ": " + e.getMessage());
}
}
});
}
示例14: setDownloadTarget
import org.apache.wicket.request.resource.ContentDisposition; //导入依赖的package包/类
/**
* @param content The content of the file to download.
* @param filename
* @param contentType For setting contentType manually.
*/
public static void setDownloadTarget(final byte[] content, final String filename, final String contentType)
{
final ByteArrayResourceStream byteArrayResourceStream;
if (contentType != null) {
byteArrayResourceStream = new ByteArrayResourceStream(content, filename, contentType);
} else {
byteArrayResourceStream = new ByteArrayResourceStream(content, filename);
}
final ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(byteArrayResourceStream);
handler.setFileName(filename).setContentDisposition(ContentDisposition.ATTACHMENT);
RequestCycle.get().scheduleRequestHandlerAfterCurrent(handler);
log.info("Starting download for file. filename:" + filename + ", content-type:" + byteArrayResourceStream.getContentType());
}
示例15: setResponseHeaders
import org.apache.wicket.request.resource.ContentDisposition; //导入依赖的package包/类
@Override
protected void setResponseHeaders(ResourceResponse data, Attributes attributes) {
data.disableCaching();
data.setContentDisposition(ContentDisposition.ATTACHMENT);
String name;
if (charts.size() == 1) {
name = charts.get(0).getName();
} else {
name = "downloaded_charts";
}
data.setFileName(name + ".zip");
super.setResponseHeaders(data, attributes);
}