fix #1169 add addInlineMimeType

This commit is contained in:
Shinsuke Sugaya 2017-07-17 22:35:51 +09:00
parent be409c27d0
commit e5c2865408
2 changed files with 27 additions and 5 deletions

View file

@ -25,9 +25,11 @@ import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import java.util.function.Function;
@ -78,6 +80,8 @@ import com.ibm.icu.text.SimpleDateFormat;
public class ViewHelper {
private static final String CONTENT_DISPOSITION = "Content-Disposition";
private static final String HL_CACHE = "hl_cache";
private static final String QUERIES = "queries";
@ -135,6 +139,8 @@ public class ViewHelper {
protected ActionHook actionHook = new ActionHook();
private Set<String> inlineMimeTypeSet = new HashSet<>();
@PostConstruct
public void init() {
escapedHighlightPre = LaFunctions.h(originalHighlightTagPre);
@ -557,22 +563,31 @@ public class ViewHelper {
logger.debug("userAgentType: " + userAgentType + ", charset: " + charset + ", name: " + name);
}
final String contentDispositionType;
if (inlineMimeTypeSet.contains(responseData.getMimeType())) {
contentDispositionType = "inline";
} else {
contentDispositionType = "attachment";
}
switch (userAgentType) {
case IE:
response.header("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode(name, Constants.UTF_8) + "\"");
response.header(CONTENT_DISPOSITION, contentDispositionType + "; filename=\"" + URLEncoder.encode(name, Constants.UTF_8)
+ "\"");
break;
case OPERA:
response.header("Content-Disposition", "attachment; filename*=utf-8'ja'" + URLEncoder.encode(name, Constants.UTF_8));
response.header(CONTENT_DISPOSITION,
contentDispositionType + "; filename*=utf-8'ja'" + URLEncoder.encode(name, Constants.UTF_8));
break;
case SAFARI:
response.header("Content-Disposition", "attachment; filename=\"" + name + "\"");
response.header(CONTENT_DISPOSITION, contentDispositionType + "; filename=\"" + name + "\"");
break;
case CHROME:
case FIREFOX:
case OTHER:
default:
response.header("Content-Disposition",
"attachment; filename=\"=?utf-8?B?" + Base64Util.encode(name.getBytes(Constants.UTF_8)) + "?=\"");
response.header(CONTENT_DISPOSITION,
contentDispositionType + "; filename=\"=?utf-8?B?" + Base64Util.encode(name.getBytes(Constants.UTF_8)) + "?=\"");
break;
}
} catch (final Exception e) {
@ -640,6 +655,10 @@ public class ViewHelper {
return facetQueryViewList;
}
public void addInlineMimeType(final String mimeType) {
inlineMimeTypeSet.add(mimeType);
}
public ActionHook getActionHook() {
return actionHook;
}

View file

@ -328,6 +328,9 @@
</component>
</arg>
</postConstruct>
<postConstruct name="addInlineMimeType">
<arg>"application/pdf"</arg>
</postConstruct>
</component>
<component name="userAgentHelper" class="org.codelibs.fess.helper.UserAgentHelper">
</component>