1 16 package org.ajaxtags.tags; 17 18 import java.io.IOException ; 19 20 import javax.servlet.jsp.JspException ; 21 import javax.servlet.jsp.JspWriter ; 22 import javax.servlet.jsp.tagext.TagSupport ; 23 24 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager; 25 26 32 public class AjaxTreeTag extends TagSupport { 33 private String baseUrl; 34 35 private String styleId; 36 37 private String preFunction; 38 39 private String postFunction; 40 41 private String errorFunction; 42 43 private String parser; 44 45 private String collapsedClass; 46 47 private String expandedClass; 48 49 private String parameters; 50 51 private String nodeClass; 52 53 private String treeClass; 54 55 public String getBaseUrl() { 56 return baseUrl; 57 } 58 59 public void setBaseUrl(String baseUrl) { 60 this.baseUrl = baseUrl; 61 } 62 63 public String getTreeClass() { 64 return treeClass; 65 } 66 67 public void setTreeClass(String treeClass) { 68 this.treeClass = treeClass; 69 } 70 71 public String getNodeClass() { 72 return nodeClass; 73 } 74 75 public void setNodeClass(String nodeClass) { 76 this.nodeClass = nodeClass; 77 } 78 79 public String getParameters() { 80 return parameters; 81 } 82 83 public void setParameters(String parameters) { 84 this.parameters = parameters; 85 } 86 87 @Override 88 public int doStartTag() throws JspException { 89 this.baseUrl = (String ) ExpressionEvaluatorManager.evaluate("baseUrl", 91 this.baseUrl, String .class, this, super.pageContext); 92 this.parameters = (String ) ExpressionEvaluatorManager.evaluate( 93 "parameters", this.parameters, String .class, this, 94 super.pageContext); 95 96 if (this.collapsedClass != null) 98 this.collapsedClass = (String ) ExpressionEvaluatorManager.evaluate( 99 "collapsedClass", this.collapsedClass, String .class, this, 100 super.pageContext); 101 if (this.nodeClass != null) 102 this.nodeClass = (String ) ExpressionEvaluatorManager.evaluate( 103 "nodeClass", this.nodeClass, String .class, this, 104 super.pageContext); 105 if (this.expandedClass != null) 106 this.expandedClass = (String ) ExpressionEvaluatorManager.evaluate( 107 "expandedClass", this.expandedClass, String .class, this, 108 super.pageContext); 109 if (this.treeClass != null) 110 this.treeClass = (String ) ExpressionEvaluatorManager.evaluate( 111 "treeClass", this.treeClass, String .class, this, 112 super.pageContext); 113 return SKIP_BODY; 114 } 115 116 public String getStyleId() { 117 return styleId; 118 } 119 120 public void setStyleId(String treeStyleId) { 121 this.styleId = treeStyleId; 122 } 123 124 public String getErrorFunction() { 125 return errorFunction; 126 } 127 128 public void setErrorFunction(String errorFunction) { 129 this.errorFunction = errorFunction; 130 } 131 132 public String getParser() { 133 return parser; 134 } 135 136 public void setParser(String parser) { 137 this.parser = parser; 138 } 139 140 public String getPostFunction() { 141 return postFunction; 142 } 143 144 public void setPostFunction(String postFunction) { 145 this.postFunction = postFunction; 146 } 147 148 public String getPreFunction() { 149 return preFunction; 150 } 151 152 public void setPreFunction(String preFunction) { 153 this.preFunction = preFunction; 154 } 155 156 public String getCollapsedClass() { 157 return collapsedClass; 158 } 159 160 public void setCollapsedClass(String collapsedClass) { 161 this.collapsedClass = collapsedClass; 162 } 163 164 public String getExpandedClass() { 165 return expandedClass; 166 } 167 168 public void setExpandedClass(String expandedClass) { 169 this.expandedClass = expandedClass; 170 } 171 172 @Override 173 public int doEndTag() throws JspException { 174 OptionsBuilder options = new OptionsBuilder(); 175 options.add("target", "elem", false); 176 177 if (this.collapsedClass != null) 178 options.add("collapsedClass", this.collapsedClass, true); 179 if (this.parameters != null) 180 options.add("parameters", this.parameters, true); 181 if (this.expandedClass != null) 182 options.add("expandedClass", this.expandedClass, true); 183 if (this.treeClass != null) 184 options.add("treeClass", this.treeClass, true); 185 if (this.nodeClass != null) 186 options.add("nodeClass", this.nodeClass, true); 187 if (this.preFunction != null) 188 options.add("preFunction", this.preFunction, false); 189 if (this.postFunction != null) 190 options.add("postFunction", this.postFunction, false); 191 if (this.errorFunction != null) 192 options.add("errorFunction", this.errorFunction, false); 193 if (this.parser != null) 194 options.add("parser", this.parser, false); 195 196 StringBuffer script = new StringBuffer (); 197 script.append("<div id=\""); 198 script.append(this.styleId); 199 script.append("\"></div>\n"); 200 script.append("<script type=\"text/javascript\">\n"); 201 script 202 .append("window.toggleTreeNode = function(elem, url, params) {\n"); 203 204 script.append("var aj_").append(this.styleId); 205 206 script.append(" = new AjaxJspTag.Tree(url, {\n").append( 207 options.toString()).append("});\n").append("}\n\n").append( 208 "addOnLoadEvent(function() {window.toggleTreeNode('").append( 209 styleId).append("', '").append(this.baseUrl).append("', null") 210 .append(");});\n").append("</script>\n\n"); 211 JspWriter writer = pageContext.getOut(); 212 try { 213 writer.println(script); 214 } catch (IOException e) { 215 throw new JspException (e.getMessage()); 216 } 217 return EVAL_PAGE; 218 } 219 220 @Override 221 public void release() { 222 baseUrl = null; 223 styleId = null; 224 preFunction = null; 225 postFunction = null; 226 errorFunction = null; 227 parser = null; 228 collapsedClass = null; 229 expandedClass = null; 230 parameters = null; 231 nodeClass = null; 232 treeClass = null; 233 super.release(); 234 } 235 } 236
| Popular Tags
|