Package net.sf.jasperreports.engine.util
Class JRResourcesUtil
- java.lang.Object
-
- net.sf.jasperreports.engine.util.JRResourcesUtil
-
public final class JRResourcesUtil extends java.lang.ObjectProvides methods for resource resolution via class loaders or URL stream handlers.- Author:
- Lucian Chirita (lucianc@users.sourceforge.net)
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static java.net.URLcreateURL(java.lang.String spec, java.net.URLStreamHandlerFactory urlHandlerFactory)Tries to parse aStringas an URL.protected static java.io.FiledefaultLocateFile(java.lang.String location)static java.net.URLfindClassLoaderResource(java.lang.String location, java.lang.ClassLoader clsLoader)Attempts to find a resource using a class loader.static java.net.URLfindClassLoaderResource(java.lang.String location, java.lang.ClassLoader clsLoader, java.lang.Class<?> clazz)Deprecated.Replaced byfindClassLoaderResource(String, ClassLoader).static java.lang.ClassLoadergetClassLoader(java.lang.ClassLoader clsLoader)Returns a class loader.static java.lang.ClassLoadergetGlobalClassLoader()Returns the global class loader.static java.lang.ClassLoadergetThreadClassLoader()Returns the thread local class loader.static java.net.URLStreamHandlergetURLHandler(java.lang.String spec, java.net.URLStreamHandlerFactory urlHandlerFact)Returns an URL stream handler for an URL specified as aString.static java.util.ResourceBundleloadResourceBundle(java.lang.String baseName, java.util.Locale locale)Loads a resource bundle for a given base name and locale.static java.util.ResourceBundleloadResourceBundle(java.lang.String baseName, java.util.Locale locale, java.lang.ClassLoader clsLoader)Loads a resource bundle for a given base name and locale.static java.util.ResourceBundleloadResourceBundle(JasperReportsContext jasperReportsContext, java.lang.String baseName, java.util.Locale locale)Loads a resource bundle for a given base name and locale.static java.util.ResourceBundleloadResourceBundle(RepositoryContext repositoryContext, java.lang.String baseName, java.util.Locale locale)protected static java.io.FilelocateContextDirectory(RepositoryResourceContext resourceContext, java.util.function.Function<java.lang.String,java.io.File> rootLocator)protected static java.io.FilelocateFile(RepositoryResourceContext resourceContext, java.lang.String location, java.util.function.Function<java.lang.String,java.io.File> rootLocator)static voidresetClassLoader()Resets the the thread local class loader to its previous value.static java.io.FileresolveFile(java.lang.String location, FileResolver fileRes)Deprecated.To be removed.static java.io.FileresolveFile(RepositoryContext context, java.lang.String location)static java.io.FileresolveFile(RepositoryContext context, java.lang.String location, java.util.function.Function<java.lang.String,java.io.File> rootLocator)static voidsetGlobalClassLoader(java.lang.ClassLoader classLoader)Sets a global class loader to be used for resource resolution.static voidsetThreadClassLoader(java.lang.ClassLoader classLoader)Sets the thread local class loader.
-
-
-
Method Detail
-
createURL
public static java.net.URL createURL(java.lang.String spec, java.net.URLStreamHandlerFactory urlHandlerFactory)Tries to parse aStringas an URL.- Parameters:
spec- theStringto parseurlHandlerFactory- an URL stream handler factory to use- Returns:
- an URL if the parsing is successful
- See Also:
getURLHandler(String, URLStreamHandlerFactory)
-
getURLHandler
public static java.net.URLStreamHandler getURLHandler(java.lang.String spec, java.net.URLStreamHandlerFactory urlHandlerFact)Returns an URL stream handler for an URL specified as aString.- Parameters:
spec- theStringto parse as an URLurlHandlerFact- an URL stream handler factory- Returns:
- an URL stream handler if one was found for the protocol of the URL
-
resolveFile
public static java.io.File resolveFile(java.lang.String location, FileResolver fileRes)Deprecated.To be removed.Attempts to find a file using a file resolver.- Parameters:
location- file namefileRes- a file resolver- Returns:
- the file, if found
-
resolveFile
public static java.io.File resolveFile(RepositoryContext context, java.lang.String location)
-
resolveFile
public static java.io.File resolveFile(RepositoryContext context, java.lang.String location, java.util.function.Function<java.lang.String,java.io.File> rootLocator)
-
defaultLocateFile
protected static java.io.File defaultLocateFile(java.lang.String location)
-
locateFile
protected static java.io.File locateFile(RepositoryResourceContext resourceContext, java.lang.String location, java.util.function.Function<java.lang.String,java.io.File> rootLocator)
-
locateContextDirectory
protected static java.io.File locateContextDirectory(RepositoryResourceContext resourceContext, java.util.function.Function<java.lang.String,java.io.File> rootLocator)
-
getClassLoader
public static java.lang.ClassLoader getClassLoader(java.lang.ClassLoader clsLoader)
Returns a class loader. The first not null value from the following is returned:- the value of the parameter
- the thread local class loader
- the global class loader
- Parameters:
clsLoader- 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)
-
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 clsLoader, java.lang.Class<?> clazz)Deprecated.Replaced byfindClassLoaderResource(String, ClassLoader).Attempts to find a resource using a class loader. The following sources are tried:- the class loader returned by
getClassLoader(ClassLoader) - the context class loader
clazz.getClassLoader()clazz.getResource()
- Parameters:
location- the resource nameclsLoader- a class loaderclazz- a class- Returns:
- the resource URL if found
- the class loader returned by
-
findClassLoaderResource
public static java.net.URL findClassLoaderResource(java.lang.String location, java.lang.ClassLoader clsLoader)Attempts to find a resource using a class loader. The following sources are tried:- the class loader returned by
getClassLoader(ClassLoader) - the context class loader
JRLoader.class.getClassLoader()JRLoader.class.getResource()
- Parameters:
location- the resource nameclsLoader- a class loader- Returns:
- the resource URL if found
- the class loader returned by
-
loadResourceBundle
public static java.util.ResourceBundle loadResourceBundle(JasperReportsContext jasperReportsContext, java.lang.String baseName, java.util.Locale locale)
Loads a resource bundle for a given base name and locale.This methods calls
loadResourceBundle(String, Locale, ClassLoader)with a null classloader.- Parameters:
baseName- the base namelocale- the locale- Returns:
- the resource bundle for the given base name and locale
-
loadResourceBundle
public static java.util.ResourceBundle loadResourceBundle(RepositoryContext repositoryContext, java.lang.String baseName, java.util.Locale locale)
-
loadResourceBundle
public static java.util.ResourceBundle loadResourceBundle(java.lang.String baseName, java.util.Locale locale)Loads a resource bundle for a given base name and locale.This methods calls
loadResourceBundle(String, Locale, ClassLoader)with a null classloader.- Parameters:
baseName- the base namelocale- the locale- Returns:
- the resource bundle for the given base name and locale
-
loadResourceBundle
public static java.util.ResourceBundle loadResourceBundle(java.lang.String baseName, java.util.Locale locale, java.lang.ClassLoader clsLoader)Loads a resource bundle for a given base name and locale.The method attempts to load the resource bundle using the following classloaders (and stops at the first successful attempt):
- the class loader returned by
getClassLoader(ClassLoader) - the context class loader
JRClassLoader.class.getClassLoader()
- Parameters:
baseName- the base namelocale- the localeclsLoader-- Returns:
- the resource bundle for the given base name and locale
- See Also:
ResourceBundle.getBundle(String, Locale, ClassLoader)
- the class loader returned by
-
-