apache > cocoon
 
Font size:      

ScriptAction in Cocoon (2.1 legacy document)

Warning
This document was copied as is from the Cocoon 2.1 documentation, but has not yet been fully reviewed or moved to its new home.

ScriptAction

NAMEscript
WHATThe ScriptAction component is used to executes any script that can be run by the BSF.
TYPEAction
BLOCKbsf
CLASSorg.apache.cocoon.action.ScriptAction
SINCECocoon 2.1
CACHEABLEnot applicable

Description

A simple action that executes any script that can be run by the BSF system. BSF supports script languages like javascript, python, etc.

Usage

This Action is used for quick prototyping of Action, realizing an Action in a script language instead of java language.

Sitemap pipeline examples

The following sample executes the script action/my-action.js for each URI matching pattern *.vm. If the ScriptAction succeeds, the pipeline continues, invoking the VelocityGenerator, and serializing the XML stream.

<map:match pattern="*.vm">
  <map:action type="script" src="action/my-action.js">
    <map:generate type="velocity" src="{1}.vm"/>
    <map:serialize/>
  </map:action>
</map:match>

Sitemap component configuration example

The following sample configures an ScriptAction, naming it script.

<map:actions...
  <map:action name="script"
    src="org.apache.cocoon.acting.ScriptAction"> 
    logger="sitemap.action.script"/>    
    <!-- optional action configuration -->
    ...
</map:actions>

Configuration

ScriptAction has no configuration options.

Setup

ScriptAction determines the name of the script getting executed from its src attribute.

The language of the script file is auto-detected by the BSF system from the extension of the script.

The next table lists the default mapping of BSF:

Script languageExtension
javascriptjs
jacljacl
netrexxnrx
javajava
javaclassclass
bmlbml
vbscriptvbs
jscriptjss
perlscriptpls
perlpl
jpythonpy
lotusscriptlss
xsltxslt
pnutspnut
beanbasicbb

ScriptAction registers following objects before invoking the script:

nameObject TypComment
resolverSourceResolverCocoon's source resolver
objectModelMapCocoon's object model
parametersParametersCocoon's action parameter
actionMapMapUsed for passing objects from the script back to the ScriptAction, and to Cocoon's sitemap
loggerLoggerCocoon's logger of this ScriptAction
requestRequestRequest provided by the object model
scriptactionActionThe instance of this ScriptAction
managerManagerCocoon's manager of this ScriptAction

These objects are accessible from within the script.

Effect on Object Model and Sitemap Parameters

ScriptAction checks the existence of the key scriptaction-continue in the actionMap. If this key exists ScriptAction returns actionMap, otherwise null is returned.

Objects available in the actionMap are available in the sitemap.

Bugs/Caveats

Using ScriptAction relies heavily on the setting of the key scriptaction-continue in the mapAction.

Be aware to provide script language implementation, beside BSF implementation.

History

07-24-03: initial creation

04-02-04: Updated to Jakarta BSF

Copyright

Copyright (C) 1999-2004 The Apache Software Foundation. All rights reserved.

See also

A general documentation about actions is available at Actions.

Further Documentation visit Jakarta BSF Project.

Comments

add your comments