Skip to content

Commit

Permalink
fix #2784 Added functionality to set Content-Disposition to inline ba…
Browse files Browse the repository at this point in the history
…sed on MIME types configuration
  • Loading branch information
marevol committed Nov 19, 2023
1 parent 5bbf180 commit e35c04d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/main/java/org/codelibs/fess/helper/ViewHelper.java
Expand Up @@ -83,7 +83,6 @@
import org.lastaflute.web.response.StreamResponse;
import org.lastaflute.web.ruts.process.ActionRuntime;
import org.lastaflute.web.util.LaRequestUtil;
import org.lastaflute.web.util.LaResponseUtil;
import org.lastaflute.web.util.LaServletContextUtil;
import org.opensearch.core.common.text.Text;
import org.opensearch.search.fetch.subphase.highlight.HighlightField;
Expand Down Expand Up @@ -211,6 +210,9 @@ public void init() {
textFragmentPrefixLength = fessConfig.getQueryHighlightTextFragmentPrefixLengthAsInteger();
textFragmentSuffixLength = fessConfig.getQueryHighlightTextFragmentSuffixLengthAsInteger();
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) {
Expand Down Expand Up @@ -759,7 +761,7 @@ protected void writeContentType(final StreamResponse response, final ResponseDat
return;
}
if (mimeType.startsWith("text/")) {
final String charset = LaResponseUtil.getResponse().getCharacterEncoding();
final String charset = responseData.getCharSet();
if (charset != null) {
response.contentType(mimeType + "; charset=" + charset);
return;
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java
Expand Up @@ -673,6 +673,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/** The key of the configuration. e.g. true */
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 */
String INDEX_DOCUMENT_SEARCH_INDEX = "index.document.search.index";

Expand Down Expand Up @@ -3881,6 +3884,13 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
*/
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>
* The value is, e.g. fess.search <br>
Expand Down Expand Up @@ -8774,6 +8784,10 @@ public boolean isResponseHighlightContentTitleEnabled() {
return is(FessConfig.RESPONSE_HIGHLIGHT_content_title_ENABLED);
}

public String getResponseInlineMimetypes() {
return get(FessConfig.RESPONSE_INLINE_MIMETYPES);
}

public String getIndexDocumentSearchIndex() {
return get(FessConfig.INDEX_DOCUMENT_SEARCH_INDEX);
}
Expand Down Expand Up @@ -10990,6 +11004,7 @@ protected java.util.Map<String, String> prepareGeneratedDefaultMap() {
defaultMap.put(FessConfig.RESPONSE_MAX_TITLE_LENGTH, "50");
defaultMap.put(FessConfig.RESPONSE_MAX_SITE_PATH_LENGTH, "100");
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_UPDATE_INDEX, "fess.update");
defaultMap.put(FessConfig.INDEX_DOCUMENT_SUGGEST_INDEX, "fess");
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/app.xml
Expand Up @@ -56,9 +56,6 @@
</postConstruct>
</component>
<component name="viewHelper" class="org.codelibs.fess.helper.ViewHelper">
<postConstruct name="addInlineMimeType">
<arg>"application/pdf"</arg>
</postConstruct>
</component>
<component name="userAgentHelper" class="org.codelibs.fess.helper.UserAgentHelper">
</component>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/fess_config.properties
Expand Up @@ -337,6 +337,7 @@ response.field.site_path=site_path
response.max.title.length=50
response.max.site.path.length=100
response.highlight.content_title.enabled=true
response.inline.mimetypes=application/pdf,text/plain

# document index
index.document.search.index=fess.search
Expand Down

0 comments on commit e35c04d

Please sign in to comment.