You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2006/03/18 00:14:05 UTC

svn commit: r386762 - in /beehive/trunk/netui: src/pageflow/org/apache/beehive/netui/pageflow/xmlhttprequest/ src/tags-html/org/apache/beehive/netui/tags/divpanel/ src/tags-html/org/apache/beehive/netui/tags/tree/ src/util/org/apache/beehive/netui/util...

Author: ekoneil
Date: Fri Mar 17 15:14:03 2006
New Revision: 386762

URL: http://svn.apache.org/viewcvs?rev=386762&view=rev
Log:
Checkpoint work to enable the new CoR pattern for the XmlHttpRequestServlet.

BB: self
Test: NetUI BVT pass


Modified:
    beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/xmlhttprequest/XmlHttpRequestServlet.java
    beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/divpanel/DivPanelCRI.java
    beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/tree/TreeCRI.java
    beehive/trunk/netui/src/util/org/apache/beehive/netui/util/config/internal/catalog/catalog-config.xsd
    beehive/trunk/netui/src/webapp-template/default/WEB-INF/beehive-netui-config.xml
    beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/chain/xmls/simple-chain.xml
    beehive/trunk/netui/test/webapps/drt/web/WEB-INF/beehive-netui-config.xml

Modified: beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/xmlhttprequest/XmlHttpRequestServlet.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/xmlhttprequest/XmlHttpRequestServlet.java?rev=386762&r1=386761&r2=386762&view=diff
==============================================================================
--- beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/xmlhttprequest/XmlHttpRequestServlet.java (original)
+++ beehive/trunk/netui/src/pageflow/org/apache/beehive/netui/pageflow/xmlhttprequest/XmlHttpRequestServlet.java Fri Mar 17 15:14:03 2006
@@ -18,6 +18,10 @@
 package org.apache.beehive.netui.pageflow.xmlhttprequest;
 
 import org.apache.beehive.netui.core.urls.URLRewriterService;
+import org.apache.beehive.netui.core.chain.web.WebChainContext;
+import org.apache.beehive.netui.core.chain.CatalogFactory;
+import org.apache.beehive.netui.core.chain.Catalog;
+import org.apache.beehive.netui.core.chain.Command;
 import org.apache.beehive.netui.pageflow.interceptor.request.RequestInterceptorContext;
 import org.apache.beehive.netui.pageflow.interceptor.request.RequestInterceptor;
 import org.apache.beehive.netui.pageflow.interceptor.Interceptors;
@@ -26,6 +30,8 @@
 import org.apache.beehive.netui.pageflow.internal.DefaultURLRewriter;
 import org.apache.beehive.netui.util.logging.Logger;
 import org.apache.beehive.netui.util.internal.ServletUtils;
+import org.apache.beehive.netui.util.config.bean.CatalogConfig;
+import org.apache.beehive.netui.util.config.ConfigUtil;
 
 import javax.servlet.http.HttpServlet;
 import javax.servlet.http.HttpServletResponse;
@@ -57,28 +63,60 @@
         //System.err.println("Inside the XmlHppRequestServlet:" + request.getRequestURI());
 
         // create an XML empty document, that isn't cached on the client
+        /* todo: move this response manipulation into the CRIs */
         response.setContentType("text/xml");
         response.setHeader("Pragma", "No-cache");
         response.setHeader("Cache-Control", "no-cache");
         
-        ServletContext ctxt = getServletContext();
-        RequestInterceptorContext context = new RequestInterceptorContext(request, response, ctxt);
-        List/*< Interceptor >*/ interceptors = context.getRequestInterceptors();
-
         // Register the default URLRewriter
         URLRewriterService.registerURLRewriter(0, request, new DefaultURLRewriter());
 
