public static void directoryListJSON( IVResource dir, String path, User user, JSONWriter jsonWriter) { if (dir.exists()) { IVResource[] listFiles = dir.listFiles(); for (int j = 0; j < listFiles.length; j++) { IVResource member = listFiles[j]; if (Resource.isHidden(member)) continue; jsonWriter .startObject() .addField("name", member.getName()) .addField("isDir", member.isDirectory()) .endObject(); } List links = user.getLinks().findLinks(path); for (Iterator iterator = links.iterator(); iterator.hasNext(); ) { Link link = (Link) iterator.next(); jsonWriter .startObject() .addField("name", link.name) .addField("isDir", true) .addField("link", link.location) .endObject(); } } /* if (path.equals(".") || path.length()==0 || jsonWriter.isEmpty()) { ServerManager.getServerManger().getLibraryManager().listFiles(path,jsonWriter); } */ }
public IVResource[] getParents() { Vector parents = new Vector(); IVResource parent = this.getParent(); while (parent != null) { parents.add(0, parent); parent = parent.getParent(); } if (this.isDirectory()) parents.add(this); return (IVResource[]) parents.toArray(new IVResource[parents.size()]); }
public static void copyDirectory(IVResource source, IVResource destination, boolean recurse) { IVResource[] list = source.listFiles(); for (int i = 0; i < list.length; i++) { destination.mkdir(); IVResource r = destination.create(list[i].getName()); if (list[i].isDirectory()) { r.mkdir(); if (recurse) { VResourceUtils.copyDirectory(list[i], r, recurse); } } else { try { if (!r.exists()) { r.createNewInstance(); VResourceUtils.copyFile(list[i], r); r.flushWorkingCopy(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
public boolean isHidden(IVResource file) { IPath path = new Path(file.getPath()); for (int i = 0; i < this.filterDirs.length; i++) { IPath fp = new Path(filterDirs[i]); if (fp.isPrefixOf(path)) return true; } return false; }
public static void copyFile(IVResource src, IVResource dest) throws IOException { InputStream in = null; OutputStream out = null; try { in = src.getInputStreem(); out = dest.getOutputStreem(); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } dest.flushWorkingCopy(); } finally { if (in != null) in.close(); if (out != null) out.close(); } }
@Override public boolean isDirectory() { // TODO Auto-generated method stub return original.isDirectory(); }
@Override public boolean mkdir() { // TODO Auto-generated method stub return original.mkdir(); }
@Override public String getPath() { return original.getPath(); }
@Override public URI getURI() throws URISyntaxException { // TODO Auto-generated method stub return original.getURI(); }
@Override public IVResource getParent() { return original.getParent(); }
@Override public IVResource[] getParents() { // TODO Auto-generated method stub return original.getParents(); }
@Override public IVResource get(String childName) { return original.get(childName); }
@Override public IVResource create(String path) { // TODO Auto-generated method stub return original.create(path); }
@Override public IVResource[] find(String path) { // TODO Auto-generated method stub return original.find(path); }
@Override public void removeWorkingCopy() { original.removeWorkingCopy(); }
@Override public boolean exists() { // TODO Auto-generated method stub return original.exists(); }
@Override public boolean delete() { // TODO Auto-generated method stub return original.delete(); }
@Override public void createNewInstance() throws IOException { original.createNewInstance(); }
@Override public IVResource[] listFiles() { // TODO Auto-generated method stub return original.listFiles(); }
@Override public String getName() { return original.getName(); }
@Override public void flushWorkingCopy() { original.flushWorkingCopy(); }
@Override public void add(IVResource v) { original.add(v); }