Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 6 additions & 15 deletions sitemesh3/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@
<packaging>war</packaging>

<properties>
<!--
it doesn't work with latest changes
https://github.com/apache/struts/pull/1265
<struts2.version>7.0.4-SNAPSHOT</struts2.version>
-->
<!-- it works with version where FORWARD_SERVLET_PATH is updated -->
<struts2.version>7.0.3</struts2.version>
</properties>

<dependencies>
Expand All @@ -35,21 +41,6 @@
<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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.struts.examples.sitemesh3;

import org.apache.struts2.ActionSupport;
import org.apache.struts2.action.UploadedFilesAware;
import org.apache.struts2.dispatcher.multipart.UploadedFile;

import java.io.File;
import java.util.List;

/**
* <code>Allows upload a file</code>
*/
public class UploadAction extends ActionSupport implements UploadedFilesAware {

private File[] upload;
private String[] uploadFileName;
private String[] uploadContentType;

public String execute() throws Exception {
return INPUT;
}

public File[] getUpload() {
return upload;
}

public String[] getUploadFileName() {
return uploadFileName;
}

public String[] getUploadContentType() {
return uploadContentType;
}

@Override
public void withUploadedFiles(List<UploadedFile> uploadedFiles) {
upload = uploadedFiles.stream().map(UploadedFile::getContent).toArray(File[]::new);
uploadFileName = uploadedFiles.stream().map(UploadedFile::getName).toArray(String[]::new);
uploadContentType = uploadedFiles.stream().map(UploadedFile::getContentType).toArray(String[]::new);
}
}
4 changes: 2 additions & 2 deletions sitemesh3/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<Configuration>
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="[%-5p] %C{2} (%F:%L) - %m%n"/>
<PatternLayout pattern="[%p] %C{2} (%F:%L): %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="info">
<AppenderRef ref="STDOUT"/>
</Root>
<Logger name="org.apache.struts2.tiles" level="trace"/>
<Logger name="org.apache.struts2" level="info"/>
</Loggers>
</Configuration>
3 changes: 3 additions & 0 deletions sitemesh3/src/main/resources/struts.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<result name="error">/WEB-INF/error.jsp</result>
</action>

<action name="upload" class="org.apache.struts.examples.sitemesh3.UploadAction">
<result name="input">/WEB-INF/upload.jsp</result>
</action>
</package>

<package name="default2" extends="struts-default" namespace="/admin">
Expand Down
3 changes: 2 additions & 1 deletion sitemesh3/src/main/webapp/WEB-INF/admin/hello.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
</head>
<body>
<h2>SiteMesh example: Admin Index with Default Decorator</h2>
<s:url var="url" action="hello" namespace="/">
<s:url var="url" action="hello" namespace="/admin">
<s:param name="decorator" value="1"/>
</s:url>
<s:a href="%{url}">Hello</s:a>
<s:a action="index" namespace="/admin">Admin Index</s:a>
</body>
</html>
3 changes: 2 additions & 1 deletion sitemesh3/src/main/webapp/WEB-INF/admin/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
</head>
<body>
<h2>SiteMesh example: Admin Index with Default Decorator</h2>
<s:url var="url" action="hello" namespace="/">
<s:a action="index" namespace="/">Index</s:a>
<s:url var="url" action="hello" namespace="/admin">
<s:param name="decorator" value="1"/>
</s:url>
<s:a href="%{url}">Hello</s:a>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html>
<html lang="en">
<head>
<title><sitemesh:write property="title"/></title>
<sitemesh:write property="head"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html>
<html lang="en">
<head>
<title><sitemesh:write property="title"/></title>
<sitemesh:write property="head"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<html>
<html lang="en">
<head>
<title><sitemesh:write property="title"/></title>
<sitemesh:write property="head"/>
Expand Down
10 changes: 10 additions & 0 deletions sitemesh3/src/main/webapp/WEB-INF/decorators/upload-decorator.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html lang="en">
<head>
<title><sitemesh:write property="title"/></title>
<sitemesh:write property="head"/>
</head>
<body>
<h1>Upload Decorator</h1>
<sitemesh:write property="body"/>
</body>
</html>
1 change: 1 addition & 0 deletions sitemesh3/src/main/webapp/WEB-INF/hello1.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
</s:form>
</div>
<p>Selected decorator: <s:property value="decorator"/></p>
<s:a action="index">Index</s:a>
</body>
</html>
3 changes: 2 additions & 1 deletion sitemesh3/src/main/webapp/WEB-INF/hello2.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<title>SiteMesh example: Hello 2 with Decorator 2</title>
</head>
<body>
<h2>SiteMesh example: Hello 2 with Decorator 2</h1>
<h2>SiteMesh example: Hello 2 with Decorator 2</h2>
<h3>Decorators</h3>
<div>
<s:form action="hello" method="get">
Expand All @@ -14,5 +14,6 @@
</s:form>
</div>
<p>Selected decorator: <s:property value="decorator"/></p>
<s:a action="index">Index</s:a>
</body>
</html>
2 changes: 2 additions & 0 deletions sitemesh3/src/main/webapp/WEB-INF/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,7 @@
<s:param name="decorator" value="1"/>
</s:url>
<s:a href="%{url}">Hello</s:a>
<s:a action="index" namespace="/admin">Admin</s:a>
<s:a action="upload">Upload</s:a>
</body>
</html>
1 change: 1 addition & 0 deletions sitemesh3/src/main/webapp/WEB-INF/sitemesh3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<mapping path="/WEB-INF/error.jsp" exclude="true"/>
<mapping path="/WEB-INF/hello1.jsp" decorator="decorator1.html"/>
<mapping path="/WEB-INF/hello2.jsp" decorator="decorator2.html"/>
<mapping path="/WEB-INF/upload.jsp" decorator="upload-decorator.html"/>
</sitemesh>
30 changes: 30 additions & 0 deletions sitemesh3/src/main/webapp/WEB-INF/upload.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Sitemesh example: File upload</title>
</head>
<body>
<h2>Sitemesh example: Upload with Upload Decorator</h2>
<s:form action="upload" method="post" enctype="multipart/form-data" theme="xhtml">
<s:file name="upload"/>
<s:file name="upload"/>
<s:file name="upload"/>
<s:submit/>
</s:form>

<s:actionerror/>

<s:iterator value="upload" var="u">
File: <s:property value="u"/><br/>
</s:iterator>
<s:iterator value="uploadContentType" var="ct">
Content-Type: <s:property value="ct"/><br/>
</s:iterator>
<s:iterator value="uploadFileName" var="fn">
File name: <s:property value="fn"/><br/>
</s:iterator>

<s:a action="index">Index</s:a>
</body>
</html>
4 changes: 2 additions & 2 deletions sitemesh3/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">

<display-name>Struts Tiles 2 Demo</display-name>
<display-name>Struts Sitemesh 3 Demo</display-name>

<filter>
<filter-name>struts2-prepare</filter-name>
Expand Down Expand Up @@ -38,7 +38,7 @@
</filter-mapping>

<welcome-file-list>
<welcome-file>/index.html</welcome-file>
<welcome-file>/index</welcome-file>
</welcome-file-list>

</web-app>
10 changes: 0 additions & 10 deletions sitemesh3/src/main/webapp/index.html

This file was deleted.