165 * 166 * @param te the class to convert. 167 * @param outputdir the name of the directory to output to 168 * @throws DocFileIOException if there is a problem generating the output file 169 * @throws SimpleDocletException if there is a problem reading the source file 170 */ 171 public void convertClass(TypeElement te, DocPath outputdir) 172 throws DocFileIOException, SimpleDocletException { 173 if (te == null) { 174 return; 175 } 176 FileObject fo = utils.getFileObject(te); 177 if (fo == null) 178 return; 179 180 try { 181 Reader r = fo.openReader(true); 182 int lineno = 1; 183 String line; 184 relativePath = DocPaths.SOURCE_OUTPUT 185 .resolve(DocPath.forPackage(utils, te)) 186 .invert(); 187 Content body = getHeader(); 188 Content pre = new HtmlTree(HtmlTag.PRE); 189 try (LineNumberReader reader = new LineNumberReader(r)) { 190 while ((line = reader.readLine()) != null) { 191 addLineNo(pre, lineno); 192 addLine(pre, line, lineno); 193 lineno++; 194 } 195 } 196 addBlankLines(pre); 197 Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre); 198 body.addContent((configuration.allowTag(HtmlTag.MAIN)) ? HtmlTree.MAIN(div) : div); 199 writeToFile(body, outputdir.resolve(DocPath.forClass(utils, te))); 200 } catch (IOException e) { 201 String message = resources.getText("doclet.exception.read.file", fo.getName()); 202 throw new SimpleDocletException(message, e); 203 } 204 } 205 206 /** 207 * Write the output to the file. 208 * 209 * @param body the documentation content to be written to the file. 210 * @param path the path for the file. 211 */ 212 private void writeToFile(Content body, DocPath path) throws DocFileIOException { 213 DocType htmlDocType = DocType.forVersion(configuration.htmlVersion); 214 Head head = new Head(path, configuration.htmlVersion, configuration.docletVersion) 215 // .setTimestamp(!configuration.notimestamp) // temporary: compatibility! 216 .setTitle(resources.getText("doclet.Window_Source_title")) 217 // .setCharset(configuration.charset) // temporary: compatibility! 218 .addDefaultScript(false) 219 .setStylesheets(configuration.getMainStylesheet(), configuration.getAdditionalStylesheets()); | 165 * 166 * @param te the class to convert. 167 * @param outputdir the name of the directory to output to 168 * @throws DocFileIOException if there is a problem generating the output file 169 * @throws SimpleDocletException if there is a problem reading the source file 170 */ 171 public void convertClass(TypeElement te, DocPath outputdir) 172 throws DocFileIOException, SimpleDocletException { 173 if (te == null) { 174 return; 175 } 176 FileObject fo = utils.getFileObject(te); 177 if (fo == null) 178 return; 179 180 try { 181 Reader r = fo.openReader(true); 182 int lineno = 1; 183 String line; 184 relativePath = DocPaths.SOURCE_OUTPUT 185 .resolve(configuration.docPaths.forPackage(te)) 186 .invert(); 187 Content body = getHeader(); 188 Content pre = new HtmlTree(HtmlTag.PRE); 189 try (LineNumberReader reader = new LineNumberReader(r)) { 190 while ((line = reader.readLine()) != null) { 191 addLineNo(pre, lineno); 192 addLine(pre, line, lineno); 193 lineno++; 194 } 195 } 196 addBlankLines(pre); 197 Content div = HtmlTree.DIV(HtmlStyle.sourceContainer, pre); 198 body.addContent((configuration.allowTag(HtmlTag.MAIN)) ? HtmlTree.MAIN(div) : div); 199 writeToFile(body, outputdir.resolve(configuration.docPaths.forClass(te))); 200 } catch (IOException e) { 201 String message = resources.getText("doclet.exception.read.file", fo.getName()); 202 throw new SimpleDocletException(message, e); 203 } 204 } 205 206 /** 207 * Write the output to the file. 208 * 209 * @param body the documentation content to be written to the file. 210 * @param path the path for the file. 211 */ 212 private void writeToFile(Content body, DocPath path) throws DocFileIOException { 213 DocType htmlDocType = DocType.forVersion(configuration.htmlVersion); 214 Head head = new Head(path, configuration.htmlVersion, configuration.docletVersion) 215 // .setTimestamp(!configuration.notimestamp) // temporary: compatibility! 216 .setTitle(resources.getText("doclet.Window_Source_title")) 217 // .setCharset(configuration.charset) // temporary: compatibility! 218 .addDefaultScript(false) 219 .setStylesheets(configuration.getMainStylesheet(), configuration.getAdditionalStylesheets()); |