From b947cfc864db6971aa49242d268b41d213f0a75c Mon Sep 17 00:00:00 2001 From: Britt Park Date: Sun, 3 Dec 2006 01:46:46 +0000 Subject: [PATCH] Another CLT plus some tweaks. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4495 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../org/alfresco/repo/avm/clt/AVMCltBase.java | 24 +++ .../org/alfresco/repo/avm/clt/AVMCopyIn.java | 23 +-- .../org/alfresco/repo/avm/clt/AVMCopyOut.java | 145 ++++++++++++++++++ .../repo/avm/clt/AVMSyncServiceClient.java | 1 - 4 files changed, 170 insertions(+), 23 deletions(-) create mode 100644 source/java/org/alfresco/repo/avm/clt/AVMCopyOut.java diff --git a/source/java/org/alfresco/repo/avm/clt/AVMCltBase.java b/source/java/org/alfresco/repo/avm/clt/AVMCltBase.java index c8f70b0daf..d134887c94 100644 --- a/source/java/org/alfresco/repo/avm/clt/AVMCltBase.java +++ b/source/java/org/alfresco/repo/avm/clt/AVMCltBase.java @@ -3,6 +3,9 @@ */ package org.alfresco.repo.avm.clt; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -172,5 +175,26 @@ public abstract class AVMCltBase return ret; } + protected void copyStream(InputStream in, OutputStream out) + { + try + { + byte [] buff = new byte[8192]; + int read = 0; + while ((read = in.read(buff)) != -1) + { + out.write(buff, 0, read); + } + in.close(); + out.close(); + } + catch (IOException e) + { + e.printStackTrace(); + fContext.close(); + System.exit(1); + } + } + protected abstract void run(Map> flags, List args); } diff --git a/source/java/org/alfresco/repo/avm/clt/AVMCopyIn.java b/source/java/org/alfresco/repo/avm/clt/AVMCopyIn.java index 53e7f1fd5e..e3b4a3cbba 100644 --- a/source/java/org/alfresco/repo/avm/clt/AVMCopyIn.java +++ b/source/java/org/alfresco/repo/avm/clt/AVMCopyIn.java @@ -21,7 +21,7 @@ public class AVMCopyIn extends AVMCltBase { private static Object [] flagDefs = { "-r", 0, "-v", 0 }; - private static String USAGE = "usage: [-r] sourcepath nodepath"; + private static String USAGE = "usage: [-r] [-v] sourcepath nodepath"; private boolean fVerbose; @@ -109,27 +109,6 @@ public class AVMCopyIn extends AVMCltBase } } - private void copyStream(InputStream in, OutputStream out) - { - try - { - byte [] buff = new byte[8192]; - int read = 0; - while ((read = in.read(buff)) != -1) - { - out.write(buff, 0, read); - } - in.close(); - out.close(); - } - catch (IOException e) - { - e.printStackTrace(); - fContext.close(); - System.exit(1); - } - } - private void recursiveCopy(String sourcePath, String dest) { File file = new File(sourcePath); diff --git a/source/java/org/alfresco/repo/avm/clt/AVMCopyOut.java b/source/java/org/alfresco/repo/avm/clt/AVMCopyOut.java new file mode 100644 index 0000000000..b6ef4e5704 --- /dev/null +++ b/source/java/org/alfresco/repo/avm/clt/AVMCopyOut.java @@ -0,0 +1,145 @@ +/** + * + */ +package org.alfresco.repo.avm.clt; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.List; +import java.util.Map; + +import org.alfresco.service.cmr.avm.AVMNodeDescriptor; + +/** + * Copy out a file or a directory recursively from the repository + * to a local filesystem. + * @author britt + */ +public class AVMCopyOut extends AVMCltBase +{ + private static Object [] flagDefs = { "-r", 0, "-v", 0 }; + + private static String USAGE = "usage: AVMCopyOut [-r] [-v] nodepath@version fspath"; + + private boolean fVerbose; + + /* (non-Javadoc) + * @see org.alfresco.repo.avm.clt.AVMCltBase#run(java.util.Map, java.util.List) + */ + @Override + protected void run(Map> flags, List args) + { + if (flags.containsKey("-v")) + { + fVerbose = true; + } + else + { + fVerbose = false; + } + String [] versionPath = args.get(0).split("@"); + if (versionPath.length != 2) + { + usage(USAGE); + } + String path = versionPath[0]; + int version = Integer.parseInt(versionPath[1]); + AVMNodeDescriptor desc = fAVMRemote.lookup(version, path); + if (flags.containsKey("-r")) + { + recursiveCopy(version, desc, args.get(1)); + return; + } + if (desc == null) + { + System.err.println(versionPath[0] + " does not exist."); + fContext.close(); + System.exit(1); + } + if (!desc.isFile()) + { + System.err.println(versionPath[0] + " is not a file."); + fContext.close(); + System.exit(1); + } + File dest = new File(args.get(1)); + if (dest.exists()) + { + if (!dest.isDirectory()) + { + System.err.println("Destination must be a directory."); + fContext.close(); + System.exit(1); + } + try + { + InputStream in = fAVMRemote.getFileInputStream(version, path); + String [] parentBase = splitPath(path); + OutputStream out = new FileOutputStream(args.get(1) + File.separator + parentBase[1]); + copyStream(in, out); + } + catch (IOException e) + { + e.printStackTrace(); + fContext.close(); + System.exit(1); + } + } + else + { + try + { + InputStream in = fAVMRemote.getFileInputStream(version, path); + OutputStream out = new FileOutputStream(args.get(1)); + copyStream(in, out); + } + catch (IOException e) + { + e.printStackTrace(); + fContext.close(); + System.exit(1); + } + } + } + + private void recursiveCopy(int version, AVMNodeDescriptor src, String dst) + { + String newDst = dst + File.separator + src.getName(); + if (fVerbose) + { + System.out.println(src.getPath() + " -> " + dst); + } + if (src.isDirectory()) + { + File destFile = new File(newDst); + destFile.mkdir(); + Map listing = fAVMRemote.getDirectoryListing(src); + for (AVMNodeDescriptor child : listing.values()) + { + recursiveCopy(version, child, newDst); + } + return; + } + try + { + InputStream in = fAVMRemote.getFileInputStream(version, src.getPath()); + OutputStream out = new FileOutputStream(newDst); + copyStream(in, out); + } + catch (IOException e) + { + e.printStackTrace(); + fContext.close(); + System.exit(1); + } + } + + public static void main(String[] args) + { + AVMCopyOut me = new AVMCopyOut(); + me.exec(args, flagDefs, 2, USAGE); + } +} diff --git a/source/java/org/alfresco/repo/avm/clt/AVMSyncServiceClient.java b/source/java/org/alfresco/repo/avm/clt/AVMSyncServiceClient.java index 2842ad0166..facd9c5670 100644 --- a/source/java/org/alfresco/repo/avm/clt/AVMSyncServiceClient.java +++ b/source/java/org/alfresco/repo/avm/clt/AVMSyncServiceClient.java @@ -8,7 +8,6 @@ import java.util.List; import org.alfresco.service.cmr.avmsync.AVMDifference; import org.alfresco.service.cmr.avmsync.AVMSyncService; import org.alfresco.service.cmr.avmsync.AVMSyncServiceTransport; -import org.alfresco.service.cmr.security.AuthenticationService; /** * Client side wrapper around the RMI based AVMSyncServiceTransport.