/** * Create the files for an entry. * Recursive implementation for directory entries. */ public File[] createFiles(String key, MultiCollection<String, ZipEntry> entries) { Collection<ZipEntry> col = entries.getCollection(key); JarAsDirectory[] ret = new JarAsDirectory[col.size()]; Iterator<ZipEntry> it = col.iterator(); for(int i=0; it.hasNext(); i++) { ZipEntry entry = (ZipEntry)it.next(); ret[i] = new JarAsDirectory(jarpath, entry); if(ret[i].isDirectory()) { ret[i].entries = createFiles(ret[i].getEntryName(), entries); } entryfiles.put(entry.getName(), ret[i]); } // System.out.println("create files: "+key+", "+SUtil.arrayToString(ret)); return ret; }
/** * Get the corresponding relative path for a file. * Handles jars specially. */ protected static String convertPathToRelative(File file) { String ret; if(file instanceof JarAsDirectory) { JarAsDirectory jar = (JarAsDirectory)file; if(jar.getZipEntry()!=null) ret = jar.getZipEntry().getName(); else ret = SUtil.convertPathToRelative(jar.getJarPath()); } else { ret = file!=null ? SUtil.convertPathToRelative(file.getAbsolutePath()): null; } return ret; }
/** * Get a file for an entry path. */ public synchronized File getFile(String path) { if(entryfiles==null) refresh(); return (File)entryfiles.get(path); }
/** * Refresh the jar entries. */ public synchronized boolean refresh() { boolean changed = false; // Only the root node needs to be refreshed. if(isRefresh() && new File(jarpath).lastModified()>lastmodified) { changed = true; this.lastmodified = new File(jarpath).lastModified(); // Read entries into multi-collection (path->entries). MultiCollection<String, ZipEntry> entries = createEntries(); // Recursively create files for entries. this.entryfiles = new HashMap<String, JarAsDirectory>(); this.entries = createFiles("/", entries); } // System.out.println("refresh: "+entry+", "+changed); return changed; }
/** * Refresh the jar entries. */ public synchronized boolean refresh() { boolean changed = false; // Only the root node needs to be refreshed. if(entry==null && new File(jarpath).lastModified()>lastmodified) { changed = true; this.lastmodified = new File(jarpath).lastModified(); // Read entries into multi-collection (path->entries). MultiCollection entries = createEntries(); // Recursively create files for entries. this.entryfiles = new HashMap(); this.entries = createFiles("/", entries); } // System.out.println("refresh: "+entry+", "+changed); return changed; }
try final JarAsDirectory jad = new JarAsDirectory(file.getPath()); jad.refresh(); MultiCollection zipentries = jad.createEntries(); ename = ename.substring(slash!=-1? slash+1: 0, ename.endsWith("/")? ename.length()-1: ename.length()); final RemoteJarFile tmp = new RemoteJarFile(ename, "jar:file:"+jad.getJarPath()+"!/"+entry.getName(), entry.isDirectory(), ename, rjfentries, entry.getName(), entry.getTime(), File.separatorChar, SUtil.getPrefixLength(jad), jad.length()); filter.filter(jad.getFile(entry.getName())).addResultListener(new IResultListener<Boolean>()
/** * Create the files for an entry. * Recursive implementation for directory entries. */ public File[] createFiles(String key, MultiCollection entries) { Collection col = entries.getCollection(key); JarAsDirectory[] ret = new JarAsDirectory[col.size()]; Iterator it = col.iterator(); for(int i=0; it.hasNext(); i++) { ZipEntry entry = (ZipEntry)it.next(); ret[i] = new JarAsDirectory(jarpath, entry); if(ret[i].isDirectory()) { ret[i].entries = createFiles(ret[i].entry.getName(), entries); } entryfiles.put(entry.getName(), ret[i]); } // System.out.println("create files: "+key+", "+SUtil.arrayToString(ret)); return ret; }
public boolean isEnabled() { boolean ret = false; if(first!=null && first.getSelectedTreePath()!=null) { Object node = first.getSelectedTreePath().getLastPathComponent(); if(node instanceof FileNode) { File file = ((FileNode)node).getFile(); ret = !file.isDirectory() || (file instanceof JarAsDirectory && ((JarAsDirectory)file).isRoot()); } else if(node instanceof RemoteFileNode) { ret = !((RemoteFileNode)node).getRemoteFile().isDirectory(); } } return ret; } };
/** * Create a new service container node. */ public JarNode(ISwingTreeNode parent, AsyncSwingTreeModel model, JTree tree, File file, IIconCache iconcache, INodeFactory factory) { super(parent, model, tree, file instanceof JarAsDirectory? file: new JarAsDirectory(file.getPath()), iconcache, factory); // System.out.println("node: "+getClass()+" "+desc.getName()); }
/** * Get the path entries {path, display name}. */ public String[] getPathEntries() { String[] ret = new String[getChildCount()]; for(int i=0; i<ret.length; i++) { ISwingTreeNode node = getChild(i); if(node instanceof FileNode) { if(node instanceof JarNode) { ret[i] = ((JarAsDirectory)((FileNode)node).getFile()).getJarPath(); } else { ret[i] = ((FileNode)node).getFile().getAbsolutePath(); } } else { // Todo: if(node instanceof RemoteJarNode)??? ret[i] = ((RemoteFileNode)node).getRemoteFile().getPath(); } } return ret; } }
final String mypath = getAbsolutePath();
final boolean dir = file instanceof RemoteJarFile? ((RemoteJarFile)file).isDirectory(): false; final JarAsDirectory jad = name!=null? new JarAsDirectory(file.getPath(), name, dir, true): new JarAsDirectory(file.getPath()); jad.refresh(); MultiCollection zipentries = jad.createEntries(); final RemoteJarFile tmp = new RemoteJarFile(ename, jad.getJarPath(), entry.isDirectory(), ename, null, entry.getName(), entry.getTime(), File.separatorChar, SUtil.getPrefixLength(jad), jad.length()); filter.filter(jad.getFile(entry.getName())).addResultListener(new IResultListener<Boolean>()
public boolean isEnabled() { boolean ret = false; if(first!=null && first.getSelectedTreePath()!=null) { Object node = first.getSelectedTreePath().getLastPathComponent(); if(node instanceof FileNode) { File file = ((FileNode)node).getFile(); ret = !file.isDirectory() || (file instanceof JarAsDirectory && ((JarAsDirectory)file).isRoot()); } else if(node instanceof RemoteFileNode) { ret = !((RemoteFileNode)node).getRemoteFile().isDirectory(); } } return ret; } };
/** * Set the file. */ public void setFile(File file) { this.file = file instanceof JarAsDirectory? file: new JarAsDirectory(file.getPath()); }
final String mypath = getAbsolutePath();
/** * Get a file for an entry path. */ public synchronized File getFile(String path) { if(entryfiles==null) refresh(); return (File)entryfiles.get(path); }
if(!isroot) if(!file.isDirectory() || (file instanceof JarAsDirectory && ((JarAsDirectory)file).isRoot()))
/** * Asynchronously search for children. * Should call setChildren() once children are found. */ protected void searchChildren() { ((JarAsDirectory)getFile()).refresh(); super.searchChildren(); }
((JarAsDirectory)file).refresh();