1 package org.wamblee.crawler.impl;
4 import java.io.FileInputStream;
5 import java.io.InputStream;
7 import org.apache.commons.httpclient.HttpClient;
8 import org.dom4j.Element;
9 import org.wamblee.crawler.Action;
10 import org.wamblee.crawler.Configuration;
11 import org.wamblee.crawler.Crawler;
12 import org.wamblee.crawler.Page;
13 import org.wamblee.crawler.PageException;
16 * Copyright 2005 the original author or authors.
18 * Licensed under the Apache License, Version 2.0 (the "License");
19 * you may not use this file except in compliance with the License.
20 * You may obtain a copy of the License at
22 * http://www.apache.org/licenses/LICENSE-2.0
24 * Unless required by applicable law or agreed to in writing, software
25 * distributed under the License is distributed on an "AS IS" BASIS,
26 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27 * See the License for the specific language governing permissions and
28 * limitations under the License.
32 * Test application which uses the crawler.
34 public final class App {
37 * Disabled constructor.
45 * Runs a test program.
48 * Arguments. First argument is the crawler config file name and
49 * second argument is the start url.
51 * In case of problems.
53 public static void main(String[] aArgs) throws Exception {
54 String configFileName = aArgs[0];
55 String starturl = aArgs[1];
57 ConfigurationParser parser = new ConfigurationParser();
58 InputStream configFile = new FileInputStream(new File(configFileName));
59 Configuration config = parser.parse(configFile);
61 HttpClient client = new HttpClient();
62 // client.getHostConfiguration().setProxy("localhost", 3128);
64 Crawler crawler = new CrawlerImpl(client, config);
66 System.out.println("Retrieving: " + starturl);
67 Page page = crawler.getPage(starturl);
69 page = page.getAction("channels-favorites").execute();
70 recordInterestingShows(page);
72 page = page.getAction("Nederland 1").execute();
74 page = page.getAction("right-now").execute();
76 page = page.getAction("Het elfde uur").execute();
84 private static void showPage(Page aPage) {
85 Action[] links = aPage.getActions();
86 for (Action link : links) {
87 System.out.println("Link found '" + link.getName() + "'");
89 Element element = aPage.getContent();
90 System.out.println("Retrieved content: " + element.asXML());
93 private static void recordInterestingShows(Page page) throws PageException {
94 Action[] channels = page.getActions();
95 for (Action channel : channels) {
96 examineChannel(channel.getName(), channel.execute().getAction(
97 "right-now").execute());
101 private static void examineChannel(String aChannel, Page aPage)
102 throws PageException {
103 Action[] programs = aPage.getActions();
104 for (Action program : programs) {
105 System.out.println(aChannel + " - " + program.getName());
106 if (program.getName().toLowerCase().matches(".*babe.*")) {
107 Page programPage = program.execute();
108 Action record = programPage.getAction("record");
109 System.out.println("Recording possible: " + record != null);