1 24 package org.riotfamily.components.locator; 25 26 import javax.servlet.http.HttpServletRequest ; 27 28 import org.riotfamily.components.ComponentListLocator; 29 import org.riotfamily.components.Location; 30 31 38 public abstract class AbstractComponentListLocator 39 implements ComponentListLocator { 40 41 private String type; 42 43 private SlotResolver slotResolver = new TemplateSlotResolver(); 44 45 public AbstractComponentListLocator(String type) { 46 this.type = type; 47 } 48 49 public void setSlotResolver(SlotResolver slotResolver) { 50 this.slotResolver = slotResolver; 51 } 52 53 public boolean supports(String type) { 54 return this.type.equals(type); 55 } 56 57 public Location getLocation(HttpServletRequest request) { 58 Location location = new Location(); 59 location.setType(getType(request)); 60 location.setPath(getPath(request)); 61 location.setSlot(slotResolver.getSlot(request)); 62 return location; 63 } 64 65 protected String getType(HttpServletRequest request) { 66 return type; 67 } 68 69 protected abstract String getPath(HttpServletRequest request); 70 71 public Location getParentLocation(Location location) { 72 Location parent = new Location(); 73 parent.setType(type); 74 parent.setPath(getParentPath(location.getPath())); 75 parent.setSlot(location.getSlot()); 76 return parent; 77 } 78 79 protected abstract String getParentPath(String path); 80 81 public String getUrl(Location location) { 82 return getUrlForPath(location.getPath()); 83 } 84 85 protected abstract String getUrlForPath(String path); 86 87 } 88 | Popular Tags |