Jelajahi Sumber

fix #2784 Added functionality to set Content-Disposition to inline based on MIME types configuration

Shinsuke Sugaya 1 tahun lalu
induk
melakukan
e35c04d8c6

+ 4 - 2
src/main/java/org/codelibs/fess/helper/ViewHelper.java

@@ -83,7 +83,6 @@ import org.lastaflute.web.response.ActionResponse;
 import org.lastaflute.web.response.StreamResponse;
 import org.lastaflute.web.response.StreamResponse;
 import org.lastaflute.web.ruts.process.ActionRuntime;
 import org.lastaflute.web.ruts.process.ActionRuntime;
 import org.lastaflute.web.util.LaRequestUtil;
 import org.lastaflute.web.util.LaRequestUtil;
-import org.lastaflute.web.util.LaResponseUtil;
 import org.lastaflute.web.util.LaServletContextUtil;
 import org.lastaflute.web.util.LaServletContextUtil;
 import org.opensearch.core.common.text.Text;
 import org.opensearch.core.common.text.Text;
 import org.opensearch.search.fetch.subphase.highlight.HighlightField;
 import org.opensearch.search.fetch.subphase.highlight.HighlightField;
@@ -211,6 +210,9 @@ public class ViewHelper {
         textFragmentPrefixLength = fessConfig.getQueryHighlightTextFragmentPrefixLengthAsInteger();
         textFragmentPrefixLength = fessConfig.getQueryHighlightTextFragmentPrefixLengthAsInteger();
         textFragmentSuffixLength = fessConfig.getQueryHighlightTextFragmentSuffixLengthAsInteger();
         textFragmentSuffixLength = fessConfig.getQueryHighlightTextFragmentSuffixLengthAsInteger();
         textFragmentSize = fessConfig.getQueryHighlightTextFragmentSizeAsInteger();
         textFragmentSize = fessConfig.getQueryHighlightTextFragmentSizeAsInteger();
+
+        split(fessConfig.getResponseInlineMimetypes(), ",")
+                .of(stream -> stream.map(String::trim).filter(StringUtil::isNotEmpty).forEach(inlineMimeTypeSet::add));
     }
     }
 
 
     public String getContentTitle(final Map<String, Object> document) {
     public String getContentTitle(final Map<String, Object> document) {
@@ -759,7 +761,7 @@ public class ViewHelper {
             return;
             return;
         }
         }
         if (mimeType.startsWith("text/")) {
         if (mimeType.startsWith("text/")) {
-            final String charset = LaResponseUtil.getResponse().getCharacterEncoding();
+            final String charset = responseData.getCharSet();
             if (charset != null) {
             if (charset != null) {
                 response.contentType(mimeType + "; charset=" + charset);
                 response.contentType(mimeType + "; charset=" + charset);
                 return;
                 return;

+ 15 - 0
src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java

@@ -673,6 +673,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
     /** The key of the configuration. e.g. true */
     /** The key of the configuration. e.g. true */
     String RESPONSE_HIGHLIGHT_content_title_ENABLED = "response.highlight.content_title.enabled";
     String RESPONSE_HIGHLIGHT_content_title_ENABLED = "response.highlight.content_title.enabled";
 
 
+    /** The key of the configuration. e.g. application/pdf,text/plain */
+    String RESPONSE_INLINE_MIMETYPES = "response.inline.mimetypes";
+
     /** The key of the configuration. e.g. fess.search */
     /** The key of the configuration. e.g. fess.search */
     String INDEX_DOCUMENT_SEARCH_INDEX = "index.document.search.index";
     String INDEX_DOCUMENT_SEARCH_INDEX = "index.document.search.index";
 
 
@@ -3881,6 +3884,13 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
      */
      */
     boolean isResponseHighlightContentTitleEnabled();
     boolean isResponseHighlightContentTitleEnabled();
 
 
+    /**
+     * Get the value for the key 'response.inline.mimetypes'. <br>
+     * The value is, e.g. application/pdf,text/plain <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     */
+    String getResponseInlineMimetypes();
+
     /**
     /**
      * Get the value for the key 'index.document.search.index'. <br>
      * Get the value for the key 'index.document.search.index'. <br>
      * The value is, e.g. fess.search <br>
      * The value is, e.g. fess.search <br>
@@ -8774,6 +8784,10 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
             return is(FessConfig.RESPONSE_HIGHLIGHT_content_title_ENABLED);
             return is(FessConfig.RESPONSE_HIGHLIGHT_content_title_ENABLED);
         }
         }
 
 
+        public String getResponseInlineMimetypes() {
+            return get(FessConfig.RESPONSE_INLINE_MIMETYPES);
+        }
+
         public String getIndexDocumentSearchIndex() {
         public String getIndexDocumentSearchIndex() {
             return get(FessConfig.INDEX_DOCUMENT_SEARCH_INDEX);
             return get(FessConfig.INDEX_DOCUMENT_SEARCH_INDEX);
         }
         }
@@ -10990,6 +11004,7 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
             defaultMap.put(FessConfig.RESPONSE_MAX_TITLE_LENGTH, "50");
             defaultMap.put(FessConfig.RESPONSE_MAX_TITLE_LENGTH, "50");
             defaultMap.put(FessConfig.RESPONSE_MAX_SITE_PATH_LENGTH, "100");
             defaultMap.put(FessConfig.RESPONSE_MAX_SITE_PATH_LENGTH, "100");
             defaultMap.put(FessConfig.RESPONSE_HIGHLIGHT_content_title_ENABLED, "true");
             defaultMap.put(FessConfig.RESPONSE_HIGHLIGHT_content_title_ENABLED, "true");
+            defaultMap.put(FessConfig.RESPONSE_INLINE_MIMETYPES, "application/pdf,text/plain");
             defaultMap.put(FessConfig.INDEX_DOCUMENT_SEARCH_INDEX, "fess.search");
             defaultMap.put(FessConfig.INDEX_DOCUMENT_SEARCH_INDEX, "fess.search");
             defaultMap.put(FessConfig.INDEX_DOCUMENT_UPDATE_INDEX, "fess.update");
             defaultMap.put(FessConfig.INDEX_DOCUMENT_UPDATE_INDEX, "fess.update");
             defaultMap.put(FessConfig.INDEX_DOCUMENT_SUGGEST_INDEX, "fess");
             defaultMap.put(FessConfig.INDEX_DOCUMENT_SUGGEST_INDEX, "fess");

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

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

+ 1 - 0
src/main/resources/fess_config.properties

@@ -337,6 +337,7 @@ response.field.site_path=site_path
 response.max.title.length=50
 response.max.title.length=50
 response.max.site.path.length=100
 response.max.site.path.length=100
 response.highlight.content_title.enabled=true
 response.highlight.content_title.enabled=true
+response.inline.mimetypes=application/pdf,text/plain
 
 
 # document index
 # document index
 index.document.search.index=fess.search
 index.document.search.index=fess.search