Author: jkuhnert
Date: Wed Nov 15 15:24:20 2006
New Revision: 475491

URL: http://svn.apache.org/viewvc?view=rev&rev=475491
Log:
Fixes for TAPESTRY-1150. Was using asset service to generate urls when I 
could've just called IAsset.buildURL(). This now
properly allows for using context based dojo/etc includes. 

Also fixed tapestry.namespace to properly detect a module registration path for 
tapestry js modules and act appropriately.

Added:
    tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/js/
Modified:
    
tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/Border.html
    
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/AjaxShellDelegate.java
    
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/html/ScriptIncludes.jwc
    
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Shell.jwc
    tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/dojo.js
    tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/namespace.js
    tapestry/tapestry4/trunk/tapestry-framework/src/scripts/TestLibrary.xml
    tapestry/tapestry4/trunk/tapestry-framework/src/scripts/TestSimple.xml
    
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/dojo/AjaxShellDelegateTest.java

Modified: 
tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/Border.html
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/Border.html?view=diff&rev=475491&r1=475490&r2=475491
==============================================================================
--- 
tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/Border.html
 (original)
+++ 
tapestry/tapestry4/trunk/tapestry-examples/TimeTracker/src/context/WEB-INF/Border.html
 Wed Nov 15 15:24:20 2006
@@ -1,7 +1,8 @@
 <html jwcid="@Shell" 
          title="message:window.title"
          browserLogLevel="DEBUG"
-         consoleEnabled="true" >
+         consoleEnabled="true"
+         >
 <link jwcid="@Relation" href="favicon.ico" type="image/gif" rel="shortcut 
icon" />    
 <link jwcid="@Relation" href="css/timetracker.css" media="all" />
 

Modified: 
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/AjaxShellDelegate.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/AjaxShellDelegate.java?view=diff&rev=475491&r1=475490&r2=475491
==============================================================================
--- 
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/AjaxShellDelegate.java
 (original)
+++ 
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/AjaxShellDelegate.java
 Wed Nov 15 15:24:20 2006
@@ -20,7 +20,6 @@
 import org.apache.tapestry.IMarkupWriter;
 import org.apache.tapestry.IRender;
 import org.apache.tapestry.IRequestCycle;
-import org.apache.tapestry.engine.IEngineService;
 import org.apache.tapestry.html.Shell;
 import org.apache.tapestry.json.JSONObject;
 
@@ -50,7 +49,7 @@
     
     private IAsset _tapestrySource;
     
-    private IEngineService _assetService;
+    private IAsset _tapestryPath;
     
     private boolean _parseWidgets;
     
@@ -89,9 +88,7 @@
         
         // The key to resolving everything out of the asset service
         
-        dojoConfig.put("baseRelativePath", 
-                _assetService.getLink(true, 
_dojoPath.getResourceLocation().getPath()).getURL());
-        
+        dojoConfig.put("baseRelativePath", _dojoPath.buildURL());
         dojoConfig.put("preventBackButtonFix", _preventBackButtonFix);
         dojoConfig.put("parseWidgets", _parseWidgets);
         
@@ -116,16 +113,19 @@
         // include the core dojo.js package
         
         str.append("<script type=\"text/javascript\" src=\"")
-        .append(_assetService.getLink(true,
-                _dojoSource.getResourceLocation()
-                .getPath()).getURL()).append("\"></script>");
+        .append(_dojoSource.buildURL()).append("\"></script>");
+        
+        // module path registration to tapestry javascript sources
+        
+        str.append("\n<script type=\"text/javascript\">\n")
+        .append("dojo.registerModulePath(\"tapestry\", \"")
+        .append(_tapestryPath.buildURL()).append("\");\n");
+        str.append("</script>\n");
         
         // include core tapestry.js package
         
         str.append("<script type=\"text/javascript\" src=\"")
-        .append(_assetService.getLink(true,
-                _tapestrySource.getResourceLocation()
-                .getPath()).getURL()).append("\"></script>");
+        .append(_tapestrySource.buildURL()).append("\"></script>");
         
         String logRequire = _consoleEnabled ? 
"dojo.require(\"dojo.debug.console\");\n"
                 : "dojo.require(\"dojo.logging.Logger\");\n";
@@ -279,11 +279,13 @@
     }
     
     /**
-     * Injected asset service.
-     * @param service
+     * Sets the path to the tapestry javascript modules. (Needed for dojo to 
resolve the 
+     * path to tapestry javascript, esp when overriding the default bundled 
dojo.)
+     * 
+     * @param tapestryPath The path to tapestry.
      */
-    public void setAssetService(IEngineService service)
+    public void setTapestryPath(IAsset tapestryPath)
     {
-        _assetService = service;
+        _tapestryPath = tapestryPath;
     }
 }

Modified: 
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/html/ScriptIncludes.jwc
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/html/ScriptIncludes.jwc?view=diff&rev=475491&r1=475490&r2=475491
==============================================================================
--- 
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/html/ScriptIncludes.jwc
 (original)
+++ 
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/dojo/html/ScriptIncludes.jwc
 Wed Nov 15 15:24:20 2006
@@ -77,7 +77,14 @@
             If specified, allows for the default tapestry source included to 
be overriden.
         </description>
     </parameter>
-
+    
+    <parameter name="tapestryPath" default-value="asset:defaultTapestryPath">
+        <description>
+            Sets the tapestry path, needed for dojo to properly detect and 
find tapestry js modules
+            when overriding the default dojo bundled with tapestry.
+        </description>
+    </parameter>
+    
     <parameter name="dojoSource" default-value="asset:defaultDojoSource">
         <description>
             If specified, allows for the default dojo source included to be 
overriden.
@@ -90,14 +97,12 @@
             used by the djConfig.baseRelativePath javascript configuration 
variable in dojo.
         </description>
     </parameter>
-    
-    <inject property="assetService" object="service:tapestry.services.Asset" />
 
     <bean name="coreAjaxDelegate" 
class="org.apache.tapestry.dojo.AjaxShellDelegate">
         <set name="dojoSource" value="dojoSource" />
-        <set name="assetService" value="assetService" />
         <set name="dojoPath" value="dojoPath" />
         <set name="tapestrySource" value="tapestrySource" />
+        <set name="tapestryPath" value="tapestryPath" />
         <set name="logLevel" value="browserLogLevel" />
         <set name="debug" value="debugEnabled" />
         <set name="debugAtAllCosts" value="debugAtAllCosts" />
@@ -110,5 +115,6 @@
     <asset name="defaultDojoSource" path="classpath:/dojo/dojo.js" />
     <asset name="defaultDojoPath" path="classpath:/dojo/" />
     <asset name="defaultTapestrySource" path="classpath:/tapestry/core.js" />
+    <asset name="defaultTapestryPath" path="classpath:/tapestry/" />
     
 </component-specification>

Modified: 
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Shell.jwc
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Shell.jwc?view=diff&rev=475491&r1=475490&r2=475491
==============================================================================
--- 
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Shell.jwc
 (original)
+++ 
tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/html/Shell.jwc
 Wed Nov 15 15:24:20 2006
@@ -136,6 +136,13 @@
         </description>
     </parameter>
 
+    <parameter name="tapestryPath" default-value="asset:defaultTapestryPath">
+        <description>
+            Sets the tapestry path, needed for dojo to properly detect and 
find tapestry js modules
+            when overriding the default dojo bundled with tapestry.
+        </description>
+    </parameter>
+
     <parameter name="dojoSource" default-value="asset:defaultDojoSource">
         <description>
             If specified, allows for the default dojo source included to be 
overriden.
@@ -153,13 +160,12 @@
     <inject property="pageService" object="engine-service:page" />
     <inject property="applicationSpecification" 
object="infrastructure:applicationSpecification" />
     <inject property="baseTagWriter" 
object="service:tapestry.url.BaseTagWriter" />
-    <inject property="assetService" object="service:tapestry.services.Asset" />
 
     <bean name="coreAjaxDelegate" 
class="org.apache.tapestry.dojo.AjaxShellDelegate">
         <set name="dojoSource" value="dojoSource" />
-        <set name="assetService" value="assetService" />
         <set name="dojoPath" value="dojoPath" />
         <set name="tapestrySource" value="tapestrySource" />
