WW-1340 Add "tutorial" module to blank, corresponding with "Bootstrap" tutorial in documentation.

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@440388 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ted Nathan Husted
2006-09-05 16:37:18 +00:00
parent 1f188dbcce
commit 70da30113d
20 changed files with 324 additions and 126 deletions
+14 -14
View File
@@ -3,25 +3,25 @@
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.struts</groupId>
<artifactId>struts2-apps</artifactId>
<version>2.0.0-SNAPSHOT</version>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-apps</artifactId>
<version>2.0.0-SNAPSHOT</version>
</parent>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-blank</artifactId>
<packaging>war</packaging>
<name>Blank Webapp</name>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
@@ -41,6 +41,6 @@
</plugin>
</plugins>
</build>
</project>
@@ -1,57 +0,0 @@
/*
* $Id$
*
* Copyright 2006 The Apache Software Foundation.
*
* 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 example;
import com.opensymphony.xwork2.ActionSupport;
/**
* <code>Set welcome message.</code>
*
*/
public class Welcome extends ActionSupport {
private static final long serialVersionUID = -3881551454078687096L;
public static final String MESSAGE = "Struts is up and running ...";
public String execute() throws Exception {
setMessage(MESSAGE);
return SUCCESS;
}
/**
* Field for Message property.
*/
private String message;
/**
* Return Message property.
* @return Message property
*/
public String getMessage() {
return message;
}
/**
* Set Message property.
* @param message Text to display on Welcome page.
*/
public void setMessage(String message){
this.message = message;
}
}
@@ -0,0 +1,37 @@
package tutorial;
/**
* <code>Set welcome message.</code>
*/
public class HelloWorld extends TutorialSupport {
public static final String MESSAGE = "HelloWorld.message";
public String execute() throws Exception {
setMessage(getText(MESSAGE));
return SUCCESS;
}
/**
* Field for Message property.
*/
private String message;
/**
* Return Message property.
*
* @return Message property
*/
public String getMessage() {
return message;
}
/**
* Set Message property.
*
* @param message Text to display on HelloWorld page.
*/
public void setMessage(String message) {
this.message = message;
}
}
@@ -0,0 +1,16 @@
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="username">
<field-validator type="requiredstring">
<message key="username.required"/>
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<message key="password.required"/>
</field-validator>
</field>
</validators>
@@ -0,0 +1,38 @@
package tutorial;
public class Login extends TutorialSupport {
public String execute() throws Exception {
if (isInvalid(getUsername())) return INPUT;
if (isInvalid(getPassword())) return INPUT;
return SUCCESS;
}
private boolean isInvalid(String value) {
return (value == null || value.length() == 0);
}
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
private String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
@@ -0,0 +1,9 @@
package tutorial;
import com.opensymphony.xwork2.ActionSupport;
/**
* Base Action class for the Tutorial package.
*/
public class TutorialSupport extends ActionSupport {
}
@@ -0,0 +1,7 @@
password = Password
password.required = Password is required.
username = User Name
username.required = User Name is required.
HelloWorld.message= Struts is up and running ...
Missing.message = This feature is under construction. Please try again in the next interation.
+5 -8
View File
@@ -1,16 +1,13 @@
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml"/>
<package name="example" extends="struts-default">
<include file="tutorial.xml"/>
<action name="*" class="example.{1}">
<result>/example/{1}.jsp</result>
</action>
<!-- Add packages here -->
<!-- Add your actions here -->
</package>
</struts>
@@ -0,0 +1,24 @@
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="tutorial" namespace="/tutorial" extends="struts-default">
<action name="HelloWorld" class="tutorial.HelloWorld">
<result>/tutorial/HelloWorld.jsp</result>
</action>
<action name="Login!*" method="{1}" class="tutorial.Login">
<result name="input">/tutorial/Login.jsp</result>
<result type="redirect-action">Menu</result>
</action>
<action name="*" class="tutorial.TutorialSupport">
<result>/tutorial/{1}.jsp</result>
</action>
<!-- Add actions here -->
</package>
</struts>
@@ -1,10 +0,0 @@
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Welcome</title>
</head>
<body>
<h2><s:property value="message" /></h2>
</body>
</html>
+11 -1
View File
@@ -1 +1,11 @@
<% response.sendRedirect(request.getContextPath() + "/Welcome.action"); %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=<s:url action="Welcome" namespace="tutorial"/>">
</head>
<body>
<p>Loading ...</p>
</body>
</html>
@@ -0,0 +1,11 @@
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Hello World!</title>
</head>
<body>
<h2><s:property value="message"/></h2>
</body>
</html>
@@ -0,0 +1,15 @@
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Logon</title>
</head>
<body>
<s:form action="Login">
<s:textfield label="%{getText('username')}" name="username"/>
<s:textfield label="%{getText('password')}" name="password"/>
<s:submit/>
</s:form>
</body>
</html>
@@ -0,0 +1,3 @@
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<s:include value="Missing.jsp"/>
@@ -0,0 +1,11 @@
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head><title>Missing Feature</title></head>
<body>
<p>
<s:text name="Missing.message"/>
</p>
</body>
</html>
@@ -0,0 +1,35 @@
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Welcome</title>
<link href="<s:url value="/css/tutorial.css"/>" rel="stylesheet"
type="text/css"/>
</head>
<body>
<h3>Commands</h3>
<ul>
<li><a href="<s:url action="Register"/>">Register</a></li>
<li><a href="<s:url action="Login!input"/>">Sign On</a></li>
</ul>
<h3>Languages</h3>
<ul>
<li>
<s:url id="url" action="Welcome">
<s:param name="request_locale">en</s:param>
</s:url>
<s:a href="%{url}">English</s:a>
</li>
<li>
<s:url id="url" action="Welcome">
<s:param name="request_locale">ja</s:param>
</s:url>
<s:a href="%{url}">Japanese</s:a>
</li>
</ul>
</body>
</html>
@@ -1,36 +0,0 @@
/*
* $Id: WelcomeTest.java 418530 2006-07-01 23:58:13Z mrdon $
*
* Copyright 2006 The Apache Software Foundation.
*
* 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 example;
import junit.framework.TestCase;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;
/**
* <code>WelcomeTest</code>
*
*/
public class WelcomeTest extends TestCase {
public void testWelcome() throws Exception {
Welcome welcome = new Welcome();
String result = welcome.execute();
assertEquals(ActionSupport.SUCCESS, result);
assertEquals(welcome.getMessage(), Welcome.MESSAGE);
}
}
@@ -0,0 +1,50 @@
package tutorial;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.XWorkTestCase;
import com.opensymphony.xwork2.config.RuntimeConfiguration;
import com.opensymphony.xwork2.config.entities.ActionConfig;
import com.opensymphony.xwork2.config.entities.ResultConfig;
import com.opensymphony.xwork2.config.providers.XmlConfigurationProvider;
import java.util.Map;
public class ConfigTest extends XWorkTestCase {
protected void AssertSuccess(String result) throws Exception {
assertTrue("Expected a success result!",
ActionSupport.SUCCESS.equals(result));
}
protected void setUp() throws Exception {
super.setUp();
XmlConfigurationProvider c = new XmlConfigurationProvider("struts.xml");
configurationManager.addConfigurationProvider(c);
configurationManager.reload();
}
protected ActionConfig assertClass(String action_name, String class_name) {
RuntimeConfiguration configuration = configurationManager.getConfiguration().getRuntimeConfiguration();
ActionConfig config = configuration.getActionConfig("", action_name);
assertNotNull("Mssing action", config);
assertTrue("Wrong class name: [" + config.getClassName() + "]",
class_name.equals(config.getClassName()));
return config;
}
protected void assertResult(ActionConfig config, String result_name, String result_value) {
Map results = config.getResults();
ResultConfig result = (ResultConfig) results.get(result_name);
Map params = result.getParams();
String value = (String) params.get("actionName");
if (value == null)
value = (String) params.get("location");
assertTrue("Wrong result value: [" + value + "]",
result_value.equals(value));
}
public void testConfig() throws Exception {
assertNotNull(configurationManager);
}
}
@@ -0,0 +1,16 @@
package tutorial;
import com.opensymphony.xwork2.ActionSupport;
import junit.framework.TestCase;
public class HelloWorldTest extends TestCase {
public void testHelloWorld() throws Exception {
HelloWorld hello_world = new HelloWorld();
String result = hello_world.execute();
assertTrue("Expected a success result!",
ActionSupport.SUCCESS.equals(result));
assertTrue("Expected the default message!",
hello_world.getText(HelloWorld.MESSAGE).equals(hello_world.getMessage()));
}
}
@@ -0,0 +1,22 @@
package tutorial;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.config.entities.ActionConfig;
public class LoginTest extends ConfigTest {
public void FIXME_testLoginConfig() throws Exception {
ActionConfig config = assertClass("Login", "tutorial.Login");
assertResult(config, ActionSupport.SUCCESS, "Menu");
assertResult(config, ActionSupport.INPUT, "/tutorial/Login.jsp");
}
public void testLoginSubmit() throws Exception {
Login login = new Login();
login.setUsername("username");
login.setPassword("password");
String result = login.execute();
AssertSuccess(result);
}
}