tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject svn commit: r758391 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/internal/services/ main/java/org/apache/tapestry5/services/ main/resources/org/apache/tapestry5/ test/java/org/apache/tapestry5/internal/services/
Date Wed, 25 Mar 2009 18:25:17 GMT
Author: hlship
Date: Wed Mar 25 18:25:00 2009
New Revision: 758391

URL: http://svn.apache.org/viewvc?rev=758391&view=rev
Log:
TAP5-598: Hard-coded messages inside tapestry.js are not localized

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EmptyJavascriptStack.java
  (with props)
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/JavascriptStackImpl.java
  (with props)
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/JavascriptStack.java
  (with props)
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry-messages.js
  (with props)
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderSupportImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RenderSupportImplTest.java

Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EmptyJavascriptStack.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EmptyJavascriptStack.java?rev=758391&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EmptyJavascriptStack.java
(added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EmptyJavascriptStack.java
Wed Mar 25 18:25:00 2009
@@ -0,0 +1,35 @@
+// Copyright 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
+//
+//     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.tapestry5.internal.services;
+
+import org.apache.tapestry5.Asset;
+import org.apache.tapestry5.services.JavascriptStack;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Used for Ajax responses to provide an empty stack (since, by definition, the client must
already have the base
+ * stack).
+ *
+ * @since 5.1.0.2
+ */
+public class EmptyJavascriptStack implements JavascriptStack
+{
+    public List<Asset> getStack()
+    {
+        return Collections.emptyList();
+    }
+}

Propchange: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/EmptyJavascriptStack.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/JavascriptStackImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/JavascriptStackImpl.java?rev=758391&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/JavascriptStackImpl.java
(added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/JavascriptStackImpl.java
Wed Mar 25 18:25:00 2009
@@ -0,0 +1,85 @@
+// Copyright 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
+//
+//     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.tapestry5.internal.services;
+
+import org.apache.tapestry5.Asset;
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.apache.tapestry5.ioc.services.SymbolSource;
+import org.apache.tapestry5.ioc.services.ThreadLocale;
+import org.apache.tapestry5.services.AssetSource;
+import org.apache.tapestry5.services.JavascriptStack;
+
+import java.util.List;
+import java.util.Locale;
+
+/**
+ * The default Javascript Stack consists of Prototype, Scriptaculous & the Tapestry-specific
library.
+ *
+ * @since 5.1.0.2
+ */
+public class JavascriptStackImpl implements JavascriptStack
+{
+    private final SymbolSource symbolSource;
+
+    private final AssetSource assetSource;
+
+    private final ThreadLocale threadLocale;
+
+    private final List<Asset> coreResources = CollectionFactory.newList();
+
+    private static final String[] CORE_RESOURCES = new String[]
+            {
+                    // Core scripts added to any page that uses scripting
+
+                    "${tapestry.scriptaculous}/prototype.js",
+                    "${tapestry.scriptaculous}/scriptaculous.js",
+                    "${tapestry.scriptaculous}/effects.js",
+
+                    // Uses functions defined by the prior three
+
+                    "org/apache/tapestry5/tapestry.js"
+            };
+
+    public JavascriptStackImpl(SymbolSource symbolSource, AssetSource assetSource, ThreadLocale
threadLocale)
+    {
+        this.symbolSource = symbolSource;
+        this.assetSource = assetSource;
+        this.threadLocale = threadLocale;
+
+        for (String path : CORE_RESOURCES)
+        {
+            coreResources.add(expand(path, null));
+        }
+    }
+
+    private Asset expand(String path, Locale locale)
+    {
+        String expanded = symbolSource.expandSymbols(path);
+
+        return assetSource.getAsset(null, expanded, locale);
+    }
+
+    public List<Asset> getStack()
+    {
+        List<Asset> result = CollectionFactory.newList(coreResources);
+
+        Asset messages = assetSource.getAsset(null, "org/apache/tapestry5/tapestry-messages.js",
+                                              threadLocale.getLocale());
+
+        result.add(messages);
+
+        return result;
+    }
+}

Propchange: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/JavascriptStackImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderSupportImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderSupportImpl.java?rev=758391&r1=758390&r2=758391&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderSupportImpl.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderSupportImpl.java
Wed Mar 25 18:25:00 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 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.
@@ -24,9 +24,7 @@
 import org.apache.tapestry5.json.JSONArray;
 import org.apache.tapestry5.json.JSONObject;
 import org.apache.tapestry5.services.AssetSource;
-
-import java.util.Arrays;
-import java.util.List;
+import org.apache.tapestry5.services.JavascriptStack;
 
 public class RenderSupportImpl implements RenderSupport
 {
@@ -38,9 +36,9 @@
 
     private final AssetSource assetSource;
 
-    private final List<String> coreScripts;
+    private final JavascriptStack javascriptStack;
 
-    private boolean coreAssetsAdded;
+    private boolean stackAssetsAdded;
 
     private final JSONObject init = new JSONObject();
 
@@ -49,39 +47,40 @@
     private String focusFieldId;
 
     /**
-     * @param linker       Used to assemble JavaScript includes and snippets
-     * @param symbolSource Used to example symbols (in {@linkplain #addClasspathScriptLink(String...)
in classpath
-     *                     scripts)
-     * @param assetSource  Used to convert classpath scripts to {@link org.apache.tapestry5.Asset}s
-     * @param coreScripts  core scripts (evaluated as classpaths scripts) that are added
to any page that includes a
-     *                     script link or script block
+     * @param linker          Used to assemble JavaScript includes and snippets
+     * @param symbolSource    Used to example symbols (in {@linkplain #addClasspathScriptLink(String...)
in classpath
+     *                        scripts)
+     * @param assetSource     Used to convert classpath scripts to {@link org.apache.tapestry5.Asset}s
+     * @param coreScripts     core scripts (evaluated as classpaths scripts) that are added
to any page that includes a
+     *                        script link or script block
+     * @param javascriptStack
      */
     public RenderSupportImpl(DocumentLinker linker, SymbolSource symbolSource,
-                             AssetSource assetSource, String... coreScripts)
+                             AssetSource assetSource, JavascriptStack javascriptStack)
     {
-        this(linker, symbolSource, assetSource, new IdAllocator(), coreScripts);
+        this(linker, symbolSource, assetSource, new IdAllocator(), javascriptStack);
     }
 
     /**
-     * @param linker       Used to assemble JavaScript includes and snippets
-     * @param symbolSource Used to example symbols (in {@linkplain #addClasspathScriptLink(String...)
in classpath
-     *                     scripts)
-     * @param assetSource  Used to convert classpath scripts to {@link org.apache.tapestry5.Asset}s
-     * @param idAllocator  Used to allocate unique client ids during the render
-     * @param coreScripts  core scripts (evaluated as classpaths scripts) that are added
to any page that includes a
-     *                     script link or script block
+     * @param linker          Used to assemble JavaScript includes and snippets
+     * @param symbolSource    Used to example symbols (in {@linkplain #addClasspathScriptLink(String...)
in classpath
+     *                        scripts)
+     * @param assetSource     Used to convert classpath scripts to {@link org.apache.tapestry5.Asset}s
+     * @param idAllocator     Used to allocate unique client ids during the render
+     * @param coreScripts     core scripts (evaluated as classpaths scripts) that are added
to any page that includes a
+     *                        script link or script block
+     * @param javascriptStack
      */
 
     public RenderSupportImpl(DocumentLinker linker, SymbolSource symbolSource,
-                             AssetSource assetSource, IdAllocator idAllocator, String...
coreScripts)
+                             AssetSource assetSource, IdAllocator idAllocator, JavascriptStack
javascriptStack)
 
     {
         this.linker = linker;
         this.symbolSource = symbolSource;
         this.assetSource = assetSource;
         this.idAllocator = idAllocator;
-
-        this.coreScripts = Arrays.asList(coreScripts);
+        this.javascriptStack = javascriptStack;
     }
 
     public String allocateClientId(String id)
@@ -96,7 +95,7 @@
 
     public void addScriptLink(Asset... scriptAssets)
     {
-        addCore();
+        addStack();
 
         for (Asset asset : scriptAssets)
         {
@@ -108,7 +107,7 @@
 
     public void addScriptLink(String... scriptURLs)
     {
-        addCore();
+        addStack();
 
         for (String url : scriptURLs)
         {
@@ -118,7 +117,7 @@
 
     public void addClasspathScriptLink(String... classpaths)
     {
-        addCore();
+        addStack();
 
         for (String path : classpaths)
             addScriptLinkFromClasspath(path);
@@ -137,7 +136,7 @@
     {
         Defense.notBlank(script, "script");
 
-        addCore();
+        addStack();
 
         linker.addScript(script);
     }
@@ -234,14 +233,16 @@
         linker.addStylesheetLink(stylesheetURL, media);
     }
 
-    private void addCore()
+    private void addStack()
     {
-        if (!coreAssetsAdded)
+        if (!stackAssetsAdded)
         {
-            for (String path : coreScripts)
-                addScriptLinkFromClasspath(path);
+            for (Asset script : javascriptStack.getStack())
+            {
+                linker.addScriptLink(script.toClientURL());
+            }
 
-            coreAssetsAdded = true;
+            stackAssetsAdded = true;
         }
     }
 }

Added: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/JavascriptStack.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/JavascriptStack.java?rev=758391&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/JavascriptStack.java
(added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/JavascriptStack.java
Wed Mar 25 18:25:00 2009
@@ -0,0 +1,39 @@
+// Copyright 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
+//
+//     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.tapestry5.services;
+
+import org.apache.tapestry5.Asset;
+
+import java.util.List;
+
+/**
+ * A Javascript Stack is a base set of JavaScript files that are used by any page that {@linkplain
+ * org.apache.tapestry5.RenderSupport#addScript(String, Object[]) adds JavaScript to the
page}. Tapestry's default stack
+ * includes Prototype, Scriptaculous, and a Tapestry-specific library.  Note that these individual
library files will
+ * {@linkplain org.apache.tapestry5.SymbolConstants#COMBINE_SCRIPTS be combined into a single
virtual resource} (from
+ * the client's point of view).
+ *
+ * @since 5.1.0.2
+ */
+public interface JavascriptStack
+{
+    /**
+     * Returns the (localized) assets for the scripts to be included as core JavaScript stack.
The assets for the stack
+     * will be added before any other JavaScript libraries included in the render of the
page.
+     *
+     * @return list of assets
+     */
+    List<Asset> getStack();
+}

Propchange: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/JavascriptStack.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=758391&r1=758390&r2=758391&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java
Wed Mar 25 18:25:00 2009
@@ -306,6 +306,7 @@
         binder.bind(ClientDataEncoder.class, ClientDataEncoderImpl.class);
         binder.bind(ComponentEventLinkEncoder.class, ComponentEventLinkEncoderImpl.class);
         binder.bind(PageRenderLinkSource.class, PageRenderLinkSourceImpl.class);
+        binder.bind(JavascriptStack.class, JavascriptStackImpl.class);
     }
 
     // ========================================================================
@@ -1640,7 +1641,9 @@
 
                                          final AssetSource assetSource,
 
-                                         final ClientDataEncoder clientDataEncoder)
+                                         final ClientDataEncoder clientDataEncoder,
+
+                                         final JavascriptStack javascriptStack)
     {
         MarkupRendererFilter documentLinker = new MarkupRendererFilter()
         {
@@ -1669,17 +1672,7 @@
             {
                 DocumentLinker linker = environment.peekRequired(DocumentLinker.class);
 
-                RenderSupportImpl support = new RenderSupportImpl(linker, symbolSource, assetSource,
-
-                                                                  // Core scripts added to
any page that uses scripting
-
-                                                                  "${tapestry.scriptaculous}/prototype.js",
-                                                                  "${tapestry.scriptaculous}/scriptaculous.js",
-                                                                  "${tapestry.scriptaculous}/effects.js",
-
-                                                                  // Uses functions defined
by the prior three
-
-                                                                  "org/apache/tapestry5/tapestry.js");
+                RenderSupportImpl support = new RenderSupportImpl(linker, symbolSource, assetSource,
javascriptStack);
 
                 environment.push(RenderSupport.class, support);
 
@@ -1814,7 +1807,7 @@
                 DocumentLinker linker = environment.peekRequired(DocumentLinker.class);
 
                 RenderSupportImpl support = new RenderSupportImpl(linker, symbolSource, assetSource,
-                                                                  idAllocator);
+                                                                  idAllocator, new EmptyJavascriptStack());
 
                 environment.push(RenderSupport.class, support);
 

Added: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry-messages.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry-messages.js?rev=758391&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry-messages.js
(added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry-messages.js
Wed Mar 25 18:25:00 2009
@@ -0,0 +1,38 @@
+// Copyright 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
+//
+//     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.
+
+Tapestry.Messages = {
+
+    pageIsLoading : "Please wait for the page to finish loading ...",
+
+    missingInitializer : "Function Tapestry.Initializer.#{name}() does not exist.",
+
+    missingValidator :      "Function Tapestry.Validator.#{name}() does not exist for field
'#{fieldName}'.",
+
+    ajaxFailure : "Ajax failure: Status #{status} for #{request.url}: ",
+
+    ajaxRequestUnsuccessful : "Server request was unsuccessful. There may be a problem accessing
the server.",
+
+    clientException :     "Client exception processing response: ",
+
+    missingZone :   "Unable to locate Ajax Zone '#{id}' for dynamic update.",
+
+    noZoneManager :   "Ajax Zone '#{id}' does not have an associated Tapestry.ZoneManager
object." ,
+
+    pathDoesNotStartWithSlash : "External path #{path} does not start with a leading slash.",
+
+    notAnInteger : "Not an integer",
+
+    invalidCharacter : "Invalid character"
+};
\ No newline at end of file

Propchange: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry-messages.js
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js?rev=758391&r1=758390&r2=758391&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/tapestry.js
Wed Mar 25 18:25:00 2009
@@ -192,7 +192,7 @@
 
             if (initf == undefined)
             {
-                Tapestry.error("Function Tapestry.Initializer.#{name}() does not exist.",
{ name:functionName });
+                Tapestry.error(Tapestry.Messages.missingInitializer, { name:functionName
});
                 return;
             }
 
@@ -353,7 +353,7 @@
 
         Tapestry.ajaxError("Communication with the server failed: " + message);
 
-        Tapestry.debug("Ajax failure: Status #{status} for #{request.url}: " + message, response);
+        Tapestry.debug(Tapestry.Messages.ajaxFailure + message, response);
     },
 
     /**
@@ -391,7 +391,7 @@
 
                 if (! response.request.success())
                 {
-                    Tapestry.ajaxError("Server request was unsuccesful. There may be a problem
accessing the server.");
+                    Tapestry.ajaxError(Tapestry.Messages.ajaxRequestUnsuccessful);
                     return;
                 }
 
@@ -402,7 +402,7 @@
                 }
                 catch (e)
                 {
-                    Tapestry.ajaxError("Client exception processing response: " + e);
+                    Tapestry.ajaxError(Tapestry.Messages.clientException + e);
                 }
             },
             onException: Tapestry.ajaxFailureHandler,
@@ -436,7 +436,7 @@
 
         if (!zoneElement)
         {
-            Tapestry.ajaxError("Unable to locate Ajax Zone '#{id}' for dynamic update.",
{ id:zoneElement});
+            Tapestry.ajaxError(Tapestry.Messages.missingZone, { id:zoneElement});
             return null;
         }
 
@@ -444,7 +444,7 @@
 
         if (!manager)
         {
-            Tapestry.ajaxError("Ajax Zone '#{id}' does not have an associated Tapestry.ZoneManager
object.", element);
+            Tapestry.ajaxError(Tapestry.Messages.noZoneManager, element);
             return null;
         }
 
@@ -469,7 +469,7 @@
 
         if (! path.startsWith("/"))
         {
-            Tapestry.error("External path " + path + " does not start with a leading slash.");
+            Tapestry.error(Tapestry.Messages.pathDoesNotStartWithSlash, { path: path });
 
             return path;
         }
@@ -518,11 +518,11 @@
 
             if (ch == decimal)
             {
-                if (isInteger) throw "Not an integer";
+                if (isInteger) throw Tapestry.Messages.notAnInteger;
 
                 ch = ".";
             }
-            else if (ch < "0" || ch > "9") throw "Invalid character";
+            else if (ch < "0" || ch > "9") throw Tapestry.Messages.invalidCharacter;
 
             canonical += ch;
         });
@@ -546,11 +546,6 @@
     }
 };
 
-Tapestry.Messages = {
-
-    pageIsLoading : "Please wait for the page to finish loading ..."
-
-};
 
 Element.addMethods(
 {
@@ -871,7 +866,7 @@
 
             if (vfunc == undefined)
             {
-                Tapestry.error("Function Tapestry.Validator.#{name}() does not exist for
field '#{fieldName}'.", {name:name, fieldName:field.id});
+                Tapestry.error(Tapestry.Messages.missingValidator, {name:name, fieldName:field.id});
                 return;
             }
 
@@ -1342,7 +1337,7 @@
 
         // Don't try to validate blank values; if the field is required, that error is already
         // noted and presented to the user.
-        
+
         if (!t.validationError && ! value.blank())
         {
             var translated = this.translator(value);

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RenderSupportImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RenderSupportImplTest.java?rev=758391&r1=758390&r2=758391&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RenderSupportImplTest.java
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RenderSupportImplTest.java
Wed Mar 25 18:25:00 2009
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008 The Apache Software Foundation
+// Copyright 2007, 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.
@@ -20,12 +20,13 @@
 import org.apache.tapestry5.internal.test.InternalBaseTestCase;
 import org.apache.tapestry5.ioc.services.SymbolSource;
 import org.apache.tapestry5.services.AssetSource;
+import org.apache.tapestry5.services.JavascriptStack;
 import org.testng.annotations.Test;
 
+import java.util.Arrays;
+
 public class RenderSupportImplTest extends InternalBaseTestCase
 {
-    private static final String CORE_ASSET_PATH_UNEXPANDED = "${core}";
-
     private static final String ASSET_URL = "/assets/foo/bar.pdf";
 
     @Test
@@ -39,7 +40,7 @@
 
         replay();
 
-        RenderSupport support = new RenderSupportImpl(linker, null, null);
+        RenderSupport support = new RenderSupportImpl(linker, null, null, new EmptyJavascriptStack());
 
         support.addScriptLink(asset);
 
@@ -55,7 +56,7 @@
 
         replay();
 
-        RenderSupport support = new RenderSupportImpl(linker, null, null);
+        RenderSupport support = new RenderSupportImpl(linker, null, null, new EmptyJavascriptStack());
 
         support.addScriptLink(ASSET_URL);
 
@@ -67,43 +68,39 @@
     {
         getMocksControl().checkOrder(true);
 
-        DocumentLinker linker = mockDocumentLinker();
+        String coreURL1 = "/foo/core1.js";
+        String coreURL2 = "/foo/core2.js";
+
         Asset asset = mockAsset();
+
+        DocumentLinker linker = mockDocumentLinker();
+
+        Asset coreAsset1 = mockAsset();
+        Asset coreAsset2 = mockAsset();
+
         AssetSource assetSource = mockAssetSource();
         SymbolSource symbolSource = mockSymbolSource();
 
-        train_addClasspathAsset(linker, symbolSource, assetSource, CORE_ASSET_PATH_UNEXPANDED);
+        JavascriptStack stack = mockJavascriptStack(coreAsset1, coreAsset2);
+
+        train_toClientURL(coreAsset1, coreURL1);
+        linker.addScriptLink(coreURL1);
+
+        train_toClientURL(coreAsset2, coreURL2);
+        linker.addScriptLink(coreURL2);
 
         train_toClientURL(asset, ASSET_URL);
         linker.addScriptLink(ASSET_URL);
 
         replay();
 
-        RenderSupport support = new RenderSupportImpl(linker, symbolSource, assetSource,
-                                                      CORE_ASSET_PATH_UNEXPANDED);
+        RenderSupport support = new RenderSupportImpl(linker, symbolSource, assetSource,
stack);
 
         support.addScriptLink(asset);
 
         verify();
     }
 
-    private void train_addClasspathAsset(DocumentLinker linker, SymbolSource symbolSource,
AssetSource assetSource,
-                                         String scriptPath)
-    {
-        String expanded = "expanded:" + scriptPath;
-        String url = "/" + scriptPath;
-
-        Asset asset = mockAsset();
-
-        train_expandSymbols(symbolSource, scriptPath, expanded);
-
-        train_getAsset(assetSource, null, expanded, null, asset);
-
-        train_toClientURL(asset, url);
-
-        linker.addScriptLink(url);
-    }
-
     @Test
     public void add_script()
     {
@@ -112,14 +109,15 @@
         DocumentLinker linker = mockDocumentLinker();
         SymbolSource symbolSource = mockSymbolSource();
         AssetSource assetSource = mockAssetSource();
+        Asset coreAsset = mockAsset(coreScript);
+        JavascriptStack stack = mockJavascriptStack(coreAsset);
 
-        train_addClasspathAsset(linker, symbolSource, assetSource, coreScript);
-
+        linker.addScriptLink(coreScript);
         linker.addScript("Tapestry.Foo(\"bar\");");
 
         replay();
 
-        RenderSupport support = new RenderSupportImpl(linker, symbolSource, assetSource,
coreScript);
+        RenderSupport support = new RenderSupportImpl(linker, symbolSource, assetSource,
stack);
 
         support.addScript("Tapestry.Foo(\"%s\");", "bar");
 
@@ -135,8 +133,11 @@
         DocumentLinker linker = mockDocumentLinker();
         SymbolSource symbolSource = mockSymbolSource();
         AssetSource assetSource = mockAssetSource();
+        Asset coreAsset = mockAsset(coreScript);
 
-        train_addClasspathAsset(linker, symbolSource, assetSource, coreScript);
+        JavascriptStack stack = mockJavascriptStack(coreAsset);
+
+        linker.addScriptLink(coreScript);
 
         String script = "foo('%');";
 
@@ -144,13 +145,31 @@
 
         replay();
 
-        RenderSupport support = new RenderSupportImpl(linker, symbolSource, assetSource,
coreScript);
+        RenderSupport support = new RenderSupportImpl(linker, symbolSource, assetSource,
stack);
 
         support.addScript(script);
 
         verify();
     }
 
+    protected final JavascriptStack mockJavascriptStack(Asset... asset)
+    {
+        JavascriptStack stack = newMock(JavascriptStack.class);
+
+        expect(stack.getStack()).andReturn(Arrays.asList(asset)).atLeastOnce();
+
+        return stack;
+    }
+
+    protected final Asset mockAsset(String assetURL)
+    {
+        Asset asset = mockAsset();
+
+        train_toClientURL(asset, assetURL);
+
+        return asset;
+    }
+
     @Test
     public void add_classpath_script_link()
     {
@@ -171,7 +190,7 @@
 
         replay();
 
-        RenderSupport support = new RenderSupportImpl(linker, source, assetSource);
+        RenderSupport support = new RenderSupportImpl(linker, source, assetSource, new EmptyJavascriptStack());
 
         support.addClasspathScriptLink(path);
 
@@ -190,7 +209,7 @@
 
         replay();
 
-        RenderSupport support = new RenderSupportImpl(linker, null, null);
+        RenderSupport support = new RenderSupportImpl(linker, null, null, new EmptyJavascriptStack());
 
         support.addStylesheetLink(asset, media);
 
@@ -207,7 +226,7 @@
 
         replay();
 
-        RenderSupport support = new RenderSupportImpl(linker, null, null);
+        RenderSupport support = new RenderSupportImpl(linker, null, null, new EmptyJavascriptStack());
 
         support.addStylesheetLink(ASSET_URL, media);
 
@@ -223,7 +242,7 @@
 
         replay();
 
-        RenderSupportImpl support = new RenderSupportImpl(linker, null, null);
+        RenderSupportImpl support = new RenderSupportImpl(linker, null, null, new EmptyJavascriptStack());
 
         support.addInit("foo", "fred");
         support.addInit("foo", "barney");
@@ -242,7 +261,7 @@
 
         replay();
 
-        RenderSupportImpl support = new RenderSupportImpl(linker, null, null);
+        RenderSupportImpl support = new RenderSupportImpl(linker, null, null, new EmptyJavascriptStack());
 
         support.addInit("foo", "fred", "barney");
 
@@ -260,7 +279,7 @@
 
         replay();
 
-        RenderSupportImpl support = new RenderSupportImpl(linker, null, null);
+        RenderSupportImpl support = new RenderSupportImpl(linker, null, null, new EmptyJavascriptStack());
 
         support.autofocus(FieldFocusPriority.OPTIONAL, "foo");
 
@@ -278,7 +297,7 @@
 
         replay();
 
-        RenderSupportImpl support = new RenderSupportImpl(linker, null, null);
+        RenderSupportImpl support = new RenderSupportImpl(linker, null, null, new EmptyJavascriptStack());
 
         support.autofocus(FieldFocusPriority.OPTIONAL, "foo");
         support.autofocus(FieldFocusPriority.OPTIONAL, "bar");
@@ -297,7 +316,7 @@
 
         replay();
 
-        RenderSupportImpl support = new RenderSupportImpl(linker, null, null);
+        RenderSupportImpl support = new RenderSupportImpl(linker, null, null, new EmptyJavascriptStack());
 
         support.autofocus(FieldFocusPriority.OPTIONAL, "foo");
         support.autofocus(FieldFocusPriority.REQUIRED, "bar");



Mime
View raw message