public class DOMHelper extends Object
Element or Node)
but exist in almost all browsers and are sometimes required
to develop an SVG application.| Constructor and Description |
|---|
DOMHelper() |
| Modifier and Type | Method and Description |
|---|---|
static void |
appendData(com.google.gwt.dom.client.Text text,
String arg)
Append the string to the end of the character data of the node.
|
static String |
base64encode(String str)
Returns a base64 encoding of the specified binary string
|
static void |
bindEventListener(com.google.gwt.dom.client.Element elem,
String eventName)
Makes a node sink the events emitted by the specified element
|
static com.google.gwt.dom.client.Document |
createDocument(String uri,
String qname)
Creates a new empty SVG document
|
static com.google.gwt.dom.client.Element |
createElementNS(com.google.gwt.dom.client.Document document,
String namespaceURI,
String qualifiedName)
Creates an element of the given qualified name and namespace URI.
|
static boolean |
evaluateBooleanXPath(com.google.gwt.dom.client.Element root,
String expr,
XPathPrefixResolver resolver)
Evaluates the specified XPath expression and returns
the matching boolean.
|
static <T extends com.google.gwt.dom.client.Node> |
evaluateNodeListXPath(com.google.gwt.dom.client.Element root,
String expr,
XPathPrefixResolver resolver)
Evaluates the specified XPath expression and returns
a iterator for the selected
Node node list. |
static <T extends com.google.gwt.dom.client.Node> |
evaluateNodeXPath(com.google.gwt.dom.client.Element root,
String expr,
XPathPrefixResolver resolver)
Evaluates the specified XPath expression and returns
the matching
Node node. |
static float |
evaluateNumberXPath(com.google.gwt.dom.client.Element root,
String expr,
XPathPrefixResolver resolver)
Evaluates the specified XPath expression and returns
the matching float.
|
static String |
evaluateStringXPath(com.google.gwt.dom.client.Element root,
String expr,
XPathPrefixResolver resolver)
Evaluates the specified XPath expression and returns
the matching
String. |
static <T extends OMNode> |
evaluateXPath(OMElement root,
String expr,
XPathPrefixResolver resolver)
Evaluates the specified XPath expression and returns
a iterator for the selected
OMNode node list. |
static Attr |
getAttributeNode(com.google.gwt.dom.client.Element elt,
String attrName)
Retrieves an attribute node by name on the specified element.
|
static String |
getAttributeNS(com.google.gwt.dom.client.Element elem,
String namespaceURI,
String localName)
Retrieves an attribute value by local name and namespace URI on
the specified element.
|
static NamedNodeMap<Attr> |
getAttributes(com.google.gwt.dom.client.Element elem)
Returns a
NamedNodeMap containing the attributes of the
specified element. |
static OMSVGElement |
getCaptureElement()
Returns the element which currently captures all the
events after a call to
setCaptureElement(OMSVGElement, LoseCaptureHandler)
or null if element is set to capture events |
static com.google.gwt.dom.client.Document |
getCurrentDocument()
Returns the current document
|
static com.google.gwt.dom.client.NodeList<? extends com.google.gwt.dom.client.Node> |
getElementsByTagNameNS(com.google.gwt.dom.client.Document doc,
String namespaceURI,
String localName)
Returns a
NodeList of all the Elements
in the specified document with a
given local name and namespace URI in document order. |
static com.google.gwt.dom.client.NodeList<? extends com.google.gwt.dom.client.Node> |
getElementsByTagNameNS(com.google.gwt.dom.client.Element elem,
String namespaceURI,
String localName)
Returns a
NodeList of all the descendant
Elements of the specified element
with a given local name and namespace URI in
document order. |
static String |
getLocalName(com.google.gwt.dom.client.Node node)
Returns the local part of the qualified name of this node.
|
static String |
getNamespaceURI(com.google.gwt.dom.client.Node node)
The namespace URI of the specified node, or
null if it is
unspecified (see ). |
static String |
getType(com.google.gwt.core.client.JavaScriptObject x)
Returns the JavaScript type of an object.
|
static String |
getXPath(com.google.gwt.dom.client.Node node,
com.google.gwt.dom.client.Node root)
Returns an XPath expression which enables reaching the specified node
from the root node
|
static boolean |
hasAttributeNS(com.google.gwt.dom.client.Element elem,
String namespaceURI,
String localName)
Returns
true when an attribute with a given local name and
namespace URI is specified on the specified element or has a default value,
false otherwise. |
static boolean |
hasFeature(String featureName)
Tests if the underlying DOM implementation supports the specified feature
|
static com.google.gwt.dom.client.Node |
importNode(com.google.gwt.dom.client.Document document,
com.google.gwt.dom.client.Node importedNode,
boolean deep)
Imports a node from another document to this document, without altering
or removing the source node from the original document; this method
creates a new copy of the source node.
|
static void |
normalize(com.google.gwt.dom.client.Node node)
Puts all
Text nodes in the full depth of the sub-tree
underneath this Node, including attribute nodes, into a
"normal" form where only structure (e.g., elements, comments,
processing instructions, CDATA sections, and entity references)
separates Text nodes, i.e., there are neither adjacent
Text nodes nor empty Text nodes. |
static void |
releaseCaptureElement()
Stops the forwarding of all events to the capturing element
specified by
setCaptureElement(OMSVGElement, LoseCaptureHandler) |
static Attr |
setAttributeNode(com.google.gwt.dom.client.Element elt,
Attr attr)
Adds a new attribute node to the specified element.
|
static void |
setAttributeNS(com.google.gwt.dom.client.Element elem,
String namespaceURI,
String localName,
String value)
Adds a new attribute to the specified element.
|
static com.google.gwt.event.shared.HandlerRegistration |
setCaptureElement(OMSVGElement element,
com.google.gwt.event.dom.client.LoseCaptureHandler loseCaptureHandler)
Makes the specified element capture all the events, until
a call to
releaseCaptureElement()
terminates the capture |
static String |
substringData(com.google.gwt.dom.client.Text text,
int offset,
int count)
Extracts a range of data from the node.
|
static boolean |
supportsSvgTouchEvents()
Deprecated.
Use the
hasFeature(String) method with the
SVGConstants.SVG_FEATURE_TOUCH_EVENTS parameter instead. |
static String |
toUrl(String s)
Creates a value of the formed expected by SVG
href attribtues.
|
static void |
unbindEventListener(com.google.gwt.dom.client.Element elem,
String eventName)
Stops making a node sink the events emitted by the specified element
|
public static final com.google.gwt.dom.client.Element createElementNS(com.google.gwt.dom.client.Document document,
String namespaceURI,
String qualifiedName)
throws com.google.gwt.core.client.JavaScriptException
null as the
namespaceURI parameter for methods if they wish to have no namespace.document - The document in which the element is to be created.namespaceURI - The namespace URI of the element to create.qualifiedName - The qualified name of the element type to
instantiate.Element object with the following
attributes:
| Attribute | Value |
|---|---|
Node.nodeName |
qualifiedName |
Node.namespaceURI |
namespaceURI |
Node.prefix |
prefix, extracted
from qualifiedName, or null if there is
no prefix |
Node.localName |
local name, extracted from
qualifiedName |
Element.tagName |
qualifiedName |
DOMException - INVALID_CHARACTER_ERR: Raised if the specified
qualifiedName is not an XML name according to the XML
version in use specified in the Document.xmlVersion
attribute.
qualifiedName is a
malformed qualified name, if the qualifiedName has a
prefix and the namespaceURI is null, or
if the qualifiedName has a prefix that is "xml" and
the namespaceURI is different from "
http://www.w3.org/XML/1998/namespace" [XML Namespaces]
, or if the qualifiedName or its prefix is "xmlns" and
the namespaceURI is different from "http://www.w3.org/2000/xmlns/", or if the namespaceURI is "http://www.w3.org/2000/xmlns/" and neither the qualifiedName nor its prefix is "xmlns".
"XML" feature, since namespaces were
defined by XML.com.google.gwt.core.client.JavaScriptExceptionpublic static final com.google.gwt.dom.client.Document createDocument(String uri, String qname)
public static final com.google.gwt.dom.client.Node importNode(com.google.gwt.dom.client.Document document,
com.google.gwt.dom.client.Node importedNode,
boolean deep)
parentNode is null).
nodeName and nodeType, plus the
attributes related to namespaces (prefix,
localName, and namespaceURI). As in the
cloneNode operation, the source node is not altered.
User data associated to the imported node is not carried over.
However, if any UserDataHandlers has been specified
along with the associated data these handlers will be called with the
appropriate parameters before this method returns.
nodeType, attempting to mirror the behavior expected if
a fragment of XML or HTML source was copied from one document to
another, recognizing that the two documents may have different DTDs
in the XML case. The following list describes the specifics for each
type of node.
ownerElement attribute
is set to null and the specified flag is
set to true on the generated Attr. The
descendants of the source Attr are recursively imported
and the resulting nodes reassembled to form the corresponding subtree.
Note that the deep parameter has no effect on
Attr nodes; they always carry their children with them
when imported.deep option
was set to true, the descendants of the source
DocumentFragment are recursively imported and the
resulting nodes reassembled under the imported
DocumentFragment to form the corresponding subtree.
Otherwise, this simply generates an empty
DocumentFragment.Document
nodes cannot be imported.DocumentType
nodes cannot be imported.Attr nodes are attached to the generated
Element. Default attributes are not copied, though if the document being imported into defines default
attributes for this element name, those are assigned. If the
importNode deep parameter was set to
true, the descendants of the source element are
recursively imported and the resulting nodes reassembled to form the
corresponding subtree.Entity nodes can be
imported, however in the current release of the DOM the
DocumentType is readonly. Ability to add these imported
nodes to a DocumentType will be considered for addition
to a future release of the DOM.On import, the publicId,
systemId, and notationName attributes are
copied. If a deep import is requested, the descendants
of the the source Entity are recursively imported and
the resulting nodes reassembled to form the corresponding subtree.EntityReference itself is
copied, even if a deep import is requested, since the
source and destination documents might have defined the entity
differently. If the document being imported into provides a
definition for this entity name, its value is assigned.Notation nodes can be imported, however in the current
release of the DOM the DocumentType is readonly. Ability
to add these imported nodes to a DocumentType will be
considered for addition to a future release of the DOM.On import, the
publicId and systemId attributes are copied.
Note that the deep parameter has no effect on this type
of nodes since they cannot have any children.target and data values from those of the
source node.Note that the deep parameter has no effect
on this type of nodes since they cannot have any children.CharacterData copy their data and
length attributes from those of the source node.Note
that the deep parameter has no effect on these types of
nodes since they cannot have any children.document - The document in which to import the node.importedNode - The node to import.deep - If true, recursively import the subtree under
the specified node; if false, import only the node
itself, as explained above. This has no effect on nodes that cannot
have any children, and on Attr, and
EntityReference nodes.Document.DOMException - NOT_SUPPORTED_ERR: Raised if the type of node being imported is not
supported.
Document.xmlVersion attribute. This may happen when
importing an XML 1.1 [XML 1.1] element
into an XML 1.0 document, for instance.public static final void normalize(com.google.gwt.dom.client.Node node)
Text nodes in the full depth of the sub-tree
underneath this Node, including attribute nodes, into a
"normal" form where only structure (e.g., elements, comments,
processing instructions, CDATA sections, and entity references)
separates Text nodes, i.e., there are neither adjacent
Text nodes nor empty Text nodes. This can
be used to ensure that the DOM view of a document is the same as if
it were saved and re-loaded, and is useful when operations (such as
XPointer [XPointer]
lookups) that depend on a particular document tree structure are to
be used. If the parameter "normalize-characters" of the
DOMConfiguration object attached to the
Node.ownerDocument is true, this method
will also fully normalize the characters of the Text
nodes.
Note: In cases where the document contains
CDATASections, the normalize operation alone may not be
sufficient, since XPointers do not differentiate between
Text nodes and CDATASection nodes.
node - the node to normalizepublic static final String substringData(com.google.gwt.dom.client.Text text, int offset, int count) throws com.google.gwt.core.client.JavaScriptException
text - the text nodeoffset - Start offset of substring to extract.count - The number of 16-bit units to extract.offset and
count exceeds the length, then all 16-bit
units to the end of the data are returned.DOMException - INDEX_SIZE_ERR: Raised if the specified offset is
negative or greater than the number of 16-bit units in
data, or if the specified count is
negative.
String.com.google.gwt.core.client.JavaScriptExceptionpublic static final void appendData(com.google.gwt.dom.client.Text text,
String arg)
throws com.google.gwt.core.client.JavaScriptException
data provides access to the concatenation of
data and the String specified.text - the text nodearg - The String to append.DOMException - NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.com.google.gwt.core.client.JavaScriptExceptionpublic static final String getAttributeNS(com.google.gwt.dom.client.Element elem, String namespaceURI, String localName) throws com.google.gwt.core.client.JavaScriptException
null as the
namespaceURI parameter for methods if they wish to have
no namespace.elem - the elementnamespaceURI - The namespace URI of the attribute to retrieve.localName - The local name of the attribute to retrieve.Attr value as a string, or the empty string
if that attribute does not have a specified or default value.DOMException - NOT_SUPPORTED_ERR: May be raised if the implementation does not
support the feature "XML" and the language exposed
through the Document does not support XML Namespaces (such as [HTML 4.01]).com.google.gwt.core.client.JavaScriptExceptionpublic static final com.google.gwt.dom.client.NodeList<? extends com.google.gwt.dom.client.Node> getElementsByTagNameNS(com.google.gwt.dom.client.Element elem,
String namespaceURI,
String localName)
throws com.google.gwt.core.client.JavaScriptException
NodeList of all the descendant
Elements of the specified element
with a given local name and namespace URI in
document order.elem - The elementnamespaceURI - The namespace URI of the elements to match on. The
special value "*" matches all namespaces.localName - The local name of the elements to match on. The
special value "*" matches all local names.NodeList object containing all the matched
Elements.DOMException - NOT_SUPPORTED_ERR: May be raised if the implementation does not
support the feature "XML" and the language exposed
through the Document does not support XML Namespaces (such as [HTML 4.01]).com.google.gwt.core.client.JavaScriptExceptionpublic static final com.google.gwt.dom.client.NodeList<? extends com.google.gwt.dom.client.Node> getElementsByTagNameNS(com.google.gwt.dom.client.Document doc,
String namespaceURI,
String localName)
throws com.google.gwt.core.client.JavaScriptException
NodeList of all the Elements
in the specified document with a
given local name and namespace URI in document order.doc - The documentnamespaceURI - The namespace URI of the elements to match on. The
special value "*" matches all namespaces.localName - The local name of the elements to match on. The
special value "*" matches all local names.NodeList object containing all the matched
Elements.com.google.gwt.core.client.JavaScriptExceptionpublic static final com.google.gwt.dom.client.Document getCurrentDocument()
public static final NamedNodeMap<Attr> getAttributes(com.google.gwt.dom.client.Element elem)
NamedNodeMap containing the attributes of the
specified element.elem - The elementNamedNodeMap containing the attributes of the
specified elementpublic static final Attr getAttributeNode(com.google.gwt.dom.client.Element elt, String attrName)
getAttributeNodeNS method.elt - The elementattrName - The name (nodeName) of the attribute to
retrieve.Attr node with the specified name (
nodeName) or null if there is no such
attribute.public static final Attr setAttributeNode(com.google.gwt.dom.client.Element elt, Attr attr) throws com.google.gwt.core.client.JavaScriptException
nodeName) is already present in the element, it is
replaced by the new one. Replacing an attribute node by itself has no
effect.
setAttributeNodeNS method.elt - The elementattr - The Attr node to add to the attribute list.attr attribute replaces an existing
attribute, the replaced Attr node is returned,
otherwise null is returned.DOMException - WRONG_DOCUMENT_ERR: Raised if attr was created from a
different document than the one that created the element.
attr is already an
attribute of another Element object. The DOM user must
explicitly clone Attr nodes to re-use them in other
elements.com.google.gwt.core.client.JavaScriptExceptionpublic static final boolean hasAttributeNS(com.google.gwt.dom.client.Element elem,
String namespaceURI,
String localName)
throws com.google.gwt.core.client.JavaScriptException
true when an attribute with a given local name and
namespace URI is specified on the specified element or has a default value,
false otherwise.
null as the
namespaceURI parameter for methods if they wish to have
no namespace.elem - The elementnamespaceURI - The namespace URI of the attribute to look for.localName - The local name of the attribute to look for.true if an attribute with the given local name
and namespace URI is specified or has a default value on this
element, false otherwise.DOMException - NOT_SUPPORTED_ERR: May be raised if the implementation does not
support the feature "XML" and the language exposed
through the Document does not support XML Namespaces (such as [HTML 4.01]).com.google.gwt.core.client.JavaScriptExceptionpublic static final void setAttributeNS(com.google.gwt.dom.client.Element elem,
String namespaceURI,
String localName,
String value)
throws com.google.gwt.core.client.JavaScriptException
qualifiedName, and
its value is changed to be the value parameter. This
value is a simple string; it is not parsed as it is being set. So any
markup (such as syntax to be recognized as an entity reference) is
treated as literal text, and needs to be appropriately escaped by the
implementation when it is written out. In order to assign an
attribute value that contains entity references, the user must create
an Attr node plus any Text and
EntityReference nodes, build the appropriate subtree,
and use setAttributeNodeNS or
setAttributeNode to assign it as the value of an
attribute.
null as the
namespaceURI parameter for methods if they wish to have
no namespace.elem - The elementnamespaceURI - The namespace URI of the attribute to create or
alter.localName - The local name of the attribute to create or
alter.value - The value to set in string form.DOMException - INVALID_CHARACTER_ERR: Raised if the specified qualified name is not
an XML name according to the XML version in use specified in the
Document.xmlVersion attribute.
qualifiedName is
malformed per the Namespaces in XML specification, if the
qualifiedName has a prefix and the
namespaceURI is null, if the
qualifiedName has a prefix that is "xml" and the
namespaceURI is different from "
http://www.w3.org/XML/1998/namespace", if the qualifiedName or its prefix is "xmlns" and the
namespaceURI is different from "http://www.w3.org/2000/xmlns/", or if the namespaceURI is "http://www.w3.org/2000/xmlns/" and neither the qualifiedName nor its prefix is "xmlns".
"XML" and the language exposed
through the Document does not support XML Namespaces (such as [HTML 4.01]).com.google.gwt.core.client.JavaScriptExceptionpublic static String getNamespaceURI(com.google.gwt.dom.client.Node node)
null if it is
unspecified (see ).
ELEMENT_NODE and
ATTRIBUTE_NODE and nodes created with a DOM Level 1
method, such as Document.createElement(), this is always
null.
Note: Per the Namespaces in XML Specification [XML Namespaces] an attribute does not inherit its namespace from the element it is attached to. If an attribute is not explicitly given a namespace, it simply has no namespace.
node - a DOM nodepublic static String getLocalName(com.google.gwt.dom.client.Node node)
ELEMENT_NODE and
ATTRIBUTE_NODE and nodes created with a DOM Level 1
method, such as Document.createElement(), this is always
null.node - a DOM nodepublic static void bindEventListener(com.google.gwt.dom.client.Element elem,
String eventName)
elem - The element emitting the eventseventName - The event namepublic static void unbindEventListener(com.google.gwt.dom.client.Element elem,
String eventName)
elem - The element emitting the eventseventName - The event namepublic static OMSVGElement getCaptureElement()
setCaptureElement(OMSVGElement, LoseCaptureHandler)
or null if element is set to capture eventspublic static com.google.gwt.event.shared.HandlerRegistration setCaptureElement(OMSVGElement element, com.google.gwt.event.dom.client.LoseCaptureHandler loseCaptureHandler)
releaseCaptureElement()
terminates the captureelement - The capturing elementloseCaptureHandler - A handler which will be invoked
if the element loses captureHandlerRegistration used to remove this handlerpublic static void releaseCaptureElement()
setCaptureElement(OMSVGElement, LoseCaptureHandler)public static final String getType(com.google.gwt.core.client.JavaScriptObject x)
public static final String toUrl(String s)
s - the identifier of the data pointed by the href.public static boolean hasFeature(String featureName)
featureName - The name of the feature to testpublic static <T extends OMNode> Iterator<T> evaluateXPath(OMElement root, String expr, XPathPrefixResolver resolver)
OMNode node list.
The expression must evaluate to a node list.root - The element the expression is rooted atexpr - The XPath expressionresolver - A prefix resolver if the expression has prefixpublic static <T extends com.google.gwt.dom.client.Node> Iterator<T> evaluateNodeListXPath(com.google.gwt.dom.client.Element root, String expr, XPathPrefixResolver resolver)
Node node list.
The expression must evaluate to a node list.root - The element the expression is rooted atexpr - The XPath expressionresolver - A prefix resolver if the expression has prefixpublic static <T extends com.google.gwt.dom.client.Node> T evaluateNodeXPath(com.google.gwt.dom.client.Element root,
String expr,
XPathPrefixResolver resolver)
Node node.
The expression must evaluate to a single node.root - The element the expression is rooted atexpr - The XPath expressionresolver - A prefix resolver if the expression has prefixpublic static String evaluateStringXPath(com.google.gwt.dom.client.Element root, String expr, XPathPrefixResolver resolver)
String.
The expression must evaluate to a string.root - The element the expression is rooted atexpr - The XPath expressionresolver - A prefix resolver if the expression has prefixpublic static float evaluateNumberXPath(com.google.gwt.dom.client.Element root,
String expr,
XPathPrefixResolver resolver)
root - The element the expression is rooted atexpr - The XPath expressionresolver - A prefix resolver if the expression has prefixpublic static boolean evaluateBooleanXPath(com.google.gwt.dom.client.Element root,
String expr,
XPathPrefixResolver resolver)
root - The element the expression is rooted atexpr - The XPath expressionresolver - A prefix resolver if the expression has prefixpublic static String getXPath(com.google.gwt.dom.client.Node node, com.google.gwt.dom.client.Node root)
node - The node to reachroot - The root node, or null to specify the document rootpublic static boolean supportsSvgTouchEvents()
hasFeature(String) method with the
SVGConstants.SVG_FEATURE_TOUCH_EVENTS parameter instead.Copyright © 2018. All Rights Reserved.