1 16 17 package org.springframework.ui.context.support; 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 22 import org.springframework.context.ApplicationContext; 23 import org.springframework.ui.context.HierarchicalThemeSource; 24 import org.springframework.ui.context.ThemeSource; 25 26 35 public abstract class UiApplicationContextUtils { 36 37 42 public static final String THEME_SOURCE_BEAN_NAME = "themeSource"; 43 44 45 private static final Log logger = LogFactory.getLog(UiApplicationContextUtils.class); 46 47 48 56 public static ThemeSource initThemeSource(ApplicationContext context) { 57 if (context.containsLocalBean(THEME_SOURCE_BEAN_NAME)) { 58 ThemeSource themeSource = (ThemeSource) context.getBean(THEME_SOURCE_BEAN_NAME, ThemeSource.class); 59 if (context.getParent() instanceof ThemeSource && themeSource instanceof HierarchicalThemeSource) { 61 HierarchicalThemeSource hts = (HierarchicalThemeSource) themeSource; 62 if (hts.getParentThemeSource() == null) { 63 hts.setParentThemeSource((ThemeSource) context.getParent()); 66 } 67 } 68 if (logger.isDebugEnabled()) { 69 logger.debug("Using ThemeSource [" + themeSource + "]"); 70 } 71 return themeSource; 72 } 73 else { 74 HierarchicalThemeSource themeSource = null; 77 if (context.getParent() instanceof ThemeSource) { 78 themeSource = new DelegatingThemeSource(); 79 themeSource.setParentThemeSource((ThemeSource) context.getParent()); 80 } 81 else { 82 themeSource = new ResourceBundleThemeSource(); 83 } 84 if (logger.isDebugEnabled()) { 85 logger.debug("Unable to locate ThemeSource with name '" + THEME_SOURCE_BEAN_NAME + 86 "': using default [" + themeSource + "]"); 87 } 88 return themeSource; 89 } 90 } 91 92 } 93 | Popular Tags |