mirror of
https://github.com/apache/struts.git
synced 2026-08-31 19:35:40 +00:00
WW-3779 adds description of missing extension points and removes some code duplications
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1307906 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -270,7 +270,7 @@ public class ServletUrlRenderer implements UrlRenderer {
|
||||
}
|
||||
private void includeGetParameters(UrlProvider urlComponent) {
|
||||
String query = extractQueryString(urlComponent);
|
||||
mergeRequestParameters(urlComponent.getValue(), urlComponent.getParameters(), urlHelper.parseQueryString(query));
|
||||
mergeRequestParameters(urlComponent.getValue(), urlComponent.getParameters(), urlHelper.parseQueryString(query, false));
|
||||
}
|
||||
|
||||
private String extractQueryString(UrlProvider urlComponent) {
|
||||
@@ -318,7 +318,7 @@ public class ServletUrlRenderer implements UrlRenderer {
|
||||
if (value != null && value.trim().length() > 0 && value.indexOf("?") > 0) {
|
||||
String queryString = value.substring(value.indexOf("?")+1);
|
||||
|
||||
mergedParams = urlHelper.parseQueryString(queryString);
|
||||
mergedParams = urlHelper.parseQueryString(queryString, false);
|
||||
for (Map.Entry<String, Object> entry : contextParameters.entrySet()) {
|
||||
if (!mergedParams.containsKey(entry.getKey())) {
|
||||
mergedParams.put(entry.getKey(), entry.getValue());
|
||||
|
||||
@@ -159,6 +159,36 @@ import java.util.StringTokenizer;
|
||||
* <td>singleton</td>
|
||||
* <td>Loads static resources (since 2.1)</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>com.opensymphony.xwork2.conversion.impl.XWorkConverter</td>
|
||||
* <td>struts.xworkConverter</td>
|
||||
* <td>singleton</td>
|
||||
* <td>Handles conversion logic and allows to load custom converters per class or per action</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>com.opensymphony.xwork2.TextProvider</td>
|
||||
* <td>struts.xworkTextProvider</td>
|
||||
* <td>default</td>
|
||||
* <td>Allows provide custom TextProvider for whole application</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>org.apache.struts2.components.UrlRenderer</td>
|
||||
* <td>struts.urlRenderer</td>
|
||||
* <td>singleton</td>
|
||||
* <td>Allows provide custom implementation of environment specific URL rendering/creating class</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>com.opensymphony.xwork2.UnknownHandlerManager</td>
|
||||
* <td>struts.unknownHandlerManager</td>
|
||||
* <td>singleton</td>
|
||||
* <td>Implementation of this interface allows handle logic of unknown Actions, Methods or Results</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>org.apache.struts2.views.util.UrlHelper</td>
|
||||
* <td>struts.view.urlHelper</td>
|
||||
* <td>singleton</td>
|
||||
* <td>Helper class used with URLRenderer to provide exact logic for building URLs</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* <!-- END SNIPPET: extensionPoints -->
|
||||
@@ -233,31 +263,31 @@ public class BeanSelectionProvider implements ConfigurationProvider {
|
||||
props.setProperty("devMode", "false");
|
||||
}
|
||||
|
||||
if (props.containsKey(StrutsConstants.STRUTS_LOG_MISSING_PROPERTIES))
|
||||
props.setProperty("logMissingProperties", props.getProperty(StrutsConstants.STRUTS_LOG_MISSING_PROPERTIES));
|
||||
|
||||
if (props.containsKey(StrutsConstants.STRUTS_ENABLE_OGNL_EXPRESSION_CACHE))
|
||||
props.setProperty("enableOGNLExpressionCache", props.getProperty(StrutsConstants.STRUTS_ENABLE_OGNL_EXPRESSION_CACHE));
|
||||
|
||||
String val = props.getProperty(StrutsConstants.STRUTS_ALLOW_STATIC_METHOD_ACCESS);
|
||||
if (val != null) {
|
||||
props.setProperty("allowStaticMethodAccess", val);
|
||||
}
|
||||
|
||||
// TODO: This should be moved to XWork after 2.0.4
|
||||
// struts.custom.i18n.resources
|
||||
// Convert Struts properties into XWork properties
|
||||
convertIfExist(props, StrutsConstants.STRUTS_LOG_MISSING_PROPERTIES, "logMissingProperties");
|
||||
convertIfExist(props, StrutsConstants.STRUTS_ENABLE_OGNL_EXPRESSION_CACHE, "enableOGNLExpressionCache");
|
||||
convertIfExist(props, StrutsConstants.STRUTS_ALLOW_STATIC_METHOD_ACCESS, "allowStaticMethodAccess");
|
||||
|
||||
LocalizedTextUtil.addDefaultResourceBundle("org/apache/struts2/struts-messages");
|
||||
loadCustomResourceBundles(props);
|
||||
}
|
||||
|
||||
private void convertIfExist(LocatableProperties props, String fromKey, String toKey) {
|
||||
if (props.containsKey(fromKey)) {
|
||||
props.setProperty(toKey, props.getProperty(fromKey));
|
||||
}
|
||||
}
|
||||
|
||||
private void loadCustomResourceBundles(LocatableProperties props) {
|
||||
String bundles = props.getProperty(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES);
|
||||
if (bundles != null && bundles.length() > 0) {
|
||||
StringTokenizer customBundles = new StringTokenizer(props.getProperty(StrutsConstants.STRUTS_CUSTOM_I18N_RESOURCES), ", ");
|
||||
StringTokenizer customBundles = new StringTokenizer(bundles, ", ");
|
||||
|
||||
while (customBundles.hasMoreTokens()) {
|
||||
String name = customBundles.nextToken();
|
||||
try {
|
||||
if (LOG.isInfoEnabled()) {
|
||||
LOG.info("Loading global messages from " + name);
|
||||
LOG.info("Loading global messages from " + name);
|
||||
}
|
||||
LocalizedTextUtil.addDefaultResourceBundle(name);
|
||||
} catch (Exception e) {
|
||||
@@ -276,20 +306,20 @@ public class BeanSelectionProvider implements ConfigurationProvider {
|
||||
String foundName = props.getProperty(key, DEFAULT_BEAN_NAME);
|
||||
if (builder.contains(type, foundName)) {
|
||||
if (LOG.isInfoEnabled()) {
|
||||
LOG.info("Choosing bean (" + foundName + ") for " + type);
|
||||
LOG.info("Choosing bean (#1) for (#2)", foundName, type.getName());
|
||||
}
|
||||
builder.alias(type, foundName, Container.DEFAULT_NAME);
|
||||
} else {
|
||||
try {
|
||||
Class cls = ClassLoaderUtil.loadClass(foundName, this.getClass());
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Choosing bean ("+cls+") for "+type);
|
||||
LOG.debug("Choosing bean (#1) for (#2)", cls.getName(), type.getName());
|
||||
}
|
||||
builder.factory(type, cls, scope);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
// Perhaps a spring bean id, so we'll delegate to the object factory at runtime
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Choosing bean ("+foundName+") for "+type+" to be loaded from the ObjectFactory");
|
||||
LOG.debug("Choosing bean (#1) for (#2) to be loaded from the ObjectFactory", foundName, type.getName());
|
||||
}
|
||||
if (DEFAULT_BEAN_NAME.equals(foundName)) {
|
||||
// Probably an optional bean, will ignore
|
||||
@@ -297,14 +327,14 @@ public class BeanSelectionProvider implements ConfigurationProvider {
|
||||
if (ObjectFactory.class != type) {
|
||||
builder.factory(type, new ObjectFactoryDelegateFactory(foundName, type), scope);
|
||||
} else {
|
||||
throw new ConfigurationException("Cannot locate the chosen ObjectFactory implementation: "+foundName);
|
||||
throw new ConfigurationException("Cannot locate the chosen ObjectFactory implementation: " + foundName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (LOG.isWarnEnabled()) {
|
||||
LOG.warn("Unable to alias bean type "+type+", default mapping already assigned.");
|
||||
LOG.warn("Unable to alias bean type (#1), default mapping already assigned.", type.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,7 +169,7 @@ public class DefaultUrlHelper implements UrlHelper {
|
||||
|
||||
//if the action was not explicitly set grab the params from the request
|
||||
if (escapeAmp) {
|
||||
buildParametersString(params, link);
|
||||
buildParametersString(params, link, AMP);
|
||||
} else {
|
||||
buildParametersString(params, link, "&");
|
||||
}
|
||||
@@ -190,10 +190,6 @@ public class DefaultUrlHelper implements UrlHelper {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void buildParametersString(Map<String, Object> params, StringBuilder link) {
|
||||
buildParametersString(params, link, AMP);
|
||||
}
|
||||
|
||||
public void buildParametersString(Map<String, Object> params, StringBuilder link, String paramSeparator) {
|
||||
if ((params != null) && (params.size() > 0)) {
|
||||
if (!link.toString().contains("?")) {
|
||||
@@ -285,10 +281,6 @@ public class DefaultUrlHelper implements UrlHelper {
|
||||
return TextParseUtil.translateVariables(input, valueStack);
|
||||
}
|
||||
|
||||
public Map<String, Object> parseQueryString(String queryString) {
|
||||
return parseQueryString(queryString, false);
|
||||
}
|
||||
|
||||
public Map<String, Object> parseQueryString(String queryString, boolean forceValueArray) {
|
||||
Map<String, Object> queryParams = new LinkedHashMap<String, Object>();
|
||||
if (queryString != null) {
|
||||
|
||||
@@ -32,12 +32,8 @@ public interface UrlHelper {
|
||||
String buildUrl(String action, HttpServletRequest request, HttpServletResponse response, Map<String, Object> params, String scheme,
|
||||
boolean includeContext, boolean encodeResult, boolean forceAddSchemeHostAndPort, boolean escapeAmp);
|
||||
|
||||
void buildParametersString(Map<String, Object> params, StringBuilder link);
|
||||
|
||||
void buildParametersString(Map<String, Object> params, StringBuilder link, String paramSeparator);
|
||||
|
||||
Map<String, Object> parseQueryString(String queryString);
|
||||
|
||||
Map<String, Object> parseQueryString(String queryString, boolean forceValueArray);
|
||||
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ public class DefaultUrlHelperTest extends StrutsTestCase {
|
||||
|
||||
StringBuilder url = new StringBuilder("http://localhost:8080/myContext/myPage.jsp?initParam=initValue");
|
||||
|
||||
urlHelper.buildParametersString(parameters, url);
|
||||
urlHelper.buildParametersString(parameters, url, UrlHelper.AMP);
|
||||
|
||||
assertEquals(
|
||||
expectedUrl, url.toString());
|
||||
@@ -122,7 +122,7 @@ public class DefaultUrlHelperTest extends StrutsTestCase {
|
||||
|
||||
StringBuilder url = new StringBuilder("http://localhost:8080/myContext/myPage.jsp?initParam=initValue");
|
||||
|
||||
urlHelper.buildParametersString(parameters, url);
|
||||
urlHelper.buildParametersString(parameters, url, UrlHelper.AMP);
|
||||
|
||||
assertEquals(
|
||||
expectedUrl, url.toString());
|
||||
@@ -355,7 +355,7 @@ public class DefaultUrlHelperTest extends StrutsTestCase {
|
||||
|
||||
|
||||
public void testParseQuery() throws Exception {
|
||||
Map result = urlHelper.parseQueryString("aaa=aaaval&bbb=bbbval&ccc=&%3Ca%22%3E=%3Cval%3E");
|
||||
Map result = urlHelper.parseQueryString("aaa=aaaval&bbb=bbbval&ccc=&%3Ca%22%3E=%3Cval%3E", false);
|
||||
|
||||
assertEquals(result.get("aaa"), "aaaval");
|
||||
assertEquals(result.get("bbb"), "bbbval");
|
||||
@@ -364,14 +364,14 @@ public class DefaultUrlHelperTest extends StrutsTestCase {
|
||||
}
|
||||
|
||||
public void testParseEmptyQuery() throws Exception {
|
||||
Map result = urlHelper.parseQueryString("");
|
||||
Map result = urlHelper.parseQueryString("", false);
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(result.size(), 0);
|
||||
}
|
||||
|
||||
public void testParseNullQuery() throws Exception {
|
||||
Map result = urlHelper.parseQueryString(null);
|
||||
Map result = urlHelper.parseQueryString(null, false);
|
||||
|
||||
assertNotNull(result);
|
||||
assertEquals(result.size(), 0);
|
||||
|
||||
Reference in New Issue
Block a user