Author: knopp
Date: Mon Aug 25 05:50:23 2008
New Revision: 688709

URL: http://svn.apache.org/viewvc?rev=688709&view=rev
Log:
header contribution 

Modified:
    
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/AjaxBehavior.java
    
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/js/wicket-ajax-ng.js
    
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/request/AjaxRequestTarget.java
    
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/request/AjaxUrlCodingStrategy.java
    
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java

Modified: 
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/AjaxBehavior.java
URL: 
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/AjaxBehavior.java?rev=688709&r1=688708&r2=688709&view=diff
==============================================================================
--- 
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/AjaxBehavior.java
 (original)
+++ 
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/AjaxBehavior.java
 Mon Aug 25 05:50:23 2008
@@ -23,6 +23,7 @@
 
 import org.apache.wicket.Component;
 import org.apache.wicket.Page;
+import org.apache.wicket.Request;
 import org.apache.wicket.RequestCycle;
 import org.apache.wicket.ResourceReference;
 import org.apache.wicket.ajaxng.json.JSONArray;
@@ -34,6 +35,7 @@
 import org.apache.wicket.markup.ComponentTag;
 import org.apache.wicket.markup.html.IHeaderResponse;
 import org.apache.wicket.markup.html.resources.JavascriptResourceReference;
+import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
 
 /**
  * @author Matej Knopp
@@ -128,11 +130,39 @@
                config.append(AjaxUrlCodingStrategy.PARAM_BEHAVIOR_INDEX);
                config.append("';\n");
                
+               config.append("gs.urlParamUrlDepth='");
+               config.append(AjaxUrlCodingStrategy.PARAM_URL_DEPTH);
+               config.append("';\n");
+               
+               config.append("gs.urlDepthValue=");
+               config.append(getUrlDepth());
+               config.append(";\n");
+               
                config.append("})();");
 
                response.renderJavascript(config, WICKET_NS + "-Config");
        }
 
+       private int getUrlDepth()
+       {
+               Request request = RequestCycle.get().getRequest();
+               if (request instanceof ServletWebRequest)
+               {
+                       ServletWebRequest swr = (ServletWebRequest)request;
+                       // If we're coming in with an existing depth, use it. 
Otherwise,
+                       // compute from the URL. This provides correct behavior 
for repeated
+                       // AJAX requests: If we need to generate a URL within 
an AJAX
+                       // request for another one, it needs to be at the same 
depth as the
+                       // original AJAX request.
+                       int urlDepth = swr.getRequestParameters().getUrlDepth();
+                       return urlDepth > -1 ? urlDepth : 
swr.getDepthRelativeToWicketHandler();
+               }
+               else
+               {
+                       return -1;
+               }
+       }
+       
        public void afterRender(Component component)
        {
        }

Modified: 
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/js/wicket-ajax-ng.js
URL: 
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/js/wicket-ajax-ng.js?rev=688709&r1=688708&r2=688709&view=diff
==============================================================================
--- 
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/js/wicket-ajax-ng.js
 (original)
+++ 
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/js/wicket-ajax-ng.js
 Mon Aug 25 05:50:23 2008
@@ -182,7 +182,7 @@
                logger = FirebugLogger;
        }       
        
-       var logConfig = { disableAll: false, trace: true, debug: true, info: 
true, error: true, "trace:GarbageCollector": false };
+       var logConfig = { disableAll: false, trace: true, debug: true, info: 
true, error: true, "trace:GarbageCollector": false, "trace:Contribution":false 
};
        
        W.Log  = 
        {
@@ -395,7 +395,7 @@
                                        } 
                                        catch (ex)
                                        {
-                                               log.error("FunctionExecutor", 
"Error execution function: ", f);
+                                               log.error("FunctionsExecutor", 
"Error execution function: ", f);
                                                notify();
                                        }
                                }, this);
@@ -779,7 +779,7 @@
                for (key in map)
                {
                        var value = map[key];
-                       if (L.isString(value) || L.isNumber(value))
+                       if (L.isString(value) || L.isNumber(value) || 
L.isBoolean(value))
                        {
                                if (res.length > 0)
                                {
@@ -794,7 +794,7 @@
                                for (var i = 0; i < value.length; ++i)
                                {
                                        var v = value[i];
-                                       if (L.isString(v) || L.isNumber(v))
+                                       if (L.isString(v) || L.isNumber(v) || 
L.isBoolean(v))
                                        {
                                                if (res.length > 0)
                                                {
@@ -971,9 +971,9 @@
         */
        var loadStylesheet = function(url, notify)
        {
-               var failureHandler = function() 
+               var failureHandler = function(req, failure) 
                {
-                       log.error("Contribution", "Error loading stylesheet 
from ", url);
+                       log.error("Contribution", "Error loading stylesheet 
from ", url, req, failure);
                        notify();
                };
                
@@ -985,7 +985,7 @@
                        } 
                        catch (exception)
                        {
-                               log.error("Contribution", "Error adding 
stylesheet from ", url);
+                               log.error("Contribution", "Error adding 
stylesheet from ", url, exception);
                        }
                        notify();
                };
@@ -1017,9 +1017,9 @@
         */
        var loadJavascript = function(url, notify)
        {
-               var failureHandler = function() 
+               var failureHandler = function(req) 
                {
-                       log.error("Contribution", "Error loading javascript 
from ", url);
+                       log.error("Contribution", "Error loading javascript 
from ", url, req);
                        notify();
                };
                
@@ -1077,7 +1077,7 @@
        
        var isContributed = function(id, url)
        {
-               if (L.isString(id) && (Wicket.$(id) != null || 
getContributed().ids[id] == true))
+               if (L.isString(id) && (W.$(id) != null || 
getContributed().ids[id] == true))
                {
                        return true;
                }
@@ -1126,9 +1126,9 @@
                                url = element.getAttribute("href");
                        }
                        
-                       log.trace("Contribution", "TagName:", tagName, "url:", 
url, "id:", id);
+                       log.trace("Contribution", "TagName:", tagName, ", 
URL:", url, ", ID:", id);
                        
-                       if (!isContribute(id, url))
+                       if (!isContributed(id, url))
                        {
                                markContributed(id, url);
                                if (tagName == "script")
@@ -1136,7 +1136,7 @@
                                        if (url != null)
                                        {
                                                log.trace("Contribution", 
"Loading javascript:", url);
-                                               loadJavascipt(url, notify);
+                                               loadJavascript(url, notify);
                                        }
                                        else
                                        {
@@ -1147,6 +1147,7 @@
                                                log.trace("Contribution", 
"Evaluating javascript:", body);
                                                
                                                eval(body);
+                                               notify();
                                        }
                                }
                                else if (tagName == "link")
@@ -1162,17 +1163,19 @@
                                        
                                        log.trace("Contribution", "Adding 
stylesheet: ", body);
                                        
-                                       addStyle(body);
+                                       addStyle(body);                         
+                                       notify();
                                }
                        }
                        else
                        {
                                log.trace("Contribution", "Skipped - element 
already contributed.");
+                               notify();
                        }
                } 
                catch (e) 
                {
-                       log.error("Contribution", "Error contributing 
element:", element);
+                       log.error("Contribution", "Error contributing 
element:", element, e);
                        notify();
                }
        }
@@ -1486,6 +1489,7 @@
                {
                        if (this.next != null)
                        {
+                               log.info("RequestQueue", "Item processed 
successfully", this);
                                this.invokeSuccessHandlers();                   
        
                                this.next();
                                this.next = null;
@@ -1549,8 +1553,81 @@
                        return url;
                },
                
+               parseHeaderContribution: function(header)
+               {
+                       var s = "<head>" + header + "</head>";
+                       // build a DOM tree of the contribution
+                       var xmldoc;
+                       if (window.ActiveXObject) {
+                       xmldoc = new ActiveXObject("Microsoft.XMLDOM");
+                               xmldoc.loadXML(s);
+                       } else {
+                           var parser = new DOMParser();    
+                           xmldoc = parser.parseFromString(s, "text/xml");     
+                       }       
+                       
+                       return xmldoc.documentElement;; 
+               },
+               
+               processHeaderContribution: function(header, steps)
+               {
+                       var rootNode = this.parseHeaderContribution(header);
+                       
+                       var processNode = function(node)
+                       {
+                               var tagName = node.tagName.toLowerCase();
+                               if (tagName == "script" || tagName == "link" || 
tagName == "style")
+                               {
+                                       steps.push(function(notify) 
+                                       {
+                                               contributeElement(node, notify);
+                                       });
+                               }                               
+                       };
+                       
+                       // go through the individual elements and process them 
according to their type
+                       for (var i = 0; i < rootNode.childNodes.length; i++) 
+                       {
+                               var node = rootNode.childNodes[i];              
        
+                               if (node.tagName != null) 
+                               {
+                                       var name = node.tagName.toLowerCase();
+                                       
+                                       // it is possible that a reference is 
surrounded by a <wicket:link
+                                       // in that case, we need to find the 
inner element
+                                       if (name == "wicket:link") {            
                        
+                                               for (var j = 0; j < 
node.childNodes.length; ++j) 
+                                               {
+                                                       var childNode = 
node.childNodes[j];
+                                                       // try to find a 
regular node inside wicket:link
+                                                       if (childNode.nodeType 
== 1) 
+                                                       {
+                                                               
processNode(childNode);
+                                                       }                       
                
+                                               }                               
        
+                                       }
+                                                       
+                                       // process the element
+                                       processNode(node);
+                               }
+                       }
+                       
+               },
+               
                processResponse: function(response)
                {
+                       var steps = new Array();
+                       
+                       this.processHeaderContribution(response.header, steps);
+                       
+                       steps.push(bind(function(notify)
+                       {
+                               this.success();
+                       }, this));
+                       
+                       log.debug("RequestQueue", "Response processed: ", 
{toString: function() { return "Steps..."; }, steps:steps}, ". Executing.");    
              
+                       
+                       new FunctionsExecutor(steps).start();
                },
                
                onSuccess: function(transactionId, responseObject)
@@ -1561,11 +1638,12 @@
                                var responseText = 
responseObject.responseText.substring(10);
                                var response = eval(responseText);
                                log.debug("RequestQueue", "Response parsed: ", 
response);
-                               
-                               alert(response.header);
-                               
-                       } catch (exception) {
-                               log.error("RequestQueue","Error parsing or 
processing response.");
+                                                               
+                               this.processResponse(response);
+                       } 
+                       catch (exception) 
+                       {
+                               log.error("RequestQueue","Error parsing or 
processing response.", exception);
                                this.failure(exception);
                        }
                        
@@ -1577,7 +1655,8 @@
                        this.failure();
                },
                
-               getRequestCfg: function(url) {
+               getRequestCfg: function(url) 
+               {
                        var a = this.attributes;
                        var m = a.formId != null ? "POST" : "GET";
                        var f = a.formId != null ? { id:a.formId } : null;
@@ -1604,13 +1683,11 @@
                        var url = this.buildUrl();
                        var cfg = this.getRequestCfg(url);
                        
-                       log.debug("RequestQueue", "Initiating AJAX Request on 
", url, " with configuration ", cfg);
+                       log.info("RequestQueue", "Initiating AJAX Request on ", 
url, " with configuration ", cfg);
                        
                        var request = Y.io(url, cfg);
                        
                        log.trace("RequestQueue", "Obtained request object ", 
request);
-                       
-                       this.success();
                }
        };
        
@@ -1769,11 +1846,13 @@
        
        var reqCount = 0;
        
-       var timestampArgumentMethod = function(item)
+       var defaultArgumentMethod = function(item)
        {
                var stamp = "" + (reqCount ++) + (Math.ceil(Math.random() * 
10000));
                var res = {};
-               res[W.ajax.globalSettings.urlParamTimestamp] = stamp;
+               res[W.ajax.globalSettings.urlParamTimestamp] = stamp;           
        
+               res[W.ajax.globalSettings.urlParamUrlDepth] = 
W.ajax.globalSettings.urlDepthValue;
+               res["wicket:ajax"] = true;
                return res; 
        }
        
@@ -1789,14 +1868,16 @@
                successHandlers: [],
                errorHandlers: [],
                urlPostProcessors: [],
-               urlArgumentMethods: [ timestampArgumentMethod ],
+               urlArgumentMethods: [ defaultArgumentMethod ],
                urlPrefix: "INVALID_URL_PREFIX",
                urlParamComponentId: "INVALID_COMPONENT_ID_PARAM",
                urlParamTimestamp: "INVALID_TIMESTAMP_PARAM",
                urlParamPageId: "INVALID_PAGE_ID_PARAM",
                urlParamFormId: "INVALID_FORM_ID_PARAM",
                urlParamListenerInterface: "INVALID_LISTENER_INTERFACE_PARAM",
-               urlParamBehaviorIndex: "INVALID_BEHAVIOR_INDEX_PARAM"
+               urlParamBehaviorIndex: "INVALID_BEHAVIOR_INDEX_PARAM",
+               urlParamUrlDepth: "INVALID_URL_DEPTH_PARAM",
+               urlDepthValue: 0
        };
        
        var Ajax = function() 

Modified: 
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/request/AjaxRequestTarget.java
URL: 
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/request/AjaxRequestTarget.java?rev=688709&r1=688708&r2=688709&view=diff
==============================================================================
--- 
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/request/AjaxRequestTarget.java
 (original)
+++ 
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/request/AjaxRequestTarget.java
 Mon Aug 25 05:50:23 2008
@@ -75,7 +75,7 @@
                public void onBeforeRespond(List<ComponentEntry> components, 
AjaxRequestTarget target);
 
                /**
-                * Triggered after ajax request target is done with its 
response cycle. At this point only
+                * Triggered after ajax request target is notify with its 
response cycle. At this point only
                 * additional javascript can be output to the response using 
the provided
                 * [EMAIL PROTECTED] IJavascriptResponse} object
                 * 
@@ -228,7 +228,7 @@
                 * <dt>sourceComponentId</dt>
                 * <dd>MarkupId of component that has initiated current ajax 
request or <code>null</code>
                 * if the component is not available.
-                * <dt>done</dt>
+                * <dt>notify</dt>
                 * <dd>Method that javascript needs to execute after it has 
finished. Note that it is
                 * mandatory to call this method otherwise the processing 
pipeline will stop</dd>
                 * </dl>
@@ -261,7 +261,7 @@
                 * <dd>RequestQueueItem instance for current request</dd>
                 * <dt>componentId</dt>
                 * <dd>MarkupId of component that has been replaced
-                * <dt>done</dt>
+                * <dt>notify</dt>
                 * <dd>Method that javascript needs to execute after it has 
finished. Note that it is
                 * mandatory to call this method otherwise the processing 
pipeline will stop</dd>
                 * </dl>
@@ -296,7 +296,7 @@
                 * <dd>MarkupId of component that has been replaced
                 * <dt>markup</dt>
                 * <dd>The new markup that should replace current markup</dd>
-                * <dt>done</dt>
+                * <dt>notify</dt>
                 * <dd>Method that javascript needs to execute after the 
component has been replaced. Note
                 * that it is mandatory to call this method otherwise the 
processing pipeline will stop</dd>
                 * </dl>
@@ -306,7 +306,7 @@
                 * <pre>
                 * var element = W.$(componentId);
                 * W.replaceOuterHtml(element, markup);
-                * done();
+                * notify();
                 * </pre>
                 * 
                 * @param replaceJavascript
@@ -465,7 +465,7 @@
         * <dl>
         * <dt>requestQueueItem</dt>
         * <dd>RequestQueueItem instance for current request</dd>
-        * <dt>done</dt>
+        * <dt>notify</dt>
         * <dd>Must be called for asynchronous javascript
         * </dl>
         * 
@@ -474,7 +474,7 @@
         * @param async
         *            indicates if the javascript should be evaluated 
asynchrously. If
         *            <code>async</code> is <code>true</code>, the javascript 
must invoke the
-        *            <code>done</code> function that it gets passed for the 
processing queue to
+        *            <code>notify</code> function that it gets passed for the 
processing queue to
         *            continue.
         */
        public void prependJavascript(String javascript, boolean async)
@@ -512,7 +512,7 @@
         * <dl>
         * <dt>requestQueueItem</dt>
         * <dd>RequestQueueItem instance for current request</dd>
-        * <dt>done</dt>
+        * <dt>notify</dt>
         * <dd>Must be called for asynchronous javascript
         * </dl>
         * 
@@ -521,7 +521,7 @@
         * @param async
         *            indicates if the javascript should be evaluated 
asynchrously. If
         *            <code>async</code> is <code>true</code>, the javascript 
must invoke the
-        *            <code>done</code> function that it gets passed for the 
processing queue to
+        *            <code>notify</code> function that it gets passed for the 
processing queue to
         *            continue.
         */
        public void appendJavascript(String javascript, boolean async)

Modified: 
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/request/AjaxUrlCodingStrategy.java
URL: 
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/request/AjaxUrlCodingStrategy.java?rev=688709&r1=688708&r2=688709&view=diff
==============================================================================
--- 
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/request/AjaxUrlCodingStrategy.java
 (original)
+++ 
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/ajaxng/request/AjaxUrlCodingStrategy.java
 Mon Aug 25 05:50:23 2008
@@ -19,6 +19,7 @@
 import org.apache.wicket.Component;
 import org.apache.wicket.IRequestTarget;
 import org.apache.wicket.Page;
+import org.apache.wicket.RequestCycle;
 import org.apache.wicket.Session;
 import org.apache.wicket.Component.IVisitor;
 import org.apache.wicket.protocol.http.PageExpiredException;
@@ -118,6 +119,10 @@
                
                int behaviorIndex = 
Integer.valueOf(getParameter(requestParameters, PARAM_BEHAVIOR_INDEX));
                
+               int urlDepth = Integer.valueOf(getParameter(requestParameters, 
PARAM_URL_DEPTH));
+               
+               
RequestCycle.get().getRequest().getRequestParameters().setUrlDepth(urlDepth);
+               
                return new AjaxRequestTarget(component, behaviorIndex);
        }
 
@@ -139,6 +144,7 @@
        public static final String PARAM_FORM_ID = PARAM_PREFIX + "formId";
        public static final String PARAM_LISTENER_INTEFACE = PARAM_PREFIX + 
"listenerInterface";
        public static final String PARAM_BEHAVIOR_INDEX = PARAM_PREFIX + 
"behaviorIndex";
+       public static final String PARAM_URL_DEPTH = PARAM_PREFIX + "urlDepth";
 
        public boolean matches(IRequestTarget requestTarget)
        {

Modified: 
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
URL: 
http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java?rev=688709&r1=688708&r2=688709&view=diff
==============================================================================
--- 
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
 (original)
+++ 
wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/servlet/ServletWebRequest.java
 Mon Aug 25 05:50:23 2008
@@ -415,6 +415,11 @@
        {
                boolean ajax = false;
 
+               if 
(Strings.isTrue(httpServletRequest.getParameter("wicket:ajax")))
+               {
+                       return true;
+               }
+               
                String ajaxHeader = httpServletRequest.getHeader("Wicket-Ajax");
                if (Strings.isEmpty(ajaxHeader) == false)
                {


Reply via email to