org.hibernate.util
public class: DTDEntityResolver [javadoc |
source]
java.lang.Object
org.hibernate.util.DTDEntityResolver
All Implemented Interfaces:
Serializable, EntityResolver
Direct Known Subclasses:
EJB3DTDEntityResolver
An
EntityResolver implementation which attempts to resolve
various systemId URLs to local classpath lookups
- Any systemId URL beginning with http://hibernate.sourceforge.net/ is
searched for as a classpath resource in the classloader which loaded the
Hibernate classes.
- Any systemId URL using classpath as the scheme (i.e. starting
with classpath:// is searched for as a classpath resource using first
the current thread context classloader and then the classloader which loaded
the Hibernate classes.
Any entity references which cannot be resolved in relation to the above
rules result in returning null, which should force the SAX reader to
handle the entity reference in its default manner.
- author:
Markus - Meissner
- author:
Gavin - King
- author:
Steve - Ebersole
| Method from org.hibernate.util.DTDEntityResolver Detail: |
public InputSource resolveEntity(String publicId,
String systemId) {
if ( systemId != null ) {
log.debug( "trying to resolve system-id [" + systemId + "]" );
if ( systemId.startsWith( HIBERNATE_NAMESPACE ) ) {
log.debug( "recognized hibernate namespace; attempting to resolve on classpath under org/hibernate/" );
String path = "org/hibernate/" + systemId.substring( HIBERNATE_NAMESPACE.length() );
InputStream dtdStream = resolveInHibernateNamespace( path );
if ( dtdStream == null ) {
log.debug( "unable to locate [" + systemId + "] on classpath" );
if ( systemId.substring( HIBERNATE_NAMESPACE.length() ).indexOf( "2.0" ) > -1 ) {
log.error( "Don't use old DTDs, read the Hibernate 3.x Migration Guide!" );
}
}
else {
log.debug( "located [" + systemId + "] in classpath" );
InputSource source = new InputSource( dtdStream );
source.setPublicId( publicId );
source.setSystemId( systemId );
return source;
}
}
else if ( systemId.startsWith( USER_NAMESPACE ) ) {
log.debug( "recognized local namespace; attempting to resolve on classpath" );
String path = systemId.substring( USER_NAMESPACE.length() );
InputStream stream = resolveInLocalNamespace( path );
if ( stream == null ) {
log.debug( "unable to locate [" + systemId + "] on classpath" );
}
else {
log.debug( "located [" + systemId + "] in classpath" );
InputSource source = new InputSource( stream );
source.setPublicId( publicId );
source.setSystemId( systemId );
return source;
}
}
}
// use default behavior
return null;
}
|
protected InputStream resolveInHibernateNamespace(String path) {
return this.getClass().getClassLoader().getResourceAsStream( path );
}
|
protected InputStream resolveInLocalNamespace(String path) {
try {
return ConfigHelper.getUserResourceAsStream( path );
}
catch( Throwable t ) {
return null;
}
}
|