resources/RooUsage.txt
[app.Builder.js] / src / Builder4 / FakeServer.vala
index 8b4bbbd..b788213 100644 (file)
@@ -29,12 +29,17 @@ public class FakeServerCache : Object
         
        public static Gee.HashMap<string,FakeServerCache> cache;
        
-       public static FakeServerCache factory(string fname)
+       public static FakeServerCache factory(string fname, string scheme)
        {
                if (cache == null) {
                        cache = new Gee.HashMap<string,FakeServerCache>();
                }
+               
           // print ("CACHE look for ==%s==\n", fname);
+           if (scheme == "resources") {
+                       return new FakeServerCache.from_resource(fname);
+               }
+           
            if (cache.has_key(fname)) {
                        print ("CACHE got  %s\n", fname);
                        return cache.get(fname);
@@ -81,6 +86,9 @@ public class FakeServerCache : Object
                return el;
        }
     
+    
+    
+    
        public FakeServerCache.with_data( string data )
        {
                this.fname = "/" + GLib.Checksum.compute_for_string(GLib.ChecksumType.MD5, data, data.length) + ".js";
@@ -90,7 +98,43 @@ public class FakeServerCache : Object
         
          
        }
+       public FakeServerCache.from_resource( string fname )
+       {
+               
+               
+               
+               this.fname = fname;
+               
+               var  file = File.new_for_path ( BuilderApplication.configDirectory() + "/resources/" + fname);
+               if (!file.query_exists()) {
+                       this.data = "".data;
+                       this.content_type = "";
+                       this.size = 0;
+                       return;
+               }
+               try {
+                   var info = file.query_info(
+                                    "standard::*",
+                                   FileQueryInfoFlags.NONE
+                   );
+               
+                   this.content_type = info.get_content_type();
+                   this.size = info.get_size();
+                   uint8[] data;
+                    
+                    
+                   GLib.FileUtils.get_data(file.get_path(), out data);
+                   this.data = data;
+               } catch (Error e) {
+                       this.data = "".data;
+                       this.size = 0;
+                       this.content_type = "";
+                       return;
+               }
+               
 
+         
+       }
        public FakeServerCache( string fname ) {
               
                this.fname = fname;
@@ -102,16 +146,18 @@ public class FakeServerCache : Object
                        this.size = 0;
                        return;
                }
-               var info = file.query_info(
-                                "standard::*",
-                               FileQueryInfoFlags.NONE
-               );
-               this.content_type = info.get_content_type();
-               this.size = info.get_size();
-               uint8[] data;
-               size_t length;
                try { 
-                       GLib.FileUtils.get_data(file.get_path(), out data);
+                   var info = file.query_info(
+                                    "standard::*",
+                                   FileQueryInfoFlags.NONE
+                   );
+                   this.content_type = info.get_content_type();
+                   this.size = info.get_size();
+                   uint8[] data;
+       
+                   GLib.FileUtils.get_data(file.get_path(), out data);
+                   this.data = data;
                } catch (Error e) {
                        this.data = "".data;
                        this.size = 0;
@@ -119,7 +165,7 @@ public class FakeServerCache : Object
                        return;
                }
 
-               this.data = data;
+               
 
                print("FakeServerCache :%s, %s (%s/%d)\n", fname , 
                        this.content_type, this.size.to_string(), this.data.length);
@@ -158,6 +204,7 @@ public class FakeServer : Object
                var cx = WebKit.WebContext.get_default();
                //var cx = this.view.get_context();
                cx.register_uri_scheme("xhttp",  serve);
+               cx.register_uri_scheme("resources",  serve);
                cx.set_cache_model (WebKit.CacheModel.DOCUMENT_VIEWER);
 
                // these do not help for cross domain requests..