You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by co...@apache.org on 2003/06/23 05:37:05 UTC

cvs commit: cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom FOM_JavaScriptFlowHelper.java FOM_Cocoon.java FOM_JavaScriptInterpreter.java

coliver     2003/06/22 20:37:05

  Modified:    src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom
                        FOM_Cocoon.java FOM_JavaScriptInterpreter.java
  Added:       src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom
                        FOM_JavaScriptFlowHelper.java
  Log:
  Make FOM available to view layer through request attributes
  
  Revision  Changes    Path
  1.4       +2 -2      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.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FOM_Cocoon.java	22 Jun 2003 18:12:27 -0000	1.3
  +++ FOM_Cocoon.java	23 Jun 2003 03:37:04 -0000	1.4
  @@ -128,7 +128,7 @@
                                                 lastContinuation,
                                                 0);
           }
  -        interpreter.forwardTo("cocoon://"+
  +        interpreter.forwardTo(getParentScope(), this, "cocoon://"+
                                 environment.getURIPrefix() + uri,
                                 bizData, wk, environment);
       }
  @@ -148,7 +148,7 @@
           if (!(unwrap(outputStream) instanceof OutputStream)) {
               throw new JavaScriptException("expected a java.io.OutputStream instead of " + outputStream);
           }
  -        interpreter.process(uri, map, 
  +        interpreter.process(getParentScope(), this, uri, map, 
                               (OutputStream)unwrap(outputStream), 
                               environment);
       }
  
  
  
  1.3       +35 -10    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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- FOM_JavaScriptInterpreter.java	22 Jun 2003 18:12:27 -0000	1.2
  +++ FOM_JavaScriptInterpreter.java	23 Jun 2003 03:37:04 -0000	1.3
  @@ -49,6 +49,7 @@
   import java.io.InputStream;
   import java.io.InputStreamReader;
   import java.io.Reader;
  +import java.io.OutputStream;
   import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.List;
  @@ -648,18 +649,42 @@
           return e;
       }
   
  -    public void forwardTo(String uri, Object bizData,
  -                          WebContinuation continuation,
  -                          Environment environment)
  +    void forwardTo(Scriptable scope, FOM_Cocoon cocoon,
  +                   String uri, Object bizData,
  +                   WebContinuation continuation,
  +                   Environment environment)
           throws Exception {
  +        setupView(scope, cocoon ,environment);
  +        super.forwardTo(uri, bizData, continuation, environment);
  +    }
  +
  +    boolean process(Scriptable scope, FOM_Cocoon cocoon,
  +                    String uri, Object bizData, 
  +                    OutputStream out, Environment environment)
  +        throws Exception {
  +        setupView(scope, cocoon, environment);
  +        return super.process(uri, bizData, out, environment);
  +    }
  +    
  +    private void setupView(Scriptable scope,
  +                           FOM_Cocoon cocoon,
  +                           Environment environment) {
           Map objectModel = environment.getObjectModel();
  -        // Make the live-connect objects available to the view layer
  -        JavaScriptFlow.setPackages(objectModel,
  +        // Make the JS live-connect objects available to the view layer
  +        FOM_JavaScriptFlowHelper.setPackages(objectModel,
                                      (Scriptable)ScriptableObject.getProperty(scope,
                                                                               "Packages"));
  -        JavaScriptFlow.setJavaPackage(objectModel,
  -                                      (Scriptable)ScriptableObject.getProperty(scope,
  -                                                                   "java"));
  -        super.forwardTo(uri, bizData, continuation, environment);
  +        FOM_JavaScriptFlowHelper.setJavaPackage(objectModel,
  +                                                (Scriptable)ScriptableObject.getProperty(scope,
  +                                                                                         "java"));
  +        // Make the FOM objects available to the view layer
  +        FOM_JavaScriptFlowHelper.setRequest(objectModel,
  +                                            cocoon.jsGet_request());
  +        FOM_JavaScriptFlowHelper.setResponse(objectModel,
  +                                             cocoon.jsGet_response());
  +        FOM_JavaScriptFlowHelper.setSession(objectModel,
  +                                            cocoon.jsGet_session());
  +        FOM_JavaScriptFlowHelper.setContext(objectModel,
  +                                            cocoon.jsGet_context());
       }
   }
  
  
  
  1.1                  cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom/FOM_JavaScriptFlowHelper.java
  
  Index: FOM_JavaScriptFlowHelper.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.
  
  */
  package org.apache.cocoon.components.flow.javascript.fom;
  
  import org.apache.cocoon.components.flow.FlowHelper;
  import org.mozilla.javascript.Scriptable;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.environment.Request;
  import java.util.Map;
  
  /**
   * Provides the interface between the JavaScript flow controller layer and the 
   * view layer. A view can obtain the JavaScript "live connect" objects (that
   * allow access to Java constructors) through this interface, as well as
   * the FOM objects.
   */
  
  public class FOM_JavaScriptFlowHelper extends FlowHelper {
  
      public static final String PACKAGES_OBJECT =
          "cocoon.flow.js.packages";
      public static final String JAVA_PACKAGE_OBJECT =
          "cocoon.flow.js.packages.java";
      public static final String FOM_REQUEST = 
          "cocoon.flow.js.fom.FOM_Request";
      public static final String FOM_RESPONSE = 
          "cocoon.flow.js.fom.FOM_Response";
      public static final String FOM_SESSION = 
          "cocoon.flow.js.fom.FOM_Session";
      public static final String FOM_CONTEXT = 
          "cocoon.flow.js.fom.FOM_Context";
  
      /** 
       * Return the JS "Packages" property (that gives access to Java
       * packages) for use by the view layer
       * @param objectModel The Cocoon Environment's object model
       * @return The Packages property
       */
      public static Scriptable getPackages(Map objectModel) {
          Request request = ObjectModelHelper.getRequest(objectModel);
          return (Scriptable)request.getAttribute(PACKAGES_OBJECT);
      }
  
      /** 
       * Set the JS "Packages" property in the current request
       * @param objectModel The Cocoon Environment's object model
       */
      public static void setPackages(Map objectModel, Scriptable pkgs) {
          Request request = ObjectModelHelper.getRequest(objectModel);
          request.setAttribute(PACKAGES_OBJECT, pkgs);
      }
  
      /** 
       * Return the JS "java" property (that gives access to the "java"
       * package) for use by the view layer
       * @param objectModel The Cocoon Environment's object model
       * @return The java package property
       */
      public static Scriptable getJavaPackage(Map objectModel) {
          Request request = ObjectModelHelper.getRequest(objectModel);
          return (Scriptable)request.getAttribute(JAVA_PACKAGE_OBJECT);
      }
  
      /** 
       * Set the JS "java" property in the current request
       * @param objectModel The Cocoon Environment's object model
       */
      public static void setJavaPackage(Map objectModel, Scriptable javaPkg) {
          Request request = ObjectModelHelper.getRequest(objectModel);
          request.setAttribute(JAVA_PACKAGE_OBJECT, javaPkg);
      }
  
      public static Scriptable getRequest(Map objectModel) {
          Request request = ObjectModelHelper.getRequest(objectModel);
          return (Scriptable)request.getAttribute(FOM_REQUEST);
      }
  
      public static void setRequest(Map objectModel, Scriptable fom_request) {
          Request request = ObjectModelHelper.getRequest(objectModel);
          request.setAttribute(FOM_REQUEST, fom_request);
      }
  
      public static Scriptable getResponse(Map objectModel) {
          Request request = ObjectModelHelper.getRequest(objectModel);
          return (Scriptable)request.getAttribute(FOM_RESPONSE);
      }
  
      public static void setResponse(Map objectModel, Scriptable fom_response) {
          Request request = ObjectModelHelper.getRequest(objectModel);
          request.setAttribute(FOM_RESPONSE, fom_response);
      }
  
      public static Scriptable getSession(Map objectModel) {
          Request request = ObjectModelHelper.getRequest(objectModel);
          return (Scriptable)request.getAttribute(FOM_SESSION);
      }
  
      public static void setSession(Map objectModel, Scriptable fom_session) {
          Request request = ObjectModelHelper.getRequest(objectModel);
          request.setAttribute(FOM_SESSION, fom_session);
      }
  
      public static Scriptable getContext(Map objectModel) {
          Request request = ObjectModelHelper.getRequest(objectModel);
          return (Scriptable)request.getAttribute(FOM_CONTEXT);
      }
  
      public static void setContext(Map objectModel, Scriptable fom_context) {
          Request request = ObjectModelHelper.getRequest(objectModel);
          request.setAttribute(FOM_CONTEXT, fom_context);
      }
  }