incubator-droids-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t...@apache.org
Subject svn commit: r1451536 - /incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/RegexURLFilter.java
Date Fri, 01 Mar 2013 09:04:21 GMT
Author: tobr
Date: Fri Mar  1 09:04:20 2013
New Revision: 1451536

URL: http://svn.apache.org/r1451536
Log:
added rules reader from inputstream
https://issues.apache.org/jira/browse/DROIDS-98

added documentation

Modified:
    incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/RegexURLFilter.java

Modified: incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/RegexURLFilter.java
URL: http://svn.apache.org/viewvc/incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/RegexURLFilter.java?rev=1451536&r1=1451535&r2=1451536&view=diff
==============================================================================
--- incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/RegexURLFilter.java
(original)
+++ incubator/droids/branches/0.2.x-cleanup/droids-core/src/main/java/org/apache/droids/filter/RegexURLFilter.java
Fri Mar  1 09:04:20 2013
@@ -16,10 +16,7 @@
  */
 package org.apache.droids.filter;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
+import java.io.*;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
@@ -31,8 +28,8 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Regular expression implementation of an UrlFilter. Evaluates the url based on
- * regular expression.
+ * Regular expression implementation of an UrlFilter.
+ * Evaluates the url based on regular expression.
  *
  * @version 1.0
  */
@@ -82,10 +79,12 @@ public class RegexURLFilter<T extends Ta
     }
 
     /**
-     * @param file
+     * Add rules provided by file.
+     *
+     * @param file the path to the file
      * @throws IOException
      */
-    public void setFile(String file) throws IOException {
+    public void addRulesFile(String file) throws IOException {
         URL url = null;
         if (file.startsWith("classpath:/")) {
             url = this.getClass().getResource(file.substring("classpath:/".length() - 1));
@@ -101,6 +100,25 @@ public class RegexURLFilter<T extends Ta
         }
     }
 
+    /**
+     * Add rules from an inputstream of a rules file.
+     *
+     * @param is the inputstream of a file with rules
+     * @throws IOException
+     */
+    public void addRulesFile(InputStream is) throws IOException {
+        Reader reader = new InputStreamReader(is);
+        rules.addAll(readRulesFile(reader));
+    }
+
+    /**
+     * Extract the regex rules from a reader and
+     * add the to the filter.
+     *
+     * @param reader the rules reader
+     * @return a list of regex rules
+     * @throws IOException
+     */
     private List<RegexRule> readRulesFile(Reader reader) throws IOException {
         BufferedReader in = new BufferedReader(reader);
         List<RegexRule> localRules = new ArrayList<RegexRule>(16);
@@ -138,10 +156,20 @@ public class RegexURLFilter<T extends Ta
 
     }
 
+    /**
+     * Create a new regex rule.
+     *
+     * @param sign boolean value to define the filtering in or out.
+     * @param regex the rules regex
+     * @return
+     */
     private static RegexRule createRule(boolean sign, String regex) {
         return new Rule(sign, regex);
     }
 
+    /**
+     * Implementation of {@link RegexRule}
+     */
     private static class Rule extends RegexRule {
 
         private Pattern pattern;



Mime
View raw message