1 package org.apache.turbine.services.template.mapper; 2 3 18 19 import java.util.HashMap ; 20 import java.util.Map ; 21 22 import org.apache.commons.lang.StringUtils; 23 24 import org.apache.turbine.services.template.TurbineTemplate; 25 import org.apache.turbine.services.template.TemplateEngineService; 26 27 34 35 public abstract class BaseMapper 36 { 37 38 private boolean useCache = false; 39 40 41 private int cacheSize = 5; 42 43 44 private Map templateCache = null; 45 46 47 protected String defaultProperty; 48 49 50 protected char separator; 51 52 56 61 public BaseMapper() 62 { 63 } 64 65 69 public int getCacheSize() 70 { 71 return cacheSize; 72 } 73 74 78 public void setCacheSize(int cacheSize) 79 { 80 this.cacheSize = cacheSize; 81 } 82 83 87 public boolean isUseCache() 88 { 89 return useCache; 90 } 91 92 96 public void setUseCache(boolean useCache) 97 { 98 this.useCache = useCache; 99 } 100 101 105 public String getDefaultProperty() 106 { 107 return defaultProperty; 108 } 109 110 114 public void setDefaultProperty(String defaultProperty) 115 { 116 this.defaultProperty = defaultProperty; 117 } 118 119 123 public char getSeparator() 124 { 125 return separator; 126 } 127 128 132 public void setSeparator(char separator) 133 { 134 this.separator = separator; 135 } 136 137 140 public void init() 141 { 142 if (useCache) 143 { 144 templateCache = new HashMap (cacheSize); 145 } 146 } 147 148 159 160 public String getDefaultName(String template) 161 { 162 165 TemplateEngineService tes 166 = TurbineTemplate.getTemplateEngineService(template); 167 168 if (StringUtils.isEmpty(template) || (tes == null)) 169 { 170 return TurbineTemplate.getDefaultTemplate(); 171 } 172 173 String defaultName = (String ) tes.getTemplateEngineServiceConfiguration() 174 .get(defaultProperty); 175 176 return StringUtils.isEmpty(defaultName) 177 ? TurbineTemplate.getDefaultTemplate() 178 : defaultName; 179 } 180 181 188 public String getMappedName(String template) 189 { 190 if (StringUtils.isEmpty(template)) 191 { 192 return null; 193 } 194 195 if (useCache && templateCache.containsKey(template)) 196 { 197 return (String ) templateCache.get(template); 198 } 199 200 String res = doMapping(template); 201 202 if (useCache && StringUtils.isNotEmpty(res)) 204 { 205 templateCache.put(template, res); 206 } 207 208 return res; 209 } 210 211 220 public abstract String doMapping(String template); 221 } 222 | Popular Tags |