FileDocCategorySizeDatePackage
DTDEntityResolver.javaAPI DocHibernate 3.2.53430Wed Jun 21 01:23:30 BST 2006org.hibernate.util

DTDEntityResolver

public class DTDEntityResolver extends Object implements Serializable, EntityResolver
An {@link EntityResolver} implementation which attempts to resolve various systemId URLs to local classpath lookups
  1. Any systemId URL beginning with http://hibernate.sourceforge.net/ is searched for as a classpath resource in the classloader which loaded the Hibernate classes.
  2. 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.

Fields Summary
private static final Log
log
private static final String
HIBERNATE_NAMESPACE
private static final String
USER_NAMESPACE
Constructors Summary
Methods Summary
public org.xml.sax.InputSourceresolveEntity(java.lang.String publicId, java.lang.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 java.io.InputStreamresolveInHibernateNamespace(java.lang.String path)

		return this.getClass().getClassLoader().getResourceAsStream( path );
	
protected java.io.InputStreamresolveInLocalNamespace(java.lang.String path)

		try {
			return ConfigHelper.getUserResourceAsStream( path );
		}
		catch( Throwable t ) {
			return null;
		}