+        <set name="tapestryPath" value="tapestryPath" />
         <set name="logLevel" value="browserLogLevel" />
         <set name="debug" value="debugEnabled" />
         <set name="debugAtAllCosts" value="debugAtAllCosts" />
@@ -172,5 +178,6 @@
     <asset name="defaultDojoSource" path="classpath:/dojo/dojo.js" />
     <asset name="defaultDojoPath" path="classpath:/dojo/" />
     <asset name="defaultTapestrySource" path="classpath:/tapestry/core.js" />
+    <asset name="defaultTapestryPath" path="classpath:/tapestry/" />
     
 </component-specification>

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/dojo.js
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/dojo.js?view=diff&rev=475491&r1=475490&r2=475491
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/dojo.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/dojo/dojo.js Wed Nov 15 
15:24:20 2006
@@ -54,7 +54,7 @@
 obj=obj[p[i]];}
 return true;};dojo.hostenv.normalizeLocale=function(_6e){return 
_6e?_6e.toLowerCase():dojo.locale;};dojo.hostenv.searchLocalePath=function(_6f,_70,_71){_6f=dojo.hostenv.normalizeLocale(_6f);var
 _72=_6f.split("-");var _73=[];for(var 
i=_72.length;i>0;i--){_73.push(_72.slice(0,i).join("-"));}
 _73.push(false);if(_70){_73.reverse();}
-for(var j=_73.length-1;j>=0;j--){var loc=_73[j]||"ROOT";var 
_77=_71(loc);if(_77){break;}}};dojo.hostenv.localesGenerated=["ROOT","es-es","es","it-it","pt-br","de","fr-fr","zh-cn","pt","en-us","zh","fr","zh-tw","it","en-gb","xx","de-de","ko-kr","ja-jp","ko","en","ja"];dojo.hostenv.registerNlsPrefix=function(){dojo.registerModulePath("nls","nls");};dojo.hostenv.preloadLocalizations=function(){if(dojo.hostenv.localesGenerated){dojo.hostenv.registerNlsPrefix();function
 preload(_78){dojo.log.debug("locale passed in is " + 
_78);_78=dojo.hostenv.normalizeLocale(_78);dojo.hostenv.searchLocalePath(_78,true,function(loc){for(var
 
i=0;i<dojo.hostenv.localesGenerated.length;i++){if(dojo.hostenv.localesGenerated[i]==loc){dojo["require"]("nls.dojo_"+loc);return
 true;}}
+for(var j=_73.length-1;j>=0;j--){var loc=_73[j]||"ROOT";var 
_77=_71(loc);if(_77){break;}}};dojo.hostenv.localesGenerated=["ROOT","es-es","es","it-it","pt-br","de","fr-fr","zh-cn","pt","en-us","zh","fr","zh-tw","it","en-gb","xx","de-de","ko-kr","ja-jp","ko","en","ja"];dojo.hostenv.registerNlsPrefix=function(){dojo.registerModulePath("nls","nls");};dojo.hostenv.preloadLocalizations=function(){if(dojo.hostenv.localesGenerated){dojo.hostenv.registerNlsPrefix();function
 
preload(_78){_78=dojo.hostenv.normalizeLocale(_78);dojo.hostenv.searchLocalePath(_78,true,function(loc){for(var
 
i=0;i<dojo.hostenv.localesGenerated.length;i++){if(dojo.hostenv.localesGenerated[i]==loc){dojo["require"]("nls.dojo_"+loc);return
 true;}}
 return false;});}
 preload();var _7b=djConfig.extraLocale||[];for(var 
i=0;i<_7b.length;i++){preload(_7b[i]);}}
 
dojo.hostenv.preloadLocalizations=function(){};};dojo.requireLocalization=function(_7d,_7e,_7f){dojo.hostenv.preloadLocalizations();var
 _80=[_7d,"nls",_7e].join(".");var 
_81=dojo.hostenv.findModule(_80);if(_81){if(djConfig.localizationComplete&&_81._built){return;}

Modified: 
tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/namespace.js
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/namespace.js?view=diff&rev=475491&r1=475490&r2=475491
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/namespace.js 
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/namespace.js 
Wed Nov 15 15:24:20 2006
@@ -17,6 +17,12 @@
                return map[domain][name];
        }
        
-       dojo.registerNamespaceManifest("tapestry","../tapestry", "tapestry", 
"tapestry.widget");
+       var tpath;
+       if (dojo.hostenv.moduleHasPrefix("tapestry")){
+               tpath=dojo.hostenv.getModulePrefix("tapestry");
+       } else {
+               tpath="../tapestry";
+       }
+       dojo.registerNamespaceManifest("tapestry", tpath, "tapestry", 
"tapestry.widget");
        dojo.registerNamespaceResolver("tapestry", resolveNamespace);
 })();

Modified: 
tapestry/tapestry4/trunk/tapestry-framework/src/scripts/TestLibrary.xml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/scripts/TestLibrary.xml?view=diff&rev=475491&r1=475490&r2=475491
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/scripts/TestLibrary.xml 
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/scripts/TestLibrary.xml Wed 
Nov 15 15:24:20 2006
@@ -54,6 +54,10 @@
         <match>/script</match>
         <match>script</match>
         <match>/script</match>
+        <match>script</match>
+        <match>/script</match>
+        <match>script</match>
+        <match>/script</match>
                <match>link</match>
                <match>/head</match>
                <match>body</match>     

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/scripts/TestSimple.xml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/scripts/TestSimple.xml?view=diff&rev=475491&r1=475490&r2=475491
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/scripts/TestSimple.xml 
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/scripts/TestSimple.xml Wed 
Nov 15 15:24:20 2006
@@ -47,6 +47,10 @@
         <match>/script</match>
         <match>script</match>
         <match>/script</match>
+        <match>script</match>
+        <match>/script</match>
+        <match>script</match>
+        <match>/script</match>
                <match>/head</match>
                <match>body</match>     
                <match>br</match>       

Modified: 
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/dojo/AjaxShellDelegateTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/dojo/AjaxShellDelegateTest.java?view=diff&rev=475491&r1=475490&r2=475491
==============================================================================
--- 
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/dojo/AjaxShellDelegateTest.java
 (original)
+++ 
tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/dojo/AjaxShellDelegateTest.java
 Wed Nov 15 15:24:20 2006
@@ -13,14 +13,15 @@
 // limitations under the License.
 package org.apache.tapestry.dojo;
 
+import static org.easymock.EasyMock.expect;
+
 import java.util.Locale;
-import org.apache.tapestry.IPage;
-import static org.easymock.EasyMock.*;
 
 import org.apache.hivemind.Resource;
 import org.apache.tapestry.BaseComponentTestCase;
 import org.apache.tapestry.IAsset;
 import org.apache.tapestry.IMarkupWriter;
+import org.apache.tapestry.IPage;
 import org.apache.tapestry.IRequestCycle;
 import org.apache.tapestry.engine.IEngineService;
 import org.apache.tapestry.engine.ILink;
@@ -64,24 +65,26 @@
         IAsset dojoSource = newAsset();
         IAsset dojoPath = newAsset();
         IAsset tSource = newAsset();
-        IEngineService assetService = newEngineService();
+        IAsset tPath = newAsset();
         
         IRequestCycle cycle = newCycle();
         IMarkupWriter writer = newBufferWriter();
         
-        trainStaticPath(assetService, dojoPath, "/dojo/path");
+        expect(dojoPath.buildURL()).andReturn("http:///dojo/path";);
         
         trainPageLocale(cycle, Locale.US);
         
-        trainStaticPath(assetService, dojoSource, "/dojo/path/dojo.js");
+        expect(dojoSource.buildURL()).andReturn("http:///dojo/path/dojo.js";);
         
-        trainStaticPath(assetService, tSource, "/tapestry/tapestry.js");
+        expect(tPath.buildURL()).andReturn("/tapestry");
+        
+        expect(tSource.buildURL()).andReturn("/tapestry/tapestry.js");
         
         AjaxShellDelegate d = new AjaxShellDelegate();
-        d.setAssetService(assetService);
         d.setDojoPath(dojoPath);
         d.setDojoSource(dojoSource);
         d.setTapestrySource(tSource);
+        d.setTapestryPath(tPath);
         
         replay();
         
@@ -93,11 +96,14 @@
                 + "\"baseRelativePath\":\"http:///dojo/path\",";
                 
+"\"preventBackButtonFix\":false,\"parseWidgets\":false,\"locale\":\"en-us\"} 
</script>\n" + 
                 "\n" + 
-                " <script type=\"text/javascript\" 
src=\"http:///dojo/path/dojo.js\";></script>"
-                +"<script type=\"text/javascript\" 
src=\"http:///tapestry/tapestry.js\";></script>\n" + 
+                " <script type=\"text/javascript\" 
src=\"http:///dojo/path/dojo.js\";></script>\n"
+                + "<script type=\"text/javascript\">\n" + 
+                "dojo.registerModulePath(\"tapestry\", \"/tapestry\");\n" + 
+                "</script>\n" + 
+                "<script type=\"text/javascript\" 
src=\"/tapestry/tapestry.js\"></script>\n" + 
                 "<script type=\"text/javascript\">\n" + 
                 "dojo.require(\"tapestry.namespace\");\n" + 
-        "</script>" + SYSTEM_NEWLINE);
+                "</script>" + SYSTEM_NEWLINE);
     }
     
     public void test_Debug_Render()
