You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/11/07 09:48:02 UTC

[sling-org-apache-sling-jcr-contentloader] 22/28: SLING-1592 - using the ws:/path notation in the uninstall-paths node property.

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to annotated tag org.apache.sling.jcr.contentloader-2.1.0
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-contentloader.git

commit 51f92ec816f230334f85a7783a02ef1fa7906b65
Author: Justin Edelson <ju...@apache.org>
AuthorDate: Thu Jul 8 21:22:00 2010 +0000

    SLING-1592 - using the ws:/path notation in the uninstall-paths node property.
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/bundles/jcr/contentloader@961945 13f79535-47bb-0310-9956-ffa450edef68
---
 .../internal/DefaultContentCreator.java            | 18 ++++----
 .../sling/jcr/contentloader/internal/Loader.java   | 48 ++++++++++++++++++----
 2 files changed, 50 insertions(+), 16 deletions(-)

diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java b/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
index 57af6c1..97bf1b9 100644
--- a/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
+++ b/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
@@ -264,9 +264,7 @@ public class DefaultContentCreator implements ContentCreator {
 
                 // no explicit node type, use repository default
                 node = parentNode.addNode(name);
-                if ( this.createdNodes != null ) {
-                    this.createdNodes.add(node.getPath());
-                }
+                addNodeToCreatedList(node);
                 if ( this.importListener != null ) {
                 	this.importListener.onCreate(node.getPath());
                 }
@@ -274,9 +272,7 @@ public class DefaultContentCreator implements ContentCreator {
 
                 // explicit primary node type
                 node = parentNode.addNode(name, primaryNodeType);
-                if ( this.createdNodes != null ) {
-                    this.createdNodes.add(node.getPath());
-                }
+                addNodeToCreatedList(node);
                 if ( this.importListener != null ) {
                 	this.importListener.onCreate(node.getPath());
                 }
@@ -474,6 +470,12 @@ public class DefaultContentCreator implements ContentCreator {
         resolveReferences(node);
     }
 
+    private void addNodeToCreatedList(Node node) throws RepositoryException {
+        if ( this.createdNodes != null ) {
+            this.createdNodes.add(node.getSession().getWorkspace().getName() + ":" + node.getPath());
+        }
+    }
+
     private String getAbsPath(Node node, String path) throws RepositoryException {
         if (path.startsWith("/")) return path;
 
@@ -740,9 +742,7 @@ public class DefaultContentCreator implements ContentCreator {
                     return false;
                 }
                 final Node n = node.addNode(token, newNodeType);
-                if ( this.createdNodes != null ) {
-                    this.createdNodes.add(n.getPath());
-                }
+                addNodeToCreatedList(n);
                 if ( this.importListener != null ) {
                 	this.importListener.onCreate(node.getPath());
                 }
diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java b/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
index 53e9b86..4e01752 100644
--- a/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
+++ b/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
@@ -660,19 +660,44 @@ public class Loader extends BaseImportLoader {
         return (item.isNode()) ? (Node) item : null;
     }
 
-    private void uninstallContent(final Session session, final Bundle bundle,
+    private void uninstallContent(final Session defaultSession, final Bundle bundle,
             final String[] uninstallPaths) {
+        final Map<String, Session> createdSessions = new HashMap<String, Session>();
+        
         try {
             log.debug("Uninstalling initial content from bundle {}",
                 bundle.getSymbolicName());
             if ( uninstallPaths != null && uninstallPaths.length > 0 ) {
-                for(final String path : uninstallPaths) {
-                    if ( session.itemExists(path) ) {
-                        session.getItem(path).remove();
+                for(String path : uninstallPaths) {
+                    final Session targetSession;
+                    
+                    final int wsSepPos = path.indexOf(":/");
+                    if (wsSepPos != -1) {
+                        final String workspaceName = path.substring(0, wsSepPos);
+                        path = path.substring(wsSepPos + 1);
+                        if (workspaceName.equals(defaultSession.getWorkspace().getName())) {
+                            targetSession = defaultSession;
+                        } else if (createdSessions.containsKey(workspaceName)){
+                            targetSession = createdSessions.get(workspaceName);
+                        } else {
+                            targetSession = createSession(workspaceName);
+                            createdSessions.put(workspaceName, targetSession);
+                        }
+                    } else {
+                        targetSession = defaultSession;
+                    }
+
+                    if ( targetSession.itemExists(path) ) {
+                        targetSession.getItem(path).remove();
                     }
                 }
+                
                 // persist modifications now
-                session.save();
+                defaultSession.save();
+
+                for (Session session : createdSessions.values()) {
+                    session.save();
+                }
             }
 
             log.debug("Done uninstalling initial content from bundle {}",
@@ -682,14 +707,23 @@ public class Loader extends BaseImportLoader {
                 + bundle.getSymbolicName(), re);
         } finally {
             try {
-                if (session.hasPendingChanges()) {
-                    session.refresh(false);
+                if (defaultSession.hasPendingChanges()) {
+                    defaultSession.refresh(false);
+                }
+                for (Session session : createdSessions.values()) {
+                    if (session.hasPendingChanges()) {
+                        session.refresh(false);
+                    }
                 }
             } catch (RepositoryException re) {
                 log.warn(
                     "Failure to rollback uninstaling initial content for bundle {}",
                     bundle.getSymbolicName(), re);
             }
+            
+            for (Session session : createdSessions.values()) {
+                session.logout();
+            }
         }
     }
 

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.