use of com.axway.ats.agent.core.templateactions.model.matchers.mode.TemplateBodyNodeMatchMode in project ats-framework by Axway.
the class AbstractActionObject method resolveXpathEntries.
// TODO: use Deque (non-synchronized) impl. instead of Stack
protected void resolveXpathEntries(Node node, Stack<String> nodeXpath, Map<String, Integer> allNodesIndexMap) throws DOMException, InvalidMatcherException {
String name = node.getNodeName();
// calculate the XPath for this node
String nodeXpathString = name;
if (nodeXpath.size() > 0) {
nodeXpathString = nodeXpath.peek().toString() + "/" + nodeXpathString;
}
// calculate the index for this node
Integer nodeIndex = allNodesIndexMap.get(nodeXpathString);
if (nodeIndex == null) {
nodeIndex = 1;
} else {
nodeIndex = nodeIndex + 1;
}
allNodesIndexMap.put(nodeXpathString, nodeIndex);
// calculate the XPath for this node including its index
String nodeXpathWithIndexString = nodeXpathString + "[" + nodeIndex + "]";
nodeXpath.push(nodeXpathWithIndexString);
NodeList nodeList = node.getChildNodes();
for (int i = 0; i < nodeList.getLength(); i++) {
Node currentNode = nodeList.item(i);
if (currentNode != null && currentNode.getNodeType() == Node.TEXT_NODE) {
String nodeValue = currentNode.getNodeValue();
if (nodeValue != null) {
nodeValue = nodeValue.trim();
if (nodeValue.contains("${")) {
// this node contains a user parameter we are interested in
String xpath = "//" + nodeXpath.peek();
TemplateBodyNodeMatchMode matchMode;
if (nodeValue.contains("${=")) {
// retriever
matchMode = TemplateBodyNodeMatchMode.EXTRACT;
} else {
// matcher
if (nodeValue.startsWith("${CONTAINS=")) {
nodeValue = nodeValue.substring("${CONTAINS=".length(), nodeValue.length() - 1);
matchMode = TemplateBodyNodeMatchMode.CONTAINS;
} else if (nodeValue.startsWith("${EQUALS=")) {
nodeValue = nodeValue.substring("${EQUALS=".length(), nodeValue.length() - 1);
matchMode = TemplateBodyNodeMatchMode.EQUALS;
} else if (nodeValue.startsWith("${RANGE=")) {
nodeValue = nodeValue.substring("${RANGE=".length(), nodeValue.length() - 1);
matchMode = TemplateBodyNodeMatchMode.RANGE;
} else if (nodeValue.startsWith("${LIST=")) {
nodeValue = nodeValue.substring("${LIST=".length(), nodeValue.length() - 1);
matchMode = TemplateBodyNodeMatchMode.LIST;
} else if (nodeValue.startsWith("${REGEX=")) {
nodeValue = nodeValue.substring("${REGEX=".length(), nodeValue.length() - 1);
matchMode = TemplateBodyNodeMatchMode.REGEX;
} else {
// ignore user parameters e.g. ${targetHost}
continue;
}
}
XPathBodyMatcher xPathMatcher = new XPathBodyMatcher(xpath, nodeValue, matchMode);
log.debug("Extraceted XPath matcher: " + xPathMatcher.toString());
xpathBodyMatchers.add(xPathMatcher);
}
}
} else {
// a regular node, search its children
resolveXpathEntries(currentNode, nodeXpath, allNodesIndexMap);
}
}
nodeXpath.pop();
}
Aggregations