【注意】ここで紹介しているプログラムは、たまたま名前がカブってますが、UnderDone さんによるサービス FeedMail とはまったくの別物です。以下の内容について、UnderDone さんに問い合わせたりしないようにお願いします。
「スーパー pre」のテストを兼ねて、自作 FeedMail のソースを貼ってみる。Informa や Velocity の練習から始めたので、いろんな点で汚いけど。長いので、少しずつ。まずはエントリポイントを持つ FeedMail クラスから。
import java.io.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.*;
public class FeedMail {
private List urls = new ArrayList();
private Properties config;
// config
private String formatterName;
public void addFeed(String url) throws MalformedURLException {
urls.add(new URL(url));
}
public void setFormatter(String f) {
this.formatterName = f;
}
public void execute() throws IOException, FeedMailException {
FeedInput input = new FeedInput();
List channels = input.receive(this.urls);
VelocityFormatter formatter = new VelocityFormatter(this.formatterName);
String text = formatter.format(channels);
MailOutput output = new MailOutput(this.config);
output.send(text);
}
public static void main(String[] args) throws IOException, Exception {
org.apache.velocity.app.Velocity.init();
FeedMail fm = new FeedMail();
fm.config = loadProperties(args[0]);
fm.setFormatter(fm.config.getProperty("formatter"));
for (int i = 1; i < args.length; i++) {
fm.addFeed(args[i]);
}
fm.execute();
}
private static Properties loadProperties(String file) throws IOException {
InputStream in = null;
try {
in = new FileInputStream(file);
Properties props = new Properties();
props.load(in);
return props;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
}
}
}
}
}