incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r688657 - in /incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event: EventUtil.java impl/AbstractRepositoryEventHandler.java
Date Mon, 25 Aug 2008 08:37:31 GMT
Author: cziegeler
Date: Mon Aug 25 01:37:31 2008
New Revision: 688657

URL: http://svn.apache.org/viewvc?rev=688657&view=rev
Log:
Correct ignoring prefixes and add convenience methods.

Modified:
    incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
    incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java

Modified: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java?rev=688657&r1=688656&r2=688657&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
(original)
+++ incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/EventUtil.java
Mon Aug 25 01:37:31 2008
@@ -24,6 +24,7 @@
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Calendar;
 import java.util.Dictionary;
 import java.util.Enumeration;
@@ -278,11 +279,32 @@
      * @throws RepositoryException
      */
     public static void addProperties(final Node node,
+                                     final Map<String, Object> properties,
+                                     final String[] ignoreProps,
+                                     final String binPropertyName)
+    throws RepositoryException {
+        addProperties(node, new EventPropertiesMap(properties), ignoreProps, binPropertyName);
+    }
+
+    /**
+     * Add all java properties as properties to the node.
+     * If the name and the value of a map entry can easily converted into
+     * a repository property, it is directly added. All other java
+     * properties are stored in one binary property.
+     *
+     * @param node The node where all properties are added to
+     * @param properties The map of properties.
+     * @param ignoreProps optional list of property which should be ignored
+     * @param binPropertyName The name of the binary property.
+     * @throws RepositoryException
+     */
+    public static void addProperties(final Node node,
                                      final EventPropertiesMap properties,
-                                     final List<String> ignoreProps,
+                                     final String[] ignoreProps,
                                      final String binPropertyName)
     throws RepositoryException {
         if ( properties != null ) {
+            final List<String> ignorePropList = (ignoreProps == null ? null : Arrays.asList(ignoreProps));
             // check which props we can write directly and
             // which we need to write as a binary blob
             final List<String> propsAsBlob = new ArrayList<String>();
@@ -291,7 +313,7 @@
             while ( i.hasNext() ) {
                 final Map.Entry<String, Object> current = i.next();
 
-                if (ignoreProps == null || !ignoreProps.contains(current.getKey()) ) {
+                if (ignorePropList == null || !ignorePropList.contains(current.getKey())
) {
                     // sanity check
                     if ( current.getValue() != null ) {
                         if ( !setProperty(current.getKey(), current.getValue(), node) ) {
@@ -326,7 +348,7 @@
      */
     public static EventPropertiesMap readProperties(final Node node,
                                                     final String binPropertyName,
-                                                    final List<String> ignorePrefixes)
+                                                    final String[] ignorePrefixes)
     throws RepositoryException, ClassNotFoundException {
         final Map<String, Object> properties = new HashMap<String, Object>();
 
@@ -348,8 +370,14 @@
         final PropertyIterator pI = node.getProperties();
         while ( pI.hasNext() ) {
             final Property p = pI.nextProperty();
-            if ( !p.getName().startsWith("jcr:") &&
-                 (ignorePrefixes == null || !ignorePrefixes.contains(p.getName())))  {
+            boolean ignore = p.getName().startsWith("jcr:");
+            if ( !ignore && ignorePrefixes != null ) {
+                int index = 0;
+                while ( !ignore && index < ignorePrefixes.length ) {
+                    ignore = p.getName().startsWith(ignorePrefixes[index]);
+                }
+            }
+            if ( !ignore ) {
                 final String name = ISO9075.decode(p.getName());
                 final Value value = p.getValue();
                 final Object o;

Modified: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java?rev=688657&r1=688656&r2=688657&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
(original)
+++ incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
Mon Aug 25 01:37:31 2008
@@ -19,10 +19,8 @@
 package org.apache.sling.event.impl;
 
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Dictionary;
-import java.util.List;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 
@@ -101,18 +99,16 @@
     protected SlingSettingsService settingsService;
 
     /** List of ignored properties to write to the repository. */
-    private static final List<String> IGNORE_PROPERTIES = new ArrayList<String>();
-    static {
-        IGNORE_PROPERTIES.add(EventUtil.PROPERTY_DISTRIBUTE);
-        IGNORE_PROPERTIES.add(EventUtil.PROPERTY_APPLICATION);
-        IGNORE_PROPERTIES.add(EventUtil.JobStatusNotifier.CONTEXT_PROPERTY_NAME);
-    }
+    private static final String[] IGNORE_PROPERTIES = new String[] {
+        EventUtil.PROPERTY_DISTRIBUTE,
+        EventUtil.PROPERTY_APPLICATION,
+        EventUtil.JobStatusNotifier.CONTEXT_PROPERTY_NAME
+    };
 
     /** List of ignored prefixes to read from the repository. */
-    private static final List<String> IGNORE_PREFIXES = new ArrayList<String>();
-    static {
-        IGNORE_PREFIXES.add(EventHelper.EVENT_PREFIX);
-    }
+    private static final String[] IGNORE_PREFIXES = new String[] {
+        EventHelper.EVENT_PREFIX
+    };
 
     /**
      * Activate this component.



Mime
View raw message