@@ -105,24 +111,26 @@
         IAsset dojoSource = newAsset();
         IAsset dojoPath = newAsset();
         IAsset tSource = newAsset();
-        IEngineService assetService = newEngineService();
+        IAsset tPath = newAsset();
         
         IRequestCycle cycle = newCycle();
         IMarkupWriter writer = newBufferWriter();
         
-        trainStaticPath(assetService, dojoPath, "/dojo/path");
+        expect(dojoPath.buildURL()).andReturn("http:///dojo/path";);
         
         trainPageLocale(cycle, Locale.UK);
         
-        trainStaticPath(assetService, dojoSource, "/dojo/path/dojo.js");
+        expect(dojoSource.buildURL()).andReturn("http:///dojo/path/dojo.js";);
+        
+        expect(tPath.buildURL()).andReturn("/tapestry");
         
-        trainStaticPath(assetService, tSource, "/tapestry/tapestry.js");
+        expect(tSource.buildURL()).andReturn("/tapestry/tapestry.js");
         
         AjaxShellDelegate d = new AjaxShellDelegate();
-        d.setAssetService(assetService);
         d.setDojoPath(dojoPath);
         d.setDojoSource(dojoSource);
         d.setTapestrySource(tSource);
+        d.setTapestryPath(tPath);
         d.setDebug(true);
         d.setLogLevel(AjaxShellDelegate.BROWSER_LOG_DEBUG);
         d.setConsoleEnabled(true);
