From 1e4427159425905deff210548779a99a16f68e97 Mon Sep 17 00:00:00 2001 From: markt Date: Sat, 13 Feb 2010 20:12:11 +0000 Subject: [PATCH] Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=48384 Add a per context xslt option for directory listings Make the fallback options work as described in the docs git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@909887 13f79535-47bb-0310-9956-ffa450edef68 --- conf/web.xml | 7 +++++- .../apache/catalina/servlets/DefaultServlet.java | 26 ++++++++++++++++++---- webapps/docs/default-servlet.xml | 24 +++++++++++++++----- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/conf/web.xml b/conf/web.xml index 3d271c47a..3db15fd40 100644 --- a/conf/web.xml +++ b/conf/web.xml @@ -80,7 +80,12 @@ - + + + + + + diff --git a/java/org/apache/catalina/servlets/DefaultServlet.java b/java/org/apache/catalina/servlets/DefaultServlet.java index 9ad9552cd..59ecc4970 100644 --- a/java/org/apache/catalina/servlets/DefaultServlet.java +++ b/java/org/apache/catalina/servlets/DefaultServlet.java @@ -124,13 +124,19 @@ public class DefaultServlet /** * Allow customized directory listing per directory. */ - protected String localXsltFile = null; + protected String localXsltFile = null; /** + * Allow customized directory listing per context. + */ + protected String contextXsltFile = null; + + + /** * Allow customized directory listing per instance. */ - protected String globalXsltFile = null; + protected String globalXsltFile = null; /** @@ -248,6 +254,7 @@ public class DefaultServlet fileEncoding = getServletConfig().getInitParameter("fileEncoding"); globalXsltFile = getServletConfig().getInitParameter("globalXsltFile"); + contextXsltFile = getServletConfig().getInitParameter("contextXsltFile"); localXsltFile = getServletConfig().getInitParameter("localXsltFile"); readmeFile = getServletConfig().getInitParameter("readmeFile"); @@ -1195,6 +1202,9 @@ public class DefaultServlet trimmed.equalsIgnoreCase(localXsltFile)) continue; + if ((cacheEntry.name + trimmed).equals(contextXsltFile)) + continue; + CacheEntry childCacheEntry = resources.lookupCache(cacheEntry.name + resourceName); if (!childCacheEntry.exists) { @@ -1492,11 +1502,19 @@ public class DefaultServlet } catch (NamingException e) { if (debug > 10) log("localXsltFile '" + localXsltFile + "' not found", e); - - return null; } } + if (contextXsltFile != null) { + InputStream is = + getServletContext().getResourceAsStream(contextXsltFile); + if (is != null) + return is; + + if (debug > 10) + log("contextXsltFile '" + contextXsltFile + "' not found"); + } + /* Open and read in file in one fell swoop to reduce chance * chance of leaving handle open. */ diff --git a/webapps/docs/default-servlet.xml b/webapps/docs/default-servlet.xml index 063a3ab40..6ab6ff961 100644 --- a/webapps/docs/default-servlet.xml +++ b/webapps/docs/default-servlet.xml @@ -125,9 +125,21 @@ The DefaultServlet allows the following initParamters: If you wish to customize your directory listing, you can use an XSL transformation. This value is an absolute file name which be used for all directory listings. - This can be disabled by per webapp by also declaring the - default servlet in your local webapp's web.xml. The format - of the xml is shown below. + This can be overridden per context and/or per directory. See + contextXsltFile and localXsltFile + below. The format of the xml is shown below. + + + + contextXsltFile + + You may also customize your directory listing by context by + configuring contextXsltFile. This should be a context + relative path (e.g.: /path/to/context.xslt). This + overrides globalXsltFile. If this value is present but a + file does not exist, then globalXsltFile will be used. If + globalXsltFile does not exist, then the default + directory listing will be shown. @@ -136,8 +148,10 @@ The DefaultServlet allows the following initParamters: You may also customize your directory listing by directory by configuring localXsltFile. This should be a relative file name in the directory where the listing will take place. - This overrides globalXsltFile. If this value - is present but a file does not exist, then + This overrides globalXsltFile and + contextXsltFile. If this value is present but a file + does not exist, then contextXsltFile will be used. If + contextXsltFile does not exist, then globalXsltFile will be used. If globalXsltFile does not exist, then the default directory listing will be shown. -- 2.11.0