-        try
-        {
-            Interceptors.doPreIntercept(context, interceptors);
+        ServletContext ctxt = getServletContext();
+        Command xhrServletCommand = null;
+        CatalogConfig catalogConfig = ConfigUtil.getConfig().getCatalogConfig();
+        if(catalogConfig != null) {
+            /*
+            todo: neaten up this initialization process.  because of the separation between
+                  parsing and configuration, this is a second step.
+                  Need to put this somewhere in the framework.
+             */
+            CatalogFactory catalogFactory = CatalogFactory.getInstance();
+            if(catalogFactory.getCatalog() == null)
+                catalogFactory = CatalogFactory.getInstance(catalogConfig);
+
+            assert catalogFactory != null;
+            Catalog catalog = catalogFactory.getCatalog();
+            if(catalog != null)
+                xhrServletCommand = catalog.getCommand("xhr-commands");
         }
-        catch (InterceptorException e)
-        {
-            ServletUtils.throwServletException(e);
+
+        // execute the Command if found or the interceptors if found
+        if(xhrServletCommand != null) {
+            /* todo: add a chain to create the Context object */
+            WebChainContext webChainContext = new WebChainContext(ctxt, request, response);
+            try {
+                xhrServletCommand.execute(webChainContext);
+            }
+            catch(Exception e) {
+                ServletUtils.throwServletException(e);
+            }
         }
-        
-        // Note that we're not worrying about post-intercept or whether any of the pre-interceptors cancelled the
-        // request, since there's no further processing in the request. 
+        else {
+            RequestInterceptorContext context = new RequestInterceptorContext(request, response, ctxt);
+            List interceptors = context.getRequestInterceptors();
+
+            try {
+                Interceptors.doPreIntercept(context, interceptors);
+            }
+            catch (InterceptorException e) {
+                ServletUtils.throwServletException(e);
+            }
+        }
+
+        /*
+        Note that we're not worrying about post-intercept or whether any of the pre-interceptors cancelled the
+        request, since there's no further processing in the request.
+        */
     }
 
     public void doPost(HttpServletRequest request,

Modified: beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/divpanel/DivPanelCRI.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/divpanel/DivPanelCRI.java?rev=386762&r1=386761&r2=386762&view=diff
==============================================================================
--- beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/divpanel/DivPanelCRI.java (original)
+++ beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/divpanel/DivPanelCRI.java Fri Mar 17 15:14:03 2006
@@ -23,12 +23,44 @@
 import org.apache.beehive.netui.pageflow.requeststate.INameable;
 import org.apache.beehive.netui.pageflow.requeststate.NameService;
 import org.apache.beehive.netui.tags.AbstractClientRequestInterceptor;
+import org.apache.beehive.netui.core.chain.Context;
+import org.apache.beehive.netui.core.chain.Command;
+import org.apache.beehive.netui.core.chain.web.WebChainContext;
 
 import javax.servlet.http.HttpServletRequest;
 
-public class DivPanelCRI extends AbstractClientRequestInterceptor
+public class DivPanelCRI
+    extends AbstractClientRequestInterceptor
+    implements Command
 {
     private static final String SWITCH_PAGE = "switchPage";
+
+    public boolean execute(Context context)
+        throws Exception {
+
+        assert context != null;
+        assert context instanceof WebChainContext;
+        assert ((WebChainContext)context).getServletRequest() instanceof HttpServletRequest;
+
+        boolean handled = false;
+
+        WebChainContext webChainContext = (WebChainContext)context;
+        HttpServletRequest request = (HttpServletRequest)webChainContext.getServletRequest();
+
+        // Create the command by striping off the context path and the extension
+        String uri = request.getRequestURI();
+        String ctxtPath = request.getContextPath();
+
+        String cmd = getCommand(uri, ctxtPath);
+
+        // check to see if we handle this command
+        if (SWITCH_PAGE.equals(cmd)) {
+            handlePageSwitch(request);
+            handled = true;
+        }
+
+        return handled;
+    }
 
     public void preRequest(RequestInterceptorContext ctxt, InterceptorChain chain)
     {

Modified: beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/tree/TreeCRI.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/tree/TreeCRI.java?rev=386762&r1=386761&r2=386762&view=diff
==============================================================================
--- beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/tree/TreeCRI.java (original)
+++ beehive/trunk/netui/src/tags-html/org/apache/beehive/netui/tags/tree/TreeCRI.java Fri Mar 17 15:14:03 2006
@@ -29,6 +29,9 @@
 import org.apache.beehive.netui.tags.rendering.StringBuilderRenderAppender;
 import org.apache.beehive.netui.tags.TagConfig;
 import org.apache.beehive.netui.util.logging.Logger;
+import org.apache.beehive.netui.core.chain.Command;
+import org.apache.beehive.netui.core.chain.Context;
+import org.apache.beehive.netui.core.chain.web.WebChainContext;
 
 import javax.servlet.ServletContext;
 import javax.servlet.ServletResponse;
@@ -38,7 +41,9 @@
 import java.io.IOException;
 import java.io.Writer;
 
-public class TreeCRI extends RequestInterceptor
+public class TreeCRI
+    extends RequestInterceptor
+    implements Command
 {
     private static final String TREE_COLLAPSE = "treeCollapse";
     private static final String TREE_EXPAND = "treeExpand";
@@ -48,13 +53,64 @@
     // The elements we will create in the document
     private static final String TREE_EXPAND_ELEM = "treeExpand";
 
+    /**
+     * Implementation of the {@link Command} interface for using this class as part of a
+     * Chain of Responsibility.
+     *
+     * @param context the Chain's context object
+     * @return <code>true</code> if the request was handled by this command; <code>false</code> otherwise
+     * @throws Exception any exception that is throw during processing
+     */
+    public boolean execute(Context context)
+        throws Exception {
+
+        assert context != null;
+        assert context instanceof WebChainContext;
+        assert ((WebChainContext)context).getServletRequest() instanceof HttpServletRequest;
+
+        WebChainContext webChainContext = (WebChainContext)context;
+        HttpServletRequest request = (HttpServletRequest)webChainContext.getServletRequest();
+
+        String cmd = parseCommand(request.getRequestURI());
+        return render(request,
+            webChainContext.getServletResponse(),
+            webChainContext.getServletContext(),
+            cmd);
+    }
+
+    /**
+     * Implementation of the {@link RequestInterceptor#preRequest(org.apache.beehive.netui.pageflow.interceptor.request.RequestInterceptorContext, org.apache.beehive.netui.pageflow.interceptor.InterceptorChain)}
+     * method for using this class as part of a request interceptor chain.
+     *
+     * @param ctxt the interceptor's context object
+     * @param chain the interceptor chain
+     * @throws InterceptorException any exception thrown during processing
+     */
     public void preRequest(RequestInterceptorContext ctxt, InterceptorChain chain) throws InterceptorException
     {
         HttpServletRequest request = ctxt.getRequest();
 
-        // Create the command by striping off the context path and the extension
-        String cmd = request.getRequestURI();
+        String cmd = parseCommand(request.getRequestURI());
+        render(request, ctxt.getResponse(), ctxt.getServletContext(), cmd);
+
+        chain.continueChain();
+    }
+
+    /**
+     * Implementation of the {@link RequestInterceptor#postRequest(org.apache.beehive.netui.pageflow.interceptor.request.RequestInterceptorContext, org.apache.beehive.netui.pageflow.interceptor.InterceptorChain)}
+     * method for using this class as part of a request interceptor chain.
+     *
+     * @param context the interceptor's context object
+     * @param chain the interceptor chain
+     * @throws InterceptorException any exception thrown during processing
+     */
+    public void postRequest(RequestInterceptorContext context, InterceptorChain chain) throws InterceptorException
+    {
+        chain.continueChain();
+    }
 
+    private String parseCommand(String cmd) {
+        // Create the command by striping off the context path and the extension
         // catch any runtime errors here and return.
         try {
             int dot = cmd.lastIndexOf('.');
@@ -67,23 +123,30 @@
             System.err.println("Runtime Error creating XmlRequestServlet Command:" + e.getClass().getName());
         }
 
+        return cmd;
+    }
+
+    private boolean render(HttpServletRequest request,
+                           ServletResponse response,
+                           ServletContext servletContext,
+                           String cmd) {
+
         // check to see if we handle this command
         if (TREE_COLLAPSE.equals(cmd)) {
-            handleExpandCollapse(false, request, ctxt.getResponse(), ctxt.getServletContext());
+            handleExpandCollapse(false, request, response, servletContext);
+            return true;
         }
         else if (TREE_EXPAND.equals(cmd)) {
-            handleExpandCollapse(true, request, ctxt.getResponse(), ctxt.getServletContext());
+            handleExpandCollapse(true, request, response, servletContext);
+            return true;
         }
 
-        chain.continueChain();
-    }
-
-    public void postRequest(RequestInterceptorContext context, InterceptorChain chain) throws InterceptorException
-    {
-        chain.continueChain();
+        return false;
     }
 
-    private void handleExpandCollapse(boolean expand, HttpServletRequest req, ServletResponse response,
+    private void handleExpandCollapse(boolean expand,
+                                      HttpServletRequest req,
+                                      ServletResponse response,
                                       ServletContext ctxt)
     {
         String tree = req.getParameter("tree");

Modified: beehive/trunk/netui/src/util/org/apache/beehive/netui/util/config/internal/catalog/catalog-config.xsd
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/util/org/apache/beehive/netui/util/config/internal/catalog/catalog-config.xsd?rev=386762&r1=386761&r2=386762&view=diff
==============================================================================
--- beehive/trunk/netui/src/util/org/apache/beehive/netui/util/config/internal/catalog/catalog-config.xsd (original)
+++ beehive/trunk/netui/src/util/org/apache/beehive/netui/util/config/internal/catalog/catalog-config.xsd Fri Mar 17 15:14:03 2006
@@ -17,8 +17,8 @@
   $Header:$
 -->
 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
-            targetNamespace="http://beehive.apache.org/netui/2004/server/config"
-            xmlns:netui="http://beehive.apache.org/netui/2004/server/config"
+            targetNamespace="http://beehive.apache.org/netui/2006/server/catalog"
+            xmlns:netui="http://beehive.apache.org/netui/2006/server/catalog"
             elementFormDefault="qualified">
 
     <xsd:element name="catalog">

Modified: beehive/trunk/netui/src/webapp-template/default/WEB-INF/beehive-netui-config.xml
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/webapp-template/default/WEB-INF/beehive-netui-config.xml?rev=386762&r1=386761&r2=386762&view=diff
==============================================================================
--- beehive/trunk/netui/src/webapp-template/default/WEB-INF/beehive-netui-config.xml (original)
+++ beehive/trunk/netui/src/webapp-template/default/WEB-INF/beehive-netui-config.xml Fri Mar 17 15:14:03 2006
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
+
 <!--
-   Copyright 2004-2005 The Apache Software Foundation.
+   Copyright 2004-2006 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.
@@ -27,15 +28,15 @@
         </expression-language>
     </expression-languages>
 
-    <request-interceptors>
-        <global>
-            <request-interceptor>
-                <interceptor-class>org.apache.beehive.netui.tags.tree.TreeCRI</interceptor-class>
-            </request-interceptor>
-            <request-interceptor>
-                <interceptor-class>org.apache.beehive.netui.tags.divpanel.DivPanelCRI</interceptor-class>
-            </request-interceptor>
-        </global>
-    </request-interceptors>
+    <catalog>
+        <chain name="xhr-commands">
+            <command>
+                <command-class>org.apache.beehive.netui.tags.tree.TreeCRI</command-class>
+            </command>
+            <command>
+                <command-class>org.apache.beehive.netui.tags.divpanel.DivPanelCRI</command-class>
+            </command>
+        </chain>
+    </catalog>
 
 </netui-config>

Modified: beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/chain/xmls/simple-chain.xml
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/chain/xmls/simple-chain.xml?rev=386762&r1=386761&r2=386762&view=diff
==============================================================================
--- beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/chain/xmls/simple-chain.xml (original)
+++ beehive/trunk/netui/test/src/junitTests/org/apache/beehive/netui/test/core/chain/xmls/simple-chain.xml Fri Mar 17 15:14:03 2006
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
-<catalog xmlns="http://beehive.apache.org/netui/2004/server/config">
+<catalog xmlns="http://beehive.apache.org/netui/2006/server/catalog">
     <chain name="echo-1234">
         <command>
             <id>1</id>

Modified: beehive/trunk/netui/test/webapps/drt/web/WEB-INF/beehive-netui-config.xml
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/test/webapps/drt/web/WEB-INF/beehive-netui-config.xml?rev=386762&r1=386761&r2=386762&view=diff
==============================================================================
--- beehive/trunk/netui/test/webapps/drt/web/WEB-INF/beehive-netui-config.xml (original)
+++ beehive/trunk/netui/test/webapps/drt/web/WEB-INF/beehive-netui-config.xml Fri Mar 17 15:14:03 2006
@@ -182,9 +182,6 @@
        <id-javascript>legacy</id-javascript>
     </jsp-tag-config>
 
-    <iterator-factories>
-    </iterator-factories>
-
     <request-interceptors>
         <global>
             <request-interceptor>
@@ -195,5 +192,18 @@
             </request-interceptor>
         </global>
     </request-interceptors>
+
+<!--
+    <catalog>
+        <chain name="xhr-commands">
+            <command>
+                <command-class>org.apache.beehive.netui.tags.tree.TreeCRI</command-class>
+            </command>
+            <command>
+                <command-class>org.apache.beehive.netui.tags.divpanel.DivPanelCRI</command-class>
+            </command>
+        </chain>
+    </catalog>
+-->
 
 </netui-config>