plugin-javalib.dita 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE task PUBLIC "-//OASIS//DTD DITA Task//EN" "task.dtd">
  3. <!-- This file is part of the DITA Open Toolkit project. See the accompanying LICENSE file for applicable license. -->
  4. <task id="plugin-javalib" xml:lang="en-US">
  5. <title>Adding a Java library to the DITA-OT <parmname>classpath</parmname> parameter</title>
  6. <shortdesc>You can use the <codeph>dita.conductor.lib.import</codeph> extension point to add an additional Java
  7. library to the DITA-OT <parmname>classpath</parmname> parameter.</shortdesc>
  8. <taskbody>
  9. <steps>
  10. <step>
  11. <cmd>If necessary, compile the Java code into a JAR file.</cmd>
  12. </step>
  13. <step>
  14. <cmd>Create a <filepath>plugin.xml</filepath> file that contains the following code:</cmd>
  15. <info><codeblock>&lt;plugin id="<varname>plugin-id</varname>">
  16. &lt;feature extension="dita.conductor.lib.import" file="<varname>file</varname>"/>
  17. &lt;/plugin></codeblock>where:<ul>
  18. <li><varname>plugin-id</varname> is the plug-in identifier, for example, com.example.addjar.</li>
  19. <li><varname>file</varname> is the name of the JAR file, for example,
  20. <filepath>myJavaLibrary.jar</filepath>. </li>
  21. </ul></info>
  22. </step>
  23. <step>
  24. <cmd>Install the plug-in.</cmd>
  25. </step>
  26. </steps>
  27. <result>The Ant or XSLT code now can make use of the Java code.</result>
  28. <example>
  29. <p>In the following extended example, the <filepath>myJavaLibrary.jar</filepath> file performs a validation step
  30. during processing, and you want it to run immediately before the <codeph>conref </codeph>step. To accomplish
  31. this, you will need to use several features:</p>
  32. <ul>
  33. <li>The JAR file must be added to the classpath.</li>
  34. <li>The Ant target must be added to the dependency chain for conref.</li>
  35. <li>An Ant target must be created that uses this class, and the Ant wrapper integrated into the code.</li>
  36. </ul>
  37. <p>The files might look like the following:</p>
  38. <fig>
  39. <title><filepath>plugin.xml</filepath> file</title>
  40. <codeblock>&lt;?xml version="1.0" encoding="UTF-8"?>
  41. &lt;plugin id="com.example.samplejava">
  42. &lt;!-- Add the JAR file to the DITA-OT CLASSPATH -->
  43. <b>&lt;feature extension="dita.conductor.lib.import" file="com.example.sampleValidation.jar"/></b>
  44. &lt;!-- Integrate the Ant code -->
  45. &lt;feature extension="dita.conductor.target.relative" file="antWrapper.xml"/>
  46. &lt;!-- Define the Ant target that is called, and the location (before conref) -->
  47. &lt;feature extension="depend.preprocess.conref.pre" value="validateWithJava"/>
  48. &lt;/plugin></codeblock>
  49. </fig>
  50. <fig>
  51. <title><filepath>antWrapper.xml</filepath> file</title>
  52. <codeblock>&lt;?xml version="1.0" encoding="UTF-8"?>
  53. &lt;dummy>
  54. &lt;import file="calljava-antcode.xml"/>
  55. &lt;/dummy></codeblock>
  56. </fig>
  57. <fig>
  58. <title><filepath>calljava-antcode.xml</filepath> file</title>
  59. <codeblock>&lt;?xml version="1.0" encoding="UTF-8"?>
  60. &lt;project default="validateWithJava">
  61. &lt;target name="validateWithJava">
  62. &lt;java classname="com.example.sampleValidation">
  63. &lt;!-- The class was added to dost.class.path (the DITA-OT classpath) -->
  64. &lt;classpath refid="dost.class.path"/>
  65. &lt;/java>
  66. &lt;/target>
  67. &lt;/project></codeblock>
  68. </fig>
  69. </example>
  70. </taskbody>
  71. </task>