From 2eb32fde92fec980eede319fb99da6da946b88bf Mon Sep 17 00:00:00 2001 From: Francois Prunayre Date: Fri, 20 Nov 2020 22:40:31 +0100 Subject: [PATCH] Rendering HTML. Test to add a theme and a default page structure than can be customized. Rendering is XSLT based. --- .../impl/XsltResponseProcessorImpl.java | 2 +- .../org/fao/geonet/searching/GnSearchApp.java | 15 ++ .../controller/CollectionsController.java | 69 +++++++++ .../javax.xml.transform.TransformerFactory | 1 + .../src/main/resources/bootstrap.yml | 7 +- .../xslt/collections/collections.xsl | 0 .../{ => collections/items/formats}/copy.xsl | 0 .../{ => collections/items/formats}/dcat.xsl | 0 .../xslt/collections/items/items.xsl | 0 .../xslt/commons/xsl-params-core.xsl | 9 ++ .../src/main/resources/xslt/error.xsl | 13 ++ .../src/main/resources/xslt/landingpage.xsl | 136 ++++++++++++++++++ .../resources/xslt/themes/default/footer.html | 44 ++++++ .../resources/xslt/themes/default/head.html | 18 +++ .../resources/xslt/themes/default/nav.html | 39 +++++ .../resources/xslt/themes/default/theme.xsl | 28 ++++ 16 files changed, 379 insertions(+), 2 deletions(-) create mode 100644 modules/services/searching/src/main/java/org/fao/geonet/searching/controller/CollectionsController.java create mode 100644 modules/services/searching/src/main/resources/META-INF/services/javax.xml.transform.TransformerFactory create mode 100644 modules/services/searching/src/main/resources/xslt/collections/collections.xsl rename modules/services/searching/src/main/resources/xslt/{ => collections/items/formats}/copy.xsl (100%) rename modules/services/searching/src/main/resources/xslt/{ => collections/items/formats}/dcat.xsl (100%) create mode 100644 modules/services/searching/src/main/resources/xslt/collections/items/items.xsl create mode 100644 modules/services/searching/src/main/resources/xslt/commons/xsl-params-core.xsl create mode 100644 modules/services/searching/src/main/resources/xslt/error.xsl create mode 100644 modules/services/searching/src/main/resources/xslt/landingpage.xsl create mode 100644 modules/services/searching/src/main/resources/xslt/themes/default/footer.html create mode 100644 modules/services/searching/src/main/resources/xslt/themes/default/head.html create mode 100644 modules/services/searching/src/main/resources/xslt/themes/default/nav.html create mode 100644 modules/services/searching/src/main/resources/xslt/themes/default/theme.xsl diff --git a/modules/library/common-search/src/main/java/org/fao/geonet/common/search/processor/impl/XsltResponseProcessorImpl.java b/modules/library/common-search/src/main/java/org/fao/geonet/common/search/processor/impl/XsltResponseProcessorImpl.java index a2aefe2c..70cdd82c 100644 --- a/modules/library/common-search/src/main/java/org/fao/geonet/common/search/processor/impl/XsltResponseProcessorImpl.java +++ b/modules/library/common-search/src/main/java/org/fao/geonet/common/search/processor/impl/XsltResponseProcessorImpl.java @@ -53,7 +53,7 @@ public void processResponse(HttpSession httpSession, XMLStreamWriter generator = s.getXMLStreamWriter(); String xsltFileName = String.format( - "xslt/%s.xsl", transformation); + "xslt/collections/items/formats/%s.xsl", transformation); File xsltFile = new ClassPathResource(xsltFileName).getFile(); if (!xsltFile.exists()) { diff --git a/modules/services/searching/src/main/java/org/fao/geonet/searching/GnSearchApp.java b/modules/services/searching/src/main/java/org/fao/geonet/searching/GnSearchApp.java index ac997f65..6b753025 100644 --- a/modules/services/searching/src/main/java/org/fao/geonet/searching/GnSearchApp.java +++ b/modules/services/searching/src/main/java/org/fao/geonet/searching/GnSearchApp.java @@ -11,8 +11,11 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.cloud.context.config.annotation.RefreshScope; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.web.servlet.ViewResolver; +import org.springframework.web.servlet.view.xslt.XsltViewResolver; @SpringBootApplication @RefreshScope @@ -26,4 +29,16 @@ public class GnSearchApp { public static void main(String[] args) { SpringApplication.run(GnSearchApp.class, args); } + + + @Bean + public ViewResolver xsltViewResolver() { + XsltViewResolver viewResolver = new XsltViewResolver(); + viewResolver.setPrefix("classpath:/xslt/"); + viewResolver.setSuffix(".xsl"); + viewResolver.setSourceKey("source"); + viewResolver.setCacheTemplates(false); + viewResolver.setCache(false); + return viewResolver; + } } diff --git a/modules/services/searching/src/main/java/org/fao/geonet/searching/controller/CollectionsController.java b/modules/services/searching/src/main/java/org/fao/geonet/searching/controller/CollectionsController.java new file mode 100644 index 00000000..8d5cdf8d --- /dev/null +++ b/modules/services/searching/src/main/java/org/fao/geonet/searching/controller/CollectionsController.java @@ -0,0 +1,69 @@ +/** + * (c) 2020 Open Source Geospatial Foundation - all rights reserved This code is licensed under the + * GPL 2.0 license, available at the root application directory. + */ + +package org.fao.geonet.searching.controller; + +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.Random; +import java.util.UUID; +import java.util.stream.Stream; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import javax.ws.rs.Produces; +import org.apache.commons.io.IOUtils; +import org.fao.geonet.common.search.Constants; +import org.fao.geonet.common.search.ElasticSearchProxy; +import org.fao.geonet.common.xml.XsltUtil; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.servlet.ViewResolver; +import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; +import org.springframework.web.servlet.view.xslt.XsltViewResolver; + +@RequestMapping(value = { + "/landingpage" +}) +@Controller +public class CollectionsController { + + @Autowired + ViewResolver viewResolver; + + /** + * Catalogue landing page. + */ + @GetMapping + @Produces(value = "text/html") + public String landingpage( + @RequestParam(defaultValue = "false") + boolean debug, + Model model) throws Exception { + if (debug) { + ((ContentNegotiatingViewResolver) viewResolver) + .getViewResolvers() + .stream() + .filter(v -> v instanceof XsltViewResolver) + .map(v -> (XsltViewResolver) v) + .forEach(v -> v.clearCache()); + } + + model.addAttribute("source", IOUtils.toInputStream( + String.format("", UUID.randomUUID()))); + model.addAttribute("language", "fre"); + return "landingpage"; + } +} diff --git a/modules/services/searching/src/main/resources/META-INF/services/javax.xml.transform.TransformerFactory b/modules/services/searching/src/main/resources/META-INF/services/javax.xml.transform.TransformerFactory new file mode 100644 index 00000000..776bb11f --- /dev/null +++ b/modules/services/searching/src/main/resources/META-INF/services/javax.xml.transform.TransformerFactory @@ -0,0 +1 @@ +net.sf.saxon.TransformerFactoryImpl diff --git a/modules/services/searching/src/main/resources/bootstrap.yml b/modules/services/searching/src/main/resources/bootstrap.yml index c3d62327..8160f4dd 100644 --- a/modules/services/searching/src/main/resources/bootstrap.yml +++ b/modules/services/searching/src/main/resources/bootstrap.yml @@ -33,12 +33,17 @@ eureka: logging: level: org.springframework.security: DEBUG + + --- +# Use this profile when running on a GN4 database on localhost and Elasticsearch index. +# Turn off security, config & discover. spring: profiles: standalone + rabbitmq.host: localhost datasource: driver-class-name: org.postgresql.Driver - url: jdbc:postgresql://localhost:5432/sextant7 + url: jdbc:postgresql://localhost:5432/geonetwork username: www-data password: www-data jpa: diff --git a/modules/services/searching/src/main/resources/xslt/collections/collections.xsl b/modules/services/searching/src/main/resources/xslt/collections/collections.xsl new file mode 100644 index 00000000..e69de29b diff --git a/modules/services/searching/src/main/resources/xslt/copy.xsl b/modules/services/searching/src/main/resources/xslt/collections/items/formats/copy.xsl similarity index 100% rename from modules/services/searching/src/main/resources/xslt/copy.xsl rename to modules/services/searching/src/main/resources/xslt/collections/items/formats/copy.xsl diff --git a/modules/services/searching/src/main/resources/xslt/dcat.xsl b/modules/services/searching/src/main/resources/xslt/collections/items/formats/dcat.xsl similarity index 100% rename from modules/services/searching/src/main/resources/xslt/dcat.xsl rename to modules/services/searching/src/main/resources/xslt/collections/items/formats/dcat.xsl diff --git a/modules/services/searching/src/main/resources/xslt/collections/items/items.xsl b/modules/services/searching/src/main/resources/xslt/collections/items/items.xsl new file mode 100644 index 00000000..e69de29b diff --git a/modules/services/searching/src/main/resources/xslt/commons/xsl-params-core.xsl b/modules/services/searching/src/main/resources/xslt/commons/xsl-params-core.xsl new file mode 100644 index 00000000..85b6f8fb --- /dev/null +++ b/modules/services/searching/src/main/resources/xslt/commons/xsl-params-core.xsl @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/modules/services/searching/src/main/resources/xslt/error.xsl b/modules/services/searching/src/main/resources/xslt/error.xsl new file mode 100644 index 00000000..1770234b --- /dev/null +++ b/modules/services/searching/src/main/resources/xslt/error.xsl @@ -0,0 +1,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/modules/services/searching/src/main/resources/xslt/landingpage.xsl b/modules/services/searching/src/main/resources/xslt/landingpage.xsl new file mode 100644 index 00000000..07e10cda --- /dev/null +++ b/modules/services/searching/src/main/resources/xslt/landingpage.xsl @@ -0,0 +1,136 @@ + + + + + + + + Processing doc: + + + + + +
+
+
+

Looking for data?

+

+ Search over 12534 data sets, services and maps, ... +

+

+ ... +

+ +
+ +
+
+
+
+
+ + + + + + + + + + + + +
+
+ +
+ + +
+
+ +
+
\ No newline at end of file diff --git a/modules/services/searching/src/main/resources/xslt/themes/default/footer.html b/modules/services/searching/src/main/resources/xslt/themes/default/footer.html new file mode 100644 index 00000000..7f80f7d8 --- /dev/null +++ b/modules/services/searching/src/main/resources/xslt/themes/default/footer.html @@ -0,0 +1,44 @@ + \ No newline at end of file diff --git a/modules/services/searching/src/main/resources/xslt/themes/default/head.html b/modules/services/searching/src/main/resources/xslt/themes/default/head.html new file mode 100644 index 00000000..afe6155e --- /dev/null +++ b/modules/services/searching/src/main/resources/xslt/themes/default/head.html @@ -0,0 +1,18 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/modules/services/searching/src/main/resources/xslt/themes/default/nav.html b/modules/services/searching/src/main/resources/xslt/themes/default/nav.html new file mode 100644 index 00000000..136cf19a --- /dev/null +++ b/modules/services/searching/src/main/resources/xslt/themes/default/nav.html @@ -0,0 +1,39 @@ + \ No newline at end of file diff --git a/modules/services/searching/src/main/resources/xslt/themes/default/theme.xsl b/modules/services/searching/src/main/resources/xslt/themes/default/theme.xsl new file mode 100644 index 00000000..e9aa39d0 --- /dev/null +++ b/modules/services/searching/src/main/resources/xslt/themes/default/theme.xsl @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file