The TaskAction: Triggering a Task from the Sitemap
Declaring the Action
To invoke a task from a sitemap pipeline, you use a TaskAction
. The
task ID is handled to the action by a task
parameter:
<map:components> ... <map:actions> <map:action name="publisher" src="org.lenya.cms.cocoon.acting.TaskAction"> <task id="publish"/> </map:action> </map:actions> ... </map:components>
The TaskAction
collects the request parameters and forwards them
to the task.
<map:match pattern="lenya/publish*"> <map:act type="publisher"> <map:redirect-to uri="{parent_uri}" session="true"/> </map:act> <map:redirect-to uri="publishScreen?status=failed" session="true"/> </map:match>
You can also pass the task ID as a task-id
parameter directly in the pipeline:
<map:actions> <map:action name="task" src="org.lenya.cms.cocoon.acting.TaskAction"/> </map:actions> ... <map:match pattern="lenya/publish*"> <map:act type="task"> <map:parameter name="task-id" value="publish-article"/> <map:redirect-to uri="{parent_uri}" session="true"/> </map:act> <map:redirect-to uri="publishScreen?status=failed" session="true"/> </map:match>
Scheduling a Task
See section Scheduler .
Developing Your Own Tasks
Every task must implement the org.lenya.cms.task.Task
interface.
The easiest way to develop your own task is to extend the AbstractTask
class.
Its parameterize()
method simply replaces old parameter values with new
ones. All you have to do is implementing the execute(String contextPath)
method.
You may wonder why we pass the contextPath
as a method parameter
since we already pass it as a task parameter. This ensures that the task is always
able to access the Lenya CMS directory, even if it is not created by a TaskAction
or a TaskJob
. Furthermore, if you enter a task in the jobs.xml
file manually, you won't have to provide a hard-coded servlet-context
parameter.
This feature may be subject to changes. If you have any suggestions to improve the task implementation, just contact me (Andreas Hartmann) at ah@wyona.org.