com.gargoylesoftware.htmlunit.SgmlPage

Here are the examples of the java api com.gargoylesoftware.htmlunit.SgmlPage taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

64 Examples 7

19 Source : ScriptElementSupport.java
with Apache License 2.0
from Xceptance

/**
 * Indicates if script execution is necessary and/or possible.
 *
 * @param element the element
 * @return {@code true} if the script should be executed
 */
private static boolean isExecutionNeeded(final DomElement element) {
    if (((ScriptElement) element).isExecuted()) {
        return false;
    }
    if (!element.isAttachedToPage()) {
        return false;
    }
    // If JavaScript is disabled, we don't need to execute.
    final SgmlPage page = element.getPage();
    if (!page.getWebClient().isJavaScriptEnabled()) {
        return false;
    }
    // If innerHTML or outerHTML is being parsed
    final HtmlPage htmlPage = element.getHtmlPageOrNull();
    if (htmlPage != null && htmlPage.isParsingHtmlSnippet()) {
        return false;
    }
    // If the script node is nested in an iframe, a noframes, or a noscript node, we don't need to execute.
    for (DomNode o = element; o != null; o = o.getParentNode()) {
        if (o instanceof HtmlInlineFrame || o instanceof HtmlNoFrames) {
            return false;
        }
    }
    // If the underlying page no longer owns its window, the client has moved on (possibly
    // because another script set window.location.href), and we don't need to execute.
    if (page.getEnclosingWindow() != null && page.getEnclosingWindow().getEnclosedPage() != page) {
        return false;
    }
    // If the script language is not JavaScript, we can't execute.
    final String t = element.getAttributeDirect("type");
    final String l = element.getAttributeDirect("language");
    if (!isJavaScript(element, t, l)) {
        // Was at warn level before 2.46 but other types or tricky implementations with unsupported types
        // are common out there and too many peoples out there thinking the is the root of problems.
        // Browsers are also not warning about this.
        if (LOG.isDebugEnabled()) {
            LOG.debug("Script is not JavaScript (type: '" + t + "', language: '" + l + "'). Skipping execution.");
        }
        return false;
    }
    // If the script's root ancestor node is not the page, then the script is not a part of the page.
    // If it isn't yet part of the page, don't execute the script; it's probably just being cloned.
    return element.getPage().isAncestorOf(element);
}

19 Source : HtmlRadioButtonInput.java
with Apache License 2.0
from Xceptance

/**
 * Add missing attribute if needed by fixing attribute map rather to add it afterwards as this second option
 * triggers the instantiation of the script object at a time where the DOM node has not yet been added to its
 * parent.
 */
private static Map<String, DomAttr> addValueIfNeeded(final SgmlPage page, final Map<String, DomAttr> attributes) {
    for (final String key : attributes.keySet()) {
        if ("value".equalsIgnoreCase(key)) {
            // value attribute was specified
            return attributes;
        }
    }
    // value attribute was not specified, add it
    final DomAttr newAttr = new DomAttr(page, null, "value", DEFAULT_VALUE, true);
    attributes.put("value", newAttr);
    return attributes;
}

19 Source : XSLProcessor.java
with Apache License 2.0
from Xceptance

/**
 * Starts the transformation process or resumes a previously failed transformation.
 */
@JsxFunction
public void transform() {
    final XMLDOMNode input = input_;
    final SgmlPage page = input.getDomNodeOrDie().getPage();
    if (output_ == null || !(output_ instanceof XMLDOMNode)) {
        final DomDoreplacedentFragment fragment = page.createDoreplacedentFragment();
        final XMLDOMDoreplacedentFragment node = new XMLDOMDoreplacedentFragment();
        node.setParentScope(getParentScope());
        node.setPrototype(getPrototype(node.getClreplaced()));
        node.setDomNode(fragment);
        output_ = fragment.getScriptableObject();
    }
    transform(input_, ((XMLDOMNode) output_).getDomNodeOrDie());
    final XMLSerializer serializer = new XMLSerializer(false);
    final StringBuilder output = new StringBuilder();
    for (final DomNode child : ((XMLDOMNode) output_).getDomNodeOrDie().getChildren()) {
        if (child instanceof DomText) {
            // IE: XmlPage ignores all empty text nodes (if 'xml:space' is 'default')
            // Maybe this should be changed for 'xml:space' = preserve
            // See XMLDoreplacedentTest.testLoadXML_XMLSpaceAttribute()
            if (StringUtils.isNotBlank(((DomText) child).getData())) {
                output.append(((DomText) child).getData());
            }
        } else {
            // remove trailing "\r\n"
            final String serializedString = serializer.serializeToString((XMLDOMNode) child.getScriptableObject());
            output.append(serializedString, 0, serializedString.length() - 2);
        }
    }
    output_ = output.toString();
}

19 Source : ScriptElementSupport.java
with Apache License 2.0
from null-dev

/**
 * Indicates if script execution is necessary and/or possible.
 *
 * @param element the element
 * @return {@code true} if the script should be executed
 */
private static boolean isExecutionNeeded(final DomElement element) {
    if (((ScriptElement) element).isExecuted()) {
        return false;
    }
    if (!element.isAttachedToPage()) {
        return false;
    }
    // If JavaScript is disabled, we don't need to execute.
    final SgmlPage page = element.getPage();
    if (!page.getWebClient().getOptions().isJavaScriptEnabled()) {
        return false;
    }
    // If innerHTML or outerHTML is being parsed
    final HtmlPage htmlPage = element.getHtmlPageOrNull();
    if (htmlPage != null && htmlPage.isParsingHtmlSnippet()) {
        return false;
    }
    // If the script node is nested in an iframe, a noframes, or a noscript node, we don't need to execute.
    for (DomNode o = element; o != null; o = o.getParentNode()) {
        if (o instanceof HtmlInlineFrame || o instanceof HtmlNoFrames) {
            return false;
        }
    }
    // If the underlying page no longer owns its window, the client has moved on (possibly
    // because another script set window.location.href), and we don't need to execute.
    if (page.getEnclosingWindow() != null && page.getEnclosingWindow().getEnclosedPage() != page) {
        return false;
    }
    // If the script language is not JavaScript, we can't execute.
    final String t = element.getAttributeDirect("type");
    final String l = element.getAttributeDirect("language");
    if (!isJavaScript(element, t, l)) {
        LOG.warn("Script is not JavaScript (type: " + t + ", language: " + l + "). Skipping execution.");
        return false;
    }
    // If the script's root ancestor node is not the page, then the script is not a part of the page.
    // If it isn't yet part of the page, don't execute the script; it's probably just being cloned.
    return element.getPage().isAncestorOf(element);
}

