Package com.vaadin.flow.server.streams
Class AbstractDownloadHandler<R extends AbstractDownloadHandler>
java.lang.Object
com.vaadin.flow.server.streams.TransferProgressAwareHandler<DownloadEvent,R>
com.vaadin.flow.server.streams.AbstractDownloadHandler<R>
- Type Parameters:
R- the type of the subclass implementing this abstract class
- All Implemented Interfaces:
DownloadHandler,ElementRequestHandler,Serializable
- Direct Known Subclasses:
ClassDownloadHandler,FileDownloadHandler,InputStreamDownloadHandler,ServletResourceDownloadHandler
public abstract class AbstractDownloadHandler<R extends AbstractDownloadHandler>
extends TransferProgressAwareHandler<DownloadEvent,R>
implements DownloadHandler
Abstract class for common methods used in pre-made download handlers.
- Since:
- 24.8
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the MIME type set withwithContentType(String).protected StringgetContentType(String fileName, VaadinResponse response) Gets the MIME type that the servlet container maps to the given file name, orapplication/octet-streamwhen it maps none.protected TransferContextgetTransferContext(DownloadEvent transferEvent) This method is used to get the transfer context from the transfer events (e.g.inline()Sets this download content to be displayed inside the Web page, or as the Web page, e.g. as an image or inside an iframe.booleanisInline()Returns if the download content to be displayed inside the Web page or downloaded as a file.protected final StringresolveContentType(String fileName, VaadinResponse response) Resolves the MIME type that the content is served with: the one set withwithContentType(String), or else the one thatgetContentType(String, VaadinResponse)gives for the file name.withContentType(String contentType) Sets the MIME type that the content is served with, such astext/vtt, instead of the one that the servlet container maps to the file name, orapplication/octet-streamwhen it maps none.Methods inherited from class com.vaadin.flow.server.streams.TransferProgressAwareHandler
addTransferProgressListener, getListeners, notifyError, onProgress, onProgress, onProgress, onProgress, setTransferUI, uiAccess, whenComplete, whenComplete, whenStart, whenStartMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.server.streams.DownloadHandler
allowDisabled, handleDownloadRequest, handleRequest, isRangeRequestsEnabledMethods inherited from interface com.vaadin.flow.server.streams.ElementRequestHandler
getDisabledUpdateMode, getUrlPostfix, isAllowInert
-
Constructor Details
-
AbstractDownloadHandler
public AbstractDownloadHandler()
-
-
Method Details
-
getTransferContext
Description copied from class:TransferProgressAwareHandlerThis method is used to get the transfer context from the transfer events (e.g.DownloadEvent).- Specified by:
getTransferContextin classTransferProgressAwareHandler<DownloadEvent,R extends AbstractDownloadHandler> - Parameters:
transferEvent- the transfer event- Returns:
- the transfer context
-
getContentType
Gets the MIME type that the servlet container maps to the given file name, orapplication/octet-streamwhen it maps none.Unlike
getContentType(), this ignores the type set withwithContentType(String). Override it to change how the type is derived from the file name; to serve the content with the configured type when there is one, callresolveContentType(String, VaadinResponse)instead.- Parameters:
fileName- the name of the file to look up the type forresponse- the response, which gives access to the servlet container- Returns:
- the MIME type for the file name, not
null
-
withContentType
Sets the MIME type that the content is served with, such astext/vtt, instead of the one that the servlet container maps to the file name, orapplication/octet-streamwhen it maps none.A content type that a
DownloadResponsegives for a particular download still takes precedence over this one.- Parameters:
contentType- the MIME type of the content, notnullor blank- Returns:
- this instance for method chaining
- Throws:
IllegalArgumentException- if the content type is blank
-
getContentType
Gets the MIME type set withwithContentType(String).Unlike
getContentType(String, VaadinResponse), this does not look up a type for the file name. UseresolveContentType(String, VaadinResponse)for the type that the content is served with.- Returns:
- the MIME type that the content is served with, or
nullif it is taken from the file name
-
resolveContentType
Resolves the MIME type that the content is served with: the one set withwithContentType(String), or else the one thatgetContentType(String, VaadinResponse)gives for the file name. The built-in handlers serve their content with this type, and a subclass that sets the content type of its own response should do the same.- Parameters:
fileName- the name of the file to look up the type for when none is setresponse- the response, which gives access to the servlet container- Returns:
- the MIME type that the content is served with, not
null
-
inline
Sets this download content to be displayed inside the Web page, or as the Web page, e.g. as an image or inside an iframe.Implementations of this class should ensure that the 'Content-Disposition' attribute is 'inline', if this method is called.
- Returns:
- this instance for method chaining
-
isInline
public boolean isInline()Returns if the download content to be displayed inside the Web page or downloaded as a file.- Returns:
- true if the content is to be displayed inline, false if it is to be downloaded as a file
-