1 17 18 package com.finalist.jag.taglib; 19 20 21 import com.finalist.jag.*; 22 23 import java.util.*; 24 25 26 47 public class VariableTag extends TagBodySupport { 48 49 50 private String name = null; 51 52 private String list; 53 54 55 62 public String getName() { 63 return (this.name); 64 } 65 66 73 public void setName(String name) { 74 this.name = name; 75 } 76 77 public String getList() { 78 return list; 79 } 80 81 public void setList(String list) { 82 this.list = list; 83 } 84 85 86 95 public int doStartTag() throws JagException { 96 return (EVAL_PAGE); 97 } 98 99 110 public int doAfterBodyTag() throws JagException { 111 Object result; 112 String body = getBodyText(); 113 int opentagPos = body.indexOf("jag:variable"); 114 int closetagPos = body.indexOf("/jag:variable"); 115 if (opentagPos != -1 && closetagPos != -1) { 116 body = body.substring(opentagPos + 2, closetagPos - 1); 118 setBodyText(body); 119 return EVAL_BODY_TAG; 120 121 } else if (opentagPos != -1 && closetagPos == -1) { 122 result = "true"; 125 126 } else { 127 Set previous = null; 128 if (isList()) { 129 previous = ((Set) getPageContext().getAttribute(name)); 130 if (previous == null) { 131 previous = new HashSet(); 132 } 133 previous.add(body.trim()); 134 } 135 136 if (previous == null) { 137 result = body.trim(); 138 } else { 139 result = previous; 140 } 141 } 142 getPageContext().setAttribute(name, result); 143 return SKIP_CLEAR_BODY; 144 } 145 146 private boolean isList() { 147 return list != null && "true".equalsIgnoreCase(list.trim()); 148 } 149 } | Popular Tags |