root/main/trunk/greenstone3/web/interfaces/default/transform/javascript-global-setup.xsl @ 33040

Revision 33040, 14.1 KB (checked in by kjdon, 17 months ago)

add the new utility scripts into global header - for escaping unsafe chars

  • 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            gs.requestInformation = new Array();
20        </script>
21        <xsl:call-template name="populate-cgi-param-values"/>
22        <xsl:call-template name="populate-xslt-param-values"/>
23        <xsl:call-template name="populate-image-url-values"/>
24        <xsl:call-template name="populate-metadata-values"/>
25        <xsl:call-template name="populate-request-information-values"/>
26        <xsl:call-template name="populate-user-information-values"/>
27        <xsl:call-template name="include-global-javascript-functions"/>
28    </xsl:template>
29   
30    <xsl:template name="populate-cgi-param-values">
31        <script type="text/javascript">
32            var name;
33            var value;
34            <xsl:for-each select="/page/pageRequest/paramList/param">
35                <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
36                <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of select="util:escapeNewLinesAndQuotes(@value)"/><xsl:text disable-output-escaping="yes">";</xsl:text>
37                <xsl:text disable-output-escaping="yes">name = name.replace(".", "_");</xsl:text>
38                gs.cgiParams[name] = value;
39            </xsl:for-each>
40        </script>
41    </xsl:template>
42   
43    <xsl:template name="populate-xslt-param-values">
44        <script type="text/javascript">
45            <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>
46            <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>
47            <xsl:text disable-output-escaping="yes">gs.xsltParams.site_name = "</xsl:text><xsl:value-of select="$site_name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
48            <xsl:text disable-output-escaping="yes">gs.xsltParams.use_client_side_xslt = "</xsl:text><xsl:value-of select="$use_client_side_xslt"/><xsl:text disable-output-escaping="yes">";</xsl:text>
49            <xsl:text disable-output-escaping="yes">gs.xsltParams.filepath = "</xsl:text><xsl:value-of select="$filepath"/><xsl:text disable-output-escaping="yes">";</xsl:text>
50        </script>
51    </xsl:template>
52   
53    <xsl:template name="populate-metadata-values">
54        <script type="text/javascript">
55            <xsl:text disable-output-escaping="yes">
56                function addMetadataToList(name, value, list, lang)
57                {
58                    name = name.replace(".", "_");
59                    if(lang == "" || lang == "en")
60                    {
61                        list[name] = value;
62                    }
63                    else
64                    {
65                        if (list[lang] == undefined)
66                        {
67                            list[lang] = new Array();
68                        }
69                        var langList = list[lang];
70                        langList[name] = value;
71                    }
72                }
73                var name;
74                var value;
75                var lang;
76            </xsl:text>
77            <xsl:for-each select="/page/pageResponse/metadataList/metadata">
78                <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
79                <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of disable-output-escaping="yes" select="util:escapeNewLinesAndQuotes(.)"/><xsl:text disable-output-escaping="yes">";</xsl:text>
80                <xsl:text disable-output-escaping="yes">lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
81                addMetadataToList(name, value, gs.siteMetadata, lang);
82            </xsl:for-each>
83       
84            <xsl:for-each select="/page/pageResponse/collection/metadataList/metadata">
85                <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
86                <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of disable-output-escaping="yes" select="util:escapeNewLinesAndQuotes(.)"/><xsl:text disable-output-escaping="yes">";</xsl:text>
87                <xsl:text disable-output-escaping="yes">lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
88                addMetadataToList(name, value, gs.collectionMetadata, lang);
89            </xsl:for-each>
90       
91            <xsl:for-each select="/page/pageResponse/document/metadataList/metadata">
92                <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
93                <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of disable-output-escaping="yes" select="util:escapeNewLinesAndQuotes(.)"/><xsl:text disable-output-escaping="yes">";</xsl:text>
94                <xsl:text disable-output-escaping="yes">lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
95                addMetadataToList(name, value, gs.documentMetadata, lang);
96            </xsl:for-each>
97           
98            <xsl:for-each select="/page/pageResponse/classifier/documentNode">
99                {
100                <xsl:text disable-output-escaping="yes">var nodeID = "</xsl:text><xsl:value-of select="@nodeID"/><xsl:text disable-output-escaping="yes">";</xsl:text>
101                <xsl:text disable-output-escaping="yes">var emptyLang = "";</xsl:text>
102                <xsl:text disable-output-escaping="yes">var metaList = new Array();</xsl:text>
103                <xsl:for-each select="metadataList/metadata">
104                    <xsl:text disable-output-escaping="yes">name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
105                    <xsl:text disable-output-escaping="yes">value = "</xsl:text><xsl:value-of disable-output-escaping="yes" select="util:escapeNewLinesAndQuotes(.)"/><xsl:text disable-output-escaping="yes">";</xsl:text>
106                    <xsl:text disable-output-escaping="yes">lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
107                    addMetadataToList(name, value, metaList, lang);
108                </xsl:for-each>
109                addMetadataToList(nodeID, metaList, gs.documentMetadata, emptyLang);
110                }
111            </xsl:for-each>
112           
113            <xsl:text disable-output-escaping="yes">addMetadataToList("docType", "</xsl:text><xsl:value-of select="/page/pageResponse/document/@docType"/><xsl:text disable-output-escaping="yes">", gs.documentMetadata, "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">");</xsl:text>
114        </script>
115    </xsl:template>
116   
117    <xsl:template name="populate-image-url-values">
118        <script type="text/javascript">
119            <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>
120            <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>
121            <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>
122            <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>
123            <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>
124            <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>
125            <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>
126            <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>
127            <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>
128            <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>
129            <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>
130            <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>
131            <xsl:text disable-output-escaping="yes">gs.imageURLs.next = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'next_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
132            <xsl:text disable-output-escaping="yes">gs.imageURLs.prev = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'prev_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
133            <xsl:text disable-output-escaping="yes">gs.imageURLs.trashEmpty = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'trash_empty_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
134            <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>
135            <xsl:text disable-output-escaping="yes">gs.imageURLs.greenBug = "</xsl:text><xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'green_bug_image')"/><xsl:text disable-output-escaping="yes">";</xsl:text>
136        </script>
137    </xsl:template>
138   
139    <xsl:template name="populate-request-information-values">
140        <script type="text/javascript">
141            <xsl:text disable-output-escaping="yes">
142                gs.requestInformation.fullURL = "</xsl:text><xsl:value-of select="/page/pageRequest/@fullURL"/><xsl:text disable-output-escaping="yes">";
143            </xsl:text>
144        </script>
145    </xsl:template>
146   
147    <xsl:template name="populate-user-information-values">
148        <xsl:if test="/page/pageRequest/userInformation">
149            <script type="text/javascript">
150                <xsl:text disable-output-escaping="yes">
151                    gs.userInformation = new Array();
152                    gs.userInformation.username = "</xsl:text><xsl:value-of select="/page/pageRequest/userInformation/@username"/><xsl:text disable-output-escaping="yes">";
153                    gs.userInformation.groups = "</xsl:text><xsl:value-of select="/page/pageRequest/userInformation/@groups"/><xsl:text disable-output-escaping="yes">";
154                    gs.userInformation.editEnabled = "</xsl:text><xsl:value-of select="/page/pageRequest/userInformation/@editEnabled"/><xsl:text disable-output-escaping="yes">";
155                </xsl:text>
156            </script>
157        </xsl:if>
158    </xsl:template>
159   
160    <xsl:template name="include-global-javascript-functions">
161        <script type="text/javascript" src="interfaces/default/js/javascript-global-functions.js"><xsl:text> </xsl:text></script>
162        <script type="text/javascript" src="interfaces/default/js/GSMetadata.js"><xsl:text> </xsl:text></script>
163        <script type="text/javascript" src="interfaces/{$interface_name}/js/utility_scripts.js"><xsl:text> </xsl:text></script>
164
165    </xsl:template>
166</xsl:stylesheet>
167
168    <!-- CAN WE FIND SOME WAY TO MAKE THIS WORK?
169    <xsl:call-template name="populate-metadata-values">
170        <xsl:with-param name="path">/page/pageResponse/metadataList/metadata</xsl:with-param>
171        <xsl:with-param name="metadataListName">siteMetadata</xsl:with-param>
172    </xsl:call-template>
173   
174    <xsl:call-template name="populate-metadata-values">
175        <xsl:with-param name="path">/page/pageResponse/collection/metadataList/metadata</xsl:with-param>
176        <xsl:with-param name="metadataListName">collectionMetadata</xsl:with-param>
177    </xsl:call-template>
178   
179    <xsl:call-template name="populate-metadata-values">
180        <xsl:with-param name="path">/page/pageResponse/document/metadataList/metadata</xsl:with-param>
181        <xsl:with-param name="metadataListName">documentMetadata</xsl:with-param>
182    </xsl:call-template>
183    -->
184
185    <!-- NOT WORKING BUT IT WOULD BE TIDIER IF IT DID
186    <xsl:template name="populate-metadata-values">
187        <xsl:param name="path"/>
188        <xsl:param name="metadataListName"/>
189       
190        <xsl:for-each select="$path">
191            <script type="text/javascript">
192                <xsl:text disable-output-escaping="yes">var name = "</xsl:text><xsl:value-of select="@name"/><xsl:text disable-output-escaping="yes">";</xsl:text>
193                <xsl:text disable-output-escaping="yes">var value = "</xsl:text><xsl:value-of select="."/><xsl:text disable-output-escaping="yes">";</xsl:text>
194                <xsl:text disable-output-escaping="yes">var lang = "</xsl:text><xsl:value-of select="@lang"/><xsl:text disable-output-escaping="yes">";</xsl:text>
195                <xsl:text disable-output-escaping="yes">var metadataListName = "</xsl:text><xsl:value-of select="$metadataListName"/><xsl:text disable-output-escaping="yes">";</xsl:text>
196                var list = gs[metadataListName];
197                if(lang == "")
198                {
199                    list[name] = value;
200                }
201                else
202                {
203                    if (list[lang] == undefined)
204                    {
205                        list[lang] = new Array();
206                    }
207                    var langList = list[lang];
208                    langList[name] = value;
209                }
210            </script>
211        </xsl:for-each>
212    </xsl:template>
213    -->
Note: See TracBrowser for help on using the browser.