Now using dependency injection for the XslTransformer instead of
[utils] / crawler / kiss / src / org / wamblee / crawler / kiss / main / KissCrawler.java
index b2f6064a06a524394e808f6c0957ade3a35384c9..ad8de40205a2bbf34b91acb1ade106292cc3b1d2 100644 (file)
@@ -19,10 +19,8 @@ package org.wamblee.crawler.kiss.main;
 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;
@@ -48,6 +46,8 @@ import org.wamblee.crawler.kiss.guide.Time;
 import org.wamblee.crawler.kiss.guide.TimeInterval;
 import org.wamblee.crawler.kiss.notification.NotificationException;
 import org.wamblee.crawler.kiss.notification.Notifier;
+import org.wamblee.xml.ClasspathUriResolver;
+import org.wamblee.xml.XslTransformer;
 
 /**
  * The KiSS crawler for automatic recording of interesting TV shows.
@@ -57,11 +57,6 @@ public class KissCrawler {
 
     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.
      */
@@ -121,17 +116,16 @@ public class KissCrawler {
 
         _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);
+            
+            XslTransformer transformer = new XslTransformer(new ClasspathUriResolver());
 
-            Crawler crawler = createCrawler(aCrawlerConfig, os, client);
+            Crawler crawler = createCrawler(aCrawlerConfig, client, transformer);
             InputStream programConfigFile = new FileInputStream(new File(
                     aProgramConfig));
-            ProgramConfigurationParser parser = new ProgramConfigurationParser();
+            ProgramConfigurationParser parser = new ProgramConfigurationParser(transformer);
             parser.parse(programConfigFile);
             List<ProgramFilter> programFilters = parser.getFilters();
 
@@ -141,9 +135,7 @@ public class KissCrawler {
             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");
         }
     }
 
@@ -188,9 +180,9 @@ public class KissCrawler {
      * @throws FileNotFoundException
      *             In case configuration files cannot be found.
      */
-    private Crawler createCrawler(String aCrawlerConfig, PrintStream aOs,
-            HttpClient aClient) throws FileNotFoundException {
-        ConfigurationParser parser = new ConfigurationParser(aOs);
+    private Crawler createCrawler(String aCrawlerConfig, 
+            HttpClient aClient, XslTransformer aTransformer) throws FileNotFoundException {
+        ConfigurationParser parser = new ConfigurationParser(aTransformer);
         InputStream crawlerConfigFile = new FileInputStream(new File(
                 aCrawlerConfig));
         Configuration config = parser.parse(crawlerConfigFile);