tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From drobia...@apache.org
Subject svn commit: r1134191 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/internal/services/ test/java/org/apache/tapestry5/internal/services/ test/resources/org/apache/tapestry5/internal/services/
Date Fri, 10 Jun 2011 05:25:42 GMT
Author: drobiazko
Date: Fri Jun 10 05:25:42 2011
New Revision: 1134191

URL: http://svn.apache.org/viewvc?rev=1134191&view=rev
Log:
TAP5-1543: Introduce Tapestry schema in version 5_3

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/parameter_namespace_element_deprecated.tml
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SaxTemplateParser.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SaxTemplateParser.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SaxTemplateParser.java?rev=1134191&r1=1134190&r2=1134191&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SaxTemplateParser.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/SaxTemplateParser.java
Fri Jun 10 05:25:42 2011
@@ -46,6 +46,10 @@ import org.apache.tapestry5.ioc.internal
 import org.apache.tapestry5.ioc.internal.util.InternalUtils;
 import org.apache.tapestry5.ioc.internal.util.TapestryException;
 
+import static org.apache.tapestry5.internal.services.SaxTemplateParser.Version.T_5_0;
+import static org.apache.tapestry5.internal.services.SaxTemplateParser.Version.T_5_1;
+import static org.apache.tapestry5.internal.services.SaxTemplateParser.Version.T_5_3;
+
 /**
  * SAX-based template parser logic, taking a {@link Resource} to a Tapestry
  * template file and returning
@@ -70,20 +74,13 @@ public class SaxTemplateParser
 
     public static final String XML_NAMESPACE_URI = "http://www.w3.org/XML/1998/namespace";
 
-    /**
-     * Used as the namespace URI for Tapestry templates.
-     */
-    public static final String TAPESTRY_SCHEMA_5_0_0 = "http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";
-
-    /**
-     * Adds several new elements.
-     */
-    public static final String TAPESTRY_SCHEMA_5_1_0 = "http://tapestry.apache.org/schema/tapestry_5_1_0.xsd";
+    private static final Map<String, Version> NAMESPACE_URI_TO_VERSION = CollectionFactory.newMap();
 
