Fix to remote store issues since WebStudio merge.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@12563 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2009-01-06 11:32:58 +00:00
parent ab70693a72
commit c15f4dd736
2 changed files with 73 additions and 77 deletions

View File

@@ -252,7 +252,6 @@ public class AVMRemoteStore extends BaseRemoteStore
} }
avmService.createFile(parts[0], parts[1], content); avmService.createFile(parts[0], parts[1], content);
avmService.createSnapshot(store, "AVMRemoteStore.createDocument()", path);
} }
catch (AccessDeniedException ae) catch (AccessDeniedException ae)
{ {
@@ -322,7 +321,6 @@ public class AVMRemoteStore extends BaseRemoteStore
try try
{ {
avmService.removeNode(avmPath); avmService.removeNode(avmPath);
avmService.createSnapshot(store, "AVMRemoteStore.deleteDocument()", path);
} }
catch (AccessDeniedException ae) catch (AccessDeniedException ae)
{ {
@@ -349,7 +347,7 @@ public class AVMRemoteStore extends BaseRemoteStore
try try
{ {
traverseNode(res.getWriter(), store, node, recurse); traverseNode(res.getWriter(), store, node, null, recurse);
} }
catch (AccessDeniedException ae) catch (AccessDeniedException ae)
{ {
@@ -361,29 +359,6 @@ public class AVMRemoteStore extends BaseRemoteStore
} }
} }
private void traverseNode(Writer out, String store, AVMNodeDescriptor node, boolean recurse)
throws IOException
{
/**
* The node path appears as such:
* project1:/www/avm_webapps/ROOT/WEB-INF/classes/alfresco/site-data/template-instances/file.xml
*/
int cropPoint = store.length() + this.rootPath.length() + 1;
SortedMap<String, AVMNodeDescriptor> listing = this.avmService.getDirectoryListing(node);
for (AVMNodeDescriptor n : listing.values())
{
if (n.isFile())
{
out.write(n.getPath().substring(cropPoint));
out.write("\n");
}
else if (recurse && n.isDirectory())
{
traverseNode(out, store, n, recurse);
}
}
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.repo.web.scripts.bean.BaseRemoteStore#listDocuments(org.alfresco.web.scripts.WebScriptResponse, java.lang.String, java.lang.String) * @see org.alfresco.repo.web.scripts.bean.BaseRemoteStore#listDocuments(org.alfresco.web.scripts.WebScriptResponse, java.lang.String, java.lang.String)
*/ */
@@ -404,50 +379,23 @@ public class AVMRemoteStore extends BaseRemoteStore
} }
String matcher = pattern.replace(".","\\.").replace("*",".*"); String matcher = pattern.replace(".","\\.").replace("*",".*");
final Pattern pat = Pattern.compile(matcher);
String encPath = RepoStore.encodePathISO9075(path); try
final StringBuilder query = new StringBuilder(128);
query.append("+PATH:\"").append(this.rootPath)
.append(encPath.length() != 0 ? ('/' + encPath) : "")
.append("//*\" +QNAME:")
.append(pattern);
final Writer out = res.getWriter();
final StoreRef avmStore = new StoreRef(StoreRef.PROTOCOL_AVM + StoreRef.URI_FILLER + store);
AuthenticationUtil.runAs(new RunAsWork<Object>()
{ {
@SuppressWarnings("synthetic-access") traverseNode(res.getWriter(), store, node, Pattern.compile(matcher), true);
public Object doWork() throws Exception }
{ catch (AccessDeniedException ae)
int cropPoint = store.length() + rootPath.length() + 1; {
ResultSet resultSet = searchService.query(avmStore, SearchService.LANGUAGE_LUCENE, query.toString()); res.setStatus(Status.STATUS_UNAUTHORIZED);
try }
{ finally
List<NodeRef> nodes = resultSet.getNodeRefs(); {
for (NodeRef nodeRef : nodes) res.getWriter().close();
{ }
String path = AVMNodeConverter.ToAVMVersionPath(nodeRef).getSecond();
String name = path.substring(path.lastIndexOf('/') + 1);
if (pat.matcher(name).matches())
{
out.write(path.substring(cropPoint));
out.write("\n");
}
}
}
finally
{
resultSet.close();
}
return null;
}
}, AuthenticationUtil.getSystemUserName());
} }
/** /**
* @param store the store id * @param store the AVM store id
* @param path root path relative * @param path root path relative
* *
* @return full AVM path to document including store and root path components * @return full AVM path to document including store and root path components
@@ -461,6 +409,53 @@ public class AVMRemoteStore extends BaseRemoteStore
return store + ":" + this.rootPath + (path != null ? encodePath(path) : ""); return store + ":" + this.rootPath + (path != null ? encodePath(path) : "");
} }
/**
* Traverse a Node and recursively output the file paths it contains.
*
* @param out Writer for output - relative paths separated by newline characters
* @param store AVM Store name
* @param node The AVM Node to traverse
* @param pattern Optional Pattern to match filenames against
* @param recurse True to recurse sub-directories
*
* @throws IOException
*/
private void traverseNode(Writer out, String store, AVMNodeDescriptor node, Pattern pattern, boolean recurse)
throws IOException
{
/**
* The node path appears as such:
* project1:/www/avm_webapps/ROOT/WEB-INF/classes/alfresco/site-data/template-instances/file.xml
*/
int cropPoint = store.length() + this.rootPath.length() + 1;
SortedMap<String, AVMNodeDescriptor> listing = this.avmService.getDirectoryListing(node);
for (AVMNodeDescriptor n : listing.values())
{
if (n.isFile())
{
String path = n.getPath();
if (pattern != null)
{
String name = path.substring(path.lastIndexOf('/') + 1);
if (pattern.matcher(name).matches())
{
out.write(path.substring(cropPoint));
out.write("\n");
}
}
else
{
out.write(path.substring(cropPoint));
out.write("\n");
}
}
else if (recurse && n.isDirectory())
{
traverseNode(out, store, n, pattern, recurse);
}
}
}
private static String encodePath(final String s) private static String encodePath(final String s)
{ {

View File

@@ -91,10 +91,10 @@ public abstract class BaseRemoteStore extends AbstractWebScript
{ {
public static final String TOKEN_STORE = "s"; public static final String TOKEN_STORE = "s";
public static final String TOKEN_WEBAPP = "w"; public static final String TOKEN_WEBAPP = "w";
public static final String REQUEST_PARAM_STORE = "s"; public static final String REQUEST_PARAM_STORE = "s";
public static final String REQUEST_PARAM_WEBAPP = "w"; public static final String REQUEST_PARAM_WEBAPP = "w";
private static final Log logger = LogFactory.getLog(BaseRemoteStore.class); private static final Log logger = LogFactory.getLog(BaseRemoteStore.class);
protected String defaultStore; protected String defaultStore;
@@ -160,30 +160,30 @@ public abstract class BaseRemoteStore extends AbstractWebScript
if (TOKEN_STORE.equals(el)) if (TOKEN_STORE.equals(el))
{ {
// if the token is "s", then the next token is the id of the store // if the token is TOKEN_STORE, then the next token is the id of the store
store = tokenizer.nextToken(); store = tokenizer.nextToken();
// reset el // reset element
el = (tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null); el = (tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null);
} }
if (TOKEN_WEBAPP.equals(el)) if (TOKEN_WEBAPP.equals(el))
{ {
// if the token is "w", then the next token is a WCM webapp id // if the token is TOKEN_WEBAPP, then the next token is a WCM webapp id
webapp = tokenizer.nextToken(); webapp = tokenizer.nextToken();
// reset el // reset element
el = (tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null); el = (tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null);
} }
while(el != null) while (el != null)
{ {
if(pathBuilder == null) if (pathBuilder == null)
{ {
pathBuilder = new StringBuilder(128); pathBuilder = new StringBuilder(128);
} }
pathBuilder.append("/"); pathBuilder.append('/');
pathBuilder.append(el); pathBuilder.append(el);
el = (tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null); el = (tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null);
@@ -209,7 +209,8 @@ public abstract class BaseRemoteStore extends AbstractWebScript
// this means that a store was not passed in and that we // this means that a store was not passed in and that we
// also didn't have a configured store // also didn't have a configured store
throw new WebScriptException("Unable to determine which store to operate against. A store was not specified and a default was not provided."); throw new WebScriptException("Unable to determine which store to operate against." +
" A store was not specified and a default was not provided.");
} }
} }
@@ -227,7 +228,7 @@ public abstract class BaseRemoteStore extends AbstractWebScript
// convert down to the path // convert down to the path
String path = pathBuilder.toString(); String path = pathBuilder.toString();
// debugger information // debugger information
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {