Tuesday, November 28, 2006

Integrated Google AJAX Search with LEAD Portal

First I created a LEAD Project custom search engine:

http://www.google.com/coop/cse?cx=001503951656019931001%3Ag2lqfazq_ti

Then I signed up for a Google AJAX search key for portal-dev.leadproject.org. Google gave me some stuff to add, and it worked just fine. I set the web search site restriction to the custom search engine created above:


var searchOptions = new GsearcherOptions();
searchOptions.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);

var leadWebSearch = new GwebSearch();
leadWebSearch.setSiteRestriction("001503951656019931001:g2lqfazq_ti");
searchControl.addSearcher(leadWebSearch, searchOptions);


This all worked fairly well, but I wanted a couple of other things from it. First I wanted to have the search control open up the results over the web page instead of within the web page and rearranging the layout. I found this blog entry at www.cjmillisock.com with a nice use of some simple CSS to get the right effect. Secondly, by default the search results are limited to just one. So I created a GsearcherOptions object with expanded mode set to OPEN (see the above code snippet and also the api documentation).

You can see the result at http://portal-dev.leadproject.org

Wednesday, November 01, 2006

Adding the portlet.xml schema to Eclipse

Updated 2007-04-12: Fixed the instructions. Seems the old ones don't work any longer.

I finally figured out how to do this. The inferred XML schema support in Eclipse is pretty nice and usually suffices, but sometimes I want to have completion based upon full schema knowledge. Here's how to add the portlet.xml XSD file to Eclipse:
  1. First you need to have the JSR 168 code, so go there and get it.
  2. For Eclipse you'll need WTP installed. Get Eclipse 3.2 and use Callisto Discovery Site to download WTP as well.
  3. Okay, now in Eclipse's preference window, go to Web and XML > XML Catalog. Click Add ....
  4. In the URI field, click the little arrow and select the portlet-app_1_0.xsd file that you downloaded in the JSR 168 release.
  5. In Key Type field select Schema Location. Then in the Key field, enter the schema location that you will be using in your portlet.xml files. I entered http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd.
  6. Click OK, OK.
  7. Then you need to make sure you have the following entries in the root element (portlet-app) in your portlet.xml file:
    • [Added 2007-04-12] xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
    • xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    • xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/portlet"
    • [Updated 2007-04-12] xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
  1. Then if you already have a portlet.xml file loaded you'll need to go to XML > Reload Dependencies. Then you should have tag completion in your portlet.xml files.
For more information, here is the corresponding entry from the Eclipse help documentation. I should note that Eclipse seems to think there are errors in the portlet xsd file, but this doesn't seem to cause any problems, i.e., the tag completion works properly.

I should note also that this approach works for other XSD files as well. I recently also used these steps to get schema support for Maven2 pom.xml files.