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

2003-06-30 Thread reinhard
reinhard2003/06/30 12:11:10

  Modified:src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom
FOM_Cocoon.java
  Log:
  - Implemented functions:
* getComponent( id )
* releaseComponent( component)
* load( script)
  
  - support for cocoon:// protocol when sending pages
  
  - some code formatting
  
  Revision  ChangesPath
  1.7   +81 -16
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.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FOM_Cocoon.java   26 Jun 2003 19:44:04 -  1.6
  +++ FOM_Cocoon.java   30 Jun 2003 19:11:10 -  1.7
  @@ -49,9 +49,12 @@
   
   */
   package org.apache.cocoon.components.flow.javascript.fom;
  +
   import java.io.OutputStream;
   import java.util.Map;
   
  +import org.apache.avalon.framework.component.Component;
  +import org.apache.avalon.framework.component.ComponentException;
   import org.apache.avalon.framework.component.ComponentManager;
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.cocoon.components.flow.ContinuationsManager;
  @@ -63,13 +66,20 @@
   import org.apache.cocoon.environment.Response;
   import org.apache.cocoon.environment.Session;
   import org.mozilla.javascript.JavaScriptException;
  +import org.mozilla.javascript.Script;
   import org.mozilla.javascript.Scriptable;
   import org.mozilla.javascript.ScriptableObject;
   import org.mozilla.javascript.Undefined;
   import org.mozilla.javascript.Wrapper;
   import org.mozilla.javascript.continuations.Continuation;
  +
   /**
  - * Implementation of FOM (Flow Object Model)
  + * Implementation of FOM (Flow Object Model).
  + *
  + * @since 2.1 
  + * @author a href=mailto:coliver.at.apache.org;Christopher Oliver/a
  + * @author a href=mailto:reinhard.at.apache.org;Reinhard Pötz/a
  + * @version CVS $Id$
*/
   
   public class FOM_Cocoon extends ScriptableObject {
  @@ -120,6 +130,7 @@
   this.interpreter = null;
   }
   
  +
   private void forwardTo(String uri, Object bizData,
  Continuation continuation) 
   throws Exception {
  @@ -132,8 +143,14 @@
 lastContinuation,
 0);
   }
  -interpreter.forwardTo(getParentScope(), this, cocoon://+
  -  environment.getURIPrefix() + uri,
  +
  +String redUri = uri;
  +
  +if(! uri.startsWith( cocoon:// ) ) {
  +redUri = cocoon:// + this.environment.getURIPrefix() + uri;
  +}
  +
  +interpreter.forwardTo(getParentScope(), this, redUri,
 bizData, wk, environment);
   }
   
  @@ -179,12 +196,64 @@
   }
   
   */
  -  
  -public Object jsFunction_getComponent(String id) {
  -// what is this?
  -return null;
  +
  +/**
  + * Access components.
  + * 
  + * TODO: Do we want to restrict the access of sitemap components? (RP)
  + * TODO: Do we want to raise an error or return null? (RP)
  + */  
  +public Object jsFunction_getComponent( String id ) { 
  +Object o = null;
  +try {
  +   o = this.componentManager.lookup( id );
  + } catch (ComponentException e) {
  +  o = null; 
  + }
  +return o;
  +}
  +
  +/**
  + * Release pooled components.
  + * 
  + * @param component - an codeObject/code that is an instance 
  + * of codeorg.apache.avalon.framework.component.Component/code
  + */
  +public void jsFunction_releaseComponent( Object component ) 
  +  throws JavaScriptException {
  +try {
  +this.componentManager.release( (Component) component );
  +} catch( ClassCastException cce ) {
  +throw new JavaScriptException( Only components can be released! );
  +} catch( Exception e ) {
  +throw new JavaScriptException( Error during release of component 
occurred! + e.getMessage() ); 
  +}
   }
   
  +/**
  + * Load the script file specified as argument.
  + *
  + * @param filename a codeString/code value
  + * @return an codeObject/code value
  + * @exception JavaScriptException if an error occurs
  + */
  +public Object jsFunction_load( String filename ) 
  +throws JavaScriptException {
  +org.mozilla.javascript.Context cx = 
  +org.mozilla.javascript.Context.getCurrentContext();
  +try {
  +Scriptable scope = getParentScope();
  +Script script = 

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

2003-06-26 Thread stefano
stefano 2003/06/26 12:44:05

  Modified:src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom
FOM_Cocoon.java
  Log:
  commented out the hooks to the FOM event model that we'll design and implement in 
the future
  
  Revision  ChangesPath
  1.6   +10 -1 
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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- FOM_Cocoon.java   24 Jun 2003 16:59:20 -  1.5
  +++ FOM_Cocoon.java   26 Jun 2003 19:44:04 -  1.6
  @@ -161,6 +161,13 @@
   environment.redirect(false, uri);
   }
   
  +/*
  +
  + NOTE (SM): These are the hooks to the future FOM Event Model that will be
  + designed in the future. It has been postponed because we think
  + there are more important things to do at the moment, but these
  + are left here to indicate that they are planned.
  + 
   public void jsFunction_addEventListener(String eventName, 
   Object function) {
   // what is this?
  @@ -170,7 +177,9 @@
  Object function) {
   // what is this?
   }
  -
  +
  +*/
  +  
   public Object jsFunction_getComponent(String id) {
   // what is this?
   return null;
  
  
  


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

2003-06-20 Thread coliver
coliver 2003/06/20 01:28:20

  Added:   src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom
FOM_Cocoon.java FOM_JavaScriptInterpreter.java
fom_system.js
  Log:
  Prototype implementation of FOM
  
  Revision  ChangesPath
  1.1  
cocoon-2.1/src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom/FOM_Cocoon.java
  
  Index: FOM_Cocoon.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
  [EMAIL PROTECTED]
  
   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.mozilla.javascript.JavaScriptException;
  import org.mozilla.javascript.Scriptable;
  import org.mozilla.javascript.Function;
  import org.mozilla.javascript.ScriptableObject;
  import org.mozilla.javascript.Context;
  import org.mozilla.javascript.Undefined;
  import org.mozilla.javascript.Wrapper;
  import org.mozilla.javascript.continuations.Continuation;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.environment.Request;
  import org.apache.cocoon.environment.Response;
  import org.apache.cocoon.environment.Session;
  import org.apache.cocoon.environment.Cookie;
  import org.apache.cocoon.environment.ObjectModelHelper;
  import org.apache.cocoon.components.flow.WebContinuation;
  import org.apache.cocoon.components.flow.ContinuationsManager;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.logger.Logger;
  import java.util.Map;
  import java.io.OutputStream;
  /**
   * Implementation of FOM (Flow Object Model)
   */
  
  public class FOM_Cocoon extends ScriptableObject {
  
  private FOM_JavaScriptInterpreter interpreter;
  
  private Environment environment;
  private ComponentManager componentManager;
  
  private FOM_Request request;
  private FOM_Response response;
  private FOM_Session session;
  private FOM_Context context;
  private FOM_Log log;
  
  private WebContinuation lastContinuation;
  
  public String getClassName() {
  return FOM_Cocoon;
  }
  
  public void setup(FOM_JavaScriptInterpreter interp,
Environment env, 
ComponentManager manager) {
  this.interpreter = interp;
  this.environment = env;
  this.componentManager = manager;
  }
  
  public void invalidate() {
  this.request = null;

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

2003-06-20 Thread coliver
coliver 2003/06/20 01:30:29

  Modified:src/scratchpad/src/org/apache/cocoon/components/flow/javascript/fom
FOM_Cocoon.java
  Log:
  removed tabs
  
  Revision  ChangesPath
  1.2   +231 -231  
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.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FOM_Cocoon.java   20 Jun 2003 08:28:20 -  1.1
  +++ FOM_Cocoon.java   20 Jun 2003 08:30:29 -  1.2
  @@ -107,7 +107,7 @@
   
   private void forwardTo(String uri, Object bizData,
  Continuation continuation) 
  - throws Exception {
  +throws Exception {
   WebContinuation wk = null;
   if (continuation != null) {
   ContinuationsManager contMgr = (ContinuationsManager)
  @@ -125,7 +125,7 @@
   public void jsFunction_sendPage(String uri, 
   Object obj, 
   Object continuation) 
  - throws Exception {
  +throws Exception {
   forwardTo(uri, obj, (Continuation)unwrap(continuation)); 
   }
   
  @@ -134,12 +134,12 @@
Object map,
Object outputStream) 
   throws Exception {
  - if (!(unwrap(outputStream) instanceof OutputStream)) {
  - throw new JavaScriptException(expected a java.io.OutputStream instead of 
 + outputStream);
  - }
  +if (!(unwrap(outputStream) instanceof OutputStream)) {
  +throw new JavaScriptException(expected a java.io.OutputStream instead 
of  + outputStream);
  +}
   interpreter.process(uri, map, 
  - (OutputStream)unwrap(outputStream), 
  - environment);
  +(OutputStream)unwrap(outputStream), 
  +environment);
   }
   
   public void jsFunction_redirectTo(String uri) throws Exception {
  @@ -166,8 +166,8 @@
   Request request;
   
   public FOM_Request() {
  - // prototype ctor
  - }
  +// prototype ctor
  +}
   
   public FOM_Request(Object request) {
   this.request = (Request)unwrap(request);
  @@ -186,7 +186,7 @@
   }
   
   public void jsFunction_removeAttribute(String name) {
  - request.removeAttribute(name);
  +request.removeAttribute(name);
   }
   
   public void jsFunction_setAttribute(String name,
  @@ -211,7 +211,7 @@
   }
   
   public void jsFunction_setCharacterEncoding(String value) 
  - throws Exception {
  +throws Exception {
   request.setCharacterEncoding(value);
   }
   
  @@ -246,245 +246,245 @@
   
   public static class FOM_Cookie extends ScriptableObject {
   
  - Cookie cookie;
  +Cookie cookie;
   
  - public FOM_Cookie() {
  - // prototype ctor
  - }
  -
  - public FOM_Cookie(Object cookie) {
  - this.cookie = (Cookie)unwrap(cookie);
  - }
  +public FOM_Cookie() {
  +// prototype ctor
  +}
  +
  +public FOM_Cookie(Object cookie) {
  +this.cookie = (Cookie)unwrap(cookie);
  +}
   
   public String getClassName() {
   return FOM_Cookie;
   }
   
  - public String jsGet_name() {
  - return cookie.getName();
  - }
  -
  - public int jsGet_version() {
  - return cookie.getVersion();
  - }
  -
  - public void jsSet_version(int value) {
  - cookie.setVersion(value);
  - }
  -
  - public String jsGet_value() {
  - return cookie.getValue();
  - }
  -
  - public void jsSet_value(String value) {
  - cookie.setValue(value);
  - }
  -
  - public void jsSet_comment(String purpose) {
  - cookie.setComment(purpose);
  - }
  -
  - public String jsGet_comment() {
  - return cookie.getComment();
  - }
  -
  - public void jsSet_domain(String pattern) {
  - cookie.setDomain(pattern);
  - }
  -
  - public String jsGet_domain() {
  - return cookie.getDomain();
  - }
  -
  - public void jsSet_maxAge(int value) {
  - cookie.setMaxAge(value);
  - }
  -
  - public int jsGet_maxAge() {
  - return cookie.getMaxAge();
  - }
  -
  - public void jsSet_path(String value) {
  - cookie.setPath(value);
  - }
  -
  - public String jsGet_path() {
  - return cookie.getPath();
  - }
  -
  -