Class sap.ushell.services.URLParsingModule: sap/ushell/services/URLParsing
Since: 1.15.0.
sap.ushell.Container.getService("URLParsing")
.for non compliant hash strings, the empty object {} is returned.
sap.ui.model.odata.ODataUtils.setOrigin(sServiceUrl, { alias : sSystem });
Makes the given server-relative SAP OData service URL point to the system given explicitly as parameter vComponentOrSystem
.sap.ushell.Container.getService("URLParsing")
. Constructs a new instance of the URL parsing service. Methods in this class allow to break down a shell compliant hash into it's respective parts (SemanticObject,Action,Context, Parameters, appSpecificHash) or (ShellPart,appSpecificHash) respectively or construct a hash from its constituents.
All methods deal with the *internal* shellHash format.
Most of the parse methods are robust w.r.t. a leading "#".
Note: The functions were designed with a "truthy" behaviour for not present values, Thus a client should not rely on the difference between null, "undefined", "" when testing for the result of a parse action.
The parsing functions are deliberately restrictive and fragile, only shell compliant hashes are parsed correctly, behaviour for non-compliant hashes is undefined and subject to change, notably we do not aim do "degrade" nicefully or support partial parsing of corrupted urls.
{object} | oShellHash | undefined if not a parseable hash { target : { semanticObject : string, xor { target : { shellHash } Note: in general it is preferred to add an appStateKey directly to the params object |
- Since:
- 1.16.0
{string} | the hash part of an URL, e.g. "Object-name~AFE2==?PV1=PV2&PV4=V5&/display/detail/7?UU=HH returns "" for an undefined object The action must be a valid action, it may not contain "?" or directly a parameter string |
{String} | sURL | any value |
- Since:
- 1.16.0
{String} | extracted string if and only if a hash is present, undefined otherwise |
http://www.mycorp.com/sap/fiori/FioriLaunchpad.html?sap-language=DE#SO-action?P1=value1
, the following parts http://www.mycorp.com/sap/fiori/FioriLaunchpad.html must match. The actual test is synchronous and *only* tests whether the hash part can be parsed and contains a semantic object and action. It does not test whether the intent or it's parameters is valid for a given user
Parameters:
{String} | sUrl | the URL to test |
Since:
1.30.0
Returns:
{Boolean} | true if the conditions are fulfilled. |
paramsToString(oParams): String combine members of a javascript object into a parameter string, note that parameters are ordered in an arbitrary manner which is subject to change Parameters:{Object} oParams any value { ABC : [1,"1 2"], DEF : ["4"]}
- Since:
- 1.20.0
Returns:{String} ABC=1&ABC=1%202DEF=4
Note that the result is *not* prefixed with a "?", parameter values are encodeURIComponent encoded.
parseParameters(sParams): Object parse parameters from a URI query string (starting with ?) into a parameter object Parameters:{String} sParams Parameter string, e.g. ?ABC=1&ABC=1%202DEF=4
- Since:
- 1.20.0
Returns:{Object} oParams any value { ABC : ["1","1 2"], DEF : ["4"]}
parseShellHash(sHash): object Decompose a shell hash into the respective parts Parameters:{String} sHash Hash part of a shell compliant URL #SO-Action~Context?P1=a&P2=x&/route?RPV=1
the hash part of an URL,
e.g. "#Object-name~AFE2==?PV1=PV2&PV4=V5&/display/detail/7?UU=HH
Note that params always has an Array for each parameter value!
- Since:
- 1.16.0
Returns:{object} undefined
if not a parseable hash
{ semanticObject : string,
action : string,
contextRaw : string,
params : MapObject,
appSpecificRoute : string
}
splitHash(sHash): object split a Unified Shell compliant hash into an Object containing a shell specific part and an app specific parts
for non compliant hash strings, the empty object {} is returned. an optional leading # is stripped Parameters:{String} sHash Hash part of a shell conformant URL {code}#SO-Action~Context?P1=a&P2=x&/route?RPV=1{code} the hash part of an URL, e.g. {code}"#Object-name~AFE2==?PV1=PV2&PV4=V5&/display/detail/7?UU=HH{code} Note that params always has an Array for each parameter value!
- Since:
- 1.16.0
Returns:{object} {}
(empty object) if not a parseable hash { shellPart : "Object-name~AFE2==?PV1=PV2&PV4=V5",
appSpecificRoute : "display/detail/7?UU=HH"
}
otherwise
addSystemToServiceUrl(sServiceUrl, vComponentOrSystem?): string Note: deprecated, please use sap.ui.model.odata.ODataUtils.setOrigin(sServiceUrl, { alias : sSystem });
Makes the given server-relative SAP OData service URL point to the system given explicitly as parameter vComponentOrSystem
. If this parameter is not provided, it makes the server-relative URL point to the system of the current application. Server-relative URL means a URL starting with exactly one "/" (also known as absolute-path URL). The system of the current application is taken from the parameter "sap-system" of the last navigation target resolution result. If either a multiple-origin parameter ;mo/
or an origin parameter with qualified system (;o=sid(SYS.123)
or o=SYSALIAS
) is already present, the sServiceUrl
is returned unchanged.
The framework invokes this function for SAPUI5 applications that have been built using declarative model instantiation with the application descriptor (data source) mechanism or using an sap.ca framework. For these applications, you do not need to invoke this function explicitly in the application code. If the application does not use any of these mechanisms, but explicitly constructs additional OData models or performs OData requests, the application code shall invoke this function. It shall pass its root component instance as vComponentOrSystem
- the function will then determine the system from the navigation start-up parameter "sap-system" (getComponentData().startupParameters["sap-system"][0]). Applications may call this API with parameter vComponentOrSystem
and a non-empty string value if application-specific logic is used to determine the target system for service calls.
With service URLs converted using this API, administrators can redirect service calls to servers other than the default SAP Gateway and back-end server either via reverse proxy (e.g. SAP Web Dispatcher) configuration or using the system alias functionality of the SAP Gateway server.
The system is added to the last URL segment of the service URL with the segment parameter ;o=
. You can also make this function put the system to a different URL path segment of the service URL by specifying the empty segment parameter ;o=
, e.g. /sap/opu/odata/MyService;o=/MyEntities/$count?p1=v1
. If both vComponentOrSystem
is empty and the current application has no system, no system is added and the empty segment parameter ;o
is removed.
Example 1:/sap/opu/odata/MyService/?p1=v1
is converted to /sap/opu/odata/MyService;o=SYS/?p1=v1
if the target system is "SYS". However it remains unchanged if both the current application's system and the parameter vComponentOrSystem
are empty.
Example 2:/sap/opu/odata/MyService;o=/MyEntities/$count?p1=v1
is converted to /sap/opu/odata/MyService;o=sid(SYS.123)/MyEntities/$count?p1=v1
if parameter vComponentOrSystem
is set to "sid(SYS.123)"
.
The URL is in no way normalized.
Parameters:{string} sServiceUrl a server-relative URL without system alias information {string|sap.ui.core.Component} vComponentOrSystem? the root component of the FLP application ( getComponentData().startupParameters["sap-system"][0]
is used as system alias if present) or a string valued system specification like "SYS" or "sid(SYS.123)" if undefined or falsy the system of the current application is used
- Deprecated:
- please use
sap.ui.model.odata.ODataUtils.setOrigin(sServiceUrl, { alias : sSystem });
The system alias can be extracted from the Component via getComponentData().startupParameters["sap-system"][0]
- Since:
- 1.19.1 (passing an SAPUI5 component instance as second parameter is supported since version 1.32.0)
Exceptions: Error if the URL is not server-relative (e.g. ./something
, http://foo.bar/something
, ...)
Returns:{string} the service URL pointing to the system specified in parameter vComponentOrSystem
or to the system of the current application