|
|
@ -59,10 +59,12 @@ public class RobotsTxtEntry {
|
|
|
|
private final Map<String, byte[]> mem;
|
|
|
|
private final Map<String, byte[]> mem;
|
|
|
|
private final List<String> allowPathList, denyPathList;
|
|
|
|
private final List<String> allowPathList, denyPathList;
|
|
|
|
private final String hostName, agentName;
|
|
|
|
private final String hostName, agentName;
|
|
|
|
|
|
|
|
private String info; // this is filled if robots disallowed access; then the reason is noted there;
|
|
|
|
|
|
|
|
|
|
|
|
protected RobotsTxtEntry(final String hostName, final Map<String, byte[]> mem) {
|
|
|
|
protected RobotsTxtEntry(final String hostName, final Map<String, byte[]> mem) {
|
|
|
|
this.hostName = hostName.toLowerCase();
|
|
|
|
this.hostName = hostName.toLowerCase();
|
|
|
|
this.mem = mem;
|
|
|
|
this.mem = mem;
|
|
|
|
|
|
|
|
this.info = "";
|
|
|
|
|
|
|
|
|
|
|
|
if (this.mem.containsKey(DISALLOW_PATH_LIST)) {
|
|
|
|
if (this.mem.containsKey(DISALLOW_PATH_LIST)) {
|
|
|
|
this.denyPathList = new LinkedList<String>();
|
|
|
|
this.denyPathList = new LinkedList<String>();
|
|
|
@ -122,7 +124,7 @@ public class RobotsTxtEntry {
|
|
|
|
this.allowPathList.addAll(allowPathList);
|
|
|
|
this.allowPathList.addAll(allowPathList);
|
|
|
|
|
|
|
|
|
|
|
|
final StringBuilder pathListStr = new StringBuilder(allowPathList.size() * 30);
|
|
|
|
final StringBuilder pathListStr = new StringBuilder(allowPathList.size() * 30);
|
|
|
|
for (String element : allowPathList) {
|
|
|
|
for (final String element : allowPathList) {
|
|
|
|
pathListStr.append(element)
|
|
|
|
pathListStr.append(element)
|
|
|
|
.append(RobotsTxt.ROBOTS_DB_PATH_SEPARATOR);
|
|
|
|
.append(RobotsTxt.ROBOTS_DB_PATH_SEPARATOR);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -133,7 +135,7 @@ public class RobotsTxtEntry {
|
|
|
|
this.denyPathList.addAll(disallowPathList);
|
|
|
|
this.denyPathList.addAll(disallowPathList);
|
|
|
|
|
|
|
|
|
|
|
|
final StringBuilder pathListStr = new StringBuilder(disallowPathList.size() * 30);
|
|
|
|
final StringBuilder pathListStr = new StringBuilder(disallowPathList.size() * 30);
|
|
|
|
for (String element : disallowPathList) {
|
|
|
|
for (final String element : disallowPathList) {
|
|
|
|
pathListStr.append(element)
|
|
|
|
pathListStr.append(element)
|
|
|
|
.append(RobotsTxt.ROBOTS_DB_PATH_SEPARATOR);
|
|
|
|
.append(RobotsTxt.ROBOTS_DB_PATH_SEPARATOR);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -167,11 +169,11 @@ public class RobotsTxtEntry {
|
|
|
|
* @return the sitemap url or null if no sitemap url is given
|
|
|
|
* @return the sitemap url or null if no sitemap url is given
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public MultiProtocolURI getSitemap() {
|
|
|
|
public MultiProtocolURI getSitemap() {
|
|
|
|
String url = this.mem.containsKey(SITEMAP)? UTF8.String(this.mem.get(SITEMAP)): null;
|
|
|
|
final String url = this.mem.containsKey(SITEMAP)? UTF8.String(this.mem.get(SITEMAP)): null;
|
|
|
|
if (url == null) return null;
|
|
|
|
if (url == null) return null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
return new MultiProtocolURI(url);
|
|
|
|
return new MultiProtocolURI(url);
|
|
|
|
} catch (MalformedURLException e) {
|
|
|
|
} catch (final MalformedURLException e) {
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -217,23 +219,35 @@ public class RobotsTxtEntry {
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public boolean isDisallowed(MultiProtocolURI subpathURL) {
|
|
|
|
public boolean isDisallowed(final MultiProtocolURI subpathURL) {
|
|
|
|
String path = subpathURL.getFile();
|
|
|
|
String path = subpathURL.getFile();
|
|
|
|
if ((this.mem == null) || (this.denyPathList.isEmpty())) return false;
|
|
|
|
if (this.mem == null) {
|
|
|
|
|
|
|
|
this.info = "no robots file available";
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.denyPathList.isEmpty()) {
|
|
|
|
|
|
|
|
this.info = "no entry in robots.txt";
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// if the path is null or empty we set it to /
|
|
|
|
// if the path is null or empty we set it to /
|
|
|
|
if ((path == null) || (path.length() == 0)) path = "/";
|
|
|
|
if (path == null || path.length() == 0) path = "/";
|
|
|
|
// escaping all occurences of ; because this char is used as special char in the Robots DB
|
|
|
|
// escaping all occurences of ; because this char is used as special char in the Robots DB
|
|
|
|
else path = RobotsTxt.ROBOTS_DB_PATH_SEPARATOR_MATCHER.matcher(path).replaceAll("%3B");
|
|
|
|
else path = RobotsTxt.ROBOTS_DB_PATH_SEPARATOR_MATCHER.matcher(path).replaceAll("%3B");
|
|
|
|
|
|
|
|
|
|
|
|
for (String element : this.denyPathList) {
|
|
|
|
for (final String element : this.denyPathList) {
|
|
|
|
|
|
|
|
|
|
|
|
// disallow rule
|
|
|
|
// disallow rule
|
|
|
|
if (path.startsWith(element)) {
|
|
|
|
if (path.startsWith(element)) {
|
|
|
|
|
|
|
|
this.info = "path '" + path + "' starts with '" + element + "' from deny path list";
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.info = "path '" + path + "' does not start with any element from deny path list";
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getInfo() {
|
|
|
|
|
|
|
|
return this.info;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|