List of usage examples for org.w3c.dom Element getParentNode
public Node getParentNode();
From source file:org.kuali.test.handlers.htmltag.KualiCapitalAssetTagHandler.java
private String getItemNumberForLocation(Element node) { String retval = ""; Node parent = node.getParentNode(); while (Utils.isElement(parent)) { if (Utils.isElement(parent.getParentNode())) { if (Constants.HTML_TAG_TYPE_TABLE.equalsIgnoreCase(parent.getParentNode().getNodeName()) && Constants.HTML_TAG_TYPE_TR.equalsIgnoreCase(parent.getNodeName())) { Element table = (Element) parent.getParentNode(); if (Constants.HTML_TAG_ATTRIBUTE_CLASS_DATATABLE .equalsIgnoreCase(table.getAttribute(Constants.HTML_TAG_ATTRIBUTE_CLASS)) && CAPITAL_ASSET_ITEMS_TABLE_SUMMARY .equalsIgnoreCase(table.getAttribute(Constants.HTML_TAG_ATTRIBUTE_SUMMARY))) { Element sibling = Utils.findPreviousSiblingNode((Element) parent, Constants.HTML_TAG_TYPE_TR); if (sibling != null) { Element td = Utils.findFirstChildNode(sibling, Constants.HTML_TAG_TYPE_TD); if (td != null) { retval = Utils.cleanDisplayText(td); break; }// w ww . ja va2s. c o m } } } } parent = parent.getParentNode(); } return retval; }
From source file:org.kuali.test.handlers.htmltag.TdTagHandler.java
/** * * @param node// w w w . j av a2 s. c o m * @return */ @Override public String getSectionName(Element node) { String retval = null; if (getTagHandler().getSectionMatcher() != null) { retval = Utils.getMatchedNodeText(getTagHandler().getSectionMatcher().getTagMatcherArray(), node); } if (StringUtils.isBlank(retval)) { Element pnode = (Element) node.getParentNode(); if ((pnode != null) && Constants.HTML_TAG_TYPE_TR.equals(pnode.getTagName())) { int row = Utils.getChildNodeIndex(pnode); if (row > 0) { retval = "row[" + row + "]"; } } } if (LOG.isDebugEnabled()) { LOG.debug("section: " + retval); } return retval; }
From source file:org.kuali.test.utils.HtmlDomProcessor.java
private String getIframeParentIds(Element node) { String retval = null;/*from w w w.j a v a 2s . c o m*/ Node pnode = node.getParentNode(); List<String> ids = new ArrayList<String>(); while (pnode != null) { if (Constants.HTML_TAG_TYPE_IFRAME.equals(pnode.getNodeName())) { Node idnode = pnode.getAttributes().getNamedItem(Constants.HTML_TAG_ATTRIBUTE_ID); if (idnode != null) { ids.add(idnode.getNodeValue()); } } pnode = pnode.getParentNode(); } if (!ids.isEmpty()) { StringBuilder s = new StringBuilder(128); String comma = ""; for (int i = ids.size() - 1; i >= 0; --i) { s.append(comma); s.append(ids.get(i)); comma = ","; } retval = s.toString(); } return retval; }
From source file:org.kuali.test.utils.JWebBrowserDocumentGenerator.java
private Element getIframeParent(Element element) { Element retval = null;// w ww.ja v a 2 s . c o m Element pnode = (Element) element.getParentNode(); while (pnode != null) { if (Constants.HTML_TAG_TYPE_IFRAME.equalsIgnoreCase(pnode.getTagName())) { retval = pnode; break; } if (pnode.getParentNode() instanceof Element) { pnode = (Element) pnode.getParentNode(); } else { break; } } return retval; }
From source file:org.kuali.test.utils.Utils.java
/** * * @param node/* ww w . j a v a 2 s . com*/ * @param parentTagMatch * @return */ public static boolean isParentTagMatchFailure(Element node, ParentTagMatch parentTagMatch) { boolean retval = false; if ((parentTagMatch != null) && (node != null)) { Set<String> parentTagNames = new HashSet<String>(); StringTokenizer st = new StringTokenizer(parentTagMatch.getParentTagName(), "|"); while (st.hasMoreTokens()) { parentTagNames.add(st.nextToken()); } Element validParent = null; Node parent = node.getParentNode(); // if we are looking for table and this is a tbody ten move up 1 level if (Constants.HTML_TAG_TYPE_TABLE.equalsIgnoreCase(parentTagMatch.getParentTagName()) && Constants.HTML_TAG_TYPE_TBODY.equalsIgnoreCase(parent.getNodeName())) { parent = parent.getParentNode(); } if (isElement(parent)) { if (parentTagNames.contains(parent.getNodeName())) { if (parentTagMatch.getMatchAttributes() != null) { if (parentTagMatch.getMatchAttributes().sizeOfMatchAttributeArray() > 0) { boolean ok = true; for (TagMatchAttribute att : parentTagMatch.getMatchAttributes() .getMatchAttributeArray()) { String parentAttr = ((Element) parent).getAttribute(att.getName()); if (StringUtils.isNotBlank(parentAttr)) { int pos = att.getValue().indexOf('*'); if (pos > -1) { if (pos == 0) { ok = parentAttr.endsWith(att.getValue().substring(1)); } else { String s1 = att.getValue().substring(0, pos); String s2 = att.getValue().substring(pos + 1); ok = (parentAttr.startsWith(s1) && parentAttr.endsWith(s2)); } } else { ok = parentAttr.equalsIgnoreCase(att.getValue()); } } else { ok = false; } if (!ok) { break; } } if (ok) { validParent = (Element) parent; } } } else { validParent = (Element) parent; } } } retval = (validParent == null); } return retval; }
From source file:org.kuali.test.utils.Utils.java
/** * * @param tm/*from w ww . j a v a 2s . c om*/ * @param node * @return */ public static Element getMatchingParent(TagMatcher tm, Element node) { Element retval = null; Node parent = node.getParentNode(); int cnt = 0; int totalCnt = Integer.MAX_VALUE; boolean limited = false; String sdef = tm.getSearchDefinition(); if (StringUtils.isNotBlank(sdef)) { if (StringUtils.isNumeric(sdef)) { totalCnt = Integer.parseInt(sdef); limited = true; } } while ((cnt < totalCnt) && isElement(parent)) { if (parent.getNodeName().equalsIgnoreCase(tm.getTagName())) { cnt++; TagMatchAttribute[] attrs = null; if (tm.getMatchAttributes() != null) { attrs = tm.getMatchAttributes().getMatchAttributeArray(); } if ((!limited || (cnt == totalCnt)) && isTagMatch((Element) parent, tm)) { retval = (Element) parent; break; } } parent = parent.getParentNode(); } return retval; }
From source file:org.kuali.test.utils.Utils.java
/** * * @param node/*from ww w . ja va 2 s .c o m*/ * @return */ public static Element getParentNodeByTagName(Element node, String parentTagName) { Element retval = null; Element curnode = (Element) node.getParentNode(); while (curnode != null) { if (parentTagName.equalsIgnoreCase(curnode.getTagName())) { retval = curnode; break; } if (curnode.getParentNode() instanceof Element) { curnode = (Element) curnode.getParentNode(); } else { break; } } return retval; }
From source file:org.kuali.test.utils.Utils.java
/** * * @param tm//from w w w . ja v a 2s . com * @param node * @return */ public static Element getMatchingSibling(TagMatcher tm, Element node) { Element retval = null; String searchDefinition = tm.getSearchDefinition(); // default to search all children forward if (StringUtils.isBlank(searchDefinition)) { searchDefinition = "+*"; } int startIndex = getChildNodeIndex(node); int cnt = 0; switch (getSiblingNodeSearchDirection(searchDefinition)) { case Constants.SIBLING_NODE_SEARCH_DIRECTION_PREVIOUS: if (startIndex > -1) { int targetCnt = Integer.MAX_VALUE; boolean limited = true; // if we have an * then loop through all siblings if (!searchDefinition.substring(1).equals("*")) { targetCnt = Integer.parseInt(searchDefinition.substring(1)); } else { limited = false; } Element prev = getPreviousSiblingElement(node); while ((prev != null) && (cnt < targetCnt)) { cnt++; if (!limited || (cnt == targetCnt)) { if (prev.getNodeName().equalsIgnoreCase(tm.getTagName()) && isTagMatch(prev, tm)) { retval = prev; } if (limited || (retval != null)) { break; } } prev = getPreviousSiblingElement(prev); } } break; case Constants.SIBLING_NODE_SEARCH_DIRECTION_NEXT: if (startIndex > -1) { int targetCnt = Integer.MAX_VALUE; boolean limited = true; // if we have an * then loop through all siblins if (!searchDefinition.substring(1).equals("*")) { if (StringUtils.isBlank(searchDefinition.substring(1))) { targetCnt = 1; } else { targetCnt = Integer.parseInt(searchDefinition.substring(1)); } } else { limited = false; } Element next = getNextSiblingElement(node); while ((next != null) && (cnt < targetCnt)) { cnt++; if (!limited || (cnt == targetCnt)) { if (next.getNodeName().equalsIgnoreCase(tm.getTagName()) && isTagMatch(next, tm)) { retval = next; } if (limited || (retval != null)) { break; } } next = getNextSiblingElement(next); } } break; case Constants.SIBLING_NODE_SEARCH_DIRECTION_ABSOLUTE: if (startIndex > -1) { int targetCnt = Integer.MAX_VALUE; boolean limited = true; // if we have an * then loop through all chiildren if (!searchDefinition.equals("*")) { targetCnt = Integer.parseInt(searchDefinition); } else { limited = false; } for (Element child : getChildElements((Element) node.getParentNode())) { cnt++; if (!limited || (cnt == targetCnt)) { if (child.getNodeName().equalsIgnoreCase(tm.getTagName()) && isTagMatch(child, tm)) { retval = child; } if (limited || (retval != null)) { break; } } } } break; } return retval; }
From source file:org.kuali.test.utils.Utils.java
/** * * @param node/*from w w w . j a va2 s . c o m*/ * @return */ public static int getSiblingIndex(Element node) { int retval = -1; Element parent = (Element) node.getParentNode(); int indx = 0; for (Node curnode : getChildElements(parent)) { if (node == curnode) { retval = indx; break; } indx++; } return retval; }
From source file:org.kuali.test.utils.Utils.java
/** * * @param node/*ww w. j a v a 2s . co m*/ * @return */ public static int getSiblingIndexByTagType(Element node) { int retval = 0; Element parent = (Element) node.getParentNode(); for (Element sibling : getChildElements(parent)) { if (getChildNodeIndex(sibling) == getChildNodeIndex(node)) { break; } if (sibling.getNodeName().equals(node.getNodeName())) { retval++; } } return retval; }