root / trunk / web / dojo / dojox / storage / AirFileStorageProvider.js
History | View | Annotate | Download (4.63 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.AirFileStorageProvider"]){ |
| 9 |
dojo._hasResource["dojox.storage.AirFileStorageProvider"]=true; |
| 10 |
dojo.provide("dojox.storage.AirFileStorageProvider");
|
| 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.File=window.runtime.flash.filesystem.File; |
| 19 |
_1.FileStream=window.runtime.flash.filesystem.FileStream; |
| 20 |
_1.FileMode=window.runtime.flash.filesystem.FileMode; |
| 21 |
dojo.declare("dojox.storage.AirFileStorageProvider",[dojox.storage.Provider],{initialized:false,_storagePath:"__DOJO_STORAGE/",initialize:function(){ |
| 22 |
this.initialized=false; |
| 23 |
try{
|
| 24 |
var _2=_1.File.applicationStorageDirectory.resolvePath(this._storagePath); |
| 25 |
if(!_2.exists){
|
| 26 |
_2.createDirectory(); |
| 27 |
} |
| 28 |
this.initialized=true; |
| 29 |
} |
| 30 |
catch(e){
|
| 31 |
} |
| 32 |
dojox.storage.manager.loaded(); |
| 33 |
},isAvailable:function(){ |
| 34 |
return true; |
| 35 |
},put:function(_3,_4,_5,_6){ |
| 36 |
if(this.isValidKey(_3)==false){ |
| 37 |
throw new Error("Invalid key given: "+_3); |
| 38 |
} |
| 39 |
_6=_6||this.DEFAULT_NAMESPACE;
|
| 40 |
if(this.isValidKey(_6)==false){ |
| 41 |
throw new Error("Invalid namespace given: "+_6); |
| 42 |
} |
| 43 |
try{
|
| 44 |
this.remove(_3,_6);
|
| 45 |
var _7=_1.File.applicationStorageDirectory.resolvePath(this._storagePath+_6); |
| 46 |
if(!_7.exists){
|
| 47 |
_7.createDirectory(); |
| 48 |
} |
| 49 |
var _8=_7.resolvePath(_3);
|
| 50 |
var _9=new _1.FileStream(); |
| 51 |
_9.open(_8,_1.FileMode.WRITE); |
| 52 |
_9.writeObject(_4); |
| 53 |
_9.close(); |
| 54 |
} |
| 55 |
catch(e){
|
| 56 |
_5(this.FAILED,_3,e.toString(),_6);
|
| 57 |
return;
|
| 58 |
} |
| 59 |
if(_5){
|
| 60 |
_5(this.SUCCESS,_3,null,_6); |
| 61 |
} |
| 62 |
},get:function(_a,_b){ |
| 63 |
if(this.isValidKey(_a)==false){ |
| 64 |
throw new Error("Invalid key given: "+_a); |
| 65 |
} |
| 66 |
_b=_b||this.DEFAULT_NAMESPACE;
|
| 67 |
var _c=null; |
| 68 |
var _d=_1.File.applicationStorageDirectory.resolvePath(this._storagePath+_b+"/"+_a); |
| 69 |
if(_d.exists&&!_d.isDirectory){
|
| 70 |
var _e=new _1.FileStream(); |
| 71 |
_e.open(_d,_1.FileMode.READ); |
| 72 |
_c=_e.readObject(); |
| 73 |
_e.close(); |
| 74 |
} |
| 75 |
return _c;
|
| 76 |
},getNamespaces:function(){ |
| 77 |
var _f=[this.DEFAULT_NAMESPACE]; |
| 78 |
var dir=_1.File.applicationStorageDirectory.resolvePath(this._storagePath); |
| 79 |
var _10=dir.getDirectoryListing(),i;
|
| 80 |
for(i=0;i<_10.length;i++){ |
| 81 |
if(_10[i].isDirectory&&_10[i].name!=this.DEFAULT_NAMESPACE){ |
| 82 |
_f.push(_10[i].name); |
| 83 |
} |
| 84 |
} |
| 85 |
return _f;
|
| 86 |
},getKeys:function(_11){ |
| 87 |
_11=_11||this.DEFAULT_NAMESPACE;
|
| 88 |
if(this.isValidKey(_11)==false){ |
| 89 |
throw new Error("Invalid namespace given: "+_11); |
| 90 |
} |
| 91 |
var _12=[];
|
| 92 |
var dir=_1.File.applicationStorageDirectory.resolvePath(this._storagePath+_11); |
| 93 |
if(dir.exists&&dir.isDirectory){
|
| 94 |
var _13=dir.getDirectoryListing(),i;
|
| 95 |
for(i=0;i<_13.length;i++){ |
| 96 |
_12.push(_13[i].name); |
| 97 |
} |
| 98 |
} |
| 99 |
return _12;
|
| 100 |
},clear:function(_14){ |
| 101 |
if(this.isValidKey(_14)==false){ |
| 102 |
throw new Error("Invalid namespace given: "+_14); |
| 103 |
} |
| 104 |
var dir=_1.File.applicationStorageDirectory.resolvePath(this._storagePath+_14); |
| 105 |
if(dir.exists&&dir.isDirectory){
|
| 106 |
dir.deleteDirectory(true);
|
| 107 |
} |
| 108 |
},remove:function(key,_15){ |
| 109 |
_15=_15||this.DEFAULT_NAMESPACE;
|
| 110 |
var _16=_1.File.applicationStorageDirectory.resolvePath(this._storagePath+_15+"/"+key); |
| 111 |
if(_16.exists&&!_16.isDirectory){
|
| 112 |
_16.deleteFile(); |
| 113 |
} |
| 114 |
},putMultiple:function(_17,_18,_19,_1a){ |
| 115 |
if(this.isValidKeyArray(_17)===false||!_18 instanceof Array||_17.length!=_18.length){ |
| 116 |
throw new Error("Invalid arguments: keys = ["+_17+"], values = ["+_18+"]"); |
| 117 |
} |
| 118 |
if(_1a==null||typeof _1a=="undefined"){ |
| 119 |
_1a=this.DEFAULT_NAMESPACE;
|
| 120 |
} |
| 121 |
if(this.isValidKey(_1a)==false){ |
| 122 |
throw new Error("Invalid namespace given: "+_1a); |
| 123 |
} |
| 124 |
this._statusHandler=_19;
|
| 125 |
try{
|
| 126 |
for(var i=0;i<_17.length;i++){ |
| 127 |
this.put(_17[i],_18[i],null,_1a); |
| 128 |
} |
| 129 |
} |
| 130 |
catch(e){
|
| 131 |
if(_19){
|
| 132 |
_19(this.FAILED,_17,e.toString(),_1a);
|
| 133 |
} |
| 134 |
return;
|
| 135 |
} |
| 136 |
if(_19){
|
| 137 |
_19(this.SUCCESS,_17,null,_1a); |
| 138 |
} |
| 139 |
},getMultiple:function(_1b,_1c){ |
| 140 |
if(this.isValidKeyArray(_1b)===false){ |
| 141 |
throw new Error("Invalid key array given: "+_1b); |
| 142 |
} |
| 143 |
if(_1c==null||typeof _1c=="undefined"){ |
| 144 |
_1c=this.DEFAULT_NAMESPACE;
|
| 145 |
} |
| 146 |
if(this.isValidKey(_1c)==false){ |
| 147 |
throw new Error("Invalid namespace given: "+_1c); |
| 148 |
} |
| 149 |
var _1d=[];
|
| 150 |
for(var i=0;i<_1b.length;i++){ |
| 151 |
_1d[i]=this.get(_1b[i],_1c);
|
| 152 |
} |
| 153 |
return _1d;
|
| 154 |
},removeMultiple:function(_1e,_1f){ |
| 155 |
_1f=_1f||this.DEFAULT_NAMESPACE;
|
| 156 |
for(var i=0;i<_1e.length;i++){ |
| 157 |
this.remove(_1e[i],_1f);
|
| 158 |
} |
| 159 |
},isPermanent:function(){ |
| 160 |
return true; |
| 161 |
},getMaximumSize:function(){ |
| 162 |
return this.SIZE_NO_LIMIT; |
| 163 |
},hasSettingsUI:function(){ |
| 164 |
return false; |
| 165 |
},showSettingsUI:function(){ |
| 166 |
throw new Error(this.declaredClass+" does not support a storage settings user-interface"); |
| 167 |
},hideSettingsUI:function(){ |
| 168 |
throw new Error(this.declaredClass+" does not support a storage settings user-interface"); |
| 169 |
}}); |
| 170 |
dojox.storage.manager.register("dojox.storage.AirFileStorageProvider",new dojox.storage.AirFileStorageProvider()); |
| 171 |
dojox.storage.manager.initialize(); |
| 172 |
})(); |
| 173 |
} |
| 174 |
} |