You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2014/08/25 21:35:35 UTC

[1/3] git commit: Solves minor issue with example

Repository: struts
Updated Branches:
  refs/heads/develop bf0826f59 -> 69baf692a


Solves minor issue with example


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/6f58de3f
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/6f58de3f
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/6f58de3f

Branch: refs/heads/develop
Commit: 6f58de3f8b2dbdf7c10824dd8e599f16677873d0
Parents: bf0826f
Author: Lukasz Lenart <lu...@apache.org>
Authored: Mon Aug 25 20:55:05 2014 +0200
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Mon Aug 25 20:55:05 2014 +0200

----------------------------------------------------------------------
 .../xwork2/validator/validators/RegexFieldValidator.java           | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/6f58de3f/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/RegexFieldValidator.java
----------------------------------------------------------------------
diff --git a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/RegexFieldValidator.java b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/RegexFieldValidator.java
index aa0bc8a..0c6fc13 100644
--- a/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/RegexFieldValidator.java
+++ b/xwork-core/src/main/java/com/opensymphony/xwork2/validator/validators/RegexFieldValidator.java
@@ -53,7 +53,7 @@ import java.util.regex.Pattern;
  *     &lt;!-- Plain Validator Syntax --&gt;
  *     &lt;validator type="regex"&gt;
  *         &lt;param name="fieldName"&gt;myStrangePostcode&lt;/param&gt;
- *         &lt;param name="regex"&gt;&lt;![CDATA[([aAbBcCdD][123][eEfFgG][456])]]&lt;&gt;/param&gt;
+ *         &lt;param name="regex"&gt;&lt;![CDATA[([aAbBcCdD][123][eEfFgG][456])]]&gt;&lt;/param&gt;
  *     &lt;/validator&gt;
  *
  *     &lt;!-- Field Validator Syntax --&gt;


[3/3] git commit: WW-4024 Allows specify scheme via expression

Posted by lu...@apache.org.
WW-4024 Allows specify scheme via expression


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/69baf692
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/69baf692
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/69baf692

Branch: refs/heads/develop
Commit: 69baf692a44798ed4e1a5ab1e5e0236bba315b39
Parents: 367e3ef
Author: Lukasz Lenart <lu...@apache.org>
Authored: Mon Aug 25 21:34:54 2014 +0200
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Mon Aug 25 21:34:54 2014 +0200

----------------------------------------------------------------------
 .../apache/struts2/components/ServletUrlRenderer.java | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/69baf692/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java b/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java
index 04a3509..0b4e13b 100644
--- a/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java
+++ b/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java
@@ -25,6 +25,7 @@ import com.opensymphony.xwork2.ActionContext;
 import com.opensymphony.xwork2.ActionInvocation;
 import com.opensymphony.xwork2.config.entities.ActionConfig;
 import com.opensymphony.xwork2.inject.Inject;
+import com.opensymphony.xwork2.util.ValueStack;
 import com.opensymphony.xwork2.util.logging.Logger;
 import com.opensymphony.xwork2.util.logging.LoggerFactory;
 import org.apache.commons.lang3.StringUtils;
