Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions oai-pmh_data_provider/data_provider_web/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,12 @@
<artifactId>velocity-tools-view</artifactId>
<version>1.1</version>
</dependency>
<!-- Apache Velocity Engine for Spring 5.x compatibility -->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity-engine-core</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.cipres.treebase</groupId>
<artifactId>treebase-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.springframework.web.servlet.view.velocity;

import java.io.IOException;
import java.util.Properties;

import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.exception.VelocityException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ResourceLoaderAware;
import org.springframework.core.io.ResourceLoader;
import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;

/**
* Custom VelocityConfigurer for Spring 5.x compatibility.
* This class provides Velocity template engine configuration that was removed from Spring 5.x.
*/
public class VelocityConfigurer implements InitializingBean, ResourceLoaderAware, ServletContextAware {

private VelocityEngine velocityEngine;
private String resourceLoaderPath;
private Properties velocityProperties;
private ResourceLoader resourceLoader;
private ServletContext servletContext;

public void setResourceLoaderPath(String resourceLoaderPath) {
this.resourceLoaderPath = resourceLoaderPath;
}

public void setVelocityProperties(Properties velocityProperties) {
this.velocityProperties = velocityProperties;
}

@Override
public void setResourceLoader(ResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}

@Override
public void setServletContext(ServletContext servletContext) {
this.servletContext = servletContext;
}

public VelocityEngine getVelocityEngine() {
return this.velocityEngine;
}

@Override
public void afterPropertiesSet() throws Exception {
this.velocityEngine = createVelocityEngine();
}

protected VelocityEngine createVelocityEngine() throws Exception {
VelocityEngine velocityEngine = new VelocityEngine();

Properties props = new Properties();

// Determine loader type and path
String loaderType = "classpath";
String loaderClass = "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader";
String loaderPath = null;

if (resourceLoaderPath != null) {
String path = resourceLoaderPath;
if (servletContext != null) {
if (!path.startsWith("/")) {
path = "/" + path;
}
String realPath = servletContext.getRealPath(path);
// Use file loader if real path is available
if (realPath != null) {
loaderType = "file";
loaderClass = "org.apache.velocity.runtime.resource.loader.FileResourceLoader";
loaderPath = realPath;
}
}
}

// Set loader configuration
props.setProperty("resource.loaders", loaderType);
props.setProperty("resource.loader." + loaderType + ".class", loaderClass);
if (loaderPath != null) {
props.setProperty("resource.loader." + loaderType + ".path", loaderPath);
}

// Add any custom properties
if (velocityProperties != null) {
props.putAll(velocityProperties);
}

velocityEngine.init(props);
return velocityEngine;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package org.springframework.web.servlet.view.velocity;

import java.io.StringWriter;
import java.util.Locale;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.context.Context;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.view.AbstractUrlBasedView;

/**
* Custom VelocityViewResolver for Spring 5.x compatibility.
* This class provides Velocity view resolution that was removed from Spring 5.x.
*/
public class VelocityViewResolver implements ViewResolver, InitializingBean, ApplicationContextAware {

private VelocityEngine velocityEngine;
private String prefix = "";
private String suffix = ".vm";
private String contentType = "text/html;charset=UTF-8";
private String encoding = "UTF-8";
private boolean exposeRequestAttributes = false;
private boolean exposeSessionAttributes = false;
private ApplicationContext applicationContext;

public void setVelocityEngine(VelocityEngine velocityEngine) {
this.velocityEngine = velocityEngine;
}

public void setPrefix(String prefix) {
this.prefix = (prefix != null ? prefix : "");
}

public void setSuffix(String suffix) {
this.suffix = (suffix != null ? suffix : "");
}

public void setContentType(String contentType) {
this.contentType = contentType;
}

public void setEncoding(String encoding) {
this.encoding = encoding;
}

public void setExposeRequestAttributes(boolean exposeRequestAttributes) {
this.exposeRequestAttributes = exposeRequestAttributes;
}

public void setExposeSessionAttributes(boolean exposeSessionAttributes) {
this.exposeSessionAttributes = exposeSessionAttributes;
}

@Override
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}

@Override
public void afterPropertiesSet() throws Exception {
// If velocityEngine is not set, try to get it from VelocityConfigurer
if (this.velocityEngine == null && this.applicationContext != null) {
try {
VelocityConfigurer configurer = this.applicationContext.getBean(VelocityConfigurer.class);
this.velocityEngine = configurer.getVelocityEngine();
} catch (Exception e) {
// VelocityConfigurer bean not found or error getting engine
}
}

if (this.velocityEngine == null) {
throw new IllegalArgumentException("Property 'velocityEngine' is required");
}
}

@Override
public View resolveViewName(String viewName, Locale locale) throws Exception {
return new VelocityView(prefix + viewName + suffix);
}

private class VelocityView implements View {
private final String templatePath;

public VelocityView(String templatePath) {
this.templatePath = templatePath;
}

@Override
public String getContentType() {
return contentType;
}

@Override
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
throws Exception {

response.setContentType(getContentType());

Context velocityContext = new VelocityContext();

// Add model attributes to Velocity context
if (model != null) {
for (Map.Entry<String, ?> entry : model.entrySet()) {
velocityContext.put(entry.getKey(), entry.getValue());
}
}

// Add request attributes if configured
if (exposeRequestAttributes && request != null) {
java.util.Enumeration<String> attrNames = request.getAttributeNames();
while (attrNames.hasMoreElements()) {
String attrName = attrNames.nextElement();
velocityContext.put(attrName, request.getAttribute(attrName));
}
}

// Add session attributes if configured
if (exposeSessionAttributes && request != null && request.getSession(false) != null) {
java.util.Enumeration<String> attrNames = request.getSession().getAttributeNames();
while (attrNames.hasMoreElements()) {
String attrName = attrNames.nextElement();
velocityContext.put(attrName, request.getSession().getAttribute(attrName));
}
}

// Add request, response, and session to context for compatibility
velocityContext.put("request", request);
velocityContext.put("response", response);
if (request.getSession(false) != null) {
velocityContext.put("session", request.getSession());
}

// Merge template
StringWriter writer = new StringWriter();
velocityEngine.mergeTemplate(templatePath, encoding, velocityContext, writer);

response.getWriter().write(writer.toString());
}
}
}
10 changes: 5 additions & 5 deletions oai-pmh_data_provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,31 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.30.RELEASE</version>
<version>5.3.18</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.30.RELEASE</version>
<version>5.3.18</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.30.RELEASE</version>
<version>5.3.18</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.30.RELEASE</version>
<version>5.3.18</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.30.RELEASE</version>
<version>5.3.18</version>
<scope>test</scope>
</dependency>

Expand Down
18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,55 +75,55 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.30.RELEASE</version>
<version>5.3.18</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.3.30.RELEASE</version>
<version>5.3.18</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.30.RELEASE</version>
<version>5.3.18</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>4.3.30.RELEASE</version>
<version>5.3.18</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.3.30.RELEASE</version>
<version>5.3.18</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.3.30.RELEASE</version>
<version>5.3.18</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.30.RELEASE</version>
<version>5.3.18</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.30.RELEASE</version>
<version>5.3.18</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.30.RELEASE</version>
<version>5.3.18</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
Expand All @@ -39,7 +38,6 @@
"classpath:applicationContext-dao.xml",
"classpath:applicationContext-service.xml"
})
@TransactionConfiguration(defaultRollback = true)
@Transactional
public abstract class AbstractDAOTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;

/**
Expand All @@ -23,7 +22,6 @@
"classpath:applicationContext-dao.xml",
"classpath:applicationContext-service.xml"
})
@TransactionConfiguration(defaultRollback = true)
@Transactional
public abstract class AbstractServiceTest {

Expand Down
Loading
Loading