public class XMLElement extends Object
Element
that limits the way parsers can interact with
the XML document, and provides some convenience methods.
The main function of this wrapper is to ensure that parsers can only read elements and attributes by 'consuming' them, which removes the given value. This allows for a natural hierarchy among parsers -- more specific parsers will run first, and if they consume a value, less-specific parsers will not see it.
Modifier and Type | Class and Description |
---|---|
static interface |
XMLElement.Interpreter<T>
Callback interface used by
consumeInnerHtml(Interpreter) and
consumeChildElements(Interpreter) . |
static class |
XMLElement.Location
Represents the source location where the XMLElement was declared.
|
static interface |
XMLElement.PostProcessingInterpreter<T>
Extends
XMLElement.Interpreter with a method to be called after all elements
have been processed. |
Modifier and Type | Method and Description |
---|---|
void |
assertNoAttributes()
Ensure that the receiver has no attributes left.
|
void |
assertNoBody()
Require that the receiver's body is empty of text and has no child nodes.
|
void |
assertNoText()
Require that the receiver's body is empty of text.
|
String |
consumeAttribute(String name,
com.google.gwt.core.ext.typeinfo.JType type)
Consumes the given attribute as a literal or field reference.
|
String |
consumeAttributeWithDefault(String name,
String defaultValue,
com.google.gwt.core.ext.typeinfo.JType... types)
Like
consumeAttributeWithDefault(String, String, JType) , but
accommodates more complex type signatures. |
String |
consumeAttributeWithDefault(String name,
String defaultValue,
com.google.gwt.core.ext.typeinfo.JType type)
Consumes the given attribute as a literal or field reference.
|
String |
consumeBooleanAttribute(String name)
Convenience method for parsing the named attribute as a boolean value or
reference.
|
String |
consumeBooleanAttribute(String name,
boolean defaultValue)
Convenience method for parsing the named attribute as a boolean value or
reference.
|
Boolean |
consumeBooleanConstantAttribute(String name)
Consumes the named attribute as a boolean expression.
|
Iterable<XMLElement> |
consumeChildElements()
Consumes and returns all child elements.
|
Collection<XMLElement> |
consumeChildElements(XMLElement.Interpreter<Boolean> interpreter)
Consumes and returns all child elements selected by the interpreter.
|
String |
consumeImageResourceAttribute(String name)
Convenience method for parsing the named attribute as an ImageResource
value or reference.
|
String |
consumeInnerHtml(XMLElement.Interpreter<String> interpreter)
Consumes all child elements, and returns an HTML interpretation of them.
|
String |
consumeInnerHtml(XMLElement.PostProcessingInterpreter<String> interpreter)
Refines
consumeInnerHtml(Interpreter) to handle
PostProcessingInterpreter. |
String |
consumeInnerText(XMLElement.PostProcessingInterpreter<String> interpreter)
Refines
consumeInnerTextEscapedAsHtmlStringLiteral(Interpreter) to
handle PostProcessingInterpreter. |
String |
consumeInnerTextEscapedAsHtmlStringLiteral(XMLElement.Interpreter<String> interpreter)
Consumes all child text nodes, and asserts that this element held only
text.
|
String |
consumeInnerTextEscapedAsStringLiteral(XMLElement.Interpreter<String> interpreter)
Consumes all child text nodes, and asserts that this element held only
text.
|
String |
consumeLengthAttribute(String name)
Convenience method for parsing the named attribute as a CSS length value.
|
String |
consumeOpeningTag()
Consumes all attributes, and returns a string representing the entire
opening tag.
|
String[] |
consumeRawArrayAttribute(String name)
Consumes the named attribute and parses it to an unparsed, unescaped array
of Strings.
|
String |
consumeRawAttribute(String name)
Consumes the given attribute and returns its trimmed value, or null if it
was unset.
|
String |
consumeRawAttribute(String name,
String defaultValue)
Consumes the given attribute and returns its trimmed value, or the given
default value if it was unset.
|
String |
consumeRequiredAttribute(String name,
com.google.gwt.core.ext.typeinfo.JType... types)
Consumes the given required attribute as a literal or field reference.
|
String |
consumeRequiredDoubleAttribute(String name)
Convenience method for parsing the named required attribute as a double
value or reference.
|
String |
consumeRequiredIntAttribute(String name)
Convenience method for parsing the named required attribute as a integer
value or reference.
|
String |
consumeRequiredRawAttribute(String name)
Consumes the named attribute, or dies if it is missing.
|
String |
consumeSafeHtmlAttribute(String name)
Convenience method for parsing the named attribute as a
SafeHtml value or
reference. |
String |
consumeSafeUriOrStringAttribute(String name)
Consumes an attribute as either a SafeUri or a String.
|
XMLElement |
consumeSingleChildElement()
Consumes a single child element, ignoring any text nodes and throwing an
exception if no child is found, or more than one child element is found.
|
String[] |
consumeStringArrayAttribute(String name)
Consumes the named attribute and parses it to an array of String
expressions.
|
String |
consumeStringAttribute(String name)
Convenience method for parsing the named attribute as a String value or
reference.
|
String |
consumeStringAttribute(String name,
String defaultValue)
Convenience method for parsing the named attribute as a String value or
reference.
|
String |
consumeUnescapedInnerText()
Returns the unprocessed, unescaped, raw inner text of the receiver.
|
com.google.gwt.uibinder.rebind.XMLAttribute |
getAttribute(int i)
Get the attribute at the given index.
|
com.google.gwt.uibinder.rebind.XMLAttribute |
getAttribute(String name)
Get the attribute with the given name.
|
int |
getAttributeCount()
Returns the number of attributes this element has.
|
String |
getClosingTag() |
String |
getDesignTimePath()
Returns the design time path of this element, in form of indexes from root,
such as "0/0/1/0".
|
Element |
getElement() |
String |
getLocalName()
Gets this element's local name (sans namespace prefix).
|
XMLElement.Location |
getLocation() |
String |
getNamespaceUri()
Gets this element's namespace URI.
|
XMLElement |
getParent()
Returns the parent element, or null if parent is null or a node type other
than Element.
|
String |
getPrefix() |
boolean |
hasAttribute(String name)
Determines whether the element has a given attribute.
|
boolean |
hasChildNodes() |
String |
lookupPrefix(String prefix) |
void |
setAttribute(String name,
String value) |
String |
toString() |
public void assertNoAttributes() throws com.google.gwt.core.ext.UnableToCompleteException
com.google.gwt.core.ext.UnableToCompleteException
- if it doespublic void assertNoBody() throws com.google.gwt.core.ext.UnableToCompleteException
com.google.gwt.core.ext.UnableToCompleteException
- if it isn'tpublic void assertNoText() throws com.google.gwt.core.ext.UnableToCompleteException
com.google.gwt.core.ext.UnableToCompleteException
- if it isn'tpublic String consumeAttribute(String name, com.google.gwt.core.ext.typeinfo.JType type) throws com.google.gwt.core.ext.UnableToCompleteException
name
- the attribute's full name (including prefix)type
- the type this attribute is expected to providecom.google.gwt.core.ext.UnableToCompleteException
- on parse failurepublic String consumeAttributeWithDefault(String name, String defaultValue, com.google.gwt.core.ext.typeinfo.JType type) throws com.google.gwt.core.ext.UnableToCompleteException
name
- the attribute's full name (including prefix)defaultValue
- the value to @return if the attribute was unsettype
- the type this attribute is expected to providecom.google.gwt.core.ext.UnableToCompleteException
- on parse failurepublic String consumeAttributeWithDefault(String name, String defaultValue, com.google.gwt.core.ext.typeinfo.JType... types) throws com.google.gwt.core.ext.UnableToCompleteException
consumeAttributeWithDefault(String, String, JType)
, but
accommodates more complex type signatures.com.google.gwt.core.ext.UnableToCompleteException
public String consumeBooleanAttribute(String name) throws com.google.gwt.core.ext.UnableToCompleteException
com.google.gwt.core.ext.UnableToCompleteException
- on unparseable valuepublic String consumeBooleanAttribute(String name, boolean defaultValue) throws com.google.gwt.core.ext.UnableToCompleteException
defaultValue
- value to return if attribute was not setcom.google.gwt.core.ext.UnableToCompleteException
- on unparseable valuepublic Boolean consumeBooleanConstantAttribute(String name) throws com.google.gwt.core.ext.UnableToCompleteException
Boolean.TRUE
, Boolean.FALSE
, or null if no such
attributecom.google.gwt.core.ext.UnableToCompleteException
- on unparseable valuepublic Iterable<XMLElement> consumeChildElements() throws com.google.gwt.core.ext.UnableToCompleteException
com.google.gwt.core.ext.UnableToCompleteException
- if extra text nodes are foundpublic Collection<XMLElement> consumeChildElements(XMLElement.Interpreter<Boolean> interpreter) throws com.google.gwt.core.ext.UnableToCompleteException
interpreter
- Should return true for any child that should be consumed
and returned by the consumeChildElements callcom.google.gwt.core.ext.UnableToCompleteException
public String consumeImageResourceAttribute(String name) throws com.google.gwt.core.ext.UnableToCompleteException
com.google.gwt.core.ext.UnableToCompleteException
- on unparseable valuepublic String consumeInnerHtml(XMLElement.Interpreter<String> interpreter) throws com.google.gwt.core.ext.UnableToCompleteException
Each element encountered will be passed to the given Interpreter for possible replacement. Escaping is performed to allow the returned text to serve as a Java string literal used as input to a setInnerHTML call.
This call requires an interpreter to make sense of any special children.
The odds are you want to use
HtmlInterpreter
for an HTML
value, or TextInterpreter
for text.
interpreter
- Called for each element, expected to return a string
replacement for it, or null if it should be left as iscom.google.gwt.core.ext.UnableToCompleteException
public String consumeInnerHtml(XMLElement.PostProcessingInterpreter<String> interpreter) throws com.google.gwt.core.ext.UnableToCompleteException
consumeInnerHtml(Interpreter)
to handle
PostProcessingInterpreter.com.google.gwt.core.ext.UnableToCompleteException
public String consumeInnerText(XMLElement.PostProcessingInterpreter<String> interpreter) throws com.google.gwt.core.ext.UnableToCompleteException
consumeInnerTextEscapedAsHtmlStringLiteral(Interpreter)
to
handle PostProcessingInterpreter.com.google.gwt.core.ext.UnableToCompleteException
public String consumeInnerTextEscapedAsHtmlStringLiteral(XMLElement.Interpreter<String> interpreter) throws com.google.gwt.core.ext.UnableToCompleteException
This call requires an interpreter to make sense of any special children.
The odds are you want to use
TextInterpreter
com.google.gwt.core.ext.UnableToCompleteException
- If any elements present are not consumed
by the interpreterpublic String consumeInnerTextEscapedAsStringLiteral(XMLElement.Interpreter<String> interpreter) throws com.google.gwt.core.ext.UnableToCompleteException
This call requires an interpreter to make sense of any special children.
The odds are you want to use
TextInterpreter
com.google.gwt.core.ext.UnableToCompleteException
- If any elements present are not consumed
by the interpreterpublic String consumeLengthAttribute(String name) throws com.google.gwt.core.ext.UnableToCompleteException
com.google.gwt.core.ext.UnableToCompleteException
- on unparseable valuepublic String consumeOpeningTag()
public String[] consumeRawArrayAttribute(String name)
public String consumeRawAttribute(String name)
name
- the attribute's full name (including prefix)public String consumeRawAttribute(String name, String defaultValue)
name
- the attribute's full name (including prefix)defaultValue
- the value to return if the attribute was unsetpublic String consumeRequiredAttribute(String name, com.google.gwt.core.ext.typeinfo.JType... types) throws com.google.gwt.core.ext.UnableToCompleteException
name
- the attribute's full name (including prefix)types
- the type(s) this attribute is expected to providecom.google.gwt.core.ext.UnableToCompleteException
- on parse failure, or if the attribute is
empty or unspecifiedpublic String consumeRequiredDoubleAttribute(String name) throws com.google.gwt.core.ext.UnableToCompleteException
com.google.gwt.core.ext.UnableToCompleteException
- on unparseable value, or if the attribute
is empty or unspecifiedpublic String consumeRequiredIntAttribute(String name) throws com.google.gwt.core.ext.UnableToCompleteException
com.google.gwt.core.ext.UnableToCompleteException
- on unparseable value, or if the attribute
is empty or unspecifiedpublic String consumeRequiredRawAttribute(String name) throws com.google.gwt.core.ext.UnableToCompleteException
com.google.gwt.core.ext.UnableToCompleteException
public String consumeSafeHtmlAttribute(String name) throws com.google.gwt.core.ext.UnableToCompleteException
SafeHtml
value or
reference.SafeHtml
value in
the generated code, or null if there is no such attributecom.google.gwt.core.ext.UnableToCompleteException
- on unparseable valuepublic String consumeSafeUriOrStringAttribute(String name) throws com.google.gwt.core.ext.UnableToCompleteException
com.google.gwt.core.ext.UnableToCompleteException
- on unparseable valuepublic XMLElement consumeSingleChildElement() throws com.google.gwt.core.ext.UnableToCompleteException
com.google.gwt.core.ext.UnableToCompleteException
- on no children, or too manypublic String[] consumeStringArrayAttribute(String name) throws com.google.gwt.core.ext.UnableToCompleteException
com.google.gwt.core.ext.UnableToCompleteException
- on unparseable valuepublic String consumeStringAttribute(String name) throws com.google.gwt.core.ext.UnableToCompleteException
com.google.gwt.core.ext.UnableToCompleteException
- on unparseable valuepublic String consumeStringAttribute(String name, String defaultValue) throws com.google.gwt.core.ext.UnableToCompleteException
com.google.gwt.core.ext.UnableToCompleteException
- on unparseable valuepublic String consumeUnescapedInnerText() throws com.google.gwt.core.ext.UnableToCompleteException
You probably want to use
consumeInnerTextEscapedAsHtmlStringLiteral(com.google.gwt.uibinder.rebind.XMLElement.Interpreter<java.lang.String>)
instead.
com.google.gwt.core.ext.UnableToCompleteException
- if it held anything other than text nodespublic com.google.gwt.uibinder.rebind.XMLAttribute getAttribute(int i)
public com.google.gwt.uibinder.rebind.XMLAttribute getAttribute(String name)
public int getAttributeCount()
public String getClosingTag()
public String getDesignTimePath()
public String getLocalName()
public XMLElement.Location getLocation()
public String getNamespaceUri()
public XMLElement getParent()
public String getPrefix()
public boolean hasAttribute(String name)
public boolean hasChildNodes()
public Element getElement()
Copyright © 2018. All Rights Reserved.