Scratchpad component

A ModulSource reads from streams and strings found by using an input module. It can among other things replace the StreamGenerator and the PartSource.


Readable source that are accessed with URI:s like:

module:<input-module>:<attribute-name>[#xpath]

For reading the object that is found by applying the XPath (JXPath), on the attribute from the input-module. If the object is a String or an InputStream, it made available in form of an InputStream otherwise an exception is thrown.

The module source can be used for various things e.g. instead of the StreamGenerator:

<map:generate type="file" src="module:request:inputStream"/>

For reading html from a input field in a form:

<map:generate type="html" src="module:request-param:html-field"/>

Instead of the PartSource for reading multi part mime data:

module:raw-request-param:foo

To use this uploads must be enabled in web.xml.

It can also be used for more advanced things like reading Wiki content from a textarea

<map:generate type="text"     src="module:request-param:wiki-field"/>
<map:transform type="lexer"   src="cocoon:/wiki.xlex"/>
<map:transform type="parser"  src="cocoon:/wiki.xgrm"/>
<map:transform                src="stylesheets/wiki2xdoc.xsl"/>

I didn't made the module source modifiable as I had no clear use cases for it, nor was it obvious to me in what form to save the input.

Relation to other Cocoon components

StreamGenerator

The StreamGenerator can generate xml from the request input stream or from xml in request parameters, these cases can be replaced by:

<map:generate type="file" src="module:request:inputStream"/>

and

<map:generate type="file" src="module:request-param:form-name"/>

respectively.

There are no downsides of replacing the StreamGenerator that I know of. On the upside reading is not limited to XML anymore, and the source can be used in [[C|X]IncludeTransformer and flowscripts as well, and also read from other places than the request parameters and input stream.

PartSource

For PartSource the URI:

upload://formField1

can be replaced by:

module:raw-request-param:formField1

the mime type and content length will not be given from the module source though. I don't know if there are use cases where this information is necessary.

ModuleSource (last edited 2009-09-20 23:42:33 by localhost)