@@ -322,6 +322,71 @@ protected boolean registerSystemIdFilename(String systemId, String filename) {
322
322
return ret == null ;
323
323
}
324
324
325
+ /**
326
+ * Allows applications to map references to external entities into input
327
+ * sources.
328
+ * <p>
329
+ * This method is only called for external entities which have been properly
330
+ * declared. It provides more flexibility than the
331
+ * {@link org.xml.sax.EntityResolver EntityResolver} interface, supporting
332
+ * implementations of more complex catalogue schemes such as the one defined by
333
+ * the
334
+ * <a href= "http://www.oasis-open.org/committees/entity/spec-2001-08-06.html"
335
+ * >OASIS XML Catalogs</a> specification.
336
+ * </p>
337
+ * <p>
338
+ * Parsers configured to use this resolver method will call it to determine the
339
+ * input source to use for any external entity being included because of a
340
+ * reference in the XML text. That excludes the document entity, and any
341
+ * external entity returned by {@link #getExternalSubset getExternalSubset()}.
342
+ * When a (non-validating) processor is configured not to include a class of
343
+ * entities (parameter or general) through use of feature flags, this method is
344
+ * not invoked for such entities.
345
+ * </p>
346
+ * <p>
347
+ * If no valid input source could be determined, this method will throw a
348
+ * {@code SAXException} instead of returning {@code null} as other
349
+ * implementations would do. If you have to retrieve a DTD which is not directly
350
+ * provided by this resolver, you need to whitelist the host using
351
+ * {@link #addHostToWhiteList(String)} first. Make sure that either the systemId
352
+ * URL ends with a valid extension, or that the retrieved URL was served with a
353
+ * valid DTD media type.
354
+ * </p>
355
+ * <p>
356
+ * Note that the entity naming scheme used here is the same one used in the
357
+ * {@link org.xml.sax.ext.LexicalHandler LexicalHandler}, or in the
358
+ * {@link org.xml.sax.ContentHandler#skippedEntity
359
+ * ContentHandler.skippedEntity()} method.
360
+ * </p>
361
+ *
362
+ * @param name Identifies the external entity being resolved. Either
363
+ * "{@code [dtd]}" for the external subset, or a name starting
364
+ * with "{@code %}" to indicate a parameter entity, or else the
365
+ * name of a general entity. This is never {@code null} when
366
+ * invoked by a SAX2 parser.
367
+ * @param publicId The public identifier of the external entity being referenced
368
+ * (normalized as required by the XML specification), or
369
+ * {@code null} if none was supplied.
370
+ * @param baseURI The URI with respect to which relative systemIDs are
371
+ * interpreted. This is always an absolute URI, unless it is
372
+ * {@code null} (likely because the {@code XMLReader} was given
373
+ * an {@code InputSource} without one). This URI is defined by
374
+ * the XML specification to be the one associated with the
375
+ * "{@literal <}" starting the relevant declaration.
376
+ * @param systemId The system identifier of the external entity being
377
+ * referenced; either a relative or absolute URI. This is never
378
+ * {@code null} when invoked by a SAX2 parser; only declared
379
+ * entities, and any external subset, are resolved by such
380
+ * parsers.
381
+ *
382
+ * @return an {@code InputSource} object describing the new input source to be
383
+ * used by the parser. This implementation never returns {@code null}.
384
+ *
385
+ * @throws SAXException if either the provided arguments or the input
386
+ * source were invalid or not allowed.
387
+ * @throws java.io.IOException if an I/O problem was found while forming the URL
388
+ * to the input source, or when connecting to it.
389
+ */
325
390
@ Override
326
391
public final InputSource resolveEntity (String name , String publicId , String baseURI , String systemId )
327
392
throws SAXException , IOException {
@@ -498,15 +563,73 @@ protected boolean isValidContentType(String conType) {
498
563
|| conType .equals ("application/xml-external-parsed-entity" ));
499
564
}
500
565
566
+ /**
567
+ * Allow the application to resolve external entities.
568
+ *
569
+ * <p>
570
+ * The parser will call this method before opening any external entity except
571
+ * the top-level document entity. Such entities include the external DTD subset
572
+ * and external parameter entities referenced within the DTD (in either case,
573
+ * only if the parser reads external parameter entities), and external general
574
+ * entities referenced within the document element (if the parser reads external
575
+ * general entities). The application may request that the parser locate the
576
+ * entity itself, that it use an alternative URI, or that it use data provided
577
+ * by the application (as a character or byte input stream).
578
+ * </p>
579
+ * <p>
580
+ * If no valid input source could be determined, this method will throw a
581
+ * {@code SAXException} instead of returning {@code null} as other
582
+ * implementations would do. If you have to retrieve a DTD which is not directly
583
+ * provided by this resolver, you need to whitelist the host using
584
+ * {@link #addHostToWhiteList(String)} first. Make sure that either the systemId
585
+ * URL ends with a valid extension, or that the retrieved URL was served with a
586
+ * valid DTD media type.
587
+ * </p>
588
+ *
589
+ * @param publicId The public identifier of the external entity being
590
+ * referenced, or {@code null} if none was supplied.
591
+ * @param systemId The system identifier of the external entity being
592
+ * referenced.
593
+ * @return an {@code InputSource} object describing the new input source. This
594
+ * implementation never returns {@code null}.
595
+ * @throws SAXException if either the provided arguments or the input
596
+ * source were invalid or not allowed.
597
+ * @throws java.io.IOException if an I/O problem was found while forming the URL
598
+ * to the input source, or when connecting to it.
599
+ */
501
600
@ Override
502
601
public final InputSource resolveEntity (String publicId , String systemId ) throws SAXException , IOException {
503
602
return resolveEntity (null , publicId , null , systemId );
504
603
}
505
604
605
+ /**
606
+ * Resolve external entities according to the given {@code DocumentType}.
607
+ * <p>
608
+ * If no valid input source could be determined, this method will throw a
609
+ * {@code SAXException} instead of returning {@code null} as other
610
+ * implementations would do. If you have to retrieve a DTD which is not directly
611
+ * provided by this resolver, you need to whitelist the host using
612
+ * {@link #addHostToWhiteList(String)} first. Make sure that either the systemId
613
+ * URL ends with a valid extension, or that the retrieved URL was served with a
614
+ * valid DTD media type.
615
+ * </p>
616
+ *
617
+ * @param dtDecl the {@code DocumentType}.
618
+ * @return an {@code InputSource} object describing the new input source.
619
+ * @throws SAXException if either the provided arguments or the input
620
+ * source were invalid or not allowed.
621
+ * @throws java.io.IOException if an I/O problem was found while forming the URL
622
+ * to the input source, or when connecting to it.
623
+ */
506
624
public InputSource resolveEntity (DocumentType dtDecl ) throws SAXException , IOException {
507
625
return resolveEntity (dtDecl .getName (), dtDecl .getPublicId (), dtDecl .getBaseURI (), dtDecl .getSystemId ());
508
626
}
509
627
628
+ /**
629
+ * Set the class loader to be used to read the built-in DTDs.
630
+ *
631
+ * @param loader the class loader.
632
+ */
510
633
public void setClassLoader (ClassLoader loader ) {
511
634
this .loader = loader ;
512
635
}
0 commit comments