docGenerator.jar
, which is distributed in the docGenerator-bin-<version>.zip
filedocGeneratorAPI.jar
, which is distributed in the docGenerator-api-<version>.zip
filepackage apigeneration; import java.io.File; import javax.swing.JFileChooser; public class APIGeneration { private DocGeneratorAPI api = null; public APIGeneration() { } public void generate(File directory) { } public static void main(String[] args) { JFileChooser chooser = new JFileChooser(new File(System.getProperty("user.dir"))); chooser.setDialogTitle("Select the output directory"); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { APIGeneration generation = new APIGeneration(); generation.generate(chooser.getSelectedFile()); } } }For the moment the generator does not do anything. When we run the application, a file chooser appear and we can choose the directory where to generate the wiki. But nothing more happens and the application exits.
File directory
method to create the API, and generate the html result:package apigeneration; import java.io.File; import javax.swing.JFileChooser; public class APIGeneration { private DocGeneratorAPI api = null; public APIGeneration() { } public void generate(File directory) { api = new DocGeneratorAPI(); api.createModel(); api.setOutputDirectory(directory); // generate the wiki (the output directory existing content will be cleaned prior to the generation) api.writeContent(true); } }This code won't compile because the
writeContent
method can throw a DocGeneratorAPIException
exception. We modify the class to properly catch this exception:package apigeneration; import java.io.File; import javax.swing.JFileChooser; public class APIGeneration { private DocGeneratorAPI api = null; public APIGeneration() { } public void generate(File directory) throws DocGeneratorAPIException { api = new DocGeneratorAPI(); api.createModel(); api.setOutputDirectory(directory); // generate the wiki (the output directory existing content will be cleaned prior to the generation) api.writeContent(true); } public static void main(String[] args) { JFileChooser chooser = new JFileChooser(new File(System.getProperty("user.dir"))); chooser.setDialogTitle("Select the output directory"); chooser.setDialogType(JFileChooser.OPEN_DIALOG); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { APIGeneration generation = new APIGeneration(); try { generation.generate(chooser.getSelectedFile()); } catch (DocGeneratorAPIException e) { e.printStackTrace(); } } } }
api.addSentence(api.getIndex(), "This is a wiki about animals");The full code of the method becomes:
public void generate(File directory) throws DocGeneratorAPIException { api = new DocGeneratorAPI(); api.createModel(); api.setOutputDirectory(directory); // generate the wiki (the output directory existing content will be cleaned prior to the generation) api.writeContent(true); api.addSentence(api.getIndex(), "This is a wiki about animals"); // generate the wiki (the output directory existing content will be cleaned prior to the generation) api.writeContent(true); }
public void generate(File directory) throws DocGeneratorAPIException { api = new DocGeneratorAPI(); api.createModel(); api.setOutputDirectory(directory); // generate the wiki (the output directory existing content will be cleaned prior to the generation) api.writeContent(true); api.addSentence(api.getIndex(), "This is a wiki about animals"); // create an article about birds XMLArticle birdArticle = api.createArticle("Bird"); // create an article about vertebrates XMLArticle vertebrateArticle = api.createArticle("Vertebrate"); // generate the wiki (the output directory existing content will be cleaned prior to the generation) api.writeContent(true); }
public void generate(File directory) throws DocGeneratorAPIException { // create an article about birds XMLArticle birdArticle = api.createArticle("Bird"); api.addSentence(birdArticle, "A bird is a warm-blooded "); api.addReference(birdArticle, "vertebrate"); // create an article about vertebrates XMLArticle vertebrateArticle = api.createArticle("Vertebrate"); }Now we create a reference between the "Vertebrate" and the "Bird" article:
public void generate(File directory) throws DocGeneratorAPIException { // create an article about birds XMLArticle birdArticle = api.createArticle("Bird"); api.addSentence(birdArticle, "A bird is a warm-blooded "); api.addReference(birdArticle, "vertebrate"); // create an article about vertebrates XMLArticle vertebrateArticle = api.createArticle("Vertebrate"); api.addSentence(vertebrateArticle, "A vertebrate is a mammal who has vertebrae. An example of vertebrate is a "); api.addReference(vertebrateArticle, birdArticle); }
public void generate(File directory) throws DocGeneratorAPIException { // create an article about birds XMLArticle birdArticle = api.createArticle("Bird"); api.addSentence(birdArticle, "A bird is a warm-blooded "); api.addReference(birdArticle, "vertebrate"); api.addTitle(birdArticle, "Physiology"); api.addSentence(birdArticle, "A bird has two wings"); // create an article about vertebrates XMLArticle vertebrateArticle = api.createArticle("Vertebrate"); api.addSentence(vertebrateArticle, "A vertebrate is a mammal who has vertebrae. An example of vertebrate is a "); api.addReference(vertebrateArticle, birdArticle); }
public void generate(File directory) throws DocGeneratorAPIException { // create an article about birds XMLArticle birdArticle = api.createArticle("Bird"); api.addSentence(birdArticle, "A bird is a warm-blooded "); api.addReference(birdArticle, "vertebrate"); api.addTitle(birdArticle, "Physiology"); api.addSentence(birdArticle, "A bird has two wings"); api.addTitle(birdArticle, "List of birds"); // add a new title XMLTable table = api.addTable(birdArticle); // add a table table.setWidth(20, true); // set the width of the table a 20% of the width of the page table.setAlignment(Alignment.LEFT); // align the table to the left table.setCaption("List of birds"); // set the table caption api.addTableColumn(table, "Classification"); // add only one column to the table, and set its name XMLTableRow row = api.addTableRow(table); // add a first row api.addTableCell(row, "Pigeon"); // add one cell to the row row = api.addTableRow(table); // add a second row api.addTableCell(row, "Crow"); row = api.addTableRow(table); // add a third row api.addTableCell(row, "Eagle"); // create an article about vertebrates XMLArticle vertebrateArticle = api.createArticle("Vertebrate"); api.addSentence(vertebrateArticle, "A vertebrate is a mammal who has vertebrae. An example of vertebrate is a "); api.addReference(vertebrateArticle, birdArticle); }
docJGenerator Copyright (c) 2016-2023 Herve Girod. All rights reserved.