struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject git commit: WW-4255 restores TagLibrary interface and marks it as deprecated
Date Wed, 09 Jul 2014 18:00:22 GMT
Repository: struts
Updated Branches:
  refs/heads/develop cc89601b6 -> 9aedd857a


WW-4255 restores TagLibrary interface and marks it as deprecated


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

Branch: refs/heads/develop
Commit: 9aedd857a4294a5091bce6abcdcb183f83833cb6
Parents: cc89601
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Wed Jul 9 20:00:08 2014 +0200
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Wed Jul 9 20:00:08 2014 +0200

----------------------------------------------------------------------
 .../apache/struts2/views/DefaultTagLibrary.java | 10 +++-
 .../org/apache/struts2/views/TagLibrary.java    | 57 ++++++++++++++++++++
 .../views/freemarker/FreemarkerManager.java     | 15 ++++++
 .../struts2/views/velocity/VelocityManager.java | 16 ++++++
 4 files changed, 97 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/9aedd857/core/src/main/java/org/apache/struts2/views/DefaultTagLibrary.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/views/DefaultTagLibrary.java b/core/src/main/java/org/apache/struts2/views/DefaultTagLibrary.java
index b5d9049..4ed6bc3 100644
--- a/core/src/main/java/org/apache/struts2/views/DefaultTagLibrary.java
+++ b/core/src/main/java/org/apache/struts2/views/DefaultTagLibrary.java
@@ -70,7 +70,7 @@ import com.opensymphony.xwork2.util.ValueStack;
 /**
  * The default Struts tag library
  */
