@@ -0,0 +1,3004 @@
+package org.lockss.plugin.atypon.aaas;%0A%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0Aimport org.jsoup.nodes.Node;%0Aimport org.lockss.extractor.JsoupHtmlLinkExtractor.LinkExtractor;%0Aimport org.lockss.extractor.LinkExtractor.Callback;%0Aimport org.lockss.plugin.ArchivalUnit;%0Aimport org.lockss.plugin.atypon.BaseAtyponHtmlLinkExtractorFactory;%0Aimport org.lockss.util.Logger;%0A%0Apublic class AaasHtmlLinkExtractorFactory%0A    extends BaseAtyponHtmlLinkExtractorFactory %7B%0A%0A  /*%0A   *  AaasHtmlLinkExtractorFactory creates a url to a metadata file (.ris) for every article DOI_HTML page it%0A   *  encounters.%0A   */%0A%0A  private static final Pattern DOI_URL_PATTERN = Pattern.compile(%22%5E(https?://.*/)doi/(%5B.0-9%5D+)/(%5B%5E/%5D+)$%22);%0A  private static final String ACTION_DOWNLOAD_CITATION = %22action/downloadCitation%22;%0A  private static final String PILL_CITATIONS_ANCHOR = %22#pill-citations%22;%0A  private static final String DOWNLOAD_RIS_TAIL = %22&format=ris&include=cit%22;%0A%0A  @Override%0A  protected LinkExtractor createLinkTagExtractor(String attr) %7B%0A    return new AaasLinkTagLinkExtractor(attr);%0A  %7D%0A%0A  /*%0A   *  Extend the BaseAtyponLinkTagLinkExtractor to create the%0A   *  RIS metadata URL from the #pill-citations anchor (which links to a form)%0A   *  all other link tag cases are handled as per BaseAtypon and Jsoup%0A   */%0A  public static class AaasLinkTagLinkExtractor extends BaseAtyponLinkTagLinkExtractor %7B%0A%0A    private static final Logger logger = Logger.getLogger(AaasLinkTagLinkExtractor.class);%0A%0A    // nothing needed in the constructor - just call the parent%0A    public AaasLinkTagLinkExtractor(String attr) %7B%0A      super(attr);%0A    %7D%0A%0A    /*%0A     * Extending the way links are extracted by the Jsoup link extractor in a specific case:%0A     * In this case we create a link to the citations download page by pulling the DOI from the srcUrl%0A     * and generating a link like this:%0A     *     %3Cbase_url%3Eaction/downloadCitation?doi=...&format=ris&include=cit%0A     * after creating this link, fall back to standard atypon/jsoup implementations%0A     */%0A    public void tagBegin(Node node, ArchivalUnit au, Callback cb) %7B%0A      String srcUrl = node.baseUri();%0A      Matcher doiMat = DOI_URL_PATTERN.matcher(srcUrl);%0A      // Are we on a page for which this would be pertinent?%0A      if ( (srcUrl != null) && doiMat.find()) %7B%0A        // now do we have a link to the citations export%0A%0A        if ((node.hasAttr(%22href%22)) ) %7B%0A          String hrefval = node.attr(%22href%22);%0A          if (hrefval.contains(PILL_CITATIONS_ANCHOR)) %7B%0A            logger.info(%22found #pill-citations, rewriting%22);%0A            // the %22/%22 gets normalized to %252F%0A            String newUrl = doiMat.group(1) + ACTION_DOWNLOAD_CITATION + %22?doi=%22 + doiMat.group(2) + %22/%22 + doiMat.group(3) + DOWNLOAD_RIS_TAIL;%0A            logger.debug3(%22Generated ris citation url: %22 + newUrl);%0A            cb.foundLink(newUrl);%0A          %7D%0A        %7D%0A      %7D%0A      // allow the parent to get the actual pdf link%0A      super.tagBegin(node, au, cb);%0A    %7D%0A  %7D%0A%7D%0A

create link extractor that adds a ris file to the crawl