1 5 package xdoclet.modules.doc; 6 7 import java.util.*; 8 9 import org.apache.tools.ant.types.EnumeratedAttribute; 10 11 import xjavadoc.XClass; 12 import xjavadoc.XTag; 13 14 import xdoclet.DocletContext; 15 import xdoclet.DocletTask; 16 import xdoclet.XDocletException; 17 import xdoclet.XDocletTagSupport; 18 19 27 public class AntdocTagsHandler extends XDocletTagSupport 28 { 29 32 protected AntdocSubTask.Element docElement; 33 36 protected AntdocSubTask.SubElement subElement; 37 38 public void setDocElement(AntdocSubTask.Element antElement) 39 { 40 docElement = antElement; 41 setCurrentClass(antElement.getXClass()); 42 } 43 44 51 public String subElementName() throws XDocletException 52 { 53 return subElement.getName(); 54 } 55 56 63 public String elementName() throws XDocletException 64 { 65 return docElement.getName(); 66 } 67 68 75 public void ifHasSubElements(String template) throws XDocletException 76 { 77 if (docElement.getSubElements() != null && docElement.getSubElements().size() > 0) { 78 generate(template); 79 } 80 } 81 82 89 public void forAllSubElements(String template) throws XDocletException 90 { 91 XClass old_cur_class = getCurrentClass(); 92 93 for (Iterator i = docElement.getSubElements().iterator(); i.hasNext(); ) { 94 subElement = (AntdocSubTask.SubElement) i.next(); 95 96 setCurrentClass(subElement.getXClass()); 97 98 generate(template); 99 } 100 101 setCurrentClass(old_cur_class); 102 } 103 104 110 public String subElementDescription() 111 { 112 return subElement.getDescription(); 113 } 114 115 122 public String required() 123 { 124 String result = null; 126 XTag required = getCurrentMethod().getDoc().getTag("ant.required"); 127 128 if (required != null) { 129 result = required.getValue().trim(); 130 if (result.equals("")) { 131 result = "Yes."; 132 } 133 } 134 else { 135 XTag not_required = getCurrentMethod().getDoc().getTag("ant.not-required"); 136 137 if (not_required != null) { 138 result = not_required.getValue().trim(); 139 if (result.equals("")) { 140 result = "No."; 141 } 142 } 143 else 144 result = "No."; 145 } 146 147 return result; 148 } 149 150 157 public String rootlink() 158 { 159 return getRootlinkFor(getCurrentClass()); 160 } 161 162 168 public String subElementLink() 169 { 170 XClass subElementClass = subElement.getSubject().getXClass(); 171 172 AntdocSubTask subtask = ((AntdocSubTask) DocletContext.getInstance().getSubTaskBy(DocletTask.getSubTaskName(AntdocSubTask.class))); 174 String link = (String ) subtask.getConfigParamsAsMap().get(subElementClass.getQualifiedName()); 175 176 if (link == null) { 177 link = getRootlinkFor(docElement.getXClass()) + subElementClass.getContainingPackage().getName().replace('.', '/') 179 + '/' + subElementClass.getTransformedName() + ".html"; 180 } 181 return link; 182 } 183 184 191 public String enumerateValues() throws XDocletException 192 { 193 String ret = ""; 194 xjavadoc.XMethod method = getCurrentMethod(); 195 196 if (method != null) { 197 xjavadoc.Type type = method.getPropertyType(); 198 199 if (type != null) { 200 try { 201 StringBuffer sb = new StringBuffer (); 202 203 String className = type.getType().getTransformedQualifiedName(); 204 EnumeratedAttribute enumClass = (EnumeratedAttribute) Class.forName(className).newInstance(); 205 String [] values = enumClass.getValues(); 206 207 for (int i = 0; i < values.length; i++) { 208 if (i > 0) 209 sb.append(", "); 210 sb.append(values[i]); 211 } 212 ret = sb.toString(); 213 } 214 catch (ClassCastException e) { 215 throw new XDocletException(e, e.getMessage()); 216 } 218 catch (ClassNotFoundException e) { 219 throw new XDocletException(e, e.getMessage()); 220 } 222 catch (IllegalAccessException e) { 223 throw new XDocletException(e, e.getMessage()); 224 } 226 catch (InstantiationException e) { 227 throw new XDocletException(e, e.getMessage()); 228 } 230 } 231 } 232 return ret; 233 } 234 235 private String getRootlinkFor(XClass clazz) 236 { 237 StringTokenizer st = new StringTokenizer(clazz.getQualifiedName(), "."); 238 int n = st.countTokens() - 1; 239 StringBuffer sbuf = new StringBuffer (); 240 241 for (int i = 0; i < n; i++) { 242 sbuf.append("../"); 243 } 244 245 return sbuf.toString(); 246 } 247 248 } 249 | Popular Tags |