It's pretty easy. There are a number of org.apache.cocoon.acting classes that you can extend, depending on your need. AbstractAction will get you the bare minimum - it implements the Action interface and gives you access to a logger. I needed to extend ComposerAction, because I needed to accomplish some one-time lookups to other components via ComponentManager. You may need to do the same.
Here's my action (with all the actual meat taken out because it's only for developer use temporarily and could introduce a security issue - OK i'm paranoid) and some comments added to demonstrate functionality you may want but I didn't need. Good luck- Geoff package com.crosswalk.cocoon.acting; import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.acting.ComposerAction; import java.util.Map; import java.util.HashMap; import org.apache.cocoon.environment.Redirector; import org.apache.cocoon.environment.Request; import org.apache.cocoon.environment.SourceResolver; import org.apache.cocoon.environment.ObjectModelHelper; import org.apache.cocoon.components.store.StoreJanitor; import org.apache.cocoon.components.store.Store; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentManager; public class CacheClearAction extends ComposerAction { private Store cache; public void compose (ComponentManager manager) throws ComponentException { super.compose(manager); this.cache = (Store)this.manager.lookup(Store.TRANSIENT_CACHE); } public Map act (Redirector redirector, SourceResolver resolver, Map objectModel, String source, Parameters params) { // My particular action didn't need to return any values - most do. // If I needed to return something, I'd use the map commented out here // and return it instead of org.apache.cocoon.acting.AbstractAction.EMPTY_MAP. // In the sitemap after this action {key} should produce "value". //Map availableToSitemap = new HashMap(); //availableToSitemap.put("key","value"); // String paramICareAbout; Request request = ObjectModelHelper.getRequest(objectModel); if (request == null) { // getLogger() provides a handle to the action's logger. // getLogger().info(), etc. gives you a different logging level. getLogger().error("RequestInfoAction: no request object!"); // if the action fails, you should return null and all nested sitemap items will not execute. return(null); } request.getParameter("paramName"); // Code missing - do some stuff with the request parameters. return EMPTY_MAP; // return availableToSitemap; } } > -----Original Message----- > From: gorillacommunications [mailto:[EMAIL PROTECTED]] > Sent: Monday, June 10, 2002 11:17 AM > To: [EMAIL PROTECTED] > Subject: writing actions > > > Hi All, > > I am trying to write an action for my application. > I have this line in my sitemap to define the action. > <map:action logger="sitemap.action.gs-login" name="login" > src="com.kg.gs.GSLogin"/> > > > My class is in a jar file in \tomcat\webapps\cocoon\WEB-INF\lib. Is > this the correct place for it? Also, I am confused about what my class > needs to extend. Is it AbstractAction? The method I want to call > is "login". I would love to see an example > of a class someone has written, so I can figure out how to write my > class and how to return a value. > > I also have this pipeline: > <map:pipeline> > <map:match pattern="login"> > <map:act type="gs-login"> > <!-- how do I get the return value and pass it to the > redirect page? --> > <map:redirect-to uri="gs"/> > </map:act> > <map:serialize type="html"/> > </map:match> > </map:pipeline> > > Obviously, I'm doing something wrong, because I get the > following error > when I try to run my application: > > type fatal > > message Error in sitemap configuration : com.kg.gs.GSLogin > > description > org.apache.avalon.framework.configuration.ConfigurationExcepti > on: Error in > sitemap configuration : com.kg.gs.GSLogin > > sender org.apache.cocoon.servlet.CocoonServlet > > source Cocoon servlet > > stack-trace > > org.apache.avalon.framework.configuration.ConfigurationExcepti > on: Error in > sitemap configuration : com.kg.gs.GSLogin > at > org.apache.cocoon.www.file_.D_.tomcat.webapps.GorillaStation.s > itemap_xmap.co > nfigure(D:\tomcat\work\localhost\GorillaStation\cocoon-files\o > rg/apache/coco > on/www/file_/D_/tomcat/webapps/GorillaStation\sitemap_xmap.java:498) > at > org.apache.avalon.excalibur.component.DefaultComponentFactory. > newInstance(De > faultComponentFactory.java:172) > at > org.apache.avalon.excalibur.component.ThreadSafeComponentHandl > er.initialize( > ThreadSafeComponentHandler.java:84) > at > org.apache.cocoon.components.language.generator.GeneratorSelec > tor.addGenerat > or(GeneratorSelector.java:170) > at > org.apache.cocoon.components.language.generator.ProgramGenerat > orImpl.createR > esource(ProgramGeneratorImpl.java:332) > at > org.apache.cocoon.components.language.generator.ProgramGenerat > orImpl.load(Pr > ogramGeneratorImpl.java:291) > at org.apache.cocoon.sitemap.Handler.run(Handler.java:270) > at java.lang.Thread.run(Thread.java:484) > > > request-uri > > /GorillaStation/gs > > path-info > > gs > Can anyone tell me what I'm doing wrong? > Many thanks, > Leona > > > > > > --------------------------------------------------------------------- > Please check that your question has not already been answered in the > FAQ before posting. <http://xml.apache.org/cocoon/faq/index.html> > > To unsubscribe, e-mail: <[EMAIL PROTECTED]> > For additional commands, e-mail: <[EMAIL PROTECTED]> > --------------------------------------------------------------------- Please check that your question has not already been answered in the FAQ before posting. <http://xml.apache.org/cocoon/faq/index.html> To unsubscribe, e-mail: <[EMAIL PROTECTED]> For additional commands, e-mail: <[EMAIL PROTECTED]>