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

  1. package air.update.descriptors
  2. {
  3.    import flash.display.NativeWindowSystemChrome;
  4.    import flash.geom.Point;
  5.    
  6.    public class ApplicationDescriptor
  7.    {
  8.       public static const ICON_IMAGES:Object = {
  9.          "image16x16":16,
  10.          "image32x32":32,
  11.          "image48x48":48,
  12.          "image128x128":128
  13.       };
  14.       
  15.       private var m_defaultNs:Namespace;
  16.       
  17.       private var m_xml:XML;
  18.       
  19.       private var m_name:String;
  20.       
  21.       private var m_description:String;
  22.       
  23.       public function ApplicationDescriptor(param1:XML)
  24.       {
  25.          super();
  26.          this.m_xml = param1;
  27.          this.m_defaultNs = this.m_xml.namespace();
  28.       }
  29.       
  30.       private static function validateDimension(param1:String) : Boolean
  31.       {
  32.          var result:Boolean;
  33.          var dimensionNumber:Number = NaN;
  34.          var dimensionString:String = param1;
  35.          default xml namespace = result;
  36.          result = false;
  37.          if(dimensionString.length > 0)
  38.          {
  39.             try
  40.             {
  41.                dimensionNumber = Number(dimensionString);
  42.                if(dimensionNumber >= 0)
  43.                {
  44.                   result = true;
  45.                }
  46.             }
  47.             catch(theException:*)
  48.             {
  49.                result = false;
  50.             }
  51.          }
  52.          else
  53.          {
  54.             result = true;
  55.          }
  56.          return result;
  57.       }
  58.       
  59.       private static function convertDimension(param1:String) : Number
  60.       {
  61.          var _loc3_:uint = 0;
  62.          default xml namespace = _loc2_;
  63.          var _loc2_:Number = -1;
  64.          if(param1.length > 0)
  65.          {
  66.             _loc3_ = uint(param1);
  67.             _loc2_ = Number(_loc3_);
  68.          }
  69.          return _loc2_;
  70.       }
  71.       
  72.       private static function convertLocation(param1:String) : Number
  73.       {
  74.          var _loc3_:int = 0;
  75.          default xml namespace = _loc2_;
  76.          var _loc2_:Number = -1;
  77.          if(param1.length > 0)
  78.          {
  79.             _loc3_ = int(param1);
  80.             _loc2_ = Number(_loc3_);
  81.          }
  82.          return _loc2_;
  83.       }
  84.       
  85.       private static function validateLocalizedText(param1:XMLList, param2:Namespace) : Boolean
  86.       {
  87.          var _loc5_:XML = null;
  88.          default xml namespace = param2;
  89.          var _loc3_:Namespace = new Namespace("http://www.w3.org/XML/1998/namespace");
  90.          if(param1.hasSimpleContent())
  91.          {
  92.             return true;
  93.          }
  94.          if(param1.length() > 1)
  95.          {
  96.             return false;
  97.          }
  98.          var _loc4_:XMLList = param1.*;
  99.          for each(_loc5_ in _loc4_)
  100.          {
  101.             if(_loc5_.name() == null || _loc5_.name().localName != "text")
  102.             {
  103.                return false;
  104.             }
  105.             if(_loc5_._loc3_::@lang.length() == 0)
  106.             {
  107.                return false;
  108.             }
  109.             if(!_loc5_.hasSimpleContent())
  110.             {
  111.                return false;
  112.             }
  113.          }
  114.          return true;
  115.       }
  116.       
  117.       private static function validateDimensionPair(param1:String) : Boolean
  118.       {
  119.          var _loc3_:Point = null;
  120.          default xml namespace = _loc2_;
  121.          var _loc2_:Boolean = false;
  122.          if(param1.length > 0)
  123.          {
  124.             _loc3_ = convertDimensionPoint(param1);
  125.             if(_loc3_ != null && _loc3_.x != -1 && _loc3_.y != -1)
  126.             {
  127.                _loc2_ = true;
  128.             }
  129.          }
  130.          else
  131.          {
  132.             _loc2_ = true;
  133.          }
  134.          return _loc2_;
  135.       }
  136.       
  137.       private static function validateLocation(param1:String) : Boolean
  138.       {
  139.          var result:Boolean;
  140.          var dimensionNumber:Number = NaN;
  141.          var inputString:String = param1;
  142.          default xml namespace = result;
  143.          result = false;
  144.          if(inputString.length > 0)
  145.          {
  146.             try
  147.             {
  148.                dimensionNumber = Number(inputString);
  149.                if(!isNaN(dimensionNumber))
  150.                {
  151.                   result = true;
  152.                }
  153.             }
  154.             catch(theException:*)
  155.             {
  156.                result = false;
  157.             }
  158.          }
  159.          else
  160.          {
  161.             result = true;
  162.          }
  163.          return result;
  164.       }
  165.       
  166.       private static function convertDimensionPoint(param1:String) : Point
  167.       {
  168.          var result:Point;
  169.          var list:Array = null;
  170.          var x:Number = NaN;
  171.          var y:Number = NaN;
  172.          var pt:Point = null;
  173.          var dimensionString:String = param1;
  174.          default xml namespace = result;
  175.          result = null;
  176.          if(dimensionString.length > 0)
  177.          {
  178.             try
  179.             {
  180.                list = dimensionString.split(/ +/);
  181.                if(list.length == 2)
  182.                {
  183.                   x = convertDimension(String(list[0]));
  184.                   y = convertDimension(String(list[1]));
  185.                   pt = new Point();
  186.                   pt.x = x;
  187.                   pt.y = y;
  188.                   result = pt;
  189.                }
  190.             }
  191.             catch(e:Error)
  192.             {
  193.                result = null;
  194.             }
  195.          }
  196.          return result;
  197.       }
  198.       
  199.       public function get initialWindowX() : Number
  200.       {
  201.          default xml namespace = this.m_defaultNs;
  202.          return convertLocation(this.m_xml.initialWindow.x.toString());
  203.       }
  204.       
  205.       public function get initialWindowContent() : String
  206.       {
  207.          default xml namespace = this.m_defaultNs;
  208.          return this.m_xml.initialWindow.content;
  209.       }
  210.       
  211.       public function get filename() : String
  212.       {
  213.          default xml namespace = this.m_defaultNs;
  214.          return this.m_xml.filename.toString();
  215.       }
  216.       
  217.       public function get minimumPatchLevel() : int
  218.       {
  219.          default xml namespace = this.m_defaultNs;
  220.          return this.m_xml.@minimumPatchLevel;
  221.       }
  222.       
  223.       public function get name() : String
  224.       {
  225.          default xml namespace = this.m_defaultNs;
  226.          return this.m_name == "" ? this.filename : this.m_name;
  227.       }
  228.       
  229.       private function stringToBoolean_defaultTrue(param1:String) : Boolean
  230.       {
  231.          default xml namespace = this.m_defaultNs;
  232.          switch(param1)
  233.          {
  234.             case "":
  235.             case "true":
  236.             case "1":
  237.                return true;
  238.             case "false":
  239.             case "0":
  240.                return false;
  241.             default:
  242.                return true;
  243.          }
  244.       }
  245.       
  246.       public function get initialWindowMinimizable() : Boolean
  247.       {
  248.          default xml namespace = this.m_defaultNs;
  249.          return this.stringToBoolean_defaultTrue(this.m_xml.initialWindow.minimizable.toString());
  250.       }
  251.       
  252.       public function get copyright() : String
  253.       {
  254.          default xml namespace = this.m_defaultNs;
  255.          return this.m_xml.copyright.toString();
  256.       }
  257.       
  258.       public function get initialWindowMaxSize() : Point
  259.       {
  260.          default xml namespace = this.m_defaultNs;
  261.          return convertDimensionPoint(this.m_xml.initialWindow.maxSize.toString());
  262.       }
  263.       
  264.       public function get initialWindowWidth() : Number
  265.       {
  266.          default xml namespace = this.m_defaultNs;
  267.          return convertDimension(this.m_xml.initialWindow.width.toString());
  268.       }
  269.       
  270.       public function get initialWindowY() : Number
  271.       {
  272.          default xml namespace = this.m_defaultNs;
  273.          return convertLocation(this.m_xml.initialWindow.y.toString());
  274.       }
  275.       
  276.       public function validate() : void
  277.       {
  278.          default xml namespace = this.m_defaultNs;
  279.          if(this.filename == "")
  280.          {
  281.             throw new Error("application filename must have a non-empty value.");
  282.          }
  283.          if(!/^([^\*\"\/:<>\?\\\|\. ]|[^\*\"\/:<>\?\\\| ][^\*\"\/:<>\?\\\|]*[^\*\"\/:<>\?\\\|\. ])$/.test(this.filename))
  284.          {
  285.             throw new Error("invalid application filename");
  286.          }
  287.          if(this.m_xml.initialWindow.content.toString() == "")
  288.          {
  289.             throw new Error("initialWindow/content must have a non-empty value.");
  290.          }
  291.          if(this.installFolder != "" && !/^([^\*\"\/:<>\?\\\|\. ]|[^\*\"\/:<>\?\\\| ][^\*\":<>\?\\\|]*[^\*\":<>\?\\\|\. ])$/.test(this.installFolder))
  292.          {
  293.             throw new Error("invalid install folder");
  294.          }
  295.          if(this.programMenuFolder != "" && !/^([^\*\"\/:<>\?\\\|\. ]|[^\*\"\/:<>\?\\\| ][^\*\":<>\?\\\|]*[^\*\":<>\?\\\|\. ])$/.test(this.programMenuFolder))
  296.          {
  297.             throw new Error("invalid program menu folder");
  298.          }
  299.          if(["",NativeWindowSystemChrome.NONE,NativeWindowSystemChrome.STANDARD].indexOf(this.m_xml.initialWindow.systemChrome.toString()) == -1)
  300.          {
  301.             throw new Error("Illegal value \"" + this.m_xml.initialWindow.systemChrome.toString() + "\" for application/initialWindow/systemChrome.");
  302.          }
  303.          if(["","true","false","1","0"].indexOf(this.m_xml.initialWindow.transparent.toString()) == -1)
  304.          {
  305.             throw new Error("Illegal value \"" + this.m_xml.initialWindow.transparent.toString() + "\" for application/initialWindow/transparent.");
  306.          }
  307.          if(["","true","false","1","0"].indexOf(this.m_xml.initialWindow.visible.toString()) == -1)
  308.          {
  309.             throw new Error("Illegal value \"" + this.m_xml.initialWindow.visible.toString() + "\" for application/initialWindow/visible.");
  310.          }
  311.          if(["","true","false","1","0"].indexOf(this.m_xml.initialWindow.minimizable.toString()) == -1)
  312.          {
  313.             throw new Error("Illegal value \"" + this.m_xml.initialWindow.minimizable.toString() + "\" for application/initialWindow/minimizable.");
  314.          }
  315.          if(["","true","false","1","0"].indexOf(this.m_xml.initialWindow.maximizable.toString()) == -1)
  316.          {
  317.             throw new Error("Illegal value \"" + this.m_xml.initialWindow.maximizable.toString() + "\" for application/initialWindow/maximizable.");
  318.          }
  319.          if(["","true","false","1","0"].indexOf(this.m_xml.initialWindow.resizable.toString()) == -1)
  320.          {
  321.             throw new Error("Illegal value \"" + this.m_xml.initialWindow.resizable.toString() + "\" for application/initialWindow/resizeable.");
  322.          }
  323.          if(["","true","false","1","0"].indexOf(this.m_xml.initialWindow.closeable.toString()) == -1)
  324.          {
  325.             throw new Error("Illegal value \"" + this.m_xml.initialWindow.closeable.toString() + "\" for application/initialWindow/closeable.");
  326.          }
  327.          if(this.initialWindowTransparent && this.initialWindowSystemChrome != NativeWindowSystemChrome.NONE)
  328.          {
  329.             throw new Error("Illegal window settings.  Transparent windows are only supported when systemChrome is set to \"none\".");
  330.          }
  331.          if(!validateDimension(this.m_xml.initialWindow.width.toString()))
  332.          {
  333.             throw new Error("Illegal value \"" + this.m_xml.initialWindow.width.toString() + "\" for application/initialWindow/width.");
  334.          }
  335.          if(!validateDimension(this.m_xml.initialWindow.height.toString()))
  336.          {
  337.             throw new Error("Illegal value \"" + this.m_xml.initialWindow.height.toString() + "\" for application/initialWindow/height.");
  338.          }
  339.          if(!validateLocation(this.m_xml.initialWindow.x.toString()))
  340.          {
  341.             throw new Error("Illegal value \"" + this.m_xml.initialWindow.x.toString() + "\" for application/initialWindow/x.");
  342.          }
  343.          if(!validateLocation(this.m_xml.initialWindow.y.toString()))
  344.          {
  345.             throw new Error("Illegal value \"" + this.m_xml.initialWindow.y.toString() + "\" for application/initialWindow/y.");
  346.          }
  347.          if(!validateDimensionPair(this.m_xml.initialWindow.minSize.toString()))
  348.          {
  349.             throw new Error("Illegal value \"" + this.m_xml.initialWindow.minSize.toString() + "\" for application/initialWindow/minSize.");
  350.          }
  351.          if(!validateDimensionPair(this.m_xml.initialWindow.maxSize.toString()))
  352.          {
  353.             throw new Error("Illegal value \"" + this.m_xml.initialWindow.maxSize.toString() + "\" for application/initialWindow/maxSize.");
  354.          }
  355.          if(!validateLocalizedText(this.m_xml.name,this.m_defaultNs))
  356.          {
  357.             throw new Error("Illegal values for application/name.");
  358.          }
  359.          if(!validateLocalizedText(this.m_xml.description,this.m_defaultNs))
  360.          {
  361.             throw new Error("Illegal values for application/description.");
  362.          }
  363.          if(!/^[A-Za-z0-9\-\.]{1,212}$/.test(this.id))
  364.          {
  365.             throw new Error("invalid application identifier");
  366.          }
  367.       }
  368.       
  369.       public function get version() : String
  370.       {
  371.          default xml namespace = this.m_defaultNs;
  372.          return this.m_xml.version.toString();
  373.       }
  374.       
  375.       public function get namespace() : Namespace
  376.       {
  377.          default xml namespace = this.m_defaultNs;
  378.          return this.m_xml.namespace();
  379.       }
  380.       
  381.       public function get fileTypes() : XMLList
  382.       {
  383.          default xml namespace = this.m_defaultNs;
  384.          return this.m_xml.fileTypes.elements();
  385.       }
  386.       
  387.       public function get initialWindowCloseable() : Boolean
  388.       {
  389.          default xml namespace = this.m_defaultNs;
  390.          return this.stringToBoolean_defaultTrue(this.m_xml.initialWindow.closeable.toString());
  391.       }
  392.       
  393.       public function get initialWindowMaximizable() : Boolean
  394.       {
  395.          default xml namespace = this.m_defaultNs;
  396.          return this.stringToBoolean_defaultTrue(this.m_xml.initialWindow.maximizable.toString());
  397.       }
  398.       
  399.       public function get programMenuFolder() : String
  400.       {
  401.          default xml namespace = this.m_defaultNs;
  402.          return this.m_xml.programMenuFolder.toString();
  403.       }
  404.       
  405.       public function get initialWindowHeight() : Number
  406.       {
  407.          default xml namespace = this.m_defaultNs;
  408.          return convertDimension(this.m_xml.initialWindow.height.toString());
  409.       }
  410.       
  411.       public function get initialWindowTitle() : String
  412.       {
  413.          default xml namespace = this.m_defaultNs;
  414.          var _loc1_:String = this.m_xml.initialWindow.title.toString();
  415.          if(_loc1_ == "")
  416.          {
  417.             _loc1_ = this.name;
  418.          }
  419.          return _loc1_;
  420.       }
  421.       
  422.       private function stringToBoolean_defaultFalse(param1:String) : Boolean
  423.       {
  424.          default xml namespace = this.m_defaultNs;
  425.          switch(param1)
  426.          {
  427.             case "true":
  428.             case "1":
  429.                return true;
  430.             case "":
  431.             case "false":
  432.             case "0":
  433.                return false;
  434.             default:
  435.                return false;
  436.          }
  437.       }
  438.       
  439.       public function hasCustomUpdateUI() : Boolean
  440.       {
  441.          default xml namespace = this.m_defaultNs;
  442.          return this.stringToBoolean_defaultFalse(this.m_xml.customUpdateUI.toString());
  443.       }
  444.       
  445.       public function get installFolder() : String
  446.       {
  447.          default xml namespace = this.m_defaultNs;
  448.          return this.m_xml.installFolder.toString();
  449.       }
  450.       
  451.       public function get id() : String
  452.       {
  453.          default xml namespace = this.m_defaultNs;
  454.          return this.m_xml.id.toString();
  455.       }
  456.       
  457.       public function get initialWindowTransparent() : Boolean
  458.       {
  459.          default xml namespace = this.m_defaultNs;
  460.          return this.stringToBoolean_defaultFalse(this.m_xml.initialWindow.transparent.toString());
  461.       }
  462.       
  463.       public function getIcon(param1:String) : String
  464.       {
  465.          default xml namespace = this.m_defaultNs;
  466.          return this.m_xml.icon.elements(new QName(this.m_defaultNs,param1)).toString();
  467.       }
  468.       
  469.       public function get initialWindowResizable() : Boolean
  470.       {
  471.          default xml namespace = this.m_defaultNs;
  472.          return this.stringToBoolean_defaultTrue(this.m_xml.initialWindow.resizable.toString());
  473.       }
  474.       
  475.       public function get description() : String
  476.       {
  477.          default xml namespace = this.m_defaultNs;
  478.          return this.m_description;
  479.       }
  480.       
  481.       public function get initialWindowSystemChrome() : String
  482.       {
  483.          default xml namespace = this.m_defaultNs;
  484.          var _loc1_:String = this.m_xml.initialWindow.systemChrome.toString();
  485.          var _loc2_:String = NativeWindowSystemChrome.STANDARD;
  486.          switch(_loc1_)
  487.          {
  488.             case NativeWindowSystemChrome.STANDARD:
  489.             case NativeWindowSystemChrome.NONE:
  490.                _loc2_ = _loc1_;
  491.          }
  492.          return _loc2_;
  493.       }
  494.       
  495.       public function get initialWindowVisible() : Boolean
  496.       {
  497.          default xml namespace = this.m_defaultNs;
  498.          return this.stringToBoolean_defaultFalse(this.m_xml.initialWindow.visible.toString());
  499.       }
  500.       
  501.       public function get initialWindowMinSize() : Point
  502.       {
  503.          default xml namespace = this.m_defaultNs;
  504.          return convertDimensionPoint(this.m_xml.initialWindow.minSize.toString());
  505.       }
  506.    }
  507. }
  508.  
  509.