org.apache.cocoon.components.flow.javascript.fom
Class FOM_Cocoon

java.lang.Object
  extended byorg.mozilla.javascript.ScriptableObject
      extended byorg.apache.cocoon.components.flow.javascript.fom.FOM_Cocoon
All Implemented Interfaces:
org.mozilla.javascript.ConstProperties, org.mozilla.javascript.debug.DebuggableObject, org.mozilla.javascript.Scriptable, Serializable

public class FOM_Cocoon
extends org.mozilla.javascript.ScriptableObject

Implementation of FOM (Flow Object Model).

Since:
2.1
Version:
$Id: FOM_Cocoon.html 1304280 2012-03-23 11:18:01Z ilgrosso $
See Also:
Serialized Form

Nested Class Summary
static class FOM_Cocoon.FOM_Context
          JS wrapper for Cocoon's context object.
static class FOM_Cocoon.FOM_Request
          JS wrapper for Cocoon's request object.
static class FOM_Cocoon.FOM_Session
          JS wrapper for Cocoon's session object.
 
Field Summary
protected  PageLocalScopeHolder pageLocal
           
 
Fields inherited from class org.mozilla.javascript.ScriptableObject
CONST, DONTENUM, EMPTY, PERMANENT, READONLY, UNINITIALIZED_CONST
 
Fields inherited from interface org.mozilla.javascript.Scriptable
NOT_FOUND
 
Constructor Summary
FOM_Cocoon()
           
 
Method Summary
 void forwardTo(String uri, Object bean, FOM_WebContinuation fom_wk)
          Call the Cocoon Sitemap to process a page
 WebApplicationContext getApplicationContext()
          Get the current application context.
 String getClassName()
           
 org.apache.cocoon.environment.Context getContext()
          Get the current context
 String getInterpreterId()
          Required by FOM_WebContinuation.
 Map getObjectModel()
          Get the current object model
 org.mozilla.javascript.Scriptable getParameters()
           
 org.apache.cocoon.environment.Request getRequest()
          Get the current request
 org.apache.cocoon.environment.Response getResponse()
          Get the current response
 org.apache.cocoon.environment.Session getSession()
          Get the current session
 org.apache.cocoon.configuration.Settings getSettings()
          Get the current settings object.
 void handleContinuation(String kontId, org.mozilla.javascript.Scriptable parameters)
          Perform the behavior of This can be used in cases where the continuation id is not encoded in the request in a form convenient to access in the sitemap.
 Object jsFunction_createObject(Object classObj)
          Create and setup an object so that it can access the information provided to regular components.
 org.mozilla.javascript.Scriptable jsFunction_createPageLocal()
           
 void jsFunction_disposeObject(Object obj)
          Dispose an object that has been created using jsFunction_createObject(Object).
 Object jsFunction_getComponent(String id)
          Access components.
 Object jsFunction_load(String filename)
          Load the script file specified as argument.
 FOM_WebContinuation jsFunction_makeWebContinuation(Object k, Object ttl)
          Create a Bookmark WebContinuation from a JS Continuation with the last continuation of sendPageAndWait as its parent.
 void jsFunction_processPipelineTo(String uri, Object map, Object outputStream)
           
 void jsFunction_redirectTo(String uri, boolean isGlobal)
           
 void jsFunction_releaseComponent(Object component)
          Release pooled components.
 FOM_WebContinuation jsFunction_sendPage(String uri, Object obj, Object wk)
           
 void jsFunction_sendStatus(int sc)
           
 Object jsFunction_setupObject(Object obj)
          Setup an object so that it can access the information provided to regular components.
 org.mozilla.javascript.Scriptable jsGet_applicationContext()
          Get the current application context for java script.
 org.mozilla.javascript.Scriptable jsGet_context()
           
 FOM_WebContinuation jsGet_continuation()
           
 org.mozilla.javascript.Scriptable jsGet_log()
           
 org.mozilla.javascript.Scriptable jsGet_parameters()
          Get Sitemap parameters
 org.mozilla.javascript.Scriptable jsGet_request()
           
 org.mozilla.javascript.Scriptable jsGet_response()
           
 org.mozilla.javascript.Scriptable jsGet_session()
           
 org.mozilla.javascript.Scriptable jsGet_settings()
          Get the current settings object for java script.
 void jsSet_continuation(Object obj)
           
 FOM_WebContinuation makeWebContinuation(org.mozilla.javascript.continuations.Continuation k, FOM_WebContinuation parent, int timeToLive)
          Create a Web Continuation from a JS Continuation
 void popCallContext()
           
 void pushCallContext(FOM_JavaScriptInterpreter interp, org.apache.cocoon.environment.Redirector redirector, Context avalonContext, org.apache.cocoon.components.flow.WebContinuation lastContinuation)
           
 
