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 2016/09/16 14:08:15 UTC

[1/3] struts git commit: WW-4685 Supports evaluating expressions from tiles definitions as a Struts values

Repository: struts
Updated Branches:
  refs/heads/support-2-3 6f5ddca47 -> 81371e09c


WW-4685 Supports evaluating expressions from tiles definitions as a Struts values


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

Branch: refs/heads/support-2-3
Commit: 156db8e5dfb82c394564d8268d9ef553f28356af
Parents: 6f5ddca
Author: Lukasz Lenart <lu...@apache.org>
Authored: Tue Sep 6 21:33:31 2016 +0200
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Fri Sep 16 16:00:27 2016 +0200

----------------------------------------------------------------------
 .../struts2/tiles/StrutsAttributeEvaluator.java | 91 ++++++++++++++++++++
 .../tiles/StrutsTilesContainerFactory.java      | 24 +++++-
 2 files changed, 111 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/156db8e5/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsAttributeEvaluator.java
----------------------------------------------------------------------
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsAttributeEvaluator.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsAttributeEvaluator.java
new file mode 100644
index 0000000..8b98ab2
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsAttributeEvaluator.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.struts2.tiles;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.LocaleProvider;
+import com.opensymphony.xwork2.TextProvider;
+import com.opensymphony.xwork2.TextProviderFactory;
+import com.opensymphony.xwork2.config.ConfigurationException;
+import com.opensymphony.xwork2.ognl.OgnlUtil;
+import com.opensymphony.xwork2.util.logging.Logger;
+import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import ognl.OgnlException;
+import org.apache.struts2.ServletActionContext;
+import org.apache.tiles.context.TilesRequestContext;
+import org.apache.tiles.evaluator.AbstractAttributeEvaluator;
+import org.apache.tiles.evaluator.EvaluationException;
+import org.apache.tiles.servlet.context.ServletUtil;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
+
+public class StrutsAttributeEvaluator extends AbstractAttributeEvaluator {
+
+    private static final Logger LOG = LoggerFactory.getLogger(StrutsAttributeEvaluator.class);
+
+    public Object evaluate(String expression, TilesRequestContext request) {
+        try {
+            Object result = null;
+
+            HttpServletRequest httpRequest = ServletUtil.getServletRequest(request).getRequest();
+            ActionContext ctx = ServletActionContext.getActionContext(httpRequest);
+
+            if (ctx == null) {
+                LOG.error("Cannot obtain HttpServletRequest from [{}]", request.getClass().getName());
+                throw new ConfigurationException("There is no ActionContext for current request!");
+            }
+
+            TextProviderFactory tpf = new TextProviderFactory();
+            ctx.getContainer().inject(tpf);
+            LocaleProvider localeProvider = ctx.getContainer().getInstance(LocaleProvider.class);
+
+            TextProvider textProvider = tpf.createInstance(ctx.getActionInvocation().getAction().getClass(), localeProvider);
+
+            if (textProvider != null) {
+                LOG.debug("Trying find text [{}] using TextProvider {}", expression, textProvider);
+                result = textProvider.getText(expression);
+                if (expression.equals(result)) {
+                    LOG.debug("Could not evaluate expression [{}] as a I18N key", expression);
+                    result = null;
+                }
+            }
+
+            if (result == null) {
+                OgnlUtil ognlUtil = ctx.getContainer().getInstance(OgnlUtil.class);
+                LOG.debug("Trying evaluate expression [{}] using OgnlUtil's getValue", expression);
+                result = ognlUtil.getValue(expression, ctx.getContextMap(), ctx.getValueStack().getRoot());
+            }
+
+            LOG.debug("Final result of evaluating expression [{}] is: {}", expression, result);
+
+            if (result == null) {
+                return expression;
+            } else {
+                return result;
+            }
+        } catch (OgnlException e) {
+            throw new EvaluationException(e);
+        }
+    }
+
+    public void init(Map<String, String> initParameters) {
+    }
+}

http://git-wip-us.apache.org/repos/asf/struts/blob/156db8e5/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
----------------------------------------------------------------------
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
index 0ed8c5c..ee6cbfe 100644
--- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
@@ -83,9 +83,9 @@ import java.util.Set;
 /**
  * Dedicated Struts factory to build Tiles container with support for:
  * - Freemarker
- * - OGNL (as default)
+ * - Struts I18N & ValueStack (as default)
+ * - OGNL
  * - EL
- * - Wildcards
  *
  * If you need additional features create your own listener and factory,
  * you can base on code from Tiles' CompleteAutoloadTilesContainerFactory
@@ -108,6 +108,13 @@ public class StrutsTilesContainerFactory extends BasicTilesContainerFactory {
      */
     public static final String TILES_DEFAULT_PATTERN = "tiles*.xml";
 