-public class DefaultTagLibrary implements TagLibraryDirectiveProvider, TagLibraryModelProvider
{
+public class DefaultTagLibrary implements TagLibraryDirectiveProvider, TagLibraryModelProvider,
TagLibrary {
 
     public Object getModels(ValueStack stack, HttpServletRequest req,
                             HttpServletResponse res) {
@@ -120,4 +120,12 @@ public class DefaultTagLibrary implements TagLibraryDirectiveProvider,
TagLibrar
         return Arrays.asList(directives);
     }
 
+    public Object getFreemarkerModels(ValueStack stack, HttpServletRequest req, HttpServletResponse
res) {
+        return getModels(stack, req, res);
+    }
+
+    public List<Class> getVelocityDirectiveClasses() {
+        return getDirectiveClasses();
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/struts/blob/9aedd857/core/src/main/java/org/apache/struts2/views/TagLibrary.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/views/TagLibrary.java b/core/src/main/java/org/apache/struts2/views/TagLibrary.java
new file mode 100644
index 0000000..b4c36d7
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/views/TagLibrary.java
@@ -0,0 +1,57 @@
+/*
+ * $Id$
+ *
+ * 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.views;
+
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.opensymphony.xwork2.util.ValueStack;
+
+/**
+ * Provides Velocity and Freemarker implementation classes for a tag library
+ *
+ * @deprecated use two other interfaces: {@link TagLibraryDirectiveProvider}, {@link TagLibraryModelProvider}
+ */
+@Deprecated
+public interface TagLibrary {
+
+    /**
+     * Gets a Java object that contains getters for the tag library's Freemarker models.
 
+     * Called once per Freemarker template processing.
+     *
+     * @param stack The current value stack
+     * @param req The HTTP request
+     * @param res The HTTP response
+     * @return The Java object containing the Freemarker model getter methods
+     */
+    public Object getFreemarkerModels(ValueStack stack, HttpServletRequest req, HttpServletResponse
res);
+
+    /**
+     * Gets a list of Velocity directive classes for the tag library.  Called once on framework
+     * startup when initializing Velocity.
+     *
+     * @return A list of Velocity directive classes
+     */
+    public List<Class> getVelocityDirectiveClasses();
+}

http://git-wip-us.apache.org/repos/asf/struts/blob/9aedd857/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java
b/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java
index 39b7fe6..2a16689 100644
--- a/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java
+++ b/core/src/main/java/org/apache/struts2/views/freemarker/FreemarkerManager.java
@@ -47,6 +47,7 @@ import freemarker.template.TemplateModel;
 import freemarker.template.utility.StringUtil;
 import org.apache.struts2.StrutsConstants;
 import org.apache.struts2.views.JspSupportServlet;
+import org.apache.struts2.views.TagLibrary;
 import org.apache.struts2.views.TagLibraryModelProvider;
 import org.apache.struts2.views.util.ContextUtil;
 
@@ -177,6 +178,7 @@ public class FreemarkerManager {
     protected int mruMaxStrongSize;
     protected String templateUpdateDelay;
     protected Map<String,TagLibraryModelProvider> tagLibraries;
+    protected Map<String, TagLibrary> oldTagLibraries;
 
     private FileManager fileManager;
     private FreemarkerThemeTemplateLoader themeTemplateLoader;
@@ -214,6 +216,13 @@ public class FreemarkerManager {
             map.put(prefix, container.getInstance(TagLibraryModelProvider.class, prefix));
         }
         this.tagLibraries = Collections.unmodifiableMap(map);
+
+        Map<String, TagLibrary> oldMap = new HashMap<String, TagLibrary>();
+        Set<String> oldPrefixes = container.getInstanceNames(TagLibrary.class);
+        for (String prefix : oldPrefixes) {
+            oldMap.put(prefix, container.getInstance(TagLibrary.class, prefix));
+        }
+        this.oldTagLibraries = Collections.unmodifiableMap(oldMap);
     }
 
     @Inject
@@ -534,6 +543,12 @@ public class FreemarkerManager {
             }
         }
 
+        if (oldTagLibraries != null) {
+            for (String prefix : oldTagLibraries.keySet()) {
+                model.put(prefix, oldTagLibraries.get(prefix).getFreemarkerModels(stack,
request, response));
+            }
+        }
+
         //place the model in the request using the special parameter.  This can be retrieved
for freemarker and velocity.
         request.setAttribute(ATTR_TEMPLATE_MODEL, model);
 

http://git-wip-us.apache.org/repos/asf/struts/blob/9aedd857/core/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java b/core/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java
index 1e159b8..e026a2c 100644
--- a/core/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java
+++ b/core/src/main/java/org/apache/struts2/views/velocity/VelocityManager.java
@@ -32,6 +32,7 @@ import org.apache.struts2.ServletActionContext;
 import org.apache.struts2.StrutsConstants;
 import org.apache.struts2.StrutsException;
 import org.apache.struts2.util.VelocityStrutsUtil;
+import org.apache.struts2.views.TagLibrary;
 import org.apache.struts2.views.TagLibraryDirectiveProvider;
 import org.apache.struts2.views.jsp.ui.OgnlTool;
 import org.apache.struts2.views.util.ContextUtil;
@@ -100,6 +101,7 @@ public class VelocityManager {
     private String customConfigFile;
 
     private List<TagLibraryDirectiveProvider> tagLibraries;
+    private List<TagLibrary> oldTagLibraries;
 
     @Inject
     public void setObjectFactory(ObjectFactory fac) {
@@ -114,6 +116,13 @@ public class VelocityManager {
             list.add(container.getInstance(TagLibraryDirectiveProvider.class, prefix));
         }
         this.tagLibraries = Collections.unmodifiableList(list);
+
+        List<TagLibrary> oldList = new ArrayList<TagLibrary>();
+        Set<String> oldPrefixes = container.getInstanceNames(TagLibrary.class);
+        for (String prefix : oldPrefixes) {
+            oldList.add(container.getInstance(TagLibrary.class, prefix));
+        }
+        this.oldTagLibraries = Collections.unmodifiableList(oldList);
     }
 
     /**
@@ -531,6 +540,13 @@ public class VelocityManager {
             }
         }
 
+        for (TagLibrary tagLibrary : oldTagLibraries) {
+            List<Class> directives = tagLibrary.getVelocityDirectiveClasses();
+            for (Class directive : directives) {
+                addDirective(sb, directive);
+            }
+        }
+
         String directives = sb.toString();
 
         String userdirective = p.getProperty("userdirective");


Mime
View raw message