001 package org.crsh.cmdline.completers; 002 003 import java.io.File; 004 import java.util.Arrays; 005 import java.util.Collection; 006 007 /** 008 * A completer for the current file system. 009 * <ul> 010 * <li>When the prefix is absolute (it starts with <code>/</code> char) completion will be done from the prefix</li> 011 * <li>When the prefix is relative (it does not start with a <code>/</code> char, the completion is done from the 012 * directory evaluated with the expression <code>new java.io.File(".").getCanonicalPath()</code></li> 013 * </ul> 014 * 015 * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a> 016 */ 017 public class FileCompleter extends AbstractPathCompleter<File> { 018 019 @Override 020 protected String getCurrentPath() throws Exception { 021 return new File(".").getCanonicalPath(); 022 } 023 024 @Override 025 protected File getPath(String path) { 026 return new File(path); 027 } 028 029 @Override 030 protected boolean exists(File path) { 031 return path.exists(); 032 } 033 034 @Override 035 protected boolean isDirectory(File path) { 036 return path.isDirectory(); 037 } 038 039 @Override 040 protected boolean isFile(File path) { 041 return path.isFile(); 042 } 043 044 @Override 045 protected Collection<File> getChilren(File path) { 046 File[] files = path.listFiles(); 047 return files != null ? Arrays.asList(files) : null; 048 } 049 050 @Override 051 protected String getName(File path) { 052 return path.getName(); 053 } 054 }