1 16 17 18 package org.apache.webapp.admin; 19 20 21 import java.io.IOException ; 22 import java.net.URLEncoder ; 23 import java.util.ArrayList ; 24 import javax.servlet.http.HttpServletRequest ; 25 import javax.servlet.http.HttpServletResponse ; 26 import javax.servlet.jsp.JspException ; 27 import javax.servlet.jsp.JspWriter ; 28 import javax.servlet.jsp.PageContext ; 29 import javax.servlet.jsp.tagext.BodyTagSupport ; 30 import javax.servlet.jsp.tagext.Tag ; 31 32 33 52 53 public class ActionTag extends BodyTagSupport { 54 55 56 58 59 62 protected String label = null; 63 64 65 67 68 71 protected boolean selected = false; 72 73 public boolean getSelected() { 74 return (this.selected); 75 } 76 77 public void setSelected(boolean selected) { 78 this.selected = selected; 79 } 80 81 85 protected boolean disabled = false; 86 87 public boolean getDisabled() { 88 return (this.disabled); 89 } 90 91 public void setDisabled(boolean disabled) { 92 this.disabled = disabled; 93 } 94 95 98 protected String url = null; 99 100 public String getUrl() { 101 return (this.url); 102 } 103 104 public void setUrl(String url) { 105 this.url = url; 106 } 107 108 109 111 112 117 public int doStartTag() throws JspException { 118 119 this.label = null; 121 122 return (EVAL_BODY_TAG); 124 125 } 126 127 128 133 public int doAfterBody() throws JspException { 134 135 String label = bodyContent.getString(); 136 if (label != null) { 137 label = label.trim(); 138 if (label.length() > 0) 139 this.label = label; 140 } 141 return (SKIP_BODY); 142 143 } 144 145 146 151 public int doEndTag() throws JspException { 152 153 Tag parent = getParent(); 155 while ((parent != null) && !(parent instanceof ActionsTag)) { 156 parent = parent.getParent(); 157 } 158 if ((parent == null) || !(parent instanceof ActionsTag)) 159 throw new JspException ("Must be nested in an ActionsTag isntance"); 160 ActionsTag actions = (ActionsTag) parent; 161 162 HttpServletRequest request = 165 (HttpServletRequest ) pageContext.getRequest(); 166 HttpServletResponse response = 167 (HttpServletResponse ) pageContext.getResponse(); 168 String path = null; 169 if ((url != null) && (url.startsWith("/"))) { 170 path = request.getContextPath() + url; 171 } else { 172 path = url; 173 } 174 actions.addAction(label, selected, disabled, 175 response.encodeURL(path)); 176 177 return (EVAL_PAGE); 178 179 } 180 181 182 185 public void release() { 186 187 this.label = null; 188 this.selected = false; 189 this.disabled = false; 190 this.url = null; 191 192 } 193 194 195 } 196 | Popular Tags |