You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Hensley, Richard" <Ri...@McKesson.com> on 2005/06/16 20:17:17 UTC

[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