UNPKG

4.99 kBJavaScriptView Raw
1/*!
2 * OpenUI5
3 * (c) Copyright 2009-2022 SAP SE or an SAP affiliate company.
4 * Licensed under the Apache License, Version 2.0 - see LICENSE.txt.
5 */
6
7// Provides access to Java-like properties files
8sap.ui.define(['jquery.sap.global', 'sap/base/util/Properties'],
9 function(jQuery, Properties) {
10 "use strict";
11
12 /**
13 * Creates and returns a new instance of {@link jQuery.sap.util.Properties}.
14 *
15 * If option 'url' is passed, immediately a load request for the given target is triggered.
16 * A property file that is loaded can contain comments with a leading ! or #.
17 * The loaded property list does not contain any comments.
18 *
19 * <b>Example for loading a property file:</b>
20 * <pre>
21 * jQuery.sap.properties({url : "../myProperty.properties"});
22 * </pre>
23 *
24 * <b>Example for creating an empty properties instance:</b>
25 * <pre>
26 * jQuery.sap.properties();
27 * </pre>
28 *
29 * <b>Examples for getting and setting properties:</b>
30 * <pre>
31 * var oProperties = jQuery.sap.properties();
32 * oProperties.setProperty("KEY_1","Test Key");
33 * var sValue1 = oProperties.getProperty("KEY_1");
34 * var sValue2 = oProperties.getProperty("KEY_2","Default");
35 * </pre>
36 *
37 * @name jQuery.sap.properties
38 * @function
39 * @param {object} [mParams] Parameters used to initialize the property list
40 * @param {string} [mParams.url] The URL to the .properties file which should be loaded
41 * @param {boolean} [mParams.async=false] Whether the .properties file should be loaded asynchronously or not
42 * @param {object} [mParams.headers] A map of additional header key/value pairs to send along with
43 * the request (see <code>headers</code> option of <code>jQuery.ajax</code>)
44 * @param {object} [mParams.returnNullIfMissing=false] Whether <code>null</code> should be returned
45 * for a missing properties file; by default an empty collection is returned
46 * @return {jQuery.sap.util.Properties|null|Promise} A new property collection (synchronous case)
47 * or <code>null</code> if the file could not be loaded and <code>returnNullIfMissing</code>
48 * was set; in case of asynchronous loading, always a Promise is returned, which resolves with
49 * the property collection or with <code>null</code> if the file could not be loaded and
50 * <code>returnNullIfMissing</code> was set to true
51 * @throws {Error} When the file has syntax issues (e.g. incomplete unicode escapes);
52 * in async mode, the error is not thrown but the returned Promise will be rejected
53 * @SecSink {0|PATH} Parameter is used for future HTTP requests
54 * @deprecated since 1.58 use {@link module:sap/base/util/Properties.create} instead
55 * @public
56 */
57 jQuery.sap.properties = Properties.create;
58
59 /**
60 * @interface Represents a collection of string properties (key/value pairs).
61 *
62 * Each key and its corresponding value in the collection is a string, keys are case-sensitive.
63 *
64 * Use {@link jQuery.sap.properties} to create an instance of <code>jQuery.sap.util.Properties</code>.
65 *
66 * The {@link #getProperty} method can be used to retrieve a value from the collection,
67 * {@link #setProperty} to store or change a value for a key and {@link #getKeys}
68 * can be used to retrieve an array of all keys that are currently stored in the collection.
69 *
70 * @version 1.90.11
71 * @since 0.9.0
72 * @name jQuery.sap.util.Properties
73 * @public
74 * @deprecated since 1.58 use {@link module:sap/base/util/Properties} instead
75 */
76
77 /**
78 * Returns the value for the given key or <code>null</code> if the collection has no value for the key.
79 *
80 * Optionally, a default value can be given which will be returned if the collection does not contain
81 * a value for the key; only non-empty default values are supported.
82 *
83 * @param {string} sKey Key to return the value for
84 * @param {string} [sDefaultValue=null] Optional, a default value that will be returned
85 * if the requested key is not in the collection
86 * @returns {string} Value for the given key or the default value or <code>null</code>
87 * if no default value or a falsy default value was given
88 * @public
89 *
90 * @function
91 * @name jQuery.sap.util.Properties#getProperty
92 */
93 /**
94 * Returns an array of all keys in the property collection.
95 * @returns {string[]} All keys in the property collection
96 * @public
97 *
98 * @function
99 * @name jQuery.sap.util.Properties#getKeys
100 */
101 /**
102 * Stores or changes the value for the given key in the collection.
103 *
104 * If the given value is not a string, the collection won't be modified.
105 * The key is always cast to a string.
106 *
107 * @param {string} sKey Key of the property
108 * @param {string} sValue String value for the key
109 * @public
110 *
111 * @function
112 * @name jQuery.sap.util.Properties#setProperty
113 */
114 /**
115 * Creates and returns a clone of the property collection.
116 * @returns {jQuery.sap.util.Properties} A clone of the property collection
117 * @public
118 *
119 * @function
120 * @name jQuery.sap.util.Properties#clone
121 */
122
123 return jQuery;
124
125});