Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added NodeExporter to export only the content of a primary artifact when a flag is set in the ExportOptions #91

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems on the wrong API level, a node is not really a package. Can you work with the DocViewSAXFormatter and DocViewSAXImporter directly? Maybe we should just export that as API...


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 {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;