Search in sources :

Example 1 with JspPropertyGroupDescriptor

use of jakarta.servlet.descriptor.JspPropertyGroupDescriptor in project tomcat by apache.

the class JspConfig method processWebDotXml.

private void processWebDotXml() {
    // Very, very unlikely but just in case...
    if (ctxt.getEffectiveMajorVersion() < 2) {
        defaultIsELIgnored = "true";
        defaultDeferedSyntaxAllowedAsLiteral = "true";
        return;
    }
    if (ctxt.getEffectiveMajorVersion() == 2) {
        if (ctxt.getEffectiveMinorVersion() < 5) {
            defaultDeferedSyntaxAllowedAsLiteral = "true";
        }
        if (ctxt.getEffectiveMinorVersion() < 4) {
            defaultIsELIgnored = "true";
            return;
        }
    }
    JspConfigDescriptor jspConfig = ctxt.getJspConfigDescriptor();
    if (jspConfig == null) {
        return;
    }
    jspProperties = new Vector<>();
    Collection<JspPropertyGroupDescriptor> jspPropertyGroups = jspConfig.getJspPropertyGroups();
    for (JspPropertyGroupDescriptor jspPropertyGroup : jspPropertyGroups) {
        Collection<String> urlPatterns = jspPropertyGroup.getUrlPatterns();
        if (urlPatterns.size() == 0) {
            continue;
        }
        JspProperty property = new JspProperty(jspPropertyGroup.getIsXml(), jspPropertyGroup.getElIgnored(), jspPropertyGroup.getErrorOnELNotFound(), jspPropertyGroup.getScriptingInvalid(), jspPropertyGroup.getPageEncoding(), jspPropertyGroup.getIncludePreludes(), jspPropertyGroup.getIncludeCodas(), jspPropertyGroup.getDeferredSyntaxAllowedAsLiteral(), jspPropertyGroup.getTrimDirectiveWhitespaces(), jspPropertyGroup.getDefaultContentType(), jspPropertyGroup.getBuffer(), jspPropertyGroup.getErrorOnUndeclaredNamespace());
        // the matching logic easier.
        for (String urlPattern : urlPatterns) {
            String path = null;
            String extension = null;
            if (urlPattern.indexOf('*') < 0) {
                // Exact match
                path = urlPattern;
            } else {
                int i = urlPattern.lastIndexOf('/');
                String file;
                if (i >= 0) {
                    path = urlPattern.substring(0, i + 1);
                    file = urlPattern.substring(i + 1);
                } else {
                    file = urlPattern;
                }
                // pattern must be "*", or of the form "*.jsp"
                if (file.equals("*")) {
                    extension = "*";
                } else if (file.startsWith("*.")) {
                    extension = file.substring(file.indexOf('.') + 1);
                }
                // The url patterns are reconstructed as the following:
                // path != null, extension == null:  / or /foo/bar.ext
                // path == null, extension != null:  *.ext
                // path != null, extension == "*":   /foo/*
                boolean isStar = "*".equals(extension);
                if ((path == null && (extension == null || isStar)) || (path != null && !isStar)) {
                    if (log.isWarnEnabled()) {
                        log.warn(Localizer.getMessage("jsp.warning.bad.urlpattern.propertygroup", urlPattern));
                    }
                    continue;
                }
            }
            JspPropertyGroup propertyGroup = new JspPropertyGroup(path, extension, property);
            jspProperties.addElement(propertyGroup);
        }
    }
}
Also used : JspConfigDescriptor(jakarta.servlet.descriptor.JspConfigDescriptor) JspPropertyGroupDescriptor(jakarta.servlet.descriptor.JspPropertyGroupDescriptor)

Example 2 with JspPropertyGroupDescriptor

use of jakarta.servlet.descriptor.JspPropertyGroupDescriptor in project tomcat by apache.

the class TestJspConfigDescriptorImpl method testPropertyGroupsAreIsolate.

@Test
public void testPropertyGroupsAreIsolate() {
    List<TaglibDescriptor> taglibs = Collections.emptyList();
    List<JspPropertyGroupDescriptor> propertyGroups = new ArrayList<>();
    propertyGroups.add(new JspPropertyGroupDescriptorImpl(new JspPropertyGroup()));
    JspConfigDescriptor descriptor = new JspConfigDescriptorImpl(propertyGroups, taglibs);
    descriptor.getJspPropertyGroups().clear();
    Assert.assertEquals(propertyGroups, descriptor.getJspPropertyGroups());
}
Also used : TaglibDescriptor(jakarta.servlet.descriptor.TaglibDescriptor) ArrayList(java.util.ArrayList) JspConfigDescriptor(jakarta.servlet.descriptor.JspConfigDescriptor) JspPropertyGroupDescriptor(jakarta.servlet.descriptor.JspPropertyGroupDescriptor) Test(org.junit.Test)

