source: main/trunk/greenstone3/web/interfaces/default/transform/javascript-global-setup.xsl@ 38256

Last change on this file since 38256 was 38256, checked in by anupama, 8 months ago

Untested. Committing changes for bypassing webswing authentication when already logged in to greenstone.

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