@XACMLFunction({"urn:oasis:names:tc:xacml:1.0:function:xpath-node-equal"}) public static AttributeValue nodeEqual(EvaluationContext ctx, Object[] params) throws IndeterminateException { checkArguments(params, 2); AttributeValue exp1 = (AttributeValue) params[0]; AttributeValue exp2 = (AttributeValue) params[1]; checkArgumentType(exp1, Constants.TYPE_STRING); checkArgumentType(exp2, Constants.TYPE_STRING); String xpathExp1 = (String) exp1.getValue(); String xpathExp2 = (String) exp2.getValue(); try { NodeList nList1 = evaluateXPath(ctx, xpathExp1); NodeList nList2 = evaluateXPath(ctx, xpathExp2); for (int i = 0; i < nList1.getLength(); i++) { Node node1 = nList1.item(i); for (int j = 0; j < nList2.getLength(); j++) { Node node2 = nList2.item(j); if (node2.isEqualNode(node1)) { return TRUE; } } } return FALSE; } catch (IndeterminateException intEx) { throw intEx; } catch (Exception ex) { throw new IndeterminateException( "Error occurs while evaluating function nodeEqual : " + xpathExp1 + ", " + xpathExp2); } }
private static boolean isNodeMatch(Node node1, Node node2) { if (node1.isEqualNode(node2)) { return true; } else { NodeList children = node1.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (isNodeMatch(child, node2)) { return true; } } } return false; }