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 24de4c8b799022f30edf65780ac48a96fde5db49 Author: Carsten Ziegeler <[email protected]> AuthorDate: Mon Jun 23 15:16:33 2008 +0000 SLING-548: Initial version to extract zips and jars into the repository. git-svn-id: https://svn.apache.org/repos/asf/incubator/sling/trunk/jcr/contentloader@670650 13f79535-47bb-0310-9956-ffa450edef68 --- pom.xml | 4 ++++ .../jcr/contentloader/internal/ContentCreator.java | 7 ++----- .../jcr/contentloader/internal/ContentLoader.java | 21 +++++++++++++------- .../sling/jcr/contentloader/internal/Loader.java | 2 ++ .../jcr/contentloader/internal/ZipReader.java | 23 +++++++++++++++++++++- 5 files changed, 44 insertions(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 7da5dc6..3d20da2 100644 --- a/pom.xml +++ b/pom.xml @@ -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> diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentCreator.java b/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentCreator.java index 3e9acaf..86b2476 100644 --- a/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentCreator.java +++ b/src/main/java/org/apache/sling/jcr/contentloader/internal/ContentCreator.java @@ -20,7 +20,6 @@ package org.apache.sling.jcr.contentloader.internal; import java.io.InputStream; -import javax.jcr.Node; import javax.jcr.RepositoryException; /** @@ -41,7 +40,7 @@ interface ContentCreator { * @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 @@ interface ContentCreator { /** * 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, {@link #finishNode()} * must be callsed. * @param subPath The relative path 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 fe2e544..bb1827e 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 @@ -84,14 +84,23 @@ public class ContentLoader implements ContentCreator { 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 @@ public class ContentLoader implements ContentCreator { /** * @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 @@ public class ContentLoader implements ContentCreator { if ( this.rootNode == null ) { this.rootNode = node; } - return node; } - return null; } /** @@ -393,6 +400,8 @@ public class ContentLoader implements ContentCreator { 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 class ContentLoader implements ContentCreator { */ 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 @@ public class ContentLoader implements ContentCreator { if ( newNodeType == null ) { return false; } - node = node.addNode(token, newNodeType); + node.addNode(token, newNodeType); } + node = node.getNode(token); } this.parentNodeStack.push(node); return true; 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 fd55242..ac58191 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 @@ -80,6 +80,8 @@ public class Loader { 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() { diff --git a/src/main/java/org/apache/sling/jcr/contentloader/internal/ZipReader.java b/src/main/java/org/apache/sling/jcr/contentloader/internal/ZipReader.java index 176c9bb..70e661c 100644 --- a/src/main/java/org/apache/sling/jcr/contentloader/internal/ZipReader.java +++ b/src/main/java/org/apache/sling/jcr/contentloader/internal/ZipReader.java @@ -25,6 +25,8 @@ import java.util.zip.ZipInputStream; import javax.jcr.RepositoryException; +import org.apache.commons.io.input.CloseShieldInputStream; + /** * The <code>JsonReader</code> TODO @@ -60,17 +62,36 @@ class ZipReader implements ContentReader { 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(); } } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
