|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.vaadin.server.AbstractClientConnector
com.vaadin.server.AbstractExtension
com.vaadin.server.FileDownloader
public class FileDownloader
Extension that starts a download when the extended component is clicked. This is used to overcome two challenges:
Please note that the download will be started in an iframe, which means that
care should be taken to avoid serving content types that might make the
browser attempt to show the content using a plugin instead of downloading it.
Connector resources (e.g. FileResource
and ClassResource
)
will automatically be served using a
Content-Type: application/octet-stream
header unless
setOverrideContentType(boolean)
has been set to false
while files served in other ways, (e.g. ExternalResource
or
ThemeResource
) will not automatically get this treatment.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector |
---|
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener |
Constructor Summary | |
---|---|
FileDownloader(Resource resource)
Creates a new file downloader for the given resource. |
Method Summary | |
---|---|
void |
extend(AbstractComponent target)
|
Resource |
getFileDownloadResource()
Gets the resource set for download. |
boolean |
handleConnectorRequest(VaadinRequest request,
VaadinResponse response,
java.lang.String path)
Handle a request directed to this connector. |
boolean |
isOverrideContentType()
Checks whether the content type should be overridden. |
void |
setFileDownloadResource(Resource resource)
Sets the resource that is downloaded when the extended component is clicked. |
void |
setOverrideContentType(boolean overrideContentType)
Sets whether the content type of served resources should be overriden to application/octet-stream to reduce the risk of a browser
plugin choosing to display the resource instead of downloading it. |
Methods inherited from class com.vaadin.server.AbstractExtension |
---|
extend, getParent, getSupportedParentType, remove, setParent |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.vaadin.server.ClientConnector |
---|
addAttachListener, addDetachListener, attach, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, getUI, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler |
Methods inherited from interface com.vaadin.shared.Connector |
---|
getConnectorId |
Constructor Detail |
---|
public FileDownloader(Resource resource)
AbstractExtension.extend(AbstractClientConnector)
the
component.
resource
- the resource to download when the user clicks the extended
component.Method Detail |
---|
public void extend(AbstractComponent target)
public Resource getFileDownloadResource()
public void setFileDownloadResource(Resource resource)
resource
- the resource to downloadpublic void setOverrideContentType(boolean overrideContentType)
application/octet-stream
to reduce the risk of a browser
plugin choosing to display the resource instead of downloading it. This
is by default set to true
.
Please note that this only affects Connector resources (e.g.
FileResource
and ClassResource
) but not other resource
types (e.g. ExternalResource
or ThemeResource
).
overrideContentType
- true
to override the content type if possible;
false
to use the original content type.public boolean isOverrideContentType()
true
if the content type will be overridden when
possible; false
if the original content type will be
used.setOverrideContentType(boolean)
public boolean handleConnectorRequest(VaadinRequest request, VaadinResponse response, java.lang.String path) throws java.io.IOException
ClientConnector
ConnectorResource
s.
Requests to /APP/connector/[ui id]/[connector id]/
are
routed to this method with the remaining part of the requested path
available in the path parameter.
NOTE that the session is not locked when this method is called. It is the responsibility of the connector to ensure that the session is locked while handling state or other session related data. For best performance the session should be unlocked before writing a large response to the client.
handleConnectorRequest
in interface ClientConnector
handleConnectorRequest
in class AbstractClientConnector
request
- the request that should be handledresponse
- the response object to which the response should be writtenpath
- the requested relative path
true
if the request has been handled,
false
if no response has been written.
java.io.IOException
- if there is a problem generating a response.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |