/*
 * $Id: GeorgThiemeVerlagHtmlMetadataExtractorFactory.java,v 1.2 2014-01-03 17:28:22 etenbrink Exp $
 */

/*

Copyright (c) 2000-2013 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.georgthiemeverlag;

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.*;


/**
 * One of the articles used to get the html source for this plugin is:
 * https://www.thieme-connect.de/ejournals/abstract/10.1055/s-0029-1214947
 */
public class GeorgThiemeVerlagHtmlMetadataExtractorFactory implements FileMetadataExtractorFactory {
  static Logger log = Logger.getLogger(GeorgThiemeVerlagHtmlMetadataExtractorFactory.class);

  public FileMetadataExtractor createFileMetadataExtractor(MetadataTarget target,
      String contentType)
      throws PluginException {
    return new GeorgThiemeVerlagHtmlMetadataExtractor();
  }
  
  public static class GeorgThiemeVerlagHtmlMetadataExtractor
    extends SimpleHtmlMetaTagMetadataExtractor {
   
    private static MultiMap tagMap = new MultiValueMap();
    static {
      //<meta name="citation_doi" content="10.1055/s-0029-1214474"/>
      tagMap.put("citation_doi", MetadataField.FIELD_DOI);
      //<meta name="citation_publication_date" content="2009/04/27"/>
      tagMap.put("citation_publication_date", MetadataField.FIELD_DATE);
      //<meta name="citation_title" content="Medikamentöse Systemtherapien der Psoriasis"/>
      tagMap.put("citation_title", MetadataField.FIELD_ARTICLE_TITLE);
      //<meta name="citation_issn" content="0340-2541"/>
      tagMap.put("citation_issn", MetadataField.FIELD_ISSN);
      //<meta name="citation_volume" content="36"/>
      tagMap.put("citation_volume", MetadataField.FIELD_VOLUME);
      //<meta name="citation_issue" content="04"/>
      tagMap.put("citation_issue", MetadataField.FIELD_ISSUE);
      //<meta name="citation_firstpage" content="142"/>
      tagMap.put("citation_firstpage", MetadataField.FIELD_START_PAGE);
      //<meta name="citation_author" content="R. Mössner"/>
      tagMap.put("citation_author",MetadataField.FIELD_AUTHOR);
      //<meta name="citation_journal_title" content="Aktuelle Dermatologie" />
      tagMap.put("citation_journal_title", MetadataField.FIELD_PUBLICATION_TITLE);
      //<meta name="citation_publisher" content="..."/> 
      // FIELD_PUBLISHER value will be extracted from tdb file
      //<meta name="citation_language" content="de" />
      tagMap.put("citation_language", MetadataField.FIELD_LANGUAGE);
    }
    
    @Override
    public ArticleMetadata extract(MetadataTarget target, CachedUrl cu)
        throws IOException {
      ArticleMetadata am = super.extract(target, cu);
      am.cook(tagMap);
      return am;
    }
  }
  
}

@@ -63,29 +63,29 @@
 v 1.
-2
+3
  2014-0
-1-03 17:28:22
+2-05 22:26:03
  ete
@@ -2359,38 +2359,29 @@
 ctor
+ 
 %0A    
-extends SimpleHtmlMetaTag
+implements File
 Meta
@@ -3768,31 +3768,102 @@
  be 
-extr
+repl
 ac
-t
 ed 
-from tdb file
+below (PD-440)%0A      tagMap.put(%22citation_publisher%22, MetadataField.FIELD_PUBLISHER);
 %0A   
@@ -4002,44 +4002,19 @@
     
-@Override%0A    public ArticleMetadata
+public void
  ext
@@ -4053,16 +4053,33 @@
 edUrl cu
+, Emitter emitter
 )%0A      
@@ -4132,13 +4132,48 @@
 m = 
-super
+new SimpleHtmlMetaTagMetadataExtractor()
 .ext
@@ -4223,25 +4223,160 @@
     
-return am
+// PD-440 hardcode publisher value%0A      am.replace(MetadataField.FIELD_PUBLISHER, %22Georg Thieme Verlag KG%22);%0A      emitter.emitMetadata(cu, am)
 ;%0A    %7D%0A
   %7D%0A
@@ -4371,16 +4371,21 @@
 ;%0A    %7D%0A
+    %0A
   %7D%0A  %0A%7D

Update to extract citation_publisher, then replace with hard-coded value