To write an XSP Action you need to declarate the use of the built-in logicsheet action. In the header of your XSP please include:


Allowed Tags

Here is a description of all the tags and the parameters it uses:

Writing an action using XSP

This is some basic information that explains how to write an action using XSP. It might not be clean or perfect but it did work for Litrik

When you write your action in XSP, Cocoon will notice when the file has changed and recompile automagically.


Declaring the Action component

Your sitemap should contain the following declaration of the action component:


Note: Some other pieces of documentation use serverpages as the action name instead of xsp-action. I prefer to use xsp-action to avoid confusions of what it defines. Note that the name serverpages is already used by the XSP Generator. This is why I dont use it.

How to use in a Pipeline

And of course your sitemap should contain a pipeline that actually contains an action written in XSP. To use it we must use the <map:action>. The value of the type attribute must be xsp-action and the value of the src attribute will contain the full path to the XSP file.

<map:match pattern="test-of-xsp-action">
  <map:act type="xsp-action" src="my-xsp-action.xsp">
    <!-- This part is called when the action executes <action:set-success/> -->
    <map:read src="{my-result-filename}" mime-type="image/gif"/>
  <!-- This part is called when the action executes <action:set-failure/> -->
  <map:generate type="serverpages" src="error.xsp"/>

Writing the Action

The src attribute of the <map:act> of the pipeline contains my-xsp-action.xsp. That is the XSP file that is actually implementing the action logic.

This is what my-xsp-action.xsp could look like:

<?xml version="1.0"?>

    if( /* do some test here */ )
      /* With <action:set-result/> we set return values
      ** that can be used in the calling pipeline */
      <action:set-result name="my-result-filename" value="GoodMorning.gif"/>
      <action:set-result name="some-other-result" value="5987"/>

      // You can use action:param to set the name and/or the value dynamically.
        <action:param name="name"><xsp:expr>getName()</xsp:expr></action:param>
        <action:param name="value"><xsp:expr>getValue()</xsp:expr></action:param>
    else if( /* do some other test here */ )
      <action:set-result name="my-result-filename" value="GoodAfternoon.gif"/>
      throw new Exception() ;

    // With <action:set-success/> we indicate that
    // everything went just fine
  catch(Exception e)
    e.printStackTrace() ;
    // With <action:set-failure/> we indicate that
    // something went wrong and that the action has failed



XSPAction (last edited 2009-09-20 23:39:58 by localhost)