diff --git a/sitemesh/src/main/java/org/sitemesh/config/ConfigurableSiteMeshFilter.java b/sitemesh/src/main/java/org/sitemesh/config/ConfigurableSiteMeshFilter.java index f29dad0..ab90051 100644 --- a/sitemesh/src/main/java/org/sitemesh/config/ConfigurableSiteMeshFilter.java +++ b/sitemesh/src/main/java/org/sitemesh/config/ConfigurableSiteMeshFilter.java @@ -210,11 +210,10 @@ public void destroy() { * To read from another place, override this.
*/ protected Map@@ -292,12 +315,10 @@ protected Element loadConfigXml(FilterConfig filterConfig, String configFilePath try { DocumentBuilder documentBuilder = Xml.getSecureDocumentBuilder(); - xmlConfigFile = new File(configFilePath); - ServletContext servletContext = filterConfig.getServletContext(); - - if (servletContext.getRealPath(configFilePath) != null) { - xmlConfigFile = new File(servletContext.getRealPath(configFilePath)); + xmlConfigFile = loadFile(servletContext, configFilePath); + if (xmlConfigFile == null) { + xmlConfigFile = new File(configFilePath); } if (xmlConfigFile.canRead()) { @@ -310,7 +331,7 @@ protected Element loadConfigXml(FilterConfig filterConfig, String configFilePath throw new ServletException("Could not parse " + xmlConfigFile.getAbsolutePath(), e); } } else { - InputStream stream = servletContext.getResourceAsStream(configFilePath); + InputStream stream = loadStream(servletContext, configFilePath); if (stream == null) { logger.config("No config file present - using defaults and init-params. Tried: " + xmlConfigFile.getAbsolutePath() + " and ServletContext:" + configFilePath); @@ -368,5 +389,18 @@ public DecoratorSelectorgetDecoratorSelector() { return ((SiteMeshFilter) filter).getDecoratorSelector(); } + public interface CustomConfiguration { + void applyCustomConfiguration(SiteMeshFilterBuilder builder); + } + + public static ConfigurableSiteMeshFilter create(CustomConfiguration config) { + return new ConfigurableSiteMeshFilter() { + @Override + protected void applyCustomConfiguration(SiteMeshFilterBuilder builder) { + config.applyCustomConfiguration(builder); + } + }; + } + } \ No newline at end of file