1 12 package org.displaytag.tags; 13 14 import java.util.List ; 15 16 import javax.servlet.jsp.JspException ; 17 import javax.servlet.jsp.tagext.BodyTagSupport ; 18 19 import org.displaytag.exception.TagStructureException; 20 import org.displaytag.properties.MediaTypeEnum; 21 import org.displaytag.util.HtmlAttributeMap; 22 import org.displaytag.util.MediaUtil; 23 import org.displaytag.util.MultipleHtmlAttribute; 24 import org.displaytag.util.TagConstants; 25 26 27 32 public class CaptionTag extends BodyTagSupport implements MediaUtil.SupportsMedia 33 { 34 35 38 private static final long serialVersionUID = 899149338534L; 39 40 43 private HtmlAttributeMap attributeMap = new HtmlAttributeMap(); 44 45 48 private boolean firstIteration = true; 49 50 53 private List supportedMedia; 54 55 59 public void setStyle(String value) 60 { 61 this.attributeMap.put(TagConstants.ATTRIBUTE_STYLE, value); 62 } 63 64 68 public void setClass(String value) 69 { 70 this.attributeMap.put(TagConstants.ATTRIBUTE_CLASS, new MultipleHtmlAttribute(value)); 71 } 72 73 77 public void setId(String value) 78 { 79 this.attributeMap.put(TagConstants.ATTRIBUTE_ID, value); 80 } 81 82 86 public void setTitle(String value) 87 { 88 this.attributeMap.put(TagConstants.ATTRIBUTE_TITLE, value); 89 } 90 91 95 public void setLang(String value) 96 { 97 this.attributeMap.put(TagConstants.ATTRIBUTE_LANG, value); 98 } 99 100 104 public void setDir(String value) 105 { 106 this.attributeMap.put(TagConstants.ATTRIBUTE_DIR, value); 107 } 108 109 113 public String getOpenTag() 114 { 115 116 if (this.attributeMap.size() == 0) 117 { 118 return TagConstants.TAG_OPEN + TagConstants.TAGNAME_CAPTION + TagConstants.TAG_CLOSE; 119 } 120 121 StringBuffer buffer = new StringBuffer (); 122 123 buffer.append(TagConstants.TAG_OPEN).append(TagConstants.TAGNAME_CAPTION); 124 125 buffer.append(this.attributeMap); 126 127 buffer.append(TagConstants.TAG_CLOSE); 128 129 return buffer.toString(); 130 } 131 132 136 public String getCloseTag() 137 { 138 return TagConstants.TAG_OPENCLOSING + TagConstants.TAGNAME_CAPTION + TagConstants.TAG_CLOSE; 139 } 140 141 144 public int doStartTag() throws JspException 145 { 146 TableTag tableTag = (TableTag) findAncestorWithClass(this, TableTag.class); 147 148 if (tableTag == null) 149 { 150 throw new TagStructureException(getClass(), "caption", "table"); } 152 153 MediaTypeEnum currentMediaType = (MediaTypeEnum) this.pageContext.findAttribute(TableTag.PAGE_ATTRIBUTE_MEDIA); 154 if (!MediaUtil.availableForMedia(this, currentMediaType)) 155 { 156 return SKIP_BODY; 157 } 158 159 if (tableTag.isFirstIteration()) 161 { 162 this.firstIteration = true; 163 return 2; 165 } 166 167 this.firstIteration = false; 168 return SKIP_BODY; 169 } 170 171 174 public void setSupportedMedia(List media) 175 { 176 this.supportedMedia = media; 177 } 178 179 182 public List getSupportedMedia() 183 { 184 return this.supportedMedia; 185 } 186 187 191 public void setMedia(String media) 192 { 193 MediaUtil.setMedia(this, media); 194 } 195 196 199 public int doEndTag() throws JspException 200 { 201 if (this.firstIteration) 202 { 203 TableTag tableTag = (TableTag) findAncestorWithClass(this, TableTag.class); 204 205 if (tableTag == null) 206 { 207 throw new TagStructureException(getClass(), "caption", "table"); } 209 210 MediaTypeEnum currentMediaType = (MediaTypeEnum) this.pageContext 211 .findAttribute(TableTag.PAGE_ATTRIBUTE_MEDIA); 212 if (currentMediaType != null && !MediaUtil.availableForMedia(this, currentMediaType)) 213 { 214 return SKIP_BODY; 215 } 216 217 if (getBodyContent() != null) 218 { 219 tableTag.setCaption(getBodyContent().getString()); 221 tableTag.setCaptionTag(this); 223 } 224 225 this.firstIteration = false; 226 227 } 228 229 return EVAL_PAGE; 230 } 231 232 235 public void release() 236 { 237 super.release(); 238 this.attributeMap.clear(); 239 this.supportedMedia = null; 240 } 241 242 } | Popular Tags |