1 6 7 package org.contineo.documan; 8 9 import java.text.BreakIterator ; 10 import java.util.Collection ; 11 import java.util.Iterator ; 12 13 import org.apache.ojb.broker.util.collections.RemovalAwareCollection; 14 15 20 public class Keywords { 21 22 25 private int docId; 26 27 30 private String keyword; 31 32 33 34 public Keywords() { 35 docId = 0; 36 keyword = ""; 37 } 38 39 43 public int getDocId() { 44 return docId; 45 } 46 47 51 public String getKeyword() { 52 return keyword; 53 } 54 55 59 public void setDocId(int id) { 60 docId = id; 61 } 62 63 67 public void setKeyword(String word) { 68 keyword = word; 69 } 70 71 72 public Collection toKeywords(String words) { 73 Collection coll = new RemovalAwareCollection(); 74 BreakIterator boundary = BreakIterator.getWordInstance(); 75 boundary.setText(words); 76 int start = boundary.first(); 77 for (int end = boundary.next();end != BreakIterator.DONE;start = end, end = boundary.next()) { 78 String word = words.substring(start,end).toLowerCase().trim(); 79 if (word.length() > 2) { 80 Keywords key = new Keywords(); 81 key.setKeyword(word); 82 coll.add(key); 83 } 84 } 85 return coll; 86 } 87 88 public String toString(Collection keywords) { 89 StringBuffer sb = new StringBuffer (); 90 Iterator iter = keywords.iterator(); 91 boolean start = true; 92 while (iter.hasNext()) { 93 Keywords words = (Keywords)iter.next(); 94 if (!start) 95 sb.append(", "); 96 else 97 start = false; 98 sb.append(words.keyword); 99 } 100 return sb.toString(); 101 } 102 } 103
| Popular Tags
|