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.wamblee.crawler.Action;
20 import org.wamblee.crawler.Page;
21 import org.wamblee.crawler.PageException;
24 * Represents a television program.
26 public class Program {
29 * Name of the record action on the program details page.
31 private static final String RECORD_ACTION = "record";
33 private static final String RESULT_ELEM = "result";
35 public enum RecordingResult {
36 OK("Successfully recorded programs"),
37 DUPLICATE("Already recorded programs"),
38 CONFLICT("Programs in conflict with another recorded program"),
39 OLDSHOW("Programs that occured in the past"),
40 ERROR("Programs that could not be recorded for technical reasons");
42 private String _description;
44 private RecordingResult(String aDescription) {
45 _description = aDescription;
48 public String getDescription() {
54 * Indent string to use for pretty printing.
56 private static final String INDENT = " ";
59 * Channel the program is on.
61 private String _channel;
69 * Program description.
71 private String _description;
74 * Keywords or classification of the program.
76 private String _keywords;
79 * Time interval for the program (from/to).
81 private TimeInterval _interval;
84 * Action to execute to obtain program information and/or record the program.
86 private Action _programInfo;
89 * Constructs the program.
90 * @param aChannel Channel name.
91 * @param aName Program name.
92 * @param aDescription Description.
93 * @param aKeywords Keywords/classification.
94 * @param aInterval Time interval.
95 * @param aProgramInfo Action to execute for detailed program information or
96 * for recording the page.
98 public Program(String aChannel, String aName, String aDescription,
99 String aKeywords, TimeInterval aInterval, Action aProgramInfo) {
102 _description = aDescription;
103 _keywords = aKeywords;
104 _interval = aInterval;
105 _programInfo = aProgramInfo;
112 public String getChannel() {
117 * Gets the program name.
120 public String getName() {
125 * Gets the description.
126 * @return Description.
128 public String getDescription() {
133 * Gets the keywords/classification.
134 * @return Keywords/classification
136 public String getKeywords() {
141 * Gets the time interval.
142 * @return Time interval.
144 public TimeInterval getInterval() {
150 * @return True iff an attempt could be made to record the page.
151 * @throws PageException In case of problems recording the page.
153 public RecordingResult record() throws PageException {
154 Action record = _programInfo.execute().getAction(RECORD_ACTION);
155 if (record == null) {
156 return RecordingResult.OLDSHOW;
158 Page result = record.execute();
159 return RecordingResult.valueOf(result.getContent().getText());
163 * Accepts the visitor.
164 * @param aVisitor Visitor.
166 public void accept(Visitor aVisitor) {
167 aVisitor.visitProgram(this);
173 * @see java.lang.Object#toString()
176 public String toString() {
177 return _interval + " - " + _name + " (" + _channel + "/" + _keywords
179 + (INDENT + _description).replaceAll("\n", "\n" + INDENT);