1 package org.apache.turbine.util.template; 2 3 18 19 import java.util.Map ; 20 import java.util.HashMap ; 21 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 25 import org.apache.turbine.services.template.TurbineTemplate; 26 import org.apache.turbine.util.RunData; 27 import org.apache.turbine.util.uri.URIConstants; 28 29 30 40 public class TemplateInfo 41 { 42 43 private static Log log = LogFactory.getLog(TemplateInfo.class); 44 45 46 47 public static final String NAVIGATION_TEMPLATE = "00navigation_template00"; 48 public static final String LAYOUT_TEMPLATE = "00layout_template00"; 49 public static final String SERVICE_NAME = "template_service"; 50 51 52 private RunData data = null; 53 54 55 private Map tempStorage = null; 56 57 62 public TemplateInfo(RunData data) 63 { 64 this.data = data; 65 tempStorage = new HashMap (10); 66 } 67 68 73 public String getNavigationTemplate() 74 { 75 return getString(TemplateInfo.NAVIGATION_TEMPLATE); 76 } 77 78 83 public void setNavigationTemplate(String v) 84 { 85 setTemp(TemplateInfo.NAVIGATION_TEMPLATE, v); 86 } 87 88 94 public String getScreenTemplate() 95 { 96 return data.getParameters().getString(URIConstants.CGI_TEMPLATE_PARAM, null); 97 } 98 99 105 public void setScreenTemplate(String v) 106 { 107 data.getParameters().setString(URIConstants.CGI_TEMPLATE_PARAM, v); 108 109 try 114 { 115 setLayoutTemplate(TurbineTemplate.getLayoutTemplateName(v)); 116 } 117 catch (Exception e) 118 { 119 122 } 123 } 124 125 130 public String getLayoutTemplate() 131 { 132 String value = getString(TemplateInfo.LAYOUT_TEMPLATE); 133 return value; 134 } 135 136 141 public void setLayoutTemplate(String v) 142 { 143 setTemp(TemplateInfo.LAYOUT_TEMPLATE, v); 144 } 145 146 153 public Object getTemplateContext(String name) 154 { 155 return getTemp(name); 156 } 157 158 164 public void setTemplateContext(String name, Object v) 165 { 166 setTemp(name, v); 167 } 168 169 174 public String getService() 175 { 176 return getString(TemplateInfo.SERVICE_NAME); 177 } 178 179 184 public void setService(String v) 185 { 186 setTemp(TemplateInfo.SERVICE_NAME, v); 187 } 188 189 195 public Object getTemp(String name) 196 { 197 return tempStorage.get(name); 198 } 199 200 207 public Object getTemp(String name, Object def) 208 { 209 try 210 { 211 Object val = tempStorage.get(name); 212 return (val != null) ? val : def; 213 } 214 catch (Exception e) 215 { 216 return def; 217 } 218 } 219 220 226 public void setTemp(String name, Object value) 227 { 228 tempStorage.put(name, value); 229 } 230 231 237 public String [] getStringArray(String name) 238 { 239 String [] value = null; 240 Object object = getTemp(name, null); 241 if (object != null) 242 { 243 value = (String []) object; 244 } 245 return value; 246 } 247 248 254 public String getString(String name) 255 { 256 String value = null; 257 Object object = getTemp(name, null); 258 if (object != null) 259 { 260 value = (String ) object; 261 } 262 return value; 263 } 264 265 272 public Object removeTemp(String name) 273 { 274 return tempStorage.remove(name); 275 } 276 277 282 public Object [] getTempKeys() 283 { 284 return tempStorage.keySet().toArray(); 285 } 286 } 287 | Popular Tags |