Skip to content

Commit e906543

Browse files
committed
Reworked command line parsing; improved examples
1 parent 3835ba2 commit e906543

File tree

7 files changed

+629
-389
lines changed

7 files changed

+629
-389
lines changed

README.md

Lines changed: 105 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,17 @@ integrate the resolver into other applications.
77

88
## What is it?
99

10-
A simple application that performs
10+
A simple application that has three features:
1111

12-
1. Well-formed or validating parses of XML documents.
12+
1. It can parse a document and perform validation and transformation on it.
13+
2. It can perform specific lookup operations in a set of catalogs.
14+
3. It can show the catalog entries found by the resolver in a set of catalogs.
15+
16+
### Validation and parsing
17+
18+
Four operations can be performed on a document:
19+
20+
1. Well-formed or validating parsing.
1321
2. XML Schema validation with Xerces.
1422
3. RELAX NG validation with Jing.
1523
4. XSLT transformations with Saxon-HE.
@@ -18,15 +26,26 @@ Parsing XML documents demonstrates how external identifiers are
1826
resolved. The other features demonstrate various forms of URI
1927
resolution.
2028

29+
### Lookup operations
30+
31+
Performs specific lookup operations (system, public, entity, URI,
32+
etc.) and returns the resolved URI from a set of catalogs.
33+
34+
### Showing catalog entries
35+
36+
Displays all (or a subset) of the entries in a set of catalogs. This
37+
displays what the catalog parser determined to be the valid entries in
38+
the catalogs.
39+
2140
## What does it do?
2241

2342
The point of the application is to demonstrate how the resolver works;
2443
the validation outcomes and XSLT results are not the
2544
most important part.
2645

27-
The application installs a very “chatty” resolver that will print
28-
information about each request, how it was processed, and what was
29-
returned. For example:
46+
The parsing application installs a very “chatty” resolver that will
47+
print information about each request, how it was processed, and what
48+
was returned. For example:
3049

3150
```
3251
✗ Resolved: [dtd]: https://example.com/sample.dtd (-//Example//DTD Sample v1.0//EN)
@@ -51,46 +70,71 @@ comes from a `jar:` or `classpath:` URI.
5170

5271
## Command line options
5372

54-
Running the application with no arguments will print a summary of the
73+
Running the application with no arguments will a summary of the
5574
command line options:
5675

5776
```
58-
$ java -jar sampleapp-3.0.1beta3.jar
59-
Usage: org.xmlresolver.example.SampleApp [options] document.xml
60-
61-
Options:
62-
-dtd Perform a (DTD) validating parse of the document
63-
-xsd:file Perform XML Schema validation with XML Schema ‘file’
64-
-rng:file Perform RELAX NG validation with RELAX NG grammar ‘file’
65-
-xsl:file Perform an XSLT transformation with stylesheet ‘file’
66-
-catalog:file Use ‘file’ as an XML Catalog
67-
-cache[:dir] Enable caching (using ‘dir’ as the cache directory)
68-
-validate Validate catalog files when they’re loaded
69-
-[no-]resolver [Don't] use the resolver (the default)
70-
-[no-]classpath-catalogs [Don't] search the classpath for catalogs
71-
-help Print this usage message
72-
73-
The -catalog and -xsd options may be repeated.
74-
```
75-
76-
The filename you provide will be parsed and processed according to the
77-
options provided:
78-
79-
* `-dtd` enables DTD validation during the initial parse
80-
* `-xsd` enables XML Schema validation with the specified schema(s)
81-
* `-rng` enables RELAX NG validation with the specified grammar
82-
* `-xsl` enables XSLT transformation with the specified stylesheet
83-
* `-catalog` allows you to specify one or more catalogs to use
84-
* `-cache` enables caching. If you specify a directory, it will be used
85-
as the cache directory. If you don’t specify a directory, the default
86-
is `./xmlresolver-cache`.
87-
* `-validate` enables validation *of the XML Catalog files*; this has nothing
88-
to do with the main document being processed
89-
* `-no-resolver` will disable the resolver entirely. By default, the resolver
90-
will be used.
91-
* `-no-classpath-catalogs` will disable automatic searching for catalogs on
92-
the classpath. By default, the resolver will search for catalogs in
93-
`org/xmlresolver/catalog.xml` on the classpath.
77+
$ java -jar sampleapp-3.0.1-SNAPSHOT.jar
78+
Usage: SampleApp [options] [command] [command options]
79+
Options:
80+
-help, -h, --help
81+
Display help
82+
-cache
83+
Enable caching
84+
Default: false
85+
-cache-directory, -cache-dir
86+
Directory to use for caching (implies -cache)
87+
-catalog
88+
Use XML Catalog for resolution
89+
Default: []
90+
-classpath-catalogs, -cp
91+
Search the classpath for catalogs
92+
Default: true
93+
-resolver
94+
Use the XML Resolver during processing
95+
Default: true
96+
-validate
97+
Validate catalog files
98+
Default: false
99+
Commands:
100+
parse Parse, validate, and/or transform a document
101+
Usage: parse [options] The document to process
102+
Options:
103+
-dtd
104+
Perform a (DTD) validating parse
105+
Default: false
106+
-rng
107+
Perform RELAX NG validation with grammar
108+
-xsd
109+
Perform XML Schema validation with schema(s)
110+
Default: []
111+
-xsl
112+
Transform the document wht the XSL stylesheet
113+
114+
lookup Lookup entries in the catalog(s)
115+
Usage: lookup [options]
116+
Options:
117+
-name
118+
Specify the doctype or entity name
119+
-nature
120+
Specify the namespace nature
121+
-public
122+
Specify the public identifier
123+
-purpose
124+
Specify the namespace purpose
125+
-system
126+
Specify the system identifier
127+
-type
128+
Perform lookup of a particular type
129+
-uri
130+
Specify the URI
131+
132+
show Show the content of the catalog(s)
133+
Usage: show [options]
134+
Options:
135+
-regex, -r
136+
A regular expression to filter the entries shown
137+
```
94138

95139
## Examples
96140

@@ -108,7 +152,7 @@ If you simply parse a JATS document, it will download all of the required
108152
DTD files:
109153

110154
```
111-
$ java -jar sampleapp-3.0.1beta3.jar -dtd xml/jats/doc.xml
155+
$ java -jar sampleapp-3.0.1-SNAPSHOT.jar -dtd xml/jats/doc.xml
112156
Performing a (DTD) validating parse of xml/jats/doc.xml
113157
✗ Resolved: [dtd]: https://jats.nlm.nih.gov/articleauthoring/1.2/JATS-articleauthoring1.dtd
114158
✗ Resolved: %articleauthcustom-modules.ent: https://jats.nlm.nih.gov/articleauthoring/1.2/JATS-articleauthcustom-modules1.ent (-//NLM//DTD JATS (Z39.96) Article Authoring DTD-Specific Modules v1.2 20190208//EN)
@@ -125,7 +169,7 @@ The distribution includes a local copy of the JATS DTD files and a
125169
catalog that uses them:
126170

127171
```
128-
$ java -jar sampleapp-3.0.1beta3.jar -dtd -catalog:schema/jats/catalog.xml xml/jats/doc.xml
172+
$ java -jar sampleapp-3.0.1-SNAPSHOT.jar -dtd -catalog:schema/jats/catalog.xml xml/jats/doc.xml
129173
Performing a (DTD) validating parse of xml/jats/doc.xml
130174
✓ Resolved: [dtd]: https://jats.nlm.nih.gov/articleauthoring/1.2/JATS-articleauthoring1.dtd
131175
as: file:/Users/ndw/Projects/xmlresolver/sampleapp/build/stage/schema/jats/1.2/JATS-articleauthoring1.dtd
@@ -152,7 +196,7 @@ simplify the catalog to just a single “rewrite” entry.
152196
There’s one in `schema/jats/rewrite.xml`:
153197

154198
```
155-
$ java -jar sampleapp-3.0.1beta3.jar -dtd -catalog:schema/jats/rewrite.xml xml/jats/doc.xml
199+
$ java -jar sampleapp-3.0.1-SNAPSHOT.jar -dtd -catalog:schema/jats/rewrite.xml xml/jats/doc.xml
156200
✓ Resolved: [dtd]: https://jats.nlm.nih.gov/articleauthoring/1.2/JATS-articleauthoring1.dtd
157201
as: file:/Users/ndw/Projects/xmlresolver/sampleapp/build/stage/schema/jats/1.2/JATS-articleauthoring1.dtd
158202
from: file:/Users/ndw/Projects/xmlresolver/sampleapp/build/stage/schema/jats/1.2/JATS-articleauthoring1.dtd
@@ -173,7 +217,7 @@ Another way to take advantage of catalogs without having to maintain them yourse
173217
is to use the caching feature:
174218

175219
```
176-
$ java -jar sampleapp-3.0.1beta3.jar -dtd -cache xml/jats/doc.xml
220+
$ java -jar sampleapp-3.0.1-SNAPSHOT.jar -dtd -cache xml/jats/doc.xml
177221
✓ Resolved: [dtd]: https://jats.nlm.nih.gov/articleauthoring/1.2/JATS-articleauthoring1.dtd
178222
as: https://jats.nlm.nih.gov/articleauthoring/1.2/JATS-articleauthoring1.dtd
179223
from: file:/Users/ndw/Projects/xmlresolver/sampleapp/build/stage/xmlresolver-cache/data/7be3429ebd754b3978ae10454ea09856dce0c83e1d11eb2400939b9cfa9246c5.dtd
@@ -200,7 +244,7 @@ JATS directory:
200244
```
201245
✓ Resolved: %ent-mmlextra: file:/Users/ndw/Projects/xmlresolver/sampleapp/build/stage/schema/jats/1.2/mathml/mmlextra.ent (-//W3C//ENTITIES Extra for MathML 2.0//EN)
202246
as: mathml/mmlextra.ent
203-
from: jar:file:/Users/ndw/Projects/xmlresolver/sampleapp/build/stage/lib/xmlresolver-3.0.1beta3-SNAPSHOT-data.jar!/org/xmlresolver/www.w3.org/Math/DTD/mathml2/mathml/mmlextra.ent
247+
from: jar:file:/Users/ndw/Projects/xmlresolver/sampleapp/build/stage/lib/xmlresolver-3.0.1-SNAPSHOT-data.jar!/org/xmlresolver/www.w3.org/Math/DTD/mathml2/mathml/mmlextra.ent
204248
```
205249

206250
The XML Resolver ships with a “data” jar file that contains a large
@@ -210,7 +254,7 @@ catalog and used to resolve the entity. If you tell the resolver not
210254
to search for catalogs on the classpath, this won’t happen:
211255

212256
```
213-
$ java -jar sampleapp-3.0.1beta3.jar -dtd -catalog:schema/jats/rewrite.xml xml/jats/doc.xml
257+
$ java -jar sampleapp-3.0.1-SNAPSHOT.jar -dtd -catalog:schema/jats/rewrite.xml xml/jats/doc.xml
214258
215259
✗ Resolved: %ent-mmlextra: file:/Users/ndw/Projects/xmlresolver/sampleapp/build/stage/schema/jats/1.2/mathml/mmlextra.ent (-//W3C//ENTITIES Extra for MathML 2.0//EN)
216260
@@ -228,7 +272,7 @@ servers anyway, you’ll eventually get locked out entirely.)
228272
You can see this if you try to parse an XHTML document:
229273

230274
```
231-
$ java -jar sampleapp-3.0.1beta3.jar -dtd -no-classpath-catalogs xml/xhtml/index.xhtml
275+
$ java -jar sampleapp-3.0.1-SNAPSHOT.jar -dtd -no-classpath-catalogs xml/xhtml/index.xhtml
232276
Performing a (DTD) validating parse of xml/xhtml/index.xhtml
233277
✗ Resolved: [dtd]: https://www.w3.org/MarkUp/DTD/xhtml11.dtd (-//W3C//DTD XHTML 1.1//EN)
234278
✗ Resolved: %xhtml-inlstyle.mod: http://www.w3.org/MarkUp/DTD/xhtml-inlstyle-1.mod (-//W3C//ELEMENTS XHTML Inline Style 1.0//EN)
@@ -243,13 +287,13 @@ Try it again, letting the resolver use the data jar, and it takes only a
243287
fraction of a second:
244288

245289
```
246-
$ java -jar sampleapp-3.0.1beta3.jar -dtd xml/xhtml/index.xhtml
290+
$ java -jar sampleapp-3.0.1-SNAPSHOT.jar -dtd xml/xhtml/index.xhtml
247291
✓ Resolved: [dtd]: https://www.w3.org/MarkUp/DTD/xhtml11.dtd (-//W3C//DTD XHTML 1.1//EN)
248292
as: https://www.w3.org/MarkUp/DTD/xhtml11.dtd
249-
from: jar:file:/Users/ndw/Projects/xmlresolver/sampleapp/build/stage/lib/xmlresolver-3.0.1beta3-SNAPSHOT-data.jar!/org/xmlresolver/www.w3.org/MarkUp/DTD/xhtml11.dtd
293+
from: jar:file:/Users/ndw/Projects/xmlresolver/sampleapp/build/stage/lib/xmlresolver-3.0.1-SNAPSHOT-data.jar!/org/xmlresolver/www.w3.org/MarkUp/DTD/xhtml11.dtd
250294
✓ Resolved: %xhtml-inlstyle.mod: http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlstyle-1.mod (-//W3C//ELEMENTS XHTML Inline Style 1.0//EN)
251295
as: http://www.w3.org/TR/xhtml-modularization/DTD/xhtml-inlstyle-1.mod
252-
from: jar:file:/Users/ndw/Projects/xmlresolver/sampleapp/build/stage/lib/xmlresolver-3.0.1beta3-SNAPSHOT-data.jar!/org/xmlresolver/www.w3.org/MarkUp/DTD/xhtml-inlstyle-1.mod
296+
from: jar:file:/Users/ndw/Projects/xmlresolver/sampleapp/build/stage/lib/xmlresolver-3.0.1-SNAPSHOT-data.jar!/org/xmlresolver/www.w3.org/MarkUp/DTD/xhtml-inlstyle-1.mod
253297
254298
```
255299

@@ -260,8 +304,8 @@ still wanted fast access to the data jar resources, you can specify the catalog
260304
explicitly:
261305

262306
```
263-
$ java -jar sampleapp-3.0.1beta3.jar -dtd -no-classpath-catalogs \
264-
-catalog:jar:file:lib/xmlresolver-3.0.1beta3-SNAPSHOT-data.jar!/org/xmlresolver/catalog.xml \
307+
$ java -jar sampleapp-3.0.1-SNAPSHOT.jar -dtd -no-classpath-catalogs \
308+
-catalog:jar:file:lib/xmlresolver-3.0.1-SNAPSHOT-data.jar!/org/xmlresolver/catalog.xml \
265309
xml/xhtml/index.xhtml
266310
267311
```
@@ -274,10 +318,10 @@ Usually, the resolver ignores catalog errors. You don’t want your production a
274318
falling over because someone puts a typo in a catalog:
275319

276320
```
277-
$ java -jar sampleapp-3.0.1beta3.jar -dtd -catalog:schema/caterror.xml xml/xhtml/index.xhtml
321+
$ java -jar sampleapp-3.0.1-SNAPSHOT.jar -dtd -catalog:schema/caterror.xml xml/xhtml/index.xhtml
278322
✓ Resolved: [dtd]: https://www.w3.org/MarkUp/DTD/xhtml11.dtd (-//W3C//DTD XHTML 1.1//EN)
279323
as: https://www.w3.org/MarkUp/DTD/xhtml11.dtd
280-
from: jar:file:/Users/ndw/Projects/xmlresolver/sampleapp/build/stage/lib/xmlresolver-3.0.1beta3-SNAPSHOT-data.jar!/org/xmlresolver/www.w3.org/MarkUp/DTD/xhtml11.dtd
324+
from: jar:file:/Users/ndw/Projects/xmlresolver/sampleapp/build/stage/lib/xmlresolver-3.0.1-SNAPSHOT-data.jar!/org/xmlresolver/www.w3.org/MarkUp/DTD/xhtml11.dtd
281325
282326
```
283327

@@ -286,7 +330,7 @@ resolver to process catalogs with a validating parser. This will throw an except
286330
if an invalid catalog is loaded:
287331

288332
```
289-
$ java -jar sampleapp-3.0.1beta3.jar -dtd -validate -catalog:schema/caterror.xml xml/xhtml/index.xhtml
333+
$ java -jar sampleapp-3.0.1-SNAPSHOT.jar -dtd -validate -catalog:schema/caterror.xml xml/xhtml/index.xhtml
290334
Exception in thread "main" org.xmlresolver.exceptions.CatalogInvalidException: Catalog 'file:/Users/ndw/Projects/xmlresolver/sampleapp/build/stage/schema/caterror.xml' is invalid: attribute "systemid" not allowed here; expected attribute "id", "systemId" or "uri" or an attribute from another namespace
291335
at org.xmlresolver.loaders.ValidatingXmlLoader.loadCatalog(ValidatingXmlLoader.java:147)
292336
@@ -303,7 +347,7 @@ public identifier involved.
303347
There’s a sample schema in RELAX NG in the distribution:
304348

305349
```
306-
$ java -jar sampleapp-3.0.1beta3.jar -catalog:schema/sample/catalog.xml -rng:schema/sample/sample.rnc xml/sample/doc.xml
350+
$ java -jar sampleapp-3.0.1-SNAPSHOT.jar -catalog:schema/sample/catalog.xml -rng:schema/sample/sample.rnc xml/sample/doc.xml
307351
✗ Resolved: book (file:///Users/ndw/Projects/xmlresolver/sampleapp/build/stage/xml/sample/doc.xml)
308352
Parse complete
309353
✗ Resolved: schema/sample/sample.rnc
@@ -325,7 +369,7 @@ construct the call to java with an explicit classpath:
325369

326370
```
327371
$ java -cp docbook/schemas-docbook-5.2b10a4.jar\
328-
:sampleapp-3.0.1beta3.jar org.xmlresolver.example.SampleApp \
372+
:sampleapp-3.0.1-SNAPSHOT.jar org.xmlresolver.example.SampleApp \
329373
-rng:xml/docbook/schema.rng xml/docbook/doc.xml
330374
✗ Resolved: article (file:///Users/ndw/Projects/xmlresolver/sampleapp/build/stage/xml/docbook/doc.xml)
331375
Parse complete
@@ -350,7 +394,7 @@ Using a catalog for XML Schema validation is also much the same.
350394
There’s a sample XML Schema in the distribution:
351395

352396
```
353-
$ java -jar sampleapp-3.0.1beta3.jar -catalog:schema/sample/catalog.xml -xsd:schema/sample/sample.rnc xml/sample/doc.xml
397+
$ java -jar sampleapp-3.0.1-SNAPSHOT.jar -catalog:schema/sample/catalog.xml -xsd:schema/sample/sample.rnc xml/sample/doc.xml
354398
✗ Resolved: book (file:///Users/ndw/Projects/xmlresolver/sampleapp/build/stage/xml/sample/doc.xml)
355399
Parse complete
356400
✓ Resolved: http://www.w3.org/2001/XMLSchema: https://xmlresolver.org/ns/sample/blocks.xsd (http://xmlresolver.com/ns/sample)
@@ -371,7 +415,7 @@ resolve stylesheet URIs:
371415
```
372416
$ java -cp docbook/docbook-xslTNG-1.5.0.jar\
373417
:docbook/schemas-docbook-5.2b10a4.jar\
374-
:sampleapp-3.0.1beta3.jar org.xmlresolver.example.SampleApp \
418+
:sampleapp-3.0.1-SNAPSHOT.jar org.xmlresolver.example.SampleApp \
375419
-rng:xml/docbook/schema.rng -xsl:xml/docbook/style.xsl xml/docbook/doc.xml
376420
✗ Resolved: article (file:///Users/ndw/Projects/xmlresolver/sampleapp/build/stage/xml/docbook/doc.xml)
377421
Parse complete
@@ -389,17 +433,3 @@ RELAX NG validation: valid
389433
390434
Done
391435
```
392-
393-
## What is the other jar file?
394-
395-
The distribution also contains a copy of the “apps” jar from the XML
396-
Resolver. This jar contains the “CacheDetails” application that will
397-
show you what is in your XML Resolver cache, if you have one.
398-
399-
Try:
400-
401-
```
402-
$ java -jar xmlresolver-3.0.1beta3-apps.jar ./resolver-cache
403-
Cache contains 73 entries
404-
405-
```

0 commit comments

Comments
 (0)