abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r541758 - /incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/EncodingUtil.java
Date Fri, 25 May 2007 19:45:24 GMT
Author: jmsnell
Date: Fri May 25 12:45:23 2007
New Revision: 541758

URL: http://svn.apache.org/viewvc?view=rev&rev=541758
Log:
Allow callers to pass in their own regex pattern for the santize function.

Modified:
    incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/EncodingUtil.java

Modified: incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/EncodingUtil.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/EncodingUtil.java?view=diff&rev=541758&r1=541757&r2=541758
==============================================================================
--- incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/EncodingUtil.java
(original)
+++ incubator/abdera/java/trunk/protocol/src/main/java/org/apache/abdera/protocol/util/EncodingUtil.java
Fri May 25 12:45:23 2007
@@ -34,16 +34,34 @@
 
 public class EncodingUtil {
 
+  public static final String SANITIZE_PATTERN = "[^A-Za-z0-9\\%!$&\\\\'()*+,;=]";
+  
   public static String sanitize(String slug) {
-    return sanitize(slug, null, false, null);
+    return sanitize(slug, null, false, null, SANITIZE_PATTERN);
   }
   
   public static String sanitize(String slug, String filler) {
-    return sanitize(slug, filler, false, null);
+    return sanitize(slug, filler, false, null, SANITIZE_PATTERN);
   }
   
   public static String sanitize(String slug, String filler, boolean lower) {
-    return sanitize(slug, filler, lower, null);
+    return sanitize(slug, filler, lower, null, SANITIZE_PATTERN);
+  }
+  
+  public static String sanitize(String slug, String filler, String pattern) {
+    return sanitize(slug, filler, false, null, pattern);
+  }
+  
+  public static String sanitize(String slug, String filler, boolean lower, String pattern)
{
+    return sanitize(slug, filler, lower, null, pattern);
+  }
+
+  public static String sanitize(
+      String slug, 
+      String filler, 
+      boolean lower, 
+      Normalizer.Form form) {
+    return sanitize(slug,filler,lower,form,SANITIZE_PATTERN);
   }
   
   /**
@@ -59,7 +77,8 @@
     String slug, 
     String filler, 
     boolean lower, 
-    Normalizer.Form form) {
+    Normalizer.Form form,
+    String pattern) {
       if (slug == null) return null;
       if (lower) slug = slug.toLowerCase();
       if (form != null) {
@@ -73,7 +92,7 @@
         slug = Escaping.encode(slug, Constants.PATH);
       }
       if (filler != null) {
-        slug = slug.replaceAll("[^A-Za-z0-9\\%!$&\\\\'()*+,;=]",filler);
+        slug = slug.replaceAll(pattern,filler);
       } else { 
         slug = Escaping.encode(slug, Constants.PATHNODELIMS);
       }



Mime
View raw message