mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Moved a bunch of things to more logical locations.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4497 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
156
source/java/org/alfresco/repo/clt/AVMCopyIn.java
Normal file
156
source/java/org/alfresco/repo/clt/AVMCopyIn.java
Normal file
@@ -0,0 +1,156 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.alfresco.repo.clt;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Like cp from a local filesystem to AVM.
|
||||
* @author britt
|
||||
*/
|
||||
public class AVMCopyIn extends CltBase
|
||||
{
|
||||
private static Object [] flagDefs = { "-r", 0, "-v", 0 };
|
||||
|
||||
private static String USAGE = "usage: [-r] [-v] sourcepath nodepath";
|
||||
|
||||
private boolean fVerbose;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.clt.AVMCltBase#run(java.util.Map, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
protected void run(Map<String, List<String>> flags, List<String> args)
|
||||
{
|
||||
if (flags.containsKey("-v"))
|
||||
{
|
||||
fVerbose = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
fVerbose = false;
|
||||
}
|
||||
if (flags.containsKey("-r"))
|
||||
{
|
||||
recursiveCopy(args.get(0), args.get(1));
|
||||
return;
|
||||
}
|
||||
File file = new File(args.get(0));
|
||||
if (!file.isFile())
|
||||
{
|
||||
System.err.println(args.get(0) + " not found, or not a file.");
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
AVMNodeDescriptor desc = fAVMRemote.lookup(-1, args.get(1));
|
||||
if (desc == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
String [] pathBase = splitPath(args.get(1));
|
||||
if (pathBase.length == 1)
|
||||
{
|
||||
System.err.println(args.get(1) + " is a root path.");
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
if (fVerbose)
|
||||
{
|
||||
System.out.println(file.getName() + " -> " + pathBase[0]);
|
||||
}
|
||||
InputStream in =
|
||||
new FileInputStream(file);
|
||||
OutputStream out = fAVMRemote.createFile(pathBase[0], pathBase[1]);
|
||||
|
||||
copyStream(in, out);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!desc.isDirectory())
|
||||
{
|
||||
System.err.println("Target must be a directory.");
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
try
|
||||
{
|
||||
if (fVerbose)
|
||||
{
|
||||
System.out.println(file.getName() + " -> " + args.get(1));
|
||||
}
|
||||
InputStream in =
|
||||
new FileInputStream(file);
|
||||
OutputStream out =
|
||||
fAVMRemote.createFile(args.get(1), file.getName());
|
||||
copyStream(in, out);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void recursiveCopy(String sourcePath, String dest)
|
||||
{
|
||||
File file = new File(sourcePath);
|
||||
if (fVerbose)
|
||||
{
|
||||
System.out.println(sourcePath + " -> " + dest);
|
||||
}
|
||||
if (file.isDirectory())
|
||||
{
|
||||
fAVMRemote.createDirectory(dest, file.getName());
|
||||
String newDest = dest + '/' + file.getName();
|
||||
String [] names = file.list();
|
||||
for (String name : names)
|
||||
{
|
||||
recursiveCopy(sourcePath + File.separatorChar + name,
|
||||
newDest);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
InputStream in =
|
||||
new FileInputStream(file);
|
||||
OutputStream out = fAVMRemote.createFile(dest, file.getName());
|
||||
copyStream(in, out);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
AVMCopyIn me = new AVMCopyIn();
|
||||
me.exec(args, flagDefs, 2, USAGE);
|
||||
}
|
||||
}
|
145
source/java/org/alfresco/repo/clt/AVMCopyOut.java
Normal file
145
source/java/org/alfresco/repo/clt/AVMCopyOut.java
Normal file
@@ -0,0 +1,145 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.alfresco.repo.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 CltBase
|
||||
{
|
||||
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<String, List<String>> flags, List<String> 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(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(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<String, AVMNodeDescriptor> listing = fAVMRemote.getDirectoryListing(src);
|
||||
for (AVMNodeDescriptor child : listing.values())
|
||||
{
|
||||
recursiveCopy(child, newDst);
|
||||
}
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
InputStream in = fAVMRemote.getFileInputStream(src);
|
||||
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);
|
||||
}
|
||||
}
|
77
source/java/org/alfresco/repo/clt/AVMLs.java
Normal file
77
source/java/org/alfresco/repo/clt/AVMLs.java
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.alfresco.repo.clt;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
|
||||
|
||||
/**
|
||||
* Get a listing of a node.
|
||||
* @author britt
|
||||
*/
|
||||
public class AVMLs extends CltBase
|
||||
{
|
||||
private static Object [] flagDefs = { "-R", 0 };
|
||||
|
||||
private static String USAGE = "usage: AVMLs [-R] nodepath";
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.clt.AVMCltBase#run(java.util.Map, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
protected void run(Map<String, List<String>> flags, List<String> args)
|
||||
{
|
||||
String[] pathVersion = args.get(0).split("@");
|
||||
AVMNodeDescriptor desc = fAVMRemote.lookup(Integer.parseInt(pathVersion[1]),
|
||||
pathVersion[0]);
|
||||
if (flags.containsKey("-R"))
|
||||
{
|
||||
recursiveList(desc, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
list(desc);
|
||||
}
|
||||
}
|
||||
|
||||
private void list(AVMNodeDescriptor desc)
|
||||
{
|
||||
if (desc.isFile())
|
||||
{
|
||||
System.out.println(desc.getName() + '\t' + desc);
|
||||
return;
|
||||
}
|
||||
Map<String, AVMNodeDescriptor> listing = fAVMRemote.getDirectoryListing(desc);
|
||||
for (Map.Entry<String, AVMNodeDescriptor> entry : listing.entrySet())
|
||||
{
|
||||
System.out.println(entry.getKey() + '\t' + entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
private void recursiveList(AVMNodeDescriptor desc, int indent)
|
||||
{
|
||||
for (int i = 0; i < indent; i++)
|
||||
{
|
||||
System.out.print(' ');
|
||||
}
|
||||
System.out.println(desc.getName() + '\t' + desc);
|
||||
if (desc.isDirectory())
|
||||
{
|
||||
indent += 2;
|
||||
Map<String, AVMNodeDescriptor> listing = fAVMRemote.getDirectoryListing(desc);
|
||||
for (Map.Entry<String, AVMNodeDescriptor> entry : listing.entrySet())
|
||||
{
|
||||
recursiveList(entry.getValue(), indent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
AVMLs me = new AVMLs();
|
||||
me.exec(args, flagDefs, 1, USAGE);
|
||||
}
|
||||
}
|
39
source/java/org/alfresco/repo/clt/AVMLsStores.java
Normal file
39
source/java/org/alfresco/repo/clt/AVMLsStores.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.alfresco.repo.clt;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.avm.AVMStoreDescriptor;
|
||||
|
||||
/**
|
||||
* List all avm stores in the repository.
|
||||
* @author britt
|
||||
*/
|
||||
public class AVMLsStores extends CltBase
|
||||
{
|
||||
private static Object[] flagDefs = { };
|
||||
|
||||
private static String USAGE = "usage: AVMLsStores";
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.clt.AVMCltBase#run(java.util.Map, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
protected void run(Map<String, List<String>> flags, List<String> args)
|
||||
{
|
||||
List<AVMStoreDescriptor> stores = fAVMRemote.getAVMStores();
|
||||
for (AVMStoreDescriptor store : stores)
|
||||
{
|
||||
System.out.println(store);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
AVMLsStores me = new AVMLsStores();
|
||||
me.exec(args, flagDefs, 0, USAGE);
|
||||
}
|
||||
}
|
39
source/java/org/alfresco/repo/clt/AVMLsVersions.java
Normal file
39
source/java/org/alfresco/repo/clt/AVMLsVersions.java
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.alfresco.repo.clt;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.avm.VersionDescriptor;
|
||||
|
||||
/**
|
||||
* List all versions of a given store.
|
||||
* @author britt
|
||||
*/
|
||||
public class AVMLsVersions extends CltBase
|
||||
{
|
||||
private static Object [] flagDefs = { };
|
||||
|
||||
private static String USAGE = "usage: AVMLsVersion storename";
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.clt.AVMCltBase#run(java.util.Map, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
protected void run(Map<String, List<String>> flags, List<String> args)
|
||||
{
|
||||
List<VersionDescriptor> versions = fAVMRemote.getAVMStoreVersions(args.get(0));
|
||||
for (VersionDescriptor version : versions)
|
||||
{
|
||||
System.out.println(version);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
AVMLsVersions me = new AVMLsVersions();
|
||||
me.exec(args, flagDefs, 1, USAGE);
|
||||
}
|
||||
}
|
68
source/java/org/alfresco/repo/clt/AVMMkDir.java
Normal file
68
source/java/org/alfresco/repo/clt/AVMMkDir.java
Normal file
@@ -0,0 +1,68 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.alfresco.repo.clt;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
|
||||
|
||||
/**
|
||||
* Make a directory.
|
||||
* @author britt
|
||||
*/
|
||||
public class AVMMkDir extends CltBase
|
||||
{
|
||||
private static Object [] flagDefs = { "-p", 0 };
|
||||
|
||||
private static String USAGE = "usage: AVMMkDir [-p] nodepath";
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.clt.AVMCltBase#run(java.util.Map, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
protected void run(Map<String, List<String>> flags, List<String> args)
|
||||
{
|
||||
if (flags.containsKey("-p"))
|
||||
{
|
||||
mkdirp(args.get(0));
|
||||
return;
|
||||
}
|
||||
String [] parentBase = splitPath(args.get(0));
|
||||
if (parentBase.length == 1)
|
||||
{
|
||||
System.err.println(args.get(0) + " is a root path.");
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
fAVMRemote.createDirectory(parentBase[0], parentBase[1]);
|
||||
}
|
||||
|
||||
private void mkdirp(String path)
|
||||
{
|
||||
AVMNodeDescriptor desc = fAVMRemote.lookup(-1, path);
|
||||
if (desc != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
String [] parentBase = splitPath(path);
|
||||
if (parentBase.length == 1)
|
||||
{
|
||||
System.err.println(path + " does not exist.");
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
mkdirp(parentBase[0]);
|
||||
fAVMRemote.createDirectory(parentBase[0], parentBase[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
AVMMkDir me = new AVMMkDir();
|
||||
me.exec(args, flagDefs, 1, USAGE);
|
||||
}
|
||||
}
|
40
source/java/org/alfresco/repo/clt/AVMMkLayeredDir.java
Normal file
40
source/java/org/alfresco/repo/clt/AVMMkLayeredDir.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.alfresco.repo.clt;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author britt
|
||||
*
|
||||
*/
|
||||
public class AVMMkLayeredDir extends CltBase
|
||||
{
|
||||
private static Object [] flagDefs = { };
|
||||
|
||||
private static String USAGE = "usage: AVMMkLayeredDir nodepath targetnodepath";
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.clt.AVMCltBase#run(java.util.Map, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
protected void run(Map<String, List<String>> flags, List<String> args)
|
||||
{
|
||||
String [] pathBase = splitPath(args.get(0));
|
||||
if (pathBase.length == 1)
|
||||
{
|
||||
System.err.println("Cannot make a layered root directory.");
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
fAVMRemote.createLayeredDirectory(args.get(1), pathBase[0], pathBase[1]);
|
||||
}
|
||||
|
||||
public static void main(String [] args)
|
||||
{
|
||||
AVMMkLayeredDir me = new AVMMkLayeredDir();
|
||||
me.exec(args, flagDefs, 2, USAGE);
|
||||
}
|
||||
}
|
36
source/java/org/alfresco/repo/clt/AVMMkStore.java
Normal file
36
source/java/org/alfresco/repo/clt/AVMMkStore.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.alfresco.repo.clt;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Create an AVM store.
|
||||
* @author britt
|
||||
*/
|
||||
public class AVMMkStore extends CltBase
|
||||
{
|
||||
private static Object [] flagDefs = { };
|
||||
|
||||
private static String USAGE = "usage: AVMMkStore storename";
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.clt.AVMCltBase#run(java.util.Map, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
protected void run(Map<String, List<String>> flags, List<String> args)
|
||||
{
|
||||
fAVMRemote.createAVMStore(args.get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
AVMMkStore me = new AVMMkStore();
|
||||
me.exec(args, flagDefs, 1, USAGE);
|
||||
}
|
||||
}
|
40
source/java/org/alfresco/repo/clt/AVMRm.java
Normal file
40
source/java/org/alfresco/repo/clt/AVMRm.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.alfresco.repo.clt;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Remove an AVM Node.
|
||||
* @author britt
|
||||
*/
|
||||
public class AVMRm extends CltBase
|
||||
{
|
||||
private static Object [] flagDefs = { };
|
||||
|
||||
private static String USAGE = "usage: AVMRm nodepath";
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.clt.AVMCltBase#run(java.util.Map, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
protected void run(Map<String, List<String>> flags, List<String> args)
|
||||
{
|
||||
String [] pathBase = splitPath(args.get(0));
|
||||
if (pathBase.length == 1)
|
||||
{
|
||||
System.err.println("One cannot remove a root node.");
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
fAVMRemote.removeNode(pathBase[0], pathBase[1]);
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
AVMRm me = new AVMRm();
|
||||
me.exec(args, flagDefs, 1, USAGE);
|
||||
}
|
||||
}
|
36
source/java/org/alfresco/repo/clt/AVMSnapshot.java
Normal file
36
source/java/org/alfresco/repo/clt/AVMSnapshot.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.alfresco.repo.clt;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Snapshot a store.
|
||||
* @author britt
|
||||
*/
|
||||
public class AVMSnapshot extends CltBase
|
||||
{
|
||||
private static Object [] flagDefs = { };
|
||||
|
||||
private static String USAGE = "usage: AVMSnapshot storename label comment";
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.avm.clt.AVMCltBase#run(java.util.Map, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
protected void run(Map<String, List<String>> flags, List<String> args)
|
||||
{
|
||||
fAVMRemote.createSnapshot(args.get(0), args.get(1), args.get(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
AVMSnapshot me = new AVMSnapshot();
|
||||
me.exec(args, flagDefs, 3, USAGE);
|
||||
}
|
||||
}
|
201
source/java/org/alfresco/repo/clt/CltBase.java
Normal file
201
source/java/org/alfresco/repo/clt/CltBase.java
Normal file
@@ -0,0 +1,201 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.alfresco.repo.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;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.repo.remote.ClientTicketHolder;
|
||||
import org.alfresco.service.cmr.avmsync.AVMSyncService;
|
||||
import org.alfresco.service.cmr.remote.AVMRemote;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
/**
|
||||
* This is the base class for AVM clts.
|
||||
* @author britt
|
||||
*/
|
||||
public abstract class CltBase
|
||||
{
|
||||
/**
|
||||
* The instance of the remote interface.
|
||||
*/
|
||||
protected AVMRemote fAVMRemote;
|
||||
|
||||
/**
|
||||
* The instance of the remote sync service interface.
|
||||
*/
|
||||
protected AVMSyncService fAVMSyncService;
|
||||
|
||||
/**
|
||||
* The ApplicationContext.
|
||||
*/
|
||||
protected ConfigurableApplicationContext fContext;
|
||||
|
||||
/**
|
||||
* The Authentication Service.
|
||||
*/
|
||||
protected AuthenticationService fAuthenticationService;
|
||||
|
||||
/**
|
||||
* Construct a new one. This takes care of instantiating
|
||||
* the application context and grabs references to the
|
||||
* services.
|
||||
* @param args The program arguments.
|
||||
*/
|
||||
protected CltBase()
|
||||
{
|
||||
fContext = new ClassPathXmlApplicationContext("alfresco/avm-clt-context.xml");
|
||||
fAVMRemote = (AVMRemote)fContext.getBean("avmRemote");
|
||||
fAVMSyncService = (AVMSyncService)fContext.getBean("avmSyncService");
|
||||
fAuthenticationService = (AuthenticationService)fContext.getBean("authenticationService");
|
||||
fAuthenticationService.authenticate("admin", "admin".toCharArray());
|
||||
String ticket = fAuthenticationService.getCurrentTicket();
|
||||
ClientTicketHolder.SetTicket(ticket);
|
||||
}
|
||||
|
||||
/**
|
||||
* All clts go through this call. This parses the arguments, exits if
|
||||
* there are any errors and then passes the broken flags and arguments
|
||||
* to the run method of the derived clt.
|
||||
* @param args The raw command line arguments.
|
||||
* @param flagDefs The definition of what flags to accept and their
|
||||
* arities.
|
||||
* @param minArgs The minimum number of actual arguments expected.
|
||||
* @param usageMessage The message that should be printed if there is a
|
||||
* syntax error.
|
||||
*/
|
||||
public void exec(String [] args,
|
||||
Object [] flagDefs,
|
||||
int minArgs,
|
||||
String usageMessage)
|
||||
{
|
||||
Map<String, Integer> flagArgs = new HashMap<String, Integer>();
|
||||
Map<String, List<String>> flagValues = new HashMap<String, List<String>>();
|
||||
List<String> actualArgs = new ArrayList<String>();
|
||||
// Convert the flag definitions into a convenient form.
|
||||
for (int i = 0; i < flagDefs.length / 2; i++)
|
||||
{
|
||||
flagArgs.put((String)flagDefs[i * 2], (Integer)flagDefs[i * 2 + 1]);
|
||||
}
|
||||
// Walk through the raw command line arguments.
|
||||
int pos = 0;
|
||||
while (pos < args.length)
|
||||
{
|
||||
if (args[pos].equals("-h"))
|
||||
{
|
||||
usage(usageMessage);
|
||||
}
|
||||
// If the argument is one of the accepted flags then it's
|
||||
// a flag.
|
||||
if (flagArgs.containsKey(args[pos]))
|
||||
{
|
||||
String flag = args[pos];
|
||||
pos++;
|
||||
int count = flagArgs.get(flag);
|
||||
// Check for too few arguments
|
||||
if (args.length - pos < count)
|
||||
{
|
||||
usage(usageMessage);
|
||||
}
|
||||
// Stuff the parsed flag away.
|
||||
List<String> flArgs = new ArrayList<String>();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
flArgs.add(args[pos + i]);
|
||||
}
|
||||
flagValues.put(flag, flArgs);
|
||||
pos += count;
|
||||
continue;
|
||||
}
|
||||
// Otherwise its just a plain old arg.
|
||||
actualArgs.add(args[pos]);
|
||||
pos++;
|
||||
}
|
||||
// Check for too few arguments.
|
||||
if (actualArgs.size() < minArgs)
|
||||
{
|
||||
usage(usageMessage);
|
||||
}
|
||||
// Do the work.
|
||||
run(flagValues, actualArgs);
|
||||
// Cleanup.
|
||||
fContext.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle syntax error by exiting.
|
||||
* @param usageMessage The message to print.
|
||||
*/
|
||||
protected void usage(String usageMessage)
|
||||
{
|
||||
System.err.println(usageMessage);
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility to split an AVM path into a parent path and a
|
||||
* base name.
|
||||
* @param path The path to split.
|
||||
* @return An array of 1 or 2 Strings representing the parent path
|
||||
* and the base name, or just the path if the path given is a root path.
|
||||
*/
|
||||
protected String[] splitPath(String path)
|
||||
{
|
||||
if (path.endsWith(":/"))
|
||||
{
|
||||
String [] ret = { path };
|
||||
return ret;
|
||||
}
|
||||
int lastSlash = path.lastIndexOf("/");
|
||||
if (lastSlash == -1)
|
||||
{
|
||||
System.err.println("Malformed path: " + path);
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
String name = path.substring(lastSlash + 1);
|
||||
String parent = path.substring(0, lastSlash);
|
||||
if (parent.endsWith(":"))
|
||||
{
|
||||
parent = parent + "/";
|
||||
}
|
||||
while (parent.endsWith("/") && !parent.endsWith(":/"))
|
||||
{
|
||||
parent = parent.substring(0, parent.length() - 1);
|
||||
}
|
||||
String [] ret = { parent, name };
|
||||
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<String, List<String>> flags, List<String> args);
|
||||
}
|
Reference in New Issue
Block a user