private static Dir emptyVfsDir(final URL url) { return new Dir() { @Override public String getPath() { return url.toExternalForm(); } @Override public Iterable<File> getFiles() { return Collections.emptyList(); } @Override public void close() { } }; }
public Dir createDir(final URL url) { try { URL adaptedUrl = adaptURL(url); return new ZipDir(new JarFile(adaptedUrl.getFile())); } catch (Exception e) { try { return new ZipDir(new JarFile(url.getFile())); } catch (IOException e1) { if (Reflections.log != null) { Reflections.log.warn("Could not get URL", e); Reflections.log.warn("Could not get URL", e1); } } } return null; }
@Override public Dir createDir(URL url) throws Exception { File file = Vfs.getFile(url); if (file == null || file.exists() == false) { s_logger.warn("URL could not be resolved to a file: " + url); return new EmptyDir(file); } else { return new SystemDir(file); } }
public Dir createDir(final URL url) throws Exception { return emptyVfsDir(url); }
private void initResources(FilterConfig config) { try { if (CONFIG.getContent().getAssetsUrl() != null) { LOGGER.log(Level.INFO, "Using external assets, please provide the jsmart assets content at [" + CONFIG.getContent().getAssetsUrl() + "]"); } ServletContext context = config.getServletContext(); Set<String> libs = context.getResourcePaths(LIB_FILE_PATH); if (libs == null || libs.isEmpty()) { LOGGER.log(Level.SEVERE, "Could not find the JSmart library JAR file. Empty [" + LIB_FILE_PATH + "] resource folder."); return; } String libFilePath = null; for (String lib : libs) { Matcher matcher = JAR_FILE_PATTERN.matcher(lib); if (matcher.find()) { libFilePath = matcher.group(); break; } } if (libFilePath == null) { LOGGER.log(Level.SEVERE, "Could not find the JSmart library JAR file inside [" + LIB_FILE_PATH + "]"); return; } Resources jsonResources = EXPRESSIONS.GSON.fromJson(convertResourceToString(FILTER_RESOURCES), Resources.class); File libFile = new File(context.getRealPath(libFilePath)); Dir content = Vfs.fromURL(libFile.toURI().toURL()); Iterator<Vfs.File> files = content.getFiles().iterator(); while (files.hasNext()) { Vfs.File file = files.next(); // Copy index.jsp and replace content to redirect to welcome-url case configured if (file.getRelativePath().startsWith(INDEX_JSP)) { if (CONFIG.getContent().getWelcomeUrl() != null) { StringWriter writer = new StringWriter(); IOUtils.copy(file.openInputStream(), writer); String index = writer.toString().replace("{0}", CONFIG.getContent().getWelcomeUrl()); copyFileResource(new ByteArrayInputStream(index.getBytes(ENCODING)), file.getRelativePath(), context); } } // Do not copy anything if assets-url was provided if (CONFIG.getContent().getAssetsUrl() != null) { continue; } // Copy js, css and font resources to specific location for (String resource : jsonResources.getResources()) { String resourcePath = resource.replace("*", ""); if (file.getRelativePath().startsWith(resourcePath)) { initDirResources(context.getRealPath(PATH_SEPARATOR), file.getRelativePath()); copyFileResource(file.openInputStream(), file.getRelativePath(), context); break; } } } } catch (Exception ex) { LOGGER.log(Level.SEVERE, ex.getMessage()); } }