/* SearchResult.java - October 1999 - Scott Parent (except where otherwise noted) */ import java.io.*; import java.net.*; import java.util.*; import java.text.SimpleDateFormat; /** * @com.register ( clsid=3BC0D8B2-8981-11D3-91AE-004095013729, typelib=3BC0D8AB-8981-11D3-91AE-004095013729 ) */ public class SearchResult implements java.io.Serializable { private URL m_url = null; private String m_title = null; private int m_rank = 0; private String m_description = null; private Date m_lastModified = null; private int m_estimatedSize = -1; InetAddress m_cachedHostIP = null; private String m_dateFormatString = "MMddyyyy"; public SearchResult(){} public SearchResult( String urlString, String aTitle, int aRank, String aDescription, Date modDate, int estSize) throws MalformedURLException { setURLString( urlString); m_title = aTitle; m_rank = aRank; m_description = aDescription; m_lastModified = modDate; m_estimatedSize = estSize; try { getHostIP(); // cache host IP } catch( UnknownHostException x){}; } public SearchResult( SearchResult source) { setURL( source.getURL()); m_title = source.getTitle(); m_rank = source.getRank(); m_description = source.getDescription(); m_lastModified = source.getLastModifiedDate(); m_estimatedSize = source.getEstimatedSize(); } public SearchResult(String s) // takes tab-delimited string throws MalformedURLException, java.text.ParseException { /* Deserializer - 10/29/99 - Tom Yoo str[0] = URL str[1] = Title str[2] = Rank str[3] = Description str[4] = LastModified str[5] = PageSize */ StringTokenizer m = new StringTokenizer( s, "\t"); SimpleDateFormat f = new SimpleDateFormat( m_dateFormatString); setURLString( m.nextToken()); m_title = m.nextToken(); m_rank = Integer.parseInt( m.nextToken()); m_description = m.nextToken(); String dateString = m.nextToken(); m_lastModified = f.parse( dateString); m_estimatedSize = Integer.parseInt( m.nextToken()); } public URL getURL(){ return m_url;} public void setURL( URL newURL){ m_url = newURL;} public String getURLString(){ return m_url.toString();} public void setURLString( String newString) throws MalformedURLException { m_url = new URL( newString); } public String getTitle(){ return m_title;} public int getRank() { return m_rank;} public String getDescription(){ return m_description;} public Date getLastModifiedDate(){ return m_lastModified;} public int getEstimatedSize() { return m_estimatedSize;} public long getAge() { long aDay = 60 * 60 * 24; Date today = new Date(); return (m_lastModified.getTime() - today.getTime()) / aDay; } public String getHostName(){ return m_url.getHost(); } public byte[] getHostIP() throws UnknownHostException { if( m_cachedHostIP == null) { m_cachedHostIP = InetAddress.getByName( getHostName()); } return m_cachedHostIP.getAddress(); } /* Tab-delimited serialization format: \t\t<Rank>\t<Description>\t<LastModified (as mmddyyyy)>\tPageSize */ public String toString() { SimpleDateFormat f = new SimpleDateFormat( m_dateFormatString); String returnValue; returnValue = getURL() + "\t" + m_title + "\t" + m_rank + "\t" + m_description + "\t" + f.format( m_lastModified) + "\t" + Integer.toString( m_estimatedSize); return returnValue; } }