Search in sources :

Example 1 with ApplicationTaglibDescriptor

use of org.apache.catalina.core.ApplicationTaglibDescriptor in project tomcat70 by apache.

the class WebXml method configureContext.

/**
 * Configure a {@link Context} using the stored web.xml representation.
 *
 * @param context   The context to be configured
 */
public void configureContext(Context context) {
    // As far as possible, process in alphabetical order so it is easy to
    // check everything is present
    // Some validation depends on correct public ID
    context.setPublicId(publicId);
    // Everything else in order
    context.setEffectiveMajorVersion(getMajorVersion());
    context.setEffectiveMinorVersion(getMinorVersion());
    for (Entry<String, String> entry : contextParams.entrySet()) {
        context.addParameter(entry.getKey(), entry.getValue());
    }
    context.setDisplayName(displayName);
    context.setDistributable(distributable);
    for (ContextLocalEjb ejbLocalRef : ejbLocalRefs.values()) {
        context.getNamingResources().addLocalEjb(ejbLocalRef);
    }
    for (ContextEjb ejbRef : ejbRefs.values()) {
        context.getNamingResources().addEjb(ejbRef);
    }
    for (ContextEnvironment environment : envEntries.values()) {
        context.getNamingResources().addEnvironment(environment);
    }
    for (ErrorPage errorPage : errorPages.values()) {
        context.addErrorPage(errorPage);
    }
    for (FilterDef filter : filters.values()) {
        if (filter.getAsyncSupported() == null) {
            filter.setAsyncSupported("false");
        }
        context.addFilterDef(filter);
    }
    for (FilterMap filterMap : filterMaps) {
        context.addFilterMap(filterMap);
    }
    for (JspPropertyGroup jspPropertyGroup : jspPropertyGroups) {
        JspPropertyGroupDescriptor descriptor = new ApplicationJspPropertyGroupDescriptor(jspPropertyGroup);
        context.getJspConfigDescriptor().getJspPropertyGroups().add(descriptor);
    }
    for (String listener : listeners) {
        context.addApplicationListener(listener);
    }
    for (Entry<String, String> entry : localeEncodingMappings.entrySet()) {
        context.addLocaleEncodingMappingParameter(entry.getKey(), entry.getValue());
    }
    // Prevents IAE
    if (loginConfig != null) {
        context.setLoginConfig(loginConfig);
    }
    for (MessageDestinationRef mdr : messageDestinationRefs.values()) {
        context.getNamingResources().addMessageDestinationRef(mdr);
    }
    // messageDestinations were ignored in Tomcat 6, so ignore here
    context.setIgnoreAnnotations(metadataComplete);
    for (Entry<String, String> entry : mimeMappings.entrySet()) {
        context.addMimeMapping(entry.getKey(), entry.getValue());
    }
    // Name is just used for ordering
    for (ContextResourceEnvRef resource : resourceEnvRefs.values()) {
        context.getNamingResources().addResourceEnvRef(resource);
    }
    for (ContextResource resource : resourceRefs.values()) {
        context.getNamingResources().addResource(resource);
    }
    for (SecurityConstraint constraint : securityConstraints) {
        context.addConstraint(constraint);
    }
    for (String role : securityRoles) {
        context.addSecurityRole(role);
    }
    for (ContextService service : serviceRefs.values()) {
        context.getNamingResources().addService(service);
    }
    for (ServletDef servlet : servlets.values()) {
        Wrapper wrapper = context.createWrapper();
        if (servlet.getLoadOnStartup() != null) {
            wrapper.setLoadOnStartup(servlet.getLoadOnStartup().intValue());
        }
        if (servlet.getEnabled() != null) {
            wrapper.setEnabled(servlet.getEnabled().booleanValue());
        }
        wrapper.setName(servlet.getServletName());
        Map<String, String> params = servlet.getParameterMap();
        for (Entry<String, String> entry : params.entrySet()) {
            wrapper.addInitParameter(entry.getKey(), entry.getValue());
        }
        wrapper.setRunAs(servlet.getRunAs());
        Set<SecurityRoleRef> roleRefs = servlet.getSecurityRoleRefs();
        for (SecurityRoleRef roleRef : roleRefs) {
            wrapper.addSecurityReference(roleRef.getName(), roleRef.getLink());
        }
        wrapper.setServletClass(servlet.getServletClass());
        MultipartDef multipartdef = servlet.getMultipartDef();
        if (multipartdef != null) {
            if (multipartdef.getMaxFileSize() != null && multipartdef.getMaxRequestSize() != null && multipartdef.getFileSizeThreshold() != null) {
                wrapper.setMultipartConfigElement(new MultipartConfigElement(multipartdef.getLocation(), Long.parseLong(multipartdef.getMaxFileSize()), Long.parseLong(multipartdef.getMaxRequestSize()), Integer.parseInt(multipartdef.getFileSizeThreshold())));
            } else {
                wrapper.setMultipartConfigElement(new MultipartConfigElement(multipartdef.getLocation()));
            }
        }
        if (servlet.getAsyncSupported() != null) {
            wrapper.setAsyncSupported(servlet.getAsyncSupported().booleanValue());
        }
        wrapper.setOverridable(servlet.isOverridable());
        context.addChild(wrapper);
    }
    for (Entry<String, String> entry : servletMappings.entrySet()) {
        context.addServletMapping(entry.getKey(), entry.getValue());
    }
    if (sessionConfig != null) {
        if (sessionConfig.getSessionTimeout() != null) {
            context.setSessionTimeout(sessionConfig.getSessionTimeout().intValue());
        }
        SessionCookieConfig scc = context.getServletContext().getSessionCookieConfig();
        scc.setName(sessionConfig.getCookieName());
        scc.setDomain(sessionConfig.getCookieDomain());
        scc.setPath(sessionConfig.getCookiePath());
        scc.setComment(sessionConfig.getCookieComment());
        if (sessionConfig.getCookieHttpOnly() != null) {
            scc.setHttpOnly(sessionConfig.getCookieHttpOnly().booleanValue());
        }
        if (sessionConfig.getCookieSecure() != null) {
            scc.setSecure(sessionConfig.getCookieSecure().booleanValue());
        }
        if (sessionConfig.getCookieMaxAge() != null) {
            scc.setMaxAge(sessionConfig.getCookieMaxAge().intValue());
        }
        if (sessionConfig.getSessionTrackingModes().size() > 0) {
            context.getServletContext().setSessionTrackingModes(sessionConfig.getSessionTrackingModes());
        }
    }
    for (Entry<String, String> entry : taglibs.entrySet()) {
        TaglibDescriptor descriptor = new ApplicationTaglibDescriptor(entry.getValue(), entry.getKey());
        context.getJspConfigDescriptor().getTaglibs().add(descriptor);
    }
    for (String welcomeFile : welcomeFiles) {
        /*
             * The following will result in a welcome file of "" so don't add
             * that to the context
             * <welcome-file-list>
             *   <welcome-file/>
             * </welcome-file-list>
             */
        if (welcomeFile != null && welcomeFile.length() > 0) {
            context.addWelcomeFile(welcomeFile);
        }
    }
    // Do this last as it depends on servlets
    for (JspPropertyGroup jspPropertyGroup : jspPropertyGroups) {
        String jspServletName = context.findServletMapping("*.jsp");
        if (jspServletName == null) {
            jspServletName = "jsp";
        }
        if (context.findChild(jspServletName) != null) {
            for (String urlPattern : jspPropertyGroup.getUrlPatterns()) {
                context.addServletMapping(urlPattern, jspServletName, true);
            }
        } else {
            if (log.isDebugEnabled()) {
                for (String urlPattern : jspPropertyGroup.getUrlPatterns()) {
                    log.debug("Skiping " + urlPattern + " , no servlet " + jspServletName);
                }
            }
        }
    }
    for (Entry<String, String> entry : postConstructMethods.entrySet()) {
        context.addPostConstructMethod(entry.getKey(), entry.getValue());
    }
    for (Entry<String, String> entry : preDestroyMethods.entrySet()) {
        context.addPreDestroyMethod(entry.getKey(), entry.getValue());
    }
}
Also used : ApplicationJspPropertyGroupDescriptor(org.apache.catalina.core.ApplicationJspPropertyGroupDescriptor) JspPropertyGroupDescriptor(javax.servlet.descriptor.JspPropertyGroupDescriptor) SessionCookieConfig(javax.servlet.SessionCookieConfig) ApplicationTaglibDescriptor(org.apache.catalina.core.ApplicationTaglibDescriptor) Wrapper(org.apache.catalina.Wrapper) ApplicationJspPropertyGroupDescriptor(org.apache.catalina.core.ApplicationJspPropertyGroupDescriptor) MultipartConfigElement(javax.servlet.MultipartConfigElement) TaglibDescriptor(javax.servlet.descriptor.TaglibDescriptor) ApplicationTaglibDescriptor(org.apache.catalina.core.ApplicationTaglibDescriptor)

Aggregations

MultipartConfigElement (javax.servlet.MultipartConfigElement)1 SessionCookieConfig (javax.servlet.SessionCookieConfig)1 JspPropertyGroupDescriptor (javax.servlet.descriptor.JspPropertyGroupDescriptor)1 TaglibDescriptor (javax.servlet.descriptor.TaglibDescriptor)1 Wrapper (org.apache.catalina.Wrapper)1 ApplicationJspPropertyGroupDescriptor (org.apache.catalina.core.ApplicationJspPropertyGroupDescriptor)1 ApplicationTaglibDescriptor (org.apache.catalina.core.ApplicationTaglibDescriptor)1