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.4-incubator in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-contentloader.git
commit 63fc0a97e1070dc7192c4ff3beba18d6486cd505 Author: Carsten Ziegeler <[email protected]> AuthorDate: Wed Jul 23 05:59:48 2008 +0000 SLING-578 : Create intermediate nodes with type sling:Folder SLING-579 : Allow additional content information for files. git-svn-id: https://svn.apache.org/repos/asf/incubator/sling/trunk/jcr/contentloader@678998 13f79535-47bb-0310-9956-ffa450edef68 --- .../jcr/contentloader/internal/ContentLoader.java | 10 ++++- .../sling/jcr/contentloader/internal/Loader.java | 46 ++++++++++++++++------ 2 files changed, 43 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoader.java b/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoader.java index 233488f..a9c656a 100644 --- a/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoader.java +++ b/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoader.java @@ -60,6 +60,8 @@ public class ContentLoader implements ContentCreator { private boolean isRootNodeImport; + private boolean ignoreOverwriteFlag = false; + // default content type for createFile() private static final String DEFAULT_CONTENT_TYPE = "application/octet-stream"; @@ -119,6 +121,10 @@ public class ContentLoader implements ContentCreator { this.versionables.clear(); } + public void setIgnoreOverwriteFlag(boolean flag) { + this.ignoreOverwriteFlag = flag; + } + /** * Get the created root node. */ @@ -172,7 +178,7 @@ public class ContentLoader implements ContentCreator { // if we are in root node import mode, we don't create the root top level node! if ( !isRootNodeImport || this.parentNodeStack.size() > 1 ) { // if node already exists but should be overwritten, delete it - if (this.configuration.isOverwrite() && parentNode.hasNode(name)) { + if (!this.ignoreOverwriteFlag && this.configuration.isOverwrite() && parentNode.hasNode(name)) { parentNode.getNode(name).remove(); } @@ -185,7 +191,7 @@ public class ContentLoader implements ContentCreator { } else if (primaryNodeType == null) { - // node explicit node type, use repository default + // no explicit node type, use repository default node = parentNode.addNode(name); } else { 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 96e771e..3d7420c 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 @@ -313,8 +313,7 @@ public class Loader { if (entry.endsWith("/")) { // dir, check for node descriptor , else create dir - String base = entry.substring(0, entry.length() - 1); - String name = getName(base); + final String base = entry.substring(0, entry.length() - 1); URL nodeDescriptor = null; for (String ext : this.contentCreator.getImportProviders().keySet()) { @@ -327,6 +326,7 @@ public class Loader { // if we have a descriptor, which has not been processed yet, // otherwise call createFolder, which creates an nt:folder or // returns an existing node (created by a descriptor) + final String name = getName(base); Node node = null; if (nodeDescriptor != null) { node = processedEntries.get(nodeDescriptor); @@ -347,28 +347,52 @@ public class Loader { } else { // file => create file - URL file = bundle.getEntry(entry); + final URL file = bundle.getEntry(entry); if (processedEntries.containsKey(file)) { // this is a consumed node descriptor continue; } + final String name = getName(entry); + + // file, check for node descriptor , else create dir + URL nodeDescriptor = null; + for (String ext : this.contentCreator.getImportProviders().keySet()) { + nodeDescriptor = bundle.getEntry(entry + ext); + if (nodeDescriptor != null) { + break; + } + } // install if it is a descriptor boolean foundProvider = this.contentCreator.getImportProvider(entry) != null; + Node node = null; if (foundProvider) { - Node node = null; - if ((node = createNode(parent, getName(entry), file, configuration)) != null) { + if ((node = createNode(parent, name, file, configuration)) != null) { processedEntries.put(file, node); - continue; } } // otherwise just place as file - try { - createFile(configuration, parent, file); - } catch (IOException ioe) { - log.warn("Cannot create file node for {}", file, ioe); + if ( node == null ) { + try { + createFile(configuration, parent, file); + node = parent.getNode(name); + } catch (IOException ioe) { + log.warn("Cannot create file node for {}", file, ioe); + } + } + // if we have a descriptor, which has not been processed yet, + // process it + if (nodeDescriptor != null && processedEntries.get(nodeDescriptor) == null ) { + try { + this.contentCreator.setIgnoreOverwriteFlag(true); + node = createNode(parent, name, nodeDescriptor, + configuration); + processedEntries.put(nodeDescriptor, node); + } finally { + this.contentCreator.setIgnoreOverwriteFlag(false); + } } } } @@ -463,7 +487,7 @@ public class Loader { } } - return parent.addNode(name, "nt:folder"); + return parent.addNode(name, "sling:Folder"); } /** -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
