本文整理了Java中org.openide.filesystems.FileUtil.isParentOf()
方法的一些代码示例,展示了FileUtil.isParentOf()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.isParentOf()
方法的具体详情如下:
包路径:org.openide.filesystems.FileUtil
类名称:FileUtil
方法名:isParentOf
[英]Recursively checks whether the file is underneath the folder. It checks whether the file and folder are located on the same filesystem, in such case it checks the parent FileObject
of the file recursively until the folder is found or the root of the filesystem is reached.
Warning: this method will return false in the case that folder == fo
.
[中]递归检查文件是否位于文件夹下。它检查文件和文件夹是否位于同一文件系统上,在这种情况下,它会递归检查文件的父级FileObject
,直到找到文件夹或到达文件系统的根。
警告:如果folder == fo
,此方法将返回false。
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
/**
* Gets a relative resource path between folder and fo.
* @param folder root of filesystem or any other folder in folders hierarchy
* @param fo arbitrary FileObject in folder's tree (including folder itself)
* @return relative path between folder and fo. The returned path never
* starts with a '/'. It never ends with a '/'. Specifically, if
* folder==fo, returns "". Returns <code>null</code> if fo is not in
* folder's tree.
* @see #isParentOf
* @since 4.16
*/
public static String getRelativePath(FileObject folder, FileObject fo) {
if (!isParentOf(folder, fo) && (folder != fo)) {
return null;
}
String result = fo.getPath().substring(folder.getPath().length());
if (result.startsWith("/") && !result.startsWith("//")) {
result = result.substring(1);
}
return result;
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
/** Copies this file. This allows the filesystem to perform any additional
* operation associated with the copy. But the default implementation is simple
* copy of the file and its attributes
*
* @param target target folder to move this file to
* @param name new basename of file
* @param ext new extension of file (ignored for folders)
* @return the newly created file object representing the moved file
*/
public FileObject copy(FileObject target, String name, String ext)
throws IOException {
if (FileUtil.isParentOf(this, target)) {
throw new FSException(NbBundle.getMessage(FileObject.class, "EXC_CopyChild", this, target)); // NOI18N
}
return leader.copy(target, name, ext);
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
public void fileDeleted(FileEvent fe) {
FileObject thisFo = this.get();
final FileObject file = fe.getFile();
if (thisFo != null && FileUtil.isParentOf(thisFo, file)) {
fcl.fileDeleted(fe);
if (kept != null) {
kept.remove(file);
}
}
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
public void fileDataCreated(FileEvent fe) {
FileObject thisFo = this.get();
final FileObject file = fe.getFile();
if (thisFo != null && FileUtil.isParentOf(thisFo, file)) {
fcl.fileDataCreated(fe);
if (kept != null) {
kept.add(file);
}
}
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
public void fileRenamed(FileRenameEvent fe) {
FileObject thisFo = this.get();
if (thisFo != null && FileUtil.isParentOf(thisFo, fe.getFile())) {
fcl.fileRenamed(fe);
}
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
public void fileAttributeChanged(FileAttributeEvent fe) {
FileObject thisFo = this.get();
if (thisFo != null && FileUtil.isParentOf(thisFo, fe.getFile())) {
fcl.fileAttributeChanged(fe);
}
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
public void fileChanged(FileEvent fe) {
FileObject thisFo = this.get();
if (thisFo != null && FileUtil.isParentOf(thisFo, fe.getFile())) {
fcl.fileChanged(fe);
}
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
public void fileFolderCreated(FileEvent fe) {
FileObject thisFo = this.get();
final FileObject file = fe.getFile();
if (thisFo != null && FileUtil.isParentOf(thisFo, file)) {
fcl.fileFolderCreated(fe);
addAll(file);
}
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
/** Copies this file. This allows the filesystem to perform any additional
* operation associated with the copy. But the default implementation is simple
* copy of the file and its attributes
*
* @param target target folder to move this file to
* @param name new basename of file
* @param ext new extension of file (ignored for folders)
* @return the newly created file object representing the moved file
*/
public FileObject copy(FileObject target, String name, String ext)
throws IOException {
if (isFolder()) {
if (FileUtil.isParentOf(this, target)) {
throw new FSException(NbBundle.getMessage(FileObject.class, "EXC_OperateChild", this, target)); // NOI18N
}
FileObject peer = target.createFolder(name);
FileUtil.copyAttributes(this, peer);
for (FileObject fo : getChildren()) {
fo.copy(peer, fo.getName(), fo.getExt());
}
return peer;
}
FileObject dest = FileUtil.copyFileImpl(this, target, name, ext);
return dest;
}
代码示例来源:origin: org.netbeans.api/org-openide-filesystems
if (FileUtil.isParentOf(this, target)) {
throw new FSException(NbBundle.getMessage(FileObject.class, "EXC_MoveChild", this, target)); // NOI18N
代码示例来源:origin: dcaoyuan/nbscala
private synchronized Library getLastUsedLibrary (FileObject fo) {
if (this.lastUsedRoot != null && FileUtil.isParentOf(this.lastUsedRoot,fo)) {
return this.lastUsedLibrary;
}
else {
return null;
}
}
代码示例来源:origin: dcaoyuan/nbscala
private FileObject getRoot(FileObject[] roots, FileObject file) {
assert file != null : "File can't be null"; //NOI18N
FileObject srcDir = null;
for (int i = 0; i < roots.length; i++) {
assert roots[i] != null : "Source Path Root can't be null"; //NOI18N
if (FileUtil.isParentOf(roots[i], file) || roots[i].equals(file)) {
srcDir = roots[i];
break;
}
}
return srcDir;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-javascript2-model
private static boolean isInternalFile(FileObject file) {
PlatformProvider p = Lookup.getDefault().lookup(PlatformProvider.class);
if (p == null) {
return false;
}
for (FileObject dir : p.getPlatformStubs()) {
if (dir.equals(file) || FileUtil.isParentOf(dir, file)) {
return true;
}
}
return false;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-project
private static String relativePath(FileObject parent, FileObject child) {
if (child.equals(parent)) {
return ""; // NOI18N
}
if (!FileUtil.isParentOf(parent, child)) {
throw new IllegalArgumentException("Cannot find relative path, " + parent + " is not parent of " + child);
}
return child.getPath().substring(parent.getPath().length() + 1);
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-javafx2-project
private boolean isParentOf(File parent, File child) {
if(parent == null || child == null) {
return false;
}
if(!parent.exists() || !child.exists()) {
return false;
}
FileObject parentFO = FileUtil.toFileObject(parent);
FileObject childFO = FileUtil.toFileObject(child);
return FileUtil.isParentOf(parentFO, childFO);
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-jsf
private SourceGroup getPreselectedGroup(SourceGroup[] groups, FileObject folder) {
for (int i = 0; folder != null && i < groups.length; i++) {
if (FileUtil.isParentOf(groups[i].getRootFolder(), folder)
|| groups[i].getRootFolder().equals(folder)) {
return groups[i];
}
}
if (groups.length > 0) {
return groups[0];
}
return null;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-insync
private FileObject getOurFileObject(FileObject fileObject) {
fileObject = getLocalFileObject(fileObject);
if (fileObject == null)
return null;
// we should create Model only if the file is under document root or source root
if (!FileUtil.isParentOf(JsfProjectUtils.getDocumentRoot(getProject()), fileObject) &&
!FileUtil.isParentOf(JsfProjectUtils.getSourceRoot(getProject()), fileObject)) {
return null;
}
return fileObject;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-javaee-project
private static boolean isInSourceGroup(
@NonNull final FileObject fo,
@NonNull final SourceGroup... sgs) {
for (SourceGroup sg : sgs) {
if (FileUtil.isParentOf(sg.getRootFolder(), fo)) {
return true;
}
}
return false;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-groovy-grailsproject
private boolean isController(FileObject source, Project project) {
if (source == null || !source.getName().endsWith("Controller")) { // NOI18N
return false;
}
FileObject controllerDir = project.getProjectDirectory().getFileObject("grails-app/controllers"); // NOI18N
if (controllerDir == null || !controllerDir.isFolder()) {
return false;
}
return FileUtil.isParentOf(controllerDir, source);
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-java-project-ui
@Override public void destroy() throws IOException {
if (parent != null) {
for (DataObject d = getLookup().lookup(DataObject.class); d != null && FileUtil.isParentOf(parent.getPrimaryFile(), d.getPrimaryFile()); d = d.getFolder()) {
d.delete();
}
} else {
super.destroy();
}
}
内容来源于网络,如有侵权,请联系作者删除!