1 64 65 package com.jcorporate.expresso.ext.taglib; 66 67 import com.jcorporate.expresso.core.i18n.Messages; 68 import com.jcorporate.expresso.ext.struts.taglib.bean.ExMessageTag; 69 import com.jcorporate.expresso.kernel.util.FastStringBuffer; 70 71 import javax.servlet.jsp.JspTagException ; 72 import javax.servlet.jsp.JspWriter ; 73 import javax.servlet.jsp.PageContext ; 74 import javax.servlet.jsp.tagext.Tag ; 75 import javax.servlet.jsp.tagext.TagSupport ; 76 import java.io.IOException ; 77 import java.util.Locale ; 78 import java.util.StringTokenizer ; 79 80 81 88 public class TableHead 89 extends TagSupport { 90 91 94 private String value = null; 95 96 99 private String keys = null; 100 101 public TableHead() { 102 super(); 103 } 104 105 public int doStartTag() 106 throws javax.servlet.jsp.JspTagException { 107 Locale l = (Locale ) pageContext.getAttribute(Messages.LOCALE_KEY, 108 PageContext.SESSION_SCOPE); 109 110 if (l == null) { 111 l = Locale.getDefault(); 112 } 113 114 boolean translate = false; 115 116 if (keys != null) { 117 value = keys; 118 translate = true; 119 } 120 try { 121 if (value != null) { 122 FastStringBuffer fsb = FastStringBuffer.getInstance(); 123 try { 124 JspWriter writer = pageContext.getOut(); 125 StringTokenizer stk = new StringTokenizer (value, "|"); 126 fsb.append("<tr class=\"jc-default\">"); 127 128 while (stk.hasMoreTokens()) { 129 fsb.append("<th scope=\"col\" class=\"jc-tabletitle\" nowrap>"); 130 131 if (translate) { 132 fsb.append(getString(l, stk.nextToken())); 133 } else { 134 fsb.append(stk.nextToken()); 135 } 136 fsb.append("</th>"); 137 } 138 fsb.append("</tr>\n"); 139 writer.print(fsb.toString()); 140 } finally { 141 fsb.release(); 142 } 143 } else { 144 throw new JspTagException ("No value supplied"); 145 } 146 } catch (IOException ie) { 147 throw new JspTagException ("IO Exception:" + ie.getMessage()); 148 } 149 150 return Tag.SKIP_BODY; 151 } 152 153 public java.lang.String getValue() { 154 return value; 155 } 156 157 public void setValue(java.lang.String newValue) { 158 value = newValue; 159 } 160 161 public java.lang.String getKeys() { 162 return keys; 163 } 164 165 public void setKeys(java.lang.String newKeys) { 166 keys = newKeys; 167 } 168 169 private String getString(Locale l, String key) { 170 String schemaClass = (String ) pageContext.getAttribute(ExMessageTag.SCHEMA_KEY, 171 PageContext.PAGE_SCOPE); 172 173 if (schemaClass != null) { 174 Object [] args = {}; 175 176 return Messages.getString(schemaClass, l, key, args); 177 } else { 178 return Messages.getString(l, key); 179 } 180 } 181 } 182 183 | Popular Tags |