*/\r
Date getTextAsDate();\r
\r
+ /**\r
+ * Returns whether the text content of the element is true or false. \r
+ * It is false when the string matches false, off, 0 or empty. \r
+ */\r
+ boolean getTextAsBoolean();\r
+ \r
+ /**\r
+ * Returns the Enum value of the text content of the element.\r
+ */\r
+ <T extends Enum<T>> T getTextAsEnum(Class<T> clazz);\r
}\r
return g.attr(n);
}
- @Override
public String getText() {
return g.text();
}
- @Override
public double getTextAsNumber() {
String t = g.text().replaceAll("[^\\d\\.\\-]", "");
return t.isEmpty() ? 0 : Double.parseDouble(t);
}
- @Override
public Date getTextAsDate() {
String t = g.text().trim();
if (t.matches("\\d+")) {
}
}
+ public boolean getTextAsBoolean() {
+ String t = g.text().trim().toLowerCase();
+ return !t.matches("^(|false|off|0)$");
+ }
+
+ public <T extends Enum<T>> T getTextAsEnum(Class<T> clazz) {
+ String t = g.text().trim();
+ return Enum.valueOf(clazz, t);
+ }
+
@SuppressWarnings("unchecked")
public J load(Object o) {
assert o == null || o instanceof JavaScriptObject && JsUtils.isElement((JavaScriptObject)o) || o instanceof String;
}
@SuppressWarnings("unchecked")
- @Override
public <T> T setText(String t) {
g.text(t);
return (T)this;