incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r961945 - in /sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal: DefaultContentCreator.java Loader.java
Date Thu, 08 Jul 2010 21:22:01 GMT
Author: justin
Date: Thu Jul  8 21:22:00 2010
New Revision: 961945

URL: http://svn.apache.org/viewvc?rev=961945&view=rev
Log:
SLING-1592 - using the ws:/path notation in the uninstall-paths node property.

Modified:
    sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
    sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java

Modified: sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java?rev=961945&r1=961944&r2=961945&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
(original)
+++ sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/DefaultContentCreator.java
Thu Jul  8 21:22:00 2010
@@ -264,9 +264,7 @@ public class DefaultContentCreator imple
 
                 // 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 imple
 
                 // 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 imple
         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 imple
                     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());
                 }

Modified: sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java?rev=961945&r1=961944&r2=961945&view=diff
==============================================================================
--- sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
(original)
+++ sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
Thu Jul  8 21:22:00 2010
@@ -660,19 +660,44 @@ public class Loader extends BaseImportLo
         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 BaseImportLo
                 + 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();
+            }
         }
     }
 



Mime
View raw message