mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Exported some Repo functionality via RMI. First (still broken) Repo
based CLT. Some cleanup and modification to other CLTs. WIP. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4500 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -145,9 +145,6 @@ public class AVMCopyIn extends CltBase
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args)
|
||||
{
|
||||
AVMCopyIn me = new AVMCopyIn();
|
||||
|
@@ -12,6 +12,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
* Copy out a file or a directory recursively from the repository
|
||||
@@ -40,13 +41,9 @@ public class AVMCopyOut extends CltBase
|
||||
{
|
||||
fVerbose = false;
|
||||
}
|
||||
String [] versionPath = args.get(0).split("@");
|
||||
if (versionPath.length != 2)
|
||||
{
|
||||
usage(USAGE);
|
||||
}
|
||||
String path = versionPath[0];
|
||||
int version = Integer.parseInt(versionPath[1]);
|
||||
Pair<String, Integer> versionPath = splitPathVersion(args.get(0));
|
||||
String path = versionPath.getFirst();
|
||||
int version = versionPath.getSecond();
|
||||
AVMNodeDescriptor desc = fAVMRemote.lookup(version, path);
|
||||
if (flags.containsKey("-r"))
|
||||
{
|
||||
@@ -55,13 +52,13 @@ public class AVMCopyOut extends CltBase
|
||||
}
|
||||
if (desc == null)
|
||||
{
|
||||
System.err.println(versionPath[0] + " does not exist.");
|
||||
System.err.println(path + " does not exist.");
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
if (!desc.isFile())
|
||||
{
|
||||
System.err.println(versionPath[0] + " is not a file.");
|
||||
System.err.println(path + " is not a file.");
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.avm.AVMNodeDescriptor;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
* Get a listing of a node.
|
||||
@@ -24,9 +25,9 @@ public class AVMLs extends CltBase
|
||||
@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]);
|
||||
Pair<String, Integer> pathVersion = splitPathVersion(args.get(0));
|
||||
AVMNodeDescriptor desc = fAVMRemote.lookup(pathVersion.getSecond(),
|
||||
pathVersion.getFirst());
|
||||
if (flags.containsKey("-R"))
|
||||
{
|
||||
recursiveList(desc, 0);
|
||||
|
@@ -14,7 +14,9 @@ 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.remote.RepoRemote;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
@@ -33,6 +35,11 @@ public abstract class CltBase
|
||||
* The instance of the remote sync service interface.
|
||||
*/
|
||||
protected AVMSyncService fAVMSyncService;
|
||||
|
||||
/**
|
||||
* The instance of the remote repo interface.
|
||||
*/
|
||||
protected RepoRemote fRepoRemote;
|
||||
|
||||
/**
|
||||
* The ApplicationContext.
|
||||
@@ -44,6 +51,11 @@ public abstract class CltBase
|
||||
*/
|
||||
protected AuthenticationService fAuthenticationService;
|
||||
|
||||
/**
|
||||
* The usage string.
|
||||
*/
|
||||
private String fUsage;
|
||||
|
||||
/**
|
||||
* Construct a new one. This takes care of instantiating
|
||||
* the application context and grabs references to the
|
||||
@@ -52,9 +64,10 @@ public abstract class CltBase
|
||||
*/
|
||||
protected CltBase()
|
||||
{
|
||||
fContext = new ClassPathXmlApplicationContext("alfresco/avm-clt-context.xml");
|
||||
fContext = new ClassPathXmlApplicationContext("alfresco/clt-context.xml");
|
||||
fAVMRemote = (AVMRemote)fContext.getBean("avmRemote");
|
||||
fAVMSyncService = (AVMSyncService)fContext.getBean("avmSyncService");
|
||||
fRepoRemote = (RepoRemote)fContext.getBean("repoRemote");
|
||||
fAuthenticationService = (AuthenticationService)fContext.getBean("authenticationService");
|
||||
fAuthenticationService.authenticate("admin", "admin".toCharArray());
|
||||
String ticket = fAuthenticationService.getCurrentTicket();
|
||||
@@ -77,6 +90,7 @@ public abstract class CltBase
|
||||
int minArgs,
|
||||
String usageMessage)
|
||||
{
|
||||
fUsage = 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>();
|
||||
@@ -91,7 +105,7 @@ public abstract class CltBase
|
||||
{
|
||||
if (args[pos].equals("-h"))
|
||||
{
|
||||
usage(usageMessage);
|
||||
usage();
|
||||
}
|
||||
// If the argument is one of the accepted flags then it's
|
||||
// a flag.
|
||||
@@ -103,7 +117,7 @@ public abstract class CltBase
|
||||
// Check for too few arguments
|
||||
if (args.length - pos < count)
|
||||
{
|
||||
usage(usageMessage);
|
||||
usage();
|
||||
}
|
||||
// Stuff the parsed flag away.
|
||||
List<String> flArgs = new ArrayList<String>();
|
||||
@@ -122,7 +136,7 @@ public abstract class CltBase
|
||||
// Check for too few arguments.
|
||||
if (actualArgs.size() < minArgs)
|
||||
{
|
||||
usage(usageMessage);
|
||||
usage();
|
||||
}
|
||||
// Do the work.
|
||||
run(flagValues, actualArgs);
|
||||
@@ -132,11 +146,10 @@ public abstract class CltBase
|
||||
|
||||
/**
|
||||
* Handle syntax error by exiting.
|
||||
* @param usageMessage The message to print.
|
||||
*/
|
||||
protected void usage(String usageMessage)
|
||||
protected void usage()
|
||||
{
|
||||
System.err.println(usageMessage);
|
||||
System.err.println(fUsage);
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
@@ -197,5 +210,17 @@ public abstract class CltBase
|
||||
}
|
||||
}
|
||||
|
||||
protected Pair<String, Integer> splitPathVersion(String pathVersion)
|
||||
{
|
||||
int index = pathVersion.lastIndexOf('@');
|
||||
if (index == -1)
|
||||
{
|
||||
usage();
|
||||
}
|
||||
String path = pathVersion.substring(0, index);
|
||||
int version = Integer.parseInt(pathVersion.substring(index + 1));
|
||||
return new Pair<String, Integer>(path, version);
|
||||
}
|
||||
|
||||
protected abstract void run(Map<String, List<String>> flags, List<String> args);
|
||||
}
|
||||
|
60
source/java/org/alfresco/repo/clt/RepoLs.java
Normal file
60
source/java/org/alfresco/repo/clt/RepoLs.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.alfresco.repo.clt;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
|
||||
/**
|
||||
* List the contents of a directory in a repo.
|
||||
* @author britt
|
||||
*/
|
||||
public class RepoLs extends CltBase
|
||||
{
|
||||
private static Object [] flagDefs = { "-R", 0 };
|
||||
|
||||
private static String USAGE = "usage: RepoLs path";
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.repo.clt.CltBase#run(java.util.Map, java.util.List)
|
||||
*/
|
||||
@Override
|
||||
protected void run(Map<String, List<String>> flags, List<String> args)
|
||||
{
|
||||
NodeRef root = fRepoRemote.getRoot();
|
||||
NodeRef dir = null;
|
||||
String path = args.get(0);
|
||||
if (path.equals("/"))
|
||||
{
|
||||
dir = root;
|
||||
}
|
||||
else
|
||||
{
|
||||
while (path.startsWith("/"))
|
||||
{
|
||||
path = path.substring(1);
|
||||
}
|
||||
dir = fRepoRemote.lookup(root, path);
|
||||
if (dir == null)
|
||||
{
|
||||
System.err.println(path + " does not exist");
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
Map<String, NodeRef> listing = fRepoRemote.getListing(dir);
|
||||
for (String name : listing.keySet())
|
||||
{
|
||||
System.out.println(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
RepoLs me = new RepoLs();
|
||||
me.exec(args, flagDefs, 1, USAGE);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user