Skip to content

Commit 5f2495d

Browse files
authored
Merge pull request #461 from apache/feature/sitemesh3-upload
Integrates upload example with Sitemesh 3
2 parents 4e78fd7 + 5f006c1 commit 5f2495d

17 files changed

Lines changed: 126 additions & 35 deletions

File tree

sitemesh3/pom.xml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
<packaging>war</packaging>
1515

1616
<properties>
17+
<!--
18+
it doesn't work with latest changes
19+
https://github.com/apache/struts/pull/1265
1720
<struts2.version>7.0.4-SNAPSHOT</struts2.version>
21+
-->
22+
<!-- it works with version where FORWARD_SERVLET_PATH is updated -->
23+
<struts2.version>7.0.3</struts2.version>
1824
</properties>
1925

2026
<dependencies>
@@ -35,21 +41,6 @@
3541
<artifactId>log4j-slf4j-impl</artifactId>
3642
<version>${log4j2.version}</version>
3743
</dependency>
38-
39-
<dependency>
40-
<groupId>org.apache.struts</groupId>
41-
<artifactId>struts2-junit-plugin</artifactId>
42-
<version>${struts2.version}</version>
43-
<scope>test</scope>
44-
</dependency>
45-
46-
<dependency>
47-
<groupId>junit</groupId>
48-
<artifactId>junit</artifactId>
49-
<version>4.13.2</version>
50-
<scope>test</scope>
51-
</dependency>
52-
5344
</dependencies>
5445

5546
<build>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.apache.struts.examples.sitemesh3;
21+
22+
import org.apache.struts2.ActionSupport;
23+
import org.apache.struts2.action.UploadedFilesAware;
24+
import org.apache.struts2.dispatcher.multipart.UploadedFile;
25+
26+
import java.io.File;
27+
import java.util.List;
28+
29+
/**
30+
* <code>Allows upload a file</code>
31+
*/
32+
public class UploadAction extends ActionSupport implements UploadedFilesAware {
33+
34+
private File[] upload;
35+
private String[] uploadFileName;
36+
private String[] uploadContentType;
37+
38+
public String execute() throws Exception {
39+
return INPUT;
40+
}
41+
42+
public File[] getUpload() {
43+
return upload;
44+
}
45+
46+
public String[] getUploadFileName() {
47+
return uploadFileName;
48+
}
49+
50+
public String[] getUploadContentType() {
51+
return uploadContentType;
52+
}
53+
54+
@Override
55+
public void withUploadedFiles(List<UploadedFile> uploadedFiles) {
56+
upload = uploadedFiles.stream().map(UploadedFile::getContent).toArray(File[]::new);
57+
uploadFileName = uploadedFiles.stream().map(UploadedFile::getName).toArray(String[]::new);
58+
uploadContentType = uploadedFiles.stream().map(UploadedFile::getContentType).toArray(String[]::new);
59+
}
60+
}

sitemesh3/src/main/resources/log4j2.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
<Configuration>
33
<Appenders>
44
<Console name="STDOUT" target="SYSTEM_OUT">
5-
<PatternLayout pattern="[%-5p] %C{2} (%F:%L) - %m%n"/>
5+
<PatternLayout pattern="[%p] %C{2} (%F:%L): %m%n"/>
66
</Console>
77
</Appenders>
88
<Loggers>
99
<Root level="info">
1010
<AppenderRef ref="STDOUT"/>
1111
</Root>
12-
<Logger name="org.apache.struts2.tiles" level="trace"/>
12+
<Logger name="org.apache.struts2" level="info"/>
1313
</Loggers>
1414
</Configuration>

sitemesh3/src/main/resources/struts.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
<result name="error">/WEB-INF/error.jsp</result>
2121
</action>
2222

23+
<action name="upload" class="org.apache.struts.examples.sitemesh3.UploadAction">
24+
<result name="input">/WEB-INF/upload.jsp</result>
25+
</action>
2326
</package>
2427

2528
<package name="default2" extends="struts-default" namespace="/admin">

sitemesh3/src/main/webapp/WEB-INF/admin/hello.jsp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
</head>
77
<body>
88
<h2>SiteMesh example: Admin Index with Default Decorator</h2>
9-
<s:url var="url" action="hello" namespace="/">
9+
<s:url var="url" action="hello" namespace="/admin">
1010
<s:param name="decorator" value="1"/>
1111
</s:url>
1212
<s:a href="%{url}">Hello</s:a>
13+
<s:a action="index" namespace="/admin">Admin Index</s:a>
1314
</body>
1415
</html>

sitemesh3/src/main/webapp/WEB-INF/admin/index.jsp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
</head>
77
<body>
88
<h2>SiteMesh example: Admin Index with Default Decorator</h2>
9-
<s:url var="url" action="hello" namespace="/">
9+
<s:a action="index" namespace="/">Index</s:a>
10+
<s:url var="url" action="hello" namespace="/admin">
1011
<s:param name="decorator" value="1"/>
1112
</s:url>
1213
<s:a href="%{url}">Hello</s:a>

sitemesh3/src/main/webapp/WEB-INF/decorators/decorator.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<html>
1+
<html lang="en">
22
<head>
33
<title><sitemesh:write property="title"/></title>
44
<sitemesh:write property="head"/>

sitemesh3/src/main/webapp/WEB-INF/decorators/decorator1.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<html>
1+
<html lang="en">
22
<head>
33
<title><sitemesh:write property="title"/></title>
44
<sitemesh:write property="head"/>

sitemesh3/src/main/webapp/WEB-INF/decorators/decorator2.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<html>
1+
<html lang="en">
22
<head>
33
<title><sitemesh:write property="title"/></title>
44
<sitemesh:write property="head"/>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<html lang="en">
2+
<head>
3+
<title><sitemesh:write property="title"/></title>
4+
<sitemesh:write property="head"/>
5+
</head>
6+
<body>
7+
<h1>Upload Decorator</h1>
8+
<sitemesh:write property="body"/>
9+
</body>
10+
</html>

0 commit comments

Comments
 (0)