DSpace UI Prototype Challenge: Spring Boot + Thymeleaf

14
Licensed under Creative Commons Attribution-ShareAlike 4.0 International License UI Prototype Spring Boot + Thymeleaf Tim Donohue, DuraSpace [email protected]

Transcript of DSpace UI Prototype Challenge: Spring Boot + Thymeleaf

Page 1: DSpace UI Prototype Challenge: Spring Boot + Thymeleaf

Licensed under Creative Commons Attribution-ShareAlike 4.0 International License

UI PrototypeSpring Boot + Thymeleaf

Tim Donohue, [email protected]

Page 2: DSpace UI Prototype Challenge: Spring Boot + Thymeleaf

Technologies used• Spring Boot

– Newer, but built on Spring MVC• See Cineca’s prototype for MVC overview

– Convention over configuration• Prepackaged Maven / Gradle plugins

– Embeddable Tomcat/Jetty (in JAR)– Autoconfiguration of Spring

• No requirement for XML configs– Autoconfiguration of many templating

engines (Thymeleaf being one)

Page 3: DSpace UI Prototype Challenge: Spring Boot + Thymeleaf

Technologies used• Thymeleaf

– Java/HTML5 templating engine– Looks like HTML (mostly)– Natural templating (view static HTML)– Supports HTML “fragments”– FORCES separating content from layout– Spring specific integrations

• Bootstrap

Page 4: DSpace UI Prototype Challenge: Spring Boot + Thymeleaf

Technologies used• DSpace 6 (pre-6) Java API

– With Enhanced Configuration Scheme (local.cfg / Apache Commons Config)

• Provides auto-reloadable configs• Spring Security (AutnN/Z)

– Used test “in memory” authN– AuthZ lets you limit access via Path– Very easy to use with Spring Boot

Page 5: DSpace UI Prototype Challenge: Spring Boot + Thymeleaf

Spring Boot• Configured to build a runnable JAR

(embedded Tomcat)• Enabled Thymeleaf plugin• Enabled Spring Security plugin• Spring Boot Application configuration

– Application class– application.properties

Page 6: DSpace UI Prototype Challenge: Spring Boot + Thymeleaf

Thymeleaf• Looks like HTML, with “th:” attributes

– th:fragment => th:include, th:replace– th:text (replace text)– th:if / th:unless– th:each (loop Lists/Iterable/Map/array)– th:with (sets a local variable)– th:href (dynamically build links)

Page 7: DSpace UI Prototype Challenge: Spring Boot + Thymeleaf

Thymeleaf• Looks like HTML, with “th:” attributes

– th:fragment => th:include, th:replace– th:text (replace text / adds i18n)– th:if / th:unless– th:each (loop Lists/Iterable/Map/array)– th:with (sets a local variable)– th:href (dynamically build links)

• (Very) basic Java calls supported

Page 8: DSpace UI Prototype Challenge: Spring Boot + Thymeleaf

Thymeleaf• Also some special expressions / syntax:

– ${variable} => output value of variable– #{i18n.key} => output i18n msg– @{path} => output a link/URL

• And Java utility objects:– #lists.isEmpty(java.util.List)– #arrays– #dates (formatting java.util.Date objs)

Page 9: DSpace UI Prototype Challenge: Spring Boot + Thymeleaf

Prototype Theming• Basic at this point

– /static/themes directory– Themes consist of a layout.html and

CSS, images, JS• Custom code in DSpaceController

– Allows one to customize theme loaded based on paths (in local.cfg)

Page 10: DSpace UI Prototype Challenge: Spring Boot + Thymeleaf

Theming with Thymeleaf• layout.html

– Contains all our theme “fragments”– (could split these into separate files, e.g.

header.html, footer.hml)• Thymeleaf can select fragments

– by name– by DOM selects (e.g. #id selects an

HTML tag by ‘id’)

Page 11: DSpace UI Prototype Challenge: Spring Boot + Thymeleaf

AuthN/AuthZ• Spring Security

– Not yet integrated with DSpace’s Auth• AuthN is using Spring Security’s “test

mode” (in memory auth)• AuthN/Z Defined entirely in

WebSecurityConfig• Only one restricted path (/admin)

Page 12: DSpace UI Prototype Challenge: Spring Boot + Thymeleaf

Demo

Page 13: DSpace UI Prototype Challenge: Spring Boot + Thymeleaf

Prototype code / docs• https://github.com/tdonohue/DSpace-

Spring-Boot– See README for documentation

Page 14: DSpace UI Prototype Challenge: Spring Boot + Thymeleaf

Limits of Prototype• No actual item editing/creation

– Concentrated more on testing Thymeleaf extendability

• Spring Security AuthN/Z not integrated with DSpace’s