incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r889584 - /sling/trunk/bundles/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/Loader.java
Date Fri, 11 Dec 2009 12:12:01 GMT
Author: cziegeler
Date: Fri Dec 11 12:12:00 2009
New Revision: 889584

URL: http://svn.apache.org/viewvc?rev=889584&view=rev
Log:
SLING-694 :  Initial Content does not load initial content from a file 

Modified:
    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/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=889584&r1=889583&r2=889584&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
Fri Dec 11 12:12:00 2009
@@ -336,17 +336,30 @@
                                  final Node parent,
                                  final List<String> createdNodes)
     throws RepositoryException {
+        //  init content creator
+        this.contentCreator.init(configuration, this.defaultImportProviders, createdNodes);
+
+        final Map<URL, Node> processedEntries = new HashMap<URL, Node>();
 
         @SuppressWarnings("unchecked")
         Enumeration<String> entries = bundle.getEntryPaths(path);
         if (entries == null) {
-            log.info("install: No initial content entries at {}", path);
+            // check for single content
+            final URL u = bundle.getEntry(path);
+            if ( u == null ) {
+                log.info("install: No initial content entries at {} in bundle {}", path,
bundle.getSymbolicName());
+                return;
+            }
+            // we have a single file content, let's check if this has an import provider
extension
+            for (String ext : this.contentCreator.getImportProviders().keySet()) {
+                if ( path.endsWith(ext) ) {
+
+                }
+            }
+            handleFile(path, bundle, processedEntries, configuration, parent, createdNodes);
             return;
         }
-        //  init content creator
-        this.contentCreator.init(configuration, this.defaultImportProviders, createdNodes);
 
-        final Map<URL, Node> processedEntries = new HashMap<URL, Node>();
         // potential root node import/extension
         URL rootNodeDescriptor = importRootNode(parent.getSession(), bundle, path);
         if (rootNodeDescriptor != null) {
@@ -356,7 +369,7 @@
 
         while (entries.hasMoreElements()) {
             final String entry = entries.nextElement();
-            log.debug("Processing initial content entry {}", entry);
+            log.debug("Processing initial content entry {} in bundle {}", entry, bundle.getSymbolicName());
             if (entry.endsWith("/")) {
 
                 // dir, check for node descriptor , else create dir
@@ -392,55 +405,76 @@
                 }
 
             } else {
-
                 // file => create file
-                final URL file = bundle.getEntry(entry);
-                if (processedEntries.containsKey(file)) {
-                    // this is a consumed node descriptor
-                    continue;
-                }
-                final String name = getName(entry);
+                handleFile(entry, bundle, processedEntries, configuration, parent, createdNodes);
+            }
+        }
+    }
 
-                // 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;
-                    }
-                }
+    /**
+     * Handle a file entry.
+     * @param entry
+     * @param file   The url to the content file.
+     * @param bundle
+     * @param processedEntries
+     * @param configuration
+     * @param parent
+     * @param createdNodes
+     * @throws RepositoryException
+     */
+    private void handleFile(final String entry,
+                            final Bundle bundle,
+                            final Map<URL, Node> processedEntries,
+                            final PathEntry configuration,
+                            final Node parent,
+                            final List<String> createdNodes)
+    throws RepositoryException {
+        final URL file = bundle.getEntry(entry);
+        final String name = getName(entry);
 
-                // install if it is a descriptor
-                boolean foundProvider = this.contentCreator.getImportProvider(entry) != null;
+        if (processedEntries.containsKey(file)) {
+            // this is a consumed node descriptor
+            return;
+        }
 
-                Node node = null;
-                if (foundProvider) {
-                    if ((node = createNode(parent, name, file, configuration)) != null) {
-                        processedEntries.put(file, node);
-                    }
-                }
+        // check for node descriptor
+        URL nodeDescriptor = null;
+        for (String ext : this.contentCreator.getImportProviders().keySet()) {
+            nodeDescriptor = bundle.getEntry(entry + ext);
+            if (nodeDescriptor != null) {
+                break;
+            }
+        }
 
-                // otherwise just place as file
-                if ( node == null ) {
-                    try {
-                        createFile(configuration, parent, file, createdNodes);
-                        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);
-                    }
-                }
+        // install if it is a descriptor
+        boolean foundProvider = this.contentCreator.getImportProvider(entry) != null;
+
+        Node node = null;
+        if (foundProvider) {
+            if ((node = createNode(parent, name, file, configuration)) != null) {
+                processedEntries.put(file, node);
+            }
+        }
+
+        // otherwise just place as file
+        if ( node == null ) {
+            try {
+                createFile(configuration, parent, file, createdNodes);
+                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);
             }
         }
     }
@@ -545,7 +579,7 @@
     }
 
     /**
-     * Gets and decods the name part of the <code>path</code>. The name is
+     * Gets and decodes the name part of the <code>path</code>. The name is
      * the part of the path after the last slash (or the complete path if no
      * slash is contained). To support names containing unsupported characters
      * such as colon (<code>:</code>), names may be URL encoded (see



Mime
View raw message