PATH Documentation > WebObjects

Table of Contents

WOResourceManager


Inherits from:
Object
Package:
com.webobjects.appserver


Class Description


WOResourceManager manages an application's resources. It defines methods that retrieve resources from standard directories. Each WebObjects application contains a resource manager object, which you can access by sending resourceManager to the WOApplication class




Method Types


Retrieving resources
bytesForResourceNamed
contentTypeForResourceNamed
errorMessageUrlForResourceNamed
inputStreamForResourceNamed
pathForResourceNamed
urlForResourceNamed
Retrieving localized strings
stringForKey
Managing the application-wide data cache
flushDataCache
removeDataForKey
setData
Other
toString


Constructors



WOResourceManager

protected WOResourceManager()

Description forthcoming.


Instance Methods



bytesForResourceNamed

public byte[] bytesForResourceNamed( String aResourceName, String aFrameworkName, NSArray aLanguagesList)

Returns, as a Java byte array, the contents of the specified resource. When calling this method you must provide the name of the resource (including the filename extension) specified byaResourceName, the name of the framework in which the resource resides (or null if the resource resides within the application) specified by aFrameworkName, and an NSArray of String objects identifying the order in which the language-specific resources should be searched (supply null for this third argument specified by aLanguageList if the default order is sufficient).

contentTypeForResourceNamed

public String contentTypeForResourceNamed(String aResourcePath)

Returns a String containing the HTTP content type for the named resource specified by aResourcePath. The content type is determined based upon the filename extension; if the resource's filename supplied to this method has no extension or the extension isn't one of those listed in System/Library/Frameworks/JavaWebObjects/Resources/MIME.plist, this method returns "text/plain".

errorMessageUrlForResourceNamed

public String errorMessageUrlForResourceNamed( String aResourceName, String aFrameworkName)

Returns a String containing an error URL for the resource name specified by aResourceName and framework name specified by aFrameworkName. If a resource name is not supplied (that is, if null is passed as the first parameter), the error message will contain "null" in place of the resource name. If a framework name is passed as the second parameter, the error message will have the following form: /ERROR/NOT_FOUND/framework=frameworkName/filename=resourceName. If null is passed as the second parameter, the error message will include the application name instead of a framework name and will have the following form: /ERROR/NOT_FOUND/app=applicationName/filename=resourceName.

flushDataCache

public void flushDataCache()

Removes all data from the image data cache. Use this method if you are storing data in the application-wide cache that you no longer need.

Access to the WOResourceManager object is locked at the beginning of this method and unlocked at the end.

See Also: removeDataForKey, setData



inputStreamForResourceNamed

public java.io.InputStream inputStreamForResourceNamed( String aResourceName, String aFrameworkName, NSArray aLanguagesList)

Returns a java.io.InputStream which you can use to read the contents of the specified resource. When calling this method you must provide the name of the resource (including the filename extension) specified by aResourceName, the name of the framework in which the resource resides (or null if the resource resides within the application) specified by aFrameworkName, and an NSArray of String objects identifying the order in which the language-specific resources should be searched (supply null for this third argument if the default order is sufficient) specified by aLanguageList.

pathForResourceNamed

public String pathForResourceNamed( String aResourceFile, String aFrameworkName, NSArray languagesList)

Returns the absolute path for the resource aResourceFile. Include the file's extension when specifying aResourceFile. If the file is in the application, specify null for the framework argument.

This method always returns a path like /Local/Library/WebObjects/Applications/MyApp.woa/WebServerResources/MyResource. It does not return the path relative to the HTTP server's document root unless the entire application is located in the document root.

Access to the WOResourceManager object is locked at the beginning of this method and unlocked at the end.

See Also: urlForResourceNamed



removeDataForKey

public void removeDataForKey( String key, WOSession aSession)

Removes the data stored in the data cache under the key key. The session argument is currently ignored; specify null to have WOResourceManager use the application-wide cache.

This method is used by default when a dynamic element requests an image or embedded object from a database and the key attribute is not set for that dynamic element. If the key attribute isn't set, the data retrieved from the database is stored in the cache using setData, sent to the dynamic element, and then removed from the cache using removeDataForKey. If the key attribute is set, removeDataForKey is not invoked.

You rarely need to invoke this method yourself. Use it only if you need to limit the amount of memory your application uses, if your application has data stored in the cache, and you know that the data is no longer needed.

Access to the WOResourceManager object is locked at the beginning of this method and unlocked at the end.

See Also: flushDataCache



setData

public void setData( NSData someData, String key, String mimeType, WOSession aSession)

Adds the image or embbedded object someData of MIME type type to the data cache for the session specify by aSession. The data is stored under the key key. The session argument is currently ignored; specify null to have WOResourceManager use the application-wide cache.

This method is invoked any time a dynamic element requests an image or embedded object from a database. You rarely need to invoke it yourself.

By default when a dynamic element requests an image from the database, WOResourceManager fetches the image, stores it in the cache using setData, sends it to the dynamic element, and then removes it from the cache using removeDataForKey. However, if the dynamic element has a key attribute defined, then the image is stored in the database under that key, and it is not removed from the database.

Access to the WOResourceManager object is locked at the beginning of this method and unlocked at the end.

See Also: flushDataCache



stringForKey

public String stringForKey( String aKey, String aTableName, String aDefaultValue, String aFrameworkName, NSArray languagesList)

Returns a localized string from string table aTable.strings using aKey to look it up. If no string value for the key is found in the table, aDefaultValue (optional) is returned. The method first searches the aTable.strings file, if it exists, in each of the localized (.lproj) subdirectories of the application wrapper; searching proceeds in the order specified by the array languagesList. If no string value matching the key is found, the search then continues to the aTable.strings file (if it exists) directly under the Resources directory (inside the directory with the .woa extension).

toString

public String toString()

Returns a String representation of the receiver suitable for debugging purposes.

urlForResourceNamed

public String urlForResourceNamed( String aResourceFile, String aFrameworkName, NSArray languagesList, WORequest aRequest)

Returns the URL associated with a resource named aResourceFile. The URL returned is of the following form:

WebObjects/MyApp.woa/WebServerResources/English.lproj/aResourceFile

Include the file's extension when specifying aResourceFile. If the file is in the application, specify null for the framework argument.

This method locates resources under the application or framework. The URL returned is computed by concatenating the application's base URL (returned by WOApplication's baseURL method and settable using the WOApplicationBaseURL user default) and the relative path of the resource. This method does not check to see if the file is actually under the document root. For example, if your application is installed in /Local/Library/WebObjects/Applications, and the method finds aResourceFile in the Resources directory, it returns:

/WebObjects/MyApp.woa/Resources/aResourceFile

even though the Resources directory is not under the document root.

Access to the WOResourceManager object is locked at the beginning of this method and unlocked at the end.

See Also: pathForResourceNamed



© 2001 Apple Computer, Inc. (Last Published April 15, 2001)


Table of Contents