(no commit message)
authorerik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Fri, 17 Mar 2006 22:44:29 +0000 (22:44 +0000)
committererik <erik@77661180-640e-0410-b3a8-9f9b13e6d0e0>
Fri, 17 Mar 2006 22:44:29 +0000 (22:44 +0000)
.classpath
crawler/kiss/src/org/wamblee/crawler/kiss/KissCrawler.java
crawler/kiss/src/org/wamblee/crawler/kiss/Program.java

index 0aa75ddd92e51a9a00e66cfdcbe96704bade1133..5ea6c60535138d68738f7847371796918c7cf183 100644 (file)
@@ -8,7 +8,6 @@
        <classpathentry kind="lib" path="crawler/basic/lib/external/commons-httpclient-3.0.jar"/>
        <classpathentry kind="lib" path="crawler/basic/lib/external/commons-logging-1.0.2.jar"/>
        <classpathentry kind="lib" path="crawler/basic/lib/external/dom4j-1.6.jar"/>
-       <classpathentry kind="lib" path="crawler/basic/lib/external/ehcache-1.1.jar"/>
        <classpathentry kind="lib" path="crawler/basic/lib/external/jtidy-4aug2000r7-dev.jar"/>
        <classpathentry kind="lib" path="crawler/basic/lib/external/log4j-1.2.9.jar"/>
        <classpathentry kind="lib" path="crawler/basic/lib/test/dbunit-2.1.jar"/>
@@ -22,7 +21,6 @@
        <classpathentry kind="lib" path="crawler/kiss/lib/external/commons-httpclient-3.0.jar"/>
        <classpathentry kind="lib" path="crawler/kiss/lib/external/commons-logging-1.0.2.jar"/>
        <classpathentry kind="lib" path="crawler/kiss/lib/external/dom4j-1.6.jar"/>
-       <classpathentry kind="lib" path="crawler/kiss/lib/external/ehcache-1.1.jar"/>
        <classpathentry kind="lib" path="crawler/kiss/lib/external/jtidy-4aug2000r7-dev.jar"/>
        <classpathentry kind="lib" path="crawler/kiss/lib/external/log4j-1.2.9.jar"/>
        <classpathentry kind="lib" path="crawler/kiss/lib/test/dbunit-2.1.jar"/>
index e8687d9d09a5d01f15090592bce528bae1091c65..2f47c695a7a747b4ad00fa870d4b4923726f7a1a 100644 (file)
@@ -166,33 +166,27 @@ public class KissCrawler {
         List<Program> programs = matcher.getMatches();
         EnumMap<RecordingResult, List<Program>> messages = new EnumMap<RecordingResult, List<Program>>(
                 RecordingResult.class);
-        for (RecordingResult result: RecordingResult.values()) {
+        for (RecordingResult result : RecordingResult.values()) {
             messages.put(result, new ArrayList<Program>());
         }
         for (Program program : programs) {
-            try {
-                Program.RecordingResult result = program.record();
-                messages.get(result).add(program);
-            } catch (PageException e) {
-                LOG.info("Attempt to record " + program + " failed.");
-                messages.get(RecordingResult.ERROR).add(program);
-            }
+            Program.RecordingResult result = program.record();
+            messages.get(result).add(program);
         }
         String msg = "Summary of KiSS crawler: \n\n\n";
-        
-       
-        for (RecordingResult result: RecordingResult.values()) { 
-            if ( messages.get(result).size() > 0 ) { 
-                msg += result.getDescription() + "\n\n"; 
-                for (Program program: messages.get(result)) { 
+
+        for (RecordingResult result : RecordingResult.values()) {
+            if (messages.get(result).size() > 0) {
+                msg += result.getDescription() + "\n\n";
+                for (Program program : messages.get(result)) {
                     msg += program + "\n";
                 }
             }
         }
-        if ( programs.size() == 0 ) { 
-            msg += "No suitable programs found"; 
+        if (programs.size() == 0) {
+            msg += "No suitable programs found";
         }
-        
+
         System.out.println(msg);
         sendMail(msg);
     }
@@ -257,8 +251,8 @@ public class KissCrawler {
                 Channel channel = createChannel(action.getName(), action
                         .execute().getAction("right-now").execute());
                 channels.add(channel);
-                if ( SystemProperties.isDebugMode() ) { 
-                    break; // Only one channel is crawled. 
+                if (SystemProperties.isDebugMode()) {
+                    break; // Only one channel is crawled.
                 }
             } catch (PageException e) {
                 LOG.error("Could not create channel information for '"
index e48ccae48a3ca0d9a0d989ae1f164a0244465218..83531ff75100d4040f2c1572d9f44cb28ee84247 100644 (file)
 
 package org.wamblee.crawler.kiss;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.wamblee.crawler.Action;
 import org.wamblee.crawler.Page;
 import org.wamblee.crawler.PageException;
 
 /**
- * Represents a television program. 
+ * Represents a television program.
  */
 public class Program {
+    
+    private static final Log LOG = LogFactory.getLog(Program.class);
 
     /**
-     * Name of the record action on the program details page. 
+     * Name of the record action on the program details page.
      */
     private static final String RECORD_ACTION = "record";
-    
+
     private static final String RESULT_ELEM = "result";
-    
+
     public enum RecordingResult {
-            OK("Successfully recorded programs"), 
-            DUPLICATE("Already recorded programs"), 
-            CONFLICT("Programs in conflict with another recorded program"), 
-            OLDSHOW("Programs that occurred in the past"), 
-            ERROR("Programs that could not be recorded for technical reasons");
-            
-            private String _description; 
-            
-            private RecordingResult(String aDescription) { 
-                _description = aDescription;     
-            }
-            
-            public String getDescription() { 
-                return _description; 
-            }
+        OK("Successfully recorded programs"), DUPLICATE(
+                "Already recorded programs"), CONFLICT(
+                "Programs in conflict with another recorded program"), OLDSHOW(
+                "Programs that occurred in the past"), ERROR(
+                "Programs that could not be recorded for technical reasons");
+
+        private String _description;
+
+        private RecordingResult(String aDescription) {
+            _description = aDescription;
+        }
+
+        public String getDescription() {
+            return _description;
+        }
     };
 
     /**
-     * Indent string to use for pretty printing. 
+     * Indent string to use for pretty printing.
      */
     private static final String INDENT = "       ";
 
     /**
-     * Channel the program is on.  
+     * Channel the program is on.
      */
     private String _channel;
 
     /**
-     * Program name. 
+     * Program name.
      */
     private String _name;
 
     /**
-     * Program description. 
+     * Program description.
      */
     private String _description;
 
     /**
-     * Keywords or classification of the program. 
+     * Keywords or classification of the program.
      */
     private String _keywords;
 
@@ -81,19 +85,27 @@ public class Program {
     private TimeInterval _interval;
 
     /**
-     * Action to execute to obtain program information and/or record the program.
+     * Action to execute to obtain program information and/or record the
+     * program.
      */
     private Action _programInfo;
 
     /**
-     * Constructs the program. 
-     * @param aChannel Channel name. 
-     * @param aName Program name. 
-     * @param aDescription Description. 
-     * @param aKeywords Keywords/classification.
-     * @param aInterval Time interval. 
-     * @param aProgramInfo Action to execute for detailed program information or
-     *    for recording the page. 
+     * Constructs the program.
+     * 
+     * @param aChannel
+     *            Channel name.
+     * @param aName
+     *            Program name.
+     * @param aDescription
+     *            Description.
+     * @param aKeywords
+     *            Keywords/classification.
+     * @param aInterval
+     *            Time interval.
+     * @param aProgramInfo
+     *            Action to execute for detailed program information or for
+     *            recording the page.
      */
     public Program(String aChannel, String aName, String aDescription,
             String aKeywords, TimeInterval aInterval, Action aProgramInfo) {
@@ -107,6 +119,7 @@ public class Program {
 
     /**
      * Gets the channel.
+     * 
      * @return Channel.
      */
     public String getChannel() {
@@ -115,7 +128,8 @@ public class Program {
 
     /**
      * Gets the program name.
-     * @return Name. 
+     * 
+     * @return Name.
      */
     public String getName() {
         return _name;
@@ -123,14 +137,16 @@ public class Program {
 
     /**
      * Gets the description.
-     * @return Description. 
+     * 
+     * @return Description.
      */
     public String getDescription() {
         return _description;
     }
 
     /**
-     * Gets the keywords/classification. 
+     * Gets the keywords/classification.
+     * 
      * @return Keywords/classification
      */
     public String getKeywords() {
@@ -138,8 +154,9 @@ public class Program {
     }
 
     /**
-     * Gets the time interval. 
-     * @return Time interval. 
+     * Gets the time interval.
+     * 
+     * @return Time interval.
      */
     public TimeInterval getInterval() {
         return _interval;
@@ -147,21 +164,28 @@ public class Program {
 
     /**
      * Records the show.
-     * @return True iff an attempt could be made to record the page. 
-     * @throws PageException In case of problems recording the page.
+     * 
+     * @return Status describing the result of recording.
      */
-    public RecordingResult record() throws PageException {
-        Action record = _programInfo.execute().getAction(RECORD_ACTION);
-        if (record == null) {
-            return RecordingResult.OLDSHOW;
+    public RecordingResult record() {
+        try {
+            Action record = _programInfo.execute().getAction(RECORD_ACTION);
+            if (record == null) {
+                return RecordingResult.OLDSHOW;
+            }
+            Page result = record.execute();
+            return RecordingResult.valueOf(result.getContent().getText());
+        } catch (PageException e) {
+            LOG.warn("Technical problem recording program: '" + this + "'", e);
+            return RecordingResult.ERROR;
         }
-        Page result = record.execute();
-        return RecordingResult.valueOf(result.getContent().getText());    
     }
 
     /**
-     * Accepts the visitor. 
-     * @param aVisitor Visitor. 
+     * Accepts the visitor.
+     * 
+     * @param aVisitor
+     *            Visitor.
      */
     public void accept(Visitor aVisitor) {
         aVisitor.visitProgram(this);