private File extractFile(VFSItem item) { if (item instanceof LocalImpl) { LocalImpl resource = (LocalImpl) item; return resource.getBasefile(); } return null; }
/** * Check if the file exist or not * * @param item * @return */ public static boolean exists(VFSItem item) { if (item instanceof NamedContainerImpl) { item = ((NamedContainerImpl) item).getDelegate(); } if (item instanceof MergeSource) { MergeSource source = (MergeSource) item; item = source.getRootWriteContainer(); if (item == null) { // no write container, but the virtual container exist return true; } } if (item instanceof LocalImpl) { LocalImpl localFile = (LocalImpl) item; return localFile.getBasefile() != null && localFile.getBasefile().exists(); } return false; }
private File getOriginFile(VFSItem item) { if (item instanceof LocalImpl) { LocalImpl localImpl = (LocalImpl) item; return localImpl.getBasefile(); } if (item instanceof OlatRelPathImpl) { OlatRelPathImpl relPath = (OlatRelPathImpl) item; return new File(getCanonicalRoot(), relPath.getRelPath()); } return null; }
/** * Copy the content of the source container to the target container. * * @param source * @param target * @return */ public static boolean copyContent(VFSContainer source, VFSContainer target) { if (!source.exists()) { return false; } if (isSelfOrParent(source, target)) { return false; } if (source instanceof NamedContainerImpl) { source = ((NamedContainerImpl) source).getDelegate(); } if (target instanceof NamedContainerImpl) { target = ((NamedContainerImpl) target).getDelegate(); } if (source instanceof LocalImpl && target instanceof LocalImpl) { LocalImpl localSource = (LocalImpl) source; LocalImpl localTarget = (LocalImpl) target; File localSourceFile = localSource.getBasefile(); File localTargetFile = localTarget.getBasefile(); return FileUtils.copyDirContentsToDir(localSourceFile, localTargetFile, false, "VFScopyDir"); } return false; }
private String getRelPath(VFSItem item) { String relPath = null; if (item instanceof NamedContainerImpl) { item = ((NamedContainerImpl) item).getDelegate(); } if (item instanceof MergeSource) { item = ((MergeSource) item).getRootWriteContainer(); } if (item instanceof OlatRelPathImpl) { relPath = ((OlatRelPathImpl) item).getRelPath(); } else if (item instanceof LocalImpl) { LocalImpl impl = (LocalImpl) item; String absolutPath = impl.getBasefile().getAbsolutePath(); if (absolutPath.startsWith(getCanonicalRoot())) { relPath = absolutPath.substring(getCanonicalRoot().length()); } Path path = impl.getBasefile().toPath(); Path relativePath = getCanonicalRootFile().toPath().relativize(path); String relPath2 = "/" + relativePath.toString(); log.debug(relPath + " :: " + relPath2); } return relPath; }