@@ -68,7 +69,11 @@ public class ServletUrlRenderer implements UrlRenderer {
         String scheme = urlComponent.getHttpServletRequest().getScheme();
 
         if (urlComponent.getScheme() != null) {
-            scheme = urlComponent.getScheme();
+            ValueStack vs = ActionContext.getContext().getValueStack();
+            scheme = vs.findString(urlComponent.getScheme());
+            if (scheme == null) {
+                scheme = urlComponent.getScheme();
+            }
         }
 
         String result;
@@ -127,6 +132,9 @@ public class ServletUrlRenderer implements UrlRenderer {
         String namespace = formComponent.determineNamespace(formComponent.namespace, formComponent.getStack(), formComponent.request);
         String action;
 
+        ValueStack vs = ActionContext.getContext().getValueStack();
+        String scheme = vs.findString("scheme");
+
         if (formComponent.action != null) {
             action = formComponent.findString(formComponent.action);
         } else {
@@ -161,7 +169,7 @@ public class ServletUrlRenderer implements UrlRenderer {
 
             ActionMapping mapping = new ActionMapping(actionName, namespace, actionMethod, formComponent.parameters);
             String result = urlHelper.buildUrl(formComponent.actionMapper.getUriFromActionMapping(mapping),
-                    formComponent.request, formComponent.response, actionParams, null, formComponent.includeContext, true, false, false);
+                    formComponent.request, formComponent.response, actionParams, scheme, formComponent.includeContext, true, false, false);
             formComponent.addParameter("action", result);
 
             // let's try to get the actual action class and name
@@ -196,7 +204,7 @@ public class ServletUrlRenderer implements UrlRenderer {
                 LOG.warn("No configuration found for the specified action: '" + actionName + "' in namespace: '" + namespace + "'. Form action defaulting to 'action' attribute's literal value.");
             }
 
-            String result = urlHelper.buildUrl(action, formComponent.request, formComponent.response, null, null, formComponent.includeContext, true);
+            String result = urlHelper.buildUrl(action, formComponent.request, formComponent.response, null, scheme, formComponent.includeContext, true);
             formComponent.addParameter("action", result);
 
             // namespace: cut out anything between the start and the last /


[2/3] git commit: Formats source code

Posted by lu...@apache.org.
Formats source code


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/367e3ef4
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/367e3ef4
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/367e3ef4

Branch: refs/heads/develop
Commit: 367e3ef4937a1c5d6775d805a9ae27faa7f50f03
Parents: 6f58de3
Author: Lukasz Lenart <lu...@apache.org>
Authored: Mon Aug 25 21:23:20 2014 +0200
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Mon Aug 25 21:23:20 2014 +0200

----------------------------------------------------------------------
 .../struts2/components/ServletUrlRenderer.java  | 275 ++++++++++---------
 1 file changed, 138 insertions(+), 137 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/367e3ef4/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java b/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java
index df72d84..04a3509 100644
--- a/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java
+++ b/core/src/main/java/org/apache/struts2/components/ServletUrlRenderer.java
@@ -41,7 +41,6 @@ import java.util.Map;
 
 /**
  * Implementation of the {@link UrlRenderer} interface that creates URLs suitable in a servlet environment.
- * 
  */
 public class ServletUrlRenderer implements UrlRenderer {
     /**
@@ -63,40 +62,40 @@ public class ServletUrlRenderer implements UrlRenderer {
     }
 
     /**
-	 * {@inheritDoc}
-	 */
-	public void renderUrl(Writer writer, UrlProvider urlComponent) {
-		String scheme = urlComponent.getHttpServletRequest().getScheme();
-
-		if (urlComponent.getScheme() != null) {
-			scheme = urlComponent.getScheme();
-		}
-
-	       String result;
-	       ActionInvocation ai = (ActionInvocation) ActionContext.getContext().get(ActionContext.ACTION_INVOCATION);
-	        if (urlComponent.getValue() == null && urlComponent.getAction() != null) {
-	                result = urlComponent.determineActionURL(urlComponent.getAction(), urlComponent.getNamespace(), urlComponent.getMethod(), urlComponent.getHttpServletRequest(), urlComponent.getHttpServletResponse(), urlComponent.getParameters(), scheme, urlComponent.isIncludeContext(), urlComponent.isEncode(), urlComponent.isForceAddSchemeHostAndPort(), urlComponent.isEscapeAmp());
-	        } else if (urlComponent.getValue() == null && urlComponent.getAction() == null && ai != null) {
-	                // both are null, we will default to the current action
-
-	                final String action = ai.getProxy().getActionName();
-	                final String namespace = ai.getProxy().getNamespace();
-	                final String method = urlComponent.getMethod() != null || !ai.getProxy().isMethodSpecified() ? urlComponent.getMethod() : ai.getProxy().getMethod();
-	                result = urlComponent.determineActionURL(action, namespace, method, urlComponent.getHttpServletRequest(), urlComponent.getHttpServletResponse(), urlComponent.getParameters(), scheme, urlComponent.isIncludeContext(), urlComponent.isEncode(), urlComponent.isForceAddSchemeHostAndPort(), urlComponent.isEscapeAmp());
-	        } else {
-	                String _value = urlComponent.getValue();
-
-	                // We don't include the request parameters cause they would have been
-	                // prioritised before this [in start(Writer) method]
-	                if (_value != null && _value.indexOf("?") > 0) {
-	                    _value = _value.substring(0, _value.indexOf("?"));
-	                }
-	                result = urlHelper.buildUrl(_value, urlComponent.getHttpServletRequest(), urlComponent.getHttpServletResponse(), urlComponent.getParameters(), scheme, urlComponent.isIncludeContext(), urlComponent.isEncode(), urlComponent.isForceAddSchemeHostAndPort(), urlComponent.isEscapeAmp());
-	        }
-            String anchor = urlComponent.getAnchor();
-	        if (StringUtils.isNotEmpty(anchor)) {
-	        	result += '#' + urlComponent.findString(anchor);
-	        }
+     * {@inheritDoc}
+     */
+    public void renderUrl(Writer writer, UrlProvider urlComponent) {
+        String scheme = urlComponent.getHttpServletRequest().getScheme();
+
+        if (urlComponent.getScheme() != null) {
+            scheme = urlComponent.getScheme();
+        }
+
+        String result;
+        ActionInvocation ai = (ActionInvocation) ActionContext.getContext().get(ActionContext.ACTION_INVOCATION);
+        if (urlComponent.getValue() == null && urlComponent.getAction() != null) {
+            result = urlComponent.determineActionURL(urlComponent.getAction(), urlComponent.getNamespace(), urlComponent.getMethod(), urlComponent.getHttpServletRequest(), urlComponent.getHttpServletResponse(), urlComponent.getParameters(), scheme, urlComponent.isIncludeContext(), urlComponent.isEncode(), urlComponent.isForceAddSchemeHostAndPort(), urlComponent.isEscapeAmp());
+        } else if (urlComponent.getValue() == null && urlComponent.getAction() == null && ai != null) {
+            // both are null, we will default to the current action
+
+            final String action = ai.getProxy().getActionName();
+            final String namespace = ai.getProxy().getNamespace();
+            final String method = urlComponent.getMethod() != null || !ai.getProxy().isMethodSpecified() ? urlComponent.getMethod() : ai.getProxy().getMethod();
+            result = urlComponent.determineActionURL(action, namespace, method, urlComponent.getHttpServletRequest(), urlComponent.getHttpServletResponse(), urlComponent.getParameters(), scheme, urlComponent.isIncludeContext(), urlComponent.isEncode(), urlComponent.isForceAddSchemeHostAndPort(), urlComponent.isEscapeAmp());
+        } else {
+            String _value = urlComponent.getValue();
+
+            // We don't include the request parameters cause they would have been
+            // prioritised before this [in start(Writer) method]
+            if (_value != null && _value.indexOf("?") > 0) {
+                _value = _value.substring(0, _value.indexOf("?"));
+            }
+            result = urlHelper.buildUrl(_value, urlComponent.getHttpServletRequest(), urlComponent.getHttpServletResponse(), urlComponent.getParameters(), scheme, urlComponent.isIncludeContext(), urlComponent.isEncode(), urlComponent.isForceAddSchemeHostAndPort(), urlComponent.isEscapeAmp());
+        }
+        String anchor = urlComponent.getAnchor();
+        if (StringUtils.isNotEmpty(anchor)) {
+            result += '#' + urlComponent.findString(anchor);
+        }
 
         if (urlComponent.isPutInContext()) {
             String var = urlComponent.getVar();
@@ -119,31 +118,31 @@ public class ServletUrlRenderer implements UrlRenderer {
                 throw new StrutsException("IOError: " + e.getMessage(), e);
             }
         }
-	}
-
-	/**
-	 * {@inheritDoc}
-	 */
-	public void renderFormUrl(Form formComponent) {
-		String namespace = formComponent.determineNamespace(formComponent.namespace, formComponent.getStack(), formComponent.request);
-		String action;
-
-		if(formComponent.action != null) {
-			action = formComponent.findString(formComponent.action);
-		} else {
-			// no action supplied? ok, then default to the current request
-			// (action or general URL)
-			ActionInvocation ai = (ActionInvocation) formComponent.getStack().getContext().get(
-					ActionContext.ACTION_INVOCATION);
-			if (ai != null) {
-				action = ai.getProxy().getActionName();
-				namespace = ai.getProxy().getNamespace();
-			} else {
-				// hmm, ok, we need to just assume the current URL cut down
-				String uri = formComponent.request.getRequestURI();
-				action = uri.substring(uri.lastIndexOf('/'));
-			}
-		}
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void renderFormUrl(Form formComponent) {
+        String namespace = formComponent.determineNamespace(formComponent.namespace, formComponent.getStack(), formComponent.request);
+        String action;
+
+        if (formComponent.action != null) {
+            action = formComponent.findString(formComponent.action);
+        } else {
+            // no action supplied? ok, then default to the current request
+            // (action or general URL)
+            ActionInvocation ai = (ActionInvocation) formComponent.getStack().getContext().get(
+                    ActionContext.ACTION_INVOCATION);
+            if (ai != null) {
+                action = ai.getProxy().getActionName();
+                namespace = ai.getProxy().getNamespace();
+            } else {
+                // hmm, ok, we need to just assume the current URL cut down
+                String uri = formComponent.request.getRequestURI();
+                action = uri.substring(uri.lastIndexOf('/'));
+            }
+        }
 
         Map actionParams = null;
         if (action != null && action.indexOf("?") > 0) {
@@ -156,82 +155,82 @@ public class ServletUrlRenderer implements UrlRenderer {
         String actionName = nameMapping.getName();
         String actionMethod = nameMapping.getMethod();
 
-		final ActionConfig actionConfig = formComponent.configuration.getRuntimeConfiguration().getActionConfig(
-				namespace, actionName);
-		if (actionConfig != null) {
+        final ActionConfig actionConfig = formComponent.configuration.getRuntimeConfiguration().getActionConfig(
+                namespace, actionName);
+        if (actionConfig != null) {
 
-			ActionMapping mapping = new ActionMapping(actionName, namespace, actionMethod, formComponent.parameters);
-			String result = urlHelper.buildUrl(formComponent.actionMapper.getUriFromActionMapping(mapping),
+            ActionMapping mapping = new ActionMapping(actionName, namespace, actionMethod, formComponent.parameters);
+            String result = urlHelper.buildUrl(formComponent.actionMapper.getUriFromActionMapping(mapping),
                     formComponent.request, formComponent.response, actionParams, null, formComponent.includeContext, true, false, false);
-			formComponent.addParameter("action", result);
-
-			// let's try to get the actual action class and name
-			// this can be used for getting the list of validators
-			formComponent.addParameter("actionName", actionName);
-			try {
-				Class clazz = formComponent.objectFactory.getClassInstance(actionConfig.getClassName());
-				formComponent.addParameter("actionClass", clazz);
-			} catch (ClassNotFoundException e) {
-				// this is OK, we'll just move on
-			}
-
-			formComponent.addParameter("namespace", namespace);
-
-			// if the name isn't specified, use the action name
-			if (formComponent.name == null) {
-				formComponent.addParameter("name", actionName);
-			}
-
-			// if the id isn't specified, use the action name
-			if (formComponent.getId() == null  && actionName!=null ) {
-				formComponent.addParameter("id", formComponent.escape(actionName));
-			}
-		} else if (action != null) {
-			// Since we can't find an action alias in the configuration, we just
-			// assume the action attribute supplied is the path to be used as
-			// the URI this form is submitting to.
+            formComponent.addParameter("action", result);
+
+            // let's try to get the actual action class and name
+            // this can be used for getting the list of validators
+            formComponent.addParameter("actionName", actionName);
+            try {
+                Class clazz = formComponent.objectFactory.getClassInstance(actionConfig.getClassName());
+                formComponent.addParameter("actionClass", clazz);
+            } catch (ClassNotFoundException e) {
+                // this is OK, we'll just move on
+            }
+
+            formComponent.addParameter("namespace", namespace);
+
+            // if the name isn't specified, use the action name
+            if (formComponent.name == null) {
+                formComponent.addParameter("name", actionName);
+            }
+
+            // if the id isn't specified, use the action name
+            if (formComponent.getId() == null && actionName != null) {
+                formComponent.addParameter("id", formComponent.escape(actionName));
+            }
+        } else if (action != null) {
+            // Since we can't find an action alias in the configuration, we just
+            // assume the action attribute supplied is the path to be used as
+            // the URI this form is submitting to.
 
             // Warn user that the specified namespace/action combo
             // was not found in the configuration.
             if (namespace != null && LOG.isWarnEnabled()) {
-              LOG.warn("No configuration found for the specified action: '" + actionName + "' in namespace: '" + namespace + "'. Form action defaulting to 'action' attribute's literal value.");
+                LOG.warn("No configuration found for the specified action: '" + actionName + "' in namespace: '" + namespace + "'. Form action defaulting to 'action' attribute's literal value.");
             }
 
-			String result = urlHelper.buildUrl(action, formComponent.request, formComponent.response, null, null, formComponent.includeContext, true);
-			formComponent.addParameter("action", result);
-
-			// namespace: cut out anything between the start and the last /
-			int slash = result.lastIndexOf('/');
-			if (slash != -1) {
-				formComponent.addParameter("namespace", result.substring(0, slash));
-			} else {
-				formComponent.addParameter("namespace", "");
-			}
-
-			// name/id: cut out anything between / and . should be the id and
-			// name
-			String id = formComponent.getId();
-			if (id == null) {
-				slash = result.lastIndexOf('/');
-				int dot = result.indexOf('.', slash);
-				if (dot != -1) {
-					id = result.substring(slash + 1, dot);
-				} else {
-					id = result.substring(slash + 1);
-				}
-				formComponent.addParameter("id", formComponent.escape(id));
-			}
-		}
-
-		// WW-1284
-		// evaluate if client-side js is to be enabled. (if validation
-		// interceptor does allow validation eg. method is not filtered out)
-		formComponent.evaluateClientSideJsEnablement(actionName, namespace, actionMethod);
-	}
-
-
-	public void beforeRenderUrl(UrlProvider urlComponent) {
-		if (urlComponent.getValue() != null) {
+            String result = urlHelper.buildUrl(action, formComponent.request, formComponent.response, null, null, formComponent.includeContext, true);
+            formComponent.addParameter("action", result);
+
+            // namespace: cut out anything between the start and the last /
+            int slash = result.lastIndexOf('/');
+            if (slash != -1) {
+                formComponent.addParameter("namespace", result.substring(0, slash));
+            } else {
+                formComponent.addParameter("namespace", "");
+            }
+
+            // name/id: cut out anything between / and . should be the id and
+            // name
+            String id = formComponent.getId();
+            if (id == null) {
+                slash = result.lastIndexOf('/');
+                int dot = result.indexOf('.', slash);
+                if (dot != -1) {
+                    id = result.substring(slash + 1, dot);
+                } else {
+                    id = result.substring(slash + 1);
+                }
+                formComponent.addParameter("id", formComponent.escape(id));
+            }
+        }
+
+        // WW-1284
+        // evaluate if client-side js is to be enabled. (if validation
+        // interceptor does allow validation eg. method is not filtered out)
+        formComponent.evaluateClientSideJsEnablement(actionName, namespace, actionMethod);
+    }
+
+
+    public void beforeRenderUrl(UrlProvider urlComponent) {
+        if (urlComponent.getValue() != null) {
             urlComponent.setValue(urlComponent.findString(urlComponent.getValue()));
         }
 
@@ -263,21 +262,22 @@ public class ServletUrlRenderer implements UrlRenderer {
             }
         } catch (Exception e) {
             if (LOG.isWarnEnabled()) {
-        	LOG.warn("Unable to put request parameters (" + urlComponent.getHttpServletRequest().getQueryString() + ") into parameter map.", e);
+                LOG.warn("Unable to put request parameters (" + urlComponent.getHttpServletRequest().getQueryString() + ") into parameter map.", e);
             }
         }
 
-		
-	}
-	
+
+    }
+
     private void includeExtraParameters(UrlProvider urlComponent) {
         if (urlComponent.getExtraParameterProvider() != null) {
             mergeRequestParameters(urlComponent.getValue(), urlComponent.getParameters(), urlComponent.getExtraParameterProvider().getExtraParameters());
         }
     }
+
     private void includeGetParameters(UrlProvider urlComponent) {
-    	String query = extractQueryString(urlComponent);
-    	mergeRequestParameters(urlComponent.getValue(), urlComponent.getParameters(), urlHelper.parseQueryString(query, false));
+        String query = extractQueryString(urlComponent);
+        mergeRequestParameters(urlComponent.getValue(), urlComponent.getParameters(), urlHelper.parseQueryString(query, false));
     }
 
     private String extractQueryString(UrlProvider urlComponent) {
@@ -297,7 +297,7 @@ public class ServletUrlRenderer implements UrlRenderer {
         }
         return query;
     }
-    
+
     /**
      * Merge request parameters into current parameters. If a parameter is
      * already present, than the request parameter in the current request and value atrribute
@@ -314,7 +314,7 @@ public class ServletUrlRenderer implements UrlRenderer {
      * @param parameters component parameters
      * @param contextParameters request parameters
      */
-    protected void mergeRequestParameters(String value, Map<String, Object> parameters, Map<String, Object> contextParameters){
+    protected void mergeRequestParameters(String value, Map<String, Object> parameters, Map<String, Object> contextParameters) {
 
         Map<String, Object> mergedParams = new LinkedHashMap<String, Object>(contextParameters);
 
@@ -323,7 +323,7 @@ public class ServletUrlRenderer implements UrlRenderer {
         // where the parameters specified in value attribute takes priority.
 
         if (value != null && value.trim().length() > 0 && value.indexOf("?") > 0) {
-            String queryString = value.substring(value.indexOf("?")+1);
+            String queryString = value.substring(value.indexOf("?") + 1);
 
             mergedParams = urlHelper.parseQueryString(queryString, false);
             for (Map.Entry<String, Object> entry : contextParameters.entrySet()) {
@@ -345,4 +345,5 @@ public class ServletUrlRenderer implements UrlRenderer {
             }
         }
     }
+
 }