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:36 UTC

[2/3] git commit: Formats source code

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 {
             }
         }
     }
+
 }