source: gs3-installations/intermuse/trunk/sites/intermuse/collect/programmes/transform/pages/document.xsl@ 37111

Last change on this file since 37111 was 37111, checked in by davidb, 16 months ago

Change to using document_extra.js in web/ext/structured-image/js; some other code tidy up

File size: 13.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 gsf">
10
11
12 <xsl:variable name="httpDocument">
13 <xsl:value-of select="$library_name"/>
14 <xsl:text>/collection/</xsl:text>
15 <xsl:value-of select="/page/pageResponse/collection/@name"/>
16 <xsl:text>/document/</xsl:text>
17 <xsl:value-of select="/page/pageRequest/paramList/param[@name = 'd']/@value"/> <!-- or use $docID from default/transform/pages/document.xsl ???? -->
18 </xsl:variable>
19
20
21 <xsl:template name="iiif-links">
22 <xsl:param name="identifier"/>
23
24 <gsf:variable name="iiifImageRootIdentifier">
25 <xsl:text>/gs-cantaloupe/iiif/2/</xsl:text><xsl:value-of select="$site_name"/>:<xsl:value-of select="$collNameChecked"/>:<xsl:value-of select="$identifier"/>
26 </gsf:variable>
27
28 <!--
29 <gsf:variable name="iiifPresentationRootIdentifier"><xsl:value-of select="$docID"/></gsf:variable>
30 -->
31
32 <gsf:variable name="iiifPresentationRootIdentifier">http-greenstone://<xsl:value-of select="$site_name"/>/<xsl:value-of select="$collNameChecked"/>/<xsl:value-of select="$docID"/></gsf:variable>
33
34 <gsf:script>
35 var chosen_title = "untitled";
36
37 if (gs.variables.chosenTitle &amp;&amp; !gs.variables.docNodeID) {
38 // simple doc
39 chosen_title = gs.variables.chosenTitle;
40 }
41 else {
42 var docNodeID = gs.variables.docNodeID;
43 var page_pos = docNodeID.indexOf('.');
44 chosen_title = (page_pos>=0) ? "page " + docNodeID.substring(page_pos+1) : docNodeID;
45 }
46
47 var iiif_doc_image = {
48 "id": document.location.origin + gs.variables.iiifImageRootIdentifier,
49 //"format": mime_type, // ???? or is it OK to always have this as image/jpeg and rely on IIIF Image Server coverting as/when needed???
50 //"chosen_title": gs.variables.chosenTitle,
51 "chosen_title": chosen_title,
52 "x_dim": gs.variables.imageWidth,
53 "y_dim": gs.variables.imageHeight,
54 };
55
56 IIIF_Doc_Images.push(iiif_doc_image);
57
58 </gsf:script>
59
60 </xsl:template>
61
62
63 <xsl:template name="opt-googlevision-ocr-json">
64 <xsl:param name="assocfilepath"/>
65
66 <gsf:variable name="GVDocumentOCRJSON"><gsf:metadata name="GVDocumentOCRJSON"/></gsf:variable>
67 <gsf:variable name="docSectionID"><xsl:value-of select="util:replace(@nodeID, '.', '_')"/></gsf:variable>
68
69 <gsf:switch>
70 <gsf:metadata name="HasGoogleVisionDocumentOCRJSON"/>
71 <gsf:when test='equals' test-value="1">
72
73 <gsf:script>
74 // Load in the Google Vision OCR JSON file and display bounding boxes for this document (docType=simple) or page (docType=paged)
75 load_gv_dococr_json(gs.variables.GVDocumentOCRJSON,gs.variables.docSectionID,display_gv_ocr_bounding_boxes);
76 </gsf:script>
77 </gsf:when>
78 </gsf:switch>
79
80 </xsl:template>
81
82
83 <xsl:template name="wrappedSectionPost">
84
85 <!-- add in IIIF Server link for section image -->
86 <xsl:variable name="nodeID" select="@nodeID"/>
87 <xsl:call-template name="iiif-links">
88 <xsl:with-param name="identifier" select="$nodeID" />
89 </xsl:call-template>
90
91 <!-- add in Google Vision OCR JSON link for section image -->
92 <xsl:call-template name="opt-googlevision-ocr-json">
93 <xsl:with-param name="assocfilepath"><gsf:metadata name="assocfilepath" select="root"/></xsl:with-param>
94 </xsl:call-template>
95
96 </xsl:template>
97
98 <xsl:template name="sectionImage">
99 <xsl:if test="$bookswitch != 'mirador'">
100 <gsf:image type="screen"/>
101 </xsl:if>
102 </xsl:template>
103
104 <xsl:template name="sectionContent">
105
106 <xsl:choose>
107 <xsl:when test="$bookswitch = 'mirador'">
108 <gsf:variable name="screenImageWidth"><gsf:metadata name="ScreenWidth"/></gsf:variable>
109 <gsf:variable name="screenImageHeight"><gsf:metadata name="ScreenHeight"/></gsf:variable>
110 <gsf:variable name="imageWidth"><gsf:metadata name="ImageWidth"/></gsf:variable>
111 <gsf:variable name="imageHeight"><gsf:metadata name="ImageHeight"/></gsf:variable>
112 <gsf:variable name="docNodeID"><xsl:value-of select="@nodeID"/></gsf:variable> <!-- used to make each 'tidyDiv' unique -->
113 </xsl:when>
114
115 <xsl:otherwise>
116 <xsl:call-template name="wrappedSectionImage"/>
117
118 <div style="padding: 10px 0px 10px 0px">Ocr'd Text:</div>
119 <i>
120 <xsl:call-template name="wrappedSectionText"/>
121 </i>
122 </xsl:otherwise>
123 </xsl:choose>
124
125 <xsl:call-template name="wrappedSectionPost"/>
126 </xsl:template>
127
128 <xsl:template name="sectionContentForEditing">
129 <xsl:call-template name="wrappedSectionImage"/>
130 <xsl:call-template name="wrappedSectionTextForEditing"/>
131 </xsl:template>
132
133 <xsl:template name="documentHeading">
134 <xsl:if test="$bookswitch != 'mirador'">
135 <span style="font-weight:bold; font-size: 120%;">
136 <xsl:call-template name="choose-title"/>
137 </span>
138 </xsl:if>
139
140 <gsf:metadata-table>
141 <gsf:metadata name="ex.im.No">Catalogue No:</gsf:metadata>
142 <gsf:metadata name="ex.im.Work">Work:</gsf:metadata>
143 <gsf:metadata name="ex.im.Artist">Artist(s):</gsf:metadata>
144 <gsf:metadata name="ex.im.Venue">Venue:</gsf:metadata>
145 <gsf:metadata name="ex.im.Composer">Composer:</gsf:metadata>
146 </gsf:metadata-table>
147
148 </xsl:template>
149
150 <xsl:template name="documentPre">
151 <xsl:variable name="httpCollection">library/sites/<xsl:value-of select="$site_name"/>/collect/<xsl:value-of select="/page/pageResponse/collection/@name"/></xsl:variable>
152
153 <gsf:variable name="optionIncludeFileAssocOpenAnnotations">
154 <xsl:value-of select="/page/pageResponse/format[@type='display']/gsf:option[@name='includeFileAssocOpenAnnotations']/@value"/>
155 </gsf:variable>
156 <gsf:variable name="optionIncludeEditableOpenAnnotations">
157 <xsl:value-of select="/page/pageResponse/format[@type='display']/gsf:option[@name='includeEditableOpenAnnotations']/@value"/>
158 </gsf:variable>
159 <gsf:variable name="optionIncludeEditableOpenAnnotationsEndpointURL">
160 <xsl:value-of select="/page/pageResponse/format[@type='display']/gsf:option[@name='includeEditableOpenAnnotations']/@endpointURL"/>
161 </gsf:variable>
162
163
164 <gsf:variable name="chosenTitle"><xsl:call-template name="choose-title"/></gsf:variable>
165 <!-- <gsf:variable name="toplevelTitle"><gsf:metadata name="Title" select="root"/></gsf:variable> -->
166 <gsf:variable name="imageWidth"><gsf:metadata name="ImageWidth"/></gsf:variable>
167 <gsf:variable name="imageHeight"><gsf:metadata name="ImageHeight"/></gsf:variable>
168
169 <gsf:script>
170 console.log("**** chosenTitle = " + gs.variables.chosenTitle);
171 </gsf:script>
172
173 <!--
174 <gsf:script src="{$httpCollection}/js/document_viewer.js"/>
175 -->
176
177 <gsf:script src="ext/structured-image/js/document_extra.js"/>
178 <style>
179 div.ocr-boundingbox-overlay {
180 position: absolute;
181 left: 0;
182 top: 0;
183 }
184
185 div.ocr-boundingbox {
186 position: absolute;
187 border: solid black 1px;
188 }
189
190 </style>
191
192 <xsl:if test="$bookswitch = 'mirador'">
193 <gsf:script src="ext/structured-image/mirador3/dist/mirador-with-annotations.js"/>
194 <!-- Mirador, by default, uses Roboto font, so load it in -->
195 <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" />
196 </xsl:if>
197
198 <gsf:script>
199 var IIIF_Doc_Images = [];
200 </gsf:script>
201
202 </xsl:template>
203
204
205 <xsl:template name="documentContentMirador3">
206 <xsl:if test="@docType='simple'">
207 <gsf:script>$('#tocLoadingImage').hide()</gsf:script>
208 <!-- add in IIIF Server link for simple page image -->
209 <xsl:call-template name="iiif-links">
210 <xsl:with-param name="identifier" select="$docID" />
211 </xsl:call-template>
212 </xsl:if>
213 </xsl:template>
214
215 <xsl:template name="documentContent">
216 <!-- The way document.xsl tempaltes are structured, only get to here is if @docType = 'simple' -->
217 <!-- A 'paged' (or 'hierarical') document goes throgh 'wrappedContent' -->
218
219 <div id="gs-document">
220
221 <xsl:choose>
222 <xsl:when test="$bookswitch = 'mirador'">
223 <xsl:call-template name="documentPre"/>
224 <xsl:call-template name="documentContentMirador3"/>
225 <xsl:call-template name="documentPost"/>
226 <xsl:call-template name="documentPostMirador3"/>
227 </xsl:when>
228
229 <xsl:otherwise>
230 <xsl:call-template name="documentPre"/>
231 <xsl:call-template name="wrappedSectionImage"/>
232 <div id="gs-document-text">
233 <xsl:call-template name="documentNodeText"/>
234 </div>
235 <xsl:call-template name="documentPost"/>
236 </xsl:otherwise>
237
238 </xsl:choose>
239 </div>
240
241 </xsl:template>
242
243
244 <xsl:template name="documentPost">
245
246 <xsl:if test="@docType='simple'">
247 <xsl:call-template name="opt-googlevision-ocr-json">
248 <xsl:with-param name="assocfilepath"><gsf:metadata name="assocfilepath" pos="first"/></xsl:with-param>
249 </xsl:call-template>
250 </xsl:if>
251 </xsl:template>
252
253 <xsl:template name="documentPostMirador3">
254
255 <!-- Container element of Mirador whose id should be passed to the instantiating call as "id" -->
256 <div style="position: relative; width: 100%; height: 800px;">
257 <div id="mirador3-viewer"><xsl:comment>filler</xsl:comment></div>
258 </div>
259
260 <!--
261 <gsf:variable name="endpointURL">
262 <xsl:choose>
263 <xsl:when test="/page/pageResponse/format[@type='display']/gsf:option[@name='includeEditableOpenAnnotations']/@value='true'">
264 <xsl:choose>
265 <xsl:when test="/page/pageResponse/format[@type='display']/gsf:option[@name='includeEditableOpenAnnotations']/@endpointURL">
266 <xsl:value-of select="/page/pageResponse/format[@type='display']/gsf:option[@name='includeEditableOpenAnnotations']/@endpointURL"/>
267 </xsl:when>
268 <xsl:otherwise>
269 <xsl:text>localStorage</xsl:text> < ! - - default - - >
270 </xsl:otherwise>
271 </xsl:choose>
272 </xsl:when>
273 <xsl:otherwise></xsl:otherwise>
274 </xsl:choose>
275 </gsf:variable>
276 -->
277
278 <gsf:script>
279 var iiifpres_root_id = gs.variables.iiifPresentationRootIdentifier;
280 console.log(gs);
281 var iiifpres_label = (gs.variables.toplevelTitle) ? gs.variables.toplevelTitle : gs.variables.chosenTitle;
282
283 var iiif_manifest = initIIIFManifest(iiifpres_root_id,iiifpres_label, IIIF_Doc_Images);
284
285 var mirador3 = createMirador3Viewer();
286 </gsf:script>
287
288 </xsl:template>
289
290 <xsl:template name="wrappedDocumentTopLevel">
291 <gsf:variable name="toplevelTitle"><xsl:value-of disable-output-escaping="yes" select="/page/pageResponse/document/documentNode/metadataList/metadata[@name='Title']" /></gsf:variable>
292 <xsl:choose>
293 <xsl:when test="$bookswitch = 'mirador'">
294 <!-- <xsl:call-template name="documentPre"/> -->
295 <div style="display:none;">
296 <xsl:call-template name="wrappedDocument"/> <!-- without ed=1, this template misses the binds in of documentPre and documentPost -->
297 </div>
298 <!-- <xsl:call-template name="documentPost"/> -->
299 <xsl:call-template name="documentPostMirador3"/>
300 </xsl:when>
301 <xsl:otherwise>
302 <xsl:call-template name="wrappedDocument"/> <!-- without ed=1, this template misses the binds in of documentPre and documentPost -->
303 </xsl:otherwise>
304 </xsl:choose>
305 </xsl:template>
306
307
308 <!-- content of a simple document. Will not be used for editing mode -->
309 <xsl:template name="documentPostInProgress">
310
311
312 <!--
313 canDoEditing = <xsl:value-of select="$canDoEditing"/> <br />
314 editingTurnedOn = <xsl:value-of select="$editingTurnedOn"/>
315 -->
316
317 <!--
318
319 <xsl:choose>
320 <xsl:when test="$canDoEditing = 'true' and $editingTurnedOn = 'true'">
321
322 <xsl:when test="$canDoEditing = 'true'">
323-->
324 <gsf:script src="https://unpkg.com/mirador@latest/dist/mirador.min.js"/>
325
326
327 <!-- By default uses Roboto font. Be sure to load this or change the font -->
328 <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" />
329 <!-- Container element of Mirador whose id should be passed to the instantiating call as "id" -->
330
331 <div style="position: relative; width: 100%; height: 800px;">
332 <div id="my-mirador"> <xsl:comment>filler</xsl:comment></div>
333 </div>
334
335 <gsf:script>
336
337var mirador = Mirador.viewer({
338 "id": "my-mirador",
339 "manifests": {
340 "https://intermuse.sowemustthink.space/greenstone3/sample-manifest.json": {
341 "provider": "IntermusE"
342 }
343 },
344 "window" : { "panels" : { "annotations": true, "attribution": false } },
345 "annotations": {
346 "htmlSanitizationRuleSet": 'iiif', // See src/lib/htmlRules.js for acceptable values
347 "filteredMotivations": ['oa:commenting', 'oa:tagging', 'sc:painting', 'commenting', 'tagging'],
348 },
349 "windows": [
350 {
351 "loadedManifest": "https://intermuse.sowemustthink.space/greenstone3/sample-manifest.json",
352 "canvasIndex": 1,
353 "thumbnailNavigationPosition": 'far-bottom'
354 }
355 ]
356});
357 </gsf:script>
358
359 <!--
360 </xsl:when>
361 </xsl:choose>
362-->
363
364 </xsl:template>
365
366
367</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.