cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From coli...@apache.org
Subject cvs commit: cocoon-2.1/src/scratchpad/webapp/samples/petstore/flow PetStoreImpl.js petstore.js
Date Sun, 06 Jul 2003 23:27:25 GMT
coliver     2003/07/06 16:27:25

  Modified:    src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom
                        FOM_Cocoon.java FOM_JavaScriptFlowHelper.java
                        FOM_JavaScriptInterpreter.java fom_system.js
               src/scratchpad/src/org/apache/cocoon/generation
                        GarbageGenerator.java JXTemplateGenerator.java
               src/scratchpad/webapp/samples/garbage/calc sitemap.xmap
               src/scratchpad/webapp/samples/jxforms sitemap.xmap
               src/scratchpad/webapp/samples/jxforms/flow feedbackWizard.js
               src/scratchpad/webapp/samples/petstore sitemap.xmap
               src/scratchpad/webapp/samples/petstore/flow PetStoreImpl.js
                        petstore.js
  Added:       src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom
                        FOM_JavaScript.xconf
               src/scratchpad/src/org/apache/cocoon/components/jxforms/flow/javascript
                        JXForm.java JXForm.js
               src/scratchpad/webapp/samples/garbage samples.xml
  Removed:     src/scratchpad/src/org/apache/cocoon/components/jxforms/flow
                        jxForm.js
  Log:
  Implemented FOM WebContinuation and modified JXForms and all scratchpad samples to use FOM flowscript interpreter
  
  Revision  Changes    Path
  1.10      +121 -7    cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
  
  Index: FOM_Cocoon.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- FOM_Cocoon.java	6 Jul 2003 07:09:18 -0000	1.9
  +++ FOM_Cocoon.java	6 Jul 2003 23:27:24 -0000	1.10
  @@ -55,6 +55,7 @@
   import java.util.List;
   import java.util.LinkedList;
   import java.util.Enumeration;
  +import java.util.Iterator;
   
   import org.apache.avalon.framework.component.Component;
   import org.apache.avalon.framework.component.ComponentException;
  @@ -74,6 +75,7 @@
   import org.mozilla.javascript.ScriptableObject;
   import org.mozilla.javascript.Undefined;
   import org.mozilla.javascript.Wrapper;
  +import org.mozilla.javascript.NativeArray;
   import org.mozilla.javascript.continuations.Continuation;
   import org.apache.avalon.framework.logger.Logger;
   
  @@ -115,6 +117,7 @@
           defineClass(scope, FOM_Session.class);
           defineClass(scope, FOM_Context.class);
           defineClass(scope, FOM_Log.class);
  +        defineClass(scope, FOM_WebContinuation.class);
       }
   
       public void setup(FOM_JavaScriptInterpreter interp,
  @@ -140,8 +143,8 @@
       }
   
   
  -    private void forwardTo(String uri, Object bizData,
  -                           Continuation continuation) 
  +    private FOM_WebContinuation forwardTo(String uri, Object bizData,
  +                                          Continuation continuation) 
           throws Exception {
           WebContinuation wk = null;
           if (continuation != null) {
  @@ -161,13 +164,22 @@
           
           interpreter.forwardTo(getParentScope(), this, redUri,
                                 bizData, wk, environment);
  +
  +        FOM_WebContinuation result = null;
  +        if (wk != null) {
  +            result = new FOM_WebContinuation(wk);
  +            result.setParentScope(getParentScope());
  +            result.setPrototype(getClassPrototype(getParentScope(),
  +                                                  result.getClassName()));
  +        }
  +        return result;
       }
   
  -    public void jsFunction_sendPage(String uri, 
  -                                    Object obj, 
  -                                    Object continuation) 
  +    public FOM_WebContinuation jsFunction_sendPage(String uri, 
  +                                                   Object obj, 
  +                                                   Object continuation) 
           throws Exception {
  -        forwardTo(uri, obj, (Continuation)unwrap(continuation)); 
  +        return forwardTo(uri, obj, (Continuation)unwrap(continuation)); 
       }
                                       
   
  @@ -669,6 +681,70 @@
           }
       }
   
  +    public static class FOM_WebContinuation extends ScriptableObject {
  +        
  +        WebContinuation wk;
  +
  +        public FOM_WebContinuation() {
  +        }
  +
  +        public FOM_WebContinuation(Object wk) {
  +            this.wk = (WebContinuation)unwrap(wk);
  +        }
  +
  +        public String getClassName() {
  +            return "FOM_WebContinuation";
  +        }
  +
  +        public String jsGet_id() {
  +            return wk.getId();
  +        }
  +
  +        public FOM_WebContinuation jsFunction_getParent() {
  +            WebContinuation parent = wk.getParentContinuation();
  +            if (parent == null) return null;
  +            FOM_WebContinuation pwk = new FOM_WebContinuation(parent);
  +            pwk.setParentScope(getParentScope());
  +            pwk.setPrototype(getClassPrototype(getParentScope(), 
  +                                               pwk.getClassName()));
  +            return pwk;
  +        }
  +
  +        public NativeArray jsFunction_getChildren() throws Exception {
  +            List list = wk.getChildren();
  +            NativeArray arr = 
  +                (NativeArray)org.mozilla.javascript.Context.getCurrentContext().newObject(getParentScope(), 
  +                                               "Array",
  +                                               new Object[]{new Integer(list.size())});
  +            Iterator iter = list.iterator();
  +            for (int i = 0; iter.hasNext(); i++) {
  +                WebContinuation child = (WebContinuation)iter.next();
  +                FOM_WebContinuation cwk = new FOM_WebContinuation(child);
  +                cwk.setParentScope(getParentScope());
  +                cwk.setPrototype(getClassPrototype(getParentScope(), 
  +                                                   cwk.getClassName()));
  +                arr.put(i, arr, cwk);
  +            }
  +            return arr;
  +        }
  +
  +        public void jsFunction_invalidate() throws Exception {
  +            ContinuationsManager contMgr = null;
  +            FOM_Cocoon cocoon = 
  +                (FOM_Cocoon)getProperty(getTopLevelScope(this),
  +                                        "cocoon");
  +            ComponentManager componentManager = 
  +                cocoon.getComponentManager();
  +            contMgr = (ContinuationsManager)
  +                componentManager.lookup(ContinuationsManager.ROLE);
  +            contMgr.invalidateWebContinuation(wk);
  +        }
  +
  +        public WebContinuation getWebContinuation() {
  +            return wk;
  +        }
  +    }
  +
       public FOM_Request jsGet_request() {
           if (request != null) {
               return request;
  @@ -748,4 +824,42 @@
           return obj;
       }
   
  +    // Make everything available to JavaScript objects implemented in Java:
  +
  +    public Request getRequest() {
  +        return jsGet_request().request;
  +    }
  +
  +    public Session getSession() {
  +        return jsGet_session().session;
  +    }
  +
  +    public Response getResponse() {
  +        return jsGet_response().response;
  +    }
  +
  +    public org.apache.cocoon.environment.Context getContext() {
  +        return jsGet_context().context;
  +    }
  +
  +    public Environment getEnvironment() {
  +        return environment;
  +    }
  +
  +    public ComponentManager getComponentManager() {
  +        return componentManager;
  +    }
  +
  +    public FOM_JavaScriptInterpreter getInterpreter() {
  +        return interpreter;
  +    }
  +
  +    public FOM_WebContinuation makeWebContinuation(WebContinuation wk) {
  +        if (wk == null) return null;
  +        FOM_WebContinuation result = new FOM_WebContinuation(wk);
  +        result.setParentScope(getParentScope());
  +        result.setPrototype(getClassPrototype(getParentScope(), 
  +                                              result.getClassName()));
  +        return result;
  +    }
   }
  
  
  
  1.3       +21 -8     cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptFlowHelper.java
  
  Index: FOM_JavaScriptFlowHelper.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptFlowHelper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FOM_JavaScriptFlowHelper.java	24 Jun 2003 16:59:20 -0000	1.2
  +++ FOM_JavaScriptFlowHelper.java	6 Jul 2003 23:27:24 -0000	1.3
  @@ -77,6 +77,8 @@
           "cocoon.flow.js.fom.FOM_Session";
       public static final String FOM_CONTEXT = 
           "cocoon.flow.js.fom.FOM_Context";
  +    public static final String FOM_WEB_CONTINUATION = 
  +        "cocoon.flow.js.fom.FOM_WebContinuation";
   
       /** 
        * Return the JS "Packages" property (that gives access to Java
  @@ -118,44 +120,55 @@
           request.setAttribute(JAVA_PACKAGE_OBJECT, javaPkg);
       }
   
  -    public static Scriptable getRequest(Map objectModel) {
  +    public static Scriptable getFOM_Request(Map objectModel) {
           Request request = ObjectModelHelper.getRequest(objectModel);
           return (Scriptable)request.getAttribute(FOM_REQUEST);
       }
   
  -    public static void setRequest(Map objectModel, Scriptable fom_request) {
  +    public static void setFOM_Request(Map objectModel, Scriptable fom_request) {
           Request request = ObjectModelHelper.getRequest(objectModel);
           request.setAttribute(FOM_REQUEST, fom_request);
       }
   
  -    public static Scriptable getResponse(Map objectModel) {
  +    public static Scriptable getFOM_Response(Map objectModel) {
           Request request = ObjectModelHelper.getRequest(objectModel);
           return (Scriptable)request.getAttribute(FOM_RESPONSE);
       }
   
  -    public static void setResponse(Map objectModel, Scriptable fom_response) {
  +    public static void setFOM_Response(Map objectModel, Scriptable fom_response) {
           Request request = ObjectModelHelper.getRequest(objectModel);
           request.setAttribute(FOM_RESPONSE, fom_response);
       }
   
  -    public static Scriptable getSession(Map objectModel) {
  +    public static Scriptable getFOM_Session(Map objectModel) {
           Request request = ObjectModelHelper.getRequest(objectModel);
           return (Scriptable)request.getAttribute(FOM_SESSION);
       }
   
  -    public static void setSession(Map objectModel, Scriptable fom_session) {
  +    public static void setFOM_Session(Map objectModel, Scriptable fom_session) {
           Request request = ObjectModelHelper.getRequest(objectModel);
           request.setAttribute(FOM_SESSION, fom_session);
       }
   
  -    public static Scriptable getContext(Map objectModel) {
  +    public static Scriptable getFOM_Context(Map objectModel) {
           Request request = ObjectModelHelper.getRequest(objectModel);
           return (Scriptable)request.getAttribute(FOM_CONTEXT);
       }
   
  -    public static void setContext(Map objectModel, Scriptable fom_context) {
  +    public static void setFOM_Context(Map objectModel, Scriptable fom_context) {
           Request request = ObjectModelHelper.getRequest(objectModel);
           request.setAttribute(FOM_CONTEXT, fom_context);
  +    }
  +
  +    public static Scriptable getFOM_WebContinuation(Map objectModel) {
  +        Request request = ObjectModelHelper.getRequest(objectModel);
  +        return (Scriptable)request.getAttribute(FOM_WEB_CONTINUATION);
  +    }
  +
  +    public static void setFOM_WebContinuation(Map objectModel, 
  +                                              Scriptable fom_webContinuation) {
  +        Request request = ObjectModelHelper.getRequest(objectModel);
  +        request.setAttribute(FOM_WEB_CONTINUATION, fom_webContinuation);
       }
   }
   
  
  
  
  1.7       +25 -16    cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java
  
  Index: FOM_JavaScriptInterpreter.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptInterpreter.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FOM_JavaScriptInterpreter.java	6 Jul 2003 07:09:19 -0000	1.6
  +++ FOM_JavaScriptInterpreter.java	6 Jul 2003 23:27:24 -0000	1.7
  @@ -85,6 +85,7 @@
   import org.mozilla.javascript.continuations.Continuation;
   import org.mozilla.javascript.tools.ToolErrorReporter;
   import org.mozilla.javascript.tools.shell.Global;
  +import org.apache.cocoon.components.flow.javascript.fom.FOM_Cocoon.FOM_WebContinuation;
   /**
    * Interface with the JavaScript interpreter.
    *
  @@ -581,9 +582,12 @@
               //}
               //}
               //cocoon.setParameters(parameters);
  -            Object[] args = new Object[] {k};
  +            Object[] args = new Object[] {k, 
  +                                          cocoon.makeWebContinuation(wk)};
               try {
  -                ScriptableObject.callMethod(cocoon, "handleContinuation", args);
  +                ScriptableObject.callMethod(cocoon, 
  +                                            "handleContinuation", 
  +                                            args);
               } catch (JavaScriptException ex) {
                   EvaluatorException ee =
                       Context.reportRuntimeError(ToolErrorReporter.getMessage("msg.uncaughtJSException",
  @@ -624,13 +628,13 @@
           return e;
       }
   
  -    // package access as this is called by FOM_Cocoon
  -    void forwardTo(Scriptable scope, FOM_Cocoon cocoon,
  -                           String uri, Object bizData,
  -                           WebContinuation continuation,
  -                           Environment environment)
  +    public void forwardTo(Scriptable scope, FOM_Cocoon cocoon,
  +                          String uri, Object bizData,
  +                          WebContinuation continuation,
  +                          Environment environment)
           throws Exception {
  -        setupView(scope, cocoon ,environment);
  +        setupView(scope, cocoon , environment, 
  +                  cocoon.makeWebContinuation(continuation));
           super.forwardTo(uri, bizData, continuation, environment);
       }
   
  @@ -639,13 +643,14 @@
                       String uri, Object bizData, 
                       OutputStream out, Environment environment)
           throws Exception {
  -        setupView(scope, cocoon, environment);
  +        setupView(scope, cocoon, environment, null);
           return super.process(uri, bizData, out, environment);
       }
       
       private void setupView(Scriptable scope,
                              FOM_Cocoon cocoon,
  -                           Environment environment) {
  +                           Environment environment,
  +                           FOM_WebContinuation kont) {
           Map objectModel = environment.getObjectModel();
           // Make the JS live-connect objects available to the view layer
           FOM_JavaScriptFlowHelper.setPackages(objectModel,
  @@ -655,13 +660,17 @@
                                                   (Scriptable)ScriptableObject.getProperty(scope,
                                                                                            "java"));
           // Make the FOM objects available to the view layer
  -        FOM_JavaScriptFlowHelper.setRequest(objectModel,
  +        FOM_JavaScriptFlowHelper.setFOM_Request(objectModel,
                                               cocoon.jsGet_request());
  -        FOM_JavaScriptFlowHelper.setResponse(objectModel,
  +        FOM_JavaScriptFlowHelper.setFOM_Response(objectModel,
                                                cocoon.jsGet_response());
  -        FOM_JavaScriptFlowHelper.setSession(objectModel,
  +        FOM_JavaScriptFlowHelper.setFOM_Session(objectModel,
                                               cocoon.jsGet_session());
  -        FOM_JavaScriptFlowHelper.setContext(objectModel,
  -                                            cocoon.jsGet_context());
  +        FOM_JavaScriptFlowHelper.setFOM_Context(objectModel,
  +                                                cocoon.jsGet_context());
  +        if (kont != null) {
  +            FOM_JavaScriptFlowHelper.setFOM_WebContinuation(objectModel, 
  +                                                            kont);
  +        }
       }
   }
  
  
  
  1.2       +2 -2      cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom/fom_system.js
  
  Index: fom_system.js
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom/fom_system.js,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- fom_system.js	20 Jun 2003 08:28:20 -0000	1.1
  +++ fom_system.js	6 Jul 2003 23:27:24 -0000	1.2
  @@ -5,6 +5,6 @@
       FOM_Cocoon.suicide();
   }
   
  -FOM_Cocoon.prototype.handleContinuation = function(k) {
  -    k(k);
  +FOM_Cocoon.prototype.handleContinuation = function(k, wk) {
  +    k(wk);
   }
  
  
  
  1.1                  cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScript.xconf
  
  Index: FOM_JavaScript.xconf
  ===================================================================
  <?xml version="1.0"?>
  <xconf xpath="/cocoon/flow-interpreters" unless="component-instance[@class='org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptInterpreter']">
      <component-instance name="FOM_JavaScript" class="org.apache.cocoon.components.flow.javascript.fom.FOM_JavaScriptInterpreter">
        <load-on-startup>resource://org/apache/cocoon/components/flow/javascript/fom/fom_system.js</load-on-startup>
        <reload-scripts>true</reload-scripts>
        <check-time>4000</check-time>
        <!--debugger>enabled</debugger-->  <!-- JavaScript Debugger support -->
      </component-instance>
  </xconf>
  
  
  
  1.1                  cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/jxforms/flow/javascript/JXForm.java
  
  Index: JXForm.java
  ===================================================================
  /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.jxforms.flow.javascript;
  import org.apache.cocoon.components.jxforms.validation.*;
  import org.apache.cocoon.components.jxforms.xmlform.*;
  import org.mozilla.javascript.*;
  import org.apache.cocoon.components.flow.javascript.fom.FOM_Cocoon;
  import org.apache.cocoon.components.flow.ContinuationsManager;
  import org.apache.cocoon.components.flow.WebContinuation;
  import org.apache.cocoon.components.flow.javascript.fom.FOM_Cocoon.FOM_WebContinuation;
  import org.apache.commons.jxpath.JXPathContext;
  import org.apache.cocoon.environment.SourceResolver;
  import org.apache.cocoon.components.source.SourceUtil;
  import org.apache.excalibur.source.Source;
  import org.xml.sax.InputSource;
  import java.util.Set;
  import java.util.List;
  import java.util.LinkedList;
  
  public class JXForm extends ScriptableObject {
  
      FOM_Cocoon cocoon;
      Object model;
      Form form;
      JXPathContext context;
      String id;
      String validatorNamespace;
      String validatorDocument;
      String scope;
      String submitId;
  
      private FOM_Cocoon getCocoon() {
          if (cocoon == null) {
              cocoon = (FOM_Cocoon)getProperty(getTopLevelScope(this), "cocoon");
          }
          return cocoon;
      }
  
      public JXForm() {
      }
  
      public static Scriptable jsConstructor(Context cx, Object[] args,
                                             Function ctorObj, 
                                             boolean inNewExpr)
          throws Exception {
          String id;
          String validatorNS;
          String validatorDoc;
          String scope;
          id = org.mozilla.javascript.Context.toString(args[0]);
          validatorNS = args[1] == null ? null : org.mozilla.javascript.Context.toString(args[1]);
          validatorDoc = args[2] == null ? null : org.mozilla.javascript.Context.toString(args[2]);
          scope = org.mozilla.javascript.Context.toString(args[3]);
          JXForm result = new JXForm();
          result.id = id;
          result.validatorNamespace = validatorNS;
          result.validatorDocument = validatorDoc;
          result.scope = scope;
          return result;
      }
  
      public String getClassName() {
          return "JXForm";
      }
  
      public Object jsFunction_getModel() {
          return model;
      }
  
      public void jsFunction_setModel(Object obj) throws Exception {
          model = unwrap(obj);
          form = new Form(id, model);
          context = JXPathContext.newContext(model);
          form.setAutoValidate(false);
          if (validatorNamespace != null && validatorDocument != null) {
              System.out.println("validatorNS="+validatorNamespace);
              System.out.println("validatorDoc="+validatorDocument);
              SourceResolver resolver = 
                  getCocoon().getEnvironment();
              Source schemaSrc = resolver.resolveURI(validatorDocument);
              InputSource is = SourceUtil.getInputSource(schemaSrc);
              SchemaFactory schf = SchemaFactory.lookup(validatorNamespace);
              Schema sch = schf.compileSchema(is);
              form.setValidator(sch.newValidator());
          }
      }
  
      public String jsFunction_getSubmitId() {
          return submitId;
      }
  
      public void jsSet_submitId(String value) {
          submitId = value;
      }
  
      public String jsGet_submitId() {
          return submitId;
      }
  
      public void jsFunction_forwardTo(String uri,
                                       Object bizData,
                                       Object continuation) 
          throws Exception {
          FOM_Cocoon cocoon = getCocoon();
          FOM_WebContinuation fom_wk = 
              (FOM_WebContinuation)unwrap(continuation);
          String redUri = "cocoon://" + 
              cocoon.getEnvironment().getURIPrefix() + uri;
           cocoon.getInterpreter().forwardTo(getTopLevelScope(cocoon),
                                             cocoon,
                                             redUri, 
                                             unwrap(bizData),
                                             fom_wk.getWebContinuation(),
                                             cocoon.getEnvironment());
      }
  
      public void jsFunction_addViolation(String xpath, String message) 
          throws Exception {
          Violation violation = new Violation();
          violation.setPath(xpath);
          violation.setMessage(message);
          List list = new LinkedList();
          list.add(violation);
          form.addViolations(list);
      }
  
      public boolean jsFunction_hasViolations() {
          Set set = form.getViolationsAsSortedSet();
          return set != null && set.size() > 0;
      }
  
      public Object jsFunction_getValue(String expr) {
          return context.getValue(expr);
      }
  
      public static void jsStaticFunction_handleContinuation(String kontId,
                                                             Object cocoon_) 
          throws Exception {
          FOM_Cocoon cocoon = (FOM_Cocoon)unwrap(cocoon_);
          cocoon.getInterpreter().handleContinuation(kontId, null, 
                                                     cocoon.getEnvironment());
      }
  
      public Object jsFunction_iterate(String expr) {
          return context.iterate(expr);
      }
  
      public FOM_WebContinuation jsFunction_makeWebContinuation(Object k, 
                                                                Object lastContinuation,
                                                                int ttl) 
          throws Exception {
          FOM_Cocoon cocoon = getCocoon();
          WebContinuation wk;
          ContinuationsManager contMgr;
          contMgr = (ContinuationsManager)
              cocoon.getComponentManager().lookup(ContinuationsManager.ROLE);
          FOM_WebContinuation fom_wk = 
              (FOM_WebContinuation)unwrap(lastContinuation);
          wk = contMgr.createWebContinuation(unwrap(k),
                                             (WebContinuation)(fom_wk == null ? null : fom_wk.getWebContinuation()),
                                             ttl);
          return cocoon.makeWebContinuation(wk);
      }
  
      // unwrap Wrapper's and convert undefined to null
      private static Object unwrap(Object obj) {
          if (obj instanceof Wrapper) {
              obj = ((Wrapper)obj).unwrap();
          } else if (obj == Undefined.instance) {
              obj = null;
          }
          return obj;
      }
  
      public void jsFunction_removeForm() {
          FOM_Cocoon cocoon = getCocoon();
          form.remove(cocoon.getEnvironment().getObjectModel(), id);
          cocoon.getRequest().removeAttribute(this.id);
      }
  
      public void jsFunction_saveForm() {
          FOM_Cocoon cocoon = getCocoon();
          form.save(cocoon.getEnvironment().getObjectModel(), "request");
      }
  
      public void jsFunction_populateForm() {
          FOM_Cocoon cocoon = getCocoon();
          form.populate(cocoon.getEnvironment().getObjectModel());
      }
  
      public void jsFunction_validateForm(String view) {
          form.validate(view);
      }
  
      public void jsFunction_clearFormViolations() {
          form.clearViolations();
      }
  
  }
  
  
  
  1.1                  cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/jxforms/flow/javascript/JXForm.js
  
  Index: JXForm.js
  ===================================================================
  /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      apache@apache.org.
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <stefano@apache.org>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  defineClass("org.apache.cocoon.components.jxforms.flow.javascript.JXForm");
  //
  // JXForms support
  //
  
  JXForm.suicide = new Continuation();
  
  /**
   * Creates a new web continuation
   * @param lastWebCont [WebContinuation] previous web continuation
   * @param timeToLive [Number] expiration time for this continuation in milliseconds
   * @return [WebContinuation] a new WebContinuation instance
   */
  JXForm.prototype.start = function(lastWebCont, timeToLive) {
      var result = this._start(lastWebCont, timeToLive);
      // 
      // _start() will return an Object when it's called
      // the first time. However, when its Continuation is invoked it
      // will return a WebContinuation instead. In the latter case
      // we're going back to the previous page: so 
      // clear the current page's violations before showing the previous page.
      // Without this, violations from the current page will
      // incorrectly be displayed on the previous page.
      if (result instanceof FOM_WebContinuation) {
          this.clearFormViolations();
          return result;
      }
      return result.kont;
  } 
  
  JXForm.prototype._start = function(lastWebCont, timeToLive) {
      var k = new Continuation();
      var kont = this.makeWebContinuation(k, lastWebCont, timeToLive);
      if (this.rootContinuation == null) {
          this.rootContinuation = kont;
      }
      return {kont: kont};
  } 
  
  
  JXForm.prototype._sendView = function(uri, lastWebCont, timeToLive) {
      var k = new Continuation();
      var wk = this.makeWebContinuation(k, lastWebCont, timeToLive);
      var bizData = this.getModel();
      if (bizData == undefined) {
          bizData = null;
      }
      this.lastWebContinuation = wk;
      this.forwardTo(uri, bizData, wk);
      JXForm.suicide();
  }
  
  /**
   * Sends view to presentation pipeline and waits for subsequent submission.
   * Automatically resends view if validation fails.
   * Creates two continuations: one immediately before the page is sent 
   * and one immediately after. These are used to implement automated support
   * for back/forward navigation in the form. When you move forward in the
   * form the second continuation is invoked. When you move back from the
   * following page the first continuation is invoked.
   * @param uri [String] presentation pipeline resource identifier of "view"
   * @param validator [Function] optional function invoked to perform validation
   */
  JXForm.prototype.sendView = function(uri, validator) {
      var lastWebCont = this.lastWebContinuation;
      // create a continuation, the invocation of which will resend
      // the page: this is used to implement <xf:submit continuation="back">
      var wk = this.start(lastWebCont);
      while (true) {
          this.removeForm();
          this.saveForm();
          var thisWebCont = this._sendView(uri, wk);
          // _sendView creates a continuation, the invocation of which
          // will return right here: it is used to implement 
          // <xf:submit continuation="forward">
          this.populateForm();
  	var phase = cocoon.request.getAttribute("jxform-submit-phase");
          if (validator != undefined) {
              validator(this);
          }
          this.validateForm(phase);
          if (!this.hasViolations()) {
              this.lastWebContinuation = thisWebCont;
              break;
          }
      }
  }
  
  
  JXForm.prototype.finish = function(uri) {
      if (uri != undefined) {
          this.form.remove(cocoon.environment.objectModel, this.id);
          this.form.save(cocoon.environment.objectModel, "request");
          this.forwardTo(uri,
                         this.getModel(), 
                         null);
      }
      if (this.rootContinuation != null) {
          this.rootContinuation.invalidate();
          this.rootContinuation = null;
          this.lastWebContinuation = null;
      }
  }
  
  /**
   * Entry point to a flow-based JXForm application. 
   * @param application [String] Name of a JavaScript function that represents the page flow for a form
   * @param id [String] Form id
   * @param validator_ns [String] XML namespace of validator
   * @param validator_doc [String] Validator document
   * @param scope [String] one of "request" or "session"
   */
  
  function jxForm(application, id, validator_ns, validator_doc, scope) {
      function getCommand() {
          var enum_ = cocoon.request.getParameterNames();
          var command = undefined;
          while (enum_.hasMoreElements()) {
              var paramName = enum_.nextElement();
              // search for the command
              if (paramName.startsWith(Packages.org.apache.cocoon.Constants.ACTION_PARAM_PREFIX)) {
                  command =
                      paramName.substring(Packages.org.apache.cocoon.Constants.ACTION_PARAM_PREFIX.length(), paramName.length());
                  break;
              }
          }
          // command encodes the continuation id for "back" or "next" actions
          return command;
      }
      var command = getCommand();
      if (command != undefined) {
          // invoke a continuation 
          // command looks like kontId:phase:id
          var kontId = command;
          var izer = new java.util.StringTokenizer(command, ":");
          if (izer.countTokens() == 3) {
              kontId = izer.nextToken();
              var phase = izer.nextToken();
              var id = izer.nextToken();
              cocoon.request.setAttribute("jxform-submit-phase", phase);
              cocoon.request.setAttribute("jxform-submit-id", id);
          }
          JXForm.handleContinuation(kontId, cocoon);
          return;
      } 
      // Just start a new instance of the application
      var args = new Array(arguments.length - 5 + 1);
      args[0] = new JXForm(id, validator_ns, validator_doc, scope);
      for (var i = 5; i < arguments.length; i++) {
        args[i-4] = arguments[i];
      }
      this[application].apply(this, args);
  }
  
  
  
  1.4       +11 -11    cocoon-2.1/src/scratchpad/src/org/apache/cocoon/generation/GarbageGenerator.java
  
  Index: GarbageGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/src/org/apache/cocoon/generation/GarbageGenerator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- GarbageGenerator.java	24 Jun 2003 16:59:24 -0000	1.3
  +++ GarbageGenerator.java	6 Jul 2003 23:27:24 -0000	1.4
  @@ -120,22 +120,22 @@
               }
           }
           Object bean = FlowHelper.getContextObject(objectModel);
  -        WebContinuation kont = FlowHelper.getWebContinuation(objectModel);
  +        Object kont = FOM_JavaScriptFlowHelper.getFOM_WebContinuation(objectModel);
           setContext(bean, kont,
  -                   FOM_JavaScriptFlowHelper.getRequest(objectModel),
  -                   FOM_JavaScriptFlowHelper.getResponse(objectModel),
  -                   FOM_JavaScriptFlowHelper.getSession(objectModel),
  -                   FOM_JavaScriptFlowHelper.getContext(objectModel),
  +                   FOM_JavaScriptFlowHelper.getFOM_Request(objectModel),
  +                   FOM_JavaScriptFlowHelper.getFOM_Response(objectModel),
  +                   FOM_JavaScriptFlowHelper.getFOM_Session(objectModel),
  +                   FOM_JavaScriptFlowHelper.getFOM_Context(objectModel),
                      parameters);
       }
       
       protected void setContext(Object contextObject,
  -                            WebContinuation kont,
  -                            Object request,
  -                            Object response,
  -                            Object session,
  -                            Object context,
  -                            Parameters parameters) {
  +			      Object kont,
  +			      Object request,
  +			      Object response,
  +			      Object session,
  +			      Object context,
  +			      Parameters parameters) {
           jxpathContext = JXPathContext.newContext(contextObject);
           Variables varScope = jxpathContext.getVariables();
           varScope.declareVariable("flowContext", contextObject);
  
  
  
  1.13      +9 -6      cocoon-2.1/src/scratchpad/src/org/apache/cocoon/generation/JXTemplateGenerator.java
  
  Index: JXTemplateGenerator.java
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/src/org/apache/cocoon/generation/JXTemplateGenerator.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- JXTemplateGenerator.java	18 May 2003 16:36:41 -0000	1.12
  +++ JXTemplateGenerator.java	6 Jul 2003 23:27:24 -0000	1.13
  @@ -2432,20 +2432,23 @@
                   }
                   for (; i <= end && iter.hasNext(); i++) {
                       Object value;
  -                    if (xpath) {
  -                        Pointer ptr = (Pointer)iter.next();
  +                    JXPathContext localJXPathContext = null;
  +                    value = iter.next();
  +                    if (value instanceof Pointer) {
  +                        Pointer ptr = (Pointer)value;
  +                        localJXPathContext = 
  +                            jxpathContext.getRelativeContext(ptr);
                           try {
                               value = ptr.getNode();
                           } catch (Exception exc) {
                               throw new SAXParseException(exc.getMessage(),
                                                           ev.location,
  -                                                        exc);
  +                                                        null);
                           }
                       } else {
  -                        value = iter.next();
  +                        localJXPathContext =
  +                            jxpathContextFactory.newContext(null, value);
                       }
  -                    JXPathContext localJXPathContext = 
  -                        jxpathContextFactory.newContext(null, value);
                       localJXPathContext.setVariables(variables);
                       if (startForEach.var != null) {
                           localJexlContext.put(startForEach.var, value);
  
  
  
  1.1                  cocoon-2.1/src/scratchpad/webapp/samples/garbage/samples.xml
  
  Index: samples.xml
  ===================================================================
  <?xml version="1.0" encoding="iso-8859-1"?>
  
  <!-- CVS $Id: samples.xml,v 1.1 2003/07/06 23:27:25 coliver Exp $ -->
  
  <samples>
  
    <group name="Back">
     <sample name="Back" href="../">
     Back to the samples home page.
     </sample>
    </group>
  
    <group name="Flowscript">
      <sample name="Calculator" href="calc/">
      A simple web-based calculator that uses javascript on the server side
      to describe the web application flow between screens in a coherent 
      unique location and continuations to maintain state between requests.
     </sample>
    </group>
    
  </samples>
  
  
  
  1.2       +1 -1      cocoon-2.1/src/scratchpad/webapp/samples/garbage/calc/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/garbage/calc/sitemap.xmap,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- sitemap.xmap	22 Jun 2003 18:48:20 -0000	1.1
  +++ sitemap.xmap	6 Jul 2003 23:27:25 -0000	1.2
  @@ -24,7 +24,7 @@
             <map:parameter name="servletPath" value="{request:servletPath}"/>
             <map:parameter name="sitemapURI" value="{request:sitemapURI}"/>
             <map:parameter name="contextPath" value="{request:contextPath}"/>
  -          <map:parameter name="file" value="/samples/flow/calc/screens/{1}.gt"/>
  +          <map:parameter name="file" value="/samples/garbage/calc/screens/{1}.gt"/>
             <map:parameter name="remove" value="{0}"/>
           </map:transform>
           <map:serialize/>
  
  
  
  1.3       +2 -2      cocoon-2.1/src/scratchpad/webapp/samples/jxforms/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/jxforms/sitemap.xmap,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- sitemap.xmap	28 Apr 2003 05:37:05 -0000	1.2
  +++ sitemap.xmap	6 Jul 2003 23:27:25 -0000	1.3
  @@ -6,7 +6,7 @@
       <map:generators default="file">
         <map:generator name="jxforms" src="org.apache.cocoon.generation.JXFormsGenerator" logger="jxforms.sitemap.generator"/>
       </map:generators>
  -    <map:flow-interpreters default="JavaScript"/>
  +    <map:flow-interpreters default="FOM_JavaScript"/>
       <map:serializers default="html"/>
       <map:matchers default="wildcard"/>
     </map:components>
  @@ -38,7 +38,7 @@
     </map:resources>
   
     <!-- =========================== Pipelines ================================= -->
  -  <map:flow language="JavaScript">
  +  <map:flow language="FOM_JavaScript">
        <map:script src="flow/feedbackWizard.js"/>
     </map:flow>
   
  
  
  
  1.3       +16 -16    cocoon-2.1/src/scratchpad/webapp/samples/jxforms/flow/feedbackWizard.js
  
  Index: feedbackWizard.js
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/jxforms/flow/feedbackWizard.js,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- feedbackWizard.js	27 Apr 2003 22:13:36 -0000	1.2
  +++ feedbackWizard.js	6 Jul 2003 23:27:25 -0000	1.3
  @@ -1,6 +1,6 @@
   // Feedback Wizard Sample
   
  -cocoon.load("resource://org/apache/cocoon/components/jxforms/flow/jxForm.js");
  +cocoon.load("resource://org/apache/cocoon/components/jxforms/flow/javascript/JXForm.js");
   
   function feedbackWizard(form) {
       var bean = {
  @@ -70,33 +70,33 @@
       form.setModel(bean);
   
       form.sendView("view/userIdentity.xml",
  -		  function(form) {
  -	var bean = form.getModel();
  -	print("I can also do validation in JavaScript");
  -	print("age = "+form.getValue("number(/age)"));
  -	print("role = "+bean.role);
  -	if (bean.age > 40) {
  -	    form.addViolation("/age", "Hey, you're too old");
  -	}
  +                  function(form) {
  +        var bean = form.getModel();
  +        cocoon.log.info("I can also do validation in JavaScript");
  +        cocoon.log.info("age = "+form.getValue("number(/age)"));
  +        cocoon.log.info("role = "+bean.role);
  +        if (bean.age > 40) {
  +            form.addViolation("/age", "Hey, you're too old");
  +        }
       });
  -    print("handling user identity");
  +    cocoon.log.info("handling user identity");
   
       form.sendView("view/deployment.xml", 
  -		  function(form) {
  +                  function(form) {
           var bean = form.getModel();
  -        print("I can also do validation in JavaScript");
  +        cocoon.log.info("I can also do validation in JavaScript");
           if (bean.publish) {
               form.addViolation("/publish", "Sorry, I won't let you publish");
           }
       });
  -    print("handling deployment");
  +    cocoon.log.info("handling deployment");
   
       form.sendView("view/system.xml");
  -    print("handling system");
  +    cocoon.log.info("handling system");
   
       form.sendView("view/confirm.xml");
  -    print("handling confirm");
  +    cocoon.log.info("handling confirm");
   
       form.finish("view/end.xml");
  -    print("done");
  +    cocoon.log.info("done");
   }
  
  
  
  1.19      +2 -2      cocoon-2.1/src/scratchpad/webapp/samples/petstore/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/petstore/sitemap.xmap,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- sitemap.xmap	6 May 2003 14:13:02 -0000	1.18
  +++ sitemap.xmap	6 Jul 2003 23:27:25 -0000	1.19
  @@ -12,7 +12,7 @@
           <map:generator label="content,data" logger="sitemap.generator.jx" name="jx" src="org.apache.cocoon.generation.JXTemplateGenerator"/>
         <map:generator name="jxforms" src="org.apache.cocoon.generation.JXFormsGenerator" logger="sitemap.generator.jxforms"/>
       </map:generators>
  -    <map:flow-interpreters default="JavaScript"/>
  +    <map:flow-interpreters default="FOM_JavaScript"/>
       <map:serializers default="html"/>
       <map:matchers default="wildcard"/>
     </map:components>
  @@ -50,7 +50,7 @@
     </map:resources>
   
     <!-- =========================== Pipelines ================================= -->
  -    <map:flow language="JavaScript">
  +    <map:flow language="FOM_JavaScript">
         <map:script src="flow/PetStoreImpl.js"/>
         <map:script src="flow/petstore.js"/>
       </map:flow>
  
  
  
  1.6       +2 -2      cocoon-2.1/src/scratchpad/webapp/samples/petstore/flow/PetStoreImpl.js
  
  Index: PetStoreImpl.js
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/petstore/flow/PetStoreImpl.js,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- PetStoreImpl.js	17 Mar 2003 18:54:04 -0000	1.5
  +++ PetStoreImpl.js	6 Jul 2003 23:27:25 -0000	1.6
  @@ -547,7 +547,7 @@
   PetStore.prototype.getProductRowCountByCategory = function(key) {
       var conn = this.getConnection(this.poolId);
       var rs = conn.query("select count(*) as ROWCOUNT from PRODUCT where CATEGORY = ?",
  -			[key]);
  +                        [key]);
       var result = rs.rows[0].ROWCOUNT;
       conn.close();
       return Number(result);
  @@ -556,7 +556,7 @@
   PetStore.prototype.getItemRowCountByProduct = function(key) {
       var conn = this.getConnection(this.poolId);
       var rs = conn.query("select count(*) as ROWCOUNT from ITEM where PRODUCTID = ?",
  -			[key]);
  +                        [key]);
       var result = rs.rows[0].ROWCOUNT;
       conn.close();
       return Number(result);
  
  
  
  1.14      +24 -22    cocoon-2.1/src/scratchpad/webapp/samples/petstore/flow/petstore.js
  
  Index: petstore.js
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/scratchpad/webapp/samples/petstore/flow/petstore.js,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- petstore.js	30 Apr 2003 20:09:44 -0000	1.13
  +++ petstore.js	6 Jul 2003 23:27:25 -0000	1.14
  @@ -46,8 +46,8 @@
   
   // Page Flow for PetStore Application
   
  -// load JXForm support
  -cocoon.load("resource://org/apache/cocoon/components/jxforms/flow/jxForm.js");
  +// load JXForms support
  +cocoon.load("resource://org/apache/cocoon/components/jxforms/flow/javascript/JXForm.js");
   
   var MAX_RESULTS = 5;
   
  @@ -72,6 +72,9 @@
   var cartForm = null;
   var categoryList = null;
   
  +function print(line) {
  +    cocoon.log.info(line);
  +}
   
   function main(funName) {
       var fun = this[funName];
  @@ -86,7 +89,6 @@
   
   function getPetStore() {
       if (petStore == null) {
  -        cocoon.createSession();
           this.petStore = new PetStore("hsql");
           this.cartForm = new CartForm();
           this.accountForm = new AccountForm();
  @@ -115,7 +117,7 @@
   function index() {
       setView();
       getPetStore();
  -    sendPage("/view/index" + EXT, {
  +    cocoon.sendPage("/view/index" + EXT, {
                view: VIEW,
                accountForm: accountForm,
                categoryList: categoryList,
  @@ -130,7 +132,7 @@
           var cartItem = cartForm.cart.cartItems[i];
           cartItems.push(cartItem);
       }
  -    sendPage("/view/Cart" + EXT, {
  +    cocoon.sendPage("/view/Cart" + EXT, {
                view: VIEW,
                accountForm: accountForm, 
                cartForm: cartForm, 
  @@ -149,7 +151,7 @@
           var cartItem = cartForm.cart.cartItems[i];
           cartItems.push(cartItem);
       }
  -    sendPage("/view/Cart" + EXT, {
  +    cocoon.sendPage("/view/Cart" + EXT, {
                view: VIEW,
                fmt: fmt, 
                accountForm: accountForm, 
  @@ -166,7 +168,7 @@
           cartItem.updateQuantity(quantity);
           cartItems.push(cartItem);
       }
  -    sendPage("/view/Cart" + EXT, {
  +    cocoon.sendPage("/view/Cart" + EXT, {
                view: VIEW,
                fmt: fmt, 
                accountForm: accountForm, 
  @@ -184,7 +186,7 @@
           var cartItem = cartForm.cart.cartItems[i];
           cartItems.push(cartItem);
       }
  -    sendPage("/view/Cart" + EXT, {
  +    cocoon.sendPage("/view/Cart" + EXT, {
                view: VIEW,
                fmt: fmt, 
                accountForm: accountForm, 
  @@ -208,7 +210,7 @@
                                                      maxResults);
           var lastPage = !productList.isLimitedByMaxRows;
           var rowCount = productList.rowCount;
  -        sendPageAndWait("/view/Category" + EXT, {
  +        cocoon.sendPageAndWait("/view/Category" + EXT, {
                           accountForm: accountForm, 
                           productList: productList.rows, 
                           category: category, 
  @@ -252,7 +254,7 @@
               getPetStore().getItemListByProduct(productId,
                                                  skipResults, 
                                                  maxResults);
  -        sendPageAndWait("/view/Product" + EXT, {
  +        cocoon.sendPageAndWait("/view/Product" + EXT, {
                           view: VIEW,
                           accountForm: accountForm, 
                           fmt: fmt,
  @@ -279,7 +281,7 @@
   function viewItem() {
       var itemId = cocoon.request.getParameter("itemId");
       var item = getPetStore().getItem(itemId);
  -    sendPage("/view/Item" + EXT, {
  +    cocoon.sendPage("/view/Item" + EXT, {
                view: VIEW,
                accountForm: accountForm, 
                cartForm: cartForm, 
  @@ -305,7 +307,7 @@
       } else {
           var message = "";
           while (true) {
  -            sendPageAndWait("/view/SignonForm" + EXT, {
  +            cocoon.sendPageAndWait("/view/SignonForm" + EXT, {
                               view: VIEW,
                               accountForm: accountForm, 
                               message: message
  @@ -332,7 +334,7 @@
       print("new account");
       var accountForm = new AccountForm();
       var account = new Account();
  -    sendPageAndWait("/view/NewAccountForm" + EXT, {
  +    cocoon.sendPageAndWait("/view/NewAccountForm" + EXT, {
                        view: VIEW,
                        accountForm: accountForm,
                        account: account,
  @@ -389,9 +391,9 @@
               form.addViolation("/userName", "User ID is required");
           } else {
             if (empty(model.password)) {
  -                form.addViolation("/password", "Password is required");
  +              form.addViolation("/password", "Password is required");
             } else if (model.password != model.password2) {
  -            form.addViolation("/password2", "Passwords don't match");
  +              form.addViolation("/password2", "Passwords don't match");
             }
           }
       });
  @@ -423,7 +425,7 @@
   function searchProducts() {
       var keyword = cocoon.request.get("keyword");
       if (empty(keyword)) {
  -        sendPage("/view/Error" + EXT, {
  +        cocoon.sendPage("/view/Error" + EXT, {
              view: VIEW,
              message: "Please enter a keyword to search for, then press the search button"
           });
  @@ -435,7 +437,7 @@
           var result = 
               getPetStore().searchProductList(keyword, skipResults,
                                               maxResults);
  -        sendPageAndWait("/view/SearchProducts" + EXT, {
  +        cocoon.sendPageAndWait("/view/SearchProducts" + EXT, {
                           view: VIEW,
                           searchResultsProductList: result.rows,
                           firstPage: skipResults == 0,
  @@ -462,7 +464,7 @@
           var cartItem = cartForm.cart.cartItems[i];
           cartItems.push(cartItem);
       }
  -    sendPageAndWait("/view/Checkout" + EXT, {
  +    cocoon.sendPageAndWait("/view/Checkout" + EXT, {
                       view: VIEW,
                       accountForm: accountForm,
                       cartForm: cartForm, 
  @@ -477,7 +479,7 @@
       var order = orderForm.order;
       var valid = false;
       while (!valid) {
  -        sendPageAndWait("/view/NewOrderForm" + EXT, { 
  +        cocoon.sendPageAndWait("/view/NewOrderForm" + EXT, { 
                           accountForm: accountForm,
                           view: VIEW,
                           fmt: fmt,
  @@ -485,19 +487,19 @@
                           order: order});
           var shippingAddressRequired = cocoon.request.get("shippingAddressRequired");
           if (shippingAddressRequired) {
  -            sendPageAndWait("/view/ShippingForm" + EXT,
  +            cocoon.sendPageAndWait("/view/ShippingForm" + EXT,
                               {order: order, fmt: fmt, accountForm: accountForm});
           }
           // fix me !! do real validation
           valid = true;
       }
  -    sendPageAndWait("/view/ConfirmOrder" + EXT,
  +    cocoon.sendPageAndWait("/view/ConfirmOrder" + EXT,
                       {accountForm: accountForm,
                        view: VIEW, order: order, fmt: fmt});
       
       var oldCartForm = cartForm;
       cartForm = new CartForm();
  -    sendPage("/view/ViewOrder" + EXT,
  +    cocoon.sendPage("/view/ViewOrder" + EXT,
                {view: VIEW, order: order, 
                 accountForm: accountForm,
                 itemList: order.lineItems, 
  
  
  

Mime
View raw message