diff --git a/src/main/java/org/codelibs/fess/api/BaseApiManager.java b/src/main/java/org/codelibs/fess/api/BaseApiManager.java index 061785633..9914f2632 100644 --- a/src/main/java/org/codelibs/fess/api/BaseApiManager.java +++ b/src/main/java/org/codelibs/fess/api/BaseApiManager.java @@ -18,10 +18,12 @@ package org.codelibs.fess.api; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; +import java.util.Locale; import javax.servlet.http.HttpServletResponse; import org.codelibs.core.exception.IORuntimeException; +import org.codelibs.fess.Constants; import org.lastaflute.web.util.LaRequestUtil; import org.lastaflute.web.util.LaResponseUtil; @@ -45,7 +47,7 @@ public abstract class BaseApiManager implements WebApiManager { if (formatType == null) { return FormatType.SEARCH; } - final String type = formatType.toUpperCase(); + final String type = formatType.toUpperCase(Locale.ROOT); if (FormatType.SEARCH.name().equals(type)) { return FormatType.SEARCH; } else if (FormatType.LABEL.name().equals(type)) { @@ -64,28 +66,27 @@ public abstract class BaseApiManager implements WebApiManager { } } - public static void write(final String text, String contentType, String encoding) { + public static void write(final String text, final String contentType, final String encoding) { + final StringBuilder buf = new StringBuilder(50); if (contentType == null) { - contentType = "text/plain"; + buf.append("text/plain"); + } else { + buf.append(contentType); } + buf.append("; charset="); if (encoding == null) { - encoding = LaRequestUtil.getRequest().getCharacterEncoding(); - if (encoding == null) { - encoding = "UTF-8"; + if (LaRequestUtil.getRequest().getCharacterEncoding() == null) { + buf.append(Constants.UTF_8); + } else { + buf.append(LaRequestUtil.getRequest().getCharacterEncoding()); } + } else { + buf.append(encoding); } final HttpServletResponse response = LaResponseUtil.getResponse(); - response.setContentType(contentType + "; charset=" + encoding); - try { - PrintWriter out = null; - try { - out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), encoding)); - out.print(text); - } finally { - if (out != null) { - out.close(); - } - } + response.setContentType(buf.toString()); + try (PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), encoding))) { + out.print(text); } catch (final IOException e) { throw new IORuntimeException(e); } diff --git a/src/main/java/org/codelibs/fess/mylasta/direction/sponsor/FessMultipartRequestHandler.java b/src/main/java/org/codelibs/fess/mylasta/direction/sponsor/FessMultipartRequestHandler.java index 28c29777a..13fefe19f 100644 --- a/src/main/java/org/codelibs/fess/mylasta/direction/sponsor/FessMultipartRequestHandler.java +++ b/src/main/java/org/codelibs/fess/mylasta/direction/sponsor/FessMultipartRequestHandler.java @@ -311,13 +311,10 @@ public class FessMultipartRequestHandler implements MultipartRequestHandler { } protected String getRepositoryPath() { - String tempDir = null; + final File tempDirFile = (File) LaServletContextUtil.getServletContext().getAttribute(CONTEXT_TEMPDIR_KEY); + String tempDir = tempDirFile.getAbsolutePath(); if (tempDir == null || tempDir.length() == 0) { - final File tempDirFile = (File) LaServletContextUtil.getServletContext().getAttribute(CONTEXT_TEMPDIR_KEY); - tempDir = tempDirFile.getAbsolutePath(); - if (tempDir == null || tempDir.length() == 0) { - tempDir = System.getProperty(JAVA_IO_TMPDIR_KEY); - } + tempDir = System.getProperty(JAVA_IO_TMPDIR_KEY); } return tempDir; } diff --git a/src/main/java/org/codelibs/fess/util/KuromojiCSVUtil.java b/src/main/java/org/codelibs/fess/util/KuromojiCSVUtil.java index 4f6fda0d7..6dfda81c1 100644 --- a/src/main/java/org/codelibs/fess/util/KuromojiCSVUtil.java +++ b/src/main/java/org/codelibs/fess/util/KuromojiCSVUtil.java @@ -119,7 +119,7 @@ public final class KuromojiCSVUtil { String result = original; if (result.indexOf('\"') >= 0) { - result.replace("\"", ESCAPED_QUOTE); + result = result.replace("\"", ESCAPED_QUOTE); } if (result.indexOf(COMMA) >= 0) { result = "\"" + result + "\"";