1 5 package xdoclet.modules.doc; 6 7 import java.io.File ; 8 import java.text.MessageFormat ; 9 import java.util.*; 10 11 import xjavadoc.XClass; 12 13 import xdoclet.TemplateSubTask; 14 import xdoclet.XDocletException; 15 import xdoclet.template.TemplateEngine; 16 import xdoclet.template.TemplateException; 17 import xdoclet.template.TemplateTagHandler; 18 import xdoclet.util.Translator; 19 20 29 public class DocumentTagsSubTask extends TemplateSubTask 30 { 31 private static String INDEX_TEMPLATE_FILE = "resources/index.xdt"; 32 33 private static String GENERATED_INDEX_FILE_NAME = "index.html"; 34 35 private static String NAMESPACES_TEMPLATE_FILE = "resources/namespaces.xdt"; 36 37 private static String GENERATED_NAMESPACES_FILE_NAME = "namespaces.html"; 38 39 private static String TAGS_MAIN_TEMPLATE_FILE = "resources/tags_main.xdt"; 40 41 private static String GENERATED_TAGS_MAIN_FILE_NAME = "tags.html"; 42 43 private static String TAGS_TOC_MAIN_TEMPLATE_FILE = "resources/tags_toc_main.xdt"; 44 45 private static String GENERATED_TAGS_TOC_MAIN_FILE_NAME = "tags_toc.html"; 46 47 private static String TAGS_TOC_TEMPLATE_FILE = "resources/tags_toc.xdt"; 48 49 private static String GENERATED_TAGS_TOC_FILE_NAME = "{0}_toc.html"; 50 51 private static String TAGS_TEMPLATE_FILE = "resources/tags.xdt"; 52 53 private static String GENERATED_TAGS_FILE_NAME = "{0}.html"; 54 55 private String currentNamespace; 56 57 62 public String getCurrentNamespace() 63 { 64 return currentNamespace; 65 } 66 67 68 73 public void validateOptions() throws XDocletException 74 { 75 } 76 77 82 public void execute() throws XDocletException 83 { 84 85 setTemplateURL(getClass().getResource(INDEX_TEMPLATE_FILE)); 86 setDestinationFile(GENERATED_INDEX_FILE_NAME); 87 startProcess(); 88 89 System.out.println(Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.GENERATING_NAMESPACES)); 90 setTemplateURL(getClass().getResource(NAMESPACES_TEMPLATE_FILE)); 91 setDestinationFile(GENERATED_NAMESPACES_FILE_NAME); 92 startProcess(); 93 94 System.out.println(Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.GENERATING_TAGS_MAIN)); 95 setTemplateURL(getClass().getResource(TAGS_MAIN_TEMPLATE_FILE)); 96 setDestinationFile(GENERATED_TAGS_MAIN_FILE_NAME); 97 startProcess(); 98 99 System.out.println(Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.GENERATING_TAGS_TOC_MAIN)); 100 setTemplateURL(getClass().getResource(TAGS_TOC_MAIN_TEMPLATE_FILE)); 101 setDestinationFile(GENERATED_TAGS_TOC_MAIN_FILE_NAME); 102 startProcess(); 103 104 System.out.println(Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.GENERATING_TAGS_MAIN)); 105 setTemplateURL(getClass().getResource(TAGS_TOC_TEMPLATE_FILE)); 106 setDestinationFile(GENERATED_TAGS_TOC_FILE_NAME); 107 addOfType("xdoclet.template.TemplateTagHandler"); 108 startProcess(); 110 111 System.out.println(Translator.getString(XDocletModulesDocMessages.class, XDocletModulesDocMessages.GENERATING_TAGS_MAIN)); 112 setTemplateURL(getClass().getResource(TAGS_TEMPLATE_FILE)); 113 setDestinationFile(GENERATED_TAGS_FILE_NAME); 114 addOfType("xdoclet.template.TemplateTagHandler"); 115 startProcess(); 117 } 118 119 126 protected String getGeneratedFileName(XClass clazz) throws XDocletException 127 { 128 String destinationFile = MessageFormat.format(getDestinationFile(), new Object []{currentNamespace}); 129 130 return new File (destinationFile).toString(); 131 } 132 133 139 protected void generateForClass(XClass clazz) throws XDocletException 140 { 141 setCurrentNamespace(clazz); 142 143 super.generateForClass(clazz); 144 } 145 146 151 protected void engineStarted() throws XDocletException 152 { 153 } 154 155 161 private void setCurrentNamespace(XClass clazz) throws XDocletException 162 { 163 for (Iterator namespaces = TemplateEngine.getEngineInstance().getNamespaces().iterator(); namespaces.hasNext(); ) { 164 String namespace = (String ) namespaces.next(); 165 166 try { 167 TemplateTagHandler handler = TemplateEngine.getEngineInstance().getTagHandlerFor(namespace); 168 169 if (handler.getClass().getName().equals(clazz.getQualifiedName())) { 170 currentNamespace = namespace; 171 break; 172 } 173 } 174 catch (TemplateException e) { 175 throw new XDocletException(e, "Error getting tag handler for " + namespace); 176 } 177 } 178 if (currentNamespace == null) { 179 } 181 } 182 } 183 | Popular Tags |