You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2010/09/29 11:57:25 UTC

svn commit: r1002548 - in /sling/trunk/bundles/extensions/event: pom.xml src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java src/main/java/org/apache/sling/event/impl/JobEventHandler.java

Author: cziegeler
Date: Wed Sep 29 09:57:25 2010
New Revision: 1002548

URL: http://svn.apache.org/viewvc?rev=1002548&view=rev
Log:
SLING-1806 : Include helper classes in bundle

Modified:
    sling/trunk/bundles/extensions/event/pom.xml
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
    sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java

Modified: sling/trunk/bundles/extensions/event/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/pom.xml?rev=1002548&r1=1002547&r2=1002548&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/pom.xml (original)
+++ sling/trunk/bundles/extensions/event/pom.xml Wed Sep 29 09:57:25 2010
@@ -68,7 +68,8 @@
                             slingevent=http://sling.apache.org/jcr/event/1.0
                         </Sling-Namespaces>
                         <Embed-Dependency>
-                            jackrabbit-jcr-commons;inline="org/apache/jackrabbit/util/ISO9075.*|org/apache/jackrabbit/util/ISO8601.*|org/apache/jackrabbit/util/XMLChar.*"
+                            jackrabbit-jcr-commons;inline="org/apache/jackrabbit/util/ISO9075.*|org/apache/jackrabbit/util/ISO8601.*|org/apache/jackrabbit/util/XMLChar.*",
+                            org.apache.sling.commons.osgi;inline="org/apache/sling/commons/osgi/OsgiUtil.*"
                         </Embed-Dependency>
                     </instructions>
                 </configuration>
@@ -115,7 +116,6 @@
             <groupId>org.osgi</groupId>
             <artifactId>org.osgi.compendium</artifactId>
         </dependency>
-        <!-- We use version 2.0 for testing! -->
         <dependency>
             <groupId>javax.jcr</groupId>
             <artifactId>jcr</artifactId>
@@ -136,7 +136,7 @@
         </dependency>
         <dependency>
             <groupId>org.apache.sling</groupId>
-            <artifactId>org.apache.sling.jcr.resource</artifactId>
+            <artifactId>org.apache.sling.commons.osgi</artifactId>
             <version>2.0.6</version>
             <scope>provided</scope>
         </dependency>
@@ -166,6 +166,12 @@
         </dependency>
       <!-- Testing -->
         <dependency>
+            <groupId>org.apache.sling</groupId>
+            <artifactId>org.apache.sling.jcr.resource</artifactId>
+            <version>2.0.6</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
         </dependency>

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java?rev=1002548&r1=1002547&r2=1002548&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java Wed Sep 29 09:57:25 2010
@@ -20,6 +20,7 @@ package org.apache.sling.event.impl;
 
 import java.util.Calendar;
 import java.util.Dictionary;
+import java.util.StringTokenizer;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 
@@ -37,7 +38,6 @@ import org.apache.sling.commons.classloa
 import org.apache.sling.commons.osgi.OsgiUtil;
 import org.apache.sling.event.JobStatusProvider;
 import org.apache.sling.jcr.api.SlingRepository;
-import org.apache.sling.jcr.resource.JcrResourceUtil;
 import org.apache.sling.settings.SlingSettingsService;
 import org.osgi.service.component.ComponentContext;
 import org.osgi.service.event.Event;
