Search in sources :

Example 1 with DomDocumentType

use of com.gargoylesoftware.htmlunit.html.DomDocumentType in project htmlunit by HtmlUnit.

the class XmlUtils method createFrom.

private static DomNode createFrom(final SgmlPage page, final Node source, final boolean handleXHTMLAsHTML, final Map<Integer, List<String>> attributesOrderMap) {
    if (source.getNodeType() == Node.TEXT_NODE) {
        return new DomText(page, source.getNodeValue());
    }
    if (source.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
        return new DomProcessingInstruction(page, source.getNodeName(), source.getNodeValue());
    }
    if (source.getNodeType() == Node.COMMENT_NODE) {
        return new DomComment(page, source.getNodeValue());
    }
    if (source.getNodeType() == Node.DOCUMENT_TYPE_NODE) {
        final DocumentType documentType = (DocumentType) source;
        return new DomDocumentType(page, documentType.getName(), documentType.getPublicId(), documentType.getSystemId());
    }
    final String ns = source.getNamespaceURI();
    String localName = source.getLocalName();
    if (handleXHTMLAsHTML && Html.XHTML_NAMESPACE.equals(ns)) {
        final ElementFactory factory = page.getWebClient().getPageCreator().getHtmlParser().getFactory(localName);
        return factory.createElementNS(page, ns, localName, namedNodeMapToSaxAttributes(source.getAttributes(), attributesOrderMap, source));
    }
    final NamedNodeMap nodeAttributes = source.getAttributes();
    if (page != null && page.isHtmlPage()) {
        localName = localName.toUpperCase(Locale.ROOT);
    }
    final String qualifiedName;
    if (source.getPrefix() == null) {
        qualifiedName = localName;
    } else {
        qualifiedName = source.getPrefix() + ':' + localName;
    }
    final String namespaceURI = source.getNamespaceURI();
    if (Html.SVG_NAMESPACE.equals(namespaceURI)) {
        return page.getWebClient().getPageCreator().getHtmlParser().getSvgFactory().createElementNS(page, namespaceURI, qualifiedName, namedNodeMapToSaxAttributes(nodeAttributes, attributesOrderMap, source));
    }
    final Map<String, DomAttr> attributes = new LinkedHashMap<>();
    for (int i = 0; i < nodeAttributes.getLength(); i++) {
        final int orderedIndex = getIndex(nodeAttributes, attributesOrderMap, source, i);
        final Attr attribute = (Attr) nodeAttributes.item(orderedIndex);
        final String attributeNamespaceURI = attribute.getNamespaceURI();
        final String attributeQualifiedName;
        if (attribute.getPrefix() == null) {
            attributeQualifiedName = attribute.getLocalName();
        } else {
            attributeQualifiedName = attribute.getPrefix() + ':' + attribute.getLocalName();
        }
        final String value = attribute.getNodeValue();
        final boolean specified = attribute.getSpecified();
        final DomAttr xmlAttribute = new DomAttr(page, attributeNamespaceURI, attributeQualifiedName, value, specified);
        attributes.put(attribute.getNodeName(), xmlAttribute);
    }
    return new DomElement(namespaceURI, qualifiedName, page, attributes);
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) DomAttr(com.gargoylesoftware.htmlunit.html.DomAttr) DomDocumentType(com.gargoylesoftware.htmlunit.html.DomDocumentType) DocumentType(org.w3c.dom.DocumentType) Attr(org.w3c.dom.Attr) DomAttr(com.gargoylesoftware.htmlunit.html.DomAttr) DomDocumentType(com.gargoylesoftware.htmlunit.html.DomDocumentType) LinkedHashMap(java.util.LinkedHashMap) DomComment(com.gargoylesoftware.htmlunit.html.DomComment) DomElement(com.gargoylesoftware.htmlunit.html.DomElement) DomText(com.gargoylesoftware.htmlunit.html.DomText) DomProcessingInstruction(com.gargoylesoftware.htmlunit.html.DomProcessingInstruction) ElementFactory(com.gargoylesoftware.htmlunit.html.ElementFactory)

Example 2 with DomDocumentType

use of com.gargoylesoftware.htmlunit.html.DomDocumentType in project htmlunit by HtmlUnit.

the class XMLDOMDocumentType method getNotations.

/**
 * Returns a list of the XMLDOMNotation objects present in the document type declaration.
 * @return notations
 */