19 Source : HtmlScript.java
with Apache License 2.0
from null-dev

/**
 * Indicates if script execution is necessary and/or possible.
 *
 * @return {@code true} if the script should be executed
 */
private boolean isExecutionNeeded() {
    if (executed_) {
        return false;
    }
    if (!isAttachedToPage()) {
        return false;
    }
    // If JavaScript is disabled, we don't need to execute.
    final SgmlPage page = getPage();
    if (!page.getWebClient().getOptions().isJavaScriptEnabled()) {
        return false;
    }
    // If innerHTML or outerHTML is being parsed
    final HtmlPage htmlPage = getHtmlPageOrNull();
    if (htmlPage != null && htmlPage.isParsingHtmlSnippet()) {
        return false;
    }
    // If the script node is nested in an iframe, a noframes, or a noscript node, we don't need to execute.
    for (DomNode o = this; o != null; o = o.getParentNode()) {
        if (o instanceof HtmlInlineFrame || o instanceof HtmlNoFrames) {
            return false;
        }
    }
    // If the underlying page no longer owns its window, the client has moved on (possibly
    // because another script set window.location.href), and we don't need to execute.
    if (page.getEnclosingWindow() != null && page.getEnclosingWindow().getEnclosedPage() != page) {
        return false;
    }
    // If the script language is not JavaScript, we can't execute.
    if (!isJavaScript(getTypeAttribute(), getLanguageAttribute())) {
        final String t = getTypeAttribute();
        final String l = getLanguageAttribute();
        LOG.warn("Script is not JavaScript (type: " + t + ", language: " + l + "). Skipping execution.");
        return false;
    }
    // If the script's root ancestor node is not the page, then the script is not a part of the page.
    // If it isn't yet part of the page, don't execute the script; it's probably just being cloned.
    if (!getPage().isAncestorOf(this)) {
        return false;
    }
    return true;
}

18 Source : HTMLAnchorElement.java
with Apache License 2.0
from Xceptance

static String getDefaultValue(final HtmlElement element) {
    String href = element.getAttributeDirect("href");
    if (DomElement.ATTRIBUTE_NOT_DEFINED == href) {
        // for example for named anchors
        return "";
    }
    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;
    }
}

18 Source : XmlSerializer.java
with Apache License 2.0
from Xceptance

/**
 * @param node a node
 * @return the xml representation according to the setting of this serializer
 * @throws IOException in case of problem saving resources
 */
public String asXml(final DomElement node) throws IOException {
    builder_.setLength(0);
    indent_.setLength(0);
    final SgmlPage page = node.getPage();
    if (null != page && page.isHtmlPage()) {
        final Charset charsetName = page.getCharset();
        if (charsetName != null && node instanceof HtmlHtml) {
            builder_.append("<?xml version=\"1.0\" encoding=\"").append(charsetName).append("\"?>").append('\n');
        }
    }
    printXml(node);
    final String response = builder_.toString();
    builder_.setLength(0);
    return response;
}

18 Source : HtmlUnitNekoHtmlParser.java
with Apache License 2.0
from Xceptance

/**
 * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br>
 *
 * Returns the pre-registered element factory corresponding to the specified tag, or an UnknownElementFactory.
 * @param page the page
 * @param namespaceURI the namespace URI
 * @param qualifiedName the qualified name
 * @param insideSvg is the node inside an SVG node or not
 * @param svgSupport true if called from javascript createElementNS
 * @return the pre-registered element factory corresponding to the specified tag, or an UnknownElementFactory
 */
@Override
public ElementFactory getElementFactory(final SgmlPage page, final String namespaceURI, final String qualifiedName, final boolean insideSvg, final boolean svgSupport) {
    if (insideSvg) {
        return SVG_FACTORY;
    }
    if (namespaceURI == null || namespaceURI.isEmpty() || Html.XHTML_NAMESPACE.equals(namespaceURI) || Html.SVG_NAMESPACE.equals(namespaceURI) || !qualifiedName.contains(":")) {
        String tagName = qualifiedName;
        final int index = tagName.indexOf(':');
        if (index == -1) {
            tagName = tagName.toLowerCase(Locale.ROOT);
        } else {
            tagName = tagName.substring(index + 1);
        }
        final ElementFactory factory;
        if (svgSupport && !"svg".equals(tagName) && Html.SVG_NAMESPACE.equals(namespaceURI)) {
            factory = SVG_FACTORY;
        } else {
            factory = ELEMENT_FACTORIES.get(tagName);
        }
        if (factory != null) {
            return factory;
        }
    }
    return UnknownElementFactory.instance;
}

18 Source : HtmlTextInput.java
with Apache License 2.0
from Xceptance

/**
 * {@inheritDoc}
 */
@Override
protected void setAttributeNS(final String namespaceURI, final String qualifiedName, final String attributeValue, final boolean notifyAttributeChangeListeners, final boolean notifyMutationObservers) {
    super.setAttributeNS(namespaceURI, qualifiedName, attributeValue, notifyAttributeChangeListeners, notifyMutationObservers);
    if ("value".equals(qualifiedName)) {
        final SgmlPage page = getPage();
        if (page != null && page.isHtmlPage()) {
            int pos = 0;
            if (!hasFeature(JS_INPUT_SET_VALUE_MOVE_SELECTION_TO_START)) {
                pos = attributeValue.length();
            }
            setSelectionStart(pos);
            setSelectionEnd(pos);
        }
    }
}

