You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by do...@apache.org on 2006/02/24 23:59:22 UTC

svn commit: r380852 - in /beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urls: AjaxUrlInfo.java URLRewriter.java URLRewriterService.java

Author: dolander
Date: Fri Feb 24 14:59:20 2006
New Revision: 380852

URL: http://svn.apache.org/viewcvs?rev=380852&view=rev
Log:
This adds a new method to the URL rewriter which will provide
information so that AJAX enabled controls can build proper
URLS on the client.



Added:
    beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urls/AjaxUrlInfo.java   (with props)
Modified:
    beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urls/URLRewriter.java
    beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urls/URLRewriterService.java

Added: beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urls/AjaxUrlInfo.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urls/AjaxUrlInfo.java?rev=380852&view=auto
==============================================================================
--- beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urls/AjaxUrlInfo.java (added)
+++ beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urls/AjaxUrlInfo.java Fri Feb 24 14:59:20 2006
@@ -0,0 +1,42 @@
+package org.apache.beehive.netui.core.urls;
+
+/**
+ * This is a class that acts as a data structure for the information for an AJAX request.
+ * An AJAX URL has the following shape commandPrefix]component-directed-command.xhr?[component-parameters]&ajaxParameter
+ */
+public class AjaxUrlInfo
+{
+    /**
+     * When an AJAX request is made, this is the name of the hidden field or URL paramter
+     * that contains the Ajax Paramter property.
+     */
+    public static final String AJAX_PARAMTER_NAME = "netuiajax";
+
+    private String _commandPrefix;
+    private String _ajaxParameter;
+
+    public AjaxUrlInfo(String commandPrefix, String ajaxParameter)
+    {
+        _commandPrefix = commandPrefix;
+        _ajaxParameter = ajaxParameter;
+    }
+
+    /**
+     * Property getter for the Command Prefix.
+     * @return return the prefix to the AJAX command
+     */
+    public String getCommandPrefix()
+    {
+        return _commandPrefix;
+    }
+
+    /**
+     * Property getter for the AjaxParamter.  This paramter must be URL encoded
+     * when added to a URL.
+     * @return return the AJAX Paramter
+     */
+    public String getAjaxParameter()
+    {
+        return _ajaxParameter;
+    }
+}

Propchange: beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urls/AjaxUrlInfo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urls/URLRewriter.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urls/URLRewriter.java?rev=380852&r1=380851&r2=380852&view=diff
==============================================================================
--- beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urls/URLRewriter.java (original)
+++ beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urls/URLRewriter.java Fri Feb 24 14:59:20 2006
@@ -56,6 +56,21 @@
     public abstract String getNamePrefix( ServletContext servletContext, ServletRequest request, String name );
 
     /**
+     * This method will return two bits of information that are used by components that want run through
+     * the AJAX facilities.  The <code>AjaxUrlInfo</code> class is returned and specifies this information.
+     * @param servletContext the current ServletContext.
+     * @param request the current ServletRequest.
+     * @param nameable this object that is the target of the Ajax request.  Typically it is an INameable.
+     */
+    public AjaxUrlInfo getAjaxUrl(ServletContext servletContext, ServletRequest request, Object nameable)
+    {
+        // @todo: this should actually be an abstract method in the next major version.
+        // @todo: the nameable is has to be an INameable, this requires taking a dependency here on the NameService
+        // For back compat, this method is implemented but only throws a runtime exception
+        throw new RuntimeException("Not Implemented");
+    }
+
+    /**
      * Rewrite the given URL.
      * 
      * @param servletContext the current ServletContext.

Modified: beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urls/URLRewriterService.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urls/URLRewriterService.java?rev=380852&r1=380851&r2=380852&view=diff
==============================================================================
--- beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urls/URLRewriterService.java (original)
+++ beehive/trunk/netui/src/core/org/apache/beehive/netui/core/urls/URLRewriterService.java Fri Feb 24 14:59:20 2006
@@ -86,6 +86,33 @@
     }
 
     /**
+     * This method will return two bits of information that are used by components that want run through
+     * the AJAX facilities.  The <code>AjaxUrlInfo</code> class is returned and specifies this information.  Unlike
+     * the other URLRewriter method, this is a true Chain of Responsibility (CoR) implementation.  The first URLRewriter
+     * to return the AjaxUrlInfo object wins and that is returned from this call.  The reason for this is that
+     * the implementation of the Ajax Context is also a true CoR implementation.  These must match.
+     * @param servletContext the current ServletContext.
+     * @param request the current ServletRequest.
+     * @param nameable this object that is the target of the Ajax request.  Typically it is an INameable.
+     */
+    public static AjaxUrlInfo getAjaxUrl(ServletContext servletContext, ServletRequest request, Object nameable)
+    {
+        ArrayList/*< URLRewriter >*/ rewriters = getRewriters( request );
+
+        if ( rewriters != null )
+        {
+            for ( Iterator i = rewriters.iterator(); i.hasNext(); )
+            {
+                URLRewriter rewriter = ( URLRewriter ) i.next();
+                AjaxUrlInfo info = rewriter.getAjaxUrl(servletContext,request,nameable);
+                if (info != null)
+                    return info;
+            }
+        }
+        return null;
+    }
+
+    /**
      * Rewrite the given URL, looping through the list of registered URLRewriters.
      *
      * <p> Once the MutableURI has been rewritten, and if it is an instance of