/* SafeTag v1.0 by Philip R. Banks (copyright) 2000 A class for displaying a tag at the bottom of web pages and providing default navigation buttons. This is a cut down version of WebTag designed to run on Java v1.0.2 environments. It expects to be run either from the root directory of the site it is to be used on or inside a Java directory off the root directory. When active it provides two buttons :- "Home" - Takes you back to the root level of the site. It assumes that you have a well configured web server that will automatically serve a file if the directory is listed in the URL. IE if the site's main page is :- http://some.site.org/index.html then the Home button tries to return you to :- http://some.site.org/ And expects the webserver to serve the index.html by default. "Index" - Returns back to the section index for that page. This is supplied as a parameter from the page that summons the applet. Thus :- The URL is relative to the root of the site as used by the Home button. If the parameter isn't supplied, this button isn't displayed. Finally the application inspects the date and loads one of two tag images. One is a more 'summery' tag while the other is a colder 'winter' one. Version History --------------- v1.0 First publicly released version. */ import java.awt.*; import java.io.*; import java.net.*; import java.lang.*; import java.util.Date; public class SafeTag extends java.applet.Applet { FlowLayout layout = new FlowLayout(FlowLayout.LEFT); Image tag; URL baseURL = null, indexURL = null; public void init() { Button btn; //Get the base URL; baseURL = getCodeBase(); String bURL = baseURL.toString(); baseURL = null; if (bURL.indexOf("Java/") != -1 ) { bURL = bURL.substring(0,bURL.indexOf("Java/")); } try { baseURL = new URL(bURL); } catch (MalformedURLException e) { baseURL = getCodeBase(); } //Get the section index URL; String iURL = getParameter("IndexPage"); if (iURL != null) { try { indexURL = new URL(baseURL.toString() + iURL); } catch (MalformedURLException e) { } } //Load the Image. String tag_name; Date today = new Date(); if ((today.getMonth() > 4) && (today.getMonth() < 9)) { tag_name = "winter.gif"; } else { tag_name = "summer.gif"; } tag = getImage(getCodeBase(),tag_name); //Add the default Buttons. setLayout(layout); if (baseURL != null) { btn = new Button("Home"); add(btn); } if (indexURL != null) { btn = new Button("Index"); add(btn); } } public void paint(Graphics screen) { setBackground(Color.white); screen.drawImage(tag, 0, 20, this); } public boolean action(Event evt, Object arg) { boolean res = false; if (evt.target instanceof Button) { String labl = (String) arg; if (labl.equals("Home")) { if (baseURL != null) getAppletContext().showDocument(baseURL); } if (labl.equals("Index")) { if (indexURL != null) getAppletContext().showDocument(indexURL); } } return res; } }