From: <hib...@li...> - 2006-05-31 16:59:31
|
Author: ste...@jb... Date: 2006-05-31 12:59:05 -0400 (Wed, 31 May 2006) New Revision: 9972 Modified: trunk/Hibernate3/src/org/hibernate/util/ConfigHelper.java Log: recognition of classpath:// entity references Modified: trunk/Hibernate3/src/org/hibernate/util/ConfigHelper.java =================================================================== --- trunk/Hibernate3/src/org/hibernate/util/ConfigHelper.java 2006-05-31 16:58:26 UTC (rev 9971) +++ trunk/Hibernate3/src/org/hibernate/util/ConfigHelper.java 2006-05-31 16:59:05 UTC (rev 9972) @@ -129,10 +129,10 @@ private ConfigHelper() {} public static InputStream getResourceAsStream(String resource) { - String stripped = resource.startsWith("/") ? + String stripped = resource.startsWith("/") ? resource.substring(1) : resource; - - InputStream stream = null; + + InputStream stream = null; ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader!=null) { stream = classLoader.getResourceAsStream( stripped ); @@ -148,4 +148,34 @@ } return stream; } + + + public static InputStream getUserResourceAsStream(String resource) { + boolean hasLeadingSlash = resource.startsWith( "/" ); + String stripped = hasLeadingSlash ? resource.substring(1) : resource; + + InputStream stream = null; + + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + if ( classLoader != null ) { + stream = classLoader.getResourceAsStream( resource ); + if ( stream == null && hasLeadingSlash ) { + stream = classLoader.getResourceAsStream( stripped ); + } + } + + if ( stream == null ) { + stream = Environment.class.getClassLoader().getResourceAsStream( resource ); + } + if ( stream == null && hasLeadingSlash ) { + stream = Environment.class.getClassLoader().getResourceAsStream( stripped ); + } + + if ( stream == null ) { + throw new HibernateException( resource + " not found" ); + } + + return stream; + } + } |