@JsxGetter
public Object getNotations() {
    final DomDocumentType domDocumentType = getDomNodeOrDie();
    final NamedNodeMap notations = domDocumentType.getNotations();
    if (null != notations) {
        return notations;
    }
    return "";
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) DomDocumentType(com.gargoylesoftware.htmlunit.html.DomDocumentType) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 3 with DomDocumentType

use of com.gargoylesoftware.htmlunit.html.DomDocumentType in project htmlunit by HtmlUnit.

the class XMLDOMDocumentType method getEntities.

/**
 * Returns a list of the entities declared in the DOCTYPE declaration.
 * @return entities
 */
@JsxGetter
public Object getEntities() {
    final DomDocumentType domDocumentType = getDomNodeOrDie();
    final NamedNodeMap entities = domDocumentType.getEntities();
    if (null != entities) {
        return entities;
    }
    return "";
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) DomDocumentType(com.gargoylesoftware.htmlunit.html.DomDocumentType) JsxGetter(com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)

Example 4 with DomDocumentType

use of com.gargoylesoftware.htmlunit.html.DomDocumentType in project htmlunit by HtmlUnit.

the class XmlUtils method appendChild.

/**
 * 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(Document)}
 */
public static void appendChild(final SgmlPage page, final DomNode parent, final Node child, final boolean handleXHTMLAsHTML, final Map<Integer, List<String>> attributesOrderMap) {
    final DocumentType documentType = child.getOwnerDocument().getDoctype();
    if (documentType != null && page instanceof XmlPage) {
        final DomDocumentType domDoctype = new DomDocumentType(page, documentType.getName(), documentType.getPublicId(), documentType.getSystemId());
        ((XmlPage) page).setDocumentType(domDoctype);
    }
    final DomNode childXml = createFrom(page, child, handleXHTMLAsHTML, attributesOrderMap);
    parent.appendChild(childXml);
    copy(page, child, childXml, handleXHTMLAsHTML, attributesOrderMap);
}
Also used : DomNode(com.gargoylesoftware.htmlunit.html.DomNode) DomDocumentType(com.gargoylesoftware.htmlunit.html.DomDocumentType) DocumentType(org.w3c.dom.DocumentType) XmlPage(com.gargoylesoftware.htmlunit.xml.XmlPage) DomDocumentType(com.gargoylesoftware.htmlunit.html.DomDocumentType)

Example 5 with DomDocumentType

use of com.gargoylesoftware.htmlunit.html.DomDocumentType in project htmlunit by HtmlUnit.

the class HtmlUnitNekoDOMBuilder method startDTD.

/**
 * {@inheritDoc}
 */
@Override
public void startDTD(final String name, final String publicId, final String systemId) {
    final DomDocumentType type = new DomDocumentType(page_, name, publicId, systemId);
    page_.setDocumentType(type);
    final Node child;
    child = type;
    page_.appendChild(child);
}
Also used : DomNode(com.gargoylesoftware.htmlunit.html.DomNode) Node(org.w3c.dom.Node) DomDocumentType(com.gargoylesoftware.htmlunit.html.DomDocumentType)

Aggregations

DomDocumentType (com.gargoylesoftware.htmlunit.html.DomDocumentType)5 NamedNodeMap (org.w3c.dom.NamedNodeMap)3 DomNode (com.gargoylesoftware.htmlunit.html.DomNode)2 JsxGetter (com.gargoylesoftware.htmlunit.javascript.configuration.JsxGetter)2 DocumentType (org.w3c.dom.DocumentType)2 DomAttr (com.gargoylesoftware.htmlunit.html.DomAttr)1 DomComment (com.gargoylesoftware.htmlunit.html.DomComment)1 DomElement (com.gargoylesoftware.htmlunit.html.DomElement)1 DomProcessingInstruction (com.gargoylesoftware.htmlunit.html.DomProcessingInstruction)1 DomText (com.gargoylesoftware.htmlunit.html.DomText)1 ElementFactory (com.gargoylesoftware.htmlunit.html.ElementFactory)1 XmlPage (com.gargoylesoftware.htmlunit.xml.XmlPage)1 LinkedHashMap (java.util.LinkedHashMap)1 Attr (org.w3c.dom.Attr)1 Node (org.w3c.dom.Node)1