/*
 * $Id: GeorgThiemeVerlagHtmlFilterFactory.java,v 1.2 2013-11-23 01:45: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, tMassachusettsMedicalSocietyHtmlFilterFactoryhe 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.htmlparser.*;
import org.htmlparser.filters.*;
import org.lockss.daemon.PluginException;
import org.lockss.filter.FilterUtil;
import org.lockss.filter.HtmlTagFilter;
import org.lockss.filter.HtmlTagFilter.TagPair;
import org.lockss.filter.WhiteSpaceFilter;
import org.lockss.filter.html.*;
import org.lockss.plugin.*;
import org.lockss.util.ListUtil;
import org.lockss.util.Logger;
import org.lockss.util.ReaderInputStream;

public class GeorgThiemeVerlagHtmlFilterFactory implements FilterFactory {
  
  Logger log = Logger.getLogger(GeorgThiemeVerlagHtmlFilterFactory.class);
  
  @Override
  public InputStream createFilteredInputStream(ArchivalUnit au,
                                               InputStream in,
                                               String encoding)
      throws PluginException {
    // First filter with HtmlParser
    NodeFilter[] filters = new NodeFilter[] {
        // Hash filter
        new TagNameFilter("script"),
        // Remove header/footer items
// XXX  remove 2 comments below when new HtmlFilterInputStream changes go into effect
//        new TagNameFilter("header"),
//        new TagNameFilter("footer"),
        // Contains ads
        HtmlNodeFilters.tagWithAttributeRegex("div", "id", "adSidebar[^\"]*"),
        // Contains navigation items
        HtmlNodeFilters.tagWithAttribute("div", "id", "navPanel"),
        // Contains functional links, not content
        HtmlNodeFilters.tagWithAttribute("div", "class", "pageFunctions"),
        HtmlNodeFilters.tagWithAttribute("div", "class", "articleFunctions"),
        HtmlNodeFilters.tagWithAttribute("span", "class", "articleCategories")
    };
    
    InputStream filtered = new HtmlFilterInputStream(in, encoding,
        HtmlNodeFilterTransform.exclude(new OrFilter(filters)));
    Reader filteredReader = FilterUtil.getReader(filtered, encoding);
    Reader tagFilter = HtmlTagFilter.makeNestedFilter(filteredReader,
        ListUtil.list(
// XXX remove this and next 3 lines when new HtmlFilterInputStream changes go into effect
            new TagPair("<header id=\"pageHeader\">", "</header>"),
            new TagPair("<footer>", "</footer>"),
// XXX 
            new TagPair("<!--[", "]-->"),
            new TagPair("<!-- ", " -->")
            ));
    return new ReaderInputStream(new WhiteSpaceFilter(tagFilter));
  }
  
}

@@ -52,29 +52,29 @@
 v 1.
-2
+3
  2013-1
-1-23 01:45:22
+2-10 00:14:29
  ete
@@ -1696,96 +1696,8 @@
 il;%0A
-import org.lockss.filter.HtmlTagFilter;%0Aimport org.lockss.filter.HtmlTagFilter.TagPair;%0A
 impo
@@ -1800,41 +1800,8 @@
 .*;%0A
-import org.lockss.util.ListUtil;%0A
 impo
@@ -2444,96 +2444,45 @@
 ems%0A
-// XXX  remove 2 comments below when new HtmlFilterInputStream changes go into effect%0A//
+        new TagNameFilter(%22header%22),%0A
     
@@ -2508,54 +2508,81 @@
 er(%22
-head
+foot
 er%22),%0A
-//        new TagNameFilter(%22footer%22
+        // remove ALL comments%0A        HtmlNodeFilters.comment(
 ),%0A 
@@ -3081,24 +3081,34 @@
 %7D;%0A    %0A    
+HtmlFilter
 InputStream 
@@ -3225,485 +3225,162 @@
 s)))
-;
 %0A    
-Reader filteredReader = FilterUtil.getReader(filtered, encoding);%0A    Reader tagFilter = HtmlTagFilter.makeNestedFilter(filteredR
+.registerTag(new HtmlTags.H
 eader
-,
+())
 %0A    
-    ListUtil.list(%0A// XXX remove this and next 3 lines when new HtmlFilterInputStream changes go into effect%0A 
+.registerTag(new HtmlTags.Footer());%0A
     
+%0A
     
-   new TagPair(%22%3Cheader id=%5C%22pageHeader%5C%22%3E%22, %22%3C/header%3E%22),%0A            new TagPair(%22%3Cfooter%3E%22, %22%3C/footer%3E%22),%0A// XXX %0A            new TagPair(%22%3C!--%5B%22, %22%5D--%3E%22),%0A            new TagPair(%22%3C!-- %22, %22 --%3E%22)%0A            )
+Reader filteredReader = FilterUtil.getReader(filtered, encoding
 );%0A 
@@ -3436,15 +3436,20 @@
 ter(
-tagFilt
+filteredRead
 er))

Replace TagPair filters with new to 1.64 built-in methods