[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/image_fupload/swfupload/tmp/Flash/ -> FileItem.as (source)

   1  package {
   2      import flash.net.FileReference;
   3  
   4      internal class FileItem
   5      {
   6          private static var file_id_sequence:Number = 0;        // tracks the file id sequence

   7  
   8          private var postObject:Object;
   9          public var file_reference:FileReference;
  10          public var id:String;
  11          public var index:Number = -1;
  12          public var file_status:int = 0;
  13          private var js_object:Object;
  14          
  15          public static var FILE_STATUS_QUEUED:int        = -1;
  16          public static var FILE_STATUS_IN_PROGRESS:int    = -2;
  17          public static var FILE_STATUS_ERROR:int            = -3;
  18          public static var FILE_STATUS_SUCCESS:int        = -4;
  19          public static var FILE_STATUS_CANCELLED:int        = -5;
  20          public static var FILE_STATUS_NEW:int            = -6;    // This file status should never be sent to JavaScript

  21          
  22  		public function FileItem(file_reference:FileReference, control_id:String, index:Number)
  23          {
  24              this.postObject = {};
  25              this.file_reference = file_reference;
  26              this.id = control_id + "_" + (FileItem.file_id_sequence++);
  27              this.file_status = FileItem.FILE_STATUS_NEW;
  28              this.index = index;
  29              
  30              this.js_object = {
  31                  id: this.id,
  32                  index: this.index,
  33                  post: this.GetPostObject()
  34              };
  35              
  36              // Cleanly attempt to retrieve the FileReference info

  37              // this can fail and so is wrapped in try..catch

  38              try {
  39                  this.js_object.name = this.file_reference.name;
  40                  this.js_object.size = this.file_reference.size;
  41                  this.js_object.type = this.file_reference.type || "";
  42                  this.js_object.creationdate = this.file_reference.creationDate || new Date(0);
  43                  this.js_object.modificationdate = this.file_reference.modificationDate || new Date(0);
  44              } catch (ex:Error) {
  45                  this.file_status = FileItem.FILE_STATUS_ERROR;
  46              }
  47              
  48              this.js_object.filestatus = this.file_status;
  49          }
  50          
  51  		public function AddParam(name:String, value:String):void {
  52              this.postObject[name] = value;
  53          }
  54          
  55  		public function RemoveParam(name:String):void {
  56              delete this.postObject[name];
  57          }
  58          
  59  		public function GetPostObject(escape:Boolean = false):Object {
  60              if (escape) {
  61                  var escapedPostObject:Object = { };
  62                  for (var k:String in this.postObject) {
  63                      if (this.postObject.hasOwnProperty(k)) {
  64                          var escapedName:String = FileItem.EscapeParamName(k);
  65                          escapedPostObject[escapedName] = this.postObject[k];
  66                      }
  67                  }
  68                  return escapedPostObject;
  69              } else {
  70                  return this.postObject;
  71              }
  72          }
  73          
  74          // Create the simply file object that is passed to the browser

  75  		public function ToJavaScriptObject():Object {
  76              this.js_object.filestatus = this.file_status;
  77              this.js_object.post = this.GetPostObject(true);
  78          
  79              return this.js_object;
  80          }
  81          
  82  		public function toString():String {
  83              return "FileItem - ID: " + this.id;
  84          }
  85          
  86          /*

  87          // The purpose of this function is to escape the property names so when Flash

  88          // passes them back to javascript they can be interpretted correctly.

  89          // ***They have to be unescaped again by JavaScript.**

  90          //

  91          // This works around a bug where Flash sends objects this way:

  92          //        object.parametername = "value";

  93          // instead of

  94          //        object["parametername"] = "value";

  95          // This can be a problem if the parameter name has characters that are not

  96          // allowed in JavaScript identifiers:

  97          //         object.parameter.name! = "value";

  98          // does not work but,

  99          //        object["parameter.name!"] = "value";

 100          // would have worked.

 101          */
 102  		public static function EscapeParamName(name:String):String {
 103              name = name.replace(/[^a-z0-9_]/gi, FileItem.EscapeCharacter);
 104              name = name.replace(/^[0-9]/, FileItem.EscapeCharacter);
 105              return name;
 106          }
 107  		public static function EscapeCharacter():String {
 108              return "$" + ("0000" + arguments[0].charCodeAt(0).toString(16)).substr(-4, 4);
 109          }
 110          
 111      }
 112  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7