abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r434249 - in /incubator/abdera/java/trunk: core/src/main/java/org/apache/abdera/filter/ core/src/main/java/org/apache/abdera/util/filter/ examples/src/main/java/org/apache/abdera/examples/simple/ parser/src/main/java/org/apache/abdera/parse...
Date Wed, 23 Aug 2006 23:36:29 GMT
Author: jmsnell
Date: Wed Aug 23 16:36:27 2006
New Revision: 434249

URL: http://svn.apache.org/viewvc?rev=434249&view=rev
Log:
Some cleanups on the existing parse filter mechanism.  This is the first step towards a 
more efficient implementation that can efficiently and effectively strip unsafe content 
from parsed feeds.

Added:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ListParseFilter.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/AbstractListParseFilter.java
Modified:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/TextFilter.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/BlackListParseFilter.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/CompoundParseFilter.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/NonOpTextFilter.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/SafeContentWhiteListParseFilter.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/WhiteListParseFilter.java
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/PrintTitles.java
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/TextFilterExample.java
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/UnacceptableElementsExample.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java
    incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java

Added: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ListParseFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ListParseFilter.java?rev=434249&view=auto
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ListParseFilter.java
(added)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ListParseFilter.java
Wed Aug 23 16:36:27 2006
@@ -0,0 +1,32 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.filter;
+
+import javax.xml.namespace.QName;
+
+public interface ListParseFilter extends ParseFilter {
+
+  public abstract void add(QName qname);
+
+  public abstract boolean contains(QName qname);
+
+  public abstract void add(QName parent, QName attribute);
+
+  public abstract boolean contains(QName qname, QName attribute);
+  
+}

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java?rev=434249&r1=434248&r2=434249&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/ParseFilter.java
Wed Aug 23 16:36:27 2006
@@ -17,11 +17,6 @@
 */
 package org.apache.abdera.filter;
 
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 import javax.xml.namespace.QName;
 
 /**
@@ -29,47 +24,19 @@
  * within a parsed document.  They are set via the ParserOptions.setParseFilter
  * method.
  */
