incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r692994 - in /incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl: EventHelper.java JobEventHandler.java TimedJobHandler.java
Date Mon, 08 Sep 2008 06:14:03 GMT
Author: cziegeler
Date: Sun Sep  7 23:14:02 2008
New Revision: 692994

URL: http://svn.apache.org/viewvc?rev=692994&view=rev
Log:
Move helper method to helper class.

Modified:
    incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/EventHelper.java
    incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
    incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/TimedJobHandler.java

Modified: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/EventHelper.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/EventHelper.java?rev=692994&r1=692993&r2=692994&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/EventHelper.java
(original)
+++ incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/EventHelper.java
Sun Sep  7 23:14:02 2008
@@ -20,12 +20,14 @@
 
 
 /**
- * Helper class defining some constants and providing support for identifying nodes in a
cluster.
+ * Helper class defining some constants and utility methods.
  */
 public abstract class EventHelper {
 
+    /** The name of the thread pool for the eventing stuff. */
     public static final String THREAD_POOL_NAME = "SLING_EVENTING";
 
+    /** The namespace prefix. */
     public static final String EVENT_PREFIX = "slingevent:";
 
     public static final String NODE_PROPERTY_TOPIC = "slingevent:topic";
@@ -46,5 +48,47 @@
     public static final String TIMED_EVENTS_NODE_TYPE = "slingevent:TimedEvents";
     public static final String TIMED_EVENT_NODE_TYPE = "slingevent:TimedEvent";
 
+    /** The nodetype for newly created folders */
     public static final String NODETYPE_FOLDER = "sling:Folder";
+
+    /** Allowed characters for a node name */
+    private static final String ALLOWED_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz0123456789_,.-+*#!¤$%&()=[]?";
+    /** Replacement characters for unallowed characters in a node name */
+    private static final char REPLACEMENT_CHAR = '_';
+
+    /**
+     * Filter the node name for not allowed characters and replace them.
+     * @param nodeName The suggested node name.
+     * @return The filtered node name.
+     */
+    public static String filter(final String nodeName) {
+        final StringBuffer sb  = new StringBuffer();
+        char lastAdded = 0;
+
+        for(int i=0; i < nodeName.length(); i++) {
+            final char c = nodeName.charAt(i);
+            char toAdd = c;
+
+            if (ALLOWED_CHARS.indexOf(c) < 0) {
+                if (lastAdded == REPLACEMENT_CHAR) {
+                    // do not add several _ in a row
+                    continue;
+                }
+                toAdd = REPLACEMENT_CHAR;
+
+            } else if(i == 0 && Character.isDigit(c)) {
+                sb.append(REPLACEMENT_CHAR);
+            }
+
+            sb.append(toAdd);
+            lastAdded = toAdd;
+        }
+
+        if (sb.length()==0) {
+            sb.append(REPLACEMENT_CHAR);
+        }
+
+        return sb.toString();
+    }
+
 }

Modified: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java?rev=692994&r1=692993&r2=692994&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
(original)
+++ incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
Sun Sep  7 23:14:02 2008
@@ -694,45 +694,12 @@
         }
     }
 
-    public static final String ALLOWED_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz0123456789_,.-+*#!¤$%&()=[]?";
-    public static final char REPLACEMENT_CHAR = '_';
-
-    public static String filter(final String nodeName) {
-        final StringBuffer sb  = new StringBuffer();
-        char lastAdded = 0;
-
-        for(int i=0; i < nodeName.length(); i++) {
-            final char c = nodeName.charAt(i);
-            char toAdd = c;
-
-            if (ALLOWED_CHARS.indexOf(c) < 0) {
-                if (lastAdded == REPLACEMENT_CHAR) {
-                    // do not add several _ in a row
-                    continue;
-                }
-                toAdd = REPLACEMENT_CHAR;
-
-            } else if(i == 0 && Character.isDigit(c)) {
-                sb.append(REPLACEMENT_CHAR);
-            }
-
-            sb.append(toAdd);
-            lastAdded = toAdd;
-        }
-
-        if (sb.length()==0) {
-            sb.append(REPLACEMENT_CHAR);
-        }
-
-        return sb.toString();
-    }
-
     /**
      * Create a unique node path (folder and name) for the job.
      */
     private String getNodePath(final String jobTopic, final String jobId) {
         if ( jobId != null ) {
-            return jobTopic.replace('/', '.') + "/" + filter(jobId);
+            return jobTopic.replace('/', '.') + "/" + EventHelper.filter(jobId);
         }
         return jobTopic.replace('/', '.') + "/Job " + UUID.randomUUID().toString();
     }

Modified: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/TimedJobHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/TimedJobHandler.java?rev=692994&r1=692993&r2=692994&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/TimedJobHandler.java
(original)
+++ incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/TimedJobHandler.java
Sun Sep  7 23:14:02 2008
@@ -627,7 +627,7 @@
         }
 
         public static String getJobId(String topic, String timedEventId, String jobId) {
-            return topic.replace('/', '.') + "/TimedEvent " + (timedEventId != null ? JobEventHandler.filter(timedEventId)
: "") + '_' + (jobId != null ? JobEventHandler.filter(jobId) : "");
+            return topic.replace('/', '.') + "/TimedEvent " + (timedEventId != null ? EventHelper.filter(timedEventId)
: "") + '_' + (jobId != null ? EventHelper.filter(jobId) : "");
         }
     }
 



Mime
View raw message