You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by as...@apache.org on 2019/03/25 21:28:41 UTC

[portals-pluto] branch master updated: PLUTO-748 Develop the thymeleaf-mvc-portlet-api module

This is an automated email from the ASF dual-hosted git repository.

asfgriff pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/portals-pluto.git


The following commit(s) were added to refs/heads/master by this push:
     new 17d5566  PLUTO-748 Develop the thymeleaf-mvc-portlet-api module
17d5566 is described below

commit 17d5566fc103dfbfcdba1664b10bb344ed30f7c6
Author: Neil Griffin <ne...@gmail.com>
AuthorDate: Mon Mar 25 17:28:06 2019 -0400

    PLUTO-748 Develop the thymeleaf-mvc-portlet-api module
---
 pom.xml                                            | 18 +++++
 .../thymeleaf-mvc-portlet-api/pom.xml              | 81 ++++++++++++++++++++++
 .../thymeleaf/mvc/portlet/ThymeleafViewEngine.java | 60 ++++++++++++++++
 .../thymeleaf/mvc/portlet/WriterSupplier.java      | 34 +++++++++
 4 files changed, 193 insertions(+)

diff --git a/pom.xml b/pom.xml
index 30e4a3b..37a992d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -350,6 +350,18 @@ TODO: Check if we need all of them. -->
 
       <!-- Specification Libraries =========================================== -->
       <dependency>
+        <groupId>javax.inject</groupId>
+        <artifactId>javax.inject</artifactId>
+        <version>1</version>
+        <scope>provided</scope>
+      </dependency>
+      <dependency>
+        <groupId>javax.mvc</groupId>
+        <artifactId>javax.mvc-api</artifactId>
+        <version>1.0-pfd</version>
+        <scope>provided</scope>
+      </dependency>
+      <dependency>
          <groupId>javax.portlet</groupId>
          <artifactId>portlet-api</artifactId>
          <version>${project.version}</version>
@@ -362,6 +374,12 @@ TODO: Check if we need all of them. -->
         <scope>provided</scope>
       </dependency>
       <dependency>
+        <groupId>javax.ws.rs</groupId>
+        <artifactId>javax.ws.rs-api</artifactId>
+        <version>2.1.1</version>
+        <scope>provided</scope>
+      </dependency>
+      <dependency>
         <groupId>org.apache.tomcat</groupId>
         <artifactId>tomcat-servlet-api</artifactId>
         <version>${tomcat.servlet-api.version}</version>
