X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=crawler%2Fkiss%2Fsrc%2Forg%2Fwamblee%2Fcrawler%2Fkiss%2FProgram.java;h=c80fea246badc9c8cfe19c2e9b0addb78e1ea392;hb=c0da3814aaa1e707d253202ceb44fa745c671de8;hp=2358180a405acb95e8f979746204b3886e3356c3;hpb=60e618c7e6c2bf721db4cca59a78d8c731e98882;p=utils diff --git a/crawler/kiss/src/org/wamblee/crawler/kiss/Program.java b/crawler/kiss/src/org/wamblee/crawler/kiss/Program.java index 2358180a..c80fea24 100644 --- a/crawler/kiss/src/org/wamblee/crawler/kiss/Program.java +++ b/crawler/kiss/src/org/wamblee/crawler/kiss/Program.java @@ -20,6 +20,8 @@ import java.util.Comparator; 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; @@ -29,13 +31,25 @@ import org.wamblee.crawler.PageException; */ public class Program { + /** + * Lexicographical comparison of programs based on (time, title, channel). + * + */ public static class TimeSorter implements Comparator { /* (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()); } } @@ -197,6 +211,9 @@ public class Program { */ public RecordingResult record() { LOG.info("Recording " + this); + if ( SystemProperties.isRecordDisabled() ) { + return RecordingResult.OK; + } try { Action record = _programInfo.execute().getAction(RECORD_ACTION); if (record == null) { @@ -248,4 +265,21 @@ public class Program { 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; + } }