org.openide.filesystems.FileUtil.getRelativePath()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(154)

本文整理了Java中org.openide.filesystems.FileUtil.getRelativePath()方法的一些代码示例,展示了FileUtil.getRelativePath()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.getRelativePath()方法的具体详情如下:
包路径:org.openide.filesystems.FileUtil
类名称:FileUtil
方法名:getRelativePath

FileUtil.getRelativePath介绍

[英]Gets a relative resource path between folder and fo.
[中]获取文件夹和fo之间的相对资源路径。

代码示例

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

FileObject folderFo = FileUtil.toFileObject(existingFolder);        
assert folderFo != null : existingFolder.getAbsolutePath();
final String relativePath = getRelativePath(existingFolder, folder);
try {
  retval = FileUtil.createFolder(folderFo,relativePath);

代码示例来源:origin: org.netbeans.api/org-openide-filesystems

FileObject folderFo = FileUtil.toFileObject(folder);
assert folderFo != null : folder.getAbsolutePath();
final String relativePath = getRelativePath(folder, data);
try {
  retval = FileUtil.createData(folderFo,relativePath);

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-grailsproject

@Override
public int compareTo(SourceGroupKey o) {
  String relativePath1 = FileUtil.getRelativePath(projectDir, fileObject);
  String relativePath2 = FileUtil.getRelativePath(projectDir, o.fileObject);
  return relativePath1.compareTo(relativePath2);
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-project-ui

private boolean contains( FileObject fo ) {
  String path = FileUtil.getRelativePath( root, fo );        
  assert path != null : "Asking for wrong folder" + fo;
  Object o = names2nodes.get( path );
  return o != null;
}

代码示例来源:origin: dcaoyuan/nbscala

private static boolean isDefaultLocation (FileObject tool, Collection<FileObject> installFolders) {
  assert tool != null && installFolders != null;
  if (installFolders.size()!=1)
    return false;
  FileObject root = installFolders.iterator().next();
  String relativePath = FileUtil.getRelativePath(root,tool);
  if (relativePath == null) {
    return false;
  }
  StringTokenizer tk = new StringTokenizer(relativePath, "/");
  return (tk.countTokens()== 2 && "bin".equals(tk.nextToken()));
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-project-ui

public PackageItem(SourceGroup group, FileObject pkg, boolean empty) {
  this.pkg = pkg;
  this.empty = empty;
  String path = FileUtil.getRelativePath(group.getRootFolder(), pkg);
  assert path != null : "No " + pkg + " in " + group;
  pkgname = path.replace('/', '.');
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-core

/** 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
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-project-ui

private PackageNode get( FileObject fo ) {
  String path = FileUtil.getRelativePath( root, fo );        
  assert path != null : "Asking for wrong folder" + fo;
  Object o = names2nodes.get( path );
  return !isNodeCreated( o ) ? null : (PackageNode)o;
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-j2eeserver

public File getDistributionPath(FileObject sourceFile) {
    for (Iterator i=rootFiles.iterator(); i.hasNext();) {
      File rootFile = (File) i.next();
      FileObject root = FileUtil.toFileObject(rootFile);
      String relative = FileUtil.getRelativePath(root, sourceFile);
      if (relative != null && ! relative.trim().equals("")) { //NOI18N
        return new File(relative);
      }
    }
    return null;
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-support

private String getPackageName(FileObject targetFolder) {
  List<SourceGroup> groups = retrieveGroups();
  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;
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-project-ui

@Override
public String getDisplayName() {
  FileObject folder = dataFolder.getPrimaryFile();
  String path = FileUtil.getRelativePath(root, folder);
  if (path == null) {
    // ???
    return "";
  }
  return PackageDisplayUtils.getDisplayLabel( path.replace('/', '.'));
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-project-jsf

private void setStartPage(Project project, WebModule webModule, FileObject targetFolder, String targetName) {
  String startPage = targetName + ".jsp";
  FileObject webFolder = webModule.getDocumentBase();
  if (webFolder != null) {
    // Allow the first start page been created under subdir of the web root.
    String startPath = FileUtil.getRelativePath(webFolder, targetFolder);
    if (startPath != null && startPath.length() > 0) {
      startPage = startPath + "/" + startPage;
    }
  }
  JsfProjectUtils.createProjectProperty(project, JsfProjectConstants.PROP_START_PAGE, startPage);
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-refactoring

private String getTargetPackageName(FileObject fo){
  String newPackageName = RefactoringUtil.getPackageName(move.getTarget().lookup(URL.class));
  String postfix = FileUtil.getRelativePath(this.folder.getParent(), fo).replace('/', '.');
  if (newPackageName.length() == 0){
    return postfix;
  }
  if (postfix.length() == 0){
    return newPackageName;
  }
  return newPackageName + "." + postfix;
}

代码示例来源:origin: dcaoyuan/nbscala

private String[] setupDebugTestSingle(Properties p, FileObject[] files) {
  FileObject[] testSrcPath = project.getTestSourceRoots().getRoots();
  FileObject root = getRoot(testSrcPath, files[0]);
  String path = FileUtil.getRelativePath(root, files[0]);
  // Convert foo/FooTest.java -> foo.FooTest
  p.setProperty("test.class", path.substring(0, path.length() - 6).replace('/', '.')); // NOI18N
  p.setProperty("javac.includes", ActionUtils.antIncludesList(files, root)); // NOI18N
  return new String[]{"debug-test"}; // NOI18N
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-project

private static URL urlForFile(PhpProject project, FileObject webRoot, FileObject file) throws MalformedURLException {
  String relativePath = null;
  if (file == null) {
    relativePath = ""; // NOI18N
  } else {
    relativePath = FileUtil.getRelativePath(webRoot, file);
    assert relativePath != null : String.format("WebRoot %s must be parent of file %s", webRoot, file);
  }
  URL retval = new URL(getBaseURL(project, StringUtils.hasText(relativePath)), encodeRelativeUrl(relativePath));
  String arguments = ProjectPropertiesSupport.getArguments(project);
  return (arguments != null) ? appendQuery(retval, arguments) : retval;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-apisupport-wizards

@Override
public String[] getModifiedPaths() {
  FileObject layer = cmf.getLayerHandle().getLayerFile();
  NbModuleProvider provider = project.getLookup().lookup(NbModuleProvider.class);
  if(layer != null) {
    return new String[]{FileUtil.getRelativePath(project.getProjectDirectory(), layer)};
  } else if (provider.getManifestFile() != null) {
    return new String[]{FileUtil.getRelativePath(project.getProjectDirectory(), provider.getManifestFile())};
  }
  return new String[0];
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-project

public String getRelativeDocumentRoot() {
  FileObject workDirFo = FileUtil.toFileObject(workDir);
  FileObject documentRootFo = FileUtil.toFileObject(documentRoot);
  String relativePath = FileUtil.getRelativePath(workDirFo, documentRootFo);
  assert relativePath != null : "Document root " + documentRoot + " must be underneath workdir " + workDir;
  return StringUtils.hasText(relativePath) ? relativePath : null;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-clientproject

private void jBrowseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBrowseButtonActionPerformed
  FileObject siteRootFolder = FileUtil.toFileObject(getSiteRoot());
  assert siteRootFolder != null;
  FileObject selectedFile = BrowseFolders.showDialog(new FileObject[] {siteRootFolder}, DataObject.class, getStartFile());
  if (selectedFile != null) {
    jFileToRunTextField.setText(FileUtil.getRelativePath(siteRootFolder, selectedFile));
  }
}//GEN-LAST:event_jBrowseButtonActionPerformed

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-project

@Override
  public String getShortDescription() {
    String filepath = FileUtil.getRelativePath(sourceDir, pair.second());
    if (filepath == null) {
      filepath = FileUtil.getFileDisplayName(pair.second());
    }
    return NbBundle.getMessage(ImportantFileNode.class, "LBL_ImportantFileTooltip", filepath, pair.first().getName());
  }
}

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-project-ui

@Override
public String getName() {
  String relativePath = FileUtil.getRelativePath(root, dataFolder.getPrimaryFile());
  if (relativePath == null) {
    LOG.log(Level.INFO, "Encountered issue #233984: folder:{0} [valid:{1}], root:{2} [valid:{3},folder={4}]", new Object[]{dataFolder.getPrimaryFile().getPath(), dataFolder.getPrimaryFile().isValid(), root.getPath(), root.isValid(), root.isFolder()});
  }
  return relativePath == null ?  dataFolder.getPrimaryFile().getNameExt() /*used to be null, but null not allowed, very rare occurence, not sure what is the right value then*/
                : relativePath.replace('/', '.'); // NOI18N
}

相关文章