18 Source : HtmlSerializer.java
with Apache License 2.0
from Xceptance

/**
 * Process {@link HtmlHiddenInput}.
 *
 * @param builder the StringBuilder to add to
 * @param domNode the target to process
 */
protected void appendDomNode(final HtmlSerializerTextBuilder builder, final DomNode domNode) {
    boolean block = false;
    if (!(domNode instanceof HtmlBody)) {
        final SgmlPage page = domNode.getPage();
        if (page != null && page.getWebClient().isJavaScriptEngineEnabled()) {
            final Object scriptableObject = domNode.getScriptableObject();
            if (scriptableObject instanceof Element) {
                final Element element = (Element) scriptableObject;
                final String display = element.getWindow().getComputedStyle(element, null).getDisplay();
                block = "block".equals(display);
            }
        }
    }
    if (block) {
        builder.appendBlockSeparator();
    }
    appendChildren(builder, domNode);
    if (block) {
        builder.appendBlockSeparator();
    }
}

18 Source : DefaultElementFactory.java
with Apache License 2.0
from Xceptance

private HtmlElement createInputElement(final String qualifiedName, final SgmlPage page, final Map<String, DomAttr> attributeMap) {
    String type = "";
    if (attributeMap != null) {
        for (final Map.Entry<String, DomAttr> entry : attributeMap.entrySet()) {
            if ("type".equalsIgnoreCase(entry.getKey())) {
                type = entry.getValue().getValue();
            }
        }
    }
    final HtmlInput result;
    switch(type.toLowerCase(Locale.ROOT)) {
        case "":
        // This not an illegal value, as it defaults to "text"
        // cf http://www.w3.org/TR/REC-html40/interact/forms.html#adef-type-INPUT
        // and the common browsers seem to treat it as a "text" input so we will as well.
        case "text":
            result = new HtmlTextInput(qualifiedName, page, attributeMap);
            break;
        case "submit":
            result = new HtmlSubmitInput(qualifiedName, page, attributeMap);
            break;
        case "checkbox":
            result = new HtmlCheckBoxInput(qualifiedName, page, attributeMap);
            break;
        case "radio":
            result = new HtmlRadioButtonInput(qualifiedName, page, attributeMap);
            break;
        case "hidden":
            result = new HtmlHiddenInput(qualifiedName, page, attributeMap);
            break;
        case "preplacedword":
            result = new HtmlPreplacedwordInput(qualifiedName, page, attributeMap);
            break;
        case "image":
            result = new HtmlImageInput(qualifiedName, page, attributeMap);
            break;
        case "reset":
            result = new HtmlResetInput(qualifiedName, page, attributeMap);
            break;
        case "button":
            result = new HtmlButtonInput(qualifiedName, page, attributeMap);
            break;
        case "file":
            result = new HtmlFileInput(qualifiedName, page, attributeMap);
            break;
        case "color":
            result = new HtmlColorInput(qualifiedName, page, attributeMap);
            break;
        case "date":
            result = new HtmlDateInput(qualifiedName, page, attributeMap);
            break;
        case "datetime-local":
            result = new HtmlDateTimeLocalInput(qualifiedName, page, attributeMap);
            break;
        case "email":
            result = new HtmlEmailInput(qualifiedName, page, attributeMap);
            break;
        case "month":
            result = new HtmlMonthInput(qualifiedName, page, attributeMap);
            break;
        case "number":
            result = new HtmlNumberInput(qualifiedName, page, attributeMap);
            break;
        case "range":
            result = new HtmlRangeInput(qualifiedName, page, attributeMap);
            break;
        case "search":
            result = new HtmlSearchInput(qualifiedName, page, attributeMap);
            break;
        case "tel":
            result = new HtmlTelInput(qualifiedName, page, attributeMap);
            break;
        case "time":
            result = new HtmlTimeInput(qualifiedName, page, attributeMap);
            break;
        case "url":
            result = new HtmlUrlInput(qualifiedName, page, attributeMap);
            break;
        case "week":
            result = new HtmlWeekInput(qualifiedName, page, attributeMap);
            break;
        default:
            if (LOG.isInfoEnabled()) {
                LOG.info("Bad input type: \"" + type + "\", creating a text input");
            }
            result = new HtmlTextInput(qualifiedName, page, attributeMap);
            break;
    }
    return result;
}

18 Source : SimpleScriptable.java
with Apache License 2.0
from null-dev

/**
 * Initialize the parent scope of a newly created scriptable.
 * @param domNode the DOM node for the script object
 * @param scriptable the script object to initialize
 */
protected void initParentScope(final DomNode domNode, final SimpleScriptable scriptable) {
    final SgmlPage page = domNode.getPage();
    final WebWindow enclosingWindow = page.getEnclosingWindow();
    if (enclosingWindow != null && enclosingWindow.getEnclosedPage() == page) {
        scriptable.setParentScope((Scriptable) enclosingWindow.getScriptableObject());
    } else {
        scriptable.setParentScope(ScriptableObject.getTopLevelScope((Scriptable) page.getScriptableObject()));
    }
}

18 Source : HTMLParser.java
with Apache License 2.0
from null-dev

/**
 * Returns the pre-registered element factory corresponding to the specified tag, or an UnknownElementFactory.
 * @param page the page
 * @param namespaceURI the namespace URI
 * @param qualifiedName the qualified name
 * @param insideSvg is the node inside an SVG node or not
 * @param svgSupport true if called from javascript createElementNS
 * @return the pre-registered element factory corresponding to the specified tag, or an UnknownElementFactory
 */
