namespace sap/base/util/LoaderExtensions

Visiblity: restricted
Available since: N/A
Module: sap/base/util/LoaderExtensions
Application Component:

Utilities extending the sap.ui.loader functionalities.


Nodes Overview

Node Description

Methods Overview

Method Description
module:sap/base/util/LoaderExtensions.getAllRequiredModules

Returns the names of all required modules in the legacy syntax for module names (dot-separated).

module:sap/base/util/LoaderExtensions.getKnownSubtypes

Returns all known subtypes.

module:sap/base/util/LoaderExtensions.loadResource

Retrieves the resource with the given name, either from the preload cache or from the server. The expected data type of the resource can either be specified in the options (dataType) or it will be derived from the suffix of the sResourceName. The only supported data types so far are 'xml', 'html', 'json' and 'text'. If the resource name extension doesn't match any of these extensions, the dataType property must be specified as option.

If the resource is found in the preload cache, it will be converted from text format to the requested dataType using conversions similar to:

  dataType | conversion
  ---------+-------------------------------------------------------------
    html   | text (no conversion)
    json   | JSON.parse(text)
    xml    | DOMParser.prototype.parseFromString(text, "application/xml")

If it is not found, the resource name will be converted to a resource URL (using #getResourcePath) and the resulting URL will be requested from the server with an XMLHttpRequest.

If the resource was found in the local preload cache and any necessary conversion succeeded or when the resource was retrieved from the backend successfully, the content of the resource will be returned. In any other case, an exception will be thrown, or if option failOnError is set, null will be returned.

For asynchronous calls, the return value of this method is a Promise which resolves with the content of the resource on success or rejects with an error in case of errors. If failOnError is false and an error occurs, the promise won't be rejected, but resolved with null.

Future implementations of this API might add more options. Generic implementations that accept an mOptions object and propagate it to this function should limit the options to the currently defined set of options or they might fail for unknown options.

module:sap/base/util/LoaderExtensions.registerResourcePath

Registers a URL prefix for a resource name prefix.

Before a resource is loaded, the longest registered prefix of its unified resource name is searched for and the associated URL prefix is used as a prefix for the request URL. The remainder of the resource name is attached to the request URL 1:1.

The registration and search operates on full name segments only. So when a prefix

   'sap/com'  ->  'http://www.sap.com/ui5/resources/'

is registered, then it will match the name

   'sap/com/Button'

but not

   'sap/commons/Button'

Note that the empty prefix ('') will always match and thus serves as a fallback for any search.

The URL prefix can either be given as string or as an object which contains a url property and optionally a final flag. If final is set to true, overwriting the path for the given resource name prefix is not possible anymore.

module:sap/base/util/LoaderExtensions.resolveUI5Url

Resolves the given ui5://... URL with sap.ui.require.toURl. Strings which are not a ui5: URL are simply returned unchanged.

module:sap/base/util/LoaderExtensions.getAllRequiredModules

Returns the names of all required modules in the legacy syntax for module names (dot-separated).

Param Type DefaultValue Description

module:sap/base/util/LoaderExtensions.getKnownSubtypes

Returns all known subtypes.

Param Type DefaultValue Description

module:sap/base/util/LoaderExtensions.loadResource

Retrieves the resource with the given name, either from the preload cache or from the server. The expected data type of the resource can either be specified in the options (dataType) or it will be derived from the suffix of the sResourceName. The only supported data types so far are 'xml', 'html', 'json' and 'text'. If the resource name extension doesn't match any of these extensions, the dataType property must be specified as option.

If the resource is found in the preload cache, it will be converted from text format to the requested dataType using conversions similar to:

  dataType | conversion
  ---------+-------------------------------------------------------------
    html   | text (no conversion)
    json   | JSON.parse(text)
    xml    | DOMParser.prototype.parseFromString(text, "application/xml")

If it is not found, the resource name will be converted to a resource URL (using #getResourcePath) and the resulting URL will be requested from the server with an XMLHttpRequest.

If the resource was found in the local preload cache and any necessary conversion succeeded or when the resource was retrieved from the backend successfully, the content of the resource will be returned. In any other case, an exception will be thrown, or if option failOnError is set, null will be returned.

For asynchronous calls, the return value of this method is a Promise which resolves with the content of the resource on success or rejects with an error in case of errors. If failOnError is false and an error occurs, the promise won't be rejected, but resolved with null.

Future implementations of this API might add more options. Generic implementations that accept an mOptions object and propagate it to this function should limit the options to the currently defined set of options or they might fail for unknown options.

Param Type DefaultValue Description
sResourceName string

resourceName In unified resource name syntax

mOptions object

Options

dataType string

One of "xml", "html", "json" or "text". If not specified, it will be derived from the extension of the resource name or URL

name string

Unified resource name of the resource to load (alternative syntax)

url string

URL of a resource to load (alternative syntax, name will only be a guess)

headers Object<string,string>

HTTP headers for an eventual XHR request

failOnError string true

Whether to propagate load errors to the caller or not

async string false

Whether the loading should be performed asynchronously

module:sap/base/util/LoaderExtensions.registerResourcePath

Registers a URL prefix for a resource name prefix.

Before a resource is loaded, the longest registered prefix of its unified resource name is searched for and the associated URL prefix is used as a prefix for the request URL. The remainder of the resource name is attached to the request URL 1:1.

The registration and search operates on full name segments only. So when a prefix

   'sap/com'  ->  'http://www.sap.com/ui5/resources/'

is registered, then it will match the name

   'sap/com/Button'

but not

   'sap/commons/Button'

Note that the empty prefix ('') will always match and thus serves as a fallback for any search.

The URL prefix can either be given as string or as an object which contains a url property and optionally a final flag. If final is set to true, overwriting the path for the given resource name prefix is not possible anymore.

Param Type DefaultValue Description
sResourceNamePrefix string

In unified resource name syntax

vUrlPrefix string object

Prefix to use instead of the sResourceNamePrefix, either a string literal or an object (e.g. {url : 'url/to/res', 'final': true})

url string

Path prefix to register

final boolean false

Prevents overwriting the URL path prefix for the given resource name prefix at a later point of time.

module:sap/base/util/LoaderExtensions.resolveUI5Url

Resolves the given ui5://... URL with sap.ui.require.toURl. Strings which are not a ui5: URL are simply returned unchanged.

Param Type DefaultValue Description
sUrl string

The URL string which should be resolved