Methods inherited from class org.mozilla.javascript.ScriptableObject
associateValue, callMethod, callMethod, defineClass, defineClass, defineClass, defineConst, defineConstProperty, defineFunctionProperties, defineProperty, defineProperty, defineProperty, defineProperty, delete, delete, deleteProperty, deleteProperty, equivalentValues, get, get, getAllIds, getAssociatedValue, getAttributes, getAttributes, getAttributes, getAttributes, getClassPrototype, getDefaultValue, getDefaultValue, getFunctionPrototype, getGetterOrSetter, getIds, getObjectPrototype, getParentScope, getProperty, getProperty, getPropertyIds, getPrototype, getTopLevelScope, getTopScopeValue, has, has, hasInstance, hasProperty, hasProperty, isConst, isSealed, put, put, putConst, putConstProperty, putProperty, putProperty, redefineProperty, sealObject, setAttributes, setAttributes, setAttributes, setAttributes, setGetterOrSetter, setParentScope, setPrototype
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pageLocal

protected PageLocalScopeHolder pageLocal
Constructor Detail

FOM_Cocoon

public FOM_Cocoon()
Method Detail

getClassName

public String getClassName()

pushCallContext

public void pushCallContext(FOM_JavaScriptInterpreter interp,
                            org.apache.cocoon.environment.Redirector redirector,
                            Context avalonContext,
                            org.apache.cocoon.components.flow.WebContinuation lastContinuation)

popCallContext

public void popCallContext()

jsGet_continuation

public FOM_WebContinuation jsGet_continuation()

jsSet_continuation

public void jsSet_continuation(Object obj)

jsFunction_sendPage

public FOM_WebContinuation jsFunction_sendPage(String uri,
                                               Object obj,
                                               Object wk)
                                        throws Exception
Throws:
Exception

jsFunction_createPageLocal

public org.mozilla.javascript.Scriptable jsFunction_createPageLocal()

jsFunction_processPipelineTo

public void jsFunction_processPipelineTo(String uri,
                                         Object map,
                                         Object outputStream)
                                  throws Exception
Throws:
Exception

jsFunction_redirectTo

public void jsFunction_redirectTo(String uri,
                                  boolean isGlobal)
                           throws Exception
Throws:
Exception

jsFunction_sendStatus

public void jsFunction_sendStatus(int sc)

jsFunction_getComponent

public Object jsFunction_getComponent(String id)
                               throws Exception
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)

Throws:
Exception

jsFunction_releaseComponent

public void jsFunction_releaseComponent(Object component)
                                 throws Exception
Release pooled components.

Parameters:
component - a component
Throws:
Exception

jsFunction_load

public Object jsFunction_load(String filename)
                       throws Exception
Load the script file specified as argument.

Parameters:
filename - a String value
Returns:
an Object value
Throws:
org.mozilla.javascript.JavaScriptException - if an error occurs
Exception

jsFunction_setupObject

public Object jsFunction_setupObject(Object obj)
                              throws Exception
Setup an object so that it can access the information provided to regular components. This is done by calling the various Avalon lifecycle interfaces implemented by the object, which are LogEnabled, Contextualizable, Serviceable and Initializable.

Contextualizable is of primary importance as it gives access to the whole object model (request, response, etc.) through the ContextHelper class.

Note that Configurable is ignored, as no configuration exists in a flowscript that can be passed to the object.

Parameters:
obj - the object to setup
Returns:
the same object (convenience that allows to write var foo = cocoon.setupObject(new Foo());).
Throws:
Exception - if something goes wrong during setup.

jsFunction_createObject

public Object jsFunction_createObject(Object classObj)
                               throws Exception