static ElementFactory getElementFactory(final SgmlPage page, final String namespaceURI, final String qualifiedName, final boolean insideSvg, final boolean svgSupport) {
    if (insideSvg) {
        return SVG_FACTORY;
    }
    if (namespaceURI == null || namespaceURI.isEmpty() || XHTML_NAMESPACE.equals(namespaceURI) || SVG_NAMESPACE.equals(namespaceURI) || !qualifiedName.contains(":")) {
        String tagName = qualifiedName;
        final int index = tagName.indexOf(':');
        if (index == -1) {
            tagName = tagName.toLowerCase(Locale.ROOT);
        } else {
            tagName = tagName.substring(index + 1);
        }
        final ElementFactory factory;
        if (svgSupport && !"svg".equals(tagName) && SVG_NAMESPACE.equals(namespaceURI)) {
            factory = SVG_FACTORY;
        } else {
            factory = ELEMENT_FACTORIES.get(tagName);
        }
        if (factory != null) {
            return factory;
        }
    }
    return UnknownElementFactory.instance;
}

17 Source : XmlUtils.java
with Apache License 2.0
from Xceptance

/**
 * Recursively appends a {@link Node} child to {@link DomNode} parent.
 *
 * @param page the owner page of {@link DomElement}s to be created
 * @param parent the parent DomNode
 * @param child the child Node
 * @param handleXHTMLAsHTML if true elements from the XHTML namespace are handled as HTML elements instead of
 *     DOM elements
 */
public static void appendChild(final SgmlPage page, final DomNode parent, final Node child, final boolean handleXHTMLAsHTML) {
    appendChild(page, parent, child, handleXHTMLAsHTML, null);
}

17 Source : SvgElementFactory.java
with Apache License 2.0
from Xceptance

/**
 * {@inheritDoc}
 */
@Override
public DomElement createElement(final SgmlPage page, final String tagName, final Attributes attributes) {
    throw new IllegalStateException("SVG.createElement not yet implemented!");
}

17 Source : SvgElementFactory.java
with Apache License 2.0
from Xceptance

/**
 * {@inheritDoc}
 */
@Override
public DomElement createElementNS(final SgmlPage page, final String namespaceURI, final String qualifiedName, final Attributes attributes) {
    return createElementNS(page, namespaceURI, qualifiedName, attributes, false);
}

17 Source : HTMLImageElement.java
with Apache License 2.0
from Xceptance

/**
 * JavaScript constructor.
 */
@JsxConstructor({ CHROME, EDGE, FF, FF78 })
public void jsConstructor() {
    final SgmlPage page = (SgmlPage) getWindow().getWebWindow().getEnclosedPage();
    final DomElement fake = page.getWebClient().getPageCreator().getHtmlParser().getFactory(HtmlImage.TAG_NAME).createElement(page, HtmlImage.TAG_NAME, null);
    setDomNode(fake);
}

17 Source : UnknownElementFactory.java
with Apache License 2.0
from Xceptance

/**
 * {@inheritDoc}
 */
@Override
public HtmlElement createElementNS(final SgmlPage page, final String namespaceURI, final String qualifiedName, final Attributes attributes) {
    return createElementNS(page, namespaceURI, qualifiedName, attributes, false);
}

17 Source : HtmlOption.java
with Apache License 2.0
from Xceptance

/**
 * {@inheritDoc}
 */
@Override
public Page mouseOver(final boolean shiftKey, final boolean ctrlKey, final boolean altKey, final int button) {
    final SgmlPage page = getPage();
    if (page.getWebClient().getBrowserVersion().hasFeature(EVENT_ONMOUSEOVER_NEVER_FOR_SELECT_OPTION)) {
        return page;
    }
    if (hasFeature(EVENT_ONMOUSEOVER_FOR_DISABLED_OPTION) && isDisabled()) {
        getEnclosingSelect().mouseOver(shiftKey, ctrlKey, altKey, button);
    }
    return super.mouseOver(shiftKey, ctrlKey, altKey, button);
}

17 Source : DomNamespaceNode.java
with Apache License 2.0
from Xceptance

/**
 * {@inheritDoc}
 */
@Override
public void processImportNode(final Doreplacedent doc) {
    super.processImportNode(doc);
    // if we are importing from a namespace-aware source
    // we have to drop the XHtmlNamespace because we did this already
    // for the HTML doreplacedent itself
    final SgmlPage page = (SgmlPage) doc.getDomNodeOrDie();
    if (page.isHtmlPage() && !(page instanceof XHtmlPage) && Html.XHTML_NAMESPACE.equals(namespaceURI_)) {
        namespaceURI_ = null;
    }
}

17 Source : DefaultElementFactory.java
with Apache License 2.0
from Xceptance

/**
 * @param page the owning page
 * @param namespaceURI the URI that identifies an XML namespace
 * @param qualifiedName the qualified name of the element type to instantiate
 * @param attributes initial attributes, possibly {@code null}
 * @return the newly created element
 */
@Override
public HtmlElement createElementNS(final SgmlPage page, final String namespaceURI, final String qualifiedName, final Attributes attributes) {
    return createElementNS(page, namespaceURI, qualifiedName, attributes, false);
}

17 Source : DefaultElementFactory.java
with Apache License 2.0
from Xceptance

/**
 * @param page the owning page
 * @param tagName the HTML tag name
 * @param attributes initial attributes, possibly {@code null}
 * @return the newly created element
 */
@Override
public HtmlElement createElement(final SgmlPage page, final String tagName, final Attributes attributes) {
    return createElementNS(page, null, tagName, attributes);
}

17 Source : XSLProcessor.java
with Apache License 2.0
from Xceptance

private void transform(final XMLDOMNode source, final DomNode parent) {
    final Object result = transform(source);
    if (result instanceof org.w3c.dom.Node) {
        final SgmlPage parentPage = parent.getPage();
        final NodeList children = ((org.w3c.dom.Node) result).getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            XmlUtils.appendChild(parentPage, parent, children.item(i), false);
        }
    } else {
        final DomText text = new DomText(parent.getPage(), (String) result);
        parent.appendChild(text);
    }
}

17 Source : XmlSerializer.java
with Apache License 2.0
from null-dev

