1 5 package xdoclet.modules.doc.info; 6 7 import java.util.*; 8 9 import xjavadoc.*; 10 11 import xdoclet.XDocletException; 12 import xdoclet.XDocletTagSupport; 13 import xdoclet.modules.doc.XDocletModulesDocMessages; 14 import xdoclet.tagshandler.*; 15 import xdoclet.template.TemplateException; 16 import xdoclet.util.Translator; 17 18 24 public class InfoTagsHandler extends XDocletTagSupport 25 { 26 33 public void ifTagCountNotZero(String template, Properties properties) throws XDocletException 34 { 35 String level = properties.getProperty("level"); 36 int tagCount = tagCount_Impl(level); 37 38 if (tagCount != 0) { 39 generate(template); 40 } 41 } 42 43 50 public String tagCount(Properties properties) throws XDocletException 51 { 52 String level = properties.getProperty("level"); 53 int tagCount = tagCount_Impl(level); 54 55 return String.valueOf(tagCount); 56 } 57 58 64 public String classTagValue() throws XDocletException 65 { 66 return getClassTagsHandler().classTagValue(getProperties()); 67 } 68 69 75 public String fieldTagValue() throws XDocletException 76 { 77 return getFieldTagsHandler().fieldTagValue(getProperties()); 78 } 79 80 86 public String constructorTagValue() throws XDocletException 87 { 88 return getConstructorTagsHandler().constructorTagValue(getProperties()); 89 } 90 91 97 public String methodTagValue() throws XDocletException 98 { 99 return getMethodTagsHandler().methodTagValue(getProperties()); 100 } 101 102 108 public void forAllClassTags(String template) throws XDocletException 109 { 110 getClassTagsHandler().forAllClassTags(template, getProperties()); 111 } 112 113 119 public void forAllConstructorTags(String template) throws XDocletException 120 { 121 getConstructorTagsHandler().forAllConstructorTags(template, getProperties()); 122 } 123 124 130 public void forAllMethodTags(String template) throws XDocletException 131 { 132 getMethodTagsHandler().forAllMethodTags(template, getProperties()); 133 } 134 135 141 public void forAllFieldTags(String template) throws XDocletException 142 { 143 getFieldTagsHandler().forAllFieldTags(template, getProperties()); 144 } 145 146 152 public String projectname() throws XDocletException 153 { 154 InfoSubTask infoSubTask = (InfoSubTask) getDocletContext().getActiveSubTask(); 155 156 return infoSubTask.getProjectname(); 157 } 158 159 165 public String rootlink() throws XDocletException 166 { 167 String packageName = ""; 168 169 if (getPackageTagsHandler().packageName() != null) { 170 packageName = getPackageTagsHandler().packageName(); 171 } 172 173 StringTokenizer st = new StringTokenizer(packageName, "."); 174 int n = st.countTokens(); 175 StringBuffer sbuf = new StringBuffer (); 176 177 for (int i = 0; i < n; i++) { 178 sbuf.append("../"); 179 } 180 return sbuf.toString(); 181 } 182 183 188 private Properties getProperties() 189 { 190 Properties properties = ((InfoSubTask) getDocletContext().getActiveSubTask()).getProperties(); 191 192 return properties; 193 } 194 195 201 private MethodTagsHandler getMethodTagsHandler() throws XDocletException 202 { 203 try { 204 return ((MethodTagsHandler) getEngine().getTagHandlerFor("Method")); 205 } 206 catch (TemplateException ex) { 207 throw new XDocletException(ex, Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.TAGSHANDLER_NOT_FOUND, new String []{"MethodTagsHandler", "Method"})); 208 } 209 } 210 211 217 private FieldTagsHandler getFieldTagsHandler() throws XDocletException 218 { 219 try { 220 return ((FieldTagsHandler) getEngine().getTagHandlerFor("Field")); 221 } 222 catch (TemplateException ex) { 223 throw new XDocletException(ex, Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.TAGSHANDLER_NOT_FOUND, new String []{"FieldTagsHandler", "Field"})); 224 } 225 } 226 227 233 private ConstructorTagsHandler getConstructorTagsHandler() throws XDocletException 234 { 235 try { 236 return ((ConstructorTagsHandler) getEngine().getTagHandlerFor("Constructor")); 237 } 238 catch (TemplateException ex) { 239 throw new XDocletException(ex, Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.TAGSHANDLER_NOT_FOUND, new String []{"ConstructorTagsHandler", "Constructor"})); 240 } 241 } 242 243 249 private ClassTagsHandler getClassTagsHandler() throws XDocletException 250 { 251 try { 252 return ((ClassTagsHandler) getEngine().getTagHandlerFor("Class")); 253 } 254 catch (TemplateException ex) { 255 throw new XDocletException(ex, Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.TAGSHANDLER_NOT_FOUND, new String []{"ClassTagsHandler", "Class"})); 256 } 257 } 258 259 265 private PackageTagsHandler getPackageTagsHandler() throws XDocletException 266 { 267 try { 268 return ((PackageTagsHandler) getEngine().getTagHandlerFor("Package")); 269 } 270 catch (TemplateException ex) { 271 throw new XDocletException(ex, Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.TAGSHANDLER_NOT_FOUND, new String []{"PackageTagsHandler", "Package"})); 272 } 273 } 274 275 282 private int tagCount_Impl(String level) throws XDocletException 283 { 284 int tagCount = 0; 285 286 if ("all".equals(level)) { 287 tagCount = tagCountInAll_Impl(getProperties()); 288 } 289 else if ("package".equals(level)) { 290 tagCount = tagCountInPackage_Impl(getProperties(), getCurrentPackage()); 291 } 292 else if ("whole-class".equals(level)) { 293 tagCount = tagCountInClass_Impl(getProperties(), getCurrentClass(), true, true, true, true); 294 } 295 else if ("class".equals(level)) { 296 tagCount = tagCountInClass_Impl(getProperties(), getCurrentClass(), true, false, false, false); 297 } 298 else if ("field".equals(level)) { 299 tagCount = tagCountInClass_Impl(getProperties(), getCurrentClass(), false, true, false, false); 300 } 301 else if ("constructor".equals(level)) { 302 tagCount = tagCountInClass_Impl(getProperties(), getCurrentClass(), false, false, true, false); 303 } 304 else if ("method".equals(level)) { 305 tagCount = tagCountInClass_Impl(getProperties(), getCurrentClass(), false, false, false, true); 306 } 307 else { 308 throw new XDocletException(Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.BAD_LEVEL, new String []{level})); 309 } 310 return tagCount; 311 } 312 313 320 private int tagCountInAll_Impl(Properties attributes) throws XDocletException 321 { 322 int tagCount = 0; 323 Collection classes = getXJavaDoc().getSourceClasses(); 324 SortedSet packages = new TreeSet(); 325 326 for (Iterator i = classes.iterator(); i.hasNext(); ) { 327 packages.add(((XClass) i.next()).getContainingPackage()); 328 } 329 330 for (Iterator packageIterator = packages.iterator(); packageIterator.hasNext(); ) { 331 XPackage cur_package = (XPackage) packageIterator.next(); 332 333 tagCount += tagCountInPackage_Impl(attributes, cur_package); 334 } 335 336 return tagCount; 337 } 338 339 346 private int tagCountInPackage_Impl(Properties attributes, XPackage pakkage) 347 { 348 int tagCount = 0; 349 Collection classes = pakkage.getClasses(); 350 351 for (Iterator i = classes.iterator(); i.hasNext(); ) { 352 tagCount += tagCountInClass_Impl(attributes, (XClass) i.next(), true, true, true, true); 353 } 354 return tagCount; 355 } 356 357 368 private int tagCountInClass_Impl(Properties attributes, XClass clazz, boolean countClass, boolean countFields, boolean countConstructors, boolean countMethods) 369 { 370 int tagCount = 0; 371 String tagName = attributes.getProperty("tagName"); 372 373 if (countClass) { 374 tagCount += tagCount(clazz, tagName); 375 } 376 if (countConstructors) { 377 Collection constructors = clazz.getConstructors(); 378 379 tagCount += tagCount(constructors, tagName); 380 } 381 if (countMethods) { 382 Collection methods = clazz.getMethods(); 383 384 tagCount += tagCount(methods, tagName); 385 } 386 if (countFields) { 387 Collection fields = clazz.getFields(); 388 389 tagCount += tagCount(fields, tagName); 390 } 391 return tagCount; 392 } 393 394 401 private int tagCount(XProgramElement programElement, String tagName) 402 { 403 return programElement.getDoc().getTags(tagName, false).size(); 404 } 405 406 413 private int tagCount(Collection programElements, String tagName) 414 { 415 int count = 0; 416 417 for (Iterator i = programElements.iterator(); i.hasNext(); ) { 418 count += tagCount((XProgramElement) i.next(), tagName); 419 } 420 return count; 421 } 422 } 423 | Popular Tags |