/* Convert MSIE Favourites to HTML page */
/* Author: Brian D. Jones */
/* Date: 10th Jan 97 */
/* Email: support@jonessoft.co.uk */
// History: 18 May 97 Check for "URL=" since not always last line in file.
// 14 Jun 97 Long names which include blanks now supported.
// 26 Jul 97 Explorer 4.0 aware
// 13 Oct 97 Explorer 4.0 Outline added.
// 20 Nov 99 Change Web site URL.
// 26 May 2001 Sort entries.
// 26 May 2001 Make like an Applet for use in HTML Application GUI

import java.io.*;
import java.util.*;

public class Favorite extends Applet {
private static int level = 0;

private static void ListDir( File Path ) {
String Names[] = Path.list();
sort(Names);
if (level == 0)
System.out.println("<div id=Out" +level +">");
else
System.out.println("<div id=Out" +level +"d style=\"display:None\">");
level = level +1;
System.out.println("<DL>");
for (int i=0; i < Names.length; i++) {
try {
File temp = new File( Path, Names[i] );
if ( temp.isDirectory() ) {
System.out.println( "<DT><H3 id=\"Out" +level +"\" class=\"Outline\" style=\"cursor: hand\"><IMG SRC=\"/icons/urlfldr.gif\" WIDTH=16 HEIGHT=16 id=\"Out" +level +"\" class=\"Outline\" style=\"cursor: hand\"> "+ temp.getName() +"</H3><DD>" );

ListDir ( temp );
System.out.println( "</DT>" );
}
else if (temp.getName().endsWith(".url")) {
try {
String BaseName = temp.getName();
String sURL = null,
sDesc = null,
sAuthor = null,
sWhatsNew = null,
sAccessed = null, sModified = null;
DataInputStream file = new DataInputStream( new FileInputStream( temp ));
String Line= null;
Date dateModified = null,
dateAccessed = null;

while ( file.available() > 0 ) {
Line = file.readLine();
// if (Line.startsWith("URL=")) break; // Not always last line.
if (Line.startsWith("URL="))
sURL = Line.substring( Line.indexOf( "=" )+1);
// These items appeared in the Beta, but don't seem to be in the final version.
if (Line.startsWith("Desc="))
sDesc = Line.substring( Line.indexOf( "=" )+1);
if (Line.startsWith("Author="))
sAuthor = Line.substring( Line.indexOf( "=" )+1);
if (Line.startsWith("WhatsNew="))
sWhatsNew = Line.substring( Line.indexOf( "=" )+1);
if (Line.startsWith("Accessed="))
sAccessed = Line.substring( Line.indexOf( "=" )+1);
if (Line.startsWith("Modified="))
sModified = Line.substring( Line.indexOf( "=" )+1);
}
file.close();
// Line = Line.substring( Line.indexOf( "=" )+1);
BaseName = BaseName.substring( 0, BaseName.lastIndexOf( "." ));
System.out.print( "<DT>");
try {
if (sModified != null) {
String tmp = null;
StringTokenizer token = new StringTokenizer( sModified, ",", false );
tmp = token.nextToken().substring(2);
dateModified = new Date( Long.parseLong(tmp,16));
// System.out.println(" Modified: " +dateModified.toLocaleString());
}
if (sAccessed != null) {
String tmp = null;
StringTokenizer token = new StringTokenizer( sAccessed, ",", false );
tmp = token.nextToken().substring(2);
dateAccessed = new Date( Long.parseLong(tmp,16));
// System.out.println(" Modified: " +dateAccessed.toLocaleString());
}
}
catch ( Exception e ) { System.out.println( "<!- " +e +" -->");}
System.out.print( "<A HREF=\"" +sURL +"\">");
if ( dateAccessed != null
&& dateModified != null
&& dateAccessed.after(dateModified))
System.out.print( "<IMG SRC=\"/icons/urlchg.gif\" WIDTH=16 HEIGHT=16 border=0>");
else
System.out.print( "<IMG SRC=\"/icons/url.gif\" WIDTH=16 HEIGHT=16 Border=0>");
System.out.println( BaseName +"</A>");
if (sWhatsNew != null)
System.out.println("<DD>What's new: " +sWhatsNew +"</DD>");
else if (sDesc != null )
System.out.println("<DD>" +sDesc +"</DD>");
}
catch ( Exception e ) { ;
}
}
else if (temp.getName().equalsIgnoreCase("desktop.ini")) {
try {
String BaseName = Path.getName();
String sURL = null,
sLogo = "/icons/url.gif",
sWideLogo = null;
DataInputStream file = new DataInputStream( new FileInputStream( temp ));
String Line= null;

while ( file.available() > 0 ) {
Line = file.readLine();
// if (Line.startsWith("URL=")) break; // Not always last line.
if (Line.startsWith("CDFURL="))
sURL = Line.substring( Line.indexOf( "=" )+1);
if (Line.startsWith("Logo="))
sLogo = Line.substring( Line.indexOf( "=" )+1);
if (Line.startsWith("WideLogo="))
sWideLogo = Line.substring( Line.indexOf( "=" )+1);
}
file.close();
if (sURL != null) {
System.out.print( "<A HREF=\"" +sURL +"\">");
if (sWideLogo != null)
System.out.print( "<IMG SRC=\"" +sWideLogo +"\"></A>");
else
System.out.print( "<IMG SRC=\"" +sLogo +"\"></A>");
}
}
catch ( Exception e ) { ;
}
}
}
catch ( Exception e ) { continue;
}
}
System.out.println("<P></DL>");
System.out.println("</div>");
}

public static void DoIt( String Path ) {

File Root = null;

try {
Root = new File( Path );
}
catch ( Exception e ) {
System.out.println("<HTML><HEAD><TITLE>404 Not Given</TITLE></HEAD>");
System.out.println("<BODY><H1>404 Not Given</H1>No path was requested.<P></BODY></HTML>");
return;
}
if ( !Root.exists()
|| !Root.isDirectory()) {
System.out.println("<HTML><HEAD><TITLE>404 Not Found</TITLE></HEAD>");
System.out.println("<BODY><H1>404 Not Found</H1>The requested path <EM>" +Path +" </EM>was not found on this server<P></BODY></HTML>");
return;
}
System.out.print( "<HTML><HEAD>");
System.out.print( "<FONT FACE=\"verdana,arial,helvetica\" SIZE=2>");
System.out.print( "<TITLE>" +Root.getName() +"</TITLE>");
System.out.println( "</HEAD>" );

System.out.println("<script language=\"JavaScript\">");
System.out.println("function clickHandler() {");
System.out.println(" var targetId, srcElement, targetElement;");
System.out.println(" srcElement = window.event.srcElement;");
System.out.println(" if (srcElement.className == \"Outline\") {");
System.out.println(" targetId = srcElement.id + \"d\";");
System.out.println(" targetElement = document.all(targetId);");
System.out.println(" if (targetElement.style.display == \"none\") {");
System.out.println(" targetElement.style.display = \"\";");
System.out.println(" document.images(srcElement.id).src = \"/icons/urlfldro.gif\";");
System.out.println(" } else {");
System.out.println(" targetElement.style.display = \"none\";");
System.out.println(" document.images(srcElement.id).src = \"/icons/urlfldr.gif\";");
System.out.println(" }");
System.out.println(" }");
System.out.println("}");
System.out.println("");
System.out.println("document.onclick = clickHandler;");
System.out.println("");
System.out.println("</script>");

System.out.print("<body>");
System.out.println( "<H1><IMG SRC=\"/icons/urlfldr.gif\" WIDTH=32 HEIGHT=32>" +Root.getName() +"</H1><HR>");

ListDir( Root );

System.out.println( "<HR>" );
System.out.println( "Created: " +new Date().toLocaleString() );
System.out.println( "using Java application created by <A HREF=\"http://www.jonessoft.co.uk\">Brian D. Jones</A>" );
System.out.println( "</BODY>" );

}

private static String cmdLine( String args[]) {
String returnString = args[0];
for ( int i=1; i< args.length; i++) returnString = returnString +" " +args[i];
return returnString;
}

public void init()
{
setForeground( Color.black );
setBackground( Color.green );
}

private static void sort( String toSort[]) {
if (toSort.length<2) return;
int i,j;
for (i=0; i < toSort.length ; i++)
for (j=i+1; j < toSort.length ; j++)
if (toSort[j].compareTo(toSort[i])< 0) {
String temp = toSort[i];
toSort[i] = toSort[j];
toSort[j] = temp;
}
}

public void save(String folder, String toFile) {
PolicyEngine.assertPermission(PermissionID.SYSTEM);
FileOutputStream saveFile = null;
level = 0;
try {
saveFile = new FileOutputStream (toFile) ;
DoIt( folder, new PrintStream( saveFile ));
saveFile.close();
} catch (Exception e) {}
}
public static void main (String args[] ) {
System.out.println("Content-type: text/html");
System.out.println("");
if (args.length < 1) {
System.out.println("<HTML><HEAD><TITLE>404 Not Given</TITLE></HEAD>");
System.out.println("<BODY><H1>404 Not Given</H1>No path was requested.<P></BODY></HTML>");
return;
}
DoIt( cmdLine( args ));
}
}


The following icons are referenced by the generated html:

blocky