/*

 * $Id: OJS2HtmlMetadataExtractorFactory.java,v 1.5 2013-01-10 21:35:25 ldoan Exp $
 */

/*

 Copyright (c) 2000-2009 Board of Trustees of Leland Stanford Jr. University,
 all rights reserved.

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 STANFORD UNIVERSITY BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
 IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 Except as contained in this notice, the name of Stanford University shall not
 be used in advertising or otherwise to promote the sale, use or other dealings
 in this Software without prior written authorization from Stanford University.

 */

package org.lockss.plugin.ojs2;

import java.io.*;
import org.apache.commons.collections.MultiMap;
import org.apache.commons.collections.map.MultiValueMap;
import org.lockss.util.*;
import org.lockss.daemon.*;
import org.lockss.extractor.*;
import org.lockss.plugin.*;

/*
 * OJS2HtmlMetadataExtractorFactory extracts metadata from each article.
 */
public class OJS2HtmlMetadataExtractorFactory implements
    FileMetadataExtractorFactory {
  
  static Logger log = Logger.getLogger(OJS2HtmlMetadataExtractorFactory.class);

  public FileMetadataExtractor createFileMetadataExtractor(
      MetadataTarget target, String contentType) throws PluginException {
    
    return new OJS2HtmlMetadataExtractor();
    
  } // createFileMetadataExtractor

  public static class OJS2HtmlMetadataExtractor 
    extends SimpleHtmlMetaTagMetadataExtractor {

    // Map OJS2-specific HTML meta tag names to cooked metadata fields
    private static MultiMap tagMap = new MultiValueMap();
    
    static {
      
      tagMap.put("DC.Format", MetadataField.DC_FIELD_FORMAT);
      tagMap.put("DC.Language", MetadataField.DC_FIELD_LANGUAGE);
      tagMap.put("DC.Title", MetadataField.DC_FIELD_TITLE);
      tagMap.put("DC.Identifier", MetadataField.DC_FIELD_IDENTIFIER);
      tagMap.put("DC.Date", MetadataField.DC_FIELD_DATE);
      tagMap.put("DC.Publisher", MetadataField.DC_FIELD_PUBLISHER);
      tagMap.put("DC.Publisher", MetadataField.FIELD_PUBLISHER);
      tagMap.put("DC.Contributor", MetadataField.DC_FIELD_CONTRIBUTOR);
      tagMap.put("citation_journal_title", MetadataField.FIELD_JOURNAL_TITLE);
      tagMap.put("citation_title", MetadataField.FIELD_ARTICLE_TITLE);
      tagMap.put("citation_date", MetadataField.FIELD_DATE);
      tagMap.put("citation_author", MetadataField.FIELD_AUTHOR);
      tagMap.put("citation_authors",
          new MetadataField(MetadataField.FIELD_AUTHOR,
              MetadataField.splitAt(";")));
      tagMap.put("citation_issn", MetadataField.FIELD_ISSN);
      tagMap.put("citation_volume", MetadataField.FIELD_VOLUME);
      tagMap.put("citation_volume", MetadataField.DC_FIELD_CITATION_VOLUME);
      tagMap.put("citation_issue", MetadataField.FIELD_ISSUE);
      tagMap.put("citation_issue", MetadataField.DC_FIELD_CITATION_ISSUE);
      tagMap.put("citation_firstpage", MetadataField.FIELD_START_PAGE);
      tagMap.put("citation_lastpage", MetadataField.FIELD_END_PAGE);
      //tagMap.put("citation_firstpage", MetadataField.DC_FIELD_CITATION_SPAGE);
      //tagMap.put("citation_lastpage", MetadataField.DC_FIELD_CITATION_EPAGE);
      tagMap.put("citation_doi", MetadataField.FIELD_DOI);
      tagMap.put("citation_public_url", MetadataField.FIELD_ACCESS_URL);
            
    } // static

    @Override
    public ArticleMetadata extract(MetadataTarget target, CachedUrl cu)
      throws IOException {
      
      log.debug3("Metadata - cachedurl cu:" + cu.getUrl());
      
      ArticleMetadata am = super.extract(target, cu);
      am.cook(tagMap);
      return am;
      
    } // extract
    
  } // OJS2HtmlMetadataExtractor
  
} // OJS2HtmlMetadataExtractorFactory
 

@@ -51,35 +51,39 @@
 v 1.
-5
+6
  2013-
-01-10 21:35:25 ldoan
+10-23 21:42:13 etenbrink
  Exp
@@ -1513,24 +1513,89 @@
  java.io.*;%0A
+import java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0A
 import org.a
@@ -1768,24 +1768,79 @@
 xtractor.*;%0A
+import org.lockss.extractor.MetadataField.Cardinality;%0A
 import org.l
@@ -2435,16 +2435,614 @@
 ctor %7B%0A%0A
+    private static Pattern OJS_DOI_PAT = Pattern.compile(%2210%5B.%5D%5B0-9a-z%5D%7B4,6%7D/.*%22);%0A%0A    /*%0A     * The representation of a DOI has key %22citation_doi%22%0A     */%0A    protected static final MetadataField OJS_DOI =%0A        new MetadataField(%22doi%22, Cardinality.Single) %7B%0A      @Override%0A      public String validate(ArticleMetadata am, String val)%0A          throws MetadataException.ValidationException %7B%0A%0A        Matcher m = OJS_DOI_PAT.matcher(val);%0A        if(!m.matches())%7B%0A          throw new MetadataException.ValidationException(%22Illegal DOI: %22 + val);%0A        %7D%0A        return val;%0A      %7D%0A    %7D;%0A%0A
     // M
@@ -4797,35 +4797,19 @@
 n_doi%22, 
-MetadataField.FIELD
+OJS
 _DOI);%0A 

Add new OJS_DOI MetadataField using new Pattern OJS_DOI_PAT