This article will guide you through services provided in Aria Templates to handle URLs. The first part focuses on mapping files paths to URLs, the second part details how to create custom URLs to communicate with your server.
Aria Templates' default behavior is to load classes using the Download Manager (
aria.core.DownloadMgr) based on these steps:
The classpath is turned into a physical path by replacing (i.e. the template
The resulting path is appended to AT's root folder.
URL mapping provides a way to modify this behavior. It may be useful in two cases:
You need to specify that a class identified by a given classpath + extension is in a specific file.
You need to specify that a given package is located somewhere else.
Let's say you want to force the definition of the
foo/bar/AnotherBarClass.js instead of
foo/bar/BarClass.js; you would then write:
You could also specify that all classes of a package are available in one file like this:
In the example above, any class which classpath starts with
foo.bar is expected to be declared inside the bar.js file.
You can define what to use as a root path for a given package using the
In this example:
foo.bar.Mainwill be retrieved in
foo.specialclasses.Mainwill be retrieved in
You can use
updateUrlMap in conjunction with
updateRootMap to create custom URLs.
UrlMap and RootMap accept function references and instances of
aria.utils.Callback in their definition. Such a function must be defined as follows:
- An urlMap callback receives one argument: the logical path to a file (e.g.
foo/bar/MyClass.js) and it must return the new path (relative to rootUrl.)
- A rootMap callback also receives the logical path to a file (e.g.
bar/MyClass.js) and must return the new root path to be used.
The callbacks can be used this way:
or using anonymous functions:
In order to be as independent as possible from the server-side framework, Aria Templates provides a simple way to build the URLs used for server requests and retrieving resources: the URL Creation Service.
To define the way URLs are created, you need to create a class implementing the aria.modules.urlService.IUrlService interface and its two methods:
createActionUrl: used to create URLs used for actions. This method is passed the following parameters:
createI18nUrl: the same for resources for this module...
Here is a sample method from an urlService class to create the call URL: