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

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

A series of changes getting the code and XSLT up to the point where the Mirador annotation viewer can be operated without annotations, with annotaitons from a static manifest, with annotations from the store (editable)

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