Create and setup an object so that it can access the information provided to regular components. This is done by calling the various Avalon lifecycle interfaces implemented by the object, which are LogEnabled, Contextualizable, Serviceable and Initializable.

Contextualizable is of primary importance as it gives access to the whole object model (request, response, etc.) through the ContextHelper class.

Note that Configurable is ignored, as no configuration exists in a flowscript that can be passed to the object.

Parameters:
classObj - the class to instantiate, either as a String or a Rhino NativeJavaClass object
Returns:
an set up instance of clazz
Throws:
Exception - if something goes wrong either during instantiation or setup.

jsFunction_disposeObject

public void jsFunction_disposeObject(Object obj)
                              throws Exception
Dispose an object that has been created using jsFunction_createObject(Object).

Parameters:
obj -
Throws:
Exception

jsGet_request

public org.mozilla.javascript.Scriptable jsGet_request()

jsGet_response

public org.mozilla.javascript.Scriptable jsGet_response()

jsGet_log

public org.mozilla.javascript.Scriptable jsGet_log()

jsGet_context

public org.mozilla.javascript.Scriptable jsGet_context()

jsGet_session

public org.mozilla.javascript.Scriptable jsGet_session()

jsGet_parameters

public org.mozilla.javascript.Scriptable jsGet_parameters()
Get Sitemap parameters

Returns:
a Scriptable value whose properties represent the Sitemap parameters from

getParameters

public org.mozilla.javascript.Scriptable getParameters()

getRequest

public org.apache.cocoon.environment.Request getRequest()
Get the current request

Returns:
The request

getSession

public org.apache.cocoon.environment.Session getSession()
Get the current session

Returns:
The session (may be null)

getResponse

public org.apache.cocoon.environment.Response getResponse()
Get the current response

Returns:
The response

getContext

public org.apache.cocoon.environment.Context getContext()
Get the current context

Returns:
The context

getSettings

public org.apache.cocoon.configuration.Settings getSettings()
Get the current settings object.


jsGet_settings

public org.mozilla.javascript.Scriptable jsGet_settings()
Get the current settings object for java script.


getApplicationContext

public WebApplicationContext getApplicationContext()
Get the current application context.


jsGet_applicationContext

public org.mozilla.javascript.Scriptable jsGet_applicationContext()
Get the current application context for java script.


getObjectModel

public Map getObjectModel()
Get the current object model

Returns:
The object model

getInterpreterId

public String getInterpreterId()
Required by FOM_WebContinuation. This way we do not make whole Interpreter public

Returns:
interpreter Id associated with this FOM.

forwardTo

public void forwardTo(String uri,
                      Object bean,
                      FOM_WebContinuation fom_wk)
               throws Exception
Call the Cocoon Sitemap to process a page

Parameters:
uri - Uri to match
bean - Input to page
fom_wk - Current Web continuation (may be null)
Throws:
Exception

handleContinuation

public void handleContinuation(String kontId,
                               org.mozilla.javascript.Scriptable parameters)
                        throws Exception
Perform the behavior of This can be used in cases where the continuation id is not encoded in the request in a form convenient to access in the sitemap. Your script can extract the id from the request and then call this method to process it as normal.

Parameters:
kontId - The continuation id
parameters - Any parameters you want to pass to the continuation (may be null)
Throws:
Exception

jsFunction_makeWebContinuation

public FOM_WebContinuation jsFunction_makeWebContinuation(Object k,
                                                          Object ttl)
                                                   throws Exception
Create a Bookmark WebContinuation from a JS Continuation with the last continuation of sendPageAndWait as its parent. PageLocal variables will be shared with the continuation of the next call to sendPageAndWait().

Parameters:
k - The JS continuation
ttl - Lifetime for this continuation (zero means no limit)
Throws:
Exception

makeWebContinuation

public FOM_WebContinuation makeWebContinuation(org.mozilla.javascript.continuations.Continuation k,
                                               FOM_WebContinuation parent,
                                               int timeToLive)
                                        throws Exception
Create a Web Continuation from a JS Continuation

Parameters:
k - The JS continuation (may be null - null will be returned in that case)
parent - The parent of this continuation (may be null)
timeToLive - Lifetime for this continuation (zero means no limit)
Throws:
Exception


Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.