Shinsuke Sugaya 9 år sedan
förälder
incheckning
2b20a0a02f

+ 18 - 17
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.IOException;
 import java.io.OutputStreamWriter;
 import java.io.OutputStreamWriter;
 import java.io.PrintWriter;
 import java.io.PrintWriter;
+import java.util.Locale;
 
 
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.HttpServletResponse;
 
 
 import org.codelibs.core.exception.IORuntimeException;
 import org.codelibs.core.exception.IORuntimeException;
+import org.codelibs.fess.Constants;
 import org.lastaflute.web.util.LaRequestUtil;
 import org.lastaflute.web.util.LaRequestUtil;
 import org.lastaflute.web.util.LaResponseUtil;
 import org.lastaflute.web.util.LaResponseUtil;
 
 
@@ -45,7 +47,7 @@ public abstract class BaseApiManager implements WebApiManager {
         if (formatType == null) {
         if (formatType == null) {
             return FormatType.SEARCH;
             return FormatType.SEARCH;
         }
         }
-        final String type = formatType.toUpperCase();
+        final String type = formatType.toUpperCase(Locale.ROOT);
         if (FormatType.SEARCH.name().equals(type)) {
         if (FormatType.SEARCH.name().equals(type)) {
             return FormatType.SEARCH;
             return FormatType.SEARCH;
         } else if (FormatType.LABEL.name().equals(type)) {
         } 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) {
         if (contentType == null) {
-            contentType = "text/plain";
+            buf.append("text/plain");
+        } else {
+            buf.append(contentType);
         }
         }
+        buf.append("; charset=");
         if (encoding == null) {
         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();
         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) {
         } catch (final IOException e) {
             throw new IORuntimeException(e);
             throw new IORuntimeException(e);
         }
         }

+ 3 - 6
src/main/java/org/codelibs/fess/mylasta/direction/sponsor/FessMultipartRequestHandler.java

@@ -311,13 +311,10 @@ public class FessMultipartRequestHandler implements MultipartRequestHandler {
     }
     }
 
 
     protected String getRepositoryPath() {
     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) {
         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;
         return tempDir;
     }
     }

+ 1 - 1
src/main/java/org/codelibs/fess/util/KuromojiCSVUtil.java

@@ -119,7 +119,7 @@ public final class KuromojiCSVUtil {
         String result = original;
         String result = original;
 
 
         if (result.indexOf('\"') >= 0) {
         if (result.indexOf('\"') >= 0) {
-            result.replace("\"", ESCAPED_QUOTE);
+            result = result.replace("\"", ESCAPED_QUOTE);
         }
         }
         if (result.indexOf(COMMA) >= 0) {
         if (result.indexOf(COMMA) >= 0) {
             result = "\"" + result + "\"";
             result = "\"" + result + "\"";