Remove the external oauth-get-signing. Only XMLConnection should be fetching things...
[potlatch2.git] / net / systemeD / potlatch2 / utils / Importer.as
index 4bf94fc77fb0939fb8da3787fda11b2013175f31..056457e3b40a4922fed11e398721d8e641e467e3 100644 (file)
@@ -1,7 +1,10 @@
 package net.systemeD.potlatch2.utils {
 
-       import net.systemeD.halcyon.Map;
+       import net.systemeD.halcyon.MapPaint;
        import net.systemeD.halcyon.ExtendedURLLoader;
+       import net.systemeD.halcyon.DebugURLRequest;
+    import net.systemeD.halcyon.connection.*;
+       import flash.net.URLLoader;
        import flash.display.LoaderInfo;
        import flash.events.*;
        import flash.net.*;
@@ -10,28 +13,38 @@ package net.systemeD.potlatch2.utils {
 
        public class Importer {
 
-               protected var map:Map;
-               protected var files:Array=[];
+               protected var container:Object;                         // destination object for way/node/relations data
+               protected var paint:MapPaint;                           // destination sprite for WayUIs/NodeUIs
+
+               public var files:Array=[];
                protected var filenames:Array;
                protected var filesloaded:uint=0;
+               protected var callback:Function;
+               protected var simplify:Boolean;
 
-               public function Importer(map:Map, filenames:Array) {
+               public function Importer(container:*, paint:MapPaint, filenames:Array, callback:Function, simplify:Boolean) {
                        Globals.vars.root.addDebug("starting importer"); 
-                       this.map = map;
+                       Globals.vars.root.addDebug("container is "+container);
+                       Globals.vars.root.addDebug("paint is "+paint);
+                       this.container = container;
+                       this.paint = paint;
                        this.filenames=filenames;
+                       this.callback=callback;
+                       this.simplify=simplify;
 
                        var sp:uint=0;
                        for each (var fn:String in filenames) {
-                               Globals.vars.root.addDebug("requesting file "+fn); 
-
+                               Globals.vars.root.addDebug("requesting file "+fn);
+                               var request:DebugURLRequest = new DebugURLRequest(fn);
                                var loader:ExtendedURLLoader = new ExtendedURLLoader();
                                loader.info['file']=sp;
                                loader.dataFormat=URLLoaderDataFormat.BINARY;
-                               loader.addEventListener(Event.COMPLETE,                                         fileLoaded,                             false, 0, true);
-                               loader.addEventListener(HTTPStatusEvent.HTTP_STATUS,            httpStatusHandler,              false, 0, true);
-                               loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,      securityErrorHandler,   false, 0, true);
-                               loader.addEventListener(IOErrorEvent.IO_ERROR,                          ioErrorHandler,                 false, 0, true);
-                               loader.load(new URLRequest(fn));
+                               loader.addEventListener(Event.COMPLETE,fileLoaded);
+                               if (callback!=null) {
+                                       loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,      securityErrorHandler);
+                                       loader.addEventListener(IOErrorEvent.IO_ERROR,                          ioErrorHandler);
+                               }
+                               loader.load(request.request);
                                sp++;
                        }
                }
@@ -40,14 +53,18 @@ package net.systemeD.potlatch2.utils {
                        Globals.vars.root.addDebug("loaded file "+e.target.info['file']); 
                        files[e.target.info['file']]=e.target.data;
                        filesloaded++;
-                       if (filesloaded==filenames.length) { doImport(); }
+                       if (filesloaded==filenames.length) { 
+                               doImport();
+                               paint.updateEntityUIs(container.getObjectsByBbox(paint.map.edge_l, paint.map.edge_r, paint.map.edge_t, paint.map.edge_b), false, false);
+                               if (callback!=null) { callback(true); }
+                       }
                }
                
-               protected function doImport():void { }
+               protected function doImport():void {
+               }
 
-               protected function httpStatusHandler( event:HTTPStatusEvent ):void { }
-               protected function securityErrorHandler( event:SecurityErrorEvent ):void { Globals.vars.root.addDebug("securityerrorevent"); }
-               protected function ioErrorHandler( event:IOErrorEvent ):void { Globals.vars.root.addDebug("ioerrorevent"); }
+               protected function securityErrorHandler( event:SecurityErrorEvent ):void { callback(false,"You don't have permission to open that file."); }
+               protected function ioErrorHandler( event:IOErrorEvent ):void { callback(false,"The file could not be loaded."); }
 
        }
 }