home *** CD-ROM | disk | FTP | other *** search
/ One Click 21 (Special) / OC021.iso / Interface / it.dig / scripts / __Packages / mx / data / binding / ObjectDumper.as < prev    next >
Encoding:
Text File  |  2006-07-04  |  3.7 KB  |  146 lines

  1. class mx.data.binding.ObjectDumper
  2. {
  3.    var inProgress;
  4.    function ObjectDumper()
  5.    {
  6.       this.inProgress = new Array();
  7.    }
  8.    static function toString(obj, showFunctions, showUndefined, showXMLstructures, maxLineLength, indent)
  9.    {
  10.       var _loc3_ = new mx.data.binding.ObjectDumper();
  11.       if(maxLineLength == undefined)
  12.       {
  13.          maxLineLength = 100;
  14.       }
  15.       if(indent == undefined)
  16.       {
  17.          indent = 0;
  18.       }
  19.       return _loc3_.realToString(obj,showFunctions,showUndefined,showXMLstructures,maxLineLength,indent);
  20.    }
  21.    function realToString(obj, showFunctions, showUndefined, showXMLstructures, maxLineLength, indent)
  22.    {
  23.       var _loc8_ = 0;
  24.       while(_loc8_ < this.inProgress.length)
  25.       {
  26.          if(this.inProgress[_loc8_] == obj)
  27.          {
  28.             return "***";
  29.          }
  30.          _loc8_ = _loc8_ + 1;
  31.       }
  32.       this.inProgress.push(obj);
  33.       indent = indent + 1;
  34.       var _loc16_ = typeof obj;
  35.       var _loc5_ = undefined;
  36.       if(obj instanceof XMLNode && showXMLstructures != true)
  37.       {
  38.          _loc5_ = obj.toString();
  39.       }
  40.       else if(obj instanceof Date)
  41.       {
  42.          _loc5_ = obj.toString();
  43.       }
  44.       else if(_loc16_ == "object")
  45.       {
  46.          var _loc4_ = new Array();
  47.          if(obj instanceof Array)
  48.          {
  49.             _loc5_ = "[";
  50.             var _loc15_ = 0;
  51.             while(_loc15_ < obj.length)
  52.             {
  53.                _loc4_.push(_loc15_);
  54.                _loc15_ = _loc15_ + 1;
  55.             }
  56.          }
  57.          else
  58.          {
  59.             _loc5_ = "{";
  60.             for(_loc15_ in obj)
  61.             {
  62.                _loc4_.push(_loc15_);
  63.             }
  64.             _loc4_.sort();
  65.          }
  66.          var _loc9_ = "";
  67.          var _loc3_ = 0;
  68.          while(_loc3_ < _loc4_.length)
  69.          {
  70.             var _loc6_ = obj[_loc4_[_loc3_]];
  71.             var _loc7_ = true;
  72.             if(typeof _loc6_ == "function")
  73.             {
  74.                _loc7_ = showFunctions == true;
  75.             }
  76.             if(typeof _loc6_ == "undefined")
  77.             {
  78.                _loc7_ = showUndefined == true;
  79.             }
  80.             if(_loc7_)
  81.             {
  82.                _loc5_ += _loc9_;
  83.                if(!(obj instanceof Array))
  84.                {
  85.                   _loc5_ += _loc4_[_loc3_] + ": ";
  86.                }
  87.                _loc5_ += this.realToString(_loc6_,showFunctions,showUndefined,showXMLstructures,maxLineLength,indent);
  88.                _loc9_ = ", `";
  89.             }
  90.             _loc3_ = _loc3_ + 1;
  91.          }
  92.          if(obj instanceof Array)
  93.          {
  94.             _loc5_ += "]";
  95.          }
  96.          else
  97.          {
  98.             _loc5_ += "}";
  99.          }
  100.       }
  101.       else if(_loc16_ == "function")
  102.       {
  103.          _loc5_ = "function";
  104.       }
  105.       else if(_loc16_ == "string")
  106.       {
  107.          _loc5_ = "\"" + obj + "\"";
  108.       }
  109.       else
  110.       {
  111.          _loc5_ = String(obj);
  112.       }
  113.       if(_loc5_ == "undefined")
  114.       {
  115.          _loc5_ = "-";
  116.       }
  117.       this.inProgress.pop();
  118.       return mx.data.binding.ObjectDumper.replaceAll(_loc5_,"`",_loc5_.length >= maxLineLength ? "\n" + this.doIndent(indent) : "");
  119.    }
  120.    static function replaceAll(str, from, to)
  121.    {
  122.       var _loc3_ = str.split(from);
  123.       var _loc4_ = "";
  124.       var _loc2_ = "";
  125.       var _loc1_ = 0;
  126.       while(_loc1_ < _loc3_.length)
  127.       {
  128.          _loc4_ += _loc2_ + _loc3_[_loc1_];
  129.          _loc2_ = to;
  130.          _loc1_ = _loc1_ + 1;
  131.       }
  132.       return _loc4_;
  133.    }
  134.    function doIndent(indent)
  135.    {
  136.       var _loc2_ = "";
  137.       var _loc1_ = 0;
  138.       while(_loc1_ < indent)
  139.       {
  140.          _loc2_ += "     ";
  141.          _loc1_ = _loc1_ + 1;
  142.       }
  143.       return _loc2_;
  144.    }
  145. }
  146.