Hi Davide,
 
page 244 of the book details the steps to build your component. You will need to add the jar files from the Cocoon lib directory to your classpath. Or use an IDE that does that for you (like Eclipse).
 
Best regards
 
Matthew Langham
-----Original Message-----
From: Davide [mailto:[EMAIL PROTECTED]
Sent: Tuesday, December 30, 2003 12:15 PM
To: [EMAIL PROTECTED]
Subject: How to compile an action?

Hi,  im'reading the Langham, Ziegler book and i'm trying to compile the first action:

package cxa.acting;

import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.avalon.framework.logger.AbstractLoggable;
import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.Action;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.SourceResolver;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class RandomAction
  extends AbstractLoggable
  implements Action, Initializable, ThreadSafe {

    protected Random generator;

    /**
     * Initialize this component
     */
    public void initialize() {
        // create a random generator
        this.generator = new Random( System.currentTimeMillis() );
    }

    public Map act(Redirector redirector,
                   SourceResolver resolver,
                   Map objectModel,
                   String src,
                   Parameters parameters)
    throws Exception {
        // get the range
        int min = parameters.getParameterAsInteger("min", 0);
        int max = parameters.getParameterAsInteger("max", 100);

        int random = this.generator.nextInt(max - min + 1) + min;

        if ( this.getLogger().isDebugEnabled() ) {
            this.getLogger().debug("Generated random between " + min + " and " + max + " : " + random);
        }

        // build resulting map
        Map map = new HashMap(1);
        map.put("number", "" + random);
        return map;
    }

}

I saved it as RandomAction.java and then...???
When i try to compile the action it gives me a lot of error probably because the classpath is not set correctly...
my classpath is:
CLASSPATH=C:\Program Files\j2sdk1.4.2_01\lib;C:\Program Files\jakarta-tomcat-5.0.16\webapps\cocoon\WEB-INF\lib

what is wrong??

thanks a lot

regards.

Reply via email to