01: package com.technoetic.xplanner.tags;
02:
03: public class AccessKeyTransformer {
04: public static String removeMnemonicMarkers(String text) {
05: if (text == null)
06: return null;
07: if (getAccessKey(text) != 0) {
08: return text.replaceFirst("&(.)",
09: "<span class=\"mnemonic\">$1</span>");
10: }
11: return text.replaceAll("&&", "&");
12: }
13:
14: public static String getHtml(String text) {
15: char mnemonic = getAccessKey(text);
16: if (mnemonic == 0)
17: return "";
18: String properties = " id=\"aK" + mnemonic + "\""
19: + " accesskey=\"" + mnemonic + "\"";
20: properties += " title= \"ALT+" + mnemonic + "\"";
21: return properties;
22: }
23:
24: public static char getAccessKey(String text) {
25: if (text == null)
26: return 0;
27: int pos = text.indexOf('&');
28: if (pos == -1 || pos == text.length() - 1)
29: return 0;
30: char mnemonic = Character.toUpperCase(text.charAt(pos + 1));
31: if (!Character.isLetterOrDigit(mnemonic))
32: return 0;
33: return mnemonic;
34: }
35: }
|