From 9c50e9b4e2470e1465b6826c91116b14eab78fc3 Mon Sep 17 00:00:00 2001 From: Jan Vonka Date: Wed, 14 May 2008 14:48:12 +0000 Subject: [PATCH] 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 --- .../alfresco/repo/web/scripts/RepoStore.java | 50 ++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/source/java/org/alfresco/repo/web/scripts/RepoStore.java b/source/java/org/alfresco/repo/web/scripts/RepoStore.java index d00dde97f1..b77f31b948 100644 --- a/source/java/org/alfresco/repo/web/scripts/RepoStore.java +++ b/source/java/org/alfresco/repo/web/scripts/RepoStore.java @@ -34,6 +34,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.regex.Pattern; import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.model.ContentModel; @@ -339,10 +340,39 @@ public class RepoStore implements Store, TenantDeployer } /* (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() { public String[] doWork() throws Exception @@ -353,15 +383,15 @@ public class RepoStore implements Store, TenantDeployer { int baseDirLength = getBaseDir().length() +1; - String query = "+PATH:\"" + repoPath + "//*\" +QNAME:*.desc.xml"; - ResultSet resultSet = searchService.query(repoStore, SearchService.LANGUAGE_LUCENE, query); + ResultSet resultSet = searchService.query(repoStore, SearchService.LANGUAGE_LUCENE, query.toString()); List documentPaths = new ArrayList(resultSet.length()); List nodes = resultSet.getNodeRefs(); for (NodeRef nodeRef : nodes) { - String nodeDir = getPath(nodeRef); - if (nodeDir.endsWith(".desc.xml")) + String name = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); + if (Pattern.matches(matcher, name)) { + String nodeDir = getPath(nodeRef); String documentPath = nodeDir.substring(baseDirLength); documentPaths.add(documentPath); } @@ -373,6 +403,14 @@ public class RepoStore implements Store, TenantDeployer } }, AuthenticationUtil.getSystemUserName()); } + + /* (non-Javadoc) + * @see org.alfresco.web.scripts.Store#getDescriptionDocumentPaths() + */ + public String[] getDescriptionDocumentPaths() + { + return getDocumentPaths("/", true, "*.desc.xml"); + } /* (non-Javadoc) * @see org.alfresco.web.scripts.Store#getAllDocumentPaths()