1 32 33 package websphinx.workbench; 34 35 import websphinx.*; 36 import java.applet.AppletContext ; 37 import java.io.File ; 38 import java.net.URL ; 39 import java.net.MalformedURLException ; 40 41 public class Browser implements LinkViewListener { 42 protected AppletContext context; 43 protected String frameName; 44 45 public Browser (AppletContext context) { 46 this.context = context; 47 frameName = null; 48 } 49 50 public Browser (AppletContext context, String frameName) { 51 this.context = context; 52 this.frameName = frameName; 53 } 54 55 public void show (Page page) { 56 URL url = page.getURL (); 57 58 if (url != null) 59 show (url); 60 else { 61 try { 64 File 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 e) { 70 System.err.println (e); } 72 } 73 } 74 75 public void show (Link link) { 76 show (link.getURL ()); 77 } 78 79 public void show (URL url) { 80 if (frameName != null) 81 context.showDocument (url, frameName); 82 else 83 context.showDocument (url); 84 } 85 86 public void show (File file) { 87 try { 88 show (Link.FileToURL (file)); 89 } catch (MalformedURLException e) { 90 } 91 } 92 93 public void viewLink (LinkViewEvent event) { 94 show (event.getLink ()); 95 } 96 } 97 | Popular Tags |