From c4e2cabb1267390c2d6a7ee6702106989f8d2db8 Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Wed, 6 Dec 2006 16:09:41 +0000 Subject: [PATCH] Merged 1.4 to HEAD (XPath fixes) svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4462 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4463 . svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4468 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4469 . svn merge svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4486 svn://svn.alfresco.com:3691/alfresco/BRANCHES/V1.4@4487 . git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@4532 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repo/node/db/DbNodeServiceImpl.java | 6 ++ .../repo/search/DocumentNavigator.java | 102 +++++++++++++++++- 2 files changed, 107 insertions(+), 1 deletion(-) diff --git a/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java b/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java index f71b5c1de2..4c03320e77 100644 --- a/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java +++ b/source/java/org/alfresco/repo/node/db/DbNodeServiceImpl.java @@ -808,6 +808,12 @@ public class DbNodeServiceImpl extends AbstractNodeServiceImpl Map properties = node.getProperties(); PropertyValue propertyValue = properties.get(qname); + // check if we need to provide a spoofed name + if (propertyValue == null && qname.equals(ContentModel.PROP_NAME)) + { + return nodeRef.getId(); + } + // get the property definition PropertyDefinition propertyDef = dictionaryService.getProperty(qname); // convert to the correct type diff --git a/source/java/org/alfresco/repo/search/DocumentNavigator.java b/source/java/org/alfresco/repo/search/DocumentNavigator.java index e0ccf66f05..a59874de95 100644 --- a/source/java/org/alfresco/repo/search/DocumentNavigator.java +++ b/source/java/org/alfresco/repo/search/DocumentNavigator.java @@ -19,6 +19,7 @@ package org.alfresco.repo.search; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -39,6 +40,7 @@ import org.alfresco.service.namespace.RegexQNamePattern; import org.alfresco.util.ISO9075; import org.jaxen.DefaultNavigator; import org.jaxen.JaxenException; +import org.jaxen.NamedAccessNavigator; import org.jaxen.UnsupportedAxisException; import org.jaxen.XPath; @@ -53,7 +55,7 @@ import org.jaxen.XPath; * @author Andy Hind * */ -public class DocumentNavigator extends DefaultNavigator +public class DocumentNavigator extends DefaultNavigator implements NamedAccessNavigator { private static QName JCR_ROOT = QName.createQName("http://www.jcp.org/jcr/1.0", "root"); @@ -309,6 +311,41 @@ public class DocumentNavigator extends DefaultNavigator // Basic navigation support + public Iterator getAttributeAxisIterator(Object contextNode, String localName, String namespacePrefix, String namespaceURI) throws UnsupportedAxisException + { + // decode the localname + localName = ISO9075.decode(localName); + + NodeRef nodeRef = ((ChildAssociationRef) contextNode).getChildRef(); + QName qName = QName.createQName(namespaceURI, localName); + Serializable value = nodeService.getProperty(nodeRef, qName); + List properties = null; + if (value != null) + { + if (value instanceof Collection) + { + Collection values = (Collection) value; + properties = new ArrayList(values.size()); + for(Serializable collectionValue : values) + { + Property property = new Property(qName, collectionValue, nodeRef); + properties.add(property); + } + } + else + { + Property property = new Property(qName, value, nodeRef); + properties = Collections.singletonList(property); + } + } + else + { + properties = Collections.emptyList(); + } + // done + return properties.iterator(); + } + public Iterator getAttributeAxisIterator(Object o) throws UnsupportedAxisException { ArrayList properties = new ArrayList(); @@ -342,6 +379,31 @@ public class DocumentNavigator extends DefaultNavigator return properties.iterator(); } + public Iterator getChildAxisIterator(Object contextNode, String localName, String namespacePrefix, String namespaceURI) throws UnsupportedAxisException + { + // decode the localname + localName = ISO9075.decode(localName); + + ChildAssociationRef assocRef = (ChildAssociationRef) contextNode; + NodeRef childRef = assocRef.getChildRef(); + QName qName = QName.createQName(namespaceURI, localName); + List list = null; + // Add compatability for JCR 170 by including the root node. + if(isDocument(contextNode) && useJCRRootNode) + { + list = new ArrayList(1); + list = Collections.singletonList( + new JCRRootNodeChildAssociationRef( + ContentModel.ASSOC_CHILDREN, childRef, JCR_ROOT, childRef, true, 0)); + } + else + { + list = nodeService.getChildAssocs(childRef, RegexQNamePattern.MATCH_ALL, qName); + } + // done + return list.iterator(); + } + public Iterator getChildAxisIterator(Object o) throws UnsupportedAxisException { // Iterator of ChildAxisRef @@ -361,6 +423,44 @@ public class DocumentNavigator extends DefaultNavigator return list.iterator(); } + /** Used to prevent crazy ordering code in from repeatedly getting child association */ + private static final UnsupportedAxisException EXCEPTION_NOT_SUPPORTED = new UnsupportedAxisException(""); + /** + * @see #EXCEPTION_NOT_SUPPORTED always thrown + */ + @Override + public Iterator getFollowingSiblingAxisIterator(Object arg0) throws UnsupportedAxisException + { + throw EXCEPTION_NOT_SUPPORTED; + } + + /** + * @see #EXCEPTION_NOT_SUPPORTED always thrown + */ + @Override + public Iterator getFollowingAxisIterator(Object arg0) throws UnsupportedAxisException + { + throw EXCEPTION_NOT_SUPPORTED; + } + + /** + * @see #EXCEPTION_NOT_SUPPORTED always thrown + */ + @Override + public Iterator getPrecedingAxisIterator(Object arg0) throws UnsupportedAxisException + { + throw EXCEPTION_NOT_SUPPORTED; + } + + /** + * @see #EXCEPTION_NOT_SUPPORTED always thrown + */ + @Override + public Iterator getPrecedingSiblingAxisIterator(Object arg0) throws UnsupportedAxisException + { + throw EXCEPTION_NOT_SUPPORTED; + } + public Iterator getNamespaceAxisIterator(Object o) throws UnsupportedAxisException { // Iterator of Namespace