/** * Looks for a policy node at the specified contextual location for the specified object. * * <p>If a policy node that contains the object name is not found, a search is also done for the * default policy for all objects, with a special name ('*'). * * @param xpathContext The XPath context around the agent configuration XML document * @param currentPointer A pointer to a particular node in the document to start searching from, * such as a <code><zone></code>, <code><template></code>, or <code><agent> * </code> node. * @param policyPath The subPath, such as "requestPolicy" * @param objectName * @return */ private Element findPolicy( JXPathContext xpathContext, Pointer currentPointer, String policyPath, String objectName) { if (currentPointer != null && currentPointer.getNode() != null) { String objectPolicyPath = "policy/" + policyPath + "/object[contains(@name,'" + objectName + "')]"; JXPathContext zoneContext = xpathContext.getRelativeContext(currentPointer); Element zonePolicy = (Element) zoneContext.selectSingleNode(objectPolicyPath); if (zonePolicy != null) { return zonePolicy; } // Look for default policy for all objects at the zone level zonePolicy = (Element) zoneContext.selectSingleNode("policy/" + policyPath + "/object[@name='*']"); if (zonePolicy != null) { return zonePolicy; } } return null; }
/** 根据给定的xpath查询Page对象 */ private Page searchPageWithXpath(Object o, String... xpaths) { JXPathContext context = JXPathContext.newContext(o); Object result; for (String xpath : xpaths) { try { result = context.selectSingleNode(xpath); } catch (Exception e) { continue; } if (result instanceof Page) { return (Page) result; } } return null; }