mirror of
https://github.com/internetarchive/heritrix3.git
synced 2026-07-20 14:31:49 +00:00
Fix HER-2021 usedBaseForVia annotation repeated many times
* CrawlURI.java
getAnnotations() - use LinkedHashSet data structure for new annotations object to prevent duplicates
* Link.java
addRelativeToVia() - only log use of base for via the first time, before the annotation has been added
This commit is contained in:
@@ -66,6 +66,7 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -651,12 +652,12 @@ implements Reporter, Serializable, OverlayContext {
|
||||
*/
|
||||
public Collection<String> getAnnotations() {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> list = (List<String>)getData().get(A_ANNOTATIONS);
|
||||
if (list == null) {
|
||||
list = new ArrayList<String>();
|
||||
getData().put(A_ANNOTATIONS, list);
|
||||
Collection<String> annotations = (Collection<String>)getData().get(A_ANNOTATIONS);
|
||||
if (annotations == null) {
|
||||
annotations = new LinkedHashSet<String>();
|
||||
getData().put(A_ANNOTATIONS, annotations);
|
||||
}
|
||||
return list;
|
||||
return annotations;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -133,19 +133,20 @@ public class Link implements Serializable, Comparable<Link> {
|
||||
}
|
||||
|
||||
|
||||
public static void addRelativeToVia(CrawlURI uri, int max,
|
||||
String newUri, LinkContext context, Hop hop) throws URIException {
|
||||
public static void addRelativeToVia(CrawlURI uri, int max, String newUri,
|
||||
LinkContext context, Hop hop) throws URIException {
|
||||
UURI relTo = uri.getVia();
|
||||
if(relTo==null) {
|
||||
LOGGER.info("no via where expected; using base instead: "+uri);
|
||||
uri.getAnnotations().add("usedBaseForVia");
|
||||
if (relTo == null) {
|
||||
if (!uri.getAnnotations().contains("usedBaseForVia")) {
|
||||
LOGGER.info("no via where expected; using base instead: " + uri);
|
||||
uri.getAnnotations().add("usedBaseForVia");
|
||||
}
|
||||
relTo = uri.getBaseURI();
|
||||
}
|
||||
UURI dest = UURIFactory.getInstance(relTo, newUri);
|
||||
add2(uri, max, dest, context, hop);
|
||||
}
|
||||
|
||||
|
||||
public static void add(CrawlURI uri, int max, String newUri,
|
||||
LinkContext context, Hop hop) throws URIException {
|
||||
UURI dest = UURIFactory.getInstance(newUri);
|
||||
|
||||
Reference in New Issue
Block a user