当前位置: 首页>>代码示例>>Java>>正文


Java FileObject.isRoot方法代码示例

本文整理汇总了Java中org.openide.filesystems.FileObject.isRoot方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.isRoot方法的具体用法?Java FileObject.isRoot怎么用?Java FileObject.isRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openide.filesystems.FileObject的用法示例。


在下文中一共展示了FileObject.isRoot方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRoot

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Returns source root for given ClassPath root as String, or <code>null</code>.
 */
public static String getRoot(FileObject fileObject) {
    File f = null;
    String path = "";
    try {
        if (fileObject.getFileSystem () instanceof JarFileSystem) {
            f = ((JarFileSystem) fileObject.getFileSystem ()).getJarFile ();
            if (!fileObject.isRoot()) {
                path = "!/"+fileObject.getPath();
            }
        } else {
            f = FileUtil.toFile (fileObject);
        }
    } catch (FileStateInvalidException ex) {
    }
    if (f != null) {
        return f.getAbsolutePath () + path;
    } else {
        return null;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:SourcePathProviderImpl.java

示例2: getURL

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public @Override URL getURL(FileObject fo, int type) {
    if (type != URLMapper.INTERNAL) {
        return null;
    }
    try {
        FileSystem fs = fo.getFileSystem();
        if (fs instanceof SourceFS) {
            String path = fo.getPath();
            if (fo.isFolder() && !fo.isRoot()) {
                path += '/';
            }
            return url((SourceFS) fs, path);
        }
    } catch (FileStateInvalidException x) {
        // ignore
    }
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:SourceURLMapper.java

示例3: delete

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Deletes an obsolete layer entry.
 * Also deletes empty parent directories.
 * @param entry a file to delete
 * @throws IOException in case of problem
 */
public void delete(FileObject entry) throws IOException {
    entry.delete();
    FileObject parent = entry.getParent();
    if (parent.getChildren().length == 0 && !parent.getAttributes().hasMoreElements()) {
        if (parent.isRoot()) {
            // XXX maybe delete the whole layer file! (and its reference in manifest.mf)
        } else {
            delete(parent);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:Hinter.java

示例4: testGetRoot

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void testGetRoot() throws IOException {
    FileSystem fs = FileBasedFileSystem.getInstance();
    FileObject workDirFo = FileBasedFileSystem.getFileObject(getWorkDir());
    while (workDirFo != null && !workDirFo.isRoot()) {
        assertFalse(workDirFo.isRoot());
        workDirFo = workDirFo.getParent();
    }
    assertNotNull(workDirFo);
    assertTrue(workDirFo.isRoot());
    assertSame(workDirFo, fs.getRoot());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:FolderObjTest.java

示例5: testIsFolder

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Test of isFolder method, of class org.netbeans.modules.masterfs.filebasedfs.fileobjects.FolderObj.
 */
public void testIsFolder() {
    File f = testFile;
    
    while (f != null && f.exists()) {            
        FileObject fo = FileBasedFileSystem.getFileObject(f);
        assertNotNull(f.getAbsolutePath(),fo);
        if (fo.isFolder() && !fo.isRoot()) {
            assertTrue(fo instanceof FolderObj);
        }
       
        f = f.getParentFile();            
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:FolderObjTest.java

示例6: findClassPath

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
@Override
public ClassPath findClassPath(FileObject file, String type) {
    while (!file.isRoot()) {
        for (Entry<Entry<FileObject, String>, ClassPath> e : classPathSpec.entrySet()) {
            if (e.getKey().getKey() == file && e.getKey().getValue().equals(type)) {
                return e.getValue();
            }
        }
        file = file.getParent();
    }

    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:RepositoryUpdaterTest.java

示例7: isAllowed

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
static boolean isAllowed(DataObject dataObject) {
    //Action is disabled for root folder eg:"/" on Linux or "C:" on Win
    if (dataObject == null) {
        return false;
    }
    FileObject fo = dataObject.getPrimaryFile();
    if (fo != null) {
        //#63459: Do not enable action on internal object/URL.
        if (URLMapper.findURL(fo, URLMapper.EXTERNAL) == null) {
            return false;
        }
        //Check if it is root.
        if (fo.isRoot()) {
            //It is root: disable.
            return false;
        }
    }

    // Fix #14740 disable action on SystemFileSystem.
    try {
        if (dataObject.getPrimaryFile().getFileSystem().isDefault()) {
            return false;
        }
    } catch (FileStateInvalidException fsie) {
        return false;
    }
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:Actions.java

示例8: getRelativePath

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
 * Finds the relative path to targetFO from sourceFO. 
 * Unlike FileUtil.getRelativePath() does not require targetFO to be within sourceFO sub-tree
 * Returns null if there is no shared parent directory except root.
 * 
 * @param sourceFO file/dir to which the relative path will be related
 * @param targetFO file whose location will be determined with respect to sourceFO
 * @return string relative path leading from sourceFO to targetFO
 */
public static String getRelativePath(@NonNull final FileObject sourceFO, @NonNull final FileObject targetFO) {
    String path = ""; //NOI18N
    FileObject src = sourceFO;
    FileObject tgt = targetFO;
    String targetName = null;
    if(!src.isFolder()) {
        src = src.getParent();
    }
    if(!tgt.isFolder()) {
        targetName = tgt.getNameExt();
        tgt = tgt.getParent();
    }
    LinkedList<String> srcSplit = new LinkedList<String>();
    LinkedList<String> tgtSplit = new LinkedList<String>();
    while(!src.isRoot()) {
        srcSplit.addFirst(src.getName());
        src = src.getParent();
    }
    while(!tgt.isRoot()) {
        tgtSplit.addFirst(tgt.getName());
        tgt = tgt.getParent();
    }
    boolean share = false;
    while(!srcSplit.isEmpty() && !tgtSplit.isEmpty()) {
        if(srcSplit.getFirst().equals(tgtSplit.getFirst())) {
            srcSplit.removeFirst();
            tgtSplit.removeFirst();
            share = true;
        } else {
            break;
        }
    }
    if(!share) {
        return null;
    }
    for(int left = 0; left < srcSplit.size(); left++) {
        if(left == 0) {
            path += ".."; //NOI18N
        } else {
            path += "/.."; //NOI18N
        }
    }
    while(!tgtSplit.isEmpty()) {
        if(path.isEmpty()) {
            path += tgtSplit.getFirst();
        } else {
            path += "/" + tgtSplit.getFirst(); //NOI18N
        }
        tgtSplit.removeFirst();
    }
    if(targetName != null) {
        if(!path.isEmpty()) {
            path += "/" + targetName; //NOI18N
        } else {
            path += targetName;
        }
    }
    return path;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:69,代码来源:JFXProjectUtils.java

示例9: createPrimaryEntry

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
@Override
protected MultiDataObject.Entry createPrimaryEntry (MultiDataObject obj, FileObject primaryFile) {
    FileEntry.Format entry = new FileEntry.Format(obj, primaryFile) {
        @Override
        protected java.text.Format createFormat (FileObject target, String n, String e) {
            ClassPath cp = ClassPath.getClassPath(target, ClassPath.SOURCE);
            String resourcePath = "";
            if (cp != null) {
                resourcePath = cp.getResourceName(target);
                if (resourcePath == null) {
                    resourcePath = ""; // NOI18N
                }
            } else {
                ErrorManager.getDefault().log(ErrorManager.WARNING, "No classpath was found for folder: "+target);
            }
            Map<String,String> m = new HashMap<String,String>();
            m.put("NAME", n ); //NOI18N
            String capitalizedName;
            if (n.length() > 1) {
                capitalizedName = Character.toUpperCase(n.charAt(0))+n.substring(1);
            } else if (n.length() == 1) {
                capitalizedName = ""+Character.toUpperCase(n.charAt(0));
            } else {
                capitalizedName = "";
            }
            m.put("CAPITALIZEDNAME", capitalizedName); //NOI18N
            m.put("LOWERNAME", n.toLowerCase()); //NOI18N
            m.put("UPPERNAME", n.toUpperCase()); //NOI18N

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < n.length(); i++) {
                char c = n.charAt(i);
                if (Character.isJavaIdentifierPart(c)) {
                    sb.append(c);
                }
            }
            String identifier = sb.toString();
            m.put("IDENTIFIER", identifier); // NOI18N
            sb.setCharAt(0, Character.toUpperCase(identifier.charAt(0)));
            m.put("CAPITALIZEDIDENTIFIER", sb.toString()); // NOI18N
            m.put("LOWERIDENTIFIER", identifier.toLowerCase()); //NOI18N
            
            // Yes, this is package sans filename (target is a folder).
            String packageName = resourcePath.replace('/', '.');
            m.put("PACKAGE", packageName); // NOI18N
            String capitalizedPkgName;
            if (packageName == null || packageName.length() == 0) {
                packageName = "";
                capitalizedPkgName = "";
            } else if (packageName.length() > 1) {
                capitalizedPkgName = Character.toUpperCase(packageName.charAt(0))+packageName.substring(1);
            } else {
                capitalizedPkgName = ""+Character.toUpperCase(packageName.charAt(0));
            }
            m.put("CAPITALIZEDPACKAGE", capitalizedPkgName); // NOI18N
            m.put("PACKAGE_SLASHES", resourcePath); // NOI18N
            // Fully-qualified name:
            if (target.isRoot ()) {
                m.put ("PACKAGE_AND_NAME", n); // NOI18N
                m.put ("PACKAGE_AND_NAME_SLASHES", n); // NOI18N
            } else {
                m.put ("PACKAGE_AND_NAME", resourcePath.replace('/', '.') + '.' + n); // NOI18N
                m.put ("PACKAGE_AND_NAME_SLASHES", resourcePath + '/' + n); // NOI18N
            }
            m.put("DATE", DateFormat.getDateInstance(DateFormat.LONG).format(new Date())); // NOI18N
            m.put("TIME", DateFormat.getTimeInstance(DateFormat.SHORT).format(new Date())); // NOI18N
            MapFormat f = new MapFormat(m);
            f.setLeftBrace( "__" ); //NOI18N
            f.setRightBrace( "__" ); //NOI18N
            f.setExactMatch(false);

            return f;
        }
    };
    return entry;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:77,代码来源:GsfDataLoader.java

示例10: modifyMap

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/** Modify the replacement map.
      * May be extended in subclasses to provide additional key/value
      * pairs sensitive to the details of instantiation.
      * @param map the map to add to
      * @param target the destination folder for instantiation
      * @param n the new file name
      * @param e the new file extension
      */
      protected void modifyMap(Map<String, String> map, FileObject target, String n, String e) {
          ClassPath cp = ClassPath.getClassPath(target, ClassPath.SOURCE);
          String resourcePath = "";
          if (cp != null) {
              resourcePath = cp.getResourceName(target);
              if (resourcePath == null) {
                  Logger.getLogger(JavaDataLoader.class.getName()).log(Level.WARNING, "{0} is not on its own source path", FileUtil.getFileDisplayName(target));
                  resourcePath = "";
              }
          } else {
              Logger.getLogger(JavaDataLoader.class.getName()).warning("No classpath was found for folder: "+target);
          }
          map.put("NAME", n); // NOI18N
          // Yes, this is package sans filename (target is a folder).
          map.put("PACKAGE", resourcePath.replace('/', '.')); // NOI18N
          map.put("PACKAGE_SLASHES", resourcePath); // NOI18N
   // Fully-qualified name:
   if (target.isRoot ()) {
map.put ("PACKAGE_AND_NAME", n); // NOI18N
map.put ("PACKAGE_AND_NAME_SLASHES", n); // NOI18N
   } else {
map.put ("PACKAGE_AND_NAME", resourcePath.replace('/', '.') + '.' + n); // NOI18N
map.put ("PACKAGE_AND_NAME_SLASHES", resourcePath + '/' + n); // NOI18N
   }
          // No longer needed due to #6025. (You can just put in quotes, they will not
          // prevent things from being escaped.) But leave the token here for
          // compatibility with old templates. --jglick 26/08/00
          map.put("QUOTES","\""); // NOI18N
          
          for (CreateFromTemplateAttributesProvider provider
                  : Lookup.getDefault().lookupAll(CreateFromTemplateAttributesProvider.class)) {
              Map<String, ?> attrs = provider.attributesFor(
                      getDataObject(),
                      DataFolder.findFolder(target),
                      n);
              if (attrs == null) //#123006
                  continue;
              Object aName = attrs.get("user"); // NOI18N
              if (aName instanceof String) {
                  map.put("USER", (String) aName); // NOI18N
                  break;
              }
          }
      }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:53,代码来源:JavaDataLoader.java

示例11: getActions

import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
@Override
public Action[] getActions(boolean context) {
    Action[] arr;
    arr = super.getActions(context);
    
    //Find if given node is root
    boolean isRoot = false;
    FileObject fo = getOriginal().getLookup().lookup(FileObject.class);
    if (fo == null) {
        Logger.getLogger(FavoritesNode.class.getName()).log(Level.INFO, "No FO in node: {0}:{1}", //NOI18N
                new Object[] { getOriginal().getName(), getOriginal()});
    } else {
        //Check if it is root.
        isRoot = fo.isRoot();
    }
    
    if (isRoot) {
        return createActionsForRoot(arr, FavoritesNode.getNode().equals(this.getParentNode()));
    } else {
        if (FavoritesNode.getNode().equals(this.getParentNode())) {
            DataShadow ds = getShadow();
            if (ds != null) {
                if (ds.getOriginal().getPrimaryFile().isFolder()) {
                    return createActionsForFavoriteFolder(arr);
                } else {
                    return createActionsForFavoriteFile(arr);
                }
            }
        } else {
            if (fo != null) {
                if (fo.isFolder()) {
                    return createActionsForFolder(arr);
                } else {
                    return createActionsForFile(arr);
                }
            }
        }
    }
    //Unknown node - return unmodified actions.
    return arr;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:42,代码来源:FavoritesNode.java


注:本文中的org.openide.filesystems.FileObject.isRoot方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。