public Object visit(PathQueryNode node, Object data) throws RepositoryException { StringBuffer sb = (StringBuffer) data; if (node.isAbsolute()) { sb.append("/"); } LocationStepQueryNode[] steps = node.getPathSteps(); String slash = ""; for (int i = 0; i < steps.length; i++) { sb.append(slash); steps[i].accept(this, sb); slash = "/"; } return sb; }
public Object visit(LocationStepQueryNode node, Object data) throws RepositoryException { return node.acceptOperands(this, data); }
LocationStepQueryNode n1 = (LocationStepQueryNode) operands.get(size - 1); LocationStepQueryNode n2 = (LocationStepQueryNode) operands.get(size - 2); if (n1.getNameTest() != null || n2.getNameTest() != null || !n1.getIncludeDescendants() || !n2.getIncludeDescendants()) { throw new NoSuchElementException("Merging not possible"); LocationStepQueryNode step = (LocationStepQueryNode) operands.get(j); LocationStepQueryNode other = (LocationStepQueryNode) nodes[i].operands.get(j); match &= (step.getNameTest() == null) ? other.getNameTest() == null : step.getNameTest().equals(other.getNameTest()); ((LocationStepQueryNode) matchedNode.operands.get(matchedNode.operands.size() - 1)).setIncludeDescendants(false); return nodes;
/** * Returns <code>true</code> if this node needs merging; <code>false</code> * otherwise. * * @return <code>true</code> if this node needs merging; <code>false</code> * otherwise. */ boolean needsMerge() { for (Iterator it = operands.iterator(); it.hasNext();) { LocationStepQueryNode step = (LocationStepQueryNode) it.next(); if (step.getIncludeDescendants() && step.getNameTest() == null) { return true; } } return false; } }
public Object visit(LocationStepQueryNode node, Object data) throws RepositoryException { StringBuffer buffer = (StringBuffer) data; buffer.append(PADDING, 0, indent); buffer.append("+ LocationStepQueryNode: "); buffer.append(" NodeTest="); if (node.getNameTest() == null) { buffer.append("*"); } else { buffer.append(node.getNameTest()); } buffer.append(" Descendants=").append(node.getIncludeDescendants()); buffer.append(" Index="); if (node.getIndex() == LocationStepQueryNode.NONE) { buffer.append("NONE"); } else if (node.getIndex() == LocationStepQueryNode.LAST) { buffer.append("last()"); } else { buffer.append(node.getIndex()); } buffer.append("\n"); traverse(node.getOperands(), buffer); return buffer; }
public Object visit(LocationStepQueryNode node, Object data) { StringBuffer sb = (StringBuffer) data; if (node.getNameTest() == null) { sb.append("%"); } else { if (node.getNameTest().getLocalName().length() > 0) { try { sb.append(resolver.getJCRName(node.getNameTest())); } catch (NamespaceException e) { exceptions.add(e); } if (node.getIndex() == LocationStepQueryNode.NONE) { sb.append("[%]"); } else if (node.getIndex() == 1) { // do nothing } else { sb.append('[').append(node.getIndex()).append(']'); } } else { // empty name test indicates root node } } return sb; }
Object[] predicates = node.acceptOperands(this, data); for (Object predicate : predicates) { andQuery.add((Query) predicate, Occur.MUST); QueryNode[] pred = node.getPredicates(); for (QueryNode aPred : pred) { if (aPred.getType() == QueryNode.TYPE_RELATION) { RelationQueryNode pos = (RelationQueryNode) aPred; if (pos.getValueType() == QueryConstants.TYPE_POSITION) { node.setIndex(pos.getPositionValue()); if (node.getNameTest() != null) { if (node.getNameTest().equals(PARENT_ELEMENT_NAME)) { andQuery.add(new ParentAxisQuery(context, null, indexFormatVersion, nsMappings), Occur.MUST); return andQuery; nameTest = new NameQuery(node.getNameTest(), indexFormatVersion, nsMappings); if (node.getIncludeDescendants()) { if (nameTest != null) { andQuery.add(new DescendantSelfAxisQuery(context, nameTest, false), Occur.MUST); PathQueryNode pathNode = (PathQueryNode) node.getParent(); if (pathNode.getPathSteps()[0] != node) { Query subQuery = new DescendantSelfAxisQuery(context, andQuery, false); PathQueryNode pathNode = (PathQueryNode) node.getParent(); if (pathNode.getPathSteps()[0] != node) { if (node.getIndex() == LocationStepQueryNode.NONE) {
if (pathConstraints.size() == 0) { LocationStepQueryNode step = factory.createLocationStepQueryNode(pathNode); step.setNameTest(null); step.setIncludeDescendants(true); pathNode.addPathStep(step); } else { for (int i = 0; i < steps.length; i++) { LocationStepQueryNode step = factory.createLocationStepQueryNode(pathNode); step.setNameTest(steps[i].getNameTest()); step.setIncludeDescendants(steps[i].getIncludeDescendants()); step.setIndex(steps[i].getIndex()); pathNode.addPathStep(step); steps[steps.length - 1].addPredicate(constraintNode.getOperands()[0]); } else if (constraintNode.getNumOperands() > 1) { steps[steps.length - 1].addPredicate(constraintNode); NodeTypeQueryNode nodeType = factory.createNodeTypeQueryNode(steps[steps.length - 1], nodeTypeName); steps[steps.length - 1].addPredicate(nodeType);
public Object visit(LocationStepQueryNode node, Object data) throws RepositoryException { StringBuffer sb = (StringBuffer) data; if (node.getIncludeDescendants()) { sb.append('/'); node.acceptOperands(new DefaultQueryNodeVisitor() { public Object visit(NodeTypeQueryNode node, Object data) { nodeType[0] = node.getValue(); if (node.getNameTest() == null) { sb.append("*"); } else { try { if (node.getNameTest().getLocalName().length() == 0) { sb.append(resolver.getJCRName(XPathQueryBuilder.JCR_ROOT)); } else { sb.append(resolver.getJCRName(encode(node.getNameTest()))); if (node.getIndex() != LocationStepQueryNode.NONE) { sb.append('[').append(node.getIndex()).append(']'); QueryNode[] predicates = node.getPredicates(); for (int i = 0; i < predicates.length; i++) {
LocationStepQueryNode[] steps = node.getPathSteps(); if (steps.length > 0) { if (node.isAbsolute() && !steps[0].getIncludeDescendants()) { Name nameTest = steps[0].getNameTest(); if (nameTest == null) { Object[] predicates = steps[0].acceptOperands(this, context); BooleanQuery andQuery = new BooleanQuery(); for (Object predicate : predicates) { context = (Query) step.accept(this, context);
LocationStepQueryNode[] steps = node.getPathSteps(); for (int i = 0; i < steps.length; i++) { if (steps[i].getNameTest() == null || steps[i].getNameTest().getLocalName().length() > 0) { sb.append('/'); if (steps[i].getIncludeDescendants()) { sb.append("%/"); steps[i].accept(this, sb); sb.append(" LIKE '"); for (int i = 0; i < steps.length; i++) { if (steps[i].getNameTest() == null || steps[i].getNameTest().getLocalName().length() > 0) { sb.append('/'); if (steps[i].getNameTest() != null) { steps[i].accept(this, sb); LocationStepQueryNode[] steps = node.getPathSteps(); for (int i = 0; i < steps.length; i++) { if (steps[i].getNameTest() == null || steps[i].getNameTest().getLocalName().length() > 0) { path.append('/'); steps[i].accept(this, path); LocationStepQueryNode[] steps = node.getPathSteps();
QueryNode[] predicates = steps[steps.length - 1].getPredicates(); && steps[1].getIncludeDescendants() && steps[1].getNameTest() == null) { && steps[0].getIncludeDescendants() && steps[0].getNameTest() == null) {
LocationStepQueryNode[] steps = relPath.getPathSteps(); Name nameTest = steps[steps.length-1].getNameTest(); if (nameTest==null) { if (queryNode.getType() == QueryNode.TYPE_LOCATION) { LocationStepQueryNode loc = (LocationStepQueryNode) queryNode; loc.setNameTest(JCR_XMLTEXT); Name nt = resolver.getQName(ntName); NodeTypeQueryNode nodeType = factory.createNodeTypeQueryNode(loc, nt); loc.addPredicate(nodeType); } catch (NameException e) { exceptions.add(new InvalidQueryException("Not a valid name: " + ntName)); if (node.getId() == JJTINTEGERLITERAL) { int index = Integer.parseInt(node.getValue()); ((LocationStepQueryNode) queryNode).setIndex(index); } else { exceptions.add(new InvalidQueryException("LocationStep only allows integer literal as position index")); case JJTDOTDOT: if (queryNode instanceof LocationStepQueryNode) { ((LocationStepQueryNode) queryNode).setNameTest(PATH_FACTORY.getParentElement().getName()); } else { ((RelationQueryNode) queryNode).addPathElement(PATH_FACTORY.getParentElement());
((RelationQueryNode) queryNode).setPositionValue(1); } else if (queryNode.getType() == QueryNode.TYPE_LOCATION) { ((LocationStepQueryNode) queryNode).setIndex(1); } else { exceptions.add(new InvalidQueryException("Unsupported location for first()")); ((RelationQueryNode) queryNode).setPositionValue(LocationStepQueryNode.LAST); } else if (queryNode.getType() == QueryNode.TYPE_LOCATION) { ((LocationStepQueryNode) queryNode).setIndex(LocationStepQueryNode.LAST); } else { exceptions.add(new InvalidQueryException("Unsupported location for last()")); LocationStepQueryNode loc = (LocationStepQueryNode) queryNode; descendant = loc.getIncludeDescendants(); queryNode = loc.getParent(); ((NAryQueryNode) queryNode).removeOperand(loc);
Name firstPathStepName = pathSteps[0].getNameTest(); if (firstPathStepName == null) { QueryNode[] pathStepOperands = pathSteps[0].getOperands(); if (pathStepOperands.length > 0) { if (pathStepOperands[0] instanceof NodeTypeQueryNode) { if (firstWorkspaceRelativeStep.getIncludeDescendants()) { return true; Name firstWorkspaceRelativeName = firstWorkspaceRelativeStep.getNameTest(); if (firstWorkspaceRelativeName == null || firstWorkspaceRelativeName.equals(NameConstants.JCR_SYSTEM)) {
step.setNameTest(qName); step.setIncludeDescendants(descendant); if (index > 0) { step.setIndex(index);
if (relPath == null) { propPath.append("."); } else if (relPath.getNumOperands() > 0 && XPathQueryBuilder.FN_POSITION_FULL.equals(relPath.getPathSteps()[0].getNameTest())) { propPath.append(resolver.getJCRName(XPathQueryBuilder.FN_POSITION_FULL)); } else {
/** * {@inheritDoc} */ public LocationStepQueryNode createLocationStepQueryNode(QueryNode parent) { return new LocationStepQueryNode(parent); }
/** * Adds a predicate node to this location step. * @param predicate the node to add. */ public void addPredicate(QueryNode predicate) { addOperand(predicate); }
Object[] predicates = node.acceptOperands(this, data); for (Object predicate : predicates) { andQuery.add((Query) predicate, Occur.MUST); QueryNode[] pred = node.getPredicates(); for (QueryNode aPred : pred) { if (aPred.getType() == QueryNode.TYPE_RELATION) { RelationQueryNode pos = (RelationQueryNode) aPred; if (pos.getValueType() == QueryConstants.TYPE_POSITION) { node.setIndex(pos.getPositionValue()); if (node.getNameTest() != null) { if (node.getNameTest().equals(PARENT_ELEMENT_NAME)) { andQuery.add(new ParentAxisQuery(context, null, indexFormatVersion, nsMappings), Occur.MUST); return andQuery; nameTest = new NameQuery(node.getNameTest(), indexFormatVersion, nsMappings); if (node.getIncludeDescendants()) { if (nameTest != null) { andQuery.add(new DescendantSelfAxisQuery(context, nameTest, false), Occur.MUST); PathQueryNode pathNode = (PathQueryNode) node.getParent(); if (pathNode.getPathSteps()[0] != node) { Query subQuery = new DescendantSelfAxisQuery(context, andQuery, false); PathQueryNode pathNode = (PathQueryNode) node.getParent(); if (pathNode.getPathSteps()[0] != node) { if (node.getIndex() == LocationStepQueryNode.NONE) {