hls_parameters_load.lsc 2.13 KB
Newer Older
Spencer Chang's avatar
Spencer Chang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
<?xml version="1.0" encoding="UTF-8"?>
<a:service xmlns:s="leaf.plugin.script" xmlns:a="http://www.leaf-framework.org/application" xmlns:p="uncertain.proc" trace="true">
    <a:init-procedure>
        <s:server-script><![CDATA[
            var para = $ctx.current_parameter || $ctx.parameter;
            var validation_sql;
            if (para.url) {
                var url = decodeURIComponent(para.url);
                var matches = url.match(/validation_sql=([^&]*)&?(.*$)/);
                validation_sql = matches[1];
                var para_list = {};
                if (matches[2]) {
                    var paras = matches[2].split('&');
                    for (var i = 0;i < paras.length;i++) {
                        var p = paras[i].split('=');
                        para_list[p[0]] = p[1];
                    }
                }
                validation_sql = validation_sql.replace(/\$\{@([^\}]*)\}/g, function(a, b) {
                    return "'" + (para_list[b] || '') + "'";
                });
            } else if (para.validation_sql) {
                validation_sql = para.validation_sql;
                validation_sql = validation_sql.replace(/\$\{@([^\}]*)\}/g, function(a, b) {
                    return "'" + (para[b] || '') + "'";
                });
            }
            validation_sql = validation_sql.replace(/\$\{\/session\/@([^\}]*)\}/g, function(a, b) {
                return "'" + $ctx.session[b] + "'";
            });
            var dsf = $instance('leaf.database.service.IDatabaseServiceFactory');
            var conn = dsf.getDataSource().getConnection();
            var stmt = conn.createStatement();
            var rs = stmt.executeQuery(validation_sql);
            var rsmd = rs.getMetaData();
            var count = rsmd.getColumnCount();
            for (var i = 1;i <= count;i++) {
                var fname = rsmd.getColumnName(i);
                var r = para.createChild("record");
                r.name = String(fname);
            }
            stmt.close();
            conn.close();
        ]]></s:server-script>
    </a:init-procedure>
    <a:service-output output="/parameter"/>
</a:service>