Datasheet
This defines the end of the portlet application.
</portlet-app>
Building a Portlet
Now, let’s work through a complete example of a portlet. This portlet is a little more complex than our
previous example, but it is not as involved as the portlets found in Chapter 9, which covers building
portlet applications.
The first thing to do in building the portlet is to build the portlet class. Most portlet classes simply
extend
GenericPortlet, as shown in the following code:
/*
* This class demonstrates a basic search portlet
* using the Jakarta Lucene search API.
*
*/
package org.opensourceportals.samples;
import java.io.IOException;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.GenericPortlet;
import javax.portlet.PortletException;
import javax.portlet.PortletMode;
import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ValidatorException;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Searcher;
/**
* @author Clay Richardson
*
*/
public class LucenePortlet extends GenericPortlet {
/*
* This method overrides the doEdit of GenericPortlet
* This is called to provide the markup to be rendered when the
* portlet mode is PortletMode.EDIT
* <p>
* This mode should always show a form to change the indexPath
* preference, indicating where the index is stored.
*/
protected void doEdit(
32
Chapter 1
04 469513 Ch01.qxd 1/16/04 11:04 AM Page 32