Add a more general support for inferred path discovery

This commit is contained in:
Kristinn Sigurðsson
2024-07-08 13:05:56 +00:00
parent 4a103f3e21
commit 778a57b3b4
@@ -19,6 +19,9 @@
package org.archive.modules.extractor;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.httpclient.URIException;
import org.archive.modules.CrawlURI;
import org.archive.modules.CrawlURI.FetchType;
@@ -39,15 +42,33 @@ public class ExtractorHTTP extends Extractor {
}
/** should all HTTP URIs be used to infer a link to the site's root? */
protected boolean inferRootPage = false;
protected boolean inferRootPage = false;
/**
* @deprecated Deprecated in favor of {@link #getInferPaths()} which allows the specification of arbitrary
* paths and can be overridden with sheets.
*/
public boolean getInferRootPage() {
return inferRootPage;
}
/**
* @deprecated Deprecated in favor of {@link #setInferPaths(List)} which allows the specification of arbitrary
* paths and can be overridden with sheets.
*/
public void setInferRootPage(boolean inferRootPage) {
this.inferRootPage = inferRootPage;
}
{
setInferPaths(new ArrayList<>());
}
@SuppressWarnings("unchecked")
public List<String> getInferPaths() {
return (List<String>) kp.get("inferPaths");
}
public void setInferPaths(List<String> inferPaths) {
kp.put("inferPaths", inferPaths);
}
@Override
protected boolean shouldProcess(CrawlURI uri) {
if (uri.getFetchStatus() <= 0) {
@@ -67,9 +88,12 @@ public class ExtractorHTTP extends Extractor {
// try /favicon.ico for every HTTP(S) URI
addOutlink(curi, "/favicon.ico", LinkContext.INFERRED_MISC, Hop.INFERRED);
if(getInferRootPage()) {
if (getInferRootPage()) {
addOutlink(curi, "/", LinkContext.INFERRED_MISC, Hop.INFERRED);
}
for (String inferPath : getInferPaths()) {
addOutlink(curi, inferPath, LinkContext.INFERRED_MISC, Hop.INFERRED);
}
}
protected void addRefreshHeaderLink(CrawlURI curi, String headerKey) {