From: pho Date: Mon, 11 Feb 2008 05:37:52 +0000 (+0900) Subject: Rakka.getSystemConfig() X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Rakka.git;a=commitdiff_plain;h=371a806dd929003a828dc2c9fb21acc377958b05 Rakka.getSystemConfig() darcs-hash:20080211053752-62b54-821f26c4b38fcb26572fc9a7a1fb96530281fd7f.gz --- 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