mirror of
https://github.com/apache/struts.git
synced 2026-08-11 09:36:57 +00:00
WW-3940 Upgrades Velocity tools
This commit is contained in:
@@ -155,7 +155,7 @@
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.jwebunit</groupId>
|
||||
<artifactId>jwebunit-htmlunit-plugin</artifactId>
|
||||
<version>1.4.1</version>
|
||||
<version>3.3</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package org.apache.struts2.portlet.test;
|
||||
|
||||
import net.sourceforge.jwebunit.junit.WebTestCase;
|
||||
import static net.sourceforge.jwebunit.junit.JWebUnit.*;
|
||||
import org.apache.pluto.core.PortletServlet;
|
||||
import org.mortbay.jetty.Server;
|
||||
import org.mortbay.jetty.servlet.ServletHolder;
|
||||
import org.mortbay.jetty.webapp.WebAppContext;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public abstract class BasePortletTest extends WebTestCase {
|
||||
public abstract class BasePortletTest extends TestCase {
|
||||
|
||||
protected Server server;
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package org.apache.struts2.portlet.test;
|
||||
|
||||
import static net.sourceforge.jwebunit.junit.JWebUnit.*;
|
||||
|
||||
public class Struts2PortletTest extends BasePortletTest {
|
||||
|
||||
private final static String PORTLET_NAME = "StrutsPortlet";
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ public class VelocityTemplateEngine extends BaseTemplateEngine {
|
||||
// try to load, and if it works, stop at the first one
|
||||
template = velocityEngine.getTemplate(templateName);
|
||||
break;
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
if (exception == null) {
|
||||
exception = e;
|
||||
}
|
||||
|
||||
@@ -134,13 +134,13 @@ public class VelocityResultTest extends StrutsInternalTestCase {
|
||||
class TestVelocityEngine extends VelocityEngine {
|
||||
public String templateName;
|
||||
|
||||
public Template getTemplate(String templateName) throws ResourceNotFoundException, ParseErrorException, Exception {
|
||||
public Template getTemplate(String templateName) throws ResourceNotFoundException, ParseErrorException {
|
||||
this.templateName = templateName;
|
||||
|
||||
return new Template();
|
||||
}
|
||||
|
||||
public Template getTemplate(String templateName, String charSet) throws ResourceNotFoundException, ParseErrorException, Exception {
|
||||
public Template getTemplate(String templateName, String charSet) throws ResourceNotFoundException, ParseErrorException {
|
||||
this.templateName = templateName;
|
||||
|
||||
return new Template();
|
||||
|
||||
+34
-19
@@ -28,6 +28,9 @@ package org.apache.struts2.sitemesh;
|
||||
import com.opensymphony.module.sitemesh.*;
|
||||
import com.opensymphony.module.sitemesh.util.OutputConverter;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.dispatcher.Dispatcher;
|
||||
@@ -36,12 +39,15 @@ import org.apache.struts2.views.velocity.VelocityManager;
|
||||
import org.apache.velocity.Template;
|
||||
import org.apache.velocity.context.Context;
|
||||
import org.apache.velocity.runtime.RuntimeConstants;
|
||||
import org.apache.velocity.tools.view.servlet.VelocityViewServlet;
|
||||
import org.apache.velocity.tools.view.VelocityView;
|
||||
import org.apache.velocity.tools.view.VelocityViewServlet;
|
||||
|
||||
import javax.servlet.ServletConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
/**
|
||||
@@ -53,6 +59,10 @@ import java.io.StringWriter;
|
||||
*/
|
||||
public class VelocityDecoratorServlet extends VelocityViewServlet {
|
||||
|
||||
private static final Logger LOG = LogManager.getLogger(VelocityDecoratorServlet.class);
|
||||
|
||||
private static final long serialVersionUID = -6731485159371716918L;
|
||||
|
||||
protected VelocityManager velocityManager;
|
||||
protected String defaultContentType;
|
||||
|
||||
@@ -78,17 +88,18 @@ public class VelocityDecoratorServlet extends VelocityViewServlet {
|
||||
velocityManager.init(config.getServletContext());
|
||||
|
||||
// do whatever we have to do to init Velocity
|
||||
setVelocityEngine(velocityManager.getVelocityEngine());
|
||||
toolboxManager = velocityManager.getToolboxManager();
|
||||
getVelocityView().setVelocityEngine(velocityManager.getVelocityEngine());
|
||||
// toolboxManager = velocityManager.getToolboxManager();
|
||||
|
||||
|
||||
// we can get these now that velocity is initialized
|
||||
defaultContentType = getVelocityProperty(CONTENT_TYPE, DEFAULT_CONTENT_TYPE);
|
||||
defaultContentType = getVelocityProperty(VelocityView.CONTENT_TYPE_KEY, VelocityView.DEFAULT_CONTENT_TYPE);
|
||||
|
||||
String encoding = getVelocityProperty(RuntimeConstants.OUTPUT_ENCODING, DEFAULT_OUTPUT_ENCODING);
|
||||
String encoding = getVelocityProperty(RuntimeConstants.OUTPUT_ENCODING, VelocityView.DEFAULT_OUTPUT_ENCODING);
|
||||
|
||||
// For non Latin-1 encodings, ensure that the charset is
|
||||
// included in the Content-Type header.
|
||||
if (!DEFAULT_OUTPUT_ENCODING.equalsIgnoreCase(encoding)) {
|
||||
if (!VelocityView.DEFAULT_OUTPUT_ENCODING.equalsIgnoreCase(encoding)) {
|
||||
int index = defaultContentType.lastIndexOf("charset");
|
||||
if (index < 0) {
|
||||
// the charset specifier is not yet present in header.
|
||||
@@ -96,14 +107,14 @@ public class VelocityDecoratorServlet extends VelocityViewServlet {
|
||||
defaultContentType += "; charset=" + encoding;
|
||||
} else {
|
||||
// The user may have configuration issues.
|
||||
getVelocityEngine().warn("VelocityViewServlet: Charset was already " + "specified in the Content-Type property. " + "Output encoding property will be ignored.");
|
||||
getVelocityView().getVelocityEngine().getLog().warn("VelocityViewServlet: Charset was already " + "specified in the Content-Type property. " + "Output encoding property will be ignored.");
|
||||
}
|
||||
}
|
||||
|
||||
getVelocityEngine().info("VelocityViewServlet: Default content-type is: " + defaultContentType);
|
||||
getVelocityView().getVelocityEngine().getLog().info("VelocityViewServlet: Default content-type is: " + defaultContentType);
|
||||
}
|
||||
|
||||
public Template handleRequest(HttpServletRequest request, HttpServletResponse response, Context context) throws Exception {
|
||||
public Template handleRequest(HttpServletRequest request, HttpServletResponse response, Context context) {
|
||||
HTMLPage htmlPage = (HTMLPage) request.getAttribute(RequestConstants.PAGE);
|
||||
String template;
|
||||
|
||||
@@ -119,16 +130,20 @@ public class VelocityDecoratorServlet extends VelocityViewServlet {
|
||||
context.put("head", "<!-- head -->");
|
||||
template = request.getServletPath();
|
||||
} else {
|
||||
context.put("title", OutputConverter.convert(htmlPage.getTitle()));
|
||||
{
|
||||
StringWriter buffer = new StringWriter();
|
||||
htmlPage.writeBody(OutputConverter.getWriter(buffer));
|
||||
context.put("body", buffer.toString());
|
||||
}
|
||||
{
|
||||
StringWriter buffer = new StringWriter();
|
||||
htmlPage.writeHead(OutputConverter.getWriter(buffer));
|
||||
context.put("head", buffer.toString());
|
||||
try {
|
||||
context.put("title", OutputConverter.convert(htmlPage.getTitle()));
|
||||
{
|
||||
StringWriter buffer = new StringWriter();
|
||||
htmlPage.writeBody(OutputConverter.getWriter(buffer));
|
||||
context.put("body", buffer.toString());
|
||||
}
|
||||
{
|
||||
StringWriter buffer = new StringWriter();
|
||||
htmlPage.writeHead(OutputConverter.getWriter(buffer));
|
||||
context.put("head", buffer.toString());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOG.error("IOException handle request template", e);
|
||||
}
|
||||
context.put("page", htmlPage);
|
||||
DecoratorMapper decoratorMapper = getDecoratorMapper();
|
||||
|
||||
@@ -513,14 +513,14 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity</artifactId>
|
||||
<version>1.6.4</version>
|
||||
<version>1.7</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-tools</artifactId>
|
||||
<version>1.3</version>
|
||||
<version>2.0</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>javax.servlet</groupId>
|
||||
|
||||
Reference in New Issue
Block a user