incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r678998 - in /incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal: ContentLoader.java Loader.java
Date Wed, 23 Jul 2008 05:59:49 GMT
Author: cziegeler
Date: Tue Jul 22 22:59:48 2008
New Revision: 678998

URL: http://svn.apache.org/viewvc?rev=678998&view=rev
Log:
SLING-578 : Create intermediate nodes with type sling:Folder
SLING-579 : Allow additional content information for files.

Modified:
    incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoader.java
    incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java

Modified: incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoader.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoader.java?rev=678998&r1=678997&r2=678998&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoader.java
(original)
+++ incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentLoader.java
Tue Jul 22 22:59:48 2008
@@ -60,6 +60,8 @@
 
     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 @@
         this.versionables.clear();
     }
 
+    public void setIgnoreOverwriteFlag(boolean flag) {
+        this.ignoreOverwriteFlag = flag;
+    }
+
     /**
      * Get the created root node.
      */
@@ -172,7 +178,7 @@
         // 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 @@
 
             } else if (primaryNodeType == null) {
 
-                // node explicit node type, use repository default
+                // no explicit node type, use repository default
                 node = parentNode.addNode(name);
 
             } else {

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=678998&r1=678997&r2=678998&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 Jul 22 22:59:48 2008
@@ -313,8 +313,7 @@
             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 @@
                 // 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 @@
             } 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 @@
             }
         }
 
-        return parent.addNode(name, "nt:folder");
+        return parent.addNode(name, "sling:Folder");
     }
 
     /**



Mime
View raw message