cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrea Pierini" <>
Subject R: R: encoding url for reader / better ways pass strings to a reader?
Date Fri, 23 May 2003 07:43:23 GMT
The pipeline

	<map:match pattern="progetticerp/*/**.jpg">
		<map:read type="imageresource" mime-type="image/jpg"
			<map:parameter name="width" value="{1}"/>

doesn't work if {2} contains spaces because they are not encoded in
%20s. So I modified the pipeline as follow:

	<map:match pattern="progetticerp/*/**.jpg">
		<map:act type="urlencodeaction">
			<map:parameter name="plainurl"
			<map:read type="imageresource"
mime-type="image/jpg" src="{encodedurl}">
				<map:parameter name="width"

The action "urlencodeaction" reads the "plainurl" parameter and encodes
it in the "encodedurl" parameter. You can find the action code below,
you should compile and install it following the cocoon documentation
regarding actions. Please note that I substitute spaces with %20s
manually because I couldn't get URLEncoder.encode() to work. Some work
must still be done.

************************** begin action code

package urlencodeaction;

import org.apache.avalon.framework.parameters.Parameters;
import org.apache.cocoon.acting.AbstractAction;
import java.util.Map;
import java.util.HashMap;
import org.apache.cocoon.environment.ObjectModelHelper;
import org.apache.cocoon.environment.Redirector;
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.xml.sax.EntityResolver;

public class urlencodeaction extends AbstractAction {

  public Map act (Redirector redirector,
                  SourceResolver resolver,
                  Map objectModel,
                  String source,
                  Parameters params) {
    // getLogger().debug("Starting urlencode action ...");
    Map sitemapParams = new HashMap();
    String plainurl;
        plainurl = params.getParameter("plainurl");
    } catch (org.apache.avalon.framework.parameters.ParameterException
        plainurl = "";
    String encodedurl = plainurl.replaceAll(" ","%20");
    sitemapParams.put("encodedurl", encodedurl);
    getLogger().debug("plainurl: "+plainurl);
    getLogger().debug("encodedurl: "+encodedurl);
    sitemapParams.put("testplainurl", plainurl);
    sitemapParams.put("testencodedurl", encodedurl);

    return sitemapParams;


************************** end action code ****************************


Andrea Pierini
Maticad s.r.l. -

> -----Messaggio originale-----
> Da: Sully []
> Inviato: venerdì 23 maggio 2003 9.27
> A:
> Oggetto: Re: R: encoding url for reader / better ways pass strings to
> reader?
> please do post your code
> you are correct in your examples, my problem is that if you match an
> encoded string and then pass that to the src it gets passed in as
> unencoded with no way (that I could find) to fix it.
> Andrea Pierini wrote:
> > I don't think it's a bug but a behaviour. What you put in the "src"
> > argument of a component in the sitemap is non encoded, so if you put
> > example src="http://test/ /test" you get an error, while if you put
> > src="http://test/%20/test" everything works fine. This is ok for
> > in the file system but not ok for files on the web.
> > I've solved the problem writing a little action in java to encode
> > sitemap parameters if they are http urls. If someone is interested I
> > post the code.
> > Bye
> > Andrea Pierini

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message