(no commit message)
[utils] / crawler / kiss / src / org / wamblee / crawler / kiss / Program.java
1 /*
2  * Copyright 2005 the original author or authors.
3  * 
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
7  * 
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  * 
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.
15  */
16
17 package org.wamblee.crawler.kiss;
18
19 import org.wamblee.crawler.Action;
20 import org.wamblee.crawler.PageException;
21
22 /**
23  * Represents a television program. 
24  */
25 public class Program {
26
27     /**
28      * Name of the record action on the program details page. 
29      */
30     private static final String RECORD_ACTION = "record";
31
32     /**
33      * Indent string to use for pretty printing. 
34      */
35     private static final String INDENT = "       ";
36
37     /**
38      * Channel the program is on.  
39      */
40     private String _channel;
41
42     /**
43      * Program name. 
44      */
45     private String _name;
46
47     /**
48      * Program description. 
49      */
50     private String _description;
51
52     /**
53      * Keywords or classification of the program. 
54      */
55     private String _keywords;
56
57     /**
58      * Time interval for the program (from/to).
59      */
60     private TimeInterval _interval;
61
62     /**
63      * Action to execute to obtain program information and/or record the program.
64      */
65     private Action _programInfo;
66
67     /**
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. 
76      */
77     public Program(String aChannel, String aName, String aDescription,
78             String aKeywords, TimeInterval aInterval, Action aProgramInfo) {
79         _channel = aChannel;
80         _name = aName;
81         _description = aDescription;
82         _keywords = aKeywords;
83         _interval = aInterval;
84         _programInfo = aProgramInfo;
85     }
86
87     /**
88      * Gets the channel.
89      * @return Channel.
90      */
91     public String getChannel() {
92         return _channel;
93     }
94
95     /**
96      * Gets the program name.
97      * @return Name. 
98      */
99     public String getName() {
100         return _name;
101     }
102
103     /**
104      * Gets the description.
105      * @return Description. 
106      */
107     public String getDescription() {
108         return _description;
109     }
110
111     /**
112      * Gets the keywords/classification. 
113      * @return Keywords/classification
114      */
115     public String getKeywords() {
116         return _keywords;
117     }
118
119     /**
120      * Gets the time interval. 
121      * @return Time interval. 
122      */
123     public TimeInterval getInterval() {
124         return _interval;
125     }
126
127     /**
128      * Records the show.
129      * @return True iff an attempt could be made to record the page. 
130      * @throws PageException In case of problems recording the page.
131      */
132     public boolean record() throws PageException {
133         Action record = _programInfo.execute().getAction(RECORD_ACTION);
134         if (record == null) {
135             return false;
136         }
137         record.execute();
138         return true;
139     }
140
141     /**
142      * Accepts the visitor. 
143      * @param aVisitor Visitor. 
144      */
145     public void accept(Visitor aVisitor) {
146         aVisitor.visitProgram(this);
147     }
148
149     /*
150      * (non-Javadoc)
151      * 
152      * @see java.lang.Object#toString()
153      */
154     @Override
155     public String toString() {
156         return _interval + " - " + _name + " (" + _channel + "/" + _keywords
157                 + ")" + "\n"
158                 + (INDENT + _description).replaceAll("\n", "\n" + INDENT);
159     }
160 }