Refine search
/** * Tests if a URL represents a JAR or ZIP archive. * If there is no such file object, the test is done by heuristic: any URL with an extension is * treated as an archive. * @param url a URL to a file * @return true if the URL seems to represent a ZIP-format archive * @since 4.48 */ public static boolean isArchiveFile(URL url) { Parameters.notNull("url", url); //NOI18N if ("jar".equals(url.getProtocol())) { //NOI18N //Already inside archive, return false return false; } FileObject fo = URLMapper.findFileObject(url); if ((fo != null) && !fo.isVirtual()) { if (LOG.isLoggable(Level.FINEST)) { LOG.log(Level.FINEST, "isArchiveFile_FILE_RESOLVED", fo); //NOI18N, used by FileUtilTest.testIsArchiveFileRace } return isArchiveFile(fo); } else { return isArchiveFile(url.getPath()); } }
/** Finds appropriate java.io.File to FileObject if possible. * If not possible then null is returned. * This is the inverse operation of {@link #toFileObject}. * @param fo FileObject whose corresponding File will be looked for * @return java.io.File or null if no corresponding File exists. * @since 1.29 */ public static File toFile(FileObject fo) { File retVal = (File) fo.getAttribute("java.io.File"); // NOI18N; if (retVal == null) { URL fileURL = URLMapper.findURL(fo, URLMapper.INTERNAL); if (fileURL == null || !"file".equals(fileURL.getProtocol())) { //NOI18N fileURL = URLMapper.findURL(fo, URLMapper.EXTERNAL); } if ((fileURL != null) && "file".equals(fileURL.getProtocol())) { retVal = Utilities.toFile(URI.create(fileURL.toExternalForm())); } } if (retVal != null) { retVal = normalizeFile(retVal); } assert assertNormalized(retVal); return retVal; }
/** Finds appropriate FileObjects to java.io.File if possible. * If not possible then empty array is returned. More FileObjects may * correspond to one java.io.File that`s why array is returned. * @param file File whose corresponding FileObjects will be looked for. * The file has to be "normalized" otherwise IllegalArgumentException is thrown. * See {@link #normalizeFile} for how to do that. * @return corresponding FileObjects or empty array if no * corresponding FileObject exists. * @since 1.29 * @deprecated Use {@link #toFileObject} instead. */ @Deprecated public static FileObject[] fromFile(File file) { FileObject[] retVal; if (!file.equals(normalizeFile(file))) { throw new IllegalArgumentException( "Parameter file was not " + // NOI18N "normalized. Was " + toDebugString(file) + " instead of " + toDebugString(normalizeFile(file))); // NOI18N } try { URL url = (Utilities.toURI(file).toURL()); retVal = URLMapper.findFileObjects(url); } catch (MalformedURLException e) { retVal = null; } return retVal; }
/** * Returns a FileObject representing the root folder of an archive. * Clients may need to first call {@link #isArchiveFile(FileObject)} to determine * if the file object refers to an archive file. * @param fo a ZIP- (or JAR-) format archive file * @return a virtual archive root folder, or null if the file is not actually an archive * @since 4.48 */ public static FileObject getArchiveRoot(FileObject fo) { URL archiveURL = URLMapper.findURL(fo, URLMapper.EXTERNAL); if (archiveURL == null) { return null; } return URLMapper.findFileObject(getArchiveRoot(archiveURL)); }
/** Find an appropriate instance of FileObject that addresses this URL * * @param url URL to be converted to file object * @return file object corresponding to URL or null if no one was found * @since 4.29 */ public static FileObject findFileObject(URL url) { if (url == null) { throw new NullPointerException("Cannot pass null URL to URLMapper.findFileObject"); // NOI18N } /** first basic implementation */ FileObject[] results = null; Iterator<URLMapper> instances = getInstances().iterator(); while (instances.hasNext() && ((results == null) || (results.length == 0))) { URLMapper mapper = instances.next(); results = mapper.getFileObjects(url); } return ((results != null) && (results.length > 0)) ? results[0] : null; }
private static FileObject findExistingParent(URI first, List<String> segments) throws MalformedURLException, URISyntaxException { URI uri = first; while (true) { URL url = uri.toURL(); FileObject fo = URLMapper.findFileObject(url); if (fo != null) { return fo; } String path = uri.getPath(); int i = path.lastIndexOf('/'); //NOI18N if (i < 0) { i = path.lastIndexOf('\\'); //NOI18N } if (i < 0) { throw new MalformedURLException("URI "+first.toString()); //NOI18N } segments.add(path.substring(i+1)); path = path.substring(0, i); uri = new URI(uri.getScheme(), uri.getUserInfo(), uri.getHost(), uri.getPort(), path, uri.getQuery(), uri.getFragment()); } }
try { String sURL = urlAttr.getValue(); URI uri = new URI(null, sURL, null); boolean nbmRelative = sURL.startsWith("nbres:") || sURL.startsWith("nbresloc:"); URL url = nbmRelative ? uri.toURL() : new URL(location, uri.getRawPath()); URL[] u = LayerUtils.currentify(url, suffix, classpath); URLConnection conn = u[0].openConnection(); conn.connect(); InputStream is = conn.getInputStream(); if (is.read(buf) != buf.length) throw new IOException("wrong content length"); // NOI18N FileObject fo = URLMapper.findFileObject(u[0]); if (fo != null) { fo.removeFileChangeListener(fileChangeListener); fo.addFileChangeListener(fileChangeListener);
private static void addTaglibFacesConfigMapEntry(URL facesConfigUrl) throws IOException, ParserConfigurationException, SAXException { FileObject facesConfigFileObject = URLMapper.findFileObject(facesConfigUrl); String zipFilePath = FileUtil.toFile(FileUtil.getArchiveFile(facesConfigFileObject)).getAbsolutePath(); ZipFile in = new ZipFile(zipFilePath); Enumeration<? extends ZipEntry> entries = in.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (entry.getName().endsWith(".tld")) { URL tagLibUrl = new URL(facesConfigUrl.toString().split("!")[0] + "!/" + entry.getName()); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(false); DocumentBuilder documentBuilder = factory.newDocumentBuilder(); documentBuilder.setEntityResolver(new EmptyEntityResolver()); Document tagLibdocument = documentBuilder.parse(tagLibUrl.openStream()); NodeList tagNodes = tagLibdocument.getElementsByTagName("uri"); // Scan the TLD file to find the taglib URI String taglibUri = tagNodes.item(0).getTextContent().trim(); TagLibFacesConfigInfo tagLibFacesConfigInfo = new TagLibFacesConfigInfo(taglibUri); tagLibFacesConfigInfo.addTagLibUrl(tagLibUrl); tagLibFacesConfigInfo.addFacesConfigUrl(facesConfigUrl); statictTaglibFacesConfigLocationMap.put(taglibUri, tagLibFacesConfigInfo); } } }
private static URL[] normalizeURLs(Collection<URL> urls) { List<URL> urlList = new LinkedList<URL>(); for(URL url : urls) { FileObject fileObject = URLMapper.findFileObject(url); if ("jar".equals(url.getProtocol())) { //NOI18N fileObject = FileUtil.getArchiveFile(fileObject); File f = FileUtil.toFile(fileObject); if (f != null) { try { URL entry = f.toURI().toURL(); if (FileUtil.isArchiveFile(entry)) { entry = FileUtil.getArchiveRoot(entry); } else if (!f.exists()) { assert !entry.toExternalForm().endsWith("/") : f; // NOI18N entry = new URL(entry.toExternalForm() + "/"); // NOI18N
/** Get the FileObject corresponding to a URL returned from the index. */ public static FileObject toFileObject(String urlStr) { try { URL url = new URL(urlStr); return URLMapper.findFileObject(url); } catch (MalformedURLException mue) { Exceptions.printStackTrace(mue); } return null; }
File mainPropertiesFile = helper.resolveFile(loc); try { LibraryManager man = LibraryManager.forLocation(Utilities.toURI(mainPropertiesFile).toURL()); Map<String, List<URI>> volumes = new HashMap<String, List<URI>>(); LibraryTypeProvider provider = LibrariesSupport.getLibraryTypeProvider(library.getType()); for (URL url : urls) { String jarFolder = null; if ("jar".equals(url.getProtocol())) { // NOI18N jarFolder = getJarFolder(URI.create(url.toExternalForm())); url = FileUtil.getArchiveFile(url); FileObject fo = URLMapper.findFileObject(url); File path = FileUtil.toFile(fo); String str = PropertyUtils.relativizeFile(mainPropertiesFile.getParentFile(), path); if (str == null) { File path = FileUtil.toFile(fo); uri = Utilities.toURI(path); } else { try { newurls.add(url.toURI()); } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); Exceptions.printStackTrace(ex);
File f = new File (srcPath); try { URL url = f.toURI().toURL(); if (FileUtil.isArchiveFile(url)) { url = FileUtil.getArchiveRoot(url); FileObject fo = URLMapper.findFileObject(url); if (fo != null) { fo = fo.getFileObject("src"); //NOI18N if (fo != null) { url = fo.getURL(); File f = new File (jdocPath); try { URL url = f.toURI().toURL(); if (FileUtil.isArchiveFile(url)) { url = FileUtil.getArchiveRoot(url); url = new URL (url.toExternalForm()+'/');
private static FileObject getFileObjectFromUrl(String url) { FileObject fo = null; try { fo = URLMapper.findFileObject(new URL(url)); } catch (MalformedURLException e) { //noop } return fo; }
URI uri = null; try { uri = new URI(null, u, null); if (uri.isAbsolute()) { return new Date(0L); external = URLMapper.findFileObject(new URL(location, uri == null ? u : uri.getRawPath())); } catch (MalformedURLException e) { assert false : e; return new Date(0L); return external.lastModified();
if (entry.getName().endsWith("Bundle.properties")) { // NOI18N try { URL url = new URL("jar:" + juri + "!/" + entry.getName()); // NOI18N FileObject fo = URLMapper.findFileObject(url); if (fo == null) { LOG.log(Level.WARNING, "#207183: no bundle file found: {0}", url); BundleNode filternode = new BundleNode(dobjnode, fo.getPath(), codeNameBase); resourcebundlenodes.add(filternode); } catch (Exception e) { Exceptions.printStackTrace(e); Exceptions.printStackTrace(ex);
if ( link.getSize() == 0 ) { Object fileName = link.getAttribute("originalFile"); // NOI18N if ( fileName instanceof String ) { targetFilePath = (String) fileName; } else if (fileName instanceof URL) { targetFilePath = ((URL) fileName).toExternalForm(); } else { LOG.warning("Invalid originalFile '" + fileName + "', ignoring editor settings link " + link.getPath()); //NOI18N URI u; try { u = new URI(targetFilePath); } catch (URISyntaxException e) { u = null; if (u != null && u.isAbsolute()) { try { FileObject ff = URLMapper.findFileObject(u.toURL()); if (ff != null) { if (ff.getFileSystem().isDefault()) { targetFile = FileUtil.getConfigFile(targetFilePath); if (!targetFile.isFolder() || targetFile == baseFolder || !FileUtil.isParentOf(baseFolder, targetFile)) { LOG.warning("Editor settings link '" + link.getPath() + "' is not pointing to " //NOI18N + "a real subfolder of '" + baseFolder.getPath() + "', but to '" + targetFile.getPath() + "'. Ignoring the link."); //NOI18N
@NonNull private RootProcessor createProcessor(@NonNull final Context ctx) throws IOException { final URL root = ctx.getRootURI(); final String mainP = root.getProtocol(); if ("jar".equals(mainP)) { //NOI18N final URL innerURL = FileUtil.getArchiveFile(root); if ("file".equals(innerURL.getProtocol())) { //NOI18N final File archive = BaseUtilities.toFile(URI.create(innerURL.toExternalForm())); if (archive.canRead()) { if (!isUpToDate(ROOT,archive.lastModified())) { final FileObject rootFo = URLMapper.findFileObject(root); if (rootFo != null) { if (!isUpToDate(ROOT,rootFo.lastModified().getTime())) { final Object path = rootFo.getAttribute(Path.class.getName()); return (path instanceof Path) ? new PathProcessor(root, (Path) path, ctx) : final File rootFile = BaseUtilities.toFile(URI.create(root.toExternalForm())); if (rootFile.isDirectory()) { return new FolderProcessor(rootFile, ctx); final FileObject rootFo = URLMapper.findFileObject(root); if (rootFo != null) { if (!isUpToDate(ROOT, rootFo.lastModified().getTime())) { final Object path = rootFo.getAttribute(Path.class.getName()); return (path instanceof Path) ?
for (ScalaPlatform platform : mgr.getInstalledPlatforms()) { for (ClassPath.Entry entry : platform.getBootstrapLibraries().entries()) { if (entry.getURL().equals (binaryRoot)) { res = new Result(platform); this.cache.put (binaryRoot, res); if (entry.getURL().equals (binaryRoot)) { res = new Result(platform); this.cache.put (binaryRoot, res); String binaryRootS = binaryRoot.toExternalForm(); if (binaryRootS.startsWith(JAR_FILE)) { String srcZipS = null; URL srcZip = FileUtil.getArchiveRoot(new URL(srcZipS)); FileObject fo = URLMapper.findFileObject(srcZip); if (fo != null) { return new UnregisteredPlatformResult (fo); Exceptions.printStackTrace(mue);
return gemUrls; FileObject environmentFO = FileUtil.toFileObject(FileUtil.normalizeFile(environment)); if (environmentFO == null) { return gemUrls; String activerecordUrl = activerecord.toExternalForm(); if (activerecordUrl.indexOf(Gems.ACTIVERECORD + "-" + railsVersion) != -1) { // NOI18N URL url = gemUrls.get(gemName); if (url != null) { String urlString = url.toExternalForm(); String replace = gemName + "-" + defaultVersion; int index = urlString.indexOf(replace); if (index != -1) { try { URL newUrl = new URL(urlString.replace(replace, gemName + "-" + railsVersion)); // NOI18N if (first) { first = false; FileObject fo = URLMapper.findFileObject(newUrl); if (fo == null) { Exceptions.printStackTrace(ex);
if (!rootFolder.isValid()) { continue; URL url = rootFolder.toURL(); if (rootFolder.isFolder() && !url.toExternalForm().endsWith("/")) { //NOI18N try { URL url2 = new URL(url.toExternalForm() + '/'); //NOI18N FileObject fo = URLMapper.findFileObject(url2); if (fo != null && fo.equals(rootFolder)) { url = url2; Exceptions.printStackTrace(ex); } catch (Exception ex) { Exceptions.printStackTrace(ex);