1 13 package info.magnolia.cms.gui.controlx.impl; 14 15 import info.magnolia.cms.gui.controlx.Control; 16 import info.magnolia.cms.gui.controlx.Renderer; 17 import info.magnolia.cms.i18n.Messages; 18 import info.magnolia.cms.i18n.MessagesManager; 19 import info.magnolia.cms.util.FreeMarkerUtil; 20 21 import java.util.HashMap ; 22 import java.util.Map ; 23 24 import org.apache.commons.lang.StringUtils; 25 26 27 32 public class TemplatedRenderer implements Renderer { 33 34 private String templateName; 35 36 39 public TemplatedRenderer() { 40 } 41 42 45 public TemplatedRenderer(String templateName) { 46 this.templateName = templateName; 47 } 48 49 53 public String render(Control control) { 54 Map data = new HashMap (); 55 data.put("this", control); 56 data.put("renderer", this); 57 return FreeMarkerUtil.process(this.getTemplateName(control), data); 58 } 59 60 65 public String getMessage(String key) { 66 return getMessages().getWithDefault(key, key); 67 } 68 69 73 public Messages getMessages() { 74 return MessagesManager.getMessages(); 75 } 76 77 80 protected String getTemplateName(Control control) { 81 if (this.templateName == null) { 82 return "/" + StringUtils.replace(control.getClass().getName(), ".", "/") + ".html"; 83 } 84 85 return this.templateName; 86 } 87 88 91 public String getTemplateName() { 92 return this.templateName; 93 } 94 95 98 public void setTemplateName(String templateName) { 99 this.templateName = templateName; 100 } 101 102 } 103 | Popular Tags |