implement-saxon-collation-uri-resolvers.html 9.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <!DOCTYPE html
  2. SYSTEM "about:legacy-compat">
  3. <html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta charset="UTF-8"><meta name="copyright" content="(C) Copyright 2019"><meta name="DC.rights.owner" content="(C) Copyright 2019"><meta name="DC.type" content="topic"><meta name="description" content="Plug-ins can provide custom URI resolvers that provide collators for specific collation URIs."><meta name="DC.subject" content="Saxon, service, Ant, jar, xsl:sort, Chinese, I18N, plug-in, plug-ins, XSLT, URI resolver"><meta name="keywords" content="Saxon, service, Ant, jar, xsl:sort, Chinese, I18N, plug-in, plug-ins, XSLT, URI resolver"><meta name="DC.relation" scheme="URI" content="../topics/implement-saxon-customizations.html"><meta name="DC.format" content="HTML5"><meta name="DC.identifier" content="implement-saxon-collation-uri-resolvers"><link rel="stylesheet" type="text/css" href="../css/commonltr.css"><link rel="stylesheet" type="text/css" href="../css/dita-ot-doc.css"><title>Implementing custom Saxon collation URI resolvers</title></head><body id="implement-saxon-collation-uri-resolvers"><header role="banner"><div class="header">
  4. <p>DITA Open Toolkit</p>
  5. <hr>
  6. </div></header><nav role="toc"><ul><li><a href="../index.html">DITA Open Toolkit 3.3</a></li><li><a href="../release-notes/index.html">Release Notes</a></li><li><a href="../topics/installing-client.html">Installing DITA-OT</a></li><li><a href="../topics/alternative-input-formats.html">Authoring formats</a></li><li><a href="../topics/building-output.html">Building output</a></li><li><a href="../parameters/index.html">Setting parameters</a></li><li><a href="../topics/customizing.html">Customizing DITA-OT</a><ul><li><a href="../topics/html-customization.html">Customizing HTML</a></li><li><a href="../topics/pdf-customization.html">Customizing PDF</a></li><li><a href="../topics/custom-plugins.html">Working with plug-ins</a><ul><li><a href="../topics/plugins-installing.html">Installing plug-ins</a></li><li><a href="../topics/plugins-removing.html">Removing plug-ins</a></li><li><a href="../topics/plugins-registry.html">Plug-in registry</a></li><li><a href="../topics/plugin-configfile.html">Plug-in descriptor file</a></li><li><a href="../topics/plugin-dependencies.html">Plug-in dependencies</a></li><li><a href="../topics/plugin-applications.html">Plug-in applications</a><ul><li><a href="../topics/plugin-xmlcatalog.html">Extending an XML catalog file</a></li><li><a href="../topics/plugin-anttarget.html">Adding a new target to the Ant build process</a></li><li><a href="../topics/plugin-antpreprocess.html">Adding an Ant target to the pre-processing pipeline</a></li><li><a href="../topics/plugin-newtranstype.html">Adding a new transformation type</a></li><li><a href="../topics/plugin-overridestyle.html">Overriding an XSLT-processing step</a></li><li><a href="../topics/using-plugin-URI-extension.html">Referencing files from other plug-ins</a></li><li><a href="../topics/plugin-xsltparams.html">Adding parameters to existing XSLT steps</a></li><li><a href="../topics/plugin-javalib.html">Adding a Java library to the classpath</a></li><li><a href="../topics/plugin-messages.html">Adding new diagnostic messages</a></li><li><a href="../topics/plugin-newextensions.html">Creating a new plug-in extension point</a></li><li><a href="../topics/implement-saxon-customizations.html">Adding Saxon customizations</a><ul><li><a href="../topics/implement-saxon-extension-functions.html">Saxon extensions</a></li><li class="active"><a href="../topics/implement-saxon-collation-uri-resolvers.html">Custom collation URI resolvers</a></li></ul></li></ul></li><li><a href="../topics/plugin-sample.html">Example plugin.xml file</a></li><li><a href="../topics/plugin-best-practices.html">Best practices</a></li><li><a href="../topics/plugin-coding-conventions.html">Coding conventions</a></li></ul></li><li><a href="../extension-points/plugin-extension-points.html">Extension points</a></li><li><a href="../topics/migration.html">Migrating customizations</a></li><li><a href="../topics/globalization.html">Globalizing DITA content</a></li><li><a href="../topics/rebuilding-docs.html">Rebuilding documentation</a></li></ul></li><li><a href="../topics/troubleshooting-overview.html">Troubleshooting</a></li><li><a href="../reference/index.html">Reference</a></li><li><a href="../topics/dita-and-dita-ot-resources.html">Resources</a></li></ul></nav><main role="main"><article role="article" aria-labelledby="ariaid-title1">
  7. <h1 class="title topictitle1" id="ariaid-title1">Implementing custom Saxon collation URI resolvers</h1>
  8. <div class="body"><p class="shortdesc">Plug-ins can provide custom URI resolvers that provide collators for specific collation URIs.</p>
  9. <p class="p">To do custom sorting and grouping in XSLT, you identify collators using URIs that Saxon resolves to collator
  10. implementations. You implement the mapping from collation URIs to collators through custom collation URI
  11. resolvers.</p>
  12. <p class="p">For example, the DITA Community I18N plugin provides a custom collator for doing dictionary-based sorting and
  13. grouping of Simplified Chinese. </p>
  14. <p class="p">To allow multiple plug-ins to contribute collation URI resolvers, DITA-OT defines a superinterface of Saxon’s
  15. <code class="ph codeph">CollationUriResolver</code> interface,
  16. <code class="ph codeph">org.dita.dost.module.saxon.DelegatingCollationUriResolver</code>, that takes a base resolver.</p>
  17. <p class="p">Implementations of <code class="ph codeph">DelegatingCollationUriResolver</code> should delegate to their base resolver if they
  18. do not resolve the URI specified on the resolve request. When multiple plug-ins provide resolvers it results in a
  19. chain of resolvers, ending with the built-in Saxon default resolver.</p>
  20. <div class="note note note_note"><span class="note__title">Note:</span> The order in which plug-ins will be processed during collation URI resolver configuration is variable, so two
  21. plug-ins should not try to resolve the same collation URI. In that case the first one configured will be used at
  22. run time.</div>
  23. <div class="p">A typical delegating collation URI resolver looks like
  24. this:<pre class="pre codeblock language-java"><code>public class DCI18nCollationUriResolver implements DelegatingCollationUriResolver {
  25. public static final String DITA_COMMUNITY_I18N_ZH_CNAWARE_COLLATOR =
  26. "http://org.dita-community.i18n.zhCNawareCollator";
  27. public static final String LANG_URI_PARAM = "lang";
  28. private CollationURIResolver baseResolver;
  29. public DCI18nCollationUriResolver() {
  30. super();
  31. this.baseResolver = StandardCollationURIResolver.getInstance();
  32. }
  33. public net.sf.saxon.lib.StringCollator resolve(String uri, Configuration configuration)
  34. throws XPathException {
  35. ZhCnAwareCollator collator = resolveToZhCnAwareCollator(uri, null, configuration);
  36. if (null == collator) {
  37. return baseResolver.resolve(uri, configuration);
  38. }
  39. return (StringCollator) collator;
  40. }
  41. @Override
  42. public void setBaseResolver(CollationURIResolver baseResolver) {
  43. this.baseResolver = baseResolver;
  44. }
  45. /* ... Code to evaluate the collation URI and provide the appropriate collator goes here */
  46. }</code></pre></div>
  47. <div class="p">To implement a custom collation URI resolver:
  48. <ol class="ol">
  49. <li class="li">Add your plugin’s JAR file in the DITA-OT class path as described in <a class="xref" href="plugin-javalib.html" title="You can use the dita.conductor.lib.import extension point to add an additional Java library to the DITA-OT classpath parameter.">Adding a Java library to the DITA-OT classpath</a>.</li>
  50. <li class="li">Implement an instance of <code class="ph codeph">org.dita.dost.module.saxon.DelegatingCollationUriResolver</code> as
  51. described above.</li>
  52. <li class="li">Include a file named <span class="ph filepath">org.dita.dost.module.saxon.DelegatingCollationUriResolver</span> in the
  53. directory <span class="ph filepath">META-INF/services</span> in the compiled JAR that your plug-in provides. Each line of
  54. the file must be the name of a class that implements
  55. <code class="ph codeph">org.dita.dost.module.saxon.DelegatingCollationUriResolver</code>:<pre class="pre codeblock"><code>org.example.i18n.saxon.MyCollationUriResolver</code></pre>
  56. <div class="p">You can create the services file using <code class="keyword markupname xmlelement">&lt;service&gt;</code> elements in an Ant
  57. <code class="keyword markupname xmlelement">&lt;jar&gt;</code>
  58. task:<pre class="pre codeblock language-xml"><code>&lt;jar destfile="${basedir}/target/lib/example-saxon.jar"&gt;
  59. &lt;service type="org.dita.dost.module.saxon.DelegatingCollationUriResolver"&gt;
  60. &lt;provider classname="org.example.i18n.saxon.MyCollationUriResolver"/&gt;
  61. &lt;/service&gt;
  62. &lt;/jar&gt;</code></pre></div></li>
  63. <li class="li">To use the collator in XSLT style sheets, specify the collation URI on <code class="keyword markupname xmlatt">@xsl:sort</code> elements (or
  64. anywhere a collator URI can be
  65. specified):<pre class="pre codeblock language-xml"><code>&lt;xsl:apply-templates select="word"&gt;
  66. &lt;xsl:sort collation="http://org.example.i18n.MyCollator"/&gt;
  67. &lt;/xsl:apply-templates&gt;</code></pre></li>
  68. </ol></div>
  69. </div>
  70. <nav role="navigation" class="related-links"><div class="familylinks"><div class="parentlink"><strong>Parent topic:</strong> <a class="link" href="../topics/implement-saxon-customizations.html" title="Plug-ins can contribute XSLT extension functions and collation URI resolvers. These customizations are automatically configured to work with Saxon when transformations are run using the DITA-OT pipeline task with custom XSLT.">Adding Saxon customizations</a></div></div></nav></article></main></body></html>