1 package org.apache.turbine.util.template; 2 3 18 19 import org.apache.commons.logging.Log; 20 import org.apache.commons.logging.LogFactory; 21 import org.apache.ecs.HtmlColor; 22 import org.apache.ecs.html.Link; 23 import org.apache.ecs.html.Meta; 24 import org.apache.ecs.html.Script; 25 import org.apache.ecs.html.Style; 26 import org.apache.ecs.html.Title; 27 import org.apache.turbine.services.pull.ApplicationTool; 28 import org.apache.turbine.util.RunData; 29 30 48 public class TemplatePageAttributes 49 implements ApplicationTool 50 { 51 52 private static Log log = LogFactory.getLog(TemplatePageAttributes.class); 53 54 55 private RunData data = null; 56 57 58 private String cachedTitle = null; 59 60 63 public TemplatePageAttributes() 64 { 65 } 66 67 72 public TemplatePageAttributes(RunData data) 73 { 74 this.data = data; 75 } 76 77 83 public void init(Object data) 84 { 85 log.warn("This class is deprecated. Use HtmlPageAttributes instead."); 86 87 this.data = (RunData) data; 90 91 this.cachedTitle = null; 93 } 94 95 98 public void refresh() 99 { 100 } 102 103 110 public TemplatePageAttributes setTitle(String intitle) 111 { 112 Title title = data.getPage().getTitle(); 113 if (cachedTitle != null) 114 { 115 cachedTitle += intitle; 116 } 117 else 118 { 119 cachedTitle = intitle; 120 } 121 title.addElement(intitle); 122 return this; 123 } 124 125 132 public String getTitle() 133 { 134 if (cachedTitle == null) 135 { 136 return ""; 137 } 138 return cachedTitle; 139 } 140 141 147 public TemplatePageAttributes setStyleSheet(String url) 148 { 149 data.getPage().getHead().addElement(new Link() 150 .setRel("stylesheet").setType("text/css").setHref(url)); 151 return this; 152 } 153 154 162 public TemplatePageAttributes setStyleSheet(String url, String media) 163 { 164 data.getPage().getHead().addElement(new Link().setRel("stylesheet") 165 .setType("text/css").setMedia(media).setHref(url)); 166 return this; 167 } 168 169 175 public TemplatePageAttributes setStyle(String styleText) 176 { 177 data.getPage().getHead().addElement(new Style("text/css", styleText)); 178 return this; 179 } 180 181 187 public TemplatePageAttributes setScript(String url) 188 { 189 data.getPage().getHead().addElement(new Script().setSrc(url) 190 .setType("text/javascript").setLanguage("JavaScript")); 191 return this; 192 } 193 194 200 public TemplatePageAttributes setKeywords(String keywords) 201 { 202 data.getPage().getHead().addElement( 203 new Meta().setName("keywords").setContent(keywords)); 204 return this; 205 } 206 207 216 public TemplatePageAttributes setHttpEquiv(String httpEquiv, String content) 217 { 218 data.getPage().getHead().addElement( 219 new Meta().setHttpEquiv(httpEquiv).setContent(content)); 220 return this; 221 } 222 223 229 public TemplatePageAttributes setDescription(String description) 230 { 231 data.getPage().getHead().addElement( 232 new Meta().setName("description").setContent(description)); 233 return this; 234 } 235 236 242 public TemplatePageAttributes setBackground(String url) 243 { 244 data.getPage().getBody().setBackground(url); 245 return this; 246 } 247 248 256 public TemplatePageAttributes setBgColor(String color) 257 { 258 String hexColor = HtmlColor.getColor(color); 259 if (hexColor == null) 260 { 261 hexColor = color; 262 } 263 data.getPage().getBody().setBgColor(hexColor); 264 return this; 265 } 266 267 274 public TemplatePageAttributes setTextColor(String color) 275 { 276 String hexColor = HtmlColor.getColor(color); 277 if (hexColor == null) 278 { 279 hexColor = color; 280 } 281 data.getPage().getBody().setText(hexColor); 282 return this; 283 } 284 285 292 public TemplatePageAttributes setLinkColor(String color) 293 { 294 String hexColor = HtmlColor.getColor(color); 295 if (hexColor == null) 296 { 297 hexColor = color; 298 } 299 data.getPage().getBody().setLink(hexColor); 300 return this; 301 } 302 303 309 public TemplatePageAttributes setVlinkColor(String color) 310 { 311 String hexColor = HtmlColor.getColor(color); 312 if (hexColor == null) 313 { 314 hexColor = color; 315 } 316 data.getPage().getBody().setVlink(hexColor); 317 return this; 318 } 319 320 327 public TemplatePageAttributes addAttribute(String name, String value) 328 { 329 data.getPage().getBody().addAttribute(name, value); 330 return this; 331 } 332 333 338 public String toString() 339 { 340 return ""; 341 } 342 } 343 | Popular Tags |