Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Blogger Posts Searcher using Google Data .NET/Java Client APIs

It just happened today that I wanted to know if I had already published a post with a given title in one of the blogs I publish: http://jes4us.blogspot.com. During translation (I translate the posts from English to Portuguese) I had a feeling that I had  already worked on a similar text… well, it turns out I was mistaken!

Instead of going through the extensive list of posts looking one by one I thought why not leverage the power of Google Data API? You may say: why not do a simple Google search instead? Good point. As I like to play with code I couldn’t resist.

So here it is. A simple and faster way of knowing if I have a post with a given title. Bellow you’ll find the codez to both the .NET client API and the Java one.

Blogger Data API for .NET
1 - Download the client library here: http://code.google.com/p/google-gdata/downloads/list

2 - Install the .msi package Google_Data_API_Setup_1.9.0.0.msi.

3 - Create a new Console project and reference the DLL Google.GData.Client that’s in this folder: C:\Google Data API SDK\Redist

using System;
using System.Linq;
using Google.GData.Client;

namespace BlogPostsSearcher
{
    class Program
    {
        static void Main(string[] args)
        {
            Service bloggeService = AcquireService();

            AtomFeed feed = AcquireAndSetupFeed(bloggeService);

            // Search posts that contain the word "StringToSearchFor" in their titles
            var query = feed.Entries.Where(p => p.Title.Text.Contains("StringToSearchFor");

            // Writes the Blog's Title
            Console.WriteLine(feed.Title.Text);

            // Prints each post found...
            foreach (AtomEntry entry in query)
            {
                Console.WriteLine(string.Format("Post Title: {0} - Date Published: {1}", entry.Title.Text, entry.Published.ToShortDateString()));
            }

        }

        private static AtomFeed AcquireAndSetupFeed(Service service)
        {
            FeedQuery blogFeedUri = new FeedQuery("http://www.blogger.com/feeds/" + YourBlogID + "/posts/default");

            // Setting the number of posts to retrieve
            blogFeedUri.NumberToRetrieve = 1000;

            AtomFeed feed = service.Query(blogFeedUri);
            
            return feed;
        }

        private static Service AcquireService()
        {
            Service service = new Service("blogger", "YourCompanyName-BloggerPostsSearcher");

            service.Credentials = new GDataCredentials("YourEmailAddress@gmail.com", "YourPassword");

            GDataGAuthRequestFactory factory = (GDataGAuthRequestFactory)service.RequestFactory;
            
            return service;
        }
    }
}

Blogger Data API for Java
1 - Download the client library here: http://code.google.com/p/gdata-java-client/downloads/list

2 - Unzip the file http://code.google.com/p/gdata-java-client/downloads/detail?name=gdata-src.java-1.46.0.zip

3 - Create a new Java Project and add references to:
- gdata-client-1.0.jar that’s in this path: gdata/java/lib/
- google-collect-1.0-rc1
that’s in this path: gdata/java/deps/

import java.io.IOException;
import java.net.URL;
import java.util.List;

import com.google.gdata.client.GoogleService;
import com.google.gdata.data.Entry;
import com.google.gdata.data.Feed;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;

/**
 * @author Leniel Macaferi
 * @date 11-21-2011
 */
public class BloggerClient
{ public static void main(String[] args) throws IOException, ServiceException { try { GoogleService bloggerService = new GoogleService("blogger", "YourCompanyName-BloggerPostsSearcher"); bloggerService.setUserCredentials("YourEmailAddress@gmail.com", "YourPassword"); searchPosts(bloggerService, "YourBlogID", "StringToSearchFor"); } catch (AuthenticationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void searchPosts(GoogleService myService, String blogId, String search) throws ServiceException, IOException { // Request the feed URL feedUrl = new URL("http://www.blogger.com/feeds/" + blogId + "/posts/default"); Feed resultFeed = myService.getFeed(feedUrl, Feed.class); // Setting the number of posts to retrieve... resultFeed.setTotalResults(1000); List<Entry> posts = resultFeed.getEntries(); // Print the results System.out.println(resultFeed.getTitle().getPlainText()); for (Entry post : posts) { if(post.getTitle().getPlainText().contains(search)) { System.out.println("\t" + post.getTitle().getPlainText()); } } System.out.println(); } }

In the code above you need to replace accordingly the following parts:

- YourEmailAddress
- YourPassword
- YourBlogID

References
Blogger Client Libraries and Sample Code

Blogger Developer's Guide: .NET

Blogger Developer's Guide: Java

Playing with Google Translator Toolkit API

Just out of curiosity I wanted to know how many words I have already translated from English to Portuguese in respect to Translating ScottGu's Blog to Portuguese.

This appeared to be a great chance to play with Google Translator Toolkit (GTT) API since I use GTT to translate Scott Guthrie’s posts.

GTT gives me the number of words it finds in the source document. I could count them one by one but that’d be a tedious task. Don’t you think? That’s what computers are for.

Google Translator Toolkit is a pretty good tool because it helps translators translate better and more quickly through one shared, innovative translation technology. It uses machine translation when possible and still allows human intervention.

When a document is uploaded for translation, GTT pretranslate the doc with a combination of previous translated docs by human translation (translation memories), machine translation, etc. Great technology put to work here. That’s why I’ve chosen it.

Given the above, the translated word count I’m interested won’t be an exact figure but it does show a realistic figure about my work as a translator. So let’s find this magic number using GTT API.

Basically what one needs to write a GTT client app is very well described at Google Translator Toolkit Data API v1.0 Developer's Guide. Pay special attention to the Getting Started section as it teaches you how to set up the Google client library. Refer to this: Getting Started with the Google Data Java Client Library.

Now I’m using a Mac and so I played with GTT API with Eclipse for Mac OS if you mind. The programming language is Java and the following code creates a console application.

This is the code I wrote to satisfy my curiosity:


import
com.google.gdata.client.gtt.*;
import com.google.gdata.client.gtt.DocumentQuery;
import com.google.gdata.data.gtt.*;
import com.google.gdata.util.*;

import java.io.IOException;
import java.net.URL;

/**
*
@author Leniel Macaferi
* 12-11-2010
*/
public class GttClient
{

   
static final String DOCUMENTS_FEED_URI = "http://translate.google.com/toolkit/feeds/documents";

   
public static void main(String[] args) throws IOException, ServiceException
   
{
       
try
       
{
           
GttService myService = new GttService("GoogleTranslatorToolkitClientApp");

           
// Your Google username and password go here...
           
myService.setUserCredentials("YourUserName", "YourPassword");

            URL feedUrl =
new URL(DOCUMENTS_FEED_URI);

            DocumentQuery query =
new DocumentQuery(feedUrl);

           
// Send the query to the server.
           
DocumentFeed resultFeed = myService.getFeed(query, DocumentFeed.class);

            printResults
(resultFeed);
       
}
       
catch (AuthenticationException e)
        {
           
// TODO Auto-generated catch block
           
e.printStackTrace();
       
}
    }

   
/**
     * Iterates the document feed and prints some information to the console screen.
     *
@param resultFeed
     */
   
private static void printResults(DocumentFeed resultFeed)
    {
       
System.out.println("...done, there are " + resultFeed.getEntries().size()
               
+ " documents matching the query in your inbox.\n");

       
int i = 1;
       
int totalWords = 0;

       
for (DocumentEntry entry : resultFeed.getEntries())
        {
           
System.out.println(String.valueOf(i++) ") "
                   
+ "id = " + entry.getId().substring(DOCUMENTS_FEED_URI.length() + 1)
                   
+ ", title = '" + entry.getTitle().getPlainText() + "'"
                   
+ ", number of words = '" + entry.getNumberOfSourceWords().getValue() + "'");

            totalWords += entry.getNumberOfSourceWords
().getValue();
       
}

       
// Here's where I satisfy my curiosity... :D
       
System.out.println("Total words translated so far = " + totalWords);
   
}
}

As you see the code is straightforward.

Make sure to replace the strings YourUserName and YourPassword to match your GTT login information.

When I ran the code, this was the output I got:

1) id = 00001vipkz2ce0w, title = 'a-few-quick-asp-net-mvc-3-installation-notes.aspx', number of words = '482'
2) id = 0000082e1f41udc, title = 'add-reference-dialog-improvements-vs-2010-and-net-4-0-series.aspx', number of words = '399'
3) id = 0000206w1a7tog0, title = 'announcing-entity-framework-code-first-ctp5-release.aspx', number of words = '2165'
4) id = 00001qlrxh63jls, title = 'announcing-nupack-asp-net-mvc-3-beta-and-webmatrix-beta-2.aspx', number of words = '1500'
5) id = 00001zm1lv1meio, title = 'announcing-silverlight-5.aspx', number of words = '784'
6) id = 00001vgl6hzbwg0, title = 'announcing-the-asp-net-mvc-3-release-candidate.aspx', number of words = '1999'
7) id = 00001rtmq1go4cg, title = 'asp-net-4-seo-improvements-vs-2010-and-net-4-0-series.aspx', number of words = '1113'
8) id = 00000snuf95gd8g, title = 'asp-net-mvc-2-model-validation.aspx', number of words = '2925'
9) id = 00000joo5ihwykg, title = 'asp-net-mvc-2-release-candidate-2-now-available.aspx', number of words = '549'
10) id = 00000si5lunjbi8, title = 'asp-net-mvc-2-released.aspx', number of words = '524'
11) id = 00000f8wakzalts, title = 'asp-net-mvc-2-strongly-typed-html-helpers.aspx', number of words = '705'
12) id = 00000en7g3nkvls, title = 'asp-net-mvc-2.aspx', number of words = '619'
13) id = 00001so4spobfnk, title = 'asp-net-mvc-3-layouts.aspx', number of words = '1817'
14) id = 00001snnr32adc0, title = 'asp-net-mvc-3-new-model-directive-support-in-razor.aspx', number of words = '792'
15) id = 00001vldns8skqo, title = 'asp-net-mvc-3-server-side-comments-with-razor.aspx', number of words = '653'
16) id = 00001r2yti5z4sg, title = 'automating-deployment-with-microsoft-web-deploy.aspx', number of words = '3784'
17) id = 00000m0if2iqmtc, title = 'built-in-charting-controls-vs-2010-and-net-4-series.aspx', number of words = '637'
18) id = 000010zzw2fq1a8, title = 'cleaner-html-markup-with-asp-net-4-web-forms-client-ids-vs-2010-a', number of words = '1725'
19) id = 00001ih7gktv6kg, title = 'code-first-development-with-entity-framework-4.aspx', number of words = '5365'
20) id = 00001r7ki4lh05c, title = 'debugging-tips-with-visual-studio-2010.aspx', number of words = '1692'
21) id = 0000151qr16itj4, title = 'download-and-share-visual-studio-color-schemes.aspx', number of words = '311'
22) id = 00001ibpvmetdkw, title = 'entity-framework-4-code-first-custom-database-schema-mapping.aspx', number of words = '1930'
23) id = 00001f6hlprohz4, title = 'introducing-asp-net-mvc-3-preview-1.aspx', number of words = '2833'
24) id = 00001so0gu8f3ls, title = 'introducing-razor.aspx', number of words = '3312'
25) id = 00000ug44uvcow0, title = 'javascript-intellisense-improvements-with-vs-2010.aspx', number of words = '930'
26) id = 00000jtavmijvgg, title = 'jquery-1-4-1-intellisense-with-visual-studio.aspx', number of words = '179'
27) id = 00001q9k1j435s0, title = 'jquery-templates-data-link-and-globalization-accepted-as-official', number of words = '828'
28) id = 00000b4mu45b4e8, title = 'microsoft-ajax-cdn-now-with-ssl-support.aspx', number of words = '309'
29) id = 00000ao1rdg9dds, title = 'my-presentations-in-europe-december-2009.aspx', number of words = '1684'
30) id = 000010q75bisw74, title = 'new-lt-gt-syntax-for-html-encoding-output-in-asp-net-4-and-asp-ne', number of words = '977'
31) id = 00000lubanp79c0, title = 'no-intellisense-with-vs-2010-rc-and-how-to-fix-it.aspx', number of words = '449'
32) id = 00000tqxxxv1h4w, title = 'optional-parameters-and-named-arguments-in-c-4-and-a-cool-scenari', number of words = '841'
33) id = 000010ydwjqjzeo, title = 'pinning-projects-and-solutions-with-visual-studio-2010.aspx', number of words = '667'
34) id = 00001wjhyhw29ds, title = 'search-engine-optimization-seo-toolkit.aspx', number of words = '711'
35) id = 000007lw738nbwg, title = 'searching-and-navigating-code-in-vs-2010-vs-2010-and-net-4-0-seri', number of words = '1305'
36) id = 00000e1cqi0ta0w, title = 'silverlight-4-demos-from-my-pdc-keynote-now-available.aspx', number of words = '613'
37) id = 00000743lq060hs, title = 'url-routing-with-asp-net-4-web-forms-vs-2010-and-net-4-0-series.a', number of words = '1045'
38) id = 000020npa0inls0, title = 'using-ef-code-first-with-an-existing-database.aspx', number of words = '2520'
39) id = 00001vo9oowkpvk, title = 'Using-Server-Side-Comments-with-ASP.NET-2.0-.aspx', number of words = '460'
40) id = 00000eafvti4sn4, title = 'visual-studio-2010-and-net-4-0-update.aspx', number of words = '391'
41) id = 000017d48tqvpc0, title = 'visual-studio-2010-productivity-power-tool-extensions.aspx', number of words = '682'
42) id = 000008fncz9zpc0, title = 'vs-2010-and-net-4-0-beta-2.aspx', number of words = '590'
43) id = 000007m1ubf8zcw, title = 'vs-2010-code-intellisense-improvements-vs-2010-and-net-4-0-series', number of words = '734'
44) id = 00000jxh5t9ebr4, title = 'vs-2010-net-4-release-candidate.aspx', number of words = '748'
45) id = 00001r3ulw3aygw, title = 'vs-2010-web-deployment.aspx', number of words = '1352'
46) id = 000008sxc7ta800, title = 'wpf-4-vs-2010-and-net-4-0-series.aspx', number of words = '3171'

