1 15 package org.apache.tapestry.engine.encoders; 16 17 import org.apache.tapestry.INamespace; 18 import org.apache.tapestry.engine.ServiceEncoder; 19 import org.apache.tapestry.engine.ServiceEncoding; 20 import org.apache.tapestry.services.ServiceConstants; 21 22 31 public class PageServiceEncoder implements ServiceEncoder 32 { 33 private String _extension; 34 35 private String _serviceName; 36 37 public void encode(ServiceEncoding encoding) 38 { 39 String service = encoding.getParameterValue(ServiceConstants.SERVICE); 40 41 if (!service.equals(_serviceName)) 42 return; 43 44 String pageName = encoding.getParameterValue(ServiceConstants.PAGE); 45 46 48 if (pageName.indexOf(INamespace.SEPARATOR) >= 0) 49 return; 50 51 StringBuffer buffer = new StringBuffer ("/"); 52 buffer.append(pageName); 53 buffer.append('.'); 54 buffer.append(_extension); 55 56 encoding.setServletPath(buffer.toString()); 57 58 encoding.setParameterValue(ServiceConstants.SERVICE, null); 59 encoding.setParameterValue(ServiceConstants.PAGE, null); 60 } 61 62 public void decode(ServiceEncoding encoding) 63 { 64 String servletPath = encoding.getServletPath(); 65 66 int dotx = servletPath.lastIndexOf('.'); 67 if (dotx < 0) 68 return; 69 70 String extension = servletPath.substring(dotx + 1); 71 72 if (!extension.equals(_extension)) 73 return; 74 75 77 String page = servletPath.substring(1, dotx); 78 79 encoding.setParameterValue(ServiceConstants.SERVICE, _serviceName); 80 encoding.setParameterValue(ServiceConstants.PAGE, page); 81 } 82 83 public void setExtension(String extension) 84 { 85 _extension = extension; 86 } 87 88 public void setServiceName(String serviceName) 89 { 90 _serviceName = serviceName; 91 } 92 } | Popular Tags |