net.sf.jasperreports.engine.util
Class JRResourcesUtil

java.lang.Object
  extended by net.sf.jasperreports.engine.util.JRResourcesUtil

public class JRResourcesUtil
extends java.lang.Object

Provides methods for resource resolution via class loaders or URL stream handlers.

Version:
$Id: JRResourcesUtil.java 1229 2006-04-19 10:27:35Z teodord $
Author:
Lucian Chirita (lucianc@users.sourceforge.net)

Constructor Summary
JRResourcesUtil()
           
 
Method Summary
static java.net.URL createURL(java.lang.String spec, java.net.URLStreamHandlerFactory urlHandlerFactory)
          Tries to parse a String as an URL.
static java.net.URL findClassLoaderResource(java.lang.String location, java.lang.ClassLoader classLoader, java.lang.Class clazz)
          Attempts to find a resource using a class loader.
static java.lang.ClassLoader getClassLoader(java.lang.ClassLoader classLoader)
          Returns a class loader.
static java.lang.ClassLoader getGlobalClassLoader()
          Returns the global class loader.
static java.net.URLStreamHandlerFactory getGlobalURLStreamHandlerFactory()
          Returns the global URL stream handler factory.
static java.lang.ClassLoader getThreadClassLoader()
          Returns the thread local class loader.
static java.net.URLStreamHandlerFactory getThreadURLStreamHandlerFactory()
          Returns the thread local URL stream handler factory.
static java.net.URLStreamHandler getURLHandler(java.lang.String spec, java.net.URLStreamHandlerFactory urlHandlerFactory)
          Returns an URL stream handler for an URL specified as a String.
static java.net.URLStreamHandlerFactory getURLHandlerFactory(java.net.URLStreamHandlerFactory urlHandlerFactory)
          Returns an URL steam handler factory.
static void resetClassLoader()
          Resets the the thread local class loader to its previous value.
static void resetThreadURLHandlerFactory()
          Resets the the thread local URL stream handler factory to its previous value.
static void setGlobalClassLoader(java.lang.ClassLoader classLoader)
          Sets a global class loader to be used for resource resolution.
static void setGlobalURLHandlerFactory(java.net.URLStreamHandlerFactory urlHandlerFactory)
          Sets a global URL stream handler facotry to be used for resource resolution.
static void setThreadClassLoader(java.lang.ClassLoader classLoader)
          Sets the thread local class loader.
static void setThreadURLHandlerFactory(java.net.URLStreamHandlerFactory urlHandlerFactory)
          Sets the thread local URL stream handler factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JRResourcesUtil

public JRResourcesUtil()
Method Detail

createURL

public static java.net.URL createURL(java.lang.String spec,
                                     java.net.URLStreamHandlerFactory urlHandlerFactory)
Tries to parse a String as an URL.

Parameters:
spec - the String to parse
urlHandlerFactory - an URL stream handler factory to use
Returns:
an URL if the parsing is successful
See Also:
getURLHandler(String, URLStreamHandlerFactory), getURLHandlerFactory(URLStreamHandlerFactory)

getURLHandler

public static java.net.URLStreamHandler getURLHandler(java.lang.String spec,
                                                      java.net.URLStreamHandlerFactory urlHandlerFactory)
Returns an URL stream handler for an URL specified as a String.

Parameters:
spec - the String to parse as an URL
urlHandlerFactory - an URL stream handler factory
Returns:
an URL stream handler if one was found for the protocol of the URL
See Also:
getURLHandlerFactory(URLStreamHandlerFactory)

getURLHandlerFactory

public static java.net.URLStreamHandlerFactory getURLHandlerFactory(java.net.URLStreamHandlerFactory urlHandlerFactory)
Returns an URL steam handler factory.

The first not null value from the following is returned:

Parameters:
urlHandlerFactory - an URL steam handler factory that will be returned if not null
Returns:
an URL steam handler factory
See Also:
setGlobalURLHandlerFactory(URLStreamHandlerFactory), setThreadURLHandlerFactory(URLStreamHandlerFactory)

getGlobalURLStreamHandlerFactory

public static java.net.URLStreamHandlerFactory getGlobalURLStreamHandlerFactory()
Returns the global URL stream handler factory.

Returns:
the global URL stream handler factory
See Also:
setGlobalURLHandlerFactory(URLStreamHandlerFactory)

getThreadURLStreamHandlerFactory

public static java.net.URLStreamHandlerFactory getThreadURLStreamHandlerFactory()
Returns the thread local URL stream handler factory.

Returns:
the thread local URL stream handler factory.
See Also:
setThreadURLHandlerFactory(URLStreamHandlerFactory)

setThreadURLHandlerFactory

public static void setThreadURLHandlerFactory(java.net.URLStreamHandlerFactory urlHandlerFactory)
Sets the thread local URL stream handler factory.

Parameters:
urlHandlerFactory - an URL stream handler factory.
See Also:
getURLHandlerFactory(URLStreamHandlerFactory), resetThreadURLHandlerFactory()

resetThreadURLHandlerFactory

public static void resetThreadURLHandlerFactory()
Resets the the thread local URL stream handler factory to its previous value.


setGlobalURLHandlerFactory

public static void setGlobalURLHandlerFactory(java.net.URLStreamHandlerFactory urlHandlerFactory)
Sets a global URL stream handler facotry to be used for resource resolution.

Parameters:
urlHandlerFactory - the URL stream handler factory
See Also:
getURLHandlerFactory(URLStreamHandlerFactory)

getClassLoader

public static java.lang.ClassLoader getClassLoader(java.lang.ClassLoader classLoader)
Returns a class loader.

The first not null value from the following is returned:

Parameters:
classLoader - a class loader that will be returned if not null
Returns:
a class loader.
See Also:
setGlobalClassLoader(ClassLoader), setThreadClassLoader(ClassLoader)

getGlobalClassLoader

public static java.lang.ClassLoader getGlobalClassLoader()
Returns the global class loader.

Returns:
the global class loader.
See Also:
setGlobalClassLoader(ClassLoader)

getThreadClassLoader

public static java.lang.ClassLoader getThreadClassLoader()
Returns the thread local class loader.

Returns:
the thread local class loader.
See Also:
setThreadClassLoader(ClassLoader)

setThreadClassLoader

public static void setThreadClassLoader(java.lang.ClassLoader classLoader)
Sets the thread local class loader.

Parameters:
classLoader - a class loader
See Also:
getClassLoader(ClassLoader), resetThreadURLHandlerFactory()

resetClassLoader

public static void resetClassLoader()
Resets the the thread local class loader to its previous value.


setGlobalClassLoader

public static void setGlobalClassLoader(java.lang.ClassLoader classLoader)
Sets a global class loader to be used for resource resolution.

Parameters:
classLoader - the class loader
See Also:
getClassLoader(ClassLoader)

findClassLoaderResource

public static java.net.URL findClassLoaderResource(java.lang.String location,
                                                   java.lang.ClassLoader classLoader,
                                                   java.lang.Class clazz)
Attempts to find a resource using a class loader.

The following sources are tried:

Parameters:
location - the resource name
classLoader - a class loader
clazz - a class
Returns:
the resource URL if found


© 2001-2006 JasperSoft Corporation www.jaspersoft.com