mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-06-02 17:35:18 +00:00
Working facsimiles of ls and half of cp for Repo.
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4510 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
parent
66c95d5dce
commit
a95b3bbed0
158
source/java/org/alfresco/repo/clt/RepoCopyIn.java
Normal file
158
source/java/org/alfresco/repo/clt/RepoCopyIn.java
Normal file
@ -0,0 +1,158 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
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;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
* Simplified cp from a local filesystem to the repo.
|
||||
* @author britt
|
||||
*/
|
||||
public class RepoCopyIn extends CltBase
|
||||
{
|
||||
private static Object [] flagDefs = { "-r", 0, "-v", 0 };
|
||||
|
||||
private static String USAGE = "usage: RepoCopyIn fspath repopath";
|
||||
|
||||
private boolean fVerbose;
|
||||
|
||||
/* (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)
|
||||
{
|
||||
if (flags.containsKey("-v"))
|
||||
{
|
||||
fVerbose = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
fVerbose = false;
|
||||
}
|
||||
NodeRef root = fRepoRemote.getRoot();
|
||||
String path = args.get(1);
|
||||
while (path.startsWith("/"))
|
||||
{
|
||||
path = path.substring(1);
|
||||
}
|
||||
Pair<NodeRef, Boolean> dst = fRepoRemote.lookup(root, path);
|
||||
if (flags.containsKey("-r"))
|
||||
{
|
||||
if (dst == null)
|
||||
{
|
||||
System.err.println(args.get(1) + " does not exist.");
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
recursiveCopy(args.get(0), dst.getFirst());
|
||||
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);
|
||||
}
|
||||
if (dst == null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (fVerbose)
|
||||
{
|
||||
System.out.println(file.getName() + " -> " + args.get(1));
|
||||
}
|
||||
InputStream in =
|
||||
new FileInputStream(file);
|
||||
OutputStream out = fRepoRemote.createFile(root, path);
|
||||
copyStream(in, out);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!dst.getSecond())
|
||||
{
|
||||
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, NodeRef dest)
|
||||
{
|
||||
File file = new File(sourcePath);
|
||||
if (fVerbose)
|
||||
{
|
||||
System.out.println(sourcePath + " -> " + dest);
|
||||
}
|
||||
if (file.isDirectory())
|
||||
{
|
||||
NodeRef dir = fRepoRemote.createDirectory(dest, file.getName());
|
||||
String [] names = file.list();
|
||||
for (String name : names)
|
||||
{
|
||||
recursiveCopy(sourcePath + File.separatorChar + name,
|
||||
dir);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
InputStream in =
|
||||
new FileInputStream(file);
|
||||
OutputStream out = fRepoRemote.createFile(dest, file.getName());
|
||||
copyStream(in, out);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
RepoCopyIn me = new RepoCopyIn();
|
||||
me.exec(args, flagDefs, 2, USAGE);
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
@ -39,21 +38,44 @@ public class RepoLs extends CltBase
|
||||
{
|
||||
path = path.substring(1);
|
||||
}
|
||||
dir = fRepoRemote.lookup(root, path);
|
||||
if (dir == null)
|
||||
Pair<NodeRef, Boolean> info = fRepoRemote.lookup(root, path);
|
||||
if (info == null)
|
||||
{
|
||||
System.err.println(path + " does not exist");
|
||||
fContext.close();
|
||||
System.exit(1);
|
||||
}
|
||||
dir = info.getFirst();
|
||||
}
|
||||
Map<String, Pair<NodeRef, QName>> listing = fRepoRemote.getListing(dir);
|
||||
if (flags.containsKey("-R"))
|
||||
{
|
||||
recursiveList(dir, 0);
|
||||
return;
|
||||
}
|
||||
Map<String, Pair<NodeRef, Boolean>> listing = fRepoRemote.getListing(dir);
|
||||
for (String name : listing.keySet())
|
||||
{
|
||||
System.out.println(name + "\t" + listing.get(name));
|
||||
}
|
||||
}
|
||||
|
||||
private void recursiveList(NodeRef dir, int indent)
|
||||
{
|
||||
Map<String, Pair<NodeRef, Boolean>> listing = fRepoRemote.getListing(dir);
|
||||
for (Map.Entry<String, Pair<NodeRef, Boolean>> entry : listing.entrySet())
|
||||
{
|
||||
for (int i = 0; i < indent; i++)
|
||||
{
|
||||
System.out.print(' ');
|
||||
}
|
||||
System.out.println(entry.getKey() + '\t' + entry.getValue());
|
||||
if (entry.getValue().getSecond())
|
||||
{
|
||||
recursiveList(entry.getValue().getFirst(), indent + 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
RepoLs me = new RepoLs();
|
||||
|
@ -10,7 +10,6 @@ import java.util.Map;
|
||||
import org.alfresco.service.cmr.remote.RepoRemote;
|
||||
import org.alfresco.service.cmr.remote.RepoRemoteTransport;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
@ -59,7 +58,7 @@ public class RepoRemoteImpl implements RepoRemote
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.remote.RepoRemote#getListing(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public Map<String, Pair<NodeRef, QName>> getListing(NodeRef dir)
|
||||
public Map<String, Pair<NodeRef, Boolean>> getListing(NodeRef dir)
|
||||
{
|
||||
return fTransport.getListing(ClientTicketHolder.GetTicket(), dir);
|
||||
}
|
||||
@ -75,7 +74,7 @@ public class RepoRemoteImpl implements RepoRemote
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.remote.RepoRemote#lookup(org.alfresco.service.cmr.repository.NodeRef, java.lang.String)
|
||||
*/
|
||||
public NodeRef lookup(NodeRef base, String path)
|
||||
public Pair<NodeRef, Boolean> lookup(NodeRef base, String path)
|
||||
{
|
||||
return fTransport.lookup(ClientTicketHolder.GetTicket(), base, path);
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import java.util.TreeMap;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.model.FileNotFoundException;
|
||||
@ -23,7 +22,6 @@ import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
@ -126,22 +124,14 @@ public class RepoRemoteService implements RepoRemote
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.remote.RepoRemote#getListing(org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public Map<String, Pair<NodeRef, QName>> getListing(NodeRef dir)
|
||||
public Map<String, Pair<NodeRef, Boolean>> getListing(NodeRef dir)
|
||||
{
|
||||
List<ChildAssociationRef> listing = fNodeService.getChildAssocs(dir);
|
||||
Map<String, Pair<NodeRef, QName>> result = new TreeMap<String, Pair<NodeRef, QName>>();
|
||||
for (ChildAssociationRef child : listing)
|
||||
Map<String, Pair<NodeRef, Boolean>> result = new TreeMap<String, Pair<NodeRef, Boolean>>();
|
||||
List<FileInfo> listing = fFileFolderService.list(dir);
|
||||
for (FileInfo info : listing)
|
||||
{
|
||||
fgLogger.error(child.getQName());
|
||||
NodeRef childRef = child.getChildRef();
|
||||
QName type = fNodeService.getType(childRef);
|
||||
if (type.equals(ContentModel.TYPE_CONTENT) ||
|
||||
type.equals(ContentModel.TYPE_FOLDER))
|
||||
{
|
||||
result.put(child.getQName().getLocalName(),
|
||||
new Pair<NodeRef, QName>(child.getChildRef(),
|
||||
type));
|
||||
}
|
||||
result.put(info.getName(), new Pair<NodeRef, Boolean>(info.getNodeRef(),
|
||||
info.isFolder()));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -167,27 +157,19 @@ public class RepoRemoteService implements RepoRemote
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.remote.RepoRemote#lookup(org.alfresco.service.cmr.repository.NodeRef, java.lang.String)
|
||||
*/
|
||||
public NodeRef lookup(NodeRef base, String path)
|
||||
public Pair<NodeRef, Boolean> lookup(NodeRef base, String path)
|
||||
{
|
||||
List<String> pathList = splitPath(path);
|
||||
NodeRef curr = base;
|
||||
for (String name : pathList)
|
||||
try
|
||||
{
|
||||
fgLogger.error(name);
|
||||
NodeRef next = fNodeService.getChildByName(curr, ContentModel.ASSOC_CONTAINS, name);
|
||||
if (next == null)
|
||||
{
|
||||
fgLogger.error("Wasn't a contains.");
|
||||
next = fNodeService.getChildByName(curr, ContentModel.ASSOC_CHILDREN, name);
|
||||
if (next == null)
|
||||
FileInfo info = fFileFolderService.resolveNamePath(base, pathList);
|
||||
return new Pair<NodeRef, Boolean>(info.getNodeRef(), info.isFolder());
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
curr = next;
|
||||
}
|
||||
return curr;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.remote.RepoRemote#readFile(org.alfresco.service.cmr.repository.NodeRef)
|
||||
@ -202,7 +184,7 @@ public class RepoRemoteService implements RepoRemote
|
||||
*/
|
||||
public InputStream readFile(NodeRef base, String path)
|
||||
{
|
||||
NodeRef fileRef = lookup(base, path);
|
||||
NodeRef fileRef = lookup(base, path).getFirst();
|
||||
if (fileRef == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Not Found: " + path);
|
||||
@ -223,7 +205,7 @@ public class RepoRemoteService implements RepoRemote
|
||||
*/
|
||||
public void removeNode(NodeRef base, String path)
|
||||
{
|
||||
NodeRef toRemove = lookup(base, path);
|
||||
NodeRef toRemove = lookup(base, path).getFirst();
|
||||
if (toRemove == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Not Found: " + path);
|
||||
@ -236,7 +218,7 @@ public class RepoRemoteService implements RepoRemote
|
||||
*/
|
||||
public void rename(NodeRef base, String src, String dst)
|
||||
{
|
||||
NodeRef srcRef = lookup(base, src);
|
||||
NodeRef srcRef = lookup(base, src).getFirst();
|
||||
if (srcRef == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Not Found: " + src);
|
||||
@ -257,7 +239,7 @@ public class RepoRemoteService implements RepoRemote
|
||||
*/
|
||||
public OutputStream writeFile(NodeRef base, String path)
|
||||
{
|
||||
NodeRef target = lookup(base, path);
|
||||
NodeRef target = lookup(base, path).getFirst();
|
||||
return fContentService.getWriter(target, ContentModel.PROP_CONTENT, true).getContentOutputStream();
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,6 @@ import org.alfresco.service.cmr.remote.RepoRemote;
|
||||
import org.alfresco.service.cmr.remote.RepoRemoteTransport;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
@ -293,7 +292,7 @@ public class RepoRemoteTransportService implements RepoRemoteTransport,
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.remote.RepoRemoteTransport#getListing(java.lang.String, org.alfresco.service.cmr.repository.NodeRef)
|
||||
*/
|
||||
public Map<String, Pair<NodeRef, QName>> getListing(String ticket, NodeRef dir)
|
||||
public Map<String, Pair<NodeRef, Boolean>> getListing(String ticket, NodeRef dir)
|
||||
{
|
||||
fAuthService.validate(ticket);
|
||||
return fRepoRemote.getListing(dir);
|
||||
@ -311,7 +310,7 @@ public class RepoRemoteTransportService implements RepoRemoteTransport,
|
||||
/* (non-Javadoc)
|
||||
* @see org.alfresco.service.cmr.remote.RepoRemoteTransport#lookup(java.lang.String, org.alfresco.service.cmr.repository.NodeRef, java.lang.String)
|
||||
*/
|
||||
public NodeRef lookup(String ticket, NodeRef base, String path)
|
||||
public Pair<NodeRef, Boolean> lookup(String ticket, NodeRef base, String path)
|
||||
{
|
||||
fAuthService.validate(ticket);
|
||||
return fRepoRemote.lookup(base, path);
|
||||
|
@ -8,7 +8,6 @@ import java.io.OutputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
@ -28,7 +27,7 @@ public interface RepoRemote
|
||||
* @param dir The node ref of the directory.
|
||||
* @return A Map of names to node refs.
|
||||
*/
|
||||
public Map<String, Pair<NodeRef, QName>> getListing(NodeRef dir);
|
||||
public Map<String, Pair<NodeRef, Boolean>> getListing(NodeRef dir);
|
||||
|
||||
/**
|
||||
* Lookup a node by path relative to a node.
|
||||
@ -36,7 +35,7 @@ public interface RepoRemote
|
||||
* @param path The relative path.
|
||||
* @return The node ref or null.
|
||||
*/
|
||||
public NodeRef lookup(NodeRef base, String path);
|
||||
public Pair<NodeRef, Boolean> lookup(NodeRef base, String path);
|
||||
|
||||
/**
|
||||
* Create a file relative to a base node.
|
||||
|
@ -6,7 +6,6 @@ package org.alfresco.service.cmr.remote;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.Pair;
|
||||
|
||||
/**
|
||||
@ -27,7 +26,7 @@ public interface RepoRemoteTransport
|
||||
* @param dir The node ref of the directory.
|
||||
* @return A Map of names to node refs.
|
||||
*/
|
||||
public Map<String, Pair<NodeRef, QName>> getListing(String ticket, NodeRef dir);
|
||||
public Map<String, Pair<NodeRef, Boolean>> getListing(String ticket, NodeRef dir);
|
||||
|
||||
/**
|
||||
* Lookup a node by path relative to a node.
|
||||
@ -35,7 +34,7 @@ public interface RepoRemoteTransport
|
||||
* @param path The relative path.
|
||||
* @return The node ref or null.
|
||||
*/
|
||||
public NodeRef lookup(String ticket, NodeRef base, String path);
|
||||
public Pair<NodeRef, Boolean> lookup(String ticket, NodeRef base, String path);
|
||||
|
||||
/**
|
||||
* Create a file relative to a base node.
|
||||
|
Loading…
x
Reference in New Issue
Block a user