@@ -210,10 +210,9 @@ public abstract class AbstractRepository
      */
     protected void startWriterSession() throws RepositoryException {
         this.writerSession = this.createSession();
-        this.writeRootNode = JcrResourceUtil.createPath(this.repositoryPath,
-                EventHelper.NODETYPE_FOLDER,
-                EventHelper.NODETYPE_ORDERED_FOLDER,
-                this.writerSession, true);
+        this.writeRootNode = this.createPath(this.writerSession.getRootNode(),
+                this.repositoryPath.substring(1),
+                EventHelper.NODETYPE_ORDERED_FOLDER);
     }
 
     /**
@@ -266,10 +265,9 @@ public abstract class AbstractRepository
             final int sepPos = nodeType.indexOf(':');
             nodeName = nodeType.substring(sepPos+1) + "-" + this.applicationId + "-" + now.getTime().getTime();
         }
-        final Node eventNode = JcrResourceUtil.createPath(rootNode,
+        final Node eventNode = this.createPath(rootNode,
                 nodeName,
-                EventHelper.NODETYPE_FOLDER,
-                nodeType, false);
+                nodeType);
 
         eventNode.setProperty(EventHelper.NODE_PROPERTY_CREATED, Calendar.getInstance());
         eventNode.setProperty(EventHelper.NODE_PROPERTY_TOPIC, e.getTopic());
@@ -350,6 +348,53 @@ public abstract class AbstractRepository
         }
     }
 
+    /**
+     * Creates or gets the {@link javax.jcr.Node Node} at the given Path.
+     * In case it has to create the Node all non-existent intermediate path-elements
+     * will be create with the given intermediate node type and the returned node
+     * will be created with the given nodeType
+     *
+     * @param parentNode starting node
+     * @param relativePath to create
+     * @param intermediateNodeType to use for creation of intermediate nodes (or null)
+     * @param nodeType to use for creation of the final node (or null)
+     * @param autoSave Should save be called when a new node is created?
+     * @return the Node at path
+     * @throws RepositoryException in case of exception accessing the Repository
+     */
+    private Node createPath(Node   parentNode,
+                            String relativePath,
+                            String nodeType)
+    throws RepositoryException {
+        if (!parentNode.hasNode(relativePath)) {
+            Node node = parentNode;
+            int pos = relativePath.lastIndexOf('/');
+            if ( pos != -1 ) {
+                final StringTokenizer st = new StringTokenizer(relativePath.substring(0, pos), "/");
+                while ( st.hasMoreTokens() ) {
+                    final String token = st.nextToken();
+                    if ( !node.hasNode(token) ) {
+                        try {
+                            node.addNode(token, EventHelper.NODETYPE_FOLDER);
+                            node.getSession().save();
+                        } catch (RepositoryException re) {
+                            // we ignore this as this folder might be created from a different task
+                            node.refresh(false);
+                        }
+                    }
+                    node = node.getNode(token);
+                }
+                relativePath = relativePath.substring(pos + 1);
+            }
+            if ( !node.hasNode(relativePath) ) {
+                node.addNode(relativePath, nodeType);
+                node.getSession().save();
+            }
+            return node.getNode(relativePath);
+        }
+        return parentNode.getNode(relativePath);
+    }
+
     public static final class EventInfo {
         public String nodePath;
         public Event event;

Modified: sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java?rev=1002548&r1=1002547&r2=1002548&view=diff
==============================================================================
--- sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java (original)
+++ sling/trunk/bundles/extensions/event/src/main/java/org/apache/sling/event/impl/JobEventHandler.java Wed Sep 29 09:57:25 2010
@@ -52,7 +52,6 @@ import org.apache.felix.scr.annotations.
 import org.apache.felix.scr.annotations.Property;
 import org.apache.felix.scr.annotations.Service;
 import org.apache.felix.scr.annotations.Services;
-import org.apache.sling.api.resource.ResourceUtil;
 import org.apache.sling.commons.osgi.OsgiUtil;
 import org.apache.sling.commons.scheduler.Scheduler;
 import org.apache.sling.commons.threads.ThreadPool;
@@ -1072,7 +1071,7 @@ public class JobEventHandler
      * @return The real job event.
      */
     private Event getJobEvent(Event e, String nodePath) {
-        final String eventTopic = ResourceUtil.normalize((String)e.getProperty(EventUtil.PROPERTY_JOB_TOPIC));
+        final String eventTopic = (String)e.getProperty(EventUtil.PROPERTY_JOB_TOPIC);
         final Dictionary<String, Object> properties = new EventPropertiesMap(e);
         // put properties for finished job callback
         properties.put(JobStatusNotifier.CONTEXT_PROPERTY_NAME,