Browse Source

refactoring

Shinsuke Sugaya 9 years ago
parent
commit
ec0bbcb4b2

+ 6 - 4
src/main/java/org/codelibs/fess/api/BaseApiManager.java

@@ -74,18 +74,20 @@ public abstract class BaseApiManager implements WebApiManager {
             buf.append(contentType);
             buf.append(contentType);
         }
         }
         buf.append("; charset=");
         buf.append("; charset=");
+        final String enc;
         if (encoding == null) {
         if (encoding == null) {
             if (LaRequestUtil.getRequest().getCharacterEncoding() == null) {
             if (LaRequestUtil.getRequest().getCharacterEncoding() == null) {
-                buf.append(Constants.UTF_8);
+                enc = Constants.UTF_8;
             } else {
             } else {
-                buf.append(LaRequestUtil.getRequest().getCharacterEncoding());
+                enc = LaRequestUtil.getRequest().getCharacterEncoding();
             }
             }
         } else {
         } else {
-            buf.append(encoding);
+            enc = encoding;
         }
         }
+        buf.append(enc);
         final HttpServletResponse response = LaResponseUtil.getResponse();
         final HttpServletResponse response = LaResponseUtil.getResponse();
         response.setContentType(buf.toString());
         response.setContentType(buf.toString());
-        try (PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), encoding))) {
+        try (PrintWriter out = new PrintWriter(new OutputStreamWriter(response.getOutputStream(), enc))) {
             out.print(text);
             out.print(text);
         } catch (final IOException e) {
         } catch (final IOException e) {
             throw new IORuntimeException(e);
             throw new IORuntimeException(e);

+ 6 - 5
src/main/java/org/codelibs/fess/app/service/FailureUrlService.java

@@ -19,6 +19,7 @@ import java.io.PrintWriter;
 import java.io.Serializable;
 import java.io.Serializable;
 import java.io.StringWriter;
 import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.List;
 import java.util.regex.Pattern;
 import java.util.regex.Pattern;
 
 
@@ -138,7 +139,7 @@ public class FailureUrlService implements Serializable {
         }
         }
 
 
         if (failureCount < 0) {
         if (failureCount < 0) {
-            return null;
+            return Collections.emptyList();
         }
         }
 
 
         final int count = failureCount;
         final int count = failureCount;
@@ -147,7 +148,7 @@ public class FailureUrlService implements Serializable {
             cb.query().setErrorCount_GreaterEqual(count);
             cb.query().setErrorCount_GreaterEqual(count);
         });
         });
         if (list.isEmpty()) {
         if (list.isEmpty()) {
-            return null;
+            return Collections.emptyList();
         }
         }
 
 
         Pattern pattern = null;
         Pattern pattern = null;
