cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrea Pierini" <ml_apier...@maticad.it>
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:pipeline>
	<map:match pattern="progetticerp/*/**.jpg">
		<map:read type="imageresource" mime-type="image/jpg"
src="http://.../dati/{2}.jpg">
			<map:parameter name="width" value="{1}"/>
		</map:read>
	</map:match>
  </map:pipeline>

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

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

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;
    try
    {
        plainurl = params.getParameter("plainurl");
    } catch (org.apache.avalon.framework.parameters.ParameterException
e)
    {
        plainurl = "";
    }
    String encodedurl = plainurl.replaceAll(" ","%20");
    sitemapParams.put("encodedurl", encodedurl);
    /*
    getLogger().debug("plainurl: "+plainurl);
    getLogger().debug("encodedurl: "+encodedurl);
    sitemapParams.put("test","http://localhost/hello%20world.xml");
    sitemapParams.put("testplainurl", plainurl);
    sitemapParams.put("testencodedurl", encodedurl);
    */

    return sitemapParams;
  }

}  

************************** end action code ****************************
Bye
Andrea

_____________________________________________

Andrea Pierini
Maticad s.r.l. - www.maticad.it


> -----Messaggio originale-----
> Da: Sully [mailto:stinkyelf@yahoo.com]
> Inviato: venerdì 23 maggio 2003 9.27
> A: cocoon-users@xml.apache.org
> Oggetto: Re: R: encoding url for reader / better ways pass strings to
a
> 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
for
> > 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
files
> > 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
the
> > sitemap parameters if they are http urls. If someone is interested I
can
> > post the code.
> > Bye
> > Andrea Pierini
> 



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


Mime
View raw message