1 2 3 4 package net.nutch.searcher; 5 6 import java.util.ArrayList ; 7 import net.nutch.html.Entities; 8 9 10 public class Summary { 11 12 13 public static class Fragment { 14 private String text; 15 16 17 public Fragment(String text) { this.text = text; } 18 19 20 public String getText() { return text; } 21 22 23 public boolean isHighlight() { return false; } 24 25 26 public boolean isEllipsis() { return false; } 27 28 29 public String toString() { return Entities.encode(text); } 30 } 31 32 33 public static class Highlight extends Fragment { 34 35 public Highlight(String text) { super(text); } 36 37 38 public boolean isHighlight() { return true; } 39 40 41 public String toString() { return "<b>" + super.toString() + "</b>"; } 42 } 43 44 45 public static class Ellipsis extends Fragment { 46 47 public Ellipsis() { super(" ... "); } 48 49 50 public boolean isEllipsis() { return true; } 51 52 53 public String toString() { return "<b> ... </b>"; } 54 } 55 56 private ArrayList fragments = new ArrayList (); 57 58 private static final Fragment[] FRAGMENT_PROTO = new Fragment[0]; 59 60 61 public Summary() {} 62 63 64 public void add(Fragment fragment) { fragments.add(fragment); } 65 66 67 public Fragment[] getFragments() { 68 return (Fragment[])fragments.toArray(FRAGMENT_PROTO); 69 } 70 71 72 public String toString() { 73 StringBuffer buffer = new StringBuffer (); 74 for (int i = 0; i < fragments.size(); i++) { 75 buffer.append(fragments.get(i)); 76 } 77 return buffer.toString(); 78 } 79 } 80 | Popular Tags |