You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by "Hensley, Richard" <Ri...@McKesson.com> on 2005/06/16 23:05:00 UTC
Encoding and ServiceEncoder enhancment suggestion
I had the use case below where I'm using a service encoder to custom map my
url parameters.
The problem I ran into was that I was not URL encoding and decoding my
parameters.
I wonder if it would be appropriate to add a couple of methods to the
org.apache.tapestry.engine.Encoding interface.
/**
* Formulate a servlet path based on the elements passed. The elements are
* URLEncoded and combined using the URL seperator character of '/'.
*
* When this method is called, the current value of the servlet path is
replaced with
* the elements assembled by this method.
*
* @see setServletPath
*/
void setServletPathElements(String[] elements);
and
/**
* Parse the servlet path into elements by splitting the servlet path
* based on the URL seperator character of '/', and URLDecoding each
* of the elements after the split.
*/
String[] getServletPathElements();
My reasoning would be that a very typical use to create a ServiceEncoder is
to assemble and disassemble a servlet path from various elements. I think
these two methods would make that easy. I don't intend that these methods
replace the current methods in Encoding, but enhance them.
What does the group think?
If this sounds reasonable, I could create a JIRA issue and code up a patch.
I know these two methods would make it easier to construct the
ServiceEncoders I've built so far.
Richard
-----Original Message-----
From: Hensley, Richard [mailto:Richard.Hensley@McKesson.com]
Sent: Thursday, June 16, 2005 11:36 AM
To: Tapestry users
Subject: RE: [Tapestry 4.0] ServiceEncoder Question
Doh!
URLEncoder.encode(value,enc)
URLDecoder.decode(value, enc)
-----Original Message-----
From: Hensley, Richard [mailto:Richard.Hensley@McKesson.com]
Sent: Thursday, June 16, 2005 11:17 AM
To: Tapestry users
Subject: [Tapestry 4.0] ServiceEncoder Question
I have a ServiceEncoder that encodes file names into a url. In one
particular case, there is a pound sign in the file name. Pound sign is not
being encoded in anyway, so the browser thinks it is an anchored link.
This is my encoder method.
/**
* @see
org.apache.tapestry.engine.ServiceEncoder#encode(org.apache.tapestry.engine.
ServiceEncoding)
*/
public void encode(ServiceEncoding encoding) {
if (!FileService.SERVICE_NAME.equals(encoding
.getParameterValue(ServiceConstants.SERVICE)))
return;
String fileName = encoding.getParameterValue(FileService.FILE_NAME);
String itemId = encoding.getParameterValue(FileService.FILE_ID);
StringBuffer sb = new StringBuffer();
sb.append(FILE);
sb.append(itemId).append('/');
sb.append(fileName);
encoding.setServletPath(sb.toString());
encoding.setParameterValue(FileService.FILE_NAME, null);
encoding.setParameterValue(ServiceConstants.SERVICE, null);
encoding.setParameterValue(FileService.FILE_ID, null);
}
I thought that the line
String fileName = encoding.getParameterValue(FileService.FILE_NAME);
would have taken care of the # sign for me, but it does not. What should be
taking care of the # sign? I did the following workaround.
String fileName = encoding.getParameterValue(FileService.FILE_NAME);
fileName = fileName.replaceAll("\\#","%23");
Works for me, but is there any other things that are going to bite me. What
tool should I be using to properly encode the filename?
Richard
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org