home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / air / update / descriptors / ConfigurationDescriptor.as < prev    next >
Encoding:
Text File  |  2010-06-23  |  5.4 KB  |  181 lines

  1. package air.update.descriptors
  2. {
  3.    import air.update.utils.Constants;
  4.    
  5.    public class ConfigurationDescriptor
  6.    {
  7.       public static const NAMESPACE_CONFIGURATION_1_0:Namespace = new Namespace("http://ns.adobe.com/air/framework/update/configuration/1.0");
  8.       
  9.       public static const DIALOG_CHECK_FOR_UPDATE:String = "checkforupdate";
  10.       
  11.       public static const DIALOG_DOWNLOAD_UPDATE:String = "downloadupdate";
  12.       
  13.       public static const DIALOG_DOWNLOAD_PROGRESS:String = "downloadprogress";
  14.       
  15.       public static const DIALOG_INSTALL_UPDATE:String = "installupdate";
  16.       
  17.       public static const DIALOG_FILE_UPDATE:String = "fileupdate";
  18.       
  19.       public static const DIALOG_UNEXPECTED_ERROR:String = "unexpectederror";
  20.       
  21.       private var defaultNS:Namespace;
  22.       
  23.       private var xml:XML;
  24.       
  25.       public function ConfigurationDescriptor(param1:XML)
  26.       {
  27.          super();
  28.          this.xml = param1;
  29.          this.defaultNS = param1.namespace();
  30.       }
  31.       
  32.       private static function validateDefaultUI(param1:XMLList) : Boolean
  33.       {
  34.          var _loc3_:XML = null;
  35.          default xml namespace = _loc2_;
  36.          if(param1.length() > 1)
  37.          {
  38.             return false;
  39.          }
  40.          var _loc2_:XMLList = param1.*;
  41.          for each(_loc3_ in _loc2_)
  42.          {
  43.             if(_loc3_.name() == null)
  44.             {
  45.                return false;
  46.             }
  47.             if(_loc3_.name().localName != "dialog")
  48.             {
  49.                return false;
  50.             }
  51.             if([DIALOG_CHECK_FOR_UPDATE,DIALOG_DOWNLOAD_UPDATE,DIALOG_DOWNLOAD_PROGRESS,DIALOG_INSTALL_UPDATE,DIALOG_FILE_UPDATE,DIALOG_UNEXPECTED_ERROR].indexOf(_loc3_.@name.toString().toLowerCase()) == -1)
  52.             {
  53.                return false;
  54.             }
  55.             if(["true","false"].indexOf(_loc3_.@visible.toString()) == -1)
  56.             {
  57.                return false;
  58.             }
  59.             if(_loc3_.hasComplexContent())
  60.             {
  61.                return false;
  62.             }
  63.          }
  64.          return true;
  65.       }
  66.       
  67.       public static function isThisVersion(param1:Namespace) : Boolean
  68.       {
  69.          return Boolean(param1) && param1.uri == NAMESPACE_CONFIGURATION_1_0.uri;
  70.       }
  71.       
  72.       private static function validateInterval(param1:String) : Boolean
  73.       {
  74.          var result:Boolean;
  75.          var intervalNumber:Number = NaN;
  76.          var intervalString:String = param1;
  77.          default xml namespace = result;
  78.          result = false;
  79.          if(intervalString.length > 0)
  80.          {
  81.             try
  82.             {
  83.                intervalNumber = Number(intervalString);
  84.                if(intervalNumber >= 0)
  85.                {
  86.                   result = true;
  87.                }
  88.             }
  89.             catch(theException:*)
  90.             {
  91.                result = false;
  92.             }
  93.          }
  94.          else
  95.          {
  96.             result = true;
  97.          }
  98.          return result;
  99.       }
  100.       
  101.       private static function convertInterval(param1:String) : Number
  102.       {
  103.          default xml namespace = _loc2_;
  104.          var _loc2_:Number = -1;
  105.          if(param1.length > 0)
  106.          {
  107.             _loc2_ = Number(param1);
  108.          }
  109.          return _loc2_;
  110.       }
  111.       
  112.       private function stringToBoolean_defaultFalse(param1:String) : Boolean
  113.       {
  114.          default xml namespace = this.defaultNS;
  115.          switch(param1)
  116.          {
  117.             case "true":
  118.             case "1":
  119.                return true;
  120.             case "":
  121.             case "false":
  122.             case "0":
  123.                return false;
  124.             default:
  125.                return false;
  126.          }
  127.       }
  128.       
  129.       public function get defaultUI() : Array
  130.       {
  131.          var _loc2_:XML = null;
  132.          var _loc3_:Object = null;
  133.          default xml namespace = this.defaultNS;
  134.          var _loc1_:Array = new Array();
  135.          for each(_loc2_ in this.xml.defaultUI.*)
  136.          {
  137.             _loc3_ = {
  138.                "name":_loc2_.@name,
  139.                "visible":this.stringToBoolean_defaultFalse(_loc2_.@visible)
  140.             };
  141.             _loc1_.push(_loc3_);
  142.          }
  143.          return _loc1_;
  144.       }
  145.       
  146.       public function validate() : void
  147.       {
  148.          default xml namespace = this.defaultNS;
  149.          if(!isThisVersion(this.defaultNS))
  150.          {
  151.             throw new Error("unknown configuration version",Constants.ERROR_CONFIGURATION_UNKNOWN);
  152.          }
  153.          if(this.url == "")
  154.          {
  155.             throw new Error("configuration url must have a non-empty value",Constants.ERROR_URL_MISSING);
  156.          }
  157.          if(!validateInterval(this.xml.delay.toString()))
  158.          {
  159.             throw new Error("Illegal value \"" + this.xml.delay.toString() + "\" for configuration/delay",Constants.ERROR_DELAY_INVALID);
  160.          }
  161.          if(!validateDefaultUI(this.xml.defaultUI))
  162.          {
  163.             throw new Error("Illegal values for configuration/defaultUI",Constants.ERROR_DEFAULTUI_INVALID);
  164.          }
  165.       }
  166.       
  167.       public function get checkInterval() : Number
  168.       {
  169.          default xml namespace = this.defaultNS;
  170.          return convertInterval(this.xml.delay.toString());
  171.       }
  172.       
  173.       public function get url() : String
  174.       {
  175.          default xml namespace = this.defaultNS;
  176.          return this.xml.url.toString();
  177.       }
  178.    }
  179. }
  180.  
  181.