Project

General

Profile

Statistics
| Revision:

root / trunk / web / dojo / dojox / storage / AirEncryptedLocalStorageProvider.js

History | View | Annotate | Download (4.6 KB)

1
/*
2
        Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
3
        Available via Academic Free License >= 2.1 OR the modified BSD license.
4
        see: http://dojotoolkit.org/license for details
5
*/
6

    
7

    
8
if(!dojo._hasResource["dojox.storage.AirEncryptedLocalStorageProvider"]){
9
dojo._hasResource["dojox.storage.AirEncryptedLocalStorageProvider"]=true;
10
dojo.provide("dojox.storage.AirEncryptedLocalStorageProvider");
11
dojo.require("dojox.storage.manager");
12
dojo.require("dojox.storage.Provider");
13
if(dojo.isAIR){
14
(function(){
15
if(!_1){
16
var _1={};
17
}
18
_1.ByteArray=window.runtime.flash.utils.ByteArray;
19
_1.EncryptedLocalStore=window.runtime.flash.data.EncryptedLocalStore,dojo.declare("dojox.storage.AirEncryptedLocalStorageProvider",[dojox.storage.Provider],{initialize:function(){
20
dojox.storage.manager.loaded();
21
},isAvailable:function(){
22
return true;
23
},_getItem:function(_2){
24
var _3=_1.EncryptedLocalStore.getItem("__dojo_"+_2);
25
return _3?_3.readUTFBytes(_3.length):"";
26
},_setItem:function(_4,_5){
27
var _6=new _1.ByteArray();
28
_6.writeUTFBytes(_5);
29
_1.EncryptedLocalStore.setItem("__dojo_"+_4,_6);
30
},_removeItem:function(_7){
31
_1.EncryptedLocalStore.removeItem("__dojo_"+_7);
32
},put:function(_8,_9,_a,_b){
33
if(this.isValidKey(_8)==false){
34
throw new Error("Invalid key given: "+_8);
35
}
36
_b=_b||this.DEFAULT_NAMESPACE;
37
if(this.isValidKey(_b)==false){
38
throw new Error("Invalid namespace given: "+_b);
39
}
40
try{
41
var _c=this._getItem("namespaces")||"|";
42
if(_c.indexOf("|"+_b+"|")==-1){
43
this._setItem("namespaces",_c+_b+"|");
44
}
45
var _d=this._getItem(_b+"_keys")||"|";
46
if(_d.indexOf("|"+_8+"|")==-1){
47
this._setItem(_b+"_keys",_d+_8+"|");
48
}
49
this._setItem("_"+_b+"_"+_8,_9);
50
}
51
catch(e){
52
_a(this.FAILED,_8,e.toString(),_b);
53
return;
54
}
55
if(_a){
56
_a(this.SUCCESS,_8,null,_b);
57
}
58
},get:function(_e,_f){
59
if(this.isValidKey(_e)==false){
60
throw new Error("Invalid key given: "+_e);
61
}
62
_f=_f||this.DEFAULT_NAMESPACE;
63
return this._getItem("_"+_f+"_"+_e);
64
},getNamespaces:function(){
65
var _10=[this.DEFAULT_NAMESPACE];
66
var _11=(this._getItem("namespaces")||"|").split("|");
67
for(var i=0;i<_11.length;i++){
68
if(_11[i].length&&_11[i]!=this.DEFAULT_NAMESPACE){
69
_10.push(_11[i]);
70
}
71
}
72
return _10;
73
},getKeys:function(_12){
74
_12=_12||this.DEFAULT_NAMESPACE;
75
if(this.isValidKey(_12)==false){
76
throw new Error("Invalid namespace given: "+_12);
77
}
78
var _13=[];
79
var _14=(this._getItem(_12+"_keys")||"|").split("|");
80
for(var i=0;i<_14.length;i++){
81
if(_14[i].length){
82
_13.push(_14[i]);
83
}
84
}
85
return _13;
86
},clear:function(_15){
87
if(this.isValidKey(_15)==false){
88
throw new Error("Invalid namespace given: "+_15);
89
}
90
var _16=this._getItem("namespaces")||"|";
91
if(_16.indexOf("|"+_15+"|")!=-1){
92
this._setItem("namespaces",_16.replace("|"+_15+"|","|"));
93
}
94
var _17=(this._getItem(_15+"_keys")||"|").split("|");
95
for(var i=0;i<_17.length;i++){
96
if(_17[i].length){
97
this._removeItem(_15+"_"+_17[i]);
98
}
99
}
100
this._removeItem(_15+"_keys");
101
},remove:function(key,_18){
102
_18=_18||this.DEFAULT_NAMESPACE;
103
var _19=this._getItem(_18+"_keys")||"|";
104
if(_19.indexOf("|"+key+"|")!=-1){
105
this._setItem(_18+"_keys",_19.replace("|"+key+"|","|"));
106
}
107
this._removeItem("_"+_18+"_"+key);
108
},putMultiple:function(_1a,_1b,_1c,_1d){
109
if(this.isValidKeyArray(_1a)===false||!_1b instanceof Array||_1a.length!=_1b.length){
110
throw new Error("Invalid arguments: keys = ["+_1a+"], values = ["+_1b+"]");
111
}
112
if(_1d==null||typeof _1d=="undefined"){
113
_1d=this.DEFAULT_NAMESPACE;
114
}
115
if(this.isValidKey(_1d)==false){
116
throw new Error("Invalid namespace given: "+_1d);
117
}
118
this._statusHandler=_1c;
119
try{
120
for(var i=0;i<_1a.length;i++){
121
this.put(_1a[i],_1b[i],null,_1d);
122
}
123
}
124
catch(e){
125
if(_1c){
126
_1c(this.FAILED,_1a,e.toString(),_1d);
127
}
128
return;
129
}
130
if(_1c){
131
_1c(this.SUCCESS,_1a,null);
132
}
133
},getMultiple:function(_1e,_1f){
134
if(this.isValidKeyArray(_1e)===false){
135
throw new Error("Invalid key array given: "+_1e);
136
}
137
if(_1f==null||typeof _1f=="undefined"){
138
_1f=this.DEFAULT_NAMESPACE;
139
}
140
if(this.isValidKey(_1f)==false){
141
throw new Error("Invalid namespace given: "+_1f);
142
}
143
var _20=[];
144
for(var i=0;i<_1e.length;i++){
145
_20[i]=this.get(_1e[i],_1f);
146
}
147
return _20;
148
},removeMultiple:function(_21,_22){
149
_22=_22||this.DEFAULT_NAMESPACE;
150
for(var i=0;i<_21.length;i++){
151
this.remove(_21[i],_22);
152
}
153
},isPermanent:function(){
154
return true;
155
},getMaximumSize:function(){
156
return this.SIZE_NO_LIMIT;
157
},hasSettingsUI:function(){
158
return false;
159
},showSettingsUI:function(){
160
throw new Error(this.declaredClass+" does not support a storage settings user-interface");
161
},hideSettingsUI:function(){
162
throw new Error(this.declaredClass+" does not support a storage settings user-interface");
163
}});
164
dojox.storage.manager.register("dojox.storage.AirEncryptedLocalStorageProvider",new dojox.storage.AirEncryptedLocalStorageProvider());
165
dojox.storage.manager.initialize();
166
})();
167
}
168
}