Reviewers: mrosett_google.com,
Description:
Fix http://code.google.com/p/google-web-toolkit/issues/detail?id=6161
by warning on suspicious looking namespaces. Also keep
StackLayoutPanelParser from generating bad code for such things.
Please review this at http://gwt-code-reviews.appspot.com/1520807/
Affected files:
M user/src/com/google/gwt/uibinder/elementparsers/HtmlInterpreter.java
M user/src/com/google/gwt/uibinder/elementparsers/StackPanelParser.java
M user/src/com/google/gwt/uibinder/rebind/XMLElement.java
M
user/test/com/google/gwt/uibinder/elementparsers/StackPanelParserTest.java
M user/test/com/google/gwt/uibinder/rebind/UiBinderParserUiWithTest.java
Index: user/src/com/google/gwt/uibinder/elementparsers/HtmlInterpreter.java
===================================================================
--- user/src/com/google/gwt/uibinder/elementparsers/HtmlInterpreter.java
(revision 10541)
+++ user/src/com/google/gwt/uibinder/elementparsers/HtmlInterpreter.java
(working copy)
@@ -94,6 +94,17 @@
if (writer.isImportedElement(elem)) {
writer.die(elem, "Not allowed in an HTML context");
}
+
+ if (elem.getNamespaceUri() != null && !writer.isBinderElement(elem)) {
+ /*
+ * It's not a widget, and it's not a ui: element. Warn the user.
Could
+ * die, but this is a recent bit of policing likely to break
accidentally
+ * functional templates. And there's a slim chance it was done on
purpose.
+ */
+ writer.warn(elem, "Prefix \"%s:\" has unrecognized xmlns \"%s\", "
+ + "will be rendered in the browser as is", elem.getPrefix(),
elem.getNamespaceUri());
+ }
+
return pipe.interpretElement(elem);
}
}
Index: user/src/com/google/gwt/uibinder/elementparsers/StackPanelParser.java
===================================================================
--- user/src/com/google/gwt/uibinder/elementparsers/StackPanelParser.java
(revision 10541)
+++ user/src/com/google/gwt/uibinder/elementparsers/StackPanelParser.java
(working copy)
@@ -31,7 +31,10 @@
UiBinderWriter writer) throws UnableToCompleteException {
// Parse children.
for (XMLElement child : elem.consumeChildElements()) {
-
+ if (!writer.isWidgetElement(child)) {
+ writer.die(child, "Widget required");
+ }
+
// Stack panel label comes from the StackPanel-text attribute of the
child
String stackItemLabel = null;
String variableAttributeName = elem.getPrefix() + ":" +
ATTRIBUTE_TEXT;
Index: user/src/com/google/gwt/uibinder/rebind/XMLElement.java
===================================================================
--- user/src/com/google/gwt/uibinder/rebind/XMLElement.java (revision 10541)
+++ user/src/com/google/gwt/uibinder/rebind/XMLElement.java (working copy)
@@ -784,11 +784,6 @@
return elem.getNamespaceURI();
}
- public String getNamespaceUriForAttribute(String fieldName) {
- Attr attr = elem.getAttributeNode(fieldName);
- return attr.getNamespaceURI();
- }
-
/**
* Returns the parent element, or null if parent is null or a node type
other
* than Element.
Index:
user/test/com/google/gwt/uibinder/elementparsers/StackPanelParserTest.java
===================================================================
---
user/test/com/google/gwt/uibinder/elementparsers/StackPanelParserTest.java
(revision 10541)
+++
user/test/com/google/gwt/uibinder/elementparsers/StackPanelParserTest.java
(working copy)
@@ -15,7 +15,11 @@
*/
package com.google.gwt.uibinder.elementparsers;
+import com.google.gwt.core.ext.UnableToCompleteException;
+
import junit.framework.TestCase;
+
+import org.xml.sax.SAXParseException;
import java.util.Iterator;
@@ -34,7 +38,7 @@
tester = new ElementParserTester(PARSED_TYPE, new StackPanelParser());
}
- public void testHappy_noStackText() throws Exception {
+ public void testHappy_noStackText() throws SAXParseException,
UnableToCompleteException {
StringBuffer b = new StringBuffer();
b.append("<g:StackPanel>");
b.append(" <g:Button/>");
@@ -45,7 +49,7 @@
assertStatements("fieldName.add(<g:Button>);");
}
- public void testHappy_hasStackText() throws Exception {
+ public void testHappy_hasStackText() throws SAXParseException,
UnableToCompleteException {
StringBuffer b = new StringBuffer();
b.append("<g:StackPanel>");
b.append(" <g:Button g:StackPanel-text='Foo'/>");
@@ -54,6 +58,19 @@
tester.parse(b.toString());
assertStatements("fieldName.add(<g:Button>, \"Foo\");");
+ }
+
+ public void testBadChild() throws SAXParseException {
+ StringBuffer b = new StringBuffer();
+ b.append("<g:StackPanel>");
+ b.append(" <g:UIObject/>");
+ b.append("</g:StackPanel>");
+ try {
+ tester.parse(b.toString());
+ fail("Expected UnableToCompleteException");
+ } catch (UnableToCompleteException e) {
+ /* pass */
+ }
}
private void assertStatements(String... expected) {
Index:
user/test/com/google/gwt/uibinder/rebind/UiBinderParserUiWithTest.java
===================================================================
--- user/test/com/google/gwt/uibinder/rebind/UiBinderParserUiWithTest.java
(revision 10541)
+++ user/test/com/google/gwt/uibinder/rebind/UiBinderParserUiWithTest.java
(working copy)
@@ -141,7 +141,6 @@
private UiBinderWriter writer;
- @SuppressWarnings("deprecation")
@Override
public void setUp() throws Exception {
super.setUp();
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors