Debian Codegraph @

dojox/storage/Provider.js

raw symbols SCIP
1 define([
2 "dojo/_base/array",
3 "dojo/_base/declare",
4 "dojo/_base/lang"
5 ], function(array, declare, lang){
6 return declare("dojox.storage.Provider", null, {
7 // summary:
8 // A singleton for working with dojox.storage.
9 // description:
10 // dojox.storage exposes the current available storage provider on this
11 // platform. It gives you methods such as dojox.storage.put(),
12 // dojox.storage.get(), etc.
13 //
14 // For more details on dojox.storage, see the primary documentation
15 // page at
16 // http://manual.dojotoolkit.org/storage.html
17 //
18 // Note for storage provider developers who are creating subclasses-
19 // This is the base class for all storage providers Specific kinds of
20 // Storage Providers should subclass this and implement these methods.
21 // You should avoid initialization in storage provider subclass's
22 // constructor; instead, perform initialization in your initialize()
23 // method.
24 constructor: function(){
25 },
26
27 // SUCCESS: String
28 // Flag that indicates a put() call to a
29 // storage provider was succesful.
30 SUCCESS: "success",
31
32 // FAILED: String
33 // Flag that indicates a put() call to
34 // a storage provider failed.
35 FAILED: "failed",
36
37 // PENDING: String
38 // Flag that indicates a put() call to a
39 // storage provider is pending user approval.
40 PENDING: "pending",
41
42 // SIZE_NOT_AVAILABLE: String
43 // Returned by getMaximumSize() if this storage provider can not determine
44 // the maximum amount of data it can support.
45 SIZE_NOT_AVAILABLE: "Size not available",
46
47 // SIZE_NO_LIMIT: String
48 // Returned by getMaximumSize() if this storage provider has no theoretical
49 // limit on the amount of data it can store.
50 SIZE_NO_LIMIT: "No size limit",
51
52 // DEFAULT_NAMESPACE: String
53 // The namespace for all storage operations. This is useful if several
54 // applications want access to the storage system from the same domain but
55 // want different storage silos.
56 DEFAULT_NAMESPACE: "default",
57
58 // onHideSettingsUI: Function
59 // If a function is assigned to this property, then when the settings
60 // provider's UI is closed this function is called. Useful, for example,
61 // if the user has just cleared out all storage for this provider using
62 // the settings UI, and you want to update your UI.
63 onHideSettingsUI: null,
64
65 initialize: function(){
66 // summary:
67 // Allows this storage provider to initialize itself. This is
68 // called after the page has finished loading, so you can not do
69 // document.writes(). Storage Provider subclasses should initialize
70 // themselves inside of here rather than in their function
71 // constructor.
72 console.warn("dojox.storage.initialize not implemented");
73 },
74
75 isAvailable: function(){ /*Boolean*/
76 // summary:
77 // Returns whether this storage provider is available on this
78 // platform.
79 console.warn("dojox.storage.isAvailable not implemented");
80 },
81
82 put: function( /*string*/ key,
83 /*object*/ value,
84 /*function*/ resultsHandler,
85 /*string?*/ namespace){
86 // summary:
87 // Puts a key and value into this storage system.
88 // example:
89 // | var resultsHandler = function(status, key, message, namespace){
90 // | alert("status="+status+", key="+key+", message="+message);
91 // | };
92 // | dojox.storage.put("test", "hello world", resultsHandler);
93 // description:
94 // Important note: if you are using Dojo Storage in conjunction with
95 // Dojo Offline, then you don't need to provide
96 // a resultsHandler; this is because for Dojo Offline we
97 // use Google Gears to persist data, which has unlimited data
98 // once the user has given permission. If you are using Dojo
99 // Storage apart from Dojo Offline, then under the covers hidden
100 // Flash might be used, which is both asychronous and which might
101 // get denied; in this case you must provide a resultsHandler.
102 // key:
103 // A string key to use when retrieving this value in the future.
104 // value:
105 // A value to store; this can be any JavaScript type.
106 // resultsHandler:
107 // A callback function that will receive three arguments. The
108 // first argument is one of three values: dojox.storage.SUCCESS,
109 // dojox.storage.FAILED, or dojox.storage.PENDING; these values
110 // determine how the put request went. In some storage systems
111 // users can deny a storage request, resulting in a
112 // dojox.storage.FAILED, while in other storage systems a storage
113 // request must wait for user approval, resulting in a
114 // dojox.storage.PENDING status until the request is either
115 // approved or denied, resulting in another call back with
116 // dojox.storage.SUCCESS.
117 // The second argument in the call back is the key name that was being stored.
118 // The third argument in the call back is an optional message that
119 // details possible error messages that might have occurred during
120 // the storage process.
121 // namespace:
122 // Optional string namespace that this value will be placed into;
123 // if left off, the value will be placed into dojox.storage.DEFAULT_NAMESPACE
124 console.warn("dojox.storage.put not implemented");
125 },
126
127 get: function(/*string*/ key, /*string?*/ namespace){ /*Object*/
128 // summary:
129 // Gets the value with the given key. Returns null if this key is
130 // not in the storage system.
131 // key:
132 // A string key to get the value of.
133 // namespace:
134 // Optional string namespace that this value will be retrieved from;
135 // if left off, the value will be retrieved from dojox.storage.DEFAULT_NAMESPACE
136 // returns:
137 // Any JavaScript object type; null if the key is not present
138 console.warn("dojox.storage.get not implemented");
139 },
140
141 hasKey: function(/*string*/ key, /*string?*/ namespace){
142 // summary:
143 // Determines whether the storage has the given key.
144 return !!this.get(key, namespace); // Boolean
145 },
146
147 getKeys: function(/*string?*/ namespace){ /*Array*/
148 // summary:
149 // Enumerates all of the available keys in this storage system.
150 // returns:
151 // Array of available keys
152 console.warn("dojox.storage.getKeys not implemented");
153 },
154
155 clear: function(/*string?*/ namespace){
156 // summary:
157 // Completely clears this storage system of all of it's values and
158 // keys. If 'namespace' is provided just clears the keys in that
159 // namespace.
160 console.warn("dojox.storage.clear not implemented");
161 },
162
163 remove: function(/*string*/ key, /*string?*/ namespace){
164 // summary:
165 // Removes the given key from this storage system.
166 console.warn("dojox.storage.remove not implemented");
167 },
168
169 getNamespaces: function(){ /*string[]*/
170 console.warn("dojox.storage.getNamespaces not implemented");
171 },
172
173 isPermanent: function(){ /*Boolean*/
174 // summary:
175 // Returns whether this storage provider's values are persisted
176 // when this platform is shutdown.
177 console.warn("dojox.storage.isPermanent not implemented");
178 },
179
180 getMaximumSize: function(){ /* mixed */
181 // summary:
182 // The maximum storage allowed by this provider
183 // returns:
184 // Returns the maximum storage size
185 // supported by this provider, in
186 // thousands of bytes (i.e., if it
187 // returns 60 then this means that 60K
188 // of storage is supported).
189 //
190 // If this provider can not determine
191 // it's maximum size, then
192 // dojox.storage.SIZE_NOT_AVAILABLE is
193 // returned; if there is no theoretical
194 // limit on the amount of storage
195 // this provider can return, then
196 // dojox.storage.SIZE_NO_LIMIT is
197 // returned
198 console.warn("dojox.storage.getMaximumSize not implemented");
199 },
200
201 putMultiple: function( /*array*/ keys,
202 /*array*/ values,
203 /*function*/ resultsHandler,
204 /*string?*/ namespace){
205 // summary:
206 // Puts multiple keys and values into this storage system.
207 // example:
208 // | var resultsHandler = function(status, key, message){
209 // | alert("status="+status+", key="+key+", message="+message);
210 // | };
211 // | dojox.storage.put(["test"], ["hello world"], resultsHandler);
212 // description:
213 // Important note: if you are using Dojo Storage in conjunction with
214 // Dojo Offline, then you don't need to provide
215 // a resultsHandler; this is because for Dojo Offline we
216 // use Google Gears to persist data, which has unlimited data
217 // once the user has given permission. If you are using Dojo
218 // Storage apart from Dojo Offline, then under the covers hidden
219 // Flash might be used, which is both asychronous and which might
220 // get denied; in this case you must provide a resultsHandler.
221 // keys:
222 // An array of string keys to use when retrieving this value in the future,
223 // one per value to be stored
224 // values:
225 // An array of values to store; this can be any JavaScript type, though the
226 // performance of plain strings is considerably better
227 // resultsHandler:
228 // A callback function that will receive three arguments. The
229 // first argument is one of three values: dojox.storage.SUCCESS,
230 // dojox.storage.FAILED, or dojox.storage.PENDING; these values
231 // determine how the put request went. In some storage systems
232 // users can deny a storage request, resulting in a
233 // dojox.storage.FAILED, while in other storage systems a storage
234 // request must wait for user approval, resulting in a
235 // dojox.storage.PENDING status until the request is either
236 // approved or denied, resulting in another call back with
237 // dojox.storage.SUCCESS.
238 // The second argument in the call back is the key name that was being stored.
239 // The third argument in the call back is an optional message that
240 // details possible error messages that might have occurred during
241 // the storage process.
242 // namespace:
243 // Optional string namespace that this value will be placed into;
244 // if left off, the value will be placed into dojox.storage.DEFAULT_NAMESPACE
245 for(var i = 0; i < keys.length; i++){
246 dojox.storage.put(keys[i], values[i], resultsHandler, namespace);
247 }
248 },
249
250 getMultiple: function(/*array*/ keys, /*string?*/ namespace){ /*Object*/
251 // summary:
252 // Gets the values corresponding to each of the given keys.
253 // Returns a null array element for each given key that is
254 // not in the storage system.
255 // keys:
256 // An array of string keys to get the value of.
257 // namespace:
258 // Optional string namespace that this value will be retrieved from;
259 // if left off, the value will be retrieved from dojox.storage.DEFAULT_NAMESPACE
260 // returns:
261 // Any JavaScript object type; null if the key is not present
262 var results = [];
263 for(var i = 0; i < keys.length; i++){
264 results.push(dojox.storage.get(keys[i], namespace));
265 }
266
267 return results;
268 },
269
270 removeMultiple: function(/*array*/ keys, /*string?*/ namespace) {
271 // summary:
272 // Removes the given keys from this storage system.
273 for(var i = 0; i < keys.length; i++){
274 dojox.storage.remove(keys[i], namespace);
275 }
276 },
277
278 isValidKeyArray: function( keys) {
279 if(keys === null || keys === undefined || !lang.isArray(keys)){
280 return false;
281 }
282
283 // JAC: This could be optimized by running the key validity test
284 // directly over a joined string
285 return !array.some(keys, function(key){
286 return !this.isValidKey(key);
287 }, this); // Boolean
288 },
289
290 hasSettingsUI: function(){ /*Boolean*/
291 // summary:
292 // Determines whether this provider has a settings UI.
293 return false;
294 },
295
296 showSettingsUI: function(){
297 // summary:
298 // If this provider has a settings UI, determined
299 // by calling hasSettingsUI(), it is shown.
300 console.warn("dojox.storage.showSettingsUI not implemented");
301 },
302
303 hideSettingsUI: function(){
304 // summary:
305 // If this provider has a settings UI, hides it.
306 console.warn("dojox.storage.hideSettingsUI not implemented");
307 },
308
309 isValidKey: function(/*string*/ keyName){ /*Boolean*/
310 // summary:
311 // Subclasses can call this to ensure that the key given is valid
312 // in a consistent way across different storage providers. We use
313 // the lowest common denominator for key values allowed: only
314 // letters, numbers, and underscores are allowed. No spaces.
315 if(keyName === null || keyName === undefined){
316 return false;
317 }
318
319 return /^[0-9A-Za-z_]*$/.test(keyName);
320 },
321
322 getResourceList: function(){ /* Array[] */
323 // summary:
324 // Returns a list of URLs that this
325 // storage provider might depend on.
326 // description:
327 // This method returns a list of URLs that this
328 // storage provider depends on to do its work.
329 // This list is used by the Dojo Offline Toolkit
330 // to cache these resources to ensure the machinery
331 // used by this storage provider is available offline.
332 // What is returned is an array of URLs.
333 // Note that Dojo Offline uses Gears as its native
334 // storage provider, and does not support using other
335 // kinds of storage providers while offline anymore.
336 return [];
337 }
338 });
339 });