Rome is now used to create and read the various feed.
This commit is contained in:
parent
2f11c58c62
commit
f8d0a80c2c
29 changed files with 789 additions and 1232 deletions
|
@ -66,7 +66,7 @@ public class CurrencyConverter implements Runnable
|
|||
/**
|
||||
* The exchange rates table URL.
|
||||
*/
|
||||
public static final String EXCHANGE_TABLE_URL = "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml";
|
||||
private static final String EXCHANGE_TABLE_URL = "http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml";
|
||||
|
||||
/**
|
||||
* The exchange rates.
|
||||
|
@ -119,7 +119,7 @@ public class CurrencyConverter implements Runnable
|
|||
}
|
||||
|
||||
// Converts specified currencies.
|
||||
public void run()
|
||||
public final void run()
|
||||
{
|
||||
if (EXCHANGE_RATES.isEmpty())
|
||||
{
|
||||
|
@ -150,12 +150,12 @@ public class CurrencyConverter implements Runnable
|
|||
catch (JDOMException e)
|
||||
{
|
||||
_bot.getLogger().debug("Unable to parse the exchange rates table.", e);
|
||||
_bot.sendNotice(_sender, "An error has occurred while parsing the exchange rates table.");
|
||||
_bot.send(_sender, "An error has occurred while parsing the exchange rates table.");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
_bot.getLogger().debug("Unable to fetch the exchange rates table.", e);
|
||||
_bot.sendNotice(_sender,
|
||||
_bot.send(_sender,
|
||||
"An error has occurred while fetching the exchange rates table: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -170,7 +170,7 @@ public class CurrencyConverter implements Runnable
|
|||
{
|
||||
if (cmds[3].equals(cmds[1]))
|
||||
{
|
||||
_bot.sendNotice(_sender, "You're kidding, right?");
|
||||
_bot.send(_sender, "You're kidding, right?");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -180,7 +180,7 @@ public class CurrencyConverter implements Runnable
|
|||
final double from = Double.parseDouble((String) EXCHANGE_RATES.get(cmds[1].toUpperCase()));
|
||||
final double to = Double.parseDouble((String) EXCHANGE_RATES.get(cmds[3].toUpperCase()));
|
||||
|
||||
_bot.sendNotice(_bot.getChannel(),
|
||||
_bot.send(_bot.getChannel(),
|
||||
NumberFormat.getCurrencyInstance(Locale.US).format(amt).substring(1) + ' ' +
|
||||
cmds[1].toUpperCase() + " = " +
|
||||
NumberFormat.getCurrencyInstance(Locale.US).format((amt * to) / from)
|
||||
|
@ -188,7 +188,7 @@ public class CurrencyConverter implements Runnable
|
|||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
_bot.sendNotice(_sender,
|
||||
_bot.send(_sender,
|
||||
"The supported currencies are: " + EXCHANGE_RATES.keySet().toString());
|
||||
}
|
||||
}
|
||||
|
@ -196,7 +196,7 @@ public class CurrencyConverter implements Runnable
|
|||
}
|
||||
else if (_query.equals(RATES_KEYWORD))
|
||||
{
|
||||
_bot.sendNotice(_sender, "Last Update: " + s_date);
|
||||
_bot.send(_sender, "Last Update: " + s_date);
|
||||
|
||||
final Iterator it = EXCHANGE_RATES.keySet().iterator();
|
||||
String rate;
|
||||
|
@ -213,19 +213,19 @@ public class CurrencyConverter implements Runnable
|
|||
buff.append(rate).append(": ").append(EXCHANGE_RATES.get(rate));
|
||||
}
|
||||
|
||||
_bot.sendNotice(_sender, buff.toString());
|
||||
_bot.send(_sender, buff.toString());
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
_bot.helpResponse(_sender, Mobibot.CURRENCY_CMD + ' ' + _query);
|
||||
_bot.sendNotice(_sender, "The supported currencies are: " + EXCHANGE_RATES.keySet().toString());
|
||||
_bot.send(_sender, "The supported currencies are: " + EXCHANGE_RATES.keySet().toString());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_bot.getLogger().debug("The exchange rate table is empty.");
|
||||
_bot.sendNotice(_sender, "Sorry, but the exchange rate table is empty.");
|
||||
_bot.send(_sender, "Sorry, but the exchange rate table is empty.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ public class EntryLink implements Serializable
|
|||
/**
|
||||
* The creation date.
|
||||
*/
|
||||
private final Date _date = Calendar.getInstance().getTime();
|
||||
private Date _date = Calendar.getInstance().getTime();
|
||||
|
||||
/**
|
||||
* The comments.
|
||||
|
@ -74,6 +74,7 @@ public class EntryLink implements Serializable
|
|||
private String _nick = "";
|
||||
private String _title = "No Title";
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new entry.
|
||||
*
|
||||
|
@ -88,6 +89,22 @@ public class EntryLink implements Serializable
|
|||
_login = login;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new entry.
|
||||
*
|
||||
* @param link The new entry's link.
|
||||
* @param title The new entry's title.
|
||||
* @param nick The nickname of the author of the link.
|
||||
* @param date The entry date.
|
||||
*/
|
||||
public EntryLink(String link, String title, String nick, Date date)
|
||||
{
|
||||
_link = link;
|
||||
_title = title;
|
||||
_nick = nick;
|
||||
_date = date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new entry.
|
||||
*
|
||||
|
|
|
@ -36,20 +36,15 @@
|
|||
*/
|
||||
package net.thauvin.erik.mobibot;
|
||||
|
||||
import org.crazybob.rss.Channel;
|
||||
import org.crazybob.rss.Item;
|
||||
import org.crazybob.rss.Parser;
|
||||
import org.crazybob.rss.UrlLoader;
|
||||
import org.crazybob.rss.UrlLoader.Response;
|
||||
import com.sun.syndication.feed.synd.SyndEntry;
|
||||
import com.sun.syndication.feed.synd.SyndEntryImpl;
|
||||
import com.sun.syndication.feed.synd.SyndFeed;
|
||||
import com.sun.syndication.fetcher.FeedFetcher;
|
||||
import com.sun.syndication.fetcher.impl.HttpURLFeedFetcher;
|
||||
|
||||
import org.jdom.JDOMException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.jdom.input.SAXBuilder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
@ -106,58 +101,32 @@ public class FeedReader implements Runnable
|
|||
/**
|
||||
* Fetches the Feed's items.
|
||||
*/
|
||||
public void run()
|
||||
public final void run()
|
||||
{
|
||||
List items = null;
|
||||
final FeedFetcher fetcher = new HttpURLFeedFetcher(_bot.getFeedInfoCache());
|
||||
|
||||
try
|
||||
{
|
||||
final Response response = new UrlLoader().load(_url, _bot.getFeedLastMod());
|
||||
final SyndFeed feed = fetcher.retrieveFeed(new URL(_url));
|
||||
SyndEntry item;
|
||||
final List items = feed.getEntries();
|
||||
|
||||
if (response != null)
|
||||
for (int i = 0; (i < items.size()) && (i < MAX_ITEMS); i++)
|
||||
{
|
||||
_bot.setFeedLastMod(response.getLastModified());
|
||||
|
||||
final Channel chan = new Parser().parse(new SAXBuilder().build(new StringReader(response.getBody())));
|
||||
items = chan.getItems();
|
||||
_bot.setFeedItems(items);
|
||||
item = (SyndEntryImpl) items.get(i);
|
||||
_bot.send(_sender, item.getTitle());
|
||||
_bot.send(_sender, TAB_INDENT + item.getLink());
|
||||
}
|
||||
}
|
||||
catch (JDOMException e)
|
||||
catch (MalformedURLException e)
|
||||
{
|
||||
_bot.getLogger().debug("Unable to parse the feed.", e);
|
||||
_bot.sendNotice(_sender, "An error has occurred while parsing the feed.");
|
||||
_bot.getLogger().debug("Invalid feed URL.", e);
|
||||
_bot.send(_sender, "The feed URL is invalid.");
|
||||
}
|
||||
catch (IOException e)
|
||||
catch (Exception e)
|
||||
{
|
||||
_bot.getLogger().debug("Unable to fetch the feed.", e);
|
||||
_bot.sendNotice(_sender, "An error has occurred while fetching the feed: " + e.getMessage());
|
||||
}
|
||||
|
||||
if (items == null)
|
||||
{
|
||||
items = _bot.getFeedItems();
|
||||
}
|
||||
|
||||
if ((items != null) && (!items.isEmpty()))
|
||||
{
|
||||
Item item;
|
||||
int i = 0;
|
||||
final Iterator it = items.iterator();
|
||||
|
||||
while (it.hasNext() && (i < MAX_ITEMS))
|
||||
{
|
||||
item = (Item) it.next();
|
||||
_bot.sendNotice(_sender, item.getTitle());
|
||||
_bot.sendNotice(_sender, TAB_INDENT + item.getLink());
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
if (_bot.getFeedLastMod().length() > 0)
|
||||
{
|
||||
_bot.sendNotice(_sender, "Last Updated: " + _bot.getFeedLastMod());
|
||||
}
|
||||
_bot.send(_sender, "An error has occurred while fetching the feed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ public class GoogleSearch implements Runnable
|
|||
/**
|
||||
* Main processing method.
|
||||
*/
|
||||
public void run()
|
||||
public final void run()
|
||||
{
|
||||
GOOGLE_BEAN.setKey(_key);
|
||||
|
||||
|
@ -127,17 +127,17 @@ public class GoogleSearch implements Runnable
|
|||
|
||||
if (Mobibot.isValidString(r))
|
||||
{
|
||||
_bot.sendNotice(_sender, Mobibot.unescapeXml(r));
|
||||
_bot.send(_sender, Mobibot.unescapeXml(r));
|
||||
}
|
||||
else
|
||||
{
|
||||
_bot.sendNotice(_sender, "You've just won our spelling bee contest.");
|
||||
_bot.send(_sender, "You've just won our spelling bee contest.");
|
||||
}
|
||||
}
|
||||
catch (GoogleSearchFault e)
|
||||
{
|
||||
_bot.getLogger().warn("Unable to spell: " + _query, e);
|
||||
_bot.sendNotice(_sender, "An error has occurred: " + e.getMessage());
|
||||
_bot.send(_sender, "An error has occurred: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -152,17 +152,17 @@ public class GoogleSearch implements Runnable
|
|||
{
|
||||
for (int i = 0; i < GOOGLE_BEAN.getResultElementsCount(); i++)
|
||||
{
|
||||
_bot.sendNotice(_sender,
|
||||
_bot.send(_sender,
|
||||
Mobibot.unescapeXml(GOOGLE_BEAN.getResultElementProperty(i, "title").replaceAll("<([bB]|/[bB])>",
|
||||
Colors.BOLD)));
|
||||
_bot.sendNotice(_sender, TAB_INDENT + GOOGLE_BEAN.getResultElementProperty(i, "url"));
|
||||
_bot.send(_sender, TAB_INDENT + GOOGLE_BEAN.getResultElementProperty(i, "url"));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (GoogleSearchFault e)
|
||||
{
|
||||
_bot.getLogger().warn("Unable to search in Google for: " + _query, e);
|
||||
_bot.sendNotice(_sender, "An error has occurred: " + e.getMessage());
|
||||
_bot.send(_sender, "An error has occurred: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
51
src/net/thauvin/erik/mobibot/ReleaseInfo.java
Normal file
51
src/net/thauvin/erik/mobibot/ReleaseInfo.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* Created by JReleaseInfo AntTask from Open Source Competence Group */
|
||||
/* Creation date Thu Sep 23 13:38:29 PDT 2004 */
|
||||
package net.thauvin.erik.mobibot;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* This class provides information gathered from the build environment.
|
||||
*
|
||||
* @author JReleaseInfo AntTask
|
||||
*/
|
||||
public class ReleaseInfo {
|
||||
|
||||
|
||||
/** buildDate (set during build process to 1095971909156L). */
|
||||
private static Date buildDate = new Date(1095971909156L);
|
||||
|
||||
/**
|
||||
* Get buildDate (set during build process to Thu Sep 23 13:38:29 PDT 2004).
|
||||
* @return Date buildDate
|
||||
*/
|
||||
public static final Date getBuildDate() { return buildDate; }
|
||||
|
||||
|
||||
/**
|
||||
* Get buildNumber (set during build process to 1).
|
||||
* @return int buildNumber
|
||||
*/
|
||||
public static final int getBuildNumber() { return 1; }
|
||||
|
||||
|
||||
/** version (set during build process to "0.2"). */
|
||||
private static String version = new String("0.2");
|
||||
|
||||
/**
|
||||
* Get version (set during build process to "0.2").
|
||||
* @return String version
|
||||
*/
|
||||
public static final String getVersion() { return version; }
|
||||
|
||||
|
||||
/** project (set during build process to "mobibot"). */
|
||||
private static String project = new String("mobibot");
|
||||
|
||||
/**
|
||||
* Get project (set during build process to "mobibot").
|
||||
* @return String project
|
||||
*/
|
||||
public static final String getProject() { return project; }
|
||||
|
||||
}
|
|
@ -90,7 +90,7 @@ public class StockQuote implements Runnable
|
|||
/**
|
||||
* Returns the specified stock quote.
|
||||
*/
|
||||
public void run()
|
||||
public final void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -107,54 +107,54 @@ public class StockQuote implements Runnable
|
|||
{
|
||||
if ((quote.length > 3) && (!"\"N/A\"".equalsIgnoreCase(quote[3])))
|
||||
{
|
||||
_bot.sendNotice(_bot.getChannel(),
|
||||
_bot.send(_bot.getChannel(),
|
||||
"Symbol: " + quote[0].replaceAll("\"", "") + " [" + quote[1].replaceAll("\"", "") +
|
||||
']');
|
||||
|
||||
if (quote.length > 5)
|
||||
{
|
||||
_bot.sendNotice(_bot.getChannel(), "Last Trade: " + quote[2] + " (" + quote[5] + ')');
|
||||
_bot.send(_bot.getChannel(), "Last Trade: " + quote[2] + " (" + quote[5] + ')');
|
||||
}
|
||||
else
|
||||
{
|
||||
_bot.sendNotice(_bot.getChannel(), "Last Trade: " + quote[2]);
|
||||
_bot.send(_bot.getChannel(), "Last Trade: " + quote[2]);
|
||||
}
|
||||
|
||||
if (quote.length > 4)
|
||||
{
|
||||
_bot.sendNotice(_sender,
|
||||
_bot.send(_sender,
|
||||
"Time: " + quote[3].replaceAll("\"", "") + ' ' + quote[4].replaceAll("\"", ""));
|
||||
}
|
||||
|
||||
if (quote.length > 6)
|
||||
{
|
||||
_bot.sendNotice(_sender, "Open: " + quote[6]);
|
||||
_bot.send(_sender, "Open: " + quote[6]);
|
||||
}
|
||||
|
||||
if (quote.length > 7)
|
||||
{
|
||||
_bot.sendNotice(_sender, "Day's Range: " + quote[7] + " - " + quote[8]);
|
||||
_bot.send(_sender, "Day's Range: " + quote[7] + " - " + quote[8]);
|
||||
}
|
||||
|
||||
if (quote.length > 9)
|
||||
{
|
||||
_bot.sendNotice(_sender, "Volume: " + quote[9]);
|
||||
_bot.send(_sender, "Volume: " + quote[9]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_bot.sendNotice(_sender, "Invalid ticker symbol.");
|
||||
_bot.send(_sender, "Invalid ticker symbol.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_bot.sendNotice(_sender, "No data returned.");
|
||||
_bot.send(_sender, "No data returned.");
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
_bot.getLogger().debug("Unable to retrieve stock quote for: " + _symbol, e);
|
||||
_bot.sendNotice(_sender, "An error has occurred: " + e.getMessage());
|
||||
_bot.send(_sender, "An error has occurred: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ public class Weather implements Runnable
|
|||
/**
|
||||
* Main processing method.
|
||||
*/
|
||||
public void run()
|
||||
public final void run()
|
||||
{
|
||||
if (_station.length() == 4)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue