Changeset 4364 for trunk/gli/src/org/greenstone/gatherer/util/GURL.java
- Timestamp:
- 2003-05-27T15:40:47+12:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gli/src/org/greenstone/gatherer/util/GURL.java
r4293 r4364 60 60 */ 61 61 public class GURL 62 62 implements Cloneable, Serializable { 63 63 64 64 private Integer type; 65 65 66 66 private URL url; 67 67 68 69 70 71 72 68 private String file; 69 private String host; 70 private String path; 71 private String protocol; 72 private String title = "empty"; 73 73 74 75 76 77 78 79 80 81 82 83 74 /** This Vector maintains a record of the url links from within 75 * this resource, and their type (EXTERNAL vs INTERNAL). Internal 76 * links can be 'hidden' from the user if desired, or a user can 77 * opt to have all internal links automatically moved into a 78 * collection if the page that depends upon them is moved. <BR> 79 * Each entry in the vector is of the form. 80 * links[i] = String url 81 * links[i+1] = int type 82 */ 83 private Vector links; 84 84 85 86 87 85 /* Static Integer identifiers for ease of use. */ 86 static public Integer INTERNAL = new Integer(0); 87 static public Integer EXTERNAL = new Integer(1); 88 88 89 90 91 89 public GURL(String url_str) { 90 this(url_str, GURL.EXTERNAL); 91 } 92 92 93 94 95 93 public GURL(URL url) { 94 this(url, GURL.EXTERNAL); 95 } 96 96 97 98 99 100 97 public GURL(URL url, Integer type) { 98 this.type = type; 99 this.url = url; 100 } 101 101 102 103 102 public GURL(String url_str, Integer type) { 103 this.type = type; 104 104 105 106 107 108 109 110 111 105 try { 106 if(!url_str.startsWith("file:") && url_str.indexOf("://") == -1) { 107 url_str = "http://" + url_str; 108 } 109 url = new URL(url_str); 110 } 111 catch (MalformedURLException e) { 112 112 // Fix it 113 114 113 } 114 } 115 115 116 117 118 116 public void addLink(String url) { 117 addLink(url, GURL.EXTERNAL); 118 } 119 119 120 121 122 123 124 125 126 120 public void addLink(String url, Integer type) { 121 if(links == null) { 122 links = new Vector(); 123 } 124 links.add(url); 125 links.add(type); 126 } 127 127 128 129 130 131 132 133 128 /** Used by tree renderer to display name. So we'll only return the 129 * filename. 130 */ 131 public String getFile() { 132 return parseFile(url.getFile()); 133 } 134 134 135 136 137 135 public String getHost() { 136 return url.getHost(); 137 } 138 138 139 140 141 142 143 144 145 146 139 public String getLocalFile() { 140 String local_file = getPath() + File.separator + getFile(); 141 // Strip msdos roots if they're still there. 142 while(local_file.indexOf(":") != -1) { 143 local_file = local_file.substring(0, local_file.indexOf(":")) + local_file.substring(local_file.indexOf(":") + 1); 144 } 145 return local_file; 146 } 147 147 148 149 150 148 public String getPath() { 149 return getHost() + parsePath(url.getFile()); 150 } 151 151 152 153 154 155 156 157 158 152 public String getProtocol() { 153 String protocol = url.getProtocol(); 154 if(protocol.equals("file")) { 155 return protocol + ":"; 156 } 157 return protocol + "://"; 158 } 159 159 160 161 162 160 public URL getURL() { 161 return url; 162 } 163 163 164 165 166 164 public String toString() { 165 return url.toString(); 166 } 167 167 168 169 170 168 public boolean valid() { 169 return (url != null); 170 } 171 171 172 173 172 private String parseFile(String raw) { 173 if(raw != null && !raw.equals("")) { 174 174 // Remove everything upto and including the last '/' 175 176 177 178 179 180 175 if(raw.indexOf("/") != -1) { 176 return raw.substring(raw.lastIndexOf("/") + 1); 177 } 178 } 179 return raw; 180 } 181 181 182 183 182 private String parsePath(String raw) { 183 if(raw != null && !raw.equals("")) { 184 184 // Remove everything after the last "/" 185 186 187 188 189 190 185 if(raw.indexOf("/") != -1) { 186 return raw.substring(0, raw.lastIndexOf("/")); 187 } 188 } 189 return raw; 190 } 191 191 192 192 } 193
Note:
See TracChangeset
for help on using the changeset viewer.