List of usage examples for org.springframework.util ResourceUtils URL_PROTOCOL_VFSZIP
String URL_PROTOCOL_VFSZIP
To view the source code for org.springframework.util ResourceUtils URL_PROTOCOL_VFSZIP.
Click Source Link
From source file:org.springframework.extensions.config.source.UrlConfigSource.java
/** * Processes the given JAR file pattern source. The classpath * will be searched for JAR files that contain files that match * the given pattern./* w w w .j a v a 2 s . c o m*/ * * NOTE: Currently only files within the META-INF folder are supported * i.e. patterns that look like "jar:*!/META-INF/[filename]" * * @param sourcePattern The wildcard pattern for files to find within JARs */ protected void processWildcardJarSource(String sourcePattern) { String file = sourcePattern.substring(7); if (file.startsWith(META_INF) == false) { throw new UnsupportedOperationException( "Only JAR file wildcard searches within the META-INF folder are currently supported"); } try { if (applicationContext == null) { // get a list of all the JAR files that have the META-INF folder Enumeration<URL> urls = this.getClass().getClassLoader().getResources(META_INF); while (urls.hasMoreElements()) { URL url = urls.nextElement(); // only add the item if is a reference to a JAR file if (url.getProtocol().equals(JarConfigSource.JAR_PROTOCOL)) { URLConnection conn = url.openConnection(); if (conn instanceof JarURLConnection) { // open the jar file and see if it contains what we're looking for JarURLConnection jarConn = (JarURLConnection) conn; JarFile jar = ((JarURLConnection) conn).getJarFile(); ZipEntry entry = jar.getEntry(file); if (entry != null) { if (logger.isInfoEnabled()) logger.info("Found " + file + " in " + jarConn.getJarFileURL()); String sourceString = JarConfigSource.JAR_PROTOCOL + ":" + jarConn.getJarFileURL().toExternalForm() + JarConfigSource.JAR_PATH_SEPARATOR + file; super.addSourceString(sourceString); } else if (logger.isDebugEnabled()) { logger.debug("Did not find " + file + " in " + jarConn.getJarFileURL()); } } } } } else { Resource[] resources = applicationContext.getResources(PREFIX_CLASSPATH_ALL + file); for (Resource resource : resources) { URL resourceUrl = resource.getURL(); if (ResourceUtils.isJarURL(resourceUrl) || ResourceUtils.URL_PROTOCOL_VFSZIP.equals(resourceUrl.getProtocol())) { URL jarURL = extractJarFileURL(resourceUrl); String sourceString = JarConfigSource.JAR_PROTOCOL + ":" + jarURL.toString() + JarConfigSource.JAR_PATH_SEPARATOR + file; super.addSourceString(sourceString); } else if (ResourceUtils.URL_PROTOCOL_VFS.equals(resourceUrl.getProtocol())) { super.addSourceString(resourceUrl.toString()); } } } } catch (IOException ioe) { if (logger.isDebugEnabled()) logger.debug("Failed to process JAR file wildcard: " + sourcePattern, ioe); } }
From source file:org.springframework.extensions.webscripts.ClassPathStore.java
/** * Determine whether the given URL points to a resource in a jar file, * that is, has protocol "jar", "zip", "vfszip", "wsjar" or "code-source". * <p>"zip" and "wsjar" and "vfszip" are used by BEA WebLogic Server and IBM WebSphere * and JBoss, respectively, but can be treated like jar files. The same applies to * "code-source" URLs on Oracle OC4J, provided that the path contains a jar separator. * //from w w w. j a va 2 s .c o m * @param url the URL to check * * @return whether the URL has been identified as a JAR URL */ protected static boolean isJarURL(final URL url) { final String protocol = url.getProtocol(); return (ResourceUtils.URL_PROTOCOL_JAR.equals(protocol) || ResourceUtils.URL_PROTOCOL_VFSZIP.equals(protocol) || ResourceUtils.URL_PROTOCOL_ZIP.equals(protocol) || ResourceUtils.URL_PROTOCOL_VFS.equals(protocol) || ResourceUtils.URL_PROTOCOL_WSJAR.equals(protocol) || (ResourceUtils.URL_PROTOCOL_CODE_SOURCE.equals(protocol) && url.getPath().contains(ResourceUtils.JAR_URL_SEPARATOR))); }