diff --git a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowBeansAction.java b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowBeansAction.java index 8e97a87fd..1e8dab8be 100644 --- a/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowBeansAction.java +++ b/plugins/config-browser/src/main/java/org/apache/struts2/config_browser/ShowBeansAction.java @@ -30,7 +30,7 @@ import org.apache.struts2.dispatcher.mapper.ActionMapper; 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; @@ -56,7 +56,7 @@ public class ShowBeansAction extends ActionNamesAction { 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)); } diff --git a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/OldDecorator2NewStrutsVelocityDecorator.java b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/OldDecorator2NewStrutsVelocityDecorator.java index cd0417364..33d5b1f3a 100644 --- a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/OldDecorator2NewStrutsVelocityDecorator.java +++ b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/OldDecorator2NewStrutsVelocityDecorator.java @@ -1,101 +1,110 @@ -/* - * 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.sitemesh; - -import com.opensymphony.module.sitemesh.HTMLPage; -import com.opensymphony.sitemesh.Content; -import com.opensymphony.sitemesh.compatability.Content2HTMLPage; -import com.opensymphony.xwork2.ActionContext; -import com.opensymphony.xwork2.inject.Inject; -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; -import org.apache.struts2.views.velocity.VelocityManager; -import org.apache.velocity.context.Context; - -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.PrintWriter; - -/** - * Extends OldDecorator2NewStrutsDecorator to add Struts functionality for Velocity - */ -public class OldDecorator2NewStrutsVelocityDecorator extends OldDecorator2NewStrutsDecorator { - private static final Logger LOG = LogManager.getLogger(OldDecorator2NewStrutsFreemarkerDecorator.class); - - private static VelocityManager velocityManager; - - @Inject(required = false) - public static void setVelocityManager(VelocityManager mgr) { - velocityManager = mgr; - } - - public OldDecorator2NewStrutsVelocityDecorator(com.opensymphony.module.sitemesh.Decorator oldDecorator) { - this.oldDecorator = oldDecorator; - } - - /** - * Applies the decorator, using the relevent contexts - * - * @param content The content - * @param request The servlet request - * @param response The servlet response - * @param servletContext The servlet context - * @param ctx The action context for this request, populated with the server state - */ - protected void render(Content content, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext, ActionContext ctx) throws ServletException, IOException { - if (velocityManager == null) { - throw new ServletException("Missing freemarker dependency"); - } - - try { - - // init (if needed) - velocityManager.init(servletContext); - - // get encoding - String encoding = getEncoding(); - - HTMLPage htmlPage = new Content2HTMLPage(content, request); - - // get the template and context - org.apache.velocity.Template template = velocityManager.getVelocityEngine().getTemplate(oldDecorator.getPage(), encoding); - Context context = velocityManager.createContext(ctx.getValueStack(), request, response); - - // put the page in the context - context.put("page", htmlPage); - context.put("head", htmlPage.getHead()); - context.put("title", htmlPage.getTitle()); - context.put("body", htmlPage.getBody()); - - // finally, render it - PrintWriter writer = response.getWriter(); - template.merge(context, writer); - writer.flush(); - } catch (Exception e) { - String msg = "Error applying decorator to request: " + request.getRequestURL() + "?" + request.getQueryString() + " with message:" + e.getMessage(); - LOG.error(msg, e); - throw new ServletException(msg, e); - } - } - -} - +/* + * 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.sitemesh; + +import com.opensymphony.module.sitemesh.HTMLPage; +import com.opensymphony.sitemesh.Content; +import com.opensymphony.sitemesh.compatability.Content2HTMLPage; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.inject.Inject; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.struts2.views.velocity.VelocityManager; +import org.apache.struts2.views.velocity.VelocityManagerInterface; +import org.apache.velocity.context.Context; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; + +/** + * Extends OldDecorator2NewStrutsDecorator to add Struts functionality for Velocity + */ +public class OldDecorator2NewStrutsVelocityDecorator extends OldDecorator2NewStrutsDecorator { + private static final Logger LOG = LogManager.getLogger(OldDecorator2NewStrutsFreemarkerDecorator.class); + + private static VelocityManagerInterface velocityManager; + + @Inject(required = false) + public static void setVelocityManager(VelocityManagerInterface mgr) { + velocityManager = mgr; + } + + /** + * @deprecated since 6.4.0 + */ + @Deprecated + public static void setVelocityManager(VelocityManager mgr) { + setVelocityManager((VelocityManagerInterface) mgr); + } + + public OldDecorator2NewStrutsVelocityDecorator(com.opensymphony.module.sitemesh.Decorator oldDecorator) { + this.oldDecorator = oldDecorator; + } + + /** + * Applies the decorator, using the relevent contexts + * + * @param content The content + * @param request The servlet request + * @param response The servlet response + * @param servletContext The servlet context + * @param ctx The action context for this request, populated with the server state + */ + protected void render(Content content, HttpServletRequest request, HttpServletResponse response, ServletContext servletContext, ActionContext ctx) throws ServletException, IOException { + if (velocityManager == null) { + throw new ServletException("Missing freemarker dependency"); + } + + try { + + // init (if needed) + velocityManager.init(servletContext); + + // get encoding + String encoding = getEncoding(); + + HTMLPage htmlPage = new Content2HTMLPage(content, request); + + // get the template and context + org.apache.velocity.Template template = velocityManager.getVelocityEngine().getTemplate(oldDecorator.getPage(), encoding); + Context context = velocityManager.createContext(ctx.getValueStack(), request, response); + + // put the page in the context + context.put("page", htmlPage); + context.put("head", htmlPage.getHead()); + context.put("title", htmlPage.getTitle()); + context.put("body", htmlPage.getBody()); + + // finally, render it + PrintWriter writer = response.getWriter(); + template.merge(context, writer); + writer.flush(); + } catch (Exception e) { + String msg = "Error applying decorator to request: " + request.getRequestURL() + "?" + request.getQueryString() + " with message:" + e.getMessage(); + LOG.error(msg, e); + throw new ServletException(msg, e); + } + } + +} + diff --git a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityPageFilter.java b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityPageFilter.java index 22de2c60a..d4a2314df 100644 --- a/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityPageFilter.java +++ b/plugins/sitemesh/src/main/java/org/apache/struts2/sitemesh/VelocityPageFilter.java @@ -18,16 +18,16 @@ */ package org.apache.struts2.sitemesh; -import com.opensymphony.sitemesh.webapp.SiteMeshWebAppContext; -import com.opensymphony.sitemesh.webapp.SiteMeshFilter; -import com.opensymphony.sitemesh.DecoratorSelector; -import com.opensymphony.module.sitemesh.Factory; import com.opensymphony.module.sitemesh.Config; +import com.opensymphony.module.sitemesh.Factory; +import com.opensymphony.sitemesh.DecoratorSelector; +import com.opensymphony.sitemesh.webapp.SiteMeshFilter; +import com.opensymphony.sitemesh.webapp.SiteMeshWebAppContext; import com.opensymphony.xwork2.inject.Inject; - -import javax.servlet.*; - import org.apache.struts2.views.velocity.VelocityManager; +import org.apache.struts2.views.velocity.VelocityManagerInterface; + +import javax.servlet.FilterConfig; /** * Core Filter for integrating SiteMesh into a Java web application. @@ -35,10 +35,18 @@ import org.apache.struts2.views.velocity.VelocityManager; public class VelocityPageFilter extends SiteMeshFilter { @Inject(required=false) - public static void setVelocityManager(VelocityManager mgr) { + public static void setVelocityManager(VelocityManagerInterface mgr) { OldDecorator2NewStrutsVelocityDecorator.setVelocityManager(mgr); } + /** + * @deprecated since 6.4.0 + */ + @Deprecated + public static void setVelocityManager(VelocityManager mgr) { + setVelocityManager((VelocityManagerInterface) mgr); + } + private FilterConfig filterConfig; public void init(FilterConfig filterConfig) {