/jEdit/tags/jedit-4-3-pre5/macros/Java/Preview_JavaDoc_Of_Current_Buffer.bsh

# · Unknown · 797 lines · 729 code · 68 blank · 0 comment · 0 complexity · 8e3fa56bfa9f5453524347f8320a67c3 MD5 · raw file

  1. /*
  2. * Preview_JavaDoc_Of_Current_Buffer.bsh
  3. * version 1.8
  4. * A BeanShell macro script for the jEdit text editor
  5. *
  6. * $Header$
  7. * Copyright (C) 2001-2003 Tom Gutwin
  8. * tgutwin@webarts.bc.ca
  9. *
  10. * - Macro to create and preview the JavaDocs for the current buffer
  11. * - It tries to figure everything out for you.
  12. * - Map this macro to it to a button on the button bar and away you go!
  13. *
  14. * ************************************************************************
  15. * ** Requires the Console plugin and the InfoViewer plugin
  16. * ** ALSO
  17. * ** Requires Downloading of the different doclets if you are going to use
  18. * them and pdfReaderCommand if using the pdfDoclet.
  19. * ***********************************************************************
  20. * ** Features
  21. * ***********************************************************************
  22. *
  23. * - most of the settings to customize how this macro performs are set with
  24. * boolean flags (see code below). The following features are some of the
  25. * features already selectable/customizable
  26. *
  27. * - javadoc of current buffer OR current buffer's package
  28. * set the 'doFullPackage' boolean flag in the macro code
  29. * You can then save a copy of this macro as a different name
  30. * for example... Preview_JavaDoc_Of_Current_Buffers_Package.bsh
  31. *
  32. * - default Doclet is the standard Java Doclet
  33. * (the user can change the default doclet to use by changing the XXXX
  34. * variable in this macro)
  35. *
  36. * - When this macro starts, a doclet choice dialog is presented.
  37. * this dialog can be bypassed by setting 'showDocletDialog' to false
  38. * see the code below
  39. *
  40. * - Many of the standard Doclet commandline parms are preset with some
  41. * defaults... header, footer etc.
  42. * They are all controlled via boolean flags in the code
  43. * Switch them on/off as you like.
  44. *
  45. * - Includes the ability to use 'user selectable' doclets
  46. * The following are already built in. (you just have to go get the doclet)
  47. * > the DocBook doclet - dbdoclet http://www.michael-a-fuchs.de
  48. * > the Bouvard Doclet - http://web.tiscali.it/no-redirect-tiscali/farello/bp/intro.html
  49. * > the XMLDoclet - http://
  50. * > the pdfdoclet (Java API to PDF) - http://sourceforge.net/projects/pdfdoclet
  51. * > others
  52. *
  53. * - easy selection of output dir (defaults to system temp dir)
  54. * set with the 'outputDir' var in the macro code
  55. *
  56. * - other standard doclets parameters have been supervised by variables.
  57. * see below for adding extra classpath, source path, title, header, footer
  58. * MORE below
  59. *
  60. * ************************************************************************
  61. * This program is free software; you can redistribute it and/or
  62. * modify it under the terms of the GNU General Public License
  63. * as published by the Free Software Foundation; either version 2
  64. * of the License, or any later version.
  65. *
  66. * This program is distributed in the hope that it will be useful,
  67. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  68. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  69. * GNU General Public License for more details.
  70. *
  71. * You should have received a copy of the GNU General Public License
  72. * along with the jEdit program; if not, write to the Free Software
  73. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  74. USA.
  75. */
  76. String _getClassName()
  77. {
  78. /*
  79. * Get_Class_Name.bsh - a BeanShell macro script for the
  80. * jEdit text editor - gets class name from buffer name
  81. * Copyright (C) 2001 John Gellene
  82. * jgellene@nyc.rr.com
  83. *
  84. * This program is free software; you can redistribute it and/or
  85. * modify it under the terms of the GNU General Public License
  86. * as published by the Free Software Foundation; either version 2
  87. * of the License, or any later version.
  88. *
  89. * This program is distributed in the hope that it will be useful,
  90. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  91. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  92. * GNU General Public License for more details.
  93. *
  94. * You should have received a copy of the GNU General Public License
  95. * along with the jEdit program; if not, write to the Free Software
  96. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  97. *
  98. * $Id: Preview_JavaDoc_Of_Current_Buffer.bsh 4937 2003-12-22 04:14:55Z spestov $
  99. */
  100. name = buffer.getName();
  101. index = name.lastIndexOf('.');
  102. return (index != -1 ? name.substring(0, index) : name);
  103. }
  104. /** Trys to obtain the package name from the file **/
  105. String _determinePackageName()
  106. {
  107. packageName = "";
  108. text = buffer.getText(0, buffer.getLength());
  109. //String lineSep = System.getProperty("line.separator");
  110. /* look for the word package.
  111. It must be at the start of a line.
  112. It should not be within comments. (how can we easily determine this???)
  113. */
  114. packageWord = text.indexOf("package");
  115. // If it is not on the first line of the file
  116. // then look for the 1st occurence of "package" on its own line
  117. if (packageWord > 0)
  118. packageWord = text.indexOf("\npackage");
  119. if (packageWord != -1)
  120. {
  121. packageEOLine = text.indexOf(";", packageWord);
  122. if (packageEOLine!= -1)
  123. packageName = text.substring(packageWord+8,packageEOLine);
  124. }
  125. return packageName;
  126. }
  127. /** Chooses a directory and returns the path. **/
  128. /* Use this method if you want to customize the macro to choose
  129. output and input directorys for things */
  130. String _chooseADir(String dialogTitle, String startDir)
  131. {
  132. String retVal = "";
  133. JFileChooser chooser = new JFileChooser(startDir);
  134. chooser.setDialogTitle(dialogTitle);
  135. chooser.setMultiSelectionEnabled(false);
  136. chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  137. if(chooser.showDialog(view, "Okay") == JFileChooser.APPROVE_OPTION)
  138. {
  139. retVal = chooser.getSelectedFile().getAbsolutePath();
  140. }
  141. return retVal;
  142. }
  143. void _infoView(View view, String urlStr)
  144. {
  145. // first, check if the plugin is installed.
  146. boolean version1 = false;
  147. //With version 1.0 of the plugin ... the name changed to
  148. //infoviewer.InfoViewerPlugin
  149. if(jEdit.getPlugin("InfoViewerPlugin") == null)
  150. {
  151. if(jEdit.getPlugin("infoviewer.InfoViewerPlugin") == null)
  152. {
  153. Macros.error(view,"You must install the InfoViewerPlugin"
  154. + " to use this macro.");
  155. return;
  156. }
  157. version1 = true;
  158. }
  159. try
  160. {
  161. // API change with version 1.0 of the InfoViewer
  162. if (version1)
  163. jEdit.getPlugin("infoviewer.InfoViewerPlugin").
  164. openURL(view, urlStr);// version 1.0
  165. else
  166. jEdit.getPlugin("InfoViewerPlugin").
  167. sendURL(new URL(urlStr), view); // pre 1.0
  168. }
  169. catch (MalformedURLException mu)
  170. {
  171. Macros.error(view,"Cannot find the url " + urlStr);
  172. }
  173. }
  174. String _returnSystemCommand(View view, String command)
  175. {
  176. // first, check if the plugin is installed.
  177. if(jEdit.getPlugin("console.ConsolePlugin") == null)
  178. {
  179. Macros.error(view,"You must install the Console plugin"
  180. + " to use this macro.");
  181. return;
  182. }
  183. //Macros.message(view, "Getting window manager.");
  184. manager = view.getDockableWindowManager();
  185. _console = (console.Console) manager.getDockable("console");
  186. outputPane = _console.getOutputPane();
  187. text = outputPane.getText();
  188. textLength = text.length();
  189. runInSystemShell(view, command);
  190. waitForConsole(view);
  191. text = outputPane.getText();
  192. textLength = text.length();
  193. text = outputPane.getText().substring(textLength);
  194. return text;
  195. }
  196. /**
  197. * Ensures that a folder exists.
  198. * <TABLE WIDTH="100%" BORDER="0" CELLSPACING="1" CELLPADDING="2">
  199. * <TR><TD COLSPAN="2">
  200. * <H2>Ensures that a folder exists</H2>
  201. * </TD></TR>
  202. *
  203. * <TR><TD COLSPAN="2">&nbsp;<BR>
  204. * <B>Description:</B><BR>
  205. * use it like this:
  206. * <br> _ensureFolderExists(new File(fileName).getParentFile());
  207. * </TD></TR>
  208. * </TABLE>
  209. *
  210. * @param folder The File object to check.
  211. **/
  212. void _ensureFolderExists(File folder)
  213. {
  214. if ( folder != null && ! folder.exists() )
  215. {
  216. _ensureFolderExists(folder.getParentFile());
  217. folder.mkdir();
  218. }
  219. }
  220. String versionStr = "1.8";
  221. String SYSTEM_FILE_SEPERATOR = File.separator;
  222. String SYSTEM_TEMP_DIR = System.getProperty("java.io.tmpdir");
  223. //SYSTEM_TEMP_DIR = "/tmp";
  224. String SYSTEM_PATH_SEPERATOR = System.getProperty("path.separator");
  225. // first, check if the plugin is installed.
  226. if(jEdit.getPlugin("console.ConsolePlugin") == null ||
  227. (jEdit.getPlugin("InfoViewerPlugin") == null) &&
  228. (jEdit.getPlugin("infoviewer.InfoViewerPlugin") == null))
  229. {
  230. if(jEdit.getPlugin("console.ConsolePlugin") == null)
  231. Macros.error(view,"You must install the Console plugin"
  232. + " to use this macro.");
  233. else
  234. Macros.error(view,"You must install the InfoViewerPlugin plugin"
  235. + " to use this macro.");
  236. }
  237. else
  238. {
  239. String currBufferPath = buffer.getPath();
  240. //Macros.message(view,"Current Buffer Path:\n"+currBufferPath);
  241. if (currBufferPath.endsWith(".java"))
  242. {
  243. /* Store Some class/package/path info for use later */
  244. // Get the Package name
  245. String packName = _determinePackageName();
  246. // Get the Class Name
  247. String className = _getClassName();
  248. /* ********************************************************************** */
  249. /* Change the Following Vars to personalize things */
  250. /* You should also Change the Header and Botton javadoc text down below */
  251. /* ********************************************************************** */
  252. // header message
  253. String yourProductUrlStr = "http://www.yourProductURL.goes.here";
  254. String yourProductNameStr = "My Java Product Name";
  255. // header message
  256. String yourBottomStr = "Released under a GNU Public License.";
  257. // PDFDoclet outputfilename
  258. String pdfDocletOutputFilename = "PDFDoclet.Output.pdf";
  259. // PDFDoclet outputfilename
  260. String pdfReaderCommand = "acro";
  261. // Output directory .... set this to somewhere permanent if you want
  262. String outputDir = SYSTEM_TEMP_DIR;
  263. // Allow choice of the output dir at runtime
  264. boolean chooseOutputDir = false;
  265. // This macro attempts to get the source search path right
  266. // if its not getting it... this var gets added to the Javadoc search path
  267. String extraSourceDir = "";
  268. // This macro doesn't do much with the javadoc classpath
  269. // if its not getting it... this var gets added to the Javadoc classpath
  270. String extraClassesDir = "";
  271. // flag to do the Javadoc on the package instead of just the file
  272. // Set this to true then save this macro with a new name
  273. // ie... Preview_Javadoc_Of_Current_Package.bsh
  274. boolean doFullPackage = false;
  275. // set to false to default to the standard java doclet
  276. boolean showDocletDialog = true;
  277. /* Set some default options for the javadoc command */
  278. /* change these to suit how you like your output to show up */
  279. /* better yet... make a little dialog for input at runtime */
  280. int showOnlyLevel = 3; // protected is the default
  281. String[] showOnlyStr = {"-public ","-protected ","-package ","-private"};
  282. /* some (not All) standard doclet options */
  283. /* ************************************** */
  284. // if you want one of the following options...
  285. // set the corresponding flag to true
  286. boolean[] optionFlags = {false,false,false,false,false,
  287. false,false,false,false};
  288. String[] optionStrs = {"-use ","-version ","-author ","-nosince","-notree ",
  289. "-noindex ","-nohelp ","-nodeprecated ","-verbose"};
  290. // beware OS/2 users...
  291. // ALL the following options break the IBM 1.3.0 JDK Javadoc tool
  292. // don't ask me?
  293. boolean addWindowTitle = true;
  294. StringBuffer windowTitle = new StringBuffer("-windowtitle \"Javadoc for");
  295. windowTitle.append((doFullPackage?"package ":"class "));
  296. windowTitle.append(className);
  297. windowTitle.append("\" ");
  298. /* DocTitle Text */
  299. boolean addDocTitle = true;
  300. StringBuffer docTitle = new StringBuffer("-doctitle \"");
  301. docTitle.append("Your Document Title here Javadoc API");
  302. docTitle.append("\" ");
  303. /* Header Text */
  304. boolean addHeader = true;
  305. StringBuffer header = new StringBuffer("-header \"");
  306. header.append("<B><A href=\"");
  307. header.append(yourProductUrlStr);
  308. header.append("\">");
  309. header.append(yourProductNameStr);
  310. header.append("</A></B>");
  311. header.append("<BR>Version xx.xx.xx");
  312. // Format the current time.
  313. java.text.SimpleDateFormat formatter
  314. = new java.text.SimpleDateFormat ("yyyy.MMMMM.dd 'at' hh:mm:sszzz");
  315. java.util.Date currentTime_1 = new java.util.Date();
  316. String dateString = formatter.format(currentTime_1);
  317. header.append("<BR><font size=-1>");
  318. header.append(dateString);
  319. header.append("</font>\" ");
  320. /* Footer Text */
  321. boolean addFooter = true;
  322. StringBuffer footer = new StringBuffer("-footer \"");
  323. footer.append("Produced Using the <A href=\"http://www.jedit.org\">");
  324. footer.append("jEdit</A><BR>Preview Javadoc Beanshell Macro.<BR>");
  325. footer.append("Copyright &copy; 2001-2003, ");
  326. footer.append("<A href=\"http://www.webarts.bc.ca>\"");
  327. footer.append("Tom B. Gutwin</A>");
  328. footer.append("\" ");
  329. /* Bottom Text */
  330. boolean addBottom = true;
  331. StringBuffer bottom = new StringBuffer("-bottom \"");
  332. bottom.append(yourBottomStr);
  333. bottom.append("\" ");
  334. /*********************************************************************** */
  335. /* All users setting now complete */
  336. /*********************************************************************** */
  337. // Store the directory where the buffer file lives
  338. String savedBufferdir = currBufferPath.substring(0,
  339. currBufferPath.length()-6-className.length());
  340. // build the full package.classname
  341. StringBuffer fullClassName = new StringBuffer();
  342. if (packName != null && !packName.equals(""))
  343. {
  344. fullClassName.append(packName);
  345. fullClassName.append(".");
  346. }
  347. fullClassName.append(className);
  348. /* Javadoc needs the file to live in a directory structure */
  349. /* named like its Package name */
  350. // If needed... copy the file to the temp dir into its package dir */
  351. String currBufferdir = savedBufferdir;
  352. StringBuffer tmpBufferName = new StringBuffer(SYSTEM_TEMP_DIR);
  353. if (packName != null && !packName.equals("") &&
  354. savedBufferdir.indexOf(
  355. packName.replace('.',File.separatorChar).trim()) == -1 )
  356. {
  357. // The buffer file is not in an appropriate named dir
  358. // copy and work on it in temp
  359. if (!SYSTEM_TEMP_DIR.endsWith(SYSTEM_FILE_SEPERATOR))
  360. tmpBufferName.append(SYSTEM_FILE_SEPERATOR);
  361. _ensureFolderExists(new File(tmpBufferName.toString() +
  362. packName.replace('.', File.separatorChar).trim()));
  363. tmpBufferName.append(fullClassName.toString().
  364. replace('.', File.separatorChar).trim());
  365. tmpBufferName.append(".java");
  366. //Macros.message(view, "Saving "+tmpBufferName.toString());
  367. buffer.save(view, tmpBufferName.toString(), false);
  368. // the rest of the macro uses the currBufferdir variable
  369. currBufferPath = tmpBufferName.toString();
  370. currBufferdir = currBufferPath.substring(0,
  371. currBufferPath.length()-6-className.length());
  372. }
  373. // some debug statements
  374. //Macros.message(view,"Package Name ="+packName);
  375. //Macros.message(view,"fullClassName ="+fullClassName);
  376. //Macros.message(view,"Buffer Path ="+currBufferPath);
  377. //Macros.message(view,"Buffer Dir ="+currBufferdir);
  378. /* ************************************************* */
  379. /* *********** On with the Processing ************* */
  380. Object[] options = { "Standard Java Doclet", "Bouvard Doclet",
  381. "DocBook Doclet", "XML Doclet", "PDF Doclet" };
  382. String[] docletClassName = { "", "bp.doclet.Bouvard",
  383. "com.mf.doclet.docbook.DocBookDoclet",
  384. "codeinsight.xmldoclet.XMLDoclet",
  385. "com.tarsec.javadoc.pdfdoclet.PDFDoclet"};
  386. String[] docletClassPath = { "", "Bouvard.jar", "dbdoclet.jar",
  387. "xmldoclet.jar",
  388. "pdfdoclet.jar:itext.jar:/usr/lib/pkgs" };
  389. String PDFDocletConfigPropertiesFile = "pdfdoclet.config.properties";
  390. // Set the DEFAULT Doclet to the JavaDoclet
  391. String proceed = options[0];
  392. /* Shows a Doclet Selection Dialog */
  393. if (showDocletDialog)
  394. proceed = JOptionPane.showInputDialog(view,
  395. "Choose the Doclet to use for previewing the"+
  396. "\n" + className + " JavaDocs."+
  397. "\n(Bypass this dialog... set "+
  398. "'showDocletDialog=false;' in the macro)",
  399. "JavaDoc Buffer Macro - version "+versionStr,
  400. JOptionPane.QUESTION_MESSAGE, null, options,
  401. options[0]);
  402. if (proceed != null)
  403. {
  404. // this is where you could use the _chooseADir(String startDir) method
  405. // to choose an output dir at runtime.
  406. if (chooseOutputDir)
  407. outputDir = _chooseADir("Please Choose an Output Directory.",outputDir);
  408. docletChoice = 0;
  409. for (int choiceNum = 0; choiceNum < options.length;choiceNum++)
  410. {
  411. if (((String)proceed).equals((String)options[choiceNum]))
  412. {
  413. docletChoice = choiceNum;
  414. choiceNum = options.length;
  415. }
  416. }
  417. // The currBufferSrcDir expects the current buffer to be in a subDirectory
  418. // path the same as the package name
  419. // THIS is definitely NOT always the case
  420. String currBufferSrcDir = currBufferPath.substring(0,
  421. currBufferPath.length()-fullClassName.toString().length()-5);
  422. if(outputDir != null && !outputDir.equals(""))
  423. {
  424. // you might need some of the follwing if you want to add some
  425. // commandline parms
  426. String jedit_userdir=System.getProperty("user.home") +
  427. SYSTEM_FILE_SEPERATOR +".jedit";
  428. String jedit_homedir=jEdit.getJEditHome();
  429. String currClassPath=System.getProperty("java.class.path");
  430. String java_home=System.getProperty("java.home");
  431. // Construct the command which will be executed
  432. StringBuffer command = new StringBuffer(java_home);
  433. if (java_home.toLowerCase().endsWith("jre"))
  434. command.append(File.separator).append("..");
  435. command.append(File.separator).append("bin");
  436. command.append(File.separator).append("javadoc ");
  437. if (!((String)proceed).equals((String)options[0]))
  438. {
  439. // general parms for 'other' doclets
  440. command.append("-doclet \"");
  441. command.append(docletClassName[docletChoice]);
  442. command.append("\" ");
  443. command.append("-docletpath \"");
  444. command.append(jedit_userdir);
  445. command.append(SYSTEM_FILE_SEPERATOR);
  446. command.append("jars");
  447. command.append(SYSTEM_FILE_SEPERATOR);
  448. command.append(docletClassPath[docletChoice]);
  449. command.append("\" ");
  450. // Bouvard Doclet
  451. // This assumes the Bouvard.jar already exists
  452. // in the jeditUser/jars dir
  453. if (((String)proceed).equals((String)options[1]))
  454. {
  455. /* Specify the output dir */
  456. command.append("-d \"");
  457. command.append(outputDir);
  458. command.append("\" ");
  459. }
  460. // the DocBookDoclet has an extra parm
  461. if (((String)proceed).equals((String)options[2]))
  462. {
  463. command.append("-properties \"");
  464. command.append(jedit_userdir);
  465. command.append(SYSTEM_FILE_SEPERATOR);
  466. command.append("macros");
  467. command.append(SYSTEM_FILE_SEPERATOR);
  468. command.append("Java");
  469. command.append(SYSTEM_FILE_SEPERATOR);
  470. command.append("dbdoclet-xml.properties\" ");
  471. }
  472. // the XMLDoclet has an extra parm
  473. if (((String)proceed).equals((String)options[3]))
  474. {
  475. /* Specify the output dir */
  476. //command.append("-d \"");
  477. //command.append(outputDir);
  478. //command.append("\" ");
  479. }
  480. // the PDFDoclet has an extra parm
  481. if (((String)proceed).equals((String)options[4]))
  482. {
  483. command.append("-pdf \"");
  484. command.append(outputDir);
  485. command.append(SYSTEM_FILE_SEPERATOR);
  486. command.append(pdfDocletOutputFilename);
  487. command.append("\" ");
  488. if (PDFDocletConfigPropertiesFile != null
  489. &&!PDFDocletConfigPropertiesFile.equals(""))
  490. {
  491. command.append(" -workdir \"");
  492. command.append(outputDir);
  493. command.append("\" ");
  494. command.append("-config \"");
  495. command.append(jedit_userdir);
  496. command.append(SYSTEM_FILE_SEPERATOR);
  497. command.append("macros");
  498. command.append(SYSTEM_FILE_SEPERATOR);
  499. command.append("Java");
  500. command.append(SYSTEM_FILE_SEPERATOR);
  501. command.append(PDFDocletConfigPropertiesFile);
  502. command.append("\"");
  503. }
  504. }
  505. }
  506. else
  507. { // standard doclet parms
  508. if (addWindowTitle)
  509. command.append(windowTitle.toString());
  510. if (addDocTitle)
  511. command.append(docTitle.toString());
  512. if (addHeader)
  513. command.append(header.toString());
  514. if (addFooter)
  515. command.append(footer.toString());
  516. if (addBottom)
  517. command.append(bottom.toString());
  518. /* add the on/off options */
  519. for (int opt = 0; opt <optionFlags.length; opt++)
  520. {
  521. if (optionFlags[opt])
  522. command.append(optionStrs[opt]);
  523. }
  524. /* Specify the output dir */
  525. command.append("-d \"");
  526. command.append(outputDir);
  527. command.append("\" ");
  528. }
  529. /* Set the Level of detail to show */
  530. command.append(" ");
  531. command.append(showOnlyStr[showOnlyLevel]);
  532. /* if not found add your source dir to the 'extraClassesdir' var */
  533. command.append(" -classpath \"");
  534. command.append(SYSTEM_TEMP_DIR);
  535. command.append(SYSTEM_PATH_SEPERATOR);
  536. command.append(System.getProperty("java.class.path"));
  537. command.append(SYSTEM_PATH_SEPERATOR);
  538. command.append(extraClassesDir);
  539. command.append("\" ");
  540. /* **** Done with the options ***** */
  541. /* Specify the package or file name */
  542. if (doFullPackage && packName != null && !packName.equals(""))
  543. {
  544. /* Guess where the package source is located */
  545. /* if not found... add your source dir to the 'extraSourcedir' var */
  546. command.append("-sourcepath \"");
  547. command.append(savedBufferdir);
  548. command.append(SYSTEM_PATH_SEPERATOR);
  549. command.append(currBufferSrcDir);
  550. command.append(SYSTEM_PATH_SEPERATOR);
  551. command.append(currBufferSrcDir);
  552. command.append(SYSTEM_FILE_SEPERATOR);
  553. command.append("..");
  554. command.append(SYSTEM_PATH_SEPERATOR);
  555. command.append(currBufferSrcDir);
  556. command.append(SYSTEM_FILE_SEPERATOR);
  557. command.append("..");
  558. command.append(SYSTEM_FILE_SEPERATOR);
  559. command.append("..");
  560. command.append(SYSTEM_PATH_SEPERATOR);
  561. command.append(currBufferSrcDir);
  562. command.append(SYSTEM_FILE_SEPERATOR);
  563. command.append("..");
  564. command.append(SYSTEM_FILE_SEPERATOR);
  565. command.append("..");
  566. command.append(SYSTEM_FILE_SEPERATOR);
  567. command.append("..");
  568. command.append(SYSTEM_PATH_SEPERATOR);
  569. command.append(currBufferSrcDir);
  570. command.append(SYSTEM_FILE_SEPERATOR);
  571. command.append("..");
  572. command.append(SYSTEM_FILE_SEPERATOR);
  573. command.append("..");
  574. command.append(SYSTEM_FILE_SEPERATOR);
  575. command.append("..");
  576. command.append(SYSTEM_FILE_SEPERATOR);
  577. command.append("..");
  578. command.append(SYSTEM_PATH_SEPERATOR);
  579. command.append(currBufferdir);
  580. command.append(SYSTEM_PATH_SEPERATOR);
  581. command.append(extraSourceDir);
  582. command.append("\" ");
  583. command.append(packName);
  584. }
  585. else
  586. {
  587. // add the base sourcepath
  588. command.append("-sourcepath \"");
  589. command.append(savedBufferdir);
  590. command.append(SYSTEM_PATH_SEPERATOR);
  591. command.append(currBufferSrcDir);
  592. command.append(SYSTEM_PATH_SEPERATOR);
  593. command.append(currBufferdir);
  594. command.append(SYSTEM_PATH_SEPERATOR);
  595. command.append(extraSourceDir);
  596. command.append("\" ");
  597. // now add the file to javadoc
  598. command.append("\"");
  599. command.append(currBufferPath);
  600. command.append("\"");
  601. }
  602. retVal = _returnSystemCommand(view, command.toString());
  603. if (retVal.indexOf("error") == -1)
  604. {
  605. // Build the url for the Viewer
  606. // If you don't want to use the InfoViewer plugin...
  607. // easy, change the implementation in this macros _infoView method
  608. StringBuffer urlStr = new StringBuffer();
  609. urlStr.append("file:///");
  610. urlStr.append(outputDir.replace('\\', '/').trim());
  611. if (!outputDir.endsWith(SYSTEM_FILE_SEPERATOR))
  612. urlStr.append("/");
  613. if (doFullPackage)
  614. {
  615. urlStr.append("index.html");
  616. }
  617. else
  618. {
  619. if (packName != null && !packName.equals(""))
  620. {
  621. urlStr.append(packName.replace('.', '/').trim());
  622. urlStr.append("/");
  623. }
  624. //Macros.message(view, packName);
  625. urlStr.append(className);
  626. urlStr.append(".html");
  627. //Macros.message(view, urlStr.toString());
  628. }
  629. // now which viewer (standard or Pecuchet)
  630. if (!showDocletDialog || ((String)proceed).equals((String)options[0]))
  631. _infoView(view, urlStr.toString());
  632. else if (((String)proceed).equals((String)options[1]))
  633. {
  634. // Bouvard Browser
  635. // This assumes the Pecuchet.jar already exists
  636. // and xerces is in the classpath already
  637. StringBuffer classPath = new StringBuffer("\"");
  638. classPath.append(jedit_userdir);
  639. classPath.append(SYSTEM_FILE_SEPERATOR);
  640. classPath.append("jars");
  641. classPath.append(SYSTEM_FILE_SEPERATOR);
  642. classPath.append("Pecuchet.jar");
  643. classPath.append(SYSTEM_PATH_SEPERATOR);
  644. classPath.append(jedit_homedir);
  645. classPath.append(SYSTEM_FILE_SEPERATOR);
  646. classPath.append("jars");
  647. classPath.append(SYSTEM_FILE_SEPERATOR);
  648. classPath.append("Pecuchet.jar");
  649. classPath.append(SYSTEM_PATH_SEPERATOR);
  650. classPath.append(currClassPath);
  651. classPath.append("\"");
  652. StringBuffer bViewerCommand = new StringBuffer("java -classpath ");
  653. bViewerCommand.append(classPath);
  654. bViewerCommand.append(" ");
  655. bViewerCommand.append("-Dorg.xml.sax.driver=");
  656. bViewerCommand.append("org.apache.xerces.parsers.SAXParser");
  657. bViewerCommand.append(" ");
  658. bViewerCommand.append("bp.app.Main ");
  659. bViewerCommand.append(outputDir);
  660. if (!outputDir.endsWith(SYSTEM_FILE_SEPERATOR))
  661. bViewerCommand.append(SYSTEM_FILE_SEPERATOR);
  662. bViewerCommand.append("data.bou &");
  663. retVal = _returnSystemCommand(view, bViewerCommand.toString());
  664. StringBuffer macroMessage =
  665. new StringBuffer("When the Pecuchet browser starts.\n");
  666. macroMessage.append("Open file: ");
  667. macroMessage.append(outputDir);
  668. if (!outputDir.endsWith(SYSTEM_FILE_SEPERATOR))
  669. macroMessage.append(SYSTEM_FILE_SEPERATOR);
  670. macroMessage.append("data.bou");
  671. //Macros.message(view, macroMessage.toString());
  672. }
  673. else if (((String)proceed).equals((String)options[2]))
  674. {
  675. // XML Doclet
  676. // Use a new jEdit Buffer
  677. StringBuffer newFile = new StringBuffer(outputDir);
  678. if (!outputDir.endsWith(SYSTEM_FILE_SEPERATOR))
  679. newFile.append(SYSTEM_FILE_SEPERATOR);
  680. newFile.append("Reference.xml");
  681. Buffer newTmpBuffer = jEdit.openFile(view,newFile.toString());
  682. }
  683. else if (((String)proceed).equals((String)options[3]))
  684. {
  685. // XML Doclet
  686. // Use a new jEdit Buffer
  687. StringBuffer newFile = new StringBuffer(outputDir);
  688. if (!outputDir.endsWith(SYSTEM_FILE_SEPERATOR))
  689. newFile.append(SYSTEM_FILE_SEPERATOR);
  690. newFile.append("output.xml");
  691. Buffer newTmpBuffer = jEdit.openFile(view,newFile.toString());
  692. }
  693. else if (((String)proceed).equals((String)options[4]))
  694. {
  695. // pdf Doclet
  696. StringBuffer pdfViewerCommand = new StringBuffer(pdfReaderCommand);
  697. pdfViewerCommand.append(" ");
  698. pdfViewerCommand.append(outputDir);
  699. pdfViewerCommand.append(SYSTEM_FILE_SEPERATOR);
  700. pdfViewerCommand.append(pdfDocletOutputFilename);
  701. retVal = _returnSystemCommand(view, pdfViewerCommand.toString());
  702. }
  703. else
  704. {
  705. // put the viewers for other doclets here
  706. }
  707. }
  708. else
  709. Macros.error(view, "Javadoc did NOT complete successfully. " +
  710. "See the console output");
  711. }
  712. }
  713. }
  714. else
  715. Macros.error(view, "Current Buffer does NOT appear to be a Java File");
  716. }
  717. /*
  718. Macro index data (in DocBook format)
  719. <listitem>
  720. <para><filename>Preview_Javadoc_of_Buffer.bsh</filename></para>
  721. <abstract><para>
  722. Create and display API documentation for the current buffer.
  723. </para></abstract>
  724. <para>
  725. The macro includes various configuration variables you can change; see the comment at the beginning of the macro source for details.
  726. </para>
  727. </listitem>
  728. */
  729. // end Preview_JavaDoc_of_Buffer.bsh