2 * Copyright 2005 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.wamblee.crawler.kiss;
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.wamblee.crawler.Action;
22 import org.wamblee.crawler.Page;
23 import org.wamblee.crawler.PageException;
26 * Represents a television program.
28 public class Program {
30 private static final Log LOG = LogFactory.getLog(Program.class);
33 * Name of the record action on the program details page.
35 private static final String RECORD_ACTION = "record";
37 private static final String RESULT_ELEM = "result";
39 public enum RecordingResult {
40 OK("Successfully recorded programs"), DUPLICATE(
41 "Already recorded programs"), CONFLICT(
42 "Programs in conflict with another recorded program"), OLDSHOW(
43 "Programs that occurred in the past"), ERROR(
44 "Programs that could not be recorded for technical reasons");
46 private String _description;
48 private RecordingResult(String aDescription) {
49 _description = aDescription;
52 public String getDescription() {
58 * Indent string to use for pretty printing.
60 private static final String INDENT = " ";
63 * Channel the program is on.
65 private String _channel;
73 * Program description.
75 private String _description;
78 * Keywords or classification of the program.
80 private String _keywords;
83 * Time interval for the program (from/to).
85 private TimeInterval _interval;
88 * Action to execute to obtain program information and/or record the
91 private Action _programInfo;
94 * Constructs the program.
100 * @param aDescription
103 * Keywords/classification.
106 * @param aProgramInfo
107 * Action to execute for detailed program information or for
108 * recording the page.
110 public Program(String aChannel, String aName, String aDescription,
111 String aKeywords, TimeInterval aInterval, Action aProgramInfo) {
114 _description = aDescription;
115 _keywords = aKeywords;
116 _interval = aInterval;
117 _programInfo = aProgramInfo;
125 public String getChannel() {
130 * Gets the program name.
134 public String getName() {
139 * Gets the description.
141 * @return Description.
143 public String getDescription() {
148 * Gets the keywords/classification.
150 * @return Keywords/classification
152 public String getKeywords() {
157 * Gets the time interval.
159 * @return Time interval.
161 public TimeInterval getInterval() {
168 * @return Status describing the result of recording.
170 public RecordingResult record() {
172 Action record = _programInfo.execute().getAction(RECORD_ACTION);
173 if (record == null) {
174 return RecordingResult.OLDSHOW;
176 Page result = record.execute();
177 return RecordingResult.valueOf(result.getContent().getText());
178 } catch (PageException e) {
179 LOG.warn("Technical problem recording program: '" + this + "'", e);
180 return RecordingResult.ERROR;
185 * Accepts the visitor.
190 public void accept(Visitor aVisitor) {
191 aVisitor.visitProgram(this);
197 * @see java.lang.Object#toString()
200 public String toString() {
201 return _interval + " - " + _name + " (" + _channel + "/" + _keywords
203 + (INDENT + _description).replaceAll("\n", "\n" + INDENT);