/*
 * $Id: AmericanMathematicalSocietyHtmlFilterFactory.java,v 1.1 2014-03-27 22:19:08 etenbrink Exp $
 */ 

/*

Copyright (c) 2000-2014 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.americanmathematicalsociety;

import java.io.InputStream;
import org.htmlparser.NodeFilter;
import org.htmlparser.filters.OrFilter;
import org.htmlparser.filters.TagNameFilter;
import org.lockss.daemon.PluginException;
import org.lockss.filter.FilterUtil;
import org.lockss.filter.WhiteSpaceFilter;
import org.lockss.filter.html.*;
import org.lockss.plugin.*;
import org.lockss.util.Logger;
import org.lockss.util.ReaderInputStream;

public class AmericanMathematicalSocietyHtmlFilterFactory implements FilterFactory {
  Logger log = Logger.getLogger(AmericanMathematicalSocietyHtmlFilterFactory.class);

  public InputStream createFilteredInputStream(
      ArchivalUnit au, InputStream in, String encoding)
          throws PluginException {
    NodeFilter[] filters = new NodeFilter[] {
        // filter out script
        new TagNameFilter("script"),
        // <table id="ribbon"
        HtmlNodeFilters.tagWithAttribute("table", "id", "ribbon"),
        // <table summary="Table that holds logos and navigation">
        HtmlNodeFilters.tagWithAttributeRegex("table", "summary", "logos and navigation"),
        // <td id="navCell" class="navCell" >
        HtmlNodeFilters.tagWithAttribute("td", "id", "navCell"),
        // <div class="altmetric-embed" ??? 
        HtmlNodeFilters.tagWithAttribute("div", "class", "altmetric-embed"),
        // <table id="footer" 
        HtmlNodeFilters.tagWithAttribute("table", "id", "footer"),
        
    };
    
    // Do the initial html filtering
    InputStream filteredStream = new HtmlFilterInputStream(in,encoding,
        HtmlNodeFilterTransform.exclude(new OrFilter(filters)));
    
    return new ReaderInputStream(FilterUtil.getReader(filteredStream, encoding));
  }
  
}


@@ -58,17 +58,17 @@
 ava,v 1.
-1
+2
  2014-03
@@ -73,18 +73,18 @@
 03-2
-7 22:19:08
+8 19:17:12
  ete
@@ -1707,88 +1707,8 @@
 on;%0A
-import org.lockss.filter.FilterUtil;%0Aimport org.lockss.filter.WhiteSpaceFilter;%0A
 impo
@@ -1798,50 +1798,8 @@
 ger;
-%0Aimport org.lockss.util.ReaderInputStream;
 %0A%0Apu
@@ -2167,25 +2167,48 @@
  // 
-filter out script
+Aggressive filtering of non-content tags
 %0A   
@@ -2256,26 +2256,61 @@
  // 
-%3Ctable id=%22ribbon%22
+Ribbon is at top of page with society links and icons
 %0A   
@@ -2375,32 +2375,137 @@
 on%22),%0A        //
+ Journal link block does not have a another useful attribute, hope this text%0A        // remains constant:
  %3Ctable summary=
@@ -2651,42 +2651,58 @@
  // 
-%3Ctd id=%22navCell%22 class=%22navCell%22 %3E
+issue and article navigation links that can change
 %0A   
@@ -2778,41 +2778,80 @@
  // 
-%3Cdiv class=%22altmetric-embed%22 ??? 
+not sure what this contains but in case the number changes, removing XXX
 %0A   
@@ -2939,27 +2939,38 @@
  // 
-%3Ctable id=%22footer%22 
+Changeable copyright and links
 %0A   
@@ -3248,51 +3248,8 @@
 urn 
-new ReaderInputStream(FilterUtil.getReader(
 filt
@@ -3262,20 +3262,8 @@
 ream
-, encoding))
 ;%0A  

Remove unneeded reader declaration; update comments