 |
|
|
IEBookmarks.java
|
/*
* Author: Havard Rast Blok
* E-mail: 
* Web : www.rememberjava.com
*/
import java.io.*;
import javax.swing.*;
import javax.swing.tree.*;
/**
* Class for parsing and showing the
* Internet Explorer favourites
*/
public class IEBookmarks extends JFrame
{
String urlTag="URL=";
public IEBookmarks(String path)
{
DefaultMutableTreeNode root;
DefaultTreeModel treeModel;
JTree tree;
//make the tree
root = new DefaultMutableTreeNode("Bookmarks");
addNode( new File(path), root );
treeModel = new DefaultTreeModel(root);
tree = new JTree( treeModel );
getContentPane().add( tree );
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
pack();
show();
}
private void addNode( File path, DefaultMutableTreeNode root )
{
DefaultMutableTreeNode node;
File fileList[];
String fName, link;
fileList = path.listFiles();
//if the list is null, the path was not a directory,
//or could not be read
if( fileList != null )
{
for( int i=0; i<fileList.length; i++)
{
fName = fileList[i].getName();
node = new DefaultMutableTreeNode( fName );
if( fileList[i].isFile() )
{
fName = fName.substring(0, fName.length()-4);
link = getLink( fileList[i] );
node.setUserObject( fName+" ("+link+")" );
}
root.add( node );
addNode( fileList[i], node );
}
}
}
private String getLink( File fName )
{
String ans;
BufferedReader in;
String line;
int index;
ans = "";
try
{
in = new BufferedReader( new FileReader( fName ) );
while( ( line = in.readLine() ) != null && ans.length() == 0 )
{
index = line.indexOf( urlTag );
if( index != -1 )
{
ans = line.substring( index+urlTag.length() );
}
}
in.close();
}
catch( IOException e )
{
System.out.println("IEBookmarks.getLink - error reading file: "+e);
}
return ans;
}
public static void main( String args[] )
{
if( args.length < 1 )
{
System.out.println("Usage: java IEBookmarks <Explorer favourites directory>");
System.exit(1);
}
new IEBookmarks(args[0]);
}
}
|
|
|
 |