source: main/trunk/greenstone3/web/interfaces/default/transform/pages/webswing-phind.xsl@ 38945

Last change on this file since 38945 was 38945, checked in by anupama, 8 weeks ago

Committing the GS3 XSL and webswing.config changes to successfully run JPhind as an applet (I've confirmed the updates in the previous commit to the Java and GS3 XSL code have the applet shutdown when the user navigates away from the page). To switch between running JPhind or GsdlCollageApplet as an applet and as an application, we need to make 2 changes: 1. We need to choose between webswing.config.applet and webswing.config.application to be our new webswing.config.in file and copy this from ext/webswing/web/etc into web/ext/webswing/etc/webswing.config.in. 2. In web/interfaces/default/transform/pages/webswing-phind.xsl we need to set var isWebswingRunAsApplet to true if running as an applet or false if running as an application. More commits with improvements to follow: better way of setting webswing parameters using a javascript record, and if there's an applet element for phind on the page, we repeat the behaviour implemented for GsdlCollageApplet: we need to use any applet element on the page as a shim to read in its params to set webswing's arguments (regardless of whether we run it as an actual webswing applet or webswing application).

File size: 14.1 KB
Line 
1<?xml version="1.0" encoding="UTF-8"?>
2<xsl:stylesheet version="1.0"
3 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:java="http://xml.apache.org/xslt/java"
5 xmlns:util="xalan://org.greenstone.gsdl3.util.XSLTUtil"
6 xmlns:gslib="http://www.greenstone.org/skinning"
7 xmlns:gsf="http://www.greenstone.org/greenstone3/schema/ConfigFormat"
8 extension-element-prefixes="java util"
9 exclude-result-prefixes="java util">
10
11 <!-- This page, structurally speaking, is a hybrid of home.xsl and about.xsl -->
12 <!-- Produces a general embedded Phind browser, given the library and collection -->
13
14 <!-- use the 'main' layout -->
15 <xsl:import href="layouts/main.xsl"/>
16
17 <!-- what is this used for??? Can it be deleted? -->
18 <xsl:variable name="groupPath"><xsl:value-of select="/page/pageRequest/paramList/param[@name='group']/@value"/></xsl:variable>
19
20 <!-- set page title -->
21
22 <xsl:template name="pageTitle">WebSwing Phind<!--<gslib:collectionName/><xsl:value-of select="/page/pageResponse/service/applet"/>--></xsl:template>
23
24
25 <!-- set page breadcrumbs -->
26 <xsl:template name="breadcrumbs">
27 <xsl:choose>
28 <xsl:when test="/page/pageRequest/paramList/param[@name='c']/@value != ''">
29 <gslib:siteLink/>
30 <gslib:rightArrow/>
31 <xsl:if test="$groupPath != ''">
32 <gslib:groupLinks/>
33 <gslib:rightArrow/>
34 </xsl:if>
35 <a href="{$library_name}/collection/{$collName}/page/about">
36 <gslib:collectionName/>
37 </a>
38 </xsl:when>
39 <xsl:otherwise>
40 <xsl:choose>
41 <xsl:when test="$groupPath != ''">
42 <a>
43 <xsl:attribute name="href"><gslib:groupHref path="{$groupPath}"/></xsl:attribute>
44 <xsl:attribute name="title"><gslib:groupName path="{$groupPath}"/></xsl:attribute>
45 <gslib:groupName path="{$groupPath}"/>
46 </a>
47 </xsl:when>
48 <xsl:otherwise>
49 <gslib:siteLink/>
50 </xsl:otherwise>
51 </xsl:choose>
52
53 </xsl:otherwise>
54 </xsl:choose>
55 </xsl:template>
56
57
58 <!-- the page content -->
59 <xsl:template match="/page">
60
61 <xsl:choose>
62 <xsl:when test="$this-element/displayItemList/displayItem[@name='icon']">
63 <img border="0">
64 <xsl:attribute name="src"><xsl:value-of select="$this-element/metadataList/metadata[@name='httpPath']"/>/images/<xsl:value-of select="$this-element/displayItemList/displayItem[@name='icon']"/></xsl:attribute>
65 <xsl:attribute name="alt">
66 <xsl:value-of select="$this-element/displayItemList/displayItem[@name='name']"/>
67 </xsl:attribute>
68 <xsl:attribute name="title">
69 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'webswing_phindpage')"/>
70 </xsl:attribute>
71 </img>
72 </xsl:when>
73 </xsl:choose>
74
75 <!--Display the description text of the current collection,
76 and if some services are available then create a list
77 of links for each service within a <ul id="servicelist"> element.-->
78 <xsl:call-template name="webswing-embed-phind"/>
79 </xsl:template>
80
81 <xsl:template name="webswing-embed-phind">
82 <link rel="stylesheet" href="/webswing-server/css/style.css" />
83
84 <div id="webswing-phind" class="webswing-element" data-webswing-instance="webswingInstance0" style="width: 500px; height: 500px;">
85 <div id="loading" class="ws-modal-container">
86 <div class="ws-login">
87 <div class="ws-login-content">
88 <div class="ws-spinner">
89 <div class="ws-spinner-dot-1"><xsl:comment>filler</xsl:comment></div>
90 <div class="ws-spinner-dot-2"><xsl:comment>filler</xsl:comment></div>
91 </div>
92 </div>
93 </div>
94 </div>
95 </div>
96
97 <gsf:script>
98 // https://www.webswing.org/docs/23.2/configure/applet.html
99 // https://www.webswing.org/docs/23.2/configure/swing.html
100 // https://www.webswing.org/docs/23.2/integrate/javascript-api?_h=customArgs%2Cargs#usage-with-customization-and-options
101 // https://www.webswing.org/docs/23.2/integrate/embed.html
102 // https://www.webswing.org/docs/20.1/integrate/urlparams.html
103 // https://www.webswing.org/docs/23.2/integrate/urlparams.html
104 // https://www.webswing.org/docs/20.1/integrate/customize.html
105 // https://www.webswing.org/docs/2.7/integrate/embed.html
106
107 var webswingInstance0 = {
108 options: {
109 autoStart: true,
110 //appletParams: getParam('appletParams'),
111 //appletParams: {"collection":"tudor", "library":"library"},
112 connectionUrl:'/webswing-server/phind',
113
114 customization: function(injector) {
115 injector.services.base.handleActionEvent = function(actionName, data, binaryData) {
116 //console.log("WebSwing actionEvent callback handler: called with actionName = " + actionName);
117
118 if (actionName === "openURL") {
119 var url = data;
120 // check if a target tab/window name has been specified
121 // TODO: Any better way of passing > 1 string between Java and JavaScript?
122 var index = url.indexOf(" - ");
123 if (index !== -1) {
124 var target = url.substring(index+3); // skip past " - " to get target name
125 url = url.substring(0, index);
126 window.open(url, target);
127 } else {
128 window.open(url, '_blank');
129 }
130 } else if (actionName == "javaToWebswingJSConsoleLog") {
131 console.log("Got message from java:\n" + data);
132 }
133
134 }
135 }
136
137
138 }
139 };
140
141
142 // The applet jar files can just remain in web/applet where they are compiled up
143 if(!webswingInstance0.options.args) {
144 webswingInstance0.options.args="";
145 }
146
147 var verbosity = 4;
148 var appletEl = document.querySelector("applet");
149
150 // Set to false if running the webswing instance as a webswing application. This has
151 // nothing to do with if the applet element exists on the page: it can be on the page
152 // and you can still decide to run GsdlCollage as a webswing application. If switching
153 // between running as application and applet, remember to adjust webswing.config.in
154 // If we do push the deprecated applet element onto the page, we can use it as a shim:
155 // use JavaScript to read its params and pass them to webswing as configuration args.
156 //
157 var isWebswingRunAsApplet = true;
158
159
160 if(!appletEl) {
161 if(verbosity >= 4) {
162 console.log("No applet element on page. Reading in from pageResponse/XSLT.");
163 }
164
165 //https://stackoverflow.com/questions/25203124/how-to-get-base-url-with-jquery-or-javascript
166 // dynamic phind arguments
167 var baseURL = window.location.origin+window.location.pathname;
168 var collection = gs.cgiParams.c;
169 var library = gs.xsltParams.library_name;
170
171 // largely static phind arguments
172 var phindcgi = "?a=a&amp;rt=r&amp;s=PhindApplet&amp;o=xml&amp;ro=1";
173 var classifier = 1; // true or false
174 var backdrop = "interfaces/default/images/phindbg1.jpg";
175 var orientation = "vertical";
176 var depth = 2;
177 var resultorder = "L,l,E,e,D,d";
178 var fontsize = 10;
179 var blocksize = 10;
180 }
181
182 // If run as webswing application, we need an extra cmdline arg: the baseURL at the *start*
183 // It is not of key-value form, just the baseURL by itself.
184 if(!isWebswingRunAsApplet) {
185 // webswingInstance0.options.args += "\"" + baseURL+ "?a=a&amp;rt=d&amp;s=PhindApplet&amp;c="+gs.cgiParams.c + "\"";
186 webswingInstance0.options.args += "\"" + baseURL + "\"";
187 }
188
189 webswingInstance0.options.args += " --collection " + collection;
190 webswingInstance0.options.args += " --library " + library;
191
192
193 // The more static params look like
194 //--phindcgi \"?a=a&amp;rt=r&amp;s=PhindApplet&amp;o=xml&amp;ro=1\" --classifier 1 --backdrop interfaces/default/images/phindbg1.jpg --orientation vertical --depth 2 --resultorder \"L,l,E,e,D,d\" --fontsize 10 --blocksize 10
195 webswingInstance0.options.args += " --phindcgi \"" + phindcgi + "\"";
196 webswingInstance0.options.args += " --classifier " + classifier;
197 webswingInstance0.options.args += " --backdrop \"" + backdrop + "\"";
198 webswingInstance0.options.args += " --orientation " + orientation;
199 webswingInstance0.options.args += " --depth " + depth;
200 webswingInstance0.options.args += " --resultorder \"" + resultorder + "\"";
201 webswingInstance0.options.args += " --fontsize " + fontsize;
202 webswingInstance0.options.args += " --blocksize " + blocksize;
203
204
205 // When run as webswing applet (instead of as webswing application), the webswing var
206 // customargs becomes assigned as the value of key "xtraParams" in webswing.config.in
207 // and is a string of key-value pairs. And our Java code is able to successfully
208 // receive these key-valye pairs in the form k1::v1;;k2::v2;; (URL form of key-value
209 // pairs is not easy to pass in from JavaScript through webswing into Java).
210
211 if(isWebswingRunAsApplet) {
212 var xtraParams = webswingInstance0.options.args;
213 var hyphens_index = xtraParams.indexOf("--");
214 var spaceAfterKey = -1;
215 while(hyphens_index >= 0) {
216 // Locate start of value in each key-value pair
217 spaceAfterKey = xtraParams.indexOf(" ", hyphens_index);
218 if(spaceAfterKey >= 0) {
219 // insert (splice in) the key-value internal separator,creating "key::value"
220 xtraParams = [xtraParams.slice(0, spaceAfterKey), "::", xtraParams.slice(spaceAfterKey+1)].join('');
221 }
222 hyphens_index = xtraParams.indexOf("--", hyphens_index+2);
223 }
224 // now add separator *between* each key-value pairs with ;;
225 xtraParams = xtraParams.replaceAll(" --", ";;");
226 webswingInstance0.options.args = xtraParams.substring(2);
227 }
228
229 if(verbosity >= 4) {
230 console.log("args: " + webswingInstance0.options.args);
231 }
232
233 /*
234 // Not yet working. Stick ${customArgs} at end of final param Value (BEFORE the closing double quote of the value) in webswing.config.in
235 // The applet jar files can just remain in web/applet where they are compiled up
236 if(!webswingInstance0.options.args) {
237 webswingInstance0.options.args="";
238 }
239 if (gs.cgiParams.c) {
240 webswingInstance0.options.args += ", -Dwebswing.appletParam_collection=" + gs.cgiParams.c;
241 }
242 webswingInstance0.options.args += ", -Dwebswing.appletParam_library=";
243 webswingInstance0.options.args+=(gs.xsltParams.library_name)?gs.xsltParams.library_name:"library";
244
245 console.log("args: " + webswingInstance0.options.args);
246 */
247
248 /*
249 if(!webswingInstance0.options.appletParams) {
250 webswingInstance0.options.appletParams={};
251 }
252 if (gs.cgiParams.c) {
253 webswingInstance0.options.appletParams["collection"] = gs.cgiParams.c;
254 }
255 webswingInstance0.options.appletParams["library"] = (gs.xsltParams.library_name) ? gs.xsltParams.library_name : "library";
256 */
257 /*
258 if(!webswingInstance0.options.appletParams) {
259 webswingInstance0.options.appletParams="";
260 }
261 webswingInstance0.options.appletParams += "&amp;collection=tudor&amp;library=library";
262 console.log("Custom Args: " + JSON.stringify(webswingInstance0.options.appletParams));
263 */
264
265 function getParam(name) {
266 name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
267 var results = new RegExp("[\\?&amp;]" + name + "=([^&amp;#]*)").exec(location.href);
268 return results == null ? null : decodeURIComponent(results[1]);
269 }
270 </gsf:script>
271
272
273 <script data-webswing-global-var="webswing">
274 <xsl:text disable-output-escaping="yes">
275 var unloaded = false;
276 (function (window, document) {
277 var loader = function () {
278 var baseUrl = '/webswing-server/phind';
279 baseUrl = baseUrl.indexOf("/", baseUrl.length - 1) !== -1 ? baseUrl : (baseUrl + "/");
280 var xmlhttp = new XMLHttpRequest();
281 xmlhttp.onreadystatechange = function () {
282 if (xmlhttp.readyState == XMLHttpRequest.DONE) {
283 var version = xmlhttp.status == 200 ? xmlhttp.responseText : "undefined";
284 var script = document.createElement("script"),
285 tag = document.getElementsByTagName("script")[0];
286 script.src = baseUrl + "javascript/webswing-embed.js?version=" + version;
287 tag.parentNode.insertBefore(script, tag);
288 }
289 };
290 xmlhttp.open("GET", baseUrl + "rest/version", true);
291 xmlhttp.send();
292 };
293
294 var navigatingAway = function () {
295 if(verbosity >= 4) {
296 console.log("*** navigatingAway called");
297 }
298
299 if(!unloaded) {
300
301 if(typeof webswingInstance0.kill === 'function') { // it should exist
302 if(verbosity >= 3) {
303 console.log("@@@ Telling webswing to stop the collage application/applet");
304 }
305 webswingInstance0.kill();
306 unloaded = true; // do not unload again, if multiple listeners call navigatingAway() callback function
307 if(verbosity >= 4) {
308 console.log("@@@@ unloaded");
309 }
310 } // else cannot call method that does not exist
311 } else {
312 if(verbosity >= 4) {
313 console.log("@@@@ already unloaded.");
314 }
315 }
316
317 };
318
319 window.addEventListener ? window.addEventListener("load", loader, false) : window.attachEvent("onload", loader);
320
321
322 // When the user navigates away from this page or reloads it, we want to shutdown
323 // the webswing Java application/applet. For more info, see layouts/webswing-collage.xsl
324
325 window.addEventListener ? window.addEventListener("beforeunload", navigatingAway, false) : window.attachEvent("onbeforeunload", navigatingAway);
326 window.addEventListener ? window.addEventListener("pagehide", navigatingAway, false) : window.attachEvent("onpagehide", navigatingAway);
327 // Not visibilitychange: it's triggered even if the user minimises the browser window
328 // don't want to kill Phind if the user only changed focus to another application.
329 //window.addEventListener ? window.addEventListener("visibilitychange", navigatingAway, false) : window.attachEvent("onvisibilitychange", navigatingAway);
330
331 })(window, document);
332 </xsl:text>
333 </script>
334
335
336
337 </xsl:template>
338
339</xsl:stylesheet>
340
Note: See TracBrowser for help on using the repository browser.