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 2017/06/18 09:11:32 UTC

[1/2] struts git commit: WW-4758 Uses ObjectFactory to create Tiles' ViewPrepare

Repository: struts
Updated Branches:
  refs/heads/master 843693fdd -> 93dba5bce


WW-4758 Uses ObjectFactory to create Tiles' ViewPrepare


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

Branch: refs/heads/master
Commit: 93dba5bce22e9e7e539e3e631166d6510efca023
Parents: 216c520
Author: Lukasz Lenart <lu...@apache.org>
Authored: Sun Jun 18 11:11:11 2017 +0200
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Sun Jun 18 11:11:25 2017 +0200

----------------------------------------------------------------------
 .../struts2/tiles/StrutsPreparerFactory.java    | 53 ++++++++++++++++++++
 .../tiles/StrutsTilesContainerFactory.java      |  6 +++
 2 files changed, 59 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/93dba5bc/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsPreparerFactory.java
----------------------------------------------------------------------
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsPreparerFactory.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsPreparerFactory.java
new file mode 100644
index 0000000..d231786
--- /dev/null
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsPreparerFactory.java
@@ -0,0 +1,53 @@
+/*
+ * 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.ObjectFactory;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.message.ParameterizedMessage;
+import org.apache.tiles.preparer.ViewPreparer;
+import org.apache.tiles.preparer.factory.BasicPreparerFactory;
+
+/**
+ * This is a basic ViewPreparer factory that uses {@link ObjectFactory} to create the ViewPreparer
+ */
+public class StrutsPreparerFactory extends BasicPreparerFactory {
+
+    private static final Logger LOG = LogManager.getLogger(StrutsPreparerFactory.class);
+
+    @Override
+    protected ViewPreparer createPreparer(String name) {
+        ActionContext actionContext = ActionContext.getContext();
+        if (actionContext == null) {
+            LOG.warn("Action context not initialised, request has omitted an action? Fallback to super.createPreparer!");
+            return super.createPreparer(name);
+        }
+
+        try {
+            ObjectFactory factory = actionContext.getContainer().getInstance(ObjectFactory.class);
+            return (ViewPreparer) factory.buildBean(name, ActionContext.getContext().getContextMap());
+        } catch (Exception e) {
+            LOG.error(new ParameterizedMessage("Cannot create a ViewPreparer [{}], fallback to super.createPreparer!", name), e);
+            return super.createPreparer(name);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/struts/blob/93dba5bc/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 b7564a9..99a259d 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
@@ -52,6 +52,7 @@ import org.apache.tiles.ognl.PropertyAccessorDelegateFactory;
 import org.apache.tiles.ognl.ScopePropertyAccessor;
 import org.apache.tiles.ognl.TilesApplicationContextNestedObjectExtractor;
 import org.apache.tiles.ognl.TilesContextPropertyAccessorDelegateFactory;
+import org.apache.tiles.preparer.factory.PreparerFactory;
 import org.apache.tiles.request.ApplicationContext;
 import org.apache.tiles.request.ApplicationResource;
 import org.apache.tiles.request.Request;
@@ -204,6 +205,11 @@ public class StrutsTilesContainerFactory extends BasicTilesContainerFactory {
         return filteredResources;
     }
 
+    @Override
+    protected PreparerFactory createPreparerFactory(ApplicationContext applicationContext) {
+        return new StrutsPreparerFactory();
+    }
+
     protected Set<String> getTilesDefinitions(Map<String, String> params) {
         if (params.containsKey(DefinitionsFactory.DEFINITIONS_CONFIG)) {
             return TextParseUtil.commaDelimitedStringToSet(params.get(DefinitionsFactory.DEFINITIONS_CONFIG));


[2/2] struts git commit: Cleans up code

Posted by lu...@apache.org.
Cleans up code


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

Branch: refs/heads/master
Commit: 216c52095ecabbe87ff4c121d7602ec35ce65123
Parents: 843693f
Author: Lukasz Lenart <lu...@apache.org>
Authored: Sun Jun 18 11:07:25 2017 +0200
Committer: Lukasz Lenart <lu...@apache.org>
Committed: Sun Jun 18 11:11:25 2017 +0200

----------------------------------------------------------------------
 .../org/apache/struts2/tiles/StrutsTilesAnnotationProcessor.java | 4 ++--
 .../java/org/apache/struts2/tiles/StrutsTilesLocaleResolver.java | 1 -
 2 files changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/216c5209/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesAnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesAnnotationProcessor.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesAnnotationProcessor.java
index fa5f735..e36b75d 100644
--- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesAnnotationProcessor.java
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesAnnotationProcessor.java
@@ -54,14 +54,14 @@ public class StrutsTilesAnnotationProcessor {
      * @return {@link TilesDefinition}
      */
     public TilesDefinition findAnnotation(Object action, String tileName) {
-        Class<? extends Object> clazz = action.getClass();
+        Class<?> clazz = action.getClass();
         TilesDefinition tilesDefinition = clazz.getAnnotation(TilesDefinition.class);
         TilesDefinitions tilesDefinitions = clazz.getAnnotation(TilesDefinitions.class);
 
         if (tilesDefinition == null && tilesDefinitions != null) {
             if (!StringUtils.isEmpty(tileName)) {
                 for (TilesDefinition i : tilesDefinitions.value()) {
-                    if (i.name() != null && i.name().equals(tileName)) {
+                    if (i.name().equals(tileName)) {
                         tilesDefinition = i;
                         break;
                     }

http://git-wip-us.apache.org/repos/asf/struts/blob/216c5209/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesLocaleResolver.java
----------------------------------------------------------------------
diff --git a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesLocaleResolver.java b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesLocaleResolver.java
index e75cd48..90b9fa0 100644
--- a/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesLocaleResolver.java
+++ b/plugins/tiles/src/main/java/org/apache/struts2/tiles/StrutsTilesLocaleResolver.java
@@ -20,7 +20,6 @@
 package org.apache.struts2.tiles;
 
 import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.LocaleProvider;
 import com.opensymphony.xwork2.LocaleProviderFactory;
 import com.opensymphony.xwork2.config.ConfigurationException;
 import org.apache.logging.log4j.LogManager;