01: /*
02: * This program is free software; you can redistribute it and/or modify
03: * it under the terms of the GNU General Public License as published by
04: * the Free Software Foundation; either version 2 of the License, or
05: * (at your option) any later version.
06: *
07: * This program is distributed in the hope that it will be useful,
08: * but WITHOUT ANY WARRANTY; without even the implied warranty of
09: * 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;
19: import java.security.MessageDigest;
20: import java.security.NoSuchAlgorithmException;
21:
22: import dlog4j.util.StringUtils;
23:
24: /**
25: * 摘要信息
26: * @author Winter Lau
27: */
28: public class Item implements Serializable {
29:
30: protected String title;
31: protected String link;
32: protected String description;
33:
34: public Item() {
35: }
36:
37: public String getDescription() {
38: return description;
39: }
40:
41: public void setDescription(String description) {
42: this .description = description;
43: }
44:
45: public String getLink() {
46: return link;
47: }
48:
49: public void setLink(String link) {
50: this .link = link;
51: }
52:
53: public String getTitle() {
54: return title;
55: }
56:
57: public void setTitle(String title) {
58: this .title = title;
59: }
60:
61: public String uuid() {
62: try {
63: MessageDigest md = MessageDigest.getInstance("SHA-1");
64: if (title != null)
65: md.update(title.getBytes());
66: if (link != null)
67: md.update(link.getBytes());
68: if (description != null)
69: md.update(description.getBytes());
70: byte[] bs = md.digest();
71: return StringUtils.byte2hex(bs);
72: } catch (NoSuchAlgorithmException e) {
73: }
74: return null;
75: }
76:
77: public int hashCode() {
78: return uuid().hashCode();
79: }
80:
81: public static void main(String[] args) {
82: Item itm = new Item();
83: itm.setTitle("Java自由人");
84: itm.setLink("http://www.javayou.com/main.jspe");
85: itm.setDescription("Java自由人 Bloging...");
86: System.out.println(itm.uuid());
87: }
88: }
|