apache > cocoon
 
Font size:      

ScriptGenerator 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.

ScriptGenerator

NAMEscript
WHATThe ScriptGenerator component is used to generate XML by invoking a script.
TYPEGenerator, Sitemap Component
BLOCKbsf
CLASSorg.apache.cocoon.generation.ScriptGenerator
SINCECocoon 2.1
CACHEABLEno

Description

The ScriptGenerator executes arbitrary scripts using the Apache BSF framework and additional interpreter (Rhino, Jython, etc.) as a Cocoon Generator.

Usage

The ScriptGenerator is used primarily for prototyping a Cocoon generator. Moreover if the generator's XML output is low and the logic processing is high.

Sitemap pipeline examples

The following sample uses the ScriptGenerator for generating XML content for URIs matching the pattern *.js. The output of the script invoked by ScriptGenerator is serialized by the default serializer.

<map:match pattern="*.js">
  <map:generate type="script" src="{0}" >
  </map:generate>
  <map:serialize/>
</map:match>
       

Sitemap component configuration example

The following sample declares the ScriptGenerator in the sitemap's component section. The ScriptGenerator can be used in the sitemap's section using type value script. In this sample no extra script language is declared.

<map:generators...
  <map:generator name="script" 
    src="org.apache.cocoon.generation.ScriptGenerator"
    logger="sitemap.generation.scriptgenerator" 
  />
    <!-- optional generator configuration -->
    ...
</map:generators>
...

Configuration

The ScriptGenerator allows registering additional script languages.

List the newly registered language inside the add-language element, each language is defined in language element, by specifying the name of the language using the name attribute, and the language BSF adaptor using the attribute src.

Each registered language should be mapped to at least one extension, as the language detection of ScriptGenerator is based on the script's extension.

The following sample register an new language foobar, the BSF adaptor class is foo.bar.ScriptLanguage, and it is associated with the extensions foo, and bar.

<add-language>
  <language name="foobar" src="foo.bar.ScriptLanguage">
    <extension>foo</extension>
    <extension>bar</extension>
  </language>
  ...
</add-language>

The next table lists the default mapping of BSF:

ExtensionScript language
javascriptjs
jacljacl
netrexxnrx
javajava
javaclassclass
bmlbml
vbscriptvbs
jscriptjss
jscriptjss
perlscriptpls
perlpl
jpythonpy
lotusscriptlss
xsltxslt
pnutspnut
beanbasicbb

Setup

ScriptGenerator registers following objects before invoking the script:

NameObject TypComment
resolverResolverCocoon's resolver
sourceSourcesrc attribute of this ScriptGenerator
objectModelMapCocoon's objectModel
parametersParametersparamters of this ScriptGenerator
outputStringBufferXML content, forwarded into Cocoon's XML pipeline
loggerLoggerlogger of this ScriptGenerator

The script shall write XML content into the StringBuffer object output. The content of output is parsed by the ScriptGenerator and forwarded into the sitemap pipeline.

Effect on Object Model and Sitemap Parameters

none

Bugs/Caveats

ScriptGenerator expects the script to write the XML content into the passed object output.

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

History

07-24-03: initial creation

See also

A general documentation about generators is available at generators.

Further Documentation about Apache BSF is available here.

Comments

add your comments