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.PageException;
23 * Represents a television program.
25 public class Program {
28 * Name of the record action on the program details page.
30 private static final String RECORD_ACTION = "record";
33 * Indent string to use for pretty printing.
35 private static final String INDENT = " ";
38 * Channel the program is on.
40 private String _channel;
48 * Program description.
50 private String _description;
53 * Keywords or classification of the program.
55 private String _keywords;
58 * Time interval for the program (from/to).
60 private TimeInterval _interval;
63 * Action to execute to obtain program information and/or record the program.
65 private Action _programInfo;
68 * Constructs the program.
69 * @param aChannel Channel name.
70 * @param aName Program name.
71 * @param aDescription Description.
72 * @param aKeywords Keywords/classification.
73 * @param aInterval Time interval.
74 * @param aProgramInfo Action to execute for detailed program information or
75 * for recording the page.
77 public Program(String aChannel, String aName, String aDescription,
78 String aKeywords, TimeInterval aInterval, Action aProgramInfo) {
81 _description = aDescription;
82 _keywords = aKeywords;
83 _interval = aInterval;
84 _programInfo = aProgramInfo;
91 public String getChannel() {
96 * Gets the program name.
99 public String getName() {
104 * Gets the description.
105 * @return Description.
107 public String getDescription() {
112 * Gets the keywords/classification.
113 * @return Keywords/classification
115 public String getKeywords() {
120 * Gets the time interval.
121 * @return Time interval.
123 public TimeInterval getInterval() {
129 * @return True iff an attempt could be made to record the page.
130 * @throws PageException In case of problems recording the page.
132 public boolean record() throws PageException {
133 Action record = _programInfo.execute().getAction(RECORD_ACTION);
134 if (record == null) {
142 * Accepts the visitor.
143 * @param aVisitor Visitor.
145 public void accept(Visitor aVisitor) {
146 aVisitor.visitProgram(this);
152 * @see java.lang.Object#toString()
155 public String toString() {
156 return _interval + " - " + _name + " (" + _channel + "/" + _keywords
158 + (INDENT + _description).replaceAll("\n", "\n" + INDENT);