Delete partially implemented HtmlElementFactory feature. Review at http://gwt-code-reviews.appspot.com/1412802 Review by: rchandia@google.com git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9980 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/uibinder/UiBinder.gwt.xml b/user/src/com/google/gwt/uibinder/UiBinder.gwt.xml index b9f2731..9a57445 100644 --- a/user/src/com/google/gwt/uibinder/UiBinder.gwt.xml +++ b/user/src/com/google/gwt/uibinder/UiBinder.gwt.xml
@@ -19,10 +19,6 @@ <source path="client"/> <source path="resources"/> - <!-- Pluggable factory for creating field types for HTML elements --> - <define-configuration-property name="uibinder.html.elementfactory" is-multi-valued="false"/> - <set-configuration-property name="uibinder.html.elementfactory" value="com.google.gwt.uibinder.rebind.GwtDomHtmlElementFactory"/> - <!-- By default UiBinder implementations are generated to use SafeHtmlTemplates to help protect against the introduction of cross-site scripting (XSS) attacks. This deprecated property can be used to disable that integration while the
diff --git a/user/src/com/google/gwt/uibinder/rebind/GwtDomHtmlElementFactory.java b/user/src/com/google/gwt/uibinder/rebind/GwtDomHtmlElementFactory.java deleted file mode 100644 index a0a4395..0000000 --- a/user/src/com/google/gwt/uibinder/rebind/GwtDomHtmlElementFactory.java +++ /dev/null
@@ -1,43 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.google.gwt.uibinder.rebind; - -import com.google.gwt.core.ext.typeinfo.JClassType; -import com.google.gwt.core.ext.typeinfo.TypeOracle; -import com.google.gwt.dom.client.TagName; - -/** - * Looks up implementation of DOM elements via @TagName interface in GWT DOM - * package. - */ -public class GwtDomHtmlElementFactory implements HtmlElementFactory { - - public JClassType findElementTypeForTag(String htmlTag, TypeOracle oracle) { - JClassType elementClass = oracle.findType("com.google.gwt.dom.client.Element"); - JClassType[] types = elementClass.getSubtypes(); - for (JClassType type : types) { - TagName annotation = type.getAnnotation(TagName.class); - if (annotation != null) { - for (String annotationTag : annotation.value()) { - if (annotationTag.equals(htmlTag)) { - return type; - } - } - } - } - return elementClass; - } -}
diff --git a/user/src/com/google/gwt/uibinder/rebind/HtmlElementFactory.java b/user/src/com/google/gwt/uibinder/rebind/HtmlElementFactory.java deleted file mode 100644 index 84f05ae..0000000 --- a/user/src/com/google/gwt/uibinder/rebind/HtmlElementFactory.java +++ /dev/null
@@ -1,27 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.google.gwt.uibinder.rebind; - -import com.google.gwt.core.ext.typeinfo.JClassType; -import com.google.gwt.core.ext.typeinfo.TypeOracle; - -/** - * Looks up html tag names and returns corresponding type used to represent - * its bindings. - */ -public interface HtmlElementFactory { - JClassType findElementTypeForTag(String htmlTag, TypeOracle oracle); -}
diff --git a/user/src/com/google/gwt/uibinder/rebind/UiBinderGenerator.java b/user/src/com/google/gwt/uibinder/rebind/UiBinderGenerator.java index e459922..79f405c 100644 --- a/user/src/com/google/gwt/uibinder/rebind/UiBinderGenerator.java +++ b/user/src/com/google/gwt/uibinder/rebind/UiBinderGenerator.java
@@ -16,7 +16,6 @@ package com.google.gwt.uibinder.rebind; import com.google.gwt.core.ext.BadPropertyValueException; -import com.google.gwt.core.ext.ConfigurationProperty; import com.google.gwt.core.ext.Generator; import com.google.gwt.core.ext.GeneratorContext; import com.google.gwt.core.ext.PropertyOracle; @@ -143,7 +142,7 @@ UiBinderWriter uiBinderWriter = new UiBinderWriter(interfaceType, implName, templatePath, oracle, logger, new FieldManager(oracle, logger), - messages, designTime, uiBinderCtx, getElementFactory(propertyOracle), + messages, designTime, uiBinderCtx, useSafeHtmlTemplates(logger, propertyOracle)); Document doc = getW3cDoc(logger, designTime, resourceOracle, templatePath); @@ -161,20 +160,6 @@ writerManager.commit(); } - private HtmlElementFactory getElementFactory(PropertyOracle propertyOracle) { - Class<?> elementFactoryClass; - - try { - // TODO(cromwellian) finish this or get it out of here - ConfigurationProperty factoryProperty = propertyOracle - .getConfigurationProperty(ELEMENT_FACTORY_PROPERTY); - elementFactoryClass = Class.forName(factoryProperty.getValues().get(0)); - return (HtmlElementFactory) elementFactoryClass.newInstance(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - private Document getW3cDoc(MortalLogger logger, DesignTimeUtils designTime, ResourceOracle resourceOracle, String templatePath) throws UnableToCompleteException {
diff --git a/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java b/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java index 95fb765..528a024 100644 --- a/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java +++ b/user/src/com/google/gwt/uibinder/rebind/UiBinderWriter.java
@@ -19,6 +19,7 @@ import com.google.gwt.core.ext.typeinfo.JClassType; import com.google.gwt.core.ext.typeinfo.JPackage; import com.google.gwt.core.ext.typeinfo.TypeOracle; +import com.google.gwt.dom.client.TagName; import com.google.gwt.resources.client.ClientBundle; import com.google.gwt.uibinder.attributeparsers.AttributeParser; import com.google.gwt.uibinder.attributeparsers.AttributeParsers; @@ -183,8 +184,6 @@ */ private final JClassType baseClass; - private final HtmlElementFactory elementFactory; - /** * The name of the class we're creating, e.g. MyUiBinderImpl */ @@ -234,7 +233,7 @@ String templatePath, TypeOracle oracle, MortalLogger logger, FieldManager fieldManager, MessagesWriter messagesWriter, DesignTimeUtils designTime, UiBinderContext uiBinderCtx, - HtmlElementFactory elementFactory, boolean useSafeHtmlTemplates) + boolean useSafeHtmlTemplates) throws UnableToCompleteException { this.baseClass = baseClass; this.implClassName = implClassName; @@ -245,7 +244,6 @@ this.messages = messagesWriter; this.designTime = designTime; this.uiBinderCtx = uiBinderCtx; - this.elementFactory = elementFactory; this.useSafeHtmlTemplates = useSafeHtmlTemplates; // Check for possible misuse 'GWT.create(UiBinder.class)' @@ -827,7 +825,19 @@ * Given a DOM tag name, return the corresponding JSO subclass. */ private JClassType findDomElementTypeForTag(String tag) { - return elementFactory.findElementTypeForTag(tag, oracle); + JClassType elementClass = oracle.findType("com.google.gwt.dom.client.Element"); + JClassType[] types = elementClass.getSubtypes(); + for (JClassType type : types) { + TagName annotation = type.getAnnotation(TagName.class); + if (annotation != null) { + for (String annotationTag : annotation.value()) { + if (annotationTag.equals(tag)) { + return type; + } + } + } + } + return elementClass; } /**
diff --git a/user/test/com/google/gwt/uibinder/elementparsers/ElementParserTester.java b/user/test/com/google/gwt/uibinder/elementparsers/ElementParserTester.java index 14dbbff..3d9f200 100644 --- a/user/test/com/google/gwt/uibinder/elementparsers/ElementParserTester.java +++ b/user/test/com/google/gwt/uibinder/elementparsers/ElementParserTester.java
@@ -30,8 +30,6 @@ import com.google.gwt.uibinder.rebind.FieldManager; import com.google.gwt.uibinder.rebind.FieldWriter; import com.google.gwt.uibinder.rebind.MockMortalLogger; -import com.google.gwt.uibinder.rebind.HtmlElementFactory; -import com.google.gwt.uibinder.rebind.GwtDomHtmlElementFactory; import com.google.gwt.uibinder.rebind.W3cDomHelper; import com.google.gwt.uibinder.rebind.XMLElement; import com.google.gwt.uibinder.rebind.XMLElementProvider; @@ -115,9 +113,8 @@ MessagesWriter messages = new MessagesWriter(BINDER_URI, logger, templatePath, baseType.getPackage().getName(), implName); - HtmlElementFactory elementFactory = new GwtDomHtmlElementFactory(); writer = new MockUiBinderWriter(baseType, implName, templatePath, types, - logger, fieldManager, messages, elementFactory); + logger, fieldManager, messages); fieldManager.registerField(types.findType(parsedTypeName), FIELD_NAME); parsedType = types.findType(parsedTypeName); }
diff --git a/user/test/com/google/gwt/uibinder/elementparsers/MockUiBinderWriter.java b/user/test/com/google/gwt/uibinder/elementparsers/MockUiBinderWriter.java index 03dcf98..7264f1a 100644 --- a/user/test/com/google/gwt/uibinder/elementparsers/MockUiBinderWriter.java +++ b/user/test/com/google/gwt/uibinder/elementparsers/MockUiBinderWriter.java
@@ -21,7 +21,6 @@ import com.google.gwt.uibinder.rebind.DesignTimeUtilsStub; import com.google.gwt.uibinder.rebind.FieldManager; import com.google.gwt.uibinder.rebind.MortalLogger; -import com.google.gwt.uibinder.rebind.HtmlElementFactory; import com.google.gwt.uibinder.rebind.UiBinderContext; import com.google.gwt.uibinder.rebind.UiBinderWriter; import com.google.gwt.uibinder.rebind.XMLElement; @@ -32,31 +31,29 @@ class MockUiBinderWriter extends UiBinderWriter { final List<String> statements = new ArrayList<String>(); - - public MockUiBinderWriter(JClassType baseClass, String implClassName, - String templatePath, TypeOracle oracle, MortalLogger logger, - FieldManager fieldManager, MessagesWriter messagesWriter, - HtmlElementFactory factory) throws UnableToCompleteException { - super(baseClass, implClassName, templatePath, oracle, logger, fieldManager, - messagesWriter, DesignTimeUtilsStub.EMPTY, new UiBinderContext(), - factory, true); + + public MockUiBinderWriter(JClassType baseClass, String implClassName, String templatePath, + TypeOracle oracle, MortalLogger logger, FieldManager fieldManager, + MessagesWriter messagesWriter) throws UnableToCompleteException { + super(baseClass, implClassName, templatePath, oracle, logger, fieldManager, messagesWriter, + DesignTimeUtilsStub.EMPTY, new UiBinderContext(), true); } @Override public void addStatement(String format, Object... args) { statements.add(String.format(format, args)); } - + /** - * Mocked out version of the template declaration. Returns - * the template prefixed with "@mockToken-" + * Mocked out version of the template declaration. Returns the template + * prefixed with "@mockToken-" */ public String declareTemplateCall(String html) { return "\"@mockToken-" + html + "\""; } - + @Override public String parseElementToField(XMLElement elem) { return elem.consumeOpeningTag(); - } + } }