Java Code Examples for org.openide.filesystems.FileUtil#getRelativePath()
The following examples show how to use
org.openide.filesystems.FileUtil#getRelativePath() .
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: JSFFrameworkProvider.java From netbeans with Apache License 2.0 | 6 votes |
@Override public String getServletPath(FileObject file){ String url = null; if (file == null) return url; WebModule wm = WebModule.getWebModule(file); if (wm != null){ url = FileUtil.getRelativePath(wm.getDocumentBase(), file); if (url == null) { return null; } if (url.charAt(0)!='/') url = "/" + url; String mapping = ConfigurationUtils.getFacesServletMapping(wm); if (mapping != null && !"".equals(mapping)){ if (mapping.endsWith("/*")){ mapping = mapping.substring(0, mapping.length()-2); url = mapping + url; } } } return url; }
Example 2
Source File: EjbJarMultiViewDataObject.java From netbeans with Apache License 2.0 | 6 votes |
private String getPackageName(FileObject clazz) { synchronized(srcRoots){ if (!initialized) { refreshSourcesTask.waitFinished(); } for (FileObject fo : srcRoots) { String rp = FileUtil.getRelativePath(fo, clazz); if (rp != null) { if (clazz.getExt().length() > 0) { rp = rp.substring(0, rp.length() - clazz.getExt().length() - 1); } return rp.replace('/', '.'); } } } return null; }
Example 3
Source File: JspToggleBreakpointActionProvider.java From netbeans with Apache License 2.0 | 6 votes |
private boolean isJSP(FileObject fo) { WebModule owner = null; if (fo != null) { owner = WebModule.getWebModule(fo); } boolean isJsp = Utils.isJsp(fo) || Utils.isTag(fo); String webRoot = null; if (owner != null && owner.getDocumentBase() != null) { webRoot = FileUtil.getRelativePath(owner.getDocumentBase(), fo); } //#issue 65969 fix: //we allow bp setting only if the file is JSP or TAG file //TODO it should be solved by adding new API into j2eeserver which should announce whether the target server //supports JSP debugging or not return owner != null && webRoot != null && isJsp; }
Example 4
Source File: RequireJsPanel.java From netbeans with Apache License 2.0 | 6 votes |
private String findRelativePath(FileObject from, FileObject to) { String path = FileUtil.getRelativePath(from, to); StringBuilder result = new StringBuilder(); FileObject parent = from.getParent(); while (path == null && parent != null) { result.append("../"); path = FileUtil.getRelativePath(parent, to); parent = parent.getParent(); } if (path != null) { result.append(path); } else { result.append(to.getPath()); } return result.toString(); }
Example 5
Source File: CreateRulePanel.java From netbeans with Apache License 2.0 | 5 votes |
/** * Creates a renderer for the stylesheets combobox dropdown. */ private ListCellRenderer createStylesheetsRenderer() { return new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value == null) { //empty model return c; } if(value instanceof FileObject) { FileObject file = (FileObject) value; if(webRoot == null) { setText(file.getNameExt()); } else { String relativePath = FileUtil.getRelativePath(webRoot, file); if(relativePath != null) { setText(relativePath); } else { //should not happen setText(file.getNameExt()); } } } else if(value instanceof String) { setText((String)value); } return c; } }; }
Example 6
Source File: GrailsArtifactWizardIterator.java From netbeans with Apache License 2.0 | 5 votes |
private static String getPackageName(FileObject targetFolder) { Project project = FileOwnerQuery.getOwner(targetFolder); Sources sources = ProjectUtils.getSources(project); List<SourceGroup> groups = GroovySources.getGroovySourceGroups(sources); String packageName = null; for (int i = 0; i < groups.size() && packageName == null; i++) { packageName = FileUtil.getRelativePath(groups.get(i).getRootFolder(), targetFolder); } if (packageName != null) { packageName = packageName.replaceAll("/", "."); // NOI18N } return packageName; }
Example 7
Source File: GrailsTargetChooserPanelGUI.java From netbeans with Apache License 2.0 | 5 votes |
/** * Get a package combo model item for the package the user selected before opening the wizard. * May return null if it cannot find it; or a String instance if there is a well-defined * package but it is not listed among the packages shown in the list model. */ private Object getPreselectedPackage(SourceGroup group, FileObject folder, ListModel model) { if ( folder == null ) { return null; } FileObject root = group.getRootFolder(); String relPath = FileUtil.getRelativePath( root, folder ); if ( relPath == null ) { // Group Root folder is no a parent of the preselected folder // No package should be selected return null; } else { // Find the right item. String name = relPath.replace('/', '.'); /* int max = model.getSize(); for (int i = 0; i < max; i++) { Object item = model.getElementAt(i); if (item.toString().equals(name)) { return item; } } */ // Didn't find it. // #49954: should nonetheless show something in the combo box. return name; } }
Example 8
Source File: EjbJarWebServicesClientSupport.java From netbeans with Apache License 2.0 | 5 votes |
private String getPackageName(FileObject file){ FileObject parent = file.getParent(); Sources sources = ProjectUtils.getSources(project); SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); String packageName = null; for (int i = 0; i < groups.length && packageName == null; i++) { packageName = FileUtil.getRelativePath(groups[i].getRootFolder(), parent); if (packageName != null) { packageName = groups[i].getName() + "/" + packageName; // NOI18N } } return packageName + ""; // NOI18N }
Example 9
Source File: ModifyElementRulesPanel.java From netbeans with Apache License 2.0 | 5 votes |
private ListCellRenderer createStyleSheetsRenderer() { return new DefaultListCellRenderer() { @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); if (value == null) { setText("<html>" + Bundle.none_item()); } else { FileObject file = (FileObject) value; FileObject webRoot = ProjectWebRootQuery.getWebRoot(file); String file2string; if (webRoot != null) { file2string = FileUtil.getRelativePath(webRoot, file); } else { file2string = FileUtil.getFileDisplayName(file); } setText(file2string); } return c; } }; }
Example 10
Source File: SelectFilePanel.java From netbeans with Apache License 2.0 | 5 votes |
private String getRelativePath(List<FileObject> folders, FileObject file) { for (FileObject folder : folders) { String relativePath = FileUtil.getRelativePath(folder, file); if (relativePath != null) { return folder.getNameExt() + "/" + relativePath; // NOI18N } } return null; }
Example 11
Source File: ThreadsModel.java From netbeans with Apache License 2.0 | 5 votes |
private String getScriptName( DebugSession session ) { SessionId id = session.getSessionId(); if ( id == null ){ return ""; } String fileName = session.getFileName(); FileObject script = id.toSourceFile( fileName ); if (script == null) { return ""; //NOI18N } Project project = FileOwnerQuery.getOwner( script ); return FileUtil.getRelativePath( project.getProjectDirectory(), script ); }
Example 12
Source File: WebProjectWebServicesSupport.java From netbeans with Apache License 2.0 | 5 votes |
private String getPackageName(FileObject file){ FileObject parent = file.getParent(); Sources sources = ProjectUtils.getSources(project); SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); String packageName = null; for (int i = 0; i < groups.length && packageName == null; i++) { packageName = FileUtil.getRelativePath(groups[i].getRootFolder(), parent); if (packageName != null) { packageName = groups[i].getName() + "/" + packageName; } } return packageName + ""; }
Example 13
Source File: DefaultReplaceTokenProvider.java From netbeans with Apache License 2.0 | 5 votes |
@Override public String convert(String action, Lookup lookup) { if (SingleMethod.COMMAND_DEBUG_SINGLE_METHOD.equals(action)) { return ActionProvider.COMMAND_DEBUG_TEST_SINGLE; } if (SingleMethod.COMMAND_RUN_SINGLE_METHOD.equals(action)) { return ActionProvider.COMMAND_TEST_SINGLE; } if (ActionProvider.COMMAND_RUN_SINGLE.equals(action) || ActionProvider.COMMAND_DEBUG_SINGLE.equals(action) || ActionProvider.COMMAND_PROFILE_SINGLE.equals(action)) { FileObject[] fos = extractFileObjectsfromLookup(lookup); if (fos.length > 0) { FileObject fo = fos[0]; if ("text/x-java".equals(fo.getMIMEType())) {//NOI18N Sources srcs = ProjectUtils.getSources(project); SourceGroup[] grp = srcs.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); for (int i = 0; i < grp.length; i++) { String relPath = FileUtil.getRelativePath(grp[i].getRootFolder(), fo); if (relPath != null) { if (SourceUtils.isMainClass(relPath.replaceFirst("[.]java$", "").replace('/', '.'), ClasspathInfo.create(fo), true)) { return action + ".main";//NOI18N } } } } } } return null; }
Example 14
Source File: CreateFromTemplateAttributesImpl.java From netbeans with Apache License 2.0 | 5 votes |
@CheckForNull private static String getWebRootPath(Project project) { for (FileObject webRoot : ProjectWebRootQuery.getWebRoots(project)) { return FileUtil.getRelativePath(project.getProjectDirectory(), webRoot); } return null; }
Example 15
Source File: CreateProjectBuilder.java From netbeans with Apache License 2.0 | 4 votes |
public AddModuleToParentOperation(FileObject projectDirectory, File projFile) { FileObject dir = FileUtil.toFileObject(projFile); relPath = FileUtil.getRelativePath(projectDirectory, dir); }
Example 16
Source File: ProjectWebModule.java From netbeans with Apache License 2.0 | 4 votes |
public String getRelativePath () { return FileUtil.getRelativePath (root, f); }
Example 17
Source File: GroovyVirtualSourceProvider.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void translate(Iterable<File> files, File sourceRoot, Result result) { JavaStubGenerator generator = new JavaStubGenerator(); FileObject rootFO = FileUtil.toFileObject(sourceRoot); Iterator<File> it = files.iterator(); while (it.hasNext()) { File file = FileUtil.normalizeFile(it.next()); List<ClassNode> classNodes = getClassNodes(file); if (classNodes.isEmpty()) { // source is probably broken and there is no AST // let's generate empty Java stub with simple name equal to file name FileObject fo = FileUtil.toFileObject(file); if (fo != null) { String pkg = FileUtil.getRelativePath(rootFO, fo.getParent()); if (pkg != null) { pkg = pkg.replace('/', '.'); StringBuilder sb = new StringBuilder(); if (!pkg.equals("")) { // NOI18N sb.append("package ").append(pkg).append(";"); // NOI18N } String name = fo.getName(); sb.append("public class ").append(name).append("{}"); // NOI18N result.add(file, pkg, name, sb.toString()); } } } else { for (ClassNode classNode : classNodes) { try { CharSequence javaStub = generator.generateClass(classNode); String pkgName = classNode.getPackageName(); if (pkgName == null) { pkgName = ""; // NOI18N } result.add(file, pkgName, classNode.getNameWithoutPackage(), javaStub); } catch (FileNotFoundException ex) { Exceptions.printStackTrace(ex); } } } } }
Example 18
Source File: ProjectTestBase.java From netbeans with Apache License 2.0 | 4 votes |
@Override public boolean contains(FileObject file) throws IllegalArgumentException { return FileUtil.getRelativePath(root, file) != null; }
Example 19
Source File: ProjectEar.java From netbeans with Apache License 2.0 | 4 votes |
public String getRelativePath () { return FileUtil.getRelativePath (root, f); }
Example 20
Source File: JspCompileUtil.java From netbeans with Apache License 2.0 | 2 votes |
/** Finds a relative context path between rootFolder and relativeObject. * Similar to <code>FileUtil.getRelativePath(FileObject, FileObject)</code>, only * different slash '/' conventions. * @return relative context path between rootFolder and relativeObject. The returned path * always starts with a '/'. It ends with a '/' if the relative object is a directory. * @exception IllegalArgumentException if relativeObject is not in rootFolder's tree. */ public static String findRelativeContextPath(FileObject rootFolder, FileObject relativeObject) { String result = "/" + FileUtil.getRelativePath(rootFolder, relativeObject); // NOI18N return relativeObject.isFolder() ? (result + "/") : result; // NOI18N }