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

Last change on this file since 38947 was 38947, checked in by anupama, 4 weeks ago

Forgot to remove commented out, non-working code

File size: 12.7 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("custom args: " + webswingInstance0.options.args);
231 }
232
233
234 function getParam(name) {
235 name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
236 var results = new RegExp("[\\?&amp;]" + name + "=([^&amp;#]*)").exec(location.href);
237 return results == null ? null : decodeURIComponent(results[1]);
238 }
239 </gsf:script>
240
241
242 <script data-webswing-global-var="webswing">
243 <xsl:text disable-output-escaping="yes">
244 var unloaded = false;
245 (function (window, document) {
246 var loader = function () {
247 var baseUrl = '/webswing-server/phind';
248 baseUrl = baseUrl.indexOf("/", baseUrl.length - 1) !== -1 ? baseUrl : (baseUrl + "/");
249 var xmlhttp = new XMLHttpRequest();
250 xmlhttp.onreadystatechange = function () {
251 if (xmlhttp.readyState == XMLHttpRequest.DONE) {
252 var version = xmlhttp.status == 200 ? xmlhttp.responseText : "undefined";
253 var script = document.createElement("script"),
254 tag = document.getElementsByTagName("script")[0];
255 script.src = baseUrl + "javascript/webswing-embed.js?version=" + version;
256 tag.parentNode.insertBefore(script, tag);
257 }
258 };
259 xmlhttp.open("GET", baseUrl + "rest/version", true);
260 xmlhttp.send();
261 };
262
263 var navigatingAway = function () {
264 if(verbosity >= 4) {
265 console.log("*** navigatingAway called");
266 }
267
268 if(!unloaded) {
269
270 if(typeof webswingInstance0.kill === 'function') { // it should exist
271 if(verbosity >= 3) {
272 console.log("@@@ Telling webswing to stop the collage application/applet");
273 }
274 webswingInstance0.kill();
275 unloaded = true; // do not unload again, if multiple listeners call navigatingAway() callback function
276 if(verbosity >= 4) {
277 console.log("@@@@ unloaded");
278 }
279 } // else cannot call method that does not exist
280 } else {
281 if(verbosity >= 4) {
282 console.log("@@@@ already unloaded.");
283 }
284 }
285
286 };
287
288 window.addEventListener ? window.addEventListener("load", loader, false) : window.attachEvent("onload", loader);
289
290
291 // When the user navigates away from this page or reloads it, we want to shutdown
292 // the webswing Java application/applet. For more info, see layouts/webswing-collage.xsl
293
294 window.addEventListener ? window.addEventListener("beforeunload", navigatingAway, false) : window.attachEvent("onbeforeunload", navigatingAway);
295 window.addEventListener ? window.addEventListener("pagehide", navigatingAway, false) : window.attachEvent("onpagehide", navigatingAway);
296 // Not visibilitychange: it's triggered even if the user minimises the browser window
297 // don't want to kill Phind if the user only changed focus to another application.
298 //window.addEventListener ? window.addEventListener("visibilitychange", navigatingAway, false) : window.attachEvent("onvisibilitychange", navigatingAway);
299
300 })(window, document);
301 </xsl:text>
302 </script>
303
304
305
306 </xsl:template>
307
308</xsl:stylesheet>
309
Note: See TracBrowser for help on using the repository browser.