Skip to content

Commit

Permalink
Merge pull request apache#867 from apache/WW-5391-velocity-ext-point
Browse files Browse the repository at this point in the history
WW-5391 Add interface for VelocityManager extension point
  • Loading branch information
kusalk authored Feb 5, 2024
2 parents ce24675 + 889a418 commit 4aa1cbc
Show file tree
Hide file tree
Showing 12 changed files with 727 additions and 593 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.struts2.dispatcher.multipart.MultiPartRequest;
import org.apache.struts2.views.freemarker.FreemarkerManager;
import org.apache.struts2.views.velocity.VelocityConstants;
import org.apache.struts2.views.velocity.VelocityManager;
import org.apache.struts2.views.velocity.VelocityManagerInterface;

import java.util.Map;
import java.util.Set;
Expand All @@ -56,7 +56,7 @@ public void setContainer(Container container) {
bindings.put(ActionMapper.class.getName(), addBindings(container, ActionMapper.class, StrutsConstants.STRUTS_MAPPER_CLASS));
bindings.put(MultiPartRequest.class.getName(), addBindings(container, MultiPartRequest.class, StrutsConstants.STRUTS_MULTIPART_PARSER));
bindings.put(FreemarkerManager.class.getName(), addBindings(container, FreemarkerManager.class, StrutsConstants.STRUTS_FREEMARKER_MANAGER_CLASSNAME));
bindings.put(VelocityManager.class.getName(), addBindings(container, VelocityManager.class, VelocityConstants.STRUTS_VELOCITY_MANAGER_CLASSNAME));
bindings.put(VelocityManagerInterface.class.getName(), addBindings(container, VelocityManagerInterface.class, VelocityConstants.STRUTS_VELOCITY_MANAGER_CLASSNAME));
bindings.put(UrlRenderer.class.getName(), addBindings(container, UrlRenderer.class, StrutsConstants.STRUTS_URL_RENDERER));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,22 @@
import com.opensymphony.xwork2.config.Configuration;
import com.opensymphony.xwork2.config.ConfigurationException;
import com.opensymphony.xwork2.config.PackageProvider;
import com.opensymphony.xwork2.config.entities.PackageConfig;
import com.opensymphony.xwork2.inject.Inject;
import com.opensymphony.xwork2.util.finder.ClassLoaderInterface;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.osgi.host.OsgiHost;
import org.apache.struts2.osgi.loaders.VelocityBundleResourceLoader;
import org.apache.struts2.views.velocity.VelocityManager;
import org.apache.struts2.views.velocity.VelocityManagerInterface;
import org.apache.velocity.app.Velocity;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;

import javax.servlet.ServletContext;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
Expand Down Expand Up @@ -255,16 +254,27 @@ public void setBundleAccessor(BundleAccessor acc) {
}

@Inject
public void setVelocityManager(VelocityManager vm) {
LOG.trace("OSGi ConfigurationProvider - setVelocityManager() called - VelocityManager: [{}]", vm);

public void setVelocityManager(VelocityManagerInterface vmi) {
LOG.trace("OSGi ConfigurationProvider - setVelocityManager() called - VelocityManager: [{}]", vmi);
if (!(vmi instanceof VelocityManager)) {
return;
}
VelocityManager vm = (VelocityManager) vmi;
Properties props = new Properties();
props.setProperty("osgi.resource.loader.description", "OSGI bundle loader");
props.setProperty("osgi.resource.loader.class", VelocityBundleResourceLoader.class.getName());
props.setProperty(Velocity.RESOURCE_LOADER, "strutsfile,strutsclass,osgi");
vm.setVelocityProperties(props);
}

/**
* @deprecated since 6.4.0
*/
@Deprecated
public void setVelocityManager(VelocityManager mgr) {
setVelocityManager((VelocityManagerInterface) mgr);
}

@Inject
public void setServletContext(ServletContext servletContext) {
LOG.trace("OSGi ConfigurationProvider - setServletContext() called - ServletContext: [{}]", servletContext);
Expand Down
Loading

0 comments on commit 4aa1cbc

Please sign in to comment.