Repository: struts
Updated Branches:
  refs/heads/master 2e9df577a -> 5a835cf6a


http://git-wip-us.apache.org/repos/asf/struts/blob/5a835cf6/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java
----------------------------------------------------------------------
diff --git 
a/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java 
b/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java
index e637f20..1a2cac2 100644
--- a/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java
+++ b/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionMapper.java
@@ -25,8 +25,9 @@ import com.opensymphony.xwork2.config.Configuration;
 import com.opensymphony.xwork2.config.ConfigurationManager;
 import com.opensymphony.xwork2.config.entities.PackageConfig;
 import com.opensymphony.xwork2.inject.Inject;
-import org.apache.logging.log4j.Logger;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.apache.struts2.RequestUtils;
 import org.apache.struts2.StrutsConstants;
 import org.apache.struts2.dispatcher.mapper.ActionMapping;
@@ -97,7 +98,15 @@ import java.util.HashMap;
 public class RestActionMapper extends DefaultActionMapper {
 
     protected static final Logger LOG = 
LogManager.getLogger(RestActionMapper.class);
+
     public static final String HTTP_METHOD_PARAM = "_method";
+
+    private static final String GET = "get";
+    private static final String POST = "post";
+    private static final String PUT = "put";
+    private static final String DELETE = "delete";
+    private static final String OPTIONS = "options";
+
     private String idParameterName = "id";
     private String indexMethodName = "index";
     private String getMethodName = "show";
@@ -201,7 +210,7 @@ public class RestActionMapper extends DefaultActionMapper {
 
         String fullName = mapping.getName();
         // Only try something if the action name is specified
-        if (fullName != null && fullName.length() > 0) {
+        if (StringUtils.isNotEmpty(fullName)) {
 
             // cut off any ;jsessionid= type appendix but allow the rails-like 
;edit
             int scPos = fullName.indexOf(';');
@@ -282,7 +291,7 @@ public class RestActionMapper extends DefaultActionMapper {
             if (id != null) {
                 if (!"new".equals(id)) {
                     if (mapping.getParams() == null) {
-                        mapping.setParams(new HashMap());
+                        mapping.setParams(new HashMap<String, Object>());
                     }
                     mapping.getParams().put(idParameterName, new String[]{id});
                 }
@@ -317,8 +326,7 @@ public class RestActionMapper extends DefaultActionMapper {
      * @param mapping
      *            The action mapping to populate
      */
-    protected void parseNameAndNamespace(String uri, ActionMapping mapping,
-            ConfigurationManager configManager) {
+    protected void parseNameAndNamespace(String uri, ActionMapping mapping, 
ConfigurationManager configManager) {
         String namespace, name;
         int lastSlash = uri.lastIndexOf("/");
         if (lastSlash == -1) {
@@ -353,31 +361,23 @@ public class RestActionMapper extends DefaultActionMapper 
{
     }
 
     protected boolean isGet(HttpServletRequest request) {
-        return "get".equalsIgnoreCase(request.getMethod());
+        return GET.equalsIgnoreCase(request.getMethod());
     }
 
     protected boolean isPost(HttpServletRequest request) {
-        return "post".equalsIgnoreCase(request.getMethod());
+        return POST.equalsIgnoreCase(request.getMethod());
     }
 
     protected boolean isPut(HttpServletRequest request) {
-        if ("put".equalsIgnoreCase(request.getMethod())) {
-            return true;
-        } else {
-            return isPost(request) && 
"put".equalsIgnoreCase(request.getParameter(HTTP_METHOD_PARAM));
-        }
+        return PUT.equalsIgnoreCase(request.getMethod()) || isPost(request) && 
PUT.equalsIgnoreCase(request.getParameter(HTTP_METHOD_PARAM));
     }
 
     protected boolean isDelete(HttpServletRequest request) {
-        if ("delete".equalsIgnoreCase(request.getMethod())) {
-            return true;
-        } else {
-            return 
"delete".equalsIgnoreCase(request.getParameter(HTTP_METHOD_PARAM));
-        }
+        return DELETE.equalsIgnoreCase(request.getMethod()) || 
DELETE.equalsIgnoreCase(request.getParameter(HTTP_METHOD_PARAM));
     }
 
     protected boolean isOptions(HttpServletRequest request) {
-        return "options".equalsIgnoreCase(request.getMethod());
+        return OPTIONS.equalsIgnoreCase(request.getMethod());
     }
     
     protected boolean isExpectContinue(HttpServletRequest request) {

http://git-wip-us.apache.org/repos/asf/struts/blob/5a835cf6/plugins/rest/src/main/java/org/apache/struts2/rest/RestWorkflowInterceptor.java
----------------------------------------------------------------------
diff --git 
a/plugins/rest/src/main/java/org/apache/struts2/rest/RestWorkflowInterceptor.java
 
b/plugins/rest/src/main/java/org/apache/struts2/rest/RestWorkflowInterceptor.java
index ce794c1..073d312 100644
--- 
a/plugins/rest/src/main/java/org/apache/struts2/rest/RestWorkflowInterceptor.java
+++ 
b/plugins/rest/src/main/java/org/apache/struts2/rest/RestWorkflowInterceptor.java
@@ -27,15 +27,16 @@ import com.opensymphony.xwork2.ActionInvocation;
 import com.opensymphony.xwork2.ValidationAware;
 import com.opensymphony.xwork2.inject.Inject;
 import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
-import org.apache.logging.log4j.Logger;
 import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.apache.struts2.ServletActionContext;
 import org.apache.struts2.dispatcher.mapper.ActionMapping;
 
-import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
 import java.util.HashMap;
 import java.util.Map;
 
+import static javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST;
+
 /**
  * <!-- START SNIPPET: description -->
  *
@@ -200,9 +201,7 @@ public class RestWorkflowInterceptor extends 
MethodFilterInterceptor {
             ValidationAware validationAwareAction = (ValidationAware) action;
 
             if (validationAwareAction.hasErrors()) {
-               if (LOG.isDebugEnabled()) {
-                       LOG.debug("Errors on action "+validationAwareAction+", 
returning result name 'input'");
-               }
+                       LOG.debug("Errors on action {}, returning result name 
'input'", validationAwareAction);
                ActionMapping mapping = (ActionMapping) 
ActionContext.getContext().get(ServletActionContext.ACTION_MAPPING);
                String method = inputResultName;
                 if (postMethodName.equals(mapping.getMethod())) {
@@ -217,7 +216,7 @@ public class RestWorkflowInterceptor extends 
MethodFilterInterceptor {
                    .renderResult(method)
                    .withStatus(validationFailureStatusCode);
                
-               Map errors = new HashMap();
+               Map<String, Object> errors = new HashMap<>();
                
                errors.put("actionErrors", 
validationAwareAction.getActionErrors());
                errors.put("fieldErrors", 
validationAwareAction.getFieldErrors());

http://git-wip-us.apache.org/repos/asf/struts/blob/5a835cf6/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/FreemarkerDecoratorServlet.java
----------------------------------------------------------------------
diff --git 
a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/FreemarkerDecoratorServlet.java
 
b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/FreemarkerDecoratorServlet.java
index 4f573bd..573fe61 100644
--- 
a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/FreemarkerDecoratorServlet.java
+++ 
b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/FreemarkerDecoratorServlet.java
@@ -23,14 +23,9 @@ package org.apache.struts2.sitemesh;
 import com.opensymphony.module.sitemesh.HTMLPage;
 import com.opensymphony.module.sitemesh.RequestConstants;
 import com.opensymphony.xwork2.ActionContext;
-import org.apache.logging.log4j.LogManager;
 import freemarker.core.InvalidReferenceException;
-import freemarker.template.Configuration;
-import freemarker.template.ObjectWrapper;
-import freemarker.template.SimpleHash;
-import freemarker.template.Template;
-import freemarker.template.TemplateException;
-import freemarker.template.TemplateModel;
+import freemarker.template.*;
+import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 import org.apache.struts2.ServletActionContext;
 import org.apache.struts2.StrutsStatics;
@@ -74,17 +69,15 @@ public class FreemarkerDecoratorServlet extends 
freemarker.ext.servlet.Freemarke
     public void init() throws ServletException {
         try {
             Dispatcher dispatcher = (Dispatcher) 
getServletContext().getAttribute(StrutsStatics.SERVLET_DISPATCHER);
-            if (dispatcher == null)
+            if (dispatcher == null) {
                 throw new IllegalStateException("Unable to find the Dispatcher 
in the Servlet Context. Is '" + StrutsListener.class.getName() + "' missing in 
web.xml?");
-
+            }
             freemarkerManager = 
dispatcher.getContainer().getInstance(FreemarkerManager.class);
             config = createConfiguration();
 
             // Process object_wrapper init-param out of order:
             wrapper = config.getObjectWrapper();
-            if (LOG.isDebugEnabled()) {
-                LOG.debug("Using object wrapper of class " + 
wrapper.getClass().getName());
-            }
+            LOG.debug("Using object wrapper of class {}", 
wrapper.getClass().getName());
 
             // Process all other init-params:
             Enumeration initpnames = 
getServletConfig().getInitParameterNames();
@@ -92,10 +85,10 @@ public class FreemarkerDecoratorServlet extends 
freemarker.ext.servlet.Freemarke
                 String name = (String) initpnames.nextElement();
                 String value = getInitParameter(name);
                 if (name == null) {
-                    throw new ServletException("init-param without param-name. 
" + "Maybe the web.xml is not well-formed?");
+                    throw new ServletException("init-param without param-name. 
Maybe the web.xml is not well-formed?");
                 }
                 if (value == null) {
-                    throw new ServletException("init-param without 
param-value. " + "Maybe the web.xml is not well-formed?");
+                    throw new ServletException("init-param without 
param-value. Maybe the web.xml is not well-formed?");
                 }
 
                 // template path is already handled!
@@ -132,7 +125,7 @@ public class FreemarkerDecoratorServlet extends 
freemarker.ext.servlet.Freemarke
             log("Requested template: " + path);
         }
 
-        Template template = null;
+        Template template;
         try {
             template = config.getTemplate(path, deduceLocale(path, request, 
response));
         } catch (FileNotFoundException e) {
@@ -176,11 +169,15 @@ public class FreemarkerDecoratorServlet extends 
freemarker.ext.servlet.Freemarke
             // this exception is thrown if there is an error processing a 
reference.  We want to report these!
             HttpServletRequest req = ((StrutsRequestWrapper) 
ActionContext.getContext().get("com.opensymphony.xwork2.dispatcher.HttpServletRequest"));
             String resultCode = 
ActionContext.getContext().getActionInvocation().getResultCode();
-            if (req == null) req = request;
+            if (req == null){
+                req = request;
+            }
 
             StringBuilder msgBuf = new StringBuilder("Error applying 
freemarker template to\n       request: ");
             msgBuf.append(req.getRequestURL());
-            if (req.getQueryString() != null) 
msgBuf.append("?").append(req.getQueryString());
+            if (req.getQueryString() != null){
+                msgBuf.append("?").append(req.getQueryString());
+            }
             msgBuf.append(" with resultCode: 
").append(resultCode).append(".\n\n").append(x.getMessage());
             String msg = msgBuf.toString();
             LOG.error(msg, x);

http://git-wip-us.apache.org/repos/asf/struts/blob/5a835cf6/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/StrutsSiteMeshFactory.java
----------------------------------------------------------------------
diff --git 
a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/StrutsSiteMeshFactory.java
 
b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/StrutsSiteMeshFactory.java
index a47802f..2e61f1e 100644
--- 
a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/StrutsSiteMeshFactory.java
+++ 
b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/StrutsSiteMeshFactory.java
@@ -21,9 +21,9 @@ package org.apache.struts2.sitemesh;
 import com.opensymphony.module.sitemesh.Config;
 import com.opensymphony.module.sitemesh.factory.DefaultFactory;
 import com.opensymphony.xwork2.ActionContext;
-import org.apache.logging.log4j.Logger;
-import org.apache.logging.log4j.LogManager;
 import org.apache.commons.lang3.ObjectUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
 import org.apache.struts2.ServletActionContext;
 import org.apache.struts2.StrutsStatics;
 
@@ -45,9 +45,7 @@ public class StrutsSiteMeshFactory extends DefaultFactory {
 
     private boolean isInsideActionTag() {
         if(ActionContext.getContext() == null) {
-            if (LOG.isTraceEnabled()) {
-                LOG.trace("ActionContext is null! Not a user request?");
-            }
+            LOG.trace("ActionContext is null! Not a user request?");
             return false;
         }
         Object attribute = 
ServletActionContext.getRequest().getAttribute(StrutsStatics.STRUTS_ACTION_TAG_INVOCATION);

http://git-wip-us.apache.org/repos/asf/struts/blob/5a835cf6/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityDecoratorServlet.java
----------------------------------------------------------------------
diff --git 
a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityDecoratorServlet.java
 
b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityDecoratorServlet.java
index a2814b0..5ddcdd5 100644
--- 
a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityDecoratorServlet.java
+++ 
b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityDecoratorServlet.java
@@ -71,8 +71,9 @@ public class VelocityDecoratorServlet extends 
VelocityViewServlet {
     public void init(ServletConfig config) throws ServletException {
         super.init(config);
         Dispatcher dispatcher = (Dispatcher) 
getServletContext().getAttribute(StrutsStatics.SERVLET_DISPATCHER);
-        if (dispatcher == null)
+        if (dispatcher == null) {
             throw new IllegalStateException("Unable to find the Dispatcher in 
the Servlet Context. Is '" + StrutsListener.class.getName() + "' missing in 
web.xml?");
+        }
         velocityManager = 
dispatcher.getContainer().getInstance(VelocityManager.class);
         velocityManager.init(config.getServletContext());
 
@@ -81,9 +82,9 @@ public class VelocityDecoratorServlet extends 
VelocityViewServlet {
         toolboxManager = velocityManager.getToolboxManager();
 
         // we can get these now that velocity is initialized
-        defaultContentType = (String) getVelocityProperty(CONTENT_TYPE, 
DEFAULT_CONTENT_TYPE);
+        defaultContentType = getVelocityProperty(CONTENT_TYPE, 
DEFAULT_CONTENT_TYPE);
 
-        String encoding = (String) 
getVelocityProperty(RuntimeConstants.OUTPUT_ENCODING, DEFAULT_OUTPUT_ENCODING);
+        String encoding = 
getVelocityProperty(RuntimeConstants.OUTPUT_ENCODING, DEFAULT_OUTPUT_ENCODING);
 
         // For non Latin-1 encodings, ensure that the charset is
         // included in the Content-Type header.
@@ -107,7 +108,7 @@ public class VelocityDecoratorServlet extends 
VelocityViewServlet {
         String template;
 
         context.put("base", request.getContextPath());
-        // For backwards compatability with apps that used the old 
VelocityDecoratorServlet
+        // For backwards compatibility with apps that used the old 
VelocityDecoratorServlet
         // that extended VelocityServlet instead of VelocityViewServlet
         context.put("req", request);
         context.put("res", response);
@@ -140,8 +141,7 @@ public class VelocityDecoratorServlet extends 
VelocityViewServlet {
 
     private DecoratorMapper getDecoratorMapper() {
         Factory factory = Factory.getInstance(new Config(getServletConfig()));
-        DecoratorMapper decoratorMapper = factory.getDecoratorMapper();
-        return decoratorMapper;
+        return factory.getDecoratorMapper();
     }
 
     /**
@@ -160,7 +160,7 @@ public class VelocityDecoratorServlet extends 
VelocityViewServlet {
     }
 
     /**
-     * Sets the content type of the response.  This is available to be 
overriden
+     * Sets the content type of the response.  This is available to be 
overridden
      * by a derived class.
      * <p/>
      * <p>The default implementation is :

Reply via email to