瀏覽代碼

fix #1169 add addInlineMimeType

Shinsuke Sugaya 8 年之前
父節點
當前提交
e5c2865408
共有 2 個文件被更改,包括 27 次插入5 次删除
  1. 24 5
      src/main/java/org/codelibs/fess/helper/ViewHelper.java
  2. 3 0
      src/main/resources/app.xml

+ 24 - 5
src/main/java/org/codelibs/fess/helper/ViewHelper.java

@@ -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;
     }

+ 3 - 0
src/main/resources/app.xml

@@ -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>