1 24 package org.riotfamily.components.locator; 25 26 import javax.servlet.http.HttpServletRequest ; 27 28 import org.riotfamily.common.web.util.PathCompleter; 29 import org.riotfamily.common.web.util.ServletUtils; 30 31 43 public class UrlComponentListLocator extends AbstractComponentListLocator { 44 45 public static final String TYPE_URL = "url"; 46 47 private PathCompleter pathCompleter; 48 49 private String parameter; 50 51 public UrlComponentListLocator(PathCompleter pathCompleter) { 52 super(TYPE_URL); 53 this.pathCompleter = pathCompleter; 54 } 55 56 public void setParameter(String parameter) { 57 this.parameter = parameter; 58 } 59 60 protected String getPath(HttpServletRequest request) { 61 String path = ServletUtils.getOriginatingPathWithoutServletMapping(request); 62 if (parameter != null) { 63 String value = request.getParameter(parameter); 64 if (value != null) { 65 StringBuffer sb = new StringBuffer (path); 66 sb.append('?').append(parameter).append('=').append(value); 67 return sb.toString(); 68 } 69 } 70 return path; 71 } 72 73 78 protected String getParentPath(String path) { 79 int i = path.lastIndexOf('/'); 80 if (i > 0) { 81 return path.substring(0, i); 82 } 83 return null; 84 } 85 86 protected String getUrlForPath(String path) { 87 return pathCompleter.addServletMapping(path); 88 } 89 } 90 | Popular Tags |