KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > armedbear > j > RecentFilesEntry


1 /*
2  * RecentFilesEntry.java
3  *
4  * Copyright (C) 1998-2002 Peter Graves
5  * $Id: RecentFilesEntry.java,v 1.1.1.1 2002/09/24 16:08:34 piso Exp $
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */

21
22 package org.armedbear.j;
23
24 import java.util.StringTokenizer JavaDoc;
25
26 public final class RecentFilesEntry
27 {
28     private static boolean ignoreCase = Platform.isPlatformWindows();
29
30     String JavaDoc name;
31     String JavaDoc 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 JavaDoc s)
65     {
66         StringTokenizer JavaDoc st = new StringTokenizer JavaDoc(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         // Local file.
91
return ignoreCase ? location.equalsIgnoreCase(file.getParent()) : location.equals(file.getParent());
92     }
93
94     public boolean equals(Object JavaDoc 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 JavaDoc 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