public void save(final SgmlPage page, final File file) throws IOException {
    String fileName = file.getName();
    if (!fileName.endsWith(".htm") && !fileName.endsWith(".html")) {
        fileName += ".html";
    }
    final File outputFile = new File(file.getParentFile(), fileName);
    if (outputFile.exists()) {
        throw new IOException("File already exists: " + outputFile);
    }
    fileName = fileName.substring(0, fileName.lastIndexOf('.'));
    outputDir_ = new File(file.getParentFile(), fileName);
    FileUtils.writeStringToFile(outputFile, asXml(page.getDoreplacedentElement()), ISO_8859_1);
}

17 Source : InputElementFactory.java
with Apache License 2.0
from null-dev

/**
 * Creates an HtmlElement for the specified xmlElement, contained in the specified page.
 *
 * @param page the page that this element will belong to
 * @param tagName the HTML tag name
 * @param attributes the SAX attributes
 *
 * @return a new HtmlInput element
 */
@Override
public HtmlElement createElement(final SgmlPage page, final String tagName, final Attributes attributes) {
    return createElementNS(page, null, tagName, attributes);
}

17 Source : HtmlOption.java
with Apache License 2.0
from null-dev

/**
 * {@inheritDoc}
 */
@Override
public Page mouseOver(final boolean shiftKey, final boolean ctrlKey, final boolean altKey, final int button) {
    final SgmlPage page = getPage();
    if (page.getWebClient().getBrowserVersion().hasFeature(EVENT_ONMOUSEOVER_NEVER_FOR_SELECT_OPTION)) {
        return page;
    }
    return super.mouseOver(shiftKey, ctrlKey, altKey, button);
}

17 Source : DomNamespaceNode.java
with Apache License 2.0
from null-dev

/**
 * {@inheritDoc}
 */
@Override
public void processImportNode(final Doreplacedent doc) {
    super.processImportNode(doc);
    // if we are importing from a namespace-aware source
    // we have to drop the XHtmlNamespace because we did this already
    // for the HTML doreplacedent itself
    final SgmlPage page = (SgmlPage) doc.getDomNodeOrDie();
    if (page.isHtmlPage() && !(page instanceof XHtmlPage) && HTMLParser.XHTML_NAMESPACE.equals(namespaceURI_)) {
        namespaceURI_ = null;
    }
}

17 Source : XSLProcessor.java
with Apache License 2.0
from null-dev

private void transform(final XMLDOMNode source, final DomNode parent) {
    final Object result = transform(source);
    if (result instanceof org.w3c.dom.Node) {
        final SgmlPage parentPage = parent.getPage();
        final NodeList children = ((org.w3c.dom.Node) result).getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            XmlUtil.appendChild(parentPage, parent, children.item(i), false);
        }
    } else {
        final DomText text = new DomText(parent.getPage(), (String) result);
        parent.appendChild(text);
    }
}

16 Source : XSLTProcessor.java
with Apache License 2.0
from Xceptance

private void transform(final Node source, final DomNode parent) {
    final Object result = transform(source);
    if (result instanceof org.w3c.dom.Node) {
        final SgmlPage parentPage = parent.getPage();
        final NodeList children = ((org.w3c.dom.Node) result).getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            XmlUtils.appendChild(parentPage, parent, children.item(i), true);
        }
    } else {
        final DomText text = new DomText(parent.getPage(), (String) result);
        parent.appendChild(text);
    }
}

16 Source : HTMLOptionsCollection.java
with Apache License 2.0
from Xceptance

/**
 * Changes the number of options: removes options if the new length
 * is less than the current one else add new empty options to reach the
 * new length.
 * @param newLength the new length property value
 */
@JsxSetter
public void setLength(final int newLength) {
    if (newLength < 0) {
        if (getBrowserVersion().hasFeature(JS_SELECT_OPTIONS_IGNORE_NEGATIVE_LENGTH)) {
            return;
        }
        throw Context.reportRuntimeError("Length is negative");
    }
    final int currentLength = htmlSelect_.getOptionSize();
    if (currentLength > newLength) {
        htmlSelect_.setOptionSize(newLength);
    } else {
        final SgmlPage page = htmlSelect_.getPage();
        final ElementFactory factory = page.getWebClient().getPageCreator().getHtmlParser().getFactory(HtmlOption.TAG_NAME);
        for (int i = currentLength; i < newLength; i++) {
            final HtmlOption option = (HtmlOption) factory.createElement(page, HtmlOption.TAG_NAME, null);
            htmlSelect_.appendOption(option);
        }
    }
}

16 Source : Range.java
with Apache License 2.0
from Xceptance

/**
 * Parses an HTML snippet.
 * @param valuereplacedtring text that contains text and tags to be converted to a doreplacedent fragment
 * @return a doreplacedent fragment
 * @see <a href="https://developer.mozilla.org/en-US/docs/DOM/range.createContextualFragment">Mozilla
 * doreplacedentation</a>
 */
@JsxFunction
public Object createContextualFragment(final String valuereplacedtring) {
    final SgmlPage page = startContainer_.getDomNodeOrDie().getPage();
    final DomDoreplacedentFragment fragment = new DomDoreplacedentFragment(page);
    try {
        page.getWebClient().getPageCreator().getHtmlParser().parseFragment(fragment, startContainer_.getDomNodeOrDie(), valuereplacedtring);
    } catch (final Exception e) {
        LogFactory.getLog(Range.clreplaced).error("Unexpected exception occurred in createContextualFragment", e);
        throw Context.reportRuntimeError("Unexpected exception occurred in createContextualFragment: " + e.getMessage());
    }
    return fragment.getScriptableObject();
}

16 Source : XmlSerializer.java
with Apache License 2.0
from Xceptance

