Package org.apache.tomcat.util.scan

Examples of org.apache.tomcat.util.scan.Jar


     * added in web-fragment.xml priority order.
     */
    protected void processResourceJARs(Set<WebXml> fragments) {
        for (WebXml fragment : fragments) {
            URL url = fragment.getURL();
            Jar jar = null;
            try {
                // Note: Ignore file URLs for now since only jar URLs will be accepted
                if ("jar".equals(url.getProtocol())) {
                    jar = JarFactory.newInstance(url);
                    jar.nextEntry();
                    String entryName = jar.getEntryName();
                    while (entryName != null) {
                        if (entryName.startsWith("META-INF/resources/")) {
                            context.addResourceJarUrl(url);
                            break;
                        }
                        jar.nextEntry();
                        entryName = jar.getEntryName();
                    }
                } else if ("file".equals(url.getProtocol())) {
                    FileDirContext fileDirContext = new FileDirContext();
                    fileDirContext.setDocBase(new File(url.toURI()).getAbsolutePath());
                    try {
                        fileDirContext.lookup("META-INF/resources/");
                        //lookup succeeded
                        if(context instanceof StandardContext){
                            ((StandardContext)context).addResourcesDirContext(fileDirContext);
                        }
                    } catch (NamingException e) {
                        //not found, ignore
                    }
                }
            } catch (IOException ioe) {
                log.error(sm.getString("contextConfig.resourceJarFail", url,
                        context.getName()));
            } catch (URISyntaxException e) {
                log.error(sm.getString("contextConfig.resourceJarFail", url,
                    context.getName()));
            } finally {
                if (jar != null) {
                    jar.close();
                }
            }
        }
    }
View Full Code Here



    protected void processAnnotationsJar(URL url, WebXml fragment,
            boolean handlesTypesOnly) {

        Jar jar = null;
        InputStream is;

        try {
            jar = JarFactory.newInstance(url);

            jar.nextEntry();
            String entryName = jar.getEntryName();
            while (entryName != null) {
                if (entryName.endsWith(".class")) {
                    is = null;
                    try {
                        is = jar.getEntryInputStream();
                        processAnnotationsStream(
                                is, fragment, handlesTypesOnly);
                    } catch (IOException e) {
                        log.error(sm.getString("contextConfig.inputStreamJar",
                                entryName, url),e);
                    } catch (ClassFormatException e) {
                        log.error(sm.getString("contextConfig.inputStreamJar",
                                entryName, url),e);
                    } finally {
                        if (is != null) {
                            try {
                                is.close();
                            } catch (IOException ioe) {
                                // Ignore
                            }
                        }
                    }
                }
                jar.nextEntry();
                entryName = jar.getEntryName();
            }
        } catch (IOException e) {
            log.error(sm.getString("contextConfig.jarFile", url), e);
        } finally {
            if (jar != null) {
                jar.close();
            }
        }
    }