-public abstract class ParseFilter implements Cloneable {
+public interface ParseFilter extends Cloneable {
   
-  private List<QName> qnames = null;
-  private Map<QName,List<QName>> attributes = null;
+  public Object clone() throws CloneNotSupportedException;
+
+  /**
+   * Returns true if elements with the given QName are acceptable
+   */
+  public boolean acceptable(QName qname);
   
-  public Object clone() throws CloneNotSupportedException {
-    return super.clone();
-  }
+  /**
+   * Returns true if attributes with the given qname appearing on elements
+   * with the given qname are acceptable
+   */
+  public boolean acceptable(QName qname, QName attribute);
   
-  public void add(QName qname) {
-    if (qnames == null) qnames = new ArrayList<QName>();
-    if (!contains(qname)) qnames.add(qname);
-  }
-
-  public boolean contains(QName qname) {
-    if (qnames == null) qnames = new ArrayList<QName>();
-    return qnames.contains(qname);
-  }
-
-  public void addAttribute(QName parent, QName attribute) {
-    if (attributes == null) attributes = new HashMap<QName,List<QName>>();
-    if (attributes.containsKey(parent)) {
-      List<QName> attrs = attributes.get(parent);
-      if (!attrs.contains(attribute)) attrs.add(attribute);
-    } else {
-      List<QName> attrs = new ArrayList<QName>();
-      attrs.add(attribute);
-      attributes.put(parent, attrs);
-    }
-  }
-
-  public boolean containsAttribute(QName qname, QName attribute) {
-    if (attributes == null) attributes = new HashMap<QName,List<QName>>();
-    if (attributes.containsKey(qname)) {
-      List<QName> attrs = attributes.get(qname);
-      return attrs.contains(attribute);
-    } else {
-      return false;
-    }
-  }
-
-  public abstract boolean acceptable(QName qname);
-  public abstract boolean acceptableAttribute(QName qname, QName attribute);
 }

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/TextFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/TextFilter.java?rev=434249&r1=434248&r2=434249&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/TextFilter.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/filter/TextFilter.java
Wed Aug 23 16:36:27 2006
@@ -26,17 +26,19 @@
  * from elements in the Atom feed, including unwanted text and
  * markup in HTML entries.
  */
-public abstract class TextFilter implements Cloneable {
+public interface TextFilter extends Cloneable {
 
-  public Object clone() throws CloneNotSupportedException {
-    return super.clone();
-  }
+  public Object clone() throws CloneNotSupportedException;
   
-  public String filterText(String text, Element parent) {
-    return text;
-  }
+  public String applyFilter(
+    char[] c, 
+    int start, 
+    int len, 
+    Element parent);
+  
+  public String applyFilter(
+    String value, 
+    Element parent,
+    QName attribute);
   
-  public String filterAttributeText(String text, QName attribute, Element parent) {
-    return text;
-  }
 }

Added: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/AbstractListParseFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/AbstractListParseFilter.java?rev=434249&view=auto
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/AbstractListParseFilter.java
(added)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/AbstractListParseFilter.java
Wed Aug 23 16:36:27 2006
@@ -0,0 +1,78 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.util.filter;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.abdera.filter.ListParseFilter;
+
+/**
+ * ParseFilter's determine which elements and attributes are acceptable
+ * within a parsed document.  They are set via the ParserOptions.setParseFilter
+ * method.
+ */
+public abstract class AbstractListParseFilter 
+  implements Cloneable, ListParseFilter {
+  
+  private List<QName> qnames = null;
+  private Map<QName,List<QName>> attributes = null;
+  
+  public Object clone() throws CloneNotSupportedException {
+    return super.clone();
+  }
+  
+  public void add(QName qname) {
+    if (qnames == null) qnames = new ArrayList<QName>();
+    if (!contains(qname)) qnames.add(qname);
+  }
+
+  public boolean contains(QName qname) {
+    if (qnames == null) qnames = new ArrayList<QName>();
+    return qnames.contains(qname);
+  }
+
+  public void add(QName parent, QName attribute) {
+    if (attributes == null) attributes = new HashMap<QName,List<QName>>();
+    if (attributes.containsKey(parent)) {
+      List<QName> attrs = attributes.get(parent);
+      if (!attrs.contains(attribute)) attrs.add(attribute);
+    } else {
+      List<QName> attrs = new ArrayList<QName>();
+      attrs.add(attribute);
+      attributes.put(parent, attrs);
+    }
+  }
+
+  public boolean contains(QName qname, QName attribute) {
+    if (attributes == null) attributes = new HashMap<QName,List<QName>>();
+    if (attributes.containsKey(qname)) {
+      List<QName> attrs = attributes.get(qname);
+      return attrs.contains(attribute);
+    } else {
+      return false;
+    }
+  }
+
+  public abstract boolean acceptable(QName qname);
+  public abstract boolean acceptable(QName qname, QName attribute);
+}

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/BlackListParseFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/BlackListParseFilter.java?rev=434249&r1=434248&r2=434249&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/BlackListParseFilter.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/BlackListParseFilter.java
Wed Aug 23 16:36:27 2006
@@ -19,19 +19,20 @@
 
 import javax.xml.namespace.QName;
 
-import org.apache.abdera.filter.ParseFilter;
 
 /**
- * BlackList Implementation of ParseFilter.  The 
- * QNames listed will be considered unacceptable 
+ * BlackList Implementation of ParseFilter.  The QNames listed will be 
+ * considered unacceptable.  In general, black list based filtering is 
+ * problematic, at best, due largely to the fact that it's easier to 
+ * define safe subsets of elements than it is to define unsafe subsets. 
  */
-public class BlackListParseFilter extends ParseFilter {
+public class BlackListParseFilter extends AbstractListParseFilter {
 
   public boolean acceptable(QName qname) {
     return !contains(qname);
   }
 
-  public boolean acceptableAttribute(QName qname, QName attribute) {
-    return !containsAttribute(qname, attribute);
+  public boolean acceptable(QName qname, QName attribute) {
+    return !contains(qname, attribute);
   }
 }

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/CompoundParseFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/CompoundParseFilter.java?rev=434249&r1=434248&r2=434249&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/CompoundParseFilter.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/CompoundParseFilter.java
Wed Aug 23 16:36:27 2006
@@ -37,7 +37,7 @@
  * </pre>
  */
 public class CompoundParseFilter 
-  extends ParseFilter {
+  implements ParseFilter {
 
   public enum Condition {
     ACCEPTABLE_TO_ALL, 
@@ -63,7 +63,6 @@
     return (filters != null) ? filters : empty;
   }
   
-  @Override
   public boolean acceptable(QName qname) {
     for (ParseFilter filter : getFilters()) {
       if (filter.acceptable(qname)) {
@@ -85,10 +84,9 @@
     return true;
   }
 
-  @Override
-  public boolean acceptableAttribute(QName qname, QName attribute) {
+  public boolean acceptable(QName qname, QName attribute) {
     for (ParseFilter filter : getFilters()) {
-      if (filter.acceptableAttribute(qname,attribute)) {
+      if (filter.acceptable(qname,attribute)) {
         switch(condition) {
           case ACCEPTABLE_TO_ANY:
             return true;
@@ -107,30 +105,7 @@
     return true;
   }
 
-  @Override
-  public void add(QName qname) {
-    throw new UnsupportedOperationException();
+  public Object clone() throws CloneNotSupportedException {
+    return super.clone();
   }
-
-  @Override
-  public void addAttribute(QName parent, QName attribute) {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
-  public boolean contains(QName qname) {
-    for (ParseFilter filter : getFilters()) {
-      if (filter.contains(qname)) return true;
-    }
-    return false;
-  }
-
-  @Override
-  public boolean containsAttribute(QName qname, QName attribute) {
-    for (ParseFilter filter : getFilters()) {
-      if (filter.containsAttribute(qname,attribute)) return true;
-    }
-    return false;
-  }
-
 }

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/NonOpTextFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/NonOpTextFilter.java?rev=434249&r1=434248&r2=434249&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/NonOpTextFilter.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/NonOpTextFilter.java
Wed Aug 23 16:36:27 2006
@@ -17,8 +17,30 @@
 */
 package org.apache.abdera.util.filter;
 
+import javax.xml.namespace.QName;
+
 import org.apache.abdera.filter.TextFilter;
+import org.apache.abdera.model.Element;
+
+public class NonOpTextFilter 
+  implements TextFilter {
+
+  public String applyFilter(
+    char[] c, 
+    int start, 
+    int len, 
+    Element parent) {
+      return new String(c,start,len);
+  }
 
-public class NonOpTextFilter extends TextFilter {
+  public String applyFilter(
+    String value,
+    Element parent, 
+    QName attribute) {
+      return value;
+  }
 
+  public Object clone() throws CloneNotSupportedException {
+    return super.clone();
+  }
 }

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/SafeContentWhiteListParseFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/SafeContentWhiteListParseFilter.java?rev=434249&r1=434248&r2=434249&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/SafeContentWhiteListParseFilter.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/SafeContentWhiteListParseFilter.java
Wed Aug 23 16:36:27 2006
@@ -19,10 +19,11 @@
 
 import javax.xml.namespace.QName;
 
+import org.apache.abdera.filter.ParseFilter;
 import org.apache.abdera.util.Constants;
 
 public class SafeContentWhiteListParseFilter 
-  extends WhiteListParseFilter {
+  implements ParseFilter {
 
   private static enum xhtml_elements {
     a, abbr, acronym, address, area, b, big, blockquote, 
@@ -46,7 +47,6 @@
     vspace, width,
   };
   
-  @Override
   public boolean acceptable(QName qname) {
     if (qname.getNamespaceURI().equals(Constants.XHTML_NS)) {
       try {
@@ -59,8 +59,7 @@
     }
   }
 
-  @Override
-  public boolean acceptableAttribute(QName qname, QName attribute) {
+  public boolean acceptable(QName qname, QName attribute) {
     if (qname.getNamespaceURI().equals(Constants.XHTML_NS)) {
       try {
         String lp = attribute.getLocalPart();
@@ -76,25 +75,9 @@
       return true;
     }
   }
-  
-  @Override
-  public void add(QName qname) {
-    throw new UnsupportedOperationException();
-  }
-
-  @Override
-  public void addAttribute(QName parent, QName attribute) {
-    throw new UnsupportedOperationException();
-  }
 
-  @Override
-  public boolean contains(QName qname) {
-    return acceptable(qname);
+  public Object clone() throws CloneNotSupportedException {
+    return super.clone();
   }
-
-  @Override
-  public boolean containsAttribute(QName qname, QName attribute) {
-    return acceptableAttribute(qname, attribute);
-  }
-
 }
+

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/WhiteListParseFilter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/WhiteListParseFilter.java?rev=434249&r1=434248&r2=434249&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/WhiteListParseFilter.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/filter/WhiteListParseFilter.java
Wed Aug 23 16:36:27 2006
@@ -19,18 +19,24 @@
 
 import javax.xml.namespace.QName;
 
-import org.apache.abdera.filter.ParseFilter;
 
 /**
  * WhiteList Implementation of ParseFilter.  Only the 
  * QNames listed will be considered acceptable 
  */
-public class WhiteListParseFilter extends ParseFilter {
+public class WhiteListParseFilter 
+  extends AbstractListParseFilter {
 
   boolean listAttributesExplicitly = false;
   
   public WhiteListParseFilter() {}
   
+  /**
+   * If listAttributesExplicity == true, attributes MUST be whitelisted 
+   * independently of the elements on which they appear, otherwise,
+   * all attributes will automatically be considered acceptable if 
+   * the containing element is considered acceptable.
+   */
   public WhiteListParseFilter(boolean listAttributesExplicitly) {
     this.listAttributesExplicitly = listAttributesExplicitly;
   }
@@ -39,10 +45,10 @@
     return contains(qname);
   }
 
-  public boolean acceptableAttribute(QName qname, QName attribute) {
+  public boolean acceptable(QName qname, QName attribute) {
     return (listAttributesExplicitly) ? 
-      containsAttribute(qname, attribute) :
-      containsAttribute(qname, attribute) || acceptable(qname);
+      contains(qname, attribute) && acceptable(qname) :
+      acceptable(qname);
   }
 
 }

Modified: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/PrintTitles.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/PrintTitles.java?rev=434249&r1=434248&r2=434249&view=diff
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/PrintTitles.java
(original)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/PrintTitles.java
Wed Aug 23 16:36:27 2006
@@ -22,7 +22,7 @@
 import java.util.List;
 
 import org.apache.abdera.Abdera;
-import org.apache.abdera.filter.ParseFilter;
+import org.apache.abdera.filter.ListParseFilter;
 import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Entry;
 import org.apache.abdera.model.Feed;
@@ -52,7 +52,7 @@
 
     ParserOptions opts = parser.getDefaultParserOptions();
 
-    ParseFilter filter = new WhiteListParseFilter();
+    ListParseFilter filter = new WhiteListParseFilter();
     filter.add(Constants.FEED);
     filter.add(Constants.ENTRY);
     filter.add(Constants.TITLE);

Modified: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/TextFilterExample.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/TextFilterExample.java?rev=434249&r1=434248&r2=434249&view=diff
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/TextFilterExample.java
(original)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/TextFilterExample.java
Wed Aug 23 16:36:27 2006
@@ -32,6 +32,7 @@
 import org.apache.abdera.parser.Parser;
 import org.apache.abdera.parser.ParserOptions;
 import org.apache.abdera.util.Constants;
+import org.apache.abdera.util.filter.NonOpTextFilter;
 
 public class TextFilterExample {
 
@@ -40,11 +41,12 @@
     Parser parser = Abdera.getNewParser();
     
     // First create the text filter
-    TextFilter filter = new TextFilter() {
+    TextFilter filter = new NonOpTextFilter() {
       @Override
-      public String filterText(String text, Element element) {
+      public String applyFilter(char[] c, int start, int len, Element element) {
         QName qname = element.getQName();
         Base elparent = element.getParentElement();
+        String text = new String(c,start,len);
         if (Constants.NAME.equals(qname)) {
           text = "Jane Doe";
         } else if (Constants.TITLE.equals(qname) && elparent instanceof Entry) {

Modified: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/UnacceptableElementsExample.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/UnacceptableElementsExample.java?rev=434249&r1=434248&r2=434249&view=diff
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/UnacceptableElementsExample.java
(original)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/simple/UnacceptableElementsExample.java
Wed Aug 23 16:36:27 2006
@@ -22,7 +22,7 @@
 import javax.xml.namespace.QName;
 
 import org.apache.abdera.Abdera;
-import org.apache.abdera.filter.ParseFilter;
+import org.apache.abdera.filter.ListParseFilter;
 import org.apache.abdera.model.Document;
 import org.apache.abdera.model.Feed;
 import org.apache.abdera.parser.Parser;
@@ -40,7 +40,7 @@
      * By subclassing BlackListParseFilter, we can throw an error 
      * when the parsed XML contains any content we don't want
      */
-    ParseFilter exceptionFilter = new BlackListParseFilter() {
+    ListParseFilter exceptionFilter = new BlackListParseFilter() {
       @Override
       public boolean acceptable(QName qname) {
         boolean answer = super.acceptable(qname);
@@ -51,7 +51,7 @@
       }
 
       @Override
-      public boolean acceptableAttribute(QName qname, QName attribute) {
+      public boolean acceptable(QName qname, QName attribute) {
         return true;
       }
     };

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java?rev=434249&r1=434248&r2=434249&view=diff
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMBuilder.java
Wed Aug 23 16:36:27 2006
@@ -122,7 +122,7 @@
     return (filter != null) ? 
       (!attribute) ? 
          filter.acceptable(qname) : 
-         filter.acceptableAttribute(parser.getName(), qname): 
+         filter.acceptable(parser.getName(), qname): 
       true;
   }
   
@@ -133,7 +133,11 @@
       if (filter != null) {
         String value = parser.getText();
         if (!lastNode.isComplete())
-          value = filter.filterText(value, (Element)lastNode);
+          value = filter.applyFilter(
+            parser.getTextCharacters(), 
+            parser.getTextStart(), 
+            parser.getTextLength(), 
+            (Element)lastNode);
         return createOMText(value, type);
       }
     }
@@ -144,7 +148,7 @@
     if (parserOptions != null) { 
       TextFilter filter = parserOptions.getTextFilter();
       if (filter != null) {
-        return filter.filterAttributeText(value, attribute, parent);
+        return filter.applyFilter(value, parent, attribute);
       }
     }
     return value;

Modified: incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java?rev=434249&r1=434248&r2=434249&view=diff
==============================================================================
--- incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java
(original)
+++ incubator/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java
Wed Aug 23 16:36:27 2006
@@ -34,7 +34,7 @@
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.factory.Factory;
-import org.apache.abdera.filter.ParseFilter;
+import org.apache.abdera.filter.ListParseFilter;
 import org.apache.abdera.filter.TextFilter;
 import org.apache.abdera.model.AtomDate;
 import org.apache.abdera.model.Base;
@@ -64,6 +64,7 @@
 import org.apache.abdera.util.URIHelper;
 import org.apache.abdera.util.Version;
 import org.apache.abdera.util.filter.BlackListParseFilter;
+import org.apache.abdera.util.filter.NonOpTextFilter;
 import org.apache.abdera.util.filter.WhiteListParseFilter;
 import org.apache.abdera.writer.Writer;
 import org.apache.abdera.writer.WriterFactory;
@@ -175,7 +176,7 @@
 
   public void testWhiteListParseFilter() throws Exception {
     
-    ParseFilter filter = new WhiteListParseFilter();
+    ListParseFilter filter = new WhiteListParseFilter();
     filter.add(Constants.FEED);
     filter.add(Constants.ENTRY);
     filter.add(Constants.TITLE);
@@ -209,7 +210,7 @@
   
   public void testBlackListParseFilter() throws Exception {
     
-    ParseFilter filter = new BlackListParseFilter();
+    ListParseFilter filter = new BlackListParseFilter();
     filter.add(Constants.UPDATED);
     ParserOptions options = getParser().getDefaultParserOptions();
     options.setParseFilter(filter);
@@ -241,11 +242,12 @@
   
   public void testTextFilter() throws Exception {
     
-    TextFilter filter = new TextFilter() {
+    TextFilter filter = new NonOpTextFilter() {
       @Override
-      public String filterText(String text, Element parent) {
+      public String applyFilter(char[] c, int start, int len, Element parent) {
         QName qname = parent.getQName();
         Base elparent = parent.getParentElement();
+        String text = new String(c,start,len);
         if (Constants.NAME.equals(qname)) {
           text = "Jane Doe";
         } else if (Constants.TITLE.equals(qname) && elparent instanceof Entry) {



Mime
View raw message