PageRenderTime 35ms CodeModel.GetById 11ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. package javainsight;
  23. import java.io.IOException;
  24. import java.io.InputStream;
  25. import java.util.Enumeration;
  26. import java.util.Vector;
  27. import net.sf.jode.bytecode.ClassPath;
  28. import org.gjt.sp.jedit.io.VFS;
  29. import org.gjt.sp.jedit.io.VFSFile;
  30. import org.gjt.sp.jedit.io.VFSManager;
  31. public class VFSLocation extends ClassPath.Location
  32. {
  33. private String vfsPath;
  34. public VFSLocation(String vfsPath) {
  35. this.vfsPath = vfsPath;
  36. }
  37. @Override
  38. public boolean exists(String file) {
  39. VFS vfs = VFSManager.getVFSForPath(vfsPath);
  40. if (vfs == null) {
  41. return false;
  42. }
  43. String path = vfs.constructPath(vfsPath, file);
  44. VFSFile entry = null;
  45. try {
  46. entry = vfs._getFile(null, path, null);
  47. return entry != null;
  48. } catch (IOException ioe) {
  49. return false;
  50. }
  51. }
  52. @Override
  53. public InputStream getFile(String file) throws IOException {
  54. if (exists(file)) {
  55. VFS vfs = VFSManager.getVFSForPath(vfsPath);
  56. if (vfs == null) {
  57. return null;
  58. }
  59. String path = vfs.constructPath(vfsPath, file);
  60. return vfs._createInputStream(null, path, true, null);
  61. }
  62. return null;
  63. }
  64. @Override
  65. public boolean isDirectory(String file) {
  66. VFS vfs = VFSManager.getVFSForPath(vfsPath);
  67. if (vfs == null) {
  68. return false;
  69. }
  70. String path = vfs.constructPath(vfsPath, file);
  71. VFSFile entry = null;
  72. try {
  73. entry = vfs._getFile(null, path, null);
  74. return entry != null && entry.getType() == VFSFile.DIRECTORY;
  75. } catch (IOException ioe) {
  76. return false;
  77. }
  78. }
  79. @Override
  80. public Enumeration listFiles(final String directory) {
  81. if (!isDirectory(directory)) {
  82. return null;
  83. }
  84. VFS vfs = VFSManager.getVFSForPath(vfsPath);
  85. if (vfs == null) {
  86. return null;
  87. }
  88. VFSFile[] entries = null;
  89. try {
  90. entries = vfs._listFiles(null, directory, null);
  91. } catch (IOException ioe) {
  92. return null;
  93. }
  94. if (entries != null) {
  95. Vector<String> files = new Vector<String>(entries.length);
  96. for (int i = 0; i < entries.length; i++) {
  97. files.addElement(entries[i].getPath());
  98. }
  99. return files.elements();
  100. }
  101. return null;
  102. }
  103. @Override
  104. public String toString() {
  105. return vfsPath;
  106. }
  107. }