PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/projects/ant-1.8.2/docs/manual/Types/xmlcatalog.html

https://gitlab.com/essere.lab.public/qualitas.class-corpus
HTML | 306 lines | 268 code | 22 blank | 16 comment | 0 complexity | 0b24b97aa318c0964942835fd8ed0563 MD5 | raw file
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <meta http-equiv="Content-Language" content="en-us">
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>XMLCatalog Type</title>
  20. </head>
  21. <body>
  22. <h2><a name="XMLCatalog">XMLCatalog</a></h2>
  23. <p>An XMLCatalog is a catalog of public resources such as DTDs or
  24. entities that are referenced in an XML document. Catalogs are
  25. typically used to make web references to resources point to a locally
  26. cached copy of the resource.</p>
  27. <p>This allows the XML Parser, XSLT Processor or other consumer of XML
  28. documents
  29. to efficiently allow a local substitution for a resource available on the
  30. web.
  31. </p>
  32. <p><b>Note:</b> This task <em>uses, but does not depend on</em> external
  33. libraries not included in the Apache Ant distribution. See <a
  34. href="../install.html#librarydependencies">Library Dependencies</a> for more
  35. information.</p>
  36. <p>This data type provides a catalog of resource locations based
  37. on the <a
  38. href="http://oasis-open.org/committees/entity/spec-2001-08-06.html">
  39. OASIS "Open Catalog" standard</a>. The catalog entries are used
  40. both for Entity resolution and URI resolution, in accordance with
  41. the <code>org.xml.sax.EntityResolver</code> and <code>
  42. javax.xml.transform.URIResolver</code> interfaces as defined
  43. in the <a href="https://jaxp.dev.java.net/">Java API for XML
  44. Processing (JAXP) Specification</a>.</p>
  45. <p>For example, in a <code>web.xml</code> file, the DTD is referenced as:
  46. <pre>
  47. &lt;!DOCTYPE web-app PUBLIC &quot;-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN&quot;
  48. &quot;http://java.sun.com/j2ee/dtds/web-app_2_2.dtd&quot;&gt;
  49. </pre>
  50. The XML processor, without XMLCatalog support, would need to retrieve the
  51. DTD from
  52. the URL specified whenever validation of the document was required.
  53. </p>
  54. <p>This can be very time consuming during the build process,
  55. especially where network throughput is limited. Alternatively, you
  56. can do the following:
  57. <ol>
  58. <li>Copy <code>web-app_2_2.dtd</code> onto your local disk somewhere (either in the
  59. filesystem or even embedded inside a jar or zip file on the classpath).</li>
  60. <li>Create an <code>&lt;xmlcatalog&gt;</code> with a <code>&lt;dtd&gt;</code>
  61. element whose <code>location</code> attribute points to the file.</li>
  62. <li>Success! The XML processor will now use the local copy instead of calling out
  63. to the internet.</li>
  64. </ol>
  65. </p>
  66. <p>XMLCatalogs can appear inside tasks
  67. that support this feature or at the same level as <code>target</code>
  68. - i.e., as children of <code>project</code> for reuse across different
  69. tasks,
  70. e.g. XML Validation and XSLT Transformation. The XML Validate task
  71. uses XMLCatalogs for entity resolution. The XSLT Transformation
  72. task uses XMLCatalogs for both entity and URI resolution.</p>
  73. <p>XMLCatalogs are specified as either a reference to another
  74. XMLCatalog, defined previously in a build file, or as a list of
  75. <code>dtd</code> or <code>entity</code> locations. In addition,
  76. external catalog files may be specified in a nested <code>catalogpath</code> ,
  77. but they will be ignored unless the resolver library from
  78. xml-commons is available in the system classpath. <b>Due to backwards
  79. incompatible changes in the resolver code after the release of
  80. resolver 1.0, Ant will not support resolver.jar in version 1.0 - we
  81. expect a resolver release 1.1 to happen before Ant 1.6 gets
  82. released.</b> A separate classpath for entity resolution may be
  83. specified inline via nested <code>classpath</code> elements; otherwise
  84. the system classpath is used for this as well.</p>
  85. <p>XMLCatalogs can also be nested inside other XMLCatalogs. For
  86. example, a "superset" XMLCatalog could be made by including several
  87. nested XMLCatalogs that referred to other, previously defined
  88. XMLCatalogs.</p>
  89. <p>Resource locations can be specified either in-line or in
  90. external catalog file(s), or both. In order to use an external
  91. catalog file, the xml-commons resolver library ("resolver.jar")
  92. must be in your path. External catalog files may be either <a
  93. href="http://oasis-open.org/committees/entity/background/9401.html">
  94. plain text format</a> or <a
  95. href="http://www.oasis-open.org/committees/entity/spec-2001-08-06.html">
  96. XML format</a>. If the xml-commons resolver library is not found in the
  97. classpath, external catalog files, specified in <code>catalogpath</code>,
  98. will be ignored and a warning
  99. will be logged. In this case, however, processing of inline entries will
  100. proceed normally.</p>
  101. <p>Currently, only <code>&lt;dtd&gt;</code> and
  102. <code>&lt;entity&gt;</code> elements may be specified inline; these
  103. roughly correspond to OASIS catalog entry types <code>PUBLIC</code> and
  104. <code>URI</code> respectively. By contrast, external catalog files
  105. may use any of the entry types defined in the
  106. <a href="http://oasis-open.org/committees/entity/spec-2001-08-06.html">
  107. +OASIS specification</a>.</p>
  108. <h3><a name="ResolverAlgorithm">Entity/DTD/URI Resolution Algorithm</a></h3>
  109. When an entity, DTD, or URI is looked up by the XML processor, the
  110. XMLCatalog searches its list of entries to see if any match. That is,
  111. it attempts to match the <code>publicId</code> attribute of each entry
  112. with the PublicID or URI of the entity to be resolved. Assuming a
  113. matching entry is found, XMLCatalog then executes the following steps:
  114. <h4>1. Filesystem lookup</h4>
  115. <p>The <code>location</code> is first looked up in the filesystem. If
  116. the <code>location</code> is a relative path, the ant project basedir
  117. attribute is used as the base directory. If the <code>location</code>
  118. specifies an absolute path, it is used as is. Once we have an
  119. absolute path in hand, we check to see if a valid and readable file
  120. exists at that path. If so, we are done. If not, we proceed to the
  121. next step.</p>
  122. <h4>2. Classpath lookup</h4>
  123. <p>The <code>location</code> is next looked up in the classpath.
  124. Recall that jar files are merely fancy zip files. For classpath
  125. lookup, the <code>location</code> is used as is (no base is
  126. prepended). We use a Classloader to attempt to load the resource from
  127. the classpath. For example, if hello.jar is in the classpath and it
  128. contains <code>foo/bar/blat.dtd</code> it will resolve an entity whose
  129. <code>location</code> is <code>foo/bar/blat.dtd</code>. Of course, it
  130. will <em>not</em> resolve an entity whose <code>location</code> is
  131. <code>blat.dtd</code>.
  132. <h4>3a. Apache xml-commons resolver lookup</h4>
  133. <p>What happens next depends on whether the resolver library from
  134. xml-commons is available on the classpath. If so, we defer all
  135. further attempts at resolving to it. The resolver library supports
  136. extremely sophisticated functionality like URL rewriting and so on,
  137. which can be accessed by making the appropriate entries in external
  138. catalog files (XMLCatalog does not yet provide inline support for all
  139. of the entries defined in the <a
  140. href="http://oasis-open.org/committees/entity/spec-2001-08-06.html">OASIS
  141. standard</a>).</p>
  142. <h4>3. URL-space lookup</h4>
  143. <p>Finally, we attempt to make a URL out of the <code>location</code>.
  144. At first this may seem like this would defeat the purpose of
  145. XMLCatalogs -- why go back out to the internet? But in fact, this can
  146. be used to (in a sense) implement HTTP redirects, substituting one URL
  147. for another. The mapped-to URL might also be served by a local web
  148. server. If the URL resolves to a valid and readable resource, we are
  149. done. Otherwise, we give up. In this case, the XML processor will
  150. perform its normal resolution algorithm. Depending on the processor
  151. configuration, further resolution failures may or may not result in
  152. fatal (i.e. build-ending) errors.</p>
  153. <h3>XMLCatalog attributes</h3>
  154. <table border="1" cellpadding="2" cellspacing="0">
  155. <tr>
  156. <td valign="top"><b>Attribute</b></td>
  157. <td valign="top"><b>Description</b></td>
  158. <td align="center" valign="top"><b>Required</b></td>
  159. </tr>
  160. <tr>
  161. <td valign="top">id</td>
  162. <td valign="top">a unique name for an XMLCatalog, used for referencing
  163. the
  164. XMLCatalog's contents from another XMLCatalog</td>
  165. <td valign="top" align="center">No</td>
  166. </tr>
  167. <tr>
  168. <td valign="top">refid</td>
  169. <td valign="top">the <code>id</code> of another XMLCatalog whose
  170. contents
  171. you would like to be used for this XMLCatalog</td>
  172. <td valign="top" align="center">No</td>
  173. </tr>
  174. </table>
  175. <h3>XMLCatalog nested elements</h3>
  176. <h4>dtd/entity</h4>
  177. <p>The <code>dtd</code> and <code>entity</code> elements used to specify
  178. XMLCatalogs are identical in their structure</p>
  179. <table border="1" cellpadding="2" cellspacing="0">
  180. <tr>
  181. <td valign="top"><b>Attribute</b></td>
  182. <td valign="top"><b>Description</b></td>
  183. <td align="center" valign="top"><b>Required</b></td>
  184. </tr>
  185. <tr>
  186. <td valign="top">publicId</td>
  187. <td valign="top">The public identifier used when defining a dtd or
  188. entity,
  189. e.g. <code>&quot;-//Sun Microsystems, Inc.//DTD Web Application
  190. 2.2//EN&quot;</code>
  191. </td>
  192. <td valign="top" align="center">Yes</td>
  193. </tr>
  194. <tr>
  195. <td valign="top">location</td>
  196. <td valign="top">The location of the local replacement to be used for
  197. the public identifier specified. This may be specified as a file name,
  198. resource name found on the classpath, or a URL. Relative paths will
  199. be resolved according to the base, which by default is the Ant project
  200. basedir.
  201. </td>
  202. <td valign="top" align="center">Yes</td>
  203. </tr>
  204. </table>
  205. <h4>classpath</h4>
  206. <p>The classpath to use for <a href="#ResolverAlgorithm">entity
  207. resolution</a>. The nested <code>&lt;classpath&gt;</code> is a
  208. <a href="../using.html#path">path</a>-like structure.</p>
  209. <h4>catalogpath</h4>
  210. <p>
  211. The nested <code>catalogpath</code> element is a <a
  212. href="../using.html#path">path</a>-like structure listing catalog files to
  213. search. All files in this path are assumed to be OASIS catalog files, in
  214. either
  215. <a href="http://oasis-open.org/committees/entity/background/9401.html">
  216. plain text format</a> or <a
  217. href="http://www.oasis-open.org/committees/entity/spec-2001-08-06.html">
  218. XML format</a>. Entries specifying nonexistent files will be ignored. If the
  219. resolver library from xml-commons is not available in the classpath, all
  220. <code>catalogpaths</code> will be ignored and a warning will be logged.
  221. </p>
  222. <h3>Examples</h3>
  223. <p>Set up an XMLCatalog with a single dtd referenced locally in a user's
  224. home
  225. directory:</p>
  226. <blockquote><pre>
  227. &lt;xmlcatalog&gt;
  228. &lt;dtd
  229. publicId=&quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot;
  230. location=&quot;/home/dion/downloads/docbook/docbookx.dtd&quot;/&gt;
  231. &lt;/xmlcatalog&gt;
  232. </pre></blockquote>
  233. <p>Set up an XMLCatalog with a multiple dtds to be found either in the
  234. filesystem (relative to the Ant project basedir) or in the classpath:
  235. </p>
  236. <blockquote><pre>
  237. &lt;xmlcatalog id=&quot;commonDTDs&quot;&gt;
  238. &lt;dtd
  239. publicId=&quot;-//OASIS//DTD DocBook XML V4.1.2//EN&quot;
  240. location=&quot;docbook/docbookx.dtd&quot;/&gt;
  241. &lt;dtd
  242. publicId=&quot;-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN&quot;
  243. location=&quot;web-app_2_2.dtd&quot;/&gt;
  244. &lt;/xmlcatalog&gt;
  245. </pre></blockquote>
  246. <p>Set up an XMLCatalog with a combination of DTDs and entities as
  247. well as a nested XMLCatalog and external catalog files in both
  248. formats:</p>
  249. <blockquote><pre>
  250. &lt;xmlcatalog id=&quot;allcatalogs&quot;&gt;
  251. &lt;dtd
  252. publicId=&quot;-//ArielPartners//DTD XML Article V1.0//EN&quot;
  253. location=&quot;com/arielpartners/knowledgebase/dtd/article.dtd&quot;/&gt;
  254. &lt;entity
  255. publicId=&quot;LargeLogo&quot;
  256. location=&quot;com/arielpartners/images/ariel-logo-large.gif&quot;/&gt;
  257. &lt;xmlcatalog refid="commonDTDs"/&gt;
  258. &lt;catalogpath&gt;
  259. &lt;pathelement location="/etc/sgml/catalog"/&gt;
  260. &lt;fileset
  261. dir=&quot;/anetwork/drive&quot;
  262. includes=&quot;**/catalog&quot;/&gt;
  263. &lt;fileset
  264. dir=&quot;/my/catalogs&quot;
  265. includes=&quot;**/catalog.xml&quot;/&gt;
  266. &lt;/catalogpath&gt;
  267. &lt;/xmlcatalog&gt;
  268. &lt;/xmlcatalog&gt;
  269. </pre></blockquote>
  270. <p>To reference the above XMLCatalog in an <code>xslt</code> task:<p>
  271. <blockquote><pre>
  272. &lt;xslt basedir="${source.doc}"
  273. destdir="${dest.xdocs}"
  274. extension=".xml"
  275. style="${source.xsl.converter.docbook}"
  276. includes="**/*.xml"
  277. force="true"&gt;
  278. &lt;xmlcatalog refid=&quot;allcatalogs&quot;/&gt;
  279. &lt;/xslt&gt;
  280. </pre></blockquote>
  281. </body>
  282. </html>