This commit is contained in:
Shinsuke Sugaya 2015-09-20 21:59:03 +09:00
parent 8e613d0cca
commit 7bc5477cd0
37 changed files with 43 additions and 363 deletions

View file

@ -252,12 +252,12 @@ public class CrawlAction implements Serializable {
public List<String> getDayItems() {
final List<String> items = new ArrayList<String>();
for (int i = 0; i < 32; i++) {
items.add(Integer.valueOf(i).toString());
items.add(Integer.toString(i));
}
for (int i = 40; i < 370; i += 10) {
items.add(Integer.valueOf(i).toString());
items.add(Integer.toString(i));
}
items.add(Integer.valueOf(365).toString());
items.add(Integer.toString(365));
return items;
}

View file

@ -333,12 +333,6 @@ public class GsaApiManager extends BaseApiManager implements WebApiManager {
writeXmlResponse(status, xmlDtd, buf.toString(), errMsg);
}
private String convertTagName(final String name) {
final String tagName = StringUtil.decamelize(name).replaceAll("_", "-")
.toLowerCase();
return tagName;
}
protected void writeXmlResponse(final int status, final boolean xmlDtd,
final String body, final String errMsg) {

View file

@ -162,7 +162,7 @@ public class UserDictFile extends DictionaryFile<UserDictItem> {
line = line.replaceAll("#.*$", StringUtil.EMPTY);
// Skip empty lines or comment lines
if (line.trim().length() == 0) {
if (StringUtil.isBlank(line)) {
if (updater != null) {
updater.write(line);
}

View file

@ -201,7 +201,7 @@ public class UserDictItem extends DictionaryItem {
result = result.replace("\"", "\"\"");
}
if (result.indexOf(',') >= 0) {
result = "\"" + result + "\"";
return "\"" + result + "\"";
}
return result;
}

View file

@ -25,6 +25,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Pattern;
@ -131,7 +132,7 @@ public class CsvDataStoreImpl extends AbstractDataStoreImpl {
}
protected boolean isCsvFile(final File parentFile, final String filename) {
final String name = filename.toLowerCase();
final String name = filename.toLowerCase(Locale.ENGLISH);
for (final String suffix : csvFileSuffixs) {
if (name.endsWith(suffix)) {
return true;

View file

@ -23,18 +23,18 @@ import java.util.List;
import org.apache.solr.client.solrj.response.SolrPingResponse;
public class PingResponse {
private final int status = 0;
private int status = 0;
private final Target[] targets;
public PingResponse(final Collection<SolrPingResponse> responses) {
final List<Target> targetList = new ArrayList<>();
for (final SolrPingResponse response : responses) {
int status = response.getStatus();
if (status != 0) {
int innerStatus = response.getStatus();
if (innerStatus != 0) {
status = 1;
}
targetList.add(new Target(status, response.getRequestUrl(),
targetList.add(new Target(innerStatus, response.getRequestUrl(),
response.getElapsedTime(), response.getQTime()));
}
targets = targetList.toArray(new Target[targetList.size()]);

View file

@ -39,7 +39,7 @@ import org.codelibs.core.util.StringUtil;
import org.seasar.extension.filter.EncodingFilter;
public class FessEncodingFilter extends EncodingFilter {
public static String ENCODING_MAP = "encodingRules";
public static final String ENCODING_MAP = "encodingRules";
protected Map<String, String> encodingMap = new ConcurrentHashMap<>();

View file

@ -56,9 +56,7 @@ public class AdRoleHelper {
final SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
String name = domain;
name = "dc=" + name;
name = name.replace(".", ",dc=");
final String name = "dc=" + domain.replace(".", ",dc=");
//search
final NamingEnumeration<SearchResult> rslt = ctx.search(name,
@ -102,7 +100,9 @@ public class AdRoleHelper {
}
}
logger.debug("ADGroup:" + rolelist.toString());
if (logger.isDebugEnabled()) {
logger.debug("ADGroup:" + rolelist.toString());
}
return rolelist;
}
}

View file

@ -19,6 +19,7 @@ package jp.sf.fess.helper;
import java.io.IOException;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
@ -36,9 +37,9 @@ public class JobHelper {
private static final Logger logger = LoggerFactory
.getLogger(JobHelper.class);
private final ConcurrentHashMap<String, JobProcess> runningProcessMap = new ConcurrentHashMap<>();
private final ConcurrentMap<String, JobProcess> runningProcessMap = new ConcurrentHashMap<>();
private final ConcurrentHashMap<Long, JobExecutor> runningJobExecutorMap = new ConcurrentHashMap<>();
private final ConcurrentMap<Long, JobExecutor> runningJobExecutorMap = new ConcurrentHashMap<>();
@DestroyMethod
public void destroy() {

View file

@ -37,7 +37,7 @@ public class MailHelper implements Serializable {
public String from = Constants.DEFAULT_FROM_EMAIL;
private final boolean debug = false;
private boolean debug = false;
Properties props = new Properties();
@ -78,4 +78,8 @@ public class MailHelper implements Serializable {
}
}
public void setDebug(boolean debug) {
this.debug = debug;
}
}

View file

@ -18,8 +18,10 @@ package jp.sf.fess.helper;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@ -27,6 +29,7 @@ import java.util.Set;
import javax.annotation.Resource;
import jp.sf.fess.Constants;
import jp.sf.fess.db.cbean.SuggestBadWordCB;
import jp.sf.fess.db.cbean.SuggestElevateWordCB;
import jp.sf.fess.db.exbhv.SuggestBadWordBhv;
@ -121,7 +124,7 @@ public class SuggestHelper {
badWordCB.query().setSuggestWord_Equal(word);
final List<SuggestBadWord> badWordList = suggestBadWordBhv
.selectList(badWordCB);
if (badWordList.size() > 0) {
if (!badWordList.isEmpty()) {
return;
}
@ -181,7 +184,7 @@ public class SuggestHelper {
if (!file.exists()) {
file.createNewFile();
}
bw = new BufferedWriter(new FileWriter(file, false));
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), Constants.CHARSET_UTF_8));
for (final SuggestBadWord suggestBadWord : list) {
bw.write(suggestBadWord.getSuggestWord());
bw.newLine();

View file

@ -73,11 +73,13 @@ public class UserAgentHelper {
return Integer.parseInt(substring.split("[ \\.]")[1]);
} else if (userAgent.contains("rv")) {
String substring = userAgent.substring(
userAgent.indexOf("rv"), userAgent.indexOf(")"));
userAgent.indexOf("rv"), userAgent.indexOf(')'));
return Integer.parseInt(substring.split("[ :\\.]")[1]);
}
} catch (Exception e) {
logger.debug("Invalid request header: " + userAgent, e);
if (logger.isDebugEnabled()) {
logger.debug("Invalid request header: " + userAgent, e);
}
}
}
return 0;

View file

@ -22,6 +22,7 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import javax.servlet.ServletContext;
@ -382,7 +383,7 @@ public class CrawlJob {
final File[] jarFiles = libDir.listFiles(new FilenameFilter() {
@Override
public boolean accept(final File dir, final String name) {
return name.toLowerCase().endsWith(".jar");
return name.toLowerCase(Locale.ENGLISH).endsWith(".jar");
}
});
if (jarFiles != null) {

View file

@ -23,10 +23,6 @@ public class BoostDocumentRulePager extends BsBoostDocumentRulePager {
private static final long serialVersionUID = 1L;
public BoostDocumentRulePager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -23,10 +23,6 @@ public class CrawlingSessionPager extends BsCrawlingSessionPager {
private static final long serialVersionUID = 1L;
public CrawlingSessionPager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -23,10 +23,6 @@ public class DataCrawlingConfigPager extends BsDataCrawlingConfigPager {
private static final long serialVersionUID = 1L;
public DataCrawlingConfigPager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -38,10 +38,6 @@ public class FailureUrlPager extends BsFailureUrlPager {
@Maxbytelength(maxbytelength = 1000)
public String errorName;
public FailureUrlPager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -37,10 +37,6 @@ public class FavoriteLogPager extends BsFavoriteLogPager {
public String endMin;
public FavoriteLogPager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -23,10 +23,6 @@ public class FileAuthenticationPager extends BsFileAuthenticationPager {
private static final long serialVersionUID = 1L;
public FileAuthenticationPager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -23,10 +23,6 @@ public class FileCrawlingConfigPager extends BsFileCrawlingConfigPager {
private static final long serialVersionUID = 1L;
public FileCrawlingConfigPager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -23,10 +23,6 @@ public class JobLogPager extends BsJobLogPager {
private static final long serialVersionUID = 1L;
public JobLogPager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -23,10 +23,6 @@ public class KeyMatchPager extends BsKeyMatchPager {
private static final long serialVersionUID = 1L;
public KeyMatchPager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -23,10 +23,6 @@ public class LabelTypePager extends BsLabelTypePager {
private static final long serialVersionUID = 1L;
public LabelTypePager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -23,10 +23,6 @@ public class OverlappingHostPager extends BsOverlappingHostPager {
private static final long serialVersionUID = 1L;
public OverlappingHostPager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -23,10 +23,6 @@ public class PathMappingPager extends BsPathMappingPager {
private static final long serialVersionUID = 1L;
public PathMappingPager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -23,10 +23,6 @@ public class RequestHeaderPager extends BsRequestHeaderPager {
private static final long serialVersionUID = 1L;
public RequestHeaderPager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -23,10 +23,6 @@ public class RoleTypePager extends BsRoleTypePager {
private static final long serialVersionUID = 1L;
public RoleTypePager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -23,10 +23,6 @@ public class ScheduledJobPager extends BsScheduledJobPager {
private static final long serialVersionUID = 1L;
public ScheduledJobPager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -45,10 +45,6 @@ public class SearchLogPager extends BsSearchLogPager {
public String startPage;
public SearchLogPager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -23,10 +23,6 @@ public class SuggestBadWordPager extends BsSuggestBadWordPager {
private static final long serialVersionUID = 1L;
public SuggestBadWordPager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -23,10 +23,6 @@ public class SuggestElevateWordPager extends BsSuggestElevateWordPager {
private static final long serialVersionUID = 1L;
public SuggestElevateWordPager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -27,10 +27,6 @@ public class UserInfoPager extends BsUserInfoPager {
public Timestamp updatedTimeBefore;
public UserInfoPager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -23,10 +23,6 @@ public class WebAuthenticationPager extends BsWebAuthenticationPager {
private static final long serialVersionUID = 1L;
public WebAuthenticationPager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -23,10 +23,6 @@ public class WebCrawlingConfigPager extends BsWebCrawlingConfigPager {
private static final long serialVersionUID = 1L;
public WebCrawlingConfigPager() {
super();
}
@Override
public void clear() {
super.clear();

View file

@ -1,243 +0,0 @@
/*
* Copyright 2009-2015 the CodeLibs Project and the Others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package jp.sf.fess.servlet;
import java.lang.ref.Reference;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServlet;
import org.seasar.framework.util.DriverManagerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Tomcat6ConfigServlet extends HttpServlet {
private static final Logger logger = LoggerFactory
.getLogger(Tomcat6ConfigServlet.class);
private static final long serialVersionUID = 1L;
@Override
public void destroy() {
if (logger.isInfoEnabled()) {
logger.info("Removing HTTP connection manager...");
}
shutdownCommonsHttpClient();
if (logger.isInfoEnabled()) {
logger.info("Removing all drivers...");
}
DriverManagerUtil.deregisterAllDrivers();
cleanupAllThreads();
}
private void shutdownCommonsHttpClient() {
try {
final Class<?> clazz = Class
.forName("org.apache.commons.httpclient.MultiThreadedHttpConnectionManager");
final Method method = clazz.getMethod("shutdownAll", null);
method.invoke(null, null);
} catch (final ClassNotFoundException e) {
// ignore
} catch (final Exception e) {
logger.warn("Could not shutdown Commons HttpClient.", e);
}
}
@SuppressWarnings("deprecation")
private void cleanupAllThreads() {
final Thread[] threads = getThreads();
final ClassLoader cl = this.getClass().getClassLoader();
try {
cl.getResource(null);
} catch (final Exception e) {
}
final List<String> jvmThreadGroupList = new ArrayList<String>();
jvmThreadGroupList.add("system");
jvmThreadGroupList.add("RMI Runtime");
// Iterate over the set of threads
for (final Thread thread : threads) {
if (thread != null) {
final ClassLoader ccl = thread.getContextClassLoader();
if (ccl != null && ccl.equals(cl)) {
// Don't warn about this thread
if (thread == Thread.currentThread()) {
continue;
}
// Don't warn about JVM controlled threads
final ThreadGroup tg = thread.getThreadGroup();
if (tg != null && jvmThreadGroupList.contains(tg.getName())) {
continue;
}
waitThread(thread);
// Skip threads that have already died
if (!thread.isAlive()) {
continue;
}
if (logger.isInfoEnabled()) {
logger.info("Interrupting a thread ["
+ thread.getName() + "]...");
}
thread.interrupt();
waitThread(thread);
// Skip threads that have already died
if (!thread.isAlive()) {
continue;
}
if (logger.isInfoEnabled()) {
logger.info("Stopping a thread [" + thread.getName()
+ "]...");
}
thread.stop();
}
}
}
Field threadLocalsField = null;
Field inheritableThreadLocalsField = null;
Field tableField = null;
try {
threadLocalsField = Thread.class.getDeclaredField("threadLocals");
threadLocalsField.setAccessible(true);
inheritableThreadLocalsField = Thread.class
.getDeclaredField("inheritableThreadLocals");
inheritableThreadLocalsField.setAccessible(true);
// Make the underlying array of ThreadLoad.ThreadLocalMap.Entry objects
// accessible
final Class<?> tlmClass = Class
.forName("java.lang.ThreadLocal$ThreadLocalMap");
tableField = tlmClass.getDeclaredField("table");
tableField.setAccessible(true);
} catch (final Exception e) {
// ignore
}
for (final Thread thread : threads) {
if (thread != null) {
Object threadLocalMap;
try {
// Clear the first map
threadLocalMap = threadLocalsField.get(thread);
clearThreadLocalMap(cl, threadLocalMap, tableField);
} catch (final Exception e) {
// ignore
}
try { // Clear the second map
threadLocalMap = inheritableThreadLocalsField.get(thread);
clearThreadLocalMap(cl, threadLocalMap, tableField);
} catch (final Exception e) {
// ignore
}
}
}
}
private void waitThread(final Thread thread) {
int count = 0;
while (thread.isAlive() && count < 5) {
try {
Thread.sleep(100);
} catch (final InterruptedException e) {
}
count++;
}
}
/*
* Get the set of current threads as an array.
*/
private Thread[] getThreads() {
// Get the current thread group
ThreadGroup tg = Thread.currentThread().getThreadGroup();
// Find the root thread group
while (tg.getParent() != null) {
tg = tg.getParent();
}
int threadCountGuess = tg.activeCount() + 50;
Thread[] threads = new Thread[threadCountGuess];
int threadCountActual = tg.enumerate(threads);
// Make sure we don't miss any threads
while (threadCountActual == threadCountGuess) {
threadCountGuess *= 2;
threads = new Thread[threadCountGuess];
// Note tg.enumerate(Thread[]) silently ignores any threads that
// can't fit into the array
threadCountActual = tg.enumerate(threads);
}
return threads;
}
private void clearThreadLocalMap(final ClassLoader cl, final Object map,
final Field internalTableField) throws NoSuchMethodException,
IllegalAccessException, NoSuchFieldException,
InvocationTargetException {
if (map != null) {
final Method mapRemove = map.getClass().getDeclaredMethod("remove",
ThreadLocal.class);
mapRemove.setAccessible(true);
final Object[] table = (Object[]) internalTableField.get(map);
if (table != null) {
for (final Object element : table) {
if (element != null) {
boolean remove = false;
// Check the key
final Field keyField = Reference.class
.getDeclaredField("referent");
keyField.setAccessible(true);
final Object key = keyField.get(element);
if (cl.equals(key) || key != null
&& cl == key.getClass().getClassLoader()) {
remove = true;
}
// Check the value
final Field valueField = element.getClass()
.getDeclaredField("value");
valueField.setAccessible(true);
final Object value = valueField.get(element);
if (cl.equals(value) || value != null
&& cl == value.getClass().getClassLoader()) {
remove = true;
}
if (remove) {
final Object entry = ((Reference<?>) element).get();
if (logger.isInfoEnabled()) {
logger.info("Removing " + key.toString()
+ " from a thread local...");
}
mapRemove.invoke(map, entry);
}
}
}
}
}
}
}

View file

@ -20,6 +20,7 @@ import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import jp.sf.fess.Constants;
@ -71,8 +72,8 @@ public class FessStatusPolicy extends StatusPolicyImpl {
if (StringUtil.isNotBlank(indexValue)
&& UNFINISHED.equals(indexValue)) {
// index: UNFINISHED -> COMPLETED
dataMap.put("indexBefore", UNFINISHED.toUpperCase());
dataMap.put("indexAfter", COMPLETED.toUpperCase());
dataMap.put("indexBefore", UNFINISHED.toUpperCase(Locale.ENGLISH));
dataMap.put("indexAfter", COMPLETED.toUpperCase(Locale.ENGLISH));
}
break;
case ADD:
@ -80,8 +81,8 @@ public class FessStatusPolicy extends StatusPolicyImpl {
if (StringUtil.isNotBlank(indexValue)
&& UNFINISHED.equals(indexValue)) {
// index: UNFINISHED -> READY
dataMap.put("indexBefore", UNFINISHED.toUpperCase());
dataMap.put("indexAfter", READY.toUpperCase());
dataMap.put("indexBefore", UNFINISHED.toUpperCase(Locale.ENGLISH));
dataMap.put("indexAfter", READY.toUpperCase(Locale.ENGLISH));
}
break;
case PING:
@ -128,8 +129,8 @@ public class FessStatusPolicy extends StatusPolicyImpl {
&& !UNFINISHED.equals(indexValue)) {
// index: READY/COMPLETED -> UNFINISHED
dataMap.put("indexBefore", indexValue == null ? "UNKNOWN"
: indexValue.toUpperCase());
dataMap.put("indexAfter", UNFINISHED.toUpperCase());
: indexValue.toUpperCase(Locale.ENGLISH));
dataMap.put("indexAfter", UNFINISHED.toUpperCase(Locale.ENGLISH));
}
break;
case PING:

View file

@ -8,7 +8,7 @@ import org.codelibs.core.CoreLibConstants;
import com.ibm.icu.text.SimpleDateFormat;
public class CsvUtil {
public final class CsvUtil {
private CsvUtil() {
}