From aff5b9ac4ebd913ecd0cfb2acaeb1a32a707df0f Mon Sep 17 00:00:00 2001 From: Noah Levitt Date: Thu, 15 May 2014 13:31:29 -0700 Subject: [PATCH] for ARI-3712, add extracted links relative to both via and base, and annotate with "extractorSWFRelToVia", "extractorSWFRelToBase", or "extractorSWFRelToBoth" if resulting link is the same whether relative to base or via --- .../modules/extractor/ExtractorSWF.java | 27 +++++++++++-- .../modules/extractor/ExtractorSWFTest.java | 40 +++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/modules/src/main/java/org/archive/modules/extractor/ExtractorSWF.java b/modules/src/main/java/org/archive/modules/extractor/ExtractorSWF.java index cdfe7360..4a8bc6e8 100644 --- a/modules/src/main/java/org/archive/modules/extractor/ExtractorSWF.java +++ b/modules/src/main/java/org/archive/modules/extractor/ExtractorSWF.java @@ -334,17 +334,38 @@ public class ExtractorSWF extends ContentExtractor { } } else { int max = ext.getExtractorParameters().getMaxOutlinks(); - Link.addRelativeToVia(curi, max, url, LinkContext.EMBED_MISC, - Hop.EMBED); + Link relToVia = Link.addRelativeToVia(curi, max, url, + LinkContext.EMBED_MISC, Hop.EMBED); + Link relToBase = Link.addRelativeToBase(curi, max, url, + LinkContext.EMBED_MISC, Hop.EMBED); + addAnnotations(relToVia, relToBase); linkCount++; } } + protected void addAnnotations(Link relToVia, Link relToBase) { + if (relToVia != null && relToBase != null + && relToVia.getDestination().equals(relToBase.getDestination())) { + relToVia.getAnnotations().add("extractorSWFRelToBoth"); + relToBase.getAnnotations().add("extractorSWFRelToBoth"); + } else { + if (relToVia != null) { + relToVia.getAnnotations().add("extractorSWFRelToVia"); + } + if (relToBase != null) { + relToBase.getAnnotations().add("extractorSWFRelToBase"); + } + } + } + public void considerStringAsUri(String str) throws IOException { if (UriUtils.isVeryLikelyUri(str)) { int max = ext.getExtractorParameters().getMaxOutlinks(); - Link.addRelativeToVia(curi, max, str, + Link relToVia = Link.addRelativeToVia(curi, max, str, LinkContext.SPECULATIVE_MISC, Hop.SPECULATIVE); + Link relToBase = Link.addRelativeToBase(curi, max, str, + LinkContext.SPECULATIVE_MISC, Hop.SPECULATIVE); + addAnnotations(relToVia, relToBase); linkCount++; } } diff --git a/modules/src/test/java/org/archive/modules/extractor/ExtractorSWFTest.java b/modules/src/test/java/org/archive/modules/extractor/ExtractorSWFTest.java index 5167d8bb..9ed57b08 100644 --- a/modules/src/test/java/org/archive/modules/extractor/ExtractorSWFTest.java +++ b/modules/src/test/java/org/archive/modules/extractor/ExtractorSWFTest.java @@ -177,4 +177,44 @@ public class ExtractorSWFTest extends ContentExtractorTestBase { + "\" from " + url, foundIt); } } + + public void xestAri3712() throws MalformedURLException, IOException { + String url = "https://wayback.archive-it.org/3771/20131119163257/http://nyumedecs.kk5.org/_app/28727/en/resources/container.swf"; + CrawlURI curi = setupURI(url); + curi.setVia(UURIFactory.getInstance("http://nyumedecs.kk5.org/")); + long startTime = System.currentTimeMillis(); + this.extractor.extract(curi); + long elapsed = System.currentTimeMillis() - startTime; + logger.info(this.extractor.getClass().getSimpleName() + " took " + + elapsed + "ms to process " + url); + + HashMap expected = new HashMap(); + expected.put("http://nyumedecs.kk5.org/sm4/portal", "extractorSWFRelToVia"); + expected.put("https://wayback.archive-it.org/3771/20131119163257/http://nyumedecs.kk5.org/_app/28727/en/resources/sm4/portal", "extractorSWFRelToBase"); + expected.put("http://nyumedecs.kk5.org/", "extractorSWFRelToVia"); + expected.put("https://wayback.archive-it.org/", "extractorSWFRelToBase"); + expected.put("http://nyumedecs.kk5.org/loadingBarEdit.swf", "extractorSWFRelToVia"); + expected.put("https://wayback.archive-it.org/3771/20131119163257/http://nyumedecs.kk5.org/_app/28727/en/resources/loadingBarEdit.swf", "extractorSWFRelToBase"); + expected.put("http://nyumedecs.kk5.org/containermain.swf", "extractorSWFRelToVia"); + expected.put("https://wayback.archive-it.org/3771/20131119163257/http://nyumedecs.kk5.org/_app/28727/en/resources/containermain.swf", "extractorSWFRelToBase"); + + for (Link link: curi.getOutLinks()) { + System.out.println(link + " " + link.getData()); + assertEquals(1, link.getAnnotations().size()); + + String dest = link.getDestination().toString(); + assertTrue(expected.containsKey(dest)); + + // remove the entry, so at the end the map should be empty, confirming that we found all the expected links + String expectedAnnotation = expected.remove(dest); + System.out.println("expectedAnnotation=" + expectedAnnotation); + + System.out.println("link.getAnnotations()=" + link.getAnnotations()); + String annotation = link.getAnnotations().toArray(new String[0])[0]; + System.out.println("annotation=" + annotation); + + + assertEquals(expectedAnnotation, annotation); + } + } }