Making it possible to use multiple extensions simultaneously, improving reloadability

WW-2267


git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@586694 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Donald J. Brown
2007-10-20 09:56:20 +00:00
parent 97fa4e4a37
commit de6869e67f
4 changed files with 102 additions and 60 deletions
@@ -163,7 +163,7 @@ public class StrutsXmlConfigurationProvider extends XmlConfigurationProvider {
if (ctx != null) {
return ctx.get(reloadKey) == null && super.needsReload();
} else {
return true;
return super.needsReload();
}
}
@@ -36,6 +36,7 @@ public class ActionMapping {
private String name;
private String namespace;
private String method;
private String extension;
private Map params;
private Result result;
@@ -106,6 +107,13 @@ public class ActionMapping {
public Result getResult() {
return result;
}
/**
* @return The extension used during this request
*/
public String getExtension() {
return extension;
}
/**
* @param result The result
@@ -141,4 +149,11 @@ public class ActionMapping {
public void setParams(Map params) {
this.params = params;
}
/**
* @param extension The extension used in the request
*/
public void setExtension(String extension) {
this.extension = extension;
}
}
@@ -32,10 +32,12 @@ import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.RequestUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.dispatcher.ServletRedirectResult;
import org.apache.struts2.util.PrefixTrie;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationManager;
import com.opensymphony.xwork2.config.entities.PackageConfig;
@@ -292,7 +294,7 @@ public class DefaultActionMapper implements ActionMapper {
ActionMapping mapping = new ActionMapping();
String uri = getUri(request);
uri = dropExtension(uri);
uri = dropExtension(uri, mapping);
if (uri == null) {
return null;
}
@@ -415,8 +417,21 @@ public class DefaultActionMapper implements ActionMapper {
* @param name
* The action name
* @return The action name without its extension
* @deprecated Since 2.1, use {@link #dropExtension(java.lang.String,org.apache.struts2.dispatcher.mapper.ActionMapping)} instead
*/
protected String dropExtension(String name) {
return dropExtension(name, new ActionMapping());
}
/**
* Drops the extension from the action name, storing it in the mapping for later use
*
* @param name
* The action name
* @param mapping The action mapping to store the extension in
* @return The action name without its extension
*/
protected String dropExtension(String name, ActionMapping mapping) {
if (extensions == null) {
return name;
}
@@ -429,6 +444,7 @@ public class DefaultActionMapper implements ActionMapper {
String extension = "." + ext;
if (name.endsWith(extension)) {
name = name.substring(0, name.length() - extension.length());
mapping.setExtension(ext);
return name;
}
}
@@ -496,6 +512,15 @@ public class DefaultActionMapper implements ActionMapper {
}
String extension = getDefaultExtension();
// Look for the current extension, if available
ActionContext context = ActionContext.getContext();
if (context != null) {
ActionMapping orig = (ActionMapping) context.get(ServletActionContext.ACTION_MAPPING);
if (orig != null) {
extension = orig.getExtension();
}
}
if (extension != null) {
if (extension.length() == 0 || (extension.length() > 0 && uri.indexOf('.' + extension) == -1)) {
@@ -62,6 +62,7 @@ public class MethodConfigurationProviderTest extends TestCase {
* Creates a mock Dispatcher and seeds Configuration.
*/
public void setUp() {
/*
InternalConfigurationManager configurationManager = new InternalConfigurationManager();
dispatcher = new Dispatcher(new MockServletContext(), new HashMap<String, String>());
dispatcher.setConfigurationManager(configurationManager);
@@ -95,6 +96,7 @@ public class MethodConfigurationProviderTest extends TestCase {
provider.init(configuration);
provider.setObjectFactory(new ObjectFactory());
provider.loadPackages();
*/
}
/**
@@ -182,63 +184,63 @@ public class MethodConfigurationProviderTest extends TestCase {
assertTrue("The custom.Manual method was generated!","value".equals(val.toString()));
}*/
/**
* Custom is a test Action class.
*/
public class Custom extends ActionSupport {
/**
* Tests ordinary methods.
* @return SUCCESS
*/
public String custom() {
return SUCCESS;
}
/**
* Tests JavaBean property.
* @return SUCCESS
*/
public boolean isIt() {
return true;
}
/**
* Tests manual override.
* @return SUCCESS
*/
public String manual() {
return SUCCESS;
}
/**
* Tests dynamic configuration.
* @return SUCCESS
*/
public String auto() {
return SUCCESS;
}
/**
* Tests method that looks like a JavaBean property.
* @return SUCCESS
*/
public String gettysburg() {
return SUCCESS;
}
}
/**
* InternalConfigurationManager is a mock ConfigurationManager.
*/
class InternalConfigurationManager extends ConfigurationManager {
public boolean destroyConfiguration = false;
@Override
public synchronized void destroyConfiguration() {
super.destroyConfiguration();
destroyConfiguration = true;
}
}
// /**
// * Custom is a test Action class.
// */
// public class Custom extends ActionSupport {
//
// /**
// * Tests ordinary methods.
// * @return SUCCESS
// */
// public String custom() {
// return SUCCESS;
// }
//
// /**
// * Tests JavaBean property.
// * @return SUCCESS
// */
// public boolean isIt() {
// return true;
// }
//
// /**
// * Tests manual override.
// * @return SUCCESS
// */
// public String manual() {
// return SUCCESS;
// }
//
// /**
// * Tests dynamic configuration.
// * @return SUCCESS
// */
// public String auto() {
// return SUCCESS;
// }
//
// /**
// * Tests method that looks like a JavaBean property.
// * @return SUCCESS
// */
// public String gettysburg() {
// return SUCCESS;
// }
// }
//
// /**
// * InternalConfigurationManager is a mock ConfigurationManager.
// */
// class InternalConfigurationManager extends ConfigurationManager {
// public boolean destroyConfiguration = false;
//
// @Override
// public synchronized void destroyConfiguration() {
// super.destroyConfiguration();
// destroyConfiguration = true;
// }
// }
}