import java.io.File;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
import java.io.InputStream;
-import java.io.PrintStream;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.logging.Log;
* Entry point for the crawler.
*/
public final class App {
-
+
/**
* Disabled constructor.
- *
+ *
*/
- private App() {
+ private App() {
// Empty
}
-
- private static final Log LOG = LogFactory.getLog(App.class);
-
- private static final String LOG_FILE = "crawler.log";
-
+
/**
- * Runs a test program.
- * @param aArgs Arguments. First argument is the crawler config file name and second argument is
- * the start url.
- * @throws Exception In case of problems.
+ * Runs a test program.
+ *
+ * @param aArgs
+ * Arguments. First argument is the crawler config file name and
+ * second argument is the start url.
+ * @throws Exception
+ * In case of problems.
*/
public static void main(String[] aArgs) throws Exception {
String configFileName = aArgs[0];
String starturl = aArgs[1];
- FileOutputStream fos = new FileOutputStream(new File(LOG_FILE));
- PrintStream os = new PrintStream(fos);
-
- try {
- ConfigurationParser parser = new ConfigurationParser(os);
- InputStream configFile = new FileInputStream(new File(
- configFileName));
- Configuration config = parser.parse(configFile);
-
- HttpClient client = new HttpClient();
- // client.getHostConfiguration().setProxy("localhost", 3128);
-
- Crawler crawler = new CrawlerImpl(client, config);
-
- System.out.println("Retrieving: " + starturl);
- Page page = crawler.getPage(starturl);
- showPage(page);
- page = page.getAction("channels-favorites").execute();
- recordInterestingShows(page);
- showPage(page);
- page = page.getAction("Nederland 1").execute();
- showPage(page);
- page = page.getAction("right-now").execute();
- showPage(page);
- page = page.getAction("Het elfde uur").execute();
- showPage(page);
- } finally {
- os.flush();
- os.close();
- System.out.println("Output written on '" + LOG_FILE + "'");
- }
+ ConfigurationParser parser = new ConfigurationParser();
+ InputStream configFile = new FileInputStream(new File(configFileName));
+ Configuration config = parser.parse(configFile);
+
+ HttpClient client = new HttpClient();
+ // client.getHostConfiguration().setProxy("localhost", 3128);
+
+ Crawler crawler = new CrawlerImpl(client, config);
+
+ System.out.println("Retrieving: " + starturl);
+ Page page = crawler.getPage(starturl);
+ showPage(page);
+ page = page.getAction("channels-favorites").execute();
+ recordInterestingShows(page);
+ showPage(page);
+ page = page.getAction("Nederland 1").execute();
+ showPage(page);
+ page = page.getAction("right-now").execute();
+ showPage(page);
+ page = page.getAction("Het elfde uur").execute();
+ showPage(page);
}
/**
}
}
- private static void examineChannel(String aChannel, Page aPage) throws PageException {
+ private static void examineChannel(String aChannel, Page aPage)
+ throws PageException {
Action[] programs = aPage.getActions();
for (Action program : programs) {
System.out.println(aChannel + " - " + program.getName());
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
private static final Log LOG = LogFactory.getLog(KissCrawler.class);
- /**
- * Log file name for the crawler.
- */
- private static final String LOG_FILE = "kiss.log";
-
/**
* Start URL of the electronic programme guide.
*/
_pattern = Pattern.compile(TIME_REGEX);
- FileOutputStream fos = new FileOutputStream(new File(LOG_FILE));
- PrintStream os = new PrintStream(fos);
-
try {
HttpClient client = new HttpClient();
// client.getHostConfiguration().setProxy("127.0.0.1", 3128);
- Crawler crawler = createCrawler(aCrawlerConfig, os, client);
+ Crawler crawler = createCrawler(aCrawlerConfig, client);
InputStream programConfigFile = new FileInputStream(new File(
aProgramConfig));
ProgramConfigurationParser parser = new ProgramConfigurationParser();
guide.accept(printer);
processResults(programFilters, guide, parser.getNotifier());
} finally {
- os.flush();
- os.close();
- System.out.println("Output written on '" + LOG_FILE + "'");
+ System.out.println("Crawler finished");
}
}
* @throws FileNotFoundException
* In case configuration files cannot be found.
*/
- private Crawler createCrawler(String aCrawlerConfig, PrintStream aOs,
+ private Crawler createCrawler(String aCrawlerConfig,
HttpClient aClient) throws FileNotFoundException {
- ConfigurationParser parser = new ConfigurationParser(aOs);
+ ConfigurationParser parser = new ConfigurationParser();
InputStream crawlerConfigFile = new FileInputStream(new File(
aCrawlerConfig));
Configuration config = parser.parse(crawlerConfigFile);