1 16 17 package org.springframework.web.servlet.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 org.springframework.beans.BeansException; 25 26 56 public class SimpleUrlHandlerMapping extends AbstractUrlHandlerMapping { 57 58 private final Map urlMap = new HashMap (); 59 60 61 69 public void setMappings(Properties mappings) { 70 this.urlMap.putAll(mappings); 71 } 72 73 81 public void setUrlMap(Map urlMap) { 82 this.urlMap.putAll(urlMap); 83 } 84 85 92 public Map getUrlMap() { 93 return this.urlMap; 94 } 95 96 97 101 public void initApplicationContext() throws BeansException { 102 super.initApplicationContext(); 103 registerHandlers(this.urlMap); 104 } 105 106 112 protected void registerHandlers(Map urlMap) throws BeansException { 113 if (urlMap.isEmpty()) { 114 logger.warn("Neither 'urlMap' nor 'mappings' set on SimpleUrlHandlerMapping"); 115 } 116 else { 117 Iterator it = urlMap.keySet().iterator(); 118 while (it.hasNext()) { 119 String url = (String ) it.next(); 120 Object handler = urlMap.get(url); 121 if (!url.startsWith("/")) { 123 url = "/" + url; 124 } 125 registerHandler(url, handler); 126 } 127 } 128 } 129 130 } 131 | Popular Tags |