public void save(final SgmlPage page, final File file) throws IOException {
    String fileName = file.getName();
    if (!fileName.endsWith(".htm") && !fileName.endsWith(".html")) {
        fileName += ".html";
    }
    final File outputFile = new File(file.getParentFile(), fileName);
    if (outputFile.exists()) {
        throw new IOException("File already exists: " + outputFile);
    }
    fileName = fileName.substring(0, fileName.lastIndexOf('.'));
    outputDir_ = new File(file.getParentFile(), fileName);
    // don't use asXml here because we have to sync the encoding from the
    // header with the one used by the writer
    final DomElement node = page.getDoreplacedentElement();
    Charset charsetName = ISO_8859_1;
    builder_.setLength(0);
    indent_.setLength(0);
    if (page.isHtmlPage()) {
        charsetName = page.getCharset();
        if (charsetName != null && node instanceof HtmlHtml) {
            builder_.append("<?xml version=\"1.0\" encoding=\"").append(charsetName).append("\"?>").append('\n');
        }
    }
    printXml(node);
    final String response = builder_.toString();
    builder_.setLength(0);
    FileUtils.writeStringToFile(outputFile, response, charsetName);
}

16 Source : UnknownElementFactory.java
with Apache License 2.0
from Xceptance

/**
 * {@inheritDoc}
 */
@Override
public HtmlElement createElementNS(final SgmlPage page, final String namespaceURI, final String qualifiedName, final Attributes attributes, final boolean checkBrowserCompatibility) {
    final Map<String, DomAttr> attributeMap = DefaultElementFactory.toMap(page, attributes);
    return new HtmlUnknownElement(page, qualifiedName, attributeMap);
}

16 Source : HtmlSubmitInput.java
with Apache License 2.0
from Xceptance

/**
 * Add missing attribute if needed by fixing attribute map rather to add it afterwards as this second option
 * triggers the instantiation of the script object at a time where the DOM node has not yet been added to its
 * parent.
 */
private static Map<String, DomAttr> addValueIfNeeded(final SgmlPage page, final Map<String, DomAttr> attributes) {
    final BrowserVersion browserVersion = page.getWebClient().getBrowserVersion();
    if (browserVersion.hasFeature(SUBMITINPUT_DEFAULT_VALUE_IF_VALUE_NOT_DEFINED)) {
        for (final String key : attributes.keySet()) {
            if ("value".equalsIgnoreCase(key)) {
                // value attribute was specified
                return attributes;
            }
        }
        // value attribute was not specified, add it
        final DomAttr newAttr = new DomAttr(page, null, "value", DEFAULT_VALUE, true);
        attributes.put("value", newAttr);
    }
    return attributes;
}

16 Source : HtmlResetInput.java
with Apache License 2.0
from Xceptance

/**
 * Add missing attribute if needed by fixing attribute map rather to add it afterwards as this second option
 * triggers the instantiation of the script object at a time where the DOM node has not yet been added to its
 * parent.
 */
private static Map<String, DomAttr> addValueIfNeeded(final SgmlPage page, final Map<String, DomAttr> attributes) {
    final BrowserVersion browserVersion = page.getWebClient().getBrowserVersion();
    if (browserVersion.hasFeature(RESETINPUT_DEFAULT_VALUE_IF_VALUE_NOT_DEFINED)) {
        for (final String key : attributes.keySet()) {
            if ("value".equalsIgnoreCase(key)) {
                // value attribute was specified
                return attributes;
            }
        }
        // value attribute was not specified, add it
        final DomAttr newAttr = new DomAttr(page, null, "value", DEFAULT_VALUE, true);
        attributes.put("value", newAttr);
    }
    return attributes;
}

16 Source : XSLTProcessor.java
with Apache License 2.0
from null-dev

private void transform(final Node source, final DomNode parent) {
    final Object result = transform(source);
    if (result instanceof org.w3c.dom.Node) {
        final SgmlPage parentPage = parent.getPage();
        final NodeList children = ((org.w3c.dom.Node) result).getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            XmlUtil.appendChild(parentPage, parent, children.item(i), true);
        }
    } else {
        final DomText text = new DomText(parent.getPage(), (String) result);
        parent.appendChild(text);
    }
}

16 Source : HTMLImageElement.java
with Apache License 2.0
from null-dev

/**
 * JavaScript constructor.
 */
@JsxConstructor({ CHROME, FF, EDGE })
public void jsConstructor() {
    final SgmlPage page = (SgmlPage) getWindow().getWebWindow().getEnclosedPage();
    final DomElement fake = HTMLParser.getFactory(HtmlImage.TAG_NAME).createElement(page, HtmlImage.TAG_NAME, new AttributesImpl());
    setDomNode(fake);
}

16 Source : Range.java
with Apache License 2.0
from null-dev

/**
 * Parses an HTML snippet.
 * @param valuereplacedtring text that contains text and tags to be converted to a doreplacedent fragment
 * @return a doreplacedent fragment
 * @see <a href="https://developer.mozilla.org/en-US/docs/DOM/range.createContextualFragment">Mozilla
 * doreplacedentation</a>
 */
@JsxFunction
public Object createContextualFragment(final String valuereplacedtring) {
    final SgmlPage page = startContainer_.getDomNodeOrDie().getPage();
    final DomDoreplacedentFragment fragment = new DomDoreplacedentFragment(page);
    try {
        HTMLParser.parseFragment(fragment, startContainer_.getDomNodeOrDie(), valuereplacedtring);
    } catch (final Exception e) {
        LogFactory.getLog(Range.clreplaced).error("Unexpected exception occurred in createContextualFragment", e);
        throw Context.reportRuntimeError("Unexpected exception occurred in createContextualFragment: " + e.getMessage());
    }
    return fragment.getScriptableObject();
}

16 Source : HtmlForm.java
with Apache License 2.0
from null-dev

/**
 * Resets this form to its initial values, returning the page contained by this form's window after the
 * reset. Note that the returned page may or may not be the same as the original page, based on JavaScript
 * event handlers, etc.
 *
 * @return the page contained by this form's window after the reset
 */
