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

  1. package air.update.descriptors
  2. {
  3.    import air.update.utils.Constants;
  4.    
  5.    public class UpdateDescriptor
  6.    {
  7.       public static const NAMESPACE_UPDATE_1_0:Namespace = new Namespace("http://ns.adobe.com/air/framework/update/description/1.0");
  8.       
  9.       private var defaultNS:Namespace;
  10.       
  11.       private var xml:XML;
  12.       
  13.       public function UpdateDescriptor(param1:XML)
  14.       {
  15.          super();
  16.          this.xml = param1;
  17.          this.defaultNS = param1.namespace();
  18.       }
  19.       
  20.       public static function getLocalizedText(param1:XMLList, param2:Namespace) : Array
  21.       {
  22.          var _loc5_:XMLList = null;
  23.          var _loc6_:XML = null;
  24.          default xml namespace = param2;
  25.          var _loc3_:Namespace = new Namespace("http://www.w3.org/XML/1998/namespace");
  26.          var _loc4_:Array = [];
  27.          if(param1.hasSimpleContent())
  28.          {
  29.             _loc4_ = [["",param1.toString()]];
  30.          }
  31.          else
  32.          {
  33.             _loc5_ = param1.param2::text;
  34.             for each(_loc6_ in _loc5_)
  35.             {
  36.                _loc4_.push([_loc6_._loc3_::@lang.toString(),_loc6_[0].toString()]);
  37.             }
  38.          }
  39.          return _loc4_;
  40.       }
  41.       
  42.       private static function validateLocalizedText(param1:XMLList, param2:Namespace) : Boolean
  43.       {
  44.          var _loc5_:XML = null;
  45.          default xml namespace = param2;
  46.          var _loc3_:Namespace = new Namespace("http://www.w3.org/XML/1998/namespace");
  47.          if(param1.hasSimpleContent())
  48.          {
  49.             return true;
  50.          }
  51.          if(param1.length() > 1)
  52.          {
  53.             return false;
  54.          }
  55.          var _loc4_:XMLList = param1.*;
  56.          for each(_loc5_ in _loc4_)
  57.          {
  58.             if(_loc5_.name() == null)
  59.             {
  60.                return false;
  61.             }
  62.             if(_loc5_.name().localName != "text")
  63.             {
  64.                return false;
  65.             }
  66.             if(_loc5_._loc3_::@lang.length() == 0)
  67.             {
  68.                return false;
  69.             }
  70.             if(!_loc5_.hasSimpleContent())
  71.             {
  72.                return false;
  73.             }
  74.          }
  75.          return true;
  76.       }
  77.       
  78.       public static function isThisVersion(param1:Namespace) : Boolean
  79.       {
  80.          return Boolean(param1) && param1.uri == NAMESPACE_UPDATE_1_0.uri;
  81.       }
  82.       
  83.       public function getXML() : XML
  84.       {
  85.          default xml namespace = this.defaultNS;
  86.          return this.xml;
  87.       }
  88.       
  89.       public function get version() : String
  90.       {
  91.          default xml namespace = this.defaultNS;
  92.          return this.xml.version.toString();
  93.       }
  94.       
  95.       public function get description() : Array
  96.       {
  97.          default xml namespace = this.defaultNS;
  98.          return UpdateDescriptor.getLocalizedText(this.xml.description,this.defaultNS);
  99.       }
  100.       
  101.       public function validate() : void
  102.       {
  103.          default xml namespace = this.defaultNS;
  104.          if(!isThisVersion(this.defaultNS))
  105.          {
  106.             throw new Error("unknown update version",Constants.ERROR_UPDATE_UNKNOWN);
  107.          }
  108.          if(this.version == "")
  109.          {
  110.             throw new Error("update version must have a non-empty value",Constants.ERROR_VERSION_MISSING);
  111.          }
  112.          if(this.url == "")
  113.          {
  114.             throw new Error("update url must have a non-empty value",Constants.ERROR_URL_MISSING);
  115.          }
  116.          if(!validateLocalizedText(this.xml.description,this.defaultNS))
  117.          {
  118.             throw new Error("Illegal values for update/description",Constants.ERROR_DESCRIPTION_INVALID);
  119.          }
  120.       }
  121.       
  122.       public function get url() : String
  123.       {
  124.          default xml namespace = this.defaultNS;
  125.          return this.xml.url.toString();
  126.       }
  127.    }
  128. }
  129.  
  130.