net.sf.jasperreports.engine.util

## Class JRResourcesUtil

- java.lang.Object
- - net.sf.jasperreports.engine.util.JRResourcesUtil

-     public final class JRResourcesUtil
      extends java.lang.Object

  Provides methods for resource resolution via class loaders or URL stream handlers.
  Version:
    $Id: JRResourcesUtil.java 7071 2014-04-30 15:30:01Z teodord $
  Author:
    Lucian Chirita (lucianc@users.sourceforge.net)

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `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 clsLoader)` Attempts to find a resource using a class loader.
    `static java.net.URL` | `findClassLoaderResource(java.lang.String location, java.lang.ClassLoader clsLoader, java.lang.Class<?> clazz)` Deprecated. Replaced by `findClassLoaderResource(String, ClassLoader)`.
    `static java.lang.ClassLoader` | `getClassLoader(java.lang.ClassLoader clsLoader)` Returns a class loader.
    `static FileResolver` | `getFileResolver(FileResolver fileRes)` Deprecated. To be removed.
    `static java.lang.ClassLoader` | `getGlobalClassLoader()` Returns the global class loader.
    `static FileResolver` | `getGlobalFileResolver()` Deprecated. To be removed.
    `static java.net.URLStreamHandlerFactory` | `getGlobalURLStreamHandlerFactory()` Deprecated. To be removed.
    `static java.lang.ClassLoader` | `getThreadClassLoader()` Returns the thread local class loader.
    `static FileResolver` | `getThreadFileResolver()` Deprecated. To be removed.
    `static java.net.URLStreamHandlerFactory` | `getThreadURLStreamHandlerFactory()` Deprecated. To be removed.
    `static java.net.URLStreamHandler` | `getURLHandler(java.lang.String spec, java.net.URLStreamHandlerFactory urlHandlerFact)` Returns an URL stream handler for an URL specified as a `String`.
    `static java.net.URLStreamHandlerFactory` | `getURLHandlerFactory(java.net.URLStreamHandlerFactory urlHandlerFact)` Deprecated. To be removed.
    `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.
    `static java.util.ResourceBundle` | `loadResourceBundle(java.lang.String baseName, java.util.Locale locale)` Loads a resource bundle for a given base name and locale.
    `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.
    `static void` | `resetClassLoader()` Resets the the thread local class loader to its previous value.
    `static void` | `resetThreadFileResolver()` Deprecated. To be removed.
    `static void` | `resetThreadURLHandlerFactory()` Deprecated. To be removed.
    `static java.io.File` | `resolveFile(java.lang.String location, FileResolver fileRes)` Attempts to find a file using a file resolver.
    `static void` | `setGlobalClassLoader(java.lang.ClassLoader classLoader)` Sets a global class loader to be used for resource resolution.
    `static void` | `setGlobalFileResolver(FileResolver fileResolver)` Deprecated. To be removed.
    `static void` | `setGlobalURLHandlerFactory(java.net.URLStreamHandlerFactory urlHandlerFactory)` Deprecated. To be removed.
    `static void` | `setThreadClassLoader(java.lang.ClassLoader classLoader)` Sets the thread local class loader.
    `static void` | `setThreadFileResolver(FileResolver fileResolver)` Deprecated. To be removed.
    `static void` | `setThreadURLHandlerFactory(java.net.URLStreamHandlerFactory urlHandlerFactory)` Deprecated. To be removed.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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 urlHandlerFact)

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

    - #### getFileResolver

          public static FileResolver getFileResolver(FileResolver fileRes)

      Deprecated. To be removed.
      Returns a file resolver.

      The first not null value from the following is returned:
      - the value of the parameter
      - the thread local file resolver
      - the global file resolver
      Parameters:
        `fileRes` - a file resolver that will be returned if not null
      Returns:
        a file resolver
      See Also:
        `setGlobalFileResolver(FileResolver)`, `setThreadFileResolver(FileResolver)`

    - #### getGlobalFileResolver

          public static FileResolver getGlobalFileResolver()

      Deprecated. To be removed.
      Returns the global file resolver.
      Returns:
        the global file resolver
      See Also:
        `setGlobalFileResolver(FileResolver)`

    - #### getThreadFileResolver

          public static FileResolver getThreadFileResolver()

      Deprecated. To be removed.
      Returns the thread local file resolver.
      Returns:
        the thread local file resolver.
      See Also:
        `setThreadFileResolver(FileResolver)`

    - #### setThreadFileResolver

          public static void setThreadFileResolver(FileResolver fileResolver)

      Deprecated. To be removed.
      Sets the thread local file resolver.
      Parameters:
        `fileResolver` - a file resolver.
      See Also:
        `getFileResolver(FileResolver)`, `resetThreadFileResolver()`

    - #### resetThreadFileResolver

          public static void resetThreadFileResolver()

      Deprecated. To be removed.
      Resets the the thread local file resolver to its previous value.

    - #### setGlobalFileResolver

          public static void setGlobalFileResolver(FileResolver fileResolver)

      Deprecated. To be removed.
      Sets a global file resolver to be used for file resolution.
      Parameters:
        `fileResolver` - the file resolver
      See Also:
        `getFileResolver(FileResolver)`

    - #### resolveFile

          public static java.io.File resolveFile(java.lang.String location,
                                 FileResolver fileRes)

      Attempts to find a file using a file resolver.
      Parameters:
        `location` - file name
        `fileRes` - a file resolver
      Returns:
        the file, if found

    - #### getURLHandlerFactory

          public static java.net.URLStreamHandlerFactory getURLHandlerFactory(java.net.URLStreamHandlerFactory urlHandlerFact)

      Deprecated. To be removed.
      Returns an URL steam handler factory.

      The first not null value from the following is returned:
      - the value of the parameter
      - the thread local URL stream handler factory
      - the global URL stream handler factory
      Parameters:
        `urlHandlerFact` - 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()

      Deprecated. To be removed.
      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()

      Deprecated. To be removed.
      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)

      Deprecated. To be removed.
      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()

      Deprecated. To be removed.
      Resets the the thread local URL stream handler factory to its previous value.

    - #### setGlobalURLHandlerFactory

          public static void setGlobalURLHandlerFactory(java.net.URLStreamHandlerFactory urlHandlerFactory)

      Deprecated. To be removed.
      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 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)`, `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 clsLoader,
                                             java.lang.Class<?> clazz)

      Deprecated. Replaced by `findClassLoaderResource(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 name
        `clsLoader` - a class loader
        `clazz` - a class
      Returns:
        the resource URL if found

    - #### 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 name
        `clsLoader` - a class loader
      Returns:
        the resource URL if found

    - #### 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 name
        `locale` - 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)

      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 name
        `locale` - 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 name
        `locale` - the locale
        `clsLoader` -
      Returns:
        the resource bundle for the given base name and locale
      See Also:
        `ResourceBundle.getBundle(String, Locale, ClassLoader)`

© 2001-2010 Jaspersoft Corporation www.jaspersoft.com