1 12 package org.displaytag.util; 13 14 19 public class Anchor 20 { 21 22 25 private Href href; 26 27 30 private String linkText; 31 32 35 private HtmlAttributeMap attributeMap = new HtmlAttributeMap(); 36 37 42 public Anchor(Href linkHref, String linkBody) 43 { 44 this.href = linkHref; 45 this.linkText = linkBody; 46 } 47 48 52 public void setHref(Href linkHref) 53 { 54 this.href = linkHref; 55 } 56 57 61 public void setText(String linkBody) 62 { 63 this.linkText = linkBody; 64 } 65 66 70 public void setClass(String cssClass) 71 { 72 this.attributeMap.put(TagConstants.ATTRIBUTE_CLASS, cssClass); 73 } 74 75 79 public void setStyle(String style) 80 { 81 this.attributeMap.put(TagConstants.ATTRIBUTE_STYLE, style); 82 } 83 84 88 public void setTitle(String title) 89 { 90 this.attributeMap.put(TagConstants.ATTRIBUTE_TITLE, title); 91 } 92 93 97 private String getHrefString() 98 { 99 if (this.href == null) 100 { 101 return TagConstants.EMPTY_STRING; 102 } 103 return " HREF=\"" + this.href.toString() + "\""; } 105 106 110 public String getOpenTag() 111 { 112 113 if (this.attributeMap.size() == 0) 115 { 116 return TagConstants.TAG_OPEN + TagConstants.TAGNAME_ANCHOR + getHrefString() + TagConstants.TAG_CLOSE; 117 } 118 119 StringBuffer buffer = new StringBuffer (); 121 122 buffer.append(TagConstants.TAG_OPEN).append(TagConstants.TAGNAME_ANCHOR).append(getHrefString()); 123 124 buffer.append(this.attributeMap); 125 126 buffer.append(TagConstants.TAG_CLOSE); 127 128 return buffer.toString(); 129 } 130 131 135 public String getCloseTag() 136 { 137 return TagConstants.TAG_OPENCLOSING + TagConstants.TAGNAME_ANCHOR + TagConstants.TAG_CLOSE; 138 } 139 140 144 public String toString() 145 { 146 return getOpenTag() + this.linkText + getCloseTag(); 147 } 148 149 } | Popular Tags |