/** * Gets the script held within the script tag. */ private static String getScriptCode(final DomElement element) { final Iterable<DomNode> textNodes = element.getChildren(); final StringBuilder scriptCode = new StringBuilder(); for (final DomNode node : textNodes) { if (node instanceof DomText) { final DomText domText = (DomText) node; scriptCode.append(domText.getData()); } } return scriptCode.toString(); }
/** * Returns the <tt>body</tt> element (or <tt>frameset</tt> element), or {@code null} if it does not yet exist. * @return the <tt>body</tt> element (or <tt>frameset</tt> element), or {@code null} if it does not yet exist */ public HtmlElement getBody() { final DomElement doc = getDocumentElement(); if (doc != null) { for (final DomNode node : doc.getChildren()) { if (node instanceof HtmlBody || node instanceof HtmlFrameSet) { return (HtmlElement) node; } } } return null; }
/** * Returns the head element. * @return the head element */ public HtmlElement getHead() { final DomElement doc = getDocumentElement(); if (doc != null) { for (final DomNode node : doc.getChildren()) { if (node instanceof HtmlHead) { return (HtmlElement) node; } } } return null; }
/** * Returns the head element. * @return the head element */ public HtmlElement getHead() { final DomElement doc = getDocumentElement(); if (doc != null) { for (final DomNode node : doc.getChildren()) { if (node instanceof HtmlHead) { return (HtmlElement) node; } } } return null; }
/** * Gets the script held within the script tag. */ private static String getScriptCode(final DomElement element) { final Iterable<DomNode> textNodes = element.getChildren(); final StringBuilder scriptCode = new StringBuilder(); for (final DomNode node : textNodes) { if (node instanceof DomText) { final DomText domText = (DomText) node; scriptCode.append(domText.getData()); } } return scriptCode.toString(); }
/** * Returns the <tt>body</tt> element (or <tt>frameset</tt> element), or {@code null} if it does not yet exist. * @return the <tt>body</tt> element (or <tt>frameset</tt> element), or {@code null} if it does not yet exist */ public HtmlElement getBody() { final DomElement doc = getDocumentElement(); if (doc != null) { for (final DomNode node : doc.getChildren()) { if (node instanceof HtmlBody || node instanceof HtmlFrameSet) { return (HtmlElement) node; } } } return null; }
private void normalize(final DomElement domElement) { for (DomNode domNode : domElement.getChildren()) { if (domNode instanceof DomElement) { domNode.normalize(); normalize((DomElement) domNode); } } }
private void normalize(final DomElement domElement) { for (DomNode domNode : domElement.getChildren()) { if (domNode instanceof DomElement) { domNode.normalize(); normalize((DomElement) domNode); } } }
private String getNamespace(final DomElement element, final String prefix) { final Map<String, DomAttr> attributes = element.getAttributesMap(); final String xmlns = "xmlns:"; final int xmlnsLength = xmlns.length(); for (final Map.Entry<String, DomAttr> entry : attributes.entrySet()) { final String name = entry.getKey(); if (name.startsWith(xmlns) && name.regionMatches(xmlnsLength, prefix, 0, prefix.length())) { return entry.getValue().getValue(); } } for (final DomNode child : element.getChildren()) { if (child instanceof DomElement) { final String namespace = getNamespace((DomElement) child, prefix); if (namespace != null) { return namespace; } } } return null; } }
private String getNamespace(final DomElement element, final String prefix) { final Map<String, DomAttr> attributes = element.getAttributesMap(); final String xmlns = "xmlns:"; final int xmlnsLength = xmlns.length(); for (final Map.Entry<String, DomAttr> entry : attributes.entrySet()) { final String name = entry.getKey(); if (name.startsWith(xmlns) && name.regionMatches(xmlnsLength, prefix, 0, prefix.length())) { return entry.getValue().getValue(); } } for (final DomNode child : element.getChildren()) { if (child instanceof DomElement) { final String namespace = getNamespace((DomElement) child, prefix); if (namespace != null) { return namespace; } } } return null; } }
private String getNamespace(final DomElement element, final String prefix) { final Map<String, DomAttr> attributes = element.getAttributesMap(); for (final String name : attributes.keySet()) { if (name.startsWith("xmlns:")) { if (name.substring("xmlns:".length()).equals(prefix)) { return attributes.get(name).getValue(); } } } for (final DomNode child : element.getChildren()) { if (child instanceof DomElement) { final String namespace = getNamespace((DomElement) child, prefix); if (namespace != null) { return namespace; } } } return null; } }
private String getNamespace(final DomElement element, final String prefix) { final Map<String, DomAttr> attributes = element.getAttributesMap(); for (final String name : attributes.keySet()) { if (name.startsWith("xmlns:")) { if (name.substring("xmlns:".length()).equals(prefix)) { return attributes.get(name).getValue(); } } } for (final DomNode child : element.getChildren()) { if (child instanceof DomElement) { final String namespace = getNamespace((DomElement) child, prefix); if (namespace != null) { return namespace; } } } return null; } }
private String getNamespace(final DomElement element, final String prefix) { final Map<String, DomAttr> attributes = element.getAttributesMap(); for (final String name : attributes.keySet()) { if (name.startsWith("xmlns:")) { if (name.substring("xmlns:".length()).equals(prefix)) { return attributes.get(name).getValue(); } } } for (final DomNode child : element.getChildren()) { if (child instanceof DomElement) { final String namespace = getNamespace((DomElement) child, prefix); if (namespace != null) { return namespace; } } } return null; } }
/** * Search for the prefix associated with specified namespace URI. * @param element the element to start searching from * @param namespace the namespace prefix * @return the prefix bound to the namespace URI; or null if there is no such namespace */ public static String lookupPrefix(final DomElement element, final String namespace) { final Map<String, DomAttr> attributes = element.getAttributesMap(); for (final Map.Entry<String, DomAttr> entry : attributes.entrySet()) { final String name = entry.getKey(); final DomAttr value = entry.getValue(); if (name.startsWith("xmlns:") && value.getValue().equals(namespace)) { return name.substring(6); } } for (final DomNode child : element.getChildren()) { if (child instanceof DomElement) { final String prefix = lookupPrefix((DomElement) child, namespace); if (prefix != null) { return prefix; } } } return null; }
/** * Search for the prefix associated with specified namespace URI. * @param element the element to start searching from * @param namespace the namespace prefix * @return the prefix bound to the namespace URI; or null if there is no such namespace */ public static String lookupPrefix(final DomElement element, final String namespace) { final Map<String, DomAttr> attributes = element.getAttributesMap(); for (final Map.Entry<String, DomAttr> entry : attributes.entrySet()) { final String name = entry.getKey(); final DomAttr value = entry.getValue(); if (name.startsWith("xmlns:") && value.getValue().equals(namespace)) { return name.substring(6); } } for (final DomNode child : element.getChildren()) { if (child instanceof DomElement) { final String prefix = lookupPrefix((DomElement) child, namespace); if (prefix != null) { return prefix; } } } return null; }
/** * Search for the prefix associated with specified namespace URI. * @param element the element to start searching from * @param namespace the namespace prefix * @return the prefix bound to the namespace URI; or null if there is no such namespace */ public static String lookupPrefix(final DomElement element, final String namespace) { final Map<String, DomAttr> attributes = element.getAttributesMap(); for (final String name : attributes.keySet()) { if (name.startsWith("xmlns:") && attributes.get(name).getValue().equals(namespace)) { return name.substring(6); } } for (final DomNode child : element.getChildren()) { if (child instanceof DomElement) { final String prefix = lookupPrefix((DomElement) child, namespace); if (prefix != null) { return prefix; } } } return null; } }
/** * Search for the prefix associated with specified namespace URI. * @param element the element to start searching from * @param namespace the namespace prefix * @return the prefix bound to the namespace URI; or null if there is no such namespace */ public static String lookupPrefix(final DomElement element, final String namespace) { final Map<String, DomAttr> attributes = element.getAttributesMap(); for (final String name : attributes.keySet()) { if (name.startsWith("xmlns:") && attributes.get(name).getValue().equals(namespace)) { return name.substring(6); } } for (final DomNode child : element.getChildren()) { if (child instanceof DomElement) { final String prefix = lookupPrefix((DomElement) child, namespace); if (prefix != null) { return prefix; } } } return null; } }
/** * Search for the prefix associated with specified namespace URI. * @param element the element to start searching from * @param namespace the namespace prefix * @return the prefix bound to the namespace URI; or null if there is no such namespace */ public static String lookupPrefix(final DomElement element, final String namespace) { final Map<String, DomAttr> attributes = element.getAttributesMap(); for (final String name : attributes.keySet()) { if (name.startsWith("xmlns:") && attributes.get(name).getValue().equals(namespace)) { return name.substring(6); } } for (final DomNode child : element.getChildren()) { if (child instanceof DomElement) { final String prefix = lookupPrefix((DomElement) child, namespace); if (prefix != null) { return prefix; } } } return null; } }