/*
 * $Id: OJS2HtmlFilterFactory.java,v 1.10 2014-06-04 16:06:04 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.ojs2;

import java.io.InputStream;

import org.htmlparser.NodeFilter;
import org.htmlparser.filters.*;
import org.lockss.filter.html.*;
import org.lockss.plugin.*;

public class OJS2HtmlFilterFactory implements FilterFactory {

    public InputStream createFilteredInputStream(ArchivalUnit au,
                                                 InputStream in,
                                                 String encoding) {
        NodeFilter[] filters = new NodeFilter[] {
            // Some OJS sites have a tag cloud
            HtmlNodeFilters.tagWithAttribute("div", "id", "sidebarKeywordCloud"),
            // Some OJS sites have a subscription status area
            HtmlNodeFilters.tagWithAttribute("div", "id", "sidebarSubscription"),
            // Some OJS sites have a language switcher, which can change over time
            HtmlNodeFilters.tagWithAttribute("div", "id", "sidebarLanguageToggle"),
            // Top-level menu items sometimes change over time
            HtmlNodeFilters.tagWithAttribute("div", "id", "navbar"),
            // Popular location for sidebar customizations
            HtmlNodeFilters.tagWithAttribute("div", "id", "custom"),
            //  the order of <meta> tags changes capriciously, which slows down testing
            new TagNameFilter("head"),
            // Site customizations often involve Javascript (e.g. Google Analytics), which can change over time
            new TagNameFilter("script"),
            // Date accessed is a variable
            HtmlNodeFilters.tagWithTextRegex("div", "Date accessed: "),
            // The version of the OJS software, which can change over time, appears in a tag
            HtmlNodeFilters.tagWithAttribute("meta", "name", "generator"),
            // Header image with variable dimensions
            HtmlNodeFilters.tagWithAttribute("div", "id", "headerTitle"),
            // For Ubiquity Press
            HtmlNodeFilters.tagWithAttribute("div", "id", "rightSidebar"),
            // For JLIS.it: landing pages contain user view count
            HtmlNodeFilters.tagWithAttribute("span", "class", "ArticleViews"),
            // For ibictpln: PHP Query Profiler
            HtmlNodeFilters.tagWithAttribute("div", "id", "pqp-container"),
        };
        return new HtmlFilterInputStream(in,
                                         encoding,
                                         HtmlNodeFilterTransform.exclude(new OrFilter(filters)));
    }
    
}

@@ -36,17 +36,17 @@
 va,v 1.1
-0
+1
  2014-06
@@ -53,16 +53,16 @@
 -04 
-16:06:04
+22:46:29
  ete
@@ -1560,24 +1560,65 @@
 .filters.*;%0A
+import org.htmlparser.tags.CompositeTag;%0A
 import org.l
@@ -1729,19 +1729,604 @@
 ctory %7B%0A
+  
 %0A  
+/**%0A   * A B(old) tag.  Registered with PrototypicalNodeFactory to cause B%0A   * to be a CompositeTag.  See code samples in org.htmlparser.tags.%0A   * @see HtmlFilterInputStream#makeParser()%0A   */%0A  public static class bTag extends CompositeTag %7B%0A    %0A    /**%0A     * The set of names handled by this tag.%0A     */%0A    private static final String%5B%5D mIds = new String%5B%5D %7B%22b%22%7D;%0A    %0A    /**%0A     * Return the set of names handled by this tag.%0A     * @return The names to be matched that create tags of this type.%0A     */%0A    public String%5B%5D getIds() %7B%0A      return mIds;%0A    %7D%0A    %0A  %7D%0A  %0A
   public
@@ -2381,18 +2381,16 @@
 nit au,%0A
-  
         
@@ -2491,18 +2491,16 @@
         
-  
 String e
@@ -2510,20 +2510,16 @@
 ding) %7B%0A
-    
     Node
@@ -4336,138 +4336,256 @@
     
-%7D;%0A
     
-    return new HtmlFilterInputStream(in,%0A                              
+// Total de acessos: keeps changing, there is no 'good' tag wrapped around text%0A            HtmlNodeFilters.tagWithTextRegex(%22b%22, %22%5E *total de acesso( dos artigo)?s: +%5B0-9%5D+ *$%22, true),%0A
     
+%7D;%0A
     
-   encoding,%0A                               
+return new HtmlFilterInputStream(in, encoding,%0A
     
@@ -4645,23 +4645,54 @@
 lters)))
-;%0A    %7D
+.%0A          registerTag(new bTag());
 %0A  
+%7D%0A
   %0A%7D%0A

Add custom tag filter for access counts