diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java index b25f8beef10..dc0c88457f4 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java @@ -2295,9 +2295,15 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server. @Override public JspConfigDescriptor getJspConfigDescriptor() { + LOG.warn(__unimplmented); return null; } + public void setJspConfigDescriptor(JspConfigDescriptor d) + { + + } + @Override public void declareRoles(String... roleNames) { diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java index e07f805a07c..cc5fd070c21 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletContextHandler.java @@ -15,6 +15,7 @@ package org.eclipse.jetty.servlet; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.EnumSet; import java.util.EventListener; @@ -38,6 +39,8 @@ import javax.servlet.ServletSecurityElement; import javax.servlet.SessionCookieConfig; import javax.servlet.SessionTrackingMode; import javax.servlet.descriptor.JspConfigDescriptor; +import javax.servlet.descriptor.JspPropertyGroupDescriptor; +import javax.servlet.descriptor.TaglibDescriptor; import org.eclipse.jetty.security.ConstraintAware; import org.eclipse.jetty.security.ConstraintSecurityHandler; @@ -495,6 +498,290 @@ public class ServletContextHandler extends ContextHandler decorator.destroyFilterInstance(filter); } + /* ------------------------------------------------------------ */ + public static class JspPropertyGroup implements JspPropertyGroupDescriptor + { + private List _urlPatterns = new ArrayList(); + private String _elIgnored; + private String _pageEncoding; + private String _scriptingInvalid; + private String _isXml; + private List _includePreludes = new ArrayList(); + private List _includeCodas = new ArrayList(); + private String _deferredSyntaxAllowedAsLiteral; + private String _trimDirectiveWhitespaces; + private String _defaultContentType; + private String _buffer; + private String _errorOnUndeclaredNamespace; + + + + /** + * @see javax.servlet.descriptor.JspPropertyGroupDescriptor#getUrlPatterns() + */ + public Collection getUrlPatterns() + { + return new ArrayList(_urlPatterns); // spec says must be a copy + } + + public void addUrlPattern (String s) + { + if (!_urlPatterns.contains(s)) + _urlPatterns.add(s); + } + + /** + * @see javax.servlet.descriptor.JspPropertyGroupDescriptor#getElIgnored() + */ + public String getElIgnored() + { + return _elIgnored; + } + + public void setElIgnored (String s) + { + _elIgnored = s; + } + + /** + * @see javax.servlet.descriptor.JspPropertyGroupDescriptor#getPageEncoding() + */ + public String getPageEncoding() + { + return _pageEncoding; + } + + public void setPageEncoding(String pageEncoding) + { + _pageEncoding = pageEncoding; + } + + public void setScriptingInvalid(String scriptingInvalid) + { + _scriptingInvalid = scriptingInvalid; + } + + public void setIsXml(String isXml) + { + _isXml = isXml; + } + + public void setDeferredSyntaxAllowedAsLiteral(String deferredSyntaxAllowedAsLiteral) + { + _deferredSyntaxAllowedAsLiteral = deferredSyntaxAllowedAsLiteral; + } + + public void setTrimDirectiveWhitespaces(String trimDirectiveWhitespaces) + { + _trimDirectiveWhitespaces = trimDirectiveWhitespaces; + } + + public void setDefaultContentType(String defaultContentType) + { + _defaultContentType = defaultContentType; + } + + public void setBuffer(String buffer) + { + _buffer = buffer; + } + + public void setErrorOnUndeclaredNamespace(String errorOnUndeclaredNamespace) + { + _errorOnUndeclaredNamespace = errorOnUndeclaredNamespace; + } + + /** + * @see javax.servlet.descriptor.JspPropertyGroupDescriptor#getScriptingInvalid() + */ + public String getScriptingInvalid() + { + return _scriptingInvalid; + } + + /** + * @see javax.servlet.descriptor.JspPropertyGroupDescriptor#getIsXml() + */ + public String getIsXml() + { + return _isXml; + } + + /** + * @see javax.servlet.descriptor.JspPropertyGroupDescriptor#getIncludePreludes() + */ + public Collection getIncludePreludes() + { + return new ArrayList(_includePreludes); //must be a copy + } + + public void addIncludePrelude(String prelude) + { + if (!_includePreludes.contains(prelude)) + _includePreludes.add(prelude); + } + + /** + * @see javax.servlet.descriptor.JspPropertyGroupDescriptor#getIncludeCodas() + */ + public Collection getIncludeCodas() + { + return new ArrayList(_includeCodas); //must be a copy + } + + public void addIncludeCoda (String coda) + { + if (!_includeCodas.contains(coda)) + _includeCodas.add(coda); + } + + /** + * @see javax.servlet.descriptor.JspPropertyGroupDescriptor#getDeferredSyntaxAllowedAsLiteral() + */ + public String getDeferredSyntaxAllowedAsLiteral() + { + return _deferredSyntaxAllowedAsLiteral; + } + + /** + * @see javax.servlet.descriptor.JspPropertyGroupDescriptor#getTrimDirectiveWhitespaces() + */ + public String getTrimDirectiveWhitespaces() + { + return _trimDirectiveWhitespaces; + } + + /** + * @see javax.servlet.descriptor.JspPropertyGroupDescriptor#getDefaultContentType() + */ + public String getDefaultContentType() + { + return _defaultContentType; + } + + /** + * @see javax.servlet.descriptor.JspPropertyGroupDescriptor#getBuffer() + */ + public String getBuffer() + { + return _buffer; + } + + /** + * @see javax.servlet.descriptor.JspPropertyGroupDescriptor#getErrorOnUndeclaredNamespace() + */ + public String getErrorOnUndeclaredNamespace() + { + return _errorOnUndeclaredNamespace; + } + + public String toString () + { + StringBuffer sb = new StringBuffer(); + sb.append("JspPropertyGroupDescriptor:"); + sb.append(" el-ignored="+_elIgnored); + sb.append(" is-xml="+_isXml); + sb.append(" page-encoding="+_pageEncoding); + sb.append(" scripting-invalid="+_scriptingInvalid); + sb.append(" deferred-syntax-allowed-as-literal="+_deferredSyntaxAllowedAsLiteral); + sb.append(" trim-directive-whitespaces"+_trimDirectiveWhitespaces); + sb.append(" default-content-type="+_defaultContentType); + sb.append(" buffer="+_buffer); + sb.append(" error-on-undeclared-namespace="+_errorOnUndeclaredNamespace); + for (String prelude:_includePreludes) + sb.append(" include-prelude="+prelude); + for (String coda:_includeCodas) + sb.append(" include-coda="+coda); + return sb.toString(); + } + } + + /* ------------------------------------------------------------ */ + public static class TagLib implements TaglibDescriptor + { + private String _uri; + private String _location; + + /** + * @see javax.servlet.descriptor.TaglibDescriptor#getTaglibURI() + */ + public String getTaglibURI() + { + return _uri; + } + + public void setTaglibURI(String uri) + { + _uri = uri; + } + + /** + * @see javax.servlet.descriptor.TaglibDescriptor#getTaglibLocation() + */ + public String getTaglibLocation() + { + return _location; + } + + public void setTaglibLocation(String location) + { + _location = location; + } + + public String toString() + { + return ("TagLibDescriptor: taglib-uri="+_uri+" location="+_location); + } + } + + + /* ------------------------------------------------------------ */ + public static class JspConfig implements JspConfigDescriptor + { + private List _taglibs = new ArrayList(); + private List _jspPropertyGroups = new ArrayList(); + + public JspConfig() {} + + /** + * @see javax.servlet.descriptor.JspConfigDescriptor#getTaglibs() + */ + public Collection getTaglibs() + { + return new ArrayList(_taglibs); + } + + public void addTaglibDescriptor (TaglibDescriptor d) + { + _taglibs.add(d); + } + + /** + * @see javax.servlet.descriptor.JspConfigDescriptor#getJspPropertyGroups() + */ + public Collection getJspPropertyGroups() + { + return new ArrayList(_jspPropertyGroups); + } + + public void addJspPropertyGroup(JspPropertyGroupDescriptor g) + { + _jspPropertyGroups.add(g); + } + + public String toString() + { + StringBuffer sb = new StringBuffer(); + sb.append("JspConfigDescriptor: \n"); + for (TaglibDescriptor taglib:_taglibs) + sb.append(taglib+"\n"); + for (JspPropertyGroupDescriptor jpg:_jspPropertyGroups) + sb.append(jpg+"\n"); + return sb.toString(); + } + } + + /* ------------------------------------------------------------ */ public class Context extends ContextHandler.Context { @@ -863,6 +1150,13 @@ public class ServletContextHandler extends ContextHandler return _jspConfig; } + @Override + public void setJspConfigDescriptor(JspConfigDescriptor d) + { + _jspConfig = d; + } + + @Override public void declareRoles(String... roleNames) { diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/StandardDescriptorProcessor.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/StandardDescriptorProcessor.java index 745137cfb43..16e9eb91af8 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/StandardDescriptorProcessor.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/StandardDescriptorProcessor.java @@ -18,6 +18,7 @@ import java.io.IOException; import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; +import java.util.Collection; import java.util.EnumSet; import java.util.EventListener; import java.util.HashSet; @@ -31,6 +32,9 @@ import javax.servlet.MultipartConfigElement; import javax.servlet.ServletException; import javax.servlet.ServletRegistration; import javax.servlet.SessionTrackingMode; +import javax.servlet.descriptor.JspConfigDescriptor; +import javax.servlet.descriptor.JspPropertyGroupDescriptor; +import javax.servlet.descriptor.TaglibDescriptor; import org.eclipse.jetty.security.ConstraintAware; import org.eclipse.jetty.security.ConstraintMapping; @@ -40,6 +44,9 @@ import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.FilterMapping; import org.eclipse.jetty.servlet.Holder; import org.eclipse.jetty.servlet.ServletContextHandler; +import org.eclipse.jetty.servlet.ServletContextHandler.JspConfig; +import org.eclipse.jetty.servlet.ServletContextHandler.JspPropertyGroup; +import org.eclipse.jetty.servlet.ServletContextHandler.TagLib; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletMapping; import org.eclipse.jetty.util.LazyList; @@ -1246,6 +1253,18 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor String location = node.getString("taglib-location", false, true); context.setResourceAlias(uri, location); + + JspConfig config = (JspConfig)context.getServletHandler().getServletContext().getJspConfigDescriptor(); + if (config == null) + { + config = new JspConfig(); + context.getServletContext().setJspConfigDescriptor(config); + } + + TagLib tl = new TagLib(); + tl.setTaglibLocation(location); + tl.setTaglibURI(uri); + config.addTaglibDescriptor(tl); } /** @@ -1254,7 +1273,16 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor * @param node */ protected void visitJspConfig(WebAppContext context, Descriptor descriptor, XmlParser.Node node) - { + { + //Additive across web.xml and web-fragment.xml + JspConfig config = (JspConfig)context.getServletContext().getJspConfigDescriptor(); + if (config == null) + { + config = new JspConfig(); + context.getServletContext().setJspConfigDescriptor(config); + } + + for (int i = 0; i < node.size(); i++) { Object o = node.get(i); @@ -1263,19 +1291,51 @@ public class StandardDescriptorProcessor extends IterativeDescriptorProcessor } // Map URLs from jsp property groups to JSP servlet. - // this is more JSP stupidness creaping into the servlet spec + // this is more JSP stupidness creeping into the servlet spec Iterator iter = node.iterator("jsp-property-group"); List paths = new ArrayList(); while (iter.hasNext()) { + JspPropertyGroup jpg = new JspPropertyGroup(); + config.addJspPropertyGroup(jpg); XmlParser.Node group = iter.next(); + + //url-patterns Iterator iter2 = group.iterator("url-pattern"); while (iter2.hasNext()) { String url = iter2.next().toString(false, true); url = normalizePattern(url); paths.add( url); + jpg.addUrlPattern(url); } + + jpg.setElIgnored(group.getString("el-ignored", false, true)); + jpg.setPageEncoding(group.getString("page-encoding", false, true)); + jpg.setScriptingInvalid(group.getString("scripting-invalid", false, true)); + jpg.setIsXml(group.getString("is-xml", false, true)); + jpg.setDeferredSyntaxAllowedAsLiteral(group.getString("deferred-syntax-allowed-as-literal", false, true)); + jpg.setTrimDirectiveWhitespaces(group.getString("trim-directive-whitespaces", false, true)); + jpg.setDefaultContentType(group.getString("defaultContentType", false, true)); + jpg.setBuffer(group.getString("buffer", false, true)); + jpg.setErrorOnUndeclaredNamespace(group.getString("error-on-undeclared-namespace", false, true)); + + //preludes + Iterator preludes = group.iterator("include-prelude"); + while (preludes.hasNext()) + { + String prelude = preludes.next().toString(false, true); + jpg.addIncludePrelude(prelude); + } + //codas + Iterator codas = group.iterator("include-coda"); + while (codas.hasNext()) + { + String coda = codas.next().toString(false, true); + jpg.addIncludeCoda(coda); + } + + if (LOG.isDebugEnabled()) LOG.debug(config.toString()); } if (paths.size() > 0)