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;
14 import org.wamblee.xml.XslTransformer;
17 * Copyright 2005 the original author or authors.
19 * Licensed under the Apache License, Version 2.0 (the "License");
20 * you may not use this file except in compliance with the License.
21 * You may obtain a copy of the License at
23 * http://www.apache.org/licenses/LICENSE-2.0
25 * Unless required by applicable law or agreed to in writing, software
26 * distributed under the License is distributed on an "AS IS" BASIS,
27 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28 * See the License for the specific language governing permissions and
29 * limitations under the License.
33 * Test application which uses the crawler.
35 public final class App {
38 * Disabled constructor.
46 * Runs a test program.
49 * Arguments. First argument is the crawler config file name and
50 * second argument is the start url.
52 * In case of problems.
54 public static void main(String[] aArgs) throws Exception {
55 String configFileName = aArgs[0];
56 String starturl = aArgs[1];
58 ConfigurationParser parser = new ConfigurationParser(new XslTransformer());
59 InputStream configFile = new FileInputStream(new File(configFileName));
60 Configuration config = parser.parse(configFile);
62 HttpClient client = new HttpClient();
63 // client.getHostConfiguration().setProxy("localhost", 3128);
65 Crawler crawler = new CrawlerImpl(client, config);
67 System.out.println("Retrieving: " + starturl);
68 Page page = crawler.getPage(starturl);
70 page = page.getAction("channels-favorites").execute();
71 recordInterestingShows(page);
73 page = page.getAction("Nederland 1").execute();
75 page = page.getAction("right-now").execute();
77 page = page.getAction("Het elfde uur").execute();
85 private static void showPage(Page aPage) {
86 Action[] links = aPage.getActions();
87 for (Action link : links) {
88 System.out.println("Link found '" + link.getName() + "'");
90 Element element = aPage.getContent();
91 System.out.println("Retrieved content: " + element.asXML());
94 private static void recordInterestingShows(Page page) throws PageException {
95 Action[] channels = page.getActions();
96 for (Action channel : channels) {
97 examineChannel(channel.getName(), channel.execute().getAction(
98 "right-now").execute());
102 private static void examineChannel(String aChannel, Page aPage)
103 throws PageException {
104 Action[] programs = aPage.getActions();
105 for (Action program : programs) {
106 System.out.println(aChannel + " - " + program.getName());
107 if (program.getName().toLowerCase().matches(".*babe.*")) {
108 Page programPage = program.execute();
109 Action record = programPage.getAction("record");
110 System.out.println("Recording possible: " + record != null);