[java-shib-shared] 01/01: Add module for custom Thymeleaf-Spring integration classes.

Marvin S. Addison marvin.addison at gmail.com
Tue Jan 16 12:36:47 UTC 2024


This is an automated email from the git hooks/post-receive script.

serac pushed a commit to branch dev/thymeleaf
in repository java-shib-shared.

View the commit online:
http://git.shibboleth.net/view/?p=java-shib-shared.git;a=commit;h=6ebb13a9c60b1d0606d493bd68c8b5ad52ea7bbe

commit 6ebb13a9c60b1d0606d493bd68c8b5ad52ea7bbe
Author: Marvin S. Addison <serac at vt.edu>
AuthorDate: Tue Jan 16 07:33:48 2024 -0500

    Add module for custom Thymeleaf-Spring integration classes.
    
    Primary class is a custom view resolver that supports view resolver
    chaining like most Spring view resolvers.
---
 pom.xml                                            |  1 +
 shib-thymeleaf-spring/.checkstyle                  | 15 +++++++
 shib-thymeleaf-spring/.gitignore                   | 21 ++++++++++
 shib-thymeleaf-spring/pom.xml                      | 49 ++++++++++++++++++++++
 .../thymeleaf/ChainingThymeleafViewResolver.java   | 44 +++++++++++++++++++
 5 files changed, 130 insertions(+)

diff --git a/pom.xml b/pom.xml
index 0ab078a1..54cb6d3f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -36,6 +36,7 @@
         <module>shib-service</module>
         <module>shib-testing</module>
         <module>shib-velocity</module>
+        <module>shib-thymeleaf-spring</module>
         <module>shib-velocity-spring</module>
 
         <module>shib-shared-bom</module>
diff --git a/shib-thymeleaf-spring/.checkstyle b/shib-thymeleaf-spring/.checkstyle
new file mode 100644
index 00000000..186d7f35
--- /dev/null
+++ b/shib-thymeleaf-spring/.checkstyle
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<fileset-config file-format-version="1.2.0" simple-config="false" sync-formatter="false">
+
+    <local-check-config name="Shibboleth Checkstyle" location="/java-shib-shared/resources/checkstyle/checkstyle.xml" type="project" description="">
+        <additional-data name="cache-file" value="true"/>
+        <additional-data name="cache-props-file-location" value="null_1312636288299_cache.properties"/>
+        <additional-data name="cache-file-location" value="null_1312636288299_cache.xml"/>
+    </local-check-config>
+  
+    <fileset name="main source" enabled="true" check-config-name="Shibboleth Checkstyle" local="true">
+        <file-match-pattern match-pattern="src/main/java/.*\.java$" include-pattern="true"/>
+    </fileset>
+  
+</fileset-config>
diff --git a/shib-thymeleaf-spring/.gitignore b/shib-thymeleaf-spring/.gitignore
new file mode 100644
index 00000000..d8e6f876
--- /dev/null
+++ b/shib-thymeleaf-spring/.gitignore
@@ -0,0 +1,21 @@
+# A simulation of Subversion default ignores, generated by reposurgeon.
+*.o
+*.lo
+*.la
+*.al
+*.libs
+*.so
+*.so.[0-9]*
+*.a
+*.pyc
+*.pyo
+*.rej
+*.iml
+*~
+*.#*
+.*.swp
+.DS_store
+# Simulated Subversion default ignores end here
+# The contents of the svn:ignore property on the branch root.
+/test-output
+/target
diff --git a/shib-thymeleaf-spring/pom.xml b/shib-thymeleaf-spring/pom.xml
new file mode 100644
index 00000000..3a65a335
--- /dev/null
+++ b/shib-thymeleaf-spring/pom.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>net.shibboleth</groupId>
+        <artifactId>shib-shared-parent</artifactId>
+        <version>9.1.0-SNAPSHOT</version>
+    </parent>
+
+    <name>Shibboleth Shared :: Thymeleaf Spring Support</name>
+    <artifactId>shib-thymeleaf-spring</artifactId>
+    <packaging>jar</packaging>
+
+    <properties>
+        <automatic.module.name>net.shibboleth.shared.spring.thymeleaf</automatic.module.name>
+        <checkstyle.configLocation>${project.basedir}/../resources/checkstyle/checkstyle.xml</checkstyle.configLocation>
+    </properties>
+
+    <dependencies>
+        <!-- Compile Dependencies -->
+        <dependency>
+            <groupId>${project.groupId}</groupId>
+            <artifactId>shib-support</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.thymeleaf</groupId>
+            <artifactId>thymeleaf-spring6</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>${spring.groupId}</groupId>
+            <artifactId>spring-webmvc</artifactId>
+        </dependency>
+
+        <!-- Runtime Dependencies -->
+
+        <!-- Test Dependencies -->
+    </dependencies>
+
+    <scm>
+        <connection>${shibboleth.scm.connection}java-shib-shared</connection>
+        <developerConnection>${shibboleth.scm.developerConnection}java-shib-shared</developerConnection>
+        <url>${shibboleth.scm.url}java-shib-shared.git</url>
+    </scm>
+
+</project>
diff --git a/shib-thymeleaf-spring/src/main/java/net/shibboleth/shared/spring/thymeleaf/ChainingThymeleafViewResolver.java b/shib-thymeleaf-spring/src/main/java/net/shibboleth/shared/spring/thymeleaf/ChainingThymeleafViewResolver.java
new file mode 100644
index 00000000..c21bd226
--- /dev/null
+++ b/shib-thymeleaf-spring/src/main/java/net/shibboleth/shared/spring/thymeleaf/ChainingThymeleafViewResolver.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.shibboleth.shared.spring.thymeleaf;
+
+import java.util.Collections;
+import java.util.Locale;
+import org.springframework.web.servlet.View;
+import org.thymeleaf.IEngineConfiguration;
+import org.thymeleaf.spring6.view.ThymeleafViewResolver;
+import org.thymeleaf.templateresolver.ITemplateResolver;
+
+/**
+ * View resolver for Thymeleaf templates that support chaining to the next view resolver in the chain if the
+ * template does not exists. This component is necessary for progressive adoption of Thymeleaf for IdP views.
+ *
+ * @author Marvin S. Addison
+ */
+public class ChainingThymeleafViewResolver extends ThymeleafViewResolver {
+    @Override
+    protected View loadView(String viewName, Locale locale) throws Exception {
+        return checkResource(viewName) ? super.loadView(viewName, locale) : null;
+    }
+
+    private boolean checkResource(final String viewName) {
+        final IEngineConfiguration config = getTemplateEngine().getConfiguration();
+        for (ITemplateResolver resolver : config.getTemplateResolvers()) {
+            if (resolver.resolveTemplate(config, null, viewName, Collections.emptyMap()) != null) {
+                return true;
+            }
+        }
+        return false;
+    }
+}

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list