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; } }
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; } }
/** * Retrieves an attribute node by name. * @param name the name of the attribute to retrieve * @return the XMLAttr node with the specified name or <code>null</code> if there is no such attribute */ public Object jsxFunction_getAttributeNode(final String name) { final Map<String, DomAttr> attributes = getDomNodeOrDie().getAttributesMap(); for (final DomAttr attr : attributes.values()) { if (attr.getName().equals(name)) { return attr.getScriptObject(); } } return null; }
/** * Retrieves an attribute node by name. * @param name the name of the attribute to retrieve * @return the XMLAttr node with the specified name or <code>null</code> if there is no such attribute */ public Object jsxFunction_getAttributeNode(final String name) { final Map<String, DomAttr> attributes = getDomNodeOrDie().getAttributesMap(); for (final DomAttr attr : attributes.values()) { if (attr.getName().equals(name)) { return attr.getScriptObject(); } } 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; }
/** * Retrieves an attribute node by name. * @param name the name of the attribute to retrieve * @return the XMLAttr node with the specified name or <code>null</code> if there is no such attribute */ public Object jsxFunction_getAttributeNode(final String name) { final Map<String, DomAttr> attributes = getDomNodeOrDie().getAttributesMap(); for (final DomAttr attr : attributes.values()) { if (attr.getName().equals(name)) { return attr.getScriptObject(); } } 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; } }
/** * Retrieves an attribute node by name. * @param name the name of the attribute to retrieve * @return the XMLAttr node with the specified name or {@code null} if there is no such attribute */ @JsxFunction public Object getAttributeNode(final String name) { final Map<String, DomAttr> attributes = getDomNodeOrDie().getAttributesMap(); for (final DomAttr attr : attributes.values()) { if (attr.getName().equals(name)) { return attr.getScriptableObject(); } } return null; }
/** * Retrieves an attribute node by name. * @param name the name of the attribute to retrieve * @return the XMLAttr node with the specified name or {@code null} if there is no such attribute */ @JsxFunction public Object getAttributeNode(final String name) { final Map<String, DomAttr> attributes = getDomNodeOrDie().getAttributesMap(); for (final DomAttr attr : attributes.values()) { if (attr.getName().equals(name)) { return attr.getScriptableObject(); } } return null; }
/** * Returns the attribute node. * @param name the name of the attribute to return * @return the attribute node with the supplied name, {@code null} if the named attribute cannot be found * on this element */ @JsxFunction public Object getAttributeNode(final String name) { if (name == null || "null".equals(name)) { throw Context.reportRuntimeError("Type mismatch."); } if (StringUtils.isEmpty(name)) { throw Context.reportRuntimeError("The empty string '' is not a valid name."); } final Map<String, DomAttr> attributes = getDomNodeOrDie().getAttributesMap(); for (final DomAttr attr : attributes.values()) { if (attr.getName().equals(name)) { return attr.getScriptableObject(); } } return null; }
/** * Returns the attribute node. * @param name the name of the attribute to return * @return the attribute node with the supplied name, {@code null} if the named attribute cannot be found * on this element */ @JsxFunction public Object getAttributeNode(final String name) { if (name == null || "null".equals(name)) { throw Context.reportRuntimeError("Type mismatch."); } if (StringUtils.isEmpty(name)) { throw Context.reportRuntimeError("The empty string '' is not a valid name."); } final Map<String, DomAttr> attributes = getDomNodeOrDie().getAttributesMap(); for (final DomAttr attr : attributes.values()) { if (attr.getName().equals(name)) { return attr.getScriptableObject(); } } return null; }
private Map<String, DomAttr> readAttributes(final DomElement node) throws IOException { if (node instanceof HtmlImage) { return getAttributesFor((HtmlImage) node); } else if (node instanceof HtmlLink) { return getAttributesFor((HtmlLink) node); } else if (node instanceof BaseFrameElement) { return getAttributesFor((BaseFrameElement) node); } Map<String, DomAttr> attributes = node.getAttributesMap(); if (node instanceof HtmlOption) { attributes = new HashMap<>(attributes); final HtmlOption option = (HtmlOption) node; if (option.isSelected()) { if (!attributes.containsKey("selected")) { attributes.put("selected", new DomAttr(node.getPage(), null, "selected", "selected", false)); } } else { attributes.remove("selected"); } } return attributes; }
private Map<String, DomAttr> readAttributes(final DomElement node) throws IOException { if (node instanceof HtmlImage) { return getAttributesFor((HtmlImage) node); } else if (node instanceof HtmlLink) { return getAttributesFor((HtmlLink) node); } else if (node instanceof BaseFrameElement) { return getAttributesFor((BaseFrameElement) node); } Map<String, DomAttr> attributes = node.getAttributesMap(); if (node instanceof HtmlOption) { attributes = new HashMap<>(attributes); final HtmlOption option = (HtmlOption) node; if (option.isSelected()) { if (!attributes.containsKey("selected")) { attributes.put("selected", new DomAttr(node.getPage(), null, "selected", "selected", false)); } } else { attributes.remove("selected"); } } return attributes; }
/** * Sets the DOM node that corresponds to this JavaScript object. * @param domNode the DOM node */ @Override public void setDomNode(final DomNode domNode) { super.setDomNode(domNode); style_ = new CSSStyleDeclaration(this); setParentScope(getWindow().getDocument()); /** * Convert JavaScript snippets defined in the attribute map to executable event handlers. * Should be called only on construction. */ final DomElement htmlElt = (DomElement) domNode; for (final DomAttr attr : htmlElt.getAttributesMap().values()) { final String eventName = attr.getName().toLowerCase(Locale.ROOT); if (eventName.startsWith("on")) { createEventHandler(eventName.substring(2), attr.getValue()); } } }
/** * Sets the DOM node that corresponds to this JavaScript object. * @param domNode the DOM node */ @Override public void setDomNode(final DomNode domNode) { super.setDomNode(domNode); style_ = new CSSStyleDeclaration(this); setParentScope(getWindow().getDocument()); /** * Convert JavaScript snippets defined in the attribute map to executable event handlers. * Should be called only on construction. */ final DomElement htmlElt = (DomElement) domNode; for (final DomAttr attr : htmlElt.getAttributesMap().values()) { final String eventName = attr.getName().toLowerCase(Locale.ROOT); if (eventName.startsWith("on")) { createEventHandler(eventName.substring(2), attr.getValue()); } } }