1 5 package xdoclet.modules.externalizer; 6 7 import xdoclet.DocletContext; 8 import xdoclet.DocletTask; 9 import xdoclet.XDocletException; 10 import xdoclet.XDocletTagSupport; 11 import xdoclet.util.Translator; 12 13 21 public class ExternalizerTagsHandler extends XDocletTagSupport 22 { 23 private String currentKey; 24 private String currentValue; 25 26 32 private static String convertToUnicodeEscape(String str) 33 { 34 StringBuffer buf = new StringBuffer (); 35 36 buf.setLength(0); 37 38 int pos = 0; 39 40 while (pos < str.length()) { 41 char c = str.charAt(pos); 42 43 pos++; 44 if (c >= 0x100) { 45 String hex = Integer.toHexString(c); 47 48 buf.append("\\u0000".substring(0, 6 - hex.length())); 49 buf.append(hex); 50 } 51 else { 52 switch (c) { 53 case '\t': 54 buf.append("\\t"); 55 break; 56 default: 57 buf.append(c); 58 } 59 } 60 } 61 return buf.toString(); 62 } 63 64 71 public void forAllFieldTags(String template) throws XDocletException 72 { 73 ExternalizerSubTask.Combination combination = ((ExternalizerSubTask) getDocletContext().getActiveSubTask()).getCurrentCombination(); 74 75 for (int i = 0; i < combination.keys.size(); i++) { 76 currentKey = (String ) combination.keys.get(i); 77 currentValue = (String ) combination.values.get(i); 78 79 generate(template); 80 } 81 82 currentKey = null; 83 currentValue = null; 84 } 85 86 93 public String bundleKey() throws XDocletException 94 { 95 if (DocletContext.getInstance().isSubTaskDefined(DocletTask.getSubTaskName(ExternalizerSubTask.class))) { 96 return ((ExternalizerSubTask) DocletContext.getInstance().getSubTaskBy(DocletTask.getSubTaskName(ExternalizerSubTask.class))).getBundleKey(getCurrentClass()); 97 } 98 else { 99 throw new XDocletException(Translator.getString("xdoclet.modules.externalizer.ExternalizerSubtaskMessages", 100 ExternalizerSubtaskMessages.TRANSLATOR_DEPENDS_ON_EXTERNALIZER)); 101 } 102 } 103 104 111 public String key() throws XDocletException 112 { 113 return currentKey; 114 } 115 116 123 public String value() throws XDocletException 124 { 125 return convertToUnicodeEscape(currentValue); 126 } 127 } 128 | Popular Tags |