NIHVIVO-3542 BaseTemplateModel doesn't need to hold ServletContext, and the way it's set in a static field is dodgy. Remove it.
This commit is contained in:
parent
490e0a18df
commit
e0594b2681
4 changed files with 6 additions and 15 deletions
|
@ -18,7 +18,6 @@ public class FreemarkerSetup implements ServletContextListener {
|
|||
@Override
|
||||
public void contextInitialized(ServletContextEvent event) {
|
||||
ServletContext sc = event.getServletContext();
|
||||
BaseTemplateModel.setServletContext(sc);
|
||||
FreemarkerComponentGenerator.setServletContext(sc);
|
||||
UrlBuilder.contextPath = sc.getContextPath();
|
||||
|
||||
|
|
|
@ -20,8 +20,6 @@ public abstract class BaseTemplateModel {
|
|||
private static final String URI_CHARACTERS =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&%'()*+,;=";
|
||||
|
||||
protected static ServletContext servletContext;
|
||||
|
||||
// Convenience method so subclasses can call getUrl(path)
|
||||
protected String getUrl(String path) {
|
||||
return UrlBuilder.getUrl(path);
|
||||
|
@ -73,12 +71,4 @@ public abstract class BaseTemplateModel {
|
|||
AntiScript.cleanMapValues(map);
|
||||
}
|
||||
|
||||
protected static ServletContext getServletContext() {
|
||||
return servletContext;
|
||||
}
|
||||
|
||||
public static void setServletContext(ServletContext context) {
|
||||
servletContext = context;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import java.util.Collection;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -37,12 +39,14 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
|
|||
protected final Individual individual;
|
||||
protected final LoginStatusBean loginStatusBean;
|
||||
protected final VitroRequest vreq;
|
||||
private final ServletContext ctx;
|
||||
private final boolean editing;
|
||||
|
||||
protected GroupedPropertyList propertyList;
|
||||
|
||||
public BaseIndividualTemplateModel(Individual individual, VitroRequest vreq) {
|
||||
this.vreq = vreq;
|
||||
this.ctx = vreq.getSession().getServletContext();
|
||||
this.individual = individual;
|
||||
this.loginStatusBean = LoginStatusBean.getBean(vreq);
|
||||
// Needed for getting portal-sensitive urls. Remove if multi-portal support is removed.
|
||||
|
@ -54,7 +58,7 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
|
|||
boolean isVClass = individual.isVClass(vClassUri);
|
||||
// If reasoning is asynchronous (under RDB), this inference may not have been made yet.
|
||||
// Check the superclasses of the individual's vclass.
|
||||
SimpleReasoner simpleReasoner = (SimpleReasoner)getServletContext().getAttribute(SimpleReasoner.class.getName());
|
||||
SimpleReasoner simpleReasoner = (SimpleReasoner) ctx.getAttribute(SimpleReasoner.class.getName());
|
||||
if (!isVClass && simpleReasoner != null && simpleReasoner.isABoxReasoningAsynchronous()) {
|
||||
log.debug("Checking superclasses to see if individual is a " + vClassUri + " because reasoning is asynchronous");
|
||||
List<VClass> directVClasses = individual.getVClasses(true);
|
||||
|
@ -216,7 +220,7 @@ public abstract class BaseIndividualTemplateModel extends BaseTemplateModel {
|
|||
public String selfEditingId() {
|
||||
String id = null;
|
||||
String idMatchingProperty =
|
||||
ConfigurationProperties.getBean(getServletContext()).getProperty("selfEditing.idMatchingProperty");
|
||||
ConfigurationProperties.getBean(ctx).getProperty("selfEditing.idMatchingProperty");
|
||||
if (! StringUtils.isBlank(idMatchingProperty)) {
|
||||
WebappDaoFactory wdf = vreq.getUnfilteredWebappDaoFactory();
|
||||
Collection<DataPropertyStatement> ids =
|
||||
|
|
|
@ -135,8 +135,6 @@ public class ObjectPropertyTemplateModel_PropertyListConfigTest extends
|
|||
|
||||
subject = new IndividualImpl();
|
||||
|
||||
BaseTemplateModel.setServletContext(ctx);
|
||||
|
||||
Configuration fmConfig = new Configuration();
|
||||
vreq.setAttribute("freemarkerConfig", fmConfig);
|
||||
tl = new TemplateLoaderStub();
|
||||
|
|
Loading…
Add table
Reference in a new issue