Class WOResourceManager

CLASS DESCRIPTION

Inherits From:
NSObject

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

An application contains standard directories that store application resources. A deployed WebObjects application typically has the following directories:

NeXT_ROOT/NextLibrary/WOApps/MyApp/
	MyApp[.exe]
	Resources/
	WebServerResources/

DocRoot/WebObjects/MyApp/
	WebServerResources/

The Resources directory contains the component directories, the application and session script files (if any), and any other resource files that an application might need access to (for example, plists or EOModel files). The WebServerResources directory contains resources that both the application and the HTTP server might need access to, such as image files that should be displayed in the browser. Because the HTTP server needs access to these files, the WebServerResources directory is mirrored under the document root.

Alternatively, you can place the entire application directory under the document root, but doing so represents a security risk because you allow outside access to all internal files through the document root.

Project Builder helps you make the distinction between application resources and HTTP server resources. You place components under Web Components, application resources under Resources, and HTTP server resources under WebServerResources. When you build the project, Project Builder copies the resources into the appropriate subdirectories of the .woa.

Shared Resource Directories

You can access shared resource files by specifying a framework name when retrieving the resource. WOResourceManager can locate all frameworks that have been linked to the application. (In Project Builder, you should add the framework to the project under Frameworks.)

A WebObjects framework typically has the following directories:

NeXTROOT/NextLibrary/Frameworks/MyFramework/
	Resources/
	WebServerResources/

DocRoot/WebObjects/Frameworks/MyFramework/
	WebServerResources/
The resource directories of the framework contain the same types of resources as an application: components, plists, EOModels, and any other type of resource.

Development Shortcut

When you're in development mode, you typically do not have an application installed in NeXT_ROOT/NextLibrary/WOApps. Instead you have a project directory under the document root, and the built .woa directory is inside that project directory. As a convenience for debugging, WOResourceManager looks one level up from the .woa directory to see if the directory is inside of a project directory. If it is, WOResourceManager uses the components and resources from the project directory instead of the resources inside the Resources and WebServerResources directories of the .woa directory. This way, you can edit scripts or replace images and other resource files in the project and not have to rebuild the application.

Localized Resources

Localization in WebObjects depends on an array of languages stored in the WOSession object using WOSession's setLanguages:. The order of languages indicates the preferred order. Localized resources are located in Language.lproj subdirectories under the Resources or WebServerResources directories. The .lproj directories are always searched before the top-level resource directory is searched to ensure that if a localized resource is available, it will be used.

WOResourceManager does not have API for reading the localization .strings file. To access the .strings file use the method stringForKey:inTableNamed:withDefaultValue: in either WOApplication or WOComponent.

Search Path for Resources

When WOResourceManager searches for a resource, it searches either in the framework you specify or in the application (if you use nil for the framework argument). The following directories are searched in this order:


INSTANCE METHODS

pathForResourceNamed:inFramework:

- (NSString *)pathForResourceNamed:(NSString *)aResourceFile inFramework:(NSString *)aFrameworkName

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

This method always returns a path like NeXT_ROOT/NextLibrary/WOApps/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.


urlForResourceNamed:inFramework:

- (NSString *)urlForResourceNamed:(NSString *)aResourceFile inFramework:(NSString *)aFrameworkName

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 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 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 NeXT_ROOT/NextLibrary/WOApps, 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.