From 7c5b2ceb005ea9ba02cd0a657578514c3caee080 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristinn=20Sigur=C3=B0sson?= Date: Mon, 13 May 2013 15:18:02 +0000 Subject: [PATCH] Added a data map to Link. Becomes the CrawlURI's data map when Link is promoted to CrawlURI --- .../java/org/archive/modules/CrawlURI.java | 1 + .../org/archive/modules/extractor/Link.java | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/modules/src/main/java/org/archive/modules/CrawlURI.java b/modules/src/main/java/org/archive/modules/CrawlURI.java index 8ab8f6e3..160df59d 100644 --- a/modules/src/main/java/org/archive/modules/CrawlURI.java +++ b/modules/src/main/java/org/archive/modules/CrawlURI.java @@ -1649,6 +1649,7 @@ implements Reporter, Serializable, OverlayContext { extendHopsPath(getPathFromSeed(),link.getHopType().getHopChar()), getUURI(), link.getContext()); newCaURI.inheritFrom(this); + newCaURI.data=link.getRawData(); return newCaURI; } diff --git a/modules/src/main/java/org/archive/modules/extractor/Link.java b/modules/src/main/java/org/archive/modules/extractor/Link.java index a8f5f3ee..3384a0a5 100644 --- a/modules/src/main/java/org/archive/modules/extractor/Link.java +++ b/modules/src/main/java/org/archive/modules/extractor/Link.java @@ -19,9 +19,12 @@ package org.archive.modules.extractor; import java.io.Serializable; +import java.util.HashMap; +import java.util.Map; import java.util.logging.Logger; import org.apache.commons.httpclient.URIException; +import org.archive.modules.CoreAttributeConstants; import org.archive.modules.CrawlURI; import org.archive.net.UURI; import org.archive.net.UURIFactory; @@ -57,6 +60,14 @@ public class Link implements Serializable, Comparable { /** hop-type */ private Hop hop; + + /** + * Flexible dynamic attributes list. + *

+ * See further {@link Link#getData()} + */ + protected Map data; + /** * Create a Link with the given fields. @@ -106,7 +117,37 @@ public class Link implements Serializable, Comparable { public String toString() { return this.destination + " " + hop.getHopChar() + " " + this.context; } + /** + * Attribute list + *

+ * By convention the attribute list is keyed by constants found in the + * {@link CoreAttributeConstants} interface. Use this list to carry + * data or state produced by custom processors rather change the + * classes {@link CrawlURI} or this class, CrawlURI. + *

+ * This list becomes {@link CrawlURI#getData()} when the Link is promoted to CrawlURI via + * {@link CrawlURI#createCrawlURI(UURI, Link)} + *

+ * If the list is null when this method is invoked, a new instance will be created and returned. + * + * @returns a flexible map of key/value pairs for storing + * status of this URI for use by other processors. + */ + public Map getData() { + if (data == null) { + data = new HashMap(); + } + return data; + } + /** + * Same as {@link Link#getData()} except null will be returned if the underlying map is null + * instead of creating a new map + * @return + */ + public Map getRawData() { + return data; + } @Override public boolean equals(Object o) {