Add support to RepoStore/ClassPathStore to getDocumentPaths (of given document pattern within given path/sub-paths)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9107 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Jan Vonka
2008-05-14 14:48:12 +00:00
parent 6e197d5826
commit 9c50e9b4e2

View File

@@ -34,6 +34,7 @@ import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel; import org.alfresco.model.ContentModel;
@@ -339,10 +340,39 @@ public class RepoStore implements Store, TenantDeployer
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.web.scripts.Store#getDescriptionDocumentPaths() * @see org.alfresco.web.scripts.Store#getDocumentPaths(java.lang.String, boolean, java.lang.String)
*/ */
public String[] getDescriptionDocumentPaths() public String[] getDocumentPaths(String path, boolean includeSubPaths, String documentPattern)
{ {
if ((path == null) || (path.length() == 0))
{
path = "/";
}
if (! path.startsWith("/"))
{
path = "/" + path;
}
if (! path.endsWith("/"))
{
path = path + "/";
}
if ((documentPattern == null) || (documentPattern.length() == 0))
{
documentPattern = "*";
}
final String matcher = documentPattern.replace(".","\\.").replace("*",".*");
final StringBuffer query = new StringBuffer();
query.append("+PATH:\"").append(repoPath)
.append(path)
.append((includeSubPaths ? "/*\"" : ""))
.append(" +QNAME:")
.append(documentPattern);
return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<String[]>() return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<String[]>()
{ {
public String[] doWork() throws Exception public String[] doWork() throws Exception
@@ -353,15 +383,15 @@ public class RepoStore implements Store, TenantDeployer
{ {
int baseDirLength = getBaseDir().length() +1; int baseDirLength = getBaseDir().length() +1;
String query = "+PATH:\"" + repoPath + "//*\" +QNAME:*.desc.xml"; ResultSet resultSet = searchService.query(repoStore, SearchService.LANGUAGE_LUCENE, query.toString());
ResultSet resultSet = searchService.query(repoStore, SearchService.LANGUAGE_LUCENE, query);
List<String> documentPaths = new ArrayList<String>(resultSet.length()); List<String> documentPaths = new ArrayList<String>(resultSet.length());
List<NodeRef> nodes = resultSet.getNodeRefs(); List<NodeRef> nodes = resultSet.getNodeRefs();
for (NodeRef nodeRef : nodes) for (NodeRef nodeRef : nodes)
{ {
String nodeDir = getPath(nodeRef); String name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
if (nodeDir.endsWith(".desc.xml")) if (Pattern.matches(matcher, name))
{ {
String nodeDir = getPath(nodeRef);
String documentPath = nodeDir.substring(baseDirLength); String documentPath = nodeDir.substring(baseDirLength);
documentPaths.add(documentPath); documentPaths.add(documentPath);
} }
@@ -373,6 +403,14 @@ public class RepoStore implements Store, TenantDeployer
} }
}, AuthenticationUtil.getSystemUserName()); }, AuthenticationUtil.getSystemUserName());
} }
/* (non-Javadoc)
* @see org.alfresco.web.scripts.Store#getDescriptionDocumentPaths()
*/
public String[] getDescriptionDocumentPaths()
{
return getDocumentPaths("/", true, "*.desc.xml");
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.web.scripts.Store#getAllDocumentPaths() * @see org.alfresco.web.scripts.Store#getAllDocumentPaths()