tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r406134 - in /tapestry/tapestry5/tapestry-core/trunk/src: main/aspect/org/apache/tapestry/internal/aspects/ main/java/org/apache/tapestry/ main/java/org/apache/tapestry/internal/parser/ main/resources/org/apache/tapestry/internal/parser/ si...
Date Sat, 13 May 2006 18:01:49 GMT
Author: hlship
Date: Sat May 13 11:01:46 2006
New Revision: 406134

URL: http://svn.apache.org/viewcvs?rev=406134&view=rev
Log:
Flesh out the new template parser.

Added:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/CDATAToken.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/CommentToken.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/StartComponentToken.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/parser/TemplateParserImplTest.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/cdata.html
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/comment.html
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/component.html
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/componentWithBody.html
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/componentWithParameters.html
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/justHTML.html
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/multilineComment.html
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/xmlEntity.html
Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/CatchNullParameters.aj
    tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/Synchronization.aj
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/MarkupWriter.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/AttributeToken.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ComponentTemplate.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ComponentTemplateImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/EndElementToken.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ParserMessages.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/StartElementToken.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TemplateParser.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TemplateParserImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TemplateToken.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TextToken.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/parser/ParserStrings.properties
    tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/parser/tapestry_5_0_0.xsd
    tapestry/tapestry5/tapestry-core/trunk/src/site/site.xml
    tapestry/tapestry5/tapestry-core/trunk/src/test/conf/testng.xml
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/aspects/CatchNullParametersAspectTest.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/parser/ParserExperiment.java

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/CatchNullParameters.aj
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/CatchNullParameters.aj?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/CatchNullParameters.aj (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/CatchNullParameters.aj Sat May 13 11:01:46 2006
@@ -4,7 +4,7 @@
 // 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
+// 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,
@@ -15,6 +15,8 @@
 package org.apache.tapestry.internal.aspects;
 
 import org.apache.tapestry.internal.annotations.SuppressNullCheck;
+import org.aspectj.lang.Signature;
+import org.aspectj.lang.reflect.CodeSignature;
 
 /**
  * Adds code to targeted methods and constructors that prevents null values from being passed in as
@@ -28,19 +30,23 @@
     pointcut typeNotMarkedAsSuppressed() : 
         !within(@SuppressNullCheck Object+);
 
-    /** Look for methods and constructors that do NOT have the SuppressNullCheck annotation. */
+    /**
+     * Look for non-private methods and constructors that do NOT have the SuppressNullCheck
+     * annotation.
+     */
     pointcut executionNotSuppressed() :  
         execution(!@SuppressNullCheck !private * *(..)) ||
         execution(!@SuppressNullCheck !private new(..));
 
     /**
      * Exclude methods (and constructors) with no parameters. Also, exclude equals() since it has to
-     * accept null (and we don't want to force you to put the
-     * 
-     * @SupportNullCheck annotation on every class that overrides equals().
+     * accept null, and we don't want to force you to put the SupportNullCheck annotation on every
+     * class that overrides equals().
      */
     pointcut excludedMethods() :
-         execution(boolean equals(Object));
+        execution(* *()) ||
+        execution(new()) ||
+        execution(boolean equals(Object));
 
     /**
      * Find methods to check, within the set of target classes, where neither the entire class, nor
@@ -55,32 +61,30 @@
         !excludedMethods();
 
     /**
-     * Selects each parameter. The specific useage here ensures that no-argument methods and
-     * constructors are skipped. Still trying to limit this so that primitive arguments aren't
-     * checked (currently, AspectJ is converting primitives to wrapper types and passing them into
-     * the advice method).
-     */
-    pointcut parametersToCheck(Object argumentValue) :
-        args(.., argumentValue);
-
-    /**
-     * Here's where the real work gets done. I think there may be a way to do this more efficiently
-     * where much more static logic is injected, triggered by arguments.
+     * Here's where the real work gets done.
      */
-    before(Object argumentValue) : checkForNullParameters() && parametersToCheck(argumentValue) 
+    before() : checkForNullParameters()
     {
-        if (argumentValue == null)
-        {
-            // The method signature could provide the parameterName (which would be awesome),
-            // but we need to know the parameter index.
+        Signature s = thisJoinPointStaticPart.getSignature();
+
+        // Common super-parent to methods and constructors
 
-            String message = String.format(
-                    "Parameter passed to method %s (at %s) was null.",
-                    thisJoinPoint.getSignature().toString(),
-                    thisJoinPoint.getSourceLocation());
+        CodeSignature cs = (CodeSignature) s;
 
-            throw new IllegalArgumentException(message);
+        Object[] args = thisJoinPoint.getArgs();
+
+        for (int i = 0; i < args.length; i++)
+        {
+            if (args[i] == null)
+            {
+                String message = String.format(
+                        "Parameter #%d (%s) passed to method %s was null.",
+                        i + 1,
+                        cs.getParameterNames()[i],
+                        cs.toString());
 
+                throw new IllegalArgumentException(message);
+            }
         }
     }
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/Synchronization.aj
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/Synchronization.aj?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/Synchronization.aj (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/aspect/org/apache/tapestry/internal/aspects/Synchronization.aj Sat May 13 11:01:46 2006
@@ -4,7 +4,7 @@
 // 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
+// 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,
@@ -45,14 +45,17 @@
 {
     private final ReadWriteLock _lock = new ReentrantReadWriteLock();
 
-    private final ThreadLocal<Boolean> _threadHasReadLock = new ThreadLocal<Boolean>()
+    private static class ThreadBoolean extends ThreadLocal<Boolean>
     {
         @Override
         protected Boolean initialValue()
         {
             return false;
         }
-    };
+
+    }
+
+    private final ThreadBoolean _threadHasReadLock = new ThreadBoolean();
 
     private void log(JoinPoint jp, String message)
     {

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/MarkupWriter.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/MarkupWriter.java?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/MarkupWriter.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/MarkupWriter.java Sat May 13 11:01:46 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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
+//
+//     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 org.apache.tapestry;
 
 /**

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/AttributeToken.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/AttributeToken.java?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/AttributeToken.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/AttributeToken.java Sat May 13 11:01:46 2006
@@ -1,25 +1,44 @@
+// Copyright 2006 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
+//
+//     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 org.apache.tapestry.internal.parser;
 
 import org.apache.hivemind.Location;
 
+/**
+ * Stores an attribute/value pair (as part of an XML element).
+ * 
+ * @author Howard M. Lewis Ship
+ */
 public class AttributeToken extends TemplateToken
 {
-    private final String _qname;
+    private final String _name;
 
     private final String _value;
 
-    public AttributeToken(String qname, String value, Location location)
+    public AttributeToken(String name, String value, Location location)
     {
         super(location);
 
-        _qname = qname;
+        _name = name;
         _value = value;
     }
 
-    /** Returns the namespace qualified name for the attribute. */
-    public String getQname()
+    /** Returns local name for the attribute. */
+    public String getName()
     {
-        return _qname;
+        return _name;
     }
 
     /** Returns the value for the attribute. */
@@ -27,5 +46,4 @@
     {
         return _value;
     }
-
 }

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/CDATAToken.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/CDATAToken.java?rev=406134&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/CDATAToken.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/CDATAToken.java Sat May 13 11:01:46 2006
@@ -0,0 +1,40 @@
+// Copyright 2006 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
+//
+//     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 org.apache.tapestry.internal.parser;
+
+import org.apache.hivemind.Location;
+
+/**
+ * Literal text that was enclosed within a !CDATA in the input template (so we should do the same
+ * during output).
+ * 
+ * @author Howard M. Lewis Ship
+ */
+public class CDATAToken extends TemplateToken
+{
+    private final String _text;
+
+    public CDATAToken(String text, Location location)
+    {
+        super(location);
+
+        _text = text;
+    }
+
+    public String getText()
+    {
+        return _text;
+    }
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/CommentToken.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/CommentToken.java?rev=406134&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/CommentToken.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/CommentToken.java Sat May 13 11:01:46 2006
@@ -0,0 +1,40 @@
+// Copyright 2006 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
+//
+//     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 org.apache.tapestry.internal.parser;
+
+import org.apache.hivemind.Location;
+
+/**
+ * A node representing a comment embedded in the source input.
+ * 
+ * @author Howard M. Lewis Ship
+ */
+public class CommentToken extends TemplateToken
+{
+    private final String _comment;
+
+    public CommentToken(String comment, Location location)
+    {
+        super(location);
+
+        _comment = comment;
+    }
+
+    public String getComment()
+    {
+        return _comment;
+    }
+
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ComponentTemplate.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ComponentTemplate.java?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ComponentTemplate.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ComponentTemplate.java Sat May 13 11:01:46 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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
+//
+//     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 org.apache.tapestry.internal.parser;
 
 import java.util.List;

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ComponentTemplateImpl.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ComponentTemplateImpl.java?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ComponentTemplateImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ComponentTemplateImpl.java Sat May 13 11:01:46 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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
+//
+//     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 org.apache.tapestry.internal.parser;
 
 import java.util.List;
@@ -23,8 +37,6 @@
      */
     public ComponentTemplateImpl(Resource resource, List<TemplateToken> tokens)
     {
-        super();
-
         _resource = resource;
         _tokens = newList(tokens);
     }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/EndElementToken.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/EndElementToken.java?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/EndElementToken.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/EndElementToken.java Sat May 13 11:01:46 2006
@@ -1,8 +1,24 @@
+// Copyright 2006 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
+//
+//     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 org.apache.tapestry.internal.parser;
 
 import org.apache.hivemind.Location;
 
 /**
+ * Ends a previously started element (including components, parameters, etc.).
+ * 
  * @author Howard M. Lewis Ship
  */
 public class EndElementToken extends TemplateToken

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ParserMessages.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ParserMessages.java?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ParserMessages.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/ParserMessages.java Sat May 13 11:01:46 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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
+//
+//     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 org.apache.tapestry.internal.parser;
 
 import org.apache.hivemind.Messages;

Added: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/StartComponentToken.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/StartComponentToken.java?rev=406134&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/StartComponentToken.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/StartComponentToken.java Sat May 13 11:01:46 2006
@@ -0,0 +1,62 @@
+// Copyright 2006 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
+//
+//     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 org.apache.tapestry.internal.parser;
+
+import org.apache.hivemind.Location;
+import org.apache.tapestry.internal.annotations.SuppressNullCheck;
+
+/**
+ * The start element of a component within the template. Will be followed by a series of
+ * {@link org.apache.tapestry.internal.parser.AttributeToken}s for any attributes (outside of id
+ * and type), and eventually will be balanced by an
+ * {@link org.apache.tapestry.internal.parser.EndElementToken}.
+ * 
+ * @author Howard M. Lewis Ship
+ */
+public class StartComponentToken extends TemplateToken
+{
+    private final String _id;
+
+    private final String _type;
+
+    /**
+     * @param id
+     *            the id of the component (may be null for anonymous components)
+     * @param type
+     *            the type of component (may be null if the component type is specified outside the
+     *            template)
+     * @param location
+     *            the location within the template at which the element was parsed
+     */
+    @SuppressNullCheck
+    public StartComponentToken(String id, String type, Location location)
+    {
+        super(location);
+
+        _id = id;
+        _type = type;
+    }
+
+    public String getId()
+    {
+        return _id;
+    }
+
+    public String getType()
+    {
+        return _type;
+    }
+
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/StartElementToken.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/StartElementToken.java?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/StartElementToken.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/StartElementToken.java Sat May 13 11:01:46 2006
@@ -1,22 +1,47 @@
+// Copyright 2006 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
+//
+//     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 org.apache.tapestry.internal.parser;
 
 import org.apache.hivemind.Location;
 
+/**
+ * The start of an ordinary element within the template (as opposed to
+ * {@link org.apache.tapestry.internal.parser.StartComponentToken}, which represents an active
+ * Tapestry token. A start element token may be immediately followed by
+ * {@link org.apache.tapestry.internal.parser.AttributeToken}s that represents the attributes
+ * associated with the element. A start element token will always be balanced by a
+ * {@link org.apache.tapestry.internal.parser.EndElementToken} (though there will likely be some
+ * amount of intermediate tokens).
+ * 
+ * @author Howard M. Lewis Ship
+ */
 public class StartElementToken extends TemplateToken
 {
-    private final String _qname;
+    private final String _name;
 
-    public StartElementToken(String qname, Location location)
+    public StartElementToken(String name, Location location)
     {
         super(location);
 
-        _qname = qname;
+        _name = name;
     }
 
-    /** Returns the prefix qualified name for the element. */
-    public String getQname()
+    /** Returns local name for the element. */
+    public String getName()
     {
-        return _qname;
+        return _name;
     }
 
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TemplateParser.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TemplateParser.java?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TemplateParser.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TemplateParser.java Sat May 13 11:01:46 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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
+//
+//     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 org.apache.tapestry.internal.parser;
 
 import org.apache.hivemind.Resource;

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TemplateParserImpl.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TemplateParserImpl.java?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TemplateParserImpl.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TemplateParserImpl.java Sat May 13 11:01:46 2006
@@ -1,5 +1,23 @@
+// Copyright 2006 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
+//
+//     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 org.apache.tapestry.internal.parser;
 
+import static org.apache.tapestry.util.CollectionFactory.newList;
+import static org.apache.tapestry.util.CollectionFactory.newMap;
+
+import java.io.IOException;
 import java.net.URL;
 import java.util.List;
 import java.util.Map;
@@ -8,25 +26,23 @@
 import javax.xml.parsers.SAXParserFactory;
 
 import org.apache.hivemind.ApplicationRuntimeException;
+import org.apache.hivemind.HiveMind;
 import org.apache.hivemind.Location;
 import org.apache.hivemind.Resource;
 import org.apache.hivemind.impl.LocationImpl;
-import org.apache.tapestry.util.CollectionFactory;
 import org.xml.sax.Attributes;
 import org.xml.sax.InputSource;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
 import org.xml.sax.helpers.DefaultHandler;
 
-import static org.apache.tapestry.util.CollectionFactory.newList;
-import static org.apache.tapestry.util.CollectionFactory.newMap;
-
 /**
  * Non-threadsafe implementation.
  * 
  * @author Howard M. Lewis Ship
  */
-public class TemplateParserImpl extends DefaultHandler implements TemplateParser
+public class TemplateParserImpl extends DefaultHandler implements TemplateParser, LexicalHandler
 {
     public static final String TAPESTRY_SCHEMA_5_0_0 = "http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";
 
@@ -53,6 +69,8 @@
 
     private Location _textStartLocation;
 
+    private boolean _textIsCData;
+
     public TemplateParserImpl()
     {
         _parserFactory = SAXParserFactory.newInstance();
@@ -67,6 +85,8 @@
             try
             {
                 _parser = _parserFactory.newSAXParser();
+
+                _parser.setProperty("http://xml.org/sax/properties/lexical-handler", this);
             }
             catch (Exception ex)
             {
@@ -82,6 +102,8 @@
         Map<String, String> rootPrefixMap = newMap();
         _prefixResolutionStack.add(rootPrefixMap);
 
+        _templateResource = templateResource;
+
         try
         {
             InputSource source = new InputSource(resourceURL.openStream());
@@ -103,13 +125,13 @@
         }
         finally
         {
-
             _tokens.clear();
             _prefixResolutionStack.clear();
             _templateResource = null;
             _locator = null;
             _textBuffer.setLength(0);
             _textStartLocation = null;
+            _textIsCData = false;
         }
     }
 
@@ -147,7 +169,36 @@
         if (_textBuffer.length() == 0)
             _textStartLocation = getCurrentLocation();
 
-        _textBuffer.append(ch, start, length);
+        if (_textIsCData)
+        {
+            _textBuffer.append(ch, start, length);
+            return;
+        }
+
+        // The parser will have converted XML entities into normal characters.
+        // What we want in the TexztToken is the raw characters to send to the
+        // client ... which means we have to revert those characters back
+        // into XML entities.
+
+        for (int i = 0; i < length; i++)
+        {
+            char c = ch[start + i];
+
+            switch (c)
+            {
+                case '<':
+                    _textBuffer.append("&lt;");
+                    break;
+                case '>':
+                    _textBuffer.append("&gt;");
+                    break;
+                case '&':
+                    _textBuffer.append("&amp;");
+                    break;
+                default:
+                    _textBuffer.append(c);
+            }
+        }
     }
 
     /** Adds a text token, if the text buffer is non-empty. Clears the text buffer. */
@@ -161,7 +212,10 @@
         // Not ideal for multiple lines of text, and will probably be even worse
         // when we add embedded interpolations, but there you have it.
 
-        _tokens.add(new TextToken(text, _textStartLocation));
+        TemplateToken token = _textIsCData ? new CDATAToken(text, _textStartLocation)
+                : new TextToken(text, _textStartLocation);
+
+        _tokens.add(token);
 
         _textBuffer.setLength(0);
     }
@@ -172,32 +226,85 @@
     {
         addTextToken();
 
+        if (TAPESTRY_SCHEMA_5_0_0.equals(uri))
+        {
+            startTapestryElement(localName, attributes);
+            return;
+        }
+
         // TODO: Handle tapestry namespace elements
         // TODO: Handle tapestry namespace attributes in ordinary namespace elements?
         // TODO: Handle interpolations inside attributes?
-        
+
         Location location = getCurrentLocation();
 
-        _tokens.add(new StartElementToken(qName, location));
+        _tokens.add(new StartElementToken(localName, location));
+
+        int count = attributes.getLength();
+
+        for (int i = 0; i < count; i++)
+        {
+            String name = attributes.getLocalName(i);
+
+            if (HiveMind.isBlank(name))
+                continue;
+
+            String value = attributes.getValue(i);
+
+            _tokens.add(new AttributeToken(name, value, location));
+        }
+    }
+
+    private void startTapestryElement(String localName, Attributes attributes)
+    {
+        if (localName.equals("comp"))
+        {
+            startComponent(localName, attributes);
+            return;
+        }
+
+    }
 
+    private void startComponent(String localName, Attributes attributes)
+    {
+        String id = null;
+        String type = null;
         int count = attributes.getLength();
+        Location location = getCurrentLocation();
+        List<TemplateToken> attributeTokens = newList();
 
         for (int i = 0; i < count; i++)
         {
-            String qname = attributes.getQName(i);
+            String name = attributes.getLocalName(i);
             String value = attributes.getValue(i);
 
-            _tokens.add(new AttributeToken(qname, value, location));
+            if (name.equals("id"))
+            {
+                id = value;
+                continue;
+            }
+
+            if (name.equals("type"))
+            {
+                type = value;
+                continue;
+            }
+
+            attributeTokens.add(new AttributeToken(name, value, location));
         }
+
+        // Add the component
+        _tokens.add(new StartComponentToken(id, type, location));
+        _tokens.addAll(attributeTokens);
     }
 
     @Override
     public void endElement(String uri, String localName, String qName) throws SAXException
     {
         addTextToken();
-        
+
         // TODO: Handle tapestry namespace elements
-        
+
         // Because XML tags are always balanced, we don't even need to know what element just closed
         // when we assemble things later.
 
@@ -211,5 +318,62 @@
 
         return new LocationImpl(_templateResource, _locator.getLineNumber(), _locator
                 .getColumnNumber());
+    }
+
+    public void comment(char[] ch, int start, int length) throws SAXException
+    {
+        addTextToken();
+
+        String comment = new String(ch, start, length);
+
+        // TODO: Perhaps comments need to be "aggregated" the same way we aggregate text and CDATA.
+        // Hm. Probably not. Any whitespace between one comment and the next will become a
+        // TextToken.
+        // Unless we trim whitespace between consecutive comments ... and on down the rabbit hole.
+        // Oops -- unless a single comment may be passed into this method as multiple calls
+        // (have to check how multiline comments are handled).
+        // Tests against Sun's built in parser does show that multiline comments are still
+        // provided as a single call to comment(), so we're good for the meantime (until we find
+        // out some parsers aren't so compliant).
+
+        _tokens.add(new CommentToken(comment, getCurrentLocation()));
+    }
+
+    public void endCDATA() throws SAXException
+    {
+        // Add a token for any accumulated CDATA.
+
+        addTextToken();
+
+        // Again, CDATA doesn't nest, so we know we're back to ordinary markup.
+
+        _textIsCData = false;
+    }
+
+    public void endDTD() throws SAXException
+    {
+    }
+
+    public void endEntity(String name) throws SAXException
+    {
+    }
+
+    public void startCDATA() throws SAXException
+    {
+        addTextToken();
+
+        // Because CDATA doesn't mix with any other SAX/lexical events, we can simply turn on a flag
+        // here,
+        // and turn it off when we see the end.
+
+        _textIsCData = true;
+    }
+
+    public void startDTD(String name, String publicId, String systemId) throws SAXException
+    {
+    }
+
+    public void startEntity(String name) throws SAXException
+    {
     }
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TemplateToken.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TemplateToken.java?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TemplateToken.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TemplateToken.java Sat May 13 11:01:46 2006
@@ -1,10 +1,25 @@
+// Copyright 2006 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
+//
+//     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 org.apache.tapestry.internal.parser;
 
 import org.apache.hivemind.Locatable;
 import org.apache.hivemind.Location;
 
 /**
- * Base class for tokens parsed out of a template.
+ * Base class for tokens parsed out of a template. The set of classes rooted here are effectively
+ * object encapsulations of the events generated by a SAX parser.
  * 
  * @author Howard M. Lewis Ship
  */

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TextToken.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TextToken.java?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TextToken.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/parser/TextToken.java Sat May 13 11:01:46 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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
+//
+//     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 org.apache.tapestry.internal.parser;
 
 import org.apache.hivemind.Location;

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/parser/ParserStrings.properties
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/parser/ParserStrings.properties?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/parser/ParserStrings.properties (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/parser/ParserStrings.properties Sat May 13 11:01:46 2006
@@ -1,3 +1,17 @@
+# Copyright 2006 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
+#
+#     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.
+
 new-parser-error=Failure obtaining a SAX parser for resource {0}: {1}
 missing-template-resource=Template resource {0} does not exist.
 template-parse-error=Failure parsing template {0}: {1}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/parser/tapestry_5_0_0.xsd
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/parser/tapestry_5_0_0.xsd?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/parser/tapestry_5_0_0.xsd (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/internal/parser/tapestry_5_0_0.xsd Sat May 13 11:01:46 2006
@@ -4,7 +4,7 @@
     targetNamespace="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
     <xs:element name="comp">
         <xs:complexType mixed="true">
-            <xs:attribute name="id" use="required" type="xs:ID"/>
+            <xs:attribute name="id" type="xs:ID"/>
             <xs:attribute name="type" type="xs:string"/>
             <xs:anyAttribute/>
         </xs:complexType>

Modified: tapestry/tapestry5/tapestry-core/trunk/src/site/site.xml
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/site/site.xml?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/site/site.xml (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/site/site.xml Sat May 13 11:01:46 2006
@@ -1,4 +1,20 @@
 <?xml version="1.0" encoding="ISO-8859-1"?>
+<!-- 
+   Copyright 2006 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
+
+       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.
+-->
+
 <project name="Tapestry Core">
     <bannerLeft>
         <name>Tapestry</name>

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/conf/testng.xml
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/test/conf/testng.xml?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/conf/testng.xml (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/conf/testng.xml Sat May 13 11:01:46 2006
@@ -23,6 +23,7 @@
       <package name="org.apache.tapestry.internal.transform.worker"/>
       <package name="org.apache.tapestry.internal.aspects"/>
       <package name="org.apache.tapestry.internal.util"/>
+      <package name="org.apache.tapestry.internal.parser"/>
       <package name="org.apache.tapestry.util"/>
     </packages>
   </test>

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/aspects/CatchNullParametersAspectTest.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/aspects/CatchNullParametersAspectTest.java?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/aspects/CatchNullParametersAspectTest.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/aspects/CatchNullParametersAspectTest.java Sat May 13 11:01:46 2006
@@ -58,7 +58,7 @@
         new NullTarget("not null").equals(null);
     }
 
-    @Test
+@Test
     public void allParametersChecked()
     {
         NullTarget t = new NullTarget("not null");
@@ -93,11 +93,20 @@
             // Expected.
         }
 
+        try
+        {
+            t.manyParameters(this, null, Collections.EMPTY_MAP);
+            unreachable();
+        }
+        catch (IllegalArgumentException ex)
+        {
+            // Expected.
+        }
+       
+        
         t.manyParameters(this, "ok", Collections.EMPTY_MAP);
 
-    }
-
-    @Test
+    }    @Test
     public void publicMethod()
     {
         NullTarget t = new NullTarget();

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/parser/ParserExperiment.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/parser/ParserExperiment.java?rev=406134&r1=406133&r2=406134&view=diff
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/parser/ParserExperiment.java (original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/parser/ParserExperiment.java Sat May 13 11:01:46 2006
@@ -1,3 +1,17 @@
+// Copyright 2006 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
+//
+//     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 org.apache.tapestry.internal.parser;
 
 import java.io.BufferedInputStream;

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/parser/TemplateParserImplTest.java
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/parser/TemplateParserImplTest.java?rev=406134&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/parser/TemplateParserImplTest.java (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/parser/TemplateParserImplTest.java Sat May 13 11:01:46 2006
@@ -0,0 +1,255 @@
+// Copyright 2006 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
+//
+//     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 org.apache.tapestry.internal.parser;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertSame;
+
+import java.util.List;
+
+import org.apache.hivemind.ClassResolver;
+import org.apache.hivemind.Locatable;
+import org.apache.hivemind.Location;
+import org.apache.hivemind.Resource;
+import org.apache.hivemind.impl.DefaultClassResolver;
+import org.apache.hivemind.util.ClasspathResource;
+import org.testng.annotations.Configuration;
+import org.testng.annotations.Test;
+
+/**
+ * This is used to test the template parser ... and in some cases, the underlying behavior of the
+ * SAX APIs.
+ * 
+ * @author Howard M. Lewis Ship
+ */
+public class TemplateParserImplTest
+{
+    private TemplateParser _parser;
+
+    private ClassResolver _resolver = new DefaultClassResolver();
+
+    /**
+     * What's nice is that we get to set up a single parser for all the test methods to share, which
+     * will actually do a very good job of simulating how a parser is used in production.
+     */
+    @Configuration(beforeTestClass = true)
+    public void setupParser()
+    {
+        _parser = new TemplateParserImpl();
+    }
+
+    private ComponentTemplate parse(String file)
+    {
+        Resource resource = getResource(file);
+
+        return _parser.parseTemplate(resource);
+    }
+
+    private List<TemplateToken> tokens(String file)
+    {
+        return parse(file).getTokens();
+    }
+
+    private Resource getResource(String file)
+    {
+        String packageName = getClass().getPackage().getName();
+
+        String path = packageName.replace('.', '/') + "/" + file;
+
+        Resource resource = new ClasspathResource(_resolver, path);
+        return resource;
+    }
+
+    private <T extends TemplateToken> T get(List l, int index)
+    {
+        Object raw = l.get(index);
+
+        return (T) raw;
+    }
+
+    private void checkLine(Locatable l, int expectedLineNumber)
+    {
+        assertEquals(l.getLocation().getLineNumber(), expectedLineNumber);
+    }
+
+    @Test
+    void justHTML()
+    {
+        Resource resource = getResource("justHTML.html");
+        ComponentTemplate template = _parser.parseTemplate(resource);
+
+        assertSame(template.getResource(), resource);
+
+        List<TemplateToken> tokens = template.getTokens();
+
+        // They add up quick ...
+
+        assertEquals(tokens.size(), 20);
+
+        StartElementToken t0 = get(tokens, 0);
+
+        // Spot check a few things ...
+
+        assertEquals(t0.getName(), "html");
+        checkLine(t0, 1);
+
+        TextToken t1 = get(tokens, 1);
+        // Concerned this may not work cross platform.
+        assertEquals(t1.getText(), "\n    ");
+
+        StartElementToken t2 = get(tokens, 2);
+        assertEquals(t2.getName(), "head");
+        checkLine(t2, 2);
+
+        TextToken t5 = get(tokens, 5);
+        assertEquals(t5.getText(), "title");
+        checkLine(t5, 3);
+
+        get(tokens, 6);
+
+        StartElementToken t12 = get(tokens, 12);
+        assertEquals(t12.getName(), "p");
+
+        AttributeToken t13 = get(tokens, 13);
+        assertEquals(t13.getName(), "class");
+        assertEquals(t13.getValue(), "important");
+
+        TextToken t14 = get(tokens, 14);
+        // Simplify the text, converting consecutive whitespace to just a single space.
+        assertEquals(t14.getText().replaceAll("\\s+", " ").trim(), "Tapestry rocks! Line 2");
+
+        // Line number is the *start* line of the whole text block.
+        checkLine(t14, 6);
+    }
+
+    @Test
+    void xmlEntity() throws Exception
+    {
+        List<TemplateToken> tokens = tokens("xmlEntity.html");
+
+        assertEquals(tokens.size(), 3);
+
+        TextToken t = get(tokens, 1);
+
+        assertEquals(t.getText().trim(), "lt:&lt; gt:&gt; amp:&amp;");
+    }
+
+    @Test
+    void cdata() throws Exception
+    {
+        List<TemplateToken> tokens = tokens("cdata.html");
+
+        // Whitespace text tokens around the CDATA
+
+        assertEquals(tokens.size(), 5);
+
+        CDATAToken t = get(tokens, 2);
+
+        assertEquals(t.getText(), "CDATA: &lt;foo&gt; &amp; &lt;bar&gt;");
+        checkLine(t, 2);
+    }
+
+    @Test
+    void comment() throws Exception
+    {
+        List<TemplateToken> tokens = tokens("comment.html");
+
+        // Again, whitespace before and after the comment adds some tokens
+
+        assertEquals(tokens.size(), 5);
+
+        CommentToken t = get(tokens, 2);
+
+        assertEquals(t.getComment(), " Single line comment ");
+    }
+
+    @Test
+    void multilineComment() throws Exception
+    {
+        List<TemplateToken> tokens = tokens("multilineComment.html");
+
+        // Again, whitespace before and after the comment adds some tokens
+
+        assertEquals(tokens.size(), 5);
+
+        CommentToken t = get(tokens, 2);
+
+        String comment = t.getComment().trim().replaceAll("\\s+", " ");
+
+        assertEquals(comment, "Line one Line two Line three");
+    }
+
+    @Test
+    void component() throws Exception
+    {
+        List<TemplateToken> tokens = tokens("component.html");
+
+        assertEquals(tokens.size(), 6);
+
+        StartComponentToken t = get(tokens, 2);
+        assertEquals(t.getId(), "fred");
+        assertEquals(t.getType(), "Fred");
+        checkLine(t, 2);
+
+        get(tokens, 3);
+    }
+
+    @Test
+    void componentWithBody() throws Exception
+    {
+        List<TemplateToken> tokens = tokens("componentWithBody.html");
+
+        assertEquals(tokens.size(), 7);
+
+        get(tokens, 2);
+
+        TextToken t = get(tokens, 3);
+
+        assertEquals(t.getText().trim(), "fred's body");
+
+        get(tokens, 4);
+    }
+
+    @Test
+    void componentWithParameters() throws Exception
+    {
+        List<TemplateToken> tokens = tokens("componentWithParameters.html");
+
+        assertEquals(tokens.size(), 9);
+
+        Location l = get(tokens, 2).getLocation();
+
+        AttributeToken t1 = get(tokens, 3);
+
+        // TODO: Not sure what order the attributes appear in. Order in the XML? Sorted
+        // alphbetically?
+        // Random 'cause they're hashed?
+
+        assertEquals(t1.getName(), "cherry");
+        assertEquals(t1.getValue(), "bomb");
+        assertSame(t1.getLocation(), l);
+
+        AttributeToken t2 = get(tokens, 4);
+        assertEquals(t2.getName(), "align");
+        assertEquals(t2.getValue(), "right");
+        assertSame(t2.getLocation(), l);
+
+        TextToken t3 = get(tokens, 5);
+
+        assertEquals(t3.getText().trim(), "fred's body");
+
+        get(tokens, 6);
+    }
+}

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/cdata.html
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/cdata.html?rev=406134&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/cdata.html (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/cdata.html Sat May 13 11:01:46 2006
@@ -0,0 +1,3 @@
+<html>
+<![CDATA[CDATA: &lt;foo&gt; &amp; &lt;bar&gt;]]>    
+</html>
\ No newline at end of file

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/comment.html
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/comment.html?rev=406134&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/comment.html (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/comment.html Sat May 13 11:01:46 2006
@@ -0,0 +1,3 @@
+<html>
+    <!-- Single line comment -->
+</html>
\ No newline at end of file

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/component.html
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/component.html?rev=406134&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/component.html (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/component.html Sat May 13 11:01:46 2006
@@ -0,0 +1,4 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+    <t:comp id="fred" type="Fred"/>
+</html>
+    
\ No newline at end of file

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/componentWithBody.html
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/componentWithBody.html?rev=406134&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/componentWithBody.html (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/componentWithBody.html Sat May 13 11:01:46 2006
@@ -0,0 +1,5 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+    <t:comp id="fred" type="Fred"> 
+    fred's body 
+    </t:comp>
+</html>

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/componentWithParameters.html
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/componentWithParameters.html?rev=406134&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/componentWithParameters.html (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/componentWithParameters.html Sat May 13 11:01:46 2006
@@ -0,0 +1,5 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+    <t:comp id="fred" type="Fred" cherry="bomb" align="right"> 
+        fred's body 
+    </t:comp>
+</html>

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/justHTML.html
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/justHTML.html?rev=406134&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/justHTML.html (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/justHTML.html Sat May 13 11:01:46 2006
@@ -0,0 +1,12 @@
+<html>
+    <head>
+        <title>title</title>
+    </head>
+    <body>
+        <p class="important"> Tapestry rocks!
+            
+Line 2
+            
+        </p>
+    </body>
+</html>
\ No newline at end of file

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/multilineComment.html
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/multilineComment.html?rev=406134&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/multilineComment.html (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/multilineComment.html Sat May 13 11:01:46 2006
@@ -0,0 +1,5 @@
+<html>
+    <!-- Line one
+         Line two
+         Line three -->
+</html>
\ No newline at end of file

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/xmlEntity.html
URL: http://svn.apache.org/viewcvs/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/xmlEntity.html?rev=406134&view=auto
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/xmlEntity.html (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/parser/xmlEntity.html Sat May 13 11:01:46 2006
@@ -0,0 +1,3 @@
+<html>
+lt:&lt; gt:&gt; amp:&amp;
+</html>
\ No newline at end of file



Mime
View raw message