dojo.lang.extend()

in tapestry-framework/src/js/dojo-0.4.3-custom-4.1.6/src/storage/browser.js [11:356]


dojo.lang.extend(dojo.storage.browser.FileStorageProvider,{namespace:"default",initialized:false,_available:null,_statusHandler:null,_keyIndex:new Array(),initialize:function(){
if(djConfig["disableFileStorage"]==true){
return;
}
this._loadKeyIndex();
this.initialized=true;
dojo.storage.manager.loaded();
},isAvailable:function(){
this._available=false;
var _1=window.location.protocol;
if(_1.indexOf("file")!=-1||_1.indexOf("chrome")!=-1){
this._available=this._isAvailableXPCOM();
if(this._available==false){
this._available=this._isAvailableActiveX();
}
}
return this._available;
},put:function(_2,_3,_4){
if(this.isValidKey(_2)==false){
dojo.raise("Invalid key given: "+_2);
}
this._statusHandler=_4;
try{
this._save(_2,_3);
_4.call(null,dojo.storage.SUCCESS,_2);
}
catch(e){
this._statusHandler.call(null,dojo.storage.FAILED,_2,e.toString());
}
},get:function(_5){
if(this.isValidKey(_5)==false){
dojo.raise("Invalid key given: "+_5);
}
var _6=this._load(_5);
return _6;
},getKeys:function(){
return this._keyIndex;
},hasKey:function(_7){
if(this.isValidKey(_7)==false){
dojo.raise("Invalid key given: "+_7);
}
this._loadKeyIndex();
var _8=false;
for(var i=0;i<this._keyIndex.length;i++){
if(this._keyIndex[i]==_7){
_8=true;
}
}
return _8;
},clear:function(){
this._loadKeyIndex();
var _a=new Array();
for(var i=0;i<this._keyIndex.length;i++){
_a[_a.length]=new String(this._keyIndex[i]);
}
for(var i=0;i<_a.length;i++){
this.remove(_a[i]);
}
},remove:function(_c){
if(this.isValidKey(_c)==false){
dojo.raise("Invalid key given: "+_c);
}
this._loadKeyIndex();
for(var i=0;i<this._keyIndex.length;i++){
if(this._keyIndex[i]==_c){
this._keyIndex.splice(i,1);
break;
}
}
this._save(dojo.storage.browser.FileStorageProvider._KEY_INDEX_FILENAME,this._keyIndex,false);
var _e=this._getPagePath()+_c+".txt";
if(this._isAvailableXPCOM()){
this._removeXPCOM(_e);
}else{
if(this._isAvailableActiveX()){
this._removeActiveX(_e);
}
}
},isPermanent:function(){
return true;
},getMaximumSize:function(){
return dojo.storage.SIZE_NO_LIMIT;
},hasSettingsUI:function(){
return false;
},showSettingsUI:function(){
dojo.raise(this.getType()+" does not support a storage settings user-interface");
},hideSettingsUI:function(){
dojo.raise(this.getType()+" does not support a storage settings user-interface");
},getType:function(){
return "dojo.storage.browser.FileStorageProvider";
},_save:function(_f,_10,_11){
if(typeof _11=="undefined"){
_11=true;
}
if(dojo.lang.isString(_10)==false){
_10=dojo.json.serialize(_10);
_10="/* JavaScript */\n"+_10+"\n\n";
}
var _12=this._getPagePath()+_f+".txt";
if(this._isAvailableXPCOM()){
this._saveFileXPCOM(_12,_10);
}else{
if(this._isAvailableActiveX()){
this._saveFileActiveX(_12,_10);
}
}
if(_11){
this._updateKeyIndex(_f);
}
},_load:function(key){
var _14=this._getPagePath()+key+".txt";
var _15=null;
if(this._isAvailableXPCOM()){
_15=this._loadFileXPCOM(_14);
}else{
if(this._isAvailableActiveX()){
_15=this._loadFileActiveX(_14);
}else{
if(this._isAvailableJava()){
_15=this._loadFileJava(_14);
}
}
}
if(_15==null){
return null;
}
if(!dojo.lang.isUndefined(_15)&&_15!=null&&/^\/\* JavaScript \*\//.test(_15)){
_15=dojo.json.evalJson(_15);
}
return _15;
},_updateKeyIndex:function(key){
this._loadKeyIndex();
var _17=false;
for(var i=0;i<this._keyIndex.length;i++){
if(this._keyIndex[i]==key){
_17=true;
break;
}
}
if(_17==false){
this._keyIndex[this._keyIndex.length]=key;
}
this._save(dojo.storage.browser.FileStorageProvider._KEY_INDEX_FILENAME,this._keyIndex,false);
},_loadKeyIndex:function(){
var _19=this._load(dojo.storage.browser.FileStorageProvider._KEY_INDEX_FILENAME);
if(_19==null){
this._keyIndex=new Array();
}else{
this._keyIndex=_19;
}
},_saveFileXPCOM:function(_1a,_1b){
try{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var f=Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
f.initWithPath(_1a);
var _1d=Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
_1d.init(f,32|4|8,256+128,null);
_1d.write(_1b,_1b.length);
_1d.close();
}
catch(e){
var msg=e.toString();
if(e.name&&e.message){
msg=e.name+": "+e.message;
}
dojo.raise("dojo.storage.browser.FileStorageProvider._saveFileXPCOM(): "+msg);
}
},_loadFileXPCOM:function(_1f){
try{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var f=Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
f.initWithPath(_1f);
if(f.exists()==false){
return null;
}
var inp=Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
inp.init(f,1,4,null);
var _22=Components.classes["@mozilla.org/scriptableinputstream;1"].createInstance(Components.interfaces.nsIScriptableInputStream);
_22.init(inp);
var _23=_22.read(_22.available());
return _23;
}
catch(e){
var msg=e.toString();
if(e.name&&e.message){
msg=e.name+": "+e.message;
}
dojo.raise("dojo.storage.browser.FileStorageProvider._loadFileXPCOM(): "+msg);
}
return null;
},_saveFileActiveX:function(_25,_26){
try{
var _27=new ActiveXObject("Scripting.FileSystemObject");
var f=_27.OpenTextFile(_25,2,true);
f.Write(_26);
f.Close();
}
catch(e){
var msg=e.toString();
if(e.name&&e.message){
msg=e.name+": "+e.message;
}
dojo.raise("dojo.storage.browser.FileStorageProvider._saveFileActiveX(): "+msg);
}
},_loadFileActiveX:function(_2a){
try{
var _2b=new ActiveXObject("Scripting.FileSystemObject");
if(_2b.FileExists(_2a)==false){
return null;
}
var f=_2b.OpenTextFile(_2a,1);
var _2d=f.ReadAll();
f.Close();
return _2d;
}
catch(e){
var msg=e.toString();
if(e.name&&e.message){
msg=e.name+": "+e.message;
}
dojo.raise("dojo.storage.browser.FileStorageProvider._loadFileActiveX(): "+msg);
}
},_saveFileJava:function(_2f,_30){
try{
var _31=dojo.byId(dojo.storage.browser.FileStorageProvider._APPLET_ID);
_31.save(_2f,_30);
}
catch(e){
var msg=e.toString();
if(e.name&&e.message){
msg=e.name+": "+e.message;
}
dojo.raise("dojo.storage.browser.FileStorageProvider._saveFileJava(): "+msg);
}
},_loadFileJava:function(_33){
try{
var _34=dojo.byId(dojo.storage.browser.FileStorageProvider._APPLET_ID);
var _35=_34.load(_33);
return _35;
}
catch(e){
var msg=e.toString();
if(e.name&&e.message){
msg=e.name+": "+e.message;
}
dojo.raise("dojo.storage.browser.FileStorageProvider._loadFileJava(): "+msg);
}
},_isAvailableActiveX:function(){
try{
if(window.ActiveXObject){
var _37=new window.ActiveXObject("Scripting.FileSystemObject");
return true;
}
}
catch(e){
dojo.debug(e);
}
return false;
},_isAvailableXPCOM:function(){
try{
if(window.Components){
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
return true;
}
}
catch(e){
dojo.debug(e);
}
return false;
},_isAvailableJava:function(){
try{
if(dojo.render.html.safari==true||dojo.render.html.opera==true()){
if(navigator.javaEnabled()==true){
return true;
}
}
}
catch(e){
dojo.debug(e);
}
return false;
},_getPagePath:function(){
var _38=window.location.pathname;
if(/\.html?$/i.test(_38)){
_38=_38.replace(/(?:\/|\\)?[^\.\/\\]*\.html?$/,"");
}
if(/^\/?[a-z]+\:/i.test(_38)){
_38=_38.replace(/^\/?/,"");
_38=_38.replace(/\//g,"\\");
}else{
if(/^[\/\\]{2,3}[^\/]/.test(_38)){
_38=_38.replace(/^[\/\\]{2,3}/,"");
_38=_38.replace(/\//g,"\\");
_38="\\\\"+_38;
}
}
if(/\/$/.test(_38)==false&&/\\$/.test(_38)==false){
if(/\//.test(_38)){
_38+="/";
}else{
_38+="\\";
}
}
_38=unescape(_38);
return _38;
},_removeXPCOM:function(_39){
try{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var f=Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
f.initWithPath(_39);
if(f.exists()==false||f.isDirectory()){
return;
}
if(f.isFile()){
f.remove(false);
}
}
catch(e){
dojo.raise("dojo.storage.browser.FileStorageProvider.remove(): "+e.toString());
}
},_removeActiveX:function(_3b){
try{
var _3c=new ActiveXObject("Scripting.FileSystemObject");
_3c.DeleteFile(_3b);
}
catch(e){
dojo.raise("dojo.storage.browser.FileStorageProvider.remove(): "+e.toString());
}
},_removeJava:function(_3d){
try{
var _3e=dojo.byId(dojo.storage.browser.FileStorageProvider._APPLET_ID);
_3e.remove(_3d);
}
catch(e){
var msg=e.toString();
if(e.name&&e.message){
msg=e.name+": "+e.message;
}
dojo.raise("dojo.storage.browser.FileStorageProvider._removeJava(): "+msg);
}
},_writeApplet:function(){
var _40=dojo.uri.moduleUri("dojo","../DojoFileStorageProvider.jar").toString();
var tag="<applet "+"id='"+dojo.storage.browser.FileStorageProvider._APPLET_ID+"' "+"style='position: absolute; top: -500px; left: -500px; width: 1px; height: 1px;' "+"code='DojoFileStorageProvider.class' "+"archive='"+_40+"' "+"width='1' "+"height='1' "+">"+"</applet>";
document.writeln(tag);
}});