[an error occurred while processing this directive]
Domain for sale!
Start Search Contents Index Links About
OperaBookmarks.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 Opera bookmarks file
 */
public class OperaBookmarks extends JFrame
{
  String folderMark="#FOLDER";
  String urlMark="#URL";
  String endMark="-";
  String urlTag="URL=";
  String nameTag="NAME=";


  public OperaBookmarks(String fileName)
  {
    DefaultMutableTreeNode root;
    DefaultTreeModel treeModel;
    JTree tree;

    BufferedReader in;

    root = new DefaultMutableTreeNode("Bookmarks");

    try
    {
      //open file for reading
      in = new BufferedReadernew FileReaderfileName ) );

      //traverse the file
      addNodein, root );

      in.close();
    }
    catchIOException e )
    {
      System.out.println("Error reading file: "+e);
    }

    treeModel = new DefaultTreeModel(root);
    tree = new JTreetreeModel );
   
    getContentPane().addtree );

    setDefaultCloseOperationJFrame.EXIT_ON_CLOSE );
    pack();
    show();

  }

  private void addNodeBufferedReader in, DefaultMutableTreeNode root throws IOException
  {
    DefaultMutableTreeNode node;
    String name, link;
    String line;
    boolean folder, url, done;
    int idx;

    //read and parse the file
    folder = url = done = false;
    name = "";
    while( (line = in.readLine()) != null && !done )
    {
      ifline.indexOffolderMark  != -)
      {
  folder = true;
      }
      else ifline.indexOfurlMark  != -)
      {
  url = true;
      }
      else ifline.indexOfendMark  == )
      {
  //backtrack to last recursive call
  done = true;
      }
      else if( (idx = line.indexOfnameTag  )) != -)
      {
  //get the name of this record
  name = line.substringnameTag.length() + idx );

  iffolder )
  {
    //if folder, make new node in three
    node = new DefaultMutableTreeNodename );
    root.addnode );
    //RECURSIVE CALL
    addNodein, node );
    folder = false;
  }
      }
      else if( (idx = line.indexOfurlTag  )) != -&&  url)
      {
  //get the url of this record
  link = line.substringurlTag.length() + idx );  
  
  //add record to tree
  node = new DefaultMutableTreeNodename+" ("+link+")" );
  root.addnode );
  url = false;
      }
    }
  }

  public static void mainString args[] )
  {
    ifargs.length < )
    {
      System.out.println("Usage: java OperaBookmarks <Opera bookmarks file>");
      System.exit(1);
    }
    new OperaBookmarks(args[0]);
  }
}
    


site: Håvard Rast Blok
mail:
updated: 16 July 2010