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

Last change on this file since 38848 was 38848, checked in by anupama, 3 months ago
  1. Running webswing-phind as an application instead of as an applet, so we can finally pass in the variable collection and library parameters. This required altering webswing.config.in (to launch JPhind as application instead of applet) and webswing-phind.xsl (to pass in the additional parameters). 2. When run as applet, clicking leaf nodes in the search results list opened the clicked url result in a browser window/tab but this wasn't happening when run as application. The easiest solution was to handle it when JPhind is run as a webswing application: in that case, it just requires registering a new eventhandler called openURL in the webswing-phind.xsl's JavaScript code, then calling this from the Java code. In JPhind.java, we now pass in a webswing command line parameter set to 1 to indicate JPhind is run as by webswing and as an application. (The webswing cmdline arg will default to 0 if not set, such as for applets or if run from the commandline without being set.) If run as an applet, JPhind uses the inherited AppletContext object as before to open a URL in the browser where the applet is being run. But now, if run as a webswing Application, it calls the new webswing custom eventhandler called openURL (for which JPhind needs to be compiled against the webswing-api.jar now) and passes the URL and any target window where the URL is to be opened. Finally, webswing.config.in passes in the new webswing parameter set to 1, since we're running the phind webswing as an application and also needs the webswing-api.jar in its classpath for phind.
