Apache » Cocoon »

  Cocoon FlowScript
      1.0
   homepage

Cocoon FlowScript 1.0

Cocoon Object

The Cocoon object represents the current Cocoon Sitemap. This is the entry point into the FOM. There is one instance of Cocoon which you may access in your scripts as the global variable cocoon, for example like this:

      var value = cocoon.request.getAttribute("blah");
    

The Cocoon object supports the following properties and functions:

request

The current Cocoon request:

Property [Request] request

response

The current Cocoon response:

Property [Response] response

session

The current Cocoon session:

Property [Session] session

context

The current Cocoon application context:

Property [Context] context

log

A reference to the current logger:

Property [Log] log

parameters

Any parameters passed to the script by the Cocoon Sitemap

Property [Object] parameters

sendPage

Function sendPage([String] uri, [Object] bean)

Passes control to the Cocoon sitemap to generate the output page.

uri is the sitemap URI of the page to be sent back to the client. If the URI starts with a slash, it is resolved starting at the root sitemap, otherwise it is resolved relative to the current sitemap. The URI should not contain a scheme (such as cocoon:).

bean is a context object which can be accessed either inside this page to extract various values and place them in the generated page or in the sitemap to use values as parameters for actions or transformers.

Note: Use value="{flow-attribute:name}" in any parameter tag in the sitemap to access a value from the bean.

sendPageAndWait

Function [WebContinuation] sendPageAndWait([String] uri, [Object] bean, [Function] postPipelineCode, [Number] timeToLive)

Passes control to the Cocoon sitemap to generate the output page.

The flow script is suspended after the page is generated and the whole execution stack saved in the WebContinuation object returned from this function.

uri is the relative URL of the page to be sent back to the client. If the URI starts with a slash, it is resolved starting at the root sitemap, otherwise it is resolved relative to the current sitemap. The URI should not contain a scheme (such as cocoon:).

bean is a context object which can be accessed either inside this page to extract various values and place them in the generated page or in the sitemap to use values as parameters for actions or transformers.

Note: Use value="{flow-attribute:name}" in any parameter tag in the sitemap to access a value from the bean.

If provided, the postPipelineCode function will be executed after pipeline processing is complete but before the script is suspended. You can use this to release resources that are needed during the pipeline processing but should not become part of the continuation. For example:

function processPage() {
   var id = ...
   var bizData = ...
   var uri = ...
   var comp = cocoon.getComponent(id);
   // use comp
   ...
   cocoon.sendPageAndWait(uri, bizData, function() {
      cocoon.releaseComponent(comp);
      comp = null;
   });
}

timeToLive is the time to live in milliseconds for the continuation created.

The return value is the continuation object.

sendStatus

Function sendStatus([Number] sc)

Sends an empty response with the provided HTTP status code.

createPageLocal

Function [Object] createPageLocal()

Creates a Page Local object. The returned object behaves like a normal JavaScript object, but restores the property values it had when sendPageAndWait was originally called, each time a page is resubmitted (e.g. after hitting the back button). Such objects can be used to associate state with one particular page sent to the browser.

processPipelineTo

Function processPipelineTo([String] uri, [Object] bizData, [java.io.OutputStream] stream)

Call the Cocoon sitemap for the given URI, sending the output of the eventually matched pipeline to the specified OutputStream.

uri is the URI for which the request should be generated. If the URI starts with a slash, it is resolved starting at the root sitemap, otherwise it is resolved relative to the current sitemap. The URI should not contain a scheme (such as cocoon:).

bizData is the business data object to be made available to the forwarded pipeline

stream is an OutputStream where the output should be written to.

redirectTo

Function redirectTo([String] uri, [boolean] isGlobal)

Send a client-side redirect to the browser. The uri argument is the URI to which the browser should be redirected.

The isGlobal argument, if true, causes an HTTP redirect to be sent to the client browser in all cases. When isGlobal is false and the request is an internal one (using "cocoon:"), the internal request will be redirected. For example, if you have a pipeline called from an aggregation:

<map:aggregate>
  <map:part src="cocoon:/callflow"/>
</map:aggregate>

and in some flow function:

cocoon.redirectTo("http://www.google.com", false);

then the map:aggregate will try to read the content for its part from Google.

createWebContinuation

Function [WebContinuation] createWebContinuation()

Creates a new "bookmark" WebContinuation object. When invoked it will cause the script to resume right after the call. By calling this function prior to sendPageAndWait() you can be create a "bookmark" which will cause the page to be redisplayed in the browser. Note: the WebContinuation associated with sendPageAndWait() doesn't do this. Rather it resumes execution after the the page is submitted.

For example:

function processPage() {

  var bkm = cocoon.createWebContinuation();
  var biz = getBizData();
  cocoon.sendPageAndWait("uri",
                         {bookmark: bkm, biz: biz},
                         function() { releaseData(biz); });
}

load

Function load([String] uri)

Load the JavaScript script specified by uri. The Cocoon source resolver is used to resolve uri.

getComponent

Function Object getComponent([String] id)

Access an Avalon component.

releaseComponent

Function releaseComponent([Object] component)

Release a pooled Avalon component.

createObject

Function createObject([JavaClass] componentClass)

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.

disposeObject

Function disposeObject([Object] object)

Dispose an object that has been created using createObject.

exit

Function exit()

Exit the current flowscript invocation.

There are some flowscript use cases where we want to stop the current flowscript without creating a continuation, as we don't want the user to go back to the script and return from the current function.

An example is a "login" function where the caller function expects this function to exit only if login is successful, but that has to handle e.g. a registration process that includes a "cancel" button.

Errors and Improvements? If you see any errors or potential improvements in this document please help us: View, Edit or comment on the latest development version (registration required).