Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.jasig.portal.utils
Class ResourceLoader

    java.lang.Object
      org.jasig.portal.utils.ResourceLoader

    public class ResourceLoader

extends java.lang.Object

This utility provides methods for accessing resources. The methods generally use the classpath to find the resource if the requested URL isn't already specified as a fully-qualified URL string.

The methods of this class sort of replace the old UtiltiesBean.fixURI() method.

Since:
  uPortal 2.0
Version:
  $Revision: 1.20 $
Author:
  Ken Weiner, kweiner@unicon.net

Field Summary
`private static javax.xml.parsers.DocumentBuilderFactory` | `f`
`private static org.apache.commons.logging.Log` | `log`

Constructor Summary
`ResourceLoader()`

Method Summary
`static org.w3c.dom.Document` | `getResourceAsDocument(java.lang.Class requestingClass, java.lang.String resource)` Get the contents of a URL as an XML Document
`static java.io.File` | `getResourceAsFile(java.lang.Class requestingClass, java.lang.String resource)` Returns the requested resource as a File.
`static java.lang.String` | `getResourceAsFileString(java.lang.Class requestingClass, java.lang.String resource)` Returns the requested resource as a File string.
`static java.util.Properties` | `getResourceAsProperties(java.lang.Class requestingClass, java.lang.String resource)` Get the contents of a URL as a java.util.Properties object
`static org.xml.sax.InputSource` | `getResourceAsSAXInputSource(java.lang.Class requestingClass, java.lang.String resource)` Returns the requested resource as a SAX input source.
`static java.io.InputStream` | `getResourceAsStream(java.lang.Class requestingClass, java.lang.String resource)` Returns the requested resource as a stream.
`static java.lang.String` | `getResourceAsString(java.lang.Class requestingClass, java.lang.String resource)` Get the contents of a URL as a String
`static java.net.URL` | `getResourceAsURL(java.lang.Class requestingClass, java.lang.String resource)` Finds a resource with a given name.
`static java.lang.String` | `getResourceAsURLString(java.lang.Class requestingClass, java.lang.String resource)` Returns the requested resource as a URL string.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### log

    private static final org.apache.commons.logging.Log log

### f

    private static javax.xml.parsers.DocumentBuilderFactory f

Constructor Detail

### ResourceLoader

    public ResourceLoader()

Method Detail

### getResourceAsURL

    public static java.net.URL getResourceAsURL(java.lang.Class requestingClass,
                                                java.lang.String resource)
                                         throws ResourceMissingException

  Finds a resource with a given name. This is a convenience method for accessing a resource from a channel or from the uPortal framework. If a well-formed URL is passed in, this method will use that URL unchanged to find the resource. If the URL is not well-formed, this method will look for the desired resource relative to the classpath. If the resource name starts with "/", it is unchanged. Otherwise, the package name of the requesting class is prepended to the resource name.

  Parameters:
    `requestingClass` - the java.lang.Class object of the class that is attempting to load the resource
    `resource` - a String describing the full or partial URL of the resource to load
  Returns:
    a URL identifying the requested resource
  Throws:
    `ResourceMissingException`

### getResourceAsURLString

    public static java.lang.String getResourceAsURLString(java.lang.Class requestingClass,
                                                          java.lang.String resource)
                                                   throws ResourceMissingException

  Returns the requested resource as a URL string.

  Parameters:
    `requestingClass` - the java.lang.Class object of the class that is attempting to load the resource
    `resource` - a String describing the full or partial URL of the resource to load
  Returns:
    the requested resource as a URL string
  Throws:
    `ResourceMissingException`

### getResourceAsFile

    public static java.io.File getResourceAsFile(java.lang.Class requestingClass,
                                                 java.lang.String resource)
                                          throws ResourceMissingException

  Returns the requested resource as a File.

  Parameters:
    `requestingClass` - the java.lang.Class object of the class that is attempting to load the resource
    `resource` - a String describing the full or partial URL of the resource to load
  Returns:
    the requested resource as a File
  Throws:
    `ResourceMissingException`

### getResourceAsFileString

    public static java.lang.String getResourceAsFileString(java.lang.Class requestingClass,
                                                           java.lang.String resource)
                                                    throws ResourceMissingException

  Returns the requested resource as a File string.

  Parameters:
    `requestingClass` - the java.lang.Class object of the class that is attempting to load the resource
    `resource` - a String describing the full or partial URL of the resource to load
  Returns:
    the requested resource as a File string
  Throws:
    `ResourceMissingException`

### getResourceAsStream

    public static java.io.InputStream getResourceAsStream(java.lang.Class requestingClass,
                                                          java.lang.String resource)
                                                   throws ResourceMissingException,
                                                          java.io.IOException

  Returns the requested resource as a stream.

  Parameters:
    `requestingClass` - the java.lang.Class object of the class that is attempting to load the resource
    `resource` - a String describing the full or partial URL of the resource to load
  Returns:
    the requested resource as a stream
  Throws:
    `ResourceMissingException`
    `java.io.IOException`

### getResourceAsSAXInputSource

    public static org.xml.sax.InputSource getResourceAsSAXInputSource(java.lang.Class requestingClass,
                                                                      java.lang.String resource)
                                                               throws ResourceMissingException,
                                                                      java.io.IOException

  Returns the requested resource as a SAX input source.

  Parameters:
    `requestingClass` - the java.lang.Class object of the class that is attempting to load the resource
    `resource` - a String describing the full or partial URL of the resource to load
  Returns:
    the requested resource as a SAX input source
  Throws:
    `ResourceMissingException`
    `java.io.IOException`

### getResourceAsDocument

    public static org.w3c.dom.Document getResourceAsDocument(java.lang.Class requestingClass,
                                                             java.lang.String resource)
                                                      throws ResourceMissingException,
                                                             java.io.IOException,
                                                             javax.xml.parsers.ParserConfigurationException,
                                                             org.xml.sax.SAXException

  Get the contents of a URL as an XML Document

  Parameters:
    `requestingClass` - the java.lang.Class object of the class that is attempting to load the resource
    `resource` - a String describing the full or partial URL of the resource whose contents to load
  Returns:
    the actual contents of the resource as an XML Document
  Throws:
    `ResourceMissingException`
    `java.io.IOException`
    `javax.xml.parsers.ParserConfigurationException`
    `org.xml.sax.SAXException`

### getResourceAsProperties

    public static java.util.Properties getResourceAsProperties(java.lang.Class requestingClass,
                                                               java.lang.String resource)
                                                        throws ResourceMissingException,
                                                               java.io.IOException

  Get the contents of a URL as a java.util.Properties object

  Parameters:
    `requestingClass` - the java.lang.Class object of the class that is attempting to load the resource
    `resource` - a String describing the full or partial URL of the resource whose contents to load
  Returns:
    the actual contents of the resource as a Properties object
  Throws:
    `ResourceMissingException`
    `java.io.IOException`

### getResourceAsString

    public static java.lang.String getResourceAsString(java.lang.Class requestingClass,
                                                       java.lang.String resource)
                                                throws ResourceMissingException,
                                                       java.io.IOException

  Get the contents of a URL as a String

  Parameters:
    `requestingClass` - the java.lang.Class object of the class that is attempting to load the resource
    `resource` - a String describing the full or partial URL of the resource whose contents to load
  Returns:
    the actual contents of the resource as a String
  Throws:
    `ResourceMissingException`
    `java.io.IOException`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD