Well, in the meantime I read up more on ServiceEncoders and came to the 
conclusion that it shouldn't be too tough, so I went ahead and wrote one that 
seems to work fine. It was almost done by the time I got your post. The thing I 
like about this solution is that it doesn't require another library. :) I 
include the code below for anybody who's interested.

Caveats: 1) It assumes /app instead of whatever your application might be 
using, 2) it's designed to work only for one page per instance, rather than all 
external pages in your app, and 3) it requires Java 1.5 (because of the for 
loop construct). All of these things could be changed easily enough. Obviously, 
I hope it's useful, but no warranty, yada yada yada.

Robert

=====

package mshare.web.tapestry.page;

import org.apache.tapestry.engine.ServiceEncoder;
import org.apache.tapestry.engine.ServiceEncoding;
import org.apache.tapestry.services.ServiceConstants;

/**
 * Decodes old Tapestry 3 external page URLs and converts them to Tapestry 4 
URLs. It does not
 * re-encode them back to Tapestry 3 URLs, since this is only here to provide 
backward support for
 * the Tapestry 3 URLs.
 * @author Robert J. Walker
 */
public class Tap3ExternalPageEncoder implements ServiceEncoder {
        private static final String TAP_3_PARAM_NAME = "service";
        private static final String EXTERNAL_SERVICE = "external";
        private static final String SERVICE_PARAMETER = "sp";

        private String pageName;

        public void decode(ServiceEncoding encoding) {
                String tap3Param = encoding.getParameterValue(TAP_3_PARAM_NAME);

                // No service parameter?
                if(tap3Param == null) {
                        return;
                }

                String[] arr = tap3Param.split("/");

                // Serivce name has a slash?
                if(arr.length != 2) {
                        return;
                }

                // It's the external service?
                if(!EXTERNAL_SERVICE.equals(arr[0])) {
                        return;
                }

                // Right page?
                if(!arr[1].equals(pageName)) {
                        return;
                }

                // Update servlet path
                StringBuilder path = new StringBuilder("/app?");
                path.append(ServiceConstants.SERVICE)
                        .append('=')
                        .append(EXTERNAL_SERVICE)
                        .append('&')
                        .append(ServiceConstants.PAGE)
                        .append('=')
                        .append(pageName);

                for(String param : 
encoding.getParameterValues(SERVICE_PARAMETER)) {
                        path.append("&sp=").append(param);
                }

                encoding.setServletPath(path.toString());

                // Update parameter values
                encoding.setParameterValue(ServiceConstants.SERVICE, 
EXTERNAL_SERVICE);
                encoding.setParameterValue(ServiceConstants.PAGE, pageName);
        }

        public void encode(ServiceEncoding encoding) {
                // Do nothing here; we don't want to encode the URLs back to 
Tapestry 3 style
        }

        public void setPageName(String pageName) {
                this.pageName = pageName;
        }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to