KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > nutch > parse > Outlink


1 /* Copyright (c) 2003 The Nutch Organization. All rights reserved. */
2 /* Use subject to the conditions in http://www.nutch.org/LICENSE.txt. */
3
4 package net.nutch.parse;
5
6 import java.io.*;
7 import java.net.MalformedURLException JavaDoc;
8
9 import net.nutch.io.*;
10 import net.nutch.net.UrlNormalizerFactory;
11
12 /* An outgoing link from a page. */
13 public class Outlink implements Writable {
14
15   private String JavaDoc toUrl;
16   private String JavaDoc anchor;
17
18   public Outlink() {}
19
20   public Outlink(String JavaDoc toUrl, String JavaDoc anchor) throws MalformedURLException JavaDoc {
21     this.toUrl = UrlNormalizerFactory.getNormalizer().normalize(toUrl);
22     this.anchor = anchor;
23   }
24
25   public void readFields(DataInput in) throws IOException {
26     toUrl = UTF8.readString(in);
27     anchor = UTF8.readString(in);
28   }
29
30   /** Skips over one Outlink in the input. */
31   public static void skip(DataInput in) throws IOException {
32     UTF8.skip(in); // skip toUrl
33
UTF8.skip(in); // skip anchor
34
}
35
36   public void write(DataOutput out) throws IOException {
37     UTF8.writeString(out, toUrl);
38     UTF8.writeString(out, anchor);
39   }
40
41   public static Outlink read(DataInput in) throws IOException {
42     Outlink outlink = new Outlink();
43     outlink.readFields(in);
44     return outlink;
45   }
46
47   public String JavaDoc getToUrl() { return toUrl; }
48   public String JavaDoc getAnchor() { return anchor; }
49
50
51   public boolean equals(Object JavaDoc o) {
52     if (!(o instanceof Outlink))
53       return false;
54     Outlink other = (Outlink)o;
55     return
56       this.toUrl.equals(other.toUrl) &&
57       this.anchor.equals(other.anchor);
58   }
59
60   public String JavaDoc toString() {
61     return "toUrl: " + toUrl + " anchor: " + anchor; // removed "\n". toString, not printLine... WD.
62
}
63
64 }
65
Popular Tags