cocoon-docs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@cocoon.zones.apache.org
Subject [DAISY] Created: Cocoon Object
Date Thu, 07 Jun 2007 16:50:02 GMT
A new document has been created.

http://cocoon.zones.apache.org/daisy/documentation/1382.html

Document ID: 1382
Branch: main
Language: default
Name: Cocoon Object
Document Type: Cocoon Document
Created: 6/7/07 4:49:54 PM
Creator (owner): Reinhard Pötz
State: publish

Parts
=====

Content
-------
Mime type: text/xml
Size: 8446 bytes
Content:
<html>
<body>

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

<pre>      var value = cocoon.request.getAttribute("blah");
    </pre>

<p>The <tt>Cocoon</tt> object supports the following properties and functions:
</p>

<h3>request</h3>

<p>The current Cocoon request:</p>

<p><em>Property</em> [<a href="#request">Request</a>] <tt>request</tt></p>

<h3>response</h3>

<p>The current Cocoon response:</p>

<p><em>Property</em> [<a href="#response">Response</a>] <tt>response</tt></p>

<h3>session</h3>

<p>The current Cocoon session:</p>

<p><em>Property</em> [<a href="#session">Session</a>] <tt>session</tt></p>

<h3>context</h3>

<p>The current Cocoon application context:</p>

<p><em>Property</em> [<a href="#context">Context</a>] <tt>context</tt></p>

<h3>log</h3>

<p>A reference to the current logger:</p>

<p><em>Property</em> [<a href="#log">Log</a>] <tt>log</tt></p>

<h3>parameters</h3>

<p>Any parameters passed to the script by the Cocoon Sitemap</p>

<p><em>Property</em> <tt>[Object] parameters</tt></p>

<h3 id="sendPage">sendPage</h3>

<p><em>Function</em> <tt>sendPage([String] uri, [Object] bean)</tt></p>

<p>Passes control to the Cocoon sitemap to generate the output page.</p>

<p><tt>uri</tt> 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:).</p>

<p><tt>bean</tt> 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.</p>

<p class="note">Use <tt>value="{flow-attribute:name}"</tt> in any parameter
tag
in the sitemap to access a value from the bean.</p>

<h3 id="sendPageAndWait">sendPageAndWait</h3>

<p><em>Function</em> <tt>[WebContinuation] sendPageAndWait([String]
uri,
[Object] bean, [Function] postPipelineCode, [Number] timeToLive)</tt></p>

<p>Passes control to the Cocoon sitemap to generate the output page.</p>

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

<p><tt>uri</tt> 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:).</p>

<p><tt>bean</tt> 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.</p>

<p class="note">Use <tt>value="{flow-attribute:name}"</tt> in any parameter
tag
in the sitemap to access a value from the bean.</p>

<p>If provided, the <tt>postPipelineCode</tt> 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:</p>

<pre>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;
   });
}
</pre>

<p><tt>timeToLive</tt> is the time to live in milliseconds for the continuation
created.</p>

<p>The return value is the <a href="#WebContinuation">continuation</a> object.
</p>

<h3 id="sendStatus">sendStatus</h3>

<p><em>Function</em> <tt>sendStatus([Number] sc)</tt></p>

<p>Sends an empty response with the provided HTTP status code.</p>

<h3 id="createPageLocal">createPageLocal</h3>

<p><em>Function</em> <tt>[Object] createPageLocal()</tt></p>

<p>Creates a <em>Page Local</em> object. The returned object behaves like
a
normal JavaScript object, but restores the property values it had when
<a href="#sendPageAndWait">sendPageAndWait</a> 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.</p>

<h3>processPipelineTo</h3>

<p><em>Function</em> <tt>processPipelineTo([String] uri, [Object]
bizData,
[java.io.OutputStream] stream)</tt></p>

<p>Call the Cocoon sitemap for the given URI, sending the output of the
eventually matched pipeline to the specified <tt>OutputStream</tt>.</p>

<p><tt>uri</tt> 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:).</p>

<p><tt>bizData</tt> is the business data object to be made available to
the
forwarded pipeline</p>

<p><tt>stream</tt> is an <tt>OutputStream</tt> where the output
should be
written to.</p>

<h3>redirectTo</h3>

<p><em>Function</em> <tt>redirectTo([String] uri, [boolean] isGlobal)</tt></p>

<p>Send a client-side redirect to the browser. The <tt>uri</tt> argument
is the
URI to which the browser should be redirected.</p>

<p>The <tt>isGlobal</tt> argument, if <tt>true</tt>, causes
an HTTP redirect to
be sent to the client browser in all cases. When <tt>isGlobal</tt> is
<tt>false</tt> 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:</p>

<pre><tt>&lt;map:aggregate&gt;</tt>
<tt>  &lt;map:part src="cocoon:/callflow"/&gt;</tt>
<tt>&lt;/map:aggregate&gt;
</tt></pre>

<p>and in some flow function:</p>

<pre><tt>cocoon.redirectT</tt>o("http://www.google.com",<tt> false);</tt></pre>

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

<h3 id="createWebContinuation">createWebContinuation</h3>

<p><em>Function</em> <tt>[WebContinuation] createWebContinuation()</tt></p>

<p>Creates a new "bookmark" <a href="#WebContinuation">WebContinuation</a>
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.</p>

<p>For example:</p>

<pre>function processPage() {

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

<h3>load</h3>

<p><em>Function</em> <tt>load([String] uri)</tt></p>

<p>Load the JavaScript script specified by <tt>uri</tt>. The Cocoon source
resolver is used to resolve <tt>uri</tt>.</p>

<h3>getComponent</h3>

<p><em>Function</em> <tt>Object getComponent([String] id)</tt></p>

<p>Access an Avalon component.</p>

<h3>releaseComponent</h3>

<p><em>Function</em> <tt>releaseComponent([Object] component)</tt></p>

<p>Release a pooled Avalon component.</p>

<h3>createObject</h3>

<p><em>Function</em> <tt>createObject([JavaClass] componentClass)</tt></p>

<p>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.</p>

<h3>disposeObject</h3>

<p><em>Function</em> <tt>disposeObject([Object] object)</tt></p>

<p>Dispose an object that has been created using <tt>createObject</tt>.</p>

<h3>exit</h3>

<p><em>Function</em> exit()</p>

<p>Exit the current flowscript invocation.</p>

<p>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.</p>

<p>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.</p>

</body>
</html>

Collections
===========
The document belongs to the following collections: cdocs-flowscript

Mime
View raw message