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:46:04 UTC

[sling-org-apache-sling-jcr-contentloader] 11/32: SLING-453: Initial content loading to target location https://issues.apache.org/jira/browse/SLING-453

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.0.2-incubator
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-contentloader.git

commit 55e57718ba318c1172ec8776c9cefd24f7b860cb
Author: Juan Vazquez <jv...@apache.org>
AuthorDate: Tue May 20 10:29:07 2008 +0000

    SLING-453: Initial content loading to target location
    https://issues.apache.org/jira/browse/SLING-453
    
    git-svn-id: https://svn.apache.org/repos/asf/incubator/sling/trunk/jcr/contentloader@658192 13f79535-47bb-0310-9956-ffa450edef68
---
 .../sling/jcr/contentloader/internal/Loader.java   | 27 ++++++++++++++++---
 .../jcr/contentloader/internal/PathEntry.java      | 30 +++++++++++++++++-----
 2 files changed, 47 insertions(+), 10 deletions(-)

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 0f287cf..6dd1cb0 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
@@ -208,7 +208,9 @@ public class Loader {
             while (pathIter.hasNext() ) {
                 final PathEntry entry = pathIter.next();
                 if ( !contentAlreadyLoaded || entry.isOverwrite() ) {
-                    this.installFromPath(bundle, entry.getPath(), entry.isOverwrite(), session.getRootNode());
+                	Node targetNode = this.getTargetNode(session, entry.getTarget());
+                	if (targetNode != null)
+                		this.installFromPath(bundle, entry.getPath(), entry.isOverwrite(), targetNode);
                 }
             }
 
@@ -656,6 +658,23 @@ public class Loader {
         Item item = session.getItem(path);
         return (item.isNode()) ? (Node) item : null;
     }
+    
+    private Node getTargetNode(Session session, String path)
+    		throws RepositoryException {
+    	
+    	// not specyfied path directive
+    	if (path == null)
+    		return session.getRootNode();
+    	
+    	int firstSlash = path.indexOf("/");
+    	
+    	// it´s a relative path
+    	if (firstSlash != 0)
+    		path = "/" + path;
+    	
+    	Item item = session.getItem(path);
+    	return (item.isNode()) ? (Node) item : null;
+    }
 
     private void uninstallContent(final Session session, final Bundle bundle, final Iterator<PathEntry> pathIter) {
         try {
@@ -664,9 +683,11 @@ public class Loader {
             while (pathIter.hasNext() ) {
                 final PathEntry entry = pathIter.next();
                 if ( entry.isUninstall() ) {
-                    this.uninstallFromPath(bundle, entry.getPath(), session.getRootNode());
+                	Node targetNode = this.getTargetNode(session, entry.getTarget());
+                	if (targetNode != null)
+                		this.uninstallFromPath(bundle, entry.getPath(), targetNode);
                 } else {
-                    log.debug("Ignoring to uninstall content at {}, overwrite flag is not set.", entry.getPath());
+                    log.debug("Ignoring to uninstall content at {}, uninstall directive is not set.", entry.getPath());
                 }
             }
 
diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java b/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java
index c85a0b2..6369bc4 100644
--- a/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java
+++ b/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java
@@ -33,11 +33,14 @@ public class PathEntry {
     /** The manifest header to specify initial content to be loaded. */
     public static final String CONTENT_HEADER = "Sling-Initial-Content";
 
-    /** The overwrite flag specifying if content should be overwritten or just initially added. */
-    public static final String OVERWRITE_FLAG = "overwrite";
+    /** The overwrite directive specifying if content should be overwritten or just initially added. */
+    public static final String OVERWRITE_DIRECTIVE = "overwrite";
 
-    /** The uninstall flag specifying if content should be uninstalled. */
-    public static final String UNINSTALL_FLAG = "uninstall";
+    /** The uninstall directive specifying if content should be uninstalled. */
+    public static final String UNINSTALL_DIRECTIVE = "uninstall";
+    
+    /** The path directive specifying the target node where initial content will be loaded. */
+    public static final String PATH_DIRECTIVE = "path";
 
     /** The path for the initial content. */
     private final String path;
@@ -47,6 +50,9 @@ public class PathEntry {
 
     /** Should existing content be uninstalled? */
     private final boolean uninstall;
+    
+    /** Target path where initial content will be loaded. If it´s null then target node is the root node */
+    private final String target;
 
     public static Iterator<PathEntry> getContentPaths(final Bundle bundle) {
         final List<PathEntry> entries = new ArrayList<PathEntry>();
@@ -66,9 +72,10 @@ public class PathEntry {
     }
 
     public PathEntry(ManifestHeader.Entry entry) {
-        // check for overwrite and uninstall flag
-        final String overwriteValue = entry.getDirectiveValue(OVERWRITE_FLAG);
-        final String uninstallValue = entry.getDirectiveValue(UNINSTALL_FLAG);
+        // check for directives
+        final String overwriteValue = entry.getDirectiveValue(OVERWRITE_DIRECTIVE);
+        final String uninstallValue = entry.getDirectiveValue(UNINSTALL_DIRECTIVE);
+        final String pathValue = entry.getDirectiveValue(PATH_DIRECTIVE);
         boolean overwriteFlag = false;
         if ( overwriteValue != null ) {
             overwriteFlag = Boolean.valueOf(overwriteValue).booleanValue();
@@ -80,6 +87,11 @@ public class PathEntry {
         } else {
             this.uninstall = this.overwrite;
         }
+        if ( pathValue != null ) {
+        	this.target = pathValue;
+        } else {
+        	this.target = null;
+        }
     }
 
     public String getPath() {
@@ -93,4 +105,8 @@ public class PathEntry {
     public boolean isUninstall() {
         return this.uninstall;
     }
+
+	public String getTarget() {
+		return target;
+	}
 }

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