Total words translated so far = 59801

If I was to charge for those translations and considering that each word translated costs $ 0.07 (market price), this fast math gives how much I’d have accrued so far:

59801 x 0.07 = $ 4,186.07

$ 4,186.07 / 46 = $ 91.00 average per doc translated

That’s a lot of money, but as you know already I do not charge a thing to translate ScottGu’s blog. That’s something I do to help others and to keep myself up to date.

Hope you liked the curiosity that made me write this post, the reasoning regarding the math and of course this simple java console application.

Notes
It’s important to mention that I started using GTT on Oct 17, 2009, that is, more than a year after I started translating Scott’s posts. According to my records, I have translated in fact 77 posts so far since April 2008. Those remaining 31 posts ( 77 - 46 = 31 ) didn’t figure in the math above. :(

GTT cold have folders just like Google Docs so that one could organize their translations by client or whatever.

I tried to get only 100% translate completed documents but GTT doesn’t give me this info. It’s true even if I mark the translation as complete. Although GTT shows 100% complete in its UI, when I read the value of entry.getPercentComplete() it gives me not 100% but what is described at Word count and translation completion. So I had to consider every document even those that I still need to finish translating.

Download
You can download the sample app with the necessary libraries at:

https://sites.google.com/site/leniel/blog/GoogleTranslatorToolkitClientApp.zip

Adding or removing Liferay portlets

I had to install the Blogs portlet in Liferay.

Liferay is the all purpose portal framework that Chemtech uses to build its website.

The Liferay portal already deployed on production server is the 3.4.5 version. When I tried to add the Blogs portlet through the Add Content menu option I couldn’t find it.

Liferay Add Content Menu

Googling about Liferay’s Blogs portlet didn’t help me. The only positive clue I had was

Liferay Portal Administrator's Guide, Third Edition

(page 124) which has a section dedicated to the Blogs portlet.

I tried to understand why the Blogs portlet wasn’t available in the Add Content window:

Liferay Add Content Window No Blogs portlet available

Was it because the blogs portlet didn’t make it into the version 4.3.5 of the portal? The answer is no. The blogs portlet is available in version 4.3.5 (with limitations if compared to the Blogs portlet of today’s Liferay version that is currently 5.2.3).

After a little bit of more googling I found Development in the ext environment wiki article. I read in item 4 that you can turn portlets you want to deploy on/off by editing the file

\ext\ext-web\docroot\WEB-INF\liferay-portlet-ext.xml

Mine was located in

E:\chemsite\tomcat\webapps\lportal\WEB-INF\liferay-portlet-ext.xml

I did just that turning the Blogs portlet ON setting the <include> property to true:

<!--
    Liferay Portlets

    To create a minimal installation of Liferay so that only the essential Liferay portlets are available, uncomment the following block and set the include attribute to false for the portlets you want to remove. To make a portlet available, set the include attribute to true. The struts-path attribute is shown so that it's easier for the editor of this file to associate a portlet id with a portlet.
-->

<portlet>
          <portlet-name>33</portlet-name>
          <struts-path>blogs</struts-path>
          <include>true</include>
</portlet>

I then rerun Liferay portal using Eclipse. For my surprise I could find the Collaboration category in the Add Content window with the Blogs entry available:

Liferay Add Content Window with Blogs portlet

Hope this shortens the path when you come to need to turn a portlet on/off.

Java web crawler searcher robot that sends e-mail

This java crawler is extremely useful if you need to search a webpage for a specific word, tag or whatever you want to analyze in the data retrieved from a given URL.

I’ve used it for example to search for a specific error message that appeared in a page when a connection to the database could not be done. It helped me to prove that the error was really caused as a consequence of the connection link failure to the database.

The crawler saves in the file system the page that contains the string you’re searching for. The name of the file contains the time from when the string was found within the page body. With this information I could match the time information present on the file name with the time accompanying the error present in the web server log.

The code was originally developed by Rodrigo Gama that is a fellow developer/coworker of mine. I just adapted the code a little bit to fit my needs.

What’s the idea behind the crawler?
The main idea behind the crawler is the following:

You pass 2 essential parameters to run the application - these are the string you want to search for and the URLs you want to verify.

A thread for each URL is then created. This is done using the PageVerificationThread.java class that implements Runnable.

The PageVerificationThread creates a notificator object that is responsible for calling the MailSender object that in its turn sends a notification (message) to the emails you hardcoded in the Main.java class.

The message is also hardcoded inside the run() method of PageVerificationThread class.

I advise you to read the comments in the code.

You’ll have to change some strings in the code as is the case of the username and password used to send the e-mails.

The Code
The crawler has 4 classes: MailSender.java, Main.java, Notificator.java and PageVerificationThread.java.

This is the Main class:

/**
 * @authors Rodrigo Gama (main developer)
 *          Leniel Macaferi (minor modifications and additions)
 * @year 2009
 */

import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;

public class Main
{
    public static void main(String[] args) throws MalformedURLException
    {
        // URLs that will be verified
        List<String> urls = new ArrayList<String>();

        // Emails that will receive the notification
        String[] emails = new String[]
        { "youremail@gmail.com" };

        // Checking for arguments
        if(args == null || args.length < 2 || args[0] == null)
        {
            System.out.println("Usage: <crawler.jar> <search string> <URLs>");

            System.exit(0);
        }
        else
        {
            // Printing some messages to the screen
            System.out.println("Searching for " + args[0] + "...");
            System.out.println("On:");

            // Showing the URLs that will be verified and adding them to the paths variable
            for(int i = 1; i < args.length; i++)
            {
                System.out.println(args[i]);

                urls.add(args[i]);
            }
        }

        // For each URL we create a PageVerificationThread passing to it the URL address, the token to
        // search for and the destination emails.
        for(int i = 0; i < urls.size(); i++)
        {
            Thread t = new Thread(new PageVerificationThread(urls.get(i), args[0], emails));

            t.start();
        }
    }
}

This is the PageVerificationThread class:

/**
 * @authors Rodrigo Gama (main developer)
 *          Leniel Macaferi (minor modifications and additions)
 * @year 2009
 */

import java.io.BufferedReader;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Calendar;
import java.util.Properties;
import java.util.TimeZone;

public class PageVerificationThread implements Runnable
{
    private String                strUrl;
    private String                searchFor;
    private static Notificator    notificator = null;
    private static Object         lock        = new Object();
    private int                   numAttempts = 0;

    public PageVerificationThread(String strUrl, String searchFor, String[] emails)
    {
        this.strUrl = strUrl;
        this.searchFor = searchFor;

        synchronized(lock)
        {
            if(notificator == null)
            {
                notificator = new Notificator();

                // For each email, adds it to the notificator "to" list.
                for(int i = 0; i < emails.length; i++)
                {
                    notificator.addDesetination(emails[i]);
                }
            }
        }
    }

    public void run()
    {
        try
        {
            URL url = new URL(strUrl);

            // Time interval to rerun the thread
            float numMinutes = 1;

            while(true)
            {
                try
                {
                    Properties systemProperties = System.getProperties();
                    systemProperties.put("http.proxyHost",
                            "proxy.yourdomain.com");
                    systemProperties.put("http.proxyPort", "3131");
                    System.setProperties(systemProperties);

                    URLConnection conn = url.openConnection();
                    conn.setDoOutput(true);

                    // Get the response content
                    BufferedReader rd = new BufferedReader(
                            new InputStreamReader(conn.getInputStream()));
                   
                    String line;
                   
                    StringBuilder document = new StringBuilder();

                    // A calendar to configure the time
                    Calendar calendar = Calendar.getInstance();
                    TimeZone tz = TimeZone.getTimeZone("America/Sao_Paulo");
                    calendar.setTimeZone(tz);
                    calendar.add(Calendar.SECOND, 9);
                    String timeStamp = calendar.getTime().toString();

                    boolean error = false;

                    // For each line of code contained in the response
                    while((line = rd.readLine()) != null)
                    {
                        document.append(line + "\n");

                        // If the line contains the text we're after...
                        if(line.contains(searchFor))
                        {// "is temporarily unavailable."))
                            // {
                            error = true;
                        }
                    }

                    // System.out.println(document.toString());
                   
                    // If we found the token...
                    if(error)
                    {
                        // Prints a message to the console
                        System.out.println("Found " + searchFor + " on " + strUrl);

                        // Sends the e-mail
                        notificator.notify("Found " + searchFor + " on " + strUrl);

                        // Writing the file to the file system with time information
                        FileWriter fw = null;

                        try
                        {
                            String dir = "C:/Documents and Settings/leniel-macaferi/Desktop/out/" + strUrl.replaceAll("[^A-Za-z0-9]", "_") + "/";

                            File file = new File(dir);
                            file.mkdirs();
                            file = new File(dir + timeStamp.replaceAll("[^A-Za-z0-9]", "_") + ".html");
                            file.createNewFile();

                            fw = new FileWriter(file);
                            fw.append(document);
                        }
                        finally
                        {
                            if(fw != null)
                            {
                                fw.flush();
                                fw.close();
                            }
                        }
                    }

                    // If error we reduce the time interval
                    if(error)
                    {
                        numMinutes = 0.5f;
                    }
                    else
                    {
                        numMinutes = 1;
                    }

                    try
                    {
                        Thread.sleep((long) (1000 * 60 * numMinutes));
                    }
                    catch(InterruptedException e)
                    {
                        e.printStackTrace();
                    }

                    // A counter to show us the number of attempts so far
                    numAttempts++;

                    System.out.println("Attempt: " + numAttempts + " on " + strUrl + " at " + calendar.getTime().toString());
                }
                catch(IOException e)
                {
                    e.printStackTrace();
                }
            }
        }
        catch(MalformedURLException m)
        {
            m.printStackTrace();
        }
    }
}

This is the Notificator class:

/**
 * @author Rodrigo Gama
 * @year 2009
 */

import java.util.ArrayList;
import java.util.List;
import javax.mail.MessagingException;
import javax.mail.internet.AddressException;

public class Notificator
{
    private List<String>    to   = new ArrayList<String>();
    private String          from = "leniel-macaferi";

    public void addDesetination(String dest)
    {
        to.add(dest);
    }

    public synchronized void notify(String message)
    {
        try
        {
            // Sends the e-mail
            MailSender.sendMail(from, to.toArray(new String[] {}), message);
        }
        catch (AddressException e)
        {
            e.printStackTrace();
        }
        catch (MessagingException e)
        {
            e.printStackTrace();
        }
    }
}

This is the MailSender class:

/**
 * @authors Rodrigo Gama
 * @year 2009
 */

import java.util.Properties;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class MailSender
{
    public static void sendMail(String from, String[] toArray,
            String messageText) throws AddressException, MessagingException
    {
        // Get system properties
        Properties props = System.getProperties();

        // Setup mail server (here we’re using Gmail) 
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.auth", "true");

        // Get session
        Authenticator auth = new MyAuthenticator();
        Session session = Session.getDefaultInstance(props, auth);

        // Define message
        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress(from));

        for(int i = 0; i < toArray.length; i++)
        {
            String to = toArray[i];

            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
        }

        message.setSubject("The e-mail subject goes here!");
        message.setText(messageText);

        // Send message
        Transport.send(message);
    }
}

class MyAuthenticator extends Authenticator
{
    MyAuthenticator()
    {
        super();
    }

    protected PasswordAuthentication getPasswordAuthentication()
    {
        // Your e-mail your username and password
        return new PasswordAuthentication("username", "password");
    }
}

How to use it?
Using Eclipse you just have to run it as shown in this picture:

Java Crawler Run Configuration in Eclipse

I hope you make good use of it!

Source Code
Here it is for your delight: http://leniel.googlepages.com/JavaCrawler.zip