-    // Might want to change this from a Set to a map from URI to version number
-    // (if we hit a 3rd version of the namespace URI).
-    private static final Set<String> TAPESTRY_SCHEMA_URIS = CollectionFactory.newSet(
-            TAPESTRY_SCHEMA_5_0_0, TAPESTRY_SCHEMA_5_1_0);
+    {
+        NAMESPACE_URI_TO_VERSION.put("http://tapestry.apache.org/schema/tapestry_5_0_0.xsd",
T_5_0);
+        NAMESPACE_URI_TO_VERSION.put("http://tapestry.apache.org/schema/tapestry_5_1_0.xsd",
T_5_1);
+        NAMESPACE_URI_TO_VERSION.put("http://tapestry.apache.org/schema/tapestry_5_3.xsd",
T_5_3);
+    }
 
     /**
      * Special namespace used to denote Block parameters to components, as a
@@ -228,8 +225,9 @@ public class SaxTemplateParser
 
         String uri = tokenStream.getNamespaceURI();
         String name = tokenStream.getLocalName();
+        Version version = NAMESPACE_URI_TO_VERSION.get(uri);
 
-        if (TAPESTRY_SCHEMA_5_1_0.equals(uri))
+        if (T_5_1.before(version))
         {
             if (name.equalsIgnoreCase("extend"))
             {
@@ -238,7 +236,7 @@ public class SaxTemplateParser
             }
         }
 
-        if (TAPESTRY_SCHEMA_URIS.contains(uri))
+        if (version != null)
         {
             if (name.equalsIgnoreCase("container"))
             {
@@ -260,7 +258,7 @@ public class SaxTemplateParser
             {
                 case START_ELEMENT:
 
-                    if (tokenStream.getNamespaceURI().equals(TAPESTRY_SCHEMA_5_1_0)
+                    if (T_5_1.before(NAMESPACE_URI_TO_VERSION.get(tokenStream.getNamespaceURI()))
                             && tokenStream.getLocalName().equalsIgnoreCase("replace"))
                     {
                         replace(state);
@@ -350,8 +348,9 @@ public class SaxTemplateParser
 
         String uri = tokenStream.getNamespaceURI();
         String name = tokenStream.getLocalName();
+        Version version = NAMESPACE_URI_TO_VERSION.get(uri);
 
-        if (TAPESTRY_SCHEMA_5_1_0.equals(uri))
+        if (T_5_1.before(version))
         {
 
             if (name.equalsIgnoreCase("remove"))
@@ -382,7 +381,7 @@ public class SaxTemplateParser
                 mustBeRoot(name);
         }
 
-        if (TAPESTRY_SCHEMA_URIS.contains(uri))
+        if (version != null)
         {
 
             if (name.equalsIgnoreCase("body"))
@@ -404,6 +403,12 @@ public class SaxTemplateParser
 
             if (name.equalsIgnoreCase("parameter"))
             {
+                if(T_5_3.before(version))
+                {
+                    throw new RuntimeException(
+                            String.format("The <parameter> element has been deprecated
in Tapestry 5.3 in favour of '%s' namespace.", TAPESTRY_PARAMETERS_URI));
+                }
+
                 classicParameter(state);
 
                 return;
@@ -696,7 +701,7 @@ public class SaxTemplateParser
 
             String value = tokenStream.getAttributeValue(i);
 
-            if (TAPESTRY_SCHEMA_URIS.contains(uri))
+            if (NAMESPACE_URI_TO_VERSION.containsKey(uri))
             {
                 if (localName.equalsIgnoreCase(ID_ATTRIBUTE_NAME))
                 {
@@ -766,7 +771,7 @@ public class SaxTemplateParser
             // These URIs are strictly part of the server-side Tapestry template
             // and are not ever sent to the client.
 
-            if (TAPESTRY_SCHEMA_URIS.contains(uri))
+            if (NAMESPACE_URI_TO_VERSION.containsKey(uri))
                 continue;
 
             if (uri.equals(TAPESTRY_PARAMETERS_URI))
@@ -1115,4 +1120,30 @@ public class SaxTemplateParser
                     textStartLocation));
     }
 
+    static enum Version
+    {
+        T_5_0(5,0), T_5_1(5,1), T_5_3(5,3);
+
+        private int major;
+        private int minor;
+
+
+        private Version(int major, int minor)
+        {
+            this.major = major;
+            this.minor = minor;
+        }
+
+        public boolean before(Version other)
+        {
+            if(other == null)
+                return false;
+
+            if(this == other)
+                return true;
+
+            return major <= other.major && minor <= other.minor;
+        }
+    }
+
 }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java?rev=1134191&r1=1134190&r2=1134191&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/TemplateParserImplTest.java
Fri Jun 10 05:25:42 2011
@@ -695,6 +695,8 @@ public class TemplateParserImplTest exte
                 { "misplaced_parameter.tml", "Block parameters are only allowed directly
within component elements.",
                         5 },
 
+                { "parameter_namespace_element_deprecated.tml", "The <parameter> element
has been deprecated in Tapestry 5.3 in favour of 'tapestry:parameter' namespace.", 4 },
+
         };
     }
 

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/parameter_namespace_element_deprecated.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/parameter_namespace_element_deprecated.tml?rev=1134191&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/parameter_namespace_element_deprecated.tml
(added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/resources/org/apache/tapestry5/internal/services/parameter_namespace_element_deprecated.tml
Fri Jun 10 05:25:42 2011
@@ -0,0 +1,9 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd" xml:space="preserve">
+
+    <t:mycomp t:id="foo">
+        <t:parameter name="fred">
+            <!-- fred content -->
+        </t:parameter>
+    </t:mycomp>
+
+</html>



Mime
View raw message