1 15 package org.apache.tapestry.engine.encoders; 16 17 import org.apache.tapestry.INamespace; 18 import org.apache.tapestry.Tapestry; 19 import org.apache.tapestry.engine.ServiceEncoder; 20 import org.apache.tapestry.engine.ServiceEncoding; 21 import org.apache.tapestry.services.ServiceConstants; 22 23 31 public class DirectServiceEncoder implements ServiceEncoder 32 { 33 private String _statelessExtension; 34 35 private String _statefulExtension; 36 37 public void encode(ServiceEncoding encoding) 38 { 39 String service = encoding.getParameterValue(ServiceConstants.SERVICE); 40 if (!service.equals(Tapestry.DIRECT_SERVICE)) 41 return; 42 43 String pageName = encoding.getParameterValue(ServiceConstants.PAGE); 44 45 47 if (pageName.indexOf(INamespace.SEPARATOR) >= 0) 48 return; 49 50 String stateful = encoding.getParameterValue(ServiceConstants.SESSION); 51 String componentIdPath = encoding.getParameterValue(ServiceConstants.COMPONENT); 52 53 StringBuffer buffer = new StringBuffer ("/"); 54 buffer.append(pageName); 55 56 buffer.append(","); 57 buffer.append(componentIdPath); 58 59 buffer.append("."); 60 buffer.append(stateful != null ? _statefulExtension : _statelessExtension); 61 62 encoding.setServletPath(buffer.toString()); 63 64 encoding.setParameterValue(ServiceConstants.SERVICE, null); 65 encoding.setParameterValue(ServiceConstants.PAGE, null); 66 encoding.setParameterValue(ServiceConstants.SESSION, null); 67 encoding.setParameterValue(ServiceConstants.COMPONENT, null); 68 } 69 70 public void decode(ServiceEncoding encoding) 71 { 72 String servletPath = encoding.getServletPath(); 73 74 int dotx = servletPath.lastIndexOf('.'); 75 if (dotx < 0) 76 return; 77 78 String extension = servletPath.substring(dotx + 1); 79 80 if (!(extension.equals(_statefulExtension) || extension.equals(_statelessExtension))) 81 return; 82 83 int commax = servletPath.lastIndexOf(','); 84 85 String pageName = servletPath.substring(1, commax); 86 String componentIdPath = servletPath.substring(commax + 1, dotx); 87 88 encoding.setParameterValue(ServiceConstants.SERVICE, Tapestry.DIRECT_SERVICE); 89 encoding.setParameterValue(ServiceConstants.PAGE, pageName); 90 encoding.setParameterValue( 91 ServiceConstants.SESSION, 92 extension.equals(_statefulExtension) ? "T" : null); 93 encoding.setParameterValue(ServiceConstants.COMPONENT, componentIdPath); 94 } 95 96 public void setStatefulExtension(String statefulExtension) 97 { 98 _statefulExtension = statefulExtension; 99 } 100 101 public void setStatelessExtension(String statelessExtension) 102 { 103 _statelessExtension = statelessExtension; 104 } 105 } | Popular Tags |