1 16 17 package org.springframework.web.context.support; 18 19 import java.util.Iterator ; 20 import java.util.Map ; 21 22 import javax.servlet.ServletContext ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 27 import org.springframework.web.context.ServletContextAware; 28 29 49 public class ServletContextAttributeExporter implements ServletContextAware { 50 51 protected final Log logger = LogFactory.getLog(getClass()); 52 53 private Map attributes; 54 55 64 public void setAttributes(Map attributes) { 65 this.attributes = attributes; 66 } 67 68 public void setServletContext(ServletContext servletContext) { 69 for (Iterator it = this.attributes.entrySet().iterator(); it.hasNext();) { 70 Map.Entry entry = (Map.Entry ) it.next(); 71 String attributeName = (String ) entry.getKey(); 72 if (logger.isWarnEnabled()) { 73 if (servletContext.getAttribute(attributeName) != null) { 74 logger.warn("Overwriting existing ServletContext attribute with name '" + attributeName + "'"); 75 } 76 } 77 servletContext.setAttribute(attributeName, entry.getValue()); 78 if (logger.isInfoEnabled()) { 79 logger.info("Exported ServletContext attribute with name '" + attributeName + "'"); 80 } 81 } 82 } 83 84 } 85 | Popular Tags |