1 37 package net.sourceforge.cruisecontrol.publishers.rss; 38 39 import java.text.ParseException ; 40 import java.text.SimpleDateFormat ; 41 42 import java.util.Date ; 43 44 import org.jdom.Element; 45 46 53 public class Item implements Comparable { 54 55 private String title; 56 private String link; 57 private String description; 58 private Date publishDate; 59 private final SimpleDateFormat rssDateFormatter = new SimpleDateFormat (RSS.DATE_FORMAT); 60 61 public Item() { 62 } 63 64 67 public Item(Element itemNode) { 68 if (itemNode.getChild(RSS.NODE_ITEM_TITLE) != null) { 69 this.title = itemNode.getChild(RSS.NODE_ITEM_TITLE).getText(); 70 } 71 if (itemNode.getChild(RSS.NODE_ITEM_LINK) != null) { 72 this.link = itemNode.getChild(RSS.NODE_ITEM_LINK).getText(); 73 } 74 if (itemNode.getChild(RSS.NODE_ITEM_DESCRIPTION) != null) { 75 this.description = itemNode.getChild(RSS.NODE_ITEM_DESCRIPTION).getText(); 76 } 77 if (itemNode.getChild(RSS.NODE_ITEM_PUBLISH_DATE) != null) { 78 try { 79 this.publishDate = rssDateFormatter.parse(itemNode.getChild(RSS.NODE_ITEM_PUBLISH_DATE).getText()); 80 } catch (ParseException pex) { 81 this.publishDate = new Date (0); 83 } 84 } 85 } 86 87 public int compareTo(Object o) { 88 Item other = (Item) o; 89 return other.getPublishDate().compareTo(this.getPublishDate()); 90 } 91 92 public String getTitle() { 93 return this.title; 94 } 95 public void setTitle(String title) { 96 this.title = title; 97 } 98 public String getDescription() { 99 return this.description; 100 } 101 public void setDescription(String description) { 102 this.description = description; 103 } 104 public String getLink() { 105 return this.link; 106 } 107 public void setLink(String link) { 108 this.link = link; 109 } 110 public Date getPublishDate() { 111 return this.publishDate; 112 } 113 public void setPublishDate(Date publishDate) { 114 this.publishDate = publishDate; 115 } 116 117 public String toXml() { 118 StringBuffer output = new StringBuffer (); 119 120 output.append(" <"); 121 output.append(RSS.NODE_ITEM); 122 output.append(">\n"); 123 124 output.append(" <"); 126 output.append(RSS.NODE_ITEM_TITLE); 127 output.append(">"); 128 if (this.getTitle() != null) { 129 output.append(this.getTitle()); 130 } 131 output.append("</"); 132 output.append(RSS.NODE_ITEM_TITLE); 133 output.append(">\n"); 134 135 output.append(" <"); 137 output.append(RSS.NODE_ITEM_LINK); 138 output.append(">"); 139 if (this.getLink() != null) { 140 output.append(this.getLink()); 141 } 142 output.append("</"); 143 output.append(RSS.NODE_ITEM_LINK); 144 output.append(">\n"); 145 146 147 output.append(" <"); 149 output.append(RSS.NODE_ITEM_DESCRIPTION); 150 output.append("><![CDATA["); 151 if (this.getDescription() != null) { 152 output.append(this.getDescription()); 153 } 154 output.append("]]></"); 155 output.append(RSS.NODE_ITEM_DESCRIPTION); 156 output.append(">\n"); 157 158 if (this.getPublishDate() != null) { 160 output.append(" <"); 161 output.append(RSS.NODE_ITEM_PUBLISH_DATE); 162 output.append(">"); 163 output.append(rssDateFormatter.format(this.getPublishDate())); 164 output.append("</"); 165 output.append(RSS.NODE_ITEM_PUBLISH_DATE); 166 output.append(">\n"); 167 } 168 169 170 output.append(" <"); 172 output.append(RSS.NODE_ITEM_GUID); 173 output.append(" "); 174 output.append(RSS.ATTRIB_ITEM_IS_PERMA_LINK); 175 output.append("=\"true\">"); 176 if (this.getLink() != null) { 177 output.append(this.getLink()); 178 } 179 output.append("</"); 180 output.append(RSS.NODE_ITEM_GUID); 181 output.append(">\n"); 182 183 output.append(" </"); 184 output.append(RSS.NODE_ITEM); 185 output.append(">\n"); 186 187 return output.toString(); 188 } 189 } | Popular Tags |