mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-18 07:23:08 +00:00
[DS-2463] Tidy up some suggestions.
This commit is contained in:
@@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
*/
|
*/
|
||||||
public class SpiderDetector {
|
public class SpiderDetector {
|
||||||
|
|
||||||
private static Logger log = LoggerFactory.getLogger(SpiderDetector.class);
|
private static final Logger log = LoggerFactory.getLogger(SpiderDetector.class);
|
||||||
|
|
||||||
private static Boolean useProxies;
|
private static Boolean useProxies;
|
||||||
|
|
||||||
@@ -43,10 +43,12 @@ public class SpiderDetector {
|
|||||||
private static IPTable table = null;
|
private static IPTable table = null;
|
||||||
|
|
||||||
/** Collection of regular expressions to match known spiders' agents. */
|
/** 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. */
|
/** 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.
|
* 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)
|
public static Set<String> readPatterns(File patternFile)
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
Set<String> patterns = new HashSet<String>();
|
Set<String> patterns = new HashSet<>();
|
||||||
|
|
||||||
if (!patternFile.exists() || !patternFile.isFile())
|
if (!patternFile.exists() || !patternFile.isFile())
|
||||||
{
|
{
|
||||||
@@ -66,7 +68,8 @@ public class SpiderDetector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Read our file & get all them patterns.
|
//Read our file & get all them patterns.
|
||||||
BufferedReader in = new BufferedReader(new FileReader(patternFile));
|
try (BufferedReader in = new BufferedReader(new FileReader(patternFile)))
|
||||||
|
{
|
||||||
String line;
|
String line;
|
||||||
while ((line = in.readLine()) != null) {
|
while ((line = in.readLine()) != null) {
|
||||||
if (!line.startsWith("#")) {
|
if (!line.startsWith("#")) {
|
||||||
@@ -80,7 +83,7 @@ public class SpiderDetector {
|
|||||||
// ... add this functionality later
|
// ... add this functionality later
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
in.close();
|
}
|
||||||
return patterns;
|
return patterns;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +137,7 @@ public class SpiderDetector {
|
|||||||
log.info("No spider file loaded");
|
log.info("No spider file loaded");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (IOException | IPTable.IPFormatException e) {
|
||||||
log.error("Error Loading Spiders:" + e.getMessage(), e);
|
log.error("Error Loading Spiders:" + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -293,14 +296,7 @@ public class SpiderDetector {
|
|||||||
|
|
||||||
private static boolean isUseProxies() {
|
private static boolean isUseProxies() {
|
||||||
if(useProxies == null) {
|
if(useProxies == null) {
|
||||||
if ("true".equals(ConfigurationManager.getProperty("useProxies")))
|
useProxies = "true".equals(ConfigurationManager.getProperty("useProxies"));
|
||||||
{
|
|
||||||
useProxies = true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
useProxies = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return useProxies;
|
return useProxies;
|
||||||
|
@@ -76,8 +76,6 @@ public class SpiderDetectorTest
|
|||||||
candidate = "wiki.dspace.org";
|
candidate = "wiki.dspace.org";
|
||||||
req.setRemoteHost(candidate);
|
req.setRemoteHost(candidate);
|
||||||
assertFalse(candidate + " matched DNS patterns", SpiderDetector.isSpider(req));
|
assertFalse(candidate + " matched DNS patterns", SpiderDetector.isSpider(req));
|
||||||
|
|
||||||
req = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user