1 23 24 package org.dbforms.taglib; 25 26 import org.apache.commons.logging.Log; 27 import org.apache.commons.logging.LogFactory; 28 29 import org.dbforms.util.*; 30 31 import java.util.List ; 32 import java.util.StringTokenizer ; 33 34 import javax.servlet.jsp.*; 35 36 37 38 46 public class JavascriptArrayTag extends TagSupportWithScriptHandler 47 implements DataContainer, javax.servlet.jsp.tagext.TryCatchFinally { 48 private static Log logCat = LogFactory.getLog(JavascriptArrayTag.class 49 .getName()); private List embeddedData = null; 51 private String name = null; 52 53 61 public void setEmbeddedData(List embeddedData) { 62 this.embeddedData = embeddedData; 63 } 64 65 66 71 public IEscaper getEscaper() { 72 return getConfig() 73 .getEscaper(); 74 } 75 76 77 82 public void setName(String name) { 83 this.name = name; 84 } 85 86 87 94 public void doCatch(Throwable t) throws Throwable { 95 throw t; 96 } 97 98 99 107 public int doEndTag() throws javax.servlet.jsp.JspException { 108 StringBuffer tagBuf = new StringBuffer (); 109 110 if (embeddedData == null) { logCat.warn("No EmbeddedData provide for javascriptArray TagLib " 112 + name); 113 114 return EVAL_PAGE; 115 } else { 116 tagBuf.append("\n<script language=\"javascript\">\n"); 117 tagBuf.append(" var " + name + " = new Array();\n"); 118 119 int embeddedDataSize = embeddedData.size(); 120 121 for (int i = 0; i < embeddedDataSize; i++) { 122 KeyValuePair aKeyValuePair = (KeyValuePair) embeddedData.get(i); 123 String aKey = aKeyValuePair.getKey(); 124 tagBuf.append(" ") 125 .append(name) 126 .append("[") 127 .append(i) 128 .append("] = new Array('") 129 .append(aKey) 130 .append("'"); 131 132 String aValue = aKeyValuePair.getValue(); 133 134 StringTokenizer st = new StringTokenizer (aValue, ","); 135 136 while (st.hasMoreTokens()) 137 tagBuf.append(",'") 138 .append(st.nextToken()) 139 .append("'"); 140 141 tagBuf.append(");\n"); 142 } 143 144 tagBuf.append("</script>\n"); 145 } 146 147 try { 148 pageContext.getOut() 149 .write(tagBuf.toString()); 150 } catch (java.io.IOException ioe) { 151 throw new JspException("IO Error: " + ioe.getMessage()); 152 } 153 154 return EVAL_PAGE; 155 } 156 157 158 161 public void doFinally() { 162 name = null; 163 embeddedData = null; 164 } 165 166 167 174 public int doStartTag() throws javax.servlet.jsp.JspException { 175 return EVAL_BODY_BUFFERED; 176 } 177 } 178 | Popular Tags |