Search in sources :

Example 1 with TaglibDescriptor

use of jakarta.servlet.descriptor.TaglibDescriptor 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 2 with TaglibDescriptor

use of jakarta.servlet.descriptor.TaglibDescriptor 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 3 with TaglibDescriptor

use of jakarta.servlet.descriptor.TaglibDescriptor 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)

Example 4 with TaglibDescriptor

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

the class TldScanner method scanJspConfig.

/**
 * Scan for TLDs defined in &lt;jsp-config&gt;.
 * @throws IOException Error reading resources
 * @throws SAXException XML parsing error
 */
protected void scanJspConfig() throws IOException, SAXException {
    JspConfigDescriptor jspConfigDescriptor = context.getJspConfigDescriptor();
    if (jspConfigDescriptor == null) {
        return;
    }
    Collection<TaglibDescriptor> descriptors = jspConfigDescriptor.getTaglibs();
    for (TaglibDescriptor descriptor : descriptors) {
        String taglibURI = descriptor.getTaglibURI();
        String resourcePath = descriptor.getTaglibLocation();
        // handled.
        if (!resourcePath.startsWith("/")) {
            resourcePath = WEB_INF + resourcePath;
        }
        if (uriTldResourcePathMap.containsKey(taglibURI)) {
            log.warn(Localizer.getMessage(MSG + ".webxmlSkip", resourcePath, taglibURI));
            continue;
        }
        if (log.isTraceEnabled()) {
            log.trace(Localizer.getMessage(MSG + ".webxmlAdd", resourcePath, taglibURI));
        }
        URL url = context.getResource(resourcePath);
        if (url != null) {
            TldResourcePath tldResourcePath;
            if (resourcePath.endsWith(".jar")) {
                // if the path points to a jar file, the TLD is presumed to be
                // inside at META-INF/taglib.tld
                tldResourcePath = new TldResourcePath(url, resourcePath, "META-INF/taglib.tld");
            } else {
                tldResourcePath = new TldResourcePath(url, resourcePath);
            }
            // parse TLD but store using the URI supplied in the descriptor
            TaglibXml tld = tldParser.parse(tldResourcePath);
            uriTldResourcePathMap.put(taglibURI, tldResourcePath);
            tldResourcePathTaglibXmlMap.put(tldResourcePath, tld);
            if (tld.getListeners() != null) {
                listeners.addAll(tld.getListeners());
            }
        } else {
            log.warn(Localizer.getMessage(MSG + ".webxmlFailPathDoesNotExist", resourcePath, taglibURI));
            continue;
        }
    }
}
Also used : TldResourcePath(org.apache.tomcat.util.descriptor.tld.TldResourcePath) TaglibXml(org.apache.tomcat.util.descriptor.tld.TaglibXml) TaglibDescriptor(jakarta.servlet.descriptor.TaglibDescriptor) JspConfigDescriptor(jakarta.servlet.descriptor.JspConfigDescriptor) URL(java.net.URL)

Aggregations

TaglibDescriptor (jakarta.servlet.descriptor.TaglibDescriptor)4 JspConfigDescriptor (jakarta.servlet.descriptor.JspConfigDescriptor)3 JspPropertyGroupDescriptor (jakarta.servlet.descriptor.JspPropertyGroupDescriptor)3 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)2 URL (java.net.URL)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 TaglibXml (org.apache.tomcat.util.descriptor.tld.TaglibXml)1 TldResourcePath (org.apache.tomcat.util.descriptor.tld.TldResourcePath)1