@@ -174,8 +175,8 @@ public class FailureUrlService implements Serializable {
     }
     }
 
 
     public void store(final CrawlingConfig crawlingConfig, final String errorName, final String url, final Throwable e) {
     public void store(final CrawlingConfig crawlingConfig, final String errorName, final String url, final Throwable e) {
-        final FailureUrlBhv failureUrlBhv = SingletonLaContainer.getComponent(FailureUrlBhv.class);
-        FailureUrl failureUrl = failureUrlBhv.selectEntity(cb -> {
+        final FailureUrlBhv bhv = SingletonLaContainer.getComponent(FailureUrlBhv.class);
+        FailureUrl failureUrl = bhv.selectEntity(cb -> {
             cb.query().setUrl_Equal(url);
             cb.query().setUrl_Equal(url);
             if (crawlingConfig != null) {
             if (crawlingConfig != null) {
                 cb.query().setConfigId_Equal(crawlingConfig.getConfigId());
                 cb.query().setConfigId_Equal(crawlingConfig.getConfigId());
@@ -199,7 +200,7 @@ public class FailureUrlService implements Serializable {
         failureUrl.setLastAccessTime(ComponentUtil.getSystemHelper().getCurrentTimeAsLong());
         failureUrl.setLastAccessTime(ComponentUtil.getSystemHelper().getCurrentTimeAsLong());
         failureUrl.setThreadName(Thread.currentThread().getName());
         failureUrl.setThreadName(Thread.currentThread().getName());
 
 
-        failureUrlBhv.insertOrUpdate(failureUrl);
+        bhv.insertOrUpdate(failureUrl);
     }
     }
 
 
     private String getStackTrace(final Throwable t) {
     private String getStackTrace(final Throwable t) {

+ 3 - 2
src/main/java/org/codelibs/fess/app/service/ScheduledJobService.java

@@ -132,7 +132,9 @@ public class ScheduledJobService implements Serializable {
             try {
             try {
                 unregister(scheduledJob);
                 unregister(scheduledJob);
             } catch (final Exception e) {
             } catch (final Exception e) {
-                logger.debug("Failed to delete Job " + scheduledJob, e);
+                if (logger.isDebugEnabled()) {
+                    logger.debug("Failed to delete Job " + scheduledJob, e);
+                }
             }
             }
             return;
             return;
         }
         }
@@ -206,7 +208,6 @@ public class ScheduledJobService implements Serializable {
             return true;
             return true;
         }
         }
 
 
-        final FessConfig fessConfig = ComponentUtil.getFessConfig();
         final String myName = fessConfig.getSchedulerTargetName();
         final String myName = fessConfig.getSchedulerTargetName();
 
 
         final String[] targets = target.split(",");
         final String[] targets = target.split(",");

+ 2 - 2
src/main/java/org/codelibs/fess/dict/kuromoji/KuromojiFile.java

@@ -59,7 +59,7 @@ public class KuromojiFile extends DictionaryFile<KuromojiItem> {
     }
     }
 
 
     @Override
     @Override
-    public OptionalEntity<KuromojiItem> get(final long id) {
+    public synchronized OptionalEntity<KuromojiItem> get(final long id) {
         if (kuromojiItemList == null) {
         if (kuromojiItemList == null) {
             reload(null, null);
             reload(null, null);
         }
         }
@@ -182,7 +182,7 @@ public class KuromojiFile extends DictionaryFile<KuromojiItem> {
         return new BufferedInputStream(dictionaryManager.getContentInputStream(this));
         return new BufferedInputStream(dictionaryManager.getContentInputStream(this));
     }
     }
 
 
-    public void update(final InputStream in) throws IOException {
+    public synchronized void update(final InputStream in) throws IOException {
         try (KuromojiUpdater updater = new KuromojiUpdater(null)) {
         try (KuromojiUpdater updater = new KuromojiUpdater(null)) {
             reload(updater, in);
             reload(updater, in);
         }
         }

+ 2 - 2
src/main/java/org/codelibs/fess/dict/synonym/SynonymFile.java

@@ -58,7 +58,7 @@ public class SynonymFile extends DictionaryFile<SynonymItem> {
     }
     }
 
 
     @Override
     @Override
-    public OptionalEntity<SynonymItem> get(final long id) {
+    public synchronized OptionalEntity<SynonymItem> get(final long id) {
         if (synonymItemList == null) {
         if (synonymItemList == null) {
             reload(null, null);
             reload(null, null);
         }
         }
@@ -254,7 +254,7 @@ public class SynonymFile extends DictionaryFile<SynonymItem> {
         return new BufferedInputStream(dictionaryManager.getContentInputStream(this));
         return new BufferedInputStream(dictionaryManager.getContentInputStream(this));
     }
     }
 
 
-    public void update(final InputStream in) throws IOException {
+    public synchronized void update(final InputStream in) throws IOException {
         try (SynonymUpdater updater = new SynonymUpdater(null)) {
         try (SynonymUpdater updater = new SynonymUpdater(null)) {
             reload(updater, in);
             reload(updater, in);
         }
         }

+ 2 - 4
src/main/java/org/codelibs/fess/ds/impl/CsvDataStoreImpl.java

@@ -37,6 +37,7 @@ import org.codelibs.fess.ds.DataStoreCrawlingException;
 import org.codelibs.fess.ds.DataStoreException;
 import org.codelibs.fess.ds.DataStoreException;
 import org.codelibs.fess.ds.IndexUpdateCallback;
 import org.codelibs.fess.ds.IndexUpdateCallback;
 import org.codelibs.fess.es.config.exentity.DataConfig;
 import org.codelibs.fess.es.config.exentity.DataConfig;
+import org.codelibs.fess.util.StreamUtil;
 import org.lastaflute.di.core.SingletonLaContainer;
 import org.lastaflute.di.core.SingletonLaContainer;
 import org.slf4j.Logger;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.LoggerFactory;
@@ -94,10 +95,7 @@ public class CsvDataStoreImpl extends AbstractDataStoreImpl {
             for (final String path : values) {
             for (final String path : values) {
                 final File dir = new File(path);
                 final File dir = new File(path);
                 if (dir.isDirectory()) {
                 if (dir.isDirectory()) {
-                    final File[] files = dir.listFiles((FilenameFilter) (file, name) -> isCsvFile(file, name));
-                    for (final File file : files) {
-                        fileList.add(file);
-                    }
+                    StreamUtil.of(dir.listFiles()).filter(f -> isCsvFile(f.getParentFile(), f.getName())).forEach(f -> fileList.add(f));
                 } else {
                 } else {
                     logger.warn(path + " is not a directory.");
                     logger.warn(path + " is not a directory.");
                 }
                 }

+ 6 - 8
src/main/java/org/codelibs/fess/helper/WebFsIndexHelper.java

@@ -223,14 +223,12 @@ public class WebFsIndexHelper implements Serializable {
 
 
             // failure url
             // failure url
             final List<String> excludedUrlList = failureUrlService.getExcludedUrlList(webConfig.getConfigId());
             final List<String> excludedUrlList = failureUrlService.getExcludedUrlList(webConfig.getConfigId());
-            if (excludedUrlList != null) {
-                for (final String u : excludedUrlList) {
-                    if (StringUtil.isNotBlank(u)) {
-                        final String urlValue = u.trim();
-                        crawler.addExcludeFilter(urlValue);
-                        if (logger.isInfoEnabled()) {
-                            logger.info("Excluded URL from failures: " + urlValue);
-                        }
+            for (final String u : excludedUrlList) {
+                if (StringUtil.isNotBlank(u)) {
+                    final String urlValue = u.trim();
+                    crawler.addExcludeFilter(urlValue);
+                    if (logger.isInfoEnabled()) {
+                        logger.info("Excluded URL from failures: " + urlValue);
                     }
                     }
                 }
                 }
             }
             }