[DS-2463] Tidy up some suggestions.

This commit is contained in:
Mark H. Wood
2015-10-18 11:03:55 -04:00
parent 522c6fb696
commit 6183f97594
2 changed files with 23 additions and 29 deletions

View File

@@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory;
*/
public class SpiderDetector {
private static Logger log = LoggerFactory.getLogger(SpiderDetector.class);
private static final Logger log = LoggerFactory.getLogger(SpiderDetector.class);
private static Boolean useProxies;
@@ -43,10 +43,12 @@ public class SpiderDetector {
private static IPTable table = null;
/** Collection of regular expressions to match known spiders' agents. */
private static List<Pattern> agents = Collections.synchronizedList(new ArrayList<Pattern>());
private static final List<Pattern> agents
= Collections.synchronizedList(new ArrayList<Pattern>());
/** Collection of regular expressions to match known spiders' domain names. */
private static List<Pattern> domains = Collections.synchronizedList(new ArrayList<Pattern>());
private static final List<Pattern> domains
= Collections.synchronizedList(new ArrayList<Pattern>());
/**
* Utility method which reads lines from a file & returns them in a Set.
@@ -58,7 +60,7 @@ public class SpiderDetector {
public static Set<String> readPatterns(File patternFile)
throws IOException
{
Set<String> patterns = new HashSet<String>();
Set<String> patterns = new HashSet<>();
if (!patternFile.exists() || !patternFile.isFile())
{
@@ -66,7 +68,8 @@ public class SpiderDetector {
}
//Read our file & get all them patterns.
BufferedReader in = new BufferedReader(new FileReader(patternFile));
try (BufferedReader in = new BufferedReader(new FileReader(patternFile)))
{
String line;
while ((line = in.readLine()) != null) {
if (!line.startsWith("#")) {
@@ -80,7 +83,7 @@ public class SpiderDetector {
// ... add this functionality later
}
}
in.close();
}
return patterns;
}
@@ -134,7 +137,7 @@ public class SpiderDetector {
log.info("No spider file loaded");
}
}
catch (Exception e) {
catch (IOException | IPTable.IPFormatException e) {
log.error("Error Loading Spiders:" + e.getMessage(), e);
}
@@ -293,14 +296,7 @@ public class SpiderDetector {
private static boolean isUseProxies() {
if(useProxies == null) {
if ("true".equals(ConfigurationManager.getProperty("useProxies")))
{
useProxies = true;
}
else
{
useProxies = false;
}
useProxies = "true".equals(ConfigurationManager.getProperty("useProxies"));
}
return useProxies;

View File

@@ -76,8 +76,6 @@ public class SpiderDetectorTest
candidate = "wiki.dspace.org";
req.setRemoteHost(candidate);
assertFalse(candidate + " matched DNS patterns", SpiderDetector.isSpider(req));
req = null;
}
/**