You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2014/04/16 18:48:35 UTC
[2/3] git commit: TAP5-2306: Identify templates that should use
strict mixin parameters
TAP5-2306: Identify templates that should use strict mixin parameters
Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/1f0c7464
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/1f0c7464
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/1f0c7464
Branch: refs/heads/master
Commit: 1f0c7464c80e415a19825c612ca6b8139db6ba1e
Parents: 39d9aba
Author: Howard M. Lewis Ship <hl...@apache.org>
Authored: Tue Apr 15 16:13:03 2014 -0700
Committer: Howard M. Lewis Ship <hl...@apache.org>
Committed: Tue Apr 15 16:13:03 2014 -0700
----------------------------------------------------------------------
.../internal/parser/ComponentTemplate.java | 13 ++++++--
.../internal/parser/ComponentTemplateImpl.java | 31 ++++++++++++++------
.../services/ComponentTemplateSourceImpl.java | 7 +++--
.../internal/services/SaxTemplateParser.java | 30 +++++++++++++------
.../ComponentTemplateSourceImplTest.java | 4 ---
.../services/TemplateParserImplTest.java | 10 +++++--
.../internal/services/instrumented_element.tml | 2 +-
7 files changed, 68 insertions(+), 29 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1f0c7464/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplate.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplate.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplate.java
index a016614..704da05 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplate.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplate.java
@@ -1,5 +1,3 @@
-// Copyright 2006, 2008, 2009 The Apache Software Foundation
-//
// 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
@@ -38,6 +36,17 @@ public interface ComponentTemplate
boolean isExtension();
/**
+ * Indicates whether lax (the old default) or strict (the new default) mixin parameters are used.
+ * In strict mode, introduced with the 5.4 template DTD, mixin parameters must be qualified with the mixin name.
+ * In prior releases, Tapestry would attempt a search for a fit, and this causes ambiguities
+ * that can't be addressed.
+ *
+ * @since 5.4
+ * @return true if a 5.4 or later DTD
+ */
+ boolean usesStrictMixinParameters();
+
+ /**
* Returns a list of tokens associated with an extension point, or null if this template neither defines the
* extension point nor overrides it.
*
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1f0c7464/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplateImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplateImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplateImpl.java
index efc4aff..318da4c 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplateImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/parser/ComponentTemplateImpl.java
@@ -1,5 +1,3 @@
-// Copyright 2006, 2008, 2009 The Apache Software Foundation
-//
// 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
@@ -17,12 +15,13 @@ package org.apache.tapestry5.internal.parser;
import org.apache.tapestry5.ioc.Location;
import org.apache.tapestry5.ioc.Resource;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
-import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newList;
import org.apache.tapestry5.ioc.internal.util.InternalUtils;
import java.util.List;
import java.util.Map;
+import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newList;
+
public class ComponentTemplateImpl implements ComponentTemplate
{
private final Resource resource;
@@ -31,23 +30,32 @@ public class ComponentTemplateImpl implements ComponentTemplate
private final Map<String, Location> componentIds;
- private final boolean extension;
+ private final boolean extension, strictMixinParameters;
private final Map<String, List<TemplateToken>> overrides;
/**
- * @param resource the resource from which the template was parsed
- * @param tokens the tokens of the template, a copy of this list will be made
- * @param componentIds ids of components defined in the template
+ * @param resource
+ * the resource from which the template was parsed
+ * @param tokens
+ * the tokens of the template, a copy of this list will be made
+ * @param componentIds
+ * ids of components defined in the template
* @param extension
- * @param overrides id to list of tokens for that override
+ * if this template is an extension of a parent-class template
+ * @param strictMixinParameters
+ * if the template was parsed with the 5.4 DTD and is strict
+ * about mixin parameters being fully qualified
+ * @param overrides
+ * id to list of tokens for that override
*/
public ComponentTemplateImpl(Resource resource, List<TemplateToken> tokens,
Map<String, Location> componentIds, boolean extension,
- Map<String, List<TemplateToken>> overrides)
+ boolean strictMixinParameters, Map<String, List<TemplateToken>> overrides)
{
this.resource = resource;
this.extension = extension;
+ this.strictMixinParameters = strictMixinParameters;
this.overrides = overrides;
this.tokens = newList(tokens);
this.componentIds = CollectionFactory.newMap(componentIds);
@@ -68,6 +76,11 @@ public class ComponentTemplateImpl implements ComponentTemplate
return componentIds;
}
+ public boolean usesStrictMixinParameters()
+ {
+ return strictMixinParameters;
+ }
+
/**
* Returns false.
*/
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1f0c7464/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImpl.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImpl.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImpl.java
index d651625..d580b9e 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImpl.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImpl.java
@@ -1,5 +1,3 @@
-// Copyright 2006-2013 The Apache Software Foundation
-//
// 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
@@ -96,6 +94,11 @@ public final class ComponentTemplateSourceImpl extends InvalidationEventHubImpl
{
return false;
}
+
+ public boolean usesStrictMixinParameters()
+ {
+ return false;
+ }
};
public ComponentTemplateSourceImpl(@Inject
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1f0c7464/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SaxTemplateParser.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SaxTemplateParser.java b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SaxTemplateParser.java
index 67cc4ba..9900d02 100644
--- a/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SaxTemplateParser.java
+++ b/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SaxTemplateParser.java
@@ -1,5 +1,3 @@
-// Copyright 2009-2013 The Apache Software Foundation
-//
// 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
@@ -155,6 +153,8 @@ public class SaxTemplateParser
private boolean active = true;
+ private boolean strictMixinParameters = false;
+
private final Map<String, Boolean> extensionPointIdSet = CollectionFactory.newCaseInsensitiveMap();
public SaxTemplateParser(Resource resource, Map<String, URL> publicIdToURL)
@@ -174,7 +174,7 @@ public class SaxTemplateParser
root(initialParserState);
- return new ComponentTemplateImpl(resource, tokens, componentIds, extension, overrides);
+ return new ComponentTemplateImpl(resource, tokens, componentIds, extension, strictMixinParameters, overrides);
} catch (Exception ex)
{
throw new TapestryException(String.format("Failure parsing template %s: %s", resource,
@@ -697,8 +697,9 @@ public class SaxTemplateParser
/**
* @param elementName
- * @param identifiedType the type of the element, usually null, but may be the
- * component type derived from element
+ * @param identifiedType
+ * the type of the element, usually null, but may be the
+ * component type derived from element
*/
private void possibleTapestryComponent(TemplateParserState state, String elementName,
String identifiedType)
@@ -731,8 +732,18 @@ public class SaxTemplateParser
String value = tokenStream.getAttributeValue(i);
- if (NAMESPACE_URI_TO_VERSION.containsKey(uri))
+
+ Version version = NAMESPACE_URI_TO_VERSION.get(uri);
+
+ if (version != null)
{
+ // We are kind of assuming that the namespace URI appears once, in the outermost element of the template.
+ // And we don't and can't handle the case that it appears multiple times in the template.
+
+ if (version.sameOrEarlier(T_5_4)) {
+ strictMixinParameters = true;
+ }
+
if (localName.equalsIgnoreCase(ID_ATTRIBUTE_NAME))
{
id = nullForBlank(value);
@@ -1098,9 +1109,10 @@ public class SaxTemplateParser
* patterns, and adds appropriate tokens for what
* it finds.
*
- * @param text to add as
- * {@link org.apache.tapestry5.internal.parser.TextToken}s and
- * {@link org.apache.tapestry5.internal.parser.ExpansionToken}s
+ * @param text
+ * to add as
+ * {@link org.apache.tapestry5.internal.parser.TextToken}s and
+ * {@link org.apache.tapestry5.internal.parser.ExpansionToken}s
*/
private void addTokensForText(String text)
{
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1f0c7464/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImplTest.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImplTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImplTest.java
index 26e0f2b..531ef3d 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImplTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ComponentTemplateSourceImplTest.java
@@ -1,5 +1,3 @@
-// Copyright 2006, 2007, 2008, 2010, 2011 The Apache Software Foundation
-//
// 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
@@ -39,8 +37,6 @@ public class ComponentTemplateSourceImplTest extends InternalBaseTestCase
{
private static final String PACKAGE = "org.apache.tapestry5.internal.pageload";
- static public final String PATH = "org/apache/tapestry5/internal/pageload";
-
private final ClassLoader loader = Thread.currentThread().getContextClassLoader();
private final ClasspathURLConverter converter = new ClasspathURLConverterImpl();
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1f0c7464/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
index fed3068..0b3e915 100644
--- a/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
+++ b/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
@@ -1,5 +1,3 @@
-// Copyright 2006-2013 The Apache Software Foundation
-//
// 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
@@ -93,6 +91,8 @@ public class TemplateParserImplTest extends InternalBaseTestCase
assertSame(template.getResource(), resource);
+ assertFalse(template.usesStrictMixinParameters());
+
List<TemplateToken> tokens = template.getTokens();
// They add up quick ...
@@ -1039,6 +1039,12 @@ public class TemplateParserImplTest extends InternalBaseTestCase
assertEquals(toString(tokens), "Start[a] End");
}
+ @Test
+ public void t54_DTDs_are_strict_about_mixin_parameters() {
+
+ assertTrue(parse("instrumented_element.tml").usesStrictMixinParameters());
+ }
+
private String toString(List<TemplateToken> tokens)
{
StringBuilder builder = new StringBuilder();
http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/1f0c7464/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/instrumented_element.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/instrumented_element.tml b/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/instrumented_element.tml
index 9fe04f5..94ff01d 100644
--- a/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/instrumented_element.tml
+++ b/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/instrumented_element.tml
@@ -1 +1 @@
-<html t:id="fred" t:type="Fred" param="value" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"/>
+<html t:id="fred" t:type="Fred" param="value" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd"/>