@@ -137,12 +145,15 @@
                 + "\"baseRelativePath\":\"http:///dojo/path\",";
                 
+"\"preventBackButtonFix\":false,\"parseWidgets\":false,\"locale\":\"en-gb\"} 
</script>\n" + 
                 "\n" + 
-                " <script type=\"text/javascript\" 
src=\"http:///dojo/path/dojo.js\";></script>"
-                +"<script type=\"text/javascript\" 
src=\"http:///tapestry/tapestry.js\";></script>\n" + 
+                " <script type=\"text/javascript\" 
src=\"http:///dojo/path/dojo.js\";></script>\n"
+                + "<script type=\"text/javascript\">\n" + 
+                "dojo.registerModulePath(\"tapestry\", \"/tapestry\");\n" + 
+                "</script>\n" + 
+                "<script type=\"text/javascript\" 
src=\"/tapestry/tapestry.js\"></script>\n" + 
                 "<script type=\"text/javascript\">\n" + 
                 "dojo.require(\"dojo.debug.console\");\n" + 
-                "dojo.log.setLevel(dojo.log.getLevel(\"DEBUG\"));\n" + 
+                "dojo.log.setLevel(dojo.log.getLevel(\"DEBUG\"));\n" +
                 "dojo.require(\"tapestry.namespace\");\n" + 
-        "</script>" + SYSTEM_NEWLINE);
+                "</script>" + SYSTEM_NEWLINE);
     }
 }


Reply via email to