/*
 * $Id: RSC2014HtmlFilterFactory.java,v 1.2 2014-06-24 01:16:52 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.royalsocietyofchemistry;

import java.io.IOException;
import java.io.InputStream;
import java.util.Vector;

import org.htmlparser.Attribute;
import org.htmlparser.NodeFilter;
import org.htmlparser.Tag;
import org.htmlparser.filters.OrFilter;
import org.htmlparser.util.NodeList;
import org.htmlparser.util.ParserException;
import org.htmlparser.visitors.NodeVisitor;
import org.lockss.daemon.PluginException;
import org.lockss.filter.html.*;
import org.lockss.plugin.*;
import org.lockss.util.Logger;

public class RSC2014HtmlFilterFactory implements FilterFactory {
  
  Logger log = Logger.getLogger(RSC2014HtmlFilterFactory.class);
  
  public InputStream createFilteredInputStream(ArchivalUnit au, InputStream in,
                                               String encoding)
      throws PluginException {
    NodeFilter[] filters = new NodeFilter[] {
        // Contains the current year.
        HtmlNodeFilters.tagWithAttributeRegex("div", "class", "footer"),
        // Changeable scripts
        HtmlNodeFilters.tag("script"),
        // remove ALL comments, for JS version number
        HtmlNodeFilters.comment(),
    };
    
    // HTML transform to html attributes that are moving around
    HtmlTransform xform = new HtmlTransform() {
      @Override
      public NodeList transform(NodeList nodeList) throws IOException {
        try {
          nodeList.visitAllNodesWith(new NodeVisitor() {
            @Override
            public void visitTag(Tag tag) {
              String tagName = tag.getTagName().toLowerCase();
              try {
                if ("html".equals(tagName)) {
                  Attribute a = tag.getAttributeEx("html");
                  Vector<Attribute> v = new Vector<Attribute>();
                  v.add(a);
                  tag.setAttributesEx(v);
                }
              }
              catch (Exception exc) {
                log.debug2("Internal error (visitor)", exc); // Ignore this tag and move on
              }
              // Always
              super.visitTag(tag);
            }
          });
        }
        catch (ParserException pe) {
          log.debug2("Internal error (parser)", pe); // Bail
        }
        return nodeList;
      }
    };
    
    return new HtmlFilterInputStream(in, encoding, new HtmlCompoundTransform(
        HtmlNodeFilterTransform.exclude(new OrFilter(filters)), xform));
  }
  
}

@@ -38,17 +38,17 @@
 ava,v 1.
-2
+3
  2014-06
@@ -53,18 +53,18 @@
 06-2
-4 01:16:52
+7 22:06:44
  ete
@@ -1545,16 +1545,39 @@
 Stream;%0A
+import java.io.Reader;%0A
 import j
@@ -1887,32 +1887,112 @@
 luginException;%0A
+import org.lockss.filter.FilterUtil;%0Aimport org.lockss.filter.WhiteSpaceFilter;%0A
 import org.locks
@@ -2066,16 +2066,58 @@
 .Logger;
+%0Aimport org.lockss.util.ReaderInputStream;
 %0A%0Apublic
@@ -2669,27 +2669,43 @@
 ove 
-ALL comments, for J
+head for metadata changes and JS/CS
 S ve
@@ -2745,16 +2745,18 @@
 ers.
-comment(
+tag(%22head%22
 ),%0A 
@@ -3861,22 +3861,39 @@
    %0A    
-return
+InputStream filtered = 
  new Htm
@@ -3924,16 +3924,24 @@
 ncoding,
+%0A       
  new Htm
@@ -3959,25 +3959,16 @@
 ansform(
-%0A        
 HtmlNode
@@ -4024,16 +4024,158 @@
 form));%0A
+    Reader filteredReader = FilterUtil.getReader(filtered, encoding);%0A    return new ReaderInputStream(new WhiteSpaceFilter(filteredReader));%0A
   %7D%0A  %0A%7D

Add white space filter; replace comment filter with head tag filter.