package net.sourceforge.phpeclipse.news; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Locale; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableItem; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.w3c.dom.Text; /** * @author jnegre - http://www.jnegre.org/ * * (c)Copyright 2002 J�r�me N�gre * */ public class Item { protected static DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT); protected static SimpleDateFormat pubDateParser = new SimpleDateFormat("EEE, d MMM yy hh:mm:ss z", new Locale("en","US")); protected Channel channel; protected String title; protected String link; protected String description; protected String author; protected String guid; protected boolean isPermaLink = true; protected String date; protected boolean readFlag = false; /** * Constructor for Item. */ public Item(Channel channel, Element itemElement) { this.channel = channel; this.title = readValue("title", itemElement, 0); this.link = readValue("link", itemElement, 0); String simpleDescription = readValue("description", itemElement, 0); String contentEncoded = readValue("content:encoded", itemElement, 0); this.description = contentEncoded!=null?contentEncoded:simpleDescription; this.author = readValue("author", itemElement, 0); this.guid = readValue("guid", itemElement, 1); String pubDate = readValue("pubDate", itemElement, 0); String dcDate = readValue("dc:date", itemElement, 0); try { Date theDate; if(pubDate != null) { theDate = pubDateParser.parse(pubDate); } else if(dcDate != null) { theDate = decodeDCDate(dcDate); } else { theDate = new Date(); } this.date = dateFormat.format(theDate); } catch(Exception e) { if(pubDate != null) { this.date = pubDate; } else if(dcDate != null) { this.date = dcDate; } else { this.date = e.toString(); } Plugin.logInfo("Unable to parse date",e); } } protected String readValue(String elementName, Element parent, int type) { Element element = (Element)parent.getElementsByTagName(elementName).item(0); if(element != null) { switch(type) { case 1: if(element.hasAttribute("isPermaLink") && element.getAttribute("isPermaLink").equals("false")) { this.isPermaLink = false; } } NodeList children = element.getChildNodes(); StringBuffer buffer = new StringBuffer(); for(int i=0; i position && buffer.charAt(position) == expectedChar) { return true; } else { return false; } } /** * @return the description of this item */ public String getDescription() { return description; } /** * @return the author of this item */ public String getAuthor() { return author; } /** * Returns the date. * @return String */ public String getDate() { return date; } /** * Returns the readFlag. * @return boolean */ public boolean isReadFlag() { return readFlag; } /** * Returns the channel. * @return Channel */ public Channel getChannel() { return channel; } /** * Returns a unique ID used to remember which * items were read in the ChannelStore * @return */ public String getUID() { return getUsableLink() + ") ~ (" + getUsableTitle(); } }