1 21 22 package org.armedbear.j; 23 24 import java.util.StringTokenizer ; 25 26 public final class RecentFilesEntry 27 { 28 private static boolean ignoreCase = Platform.isPlatformWindows(); 29 30 String name; 31 String location; 32 long firstVisit; 33 long lastVisit; 34 int lineNumber; 35 int offs; 36 37 public RecentFilesEntry(File file) 38 { 39 name = file.getName(); 40 if (file.isRemote()) { 41 if (file.getProtocol() == File.PROTOCOL_HTTP) { 42 location = File.PREFIX_HTTP + file.getHostName(); 43 if (file.getParent() != null) 44 location += file.getParent(); 45 } else if (file.getProtocol() == File.PROTOCOL_HTTPS) { 46 location = File.PREFIX_HTTPS + file.getHostName(); 47 if (file.getParent() != null) 48 location += file.getParent(); 49 } else if (file.getProtocol() == File.PROTOCOL_FTP) { 50 location = File.PREFIX_FTP + file.getHostName() + file.getParent(); 51 } else if (file.getProtocol() == File.PROTOCOL_SSH) { 52 File parent = file.getParentFile(); 53 if (parent != null) 54 location = parent.netPath(); 55 else { 56 name = ""; 57 location = file.netPath(); 58 } 59 } 60 } else 61 location = file.getParent(); 62 } 63 64 public RecentFilesEntry(String s) 65 { 66 StringTokenizer st = new StringTokenizer (s, "\t"); 67 name = st.nextToken(); 68 location = st.nextToken(); 69 firstVisit = Long.parseLong(st.nextToken()); 70 lastVisit = Long.parseLong(st.nextToken()); 71 lineNumber = Integer.parseInt(st.nextToken()); 72 offs = Integer.parseInt(st.nextToken()); 73 if (name.equals("\"\"")) 74 name = ""; 75 } 76 77 public boolean matches(File file) 78 { 79 if (!name.equals(file.getName())) 80 return false; 81 if (location.startsWith(File.PREFIX_FTP) || 82 location.startsWith(File.PREFIX_HTTP) || 83 location.startsWith(File.PREFIX_HTTPS) || 84 location.startsWith(File.PREFIX_SSH)) { 85 File parent = File.getInstance(location); 86 return file.equals(File.getInstance(parent, name)); 87 } 88 if (file.isRemote()) 89 return false; 90 return ignoreCase ? location.equalsIgnoreCase(file.getParent()) : location.equals(file.getParent()); 92 } 93 94 public boolean equals(Object obj) 95 { 96 if (!(obj instanceof RecentFilesEntry)) 97 return false; 98 RecentFilesEntry entry = (RecentFilesEntry) obj; 99 if (ignoreCase) { 100 if (entry.name.equalsIgnoreCase(name)) 101 if (entry.location.equalsIgnoreCase(location)) 102 return true; 103 } else { 104 if (entry.name.equals(name)) 105 if (entry.location.equals(location)) 106 return true; 107 } 108 return false; 109 } 110 111 public String toString() 112 { 113 FastStringBuffer sb = new FastStringBuffer(name); 114 if (sb.length() == 0) 115 sb.append("\"\""); 116 sb.append('\t'); 117 sb.append(location); 118 sb.append('\t'); 119 sb.append(String.valueOf(firstVisit)); 120 sb.append('\t'); 121 sb.append(String.valueOf(lastVisit)); 122 sb.append('\t'); 123 sb.append(String.valueOf(lineNumber)); 124 sb.append('\t'); 125 sb.append(String.valueOf(offs)); 126 return sb.toString(); 127 } 128 129 public static final int getVersion() 130 { 131 return 1; 132 } 133 } 134 | Popular Tags |