Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a more general support for inferred path discovery #597

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,15 +42,33 @@ public ExtractorHTTP() {
}

/** 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) {
Expand All @@ -67,9 +88,12 @@ protected void extract(CrawlURI curi) {

// 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) {
Expand Down
Loading