|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.google.gwt.uibinder.rebind.XMLElement
public class XMLElement
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.
| Nested Class Summary | |
|---|---|
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. |
| Method Summary | |
|---|---|
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. |
java.lang.String |
consumeAttribute(java.lang.String name,
JType type)
Consumes the given attribute as a literal or field reference. |
java.lang.String |
consumeAttributeWithDefault(java.lang.String name,
java.lang.String defaultValue,
JType type)
Consumes the given attribute as a literal or field reference. |
java.lang.String |
consumeAttributeWithDefault(java.lang.String name,
java.lang.String defaultValue,
JType[] types)
Like consumeAttributeWithDefault(String, String, JType), but
accomodates more complex type signatures. |
java.lang.String |
consumeBooleanAttribute(java.lang.String name)
Convenience method for parsing the named attribute as a boolean value or reference. |
java.lang.String |
consumeBooleanAttribute(java.lang.String name,
boolean defaultValue)
Convenience method for parsing the named attribute as a boolean value or reference. |
java.lang.Boolean |
consumeBooleanConstantAttribute(java.lang.String name)
Consumes the named attribute as a boolean expression. |
java.lang.Iterable<XMLElement> |
consumeChildElements()
Consumes and returns all child elements. |
java.util.Collection<XMLElement> |
consumeChildElements(XMLElement.Interpreter<java.lang.Boolean> interpreter)
Consumes and returns all child elements selected by the interpreter. |
java.lang.String |
consumeImageResourceAttribute(java.lang.String name)
Convenience method for parsing the named attribute as an ImageResource value or reference. |
java.lang.String |
consumeInnerHtml(XMLElement.Interpreter<java.lang.String> interpreter)
Consumes all child elements, and returns an HTML interpretation of them. |
java.lang.String |
consumeInnerHtml(XMLElement.PostProcessingInterpreter<java.lang.String> interpreter)
Refines consumeInnerHtml(Interpreter) to handle
PostProcessingInterpreter. |
java.lang.String |
consumeInnerText(XMLElement.PostProcessingInterpreter<java.lang.String> interpreter)
Refines consumeInnerTextEscapedAsHtmlStringLiteral(Interpreter) to
handle PostProcessingInterpreter. |
java.lang.String |
consumeInnerTextEscapedAsHtmlStringLiteral(XMLElement.Interpreter<java.lang.String> interpreter)
Consumes all child text nodes, and asserts that this element held only text. |
java.lang.String |
consumeLengthAttribute(java.lang.String name)
Convenience method for parsing the named attribute as a CSS length value. |
java.lang.String |
consumeOpeningTag()
Consumes all attributes, and returns a string representing the entire opening tag. |
java.lang.String[] |
consumeRawArrayAttribute(java.lang.String name)
Consumes the named attribute and parses it to an unparsed, unescaped array of Strings. |
java.lang.String |
consumeRawAttribute(java.lang.String name)
Consumes the given attribute and returns its trimmed value, or null if it was unset. |
java.lang.String |
consumeRawAttribute(java.lang.String name,
java.lang.String defaultValue)
Consumes the given attribute and returns its trimmed value, or the given default value if it was unset. |
java.lang.String |
consumeRequiredAttribute(java.lang.String name,
JType... types)
Consumes the given required attribute as a literal or field reference. |
java.lang.String |
consumeRequiredDoubleAttribute(java.lang.String name)
Convenience method for parsing the named required attribute as a double value or reference. |
java.lang.String |
consumeRequiredRawAttribute(java.lang.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. |
java.lang.String[] |
consumeStringArrayAttribute(java.lang.String name)
Consumes the named attribute and parses it to an array of String expressions. |
java.lang.String |
consumeStringAttribute(java.lang.String name)
Convenience method for parsing the named attribute as a String value or reference. |
java.lang.String |
consumeStringAttribute(java.lang.String name,
java.lang.String defaultValue)
Convenience method for parsing the named attribute as a String value or reference. |
java.lang.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(java.lang.String name)
Get the attribute with the given name. |
int |
getAttributeCount()
|
java.lang.String |
getClosingTag()
|
java.lang.String |
getLocalName()
Gets this element's local name (sans namespace prefix). |
XMLElement.Location |
getLocation()
|
java.lang.String |
getNamespaceUri()
Gets this element's namespace URI. |
java.lang.String |
getNamespaceUriForAttribute(java.lang.String fieldName)
|
XMLElement |
getParent()
|
java.lang.String |
getPrefix()
|
boolean |
hasAttribute(java.lang.String name)
Determines whether the element has a given attribute. |
boolean |
hasChildNodes()
|
java.lang.String |
lookupPrefix(java.lang.String prefix)
|
void |
setAttribute(java.lang.String name,
java.lang.String value)
|
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Method Detail |
|---|
public void assertNoAttributes()
throws UnableToCompleteException
UnableToCompleteException - if it does
public void assertNoBody()
throws UnableToCompleteException
UnableToCompleteException - if it isn't
public void assertNoText()
throws UnableToCompleteException
UnableToCompleteException - if it isn't
public java.lang.String consumeAttribute(java.lang.String name,
JType type)
throws UnableToCompleteException
name - the attribute's full name (including prefix)type - the type this attribute is expected to provide
UnableToCompleteException - on parse failure
public java.lang.String consumeAttributeWithDefault(java.lang.String name,
java.lang.String defaultValue,
JType type)
throws 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 provide
UnableToCompleteException - on parse failure
public java.lang.String consumeAttributeWithDefault(java.lang.String name,
java.lang.String defaultValue,
JType[] types)
throws UnableToCompleteException
consumeAttributeWithDefault(String, String, JType), but
accomodates more complex type signatures.
UnableToCompleteException
public java.lang.String consumeBooleanAttribute(java.lang.String name)
throws UnableToCompleteException
UnableToCompleteException - on unparseable value
public java.lang.String consumeBooleanAttribute(java.lang.String name,
boolean defaultValue)
throws UnableToCompleteException
defaultValue - value to return if attribute was not set
UnableToCompleteException - on unparseable value
public java.lang.Boolean consumeBooleanConstantAttribute(java.lang.String name)
throws UnableToCompleteException
Boolean.TRUE, Boolean.FALSE, or null if no such
attribute
UnableToCompleteException - on unparseable value
public java.lang.Iterable<XMLElement> consumeChildElements()
throws UnableToCompleteException
UnableToCompleteException - if extra text nodes are found
public java.util.Collection<XMLElement> consumeChildElements(XMLElement.Interpreter<java.lang.Boolean> interpreter)
throws UnableToCompleteException
interpreter - Should return true for any child that should be consumed
and returned by the consumeChildElements call
UnableToCompleteException
public java.lang.String consumeImageResourceAttribute(java.lang.String name)
throws UnableToCompleteException
UnableToCompleteException - on unparseable value
public java.lang.String consumeInnerHtml(XMLElement.Interpreter<java.lang.String> interpreter)
throws 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
com.google.gwt.uibinder.elementparsers.templates.parsers.HtmlInterpreter
for an HTML value, or
com.google.gwt.uibinder.elementparsers.templates.parsers.TextInterpreter
for text.
interpreter - Called for each element, expected to return a string
replacement for it, or null if it should be left as is
UnableToCompleteException
public java.lang.String consumeInnerHtml(XMLElement.PostProcessingInterpreter<java.lang.String> interpreter)
throws UnableToCompleteException
consumeInnerHtml(Interpreter) to handle
PostProcessingInterpreter.
UnableToCompleteException
public java.lang.String consumeInnerText(XMLElement.PostProcessingInterpreter<java.lang.String> interpreter)
throws UnableToCompleteException
consumeInnerTextEscapedAsHtmlStringLiteral(Interpreter) to
handle PostProcessingInterpreter.
UnableToCompleteException
public java.lang.String consumeInnerTextEscapedAsHtmlStringLiteral(XMLElement.Interpreter<java.lang.String> interpreter)
throws UnableToCompleteException
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
UnableToCompleteException - If any elements present are not consumed
by the interpreter
public java.lang.String consumeLengthAttribute(java.lang.String name)
throws UnableToCompleteException
UnableToCompleteException - on unparseable valuepublic java.lang.String consumeOpeningTag()
public java.lang.String[] consumeRawArrayAttribute(java.lang.String name)
public java.lang.String consumeRawAttribute(java.lang.String name)
name - the attribute's full name (including prefix)
public java.lang.String consumeRawAttribute(java.lang.String name,
java.lang.String defaultValue)
name - the attribute's full name (including prefix)defaultValue - the value to return if the attribute was unset
public java.lang.String consumeRequiredAttribute(java.lang.String name,
JType... types)
throws UnableToCompleteException
name - the attribute's full name (including prefix)types - the type(s) this attribute is expected to provide
UnableToCompleteException - on parse failure, or if the attribute is
empty or unspecified
public java.lang.String consumeRequiredDoubleAttribute(java.lang.String name)
throws UnableToCompleteException
UnableToCompleteException - on unparseable value, or if the attribute
is empty or unspecified
public java.lang.String consumeRequiredRawAttribute(java.lang.String name)
throws UnableToCompleteException
UnableToCompleteExceptionpublic XMLElement consumeSingleChildElement() throws UnableToCompleteException
UnableToCompleteException - on no children, or too many
public java.lang.String[] consumeStringArrayAttribute(java.lang.String name)
throws UnableToCompleteException
UnableToCompleteException - on unparseable value
public java.lang.String consumeStringAttribute(java.lang.String name)
throws UnableToCompleteException
UnableToCompleteException - on unparseable value
public java.lang.String consumeStringAttribute(java.lang.String name,
java.lang.String defaultValue)
throws UnableToCompleteException
UnableToCompleteException - on unparseable value
public java.lang.String consumeUnescapedInnerText()
throws UnableToCompleteException
You probably want to use
consumeInnerTextEscapedAsHtmlStringLiteral(com.google.gwt.uibinder.rebind.XMLElement.Interpreter instead.
UnableToCompleteException - if it held anything other than text nodespublic XMLAttribute getAttribute(int i)
public XMLAttribute getAttribute(java.lang.String name)
public int getAttributeCount()
public java.lang.String getClosingTag()
public java.lang.String getLocalName()
public XMLElement.Location getLocation()
public java.lang.String getNamespaceUri()
public java.lang.String getNamespaceUriForAttribute(java.lang.String fieldName)
public XMLElement getParent()
public java.lang.String getPrefix()
public boolean hasAttribute(java.lang.String name)
public boolean hasChildNodes()
public java.lang.String lookupPrefix(java.lang.String prefix)
public void setAttribute(java.lang.String name,
java.lang.String value)
public java.lang.String toString()
toString in class java.lang.Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||