PATH  WebObjects 4.0 Documentation > WebObjects Framework Reference



WOResourceManager

Inherits From:
NSObject

Conforms To: NSObject (NSObject)

Declared in: WebObjects/WOResourceManager.h


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


Adopted Protocols

NSLocking
- lock
- unlock

Method Types

Retrieving resources
- pathForResourceNamed:inFramework:languages:
- urlForResourceNamed:inFramework:languages:request:
Retrieving localized strings
- stringForKey:inTableNamed:withDefaultValue:inFramework: languages:
Managing the application-wide data cache
- flushDataCache
- removeDataForKey:session:
- setData:forKey:mimeType:session:

Instance Methods


flushDataCache

- (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:session: , - setData:forKey:mimeType:session:


lock

- (void)lock

Locks access to the WOResourceManager object. When the WOResourceManager is locked, no other threads may access it.

Usually, you don't need to invoke this method in your own code. All messages that you send to a WOResourceManager object lock access to the object at the beginning of the method and unlock access at the end. You only need to use this method if you're subclassing WOResourceManager. In that case, you should lock access to the WOResourceManager object in methods that load resources.

See also: - unlock


pathForResourceNamed:inFramework:languages:

- (NSString *)pathForResourceNamed: (NSString *)aResourceFile
inFramework: (NSString *)aFrameworkName
languages: (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 lnil 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:inFramework:languages:request:


removeDataForKey:session:

- (void)removeDataForKey: (NSString *)key session: (WOSession *)aSession

Removes the data stored in the data cache under the key key. The session argument is currently ignored; specify nil 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:forKey:mimeType:session: , sent to the dynamic element, and then removed from the cache using removeDataForKey:session: . If the key attribute is set, removeDataForKey:session: 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:forKey:mimeType:session:

- (void)setData: (NSData *)someData
forKey: (NSString *)key
mimeType: (NSString *)type
session: (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 nil 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:forKey:mimeType:session: , sends it to the dynamic element, and then removes it from the cache using removeDataForKey:session: . 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:inTableNamed:withDefaultValue:inFramework:languages:

- (NSString *)stringForKey: (NSString *)aKey
inTableNamed: (NSString *)aTableName
withDefaultValue: (NSString *)aDefaultValue
inFramework: (NSString *)aFrameworkName
languages: (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).


unlock

- (void)unlock

Removes the lock on the WOResourceManager object, allowing other threads to access it.

Usually, you don't need to invoke this method in your own code. All messages that you send to a WOResourceManager object lock access to the object at the beginning of the method and unlock access at the end. You only need to use this method if you're subclassing WOResourceManager. In that case, you should lock access to the WOResourceManager object in methods that load resources and unlock when the method is finished accessing the WOResourceManager object.

See also: - lock


urlForResourceNamed:inFramework:languages:request:

- (NSString *)urlForResourceNamed: (NSString *)aResourceFile
inFramework: (NSString *)aFrameworkName
languages: (NSArray *)languagesList
request: (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, specifyl nil 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:inFramework:languages:





Copyright © 1998, Apple Computer, Inc. All rights reserved.