1 16 17 package org.springframework.web.portlet.handler; 18 19 import java.util.HashMap ; 20 import java.util.Iterator ; 21 import java.util.Map ; 22 import java.util.Properties ; 23 24 import javax.portlet.PortletMode; 25 import javax.portlet.PortletRequest; 26 27 import org.springframework.beans.BeansException; 28 import org.springframework.util.CollectionUtils; 29 30 51 public class PortletModeHandlerMapping extends AbstractMapBasedHandlerMapping { 52 53 private final Map portletModeMap = new HashMap (); 54 55 56 60 public void setMappings(Properties mappings) { 61 this.portletModeMap.putAll(mappings); 62 } 63 64 69 public void setPortletModeMap(Map portletModeMap) { 70 this.portletModeMap.putAll(portletModeMap); 71 } 72 73 74 79 public void initApplicationContext() throws BeansException { 80 super.initApplicationContext(); 81 registerHandlers(this.portletModeMap); 82 } 83 84 89 protected void registerHandlers(Map portletModeMap) throws BeansException { 90 if (CollectionUtils.isEmpty(portletModeMap)) { 91 logger.warn("Neither 'portletModeMap' nor 'mappings' set on PortletModeHandlerMapping"); 92 } 93 else { 94 for (Iterator it = portletModeMap.entrySet().iterator(); it.hasNext();) { 95 Map.Entry entry = (Map.Entry ) it.next(); 96 String modeKey = (String ) entry.getKey(); 97 PortletMode mode = new PortletMode(modeKey); 98 Object handler = entry.getValue(); 99 registerHandler(mode, handler); 100 } 101 } 102 } 103 104 105 108 protected Object getLookupKey(PortletRequest request) throws Exception { 109 return request.getPortletMode(); 110 } 111 112 } 113 | Popular Tags |