View Full Code Here

        @Override
        public void scan(JarURLConnection jarConn) throws IOException {

            URL url = jarConn.getURL();
            URL resourceURL = jarConn.getJarFileURL();
            Jar jar = null;
            InputStream is = null;
            WebXml fragment = new WebXml();

            try {
                jar = JarFactory.newInstance(url);
                is = jar.getInputStream(FRAGMENT_LOCATION);

                if (is == null) {
                    // If there is no web.xml, normal JAR no impact on
                    // distributable
                    fragment.setDistributable(true);
                } else {
                    InputSource source = new InputSource(
                            resourceURL.toString() + "!/" + FRAGMENT_LOCATION);
                    source.setByteStream(is);
                    parseWebXml(source, fragment, true);
                }
            } finally {
                if (jar != null) {
                    jar.close();
                }
                fragment.setURL(url);
                if (fragment.getName() == null) {
                    fragment.setName(fragment.getURL().toString());
                }
View Full Code Here

     *
     * Keep in sync with o.a.j.comiler.TldLocationsCache
     */
    private void tldScanJar(JarURLConnection jarConn) {

        Jar jar = null;
        InputStream is;
       
        try {
            jar = JarFactory.newInstance(jarConn.getURL());
           
            jar.nextEntry();
            String entryName = jar.getEntryName();
            while (entryName != null) {
                if (entryName.startsWith("META-INF/") &&
                        entryName.endsWith(".tld")) {
                    is = null;
                    try {
                        is = jar.getEntryInputStream();
                        XmlErrorHandler handler = tldScanStream(is);
                        handler.logFindings(log, jarConn.getURL() + entryName);
                    } finally {
                        if (is != null) {
                            try {
                                is.close();
                            } catch (IOException ioe) {
                                // Ignore
                            }
                        }
                    }
                }
                jar.nextEntry();
                entryName = jar.getEntryName();
            }
        } catch (IOException ioe) {
            log.warn(sm.getString("tldConfig.jarFail", jarConn.getURL()), ioe);
        } finally {
            if (jar != null) {
                jar.close();
            }
        }
    }
View Full Code Here

     * added in web-fragment.xml priority order.
     */
    protected void processResourceJARs(Set<WebXml> fragments) {
        for (WebXml fragment : fragments) {
            URL url = fragment.getURL();
            Jar jar = null;
            try {
                // Note: Ignore file URLs for now since only jar URLs will be accepted
                if ("jar".equals(url.getProtocol())) {
                    jar = JarFactory.newInstance(url);
                    jar.nextEntry();
                    String entryName = jar.getEntryName();
                    while (entryName != null) {
                        if (entryName.startsWith("META-INF/resources/")) {
                            context.addResourceJarUrl(url);
                            break;
                        }
                        jar.nextEntry();
                        entryName = jar.getEntryName();
                    }
                } else if ("file".equals(url.getProtocol())) {
                    FileDirContext fileDirContext = new FileDirContext();
                    fileDirContext.setDocBase(new File(url.toURI()).getAbsolutePath());
                    try {
                        fileDirContext.lookup("META-INF/resources/");
                        //lookup succeeded
                        if(context instanceof StandardContext){
                            ((StandardContext)context).addResourcesDirContext(fileDirContext);
                        }
                    } catch (NamingException e) {
                        //not found, ignore
                    }
                }
            } catch (IOException ioe) {
                log.error(sm.getString("contextConfig.resourceJarFail", url,
                        context.getName()));
            } catch (URISyntaxException e) {
                log.error(sm.getString("contextConfig.resourceJarFail", url,
                    context.getName()));
            } finally {
                if (jar != null) {
                    jar.close();
                }
            }
        }
    }
View Full Code Here


    protected void processAnnotationsJar(URL url, WebXml fragment,
            boolean handlesTypesOnly) {

        Jar jar = null;
        InputStream is;

        try {
            jar = JarFactory.newInstance(url);

            jar.nextEntry();
            String entryName = jar.getEntryName();
            while (entryName != null) {
                if (entryName.endsWith(".class")) {
                    is = null;
                    try {
                        is = jar.getEntryInputStream();
                        processAnnotationsStream(
                                is, fragment, handlesTypesOnly);
                    } catch (IOException e) {
                        log.error(sm.getString("contextConfig.inputStreamJar",
                                entryName, url),e);
                    } catch (ClassFormatException e) {
                        log.error(sm.getString("contextConfig.inputStreamJar",
                                entryName, url),e);
                    } finally {
                        if (is != null) {
                            try {
                                is.close();
                            } catch (IOException ioe) {
                                // Ignore
                            }
                        }
                    }
                }
                jar.nextEntry();
                entryName = jar.getEntryName();
            }
        } catch (IOException e) {
            log.error(sm.getString("contextConfig.jarFile", url), e);
        } finally {
            if (jar != null) {
                jar.close();
            }
        }
    }
View Full Code Here

        @Override
        public void scan(JarURLConnection jarConn) throws IOException {

            URL url = jarConn.getURL();
            URL resourceURL = jarConn.getJarFileURL();
            Jar jar = null;
            InputStream is = null;
            WebXml fragment = new WebXml();

            try {
                jar = JarFactory.newInstance(url);
                if (parseRequired || context.getXmlValidation()) {
                    is = jar.getInputStream(FRAGMENT_LOCATION);
                }

                if (is == null) {
                    // If there is no web-fragment.xml to process there is no
                    // impact on distributable
                    fragment.setDistributable(true);
                } else {
                    InputSource source = new InputSource(
                            "jar:" + resourceURL.toString() + "!/" +
                            FRAGMENT_LOCATION);
                    source.setByteStream(is);
                    parseWebXml(source, fragment, true);
                }
            } finally {
                if (jar != null) {
                    jar.close();
                }
                fragment.setURL(url);
                if (fragment.getName() == null) {
                    fragment.setName(fragment.getURL().toString());
                }
View Full Code Here

                    // need to make sure it is closed again otherwise the TLD file
                    // will be locked until GC runs.
                    conn.getInputStream().close();
                }
            }
            Jar jar = tldResourcePath.getJar();
            if (jar != null) {
                result[1] = jar.getLastModified(tldResourcePath.getEntryName());
            }
        } catch (IOException e) {
            // Ignore (shouldn't happen)
        }
        return result;
View Full Code Here

     * added in web-fragment.xml priority order.
     */
    protected void processResourceJARs(Set<WebXml> fragments) {
        for (WebXml fragment : fragments) {
            URL url = fragment.getURL();
            Jar jar = null;
            try {
                if ("jar".equals(url.getProtocol())) {
                    jar = JarFactory.newInstance(url);
                    jar.nextEntry();
                    String entryName = jar.getEntryName();
                    while (entryName != null) {
                        if (entryName.startsWith("META-INF/resources/")) {
                            context.getResources().createWebResourceSet(
                                    WebResourceRoot.ResourceSetType.RESOURCE_JAR,
                                    "/", url, "/META-INF/resources");
                            break;
                        }
                        jar.nextEntry();
                        entryName = jar.getEntryName();
                    }
                } else if ("file".equals(url.getProtocol())) {
                    File file = new File(url.toURI());
                    File resources = new File(file, "META-INF/resources/");
                    if (resources.isDirectory()) {
                        context.getResources().createWebResourceSet(
                                WebResourceRoot.ResourceSetType.RESOURCE_JAR,
                                "/", file.getAbsolutePath(), null, "/");
                    }
                }
            } catch (IOException ioe) {
                log.error(sm.getString("contextConfig.resourceJarFail", url,
                        context.getName()));
            } catch (URISyntaxException e) {
                log.error(sm.getString("contextConfig.resourceJarFail", url,
                    context.getName()));
            } finally {
                if (jar != null) {
                    jar.close();
                }
            }
        }
    }
View Full Code Here


    protected void processAnnotationsJar(URL url, WebXml fragment,
            boolean handlesTypesOnly) {

        Jar jar = null;
        InputStream is;

        try {
            jar = JarFactory.newInstance(url);

            jar.nextEntry();
            String entryName = jar.getEntryName();
            while (entryName != null) {
                if (entryName.endsWith(".class")) {
                    is = null;
                    try {
                        is = jar.getEntryInputStream();
                        processAnnotationsStream(
                                is, fragment, handlesTypesOnly);
                    } catch (IOException e) {
                        log.error(sm.getString("contextConfig.inputStreamJar",
                                entryName, url),e);
                    } catch (ClassFormatException e) {
                        log.error(sm.getString("contextConfig.inputStreamJar",
                                entryName, url),e);
                    } finally {
                        if (is != null) {
                            try {
                                is.close();
                            } catch (IOException ioe) {
                                // Ignore
                            }
                        }
                    }
                }
                jar.nextEntry();
                entryName = jar.getEntryName();
            }
        } catch (IOException e) {
            log.error(sm.getString("contextConfig.jarFile", url), e);
        } finally {
            if (jar != null) {
                jar.close();
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.tomcat.util.scan.Jar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.