Author: cziegeler
Date: Mon Jun 23 08:16:33 2008
New Revision: 670650

URL: http://svn.apache.org/viewvc?rev=670650&view=rev
Log:
SLING-548: Initial version to extract zips and jars into the repository.

Modified:
    incubator/sling/trunk/jcr/contentloader/pom.xml
    
incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentCreator.java
    
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
    
incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ZipReader.java

Modified: incubator/sling/trunk/jcr/contentloader/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/contentloader/pom.xml?rev=670650&r1=670649&r2=670650&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/contentloader/pom.xml (original)
+++ incubator/sling/trunk/jcr/contentloader/pom.xml Mon Jun 23 08:16:33 2008
@@ -123,6 +123,10 @@
             <artifactId>kxml2</artifactId>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>commons-io</groupId>
+            <artifactId>commons-io</artifactId>
+        </dependency>
     <!-- Testing -->        
         <dependency>
             <groupId>junit</groupId>

Modified: 
incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentCreator.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentCreator.java?rev=670650&r1=670649&r2=670650&view=diff
==============================================================================
--- 
incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentCreator.java
 (original)
+++ 
incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentCreator.java
 Mon Jun 23 08:16:33 2008
@@ -20,7 +20,6 @@
 
 import java.io.InputStream;
 
-import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 
 /**
@@ -41,7 +40,7 @@
      * @param mixinNodeTypes The mixin node types or null.
      * @throws RepositoryException If anything goes wrong.
      */
-    Node createNode(String name,
+    void createNode(String name,
                     String primaryNodeType,
                     String[] mixinNodeTypes)
     throws RepositoryException;
@@ -118,13 +117,11 @@
 
     /**
      * Switch the current node to the path (which must be relative
-     * to the root node of the import).
+     * to the current node).
      * If the path does not exist and a node type is supplied,
      * the nodes are created with the given node type.
      * If the path does not exist and node type is null, false is
      * returned.
-     * Switching is only allowed if the current node is the root node
-     * of the import.
      * When the changes to the node are finished, [EMAIL PROTECTED] 
#finishNode()}
      * must be callsed.
      * @param subPath The relative path

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=670650&r1=670649&r2=670650&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
 Mon Jun 23 08:16:33 2008
@@ -84,14 +84,23 @@
         isRootNodeImport = defaultRootName == null;
     }
 
+    /**
+     * Get the list of versionable nodes.
+     */
     public List<Node> getVersionables() {
         return this.versionables;
     }
 
+    /**
+     * Clear the content loader.
+     */
     public void clear() {
         this.versionables.clear();
     }
 
+    /**
+     * Get the created root node.
+     */
     public Node getRootNode() {
         return this.rootNode;
     }
@@ -100,7 +109,7 @@
     /**
      * @see 
org.apache.sling.jcr.contentloader.internal.ContentCreator#createNode(java.lang.String,
 java.lang.String, java.lang.String[])
      */
-    public Node createNode(String name,
+    public void createNode(String name,
                            String primaryNodeType,
                            String[] mixinNodeTypes)
     throws RepositoryException {
@@ -157,9 +166,7 @@
             if ( this.rootNode == null ) {
                 this.rootNode = node;
             }
-            return node;
         }
-        return null;
     }
 
     /**
@@ -393,6 +400,8 @@
         if (this.configuration.isOverwrite() && parentNode.hasNode(name)) {
             parentNode.getNode(name).remove();
         } else if (parentNode.hasNode(name)) {
+            this.parentNodeStack.push(parentNode.getNode(name));
+            
this.parentNodeStack.push(parentNode.getNode(name).getNode("jcr:content"));
             return;
         }
 
@@ -424,9 +433,6 @@
      */
     public boolean switchCurrentNode(String subPath, String newNodeType)
     throws RepositoryException {
-        if ( this.parentNodeStack.size() > 1 ) {
-            throw new RepositoryException("Switching the current node is not 
allowed.");
-        }
         if ( subPath.startsWith("/") ) {
             subPath = subPath.substring(1);
         }
@@ -438,8 +444,9 @@
                 if ( newNodeType == null ) {
                     return false;
                 }
-                node = node.addNode(token, newNodeType);
+                node.addNode(token, newNodeType);
             }
+            node = node.getNode(token);
         }
         this.parentNodeStack.push(node);
         return true;

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=670650&r1=670649&r2=670650&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
 Mon Jun 23 08:16:33 2008
@@ -80,6 +80,8 @@
         importProviders.put(EXT_JCR_XML, null);
         importProviders.put(EXT_JSON, JsonReader.PROVIDER);
         importProviders.put(EXT_XML, XmlReader.PROVIDER);
+        importProviders.put(".jar", ZipReader.JAR_PROVIDER);
+        importProviders.put(".zip", ZipReader.ZIP_PROVIDER);
     }
 
     public void dispose() {

Modified: 
incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ZipReader.java
URL: 
http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ZipReader.java?rev=670650&r1=670649&r2=670650&view=diff
==============================================================================
--- 
incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ZipReader.java
 (original)
+++ 
incubator/sling/trunk/jcr/contentloader/src/main/java/org/apache/sling/jcr/contentloader/internal/ZipReader.java
 Mon Jun 23 08:16:33 2008
@@ -25,6 +25,8 @@
 
 import javax.jcr.RepositoryException;
 
+import org.apache.commons.io.input.CloseShieldInputStream;
+
 
 /**
  * The <code>JsonReader</code> TODO
@@ -60,17 +62,36 @@
         this.jarReader = jarReader;
     }
 
+    /**
+     * @see 
org.apache.sling.jcr.contentloader.internal.ContentReader#parse(java.io.InputStream,
 org.apache.sling.jcr.contentloader.internal.ContentCreator)
+     */
     public void parse(InputStream ins, ContentCreator creator)
     throws IOException, RepositoryException {
+        creator.createNode(null, "nt:folder", null);
         final ZipInputStream zis = new ZipInputStream(ins);
+        final InputStream dataIS = new CloseShieldInputStream(zis);
         ZipEntry entry;
         do {
             entry = zis.getNextEntry();
             if ( entry != null ) {
-                entry.getName();
+                if ( !entry.isDirectory() ) {
+                    String name = entry.getName();
+                    int pos = name.lastIndexOf('/');
+                    if ( pos != -1 ) {
+                        creator.switchCurrentNode(name.substring(0, pos), 
"nt:folder");
+                    }
+                    creator.createFileAndResourceNode(name, dataIS, null, 
entry.getTime());
+                    creator.finishNode();
+                    creator.finishNode();
+                    if ( pos != -1 ) {
+                        creator.finishNode();
+                    }
+                }
+                zis.closeEntry();
             }
 
         } while ( entry != null );
+        creator.finishNode();
     }
 
 }


Reply via email to