JavaScript node and Template node xpath search now uses QueryParameters for folder path searches

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@5408 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast 2007-03-21 12:43:51 +00:00
parent 7f3c842c79
commit 6795d5dc9c
4 changed files with 52 additions and 22 deletions

View File

@ -38,14 +38,13 @@ import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.executer.TransformActionExecuter;
import org.alfresco.repo.content.transform.magick.ImageMagickContentTransformer;
import org.alfresco.repo.security.permissions.AccessDeniedException;
import org.alfresco.repo.search.QueryParameterDefImpl;
import org.alfresco.repo.template.FreeMarkerProcessor;
import org.alfresco.repo.version.VersionModel;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.InvalidAspectException;
import org.alfresco.service.cmr.lock.LockStatus;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
@ -53,13 +52,12 @@ import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NoTransformerException;
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.cmr.repository.TemplateImageResolver;
import org.alfresco.service.cmr.repository.TemplateNode;
import org.alfresco.service.cmr.search.QueryParameterDefinition;
import org.alfresco.service.cmr.security.AccessStatus;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.cmr.version.Version;
@ -67,7 +65,6 @@ import org.alfresco.service.cmr.version.VersionType;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.alfresco.util.ApplicationContextHelper;
import org.alfresco.util.ParameterCheck;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -343,17 +340,30 @@ public class Node implements Serializable, Scopeable
{
// convert the name based path to a valid XPath query
StringBuilder xpath = new StringBuilder(path.length() << 1);
for (StringTokenizer t = new StringTokenizer(path, "/"); t.hasMoreTokens(); /**/)
StringTokenizer t = new StringTokenizer(path, "/");
int count = 0;
QueryParameterDefinition[] params = new QueryParameterDefinition[t.countTokens()];
DataTypeDefinition ddText =
this.services.getDictionaryService().getDataType(DataTypeDefinition.TEXT);
NamespaceService ns = this.services.getNamespaceService();
while (t.hasMoreTokens())
{
if (xpath.length() != 0)
{
xpath.append('/');
}
xpath.append("*[@cm:name='").append(t.nextToken()) // TODO: use QueryParameterDefinition see FileFolderService.search()
.append("']");
String strCount = Integer.toString(count);
xpath.append("*[@cm:name=$cm:name")
.append(strCount)
.append(']');
params[count++] = new QueryParameterDefImpl(
QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, "name" + strCount, ns),
ddText,
true,
t.nextToken());
}
Node[] nodes = getChildrenByXPath(xpath.toString(), true);
Node[] nodes = getChildrenByXPath(xpath.toString(), params, true);
return (nodes.length != 0) ? nodes[0] : null;
}
@ -369,7 +379,7 @@ public class Node implements Serializable, Scopeable
*/
public Node[] childrenByXPath(String xpath)
{
return getChildrenByXPath(xpath, false);
return getChildrenByXPath(xpath, null, false);
}
/**
@ -1676,7 +1686,7 @@ public class Node implements Serializable, Scopeable
*
* @return Node[] can be empty but never null
*/
private Node[] getChildrenByXPath(String xpath, boolean firstOnly)
private Node[] getChildrenByXPath(String xpath, QueryParameterDefinition[] params, boolean firstOnly)
{
Node[] result = null;
@ -1684,7 +1694,7 @@ public class Node implements Serializable, Scopeable
{
if (logger.isDebugEnabled()) logger.debug("Executing xpath: " + xpath);
List<NodeRef> nodes = this.services.getSearchService().selectNodes(this.nodeRef, xpath, null,
List<NodeRef> nodes = this.services.getSearchService().selectNodes(this.nodeRef, xpath, params,
this.services.getNamespaceService(), false);
// see if we only want the first result

View File

@ -31,6 +31,7 @@ import java.util.List;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.TemplateNode;
import org.alfresco.service.cmr.search.QueryParameterDefinition;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -63,7 +64,7 @@ public abstract class BasePathResultsMap extends BaseTemplateMap
*
* @return List<TemplateNode>
*/
protected List<TemplateNode> getChildrenByXPath(String xpath, boolean firstOnly)
protected List<TemplateNode> getChildrenByXPath(String xpath, QueryParameterDefinition[] params, boolean firstOnly)
{
List<TemplateNode> result = null;
@ -75,7 +76,7 @@ public abstract class BasePathResultsMap extends BaseTemplateMap
List<NodeRef> nodes = this.services.getSearchService().selectNodes(
this.parent.getNodeRef(),
xpath,
null,
params,
this.services.getNamespaceService(),
false);

View File

@ -27,8 +27,13 @@ package org.alfresco.repo.template;
import java.util.List;
import java.util.StringTokenizer;
import org.alfresco.repo.search.QueryParameterDefImpl;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.TemplateNode;
import org.alfresco.service.cmr.search.QueryParameterDefinition;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
/**
* A special Map that executes an XPath against the parent Node as part of the get()
@ -54,19 +59,33 @@ public class NamePathResultsMap extends BasePathResultsMap
*/
public Object get(Object key)
{
StringBuilder xpath = new StringBuilder(128);
for (StringTokenizer t = new StringTokenizer(key.toString(), "/"); t.hasMoreTokens(); /**/)
String path = key.toString();
StringBuilder xpath = new StringBuilder(path.length() << 1);
StringTokenizer t = new StringTokenizer(path, "/");
int count = 0;
QueryParameterDefinition[] params = new QueryParameterDefinition[t.countTokens()];
DataTypeDefinition ddText =
this.services.getDictionaryService().getDataType(DataTypeDefinition.TEXT);
NamespaceService ns = this.services.getNamespaceService();
while (t.hasMoreTokens())
{
if (xpath.length() != 0)
{
xpath.append('/');
}
xpath.append("*[@cm:name='")
.append(t.nextToken()) // TODO: use QueryParameterDefinition see FileFolderService.search()
.append("']");
String strCount = Integer.toString(count);
xpath.append("*[@cm:name=$cm:name")
.append(strCount)
.append(']');
params[count++] = new QueryParameterDefImpl(
QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, "name" + strCount, ns),
ddText,
true,
t.nextToken());
}
List<TemplateNode> nodes = getChildrenByXPath(xpath.toString(), true);
List<TemplateNode> nodes = getChildrenByXPath(xpath.toString(), params, true);
return (nodes.size() != 0) ? nodes.get(0) : null;
}
}

View File

@ -51,6 +51,6 @@ public class XPathResultsMap extends BasePathResultsMap
*/
public Object get(Object key)
{
return getChildrenByXPath(key.toString(), false);
return getChildrenByXPath(key.toString(), null, false);
}
}