|
From: <hib...@li...> - 2006-05-31 16:58:52
|
Author: ste...@jb...
Date: 2006-05-31 12:58:26 -0400 (Wed, 31 May 2006)
New Revision: 9971
Modified:
trunk/Hibernate3/src/org/hibernate/util/DTDEntityResolver.java
Log:
recognition of classpath:// entity references
Modified: trunk/Hibernate3/src/org/hibernate/util/DTDEntityResolver.java
===================================================================
--- trunk/Hibernate3/src/org/hibernate/util/DTDEntityResolver.java 2006-05-31 16:37:03 UTC (rev 9970)
+++ trunk/Hibernate3/src/org/hibernate/util/DTDEntityResolver.java 2006-05-31 16:58:26 UTC (rev 9971)
@@ -10,12 +10,28 @@
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
+/**
+ * An {@link EntityResolver} implementation which attempts to resolve
+ * various systemId URLs to local classpath lookups<ol>
+ * <li>Any systemId URL beginning with <tt>http://hibernate.sourceforge.net/</tt> is
+ * searched for as a classpath resource in the classloader which loaded the
+ * Hibernate classes.</li>
+ * <li>Any systemId URL using <tt>classpath</tt> as the scheme (i.e. starting
+ * with <tt>classpath://</tt> is searched for as a classpath resource using first
+ * the current thread context classloader and then the classloader which loaded
+ * the Hibernate classes.
+ * </ol>
+ * <p/>
+ * 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.
+ */
public class DTDEntityResolver implements EntityResolver, Serializable {
private static final Log log = LogFactory.getLog( DTDEntityResolver.class );
private static final String HIBERNATE_NAMESPACE = "http://hibernate.sourceforge.net/";
- private static final String LOCAL_NAMESPACE = "file://";
+ private static final String USER_NAMESPACE = "classpath://";
public InputSource resolveEntity(String publicId, String systemId) {
if ( systemId != null ) {
@@ -38,9 +54,9 @@
return source;
}
}
- else if ( systemId.startsWith( LOCAL_NAMESPACE ) ) {
+ else if ( systemId.startsWith( USER_NAMESPACE ) ) {
log.debug( "recognized local namespace; attempting to resolve on classpath" );
- String path = systemId.substring( LOCAL_NAMESPACE.length() );
+ String path = systemId.substring( USER_NAMESPACE.length() );
InputStream stream = resolveInLocalNamespace( path );
if ( stream == null ) {
log.debug( "unable to locate [" + systemId + "] on classpath" );
@@ -63,12 +79,11 @@
}
protected InputStream resolveInLocalNamespace(String path) {
- // attempt to find local stuff on the context classloader first...
- InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream( path );
- if ( stream == null ) {
- // next try our classloader
- stream = getClass().getClassLoader().getResourceAsStream( path );
+ try {
+ return ConfigHelper.getUserResourceAsStream( path );
}
- return stream;
+ catch( Throwable t ) {
+ return null;
+ }
}
}
|