public class

XMLElement

extends Object
java.lang.Object
   ↳ com.google.gwt.uibinder.rebind.XMLElement

Class Overview

A wrapper for 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.

Summary

Nested Classes
interface XMLElement.Interpreter<T> Callback interface used by consumeInnerHtml(Interpreter) and consumeChildElements(Interpreter)
class XMLElement.Location Represents the source location where the XMLElement was declared. 
interface XMLElement.PostProcessingInterpreter<T> Extends XMLElement.Interpreter with a method to be called after all elements have been processed. 
Public Methods
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, JType type)
Consumes the given attribute as a literal or field reference.
String consumeAttributeWithDefault(String name, String defaultValue, JType[] types)
Like consumeAttributeWithDefault(String, String, JType), but accommodates more complex type signatures.
String consumeAttributeWithDefault(String name, String defaultValue, 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(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(PostProcessingInterpreter<String> interpreter)
Refines consumeInnerHtml(Interpreter) to handle PostProcessingInterpreter.
String consumeInnerHtml(Interpreter<String> interpreter)
Consumes all child elements, and returns an HTML interpretation of them.
String consumeInnerText(PostProcessingInterpreter<String> interpreter)
Refines consumeInnerTextEscapedAsHtmlStringLiteral(Interpreter) to handle PostProcessingInterpreter.
String consumeInnerTextEscapedAsHtmlStringLiteral(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, 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.
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.
XMLAttribute getAttribute(int i)
Get the attribute at the given index.
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".
String getLocalName()
Gets this element's local name (sans namespace prefix).
XMLElement.Location getLocation()
String getNamespaceUri()
Gets this element's namespace URI.
String getNamespaceUriForAttribute(String fieldName)
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()
[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public void assertNoAttributes ()

Ensure that the receiver has no attributes left.

Throws
UnableToCompleteException if it does

public void assertNoBody ()

Require that the receiver's body is empty of text and has no child nodes.

Throws
UnableToCompleteException if it isn't

public void assertNoText ()

Require that the receiver's body is empty of text.

Throws
UnableToCompleteException if it isn't

public String consumeAttribute (String name, JType type)

Consumes the given attribute as a literal or field reference. The type parameter is required to determine how the value is parsed and validated.

Parameters
name the attribute's full name (including prefix)
type the type this attribute is expected to provide
Returns
  • the attribute's value as a Java expression, or null if it is not set
Throws
UnableToCompleteException on parse failure

public String consumeAttributeWithDefault (String name, String defaultValue, JType[] types)

Like consumeAttributeWithDefault(String, String, JType), but accommodates more complex type signatures.

Throws
UnableToCompleteException

public String consumeAttributeWithDefault (String name, String defaultValue, JType type)

Consumes the given attribute as a literal or field reference. The type parameter is required to determine how the value is parsed and validated.

Parameters
name the attribute's full name (including prefix)
defaultValue the value to @return if the attribute was unset
type the type this attribute is expected to provide
Returns
  • the attribute's value as a Java expression, or the given default if it was unset
Throws
UnableToCompleteException on parse failure

public String consumeBooleanAttribute (String name)

Convenience method for parsing the named attribute as a boolean value or reference.

Returns
  • an expression that will evaluate to a boolean value in the generated code, or null if there is no such attribute
Throws
UnableToCompleteException on unparseable value

public String consumeBooleanAttribute (String name, boolean defaultValue)

Convenience method for parsing the named attribute as a boolean value or reference.

Parameters
defaultValue value to return if attribute was not set
Returns
  • an expression that will evaluate to a boolean value in the generated code, or defaultValue if there is no such attribute
Throws
UnableToCompleteException on unparseable value

public Boolean consumeBooleanConstantAttribute (String name)

Consumes the named attribute as a boolean expression. This will not accept {field.reference} expressions. Useful for values that must be resolved at compile time, such as generated annotation values.

Returns
Throws
UnableToCompleteException on unparseable value

public Iterable<XMLElement> consumeChildElements ()

Consumes and returns all child elements.

Throws
UnableToCompleteException if extra text nodes are found

public Collection<XMLElement> consumeChildElements (Interpreter<Boolean> interpreter)

Consumes and returns all child elements selected by the interpreter. Note that text nodes are not elements, and so are not presented for interpretation, and are not consumed.

Parameters
interpreter Should return true for any child that should be consumed and returned by the consumeChildElements call
Throws
UnableToCompleteException

public String consumeImageResourceAttribute (String name)

Convenience method for parsing the named attribute as an ImageResource value or reference.

Returns
  • an expression that will evaluate to an ImageResource value in the generated code, or null if there is no such attribute
Throws
UnableToCompleteException on unparseable value

public String consumeInnerHtml (PostProcessingInterpreter<String> interpreter)

Refines consumeInnerHtml(Interpreter) to handle PostProcessingInterpreter.

Throws
UnableToCompleteException

public String consumeInnerHtml (Interpreter<String> interpreter)

Consumes all child elements, and returns an HTML interpretation of them. Trailing and leading whitespace is trimmed.

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 com.google.gwt.uibinder.elementparsers.templates.parsers.HtmlInterpreter for an HTML value, or com.google.gwt.uibinder.elementparsers.templates.parsers.TextInterpreter for text.

Parameters
interpreter Called for each element, expected to return a string replacement for it, or null if it should be left as is
Throws
UnableToCompleteException

public String consumeInnerText (PostProcessingInterpreter<String> interpreter)

Refines consumeInnerTextEscapedAsHtmlStringLiteral(Interpreter) to handle PostProcessingInterpreter.

Throws
UnableToCompleteException

public String consumeInnerTextEscapedAsHtmlStringLiteral (Interpreter<String> interpreter)

Consumes all child text nodes, and asserts that this element held only text. Trailing and leading whitespace is trimmed, and escaped for use as a string literal. Notice that HTML entities in the text are also escaped--is this a source of errors?

This call requires an interpreter to make sense of any special children. The odds are you want to use com.google.gwt.uibinder.elementparsers.templates.parsers.TextInterpreter

Throws
UnableToCompleteException If any elements present are not consumed by the interpreter

public String consumeLengthAttribute (String name)

Convenience method for parsing the named attribute as a CSS length value.

Returns
  • a (double, Unit) pair literal, an expression that will evaluate to such a pair in the generated code, or null if there is no such attribute
Throws
UnableToCompleteException on unparseable value

public String consumeOpeningTag ()

Consumes all attributes, and returns a string representing the entire opening tag. E.g., "

"

public String[] consumeRawArrayAttribute (String name)

Consumes the named attribute and parses it to an unparsed, unescaped array of Strings. The strings in the attribute may be comma or space separated (or a mix of both).

Returns
  • array of String, empty if the attribute was not set.

public String consumeRawAttribute (String name)

Consumes the given attribute and returns its trimmed value, or null if it was unset. The returned string is not escaped.

Parameters
name the attribute's full name (including prefix)
Returns
  • the attribute's value, or ""

public String consumeRawAttribute (String name, String defaultValue)

Consumes the given attribute and returns its trimmed value, or the given default value if it was unset. The returned string is not escaped.

Parameters
name the attribute's full name (including prefix)
defaultValue the value to return if the attribute was unset
Returns
  • the attribute's value, or defaultValue

public String consumeRequiredAttribute (String name, JType... types)

Consumes the given required attribute as a literal or field reference. The types parameters are required to determine how the value is parsed and validated.

Parameters
name the attribute's full name (including prefix)
types the type(s) this attribute is expected to provide
Returns
  • the attribute's value as a Java expression
Throws
UnableToCompleteException on parse failure, or if the attribute is empty or unspecified

public String consumeRequiredDoubleAttribute (String name)

Convenience method for parsing the named required attribute as a double value or reference.

Returns
  • a double literal, an expression that will evaluate to a double value in the generated code
Throws
UnableToCompleteException on unparseable value, or if the attribute is empty or unspecified

public String consumeRequiredIntAttribute (String name)

Convenience method for parsing the named required attribute as a integer value or reference.

Returns
  • a integer literal, an expression that will evaluate to a integer value in the generated code
Throws
UnableToCompleteException on unparseable value, or if the attribute is empty or unspecified

public String consumeRequiredRawAttribute (String name)

Consumes the named attribute, or dies if it is missing.

Throws
UnableToCompleteException

public 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.

Throws
UnableToCompleteException on no children, or too many

public String[] consumeStringArrayAttribute (String name)

Consumes the named attribute and parses it to an array of String expressions. The strings in the attribute may be comma or space separated (or a mix of both).

Returns
  • array of String expressions, empty if the attribute was not set.
Throws
UnableToCompleteException on unparseable value

public String consumeStringAttribute (String name)

Convenience method for parsing the named attribute as a String value or reference.

Returns
  • an expression that will evaluate to a String value in the generated code, or null if there is no such attribute
Throws
UnableToCompleteException on unparseable value

public String consumeStringAttribute (String name, String defaultValue)

Convenience method for parsing the named attribute as a String value or reference.

Returns
  • an expression that will evaluate to a String value in the generated code, or the given defaultValue if there is no such attribute
Throws
UnableToCompleteException on unparseable value

public String consumeUnescapedInnerText ()

Returns the unprocessed, unescaped, raw inner text of the receiver. Dies if the receiver has non-text children.

You probably want to use consumeInnerTextEscapedAsHtmlStringLiteral(XMLElement.Interpreter) instead.

Returns
  • the text
Throws
UnableToCompleteException if it held anything other than text nodes

public XMLAttribute getAttribute (int i)

Get the attribute at the given index. If you are consuming attributes, remember to traverse them in reverse.

public XMLAttribute getAttribute (String name)

Get the attribute with the given name.

Returns
  • the attribute, or null if there is none of that name

public int getAttributeCount ()

Returns the number of attributes this element has.

public String getClosingTag ()

public String getDesignTimePath ()

Returns the design time path of this element, in form of indexes from root, such as "0/0/1/0".

public String getLocalName ()

Gets this element's local name (sans namespace prefix).

public XMLElement.Location getLocation ()

public String getNamespaceUri ()

Gets this element's namespace URI.

public String getNamespaceUriForAttribute (String fieldName)

public XMLElement getParent ()

Returns the parent element, or null if parent is null or a node type other than Element.

public String getPrefix ()

public boolean hasAttribute (String name)

Determines whether the element has a given attribute.

public boolean hasChildNodes ()

public String lookupPrefix (String prefix)

public void setAttribute (String name, String value)

public String toString ()