KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > web > rss > Item


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

16 package web.rss;
17
18 import java.io.Serializable JavaDoc;
19 import java.security.MessageDigest JavaDoc;
20 import java.security.NoSuchAlgorithmException JavaDoc;
21
22 import dlog4j.util.StringUtils;
23
24 /**
25  * 摘要信息
26  * @author Winter Lau
27  */

28 public class Item implements Serializable JavaDoc {
29
30     protected String JavaDoc title;
31     protected String JavaDoc link;
32     protected String JavaDoc description;
33     
34     public Item() {
35     }
36
37     public String JavaDoc getDescription() {
38         return description;
39     }
40     public void setDescription(String JavaDoc description) {
41         this.description = description;
42     }
43     public String JavaDoc getLink() {
44         return link;
45     }
46     public void setLink(String JavaDoc link) {
47         this.link = link;
48     }
49     public String JavaDoc getTitle() {
50         return title;
51     }
52     public void setTitle(String JavaDoc title) {
53         this.title = title;
54     }
55     
56     public String JavaDoc uuid() {
57         try{
58             MessageDigest JavaDoc md = MessageDigest.getInstance("SHA-1");
59             if(title!=null)
60                 md.update(title.getBytes());
61             if(link!=null)
62                 md.update(link.getBytes());
63             if(description!=null)
64                 md.update(description.getBytes());
65             byte[] bs = md.digest();
66             return StringUtils.byte2hex(bs);
67         }catch(NoSuchAlgorithmException JavaDoc e){}
68         return null;
69     }
70     
71     public int hashCode() {
72         return uuid().hashCode();
73     }
74     
75     public static void main(String JavaDoc[] args){
76         Item itm = new Item();
77         itm.setTitle("Java自由人");
78         itm.setLink("http://www.javayou.com/main.jspe");
79         itm.setDescription("Java自由人 Bloging...");
80         System.out.println(itm.uuid());
81     }
82 }
83
Popular Tags