root/main/trunk/greenstone3/web/interfaces/oran/transform/javascript-global-setup.xsl @ 24929

Revision 24929, 9.6 KB (checked in by sjm84, 8 years ago)

CGI parameters will now have any newlines escaped

  • Property svn:executable set to *
Line 
1<xsl:stylesheet version="1.0"
2    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3    xmlns:java="http://xml.apache.org/xslt/java"
4    xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
5    xmlns:gslib="http://www.greenstone.org/skinning"
6    extension-element-prefixes="java util"
7    exclude-result-prefixes="java util">
8   
9    <xsl:template name="setup-gs-variable">
10        <script type="text/javascript">
11            gs = new Array();
12            gs.cgiParams = new Array();
13            gs.xsltParams = new Array();
14            gs.siteMetadata = new Array();
15            gs.collectionMetadata = new Array();
16            gs.documentMetadata = new Array();
17            gs.imageURLs = new Array();
18            gs.variables = new Array();
19        </script>
20        <xsl:call-template name="populate-cgi-param-values"/>
21        <xsl:call-template name="populate-xslt-param-values"/>
22        <xsl:call-template name="populate-image-url-values"/>
23        <xsl:call-template name="populate-metadata-values"/>
24        <xsl:call-template name="include-global-javascript-functions"/>
25    </xsl:template>
26   
27    <xsl:template name="populate-cgi-param-values">
28        <script type="text/javascript">
29            var name;
30            var value;
31            <xsl:for-each select="/page/pageRequest/paramList/param">
32                <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
33                <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of select="util:escapeNewLines(@value)"/><xsl:text disable-output-escaping="yes">";</xsl:text>
34                <xsl:text disable-output-escaping="yes">name = name.replace(".", "_");</xsl:text>
35                gs.cgiParams[name] = value;
36            </xsl:for-each>
37        </script>
38    </xsl:template>
39   
40    <xsl:template name="populate-xslt-param-values">
41        <script type="text/javascript">
42            <xsl:text disable-output-escaping="yes">gs.xsltParams.library_name = "</xsl:text><xsl:value-of select="$library_name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
43            <xsl:text disable-output-escaping="yes">gs.xsltParams.interface_name = "</xsl:text><xsl:value-of select="$interface_name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
44        </script>
45    </xsl:template>
46   
47    <xsl:template name="populate-metadata-values">
48        <script type="text/javascript">
49            <xsl:text disable-output-escaping="yes">
50                function addMetadataToList(name, value, list, lang)
51                {
52                    name = name.replace(".", "_");
53                    if(lang == "" || lang == "en")
54                    {
55                        list[name] = value;
56                    }
57                    else
58                    {
59                        if (list[lang] == undefined)
60                        {
61                            list[lang] = new Array();
62                        }
63                        var langList = list[lang];
64                        langList[name] = value;
65                    }
66                }
67                var name;
68                var value;
69                var lang;
70            </xsl:text>
71            <xsl:for-each select="/page/pageResponse/metadataList/metadata">
72                <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
73                <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of disable-output-escaping="yes" select="."/><xsl:text disable-output-escaping="yes">";</xsl:text>
74                <xsl:text disable-output-escaping="yes">lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
75                addMetadataToList(name, value, gs.siteMetadata, lang);
76            </xsl:for-each>
77       
78            <xsl:for-each select="/page/pageResponse/collection/metadataList/metadata">
79                <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
80                <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of disable-output-escaping="yes" select="."/><xsl:text disable-output-escaping="yes">";</xsl:text>
81                <xsl:text disable-output-escaping="yes">lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
82                addMetadataToList(name, value, gs.collectionMetadata, lang);
83            </xsl:for-each>
84       
85            <xsl:for-each select="/page/pageResponse/document/metadataList/metadata">
86                <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
87                <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of disable-output-escaping="yes" select="."/><xsl:text disable-output-escaping="yes">";</xsl:text>
88                <xsl:text disable-output-escaping="yes">lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
89                addMetadataToList(name, value, gs.documentMetadata, lang);
90            </xsl:for-each>
91        </script>
92    </xsl:template>
93   
94    <xsl:template name="populate-image-url-values">
95        <script type="text/javascript">
96            <xsl:text disable-output-escaping="yes">gs.imageURLs.expand = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'expand_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
97            <xsl:text disable-output-escaping="yes">gs.imageURLs.collapse = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'collapse_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
98            <xsl:text disable-output-escaping="yes">gs.imageURLs.page = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'page_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
99            <xsl:text disable-output-escaping="yes">gs.imageURLs.chapter = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'chapter_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
100            <xsl:text disable-output-escaping="yes">gs.imageURLs.realisticBook = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'realistic_books_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
101            <xsl:text disable-output-escaping="yes">gs.imageURLs.highlight = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'highlight_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
102            <xsl:text disable-output-escaping="yes">gs.imageURLs.bookshelf = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'bookshelf_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
103            <xsl:text disable-output-escaping="yes">gs.imageURLs.book = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'book_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
104            <xsl:text disable-output-escaping="yes">gs.imageURLs.loading = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'loading_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
105            <xsl:text disable-output-escaping="yes">gs.imageURLs.pageIcon = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'page_icon_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
106            <xsl:text disable-output-escaping="yes">gs.imageURLs.trashFull = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'trash_full_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
107            <xsl:text disable-output-escaping="yes">gs.imageURLs.blank = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'blank_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
108        </script>
109    </xsl:template>
110   
111    <xsl:template name="include-global-javascript-functions">
112        <script type="text/javascript" src="interfaces/oran/js/javascript-global-functions.js"><xsl:text> </xsl:text></script>
113    </xsl:template>
114</xsl:stylesheet>
115
116    <!--
117    USEFUL FOR TESTING ASSOCIATIVE ARRAYS
118    function getKeys(obj)
119    {
120        var keys = [];
121        for(var key in obj)
122        {
123            keys.push(key);
124        }
125        return keys;
126    }
127    -->
128
129    <!-- CAN WE FIND SOME WAY TO MAKE THIS WORK?
130    <xsl:call-template name="populate-metadata-values">
131        <xsl:with-param name="path">/page/pageResponse/metadataList/metadata</xsl:with-param>
132        <xsl:with-param name="metadataListName">siteMetadata</xsl:with-param>
133    </xsl:call-template>
134   
135    <xsl:call-template name="populate-metadata-values">
136        <xsl:with-param name="path">/page/pageResponse/collection/metadataList/metadata</xsl:with-param>
137        <xsl:with-param name="metadataListName">collectionMetadata</xsl:with-param>
138    </xsl:call-template>
139   
140    <xsl:call-template name="populate-metadata-values">
141        <xsl:with-param name="path">/page/pageResponse/document/metadataList/metadata</xsl:with-param>
142        <xsl:with-param name="metadataListName">documentMetadata</xsl:with-param>
143    </xsl:call-template>
144    -->
145
146    <!-- NOT WORKING BUT IT WOULD BE TIDIER IF IT DID
147    <xsl:template name="populate-metadata-values">
148        <xsl:param name="path"/>
149        <xsl:param name="metadataListName"/>
150       
151        <xsl:for-each select="$path">
152            <script type="text/javascript">
153                <xsl:text disable-output-escaping="yes">var name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
154                <xsl:text disable-output-escaping="yes">var value = "</xsl:text><xsl:value-of select="."/><xsl:text disable-output-escaping="yes">";</xsl:text>
155                <xsl:text disable-output-escaping="yes">var lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
156                <xsl:text disable-output-escaping="yes">var metadataListName = "</xsl:text><xsl:value-of select="$metadataListName"/><xsl:text disable-output-escaping="yes">";</xsl:text>
157                var list = gs[metadataListName];
158                if(lang == "")
159                {
160                    list[name] = value;
161                }
162                else
163                {
164                    if (list[lang] == undefined)
165                    {
166                        list[lang] = new Array();
167                    }
168                    var langList = list[lang];
169                    langList[name] = value;
170                }
171            </script>
172        </xsl:for-each>
173    </xsl:template>
174    -->
Note: See TracBrowser for help on using the browser.