tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r492862 - in /tapestry/tapestry5/tapestry-core/trunk/src: main/java/org/apache/tapestry/corelib/components/ main/java/org/apache/tapestry/internal/services/ main/java/org/apache/tapestry/internal/structure/ main/resources/org/apache/tapestr...
Date Fri, 05 Jan 2007 02:27:18 GMT
Author: hlship
Date: Thu Jan  4 18:27:17 2007
New Revision: 492862

URL: http://svn.apache.org/viewvc?view=rev&rev=492862
Log:
Expose the Form's tracker parameter as a property.
Fix a bug where two expansions on the same line in the template would be merged together into
one, invalid expansion.
Add a page for testing around introspection of the ClassLoader heirarchy (towards a "sniffer"
to find all application page classes).

Added:
    tapestry/tapestry5/tapestry-core/trunk/src/test/app1/ClassLoaderInspect.html
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/ClassLoaderInspect.java
    tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/services/multiple_expansions_on_one_line.html
Modified:
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Form.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/TemplateParserImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java
    tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/default.css
    tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/TemplateParserImplTest.java

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Form.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Form.java?view=diff&rev=492862&r1=492861&r2=492862
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Form.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/corelib/components/Form.java
Thu Jan  4 18:27:17 2007
@@ -304,4 +304,8 @@
         _tracker = tracker;
     }
 
+    public ValidationTracker getTracker()
+    {
+        return _tracker;
+    }
 }

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/TemplateParserImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/TemplateParserImpl.java?view=diff&rev=492862&r1=492861&r2=492862
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/TemplateParserImpl.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/services/TemplateParserImpl.java
Thu Jan  4 18:27:17 2007
@@ -94,8 +94,12 @@
 
     private final Log _log;
 
+    // Note the use of the non-greedy modifier; this prevents the pattern from merging multiple
+    // expansions on the same text line into a single large
+    // but invalid expansion.
+
     private final Pattern EXPANSION_PATTERN = Pattern.compile(
-            "\\$\\{\\s*(.*)\\s*\\}",
+            "\\$\\{\\s*(.*?)\\s*}",
             Pattern.MULTILINE);
 
     public TemplateParserImpl(Log log)
@@ -242,6 +246,9 @@
                 _tokens.add(new TextToken(prefix, _textStartLocation));
             }
 
+            // Group 1 includes the real text of the expansion, which whitespace around the
expression (but inside the curly
+            // braces) excluded.
+            
             String expression = matcher.group(1);
 
             _tokens.add(new ExpansionToken(expression, _textStartLocation));
@@ -352,6 +359,9 @@
         }
 
         _tokens.addAll(attributeTokens);
