/openshift/adei

To get this branch, use:
bzr branch http://darksoft.org/webbzr/openshift/adei

« back to all changes in this revision

Viewing changes to js/xslpool.js

  • Committer: Suren A. Chilingaryan
  • Date: 2008-12-06 01:38:28 UTC
  • Revision ID: csa@dside.dyndns.org-20081206013828-lm3jqpc4fizd6cn7
XML+XSLT modules support, Alarms support in frontend (mozilla only)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
function XSLPOOL(cache) {
 
2
    if (typeof cache == "undefined") this.use_cache = false;
 
3
    this.use_cache = cache;
 
4
    
 
5
    this.cache = new Array();
 
6
}
 
7
 
 
8
XSLPOOL.prototype.ProcessXML = function(xmldoc, attr, error) {
 
9
    if (!xmldoc) {
 
10
        if (attr.handler) attr.handler(null, attr.attr, error);
 
11
        else adei.ReportError(error);
 
12
        return;
 
13
    }
 
14
    
 
15
    if (attr.handler) {
 
16
        var htmldoc = xsltApply(attr.xsltdoc, xmldoc);
 
17
        attr.handler(htmldoc, attr.attr);
 
18
    } else {
 
19
        xsltApply(attr.xsltdoc, xmldoc, attr.attr);
 
20
    }
 
21
}
 
22
 
 
23
XSLPOOL.prototype.ApplyXSLT = function(xsltdoc, xmlurl, handler, attr) {
 
24
    var xattr = new Object;
 
25
 
 
26
    xattr.self = this;
 
27
    xattr.handler = handler;
 
28
    xattr.attr = attr;
 
29
    xattr.xsltdoc = xsltdoc;
 
30
    
 
31
    if (typeof xmlurl == "object") {
 
32
        this.ProcessXML(xmlurl, xattr);
 
33
    } else {
 
34
        loadXML(xmlurl, 
 
35
            function (xmldoc, attr, error) { 
 
36
                attr.self.ProcessXML(xmldoc, attr, error)
 
37
            }, xattr);
 
38
    }
 
39
}
 
40
 
 
41
XSLPOOL.prototype.ProcessXSLT = function(xsltdoc, attr) {
 
42
    if (this.use_cache) {
 
43
        this.cache[attr.xslt] = xsltdoc;
 
44
    }
 
45
    
 
46
    return this.ApplyXSLT(xsltdoc, attr.xmlurl, attr.handler, attr.attr);
 
47
}
 
48
 
 
49
XSLPOOL.prototype.Load = function(xslt, xmlurl, handler, attr) {
 
50
    if (typeof this.cache[xslt] != "undefined") {
 
51
        return this.ApplyXSLT(this.cache[xslt], xmlurl, handler, attr);
 
52
    }
 
53
    
 
54
    var xattr = new Object;
 
55
    xattr.self = this;
 
56
    xattr.handler = handler;
 
57
    xattr.attr = attr;
 
58
    xattr.xslt = xslt;
 
59
    xattr.xmlurl = xmlurl;
 
60
    
 
61
    loadXSLT("xslt/" + xslt + ".xsl", 
 
62
        function (xsltdoc, self) { xattr.self.ProcessXSLT(xsltdoc, xattr) }, 
 
63
        xattr
 
64
    );
 
65
 
 
66
}