/** * 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; }
/** 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); }
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); } } }
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); } } }
public void fileRenamed(FileRenameEvent fe) { FileObject thisFo = this.get(); if (thisFo != null && FileUtil.isParentOf(thisFo, fe.getFile())) { fcl.fileRenamed(fe); } }
public void fileAttributeChanged(FileAttributeEvent fe) { FileObject thisFo = this.get(); if (thisFo != null && FileUtil.isParentOf(thisFo, fe.getFile())) { fcl.fileAttributeChanged(fe); } }
public void fileChanged(FileEvent fe) { FileObject thisFo = this.get(); if (thisFo != null && FileUtil.isParentOf(thisFo, fe.getFile())) { fcl.fileChanged(fe); } }
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); } }
/** 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; }
if (FileUtil.isParentOf(this, target)) { throw new FSException(NbBundle.getMessage(FileObject.class, "EXC_MoveChild", this, target)); // NOI18N
private synchronized Library getLastUsedLibrary (FileObject fo) { if (this.lastUsedRoot != null && FileUtil.isParentOf(this.lastUsedRoot,fo)) { return this.lastUsedLibrary; } else { return null; } }
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; }
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; }
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); }
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); }
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; }
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; }
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; }
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); }
@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(); } }