Author: jvazquez
Date: Tue May 20 03:29:07 2008
New Revision: 658192
URL: http://svn.apache.org/viewvc?rev=658192&view=rev
Log:
SLING-453: Initial content loading to target location
https://issues.apache.org/jira/browse/SLING-453
Modified:
incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java
Modified:
incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java?rev=658192&r1=658191&r2=658192&view=diff
==============================================================================
---
incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
(original)
+++
incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
Tue May 20 03:29:07 2008
@@ -208,7 +208,9 @@
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 @@
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 @@
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());
}
}
Modified:
incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java
URL:
http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java?rev=658192&r1=658191&r2=658192&view=diff
==============================================================================
---
incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java
(original)
+++
incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/PathEntry.java
Tue May 20 03:29:07 2008
@@ -33,11 +33,14 @@
/** 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 @@
/** 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 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 @@
} else {
this.uninstall = this.overwrite;
}
+ if ( pathValue != null ) {
+ this.target = pathValue;
+ } else {
+ this.target = null;
+ }
}
public String getPath() {
@@ -93,4 +105,8 @@
public boolean isUninstall() {
return this.uninstall;
}
+
+ public String getTarget() {
+ return target;
+ }
}