From 371a806dd929003a828dc2c9fb21acc377958b05 Mon Sep 17 00:00:00 2001
From: pho <pho@cielonegro.org>
Date: Mon, 11 Feb 2008 14:37:52 +0900
Subject: [PATCH] Rakka.getSystemConfig()

darcs-hash:20080211053752-62b54-821f26c4b38fcb26572fc9a7a1fb96530281fd7f.gz
---
 js/Makefile        |  1 +
 js/systemConfig.js | 61 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)
 create mode 100644 js/systemConfig.js

diff --git a/js/Makefile b/js/Makefile
index 637f7d1..00a7704 100644
--- a/js/Makefile
+++ b/js/Makefile
@@ -12,6 +12,7 @@ SOURCES = \
 	redirection.js \
 	screen.js \
 	search.js \
+	systemConfig.js \
 	uri.js \
 	$(NULL)
 
diff --git a/js/systemConfig.js b/js/systemConfig.js
new file mode 100644
index 0000000..cb46670
--- /dev/null
+++ b/js/systemConfig.js
@@ -0,0 +1,61 @@
+(function () {
+
+    var identityDecoder = function (src) {
+        return src;
+    };
+
+    var mapDecoder = function (src) {
+        var map   = {};
+        var lines = src.split(/\n/);
+        
+        $.each(lines, function () {
+            var m = this.match(/^(\S+)\s+(\S+)$/);
+
+            map[ m[1] ] = m[2];
+        });
+
+        return map;
+    };
+
+    var boolDecoder = function (src) {
+        return src == "*";
+    };
+
+    var decoder_of = {
+        siteName   : identityDecoder,
+        baseURI    : identityDecoder,
+        defaultPage: identityDecoder,
+        styleSheet : identityDecoder,
+        languages  : mapDecoder,
+        globalLock : boolDecoder
+    };
+
+    Rakka.getSystemConfig = function () {
+        var conf = {};
+        
+        $.ajax({
+            type   : "GET",
+            url    : Rakka.baseURI + "systemConfig",
+            async  : false,
+            success: function (xml) {
+                $(xml).find("value").each(function () {
+                    var path    = this.getAttribute("path");
+                    var decoder = decoder_of[path];
+
+                    if (decoder == null) {
+                        throw new Error("unknown config path: " + path);
+                    }
+                    else {
+                        conf[path] = decoder($(this).text());
+                    }
+                });
+            },
+            error  : function (req) {
+                throw new Error(req.status + " " + req.statusText);
+            }
+        });
+
+        return conf;
+    };
+
+})();
\ No newline at end of file
-- 
2.40.0