public Page reset() {
    final SgmlPage htmlPage = getPage();
    final ScriptResult scriptResult = fireEvent(Event.TYPE_RESET);
    if (ScriptResult.isFalse(scriptResult)) {
        return scriptResult.getNewPage();
    }
    for (final HtmlElement next : getHtmlElementDescendants()) {
        if (next instanceof SubmittableElement) {
            ((SubmittableElement) next).reset();
        }
    }
    return htmlPage;
}

15 Source : XmlUtils.java
with Apache License 2.0
from Xceptance

/**
 * Recursively appends a {@link Node} child to {@link DomNode} parent.
 *
 * @param page the owner page of {@link DomElement}s to be created
 * @param parent the parent DomNode
 * @param child the child Node
 * @param handleXHTMLAsHTML if true elements from the XHTML namespace are handled as HTML elements instead of
 *     DOM elements
 * @param attributesOrderMap (optional) the one returned by {@link #getAttributesOrderMap(Doreplacedent)}
 */
public static void appendChild(final SgmlPage page, final DomNode parent, final Node child, final boolean handleXHTMLAsHTML, final Map<Integer, List<String>> attributesOrderMap) {
    final DoreplacedentType doreplacedentType = child.getOwnerDoreplacedent().getDoctype();
    if (doreplacedentType != null && page instanceof XmlPage) {
        final DomDoreplacedentType domDoctype = new DomDoreplacedentType(page, doreplacedentType.getName(), doreplacedentType.getPublicId(), doreplacedentType.getSystemId());
        ((XmlPage) page).setDoreplacedentType(domDoctype);
    }
    final DomNode childXml = createFrom(page, child, handleXHTMLAsHTML, attributesOrderMap);
    parent.appendChild(childXml);
    copy(page, child, childXml, handleXHTMLAsHTML, attributesOrderMap);
}

15 Source : SvgElementFactory.java
with Apache License 2.0
from Xceptance

private static Map<String, DomAttr> toMap(final SgmlPage page, final Attributes attributes) {
    Map<String, DomAttr> attributeMap = null;
    if (attributes != null) {
        attributeMap = new LinkedHashMap<>(attributes.getLength());
        for (int i = 0; i < attributes.getLength(); i++) {
            final String qName = attributes.getQName(i);
            // browsers consider only first attribute (ex: <div id='foo' id='something'>...</div>)
            if (!attributeMap.containsKey(qName)) {
                String namespaceURI = attributes.getURI(i);
                if (namespaceURI != null && namespaceURI.isEmpty()) {
                    namespaceURI = null;
                }
                final DomAttr newAttr = new DomAttr(page, namespaceURI, qName, attributes.getValue(i), true);
                attributeMap.put(qName, newAttr);
            }
        }
    }
    return attributeMap;
}

15 Source : XSLTProcessor.java
with Apache License 2.0
from Xceptance

/**
 * Transforms the node source applying the stylesheet given by the importStylesheet() function.
 * The owner doreplacedent of the output node owns the returned doreplacedent fragment.
 * @param source the node to be transformed
 * @param output This doreplacedent is used to generate the output
 * @return the result of the transformation
 */
@JsxFunction
public DoreplacedentFragment transformToFragment(final Node source, final Object output) {
    final SgmlPage page = (SgmlPage) ((Doreplacedent) output).getDomNodeOrDie();
    final DomDoreplacedentFragment fragment = page.createDoreplacedentFragment();
    final DoreplacedentFragment rv = new DoreplacedentFragment();
    rv.setPrototype(getPrototype(rv.getClreplaced()));
    rv.setParentScope(getParentScope());
    rv.setDomNode(fragment);
    transform(source, fragment);
    return rv;
}

15 Source : XMLSerializer.java
with Apache License 2.0
from Xceptance

/**
 * The subtree rooted by the specified element is serialized to a string.
 * @param root the root of the subtree to be serialized (this may be any node, even a doreplacedent)
 * @return the serialized string
 */
@JsxFunction
public String serializeToString(Node root) {
    if (root == null) {
        return "";
    }
    if (root instanceof Doreplacedent) {
        root = ((Doreplacedent) root).getDoreplacedentElement();
    } else if (root instanceof DoreplacedentFragment) {
        if (root.getOwnerDoreplacedent() instanceof HTMLDoreplacedent && getBrowserVersion().hasFeature(JS_XML_SERIALIZER_HTML_DOreplacedENT_FRAGMENT_ALWAYS_EMPTY)) {
            return "";
        }
        root = root.getFirstChild();
        if (root == null) {
            return "";
        }
        final StringBuilder builder = new StringBuilder();
        while (root != null) {
            builder.append(serializeToString(root));
            root = root.getNextSibling();
        }
        return builder.toString();
    }
    if (root instanceof Element) {
        final StringBuilder builder = new StringBuilder();
        final DomNode node = root.getDomNodeOrDie();
        final SgmlPage page = node.getPage();
        final boolean isHtmlPage = page != null && page.isHtmlPage();
        String forcedNamespace = null;
        if (isHtmlPage) {
            forcedNamespace = "http://www.w3.org/1999/xhtml";
        }
        toXml(1, node, builder, forcedNamespace);
        return builder.toString();
    }
    if (root instanceof CDATASection && getBrowserVersion().hasFeature(JS_XML_SERIALIZER_ROOT_CDATA_AS_ESCAPED_TEXT)) {
        final DomCDataSection domCData = (DomCDataSection) root.getDomNodeOrDie();
        final String data = domCData.getData();
        if (org.apache.commons.lang3.StringUtils.isNotBlank(data)) {
            return StringUtils.escapeXmlChars(data);
        }
    }
    return root.getDomNodeOrDie().asXml();
}

15 Source : UnknownElementFactory.java
with Apache License 2.0
from Xceptance

/**
 * {@inheritDoc}
 */