diff --git a/portlet-templating/thymeleaf-mvc-portlet-api/pom.xml b/portlet-templating/thymeleaf-mvc-portlet-api/pom.xml
new file mode 100644
index 0000000..baf1284
--- /dev/null
+++ b/portlet-templating/thymeleaf-mvc-portlet-api/pom.xml
@@ -0,0 +1,81 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor 
+   license agreements. See the NOTICE file distributed with this work for additional 
+   information regarding copyright ownership. The ASF licenses this file to 
+   you 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. -->
+<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>org.apache.portals.pluto</groupId>
+		<artifactId>portlet-templating</artifactId>
+		<version>3.0.2-SNAPSHOT</version>
+		<relativePath>../pom.xml</relativePath>
+	</parent>
+	<artifactId>thymeleaf-mvc-portlet-api</artifactId>
+	<name>Thymeleaf MVC Portlet API</name>
+
+	<dependencies>
+		<dependency>
+			<groupId>javax.inject</groupId>
+			<artifactId>javax.inject</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>javax.mvc</groupId>
+			<artifactId>javax.mvc-api</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>javax.servlet</groupId>
+			<artifactId>javax.servlet-api</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>javax.portlet</groupId>
+			<artifactId>portlet-api</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>javax.ws.rs</groupId>
+			<artifactId>javax.ws.rs-api</artifactId>
+			<scope>provided</scope>
+		</dependency>
+		<dependency>
+			<groupId>org.apache.portals.pluto</groupId>
+			<artifactId>thymeleaf-portlet-api</artifactId>
+			<version>${project.version}</version>
+		</dependency>
+		<dependency>
+			<groupId>org.thymeleaf</groupId>
+			<artifactId>thymeleaf</artifactId>
+			<exclusions>
+				<exclusion>
+					<groupId>ognl</groupId>
+					<artifactId>ognl</artifactId>
+				</exclusion>
+			</exclusions>
+		</dependency>
+	</dependencies>
+
+	<build>
+		<plugins>
+			<plugin>
+				<groupId>org.apache.maven.plugins</groupId>
+				<artifactId>maven-compiler-plugin</artifactId>
+				<configuration>
+					<source>1.8</source>
+					<target>1.8</target>
+				</configuration>
+			</plugin>
+		</plugins>
+	</build>
+
+</project>
diff --git a/portlet-templating/thymeleaf-mvc-portlet-api/src/main/java/org/apache/pluto/thymeleaf/mvc/portlet/ThymeleafViewEngine.java b/portlet-templating/thymeleaf-mvc-portlet-api/src/main/java/org/apache/pluto/thymeleaf/mvc/portlet/ThymeleafViewEngine.java
new file mode 100644
index 0000000..afcf1c1
--- /dev/null
+++ b/portlet-templating/thymeleaf-mvc-portlet-api/src/main/java/org/apache/pluto/thymeleaf/mvc/portlet/ThymeleafViewEngine.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.pluto.thymeleaf.mvc.portlet;
+
+import javax.mvc.engine.ViewEngine;
+import javax.mvc.engine.ViewEngineContext;
+import javax.mvc.engine.ViewEngineException;
+
+import org.thymeleaf.TemplateEngine;
+
+import org.thymeleaf.context.IWebContext;
+
+
+/**
+ * This class implements the MVC {@link ViewEngine} interface in order to help support Thymeleaf views in a portlet
+ * application.
+ *
+ * @author  Neil Griffin
+ */
+public class ThymeleafViewEngine implements ViewEngine {
+
+	private TemplateEngine templateEngine;
+	private IWebContext webContext;
+	private WriterSupplier writerSupplier;
+
+	public ThymeleafViewEngine(TemplateEngine templateEngine, IWebContext webContext, WriterSupplier writerSupplier) {
+		this.templateEngine = templateEngine;
+		this.webContext = webContext;
+		this.writerSupplier = writerSupplier;
+	}
+
+	@Override
+	public void processView(ViewEngineContext viewEngineContext) throws ViewEngineException {
+		templateEngine.process(viewEngineContext.getView(), webContext, writerSupplier.get(viewEngineContext));
+	}
+
+	@Override
+	public boolean supports(String view) {
+
+		if (view == null) {
+			return false;
+		}
+
+		return view.endsWith(".html");
+	}
+}
diff --git a/portlet-templating/thymeleaf-mvc-portlet-api/src/main/java/org/apache/pluto/thymeleaf/mvc/portlet/WriterSupplier.java b/portlet-templating/thymeleaf-mvc-portlet-api/src/main/java/org/apache/pluto/thymeleaf/mvc/portlet/WriterSupplier.java
new file mode 100644
index 0000000..af154f3
--- /dev/null
+++ b/portlet-templating/thymeleaf-mvc-portlet-api/src/main/java/org/apache/pluto/thymeleaf/mvc/portlet/WriterSupplier.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 org.apache.pluto.thymeleaf.mvc.portlet;
+
+import java.io.Writer;
+
+import javax.mvc.engine.ViewEngineContext;
+import javax.mvc.engine.ViewEngineException;
+
+
+/**
+ * This class provides a way to obtain a {@link Writer} that is associated with an MVC {@link ViewEngineContext}.
+ *
+ * @author  Neil Griffin
+ */
+@FunctionalInterface
+public interface WriterSupplier {
+
+	public Writer get(ViewEngineContext viewEngineContext) throws ViewEngineException;
+}