+    /**
+     * Supported expression languages
+     */
+    public static final String OGNL = "OGNL";
+    public static final String EL = "EL";
+    public static final String S2 = "S2";
+
     @Override
     protected BasicTilesContainer instantiateContainer(TilesApplicationContext applicationContext) {
         CachingTilesContainer tilesContainer = new CachingTilesContainer();
@@ -182,8 +189,13 @@ public class StrutsTilesContainerFactory extends BasicTilesContainerFactory {
             LocaleResolver resolver) {
 
         BasicAttributeEvaluatorFactory attributeEvaluatorFactory = new BasicAttributeEvaluatorFactory(new DirectAttributeEvaluator());
-        attributeEvaluatorFactory.registerAttributeEvaluator("OGNL", createOGNLEvaluator());
-        attributeEvaluatorFactory.registerAttributeEvaluator("EL", createELEvaluator(applicationContext));
+        attributeEvaluatorFactory.registerAttributeEvaluator(S2, createStrutsEvaluator());
+        attributeEvaluatorFactory.registerAttributeEvaluator(OGNL, createOGNLEvaluator());
+
+        ELAttributeEvaluator elEvaluator = createELEvaluator(applicationContext);
+        if (elEvaluator != null) {
+            attributeEvaluatorFactory.registerAttributeEvaluator(EL, elEvaluator);
+        }
 
         return attributeEvaluatorFactory;
     }
@@ -252,6 +264,10 @@ public class StrutsTilesContainerFactory extends BasicTilesContainerFactory {
         return evaluator;
     }
 
+    protected StrutsAttributeEvaluator createStrutsEvaluator() {
+        return new StrutsAttributeEvaluator();
+    }
+
     protected OGNLAttributeEvaluator createOGNLEvaluator() {
         try {
             PropertyAccessor objectPropertyAccessor = OgnlRuntime.getPropertyAccessor(Object.class);


[3/3] struts git commit: WW-4685 Adjusts cherry pick to 2.3.x

Posted by lu...@apache.org.
WW-4685 Adjusts cherry pick to 2.3.x


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

Branch: refs/heads/support-2-3
Commit: 81371e09c54a1ba9c2d4d3207567263cc6e62474
Parents: 431e50e
Author: Lukasz Lenart <lu...@apache.org>
Authored: Fri Sep 16 16:07:59 2016 +0200
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Fri Sep 16 16:07:59 2016 +0200

----------------------------------------------------------------------
 .../struts2/tiles/I18NAttributeEvaluator.java    | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/81371e09/plugins/tiles/src/main/java/org/apache/struts2/tiles/I18NAttributeEvaluator.java
----------------------------------------------------------------------
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/I18NAttributeEvaluator.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/I18NAttributeEvaluator.java
index 37150ae..29b7ad2 100644
--- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/I18NAttributeEvaluator.java
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/I18NAttributeEvaluator.java
@@ -24,24 +24,21 @@ import com.opensymphony.xwork2.LocaleProvider;
 import com.opensymphony.xwork2.TextProvider;
 import com.opensymphony.xwork2.TextProviderFactory;
 import com.opensymphony.xwork2.config.ConfigurationException;
-import com.opensymphony.xwork2.ognl.OgnlUtil;
-import ognl.OgnlException;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
+import com.opensymphony.xwork2.util.logging.Logger;
+import com.opensymphony.xwork2.util.logging.LoggerFactory;
 import org.apache.struts2.ServletActionContext;
+import org.apache.tiles.context.TilesRequestContext;
 import org.apache.tiles.evaluator.AbstractAttributeEvaluator;
-import org.apache.tiles.evaluator.EvaluationException;
-import org.apache.tiles.request.Request;
-import org.apache.tiles.request.servlet.ServletUtil;
+import org.apache.tiles.servlet.context.ServletUtil;
 
 import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
 
 public class I18NAttributeEvaluator extends AbstractAttributeEvaluator {
 
-    private static final Logger LOG = LogManager.getLogger(I18NAttributeEvaluator.class);
+    private static final Logger LOG = LoggerFactory.getLogger(I18NAttributeEvaluator.class);
 
-    @Override
-    public Object evaluate(String expression, Request request) {
+    public Object evaluate(String expression, TilesRequestContext request) {
         Object result = expression;
 
         HttpServletRequest httpRequest = ServletUtil.getServletRequest(request).getRequest();
@@ -65,4 +62,6 @@ public class I18NAttributeEvaluator extends AbstractAttributeEvaluator {
         return result;
     }
 
+    public void init(Map<String, String> initParameters) {
+    }
 }


[2/3] struts git commit: WW-4685 Uses dedicated prefixes to access I18N and Struts internals

Posted by lu...@apache.org.
WW-4685 Uses dedicated prefixes to access I18N and Struts internals


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

Branch: refs/heads/support-2-3
Commit: 431e50e92242b24b98f36eaec9ac84c938bb82b6
Parents: 156db8e
Author: Lukasz Lenart <lu...@apache.org>
Authored: Wed Sep 7 09:27:43 2016 +0200
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Fri Sep 16 16:00:45 2016 +0200

----------------------------------------------------------------------
 .../struts2/tiles/I18NAttributeEvaluator.java   | 68 ++++++++++++++++++++
 .../struts2/tiles/StrutsAttributeEvaluator.java | 33 ++--------
 .../tiles/StrutsTilesContainerFactory.java      |  9 ++-
 3 files changed, 80 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/431e50e9/plugins/tiles/src/main/java/org/apache/struts2/tiles/I18NAttributeEvaluator.java
----------------------------------------------------------------------
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/I18NAttributeEvaluator.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/I18NAttributeEvaluator.java
new file mode 100644
index 0000000..37150ae
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/I18NAttributeEvaluator.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.struts2.tiles;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.LocaleProvider;
+import com.opensymphony.xwork2.TextProvider;
+import com.opensymphony.xwork2.TextProviderFactory;
+import com.opensymphony.xwork2.config.ConfigurationException;
+import com.opensymphony.xwork2.ognl.OgnlUtil;
+import ognl.OgnlException;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.struts2.ServletActionContext;
+import org.apache.tiles.evaluator.AbstractAttributeEvaluator;
+import org.apache.tiles.evaluator.EvaluationException;
+import org.apache.tiles.request.Request;
+import org.apache.tiles.request.servlet.ServletUtil;
+
+import javax.servlet.http.HttpServletRequest;
+
+public class I18NAttributeEvaluator extends AbstractAttributeEvaluator {
+
+    private static final Logger LOG = LogManager.getLogger(I18NAttributeEvaluator.class);
+
+    @Override
+    public Object evaluate(String expression, Request request) {
+        Object result = expression;
+
+        HttpServletRequest httpRequest = ServletUtil.getServletRequest(request).getRequest();
+        ActionContext ctx = ServletActionContext.getActionContext(httpRequest);
+
+        if (ctx == null) {
+            LOG.error("Cannot obtain HttpServletRequest from [{}]", request.getClass().getName());
+            throw new ConfigurationException("There is no ActionContext for current request!");
+        }
+
+        TextProviderFactory tpf = new TextProviderFactory();
+        ctx.getContainer().inject(tpf);
+        LocaleProvider localeProvider = ctx.getContainer().getInstance(LocaleProvider.class);
+
+        TextProvider textProvider = tpf.createInstance(ctx.getActionInvocation().getAction().getClass(), localeProvider);
+
+        if (textProvider != null) {
+            LOG.debug("Trying find text [{}] using TextProvider {}", expression, textProvider);
+            result = textProvider.getText(expression);
+        }
+        return result;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/struts/blob/431e50e9/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsAttributeEvaluator.java
----------------------------------------------------------------------
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsAttributeEvaluator.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsAttributeEvaluator.java
index 8b98ab2..b4ef56a 100644
--- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsAttributeEvaluator.java
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsAttributeEvaluator.java
@@ -20,9 +20,6 @@
 package org.apache.struts2.tiles;
 
 import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.LocaleProvider;
-import com.opensymphony.xwork2.TextProvider;
-import com.opensymphony.xwork2.TextProviderFactory;
 import com.opensymphony.xwork2.config.ConfigurationException;
 import com.opensymphony.xwork2.ognl.OgnlUtil;
 import com.opensymphony.xwork2.util.logging.Logger;
@@ -43,8 +40,6 @@ public class StrutsAttributeEvaluator extends AbstractAttributeEvaluator {
 
     public Object evaluate(String expression, TilesRequestContext request) {
         try {
-            Object result = null;
-
             HttpServletRequest httpRequest = ServletUtil.getServletRequest(request).getRequest();
             ActionContext ctx = ServletActionContext.getActionContext(httpRequest);
 
@@ -53,34 +48,14 @@ public class StrutsAttributeEvaluator extends AbstractAttributeEvaluator {
                 throw new ConfigurationException("There is no ActionContext for current request!");
             }
 
-            TextProviderFactory tpf = new TextProviderFactory();
-            ctx.getContainer().inject(tpf);
-            LocaleProvider localeProvider = ctx.getContainer().getInstance(LocaleProvider.class);
-
-            TextProvider textProvider = tpf.createInstance(ctx.getActionInvocation().getAction().getClass(), localeProvider);
-
-            if (textProvider != null) {
-                LOG.debug("Trying find text [{}] using TextProvider {}", expression, textProvider);
-                result = textProvider.getText(expression);
-                if (expression.equals(result)) {
-                    LOG.debug("Could not evaluate expression [{}] as a I18N key", expression);
-                    result = null;
-                }
-            }
+            OgnlUtil ognlUtil = ctx.getContainer().getInstance(OgnlUtil.class);
 
-            if (result == null) {
-                OgnlUtil ognlUtil = ctx.getContainer().getInstance(OgnlUtil.class);
-                LOG.debug("Trying evaluate expression [{}] using OgnlUtil's getValue", expression);
-                result = ognlUtil.getValue(expression, ctx.getContextMap(), ctx.getValueStack().getRoot());
-            }
+            LOG.debug("Trying evaluate expression [{}] using OgnlUtil's getValue", expression);
+            Object result = ognlUtil.getValue(expression, ctx.getContextMap(), ctx.getValueStack().getRoot());
 
             LOG.debug("Final result of evaluating expression [{}] is: {}", expression, result);
 
-            if (result == null) {
-                return expression;
-            } else {
-                return result;
-            }
+            return result;
         } catch (OgnlException e) {
             throw new EvaluationException(e);
         }

http://git-wip-us.apache.org/repos/asf/struts/blob/431e50e9/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
----------------------------------------------------------------------
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
index ee6cbfe..c1ca654 100644
--- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesContainerFactory.java
@@ -83,7 +83,8 @@ import java.util.Set;
 /**
  * Dedicated Struts factory to build Tiles container with support for:
  * - Freemarker
- * - Struts I18N & ValueStack (as default)
+ * - I18N using Struts resource bundles
+ * - S2 ro access Struts' ValueStack
  * - OGNL
  * - EL
  *
@@ -114,6 +115,7 @@ public class StrutsTilesContainerFactory extends BasicTilesContainerFactory {
     public static final String OGNL = "OGNL";
     public static final String EL = "EL";
     public static final String S2 = "S2";
+    public static final String I18N = "I18N";
 
     @Override
     protected BasicTilesContainer instantiateContainer(TilesApplicationContext applicationContext) {
@@ -190,6 +192,7 @@ public class StrutsTilesContainerFactory extends BasicTilesContainerFactory {
 
         BasicAttributeEvaluatorFactory attributeEvaluatorFactory = new BasicAttributeEvaluatorFactory(new DirectAttributeEvaluator());
         attributeEvaluatorFactory.registerAttributeEvaluator(S2, createStrutsEvaluator());
+        attributeEvaluatorFactory.registerAttributeEvaluator(I18N, createI18NEvaluator());
         attributeEvaluatorFactory.registerAttributeEvaluator(OGNL, createOGNLEvaluator());
 
         ELAttributeEvaluator elEvaluator = createELEvaluator(applicationContext);
@@ -268,6 +271,10 @@ public class StrutsTilesContainerFactory extends BasicTilesContainerFactory {
         return new StrutsAttributeEvaluator();
     }
 
+    protected I18NAttributeEvaluator createI18NEvaluator() {
+        return new I18NAttributeEvaluator();
+    }
+
     protected OGNLAttributeEvaluator createOGNLEvaluator() {
         try {
             PropertyAccessor objectPropertyAccessor = OgnlRuntime.getPropertyAccessor(Object.class);