From: Seth P. <se...@us...> - 2004-05-12 21:25:21
|
Update of /cvsroot/sunxacml/sunxacml/com/sun/xacml/finder/impl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16761/com/sun/xacml/finder/impl Modified Files: SelectorModule.java Log Message: fixed namespace mapping to use policy namespace definitions Index: SelectorModule.java =================================================================== RCS file: /cvsroot/sunxacml/sunxacml/com/sun/xacml/finder/impl/SelectorModule.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SelectorModule.java 17 Mar 2004 18:03:39 -0000 1.6 --- SelectorModule.java 12 May 2004 21:25:10 -0000 1.7 *************** *** 57,60 **** --- 57,61 ---- import org.apache.xpath.XPathAPI; + import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; import org.w3c.dom.NodeList; *************** *** 64,72 **** * This module implements the basic behavior of the AttributeSelectorType, * looking for attribute values in the physical request document using the ! * given XPath expression. This is implemented as a separate module instead ! * of in the core code (like the designator code) so that programmers can ! * remove this functionality if they want (it's optional in the spec), so ! * they can replace this code with more efficient, specific code as needed, ! * and so they can easily swap in different XPath libraries. * <p> * Note that if no matches are found, this module will return an empty bag --- 65,73 ---- * This module implements the basic behavior of the AttributeSelectorType, * looking for attribute values in the physical request document using the ! * given XPath expression. This is implemented as a separate module (instead ! * of being implemented directly in <code>AttributeSelector</code> so that ! * programmers can remove this functionality if they want (it's optional in ! * the spec), so they can replace this code with more efficient, specific ! * code as needed, and so they can easily swap in different XPath libraries. * <p> * Note that if no matches are found, this module will return an empty bag *************** *** 76,80 **** * <p> * This module uses the Xalan XPath implementation, and supports only version ! * 1.0 of XPath. * * @since 1.0 --- 77,84 ---- * <p> * This module uses the Xalan XPath implementation, and supports only version ! * 1.0 of XPath. It is a fully functional, correct implementation of XACML's ! * AttributeSelector functionality, but is not designed for environments ! * that make significant use of XPath queries. Developers for any such ! * environment should consider implementing their own module. * * @since 1.0 *************** *** 110,113 **** --- 114,119 ---- * * @param path the XPath expression to search against + * @param namespaceNode the DOM node defining namespace mappings to use, + * or null if mappings come from the context root * @param type the datatype of the attributes to find * @param context the representation of the request data *************** *** 117,122 **** * attributes or an error */ ! public EvaluationResult findAttribute(String path, URI type, ! EvaluationCtx context, String xpathVersion) { // we only support 1.0 --- 123,128 ---- * attributes or an error */ ! public EvaluationResult findAttribute(String path, Node namespaceNode, ! URI type, EvaluationCtx context, String xpathVersion) { // we only support 1.0 *************** *** 126,134 **** // get the DOM root of the request document Node root = context.getRequestRoot(); ! NodeList matches = null; try { // NOTE: see comments in XALAN docs about why this is slow ! matches = XPathAPI.selectNodeList(root, path); } catch (Exception e) { // in the case of any exception, we need to return an error --- 132,197 ---- // get the DOM root of the request document Node root = context.getRequestRoot(); ! ! // if we were provided with a non-null namespace node, then use it ! // to resolve namespaces, otherwise use the context root node ! Node nsNode = (namespaceNode != null) ? namespaceNode : root; ! ! // setup the root path (pre-pended to the context path), which... ! String rootPath = ""; ! ! // ...only has content if the context path is relative ! if (path.charAt(0) != '/') { ! String rootName = root.getLocalName(); ! ! // see if the request root is in a namespace ! String namespace = root.getNamespaceURI(); ! ! if (namespace == null) { ! // no namespacing, so we're done ! rootPath = "/" + rootName + "/"; ! } else { ! // namespaces are used, so we need to lookup the correct ! // prefix to use in the search string ! NamedNodeMap nmap = namespaceNode.getAttributes(); ! rootPath = null; ! ! for (int i = 0; i < nmap.getLength(); i++) { ! Node n = nmap.item(i); ! if (n.getNodeValue().equals(namespace)) { ! // we found the matching namespace, so get the prefix ! // and then break out ! String name = n.getNodeName(); ! int pos = name.indexOf(':'); ! ! if (pos == -1) { ! // the namespace was the default namespace ! rootPath = "/"; ! } else { ! // we found a prefixed namespace ! rootPath = "/" + name.substring(pos + 1); ! } ! ! // finish off the string ! rootPath += ":" + rootName + "/"; ! ! break; ! } ! } ! ! // if the rootPath is still null, then we don't have any ! // definitions for the namespace ! if (rootPath == null) { ! // FIXME: should this be an error, or should we add ! // the namespace somehow? ! } ! } ! } ! ! // now do the query, pre-pending the root path to the context path NodeList matches = null; try { // NOTE: see comments in XALAN docs about why this is slow ! System.out.println("asking for: " + rootPath + path); ! matches = XPathAPI.selectNodeList(root, rootPath + path, nsNode); } catch (Exception e) { // in the case of any exception, we need to return an error |