diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/NodeExporter.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/NodeExporter.java new file mode 100644 index 000000000..4eb8d4895 --- /dev/null +++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/NodeExporter.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.jackrabbit.vault.fs.io; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import javax.jcr.Node; +import javax.jcr.RepositoryException; + +import org.apache.commons.io.IOUtils; +import org.apache.jackrabbit.vault.fs.api.Artifact; +import org.apache.jackrabbit.vault.fs.api.ArtifactType; +import org.apache.jackrabbit.vault.fs.api.VaultFile; + +public class NodeExporter extends AbstractExporter { + + private OutputStream out; + + /** + * Constructs a new node exporter that writes to the output stream. + * + * @param out the output stream + */ + public NodeExporter(OutputStream out) { + this.out = out; + } + + public void writeFile(VaultFile file, String relPath) + throws RepositoryException, IOException { + Artifact a = file.getArtifact(); + if (a.getType() == ArtifactType.PRIMARY) { + track("A", relPath); + exportInfo.update(ExportInfo.Type.ADD, relPath); + switch (a.getPreferredAccess()) { + case NONE: + throw new RepositoryException("Artifact has no content."); + + case SPOOL: + a.spool(out); + break; + + case STREAM: + try (InputStream in = a.getInputSource().getByteStream()) { + IOUtils.copy(in, out); + } + break; + } + } + } + + //----------------------- empty implementations ------------------------------------------------------------ + + @Override + public void writeFile(InputStream in, String relPath) throws IOException {} + + @Override + public void open() throws IOException, RepositoryException {} + + @Override + public void close() throws IOException, RepositoryException {} + + @Override + public void createDirectory(String relPath) throws IOException {} + + @Override + public void createDirectory(VaultFile file, String relPath) throws RepositoryException, IOException {} +} diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/package-info.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/package-info.java index 2145118c7..174279729 100644 --- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/package-info.java +++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/io/package-info.java @@ -15,7 +15,7 @@ * limitations under the License. */ -@Version("2.9.1") +@Version("2.10.0") package org.apache.jackrabbit.vault.fs.io; import org.osgi.annotation.versioning.Version; diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/ExportOptions.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/ExportOptions.java index 34bc2115e..362d87258 100644 --- a/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/ExportOptions.java +++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/ExportOptions.java @@ -39,6 +39,16 @@ public class ExportOptions { private int compressionLevel = Deflater.DEFAULT_COMPRESSION; + private boolean nodeOnly; + + public boolean isNodeOnly() { + return nodeOnly; + } + + public void setNodeOnly(boolean nodeOnly) { + this.nodeOnly = nodeOnly; + } + /** * Returns the progress tracker listener. * @return the progress tracker listener. diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/PackageManagerImpl.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/PackageManagerImpl.java index a9c0c57b6..dd7b0d8cb 100644 --- a/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/PackageManagerImpl.java +++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/impl/PackageManagerImpl.java @@ -41,8 +41,10 @@ import org.apache.jackrabbit.vault.fs.config.DefaultMetaInf; import org.apache.jackrabbit.vault.fs.config.MetaInf; import org.apache.jackrabbit.vault.fs.impl.AggregateManagerImpl; +import org.apache.jackrabbit.vault.fs.io.AbstractExporter; import org.apache.jackrabbit.vault.fs.io.Archive; import org.apache.jackrabbit.vault.fs.io.JarExporter; +import org.apache.jackrabbit.vault.fs.io.NodeExporter; import org.apache.jackrabbit.vault.fs.spi.ProgressTracker; import org.apache.jackrabbit.vault.packaging.ExportOptions; import org.apache.jackrabbit.vault.packaging.PackageId; @@ -154,7 +156,7 @@ public void assemble(Session s, ExportOptions opts, OutputStream out) } VaultFileSystem jcrfs = Mounter.mount(config, metaInf.getFilter(), addr, opts.getRootPath(), s); - JarExporter exporter = new JarExporter(out, opts.getCompressionLevel()); + AbstractExporter exporter = opts.isNodeOnly() ? new NodeExporter(out) : new JarExporter(out, opts.getCompressionLevel()); exporter.setProperties(metaInf.getProperties()); if (opts.getListener() != null) { exporter.setVerbose(opts.getListener()); diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/package-info.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/package-info.java index ef85b433a..68b470052 100644 --- a/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/package-info.java +++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/packaging/package-info.java @@ -15,7 +15,7 @@ * limitations under the License. */ -@Version("2.10.0") +@Version("2.11.0") package org.apache.jackrabbit.vault.packaging; import org.osgi.annotation.versioning.Version;