+
+        if (id != null)
+            _componentIds.add(id);
     }
 
     /**

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java?view=diff&rev=492862&r1=492861&r2=492862
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/java/org/apache/tapestry/internal/structure/InternalComponentResourcesImpl.java
Thu Jan  4 18:27:17 2007
@@ -27,6 +27,7 @@
 import org.apache.tapestry.internal.InternalComponentResources;
 import org.apache.tapestry.internal.services.Instantiator;
 import org.apache.tapestry.ioc.Messages;
+import org.apache.tapestry.ioc.internal.util.InternalUtils;
 import org.apache.tapestry.ioc.internal.util.TapestryException;
 import org.apache.tapestry.ioc.services.TypeCoercer;
 import org.apache.tapestry.model.ComponentModel;
@@ -216,7 +217,7 @@
             throw new TapestryException(StructureMessages.writeParameterFailure(
                     parameterName,
                     getCompleteId(),
-                    ex), ex);
+                    ex), InternalUtils.locationOf(b), ex);
         }
     }
 

Modified: tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/default.css
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/default.css?view=diff&rev=492862&r1=492861&r2=492862
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/default.css
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/main/resources/org/apache/tapestry/default.css
Thu Jan  4 18:27:17 2007
@@ -23,3 +23,8 @@
 DIV.tapestry-error LI {
     margin-left: -20px;
 }
+
+
+DIV.invisible {
+  display: none;
+}
\ No newline at end of file

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/app1/ClassLoaderInspect.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/app1/ClassLoaderInspect.html?view=auto&rev=492862
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/app1/ClassLoaderInspect.html (added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/app1/ClassLoaderInspect.html Thu Jan 
4 18:27:17 2007
@@ -0,0 +1,70 @@
+<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+    <h1>Class Loader Inspection</h1>
+
+
+    <dl>
+        <dt>Context ClassLoader</dt>
+        <dd>${classLoader} [${classLoader.class.name}]</dd>
+
+        <dt> Instance ClassLoader </dt>
+        <dd>${class.classLoader}</dd>
+
+    </dl>
+
+    <h2>Class Loader Hierarchy</h2>
+
+    <ul>
+        <t:comp type="Loop" source="loaders" value="loader">
+            <li> ${loader} </li>
+        </t:comp>
+    </ul>
+
+    <h2> Find Resources </h2>
+
+    <form t:id="search">
+        <t:comp type="Errors"/>
+        <label t:type="Label" field="component:resource"/>: <input t:id="resource"
+            t:type="TextField" size="50" validate="validate:required"/>
+        <br/>
+        <input type="submit"/>
+    </form>
+
+    <t:comp type="If" test="showMatches">
+
+        <h3>${listSize} Matches</h3>
+
+        <ul>
+            <t:comp type="Loop" source="URLs" value="URL">
+                <li>${URL} <dl>
+                
+                <dt>Connection</dt>
+                <dd>${URLConnection} [${URLConnection.class.name}]</dd>
+                        <dt>Content</dt>
+                        <dd>${URL.content}</dd>
+
+                        <dt>Stream </dt>
+                        <dd>
+<pre>
+${contentStreamContents}
+</pre>
+                        </dd>
+
+                        <dt> JAR Entries </dt>
+
+                        <dd>
+                            <ul>
+                                <t:comp type="Loop" source="jarEntries" value="jarEntry">
+                                    <li> ${jarEntry} </li>
+                                </t:comp>
+                            </ul>
+                        </dd>
+
+                    </dl>
+                </li>
+            </t:comp>
+        </ul>
+
+    </t:comp>
+
+</html>

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/ClassLoaderInspect.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/ClassLoaderInspect.java?view=auto&rev=492862
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/ClassLoaderInspect.java
(added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/integration/app1/pages/ClassLoaderInspect.java
Thu Jan  4 18:27:17 2007
@@ -0,0 +1,230 @@
+package org.apache.tapestry.integration.app1.pages;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.jar.JarEntry;
+
+import org.apache.tapestry.annotations.Component;
+import org.apache.tapestry.annotations.ComponentClass;
+import org.apache.tapestry.annotations.Persist;
+import org.apache.tapestry.corelib.components.Form;
+import org.apache.tapestry.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry.ioc.internal.util.InternalUtils;
+
+@ComponentClass
+public class ClassLoaderInspect
+{
+    private static final ClassLoader _classLoader = Thread.currentThread().getContextClassLoader();
+
+    private ClassLoader _loader;
+
+    @Persist
+    private String _resource;
+
+    @Component
+    private Form _search;
+
+    @Persist
+    private List<URL> _URLs;
+
+    @Persist
+    private boolean _showMatches;
+
+    private URL _URL;
+
+    private JarEntry _jarEntry;
+
+    public URL getURL()
+    {
+        return _URL;
+    }
+
+    public void setURL(URL url)
+    {
+        _URL = url;
+    }
+
+    public ClassLoader getClassLoader()
+    {
+        return _classLoader;
+    }
+
+    public ClassLoader getLoader()
+    {
+        return _loader;
+    }
+
+    public void setLoader(ClassLoader loader)
+    {
+        _loader = loader;
+    }
+
+    public List<ClassLoader> getLoaders()
+    {
+        List<ClassLoader> result = CollectionFactory.newList();
+
+        ClassLoader current = getClass().getClassLoader();
+
+        while (current != null)
+        {
+            result.add(0, current);
+
+            current = current.getParent();
+        }
+
+        return result;
+    }
+
+    public int getListSize()
+    {
+        return _URLs == null ? 0 : _URLs.size();
+    }
+
+    void onFailure()
+    {
+        _showMatches = false;
+        _URLs = null;
+    }
+
+    void onSuccess()
+    {
+        _showMatches = false;
+
+        _URLs = null;
+
+        try
+        {
+            List<URL> urls = CollectionFactory.newList();
+
+            Enumeration<URL> e = _classLoader.getResources(_resource);
+
+            while (e.hasMoreElements())
+                urls.add(e.nextElement());
+
+            _URLs = urls;
+
+            _showMatches = true;
+        }
+        catch (Exception ex)
+        {
+            String message = ex.getMessage();
+
+            if (InternalUtils.isBlank(message))
+                message = ex.getClass().getName();
+
+            _search.getTracker().recordError(message);
+        }
+    }
+
+    public String getResource()
+    {
+        return _resource;
+    }
+
+    public void setResource(String resource)
+    {
+        _resource = resource;
+    }
+
+    public List<URL> getURLs()
+    {
+        return _URLs;
+    }
+
+    public boolean getShowMatches()
+    {
+        return _showMatches;
+    }
+
+    public String getContentStreamContents()
+    {
+        StringBuilder builder = new StringBuilder();
+
+        try
+        {
+            InputStream is = _URL.openStream();
+            InputStreamReader reader = new InputStreamReader(is);
+
+            char[] buffer = new char[1000];
+
+            while (true)
+            {
+                int length = reader.read(buffer);
+
+                if (length < 0)
+                    break;
+
+                builder.append(buffer, 0, length);
+            }
+
+            reader.close();
+
+            return builder.toString();
+        }
+        catch (Exception ex)
+        {
+            return ex.getMessage();
+        }
+    }
+
+    public List<JarEntry> getJarEntries()
+    {
+        try
+        {
+            URLConnection rawConnection = _URL.openConnection();
+
+            JarURLConnection jarConnection = (JarURLConnection) rawConnection;
+
+            JarEntry rootEntry = jarConnection.getJarEntry();
+
+            List<JarEntry> result = CollectionFactory.newList();
+
+            if (rootEntry.isDirectory())
+            {
+                Enumeration<JarEntry> e = jarConnection.getJarFile().entries();
+
+                while (e.hasMoreElements())
+                    result.add(e.nextElement());
+            }
+            else
+            {
+                result.add(rootEntry);
+            }
+
+            return result;
+        }
+        catch (Exception ex)
+        {
+            return null;
+        }
+
+    }
+
+    public URLConnection getURLConnection()
+    {
+        try
+        {
+            return _URL.openConnection();
+        }
+        catch (IOException ex)
+        {
+            return null;
+        }
+    }
+
+    public JarEntry getJarEntry()
+    {
+        return _jarEntry;
+    }
+
+    public void setJarEntry(JarEntry jarEntry)
+    {
+        _jarEntry = jarEntry;
+    }
+}

Modified: tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/TemplateParserImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/TemplateParserImplTest.java?view=diff&rev=492862&r1=492861&r2=492862
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/TemplateParserImplTest.java
(original)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/java/org/apache/tapestry/internal/services/TemplateParserImplTest.java
Thu Jan  4 18:27:17 2007
@@ -60,6 +60,19 @@
         return newParser(log).parseTemplate(resource);
     }
 
+    private ComponentTemplate parse(String file)
+    {
+        Log log = newLog();
+
+        replay();
+
+        ComponentTemplate result = parse(log, file);
+
+        verify();
+
+        return result;
+    }
+
     private List<TemplateToken> tokens(String file)
     {
         Log log = newLog();
@@ -289,7 +302,8 @@
     @Test
     public void instrumented_element()
     {
-        List<TemplateToken> tokens = tokens("instrumented_element.html");
+        ComponentTemplate template = parse("instrumented_element.html");
+        List<TemplateToken> tokens = template.getTokens();
 
         assertEquals(tokens.size(), 3);
 
@@ -305,6 +319,8 @@
         assertEquals(attr.getValue(), "value");
 
         assertTrue(EndElementToken.class.isInstance(tokens.get(2)));
+
+        assertEquals(template.getComponentIds(), Arrays.asList("fred"));
     }
 
     @Test
@@ -521,6 +537,30 @@
                 t1.getText().replaceAll("\\s+", " "),
                 " ${expansions must be on a single line} ");
 
+    }
+
+    @Test
+    public void multiple_expansions_on_one_line()
+    {
+        List<TemplateToken> tokens = tokens("multiple_expansions_on_one_line.html");
+
+        assertEquals(tokens.size(), 10);
+
+        ExpansionToken token3 = get(tokens, 3);
+
+        assertEquals(token3.getExpression(), "classLoader");
+
+        TextToken token4 = get(tokens, 4);
+
+        assertEquals(token4.getText(), " [");
+
+        ExpansionToken token5 = get(tokens, 5);
+
+        assertEquals(token5.getExpression(), "classLoader.class.name");
+
+        TextToken token6 = get(tokens, 6);
+
+        assertEquals(token6.getText(), "]");
     }
 
     @Test

Added: tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/services/multiple_expansions_on_one_line.html
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/services/multiple_expansions_on_one_line.html?view=auto&rev=492862
==============================================================================
--- tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/services/multiple_expansions_on_one_line.html
(added)
+++ tapestry/tapestry5/tapestry-core/trunk/src/test/resources/org/apache/tapestry/internal/services/multiple_expansions_on_one_line.html
Thu Jan  4 18:27:17 2007
@@ -0,0 +1,3 @@
+<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+    <dd>${classLoader} [${classLoader.class.name}]</dd>
+</html>



Mime
View raw message