mirror of
https://github.com/apache/struts.git
synced 2026-08-06 07:06:58 +00:00
Added svn:eol-style native property to .java files.
WW-1432 git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@440591 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package example;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
/**
|
||||
* Base Action class for the Tutorial package.
|
||||
*/
|
||||
public class ExampleSupport extends ActionSupport {
|
||||
}
|
||||
package example;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
/**
|
||||
* Base Action class for the Tutorial package.
|
||||
*/
|
||||
public class ExampleSupport extends ActionSupport {
|
||||
}
|
||||
|
||||
@@ -1,38 +1,38 @@
|
||||
package example;
|
||||
|
||||
public class Login extends ExampleSupport {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
package example;
|
||||
|
||||
public class Login extends ExampleSupport {
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,75 +1,75 @@
|
||||
package example;
|
||||
|
||||
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;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigTest extends XWorkTestCase {
|
||||
|
||||
protected void assertSuccess(String result) throws Exception {
|
||||
assertTrue("Expected a success result!",
|
||||
ActionSupport.SUCCESS.equals(result));
|
||||
}
|
||||
|
||||
protected void assertInput(String result) throws Exception {
|
||||
assertTrue("Expected an input result!",
|
||||
ActionSupport.INPUT.equals(result));
|
||||
}
|
||||
|
||||
protected Map assertFieldErrors(ActionSupport action) throws Exception {
|
||||
assertTrue(action.hasFieldErrors());
|
||||
return action.getFieldErrors();
|
||||
}
|
||||
|
||||
protected void assertFieldError(Map field_errors, String field_name, String error_message) {
|
||||
|
||||
List errors = (List) field_errors.get(field_name);
|
||||
assertNotNull("Expected errors for " + field_name, errors);
|
||||
assertTrue("Expected errors for " + field_name, errors.size()>0);
|
||||
// TODO: Should be a loop
|
||||
assertEquals(error_message,errors.get(0));
|
||||
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
XmlConfigurationProvider c = new XmlConfigurationProvider("struts.xml");
|
||||
configurationManager.addConfigurationProvider(c);
|
||||
configurationManager.reload();
|
||||
}
|
||||
|
||||
protected ActionConfig assertClass(String namespace, String action_name, String class_name) {
|
||||
RuntimeConfiguration configuration = configurationManager.getConfiguration().getRuntimeConfiguration();
|
||||
ActionConfig config = configuration.getActionConfig(namespace, action_name);
|
||||
assertNotNull("Mssing action", config);
|
||||
assertTrue("Wrong class name: [" + config.getClassName() + "]",
|
||||
class_name.equals(config.getClassName()));
|
||||
return config;
|
||||
}
|
||||
|
||||
protected ActionConfig assertClass(String action_name, String class_name) {
|
||||
return assertClass("", action_name, class_name);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
package example;
|
||||
|
||||
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;
|
||||
import java.util.List;
|
||||
|
||||
public class ConfigTest extends XWorkTestCase {
|
||||
|
||||
protected void assertSuccess(String result) throws Exception {
|
||||
assertTrue("Expected a success result!",
|
||||
ActionSupport.SUCCESS.equals(result));
|
||||
}
|
||||
|
||||
protected void assertInput(String result) throws Exception {
|
||||
assertTrue("Expected an input result!",
|
||||
ActionSupport.INPUT.equals(result));
|
||||
}
|
||||
|
||||
protected Map assertFieldErrors(ActionSupport action) throws Exception {
|
||||
assertTrue(action.hasFieldErrors());
|
||||
return action.getFieldErrors();
|
||||
}
|
||||
|
||||
protected void assertFieldError(Map field_errors, String field_name, String error_message) {
|
||||
|
||||
List errors = (List) field_errors.get(field_name);
|
||||
assertNotNull("Expected errors for " + field_name, errors);
|
||||
assertTrue("Expected errors for " + field_name, errors.size()>0);
|
||||
// TODO: Should be a loop
|
||||
assertEquals(error_message,errors.get(0));
|
||||
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
XmlConfigurationProvider c = new XmlConfigurationProvider("struts.xml");
|
||||
configurationManager.addConfigurationProvider(c);
|
||||
configurationManager.reload();
|
||||
}
|
||||
|
||||
protected ActionConfig assertClass(String namespace, String action_name, String class_name) {
|
||||
RuntimeConfiguration configuration = configurationManager.getConfiguration().getRuntimeConfiguration();
|
||||
ActionConfig config = configuration.getActionConfig(namespace, action_name);
|
||||
assertNotNull("Mssing action", config);
|
||||
assertTrue("Wrong class name: [" + config.getClassName() + "]",
|
||||
class_name.equals(config.getClassName()));
|
||||
return config;
|
||||
}
|
||||
|
||||
protected ActionConfig assertClass(String action_name, String class_name) {
|
||||
return assertClass("", action_name, class_name);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package example;
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
package example;
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
package example;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class LoginTest extends ConfigTest {
|
||||
|
||||
public void FIXME_testLoginConfig() throws Exception {
|
||||
ActionConfig config = assertClass("example", "Login!input", "example.Login");
|
||||
assertResult(config, ActionSupport.SUCCESS, "Menu");
|
||||
assertResult(config, ActionSupport.INPUT, "/example/Login.jsp");
|
||||
}
|
||||
|
||||
public void testLoginSubmit() throws Exception {
|
||||
Login login = new Login();
|
||||
login.setUsername("username");
|
||||
login.setPassword("password");
|
||||
String result = login.execute();
|
||||
assertSuccess(result);
|
||||
}
|
||||
|
||||
// Needs access to an envinronment that includes validators
|
||||
public void FIXME_testLoginSubmitInput() throws Exception {
|
||||
Login login = new Login();
|
||||
String result = login.execute();
|
||||
assertInput(result);
|
||||
Map errors = assertFieldErrors(login);
|
||||
assertFieldError(errors,"username","Username is required.");
|
||||
assertFieldError(errors,"password","Password is required.");
|
||||
}
|
||||
|
||||
}
|
||||
package example;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class LoginTest extends ConfigTest {
|
||||
|
||||
public void FIXME_testLoginConfig() throws Exception {
|
||||
ActionConfig config = assertClass("example", "Login!input", "example.Login");
|
||||
assertResult(config, ActionSupport.SUCCESS, "Menu");
|
||||
assertResult(config, ActionSupport.INPUT, "/example/Login.jsp");
|
||||
}
|
||||
|
||||
public void testLoginSubmit() throws Exception {
|
||||
Login login = new Login();
|
||||
login.setUsername("username");
|
||||
login.setPassword("password");
|
||||
String result = login.execute();
|
||||
assertSuccess(result);
|
||||
}
|
||||
|
||||
// Needs access to an envinronment that includes validators
|
||||
public void FIXME_testLoginSubmitInput() throws Exception {
|
||||
Login login = new Login();
|
||||
String result = login.execute();
|
||||
assertInput(result);
|
||||
Map errors = assertFieldErrors(login);
|
||||
assertFieldError(errors,"username","Username is required.");
|
||||
assertFieldError(errors,"password","Password is required.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
package org.apache.struts2.showcase.tutorial;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
public class HelloName extends ActionSupport {
|
||||
|
||||
public String execute() throws Exception {
|
||||
if (getName() == null || getName().length() == 0)
|
||||
return ERROR;
|
||||
else
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
package org.apache.struts2.showcase.tutorial;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
|
||||
public class HelloName extends ActionSupport {
|
||||
|
||||
public String execute() throws Exception {
|
||||
if (getName() == null || getName().length() == 0)
|
||||
return ERROR;
|
||||
else
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -1,29 +1,29 @@
|
||||
package org.apache.struts2.showcase.tutorial;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.ParameterAware;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class HelloName2 extends ActionSupport implements ParameterAware {
|
||||
|
||||
public static String NAME = "name";
|
||||
|
||||
public String execute() {
|
||||
String[] name = (String[]) parameters.get(NAME);
|
||||
if (name == null || name[0] == null || name[0].length() == 0)
|
||||
return ERROR;
|
||||
else
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
Map parameters;
|
||||
|
||||
public Map getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void setParameters(Map parameters) {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
}
|
||||
package org.apache.struts2.showcase.tutorial;
|
||||
|
||||
import com.opensymphony.xwork2.ActionSupport;
|
||||
import org.apache.struts2.interceptor.ParameterAware;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class HelloName2 extends ActionSupport implements ParameterAware {
|
||||
|
||||
public static String NAME = "name";
|
||||
|
||||
public String execute() {
|
||||
String[] name = (String[]) parameters.get(NAME);
|
||||
if (name == null || name[0] == null || name[0].length() == 0)
|
||||
return ERROR;
|
||||
else
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
Map parameters;
|
||||
|
||||
public Map getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public void setParameters(Map parameters) {
|
||||
this.parameters = parameters;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,23 @@
|
||||
package org.apache.struts2.showcase.tutorial;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class HelloWorld implements Action {
|
||||
|
||||
public String execute() {
|
||||
message = "Hello, World!\n";
|
||||
message += "The time is:\n";
|
||||
message += DateFormat.getDateInstance().format(new Date());
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private String message;
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
package org.apache.struts2.showcase.tutorial;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class HelloWorld implements Action {
|
||||
|
||||
public String execute() {
|
||||
message = "Hello, World!\n";
|
||||
message += "The time is:\n";
|
||||
message += DateFormat.getDateInstance().format(new Date());
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
private String message;
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,76 +1,76 @@
|
||||
/*
|
||||
* $Id: PlainTextResult.java 394468 2006-04-16 12:16:03Z tmjee $
|
||||
*
|
||||
* 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 org.apache.struts2.jsf;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.faces.FacesException;
|
||||
import javax.faces.application.Application;
|
||||
import javax.faces.application.ViewHandler;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.event.PhaseId;
|
||||
|
||||
/**
|
||||
* Performs the JSF render lifecycle phase.
|
||||
*
|
||||
*/
|
||||
public class FacesRender extends FacesSupport {
|
||||
|
||||
/**
|
||||
* Executes the render phase, borrowed from MyFaces
|
||||
*
|
||||
* @param facesContext
|
||||
* The faces context
|
||||
* @throws FacesException
|
||||
* If anything goes wrong
|
||||
*/
|
||||
public void render(FacesContext facesContext) throws FacesException {
|
||||
// if the response is complete we should not be invoking the phase
|
||||
// listeners
|
||||
if (isResponseComplete(facesContext, "render", true)) {
|
||||
return;
|
||||
}
|
||||
if (log.isTraceEnabled())
|
||||
log.trace("entering renderResponse");
|
||||
|
||||
informPhaseListenersBefore(facesContext, PhaseId.RENDER_RESPONSE);
|
||||
try {
|
||||
// also possible that one of the listeners completed the response
|
||||
if (isResponseComplete(facesContext, "render", true)) {
|
||||
return;
|
||||
}
|
||||
Application application = facesContext.getApplication();
|
||||
ViewHandler viewHandler = application.getViewHandler();
|
||||
try {
|
||||
viewHandler
|
||||
.renderView(facesContext, facesContext.getViewRoot());
|
||||
} catch (IOException e) {
|
||||
throw new FacesException(e.getMessage(), e);
|
||||
}
|
||||
} finally {
|
||||
informPhaseListenersAfter(facesContext, PhaseId.RENDER_RESPONSE);
|
||||
}
|
||||
if (log.isTraceEnabled()) {
|
||||
// Note: DebugUtils Logger must also be in trace level
|
||||
// DebugUtils.traceView("View after rendering");
|
||||
}
|
||||
|
||||
if (log.isTraceEnabled())
|
||||
log.trace("exiting renderResponse");
|
||||
}
|
||||
}
|
||||
/*
|
||||
* $Id: PlainTextResult.java 394468 2006-04-16 12:16:03Z tmjee $
|
||||
*
|
||||
* 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 org.apache.struts2.jsf;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.faces.FacesException;
|
||||
import javax.faces.application.Application;
|
||||
import javax.faces.application.ViewHandler;
|
||||
import javax.faces.context.FacesContext;
|
||||
import javax.faces.event.PhaseId;
|
||||
|
||||
/**
|
||||
* Performs the JSF render lifecycle phase.
|
||||
*
|
||||
*/
|
||||
public class FacesRender extends FacesSupport {
|
||||
|
||||
/**
|
||||
* Executes the render phase, borrowed from MyFaces
|
||||
*
|
||||
* @param facesContext
|
||||
* The faces context
|
||||
* @throws FacesException
|
||||
* If anything goes wrong
|
||||
*/
|
||||
public void render(FacesContext facesContext) throws FacesException {
|
||||
// if the response is complete we should not be invoking the phase
|
||||
// listeners
|
||||
if (isResponseComplete(facesContext, "render", true)) {
|
||||
return;
|
||||
}
|
||||
if (log.isTraceEnabled())
|
||||
log.trace("entering renderResponse");
|
||||
|
||||
informPhaseListenersBefore(facesContext, PhaseId.RENDER_RESPONSE);
|
||||
try {
|
||||
// also possible that one of the listeners completed the response
|
||||
if (isResponseComplete(facesContext, "render", true)) {
|
||||
return;
|
||||
}
|
||||
Application application = facesContext.getApplication();
|
||||
ViewHandler viewHandler = application.getViewHandler();
|
||||
try {
|
||||
viewHandler
|
||||
.renderView(facesContext, facesContext.getViewRoot());
|
||||
} catch (IOException e) {
|
||||
throw new FacesException(e.getMessage(), e);
|
||||
}
|
||||
} finally {
|
||||
informPhaseListenersAfter(facesContext, PhaseId.RENDER_RESPONSE);
|
||||
}
|
||||
if (log.isTraceEnabled()) {
|
||||
// Note: DebugUtils Logger must also be in trace level
|
||||
// DebugUtils.traceView("View after rendering");
|
||||
}
|
||||
|
||||
if (log.isTraceEnabled())
|
||||
log.trace("exiting renderResponse");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user