|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjp.terasoluna.fw.web.struts.actions.FileDownloadUtil
public class FileDownloadUtil
Utility class which downloads the file.
DownloadFileNameEncoder
implementation class
and do the settings in Bean definition file.
DownloadFileNameEncoder
User-Agent
detects the browser.
If the browser is FireFox, encoding is performed by using commons-codec class.
public class MyEncoder implements DownloadFileNameEncoder {
public String encode(String original, HttpServletRequest request,
HttpServletResponse response) {
String userAgent = request.getHeader("User-Agent");
if (StringUtils.contains(userAgent, "MSIE")) {
return encodeForIE(original);
} else if (StringUtils.contains(userAgent, "Gecko")) {
return encodeForGecko(original);
}
return encodeForIE(original);
}
protected String encodeForGecko(String original) {
try {
return new BCodec().encode(original);
} catch (EncoderException e) {
return original;
}
}
protected String encodeForIE(String original) {
try {
return URLEncoder.encode(original,
AbstractDownloadObject.DEFAULT_CHARSET);
} catch (UnsupportedEncodingException e) {
return original;
}
}
}
<bean class="jp.terasoluna.fw.web.struts.actions.FileDownloadUtil">
<property name="encoder" ref="encoder"/>
</bean>
<bean name="encoder" class="sample.MyEncoder"/>
Field Summary | |
---|---|
protected static DownloadFileNameEncoder |
encoder
Encoder of specified file name. |
static java.lang.String |
HEADER_CONTENT_DISPOSITION
CONTENT-DISPOSITION header name of response. |
private static org.apache.commons.logging.Log |
log
Log class. |
static java.lang.String |
TOO_MANY_DOWNLOAD_ERROR
Error code indicating that there are more than 1 instances for downloading. |
Constructor Summary | |
---|---|
FileDownloadUtil()
|
Method Summary | |
---|---|
static void |
download(AbstractDownloadObject downloadObject,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
boolean forceDownload)
Download through browser. |
static void |
download(java.lang.Object result,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Download through browser. |
void |
setEncoder(DownloadFileNameEncoder encoder)
Sets the encoder of specified file name. |
protected static void |
setFileName(javax.servlet.http.HttpServletResponse response,
java.lang.String name,
boolean forceDownload)
Sets file name. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final org.apache.commons.logging.Log log
public static final java.lang.String HEADER_CONTENT_DISPOSITION
CONTENT-DISPOSITION
header name of response.
public static final java.lang.String TOO_MANY_DOWNLOAD_ERROR
protected static DownloadFileNameEncoder encoder
Constructor Detail |
---|
public FileDownloadUtil()
Method Detail |
---|
public void setEncoder(DownloadFileNameEncoder encoder)
encoder
- Encoder of specified file name.public static void download(java.lang.Object result, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
result
- Instance that retains the download data.request
- Request.response
- Response.public static void download(AbstractDownloadObject downloadObject, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, boolean forceDownload) throws java.io.IOException
downloadObject
- Download target. request
- Request.response
- Response.
java.io.IOException
- When the I/O exception has occurred at the time of download.protected static void setFileName(javax.servlet.http.HttpServletResponse response, java.lang.String name, boolean forceDownload)
response
- Response.name
- Download name.forceDownload
- Check if it is forcible download. true
when forcible download.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |