Debian Codegraph @

net/sf/saxon/lib/StandardEntityResolver.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.lib;
9
10 import net.sf.saxon.Configuration;
11 import org.xml.sax.EntityResolver;
12 import org.xml.sax.InputSource;
13 import org.xml.sax.SAXException;
14
15 import java.io.IOException;
16 import java.io.InputStream;
17 import java.util.ArrayList;
18 import java.util.HashMap;
19 import java.util.List;
20
21 /**
22 * This class is an EntityResolver used to resolve references to common
23 * DTDs and entity files, using local copies provided with the Saxon product.
24 * It has become necessary to do this because W3C is no longer serving
25 * these files from its server. Ideally the job of caching these files
26 * would belong to the XML parser, but because many of the parsers were
27 * issued years ago, they cannot be relied on to do it.
28 */
29 public class StandardEntityResolver implements EntityResolver {
30
31 private static StandardEntityResolver THE_INSTANCE = new StandardEntityResolver();
32
33 /**
34 * Get a general-purpose instance of this class. This should be treated as immutable,
35 * since it is shared with other users. That is, it should not be associated with any
36 * configuration.
37 *
38 * @return the singleton, general-purpose instance of this class
39 */
40
41 public static StandardEntityResolver getInstance() {
42 return THE_INSTANCE;
43 }
44
45 private static HashMap<String, String> publicIds = new HashMap<String, String>(30);
46 private static HashMap<String, String> systemIds = new HashMap<String, String>(30);
47
48 public Configuration config = null;
49
50 /**
51 * Register a DTD or other entity to be resolved by this
52 * entity resolver
53 *
54 * @param publicId the public identifier of the DTD or entity
55 * @param systemId the system identifier of the DTD or entity
56 * @param fileName the fileName of the Saxon local copy of the
57 * resource, relative to the data directory in the JAR file
58 */
59
60 public static void register(
61 /*@Nullable*/ String publicId,
62 String systemId,
63 String fileName) {
64 if (publicId != null) {
65 publicIds.put(publicId, fileName);
66 }
67 if (systemId != null) {
68 systemIds.put(systemId, fileName);
69 }
70 }
71
72 static {
73
74 register("-//W3C//ENTITIES Latin 1 for XHTML//EN",
75 "http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent",
76 "w3c/xhtml-lat1.ent");
77
78 register("-//W3C//ENTITIES Symbols for XHTML//EN",
79 "http://www.w3.org/TR/xhtml1/DTD/xhtml-symbol.ent",
80 "w3c/xhtml-symbol.ent");
81
82 register("-//W3C//ENTITIES Special for XHTML//EN",
83 "http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent",
84 "w3c/xhtml-special.ent");
85
86 register("-//W3C//DTD XHTML 1.0 Transitional//EN",
87 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd",
88 "w3c/xhtml10/xhtml1-transitional.dtd");
89
90 register("-//W3C//DTD XHTML 1.0 Strict//EN",
91 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd",
92 "w3c/xhtml10/xhtml1-strict.dtd");
93
94 register("-//W3C//DTD XHTML 1.0 Frameset//EN",
95 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd",
96 "w3c/xhtml10/xhtml1-frameset.dtd");
97
98 register("-//W3C//DTD XHTML Basic 1.0//EN",
99 "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd",
100 "w3c/xhtml10/xhtml-basic10.dtd");
101
102 register("-//W3C//DTD XHTML 1.1//EN",
103 "http://www.w3.org/MarkUp/DTD/xhtml11.dtd",
104 "w3c/xhtml11/xhtml11.dtd");
105
106 register("-//W3C//DTD XHTML Basic 1.1//EN",
107 "http://www.w3.org/MarkUp/DTD/xhtml-basic11.dtd",
108 "w3c/xhtml11/xhtml-basic11.dtd");
109
110 register("-//W3C//ELEMENTS XHTML Access Element 1.0//EN",
111 "http://www.w3.org/MarkUp/DTD/xhtml-access-1.mod",
112 "w3c/xhtml11/xhtml-access-1.mod");
113
114 register("-//W3C//ENTITIES XHTML Access Attribute Qnames 1.0//EN",
115 "http://www.w3.org/MarkUp/DTD/xhtml-access-qname-1.mod",
116 "w3c/xhtml11/xhtml-access-qname-1.mod");
117
118 register("-//W3C//ELEMENTS XHTML Java Applets 1.0//EN",
119 "http://www.w3.org/MarkUp/DTD/xhtml-applet-1.mod",
120 "w3c/xhtml11/xhtml-applet-1.mod");
121
122 register("-//W3C//ELEMENTS XHTML Base Architecture 1.0//EN",
123 "http://www.w3.org/MarkUp/DTD/xhtml-arch-1.mod",
124 "w3c/xhtml11/xhtml-arch-1.mod");
125
126 register("-//W3C//ENTITIES XHTML Common Attributes 1.0//EN",
127 "http://www.w3.org/MarkUp/DTD/xhtml-attribs-1.mod",
128 "w3c/xhtml11/xhtml-attribs-1.mod");
129
130 register("-//W3C//ELEMENTS XHTML Base Element 1.0//EN",
131 "http://www.w3.org/MarkUp/DTD/xhtml-base-1.mod",
132 "w3c/xhtml11/xhtml-base-1.mod");
133
134 register("-//W3C//ELEMENTS XHTML Basic Forms 1.0//EN",
135 "http://www.w3.org/MarkUp/DTD/xhtml-basic-form-1.mod",
136 "w3c/xhtml11/xhtml-basic-form-1.mod");
137
138 register("-//W3C//ELEMENTS XHTML Basic Tables 1.0//EN",
139 "http://www.w3.org/MarkUp/DTD/xhtml-basic-table-1.mod",
140 "w3c/xhtml11/xhtml-basic-table-1.mod");
141
142 register("-//W3C//ENTITIES XHTML Basic 1.0 Document Model 1.0//EN",
143 "http://www.w3.org/MarkUp/DTD/xhtml-basic10-model-1.mod",
144 "w3c/xhtml11/xhtml-basic10-model-1.mod");
145
146 register("-//W3C//ENTITIES XHTML Basic 1.1 Document Model 1.0//EN",
147 "http://www.w3.org/MarkUp/DTD/xhtml-basic11-model-1.mod",
148 "w3c/xhtml11/xhtml-basic11-model-1.mod");
149
150 register("-//W3C//ELEMENTS XHTML BDO Element 1.0//EN",
151 "http://www.w3.org/MarkUp/DTD/xhtml-bdo-1.mod",
152 "w3c/xhtml11/xhtml-bdo-1.mod");
153
154 register("-//W3C//ELEMENTS XHTML BIDI Override Element 1.0//EN", //should be "BDO Element 1.0" not "BIDI Override Element 1.0"
155 "http://www.w3.org/MarkUp/DTD/xhtml-bdo-1.mod",
156 "w3c/xhtml11/xhtml-bdo-1.mod");
157
158 register("-//W3C//ELEMENTS XHTML Block Phrasal 1.0//EN",
159 "http://www.w3.org/MarkUp/DTD/xhtml-blkphras-1.mod",
160 "w3c/xhtml11/xhtml-blkphras-1.mod");
161
162 register("-//W3C//ELEMENTS XHTML Block Presentation 1.0//EN",
163 "http://www.w3.org/MarkUp/DTD/xhtml-blkpres-1.mod",
164 "w3c/xhtml11/xhtml-blkpres-1.mod");
165
166 register("-//W3C//ELEMENTS XHTML Block Structural 1.0//EN",
167 "http://www.w3.org/MarkUp/DTD/xhtml-blkstruct-1.mod",
168 "w3c/xhtml11/xhtml-blkstruct-1.mod");
169
170 register("-//W3C//ENTITIES XHTML Character Entities 1.0//EN",
171 "http://www.w3.org/MarkUp/DTD/xhtml-charent-1.mod",
172 "w3c/xhtml11/xhtml-charent-1.mod");
173
174 register("-//W3C//ELEMENTS XHTML Client-side Image Maps 1.0//EN",
175 "http://www.w3.org/MarkUp/DTD/xhtml-csismap-1.mod",
176 "w3c/xhtml11/xhtml-csismap-1.mod");
177
178 register("-//W3C//ENTITIES XHTML Datatypes 1.0//EN",
179 "http://www.w3.org/MarkUp/DTD/xhtml-datatypes-1.mod",
180 "w3c/xhtml11/xhtml-datatypes-1.mod");
181
182 register("-//W3C//ELEMENTS XHTML Editing Markup 1.0//EN",
183 "http://www.w3.org/MarkUp/DTD/xhtml-edit-1.mod",
184 "w3c/xhtml11/xhtml-edit-1.mod");
185
186 register("-//W3C//ELEMENTS XHTML Editing Elements 1.0//EN", // should be "Editing Markup" not "Editing Elements", but allow both
187 "http://www.w3.org/MarkUp/DTD/xhtml-edit-1.mod",
188 "w3c/xhtml11/xhtml-edit-1.mod");
189
190 register("-//W3C//ENTITIES XHTML Intrinsic Events 1.0//EN",
191 "http://www.w3.org/MarkUp/DTD/xhtml-events-1.mod",
192 "w3c/xhtml11/xhtml-events-1.mod");
193
194 register("-//W3C//ELEMENTS XHTML Forms 1.0//EN",
195 "http://www.w3.org/MarkUp/DTD/xhtml-form-1.mod",
196 "w3c/xhtml11/xhtml-form-1.mod");
197
198 register("-//W3C//ELEMENTS XHTML Frames 1.0//EN",
199 "http://www.w3.org/MarkUp/DTD/xhtml-frames-1.mod",
200 "w3c/xhtml11/xhtml-frames-1.mod");
201
202 register("-//W3C//ENTITIES XHTML Modular Framework 1.0//EN",
203 "http://www.w3.org/MarkUp/DTD/xhtml-framework-1.mod",
204 "w3c/xhtml11/xhtml-framework-1.mod");
205
206 register("-//W3C//ENTITIES XHTML HyperAttributes 1.0//EN",
207 "http://www.w3.org/MarkUp/DTD/xhtml-hyperAttributes-1.mod",
208 "w3c/xhtml11/xhtml-hyperAttributes-1.mod");
209
210 register("-//W3C//ELEMENTS XHTML Hypertext 1.0//EN",
211 "http://www.w3.org/MarkUp/DTD/xhtml-hypertext-1.mod",
212 "w3c/xhtml11/xhtml-hypertext-1.mod");
213
214 register("-//W3C//ELEMENTS XHTML Inline Frame Element 1.0//EN",
215 "http://www.w3.org/MarkUp/DTD/xhtml-iframe-1.mod",
216 "w3c/xhtml11/xhtml-iframe-1.mod");
217
218 register("-//W3C//ELEMENTS XHTML Images 1.0//EN",
219 "http://www.w3.org/MarkUp/DTD/xhtml-image-1.mod",
220 "w3c/xhtml11/xhtml-image-1.mod");
221
222 register("-//W3C//ELEMENTS XHTML Inline Phrasal 1.0//EN",
223 "http://www.w3.org/MarkUp/DTD/xhtml-inlphras-1.mod",
224 "w3c/xhtml11/xhtml-inlphras-1.mod");
225
226 register("-//W3C//ELEMENTS XHTML Inline Presentation 1.0//EN",
227 "http://www.w3.org/MarkUp/DTD/xhtml-inlpres-1.mod",
228 "w3c/xhtml11/xhtml-inlpres-1.mod");
229
230 register("-//W3C//ELEMENTS XHTML Inline Structural 1.0//EN",
231 "http://www.w3.org/MarkUp/DTD/xhtml-inlstruct-1.mod",
232 "w3c/xhtml11/xhtml-inlstruct-1.mod");
233
234 register("-//W3C//ENTITIES XHTML Inline Style 1.0//EN", // should be "ELEMENTS" not "ENTITIES", but allow either
235 "http://www.w3.org/MarkUp/DTD/xhtml-inlstyle-1.mod",
236 "w3c/xhtml11/xhtml-inlstyle-1.mod");
237
238 register("-//W3C//ELEMENTS XHTML Inline Style 1.0//EN",
239 "http://www.w3.org/MarkUp/DTD/xhtml-inlstyle-1.mod",
240 "w3c/xhtml11/xhtml-inlstyle-1.mod");
241
242 register("-//W3C//ELEMENTS XHTML Inputmode 1.0//EN",
243 "http://www.w3.org/MarkUp/DTD/xhtml-inputmode-1.mod",
244 "w3c/xhtml11/xhtml-inputmode-1.mod");
245
246 register("-//W3C//ELEMENTS XHTML Legacy Markup 1.0//EN",
247 "http://www.w3.org/MarkUp/DTD/xhtml-legacy-1.mod",
248 "w3c/xhtml11/xhtml-legacy-1.mod");
249
250 register("-//W3C//ELEMENTS XHTML Legacy Redeclarations 1.0//EN",
251 "http://www.w3.org/MarkUp/DTD/xhtml-legacy-redecl-1.mod",
252 "w3c/xhtml11/xhtml-legacy-redecl-1.mod");
253
254 register("-//W3C//ELEMENTS XHTML Link Element 1.0//EN",
255 "http://www.w3.org/MarkUp/DTD/xhtml-link-1.mod",
256 "w3c/xhtml11/xhtml-link-1.mod");
257
258 register("-//W3C//ELEMENTS XHTML Lists 1.0//EN",
259 "http://www.w3.org/MarkUp/DTD/xhtml-list-1.mod",
260 "w3c/xhtml11/xhtml-list-1.mod");
261
262 register("-//W3C//ELEMENTS XHTML Metainformation 1.0//EN",
263 "http://www.w3.org/MarkUp/DTD/xhtml-meta-1.mod",
264 "w3c/xhtml11/xhtml-meta-1.mod");
265
266 register("-//W3C//ELEMENTS XHTML Metainformation 2.0//EN",
267 "http://www.w3.org/MarkUp/DTD/xhtml-meta-2.mod",
268 "w3c/xhtml11/xhtml-meta-2.mod");
269
270 register("-//W3C//ENTITIES XHTML MetaAttributes 1.0//EN",
271 "http://www.w3.org/MarkUp/DTD/xhtml-metaAttributes-1.mod",
272 "w3c/xhtml11/xhtml-metaAttributes-1.mod");
273
274 register("-//W3C//ELEMENTS XHTML Name Identifier 1.0//EN",
275 "http://www.w3.org/MarkUp/DTD/xhtml-nameident-1.mod",
276 "w3c/xhtml11/xhtml-nameident-1.mod");
277
278 register("-//W3C//NOTATIONS XHTML Notations 1.0//EN",
279 "http://www.w3.org/MarkUp/DTD/xhtml-notations-1.mod",
280 "w3c/xhtml11/xhtml-notations-1.mod");
281
282 register("-//W3C//ELEMENTS XHTML Embedded Object 1.0//EN",
283 "http://www.w3.org/MarkUp/DTD/xhtml-object-1.mod",
284 "w3c/xhtml11/xhtml-object-1.mod");
285
286 register("-//W3C//ELEMENTS XHTML Param Element 1.0//EN",
287 "http://www.w3.org/MarkUp/DTD/xhtml-param-1.mod",
288 "w3c/xhtml11/xhtml-param-1.mod");
289
290 register("-//W3C//ELEMENTS XHTML Presentation 1.0//EN",
291 "http://www.w3.org/MarkUp/DTD/xhtml-pres-1.mod",
292 "w3c/xhtml11/xhtml-pres-1.mod");
293
294 register("-//W3C//ENTITIES XHTML-Print 1.0 Document Model 1.0//EN",
295 "http://www.w3.org/MarkUp/DTD/xhtml-print10-model-1.mod",
296 "w3c/xhtml11/xhtml-print10-model-1.mod");
297
298 register("-//W3C//ENTITIES XHTML Qualified Names 1.0//EN",
299 "http://www.w3.org/MarkUp/DTD/xhtml-qname-1.mod",
300 "w3c/xhtml11/xhtml-qname-1.mod");
301
302 register("-//W3C//ENTITIES XHTML+RDFa Document Model 1.0//EN",
303 "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-model-1.mod",
304 "w3c/xhtml11/xhtml-rdfa-model-1.mod");
305
306 register("-//W3C//ENTITIES XHTML RDFa Attribute Qnames 1.0//EN",
307 "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-qname-1.mod",
308 "w3c/xhtml11/xhtml-rdfa-qname-1.mod");
309
310 register("-//W3C//ENTITIES XHTML Role Attribute 1.0//EN",
311 "http://www.w3.org/MarkUp/DTD/xhtml-role-1.mod",
312 "w3c/xhtml11/xhtml-role-1.mod");
313
314 register("-//W3C//ENTITIES XHTML Role Attribute Qnames 1.0//EN",
315 "http://www.w3.org/MarkUp/DTD/xhtml-role-qname-1.mod",
316 "w3c/xhtml11/xhtml-role-qname-1.mod");
317
318 register("-//W3C//ELEMENTS XHTML Ruby 1.0//EN",
319 "http://www.w3.org/TR/ruby/xhtml-ruby-1.mod",
320 "w3c/xhtml11/xhtml-ruby-1.mod");
321
322 register("-//W3C//ELEMENTS XHTML Scripting 1.0//EN",
323 "http://www.w3.org/MarkUp/DTD/xhtml-script-1.mod",
324 "w3c/xhtml11/xhtml-script-1.mod");
325
326 register("-//W3C//ELEMENTS XHTML Server-side Image Maps 1.0//EN",
327 "http://www.w3.org/MarkUp/DTD/xhtml-ssismap-1.mod",
328 "w3c/xhtml11/xhtml-ssismap-1.mod");
329
330 register("-//W3C//ELEMENTS XHTML Document Structure 1.0//EN",
331 "http://www.w3.org/MarkUp/DTD/xhtml-struct-1.mod",
332 "w3c/xhtml11/xhtml-struct-1.mod");
333
334 register("-//W3C//DTD XHTML Style Sheets 1.0//EN",
335 "http://www.w3.org/MarkUp/DTD/xhtml-style-1.mod",
336 "w3c/xhtml11/xhtml-style-1.mod");
337
338 register("-//W3C//ELEMENTS XHTML Style Sheets 1.0//EN", // should be "DTD XHTML" not "ELEMENTS XHTML"
339 "http://www.w3.org/MarkUp/DTD/xhtml-style-1.mod",
340 "w3c/xhtml11/xhtml-style-1.mod");
341
342 register("-//W3C//ELEMENTS XHTML Tables 1.0//EN",
343 "http://www.w3.org/MarkUp/DTD/xhtml-table-1.mod",
344 "w3c/xhtml11/xhtml-table-1.mod");
345
346 register("-//W3C//ELEMENTS XHTML Target 1.0//EN",
347 "http://www.w3.org/MarkUp/DTD/xhtml-target-1.mod",
348 "w3c/xhtml11/xhtml-target-1.mod");
349
350 register("-//W3C//ELEMENTS XHTML Text 1.0//EN",
351 "http://www.w3.org/MarkUp/DTD/xhtml-text-1.mod",
352 "w3c/xhtml11/xhtml-text-1.mod");
353
354 register("-//W3C//ENTITIES XHTML 1.1 Document Model 1.0//EN",
355 "http://www.w3.org/MarkUp/DTD/xhtml11-model-1.mod",
356 "w3c/xhtml11/xhtml11-model-1.mod");
357
358 register("-//W3C//MathML 1.0//EN",
359 "http://www.w3.org/Math/DTD/mathml1/mathml.dtd",
360 "w3c/mathml/mathml1/mathml.dtd");
361
362 register("-//W3C//DTD MathML 2.0//EN",
363 "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd",
364 "w3c/mathml/mathml2/mathml2.dtd");
365
366 register("-//W3C//DTD MathML 3.0//EN",
367 "http://www.w3.org/Math/DTD/mathml3/mathml3.dtd",
368 "w3c/mathml/mathml3/mathml3.dtd");
369
370 register("-//W3C//DTD SVG 1.0//EN",
371 "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd",
372 "w3c/svg10/svg10.dtd");
373
374 register("-//W3C//DTD SVG 1.1//EN",
375 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd",
376 "w3c/svg11/svg11.dtd");
377
378 register("-//W3C//DTD SVG 1.1 Tiny//EN",
379 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd",
380 "w3c/svg11/svg11-tiny.dtd");
381
382 register("-//W3C//DTD SVG 1.1 Basic//EN",
383 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd",
384 "w3c/svg11/svg11-basic.dtd");
385
386 register("-//W3C//ENTITIES SVG 1.1 Document Model//EN",
387 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-model.mod",
388 "w3c/svg11/svg11-model.mod");
389
390 register("-//W3C//ENTITIES SVG 1.1 Attribute Collection//EN",
391 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-attribs.mod",
392 "w3c/svg11/svg11-attribs.mod");
393
394 register("-//W3C//ENTITIES SVG 1.1 Modular Framework//EN",
395 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-framework.mod",
396 "w3c/svg11/svg-framework.mod");
397
398 register("-//W3C//ENTITIES SVG 1.1 Datatypes//EN",
399 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-datatypes.mod",
400 "w3c/svg11/svg-datatypes.mod");
401
402 register("-//W3C//ENTITIES SVG 1.1 Qualified Name//EN",
403 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-qname.mod",
404 "w3c/svg11/svg-qname.mod");
405
406 register("-//W3C//ENTITIES SVG 1.1 Core Attribute//EN",
407 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-core-attrib.mod",
408 "w3c/svg11/svg-core-attrib.mod");
409
410 register("-//W3C//ENTITIES SVG 1.1 Container Attribute//EN",
411 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-container-attrib.mod",
412 "w3c/svg11/svg-container-attrib.mod");
413
414 register("-//W3C//ENTITIES SVG 1.1 Viewport Attribute//EN",
415 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-viewport-attrib.mod",
416 "w3c/svg11/svg-viewport-attrib.mod");
417
418 register("-//W3C//ENTITIES SVG 1.1 Paint Attribute//EN",
419 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-paint-attrib.mod",
420 "w3c/svg11/svg-paint-attrib.mod");
421
422 register("-//W3C//ENTITIES SVG 1.1 Paint Opacity Attribute//EN",
423 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-opacity-attrib.mod",
424 "w3c/svg11/svg-opacity-attrib.mod");
425
426 register("-//W3C//ENTITIES SVG 1.1 Graphics Attribute//EN",
427 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-graphics-attrib.mod",
428 "w3c/svg11/svg-graphics-attrib.mod");
429
430 register("-//W3C//ENTITIES SVG 1.1 Document Events Attribute//EN",
431 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-docevents-attrib.mod",
432 "w3c/svg11/svg-docevents-attrib.mod");
433
434 register("-//W3C//ENTITIES SVG 1.1 Graphical Element Events Attribute//EN",
435 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-graphevents-attrib.mod",
436 "w3c/svg11/svg-graphevents-attrib.mod");
437
438 register("-//W3C//ENTITIES SVG 1.1 Animation Events Attribute//EN",
439 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-animevents-attrib.mod",
440 "w3c/svg11/svg-animevents-attrib.mod");
441
442 register("-//W3C//ENTITIES SVG 1.1 XLink Attribute//EN",
443 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-xlink-attrib.mod",
444 "w3c/svg11/svg-xlink-attrib.mod");
445
446 register("-//W3C//ENTITIES SVG 1.1 External Resources Attribute//EN",
447 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-extresources-attrib.mod",
448 "w3c/svg11/svg-extresources-attrib.mod");
449
450 register("-//W3C//ELEMENTS SVG 1.1 Structure//EN",
451 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-structure.mod",
452 "w3c/svg11/svg-structure.mod");
453
454 register("-//W3C//ELEMENTS SVG 1.1 Conditional Processing//EN",
455 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-conditional.mod",
456 "w3c/svg11/svg-conditional.mod");
457
458 register("-//W3C//ELEMENTS SVG 1.1 Image//EN",
459 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-image.mod",
460 "w3c/svg11/svg-image.mod");
461
462 register("-//W3C//ELEMENTS SVG 1.1 Style//EN",
463 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-style.mod",
464 "w3c/svg11/svg-style.mod");
465
466 register("-//W3C//ELEMENTS SVG 1.1 Shape//EN",
467 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-shape.mod",
468 "w3c/svg11/svg-shape.mod");
469
470 register("-//W3C//ELEMENTS SVG 1.1 Text//EN",
471 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-text.mod",
472 "w3c/svg11/svg-text.mod");
473
474 register("-//W3C//ELEMENTS SVG 1.1 Marker//EN",
475 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-marker.mod",
476 "w3c/svg11/svg-marker.mod");
477
478 register("-//W3C//ELEMENTS SVG 1.1 Color Profile//EN",
479 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-profile.mod",
480 "w3c/svg11/svg-profile.mod");
481
482 register("-//W3C//ELEMENTS SVG 1.1 Gradient//EN",
483 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-gradient.mod",
484 "w3c/svg11/svg-gradient.mod");
485
486 register("-//W3C//ELEMENTS SVG 1.1 Pattern//EN",
487 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-pattern.mod",
488 "w3c/svg11/svg-pattern.mod");
489
490 register("-//W3C//ELEMENTS SVG 1.1 Clip//EN",
491 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-clip.mod",
492 "w3c/svg11/svg-clip.mod");
493
494 register("-//W3C//ELEMENTS SVG 1.1 Mask//EN",
495 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-mask.mod",
496 "w3c/svg11/svg-mask.mod");
497
498 register("-//W3C//ELEMENTS SVG 1.1 Filter//EN",
499 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-filter.mod",
500 "w3c/svg11/svg-filter.mod");
501
502 register("-//W3C//ELEMENTS SVG 1.1 Cursor//EN",
503 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-cursor.mod",
504 "w3c/svg11/svg-cursor.mod");
505
506 register("-//W3C//ELEMENTS SVG 1.1 Hyperlinking//EN",
507 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-hyperlink.mod",
508 "w3c/svg11/svg-hyperlink.mod");
509
510 register("-//W3C//ELEMENTS SVG 1.1 View//EN",
511 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-view.mod",
512 "w3c/svg11/svg-view.mod");
513
514 register("-//W3C//ELEMENTS SVG 1.1 Scripting//EN",
515 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-script.mod",
516 "w3c/svg11/svg-script.mod");
517
518
519 register("-//W3C//ELEMENTS SVG 1.1 Animation//EN",
520 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-animation.mod",
521 "w3c/svg11/svg-animation.mod");
522
523 register("-//W3C//ELEMENTS SVG 1.1 Font//EN",
524 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-font.mod",
525 "w3c/svg11/svg-font.mod");
526
527 register("-//W3C//ELEMENTS SVG 1.1 Extensibility//EN",
528 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg-extensibility.mod",
529 "w3c/svg11/svg-extensibility.mod");
530
531 register("-//XML-DEV//ENTITIES RDDL Document Model 1.0//EN",
532 "http://www.rddl.org/xhtml-rddl-model-1.mod",
533 "w3c/rddl/xhtml-rddl-model-1.mod");
534
535 register("-//XML-DEV//DTD XHTML RDDL 1.0//EN",
536 "http://www.rddl.org/rddl-xhtml.dtd",
537 "w3c/rddl/rddl-xhtml.dtd");
538
539 register("-//XML-DEV//ENTITIES RDDL QName Module 1.0//EN",
540 "http://www.rddl.org/rddl-qname-1.mod",
541 "w3c/rddl/rddl-qname-1.mod");
542
543 register("-//XML-DEV//ENTITIES RDDL Resource Module 1.0//EN",
544 "http://www.rddl.org/rddl-resource-1.mod",
545 "w3c/rddl/rddl-resource-1.mod");
546
547 register("-//XML-DEV//ELEMENTS RDDL Resource 1.0//EN",
548 "http://www.rddl.org/rddl-resource-1.mod",
549 "w3c/rddl/rddl-resource-1.mod");
550
551 register("-//XML-DEV//ENTITIES XLink Module 1.0//EN",
552 "http://www.rddl.org/rddl-resource-1.mod",
553 "w3c/rddl/xlink-module-1.mod");
554
555 register("-//W3C//DTD Specification V2.10//EN",
556 "http://www.w3.org/2002/xmlspec/dtd/2.10/xmlspec.dtd",
557 "w3c/xmlspec/xmlspec.dtd");
558
559 register("-//W3C//DTD XMLSCHEMA 200102//EN",
560 "http://www.w3.org/2001/XMLSchema.dtd",
561 "w3c/xmlschema10/XMLSchema.dtd");
562
563 register("datatypes",
564 "http://www.w3.org/2001/datatypes.dtd",
565 "w3c/xmlschema10/datatypes.dtd");
566
567 register("-//W3C//DTD XSD 1.1//EN",
568 "http://www.w3.org/TR/xmlschema11-1/XMLSchema.dtd",
569 "w3c/xmlschema11/XMLSchema.dtd");
570
571 register("-//W3C//DTD XSD 1.1 Datatypes//EN",
572 "http://www.w3.org/TR/xmlschema11-1/datatypes.dtd",
573 "w3c/xmlschema11/datatypes.dtd");
574
575 register("xpath-functions",
576 "http://www.w3.org/2005/xpath-functions.xsd",
577 "xpath-functions.xsd");
578
579 register("json",
580 "http://www.w3.org/2005/json.xsd",
581 "xpath-functions.xsd");
582
583 register("analyze-string",
584 "http://www.w3.org/2005/analyze-string.xsd",
585 "xpath-functions.xsd");
586
587 register("xml-to-json",
588 "xml-to-json.xsl",
589 "xml-to-json.xsl");
590
591 register("xml-to-json-indent",
592 "xml-to-json-indent.xsl",
593 "xml-to-json-indent.xsl");
594 }
595
596 /**
597 * Set configuration details. This is used to control tracing of accesses to files
598 *
599 * @param config the Saxon configuration
600 */
601
602 public void setConfiguration(Configuration config) {
603 this.config = config;
604 }
605
606 /**
607 * Allow the application to resolve external entities.
608 * <p>The parser will call this method before opening any external
609 * entity except the top-level document entity. Such entities include
610 * the external DTD subset and external parameter entities referenced
611 * within the DTD (in either case, only if the parser reads external
612 * parameter entities), and external general entities referenced
613 * within the document element (if the parser reads external general
614 * entities). The application may request that the parser locate
615 * the entity itself, that it use an alternative URI, or that it
616 * use data provided by the application (as a character or byte
617 * input stream).</p>
618 * <p>Application writers can use this method to redirect external
619 * system identifiers to secure and/or local URIs, to look up
620 * public identifiers in a catalogue, or to read an entity from a
621 * database or other input source (including, for example, a dialog
622 * box). Neither XML nor SAX specifies a preferred policy for using
623 * public or system IDs to resolve resources. However, SAX specifies
624 * how to interpret any InputSource returned by this method, and that
625 * if none is returned, then the system ID will be dereferenced as
626 * a URL. </p>
627 * <p>If the system identifier is a URL, the SAX parser must
628 * resolve it fully before reporting it to the application.</p>
629 *
630 * @param publicId The public identifier of the external entity
631 * being referenced, or null if none was supplied.
632 * @param systemId The system identifier of the external entity
633 * being referenced.
634 * @return An InputSource object describing the new input source,
635 * or null to request that the parser open a regular
636 * URI connection to the system identifier.
637 * @throws org.xml.sax.SAXException Any SAX exception, possibly
638 * wrapping another exception.
639 * @throws java.io.IOException A Java-specific IO exception,
640 * possibly the result of creating a new InputStream
641 * or Reader for the InputSource.
642 * @see org.xml.sax.InputSource
643 */
644 public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
645 // See if it's a known public ID
646 // System.err.println("Requesting PUBLIC '" + publicId + "' at '" + systemId + "'");
647 String fileName = publicIds.get(publicId);
648 if (fileName != null) {
649 return fetch(fileName, config);
650 }
651
652 // See if it's a known system ID
653 fileName = systemIds.get(systemId);
654 if (fileName != null) {
655 return fetch(fileName, config);
656 }
657
658 // If this is a W3C URI, Saxon ought really to have a copy...
659 if (systemId.startsWith("http://www.w3.org/") && config.isTiming()) {
660 config.getStandardErrorOutput().println("Saxon does not have a local copy of PUBLIC " + publicId + " SYSTEM " + systemId);
661 }
662
663 // If it's a classpath URI, handle it here
664 if (systemId.startsWith("classpath:") && systemId.length() > 10) {
665 return getResource(systemId.substring(10), config);
666 }
667
668 // Otherwise, leave the parser to resolve the URI in the normal way
669 return null;
670 }
671
672 /**
673 * Get the source from a given file.
674 * @param filename the name of the file
675 * @param config the Saxon Configuration
676 * @return an InputSource representing the contents of the file.
677 */
678
679 public static InputSource fetch(String filename, Configuration config) {
680 boolean tracing = false;
681 Logger traceDestination = null;
682 if (config != null) {
683 tracing = config.isTiming();
684 traceDestination = config.getLogger();
685 }
686 if (tracing) {
687 if (traceDestination == null) {
688 traceDestination = new StandardLogger();
689 }
690 traceDestination.info("Fetching Saxon copy of " + filename);
691 }
692 List<String> messages = new ArrayList<String>();
693 List<ClassLoader> classLoaders = new ArrayList<ClassLoader>();
694 InputStream in = Configuration.locateResource(filename, messages, classLoaders);
695 if (tracing) {
696 for (String s : messages) {
697 traceDestination.info(s);
698 }
699 }
700 if (in == null) {
701 return null;
702 }
703 InputSource result = new InputSource(in);
704 result.setSystemId("classpath:" + filename);
705 return result;
706 }
707
708 /**
709 * Get a resource from the classpath. This method is called if the URI uses the (Spring-defined)
710 * "classpath" URI scheme. It attempts to locate the resource on the
711 * classpath and returns an InputSource containing the relevant InputStream. If the
712 * inputstream cannot be located, it returns null. A subclass that does not want classpath
713 * URIs to be resolved in this way should override this method to return null unconditionally.
714 *
715 * @param resourceName the resource to be fetched from the classpath
716 * @param config the Saxon Configuration object
717 * @return an InputSource representing the named resource (fetched from the classpath)
718 * or null if no resource is available.
719 */
720
721 protected InputSource getResource(String resourceName, Configuration config) {
722 InputStream inputStream = config.getDynamicLoader().getResourceAsStream(resourceName);
723 if (inputStream != null) {
724 InputSource inputSource = new InputSource(inputStream);
725 inputSource.setSystemId("classpath:" + resourceName);
726 return inputSource;
727 } else {
728 return null;
729 }
730 }
731 }
732