List of usage examples for org.springframework.util ResourceUtils URL_PROTOCOL_VFS
String URL_PROTOCOL_VFS
To view the source code for org.springframework.util ResourceUtils URL_PROTOCOL_VFS.
Click Source Link
From source file:com.javaetmoi.core.spring.vfs.Vfs2ResourceHttpRequestHandler.java
@Override public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { checkAndPrepare(request, response, true); // check whether a matching resource exists Resource resource = getResource(request); if (resource == null) { logger.debug("No matching resource found - returning 404"); response.sendError(HttpServletResponse.SC_NOT_FOUND); return;//from w w w. j a v a2 s .com } // check the resource's media type MediaType mediaType = getMediaType(resource); if (mediaType != null) { if (logger.isDebugEnabled()) { logger.debug("Determined media type '" + mediaType + "' for " + resource); } } else { if (logger.isDebugEnabled()) { logger.debug("No media type found for " + resource + " - not sending a content-type header"); } } // header phase // Use a Vfs2Resource when asset are probided by the JBoss 5 Virtaul File System URL url = resource.getURL(); if (url.getProtocol().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) { resource = new Vfs2Resource(Vfs2Utils.getRoot(url)); } if (new ServletWebRequest(request, response).checkNotModified(resource.lastModified())) { logger.debug("Resource not modified - returning 304"); return; } setHeaders(response, resource, mediaType); // content phase if (METHOD_HEAD.equals(request.getMethod())) { logger.trace("HEAD request - skipping content"); return; } writeContent(response, resource); }
From source file:com.javaetmoi.core.spring.vfs.Vfs2PathMatchingResourcePatternResolver.java
/** * Find all resources that match the given location pattern via the Ant-style PathMatcher. * Supports resources in jar files and zip files and in the file system. * /*from w ww . j a v a 2 s .c o m*/ * @param locationPattern * the location pattern to match * @return the result as Resource array * @throws IOException * in case of I/O errors * @see #doFindPathMatchingJarResources * @see #doFindPathMatchingFileResources * @see org.springframework.util.PathMatcher */ @Override protected Resource[] findPathMatchingResources(String locationPattern) throws IOException { String rootDirPath = determineRootDir(locationPattern); String subPattern = locationPattern.substring(rootDirPath.length()); Resource[] rootDirResources = getResources(rootDirPath); Set<Resource> result = new LinkedHashSet<Resource>(16); for (Resource rootDirResource : rootDirResources) { rootDirResource = resolveRootDirResource(rootDirResource); if (isJarResource(rootDirResource)) { result.addAll(doFindPathMatchingJarResources(rootDirResource, subPattern)); } else if (rootDirResource.getURL().getProtocol().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) { result.addAll(VfsResourceMatchingDelegate.findMatchingResources(rootDirResource, subPattern, getPathMatcher())); } else { result.addAll(doFindPathMatchingFileResources(rootDirResource, subPattern)); } } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Resolved location pattern [" + locationPattern + "] to resources " + result); } return result.toArray(new Resource[result.size()]); }
From source file:com.enonic.cms.core.plugin.container.OsgiContainer.java
private void copyFrameworkJar(final File targetFile) throws Exception { URL location = FrameworkProperties.class.getProtectionDomain().getCodeSource().getLocation(); final String locationFile = location.getFile(); LOG.info("Location of framework.jar : " + locationFile); if (locationFile.endsWith(".jar!/")) // for IBM Websphere 8.5 Liberty Profile {/*from www .j a v a2 s . c o m*/ String absolutePath = locationFile.substring(0, locationFile.length() - 2); location = new URL(absolutePath); } else if (ResourceUtils.URL_PROTOCOL_VFS.equals(location.getProtocol())) // JBOSS 7.1.1 VFS { final URI uri = ResourceUtils.toURI(location); final UrlResource urlResource = new UrlResource(uri); final File file = urlResource.getFile(); String absolutePath = file.getAbsolutePath(); if (!absolutePath.endsWith(urlResource.getFilename())) { // removing /contents folder from path and adding unpacked jar to path. absolutePath = absolutePath.substring(0, absolutePath.length() - VFS_CONTENTS_FOLDER.length()) + urlResource.getFilename(); } final StringBuilder stringBuilder = new StringBuilder("file:/"); if (!SystemUtils.IS_OS_WINDOWS) // windows already has one slash in path like /c:/Program Files/.... { stringBuilder.append('/'); } stringBuilder.append(absolutePath); location = new URL(stringBuilder.toString()); } LOG.info("Copying " + location.toString() + " to " + targetFile.toString()); Files.copy(Resources.newInputStreamSupplier(location), targetFile); }
From source file:org.springframework.core.io.support.PathMatchingResourcePatternResolver.java
/** * Find all resources that match the given location pattern via the * Ant-style PathMatcher. Supports resources in jar files and zip files * and in the file system./*from ww w. ja v a2 s .c o m*/ * @param locationPattern the location pattern to match * @return the result as Resource array * @throws IOException in case of I/O errors * @see #doFindPathMatchingJarResources * @see #doFindPathMatchingFileResources * @see org.springframework.util.PathMatcher */ protected Resource[] findPathMatchingResources(String locationPattern) throws IOException { String rootDirPath = determineRootDir(locationPattern); String subPattern = locationPattern.substring(rootDirPath.length()); Resource[] rootDirResources = getResources(rootDirPath); Set<Resource> result = new LinkedHashSet<>(16); for (Resource rootDirResource : rootDirResources) { rootDirResource = resolveRootDirResource(rootDirResource); URL rootDirUrl = rootDirResource.getURL(); if (equinoxResolveMethod != null) { if (rootDirUrl.getProtocol().startsWith("bundle")) { URL resolvedUrl = (URL) ReflectionUtils.invokeMethod(equinoxResolveMethod, null, rootDirUrl); if (resolvedUrl != null) { rootDirUrl = resolvedUrl; } rootDirResource = new UrlResource(rootDirUrl); } } if (rootDirUrl.getProtocol().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) { result.addAll(VfsResourceMatchingDelegate.findMatchingResources(rootDirUrl, subPattern, getPathMatcher())); } else if (ResourceUtils.isJarURL(rootDirUrl) || isJarResource(rootDirResource)) { result.addAll(doFindPathMatchingJarResources(rootDirResource, rootDirUrl, subPattern)); } else { result.addAll(doFindPathMatchingFileResources(rootDirResource, subPattern)); } } if (logger.isDebugEnabled()) { logger.debug("Resolved location pattern [" + locationPattern + "] to resources " + result); } return result.toArray(new Resource[result.size()]); }
From source file:org.springframework.extensions.config.source.UrlConfigSource.java
/** * <p>A <code>BaseConfigSource</code> maintains a list of source strings which for a <code>UrlConfigSource</code> define * locations from which a configuration file can be retrieved. Each location should be prefixed by an identifier indicating * where to find the configuration file (e.g. on the classpath, as a physical file, etc). If a prefix is not provided * the the location is assumed to be on the classpath.</p> * <p>This method determines where to find the specified configuration file by matching the prefix to an implementation * of the <code>ConfigSource</code> interface and creating a new instance of that class using the location. The <code>ConfigSource</code> * interface requires that a <code>getInputStream</code> method is implemented and this is then invoked and the <code>InputStream</code> * returned by the <code>ConfigSource</code> is then returned by this method</p> * * @param sourceUrl A location from which to obtain an <code>InputStream</code> to a configuration file. * @return An <code>InputStream</code> to a configuration file. *//*from w ww . ja v a 2s .c o m*/ public InputStream getInputStream(String sourceUrl) { // input stream InputStream inputStream = null; // determine the config source BaseConfigSource configSource = null; String sourceString = null; if (sourceUrl.startsWith(PREFIX_FILE)) { sourceString = sourceUrl.substring(5); configSource = new FileConfigSource(sourceString); } else if (sourceUrl.startsWith(PREFIX_HTTP)) { sourceString = sourceUrl; configSource = new HTTPConfigSource(sourceString); } else if (sourceUrl.startsWith(PREFIX_CLASSPATH)) { sourceString = sourceUrl.substring(10); configSource = new ClassPathConfigSource(sourceString); } else if (sourceUrl.startsWith(PREFIX_JAR)) { sourceString = sourceUrl; configSource = new JarConfigSource(sourceString); } else if (sourceUrl.startsWith(ResourceUtils.URL_PROTOCOL_VFS)) { sourceString = sourceUrl; InputStream is = null; try { URL resourceUrl = new URL(sourceString); URLConnection con = (URLConnection) resourceUrl.openConnection(); is = con.getInputStream(); } catch (MalformedURLException e) { if (logger.isDebugEnabled()) logger.debug("The malformed URL has occurred: " + sourceString, e); e.printStackTrace(); } catch (IOException ioe) { if (logger.isDebugEnabled()) logger.debug("Failed to get input stream from open connection: " + sourceString, ioe); } // NOTE! special case for JBOSS VFS protocol! @see MNT-10050 return is; } else if (sourceUrl.startsWith(PREFIX_WEBAPP)) { if (servletContext != null) { sourceString = sourceUrl.substring(PREFIX_WEBAPP.length()); if (!sourceString.startsWith("/")) { sourceString = "/" + sourceString; } try { if (servletContext.getResource(sourceString) != null) { sourceString = servletContext.getRealPath(sourceString); if (sourceString != null) { configSource = new FileConfigSource(sourceString); } } } catch (Exception ex) { if (logger.isInfoEnabled()) logger.info("Unable to locate web application resource: " + sourceString); } } } else if (sourceUrl.indexOf(':') > -1) { throw new ConfigException("Config source cannot be determined: " + sourceUrl); } else { sourceString = sourceUrl; configSource = new ClassPathConfigSource(sourceString); } // retrieve input stream if we've identified a source if (sourceString != null && configSource != null) { inputStream = configSource.getInputStream(sourceString); } return inputStream; }
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./* www .j av a 2 s . c om*/ * * 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 ww .j av a 2 s .c om*/ * @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))); }