java-api.dita 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
  3. <!-- This file is part of the DITA Open Toolkit project. See the accompanying LICENSE file for applicable license. -->
  4. <concept id="API">
  5. <title>Using the Java API</title>
  6. <shortdesc>DITA Open Toolkit includes a Java Application Programming Interface to allow developers to embed the
  7. toolkit more easily into other Java programs.</shortdesc>
  8. <prolog>
  9. <metadata>
  10. <keywords>
  11. <indexterm>Java<indexterm>API</indexterm></indexterm>
  12. <indexterm>API</indexterm>
  13. <indexterm><cmdname>dita</cmdname> command<indexterm>classpath</indexterm></indexterm>
  14. <indexterm>Java<indexterm>classpath</indexterm></indexterm>
  15. <indexterm>classpath<indexterm>Java</indexterm><indexterm><cmdname>dita</cmdname> command</indexterm></indexterm>
  16. </keywords>
  17. </metadata>
  18. </prolog>
  19. <conbody>
  20. <p>When using the API, programmers don’t need to know or care that DITA-OT uses Ant, they can just use Java. </p>
  21. <note>When running DITA-OT via the <cmdname>dita</cmdname> command, an <codeph>ant</codeph> shell script handles the
  22. classpath setup, but when using the API the classpath should be set up as part of the normal classpath
  23. configuration for the Java application.</note>
  24. <example>
  25. <title>Example usage</title>
  26. <codeblock outputclass="language-java normalize-space show-line-numbers show-whitespace">// Create a reusable processor factory with DITA-OT base directory
  27. ProcessorFactory pf = ProcessorFactory.newInstance(ditaDir);
  28. // and set the temporary directory
  29. pf.setBaseTempDir(tempDir);
  30. // Create a processor using the factory and configure the processor
  31. Processor p = pf.newProcessor("html5")
  32. .setInput(mapFile)
  33. .setOutputDir(outDir)
  34. .setProperty("nav-toc", "partial");
  35. // Run conversion
  36. p.run();</codeblock>
  37. </example>
  38. <section>
  39. <indexterm>debugging<indexterm>logging</indexterm></indexterm>
  40. <p>By default, running DITA-OT via the API will write a debug log to the temporary directory. A custom SLF4J
  41. logger can also be used to access the log via the Simple Logging Facade for Java.</p>
  42. <p>The processor cleans the temporary directory by default, but this can be disabled to simplify debugging in
  43. cases where the processor failed.</p>
  44. <note type="tip">See the <cite>DITA-OT Java API documentation</cite> in the <filepath>doc/api/</filepath> folder
  45. of the DITA-OT distribution package for information on the packages, classes, interfaces and methods provided by
  46. the Java API.</note>
  47. </section>
  48. <section>
  49. <title>Downloading DITA-OT from Maven Central</title>
  50. <indexterm>Maven Central</indexterm>
  51. <p>As of version 2.5, the DITA Open Toolkit base library (<filepath>dost.jar</filepath>) is available via the
  52. Maven 2 Central Repository. You can use this mechanism to download the main JAR file and include it in the build
  53. for other Java projects.</p>
  54. <p>To locate the latest version, <xref href="https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.dita-ot%22"
  55. format="html" scope="external">search for the <codeph>org.dita-ot</codeph> group ID</xref>.</p>
  56. <note type="important">The <filepath>dost.jar</filepath> file provides only the DITA Open Toolkit base library. It
  57. does <b>not</b> contain the full DITA-OT distribution and cannot be used to run DITA-OT by itself. You will need
  58. to ensure that your build installs the other files and directories required for the toolkit along with the
  59. dependencies for your project.</note>
  60. </section>
  61. </conbody>
  62. </concept>