Java Code Examples for com.gargoylesoftware.htmlunit.html.HtmlElement#getPage()

The following examples show how to use com.gargoylesoftware.htmlunit.html.HtmlElement#getPage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HTMLAnchorElement.java    From htmlunit with Apache License 2.0 6 votes vote down vote up
static String getDefaultValue(final HtmlElement element) {
    String href = element.getAttributeDirect("href");

    if (DomElement.ATTRIBUTE_NOT_DEFINED == href) {
        return ""; // for example for named anchors
    }

    href = href.trim();

    final SgmlPage page = element.getPage();
    if (page == null || !page.isHtmlPage()) {
        return href;
    }

    try {
        return HtmlAnchor.getTargetUrl(href, (HtmlPage) page).toExternalForm();
    }
    catch (final MalformedURLException e) {
        return href;
    }
}
 
Example 2
Source File: HTMLAnchorElement.java    From HtmlUnit-Android with Apache License 2.0 6 votes vote down vote up
static String getDefaultValue(final HtmlElement element) {
    String href = element.getAttributeDirect("href");

    if (DomElement.ATTRIBUTE_NOT_DEFINED == href) {
        return ""; // for example for named anchors
    }

    href = href.trim();

    final SgmlPage page = element.getPage();
    if (page == null || !page.isHtmlPage()) {
        return href;
    }

    try {
        return HtmlAnchor.getTargetUrl(href, (HtmlPage) page).toExternalForm();
    }
    catch (final MalformedURLException e) {
        return href;
    }
}
 
Example 3
Source File: HTMLScriptElement.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the {@code text} property.
 * @param text the {@code text} property
 */
@JsxSetter
public void setText(final String text) {
    final HtmlElement htmlElement = getDomNodeOrDie();
    htmlElement.removeAllChildren();
    final DomNode textChild = new DomText(htmlElement.getPage(), text);
    htmlElement.appendChild(textChild);

    final HtmlScript tmpScript = (HtmlScript) htmlElement;
    tmpScript.executeScriptIfNeeded();
}
 
Example 4
Source File: HTMLUnknownElement.java    From htmlunit with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the JavaScript property {@code nodeName} for the current node.
 * @return the node name
 */
@Override
public String getNodeName() {
    final HtmlElement elem = getDomNodeOrDie();
    final Page page = elem.getPage();
    if (page instanceof XmlPage) {
        return elem.getLocalName();
    }
    return super.getNodeName();
}
 
Example 5
Source File: HTMLScriptElement.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the {@code text} property.
 * @param text the {@code text} property
 */
@JsxSetter
public void setText(final String text) {
    final HtmlElement htmlElement = getDomNodeOrDie();
    htmlElement.removeAllChildren();
    final DomNode textChild = new DomText(htmlElement.getPage(), text);
    htmlElement.appendChild(textChild);

    final HtmlScript tmpScript = (HtmlScript) htmlElement;
    tmpScript.executeScriptIfNeeded();
}
 
Example 6
Source File: HTMLUnknownElement.java    From HtmlUnit-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the JavaScript property {@code nodeName} for the current node.
 * @return the node name
 */
@Override
public String getNodeName() {
    final HtmlElement elem = getDomNodeOrDie();
    final Page page = elem.getPage();
    if (page instanceof XmlPage) {
        return elem.getLocalName();
    }
    return super.getNodeName();
}