You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Davide <da...@aliceposta.it> on 2003/12/30 12:15:21 UTC

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. 

Re: How to get the request parameters in a transformer?

Posted by Davide <da...@aliceposta.it>.
i don't think i need that transformer...i read the page but i seem it only 
encodes urls, it doesn't change them...

Best Regards,

Davide

At 09:32 AM 31-12-03, you wrote:
>Davide dijo:
> > Hi!
> >
> > I'm creating a transformer to modify link elements in an xhtml page (i.e.
> > a, img, link....);
> > I need to transform links from relative to absolute, so i need to know the
> > url of the last request to add it to the link...
>
>Can the encodeURL transformer do the work? See:
>
>http://cocoon.apache.org/2.1/userdocs/transformers/encodeurl-transformer.html
>
>Best Regards,
>
>Antonio Gallardo
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: How to get the request parameters in a transformer?

Posted by Antonio Gallardo <ag...@agsoftware.dnsalias.com>.
Davide dijo:
> Hi!
>
> I'm creating a transformer to modify link elements in an xhtml page (i.e.
> a, img, link....);
> I need to transform links from relative to absolute, so i need to know the
> url of the last request to add it to the link...

Can the encodeURL transformer do the work? See:

http://cocoon.apache.org/2.1/userdocs/transformers/encodeurl-transformer.html

Best Regards,

Antonio Gallardo


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


How to get the request parameters in a transformer?

Posted by Davide <da...@aliceposta.it>.
Hi!

I'm creating a transformer to modify link elements in an xhtml page (i.e. 
a, img, link....);
I need to transform links from relative to absolute, so i need to know the 
url of the last request to add it to the link...

this is the sitemap:

<map:match pattern="aggregate">
	<map:act type="auth-protect">
		<map:parameter name="handler" value="navigation"/>
		<map:parameter name="use-request-parameters" value="true"/>
		<map:generate type="serverpages" src="xsp/mcnavigator.xsp"/>
		<map:transform type="cinclude"/>
		<!-- adjust the tags position to create an xhtml page -->
		<map:transform type="xslt" src="style/mcnavigator.xsl"/>
		<!-- My Transformer!!! -->
		<map:transform type="AbsoluteLinkTransformer"/>
		<map:serialize type="xml"/>
		</map:act>			
	</map:match>
</map:match>

When i call the aggregate pipeline i pass it a parameter link in wich i put 
the url of the page i want to retreive (e.i. aggregate?link=www.w3.org), 
so... how to get my link parameter in the transformer?

thanks a lot, best regards.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: How to compile an action?

Posted by Matthew Langham <ml...@s-und-n.de>.
>>
I've added to the classpath the WEB-INF\lib dir that contains the jar files,
but i really don't know how to add jar files fo classpath. Yes, i could add
them manually, but i would like to know if it's possible to add to the
classpath all jar files in the dir automatically.
<<

You need to add each Jar file required individually. Using an IDE would be
easier as it does this for you (i.e. you don't need to manually extend your
classpath with each file).

More information on using Eclipse as a Cocoon IDE can be found on the Wiki
at: http://wiki.cocoondev.org

Matthew


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: How to compile an action?

Posted by Davide <da...@aliceposta.it>.
ok thanks a lot. I found that explanation. But my problem is another, 
because i'm a real beginner...

I've added to the classpath the WEB-INF\lib dir that contains the jar 
files, but i really don't know how to add jar files fo classpath. Yes, i 
could add them manually, but i would like to know if it's possible to add 
to the classpath all jar files in the dir automatically.

Do you also know some links to learn more about using eclipse to develop 
cocoon components?

regards.

At 12:33 PM 30-12-03, you wrote:
>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:dagarlas@aliceposta.it]
>Sent: Tuesday, December 30, 2003 12:15 PM
>To: users@cocoon.apache.org
>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.

RE: How to compile an action?

Posted by Matthew Langham <ml...@s-und-n.de>.
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:dagarlas@aliceposta.it]
  Sent: Tuesday, December 30, 2003 12:15 PM
  To: users@cocoon.apache.org
  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.