Java Code Examples for org.apache.tomcat.JarScanner#scan()

The following examples show how to use org.apache.tomcat.JarScanner#scan() . 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 Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Scan /WEB-INF/lib for JARs and for each one found add it and any
 * /META-INF/web-fragment.xml to the resulting Map. web-fragment.xml files
 * will be parsed before being added to the map. Every JAR will be added and
 * <code>null</code> will be used if no web-fragment.xml was found. Any JARs
 * known not contain fragments will be skipped.
 *
 * @return A map of JAR name to processed web fragment (if any)
 */
protected Map<String,WebXml> processJarsForWebFragments(WebXml application) {

    JarScanner jarScanner = context.getJarScanner();

    boolean parseRequired = true;
    Set<String> absoluteOrder = application.getAbsoluteOrdering();
    if (absoluteOrder != null && absoluteOrder.isEmpty() &&
            !context.getXmlValidation()) {
        // Skip parsing when there is an empty absolute ordering and
        // validation is not enabled
        parseRequired = false;
    }

    FragmentJarScannerCallback callback =
            new FragmentJarScannerCallback(parseRequired);

    jarScanner.scan(context.getServletContext(),
            context.getLoader().getClassLoader(), callback,
            pluggabilityJarsToSkip);

    return callback.getFragments();
}
 
Example 2
Source File: TldLocationsCache.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
private synchronized void init() throws JasperException {
    if (initialized) return;
    try {
        tldScanWebXml();
        tldScanResourcePaths(WEB_INF);
        
        JarScanner jarScanner = JarScannerFactory.getJarScanner(ctxt);
        if (jarScanner != null) {
            jarScanner.scan(ctxt,
                    Thread.currentThread().getContextClassLoader(),
                    new TldJarScannerCallback(), noTldJars);
        }

        initialized = true;
    } catch (Exception ex) {
        throw new JasperException(Localizer.getMessage(
                "jsp.error.internal.tldinit", ex.getMessage()), ex);
    }
}
 
Example 3
Source File: ContextConfig.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Scan /WEB-INF/lib for JARs and for each one found add it and any
 * /META-INF/web-fragment.xml to the resulting Map. web-fragment.xml files
 * will be parsed before being added to the map. Every JAR will be added and
 * <code>null</code> will be used if no web-fragment.xml was found. Any JARs
 * known not contain fragments will be skipped.
 *
 * @return A map of JAR name to processed web fragment (if any)
 */
protected Map<String,WebXml> processJarsForWebFragments(WebXml application) {

    JarScanner jarScanner = context.getJarScanner();

    boolean parseRequired = true;
    Set<String> absoluteOrder = application.getAbsoluteOrdering();
    if (absoluteOrder != null && absoluteOrder.isEmpty() &&
            !context.getXmlValidation()) {
        // Skip parsing when there is an empty absolute ordering and
        // validation is not enabled
        parseRequired = false;
    }

    FragmentJarScannerCallback callback =
            new FragmentJarScannerCallback(parseRequired);

    jarScanner.scan(context.getServletContext(),
            context.getLoader().getClassLoader(), callback,
            pluggabilityJarsToSkip);

    return callback.getFragments();
}
 
Example 4
Source File: TldLocationsCache.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
private synchronized void init() throws JasperException {
    if (initialized) return;
    try {
        tldScanWebXml();
        tldScanResourcePaths(WEB_INF);
        
        JarScanner jarScanner = JarScannerFactory.getJarScanner(ctxt);
        jarScanner.scan(ctxt,
                Thread.currentThread().getContextClassLoader(),
                new TldJarScannerCallback(), noTldJars);

        initialized = true;
    } catch (Exception ex) {
        throw new JasperException(Localizer.getMessage(
                "jsp.error.internal.tldinit", ex.getMessage()), ex);
    }
}
 
Example 5
Source File: ContextConfig.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Scan /WEB-INF/lib for JARs and for each one found add it and any
 * /META-INF/web-fragment.xml to the resulting Map. web-fragment.xml files
 * will be parsed before being added to the map. Every JAR will be added and
 * <code>null</code> will be used if no web-fragment.xml was found. Any JARs
 * known not contain fragments will be skipped.
 *
 * @param application The main web.xml metadata
 * @param webXmlParser The parser to use to process the web.xml file
 * @return A map of JAR name to processed web fragment (if any)
 */
protected Map<String,WebXml> processJarsForWebFragments(WebXml application,
        WebXmlParser webXmlParser) {

    JarScanner jarScanner = context.getJarScanner();
    boolean delegate = false;
    if (context instanceof StandardContext) {
        delegate = ((StandardContext) context).getDelegate();
    }
    boolean parseRequired = true;
    Set<String> absoluteOrder = application.getAbsoluteOrdering();
    if (absoluteOrder != null && absoluteOrder.isEmpty() &&
            !context.getXmlValidation()) {
        // Skip parsing when there is an empty absolute ordering and
        // validation is not enabled
        parseRequired = false;
    }

    FragmentJarScannerCallback callback =
            new FragmentJarScannerCallback(webXmlParser, delegate, parseRequired);

    jarScanner.scan(JarScanType.PLUGGABILITY,
            context.getServletContext(), callback);

    if (!callback.isOk()) {
        ok = false;
    }
    return callback.getFragments();
}
 
