@@ -40,7 +40,8 @@ public class Catalog implements EntityResolver2 {
4040 private Map <String , String > publicCatalog ;
4141 private Map <String , String > uriCatalog ;
4242 private Map <String , String > dtdCatalog ;
43- private Map <String , String > dtdEntities ;
43+ private Map <String , String > dtdPublicEntities ;
44+ private Map <String , String > dtdSystemEntities ;
4445 private Set <String > parsedDTDs ;
4546 private List <String []> uriRewrites ;
4647 private List <String []> systemRewrites ;
@@ -327,8 +328,11 @@ public InputSource resolveEntity(String name, String publicId, String baseURI, S
327328 } catch (IOException | URISyntaxException | IllegalArgumentException | NullPointerException e ) {
328329 // ignore
329330 }
330- if (dtdEntities != null && publicId != null && dtdEntities .containsKey (publicId )) {
331- return new InputSource (new FileInputStream (dtdEntities .get (publicId )));
331+ if (dtdPublicEntities != null && publicId != null && dtdPublicEntities .containsKey (publicId )) {
332+ return new InputSource (new FileInputStream (dtdPublicEntities .get (publicId )));
333+ }
334+ if (dtdSystemEntities != null && systemId != null && dtdSystemEntities .containsKey (systemId )) {
335+ return new InputSource (new FileInputStream (dtdSystemEntities .get (systemId )));
332336 }
333337 return null ;
334338 }
@@ -423,12 +427,21 @@ public String getDTD(String name) {
423427 return null ;
424428 }
425429
426- public void addDtdEntity (String publicId , String path ) {
427- if (dtdEntities == null ) {
428- dtdEntities = new Hashtable <>();
430+ public void addDtdPublicEntity (String publicId , String path ) {
431+ if (dtdPublicEntities == null ) {
432+ dtdPublicEntities = new Hashtable <>();
433+ }
434+ if (!dtdPublicEntities .containsKey (publicId )) {
435+ dtdPublicEntities .put (publicId , path );
436+ }
437+ }
438+
439+ public void addDtdSystemEntity (String systemId , String path ) {
440+ if (dtdSystemEntities == null ) {
441+ dtdSystemEntities = new Hashtable <>();
429442 }
430- if (!dtdEntities .containsKey (publicId )) {
431- dtdEntities .put (publicId , path );
443+ if (!dtdSystemEntities .containsKey (systemId )) {
444+ dtdSystemEntities .put (systemId , path );
432445 }
433446 }
434447
@@ -448,7 +461,13 @@ public void parseDTD(String publicId) {
448461 EntityDecl entity = it .next ();
449462 String path = XMLUtils .getAbsolutePath (dtdFile .getParentFile ().getAbsolutePath (),
450463 entity .getValue ());
451- addDtdEntity (entity .getPublicId (), path );
464+ addDtdPublicEntity (entity .getPublicId (), path );
465+ }
466+ entities = grammar .getSytemEntities ();
467+ it = entities .iterator ();
468+ while (it .hasNext ()) {
469+ EntityDecl entity = it .next ();
470+ addDtdSystemEntity (entity .getValue (), entity .getSystemId ());
452471 }
453472 } catch (IOException | SAXException e ) {
454473 // do nothing
0 commit comments