From e44a7e37b6c7b5961adaffc62b9042b8d442938e Mon Sep 17 00:00:00 2001 From: mensonge Date: Thu, 13 Nov 2008 09:49:11 +0000 Subject: New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f --- .../storage/AirEncryptedLocalStorageProvider.js | 221 +++++++++++++++++++++ 1 file changed, 221 insertions(+) create mode 100644 includes/js/dojox/storage/AirEncryptedLocalStorageProvider.js (limited to 'includes/js/dojox/storage/AirEncryptedLocalStorageProvider.js') diff --git a/includes/js/dojox/storage/AirEncryptedLocalStorageProvider.js b/includes/js/dojox/storage/AirEncryptedLocalStorageProvider.js new file mode 100644 index 0000000..500ac0f --- /dev/null +++ b/includes/js/dojox/storage/AirEncryptedLocalStorageProvider.js @@ -0,0 +1,221 @@ +if(!dojo._hasResource["dojox.storage.AirEncryptedLocalStorageProvider"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code. +dojo._hasResource["dojox.storage.AirEncryptedLocalStorageProvider"] = true; +dojo.provide("dojox.storage.AirEncryptedLocalStorageProvider"); +dojo.require("dojox.storage.manager"); +dojo.require("dojox.storage.Provider"); + +if (dojo.isAIR) { + (function(){ + + if (!air) { + var air = {}; + } + air.ByteArray = window.runtime.flash.utils.ByteArray; + air.EncryptedLocalStore = window.runtime.flash.data.EncryptedLocalStore, + + // summary: + // Storage provider that uses features in the Adobe AIR runtime to achieve + // permanent storage + dojo.declare("dojox.storage.AirEncryptedLocalStorageProvider", [ dojox.storage.Provider ], { + initialize: function(){ + // indicate that this storage provider is now loaded + dojox.storage.manager.loaded(); + }, + + isAvailable: function(){ + return true; + }, + + _getItem: function(key){ + var storedValue = air.EncryptedLocalStore.getItem("__dojo_" + key); + return storedValue ? storedValue.readUTFBytes(storedValue.length) : ""; + }, + + _setItem: function(key, value){ + var bytes = new air.ByteArray(); + bytes.writeUTFBytes(value); + air.EncryptedLocalStore.setItem("__dojo_" + key, bytes); + }, + + _removeItem: function(key){ + air.EncryptedLocalStore.removeItem("__dojo_" + key); + }, + + put: function(key, value, resultsHandler, namespace){ + if(this.isValidKey(key) == false){ + throw new Error("Invalid key given: " + key); + } + namespace = namespace||this.DEFAULT_NAMESPACE; + if(this.isValidKey(namespace) == false){ + throw new Error("Invalid namespace given: " + namespace); + } + + // try to store the value + try{ + var namespaces = this._getItem("namespaces")||'|'; + if(namespaces.indexOf('|'+namespace+'|')==-1){ + this._setItem("namespaces", namespaces + namespace + '|'); + } + var keys = this._getItem(namespace + "_keys")||'|'; + if(keys.indexOf('|'+key+'|')==-1){ + this._setItem(namespace + "_keys", keys + key + '|'); + } + this._setItem('_' + namespace + '_' + key, value); + }catch(e){ + // indicate we failed + console.debug("dojox.storage.AirEncryptedLocalStorageProvider.put:", e); + resultsHandler(this.FAILED, key, e.toString()); + return; + } + + if(resultsHandler){ + resultsHandler(this.SUCCESS, key, null); + } + }, + + get: function(key, namespace){ + if(this.isValidKey(key) == false){ + throw new Error("Invalid key given: " + key); + } + namespace = namespace||this.DEFAULT_NAMESPACE; + return this._getItem('_' + namespace + '_' + key); + }, + + getNamespaces: function(){ + var results = [ this.DEFAULT_NAMESPACE ]; + var namespaces = (this._getItem("namespaces")||'|').split('|'); + for (var i=0;i