1 21 22 package org.opensubsystems.patterns.dialoglayout.www; 23 24 import java.util.Properties ; 25 26 import javax.servlet.jsp.JspException ; 27 import javax.servlet.jsp.tagext.BodyContent ; 28 29 import org.opensubsystems.core.util.Config; 30 import org.opensubsystems.core.www.BlockElementTag; 31 import org.opensubsystems.core.www.TagUtils; 32 33 46 public class HelpLabelTag extends BlockElementTag 47 { 48 50 55 public static final String WEBUI_HELPLABEL_FOCUS = "oss.webui.helplabel.focus"; 56 57 59 64 public static final boolean WEBUI_HELPLABEL_FOCUS_DEFAULT = false; 65 66 68 71 private static final long serialVersionUID = -1158455519942369498L; 72 73 76 protected String m_strPostfix; 77 78 81 protected String m_strAccessKey; 82 83 89 protected String m_strAllowFocus; 90 91 93 96 public HelpLabelTag() 97 { 98 super("clsOtherStrechLabel", BlockElementTag.DIV_BLOCK_ELEMENT); 99 100 m_strStyle = ""; 101 m_strPostfix = ""; 102 m_strAccessKey = ""; 103 104 Properties prpSettings; 108 109 prpSettings = Config.getInstance().getPropertiesSafely(); 110 m_strAllowFocus = Config.getBooleanPropertyAsString( 111 prpSettings, 112 WEBUI_HELPLABEL_FOCUS, 113 WEBUI_HELPLABEL_FOCUS_DEFAULT, 114 "Flag allowing for control labels to have focus"); 115 } 116 117 119 122 public int doStartTag( 123 ) throws JspException 124 { 125 return (EVAL_BODY_BUFFERED); 126 } 127 128 131 public int doEndTag( 132 ) throws JspException 133 { 134 StringBuffer sbHtml = new StringBuffer (); 135 StringBuffer sbHtmlTemp = new StringBuffer (); 136 137 146 sbHtml.append("<"); 147 sbHtml.append(m_strType); 148 sbHtml.append(" id=\""); 149 sbHtml.append(getCurrentId()); 150 sbHtml.append(m_strId); 151 sbHtml.append("label\""); 152 if ((m_strCssclass != null) && (m_strCssclass.length() > 0)) 153 { 154 sbHtml.append(" class=\""); 155 sbHtml.append(m_strCssclass); 156 sbHtml.append("\""); 157 } 158 if ((m_strStyle != null) && (m_strStyle.length() > 0)) 159 { 160 sbHtml.append(" style=\""); 161 sbHtml.append(m_strStyle); 162 sbHtml.append("\""); 163 } 164 sbHtml.append("><label id=\""); 165 sbHtml.append(getCurrentId()); 166 sbHtml.append(m_strId); 167 sbHtml.append("help\" class=\"clsHelpLabel\""); 168 if ((m_strAccessKey != null) && (m_strAccessKey.length() > 0)) 169 { 170 sbHtml.append(" accesskey=\""); 171 sbHtml.append(m_strAccessKey); 172 sbHtml.append("\" for=\""); 173 sbHtml.append(getCurrentId()); 174 sbHtml.append("\""); 175 } 176 sbHtml.append(" title=\"Click here or press ALT+F1 when focused in the " + 177 "related control to see context help\"><a HREF=\""); 178 sbHtml.append(getCurrentId()); 179 sbHtml.append(m_strId); 180 sbHtml.append("help\" onclick=\"return false;\" rel=\"Help\" rev=\"Help\""); 181 if (!isFocusAllowed()) 182 { 183 sbHtml.append(" tabindex=\"-1\""); 188 } 189 sbHtml.append(">"); 190 191 192 BodyContent content = getBodyContent(); 194 int iCharIndex = -1; 195 String strContent = content.getString(); 196 if (content != null) 197 { 198 if ((m_strAccessKey != null) && (m_strAccessKey.length() > 0)) 202 { 203 iCharIndex = strContent.indexOf(m_strAccessKey); 204 if (iCharIndex == -1) 205 { 206 iCharIndex = strContent.toLowerCase().indexOf(m_strAccessKey.toLowerCase()); 207 } 208 } 209 if (iCharIndex == -1) 210 { 211 if ((m_strAccessKey != null) && (m_strAccessKey.length() > 0)) 212 { 213 sbHtmlTemp.append("\n<!-- Accesskey '"); 216 sbHtmlTemp.append(m_strAccessKey); 217 sbHtmlTemp.append("' was not found within the label content for "); 218 sbHtmlTemp.append(getCurrentId()); 219 sbHtmlTemp.append(m_strId); 220 sbHtmlTemp.append(" -->\n"); 221 } 222 } 223 else 224 { 225 sbHtmlTemp.append(strContent.substring(0, iCharIndex)); 228 sbHtmlTemp.append("<u>"); 229 sbHtmlTemp.append(strContent.charAt(iCharIndex)); 230 sbHtmlTemp.append("</u>"); 231 sbHtmlTemp.append(strContent.substring(iCharIndex + 1, strContent.length())); 232 strContent = sbHtmlTemp.toString(); 233 sbHtmlTemp.delete(0, sbHtmlTemp.length()); 234 } 235 sbHtml.append(strContent); 236 } 237 else 238 { 239 sbHtml.append("Missing context label for "); 240 sbHtml.append(getCurrentId()); 241 sbHtml.append(m_strId); 242 } 243 244 sbHtml.append("</a>"); 245 sbHtml.append(sbHtmlTemp); 247 sbHtml.append("</label>"); 248 if (m_strPostfix != null && m_strPostfix.length() > 0) 249 { 250 sbHtml.append("<span>"); 251 sbHtml.append(m_strPostfix); 252 sbHtml.append("</span>"); 253 } 254 sbHtml.append("</"); 255 sbHtml.append(m_strType); 256 sbHtml.append('>'); 257 258 TagUtils.write(pageContext, sbHtml.toString()); 259 260 return (EVAL_PAGE); 261 } 262 263 266 public String getPostfix( 267 ) 268 { 269 return m_strPostfix; 270 } 271 272 275 public void setPostfix( 276 String strPostfix 277 ) 278 { 279 m_strPostfix = strPostfix; 280 } 281 282 285 public String getAccesskey( 286 ) 287 { 288 return m_strAccessKey; 289 } 290 291 294 public void setAccesskey( 295 String strAccessKey 296 ) 297 { 298 m_strAccessKey = strAccessKey; 299 } 300 301 305 public String getAllowFocus( 306 ) 307 { 308 return m_strAllowFocus; 309 } 310 311 316 public void setAllowfocus( 317 String strAllowFocus 318 ) 319 { 320 m_strAllowFocus = strAllowFocus; 321 } 322 323 327 public void setAllowfocus( 328 boolean bAllowFocus 329 ) 330 { 331 m_strAllowFocus = Boolean.toString(bAllowFocus); 332 } 333 334 337 public boolean isFocusAllowed( 338 ) 339 { 340 return ((Boolean.TRUE.toString().equalsIgnoreCase(m_strAllowFocus)) 341 || ("1".equals(m_strAllowFocus))); 342 } 343 } 344 | Popular Tags |