@Override
public HtmlElement createElement(final SgmlPage page, final String tagName, final Attributes attributes) {
    String namespace = null;
    if (page != null && page.isHtmlPage() && tagName.indexOf(':') != -1) {
        final HtmlPage htmlPage = (HtmlPage) page;
        final String prefix = tagName.substring(0, tagName.indexOf(':'));
        final Map<String, String> namespaces = htmlPage.getNamespaces();
        if (namespaces.containsKey(prefix)) {
            namespace = namespaces.get(prefix);
        }
    }
    return createElementNS(page, namespace, tagName, attributes);
}

15 Source : HtmlOption.java
with Apache License 2.0
from Xceptance

/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("unchecked")
public <P extends Page> P click(final Event event, final boolean shiftKey, final boolean ctrlKey, final boolean altKey, final boolean ignoreVisibility) throws IOException {
    if (hasFeature(EVENT_ONCLICK_FOR_SELECT_ONLY)) {
        final SgmlPage page = getPage();
        if (isDisabled()) {
            return (P) page;
        }
        if (isStateUpdateFirst()) {
            doClickStateUpdate(event.isShiftKey(), event.isCtrlKey());
        }
        return getEnclosingSelect().click(event, shiftKey, ctrlKey, altKey, ignoreVisibility);
    }
    return super.click(event, shiftKey, ctrlKey, altKey, ignoreVisibility);
}

15 Source : HtmlForm.java
with Apache License 2.0
from Xceptance

/**
 * Resets this form to its initial values, returning the page contained by this form's window after the
 * reset. Note that the returned page may or may not be the same as the original page, based on JavaScript
 * event handlers, etc.
 *
 * @return the page contained by this form's window after the reset
 */
public Page reset() {
    final SgmlPage htmlPage = getPage();
    final ScriptResult scriptResult = fireEvent(Event.TYPE_RESET);
    if (ScriptResult.isFalse(scriptResult)) {
        return htmlPage.getWebClient().getCurrentWindow().getEnclosedPage();
    }
    for (final HtmlElement next : getHtmlElementDescendants()) {
        if (next instanceof SubmittableElement) {
            ((SubmittableElement) next).reset();
        }
    }
    return htmlPage;
}

15 Source : DefaultElementFactory.java
with Apache License 2.0
from Xceptance

/**
 * Converts {@link Attributes} into the map needed by {@link HtmlElement}s.
 *
 * @param page the page which contains the specified attributes
 * @param attributes the SAX attributes
 * @return the map of attribute values for {@link HtmlElement}s
 */
static Map<String, DomAttr> toMap(final SgmlPage page, final Attributes attributes) {
    if (attributes == null) {
        return null;
    }
    final Map<String, DomAttr> attributeMap = new LinkedHashMap<>(attributes.getLength());
    for (int i = 0; i < attributes.getLength(); i++) {
        final String qName = attributes.getQName(i);
        // browsers consider only first attribute (ex: <div id='foo' id='something'>...</div>)
        if (!attributeMap.containsKey(qName)) {
            String namespaceURI = attributes.getURI(i);
            if (namespaceURI != null && namespaceURI.isEmpty()) {
                namespaceURI = null;
            }
            final DomAttr newAttr = new DomAttr(page, namespaceURI, qName, attributes.getValue(i), true);
            attributeMap.put(qName, newAttr);
        }
    }
    return attributeMap;
}

15 Source : XMLSerializer.java
with Apache License 2.0
from null-dev

/**
 * The subtree rooted by the specified element is serialized to a string.
 * @param root the root of the subtree to be serialized (this may be any node, even a doreplacedent)
 * @return the serialized string
 */
@JsxFunction
public String serializeToString(Node root) {
    if (root == null) {
        return "";
    }
    if (root instanceof Doreplacedent) {
        root = ((Doreplacedent) root).getDoreplacedentElement();
    } else if (root instanceof DoreplacedentFragment) {
        if (root.getOwnerDoreplacedent() instanceof HTMLDoreplacedent && getBrowserVersion().hasFeature(JS_XML_SERIALIZER_HTML_DOreplacedENT_FRAGMENT_ALWAYS_EMPTY)) {
            return "";
        }
        root = root.getFirstChild();
    }
    if (root instanceof Element) {
        final StringBuilder builder = new StringBuilder();
        final DomNode node = root.getDomNodeOrDie();
        final SgmlPage page = node.getPage();
        final boolean isHtmlPage = page != null && page.isHtmlPage();
        String forcedNamespace = null;
        if (isHtmlPage) {
            forcedNamespace = "http://www.w3.org/1999/xhtml";
        }
        toXml(1, node, builder, forcedNamespace);
        return builder.toString();
    }
    if (root instanceof CDATASection && getBrowserVersion().hasFeature(JS_XML_SERIALIZER_ROOT_CDATA_AS_ESCAPED_TEXT)) {
        final DomCDataSection domCData = (DomCDataSection) root.getDomNodeOrDie();
        final String data = domCData.getData();
        if (org.apache.commons.lang3.StringUtils.isNotBlank(data)) {
            return StringUtils.escapeXmlChars(data);
        }
    }
    return root.getDomNodeOrDie().asXml();
}

15 Source : HtmlOption.java
with Apache License 2.0
from null-dev

/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("unchecked")
public <P extends Page> P click(final Event event, final boolean ignoreVisibility) throws IOException {
    if (hasFeature(EVENT_ONCLICK_FOR_SELECT_ONLY)) {
        final SgmlPage page = getPage();
        if (isDisabled()) {
            return (P) page;
        }
        if (isStateUpdateFirst()) {
            doClickStateUpdate(event.isShiftKey(), event.isCtrlKey());
        }
        return getEnclosingSelect().click(event, ignoreVisibility);
    }
    return super.click(event, ignoreVisibility);
}

15 Source : HtmlMeta.java
with Apache License 2.0
from null-dev

/**
 * Handles the cookies specified in meta tags,
 * like <tt><meta http-equiv='set-cookie' content='webm=none; path=/;'></tt>.
 */
protected void performSetCookie() {
    final SgmlPage page = getPage();
    final WebClient client = page.getWebClient();
    final URL url = page.getUrl();
    client.addCookie(getContentAttribute(), url, this);
}

See More Examples