KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > websphinx > workbench > Browser


1 /*
2  * WebSphinx web-crawling toolkit
3  *
4  * Copyright (c) 1998-2002 Carnegie Mellon University. All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in
16  * the documentation and/or other materials provided with the
17  * distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY CARNEGIE MELLON UNIVERSITY ``AS IS'' AND
20  * ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY
23  * NOR ITS EMPLOYEES BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  */

32
33 package websphinx.workbench;
34
35 import websphinx.*;
36 import java.applet.AppletContext JavaDoc;
37 import java.io.File JavaDoc;
38 import java.net.URL JavaDoc;
39 import java.net.MalformedURLException JavaDoc;
40
41 public class Browser implements LinkViewListener {
42     protected AppletContext JavaDoc context;
43     protected String JavaDoc frameName;
44
45     public Browser (AppletContext JavaDoc context) {
46         this.context = context;
47         frameName = null;
48     }
49
50     public Browser (AppletContext JavaDoc context, String JavaDoc frameName) {
51         this.context = context;
52         this.frameName = frameName;
53     }
54
55     public void show (Page page) {
56         URL JavaDoc url = page.getURL ();
57
58         if (url != null)
59             show (url);
60         else {
61             // assume page was dynamically-generated
62
// save it to a temporary file, and show that
63
try {
64                 File JavaDoc f = Access.getAccess ().makeTemporaryFile ("sphinx", ".html");
65                 HTMLTransformer out = new HTMLTransformer (f.toString());
66                 out.writePage (page);
67                 out.close ();
68                 show (Link.FileToURL (f));
69             } catch (Exception JavaDoc e) {
70                 System.err.println (e); // FIX: use GUI to report error
71
}
72         }
73     }
74
75     public void show (Link link) {
76         show (link.getURL ());
77     }
78
79     public void show (URL JavaDoc url) {
80         if (frameName != null)
81             context.showDocument (url, frameName);
82         else
83             context.showDocument (url);
84     }
85
86     public void show (File JavaDoc file) {
87       try {
88         show (Link.FileToURL (file));
89       } catch (MalformedURLException JavaDoc e) {
90       }
91     }
92
93     public void viewLink (LinkViewEvent event) {
94         show (event.getLink ());
95     }
96 }
97
Popular Tags