This is an automated email from the ASF dual-hosted git repository. lukaszlenart pushed a commit to branch feature/sitemesh3 in repository https://gitbox.apache.org/repos/asf/struts-examples.git
commit 93a874c3e0497d53c0b887d1089db663bf9ca77e Author: Lukasz Lenart <lukaszlen...@apache.org> AuthorDate: Fri Oct 11 08:12:53 2024 +0200 Adds simple example with Sitemesh3 integration --- pom.xml | 1 + sitemesh3/README.md | 6 ++ sitemesh3/pom.xml | 69 ++++++++++++++++++++++ .../src/main/resources/DefaultMessages.properties | 5 ++ .../main/resources/DefaultMessages_es.properties | 5 ++ sitemesh3/src/main/resources/log4j2.xml | 14 +++++ sitemesh3/src/main/resources/struts.xml | 22 +++++++ .../main/webapp/WEB-INF/decorators/decorator.html | 9 +++ sitemesh3/src/main/webapp/WEB-INF/hello.jsp | 27 +++++++++ sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml | 3 + sitemesh3/src/main/webapp/WEB-INF/web.xml | 44 ++++++++++++++ sitemesh3/src/main/webapp/index.html | 10 ++++ 12 files changed, 215 insertions(+) diff --git a/pom.xml b/pom.xml index 994105d..debfc0c 100644 --- a/pom.xml +++ b/pom.xml @@ -122,6 +122,7 @@ <module>wildcard-method-selection</module> <module>wildcard-regex</module> <module>jasperreports</module> + <module>sitemesh3</module> </modules> <dependencyManagement> diff --git a/sitemesh3/README.md b/sitemesh3/README.md new file mode 100644 index 0000000..ca3308a --- /dev/null +++ b/sitemesh3/README.md @@ -0,0 +1,6 @@ +Struts 2 Sitemesh 3 example +================== + +Simple Struts 2 project which demonstrates Sitemesh 3 usage + +Published under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0.html) diff --git a/sitemesh3/pom.xml b/sitemesh3/pom.xml new file mode 100644 index 0000000..7f31a85 --- /dev/null +++ b/sitemesh3/pom.xml @@ -0,0 +1,69 @@ +<?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/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.struts</groupId> + <artifactId>struts-examples</artifactId> + <version>2.0.0</version> + </parent> + + <artifactId>sitemesh3</artifactId> + <name>Struts Sitemesh 3 Example</name> + + <packaging>war</packaging> + + <dependencies> + <dependency> + <groupId>org.sitemesh</groupId> + <artifactId>sitemesh</artifactId> + <version>3.2.1</version> + </dependency> + + <dependency> + <groupId>org.apache.struts</groupId> + <artifactId>struts2-config-browser-plugin</artifactId> + <version>${struts2.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <version>${log4j2.version}</version> + </dependency> + + <dependency> + <groupId>org.apache.struts</groupId> + <artifactId>struts2-junit-plugin</artifactId> + <version>${struts2.version}</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.13.2</version> + <scope>test</scope> + </dependency> + + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.eclipse.jetty</groupId> + <artifactId>jetty-maven-plugin</artifactId> + <version>${jetty-plugin.version}</version> + <configuration> + <webApp> + <contextPath>/${project.artifactId}</contextPath> + </webApp> + <stopKey>CTRL+C</stopKey> + <stopPort>8999</stopPort> + <scan>10</scan> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/sitemesh3/src/main/resources/DefaultMessages.properties b/sitemesh3/src/main/resources/DefaultMessages.properties new file mode 100644 index 0000000..074cd28 --- /dev/null +++ b/sitemesh3/src/main/resources/DefaultMessages.properties @@ -0,0 +1,5 @@ +HelloWorld.message = Struts is up and running... +requiredstring= ${getText(fieldName)} is required. +password = Password +username = User Name +Missing.message = This feature is under construction. Please try again in the next iteration. diff --git a/sitemesh3/src/main/resources/DefaultMessages_es.properties b/sitemesh3/src/main/resources/DefaultMessages_es.properties new file mode 100644 index 0000000..ce5d083 --- /dev/null +++ b/sitemesh3/src/main/resources/DefaultMessages_es.properties @@ -0,0 +1,5 @@ +HelloWorld.message = \u00A1Struts est\u00E1 bien\!... +requiredstring = ${getText(fieldName)} es requerido. +password = Contrase\u00F1a +username = Nombre de Usuario +Missing.message = P\u00E1gina bajo construcci\u00F3n, trate de nuevo en la proxima versi\u00F3n. \ No newline at end of file diff --git a/sitemesh3/src/main/resources/log4j2.xml b/sitemesh3/src/main/resources/log4j2.xml new file mode 100644 index 0000000..1f4e3df --- /dev/null +++ b/sitemesh3/src/main/resources/log4j2.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Configuration> + <Appenders> + <Console name="STDOUT" target="SYSTEM_OUT"> + <PatternLayout pattern="[%-5p] %C{2} (%F:%L) - %m%n"/> + </Console> + </Appenders> + <Loggers> + <Root level="info"> + <AppenderRef ref="STDOUT"/> + </Root> + <Logger name="org.apache.struts2.tiles" level="trace"/> + </Loggers> +</Configuration> diff --git a/sitemesh3/src/main/resources/struts.xml b/sitemesh3/src/main/resources/struts.xml new file mode 100644 index 0000000..e95c041 --- /dev/null +++ b/sitemesh3/src/main/resources/struts.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE struts PUBLIC + "-//Apache Software Foundation//DTD Struts Configuration 6.0//EN" + "https://struts.apache.org/dtds/struts-6.0.dtd"> +<struts> + <constant name="struts.devMode" value="true"/> + <constant name="struts.custom.i18n.resources" value="DefaultMessages"/> + + <package name="default" extends="struts-default"> + <default-action-ref name="index"/> + <action name="index"> + <result type="redirectAction"> + <param name="actionName">hello</param> + </result> + </action> + + <action name="hello"> + <result>/WEB-INF/hello.jsp</result> + </action> + + </package> +</struts> diff --git a/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator.html b/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator.html new file mode 100644 index 0000000..eeb64a1 --- /dev/null +++ b/sitemesh3/src/main/webapp/WEB-INF/decorators/decorator.html @@ -0,0 +1,9 @@ +<html> +<head> + <title><sitemesh:write property="title"/></title> + <sitemesh:write property="head"/> +</head> +<body> +<sitemesh:write property="body"/> +</body> +</html> \ No newline at end of file diff --git a/sitemesh3/src/main/webapp/WEB-INF/hello.jsp b/sitemesh3/src/main/webapp/WEB-INF/hello.jsp new file mode 100644 index 0000000..953de73 --- /dev/null +++ b/sitemesh3/src/main/webapp/WEB-INF/hello.jsp @@ -0,0 +1,27 @@ +<%@ page contentType="text/html; charset=UTF-8" %> +<%@ taglib prefix="s" uri="/struts-tags" %> +<html> +<head> + <title>SiteMesh example: Hello World</title> +</head> +<body> +<h2><s:text name="%{getText('HelloWorld.message')}"/></h2> + +<h3>Languages</h3> +<ul> + <li> + <s:url var="url" action="hello"> + <s:param name="request_locale">en</s:param> + </s:url> + <s:a href="%{url}">English</s:a> + </li> + <li> + <s:url var="url" action="hello"> + <s:param name="request_locale">es</s:param> + </s:url> + <s:a href="%{url}">Espanol</s:a> + </li> +</ul> +EL: ${url} +</body> +</html> diff --git a/sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml b/sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml new file mode 100644 index 0000000..77fbc3b --- /dev/null +++ b/sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml @@ -0,0 +1,3 @@ +<sitemesh> + <mapping path="/*" decorator="decorator.html"/> +</sitemesh> \ No newline at end of file diff --git a/sitemesh3/src/main/webapp/WEB-INF/web.xml b/sitemesh3/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..ff5bac7 --- /dev/null +++ b/sitemesh3/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="UTF-8"?> +<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee + http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" + version="3.1"> + + <display-name>Struts Tiles 2 Demo</display-name> + + <filter> + <filter-name>struts2-prepare</filter-name> + <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareFilter</filter-class> + </filter> + + <filter> + <filter-name>sitemesh</filter-name> + <filter-class>org.sitemesh.config.ConfigurableSiteMeshFilter</filter-class> + </filter> + + <filter> + <filter-name>struts2-execute</filter-name> + <filter-class>org.apache.struts2.dispatcher.filter.StrutsExecuteFilter</filter-class> + </filter> + + <filter-mapping> + <filter-name>struts2-prepare</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + <filter-mapping> + <filter-name>sitemesh</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + <filter-mapping> + <filter-name>struts2-execute</filter-name> + <url-pattern>/*</url-pattern> + </filter-mapping> + + <welcome-file-list> + <welcome-file>/index.html</welcome-file> + </welcome-file-list> + +</web-app> diff --git a/sitemesh3/src/main/webapp/index.html b/sitemesh3/src/main/webapp/index.html new file mode 100644 index 0000000..dc2bbd0 --- /dev/null +++ b/sitemesh3/src/main/webapp/index.html @@ -0,0 +1,10 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> +<html> +<head> + <META HTTP-EQUIV="Refresh" CONTENT="0;URL=example/HelloWorld.action"> +</head> + +<body> +<p>Loading ...</p> +</body> +</html>