Java Code Examples for org.openide.filesystems.URLMapper#findURL()
The following examples show how to use
org.openide.filesystems.URLMapper#findURL() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WildFlyProperties.java From netbeans with Apache License 2.0 | 6 votes |
private List<URL> selectJars(FileObject file) { if (file == null) { return Collections.EMPTY_LIST; } if (file.isData()) { if (file.isValid() && FileUtil.isArchiveFile(file)) { URL url = URLMapper.findURL(file, URLMapper.EXTERNAL); if (url != null) { return Collections.singletonList(FileUtil.getArchiveRoot(url)); } } return Collections.EMPTY_LIST; } List<URL> result = new ArrayList<URL>(); for (FileObject child : file.getChildren()) { result.addAll(selectJars(child)); } return result; }
Example 2
Source File: WebAppParseSupport.java From netbeans with Apache License 2.0 | 6 votes |
private URL findExternalURL(FileObject fo) { // PENDING - URLMapper.EXTERNAL does not seem to be working now, so using this workaround File f = FileUtil.toFile(fo); if ((f != null)/* && (f.isDirectory())*/) { try { return f.toURI().toURL(); } catch (MalformedURLException e) { LOG.log(Level.INFO, null, e); } } // fallback URL u = URLMapper.findURL(fo, URLMapper.EXTERNAL); URL archiveFile = FileUtil.getArchiveFile(u); if (archiveFile != null) { return archiveFile; } return u; }
Example 3
Source File: MoveClassUI.java From netbeans with Apache License 2.0 | 6 votes |
private Problem setParameters(boolean checkOnly) { if (panel == null) { return null; } targetPkgName = panel.getPackageName(); URL url = URLMapper.findURL(panel.getRootFolder(), URLMapper.EXTERNAL); try { TreePathHandle targetClass = panel.getTargetClass(); if(targetClass != null) { refactoring.setTarget(Lookups.singleton(targetClass)); } else { refactoring.setTarget(Lookups.singleton(new URL(url.toExternalForm() + panel.getPackageName().replace('.', '/')))); // NOI18N } } catch (MalformedURLException ex) { Exceptions.printStackTrace(ex); } if (checkOnly) { return refactoring.fastCheckParameters(); } else { return refactoring.checkParameters(); } }
Example 4
Source File: MoveClassesUI.java From netbeans with Apache License 2.0 | 6 votes |
private Problem setParameters(boolean checkOnly) { if (panel==null) { return null; } URL url = URLMapper.findURL(panel.getRootFolder(), URLMapper.EXTERNAL); try { TreePathHandle targetClass = panel.getTargetClass(); if(targetClass != null) { refactoring.setTarget(Lookups.singleton(targetClass)); } else { refactoring.setTarget(Lookups.singleton(new URL(url.toExternalForm() + panel.getPackageName().replace('.', '/')))); // NOI18N } } catch (MalformedURLException ex) { Exceptions.printStackTrace(ex); } if (checkOnly) { return refactoring.fastCheckParameters(); } else { return refactoring.checkParameters(); } }
Example 5
Source File: TrieDictionary.java From netbeans with Apache License 2.0 | 6 votes |
private static void constructTrie(ByteArray array, List<URL> sources) throws IOException { SortedSet<CharSequence> data = new TreeSet<CharSequence>(); for (URL u : sources) { FileObject f = URLMapper.findFileObject(u); u = f != null ? URLMapper.findURL(f, URLMapper.EXTERNAL) : u; BufferedReader in = new BufferedReader(new InputStreamReader(u.openStream(), "UTF-8")); try { String line; while ((line = in.readLine()) != null) { data.add(CharSequences.create(line)); } } finally { //TODO: wrap in try - catch: in.close(); } } constructTrieData(array, data); }
Example 6
Source File: JDBCDriverDeployHelper.java From netbeans with Apache License 2.0 | 6 votes |
/** * Add JDBC drivers URLs into given List of URL objects. * * @param drivers Target ULR list where to add drivers. * @param jdbcDrivers JDBC drivers to be searched for URLs. */ static private void addDriversURLs(List<URL> drivers, JDBCDriver[] jdbcDrivers) { for (JDBCDriver jdbcDriver : jdbcDrivers) { URL[] allUrls = jdbcDriver.getURLs(); for (int i = 0; i < allUrls.length; i++) { URL driverUrl = allUrls[i]; String strUrl = driverUrl.toString(); if (strUrl.contains("nbinst:/")) { // NOI18N FileObject fo = URLMapper.findFileObject(driverUrl); if (fo != null) { URL localURL = URLMapper.findURL(fo, URLMapper.EXTERNAL); if (localURL != null) { drivers.add(localURL); } } } else { drivers.add(driverUrl); } } } //JDBCDriver }
Example 7
Source File: TransformServlet.java From netbeans with Apache License 2.0 | 5 votes |
private static URL getSampleHTTPServerURL() { FileObject fo = FileUtil.getConfigFile("HTTPServer_DUMMY"); if (fo == null) { return null; } URL u = URLMapper.findURL(fo, URLMapper.NETWORK); return u; }
Example 8
Source File: ArchiveURLMapperTest.java From netbeans with Apache License 2.0 | 5 votes |
private void doFunnyZipEntryNames(String file) throws Exception { File docx = new File(getWorkDir(), "ms-docx.jar"); JarOutputStream jos = new JarOutputStream(new FileOutputStream(docx)); ZipEntry entry = new ZipEntry(file); jos.putNextEntry(entry); jos.write("content".getBytes()); jos.close(); FileObject docxFO = URLMapper.findFileObject(Utilities.toURI(docx).toURL()); assertNotNull(docxFO); assertTrue(FileUtil.isArchiveFile(docxFO)); FileObject docxRoot = FileUtil.getArchiveRoot(docxFO); assertNotNull("Root found", docxRoot); FileObject content = docxRoot.getFileObject(file); assertNotNull("content.xml found", content); assertEquals("Has right bytes", "content", content.asText()); CharSequence log = Log.enable("", Level.WARNING); URL u = URLMapper.findURL(content, URLMapper.EXTERNAL); InputStream is = u.openStream(); byte[] arr = new byte[30]; int len = is.read(arr); assertEquals("Len is content", "content".length(), len); assertEquals("OK", "content", new String(arr, 0, len)); assertEquals("No warnings:\n" + log, 0, log.length()); assertEquals(u.toString(), content, URLMapper.findFileObject(u)); }
Example 9
Source File: XMLResultItem.java From netbeans with Apache License 2.0 | 5 votes |
@Override public CompletionDocumentation resolveLink(String link) { try { DescriptionSource target = src.resolveLink(link); if (target != null) { return new ExtDocum(target, null); } URL base = src.getContentURL(); if (base == null) { // sorry, cannot resolve. return null; } URL targetURL = new URL(base, link); // leave the VM as soon as possible. This hack uses URLMappers // to find out whether URL (converted to FO and back) can be // represented outside the VM boolean external = true; FileObject f = URLMapper.findFileObject(targetURL); if (f != null) { external = URLMapper.findURL(f, URLMapper.EXTERNAL) != null; } return new URLDocum(targetURL, external); } catch (MalformedURLException ex) { Exceptions.printStackTrace(ex); return null; } }
Example 10
Source File: DriverClassLoader.java From netbeans with Apache License 2.0 | 5 votes |
public DriverClassLoader(JDBCDriver driver) { super(new URL[] {}); // Go through the URLs, and if any of them have the nbinst: protocol, // convert these to full-path URLs usable by the classloader URL[] urls = driver.getURLs(); for ( URL url : urls ) { if ("nbinst".equals(url.getProtocol())) { // NOI18N // try to get a file: URL for the nbinst: URL FileObject fo = URLMapper.findFileObject(url); if (fo == null) { LOGGER.log(Level.WARNING, "Unable to find file object for driver url " + url); continue; } URL localURL = URLMapper.findURL(fo, URLMapper.EXTERNAL); if (localURL == null) { LOGGER.log(Level.WARNING, "Unable to get file url for nbinst url " + url); continue; } super.addURL(localURL); } else { super.addURL(url); } } }
Example 11
Source File: URLUtil.java From netbeans with Apache License 2.0 | 5 votes |
/** Returns a URL for the given file object that can be correctly interpreted * by usual web browsers (including Netscape 4.71, IE and Mozilla). * First attempts to get an EXTERNAL URL, if that is a suitable URL, it is used; * otherwise a NETWORK URL is used. */ private static URL getURLOfAppropriateType(FileObject fo, boolean allowJar) { // PENDING - there is still the problem that the HTTP server will be started // (because the HttpServerURLMapper.getURL(...) method starts it), // even when it is not needed URL retVal; URL suitable = null; Iterator instances = result.allInstances ().iterator(); while (instances.hasNext()) { URLMapper mapper = (URLMapper) instances.next(); retVal = mapper.getURL (fo, URLMapper.EXTERNAL); if ((retVal != null) && isAcceptableProtocol(retVal, allowJar)) { // return if this is a 'file' or 'jar' URL String p = retVal.getProtocol().toLowerCase(); if ("file".equals(p) || "jar".equals(p)) { // NOI18N return retVal; } suitable = retVal; } } // if we found a suitable URL, return it if (suitable != null) { return suitable; } URL url = URLMapper.findURL(fo, URLMapper.NETWORK); if (url == null){ Logger.getLogger("global").log(Level.SEVERE, "URLMapper.findURL() failed for " + fo); //NOI18N return null; } return makeURLLocal(url); }
Example 12
Source File: CloseProjectsTest.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected void setUp() throws Exception { clearWorkDir(); MockServices.setServices(TestSupport.TestProjectFactory.class); FileObject workDir = FileUtil.toFileObject(getWorkDir()); assertNotNull(workDir); down = new CountDownLatch(1); List<URL> list = new ArrayList<URL>(); List<ExtIcon> icons = new ArrayList<ExtIcon>(); List<String> names = new ArrayList<String>(); for (int i = 0; i < 30; i++) { FileObject prj = TestSupport.createTestProject(workDir, "prj" + i); URL url = URLMapper.findURL(prj, URLMapper.EXTERNAL); list.add(url); names.add(url.toExternalForm()); icons.add(new ExtIcon()); TestSupport.TestProject tmp = (TestSupport.TestProject)ProjectManager.getDefault ().findProject (prj); assertNotNull("Project found", tmp); tmp.setLookup(Lookups.singleton(new TestProjectOpenedHookImpl(down))); } OpenProjectListSettings.getInstance().setOpenProjectsURLs(list); OpenProjectListSettings.getInstance().setOpenProjectsDisplayNames(names); OpenProjectListSettings.getInstance().setOpenProjectsIcons(icons); //compute project root node children in sync mode System.setProperty("test.projectnode.sync", "true"); }
Example 13
Source File: ShellProjectUtils.java From netbeans with Apache License 2.0 | 5 votes |
public static FileObject findProjectRoots(Project project, List<URL> urls) { if (project == null) { return null; } FileObject ret = null; Set<URL> knownURLs = new HashSet<>(); for (SourceGroup sg : org.netbeans.api.project.ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) { if (org.netbeans.modules.jshell.project.ShellProjectUtils.isNormalRoot(sg)) { if (urls != null) { URL u = URLMapper.findURL(sg.getRootFolder(), URLMapper.INTERNAL); BinaryForSourceQuery.Result r = BinaryForSourceQuery.findBinaryRoots(u); for (URL ru : r.getRoots()) { // ignore JARs, prefer output folder: if (FileUtil.isArchiveArtifact(ru)) { continue; } if (knownURLs.add(ru)) { urls.add(ru); } } } if (ret == null) { ret = sg.getRootFolder(); } } } return ret; }
Example 14
Source File: ShellProjectUtils.java From netbeans with Apache License 2.0 | 5 votes |
/** * Collects project modules and packages from them. * For each modules, provides a list of (non-empty) packages from that module. * @param project * @return */ public static Map<String, Collection<String>> findProjectModulesAndPackages(Project project) { Map<String, Collection<String>> result = new HashMap<>(); if (project == null) { return result; } for (SourceGroup sg : org.netbeans.api.project.ProjectUtils.getSources(project).getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) { if (isNormalRoot(sg)) { URL u = URLMapper.findURL(sg.getRootFolder(), URLMapper.INTERNAL); BinaryForSourceQuery.Result r = BinaryForSourceQuery.findBinaryRoots(u); for (URL u2 : r.getRoots()) { String modName = SourceUtils.getModuleName(u2, true); if (modName != null) { FileObject root = URLMapper.findFileObject(u); Collection<String> pkgs = getPackages(root); //new HashSet<>(); if (!pkgs.isEmpty()) { Collection<String> oldPkgs = result.get(modName); if (oldPkgs != null) { oldPkgs.addAll(pkgs); } else { result.put(modName, pkgs); } } } } } } return result; }
Example 15
Source File: ClassNodeCache.java From netbeans with Apache License 2.0 | 5 votes |
private URL getSourceFile(String name) { // this is slightly faster then original implementation FileObject fo = path.findResource(name.replace('.', '/') + config.getDefaultScriptExtension()); if (fo == null || fo.isFolder()) { return null; } return URLMapper.findURL(fo, URLMapper.EXTERNAL); }
Example 16
Source File: CopyClassRefactoringUI.java From netbeans with Apache License 2.0 | 5 votes |
private void setupRefactoring() { refactoring.setNewName(panel.getNewName()); FileObject rootFolder = panel.getRootFolder(); Lookup target = Lookup.EMPTY; if (rootFolder != null) { try { URL url = URLMapper.findURL(rootFolder, URLMapper.EXTERNAL); URL targetURL = new URL(url.toExternalForm() + panel.getPackageName().replace('.', '/')); // NOI18N target = Lookups.singleton(targetURL); } catch (MalformedURLException ex) { Exceptions.printStackTrace(ex); } } refactoring.setTarget(target); }
Example 17
Source File: CopyStyleAction.java From netbeans with Apache License 2.0 | 5 votes |
/** Converts CSS fileobject to its href that is valid during IDE runtime. */ protected String getHref(FileObject fo) { URL u = URLMapper.findURL(fo, URLMapper.NETWORK); if (u != null) { return u.toExternalForm(); } else { return fo.getPath(); } }
Example 18
Source File: MonitorSupport.java From netbeans with Apache License 2.0 | 5 votes |
private static URL getSampleHTTPServerURL() { FileObject fo = FileUtil.getConfigFile("HTTPServer_DUMMY"); if (fo == null) { return null; } URL u = URLMapper.findURL(fo, URLMapper.NETWORK); return u; }
Example 19
Source File: OutputUtils.java From netbeans with Apache License 2.0 | 4 votes |
/** Called when some sort of action is performed on a line. * @param ev the event describing the line */ @Override @NbBundle.Messages({ "# {0} - class name", "NotFound=Class \"{0}\" not found on classpath", "# {0} - file name", "NoSource=Source file not found for \"{0}\"" }) public void outputLineAction(OutputEvent ev) { StacktraceAttributes sa = matchStackTraceLine(ev.getLine()); if(sa == null || sa.method == null || sa.file == null) { Logger.getLogger(OutputUtils.class.getName()).log(Level.WARNING, "No file found for output line {0}", ev.getLine()); // NOI18N StatusDisplayer.getDefault().setStatusText(Bundle.NoSource(ev.getLine())); return; } ClassPath classPath = getClassPath(); int index = sa.method.indexOf(sa.file); String packageName = sa.method.substring(0, index).replace('.', '/'); //NOI18N String resourceName = packageName + sa.file + ".class"; //NOI18N // issue #258546; have to check all resources. javafx unpacks all classes to target, // SourceForBinaryQuery then fails to find the according java file ... List<FileObject> resources = classPath.findAllResources(resourceName); if (resources != null) { for (FileObject resource : resources) { FileObject root = classPath.findOwnerRoot(resource); if (root != null) { URL url = URLMapper.findURL(root, URLMapper.INTERNAL); SourceForBinaryQuery.Result res = SourceForBinaryQuery.findSourceRoots(url); FileObject[] rootz = res.getRoots(); for (int i = 0; i < rootz.length; i++) { String path = packageName + sa.file + ".java"; //NOI18N FileObject javaFo = rootz[i].getFileObject(path); if (javaFo != null) { try { DataObject obj = DataObject.find(javaFo); EditorCookie cookie = obj.getLookup().lookup(EditorCookie.class); if(cookie != null) { int lineInt = Integer.parseInt(sa.lineNum); try { cookie.getLineSet().getCurrent(lineInt - 1).show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS); } catch (IndexOutOfBoundsException x) { // #155880 cookie.open(); } } else { Logger.getLogger(OutputUtils.class.getName()).log(Level.WARNING, "No cookie found for dataobject {0}", obj); // NOI18N } return; } catch (DataObjectNotFoundException ex) { Exceptions.printStackTrace(ex); } } } } } StatusDisplayer.getDefault().setStatusText(Bundle.NoSource(sa.file)); } else { StatusDisplayer.getDefault().setStatusText(Bundle.NotFound(sa.file)); } }
Example 20
Source File: FileElementQuery.java From netbeans with Apache License 2.0 | 4 votes |
private FileElementQuery(final PHPParseResult result) { super(QueryScope.FILE_SCOPE); this.result = result; this.fileObject = result.getSnapshot().getSource().getFileObject(); this.url = fileObject != null ? URLMapper.findURL(fileObject, URLMapper.INTERNAL) : null; }