Example 3 with JspPropertyGroupDescriptor

use of jakarta.servlet.descriptor.JspPropertyGroupDescriptor in project tomcat by apache.

the class TestJspConfigDescriptorImpl method testTaglibsAreIsolate.

@Test
public void testTaglibsAreIsolate() {
    List<TaglibDescriptor> taglibs = new ArrayList<>();
    taglibs.add(new TaglibDescriptorImpl("location", "uri"));
    List<JspPropertyGroupDescriptor> propertyGroups = Collections.emptyList();
    JspConfigDescriptor descriptor = new JspConfigDescriptorImpl(propertyGroups, taglibs);
    descriptor.getTaglibs().clear();
    Assert.assertEquals(taglibs, descriptor.getTaglibs());
}
Also used : TaglibDescriptor(jakarta.servlet.descriptor.TaglibDescriptor) ArrayList(java.util.ArrayList) JspConfigDescriptor(jakarta.servlet.descriptor.JspConfigDescriptor) JspPropertyGroupDescriptor(jakarta.servlet.descriptor.JspPropertyGroupDescriptor) Test(org.junit.Test)

Example 4 with JspPropertyGroupDescriptor

use of jakarta.servlet.descriptor.JspPropertyGroupDescriptor in project tomcat by apache.

the class TestApplicationContext method testJspPropertyGroupsAreIsolated.

@Test
public void testJspPropertyGroupsAreIsolated() throws Exception {
    Tomcat tomcat = getTomcatInstanceTestWebapp(false, false);
    StandardContext standardContext = (StandardContext) tomcat.getHost().findChildren()[0];
    ServletContext servletContext = standardContext.getServletContext();
    Assert.assertNull(servletContext.getJspConfigDescriptor());
    tomcat.start();
    JspConfigDescriptor jspConfigDescriptor = servletContext.getJspConfigDescriptor();
    Collection<JspPropertyGroupDescriptor> propertyGroups = jspConfigDescriptor.getJspPropertyGroups();
    Assert.assertFalse(propertyGroups.isEmpty());
    propertyGroups.clear();
    jspConfigDescriptor = servletContext.getJspConfigDescriptor();
    propertyGroups = jspConfigDescriptor.getJspPropertyGroups();
    Assert.assertFalse(propertyGroups.isEmpty());
}
Also used : Tomcat(org.apache.catalina.startup.Tomcat) ServletContext(jakarta.servlet.ServletContext) JspConfigDescriptor(jakarta.servlet.descriptor.JspConfigDescriptor) JspPropertyGroupDescriptor(jakarta.servlet.descriptor.JspPropertyGroupDescriptor) TomcatBaseTest(org.apache.catalina.startup.TomcatBaseTest) Test(org.junit.Test)

Example 5 with JspPropertyGroupDescriptor

use of jakarta.servlet.descriptor.JspPropertyGroupDescriptor in project tomcat by apache.

the class WebXml method getJspConfigDescriptor.

public JspConfigDescriptor getJspConfigDescriptor() {
    if (jspPropertyGroups.isEmpty() && taglibs.isEmpty()) {
        return null;
    }
    Collection<JspPropertyGroupDescriptor> descriptors = new ArrayList<>(jspPropertyGroups.size());
    for (JspPropertyGroup jspPropertyGroup : jspPropertyGroups) {
        JspPropertyGroupDescriptor descriptor = new JspPropertyGroupDescriptorImpl(jspPropertyGroup);
        descriptors.add(descriptor);
    }
    Collection<TaglibDescriptor> tlds = new HashSet<>(taglibs.size());
    for (Entry<String, String> entry : taglibs.entrySet()) {
        TaglibDescriptor descriptor = new TaglibDescriptorImpl(entry.getValue(), entry.getKey());
        tlds.add(descriptor);
    }
    return new JspConfigDescriptorImpl(descriptors, tlds);
}
Also used : ArrayList(java.util.ArrayList) TaglibDescriptor(jakarta.servlet.descriptor.TaglibDescriptor) JspPropertyGroupDescriptor(jakarta.servlet.descriptor.JspPropertyGroupDescriptor) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

JspPropertyGroupDescriptor (jakarta.servlet.descriptor.JspPropertyGroupDescriptor)6 JspConfigDescriptor (jakarta.servlet.descriptor.JspConfigDescriptor)5 Test (org.junit.Test)4 TaglibDescriptor (jakarta.servlet.descriptor.TaglibDescriptor)3 ArrayList (java.util.ArrayList)3 ServletContext (jakarta.servlet.ServletContext)1 File (java.io.File)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Tomcat (org.apache.catalina.startup.Tomcat)1 TomcatBaseTest (org.apache.catalina.startup.TomcatBaseTest)1