import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.dom4j.DocumentFactory;
+import org.dom4j.Element;
import org.wamblee.crawler.Action;
import org.wamblee.crawler.Page;
import org.wamblee.crawler.PageException;
*/
public class Program {
+ /**
+ * Lexicographical comparison of programs based on (time, title, channel).
+ *
+ */
public static class TimeSorter implements Comparator<Program> {
/* (non-Javadoc)
* @see java.util.Comparator#compare(T, T)
*/
public int compare(Program o1, Program o2) {
- return o1.getInterval().getBegin().compareTo(o2.getInterval().getBegin());
+ int value = o1.getInterval().getBegin().compareTo(o2.getInterval().getBegin());
+ if ( value != 0 ) {
+ return value;
+ }
+ value = o1.getName().compareTo(o2.getName());
+ if (value != 0 ) {
+ return value;
+ }
+ return o1.getChannel().compareTo(o2.getChannel());
}
}
* @return Status describing the result of recording.
*/
public RecordingResult record() {
+ LOG.info("Recording " + this);
+ if ( SystemProperties.isRecordDisabled() ) {
+ return RecordingResult.OK;
+ }
try {
Action record = _programInfo.execute().getAction(RECORD_ACTION);
if (record == null) {
+ LOG.info(" result: " + RecordingResult.OLDSHOW);
return RecordingResult.OLDSHOW;
}
Page result = record.execute();
- return RecordingResult.valueOf(result.getContent().getText());
+ RecordingResult recordingResult = RecordingResult.valueOf(result.getContent().getText());
+ LOG.info(" result: " + recordingResult);
+ return recordingResult;
} catch (PageException e) {
LOG.warn("Technical problem recording program: '" + this + "'", e);
+ LOG.info(" result: " + RecordingResult.ERROR);
return RecordingResult.ERROR;
}
}
return getName().equals(program.getName()) &&
_programInfo.equals(program._programInfo);
}
+
+ /**
+ * Converts program information to XML.
+ * @return XML representation of program information.
+ */
+ public Element asXml() {
+ DocumentFactory factory = DocumentFactory.getInstance();
+ Element program = factory.createElement("program");
+ program.addElement("name").setText(getName());
+ program.addElement("description").setText(getDescription());
+ program.addElement("keywords").setText(getKeywords());
+ program.addElement("channel").setText(getChannel());
+ Element interval = program.addElement("interval");
+ interval.addElement("begin").setText(getInterval().getBegin().toString());
+ interval.addElement("end").setText(getInterval().getEnd().toString());
+ return program;
+ }
}