home *** CD-ROM | disk | FTP | other *** search
- class com.neodelight.wddx.Wddx
- {
- var et = null;
- var etRev = null;
- var at = null;
- var atRev = null;
- var timezoneString = null;
- var preserveVarCase = null;
- var useTimezoneInfo = null;
- var wddxPacket = null;
- function Wddx()
- {
- this.et = new Object();
- this.etRev = new Object();
- this.at = new Object();
- this.atRev = new Object();
- this.timezoneString = new String();
- this.preserveVarCase = true;
- this.useTimezoneInfo = true;
- var _loc2_ = 0;
- while(_loc2_ < 256)
- {
- if(_loc2_ < 32 && _loc2_ != 9 && _loc2_ != 10 && _loc2_ != 13)
- {
- var _loc3_ = _loc2_.toString(16);
- if(_loc3_.length == 1)
- {
- _loc3_ = "0" + _loc3_;
- }
- this.et[_loc2_] = "<char code=\'" + _loc3_ + "\'/>";
- this.at[_loc2_] = "";
- }
- else if(_loc2_ < 128)
- {
- this.et[_loc2_] = chr(_loc2_);
- this.at[_loc2_] = chr(_loc2_);
- }
- else
- {
- this.et[_loc2_] = "" + _loc2_.toString(16) + ";";
- this.etRev["" + _loc2_.toString(16) + ";"] = chr(_loc2_);
- this.at[_loc2_] = "" + _loc2_.toString(16) + ";";
- this.atRev["" + _loc2_.toString(16) + ";"] = chr(_loc2_);
- }
- _loc2_ = _loc2_ + 1;
- }
- this.et[60] = "<";
- this.et[62] = ">";
- this.et[38] = "&";
- this.etRev["<"] = "<";
- this.etRev[">"] = ">";
- this.etRev["&"] = "&";
- this.at[60] = "<";
- this.at[62] = ">";
- this.at[38] = "&";
- this.at[39] = "'";
- this.at[34] = """;
- this.atRev["<"] = "<";
- this.atRev[">"] = ">";
- this.atRev["&"] = "&";
- this.atRev["'"] = "\'";
- this.atRev["""] = "\"";
- var _loc4_ = new Date().getTimezoneOffset();
- if(_loc4_ >= 0)
- {
- this.timezoneString = "-";
- }
- else
- {
- this.timezoneString = "+";
- }
- this.timezoneString += Math.floor(Math.abs(_loc4_) / 60) + ":" + Math.abs(_loc4_) % 60;
- }
- static function serialize(rootObj)
- {
- var _loc4_ = new com.neodelight.wddx.Wddx();
- var _loc2_ = new XML();
- var _loc3_ = new XML();
- _loc3_.appendChild(_loc2_.createElement("wddxPacket"));
- var _loc1_ = _loc3_.firstChild;
- _loc1_.attributes.version = "1.0";
- _loc1_.appendChild(_loc2_.createElement("header"));
- _loc1_.appendChild(_loc2_.createElement("data"));
- if(_loc4_.serializeValue(rootObj,_loc1_.childNodes[1]))
- {
- return _loc3_.toString();
- }
- return null;
- }
- function serializeValue(obj, node)
- {
- var _loc4_ = true;
- var _loc6_ = obj.valueOf();
- var _loc9_ = null;
- var _loc7_ = new XML();
- if(obj == null)
- {
- node.appendChild(_loc7_.createElement("null"));
- }
- else if(typeof _loc6_ == "string")
- {
- this.serializeString(_loc6_,node);
- }
- else if(typeof _loc6_ == "number")
- {
- if(typeof obj.getTimezoneOffset == "function")
- {
- if(this.useTimezoneInfo)
- {
- _loc9_ = this.timezoneString;
- }
- node.appendChild(_loc7_.createElement("dateTime"));
- node.lastChild.appendChild(_loc7_.createTextNode(obj.getFullYear() + "-" + (obj.getMonth() + 1) + "-" + obj.getDate() + "T" + obj.getHours() + ":" + obj.getMinutes() + ":" + obj.getSeconds() + _loc9_));
- }
- else
- {
- node.appendChild(new XML().createElement("number"));
- node.lastChild.appendChild(new XML().createTextNode(_loc6_));
- }
- }
- else if(typeof _loc6_ == "boolean")
- {
- node.appendChild(_loc7_.createElement("boolean"));
- node.lastChild.attributes.value = _loc6_;
- }
- else if(typeof obj == "object")
- {
- if(typeof obj.wddxSerialize == "function")
- {
- _loc4_ = obj.wddxSerialize(this,node);
- }
- else if(typeof obj.join == "function" && typeof obj.reverse == "function")
- {
- node.appendChild(_loc7_.createElement("array"));
- node.lastChild.attributes.length = obj.length;
- var _loc3_ = 0;
- while(_loc4_ && _loc3_ < obj.length)
- {
- _loc4_ = this.serializeValue(obj[_loc3_],node.lastChild);
- _loc3_ = _loc3_ + 1;
- }
- }
- else
- {
- node.appendChild(_loc7_.createElement("struct"));
- if(typeof obj.wddxSerializationType == "string")
- {
- node.lastChild.attributes.type = obj.wddxSerializationType;
- }
- for(var _loc8_ in obj)
- {
- if(_loc8_ != "wddxSerializationType")
- {
- _loc4_ = this.serializeVariable(_loc8_,obj[_loc8_],node.lastChild);
- if(!_loc4_)
- {
- break;
- }
- }
- }
- }
- }
- else
- {
- _loc4_ = false;
- }
- return _loc4_;
- }
- function serializeVariable(vname, obj, node)
- {
- var _loc2_ = true;
- var _loc3_ = new XML();
- if(typeof obj != "function")
- {
- node.appendChild(_loc3_.createElement("var"));
- node.lastChild.attributes.name = !this.preserveVarCase ? this.serializeAttr(vname.toLowerCase()) : this.serializeAttr(vname);
- _loc2_ = this.serializeValue(obj,node.lastChild);
- }
- return _loc2_;
- }
- function serializeString(s, node)
- {
- var _loc3_ = "";
- var _loc6_ = new XML();
- var _loc4_ = s.length;
- node.appendChild(_loc6_.createElement("string"));
- var _loc2_ = 0;
- while(_loc2_ < _loc4_)
- {
- _loc3_ += this.et[ord(s.substring(_loc2_,_loc2_ + 1))];
- _loc2_ = _loc2_ + 1;
- }
- node.lastChild.appendChild(_loc6_.createTextNode(_loc3_));
- }
- function serializeAttr(s)
- {
- var _loc3_ = "";
- var _loc4_ = s.length;
- var _loc2_ = 0;
- while(_loc2_ < _loc4_)
- {
- _loc3_ += this.at[ord(s.substring(_loc2_,_loc2_ + 1))];
- _loc2_ = _loc2_ + 1;
- }
- return _loc3_;
- }
- static function deserialize(xmlString)
- {
- var _loc6_ = new com.neodelight.wddx.Wddx();
- var _loc2_ = new XML(xmlString);
- var _loc4_ = new XML();
- var _loc3_ = new Array();
- var _loc5_ = new Object();
- while(_loc2_.nodeName == null)
- {
- _loc2_ = _loc2_.firstChild;
- }
- _loc4_ = _loc2_;
- if(_loc4_.nodeName.toLowerCase() == "wddxpacket")
- {
- _loc3_ = _loc4_.childNodes;
- var _loc1_ = 0;
- while(_loc3_[_loc1_].nodeName.toLowerCase() != "data" && _loc1_ < _loc3_.length)
- {
- _loc1_ = _loc1_ + 1;
- }
- if(_loc1_ < _loc3_.length)
- {
- _loc5_ = _loc6_.deserializeNode(_loc3_[_loc1_].firstChild);
- return _loc5_;
- }
- return null;
- }
- return null;
- }
- function deserializeNode(node)
- {
- var _loc9_ = node.nodeName.toLowerCase();
- if(_loc9_ == "number")
- {
- var _loc7_ = node.firstChild.nodeValue;
- return Number(_loc7_);
- }
- if(_loc9_ == "boolean")
- {
- _loc7_ = String(node.attributes.value).toLowerCase() == "true";
- return _loc7_;
- }
- if(_loc9_ == "string")
- {
- if(node.childNodes.length > 1)
- {
- _loc7_ = "";
- var _loc4_ = 0;
- _loc4_ = 0;
- while(_loc4_ < node.childNodes.length)
- {
- if(node.childNodes[_loc4_].nodeType == 3)
- {
- _loc7_ += this.deserializeString(node.childNodes[_loc4_].nodeValue);
- }
- else if(node.childNodes[_loc4_].nodeName == "char")
- {
- _loc7_ += chr(parseInt(node.childNodes[_loc4_].attributes.code,16));
- }
- _loc4_ = _loc4_ + 1;
- }
- }
- else
- {
- _loc7_ = this.deserializeString(node.firstChild.nodeValue);
- }
- return _loc7_;
- }
- if(_loc9_ == "array")
- {
- _loc7_ = new Array();
- var _loc16_ = 0;
- _loc4_ = 0;
- while(_loc4_ < node.attributes.length)
- {
- _loc7_[_loc4_] = this.deserializeNode(node.childNodes[_loc4_].cloneNode(true));
- _loc4_ = _loc4_ + 1;
- }
- return _loc7_;
- }
- if(_loc9_ == "datetime")
- {
- var _loc10_ = node.firstChild.nodeValue;
- var _loc13_ = _loc10_.indexOf("T");
- var _loc8_ = _loc10_.indexOf("+");
- var _loc11_ = new Array();
- var _loc12_ = new Array();
- var _loc14_ = new Array();
- _loc7_ = new Date();
- if(_loc8_ == -1)
- {
- _loc8_ = _loc10_.lastIndexOf("-");
- if(_loc8_ < _loc13_)
- {
- _loc8_ = -1;
- }
- }
- _loc11_ = _loc10_.slice(0,_loc13_).split("-");
- _loc12_ = _loc10_.slice(_loc13_ + 1,_loc8_).split(":");
- _loc14_ = _loc10_.slice(_loc8_).split(":");
- _loc7_.setFullYear(parseInt(_loc11_[0]),parseInt(_loc11_[1]) - 1,parseInt(_loc11_[2]));
- _loc7_.setHours(parseInt(_loc12_[0]),parseInt(_loc12_[1]));
- if(_loc8_ != -1)
- {
- var _loc15_ = parseInt(_loc14_[0]) * 60 + parseInt(_loc14_[1]);
- _loc7_.setMinutes(_loc7_.getMinutes() - (_loc7_.getTimezoneOffset() + _loc15_));
- }
- return _loc7_;
- }
- if(_loc9_ == "struct")
- {
- _loc7_ = new Object();
- _loc4_ = 0;
- while(_loc4_ < node.childNodes.length)
- {
- if(node.childNodes[_loc4_].nodeName.toLowerCase() == "var")
- {
- _loc7_[this.deserializeAttr(node.childNodes[_loc4_].attributes.name)] = this.deserializeNode(node.childNodes[_loc4_].firstChild);
- }
- _loc4_ = _loc4_ + 1;
- }
- return _loc7_;
- }
- if(_loc9_ == "recordset")
- {
- _loc7_ = new com.neodelight.wddx.WddxRecordSet(node.attributes.fieldNames.split(",").reverse(),parseInt(node.attributes.rowCount));
- _loc4_ = node.childNodes.length - 1;
- while(_loc4_ >= 0)
- {
- if(node.childNodes[_loc4_].nodeName.toLowerCase() == "field")
- {
- var _loc5_ = this.deserializeAttr(node.childNodes[_loc4_].attributes.name);
- _loc7_[_loc5_].wddxSerializationType = "field";
- var _loc3_ = node.childNodes[_loc4_].childNodes.length - 1;
- while(_loc3_ >= 0)
- {
- _loc7_[_loc5_][_loc3_] = new Object();
- var _loc6_ = this.deserializeNode(node.childNodes[_loc4_].childNodes[_loc3_]);
- _loc7_.setField(_loc3_,_loc5_,_loc6_);
- _loc3_ = _loc3_ - 1;
- }
- }
- _loc4_ = _loc4_ - 1;
- }
- return _loc7_;
- }
- }
- function deserializeAttr(attr)
- {
- return attr;
- }
- function deserializeString(str)
- {
- return str;
- }
- }
-