11-22-2015 11:14 PM
11-23-2015 07:13 AM
11-23-2015 10:25 AM
public List<NodeRef> selectNodes(NodeRef contextNodeRef, String xpathIn,
QueryParameterDefinition[] paramDefs, NamespacePrefixResolver namespacePrefixResolver,
boolean followAllParentLinks, String <strong>language</strong>) {
try
{
String xpath = xpathIn;
<strong>List<AttributeOrder> order = null;</strong>
DocumentNavigator documentNavigator = new DocumentNavigator(dictionaryService, nodeService, searchService,
namespacePrefixResolver, followAllParentLinks);
NodeServiceXPath nsXPath = new NodeServiceXPath(xpath, documentNavigator, paramDefs);
for (String prefix : namespacePrefixResolver.getPrefixes())
{
nsXPath.addNamespace(prefix, namespacePrefixResolver.getNamespaceURI(prefix));
}
@SuppressWarnings("rawtypes")
List list = nsXPath.selectNodes(nodeService.getPrimaryParent(contextNodeRef));
HashSet<NodeRef> unique = new HashSet<NodeRef>(list.size());
for (Object o : list)
{
if (o instanceof ChildAssociationRef)
{
unique.add(((ChildAssociationRef) o).getChildRef());
}
else if (o instanceof DocumentNavigator.Property)
{
unique.add(((DocumentNavigator.Property) o).parent);
}
else
{
throw new XPathException("Xpath expression must only select nodes");
}
}
List<NodeRef> answer = new ArrayList<NodeRef>(unique.size());
answer.addAll(unique);
if (order != null)…
List<AttributeOrder> order = null;
// replace element
order = new ArrayList<AttributeOrder>();
// We do not allow variable substitution with this pattern
xpath = xpath.replaceAll("element\\(\\s*(\\*|\\w*:\\w*)\\s*,\\s*(\\*|\\w*:\\w*)\\s*\\)", "$1[subtypeOf(\"$2\")]");
String split[] = xpath.split("order\\s*by\\s*", 2);
xpath = split[0];
if (split.length > 1 && split[1].length() > 0) {
String clauses[] = split[1].split("\\s,\\s");
for (String clause : clauses) {
if (clause.startsWith("@")) {
String attribute = clause.replaceFirst("@(\\p{Alpha}[\\w:]*)(?:\\s+(.*))?", "$1");
String sort = clause.replaceFirst("@(\\p{Alpha}[\\w:]*)(?:\\s+(.*))?", "$2");
if (sort.length() == 0) {
sort = "ascending";
}
QName attributeQName = QName.createQName(attribute, namespacePrefixResolver);
order.add(new AttributeOrder(attributeQName, sort.equalsIgnoreCase("ascending")));
} else if (clause.startsWith("jcr:score")) {
// ignore jcr:score ordering
} else {
throw new IllegalArgumentException("Malformed order by expression " + split[1]);
}
}
}
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.