1 21 22 package org.opensubsystems.patterns.dialoglayout.www; 23 24 import java.io.UnsupportedEncodingException ; 25 import java.net.URLDecoder ; 26 import java.util.Iterator ; 27 import java.util.List ; 28 import java.util.logging.Level ; 29 import java.util.logging.Logger ; 30 31 import javax.servlet.jsp.JspException ; 32 import javax.servlet.jsp.tagext.BodyContent ; 33 34 import org.opensubsystems.core.util.Log; 35 import org.opensubsystems.core.util.StringUtils; 36 import org.opensubsystems.core.www.BlockElementTag; 37 import org.opensubsystems.core.www.TagUtils; 38 39 49 public class DoubleSelectOptionsTag extends BlockElementTag 50 { 51 53 56 private static final long serialVersionUID = 2484149237972831841L; 57 58 62 protected String m_strSeparator; 63 64 71 protected String m_strItemSeparator; 72 73 79 protected String m_strDecode; 80 81 83 86 private static Logger s_logger = Log.getInstance(DoubleSelectOptionsTag.class); 87 88 90 93 public DoubleSelectOptionsTag() 94 { 95 super("", BlockElementTag.DIV_BLOCK_ELEMENT); 96 97 m_strSeparator = null; 98 m_strItemSeparator = null; 99 m_strDecode = Boolean.FALSE.toString(); 100 } 101 102 104 107 public int doStartTag( 108 ) throws JspException 109 { 110 return (EVAL_BODY_BUFFERED); 111 } 112 113 116 public int doEndTag( 117 ) throws JspException 118 { 119 StringBuffer sbHtml = new StringBuffer (); 120 boolean bError; 121 122 BodyContent content = getBodyContent(); 123 String strContent = content.getString().trim(); 124 125 List lstFractions = null; 126 lstFractions = StringUtils.parseStringToList(strContent, m_strSeparator); 128 129 if (lstFractions != null && lstFractions.size() > 0) 130 { 131 Iterator itItem; 132 String strValue = null; 133 String strText = null; 134 String strFraction; 135 136 for (itItem = lstFractions.iterator(); itItem.hasNext();) 137 { 138 bError = false; 139 strFraction = (String )itItem.next(); 141 if (m_strItemSeparator != null) 142 { 143 146 strValue = strFraction.substring( 148 0, strFraction.indexOf(m_strItemSeparator)); 149 strText = strFraction.substring( 151 strFraction.indexOf(m_strItemSeparator) + 1, 152 strFraction.length()); 153 } 154 else 155 { 156 strValue = strFraction; 161 strText = strFraction; 162 } 163 164 if (isDecodedOptionText()) 165 { 166 try 167 { 168 strText = URLDecoder.decode(strText, "UTF-8"); 169 } 170 catch (UnsupportedEncodingException eUEExc) 171 { 172 s_logger.log(Level.WARNING, 174 "An error has occured while decoded text for option " + strText, 175 eUEExc); 176 177 bError = true; 178 } 179 } 180 if (!bError) 182 { 183 sbHtml.append("<option value=\""); 184 sbHtml.append(strValue); 185 sbHtml.append("\">"); 186 sbHtml.append(strText); 187 sbHtml.append("</option>\n"); 188 } 189 } 190 } 191 192 TagUtils.write(pageContext, sbHtml.toString()); 193 194 return (EVAL_PAGE); 195 } 196 197 200 public String getSeparator() 201 { 202 return m_strSeparator; 203 } 204 205 209 public String getItemSeparator() 210 { 211 return m_strItemSeparator; 212 } 213 214 217 public String getDecode() 218 { 219 return m_strDecode; 220 } 221 222 225 public void setSeparator( 226 String strSeparator 227 ) 228 { 229 m_strSeparator = strSeparator; 230 } 231 232 236 public void setItemSeparator( 237 String strItemSeparator 238 ) 239 { 240 m_strItemSeparator = strItemSeparator; 241 } 242 243 246 public void setDecode( 247 String strDecode 248 ) 249 { 250 m_strDecode = strDecode; 251 } 252 253 256 public void setDecode( 257 boolean bDecode 258 ) 259 { 260 m_strDecode = Boolean.toString(bDecode); 261 } 262 263 266 public boolean isDecodedOptionText( 267 ) 268 { 269 return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strDecode)) 270 || ("1".equals(m_strDecode))); 271 } 272 } 273 | Popular Tags |