You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by an...@apache.org on 2007/12/18 03:34:01 UTC

svn commit: r605068 - /tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/SimpleAjaxShellDelegate.java

Author: andyhot
Date: Mon Dec 17 18:34:00 2007
New Revision: 605068

URL: http://svn.apache.org/viewvc?rev=605068&view=rev
Log:
TAPESTRY-1902: provide extension points for the real delegates

Modified:
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/SimpleAjaxShellDelegate.java

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/SimpleAjaxShellDelegate.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/SimpleAjaxShellDelegate.java?rev=605068&r1=605067&r2=605068&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/SimpleAjaxShellDelegate.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/javascript/SimpleAjaxShellDelegate.java Mon Dec 17 18:34:00 2007
@@ -28,8 +28,7 @@
  */
 public class SimpleAjaxShellDelegate implements IRender
 {
-    private static final String SYSTEM_NEWLINE = (String)java.security.AccessController.doPrivileged(
-      new sun.security.action.GetPropertyAction("line.separator"));
+    private static final String SYSTEM_NEWLINE = "\n";
 
     private JavascriptManager _javascriptManager;
 
@@ -42,40 +41,78 @@
      * {@inheritDoc}
      */
     public void render(IMarkupWriter writer, IRequestCycle cycle)
-    {
-        IPage page = cycle.getPage();
-        StringBuffer str = new StringBuffer();
+    {        
+        StringBuffer str = new StringBuffer(300);
+        
+        processPath(str, cycle, _javascriptManager.getPath());
 
         // include all the main js packages
-        appendAssetsAsJavascript(str, _javascriptManager.getAssets());
+        appendAssetsAsJavascript(str, cycle, _javascriptManager.getAssets());
+        
+        IPage page = cycle.getPage();
         if (page.hasFormComponents())
         {
-            appendAssetsAsJavascript(str, _javascriptManager.getFormAssets());
+            appendAssetsAsJavascript(str, cycle, _javascriptManager.getFormAssets());
         }
         if (page.hasWidgets())
         {
-            appendAssetsAsJavascript(str, _javascriptManager.getWidgetAssets());
+            appendAssetsAsJavascript(str, cycle, _javascriptManager.getWidgetAssets());
         }
         
+        processTapestryPath(str, cycle, _javascriptManager.getTapestryPath());
+        
         // include the tapestry js
         IAsset tapestryAsset = _javascriptManager.getTapestryAsset();
         if (tapestryAsset!=null)
         {
-            str.append("<script type=\"text/javascript\" src=\"")
-                .append(tapestryAsset.buildURL()).append("\"></script>").append(SYSTEM_NEWLINE);
+            appendAssetAsJavascript(str, cycle, tapestryAsset);
         }
 
         writer.printRaw(str.toString());
         writer.println();
     }
+    
+    /**
+     * Called before including any javascript. It does nothing by default, but allows
+     * subclasses to change this behavior.  
+     * @param cycle
+     * @param str 
+     * @param path The base path to the javascript files. May be null.
+     */
+    protected void processPath(StringBuffer str, IRequestCycle cycle, IAsset path) 
+    {
+    }  
+    
+    /**
+     * Called before including tapestry's base javascript. It does nothing by default, 
+     * but allows subclasses to change this behavior.  
+     * @param cycle
+     * @param str 
+     * @param path The base path to the tapestry javascript file. May be null.
+     */    
+    protected void processTapestryPath(StringBuffer str, IRequestCycle cycle, IAsset path) 
+    {
+    }      
+    
+    /**
+     * Appends a script tag to include the given asset. 
+     * @param str
+     * @param cycle
+     * @param asset
+     */
+    protected void appendAssetAsJavascript(StringBuffer str, IRequestCycle cycle, IAsset asset)
+    {
+        final String url = asset.buildURL();
+        str.append("<script type=\"text/javascript\" src=\"").append(url)
+                .append("\"></script>").append(SYSTEM_NEWLINE);
+        
+    }        
 
-    private void appendAssetsAsJavascript(StringBuffer str, List jsAssets)
+    private void appendAssetsAsJavascript(StringBuffer str, IRequestCycle cycle, List jsAssets)
     {
         for (int i = 0; i < jsAssets.size(); i++)
         {
-            IAsset asset = (IAsset) jsAssets.get(i);
-            str.append("<script type=\"text/javascript\" src=\"")
-                .append(asset.buildURL()).append("\"></script>").append(SYSTEM_NEWLINE);
+            appendAssetAsJavascript(str, cycle, (IAsset) jsAssets.get(i));
         }
     }
 }