Author: cbrisson Date: Thu Jun 28 12:14:41 2018 New Revision: 1834601 URL: http://svn.apache.org/viewvc?rev=1834601&view=rev Log: [tools/view] Config code simplification: relies on servlet context for WEB-INF/*, on class loader for everything else
Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ServletUtils.java velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityView.java Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ServletUtils.java URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ServletUtils.java?rev=1834601&r1=1834600&r2=1834601&view=diff ============================================================================== --- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ServletUtils.java (original) +++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/ServletUtils.java Thu Jun 28 12:14:41 2018 @@ -297,22 +297,18 @@ public class ServletUtils return null; } - public static InputStream getInputStream(final String path, ServletContext application) - { - return getInputStream(path, application, true, true); - } - - public static InputStream getInputStream(final String path, final ServletContext application, boolean searchClasspath, boolean searchWebapp) + public static InputStream getInputStream(final String path, final ServletContext application) { InputStream inputStream = null; - // first search classpath if asked so - if (searchClasspath) + boolean webappResource = path != null && (path.startsWith("WEB-INF") || path.startsWith("/WEB-INF")); + if (!webappResource) { + // search classpath except for WEB-INF/* inputStream = ClassUtils.getResourceAsStream(path, ServletUtils.class); } - if (inputStream == null && searchWebapp) + else { - // then webapp + // then webapp only for WEB-INF/* if (System.getSecurityManager() != null) { inputStream = AccessController.doPrivileged( Modified: velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityView.java URL: http://svn.apache.org/viewvc/velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityView.java?rev=1834601&r1=1834600&r2=1834601&view=diff ============================================================================== --- velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityView.java (original) +++ velocity/tools/trunk/velocity-tools-view/src/main/java/org/apache/velocity/tools/view/VelocityView.java Thu Jun 28 12:14:41 2018 @@ -337,15 +337,14 @@ public class VelocityView extends ViewTo protected void configure(final JeeConfig config, final VelocityEngine velocity) { // first get the default properties from the classpath, and bail if we don't find them - Properties defaultProperties = getProperties(DEFAULT_PROPERTIES_PATH, true, true, false); + Properties defaultProperties = getProperties(DEFAULT_PROPERTIES_PATH, true); velocity.setProperties(defaultProperties); // check for application-wide user props in the context init params String appPropsPath = servletContext.getInitParameter(PROPERTIES_KEY); if (appPropsPath != null) { - boolean isInWebInf = appPropsPath.startsWith("/WEB-INF") || appPropsPath.startsWith("WEB-INF"); - Properties appProperties = getProperties(appPropsPath, true, !isInWebInf, isInWebInf); + Properties appProperties = getProperties(appPropsPath, true); getLog().debug("Configuring Velocity with properties at: {}", appPropsPath); velocity.setProperties(appProperties); } @@ -355,7 +354,7 @@ public class VelocityView extends ViewTo if (servletPropsPath != null && (appPropsPath == null || !appPropsPath.equals(servletPropsPath))) { boolean isInWebInf = servletPropsPath.startsWith("/WEB-INF") || servletPropsPath.startsWith("WEB-INF"); - Properties servletProperties = getProperties(servletPropsPath, true, !isInWebInf, isInWebInf); + Properties servletProperties = getProperties(servletPropsPath, true); getLog().debug("Configuring Velocity with properties at: {}", servletPropsPath); velocity.setProperties(servletProperties); } @@ -364,7 +363,7 @@ public class VelocityView extends ViewTo // conventional location, and be silent if they're missing if (appPropsPath == null && servletPropsPath == null) { - Properties appProperties = getProperties(USER_PROPERTIES_PATH, false, false, true); + Properties appProperties = getProperties(USER_PROPERTIES_PATH, false); if (appProperties != null) { getLog().debug("Configuring Velocity with properties at: {}", appPropsPath); @@ -514,21 +513,16 @@ public class VelocityView extends ViewTo protected Properties getProperties(String path) { - return getProperties(path, false, true, true); + return getProperties(path, false); } protected Properties getProperties(String path, boolean required) { - return getProperties(path, required, true, true); - } - - protected Properties getProperties(String path, boolean required, boolean searchClasspath, boolean searchWebapp) - { if (getLog().isTraceEnabled()) { getLog().trace("Searching for properties at {} ", path); } - InputStream inputStream = ServletUtils.getInputStream(path, this.servletContext, searchClasspath, searchWebapp); + InputStream inputStream = ServletUtils.getInputStream(path, this.servletContext); if (inputStream == null) { String msg = "Did not find resource at: "+path;