001: /*
002: * RecentFilesEntry.java
003: *
004: * Copyright (C) 1998-2002 Peter Graves
005: * $Id: RecentFilesEntry.java,v 1.1.1.1 2002/09/24 16:08:34 piso Exp $
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: */
021:
022: package org.armedbear.j;
023:
024: import java.util.StringTokenizer;
025:
026: public final class RecentFilesEntry {
027: private static boolean ignoreCase = Platform.isPlatformWindows();
028:
029: String name;
030: String location;
031: long firstVisit;
032: long lastVisit;
033: int lineNumber;
034: int offs;
035:
036: public RecentFilesEntry(File file) {
037: name = file.getName();
038: if (file.isRemote()) {
039: if (file.getProtocol() == File.PROTOCOL_HTTP) {
040: location = File.PREFIX_HTTP + file.getHostName();
041: if (file.getParent() != null)
042: location += file.getParent();
043: } else if (file.getProtocol() == File.PROTOCOL_HTTPS) {
044: location = File.PREFIX_HTTPS + file.getHostName();
045: if (file.getParent() != null)
046: location += file.getParent();
047: } else if (file.getProtocol() == File.PROTOCOL_FTP) {
048: location = File.PREFIX_FTP + file.getHostName()
049: + file.getParent();
050: } else if (file.getProtocol() == File.PROTOCOL_SSH) {
051: File parent = file.getParentFile();
052: if (parent != null)
053: location = parent.netPath();
054: else {
055: name = "";
056: location = file.netPath();
057: }
058: }
059: } else
060: location = file.getParent();
061: }
062:
063: public RecentFilesEntry(String s) {
064: StringTokenizer st = new StringTokenizer(s, "\t");
065: name = st.nextToken();
066: location = st.nextToken();
067: firstVisit = Long.parseLong(st.nextToken());
068: lastVisit = Long.parseLong(st.nextToken());
069: lineNumber = Integer.parseInt(st.nextToken());
070: offs = Integer.parseInt(st.nextToken());
071: if (name.equals("\"\""))
072: name = "";
073: }
074:
075: public boolean matches(File file) {
076: if (!name.equals(file.getName()))
077: return false;
078: if (location.startsWith(File.PREFIX_FTP)
079: || location.startsWith(File.PREFIX_HTTP)
080: || location.startsWith(File.PREFIX_HTTPS)
081: || location.startsWith(File.PREFIX_SSH)) {
082: File parent = File.getInstance(location);
083: return file.equals(File.getInstance(parent, name));
084: }
085: if (file.isRemote())
086: return false;
087: // Local file.
088: return ignoreCase ? location.equalsIgnoreCase(file.getParent())
089: : location.equals(file.getParent());
090: }
091:
092: public boolean equals(Object obj) {
093: if (!(obj instanceof RecentFilesEntry))
094: return false;
095: RecentFilesEntry entry = (RecentFilesEntry) obj;
096: if (ignoreCase) {
097: if (entry.name.equalsIgnoreCase(name))
098: if (entry.location.equalsIgnoreCase(location))
099: return true;
100: } else {
101: if (entry.name.equals(name))
102: if (entry.location.equals(location))
103: return true;
104: }
105: return false;
106: }
107:
108: public String toString() {
109: FastStringBuffer sb = new FastStringBuffer(name);
110: if (sb.length() == 0)
111: sb.append("\"\"");
112: sb.append('\t');
113: sb.append(location);
114: sb.append('\t');
115: sb.append(String.valueOf(firstVisit));
116: sb.append('\t');
117: sb.append(String.valueOf(lastVisit));
118: sb.append('\t');
119: sb.append(String.valueOf(lineNumber));
120: sb.append('\t');
121: sb.append(String.valueOf(offs));
122: return sb.toString();
123: }
124:
125: public static final int getVersion() {
126: return 1;
127: }
128: }
|