Creating a Portable Bookmark Library using Java
Java Programming Notes # 2406
- General Background Information
- Discussion and Sample Code
- Run the Program
- What's Next?
- Complete Program Listing
This is Part 1 of a two-part lesson that will teach you how to write a Java program to create and maintain a portable bookmark (Favorites) library that will follow you from browser to browser, machine to machine, and operating system to operating system.
You may find it useful to open another copy of this lesson in a separate browser window. That will make it easier for you to scroll back and forth among the different listings and figures while you are reading about them.
I recommend that you also study the other lessons in my extensive collection of online Java tutorials. You will find those lessons published at Gamelan.com. However, as of the date of this writing, Gamelan doesn't maintain a consolidated index of my Java tutorial lessons, and sometimes they are difficult to locate there. You will find a consolidated index at www.DickBaldwin.com.
A design for an earlier age
The web page bookmark or Favorites system currently in use was invented at a time when most users had access to a single browser on a single computer using a single operating system. That scenario no longer describes the world in which we live and operate.
Multiple browsers on the same machine
If you are like me, you routinely use two or three different browsers on the same computer. When you create a bookmark to a web page that was accessed using one of those browsers, it is not readily available to the other browsers without manually recreating the bookmark in the other browser.
Many of us also routinely use two or more different computers. For example, you may use one computer in your office and a different computer at home. I do that, and I also use many different computers in the college classrooms and labs where I teach. Bookmarks created in a browser on one computer aren't readily available on the other computers.
Multiple operating systems
Some people routinely use two or more different operating systems on the same, or on different computers. Once again, bookmarks created under one operating system probably aren't readily available under the other operating system, even if they are on the same computer.
A portable bookmark library
What we need is a bookmark library that will follow us from one browser to the next on the same machine, from one machine to another, and even from one operating system to another. In this lesson, I will show you how to create and maintain such a portable bookmark library.
What is a bookmark library?
Just for review, a bookmark library is a specialized database containing a list of names and URLs for web sites or local files of interest. In Firefox and Netscape Navigator, the elements in the database are call bookmarks. In Internet Explorer (IE), the elements in the database are called Favorites. They may have different names in browsers with which I am unfamiliar.
(For convenience, I will usually refer to them as bookmarks even with regard to IE.)
In addition to a name and a URL, the bookmark may contain other information about each bookmark. However, there isn't much consistency between Firefox and IE with regard to this additional information.
For example, the bookmark library in Firefox may maintain the following information (and possibly more) about each bookmark:
- Location (the URL mentioned above)
- Date Added
- Date Last Modified
- Date Last Visited
IE also maintains other information about each bookmark such as the following:
- Date created
- Date last modified
- Date last accessed
The name and the URL are the most important
I don't know about you, but the only bookmark information that I normally care about is the name and the URL. Occasionally, I may create and later use a description, but that is extremely rare.
Organization, views, and usage
Different browsers provide different ways for users to organize, view, and use bookmarks.
The typical usage of a bookmark normally boils down to locating the bookmark within the bookmark library and selecting that bookmark with the mouse. The typical browser response is to open (or attempt to open) the web page or local file referred to by that bookmark.
Organization into folders
When I first started using browsers many years ago, I began organizing my bookmarks into folders. Over the years, I have accumulated more than 5000 bookmarks and my carefully planned folder system has become totally overwhelmed.
(Many of the 5000+ bookmarks are probably totally obsolete, but I have never taken the time to go through them and delete those that are obsolete.)
Locate by searching
It seems that these days (except for about a dozen bookmarks in a folder named Frequently Used) whenever I want to save a bookmark for later use, I simply dump it into the top level folder named Bookmarks. Later when I want to find and use it, I open the Firefox bookmark option known as Bookmarks Manager where I use the search feature in an attempt to locate the bookmark.
Therefore, except for about a dozen bookmarks that I have organized into a folder named Frequently Used, the folder system has effectively become obsolete and my primary method of finding and using bookmarks is by searching for them.
Searching works reasonably well
There's nothing wrong with this approach except that the Firefox search capability isn't very sophisticated. A far as I know, it is not possible to do sophisticated searches using the logical operators AND, OR, and NOT. The search system appears to use an implied AND but OR and NOT are not available.
(One advantage of the Firefox search system, however, is that it has the ability to do partial word searches. For example, searching for the keyword pay will find the bookmark with the name PayPal.com.)
Need a more sophisticated search capability
The fact that I normally end up searching for most bookmarks has recently led me to conclude that I need a bookmark library that will not only follow me from browser to browser as mentioned earlier, but one which will also provide a very fast search capability with the ability to use the logical operators AND, OR, and NOT operators.
A free online bookmarks database
This has led me to conclude that I need access to a (preferably free) online bookmarks database that can be accessed from any computer, (including computers in libraries and internet cafes), with no requirement for any special software.
The requirement for no special software means that the required software must normally be installed on any computer that I am likely to encounter. This leads to the conclusion that the online database must be accessible from the must ubiquitous of all software, the web browser.
So, where can I gain access to a free database that is accessible from any web browser on just about any computer and which also provides the search capabilities described above? One answer is Google Gmail. There may also be other web mail systems that provide similar capabilities as well.
Gmail is a specialized database
When viewed in its most basic sense, Gmail is nothing more or less than a specialized database that is designed to deal in a highly efficient way with Email messages. However, the fact that it is designed to deal with Email messages doesn't mean that it can't also be used to deal with other types of data, as long as that data can be formatted as Email messages. One type of data that can be formatted as Email messages is bookmarks.
Creating a portable bookmark library
Thus, all that is really necessary to create a portable bookmark library is to:
- Open a web mail account.
- Send an Email message to your web mail account for each bookmark that you want to save.
The subject of the message should contain the name of the bookmark and the body of the message should contain the URL. Obviously, the body could also contain any other information that you might want to put there including a description, for example.
Using the portable bookmark library
When time comes to use the bookmark library, all that is necessary is to:
- Open the web mail account in any compatible browser.
- Locate the message in the Email archives containing the bookmark of interest.
- Double click on the URL contained in the body of the message.
Obviously if the bookmark library is large, a sophisticated Email search capability is critical in locating the bookmark of interest.
There is a little more to it than that
If that were all there is to it, there would be no point in me publishing this lesson. However, the reality is that the effort required to send an Email message to yourself for each bookmark that you want to create is much greater than the effort required to simply click a button in your browser to cause your browser to create the bookmark and to maintain the bookmark library.
The best of both worlds
What we need, therefore, is the best of both worlds. We need to continue to create bookmarks in the browsers that we normally use to do our web research. Then we need a simple way to consolidate those bookmarks in a portable bookmark library of Email messages on a web mail server.
We need a program
Having suggested how you can use your web mail account as a portable bookmark library, in this lesson I will provide and explain a program that you can:
- Run initially to populate your web mail bookmark library with the hundreds or thousands of bookmarks that you have accumulated in the past.
- Run periodically thereafter to update and consolidate your web mail bookmark library to incorporate new bookmarks that you have created using one or more different browsers on one or more different computers as you do your normal web research.
Firefox, Netscape, and Internet Explorer
The program that I will provide can be used to consolidate Firefox, Netscape, and Internet Explorer bookmarks into your web mail bookmark library. The code that is specific to the different browser formats is isolated in two methods. If you use a browser that creates and maintains its bookmarks in a format that is different from the above, you should be able to write a new method to handle the bookmark format for that browser.
My favorite web mail is Google Gmail
Although I occasionally use three different web mail accounts, the one that I use most consistently and the one that I know the most about is Google Gmail. Therefore, most of the discussion in this lesson will be slanted toward the use of Gmail for this purpose. However, this approach should work equally well with just about any web mail account provided that it has sufficient capacity, search capability, and longevity.
As mentioned earlier, this document is the first part of a two-part lesson. This part will explain the overall control code, using method stubs for the following two methods in place of the methods that actually extract bookmarks from specific browser bookmark libraries.
Part 2 will provide and explain those two methods in detail.
Page 1 of 3