PageRenderTime 543ms CodeModel.GetById 531ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

/bundles/plugins-trunk/JavaInsight/javainsight/VFSLocation.java

#
Java | 125 lines | 86 code | 18 blank | 21 comment | 17 complexity | 7ff991a6a7dcf912f3870bf4e277eefa MD5 | raw file
  1/*
  2 * VFSLocation.java
  3 * Copyright (c) 2007 Dirk Moebius
  4 *
  5 * jEdit edit mode settings:
  6 * :mode=java:tabSize=4:indentSize=4:noTabs=true:maxLineLen=0:
  7 *
  8 * This program is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU General Public License
 10 * as published by the Free Software Foundation; either version 2
 11 * of the License, or any later version.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU General Public License
 19 * along with this program; if not, write to the Free Software
 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 21*/
 22
 23package javainsight;
 24
 25
 26import java.io.IOException;
 27import java.io.InputStream;
 28import java.util.Enumeration;
 29import java.util.Vector;
 30
 31import net.sf.jode.bytecode.ClassPath;
 32
 33import org.gjt.sp.jedit.io.VFS;
 34import org.gjt.sp.jedit.io.VFSFile;
 35import org.gjt.sp.jedit.io.VFSManager;
 36
 37
 38public class VFSLocation extends ClassPath.Location
 39{
 40    private String vfsPath;
 41
 42
 43    public VFSLocation(String vfsPath) {
 44        this.vfsPath = vfsPath;
 45    }
 46
 47
 48    @Override
 49    public boolean exists(String file) {
 50        VFS vfs = VFSManager.getVFSForPath(vfsPath);
 51        if (vfs == null) {
 52            return false;
 53        }
 54        String path = vfs.constructPath(vfsPath, file);
 55        VFSFile entry = null;
 56        try {
 57            entry = vfs._getFile(null, path, null);
 58            return entry != null;
 59        } catch (IOException ioe) {
 60            return false;
 61        }
 62    }
 63
 64
 65    @Override
 66    public InputStream getFile(String file) throws IOException {
 67        if (exists(file)) {
 68            VFS vfs = VFSManager.getVFSForPath(vfsPath);
 69            if (vfs == null) { 
 70                return null;
 71            }
 72            String path = vfs.constructPath(vfsPath, file);
 73            return vfs._createInputStream(null, path, true, null);
 74        }
 75        return null;
 76    }
 77
 78
 79    @Override
 80    public boolean isDirectory(String file) {
 81        VFS vfs = VFSManager.getVFSForPath(vfsPath);
 82        if (vfs == null) {
 83            return false;
 84        }
 85        String path = vfs.constructPath(vfsPath, file);
 86        VFSFile entry = null;
 87        try {
 88            entry = vfs._getFile(null, path, null);
 89            return entry != null && entry.getType() == VFSFile.DIRECTORY;
 90        } catch (IOException ioe) {
 91            return false;
 92        }
 93    }
 94
 95
 96    @Override
 97    public Enumeration listFiles(final String directory) {
 98        if (!isDirectory(directory)) {
 99            return null;
100        }
101        VFS vfs = VFSManager.getVFSForPath(vfsPath);
102        if (vfs == null) { 
103            return null; 
104        }
105        VFSFile[] entries = null;
106        try {
107            entries = vfs._listFiles(null, directory, null);
108        } catch (IOException ioe) {
109            return null;
110        }
111        if (entries != null) {
112            Vector<String> files = new Vector<String>(entries.length);
113            for (int i = 0; i < entries.length; i++) {
114                files.addElement(entries[i].getPath());
115            }
116            return files.elements();
117        }
118        return null;
119    }
120    
121    @Override
122    public String toString() {
123        return vfsPath;
124    }
125}