1 24 package org.riotfamily.riot.list.ui.render; 25 26 import java.io.PrintWriter ; 27 28 import org.riotfamily.common.beans.PropertyUtils; 29 import org.riotfamily.common.markup.Html; 30 import org.riotfamily.common.markup.TagWriter; 31 import org.riotfamily.common.web.util.ServletUtils; 32 import org.riotfamily.riot.list.command.core.LinkCommand; 33 34 37 public class LinkRenderer implements CellRenderer { 38 39 private String prefix; 40 41 private String suffix; 42 43 private String target; 44 45 private String messageKey; 46 47 private String titleMessageKey; 48 49 52 public void setProperty(String property) { 53 } 54 55 public void setTarget(String target) { 56 this.target = target; 57 } 58 59 public void setPrefix(String prefix) { 60 this.prefix = prefix; 61 } 62 63 public void setSuffix(String suffix) { 64 this.suffix = suffix; 65 } 66 67 public void setMessageKey(String messageKey) { 68 this.messageKey = messageKey; 69 } 70 71 public void setTitleMessageKey(String titleMessageKey) { 72 this.titleMessageKey = titleMessageKey; 73 } 74 75 public void render(String propertyName, Object item, RenderContext context, 76 PrintWriter writer) { 77 78 if (item != null) { 79 StringBuffer url = new StringBuffer (); 80 if (prefix != null) { 81 url.append(prefix); 82 } 83 if (propertyName != null) { 84 url.append(PropertyUtils.getProperty(item, propertyName)); 85 } 86 else { 87 url.append(item); 88 } 89 if (suffix != null) { 90 url.append(suffix); 91 } 92 String href = url.toString(); 93 if (!ServletUtils.isAbsoluteUrl(href) && href.startsWith("/")) { 94 href = context.getContextPath() + href; 95 } 96 TagWriter tag = new TagWriter(writer); 97 tag.start(Html.A); 98 99 tag.attribute(Html.A_HREF, href); 100 if (target != null) { 101 tag.attribute(Html.A_TARGET, target); 102 } 103 if (titleMessageKey != null) { 104 tag.attribute(Html.TITLE, context.getMessageResolver() 105 .getMessage(titleMessageKey)); 106 } 107 if (messageKey != null) { 108 tag.body(context.getMessageResolver().getMessage(messageKey)); 109 } 110 tag.end(); 111 } 112 } 113 } 114 | Popular Tags |