Remove the external oauth-get-signing. Only XMLConnection should be fetching things...
[potlatch2.git] / net / systemeD / potlatch2 / utils / Importer.as
1 package net.systemeD.potlatch2.utils {
2
3         import net.systemeD.halcyon.MapPaint;
4         import net.systemeD.halcyon.ExtendedURLLoader;
5         import net.systemeD.halcyon.DebugURLRequest;
6     import net.systemeD.halcyon.connection.*;
7         import flash.net.URLLoader;
8         import flash.display.LoaderInfo;
9         import flash.events.*;
10         import flash.net.*;
11
12         import net.systemeD.halcyon.Globals;
13
14         public class Importer {
15
16                 protected var container:Object;                         // destination object for way/node/relations data
17                 protected var paint:MapPaint;                           // destination sprite for WayUIs/NodeUIs
18
19                 public var files:Array=[];
20                 protected var filenames:Array;
21                 protected var filesloaded:uint=0;
22                 protected var callback:Function;
23                 protected var simplify:Boolean;
24
25                 public function Importer(container:*, paint:MapPaint, filenames:Array, callback:Function, simplify:Boolean) {
26                         Globals.vars.root.addDebug("starting importer"); 
27                         Globals.vars.root.addDebug("container is "+container);
28                         Globals.vars.root.addDebug("paint is "+paint);
29                         this.container = container;
30                         this.paint = paint;
31                         this.filenames=filenames;
32                         this.callback=callback;
33                         this.simplify=simplify;
34
35                         var sp:uint=0;
36                         for each (var fn:String in filenames) {
37                                 Globals.vars.root.addDebug("requesting file "+fn);
38                                 var request:DebugURLRequest = new DebugURLRequest(fn);
39                                 var loader:ExtendedURLLoader = new ExtendedURLLoader();
40                                 loader.info['file']=sp;
41                                 loader.dataFormat=URLLoaderDataFormat.BINARY;
42                                 loader.addEventListener(Event.COMPLETE,fileLoaded);
43                                 if (callback!=null) {
44                                         loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,      securityErrorHandler);
45                                         loader.addEventListener(IOErrorEvent.IO_ERROR,                          ioErrorHandler);
46                                 }
47                                 loader.load(request.request);
48                                 sp++;
49                         }
50                 }
51                 
52                 protected function fileLoaded(e:Event):void {
53                         Globals.vars.root.addDebug("loaded file "+e.target.info['file']); 
54                         files[e.target.info['file']]=e.target.data;
55                         filesloaded++;
56                         if (filesloaded==filenames.length) { 
57                                 doImport();
58                                 paint.updateEntityUIs(container.getObjectsByBbox(paint.map.edge_l, paint.map.edge_r, paint.map.edge_t, paint.map.edge_b), false, false);
59                                 if (callback!=null) { callback(true); }
60                         }
61                 }
62                 
63                 protected function doImport():void {
64                 }
65
66                 protected function securityErrorHandler( event:SecurityErrorEvent ):void { callback(false,"You don't have permission to open that file."); }
67                 protected function ioErrorHandler( event:IOErrorEvent ):void { callback(false,"The file could not be loaded."); }
68
69         }
70 }