@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); } }
@XACMLFunction({"urn:oasis:names:tc:xacml:1.0:function:xpath-node-count"}) public static AttributeValue nodeCount(EvaluationContext ctx, Object[] params) throws IndeterminateException { checkArguments(params, 1); AttributeValue exp = (AttributeValue) params[0]; checkArgumentType(exp, Constants.TYPE_STRING); String xpathExp = (String) exp.getValue(); try { NodeList nList = evaluateXPath(ctx, xpathExp); return AttributeValue.getInstance( Constants.TYPE_INTEGER, BigInteger.valueOf(nList.getLength())); } catch (IndeterminateException intEx) { throw intEx; } catch (Exception ex) { throw new IndeterminateException( "Error occurs while evaluating function nodeCount : " + xpathExp); } }