Chapter 4 XML Processing
181
return source;
}
return null;
}
// Maps an external entity URI or Public Identifier to a
// physical location.
public String mapEntityURI(String entityURI) {
return entityCatalog.getProperty(entityURI);
}
public InputSource resolveEntity(String entityURI,
String entityURL) {
InputSource source = null;
try {
// Try first to map its URI/PublicId using the catalog.
if (entityURI != null) {
String mappedLocation = mapEntityURI(entityURI);
if (mappedLocation != null) {
source = openLocation(mappedLocation);
if (source != null) { return source; }
}
}
// Try then to access the entity using its URL/System Id.
if (entityURL != null) {
source = openLocation(entityURL);
if (source != null) { return source; }
}
}
} catch (Exception exception) { ... }
return null; // Let the default entity resolver handle it.
}
}
Code Example 4.11
Entity Resolver Using a Simple Entity Catalog
# DTD Public Indentifier to physical location (URL or resource path)
//Sun Microsystems, Inc.
J2EE Blueprints Group//DTD LineItem 1.0//EN: /com/sun/j2ee/blue
prints/xmldocuments/rsrc/schemas/LineItem.dtd
New Page 1