Example 6
Source File: TldScanner.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
/**
 * Scan for TLDs in JARs in /WEB-INF/lib.
 */
public void scanJars() {
    JarScanner scanner = JarScannerFactory.getJarScanner(context);
    TldScannerCallback callback = new TldScannerCallback();
    scanner.scan(JarScanType.TLD, context, callback);
    if (callback.scanFoundNoTLDs()) {
        log.info(Localizer.getMessage("jsp.tldCache.noTldSummary"));
    }
}
 
Example 7
Source File: TldConfig.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * Scan for and configure all tag library descriptors found in this
 * web application.
 * 
 * This supports a Tomcat-specific extension to the TLD search
 * order defined in the JSP spec. It allows tag libraries packaged as JAR
 * files to be shared by web applications by simply dropping them in a 
 * location that all web applications have access to (e.g.,
 * <CATALINA_HOME>/lib). It also supports some of the weird and
 * wonderful arrangements present when Tomcat gets embedded.
 *
 * The set of shared JARs to be scanned for TLDs is narrowed down by
 * the <tt>noTldJars</tt> class variable, which contains the names of JARs
 * that are known not to contain any TLDs.
 */
@SuppressWarnings("deprecation") // Context.addApplicationListener(ApplicationListener) is deprecated.
public void execute() {
    long t1=System.currentTimeMillis();

    /*
     * Priority order of URIs required by spec is:
     * 1. J2EE platform taglibs - Tomcat doesn't provide these
     * 2. web.xml entries
     * 3. JARS in WEB-INF/lib & TLDs under WEB-INF (equal priority)
     * 4. Additional entries from the container
     * 
     * Keep processing order in sync with o.a.j.compiler.TldLocationsCache
     */
    
    // Stage 2 - web.xml entries
    tldScanWebXml();
    
    // Stage 3a - TLDs under WEB-INF (not lib or classes)
    tldScanResourcePaths(WEB_INF);

    // Stages 3b & 4
    JarScanner jarScanner = context.getJarScanner();
    
    TldJarScannerCallback tldCallBack = new TldJarScannerCallback();
    jarScanner.scan(context.getServletContext(), context.getLoader().getClassLoader(),
            tldCallBack, noTldJars);
    if(tldCallBack.scanFoundNoTLDs()){
        log.info(sm.getString("tldConfig.noTldSummary"));
    }
    // Now add all the listeners we found to the listeners for this context
    String list[] = getTldListeners();

    if( log.isDebugEnabled() )
        log.debug(sm.getString("tldConfig.addListeners",
                Integer.valueOf(list.length)));

    for( int i=0; list!=null && i<list.length; i++ ) {
        context.addApplicationListener(
                new ApplicationListener(list[i], true));
    }

    long t2=System.currentTimeMillis();
    if( context instanceof StandardContext ) {
        ((StandardContext)context).setTldScanTime(t2-t1);
    }

}
 
Example 8
Source File: TldConfig.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * Scan for and configure all tag library descriptors found in this
 * web application.
 * 
 * This supports a Tomcat-specific extension to the TLD search
 * order defined in the JSP spec. It allows tag libraries packaged as JAR
 * files to be shared by web applications by simply dropping them in a 
 * location that all web applications have access to (e.g.,
 * <CATALINA_HOME>/lib). It also supports some of the weird and
 * wonderful arrangements present when Tomcat gets embedded.
 *
 * The set of shared JARs to be scanned for TLDs is narrowed down by
 * the <tt>noTldJars</tt> class variable, which contains the names of JARs
 * that are known not to contain any TLDs.
 */
@SuppressWarnings("deprecation") // Context.addApplicationListener(ApplicationListener) is deprecated.
public void execute() {
    long t1=System.currentTimeMillis();

    /*
     * Priority order of URIs required by spec is:
     * 1. J2EE platform taglibs - Tomcat doesn't provide these
     * 2. web.xml entries
     * 3. JARS in WEB-INF/lib & TLDs under WEB-INF (equal priority)
     * 4. Additional entries from the container
     * 
     * Keep processing order in sync with o.a.j.compiler.TldLocationsCache
     */
    
    // Stage 2 - web.xml entries
    tldScanWebXml();
    
    // Stage 3a - TLDs under WEB-INF (not lib or classes)
    tldScanResourcePaths(WEB_INF);

    // Stages 3b & 4
    JarScanner jarScanner = context.getJarScanner();
    
    TldJarScannerCallback tldCallBack = new TldJarScannerCallback();
    jarScanner.scan(context.getServletContext(), context.getLoader().getClassLoader(),
            tldCallBack, noTldJars);
    if(tldCallBack.scanFoundNoTLDs()){
        log.info(sm.getString("tldConfig.noTldSummary"));
    }
    // Now add all the listeners we found to the listeners for this context
    String list[] = getTldListeners();

    if( log.isDebugEnabled() )
        log.debug(sm.getString("tldConfig.addListeners",
                Integer.valueOf(list.length)));

    for( int i=0; i<list.length; i++ ) {
        context.addApplicationListener(
                new ApplicationListener(list[i], true));
    }

    long t2=System.currentTimeMillis();
    if( context instanceof StandardContext ) {
        ((StandardContext)context).setTldScanTime(t2-t1);
    }

}