File size: 9.0 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 <!-- If no collection argument is explicitly given, then produces a general
13 embedded Phind, however if a collection is specified, then it produced
14 a page with a navigation area akin to an about this page, only with
15 Phind embedded in it, rather than about this collection txt -->
16
17 <!-- use the 'main' layout -->
18 <xsl:import href="layouts/main.xsl"/>
19
20 <!-- what is this used for??? Can it be deleted? -->
21 <xsl:variable name="groupPath"><xsl:value-of select="/page/pageRequest/paramList/param[@name='group']/@value"/></xsl:variable>
22
23 <!-- set page title -->
24
25 <xsl:template name="pageTitle">WebSwing Phind<!--<gslib:collectionName/><xsl:value-of select="/page/pageResponse/service/applet"/>--></xsl:template>
26
27
28 <!-- set page breadcrumbs -->
29 <xsl:template name="breadcrumbs">
30 <xsl:choose>
31 <xsl:when test="/page/pageRequest/paramList/param[@name='c']/@value != ''">
32 <gslib:siteLink/>
33 <gslib:rightArrow/>
34 <xsl:if test="$groupPath != ''">
35 <gslib:groupLinks/>
36 <gslib:rightArrow/>
37 </xsl:if>
38 <a href="{$library_name}/collection/{$collName}/page/about">
39 <gslib:collectionName/>
40 </a>
41 </xsl:when>
42 <xsl:otherwise>
43 <xsl:choose>
44 <xsl:when test="$groupPath != ''">
45 <a>
46 <xsl:attribute name="href"><gslib:groupHref path="{$groupPath}"/></xsl:attribute>
47 <xsl:attribute name="title"><gslib:groupName path="{$groupPath}"/></xsl:attribute>
48 <gslib:groupName path="{$groupPath}"/>
49 </a>
50 </xsl:when>
51 <xsl:otherwise>
52 <gslib:siteLink/>
53 </xsl:otherwise>
54 </xsl:choose>
55
56 </xsl:otherwise>
57 </xsl:choose>
58 </xsl:template>
59
60
61 <!-- the page content -->
62 <xsl:template match="/page">
63
64 <xsl:choose>
65 <xsl:when test="$this-element/displayItemList/displayItem[@name='icon']">
66 <img border="0">
67 <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>
68 <xsl:attribute name="alt">
69 <xsl:value-of select="$this-element/displayItemList/displayItem[@name='name']"/>
70 </xsl:attribute>
71 <xsl:attribute name="title">
72 <xsl:value-of select="util:getInterfaceText($interface_name, /page/@lang, 'webswing_phindpage')"/>
73 </xsl:attribute>
74 </img>
75 </xsl:when>
76 </xsl:choose>
77
78 <!--Display the description text of the current collection,
79 and if some services are available then create a list
80 of links for each service within a <ul id="servicelist"> element.-->
81 <xsl:call-template name="webswing-embed-phind"/>
82 </xsl:template>
83
84 <xsl:template name="webswing-embed-phind">
85 <link rel="stylesheet" href="/webswing-server/css/style.css" />
86
87 <div id="webswing-phind" class="webswing-element" data-webswing-instance="webswingInstance0" style="width: 500px; height: 500px;">
88 <div id="loading" class="ws-modal-container">
89 <div class="ws-login">
90 <div class="ws-login-content">
91 <div class="ws-spinner">
92 <div class="ws-spinner-dot-1"><xsl:comment>filler</xsl:comment></div>
93 <div class="ws-spinner-dot-2"><xsl:comment>filler</xsl:comment></div>
94 </div>
95 </div>
96 </div>
97 </div>
98 </div>
99
100 <gsf:script>
101 // https://www.webswing.org/docs/23.2/configure/applet.html
102 // https://www.webswing.org/docs/23.2/configure/swing.html
103 // https://www.webswing.org/docs/23.2/integrate/javascript-api?_h=customArgs%2Cargs#usage-with-customization-and-options
104 // https://www.webswing.org/docs/23.2/integrate/embed.html
105 // https://www.webswing.org/docs/20.1/integrate/urlparams.html
106 // https://www.webswing.org/docs/23.2/integrate/urlparams.html
107 // https://www.webswing.org/docs/20.1/integrate/customize.html
108 // https://www.webswing.org/docs/2.7/integrate/embed.html
109
110 var webswingInstance0 = {
111 options: {
112 autoStart: true,
113 //appletParams: getParam('appletParams'),
114 //appletParams: {"collection":"tudor", "library":"library"},
115 connectionUrl:'/webswing-server/phind',
116
117 customization: function(injector) {
118 injector.services.base.handleActionEvent = function(actionName, data, binaryData) {
119 //console.log("WebSwing actionEvent callback handler: called with actionName = " + actionName);
120
121 if (actionName === "openURL") {
122 var url = data;
123 // check if a target tab/window name has been specified
124 // Any better way of passing more than 1 string between Java and JavaScript?
125 var index = url.indexOf(" - ");
126 if (index !== -1) {
127 var target = url.substring(index+3); // skip past " - " to get target name
128 window.open(url, target);
129 } else {
130 window.open(url, '_blank');
131 }
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 //https://stackoverflow.com/questions/25203124/how-to-get-base-url-with-jquery-or-javascript
148 var baseURL = window.location.origin+window.location.pathname;
149 // webswingInstance0.options.args += "\"" + baseURL+ "?a=a&amp;rt=d&amp;s=PhindApplet&amp;c="+gs.cgiParams.c + "\"";
150 webswingInstance0.options.args += "\"" + baseURL + "\"";
151
152 webswingInstance0.options.args += " --collection=" + gs.cgiParams.c;
153 webswingInstance0.options.args += " --library=" + gs.xsltParams.library_name;
154
155 //console.log("args: " + webswingInstance0.options.args);
156
157
158 /*
159 // Not yet working. Stick ${customArgs} at end of final param Value (BEFORE the value's closing double quote) in webswing.config.in
160 // The applet jar files can just remain in web/applet where they are compiled up
161 if(!webswingInstance0.options.args) {
162 webswingInstance0.options.args="";
163 }
164 if (gs.cgiParams.c) {
165 webswingInstance0.options.args += ", -Dwebswing.appletParam_collection=" + gs.cgiParams.c;
166 }
167 webswingInstance0.options.args += ", -Dwebswing.appletParam_library=";
168 webswingInstance0.options.args+=(gs.xsltParams.library_name)?gs.xsltParams.library_name:"library";
169
170 console.log("args: " + webswingInstance0.options.args);
171 */
172
173 /*
174 if(!webswingInstance0.options.appletParams) {
175 webswingInstance0.options.appletParams={};
176 }
177 if (gs.cgiParams.c) {
178 webswingInstance0.options.appletParams["collection"] = gs.cgiParams.c;
179 }
180 webswingInstance0.options.appletParams["library"] = (gs.xsltParams.library_name) ? gs.xsltParams.library_name : "library";
181 */
182 /*
183 if(!webswingInstance0.options.appletParams) {
184 webswingInstance0.options.appletParams="";
185 }
186 webswingInstance0.options.appletParams += "&amp;collection=tudor&amp;library=library";
187 console.log("Custom Args: " + JSON.stringify(webswingInstance0.options.appletParams));
188 */
189
190 function getParam(name) {
191 name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
192 var results = new RegExp("[\\?&amp;]" + name + "=([^&amp;#]*)").exec(location.href);
193 return results == null ? null : decodeURIComponent(results[1]);
194 }
195 </gsf:script>
196
197
198 <script data-webswing-global-var="webswing">
199 <xsl:text disable-output-escaping="yes">
200 (function (window, document) {
201 var loader = function () {
202 var baseUrl = '/webswing-server/phind';
203 baseUrl = baseUrl.indexOf("/", baseUrl.length - 1) !== -1 ? baseUrl : (baseUrl + "/");
204 var xmlhttp = new XMLHttpRequest();
205 xmlhttp.onreadystatechange = function () {
206 if (xmlhttp.readyState == XMLHttpRequest.DONE) {
207 var version = xmlhttp.status == 200 ? xmlhttp.responseText : "undefined";
208 var script = document.createElement("script"),
209 tag = document.getElementsByTagName("script")[0];
210 script.src = baseUrl + "javascript/webswing-embed.js?version=" + version;
211 tag.parentNode.insertBefore(script, tag);
212 }
213 };
214 xmlhttp.open("GET", baseUrl + "rest/version", true);
215 xmlhttp.send();
216 };
217 window.addEventListener ? window.addEventListener("load", loader, false) : window.attachEvent("onload", loader);
218 })(window, document);
219 </xsl:text>
220 </script>
221
222
223
224 </xsl:template>
225
226</xsl:stylesheet>
227
Note: See TracBrowser for help on using the repository browser.