/** * Support for reporting HTML attribute changes. This method can be called when an attribute * has been added and it will send the appropriate {@link HtmlAttributeChangeEvent} to any * registered {@link HtmlAttributeChangeListener}s. * * Note that this method recursively calls this element's parent's * {@link #fireHtmlAttributeAdded(HtmlAttributeChangeEvent)} method. * * @param event the event * @see #addHtmlAttributeChangeListener(HtmlAttributeChangeListener) */ protected void fireHtmlAttributeAdded(final HtmlAttributeChangeEvent event) { final DomNode parentNode = getParentNode(); if (parentNode instanceof HtmlElement) { ((HtmlElement) parentNode).fireHtmlAttributeAdded(event); } }
/** * Support for reporting HTML attribute changes. This method can be called when an attribute * has been replaced and it will send the appropriate {@link HtmlAttributeChangeEvent} to any * registered {@link HtmlAttributeChangeListener}s. * * Note that this method recursively calls this element's parent's * {@link #fireHtmlAttributeReplaced(HtmlAttributeChangeEvent)} method. * * @param event the event * @see #addHtmlAttributeChangeListener(HtmlAttributeChangeListener) */ protected void fireHtmlAttributeReplaced(final HtmlAttributeChangeEvent event) { final DomNode parentNode = getParentNode(); if (parentNode instanceof HtmlElement) { ((HtmlElement) parentNode).fireHtmlAttributeReplaced(event); } }
/** * Support for reporting HTML attribute changes. This method can be called when an attribute * has been added and it will send the appropriate {@link HtmlAttributeChangeEvent} to any * registered {@link HtmlAttributeChangeListener}s. * * Note that this method recursively calls this element's parent's * {@link #fireHtmlAttributeAdded(HtmlAttributeChangeEvent)} method. * * @param event the event * @see #addHtmlAttributeChangeListener(HtmlAttributeChangeListener) */ protected void fireHtmlAttributeAdded(final HtmlAttributeChangeEvent event) { final DomNode parentNode = getParentNode(); if (parentNode instanceof HtmlElement) { ((HtmlElement) parentNode).fireHtmlAttributeAdded(event); } }
/** * Support for reporting HTML attribute changes. This method can be called when an attribute * has been replaced and it will send the appropriate {@link HtmlAttributeChangeEvent} to any * registered {@link HtmlAttributeChangeListener}s. * * Note that this method recursively calls this element's parent's * {@link #fireHtmlAttributeReplaced(HtmlAttributeChangeEvent)} method. * * @param event the event * @see #addHtmlAttributeChangeListener(HtmlAttributeChangeListener) */ protected void fireHtmlAttributeReplaced(final HtmlAttributeChangeEvent event) { final DomNode parentNode = getParentNode(); if (parentNode instanceof HtmlElement) { ((HtmlElement) parentNode).fireHtmlAttributeReplaced(event); } }
/** * {@inheritDoc} */ @Override public void ignoredStartElement(final QName elem, final XMLAttributes attrs, final Augmentations augs) { // when multiple body elements are encountered, the attributes of the discarded // elements are used when not previously defined if (body_ != null && "body".equalsIgnoreCase(elem.localpart) && attrs != null) { copyAttributes(body_, attrs); } if (body_ != null && "html".equalsIgnoreCase(elem.localpart) && attrs != null) { copyAttributes((DomElement) body_.getParentNode(), attrs); } }
/** * {@inheritDoc} */ @Override public void ignoredStartElement(final QName elem, final XMLAttributes attrs, final Augmentations augs) { // when multiple body elements are encountered, the attributes of the discarded // elements are used when not previously defined if (body_ != null && "body".equalsIgnoreCase(elem.localpart) && attrs != null) { copyAttributes(body_, attrs); } if (body_ != null && "html".equalsIgnoreCase(elem.localpart) && attrs != null) { copyAttributes((DomElement) body_.getParentNode(), attrs); } }
/** * Returns the first element with the specified tag name that is an ancestor to this element, or * {@code null} if no such element is found. * @param tagName the name of the tag searched (case insensitive) * @return the first element with the specified tag name that is an ancestor to this element */ public HtmlElement getEnclosingElement(final String tagName) { final String tagNameLC = tagName.toLowerCase(Locale.ROOT); for (DomNode currentNode = getParentNode(); currentNode != null; currentNode = currentNode.getParentNode()) { if (currentNode instanceof HtmlElement && currentNode.getNodeName().equals(tagNameLC)) { return (HtmlElement) currentNode; } } return null; }
/** * Returns the first element with the specified tag name that is an ancestor to this element, or * {@code null} if no such element is found. * @param tagName the name of the tag searched (case insensitive) * @return the first element with the specified tag name that is an ancestor to this element */ public HtmlElement getEnclosingElement(final String tagName) { final String tagNameLC = tagName.toLowerCase(Locale.ROOT); for (DomNode currentNode = getParentNode(); currentNode != null; currentNode = currentNode.getParentNode()) { if (currentNode instanceof HtmlElement && currentNode.getNodeName().equals(tagNameLC)) { return (HtmlElement) currentNode; } } return null; }
/** * Returns the first element with the specified tag name that is an ancestor to this element, or * <tt>null</tt> if no such element is found. * @param tagName the name of the tag searched (case insensitive) * @return the first element with the specified tag name that is an ancestor to this element */ public HtmlElement getEnclosingElement(final String tagName) { final String tagNameLC = tagName.toLowerCase(); DomNode currentNode = getParentNode(); while (currentNode != null) { if (currentNode instanceof HtmlElement && currentNode.getNodeName().equals(tagNameLC)) { return (HtmlElement) currentNode; } currentNode = currentNode.getParentNode(); } return null; }
/** * Returns the first element with the specified tag name that is an ancestor to this element, or * <tt>null</tt> if no such element is found. * @param tagName the name of the tag searched (case insensitive) * @return the first element with the specified tag name that is an ancestor to this element */ public HtmlElement getEnclosingElement(final String tagName) { final String tagNameLC = tagName.toLowerCase(); DomNode currentNode = getParentNode(); while (currentNode != null) { if (currentNode instanceof HtmlElement && currentNode.getNodeName().equals(tagNameLC)) { return (HtmlElement) currentNode; } currentNode = currentNode.getParentNode(); } return null; }
/** * Returns the first element with the specified tag name that is an ancestor to this element, or * <tt>null</tt> if no such element is found. * @param tagName the name of the tag searched (case insensitive) * @return the first element with the specified tag name that is an ancestor to this element */ public HtmlElement getEnclosingElement(final String tagName) { final String tagNameLC = tagName.toLowerCase(); DomNode currentNode = getParentNode(); while (currentNode != null) { if (currentNode instanceof HtmlElement && currentNode.getNodeName().equals(tagNameLC)) { return (HtmlElement) currentNode; } currentNode = currentNode.getParentNode(); } return null; }
/** * Support for reporting HTML attribute changes. This method can be called when an attribute * has been removed and it will send the appropriate {@link HtmlAttributeChangeEvent} to any * registered {@link HtmlAttributeChangeListener}s. * * Note that this method recursively calls this element's parent's * {@link #fireHtmlAttributeRemoved(HtmlAttributeChangeEvent)} method. * * @param event the event * @see #addHtmlAttributeChangeListener(HtmlAttributeChangeListener) */ protected void fireHtmlAttributeRemoved(final HtmlAttributeChangeEvent event) { synchronized (attributeListeners_) { for (final HtmlAttributeChangeListener listener : attributeListeners_) { listener.attributeRemoved(event); } } final DomNode parentNode = getParentNode(); if (parentNode instanceof HtmlElement) { ((HtmlElement) parentNode).fireHtmlAttributeRemoved(event); } }
/** * Submits the form by clikcing the submit button of the given name. * * @param name * This corresponds to the @name of {@code <f:submit />} */ public HtmlPage submit(HtmlForm form, String name) throws Exception { for( HtmlElement e : form.getElementsByTagName("button")) { HtmlElement p = (HtmlElement)e.getParentNode().getParentNode(); if (e instanceof HtmlButton && p.getAttribute("name").equals(name)) { return (HtmlPage)HtmlFormUtil.submit(form, (HtmlButton) e); } } throw new AssertionError("No such submit button with the name "+name); }
/** * {@inheritDoc} */ @Override public String getCanonicalXPath() { final DomNode parent = getParentNode(); if (parent.getNodeType() == DOCUMENT_NODE) { return "/" + getNodeName(); } return parent.getCanonicalXPath() + '/' + getXPathToken(); }
/** * Returns the {@code isContentEditable} property. * @return the {@code isContentEditable} property */ @JsxGetter public boolean isIsContentEditable() { final String attribute = getContentEditable(); if ("true".equals(attribute)) { return true; } else if ("inherit".equals(attribute)) { final DomNode parent = getDomNodeOrDie().getParentNode(); if (parent != null) { final Object parentScriptable = parent.getScriptableObject(); if (parentScriptable instanceof HTMLElement) { return ((HTMLElement) parentScriptable).isIsContentEditable(); } } } return false; }
/** * Returns the {@code isContentEditable} property. * @return the {@code isContentEditable} property */ @JsxGetter public boolean isIsContentEditable() { final String attribute = getContentEditable(); if ("true".equals(attribute)) { return true; } else if ("inherit".equals(attribute)) { final DomNode parent = getDomNodeOrDie().getParentNode(); if (parent != null) { final Object parentScriptable = parent.getScriptableObject(); if (parentScriptable instanceof HTMLElement) { return ((HTMLElement) parentScriptable).isIsContentEditable(); } } } return false; }
/** * {@inheritDoc} */ @Override public String getCanonicalXPath() { final DomNode parent = getParentNode(); if (parent.getNodeType() == DOCUMENT_NODE) { return "/" + getNodeName(); } return parent.getCanonicalXPath() + '/' + getXPathToken(); }
/** * Submits the form by clikcing the submit button of the given name. * * @param name * This corresponds to the @name of {@code <f:submit />} */ public HtmlPage submit(HtmlForm form, String name) throws Exception { for( HtmlElement e : form.getElementsByTagName("button")) { HtmlElement p = (HtmlElement)e.getParentNode().getParentNode(); if (p.getAttribute("name").equals(name) && HtmlElementUtil.hasClassName(p, "yui-submit-button")) { // For YUI handled submit buttons, just do a click. return (HtmlPage) HtmlElementUtil.click(e); } else if (e.getAttribute("name").equals(name)) { return (HtmlPage) HtmlFormUtil.submit(form, e); } } throw new AssertionError("No such submit button with the name "+name); }
/** * Returns the XPath token for this node only. */ private String getXPathToken() { final DomNode parent = getParentNode(); int total = 0; int nodeIndex = 0; for (final DomNode child : parent.getChildren()) { if (child.getNodeType() == ELEMENT_NODE && child.getNodeName().equals(getNodeName())) { total++; } if (child == this) { nodeIndex = total; } } if (nodeIndex == 1 && total == 1) { return getNodeName(); } return getNodeName() + '[' + nodeIndex + ']'; }
/** * Returns the XPath token for this node only. */ private String getXPathToken() { final DomNode parent = getParentNode(); int total = 0; int nodeIndex = 0; for (final DomNode child : parent.getChildren()) { if (child.getNodeType() == ELEMENT_NODE && child.getNodeName().equals(getNodeName())) { total++; } if (child == this) { nodeIndex = total; } } if (nodeIndex == 1 && total == 1) { return getNodeName(); } return getNodeName() + '[' + nodeIndex + ']'; }