mirror of
https://github.com/apache/struts.git
synced 2026-08-07 07:37:20 +00:00
WW-4243 Splits interface in to two to allow using different implementation
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1542808 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -70,15 +70,15 @@ import com.opensymphony.xwork2.util.ValueStack;
|
||||
/**
|
||||
* The default Struts tag library
|
||||
*/
|
||||
public class DefaultTagLibrary implements TagLibrary {
|
||||
public class DefaultTagLibrary implements TagLibraryDirectiveProvider, TagLibraryModelProvider {
|
||||
|
||||
public Object getFreemarkerModels(ValueStack stack, HttpServletRequest req,
|
||||
HttpServletResponse res) {
|
||||
public Object getModels(ValueStack stack, HttpServletRequest req,
|
||||
HttpServletResponse res) {
|
||||
|
||||
return new StrutsModels(stack, req, res);
|
||||
}
|
||||
|
||||
public List<Class> getVelocityDirectiveClasses() {
|
||||
public List<Class> getDirectiveClasses() {
|
||||
Class[] directives = new Class[] {
|
||||
ActionDirective.class,
|
||||
BeanDirective.class,
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* $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 implementation classes for a tag library
|
||||
*/
|
||||
public interface TagLibraryDirectiveProvider {
|
||||
|
||||
/**
|
||||
* 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> getDirectiveClasses();
|
||||
|
||||
}
|
||||
+8
-17
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id$
|
||||
* $Id: TagLibrary.java 651946 2008-04-27 13:41:38Z apetrelli $
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
@@ -21,34 +21,25 @@
|
||||
|
||||
package org.apache.struts2.views;
|
||||
|
||||
import java.util.List;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
|
||||
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
|
||||
* Provides Freemarker implementation classes for a tag library
|
||||
*/
|
||||
public interface TagLibrary {
|
||||
public interface TagLibraryModelProvider {
|
||||
|
||||
/**
|
||||
* Gets a Java object that contains getters for the tag library's Freemarker models.
|
||||
* 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();
|
||||
Object getModels(ValueStack stack, HttpServletRequest req, HttpServletResponse res);
|
||||
|
||||
}
|
||||
@@ -47,7 +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;
|
||||
|
||||
import javax.servlet.GenericServlet;
|
||||
@@ -176,7 +176,7 @@ public class FreemarkerManager {
|
||||
protected boolean cacheBeanWrapper;
|
||||
protected int mruMaxStrongSize;
|
||||
protected String templateUpdateDelay;
|
||||
protected Map<String,TagLibrary> tagLibraries;
|
||||
protected Map<String,TagLibraryModelProvider> tagLibraries;
|
||||
|
||||
private FileManager fileManager;
|
||||
private FreemarkerThemeTemplateLoader themeTemplateLoader;
|
||||
@@ -208,10 +208,10 @@ public class FreemarkerManager {
|
||||
|
||||
@Inject
|
||||
public void setContainer(Container container) {
|
||||
Map<String,TagLibrary> map = new HashMap<String,TagLibrary>();
|
||||
Set<String> prefixes = container.getInstanceNames(TagLibrary.class);
|
||||
Map<String,TagLibraryModelProvider> map = new HashMap<String,TagLibraryModelProvider>();
|
||||
Set<String> prefixes = container.getInstanceNames(TagLibraryModelProvider.class);
|
||||
for (String prefix : prefixes) {
|
||||
map.put(prefix, container.getInstance(TagLibrary.class, prefix));
|
||||
map.put(prefix, container.getInstance(TagLibraryModelProvider.class, prefix));
|
||||
}
|
||||
this.tagLibraries = Collections.unmodifiableMap(map);
|
||||
}
|
||||
@@ -530,7 +530,7 @@ public class FreemarkerManager {
|
||||
populateContext(model, stack, action, request, response);
|
||||
if (tagLibraries != null) {
|
||||
for (String prefix : tagLibraries.keySet()) {
|
||||
model.put(prefix, tagLibraries.get(prefix).getFreemarkerModels(stack, request, response));
|
||||
model.put(prefix, tagLibraries.get(prefix).getModels(stack, request, response));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +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;
|
||||
import org.apache.velocity.VelocityContext;
|
||||
@@ -99,7 +99,7 @@ public class VelocityManager {
|
||||
|
||||
private String customConfigFile;
|
||||
|
||||
private List<TagLibrary> tagLibraries;
|
||||
private List<TagLibraryDirectiveProvider> tagLibraries;
|
||||
|
||||
@Inject
|
||||
public void setObjectFactory(ObjectFactory fac) {
|
||||
@@ -108,10 +108,10 @@ public class VelocityManager {
|
||||
|
||||
@Inject
|
||||
public void setContainer(Container container) {
|
||||
List<TagLibrary> list = new ArrayList<TagLibrary>();
|
||||
Set<String> prefixes = container.getInstanceNames(TagLibrary.class);
|
||||
List<TagLibraryDirectiveProvider> list = new ArrayList<TagLibraryDirectiveProvider>();
|
||||
Set<String> prefixes = container.getInstanceNames(TagLibraryDirectiveProvider.class);
|
||||
for (String prefix : prefixes) {
|
||||
list.add(container.getInstance(TagLibrary.class, prefix));
|
||||
list.add(container.getInstance(TagLibraryDirectiveProvider.class, prefix));
|
||||
}
|
||||
this.tagLibraries = Collections.unmodifiableList(list);
|
||||
}
|
||||
@@ -524,8 +524,8 @@ public class VelocityManager {
|
||||
// components
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (TagLibrary tagLibrary : tagLibraries) {
|
||||
List<Class> directives = tagLibrary.getVelocityDirectiveClasses();
|
||||
for (TagLibraryDirectiveProvider tagLibrary : tagLibraries) {
|
||||
List<Class> directives = tagLibrary.getDirectiveClasses();
|
||||
for (Class directive : directives) {
|
||||
addDirective(sb, directive);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,8 @@
|
||||
|
||||
<bean type="org.apache.struts2.dispatcher.multipart.MultiPartRequest" name="jakarta" class="org.apache.struts2.dispatcher.multipart.JakartaMultiPartRequest" scope="default"/>
|
||||
|
||||
<bean type="org.apache.struts2.views.TagLibrary" name="s" class="org.apache.struts2.views.DefaultTagLibrary" />
|
||||
<bean type="org.apache.struts2.views.TagLibraryDirectiveProvider" name="s" class="org.apache.struts2.views.DefaultTagLibrary" />
|
||||
<bean type="org.apache.struts2.views.TagLibraryModelProvider" name="s" class="org.apache.struts2.views.DefaultTagLibrary" />
|
||||
|
||||
<bean class="org.apache.struts2.views.freemarker.FreemarkerThemeTemplateLoader" />
|
||||
<bean class="org.apache.struts2.views.freemarker.FreemarkerManager" name="struts" />
|
||||
|
||||
@@ -39,19 +39,19 @@ import org.apache.struts2.dojo.views.velocity.components.TabbedPanelDirective;
|
||||
import org.apache.struts2.dojo.views.velocity.components.TextAreaDirective;
|
||||
import org.apache.struts2.dojo.views.velocity.components.TreeDirective;
|
||||
import org.apache.struts2.dojo.views.velocity.components.TreeNodeDirective;
|
||||
import org.apache.struts2.views.TagLibrary;
|
||||
import org.apache.struts2.views.TagLibraryDirectiveProvider;
|
||||
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.struts2.views.TagLibraryModelProvider;
|
||||
|
||||
public class DojoTagLibrary implements TagLibrary {
|
||||
public class DojoTagLibrary implements TagLibraryDirectiveProvider, TagLibraryModelProvider {
|
||||
|
||||
public Object getFreemarkerModels(ValueStack stack, HttpServletRequest req,
|
||||
HttpServletResponse res) {
|
||||
public Object getModels(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
|
||||
|
||||
return new DojoModels(stack, req, res);
|
||||
}
|
||||
|
||||
public List<Class> getVelocityDirectiveClasses() {
|
||||
public List<Class> getDirectiveClasses() {
|
||||
Class[] directives = new Class[] {
|
||||
DateTimePickerDirective.class,
|
||||
DivDirective.class,
|
||||
|
||||
@@ -26,5 +26,6 @@
|
||||
"http://struts.apache.org/dtds/struts-2.3.dtd">
|
||||
|
||||
<struts>
|
||||
<bean type="org.apache.struts2.views.TagLibrary" name="sx" class="org.apache.struts2.dojo.views.DojoTagLibrary" />
|
||||
<bean type="org.apache.struts2.views.TagLibraryDirectiveProvider" name="sx" class="org.apache.struts2.dojo.views.DojoTagLibrary" />
|
||||
<bean type="org.apache.struts2.views.TagLibraryModelProvider" name="sx" class="org.apache.struts2.dojo.views.DojoTagLibrary" />
|
||||
</struts>
|
||||
Reference in New Issue
Block a user