javax.servlet.descriptor.TaglibDescriptor Java Examples

The following examples show how to use javax.servlet.descriptor.TaglibDescriptor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestJspConfigDescriptorImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@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());
}
 
Example #2
Source File: TestJspConfigDescriptorImpl.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@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());
}
 
Example #3
Source File: JspConfigDescriptorImpl.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
public JspConfigDescriptorImpl(Collection<JspPropertyGroupDescriptor> jspPropertyGroups,
                               Collection<TaglibDescriptor> taglibs) {
    this.jspPropertyGroups = jspPropertyGroups;
    this.taglibs = taglibs;
}
 
Example #4
Source File: JspConfigDescriptorImpl.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@Override
public Collection<TaglibDescriptor> getTaglibs() {
    return new ArrayList<>(taglibs);
}
 
Example #5
Source File: TldScanner.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * 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();
        // Note: Whilst the Servlet 2.4 DTD implies that the location must
        // be a context-relative path starting with '/', JSP.7.3.6.1 states
        // explicitly how paths that do not start with '/' should be
        // 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;
        }
    }
}
 
Example #6
Source File: TldConfig.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * Get the taglib entries from web.xml and add them to the map.
 * 
 * This is not kept in sync with o.a.j.compiler.TldLocationsCache as this
 * code needs to scan the TLDs listed in web.xml whereas Jasper only needs
 * the URI to TLD mappings.
 */
private void tldScanWebXml() {
    
    if (log.isTraceEnabled()) {
        log.trace(sm.getString("tldConfig.webxmlStart"));
    }

    Collection<TaglibDescriptor> descriptors =
        context.getJspConfigDescriptor().getTaglibs();

    for (TaglibDescriptor descriptor : descriptors) {
        String resourcePath = descriptor.getTaglibLocation();
        // Note: Whilst the Servlet 2.4 DTD implies that the location must
        // be a context-relative path starting with '/', JSP.7.3.6.1 states
        // explicitly how paths that do not start with '/' should be
        // handled.
        if (!resourcePath.startsWith("/")) {
            resourcePath = WEB_INF + resourcePath;
        }
        if (taglibUris.contains(descriptor.getTaglibURI())) {
            log.warn(sm.getString("tldConfig.webxmlSkip", resourcePath,
                    descriptor.getTaglibURI()));
        } else {
            if (log.isTraceEnabled()) {
                log.trace(sm.getString("tldConfig.webxmlAdd", resourcePath,
                        descriptor.getTaglibURI()));
            }
            InputStream stream = null;
            try {
                stream = context.getServletContext().getResourceAsStream(
                        resourcePath);
                if (stream != null) {
                    XmlErrorHandler handler = tldScanStream(stream);
                    handler.logFindings(log, resourcePath);
                    taglibUris.add(descriptor.getTaglibURI());
                    webxmlTaglibUris.add(descriptor.getTaglibURI());
                } else {
                    log.warn(sm.getString("tldConfig.webxmlFailPathDoesNotExist", resourcePath,
                            descriptor.getTaglibURI()));
                }
            } catch (IOException ioe) {
                log.warn(sm.getString("tldConfig.webxmlFail", resourcePath,
                        descriptor.getTaglibURI()), ioe);
            } finally {
                if (stream != null) {
                    try {
                        stream.close();
                    } catch (Throwable t) {
                        ExceptionUtils.handleThrowable(t);
                    }
                }
            }
        }
    }
}
 
Example #7
Source File: ApplicationJspConfigDescriptor.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<TaglibDescriptor> getTaglibs() {
    return taglibs;
}
 
Example #8
Source File: TldConfig.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Get the taglib entries from web.xml and add them to the map.
 * 
 * This is not kept in sync with o.a.j.compiler.TldLocationsCache as this
 * code needs to scan the TLDs listed in web.xml whereas Jasper only needs
 * the URI to TLD mappings.
 */
private void tldScanWebXml() {
    
    if (log.isTraceEnabled()) {
        log.trace(sm.getString("tldConfig.webxmlStart"));
    }

    Collection<TaglibDescriptor> descriptors =
        context.getJspConfigDescriptor().getTaglibs();

    for (TaglibDescriptor descriptor : descriptors) {
        String resourcePath = descriptor.getTaglibLocation();
        // Note: Whilst the Servlet 2.4 DTD implies that the location must
        // be a context-relative path starting with '/', JSP.7.3.6.1 states
        // explicitly how paths that do not start with '/' should be
        // handled.
        if (!resourcePath.startsWith("/")) {
            resourcePath = WEB_INF + resourcePath;
        }
        if (taglibUris.contains(descriptor.getTaglibURI())) {
            log.warn(sm.getString("tldConfig.webxmlSkip", resourcePath,
                    descriptor.getTaglibURI()));
        } else {
            if (log.isTraceEnabled()) {
                log.trace(sm.getString("tldConfig.webxmlAdd", resourcePath,
                        descriptor.getTaglibURI()));
            }
            InputStream stream = null;
            try {
                stream = context.getServletContext().getResourceAsStream(
                        resourcePath);
                if (stream != null) {
                    XmlErrorHandler handler = tldScanStream(stream);
                    handler.logFindings(log, resourcePath);
                    taglibUris.add(descriptor.getTaglibURI());
                    webxmlTaglibUris.add(descriptor.getTaglibURI());
                } else {
                    log.warn(sm.getString("tldConfig.webxmlFailPathDoesNotExist", resourcePath,
                            descriptor.getTaglibURI()));
                }
            } catch (IOException ioe) {
                log.warn(sm.getString("tldConfig.webxmlFail", resourcePath,
                        descriptor.getTaglibURI()), ioe);
            } finally {
                if (stream != null) {
                    try {
                        stream.close();
                    } catch (Throwable t) {
                        ExceptionUtils.handleThrowable(t);
                    }
                }
            }
        }
    }
}
 
Example #9
Source File: ApplicationJspConfigDescriptor.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
@Override
public Collection<TaglibDescriptor> getTaglibs() {
    return taglibs;
}
 
Example #10
Source File: JspCServletContext.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public JspConfigDescriptorImpl(Collection<TaglibDescriptor> taglibs,
           Collection<JspPropertyGroupDescriptor> jspPropertyGroups) {
   this.taglibs = taglibs;
   this.jspPropertyGroups = jspPropertyGroups;
}
 
Example #11
Source File: JspCServletContext.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public Collection<TaglibDescriptor> getTaglibs() {
    return this.taglibs;
}
 
Example #12
Source File: TldScanner.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
private void processWebDotXml() throws Exception {


        // Skip if we are only looking for listeners
        if (scanListeners) {
            return;
        }

        JspConfigDescriptor jspConfig = ctxt.getJspConfigDescriptor();
        if (jspConfig == null) {
            return;
        }

        for (TaglibDescriptor taglib: jspConfig.getTaglibs()) {

            if (taglib == null) {
                continue;
            }
            String tagUri = taglib.getTaglibURI();
            String tagLoc = taglib.getTaglibLocation();
            if (tagUri == null || tagLoc == null) {
                continue;
            }
            // Ignore system tlds in web.xml, for backward compatibility
            if (systemUris.contains(tagUri)
                        || (!useMyFaces && systemUrisJsf.contains(tagUri))) {
                continue;
            }
            // Save this location if appropriate
            if (uriType(tagLoc) == NOROOT_REL_URI)
                    tagLoc = "/WEB-INF/" + tagLoc;
            String tagLoc2 = null;
            if (tagLoc.endsWith(JAR_FILE_SUFFIX)) {
                tagLoc = ctxt.getResource(tagLoc).toString();
                tagLoc2 = "META-INF/taglib.tld";
            }
            if (log.isLoggable(Level.FINE)) {
                log.fine( "Add tld map from web.xml: " + tagUri + "=>" + tagLoc+ "," + tagLoc2);
            }
            mappings.put(tagUri, new String[] { tagLoc, tagLoc2 });
        }
    }