1 5 package xdoclet.modules.caucho; 6 7 import java.util.Properties ; 8 import xjavadoc.XProgramElement; 9 import xjavadoc.XTag; 10 import xdoclet.XDocletException; 11 import xdoclet.XDocletTagSupport; 12 13 20 public class ResinWebTagsHandler extends XDocletTagSupport 21 { 22 private final static int WAIT_NAME = 0; 23 private final static int IN_NAME = 1; 24 private final static int WAIT_VALUE = 2; 25 private final static int IN_VALUE = 3; 26 27 private String name; 28 private String value; 29 30 31 private static boolean isDelimiter(char c) 32 { 33 return c == '"' || c == '='; 34 } 35 36 private static boolean isSpace(char c) 37 { 38 return Character.isSpaceChar(c); 39 } 40 41 private static boolean isSpecial(char c) 42 { 43 return isDelimiter(c) || isSpace(c); 44 } 45 46 47 54 public void forAllCurrentTagParams(String template) 55 throws XDocletException 56 { 57 clear(); 58 59 int state = WAIT_NAME; 60 final StringBuffer name = new StringBuffer (); 61 final StringBuffer value = new StringBuffer (); 62 63 final String text = getCurrentTag().getValue(); 64 65 for (int i = 0; i < text.length(); i++) { 66 char c = text.charAt(i); 67 68 switch (state) { 69 case WAIT_NAME: 70 if (!isSpecial(c)) { 71 name.append(c); 72 state = IN_NAME; 73 } 74 break; 75 case IN_NAME: 76 if (c == '=') 77 state = WAIT_VALUE; 78 else if (isSpace(c)) { 79 int index = i + 1; 81 82 while (index < text.length()) { 83 char c2 = text.charAt(index); 84 85 if (isSpace(c2)) 86 index++; 87 else if (c2 == '=') { 88 i = index; 89 state = WAIT_VALUE; 90 break; 91 } 92 else { 93 name.delete(0, name.length()); 94 state = WAIT_NAME; 95 i = index - 1; 96 break; 97 } 98 } 99 } 100 else 101 name.append(c); 102 break; 103 case WAIT_VALUE: 104 if (c == '"') 105 state = IN_VALUE; 106 else if (!isSpace(c)) { 107 name.delete(0, name.length()); 108 state = WAIT_NAME; 109 } 110 break; 111 case IN_VALUE: 112 if (c == '"') { 113 this.name = name.toString(); 115 this.value = value.toString(); 116 name.delete(0, name.length()); 117 value.delete(0, value.length()); 118 state = WAIT_NAME; 119 generate(template); 120 clear(); 121 } 122 else 123 value.append(c); 124 } 125 } 126 } 127 128 140 public String parameterAsElement(Properties props) 141 throws XDocletException 142 { 143 String name = props.getProperty(parameterName()); 144 145 if (name == null || name.length() < 1) 146 name = parameterName(); 147 148 StringBuffer buffer = new StringBuffer (); 149 150 buffer.append('<'); 151 buffer.append(name); 152 buffer.append('>'); 153 buffer.append(parameterValue()); 154 buffer.append("</"); 155 buffer.append(name); 156 buffer.append('>'); 157 158 return buffer.toString(); 159 } 160 161 170 public String parameterAsInitParam() 171 throws XDocletException 172 { 173 StringBuffer buffer = new StringBuffer (); 174 175 buffer.append("<init-param "); 176 buffer.append(parameterName()); 177 buffer.append("=\""); 178 buffer.append(parameterValue()); 179 buffer.append("\"/>"); 180 181 return buffer.toString(); 182 } 183 184 195 public String parameterAsXml(Properties props) 196 throws XDocletException 197 { 198 if (props.containsKey(parameterName())) 199 return parameterAsElement(props); 200 else 201 return parameterAsInitParam(); 202 } 203 204 211 public String parameterName() 212 throws XDocletException 213 { 214 if (name == null) 215 throw L.error(L.NO_CURRENT_PARAMETER); 216 else 217 return name; 218 } 219 220 227 public String parameterValue() 228 throws XDocletException 229 { 230 if (value == null) 231 throw L.error(L.NO_CURRENT_PARAMETER); 232 else 233 return value; 234 } 235 236 243 public String sourceComment() 244 throws XDocletException 245 { 246 XProgramElement doc = getCurrentMethod(); 247 248 if (doc == null) 249 doc = getCurrentClass(); 250 if (doc == null) 251 return ""; 252 else 253 return "<!-- " + L.l(L.GENERATED_FROM, new String []{doc.getName()}) + " -->"; 254 } 255 256 private XTag getCurrentTag() 257 throws XDocletException 258 { 259 XTag tag = getCurrentMethodTag(); 260 261 if (tag == null) 262 tag = getCurrentClassTag(); 263 if (tag == null) 264 throw L.error(L.NO_CURRENT_JAVADOC_TAG); 265 return tag; 266 } 267 268 269 private void clear() 270 { 271 name = null; 272 value = null; 273 } 274 } 275 | Popular Tags |