Java Code Examples for org.apache.tomcat.util.descriptor.web.WebXml#merge()

The following examples show how to use org.apache.tomcat.util.descriptor.web.WebXml#merge() . 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: ContextConfig.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
protected void processAnnotations(Set<WebXml> fragments,
        boolean handlesTypesOnly, Map<String,JavaClassCacheEntry> javaClassCache) {
    for(WebXml fragment : fragments) {
        // Only need to scan for @HandlesTypes matches if any of the
        // following are true:
        // - it has already been determined only @HandlesTypes is required
        //   (e.g. main web.xml has metadata-complete="true"
        // - this fragment is for a container JAR (Servlet 3.1 section 8.1)
        // - this fragment has metadata-complete="true"
        boolean htOnly = handlesTypesOnly || !fragment.getWebappJar() ||
                fragment.isMetadataComplete();

        WebXml annotations = new WebXml();
        // no impact on distributable
        annotations.setDistributable(true);
        URL url = fragment.getURL();
        processAnnotationsUrl(url, annotations, htOnly, javaClassCache);
        Set<WebXml> set = new HashSet<>();
        set.add(annotations);
        // Merge annotations into fragment - fragment takes priority
        fragment.merge(set);
    }
}
 
Example 2
Source File: JspCServletContext.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private WebXml buildMergedWebXml(boolean validate, boolean blockExternal)
        throws JasperException {
    WebXml webXml = new WebXml();
    WebXmlParser webXmlParser = new WebXmlParser(validate, validate, blockExternal);
    // Use this class's classloader as Ant will have set the TCCL to its own
    webXmlParser.setClassLoader(getClass().getClassLoader());

    try {
        URL url = getResource(
                org.apache.tomcat.util.descriptor.web.Constants.WEB_XML_LOCATION);
        if (!webXmlParser.parseWebXml(url, webXml, false)) {
            throw new JasperException(Localizer.getMessage("jspc.error.invalidWebXml"));
        }
    } catch (IOException e) {
        throw new JasperException(e);
    }

    // if the application is metadata-complete then we can skip fragment processing
    if (webXml.isMetadataComplete()) {
        return webXml;
    }

    // If an empty absolute ordering element is present, fragment processing
    // may be skipped.
    Set<String> absoluteOrdering = webXml.getAbsoluteOrdering();
    if (absoluteOrdering != null && absoluteOrdering.isEmpty()) {
        return webXml;
    }

    Map<String, WebXml> fragments = scanForFragments(webXmlParser);
    Set<WebXml> orderedFragments = WebXml.orderWebFragments(webXml, fragments, this);

    // Find resource JARs
    this.resourceJARs = scanForResourceJARs(orderedFragments, fragments.values());

    // JspC is not affected by annotations so skip that processing, proceed to merge
    webXml.merge(orderedFragments);
    return webXml;
}