Author: mathwizard
Date: 2008-06-26 17:25:36 -0400 (Thu, 26 Jun 2008)
New Revision: 312
Added:
trunk/sequencers/dna-sequencer-zip/
trunk/sequencers/dna-sequencer-zip/.classpath
trunk/sequencers/dna-sequencer-zip/.project
trunk/sequencers/dna-sequencer-zip/pom.xml
trunk/sequencers/dna-sequencer-zip/src/
trunk/sequencers/dna-sequencer-zip/src/main/
trunk/sequencers/dna-sequencer-zip/src/main/java/
trunk/sequencers/dna-sequencer-zip/src/main/java/org/
trunk/sequencers/dna-sequencer-zip/src/main/java/org/jboss/
trunk/sequencers/dna-sequencer-zip/src/main/java/org/jboss/dna/
trunk/sequencers/dna-sequencer-zip/src/main/java/org/jboss/dna/sequencer/
trunk/sequencers/dna-sequencer-zip/src/main/java/org/jboss/dna/sequencer/zip/
trunk/sequencers/dna-sequencer-zip/src/main/java/org/jboss/dna/sequencer/zip/ZipSequencer.java
trunk/sequencers/dna-sequencer-zip/src/main/resources/
trunk/sequencers/dna-sequencer-zip/src/main/resources/org/
trunk/sequencers/dna-sequencer-zip/src/main/resources/org/jboss/
trunk/sequencers/dna-sequencer-zip/src/main/resources/org/jboss/dna/
trunk/sequencers/dna-sequencer-zip/src/main/resources/org/jboss/dna/sequencer/
trunk/sequencers/dna-sequencer-zip/src/main/resources/org/jboss/dna/sequencer/zip/
trunk/sequencers/dna-sequencer-zip/src/main/resources/org/jboss/dna/sequencer/zip/zip.cnd
trunk/sequencers/dna-sequencer-zip/src/test/
trunk/sequencers/dna-sequencer-zip/src/test/java/
trunk/sequencers/dna-sequencer-zip/src/test/java/org/
trunk/sequencers/dna-sequencer-zip/src/test/java/org/jboss/
trunk/sequencers/dna-sequencer-zip/src/test/java/org/jboss/dna/
trunk/sequencers/dna-sequencer-zip/src/test/java/org/jboss/dna/sequencer/
trunk/sequencers/dna-sequencer-zip/src/test/java/org/jboss/dna/sequencer/zip/
trunk/sequencers/dna-sequencer-zip/src/test/java/org/jboss/dna/sequencer/zip/PropertyClassTest.java
trunk/sequencers/dna-sequencer-zip/src/test/java/org/jboss/dna/sequencer/zip/SequencingOutputTestClass.java
trunk/sequencers/dna-sequencer-zip/src/test/java/org/jboss/dna/sequencer/zip/ZipSequencerTest.java
trunk/sequencers/dna-sequencer-zip/src/test/resources/
trunk/sequencers/dna-sequencer-zip/src/test/resources/testzip.zip
Log:
[DNA:63] Added ZIP file sequencer
Added: trunk/sequencers/dna-sequencer-zip/.classpath
===================================================================
--- trunk/sequencers/dna-sequencer-zip/.classpath (rev 0)
+++ trunk/sequencers/dna-sequencer-zip/.classpath 2008-06-26 21:25:36 UTC (rev 312)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/main/java"/>
+ <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/test-classes"
path="src/test/java"/>
+ <classpathentry kind="src" output="target/test-classes"
path="src/test/resources"/>
+ <classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con"
path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
+ <classpathentry kind="output" path="target/classes"/>
+</classpath>
Added: trunk/sequencers/dna-sequencer-zip/.project
===================================================================
--- trunk/sequencers/dna-sequencer-zip/.project (rev 0)
+++ trunk/sequencers/dna-sequencer-zip/.project 2008-06-26 21:25:36 UTC (rev 312)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>dna-sequencer-zip</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.maven.ide.eclipse.maven2Builder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.maven.ide.eclipse.maven2Nature</nature>
+ </natures>
+</projectDescription>
Added: trunk/sequencers/dna-sequencer-zip/pom.xml
===================================================================
--- trunk/sequencers/dna-sequencer-zip/pom.xml (rev 0)
+++ trunk/sequencers/dna-sequencer-zip/pom.xml 2008-06-26 21:25:36 UTC (rev 312)
@@ -0,0 +1,54 @@
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>dna</artifactId>
+ <groupId>org.jboss.dna</groupId>
+ <version>0.2-SNAPSHOT</version>
+ <relativePath>../..</relativePath>
+ </parent>
+ <!-- The groupId and version values are inherited from parent -->
+ <artifactId>dna-sequencer-zip</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss DNA ZIP Sequencer</name>
+ <description>JBoss DNA Sequencer that processes zip files and extracts content to
repository</description>
+ <
url>http://labs.jboss.org/dna</url>
+ <dependencies>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-common</artifactId>
+ <version>${dna-version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.dna</groupId>
+ <artifactId>dna-spi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit-dep</artifactId>
+ <version>4.4</version>
+ </dependency>
+ <!--
+ Logging (require SLF4J API for compiling, but use Log4J and its SLF4J binding for
testing)
+ -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
Added:
trunk/sequencers/dna-sequencer-zip/src/main/java/org/jboss/dna/sequencer/zip/ZipSequencer.java
===================================================================
---
trunk/sequencers/dna-sequencer-zip/src/main/java/org/jboss/dna/sequencer/zip/ZipSequencer.java
(rev 0)
+++
trunk/sequencers/dna-sequencer-zip/src/main/java/org/jboss/dna/sequencer/zip/ZipSequencer.java 2008-06-26
21:25:36 UTC (rev 312)
@@ -0,0 +1,72 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.jboss.dna.sequencer.zip;
+
+import org.jboss.dna.spi.sequencers.StreamSequencer;
+import org.jboss.dna.spi.sequencers.SequencerOutput;
+import org.jboss.dna.common.monitor.ProgressMonitor;
+
+import java.io.*;
+import java.util.zip.ZipInputStream;
+import java.util.zip.ZipEntry;
+
+/**
+ * @author Michael Trezzi
+ */
+public class ZipSequencer implements StreamSequencer {
+ public void sequence(InputStream stream, SequencerOutput output, ProgressMonitor
progressMonitor) {
+ try {
+ ZipInputStream in = new ZipInputStream(stream);
+ ZipEntry entry = in.getNextEntry();
+ byte[] buf = new byte[1024];
+
+ // Create top-level node
+ output.setProperty("zip:content", "jcr:primaryType",
"zip:content");
+ while (entry != null)
+ {
+
+ if(entry.isDirectory()) { // If entry is directory, create nt:folder
node
+ output.setProperty("zip:content/"+entry.getName(),
"jcr:primaryType", "nt:folder");
+ } else { // If entry is File, create nt:file
+
output.setProperty("zip:content/"+entry.getName()+"/jcr:content",
"jcr:primaryType", "nt:resource" );
+ int n;
+ ByteArrayOutputStream baout = new ByteArrayOutputStream();
+ while ((n = in.read(buf, 0, 1024)) > -1) {
+ baout.write(buf, 0, n);
+ }
+
output.setProperty("zip:content/"+entry.getName()+"/jcr:content",
"jcr:data", baout.toByteArray());
+ // all other nt:file properties should be generated by other
sequencers (mimetype, encoding,...)
+ }
+ in.closeEntry();
+ entry = in.getNextEntry();
+
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+
+ }
+}
Added:
trunk/sequencers/dna-sequencer-zip/src/main/resources/org/jboss/dna/sequencer/zip/zip.cnd
===================================================================
---
trunk/sequencers/dna-sequencer-zip/src/main/resources/org/jboss/dna/sequencer/zip/zip.cnd
(rev 0)
+++
trunk/sequencers/dna-sequencer-zip/src/main/resources/org/jboss/dna/sequencer/zip/zip.cnd 2008-06-26
21:25:36 UTC (rev 312)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+//------------------------------------------------------------------------------
+// N A M E S P A C E S
+//------------------------------------------------------------------------------
+<jcr='http://www.jcp.org/jcr/1.0'>
+<nt='http://www.jcp.org/jcr/nt/1.0'>
+<mix='http://www.jcp.org/jcr/mix/1.0'>
+<zip='http://jboss.org/dna/zip/1.0'>
+
+// ----------------------------------------------------------
+// JCR Pre-defined Mixin Types that are not loaded by default
+// ----------------------------------------------------------
+
+[mix:mimeType] mixin
+ - jcr:mimeType (string)
+ - jcr:encoding (string)
+
+
+//------------------------------------------------------------------------------
+// N O D E T Y P E S
+//------------------------------------------------------------------------------
+
+[zip:content] > nt:unstructured, mix:mimeTyped
+ + * (nt:folder)
+ + * (nt:file)
+
\ No newline at end of file
Added:
trunk/sequencers/dna-sequencer-zip/src/test/java/org/jboss/dna/sequencer/zip/PropertyClassTest.java
===================================================================
---
trunk/sequencers/dna-sequencer-zip/src/test/java/org/jboss/dna/sequencer/zip/PropertyClassTest.java
(rev 0)
+++
trunk/sequencers/dna-sequencer-zip/src/test/java/org/jboss/dna/sequencer/zip/PropertyClassTest.java 2008-06-26
21:25:36 UTC (rev 312)
@@ -0,0 +1,68 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.jboss.dna.sequencer.zip;
+
+import org.junit.Ignore;
+
+/**
+ * @author Michael Trezzi
+ */
+@Ignore
+public class PropertyClassTest {
+ public PropertyClassTest(String path, String name, Object value) {
+ this.path = path;
+ this.name = name;
+ this.value = value;
+ }
+
+ String path;
+ String name;
+ Object value;
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+
+
+
+}
Added:
trunk/sequencers/dna-sequencer-zip/src/test/java/org/jboss/dna/sequencer/zip/SequencingOutputTestClass.java
===================================================================
---
trunk/sequencers/dna-sequencer-zip/src/test/java/org/jboss/dna/sequencer/zip/SequencingOutputTestClass.java
(rev 0)
+++
trunk/sequencers/dna-sequencer-zip/src/test/java/org/jboss/dna/sequencer/zip/SequencingOutputTestClass.java 2008-06-26
21:25:36 UTC (rev 312)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.jboss.dna.sequencer.zip;
+
+import org.jboss.dna.spi.sequencers.SequencerOutput;
+import org.jboss.dna.spi.graph.*;
+import org.junit.Test;
+import org.junit.Ignore;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.ArrayList;
+
+/**
+ * @author Michael Trezzi
+ */
+@Ignore
+public class SequencingOutputTestClass implements SequencerOutput {
+ List<PropertyClassTest> properties = new ArrayList();
+ List<PropertyClassTest> references = new ArrayList();
+
+
+
+ public ValueFactories getFactories() {
+ return null;
+ }
+
+ public NamespaceRegistry getNamespaceRegistry() {
+ return null;
+ }
+
+ public void setProperty(String nodePath, String propertyName, Object... values) {
+ System.out.println("Setting property on '"+nodePath+"'
"+propertyName+":"+values[0]);
+ properties.add(new PropertyClassTest(nodePath,propertyName,values[0]));
+ }
+
+ public void setReference(String nodePath, String propertyName, String... paths) {
+ System.out.println("Setting reference on "+nodePath+"
"+propertyName+":"+paths[0]);
+ references.add(new PropertyClassTest(nodePath,propertyName,paths[0]));
+ }
+
+ public void setProperty(Path nodePath, Name propertyName, Object... values) {
+ System.out.println("Setting property on "+nodePath.getString()+"
"+propertyName.getString()+":"+values[0]);
+ properties.add(new
PropertyClassTest(nodePath.getString(),propertyName.getString(),values[0]));
+ }
+}
Added:
trunk/sequencers/dna-sequencer-zip/src/test/java/org/jboss/dna/sequencer/zip/ZipSequencerTest.java
===================================================================
---
trunk/sequencers/dna-sequencer-zip/src/test/java/org/jboss/dna/sequencer/zip/ZipSequencerTest.java
(rev 0)
+++
trunk/sequencers/dna-sequencer-zip/src/test/java/org/jboss/dna/sequencer/zip/ZipSequencerTest.java 2008-06-26
21:25:36 UTC (rev 312)
@@ -0,0 +1,63 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.jboss.dna.sequencer.zip;
+
+import org.junit.Test;
+import org.junit.After;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertThat;
+
+import java.io.InputStream;
+
+/**
+ * @author Michael Trezzi
+ */
+public class ZipSequencerTest {
+ private InputStream imageStream;
+
+ @After
+ public void afterEach() throws Exception {
+ if (imageStream != null) {
+ try {
+ imageStream.close();
+ } finally {
+ imageStream = null;
+ }
+ }
+ }
+
+ protected InputStream getTestZip( String resourcePath ) {
+ return this.getClass().getResourceAsStream("/" + resourcePath);
+ }
+
+ @Test
+ public void shouldBeAbleToExtractZip() {
+ InputStream is = getTestZip("testzip.zip");
+ ZipSequencer zs = new ZipSequencer();
+ SequencingOutputTestClass seqtest = new SequencingOutputTestClass();
+ zs.sequence(is,seqtest,null);
+
+ assertThat(seqtest.properties.get(2).getPath(), is("zip:content/test
subfolder/test2.txt/jcr:content"));
+ }
+
+}
Added: trunk/sequencers/dna-sequencer-zip/src/test/resources/testzip.zip
===================================================================
(Binary files differ)
Property changes on: trunk/sequencers/dna-sequencer-zip/src/test/resources/testzip.zip
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream