[portal-commits] JBoss Portal SVN: r9034 - in branches/JBoss_Portal_Branch_2_6/widget: src/main/org/jboss/portal/test/widget/google and 10 other directories.

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Tue Nov 20 08:49:24 EST 2007


Author: emuckenhuber
Date: 2007-11-20 08:49:23 -0500 (Tue, 20 Nov 2007)
New Revision: 9034

Added:
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/google/ServerResponseTestCase.java
Removed:
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/google/Foo3TestCase.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/netvibes/NetvibesWidgetRenderTestCase.java
Modified:
   branches/JBoss_Portal_Branch_2_6/widget/.classpath
   branches/JBoss_Portal_Branch_2_6/widget/build.xml
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/google/PreferencesTestCase.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/google/QueryResultParserTestCase.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/netvibes/JSONBuilderTestCase.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/netvibes/NetvibesProviderTestCase.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/netvibes/NetvibesQueryResultTestCase.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/AbstractWidgetProvider.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/DirectoryQueryResult.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/WidgetProvider.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/WidgetQuery.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGProvider.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResult.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResultBuilder.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResultEntry.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetInfoBuilder.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetMapEntry.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/NetvibesWidget.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesJSONInfoBuilder.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesQueryResult.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesQueryResultBuilder.java
   branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesWidgetMapEntry.java
   branches/JBoss_Portal_Branch_2_6/widget/src/resources/portal-widget-netvibes-war/WEB-INF/jsp/edit_content.jsp
   branches/JBoss_Portal_Branch_2_6/widget/src/resources/portal-widget-netvibes-war/WEB-INF/portlet.xml
   branches/JBoss_Portal_Branch_2_6/widget/src/resources/portal-widget-war/WEB-INF/jsp/edit_content.jsp
   branches/JBoss_Portal_Branch_2_6/widget/src/resources/portal-widget-war/WEB-INF/portlet.xml
   branches/JBoss_Portal_Branch_2_6/widget/src/resources/test/netvibes/json.response8
Log:
JBPORTAL-1613: improved failures, error messages, added specific exceptions and additional test cases


Modified: branches/JBoss_Portal_Branch_2_6/widget/.classpath
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/.classpath	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/.classpath	2007-11-20 13:49:23 UTC (rev 9034)
@@ -3,12 +3,11 @@
 	<classpathentry kind="src" path="src/main"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="lib" path="/thirdparty/apache-log4j/lib/log4j.jar"/>
-	<classpathentry kind="lib" path="/thirdparty/oswego-concurrent/lib/concurrent.jar"/>
-	<classpathentry kind="lib" path="/thirdparty/jboss/backport-concurrent/lib/jboss-backport-concurrent.jar"/>
 	<classpathentry kind="lib" path="/thirdparty/junit/lib/junit.jar"/>
 	<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/common/lib/portal-common-lib.jar"/>
-	<classpathentry kind="lib" path="/thirdparty/jbossas/core-libs/lib/jboss-common.jar"/>
 	<classpathentry kind="lib" path="/thirdparty/jboss/jbossxb/lib/jboss-xml-binding.jar"/>
 	<classpathentry kind="lib" path="/thirdparty/jboss-portal/modules/portlet/lib/portal-portlet-jsr168api-lib.jar"/>
+	<classpathentry combineaccessrules="false" kind="src" path="/module-common"/>
+	<classpathentry kind="lib" path="/thirdparty/jbossas/core-libs/lib/jboss-common.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>

Modified: branches/JBoss_Portal_Branch_2_6/widget/build.xml
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/build.xml	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/build.xml	2007-11-20 13:49:23 UTC (rev 9034)
@@ -168,6 +168,7 @@
       <mkdir dir="${build.lib}"/>
       <jar jarfile="${build.lib}/portal-widget-lib.jar">
          <fileset dir="${build.classes}" includes="org/jboss/portal/widget/*.class"/>
+         <fileset dir="${build.classes}" includes="org/jboss/portal/widget/exceptions/*.class"/>
       </jar>
 
       <jar jarfile="${build.lib}/portal-widget-google-lib.jar">
@@ -282,14 +283,14 @@
 -->
 
          <x-test>
-            <test todir="${test.reports}"  name="org.jboss.portal.test.widget.google.Foo3TestCase"/>
-            <test todir="${test.reports}"  name="org.jboss.portal.test.widget.netvibes.NetvibesProviderTestCase"/>
-            <test todir="${test.reports}"  name="org.jboss.portal.test.widget.netvibes.NetvibesWidgetRenderTestCase"/>
             <test todir="${test.reports}"  name="org.jboss.portal.test.widget.google.QueryResultParserTestCase"/>
             <test todir="${test.reports}"  name="org.jboss.portal.test.widget.google.PreferencesTestCase"/>
+            <test todir="${test.reports}"  name="org.jboss.portal.test.widget.google.GGQueryTestCase"/>
             <test todir="${test.reports}"  name="org.jboss.portal.test.widget.netvibes.JSONBuilderTestCase"/>
             <test todir="${test.reports}"  name="org.jboss.portal.test.widget.netvibes.NetvibesQueryTestCase"/>
 			<test todir="${test.reports}"  name="org.jboss.portal.test.widget.netvibes.NetvibesQueryResultTestCase"/>
+            <test todir="${test.reports}"  name="org.jboss.portal.test.widget.google.ServerResponseTestCase"/>
+            <test todir="${test.reports}"  name="org.jboss.portal.test.widget.netvibes.NetvibesProviderTestCase"/>
          </x-test>
          <x-classpath>
          <!-- 

Deleted: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/google/Foo3TestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/google/Foo3TestCase.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/google/Foo3TestCase.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -1,227 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat                                               *
- * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
- * contributors as indicated by the @authors tag. See the                     *
- * copyright.txt in the distribution for a full listing of                    *
- * individual contributors.                                                   *
- *                                                                            *
- * This is free software; you can redistribute it and/or modify it            *
- * under the terms of the GNU Lesser General Public License as                *
- * published by the Free Software Foundation; either version 2.1 of           *
- * the License, or (at your option) any later version.                        *
- *                                                                            *
- * This software is distributed in the hope that it will be useful,           *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
- * Lesser General Public License for more details.                            *
- *                                                                            *
- * You should have received a copy of the GNU Lesser General Public           *
- * License along with this software; if not, write to the Free                *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
- ******************************************************************************/
-package org.jboss.portal.test.widget.google;
-
-import java.net.URL;
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.jboss.portal.test.widget.support.AbstractSynchronizedServer;
-import org.jboss.portal.test.widget.support.TestQuery;
-import org.jboss.portal.widget.DirectoryQueryResultEntry;
-import org.jboss.portal.widget.Widget;
-import org.jboss.portal.widget.WidgetProvider;
-import org.jboss.portal.widget.google.provider.GGProvider;
-
-/**
- * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-public class Foo3TestCase extends TestCase
-{
-
-   public void test01() throws Exception
-   {
-      AbstractSynchronizedServer server = new AbstractSynchronizedServer.AbstractReturnFileServer(8181, "google/queryresult1.xml")
-      {
-         protected void doClient() throws Exception
-         {
-            
-            WidgetProvider provider = new GGProvider();
-            provider.start();
-
-            TestQuery q = new TestQuery();
-            
-            List<DirectoryQueryResultEntry> w = provider.search(q);
-           
-            provider.stop();
-            assertEquals(24, w.size());
-            
-         }
-      };
-      server.performInteraction();
-   }
-   
-   
-   public void test02() throws Exception
-   {
-      AbstractSynchronizedServer server = new AbstractSynchronizedServer.AbstractReturnFileServer(8181, "google/queryresult2.xml")
-      {
-         protected void doClient() throws Exception
-         {
-            
-            WidgetProvider provider = new GGProvider();
-            provider.start();
-
-            TestQuery q = new TestQuery();
-            
-            List<DirectoryQueryResultEntry> w = provider.search(q);
-
-            provider.stop();
-            assertEquals(24, w.size());
-         }
-      };
-      server.performInteraction();
-   }
-   
-   public void test03_fail() throws Exception
-   {
-      AbstractSynchronizedServer server = new AbstractSynchronizedServer.AbstractReturnFileServer(8181, "google/queryresult3_fail.xml")
-      {
-         protected void doClient() throws Exception
-         {
-            
-            WidgetProvider provider = new GGProvider();
-            provider.start();
-
-            TestQuery q = new TestQuery();
-            
-            List<DirectoryQueryResultEntry> w = provider.search(q);
-
-            provider.stop();
-            assertEquals(0, w.size());
-            
-         }
-      };
-      server.performInteraction();
-   }
-   
-   
-   public void test03_timeout() throws Exception
-   {
-      AbstractSynchronizedServer server = new AbstractSynchronizedServer.AbstractTimeoutServer(8181)
-      {
-         protected void doClient() throws Exception
-         {
-            WidgetProvider provider = new GGProvider();
-            provider.start();
-            TestQuery q = new TestQuery();
-            List<DirectoryQueryResultEntry> w = provider.search(q);
-
-            provider.stop();
-            assertEquals(0, w.size());
-         }
-      };
-      server.performInteraction();
-   }
-   
-   public void test404() throws Exception
-   {
-      AbstractSynchronizedServer server = new AbstractSynchronizedServer.Abstract404Server(8181)
-      {
-         protected void doClient() throws Exception
-         {
-            WidgetProvider provider = new GGProvider();
-            provider.start();
-            TestQuery q = new TestQuery();
-            List<DirectoryQueryResultEntry> w = provider.search(q);
-
-            provider.stop();
-            assertEquals(0, w.size());
-         }
-      };
-      server.performInteraction();
-   }
-   
-   
-   public void test_widget404() throws Exception
-   {
-      AbstractSynchronizedServer server = new AbstractSynchronizedServer.Abstract404Server(8181)
-      {
-         protected void doClient() throws Exception
-         {
-            WidgetProvider provider = new GGProvider();
-            provider.start();
-
-            URL url = new URL("http://localhost:8181");
-            Widget w = provider.getWidget(url);
-            
-            provider.stop();
-            
-            assertNull(w);
-         }
-      };
-      server.performInteraction();
-   }
-
-   public void test_widget_wrong_content() throws Exception
-   {
-      AbstractSynchronizedServer server = new AbstractSynchronizedServer.AbstractReturnFileServer(8181, "google/gadget1_fail.xml")
-      {
-         protected void doClient() throws Exception
-         {
-            WidgetProvider provider = new GGProvider();
-            provider.start();
-
-            URL url = new URL("http://localhost:8181");
-            Widget w = provider.getWidget(url);
-                       
-            provider.stop();
-            
-            assertNull(w);
-         }
-      };
-      server.performInteraction();
-   }
-   
-   public void test_widget_timeout() throws Exception
-   {
-      AbstractSynchronizedServer server = new AbstractSynchronizedServer.AbstractTimeoutServer(8181)
-      {
-         protected void doClient() throws Exception
-         {
-            WidgetProvider provider = new GGProvider();
-            provider.start();
-
-            URL url = new URL("http://localhost:8181");
-            Widget w = provider.getWidget(url);
- 
-            provider.stop();
-            
-            assertNull(w);
-         }
-      };
-      server.performInteraction();
-   }
-   
-   
-   public void test_widget_no_server() throws Exception
-   {
-      WidgetProvider provider = new GGProvider();
-     
-      try
-      {
-         provider.start();
-         
-         URL url= new URL("http://localhost:8181");
-         Widget w = provider.getWidget(url);
-         assertNull(w);
-      }
-      finally
-      {
-         provider.stop();
-      }
-   }
-}
-

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/google/PreferencesTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/google/PreferencesTestCase.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/google/PreferencesTestCase.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -24,6 +24,7 @@
 
 import junit.framework.TestCase;
 import org.jboss.portal.common.io.IOTools;
+import org.jboss.portal.widget.exceptions.WidgetNotSupportedException;
 import org.jboss.portal.widget.google.info.GGPreferenceInfo;
 import org.jboss.portal.widget.google.info.GGPreferencesInfo;
 import org.jboss.portal.widget.google.info.GGWidgetInfo;
@@ -140,30 +141,39 @@
       assertEquals(DataType.LOCATION, pi.getType().getOrdinal());
       
    }
-   /* - urlparam not supported for now
+
    public void testUserPrefs03() throws Exception
    {
       ClassLoader tcl = Thread.currentThread().getContextClassLoader();
       URL url = tcl.getResource("google/gadget3.xml");
 
       GGWidgetInfoBuilder ggwb = constructBuilder(url);
-      GGWidgetInfo ggw = ggwb.create();
-
-      assertNotNull(ggw);
+      try
+      {
+         GGWidgetInfo ggw = ggwb.create();
+      }
+      catch (WidgetNotSupportedException e)
+      {
+         // ok urlparam not supported for now
+      }
    }
    
-   // same here
    public void testUserPrefs05() throws Exception
    {
       ClassLoader tcl = Thread.currentThread().getContextClassLoader();
       URL url = tcl.getResource("google/gadget5.xml");
 
       GGWidgetInfoBuilder ggwb = constructBuilder(url);
-      GGWidgetInfo ggw = ggwb.create();
+      try
+      {
+         GGWidgetInfo ggw = ggwb.create();
+      }
+      catch (WidgetNotSupportedException e)
+      {
+         // ok urlparam not supported for now
+      }
+   }
 
-      assertNotNull(ggw);
-   }
-*/
    
    public void testUserPrefs04() throws Exception
    {
@@ -241,17 +251,24 @@
       assertNotNull(ggw);
    }
    
-   public GGWidgetInfoBuilder constructBuilder(URL url) throws Exception
+   public GGWidgetInfoBuilder constructBuilder(URL url) throws IllegalArgumentException
    {
       return new GGWidgetInfoBuilder(url)
       {
-         protected byte[] obtainWidget(URL url) throws Exception
+         protected byte[] obtainWidget(URL url) throws IllegalArgumentException
          {
-            File file = new File(url.getPath());
-            InputStream io = new FileInputStream(file);
-            byte[] bytes = IOTools.getBytes(io);
-            io.close();
-            return bytes;
+            try
+            {
+               File file = new File(url.getPath());
+               InputStream io = new FileInputStream(file);
+               byte[] bytes = IOTools.getBytes(io);
+               io.close();
+               return bytes;
+            }
+            catch(Exception e)
+            {
+               throw new IllegalArgumentException("Could not read file: "+ url.toString());
+            }
          }
       };
    }

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/google/QueryResultParserTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/google/QueryResultParserTestCase.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/google/QueryResultParserTestCase.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -23,6 +23,8 @@
 package org.jboss.portal.test.widget.google;
 
 import junit.framework.TestCase;
+
+import org.jboss.portal.widget.exceptions.WidgetException;
 import org.jboss.portal.widget.google.provider.GGQueryResult;
 import org.jboss.portal.widget.google.provider.GGQueryResultBuilder;
 import org.jboss.portal.widget.google.provider.GGQueryResultEntry;
@@ -40,75 +42,98 @@
 
    public void testA() throws MalformedURLException
    {
-
-      URL url = this.getFileURL("google/queryresult1.xml");
-      assertNotNull(url);
-      GGQueryResultBuilder builder = new GGQueryResultBuilder(url);
-      GGQueryResult result = builder.build(5000);
-      assertNotNull(result);
-      assertEquals(24, result.collection().size());
-      Iterator i = result.entries();
-      assertNotNull(i);
-      assertTrue(i.hasNext());
-      GGQueryResultEntry entry = (GGQueryResultEntry)i.next();
-      assertNotNull(entry);
-      assertEquals("Date & Time", entry.getTitle());
-      assertEquals("Add a clock to your page.  Click edit to change it to the color of your choice.", entry.getDescription());
-      assertEquals("http://www.google.com/ig/modules/datetime.png", entry.getScreenshot());
-      assertEquals("http://www.google.com/ig/modules/datetime-thm.png", entry.getThumbnail());
-      assertEquals("matt.feedback+datetime at gmail.com", entry.getAuthor());
-      assertEquals(320, entry.getWidth());
-      assertEquals(136, entry.getHeight());
-      assertEquals(new URL("http://www.google.com/ig/modules/datetime.xml"), entry.getURL());
-      
-      GGQueryResultEntry entry2 = (GGQueryResultEntry)i.next();
-      assertNotNull(entry2);
-      assertEquals("Search YouTube", entry2.getTitle());
-      assertEquals("A search module, which searches YouTube by tags.", entry2.getDescription());
-      assertEquals("http://www.google.com/ig/cache/28/a3/28a39282258f1ba32b6f6468ae6d12bc.png", entry2.getScreenshot());
-      assertEquals("http://www.google.com/ig/cache/28/a3/28a39282258f1ba32b6f6468ae6d12bc-thm.png", entry2.getThumbnail());
-      assertEquals("http://throttled.org/googlegadgets/youtubesearch.xml", entry2.getURL().toString());
-      
-      GGQueryResultEntry entry3 = (GGQueryResultEntry)i.next();
-      assertNotNull(entry3);
-      assertEquals("PacMan v2.4", entry3.getTitle());
-      assertEquals(new URL("http://www.schulz.dk/pacman.xml"), entry3.getURL());
+      try
+      {
+         URL url = this.getFileURL("google/queryresult1.xml");
+         assertNotNull(url);
+         GGQueryResultBuilder builder = new GGQueryResultBuilder(url);
+         GGQueryResult result = builder.build(5000);
+         assertNotNull(result);
+         assertEquals(24, result.collection().size());
+         Iterator i = result.entries();
+         assertNotNull(i);
+         assertTrue(i.hasNext());
+         GGQueryResultEntry entry = (GGQueryResultEntry)i.next();
+         assertNotNull(entry);
+         assertEquals("Date & Time", entry.getTitle());
+         assertEquals("Add a clock to your page.  Click edit to change it to the color of your choice.", entry.getDescription());
+         assertEquals("http://www.google.com/ig/modules/datetime.png", entry.getScreenshot());
+         assertEquals("http://www.google.com/ig/modules/datetime-thm.png", entry.getThumbnail());
+         assertEquals("matt.feedback+datetime at gmail.com", entry.getAuthor());
+         assertEquals(320, entry.getWidth());
+         assertEquals(136, entry.getHeight());
+         assertEquals(new URL("http://www.google.com/ig/modules/datetime.xml"), entry.getURL());
+         
+         GGQueryResultEntry entry2 = (GGQueryResultEntry)i.next();
+         assertNotNull(entry2);
+         assertEquals("Search YouTube", entry2.getTitle());
+         assertEquals("A search module, which searches YouTube by tags.", entry2.getDescription());
+         assertEquals("http://www.google.com/ig/cache/28/a3/28a39282258f1ba32b6f6468ae6d12bc.png", entry2.getScreenshot());
+         assertEquals("http://www.google.com/ig/cache/28/a3/28a39282258f1ba32b6f6468ae6d12bc-thm.png", entry2.getThumbnail());
+         assertEquals("http://throttled.org/googlegadgets/youtubesearch.xml", entry2.getURL().toString());
+         
+         GGQueryResultEntry entry3 = (GGQueryResultEntry)i.next();
+         assertNotNull(entry3);
+         assertEquals("PacMan v2.4", entry3.getTitle());
+         assertEquals(new URL("http://www.schulz.dk/pacman.xml"), entry3.getURL());
+      }
+      catch(WidgetException e)
+      {
+         e.printStackTrace();
+         fail();
+      }
    }
    
    public void test02() throws MalformedURLException
    {
-      URL url = this.getFileURL("google/queryresult2.xml");
-      assertNotNull(url);
-      GGQueryResultBuilder builder = new GGQueryResultBuilder(url);
-      GGQueryResult result = builder.build(5000);
-      assertNotNull(result);
-      Iterator i = result.entries();
-      assertNotNull(i);
-      assertEquals(24, result.collection().size());
-      assertTrue(i.hasNext());
-      GGQueryResultEntry entry = (GGQueryResultEntry)i.next();
-      assertNotNull(entry);
-      assertEquals("Wikipedia", entry.getTitle());
-      assertEquals(new URL("http://homepages.ipact.nl/~kruit/benno/folder/Documents/Google/wpsearchbar.xml"), entry.getURL());
-      assertEquals("A Wikipedia Search and Go widget. Language choice.", entry.getDescription());
-      assertEquals("http://www.google.com/ig/modules/ov/module_wikipedia_full.png", entry.getScreenshot());
-      assertEquals("http://www.google.com/ig/modules/ov/module_wikipedia.png", entry.getThumbnail());
-      assertEquals("bennokr+be_gone_spammers at gmail.com", entry.getAuthor());
-      assertEquals(320, entry.getWidth());
-      assertEquals(40, entry.getHeight());
-      
-      GGQueryResultEntry entry2 = (GGQueryResultEntry)i.next();
-      assertNotNull(entry2);
+      try
+      {
+         URL url = this.getFileURL("google/queryresult2.xml");
+         assertNotNull(url);
+         GGQueryResultBuilder builder = new GGQueryResultBuilder(url);
+         GGQueryResult result = builder.build(5000);
+         assertNotNull(result);
+         Iterator i = result.entries();
+         assertNotNull(i);
+         assertEquals(24, result.collection().size());
+         assertTrue(i.hasNext());
+         GGQueryResultEntry entry = (GGQueryResultEntry)i.next();
+         assertNotNull(entry);
+         assertEquals("Wikipedia", entry.getTitle());
+         assertEquals(new URL("http://homepages.ipact.nl/~kruit/benno/folder/Documents/Google/wpsearchbar.xml"), entry.getURL());
+         assertEquals("A Wikipedia Search and Go widget. Language choice.", entry.getDescription());
+         assertEquals("http://www.google.com/ig/modules/ov/module_wikipedia_full.png", entry.getScreenshot());
+         assertEquals("http://www.google.com/ig/modules/ov/module_wikipedia.png", entry.getThumbnail());
+         assertEquals("bennokr+be_gone_spammers at gmail.com", entry.getAuthor());
+         assertEquals(320, entry.getWidth());
+         assertEquals(40, entry.getHeight());
+         
+         GGQueryResultEntry entry2 = (GGQueryResultEntry)i.next();
+         assertNotNull(entry2);
+      }
+      catch(WidgetException e)
+      {
+         e.printStackTrace();
+         fail();
+      }
    }
    
    public void test03()
    {
-      URL url = this.getFileURL("google/queryresult3_fail.xml");
-      assertNotNull(url);
-      GGQueryResultBuilder builder = new GGQueryResultBuilder(url);
-      GGQueryResult result = builder.build(5000);
-      assertNotNull(result);
-      assertEquals(0, result.collection().size());
+      try
+      {
+         URL url = this.getFileURL("google/queryresult3_fail.xml");
+         assertNotNull(url);
+         GGQueryResultBuilder builder = new GGQueryResultBuilder(url);
+         GGQueryResult result = builder.build(5000);
+         assertNotNull(result);
+         assertEquals(0, result.collection().size());
+         fail();
+      }
+      catch(WidgetException e)
+      {
+         // ok
+      }
    }
    
    private URL getFileURL(String filename)

Added: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/google/ServerResponseTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/google/ServerResponseTestCase.java	                        (rev 0)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/google/ServerResponseTestCase.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -0,0 +1,340 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
+ * contributors as indicated by the @authors tag. See the                     *
+ * copyright.txt in the distribution for a full listing of                    *
+ * individual contributors.                                                   *
+ *                                                                            *
+ * This is free software; you can redistribute it and/or modify it            *
+ * under the terms of the GNU Lesser General Public License as                *
+ * published by the Free Software Foundation; either version 2.1 of           *
+ * the License, or (at your option) any later version.                        *
+ *                                                                            *
+ * This software is distributed in the hope that it will be useful,           *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
+ * Lesser General Public License for more details.                            *
+ *                                                                            *
+ * You should have received a copy of the GNU Lesser General Public           *
+ * License along with this software; if not, write to the Free                *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
+ ******************************************************************************/
+package org.jboss.portal.test.widget.google;
+
+import junit.framework.TestCase;
+
+import org.jboss.portal.test.widget.support.AbstractSynchronizedServer;
+import org.jboss.portal.test.widget.support.TestQuery;
+import org.jboss.portal.widget.DirectoryQueryResult;
+import org.jboss.portal.widget.Widget;
+import org.jboss.portal.widget.WidgetProvider;
+import org.jboss.portal.widget.exceptions.DirectoryResultFailure;
+import org.jboss.portal.widget.exceptions.WidgetException;
+import org.jboss.portal.widget.exceptions.WidgetFailure;
+import org.jboss.portal.widget.exceptions.WidgetFetchException;
+import org.jboss.portal.widget.exceptions.WidgetMetaDataParseException;
+import org.jboss.portal.widget.google.provider.GGProvider;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class ServerResponseTestCase extends TestCase
+{
+
+   public void test01() throws Exception
+   {
+      AbstractSynchronizedServer server = new AbstractSynchronizedServer.AbstractReturnFileServer(8181, "google/queryresult1.xml")
+      {
+         protected void doClient() throws Exception
+         {
+            
+            WidgetProvider provider = new GGProvider();
+            provider.start();
+
+            TestQuery q = new TestQuery();
+            
+            DirectoryQueryResult w = provider.search(q);
+           
+            provider.stop();
+            assertEquals(24, w.resultSize());
+         }
+      };
+      server.performInteraction();
+   }
+   
+   
+   public void test02() throws Exception
+   {
+      AbstractSynchronizedServer server = new AbstractSynchronizedServer.AbstractReturnFileServer(8181, "google/queryresult2.xml")
+      {
+         protected void doClient() throws Exception
+         {
+            
+            WidgetProvider provider = new GGProvider();
+            provider.start();
+
+            TestQuery q = new TestQuery();
+            
+            DirectoryQueryResult w = provider.search(q);
+
+            provider.stop();
+            assertEquals(24, w.resultSize());
+         }
+      };
+      server.performInteraction();
+   }
+   
+   public void test03_fail() throws Exception
+   {
+      AbstractSynchronizedServer server = new AbstractSynchronizedServer.AbstractReturnFileServer(8181, "google/queryresult3_fail.xml")
+      {
+         protected void doClient() throws Exception
+         {
+            
+            WidgetProvider provider = new GGProvider();
+            provider.start();
+
+            TestQuery q = new TestQuery();
+            
+            DirectoryQueryResult w = provider.search(q);
+
+            provider.stop();
+            assertEquals(0, w.resultSize());
+            if ( w instanceof DirectoryResultFailure)
+            {
+               DirectoryResultFailure r = (DirectoryResultFailure) w;
+               if ( r.getCause() instanceof WidgetException)
+               {
+                  // ok
+               }
+               else
+               {
+                  fail("Exception must be of type WidgetException");
+               }
+            }
+            else
+            {
+               fail("Directory lookup must fail.");
+            }
+            
+         }
+      };
+      server.performInteraction();
+   }
+   
+   
+   public void test03_timeout() throws Exception
+   {
+      AbstractSynchronizedServer server = new AbstractSynchronizedServer.AbstractTimeoutServer(8181)
+      {
+         protected void doClient() throws Exception
+         {
+            WidgetProvider provider = new GGProvider();
+            provider.start();
+            TestQuery q = new TestQuery();
+            DirectoryQueryResult w = provider.search(q);
+
+            provider.stop();
+            assertEquals(0, w.resultSize());
+            if ( w instanceof DirectoryResultFailure)
+            {
+               DirectoryResultFailure r = (DirectoryResultFailure) w;
+               if ( r.getCause() instanceof WidgetException)
+               {
+                  // ok
+               }
+               else
+               {
+                  fail("Exception must be of type WidgetException");
+               }
+            }
+            else
+            {
+               fail("Directory lookup must fail.");
+            }
+         }
+      };
+      server.performInteraction();
+   }
+   
+   public void test404() throws Exception
+   {
+      AbstractSynchronizedServer server = new AbstractSynchronizedServer.Abstract404Server(8181)
+      {
+         protected void doClient() throws Exception
+         {
+            WidgetProvider provider = new GGProvider();
+            provider.start();
+            TestQuery q = new TestQuery();
+            DirectoryQueryResult w = provider.search(q);
+
+            provider.stop();
+            assertEquals(0, w.resultSize());
+            if ( w instanceof DirectoryResultFailure)
+            {
+               DirectoryResultFailure r = (DirectoryResultFailure) w;
+               if ( r.getCause() instanceof WidgetException)
+               {
+                  // ok
+               }
+               else
+               {
+                  fail("Exception must be of type WidgetException");
+               }
+            }
+            else
+            {
+               fail("Directory lookup must fail.");
+            }
+         }
+      };
+      server.performInteraction();
+   }
+   
+   
+   public void test_widget404() throws Exception
+   {
+      AbstractSynchronizedServer server = new AbstractSynchronizedServer.Abstract404Server(8181)
+      {
+         protected void doClient() throws Exception
+         {
+            GGProvider provider = new GGProvider();
+            provider.start();
+
+            Widget w = provider.getWidget("http://localhost:8181");
+            
+            provider.stop();
+            
+            assertNotNull(w);
+            if ( w instanceof WidgetFailure)
+            {
+               WidgetFailure wf = (WidgetFailure) w;
+               if ( wf.getCause() instanceof WidgetException)
+               {
+                  WidgetFetchException fe = (WidgetFetchException) wf.getCause();
+                  // ok                  
+               }
+               else
+               {
+                  fail("Exception type must be of WidgetException");
+               }
+            }
+            else
+            {
+               fail("Widget must fail.");
+            }
+         }
+      };
+      server.performInteraction();
+   }
+
+   public void test_widget_wrong_content() throws Exception
+   {
+      AbstractSynchronizedServer server = new AbstractSynchronizedServer.AbstractReturnFileServer(8181, "google/gadget1_fail.xml")
+      {
+         protected void doClient() throws Exception
+         {
+            GGProvider provider = new GGProvider();
+            provider.start();
+
+            Widget w = provider.getWidget("http://localhost:8181");
+                       
+            provider.stop();
+            
+            assertNotNull(w);
+            if ( w instanceof WidgetFailure)
+            {
+               WidgetFailure wf = (WidgetFailure) w;
+               if ( wf.getCause() instanceof WidgetException)
+               {
+                  WidgetMetaDataParseException me = (WidgetMetaDataParseException) wf.getCause();
+                  // ok
+               }
+               else
+               {
+                  fail("Exception type must be of WidgetException");
+               }
+            }
+            else
+            {
+               fail("Widget must fail.");
+            }
+         }
+      };
+      server.performInteraction();
+   }
+   
+   public void test_widget_timeout() throws Exception
+   {
+      AbstractSynchronizedServer server = new AbstractSynchronizedServer.AbstractTimeoutServer(8181)
+      {
+         protected void doClient() throws Exception
+         {
+            GGProvider provider = new GGProvider();
+            provider.start();
+
+            Widget w = provider.getWidget("http://localhost:8181");
+ 
+            provider.stop();
+            
+            assertNotNull(w);
+            if ( w instanceof WidgetFailure)
+            {
+               WidgetFailure wf = (WidgetFailure) w;
+               if ( wf.getCause() instanceof WidgetException)
+               {
+                  WidgetFetchException fe = (WidgetFetchException) wf.getCause();
+                  // ok
+               }
+               else
+               {
+                  fail("Exception type must be of WidgetException");
+               }
+            }
+            else
+            {
+               fail("Widget must fail.");
+            }
+         }
+      };
+      server.performInteraction();
+   }
+   
+   
+   public void test_widget_no_server() throws Exception
+   {
+      GGProvider provider = new GGProvider();
+     
+      try
+      {
+         provider.start();
+         
+         Widget w = provider.getWidget("http://localhost:8181");
+         assertNotNull(w);
+         if ( w instanceof WidgetFailure)
+         {
+            WidgetFailure wf = (WidgetFailure) w;
+            if ( wf.getCause() instanceof WidgetException)
+            {
+               WidgetFetchException fe = (WidgetFetchException) wf.getCause();
+               // ok
+            }
+            else
+            {
+               fail("Exception type must be of WidgetException");
+            }
+         }
+         else
+         {
+            fail("Widget must fail.");
+         }
+      }
+      finally
+      {
+         provider.stop();
+      }
+   }
+}
+

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/netvibes/JSONBuilderTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/netvibes/JSONBuilderTestCase.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/netvibes/JSONBuilderTestCase.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -24,10 +24,15 @@
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
 import java.io.InputStream;
+import java.net.MalformedURLException;
 import java.net.URL;
 
 import org.jboss.portal.common.io.IOTools;
+import org.jboss.portal.widget.exceptions.WidgetException;
+import org.jboss.portal.widget.exceptions.WidgetNotSupportedException;
 import org.jboss.portal.widget.netvibes.NetvibesPreferenceInfo;
 import org.jboss.portal.widget.netvibes.NetvibesPreferencesInfo;
 import org.jboss.portal.widget.netvibes.NetvibesWidgetInfo;
@@ -252,20 +257,53 @@
       }
    }
 
+   public void test08()
+   {
+      try
+      {
+         ClassLoader tcl = Thread.currentThread().getContextClassLoader();
+         URL url = tcl.getResource("netvibes/json.response_fail");
+         
+         NetvibesJSONInfoBuilder builder = constructBuilder(url);
+         builder.create();
+         fail();
+      }
+      catch (WidgetException e)
+      {
+         if ( e instanceof WidgetNotSupportedException)
+         {
+            // okay
+         }
+         else
+         {
+            fail("Widget should not be supported if apiVersion < 1");
+         }
+      }
+   }
    
-   
    public NetvibesJSONInfoBuilder constructBuilder(URL url)
    {
       return new NetvibesJSONInfoBuilder(url)
       {
          @Override
-         protected byte[] obtainWidget(URL url) throws Exception
+         protected byte[] obtainWidget(URL url) throws IllegalArgumentException, MalformedURLException
          {
-            File file = new File(url.getPath());
-            InputStream io = new FileInputStream(file);
-            byte[] bytes = IOTools.getBytes(io);
-            io.close();
-            return bytes;
+            try 
+            {
+               File file = new File(url.getPath());
+               InputStream io = new FileInputStream(file);
+               byte[] bytes = IOTools.getBytes(io);
+               io.close();
+               return bytes;
+            }
+            catch(FileNotFoundException e)
+            {
+               throw new IllegalArgumentException("File not found: "+ url.toString(), e);
+            }
+            catch(IOException e)
+            {
+               throw new IllegalArgumentException("IOException while reading: "+ url.toString(), e);
+            }
          }
       };
    }

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/netvibes/NetvibesProviderTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/netvibes/NetvibesProviderTestCase.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/netvibes/NetvibesProviderTestCase.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -24,7 +24,10 @@
 
 import junit.framework.TestCase;
 
-import org.jboss.portal.widget.Widget;
+import org.jboss.portal.test.widget.support.AbstractSynchronizedServer;
+import org.jboss.portal.test.widget.support.TestQuery;
+import org.jboss.portal.widget.DirectoryQueryResult;
+import org.jboss.portal.widget.WidgetProvider;
 import org.jboss.portal.widget.netvibes.provider.NetvibesProvider;
 
 /**
@@ -34,17 +37,83 @@
 public class NetvibesProviderTestCase extends TestCase
 {
 
-   public void test01()
+   public void test01() throws Exception
    {
-      NetvibesProvider provider = new NetvibesProvider();
-      provider.start();
-      
-      Widget widget = provider.getWidget("http://www.netvibes.com/api/uwa/examples/alexa.html");
-      assertNotNull(widget);
-//      System.out.println(widget.render(new HashMap()));
-      
-      provider.stop();
+      AbstractSynchronizedServer server = new AbstractSynchronizedServer.AbstractReturnFileServer(8181, "netvibes/queryresult_1.xml")
+      {
+         protected void doClient() throws Exception
+         {
+            WidgetProvider provider = new NetvibesProvider();
+            provider.start();
+            
+            TestQuery query = new TestQuery();
+            
+            DirectoryQueryResult result = provider.search(query);
+            provider.stop();
+            
+            assertEquals(10, result.resultSize());
+         }
+         
+      };
+      server.performInteraction();
    }
    
+   
+   public void test02() throws Exception
+   {
+      AbstractSynchronizedServer server = new AbstractSynchronizedServer.AbstractReturnFileServer(8181, "netvibes/queryresult_1_fail.xml")
+      {
+         protected void doClient() throws Exception
+         {
+            WidgetProvider provider = new NetvibesProvider();
+            provider.start();
+            TestQuery query = new TestQuery();
+            
+            DirectoryQueryResult result = provider.search(query);
+            provider.stop();
+            
+            assertEquals(0, result.resultSize());
+         }
+      };
+      server.performInteraction();
+   }
+   
+   public void test03() throws Exception
+   {
+      AbstractSynchronizedServer server = new AbstractSynchronizedServer.AbstractTimeoutServer(8181)
+      {
+         protected void doClient() throws Exception
+         {
+            WidgetProvider provider = new NetvibesProvider();
+            provider.start();
+            TestQuery query = new TestQuery();
+            
+            DirectoryQueryResult result = provider.search(query);
+            provider.stop();
+            
+            assertEquals(0, result.resultSize());
+         }
+      };
+      server.performInteraction();
+   }
+   
+   
+   public void test404() throws Exception
+   {
+      AbstractSynchronizedServer server = new AbstractSynchronizedServer.Abstract404Server(8181)
+      {
+         protected void doClient() throws Exception
+         {
+            WidgetProvider provider = new NetvibesProvider();
+            provider.start();
+            TestQuery query = new TestQuery();
+            
+            DirectoryQueryResult result = provider.search(query);
+            provider.stop();
+            
+            assertEquals(0, result.resultSize());
+         }
+      };
+      server.performInteraction();
+   }
 }
-

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/netvibes/NetvibesQueryResultTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/netvibes/NetvibesQueryResultTestCase.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/netvibes/NetvibesQueryResultTestCase.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -27,6 +27,7 @@
 
 import junit.framework.TestCase;
 
+import org.jboss.portal.widget.exceptions.WidgetException;
 import org.jboss.portal.widget.netvibes.provider.NetvibesQueryResult;
 import org.jboss.portal.widget.netvibes.provider.NetvibesQueryResultBuilder;
 import org.jboss.portal.widget.netvibes.provider.NetvibesQueryResultEntry;
@@ -40,6 +41,8 @@
 
    public void test01()
    {
+      try
+      {
       URL url = this.getFileURL("netvibes/queryresult_1.xml");
       assertNotNull(url);
       NetvibesQueryResultBuilder builder = new NetvibesQueryResultBuilder(url);
@@ -90,8 +93,48 @@
       assertNotNull(entry);
       
       assertFalse(i.hasNext());
+      }
+      catch(WidgetException e)
+      {
+         e.printStackTrace();
+         fail();
+      }
    }
+   
+   public void test02()
+   {
+      try
+      {
+         URL url = this.getFileURL("netvibes/queryresult_2.xml");
+         assertNotNull(url);
+         NetvibesQueryResultBuilder builder = new NetvibesQueryResultBuilder(url);
+         NetvibesQueryResult result = builder.build(5000);
+         assertNotNull(result);
+      }
+      catch(WidgetException e)
+      {
+         e.printStackTrace();
+         fail();
+      }
+   }
 
+   public void test03_fail()
+   {
+      try
+      {
+         URL url = this.getFileURL("netvibes/queryresult_2_fail.xml");
+         assertNotNull(url);
+         NetvibesQueryResultBuilder builder = new NetvibesQueryResultBuilder(url);
+         NetvibesQueryResult result = builder.build(5000);
+         assertNotNull(result);
+         fail();
+      }
+      catch(Exception e)
+      {
+         // ok
+      }
+   }
+   
    private URL getFileURL(String filename)
    {
       return Thread.currentThread().getContextClassLoader().getResource(filename);

Deleted: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/netvibes/NetvibesWidgetRenderTestCase.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/netvibes/NetvibesWidgetRenderTestCase.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/test/widget/netvibes/NetvibesWidgetRenderTestCase.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -1,88 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat                                               *
- * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
- * contributors as indicated by the @authors tag. See the                     *
- * copyright.txt in the distribution for a full listing of                    *
- * individual contributors.                                                   *
- *                                                                            *
- * This is free software; you can redistribute it and/or modify it            *
- * under the terms of the GNU Lesser General Public License as                *
- * published by the Free Software Foundation; either version 2.1 of           *
- * the License, or (at your option) any later version.                        *
- *                                                                            *
- * This software is distributed in the hope that it will be useful,           *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
- * Lesser General Public License for more details.                            *
- *                                                                            *
- * You should have received a copy of the GNU Lesser General Public           *
- * License along with this software; if not, write to the Free                *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
- ******************************************************************************/
-package org.jboss.portal.test.widget.netvibes;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.net.URL;
-
-import junit.framework.TestCase;
-
-import org.jboss.portal.common.io.IOTools;
-import org.jboss.portal.widget.netvibes.NetvibesWidget;
-import org.jboss.portal.widget.netvibes.NetvibesWidgetInfo;
-import org.jboss.portal.widget.netvibes.provider.NetvibesJSONInfoBuilder;
-
-/**
- * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
- * @version $Revision$
- */
-public class NetvibesWidgetRenderTestCase extends TestCase
-{
-
-   public void test01()
-   {
-      try
-      {
-         NetvibesWidget widget = new NetvibesWidget(
-               new URL("http://www.netvibes.com/api/uwa/examples/alexa.html"),
-               getWidgetInfo("netvibes/json.response1")
-         );
-         assertNotNull(widget);
-//         System.out.println(widget.render(new HashMap()));
-      }
-      catch(Exception e)
-      {
-         e.printStackTrace();
-         fail();
-      }
-   }
-   
-   
-   private NetvibesWidgetInfo getWidgetInfo(String file) throws Exception
-   {
-      ClassLoader tcl = Thread.currentThread().getContextClassLoader();
-      URL url = tcl.getResource( file );
-      
-      NetvibesJSONInfoBuilder builder = constructBuilder(url);
-      return builder.create();
-   }
-   
-   public NetvibesJSONInfoBuilder constructBuilder(URL url)
-   {
-      return new NetvibesJSONInfoBuilder(url)
-      {
-         
-         protected byte[] obtainWidget(URL url) throws Exception
-         {
-            File file = new File(url.getPath());
-            InputStream io = new FileInputStream(file);
-            byte[] bytes = IOTools.getBytes(io);
-            io.close();
-            return bytes;
-         }
-      };
-   }
-}
-

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/AbstractWidgetProvider.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/AbstractWidgetProvider.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/AbstractWidgetProvider.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -22,13 +22,10 @@
  ******************************************************************************/
 package org.jboss.portal.widget;
 
+import java.net.MalformedURLException;
 import java.net.URL;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.ExecutionException;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ScheduledExecutorService;
@@ -36,6 +33,9 @@
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 
+import org.jboss.portal.widget.exceptions.DirectoryResultFailure;
+import org.jboss.portal.widget.exceptions.WidgetFailure;
+
 /**
  * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
  * @version $Revision$
@@ -45,31 +45,34 @@
 
    /** The widget entry map */
    protected ConcurrentMap<URL, ExpiringFutureTask<Widget>> entries = new ConcurrentHashMap<URL, ExpiringFutureTask<Widget>>();
-   
+
    /** The query result map */
    protected ConcurrentMap<WidgetQuery, ExpiringFutureTask<DirectoryQueryResult>> queries = new ConcurrentHashMap<WidgetQuery, ExpiringFutureTask<DirectoryQueryResult>>();
 
    /** The executor */
    protected ExecutorService executor;
-   
+
    /** The scheduled executor */
    protected ScheduledExecutorService scheduledExecutor;
-   
+
    /** The entry expiration time in millis (default: 1 day) */
    protected long entryExpiration = TimeUnit.MILLISECONDS.convert(86400, TimeUnit.SECONDS);
-   
+
    /** The query expiration time in millis (default: 15 minutes) */
    protected long queryExpiration = TimeUnit.MILLISECONDS.convert(900, TimeUnit.SECONDS);
-   
+
    /** Fetch all widgets in on the directory lookup */
    private boolean fetchWidgetsOnDirectoryLookup = false;
-   
+
    /** The connection timeout */
    protected int connectionTimeout = 5000;
-   
+
    /** Eviction thread timing */
    protected long timing = TimeUnit.MILLISECONDS.convert(60, TimeUnit.SECONDS);
 
+   /** The logger */
+   private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(WidgetProvider.class);
+
    public void start()
    {
       executor = new ThreadPoolExecutor(4, 4, 0, TimeUnit.SECONDS, new LinkedBlockingQueue());
@@ -78,7 +81,7 @@
       scheduledExecutor.scheduleAtFixedRate(new EntryEvictionThread(), timing, timing, TimeUnit.MILLISECONDS);
       scheduledExecutor.scheduleAtFixedRate(new QueryEvictionThread(), timing, timing, TimeUnit.MILLISECONDS);
    }
-   
+
    public void stop()
    {
       executor.shutdownNow();
@@ -86,12 +89,12 @@
       executor = null;
       scheduledExecutor = null;
    }
-   
+
    public long getConnectionTimeout()
    {
       return connectionTimeout;
    }
-   
+
    public void setConnectionTimeout(int connectionTimeout)
    {
       this.connectionTimeout = connectionTimeout;
@@ -101,153 +104,112 @@
    {
       this.queryExpiration = millis;
    }
-   
+
    public void setEntryExpiration(long millis)
    {
       this.entryExpiration = millis;
    }
-   
+
    public void setFetchWidgetsOnDirectoryLookup(boolean fetch)
    {
       this.fetchWidgetsOnDirectoryLookup = fetch;
    }
-   
-   /*
-   private void addWidget(URL url)
+
+   /**
+    * Abstract method for adding a directory query and submitting to the executor
+    * 
+    * @param query
+    */
+   protected abstract void addDirectoryResult(WidgetQuery query);
+
+   /**
+    * Abstract method for adding a widget url and submitting it to the executor
+    * 
+    * @param url
+    */
+   protected abstract void addWidget(URL url);
+
+   /**
+    * Get widget (instance of WidgetFailure on failure)
+    * 
+    * @param url
+    * @return Widget
+    */
+   public Widget getWidget(URL url)
    {
-      ExpiringFutureTask<Widget> ft = new ExpiringFutureTask<Widget>(entryExpiration, new WidgetMapEntry(url));
-      ExpiringFutureTask<Widget> e = entries.putIfAbsent(url, ft);
-      if (e == null)
+      addWidget(url);
+      ExpiringFutureTask<Widget> entry = entries.get(url);
+      try
       {
-         e = ft;
-         executor.submit(e);
+         return entry.get();
       }
+      catch (Exception e)
+      {
+         log.debug("Failed to get widget.", e.getCause());
+         entries.remove(entry);
+         return new WidgetFailure(url, e);
+      }
    }
-    */
-   public Widget getWidget(URL url) throws InterruptedException, ExecutionException
-   {
-      addWidget(url);
-      ExpiringFutureTask<Widget> e = entries.get(url);
-      return e.get();
-   }
-   
+
    public Widget getWidget(String string)
    {
       try
       {
          URL url = new URL(string);
+         // Get widget
          return getWidget(url);
       }
-      catch(Exception e)
+      catch (MalformedURLException e)
       {
-         return null;
+         log.debug("Failed to create widget url out of String: " + string);
+         return new WidgetFailure(null, e);
       }
    }
-   
-   /*
-   private void addDirectoryResult(WidgetQuery query)
+
+   private DirectoryQueryResult getDirectoryResult(WidgetQuery query)
    {
-      ExpiringFutureTask<DirectoryQueryResult> dt = new ExpiringFutureTask<DirectoryQueryResult>(queryExpiration, new DirectoryQueryMapEntry(query));
-      ExpiringFutureTask<DirectoryQueryResult> e = queries.putIfAbsent(query, dt);
-      if (e == null)
-      {
-         e = dt;
-         executor.submit(e);
-      }      
-   }
-   */
-   protected abstract void addDirectoryResult(WidgetQuery query);
-   
-   protected abstract void addWidget(URL url);
-   
-   private DirectoryQueryResult getDirectoryResult(WidgetQuery query) throws InterruptedException, ExecutionException
-   {
       addDirectoryResult(query);
-      ExpiringFutureTask<DirectoryQueryResult> e = queries.get(query);
-      return e.get();
-   }
-   
-   public List<Widget> getWidgets(List<URL> list)
-   {
-      if (list == null)
+      ExpiringFutureTask<DirectoryQueryResult> entry = queries.get(query);
+      try
       {
-         throw new IllegalArgumentException();
+         return entry.get();
       }
-      for(URL url : list)
+      catch (Exception e)
       {
-         addWidget(url);
+         log.debug("Failed to retreive widget directory information", e);
+         return new DirectoryResultFailure(e);
       }
-      List<Widget> widgets = new ArrayList<Widget>();
-      
-      for(URL url : list)
-      {
-         try
-         {
-            Widget widget = getWidget(url); 
-            if ( widget != null)
-            {
-               widgets.add(widget);   
-            }
-         }
-         catch( InterruptedException e )
-         {
-            // log.err
-            entries.remove(url);
-         }
-         catch( ExecutionException e )
-         {
-            // log.err
-            entries.remove(url);
-         }
-      }
-      return widgets;
    }
 
-   public List<DirectoryQueryResultEntry> search(WidgetQuery q)
+   public DirectoryQueryResult search(WidgetQuery q)
    {
       if (q == null)
       {
-         throw new IllegalArgumentException();
+         return new DirectoryResultFailure(new IllegalArgumentException("Query can not be null"));
       }
-      List<DirectoryQueryResultEntry> list = new ArrayList<DirectoryQueryResultEntry>();
-      DirectoryQueryResult result = null;
-      try
-      {
-          result = getDirectoryResult(q);
-          for(Iterator<? extends DirectoryQueryResultEntry> i = result.entries(); i.hasNext(); )
-          {
-             list.add(i.next() );
-          }
+      
+      //
+      DirectoryQueryResult result = getDirectoryResult(q);
 
-      }
-      catch(InterruptedException e)
+      if (this.fetchWidgetsOnDirectoryLookup)
       {
-         // TODO
-      }
-      catch(ExecutionException e)
-      {
-         // TODO
-      }
-      
-      if( this.fetchWidgetsOnDirectoryLookup )
-      {
-         for(URL url : result.collection())
+         for (URL url : result.collection())
          {
             // add widgets and submit to executor if necessary
             addWidget(url);
          }
       }
 
-      return list;
+      return result;
    }
-   
+
    private class EntryEvictionThread implements Runnable
    {
       public void run()
       {
-         if(entries != null && entries.size() > 0)
+         if (entries != null && entries.size() > 0)
          {
-            for(URL url : entries.keySet())
+            for (URL url : entries.keySet())
             {
                ExpiringFutureTask<Widget> w = entries.get(url);
                if (w.isExpired())
@@ -259,14 +221,14 @@
          }
       }
    }
-   
+
    private class QueryEvictionThread implements Runnable
    {
       public void run()
       {
          if (queries != null && queries.size() > 0)
          {
-            for(WidgetQuery query : queries.keySet())
+            for (WidgetQuery query : queries.keySet())
             {
                ExpiringFutureTask<DirectoryQueryResult> e = queries.get(query);
                if (e.isExpired())
@@ -278,4 +240,5 @@
          }
       }
    }
+
 }

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/DirectoryQueryResult.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/DirectoryQueryResult.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/DirectoryQueryResult.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -37,5 +37,6 @@
    
    public List<URL> collection();
    
+   public int resultSize();
 }
 

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/WidgetProvider.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/WidgetProvider.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/WidgetProvider.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -23,7 +23,6 @@
 package org.jboss.portal.widget;
 
 import java.net.URL;
-import java.util.List;
 import java.util.concurrent.ExecutionException;
 
 /**
@@ -39,10 +38,8 @@
 
    public Widget getWidget(URL url) throws InterruptedException, ExecutionException;
    
-   public List<Widget> getWidgets(List<URL> list);
+   public DirectoryQueryResult search(WidgetQuery query);
 
-   public List<DirectoryQueryResultEntry> search(WidgetQuery query);
-
    public void setConnectionTimeout(int connectionTimeout);
  
    public void setQueryExpiration(long millis);

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/WidgetQuery.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/WidgetQuery.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/WidgetQuery.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -31,23 +31,8 @@
  */
 public interface WidgetQuery
 {
-
+  
    /** . */
-//   public int getStart();
-   
-   /** . */
-//   public int getNum();
-   
-   /** . */
-//   public String getCat();
-
-   /** . */
-//   public String getQ();
-   
-   /** . */
-//   public int hashCode();
-   
-   /** . */
    public boolean equals(Object foo);
    
    /** . */

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGProvider.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGProvider.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGProvider.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -58,7 +58,7 @@
    @Override
    protected final void addDirectoryResult(WidgetQuery query)
    {
-      ExpiringFutureTask<DirectoryQueryResult> dt = new ExpiringFutureTask<DirectoryQueryResult>(queryExpiration, new GGDirectoryQueryMapEntry(query, (int) connectionTimeout));
+      ExpiringFutureTask<DirectoryQueryResult> dt = new ExpiringFutureTask<DirectoryQueryResult>(queryExpiration, new GGDirectoryQueryMapEntry(query, connectionTimeout));
       ExpiringFutureTask<DirectoryQueryResult> e = queries.putIfAbsent(query, dt);
       if (e == null)
       {

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResult.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResult.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResult.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -65,4 +65,10 @@
       }
       return list;
    }
+   
+   public int resultSize()
+   {
+      return entries.size();
+   }
+   
 }

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResultBuilder.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResultBuilder.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResultBuilder.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -25,8 +25,10 @@
 import org.jboss.portal.common.net.URLTools;
 import org.jboss.portal.common.io.IOTools;
 import org.jboss.portal.widget.WidgetQuery;
+import org.jboss.portal.widget.exceptions.WidgetException;
 import org.jboss.portal.widget.google.directory.GGWidgetDirectoryFactory;
 import org.jboss.portal.widget.google.metadata.GGWidgetMetaData;
+import org.jboss.xb.binding.JBossXBException;
 import org.jboss.xb.binding.Unmarshaller;
 import org.jboss.xb.binding.UnmarshallerFactory;
 import org.jboss.xb.binding.ObjectModelFactory;
@@ -37,9 +39,9 @@
 import java.text.NumberFormat;
 import java.util.ArrayList;
 import java.util.Iterator;
-import java.util.Collections;
 import java.util.List;
 import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.io.InputStream;
 
 /**
@@ -79,7 +81,7 @@
       this.url = url;
    }
 
-   public GGQueryResult build(int connectionTimeout)
+   public GGQueryResult build(int connectionTimeout) throws WidgetException
    {
       try
       {
@@ -107,7 +109,7 @@
          //
          if (bytes == null)
          {
-            throw new Exception("Cannot retrieve " + url);
+            throw new WidgetException("Cannot retrieve url: " + url);
          }
 
          String string = new String(bytes);
@@ -138,14 +140,15 @@
       }
       catch (SocketTimeoutException e)
       {
-         log.error("Query for google gadgets in directory failed due to timeout. Try to increase connectionTimeout initial parameter; ", e);
+         throw new WidgetException("Netvibes directory query failed due to timeout. Try to increase connectionTimeout initial parameter; ", e);
       }
-      catch (Exception e)
+      catch(JBossXBException e)
       {
-         log.error("Gadgets query failed: ", e);
+         throw new WidgetException("Failed to parse directory response.", e);
       }
-
-      //
-      return new GGQueryResult(Collections.EMPTY_LIST);
+      catch(IOException e)
+      {
+         throw new WidgetException("Failed to perform directory lookup.", e);
+      }
    }
 }

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResultEntry.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResultEntry.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResultEntry.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -25,6 +25,7 @@
 import org.jboss.portal.widget.DirectoryQueryResultEntry;
 import org.jboss.portal.widget.google.metadata.GGWidgetMetaData;
 
+import java.net.MalformedURLException;
 import java.net.URL;
 
 /**
@@ -79,7 +80,7 @@
       this.height = height;
    }
 
-   public GGQueryResultEntry(GGWidgetMetaData metadata) throws Exception
+   public GGQueryResultEntry(GGWidgetMetaData metadata) throws NumberFormatException, MalformedURLException
    {
       this.url = new URL(metadata.getLink());
       this.title = metadata.getTitle();

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetInfoBuilder.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetInfoBuilder.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetInfoBuilder.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -25,6 +25,10 @@
 import org.jboss.portal.common.xml.XMLTools;
 import org.jboss.portal.common.i18n.LocalizedString;
 import org.jboss.portal.common.net.URLTools;
+import org.jboss.portal.widget.exceptions.WidgetException;
+import org.jboss.portal.widget.exceptions.WidgetFetchException;
+import org.jboss.portal.widget.exceptions.WidgetMetaDataParseException;
+import org.jboss.portal.widget.exceptions.WidgetNotSupportedException;
 import org.jboss.portal.widget.google.type.DataType;
 import org.jboss.portal.widget.google.type.StringType;
 import org.jboss.portal.widget.google.type.LocationType;
@@ -42,6 +46,8 @@
 
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.DocumentBuilder;
+
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.text.NumberFormat;
 import java.util.Iterator;
@@ -81,24 +87,36 @@
    }
 
    /**
-    * Build the widget info from the url or return null if it is not possible.
+    * Build the widget info from the url or throws an exception if it is not possible.
+    * 
     * @return the widget info
     * @throws Exception
     */
-   public GGWidgetInfo create() throws Exception
+   public GGWidgetInfo create() throws WidgetException, MalformedURLException
    {
       long millis = System.currentTimeMillis();
       byte[] bytes = obtainWidget(url);
       // No response was obtained
       if (bytes == null)
       {
-         return null;
+         throw new WidgetFetchException("Could not retreive widget data.");
       }
 
       //
-      DocumentBuilderFactory factory = XMLTools.getDocumentBuilderFactory();
-      DocumentBuilder builder = factory.newDocumentBuilder();
-      Document doc = builder.parse(new ByteArrayInputStream(bytes));
+      DocumentBuilderFactory factory;
+      DocumentBuilder builder;
+      Document doc;
+      try
+      {
+         factory = XMLTools.getDocumentBuilderFactory();
+         builder = factory.newDocumentBuilder();
+         doc = builder.parse(new ByteArrayInputStream(bytes));
+      }
+      catch (Exception e)
+      {
+         throw new WidgetMetaDataParseException("Could not parse widget document.");
+      }
+      //
       Element moduleElt = doc.getDocumentElement();
 
       Map messagesBundle = new HashMap();
@@ -107,15 +125,15 @@
       Iterator modulePrefsEltIterator = XMLTools.getChildrenIterator(moduleElt, "ModulePrefs");
       if (modulePrefsEltIterator.hasNext())
       {
-         Element modulePrefsElt = (Element)modulePrefsEltIterator.next();
+         Element modulePrefsElt = (Element) modulePrefsEltIterator.next();
 
          Iterator localeEltIterator = XMLTools.getChildrenIterator(modulePrefsElt, "Locale");
 
          Map messages = new HashMap();
 
-         while(localeEltIterator.hasNext())
+         while (localeEltIterator.hasNext())
          {
-            Element localeElt = (Element)localeEltIterator.next();
+            Element localeElt = (Element) localeEltIterator.next();
 
             String langAttr = localeElt.getAttribute("lang");
             String countryAttr = localeElt.getAttribute("country");
@@ -147,14 +165,24 @@
                continue;
             }
 
-            DocumentBuilder bundleDocBuilder = factory.newDocumentBuilder();
-            Document bundleDoc = bundleDocBuilder.parse(new ByteArrayInputStream(bundleBytes));
+            DocumentBuilder bundleDocBuilder;
+            Document bundleDoc;
+            try
+            {
+               bundleDocBuilder = factory.newDocumentBuilder();
+               bundleDoc = bundleDocBuilder.parse(new ByteArrayInputStream(bundleBytes));
+            }
+            catch (Exception e)
+            {
+               throw new WidgetMetaDataParseException("Could not parse bundles.");
+            }
+
             Element messagebundleElt = bundleDoc.getDocumentElement();
             Iterator messagesEltIterator = XMLTools.getChildrenIterator(messagebundleElt, "msg");
 
-            while(messagesEltIterator.hasNext())
+            while (messagesEltIterator.hasNext())
             {
-               Element msgElt = (Element)messagesEltIterator.next();
+               Element msgElt = (Element) messagesEltIterator.next();
 
                String name = msgElt.getAttribute("name");
 
@@ -162,15 +190,16 @@
 
                //create value from the tag content
                NodeList nodes = msgElt.getChildNodes();
-               for (int i = 0; i < nodes.getLength(); i++) {
+               for (int i = 0; i < nodes.getLength(); i++)
+               {
                   Node n = nodes.item(i);
 
-                  if (n.getNodeType() == Element.TEXT_NODE) {
+                  if (n.getNodeType() == Element.TEXT_NODE)
+                  {
                      value.append(n.getNodeValue());
                   }
                }
 
-
                Map entries;
                if (!messages.containsKey(name))
                {
@@ -179,7 +208,7 @@
                }
                else
                {
-                  entries = (Map)messages.get(name);
+                  entries = (Map) messages.get(name);
                }
 
                entries.put(locale, value.toString());
@@ -189,16 +218,15 @@
          //Reiterate whole bundle to store LocalizedString values;
          for (Iterator iterator = messages.keySet().iterator(); iterator.hasNext();)
          {
-            String name = (String)iterator.next();
-            Map entries = (Map)messages.get(name);
+            String name = (String) iterator.next();
+            Map entries = (Map) messages.get(name);
 
-            messagesBundle.put(name, new LocalizedString(entries, Locale.ENGLISH)); 
+            messagesBundle.put(name, new LocalizedString(entries, Locale.ENGLISH));
          }
-
       }
       else
       {
-         throw new Exception(); // Basic for now
+         throw new WidgetMetaDataParseException("Could not parse widget meta data.");
       }
 
       //
@@ -206,7 +234,7 @@
       Iterator userPrefsEltIterator = XMLTools.getChildrenIterator(moduleElt, "UserPref");
       while (userPrefsEltIterator.hasNext())
       {
-         Element userPref = (Element)userPrefsEltIterator.next();
+         Element userPref = (Element) userPrefsEltIterator.next();
          String nameAttr = userPref.getAttribute("name");
          String displayNameAttr = userPref.getAttribute("display_name");
          String urlParamAttr = userPref.getAttribute("urlparam");
@@ -217,7 +245,7 @@
          // We don't support that for now
          if (urlParamAttr.length() > 0)
          {
-            throw new Exception("We don't support the attibute ("+ urlParamAttr + ") for now.");
+            throw new WidgetNotSupportedException("urlparam not supported yet.");
          }
 
          // String is default type when not specified
@@ -225,50 +253,45 @@
          if (dataTypeAttr.length() > 0)
          {
             int dataTypeOrdinal = DataType.parseDataTypeLiteral(dataTypeAttr);
-            switch(dataTypeOrdinal)
+            switch (dataTypeOrdinal)
             {
-               case DataType.HIDDEN:
+               case DataType.HIDDEN :
                   dataType = HiddenType.getInstance();
                   break;
-               case DataType.BOOL:
+               case DataType.BOOL :
                   dataType = BoolType.getInstance();
                   break;
-               case DataType.STRING:
+               case DataType.STRING :
                   dataType = StringType.getInstance();
                   break;
-               case DataType.LIST:
+               case DataType.LIST :
                   dataType = ListType.getInstance();
                   break;
-               case DataType.ENUM:
+               case DataType.ENUM :
                   Collection values = new ArrayList();
-                  for (Iterator i = XMLTools.getChildrenIterator(userPref, "EnumValue");i.hasNext();)
+                  for (Iterator i = XMLTools.getChildrenIterator(userPref, "EnumValue"); i.hasNext();)
                   {
-                     Element enumValueElt = (Element)i.next();
+                     Element enumValueElt = (Element) i.next();
                      String valueAttr = enumValueElt.getAttribute("value");
                      String displayValueAttr = enumValueElt.getAttribute("display_value");
 
-                     EnumType.Value value = new EnumType.Value(valueAttr, resolveLocalizedValue(displayValueAttr, messagesBundle));
+                     EnumType.Value value = new EnumType.Value(valueAttr, resolveLocalizedValue(displayValueAttr,
+                           messagesBundle));
                      values.add(value);
                   }
                   dataType = new EnumType(values);
                   break;
-               case DataType.LOCATION:
+               case DataType.LOCATION :
                   dataType = LocationType.getInstance();
                   break;
             }
          }
 
          //
+         GGPreferenceInfo prefInfo = new GGPreferenceInfo(nameAttr, dataType, resolveLocalizedValue(displayNameAttr,
+               messagesBundle), requiredAttr.length() > 0 ? Boolean.valueOf(requiredAttr).booleanValue() : false,
+               defaultValueAttr.length() > 0 ? defaultValueAttr : null);
 
-
-         GGPreferenceInfo prefInfo = new GGPreferenceInfo(
-            nameAttr,
-            dataType,
-            resolveLocalizedValue(displayNameAttr, messagesBundle),
-            requiredAttr.length() > 0 ? Boolean.valueOf(requiredAttr).booleanValue() : false,
-            defaultValueAttr.length() > 0 ? defaultValueAttr : null
-         );
-
          //
          if (tmp == null)
          {
@@ -285,7 +308,7 @@
       modulePrefsEltIterator = XMLTools.getChildrenIterator(moduleElt, "ModulePrefs");
       if (modulePrefsEltIterator.hasNext())
       {
-         Element modulePrefsElt = (Element)modulePrefsEltIterator.next();
+         Element modulePrefsElt = (Element) modulePrefsEltIterator.next();
          String titleAttr = modulePrefsElt.getAttribute("title");
          String directoryTitleAttr = modulePrefsElt.getAttribute("directory_title");
          String descriptionAttr = modulePrefsElt.getAttribute("description");
@@ -297,21 +320,21 @@
          LocalizedString directoryTitle = resolveLocalizedStringValue(directoryTitleAttr, messagesBundle);
          LocalizedString description = resolveLocalizedStringValue(descriptionAttr, messagesBundle);
 
-
          int width = (widthAttr != null && widthAttr.length() > 0) ? Integer.parseInt(widthAttr) : 320;
          int height = (heightAttr != null && heightAttr.length() > 0) ? Integer.parseInt(heightAttr) : 200;
-         System.out.println("fetchting & building gadget: " + url.toString() + " took: " + NumberFormat.getInstance().format((System.currentTimeMillis() - millis) / 1000.0));
+         System.out.println("fetchting & building gadget: " + url.toString() + " took: "
+               + NumberFormat.getInstance().format((System.currentTimeMillis() - millis) / 1000.0));
          return new GGWidgetInfo(title, directoryTitle, description, width, height, prefsInfo);
       }
       else
       {
-         throw new Exception(); // Basic for now
+         throw new WidgetMetaDataParseException("Could parse widget meta data.");
       }
    }
 
    private LocalizedString resolveLocalizedStringValue(String value, Map bundle)
    {
-      if(value != null)
+      if (value != null)
       {
          if (value.startsWith("__MSG_"))
          {
@@ -319,13 +342,12 @@
 
             if (bundle.containsKey(name))
             {
-               return (LocalizedString)bundle.get(name);
+               return (LocalizedString) bundle.get(name);
             }
          }
 
          return new LocalizedString(value, Locale.ENGLISH);
       }
-
       return null;
 
    }
@@ -338,17 +360,13 @@
       {
          return out.getDefaultString();
       }
-
       return null;
-
    }
 
-
-
    /**
     * needed for testing
     */
-   protected byte[] obtainWidget(URL url) throws Exception
+   protected byte[] obtainWidget(URL url) throws IllegalArgumentException
    {
       return obtainURL(url);
    }
@@ -356,12 +374,12 @@
    /**
     * needed for testing
     */
-   protected byte[] obtainLocaleBundle(URL url) throws Exception
+   protected byte[] obtainLocaleBundle(URL url) throws IllegalArgumentException
    {
       return obtainURL(url);
    }
 
-   private byte[] obtainURL(URL url) throws Exception
+   private byte[] obtainURL(URL url) throws IllegalArgumentException
    {
       return URLTools.getContent(url, 5000, 5000);
    }

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetMapEntry.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetMapEntry.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetMapEntry.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -46,25 +46,10 @@
    public Widget call() throws Exception
    {
       GGWidgetInfoBuilder builder = new GGWidgetInfoBuilder(url);
-      try
-      {
-         GGWidgetInfo info = builder.create();
-         if (info != null)
-         {
-            // expires 
-            return new GGWidget(url, info);
-         }
-         else
-         {
-            // expires
-            return null;
-         }
-      }
-      catch (Exception e)
-      {
-         // logging && expiration
-         return null;
-      }
+      GGWidgetInfo info = builder.create();
+      
+      // 
+      return new GGWidget(url, info);
    }
 }
 

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/NetvibesWidget.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/NetvibesWidget.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/NetvibesWidget.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -49,7 +49,7 @@
    private final String id; 
    
    /** The default widget height */
-   private final static String defaultHeight = "200"; 
+   private final static String defaultHeight = "215"; 
    
    /** The netvibes widget info */
    private final NetvibesWidgetInfo widgetInfo;
@@ -123,7 +123,7 @@
             }
          }
 
-         String actualHeight = tempHeight != null ? tempHeight : defaultHeight;
+         String actualHeight = tempHeight != null ? String.valueOf(Integer.valueOf(tempHeight).intValue() + 15) : defaultHeight;
          
          StringBuffer output = new StringBuffer();
          output.append("<iframe id=\"frame_"+ id +"\" frameborder=\"0\" width=\"100%\" height=\""+ actualHeight +"\" ");

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesJSONInfoBuilder.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesJSONInfoBuilder.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesJSONInfoBuilder.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -25,11 +25,16 @@
 import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 
 import org.jboss.portal.common.i18n.LocalizedString;
 import org.jboss.portal.common.net.URLTools;
 import org.jboss.portal.common.text.FastURLEncoder;
+import org.jboss.portal.widget.exceptions.WidgetException;
+import org.jboss.portal.widget.exceptions.WidgetFetchException;
+import org.jboss.portal.widget.exceptions.WidgetMetaDataParseException;
+import org.jboss.portal.widget.exceptions.WidgetNotSupportedException;
 import org.jboss.portal.widget.netvibes.NetvibesMetaData;
 import org.jboss.portal.widget.netvibes.NetvibesPreferenceInfo;
 import org.jboss.portal.widget.netvibes.NetvibesPreferencesInfo;
@@ -57,6 +62,9 @@
    /** The URL */
    private final URL url;
    
+   /** . */
+   private static final String COULD_NOT_PARSE = "/* String could not be parsed as XML */ null";
+   
    public NetvibesJSONInfoBuilder(URL url)
    {
       if ( url == null)
@@ -76,26 +84,31 @@
       return new URL(jsonUrl.toString());
    }
    
-   public NetvibesWidgetInfo create()
+   public NetvibesWidgetInfo create() throws WidgetException
    {
       try
       {
          byte[] bytes = obtainWidget(this.url); 
          if(bytes == null)
          {
-            return null;
+            throw new WidgetFetchException("Could not retreive widget: "+ url.toString());
          }
          
+         // If requested widget is not uwa conform it returns : String could not be parsed as XML 
+         if ( Arrays.equals(bytes, COULD_NOT_PARSE.getBytes()) )
+         {
+            throw new WidgetMetaDataParseException("Could not parse widget meta data: "+ url.toString());
+         }
+         
          // Create JSONObject
          JSONObject jsonResponse = new JSONObject(new String(bytes));
 
          // Getting the title
          LocalizedString title = new LocalizedString(jsonResponse.getString("title")); 
          
-         if(title == null)
+         if (title == null)
          {
-            // log unsupported format
-            return null;
+            throw new WidgetMetaDataParseException("Unsupported widget format: "+ url.toString());
          }
          
          // Getting the icons
@@ -132,6 +145,13 @@
                metadata.getBoolean("inline")
          );
          
+         // Checking UWA compatible version
+         int version = metadata.getInt("apiVersion");
+         if (version < 1)
+         {
+            throw new WidgetNotSupportedException("Not supported widget version.");
+         }
+         
          // Netvibes preferences
          List<NetvibesPreferenceInfo> preferences = new ArrayList<NetvibesPreferenceInfo>();
          JSONArray array = jsonResponse.getJSONArray("preferences");
@@ -199,13 +219,11 @@
       }
       catch(JSONException e)
       {
-         // log.error("Can not parse widget information: "+ url, e);
-         return null;
+         throw new WidgetMetaDataParseException("Could not parse widget meta data: "+ url.toString(), e);
       }
-      catch(Exception e)
+      catch(MalformedURLException e)
       {
-         // log.error("Can not obtain widget information: "+ url, e);
-         return null;
+         throw new WidgetFetchException("Unable to build url.", e);
       }
 
    }
@@ -228,16 +246,20 @@
    
    /**
     * needed for testing
+    * @throws MalformedURLException 
+    * @throws IllegalArgumentException 
     */
-   protected byte[] obtainWidget(URL url) throws Exception
+   protected byte[] obtainWidget(URL url) throws IllegalArgumentException, MalformedURLException
    {
       return obtainURL(url);
    }
 
    /**
     * creating correct url here to be able to also get local sources for testing  
+    * @throws MalformedURLException 
+    * @throws IllegalArgumentException 
     */
-   private byte[] obtainURL(URL url) throws Exception
+   private byte[] obtainURL(URL url) throws IllegalArgumentException, MalformedURLException
    {
       return URLTools.getContent(this.buildNetvibesJSONUrl(url), 5000, 5000);
    }

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesQueryResult.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesQueryResult.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesQueryResult.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -61,6 +61,11 @@
    {
       return entries.iterator();
    }
+   
+   public int resultSize()
+   {
+      return entries.size();
+   }
 
 }
 

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesQueryResultBuilder.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesQueryResultBuilder.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesQueryResultBuilder.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -23,20 +23,22 @@
 package org.jboss.portal.widget.netvibes.provider;
 
 import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.net.MalformedURLException;
 import java.net.SocketTimeoutException;
 import java.net.URL;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 
 import org.jboss.portal.common.io.IOTools;
 import org.jboss.portal.common.net.URLTools;
 import org.jboss.portal.widget.WidgetQuery;
+import org.jboss.portal.widget.exceptions.WidgetException;
 import org.jboss.portal.widget.netvibes.directory.NVEcosystemFactory;
 import org.jboss.portal.widget.netvibes.directory.NVQueryResultMetaData;
+import org.jboss.xb.binding.JBossXBException;
 import org.jboss.xb.binding.ObjectModelFactory;
 import org.jboss.xb.binding.Unmarshaller;
 import org.jboss.xb.binding.UnmarshallerFactory;
@@ -48,6 +50,7 @@
 public class NetvibesQueryResultBuilder
 {
 
+   /** . */
    private static final org.jboss.logging.Logger log = org.jboss.logging.Logger.getLogger(NetvibesQueryResultBuilder.class);
 
    /** . */
@@ -58,7 +61,7 @@
    {
       if (query == null)
       {
-         
+         throw new IllegalArgumentException("query must not be null.");
       }
       this.url = query.buildQueryURL();
    }
@@ -67,17 +70,16 @@
    {
       if (url == null)
       {
-         
+         throw new IllegalArgumentException("url must not be null.");
       }
       this.url = url;
    }
    
-   public NetvibesQueryResult build(int connectionTimeout)
+   public NetvibesQueryResult build(int connectionTimeout) throws WidgetException
    {
       try
       {
          // Read fully the URL content first
-         long millis = System.currentTimeMillis();
          byte[] bytes;
          if ("http".equals(url.getProtocol()))
          {
@@ -100,7 +102,7 @@
          //
          if (bytes == null)
          {
-            throw new Exception("Cannot retrieve " + url);
+            throw new WidgetException("Cannot retrieve url: " + url);
          }
          
          String string = new String(bytes);
@@ -126,14 +128,16 @@
       }
       catch (SocketTimeoutException e)
       {
-         log.error("Query for netvibs widget in directory failed due to timeout. Try to increase connectionTimeout initial parameter; ", e);
+         throw new WidgetException("Netvibes directory query failed due to timeout. Try to increase connectionTimeout initial parameter; ", e);
       }
-      catch(Exception e)
+      catch(JBossXBException e)
       {
-         log.error("Netvibes widget query failed: ", e);
+         throw new WidgetException("Failed to parse directory response.", e);
       }
-      return new NetvibesQueryResult(Collections.EMPTY_LIST);
-   }
-   
+      catch(IOException e)
+      {
+         throw new WidgetException("Failed to perform directory lookup.", e);
+      }
+   }  
 }
 

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesWidgetMapEntry.java
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesWidgetMapEntry.java	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesWidgetMapEntry.java	2007-11-20 13:49:23 UTC (rev 9034)
@@ -47,14 +47,9 @@
    {
       NetvibesJSONInfoBuilder builder = new NetvibesJSONInfoBuilder(url);
       NetvibesWidgetInfo info = builder.create();
-      if ( info != null )
-      {
-         return new NetvibesWidget(url, info);
-      }
-      else
-      {
-         return null;
-      }
+      
+      //
+      return new NetvibesWidget(url, info);
    }
 }
 

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/resources/portal-widget-netvibes-war/WEB-INF/jsp/edit_content.jsp
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/resources/portal-widget-netvibes-war/WEB-INF/jsp/edit_content.jsp	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/resources/portal-widget-netvibes-war/WEB-INF/jsp/edit_content.jsp	2007-11-20 13:49:23 UTC (rev 9034)
@@ -15,59 +15,66 @@
 <%@ page language="java" %>
 <%@ taglib uri="http://java.sun.com/portlet" prefix="p" %>
 <%@ page isELIgnored="false" %>
+<%@page import="org.jboss.portal.widget.Widget"%>
+<%@page import="org.jboss.portal.widget.exceptions.WidgetFailure"%>
+<%@page import="org.jboss.portal.widget.netvibes.NetvibesWidgetInfo"%>
+<%@page import="org.jboss.portal.widget.DirectoryQueryResult"%>
+<%@page import="org.jboss.portal.widget.netvibes.provider.NetvibesQueryResult"%>
+<%@page import="org.jboss.portal.widget.exceptions.DirectoryResultFailure"%>
 <p:defineObjects/>
 <div>
 <%
 	NetvibesProvider provider = (NetvibesProvider)request.getAttribute("provider");
 
-	NetvibesWidget selWidget = null;
+	Widget selWidget = null;
 	String uri = request.getParameter("content.uri");
 	if (uri != null)
 	{
-      selWidget = (NetvibesWidget) provider.getWidget(uri);
+	  selWidget = provider.getWidget(uri);
 	}
 	
-	   // Number of results to display
-	   int numberOfResults = 10;
-	   String resultSize= request.getParameter("numberOfResults");
-	   if (resultSize != null && !resultSize.equals(""))
-	   {
-	      numberOfResults = Integer.parseInt(resultSize);
-	   }
+	// Number of results to display
+	int numberOfResults = 10;
+	String resultSize= request.getParameter("numberOfResults");
+	if (resultSize != null && !resultSize.equals(""))
+	{
+		numberOfResults = Integer.parseInt(resultSize);
+	}
 
-	   // Pagination
-	   int currentPage = 0;
-	   String tempPage = request.getParameter("currentPage"); 
-	   if ( tempPage != null && !tempPage.equals(""))
-	   {
-	      int temp = Integer.parseInt(tempPage);
-	      currentPage = temp < 0 ? 0 : temp;
-	   }
+	//
+	int currentPage = 0;
+	String tempPage = request.getParameter("currentPage"); 
+	if ( tempPage != null && !tempPage.equals(""))
+	{
+		int temp = Integer.parseInt(tempPage);
+		currentPage = temp < 0 ? 0 : temp;
+	}
 	   
-	   // Get query term
-	   String queryTerm = request.getParameter("query");
-	   if (queryTerm == null)
-	   {
-	      queryTerm = "";
-	   }
-	   
-	   String type = request.getParameter("type");
-	   if (type == null)
-	   {
-	      type = "all";
-	   }
+	// Get query term
+	String queryTerm = request.getParameter("query");
+	if (queryTerm == null)
+	{
+		queryTerm = "";
+	}
+	
+	// Type
+	String type = request.getParameter("type");
+	if (type == null)
+	{
+		type = "all";
+	}
 
-	   // Get category term
-	   String catTerm = request.getParameter("cat");
-	   if (catTerm == null)
-	   {
-	      catTerm = "0"; // all
-	   }
+	// Get category term
+	String catTerm = request.getParameter("cat");
+	if (catTerm == null)
+	{
+		catTerm = "0"; // all
+	}
 
-	   // Compute query
-	   int queryStart = currentPage * numberOfResults;
-	   NetvibesQuery query = new NetvibesQuery(queryStart, numberOfResults + 1, catTerm, type, queryTerm);
-	   List queryResults = provider.search(query);
+	// Compute query
+	int queryStart = currentPage * numberOfResults;
+	NetvibesQuery query = new NetvibesQuery(queryStart, numberOfResults + 1, catTerm, type, queryTerm);
+	DirectoryQueryResult queryResults = provider.search(query);
 	   
 	boolean uriPickMethod = false;
     String nvPickMethod = request.getParameter("nv_pick_method");
@@ -96,13 +103,12 @@
    %>
    <form action="<%= contentURL %>" method="post">
       <%
-                     if (uri != null && selWidget == null)
+                     if (uri != null && selWidget instanceof WidgetFailure)
                      {
+                        WidgetFailure failure = (WidgetFailure) selWidget;
       %>
       <p style="color: red;">
-         <%
-         out.println("Failed to obtain widget with URI: " + uri);
-         %>
+         <%= failure.getLocalizedErrorMessage( request.getLocale() ) %>
       </p>
       <%
                   }
@@ -165,11 +171,42 @@
       <br/>
       <input type="submit" value="Search Widgets" class="portlet-form-button"/>&nbsp;
    </form>
-
+      <%
+                     if (uri != null && selWidget instanceof WidgetFailure)
+                     {
+                        WidgetFailure failure = (WidgetFailure) selWidget;
+      %>
+      <p style="color: red;">
+         <%= failure.getLocalizedErrorMessage( request.getLocale() ) %>
+      </p>
+      <%
+                  }
+                  else if (selWidget != null)
+                  {
+      %>
+      <p style="color: blue;">
+         Selected Widget: 
+         <%= selWidget.getTitle().getDefaultString() %>
+      </p>
+      <%
+      }
+      %>
+   
+   <% // If widget directory lookup was successful
+   	if ( queryResults == null || queryResults instanceof DirectoryResultFailure )
+   	{
+   		DirectoryResultFailure resultFailure = (DirectoryResultFailure) queryResults;
+   	   %>
+   	   <p style="color: red;"><%= resultFailure.getLocalizedErrorMessage( request.getLocale() ) %></p>
+   	   <%
+   	}
+   	else
+   	{
+   %>
    <p>
    <table style="width:100%; border: 1px solid;" cellspacing="0" cellpadding="0">
       <%
-            for (IteratorStatus i = new IteratorStatus(queryResults.iterator()); i.hasNext();)
+            for (IteratorStatus i = new IteratorStatus(queryResults.entries()); i.hasNext();)
             {
                if ( (i.getIndex() + 1) >= numberOfResults)
                {
@@ -177,7 +214,15 @@
                }
                   
                DirectoryQueryResultEntry result = (DirectoryQueryResultEntry) i.next();
-               boolean selected = selWidget != null && selWidget.getId().equals(result.getURL().toString());
+               boolean selected = false;
+               if ( selWidget != null
+                     && selWidget instanceof NetvibesWidget
+                	 && selWidget.getId().equals(result.getURL().toString())
+               )
+               {
+                  selected = true;
+               }
+               
                PortletURL selectURL = renderResponse.createActionURL();
                
                // Set parameters for selection
@@ -195,11 +240,14 @@
 
                //
                String rowClass = selected ? "portlet-section-selected" : (i.getIndex() % 2 == 0 ? "portlet-section-body" : "portlet-section-alternate");
+                  
       %>
       <tr class="<%= rowClass %>">
-         <td><a
+         <td>
+         <a
             href="<%= selectURL %>"><%= result.getTitle() %>
-         </a></td>
+         </a>
+         </td>
       </tr>
       <%
             }
@@ -226,7 +274,7 @@
    		</td>
    		<td style="text-align: right;">
    		<%  // next page
-   			if ( queryResults.size() > numberOfResults )
+   			if ( queryResults.resultSize() > numberOfResults )
    			{
 	   			PortletURL nextURL = renderResponse.createRenderURL();
 	   			nextURL.setParameter("cat", catTerm);
@@ -244,29 +292,34 @@
    	</tr>
    </table>
    </p>
+   <%
+   	} // instanceof NetvibesQueryResult
+   	%>
 
 </div>
 
 
-
 <%
-   if (selWidget != null && !selWidget.getWidgetInfo().getPreferencesInfo().getPreferences().isEmpty())
+   if (selWidget != null
+         && selWidget instanceof NetvibesWidget )
    {
-      
-      PortletURL selectURL = renderResponse.createActionURL();
+      NetvibesWidgetInfo widgetInfo = ((NetvibesWidget) selWidget).getWidgetInfo();
 
-      // Set parameters for selection
-      selectURL.setParameter("content.action.select", "content.action.select");
-      selectURL.setParameter("content.uri", selWidget.getId());
+      if (! widgetInfo.getPreferencesInfo().getPreferences().isEmpty() )
+      {
+		PortletURL selectURL = renderResponse.createActionURL();
+		// Set parameters for selection
+		selectURL.setParameter("content.action.select", "content.action.select");
+		selectURL.setParameter("content.uri", selWidget.getId());
       
 %>
 <div>
 	<p>
 	<form action="<%= selectURL %>" method="post"><%
-		for(Iterator i = selWidget.getWidgetInfo().getPreferencesInfo().getPreferences().iterator(); i.hasNext(); )
+		for(Iterator i = widgetInfo.getPreferencesInfo().getPreferences().iterator(); i.hasNext(); )
 		{
 		   // hidden preferences
-		   NetvibesPreferenceInfo prefInfo = (NetvibesPreferenceInfo) selWidget.getWidgetInfo().getPreferencesInfo().getPreference((String) i.next());
+		   NetvibesPreferenceInfo prefInfo = (NetvibesPreferenceInfo) widgetInfo.getPreferencesInfo().getPreference((String) i.next());
 		   if ( NVDataType.HIDDEN == prefInfo.getType().getOrdinal())
 		   {
 		      %><input type="hidden" name="content.param.<%= prefInfo.getName() %>"
@@ -275,10 +328,10 @@
 		 }	
 		%>
 		<table><%
-		   for(Iterator i = selWidget.getWidgetInfo().getPreferencesInfo().getPreferences().iterator(); i.hasNext(); )
+		   for(Iterator i = widgetInfo.getPreferencesInfo().getPreferences().iterator(); i.hasNext(); )
 		   {
 		   	String key = (String) i.next();
-		   	NetvibesPreferenceInfo prefInfo = (NetvibesPreferenceInfo) selWidget.getWidgetInfo().getPreferencesInfo().getPreference(key);
+		   	NetvibesPreferenceInfo prefInfo = (NetvibesPreferenceInfo) widgetInfo.getPreferencesInfo().getPreference(key);
 
 		   	int prefDataType = prefInfo.getType().getOrdinal();
 		   	// If preference is not hidden
@@ -347,5 +400,7 @@
 	</form>
 	</p>
 </div><%
+      }
 	}
-%></div>
\ No newline at end of file
+%>
+</div>
\ No newline at end of file

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/resources/portal-widget-netvibes-war/WEB-INF/portlet.xml
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/resources/portal-widget-netvibes-war/WEB-INF/portlet.xml	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/resources/portal-widget-netvibes-war/WEB-INF/portlet.xml	2007-11-20 13:49:23 UTC (rev 9034)
@@ -42,6 +42,11 @@
          <name>entryExpiration</name>
          <value>1440</value>
       </init-param>
+      <init-param>
+         <description>Time until a query expires. Default value is 15 minutes.</description>
+         <name>queryExpiration</name>
+         <value>15</value>
+      </init-param>
       <supports>
          <mime-type>text/html</mime-type>
          <portlet-mode>VIEW</portlet-mode>

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/resources/portal-widget-war/WEB-INF/jsp/edit_content.jsp
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/resources/portal-widget-war/WEB-INF/jsp/edit_content.jsp	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/resources/portal-widget-war/WEB-INF/jsp/edit_content.jsp	2007-11-20 13:49:23 UTC (rev 9034)
@@ -17,6 +17,11 @@
 <%@ taglib uri="http://java.sun.com/portlet" prefix="p" %>
 <%@ page isELIgnored="false" %>
 
+<%@page import="org.jboss.portal.widget.Widget"%>
+<%@page import="org.jboss.portal.widget.exceptions.WidgetFailure"%>
+<%@page import="org.jboss.portal.widget.google.info.GGWidgetInfo"%>
+<%@page import="org.jboss.portal.widget.DirectoryQueryResult"%>
+<%@page import="org.jboss.portal.widget.exceptions.DirectoryResultFailure"%>
 <p:defineObjects/>
 <div>
 
@@ -25,14 +30,13 @@
    GGProvider provider = (GGProvider)request.getAttribute("provider");
 
    // Get the selected widget if any
-   GGWidget selWidget = null;
+   Widget selWidget = null;
    String uri = request.getParameter("content.uri");
    if (uri != null)
    {
-      selWidget = (GGWidget) provider.getWidget(uri);
+      selWidget = provider.getWidget(uri);
    }
 
-
    // Number of results to display
    int numberOfResults = 10;
    String resultSize= request.getParameter("numberOfResults");
@@ -50,7 +54,6 @@
       currentPage = temp < 0 ? 0 : temp;
    }
    
-   
    // Get query term
    String queryTerm = request.getParameter("query");
    if (queryTerm == null)
@@ -68,7 +71,7 @@
    // Compute query
    int queryStart = currentPage * numberOfResults;
    GGQuery query = new GGQuery(queryStart, numberOfResults + 1, catTerm, queryTerm, request.getLocale());
-   List queryResults = provider.search(query);
+   DirectoryQueryResult queryResults = provider.search(query);
 
    String ggPickMethod = request.getParameter("gg_pick_method");
    boolean uriPickMethod = false;
@@ -100,22 +103,22 @@
    <form action="<%= contentURL %>" method="post">
 
       <%
-                     if (uri != null && selWidget == null)
+                     if (uri != null && selWidget instanceof WidgetFailure)
                      {
+                        WidgetFailure failure = (WidgetFailure) selWidget;
       %>
       <p style="color: red;">
-         <%
-         out.println("Failed to obtain widget with URI: " + uri);
-         %>
+         <%= failure.getLocalizedErrorMessage( request.getLocale() ) %>
       </p>
       <%
                   }
                   else if (selWidget != null)
                   {
+                     GGWidget widget = (GGWidget) selWidget; 
       %>
       <p style="color: blue;">
          Selected
-         Widget: <%=selWidget.getDirectoryTitle().getDefaultString().length() > 0 ? selWidget.getDirectoryTitle().getDefaultString() : selWidget.getTitle().getDefaultString()%>
+         Widget: <%= widget.getDirectoryTitle().getDefaultString().length() > 0 ? widget.getDirectoryTitle().getDefaultString() : widget.getTitle().getDefaultString()%>
       </p>
       <%
       }
@@ -157,12 +160,44 @@
       </select>
       <br/>
       <input type="submit" value="Search Gadgets" class="portlet-form-button"/>
+      <%
+                     if (uri != null && selWidget instanceof WidgetFailure)
+                     {
+                        WidgetFailure failure = (WidgetFailure) selWidget;
+      %>
+      <p style="color: red;">
+         <%= failure.getLocalizedErrorMessage( request.getLocale() ) %>
+      </p>
+      <%
+                  }
+                  else if (selWidget != null)
+                  {
+                     GGWidget widget = (GGWidget) selWidget; 
+      %>
+      <p style="color: blue;">
+         Selected
+         Widget: <%= widget.getDirectoryTitle().getDefaultString().length() > 0 ? widget.getDirectoryTitle().getDefaultString() : widget.getTitle().getDefaultString()%>
+      </p>
+      <%
+      }
+      %>
    </form>
 
+   <% // If widget directory lookup was successful
+   	if ( queryResults == null || queryResults instanceof DirectoryResultFailure )
+   	{
+   		DirectoryResultFailure resultFailure = (DirectoryResultFailure) queryResults;
+   	   %>
+   	   <p style="color: red;"><%= resultFailure.getLocalizedErrorMessage( request.getLocale() ) %></p>
+   	   <%
+   	}
+   	else
+   	{
+   %>
    <p>
    <table style="width:100%; border: 1px solid;" cellspacing="0" cellpadding="0">
       <%
-            for (IteratorStatus i = new IteratorStatus(queryResults.iterator()); i.hasNext();)
+            for (IteratorStatus i = new IteratorStatus(queryResults.entries()); i.hasNext();)
             {
                if ( (i.getIndex() + 1) >= numberOfResults)
                {
@@ -170,7 +205,14 @@
                }
                   
                DirectoryQueryResultEntry result = (DirectoryQueryResultEntry) i.next();
-               boolean selected = selWidget != null && selWidget.getId().equals(result.getURL().toString());
+               boolean selected = false;
+               if ( selWidget != null
+                     && selWidget instanceof GGWidget
+                	 && selWidget.getId().equals(result.getURL().toString())
+               )
+               {
+                  selected = true;
+               }
                PortletURL selectURL = renderResponse.createActionURL();
                
                // Set parameters for selection
@@ -217,7 +259,7 @@
    		</td>
    		<td style="text-align: right;">
    		<%  // next page
-   			if ( queryResults.size() > numberOfResults )
+   			if ( queryResults.resultSize() > numberOfResults )
    			{
 	   			PortletURL nextURL = renderResponse.createRenderURL();
 	   			nextURL.setParameter("cat", catTerm);
@@ -234,12 +276,20 @@
    	</tr>
    </table>
    </p>
+   <%
+   	} // instanceof GGQueryResult
+   	%>
 
+
 </div>
 <div>
 <%
-   if (selWidget != null && !selWidget.getInfo().getPreferences().getPreferences().isEmpty())
-   {
+   if (selWidget != null && selWidget instanceof GGWidget) 
+    {
+      GGWidgetInfo widgetInfo = ((GGWidget) selWidget).getInfo();
+      
+      if (! widgetInfo.getPreferences().getPreferences().isEmpty())
+      {
       PortletURL selectURL = renderResponse.createActionURL();
 
       // Set parameters for selection
@@ -262,7 +312,7 @@
 
 <form action="<%= selectURL %>" method="post">
    <%
-      for (Iterator i = selWidget.getInfo().getPreferences().getPreferences().iterator(); i.hasNext();)
+      for (Iterator i = widgetInfo.getPreferences().getPreferences().iterator(); i.hasNext();)
       {
          GGPreferenceInfo prefInfo = (GGPreferenceInfo)i.next();
          if (prefInfo.getType().getOrdinal() == DataType.HIDDEN)
@@ -278,7 +328,7 @@
    <table>
       <tbody>
          <%
-            for (Iterator i = selWidget.getInfo().getPreferences().getPreferences().iterator(); i.hasNext();)
+            for (Iterator i = widgetInfo.getPreferences().getPreferences().iterator(); i.hasNext();)
             {
                GGPreferenceInfo prefInfo = (GGPreferenceInfo)i.next();
 
@@ -344,6 +394,7 @@
 </form>
 </p>
 <%
+      }
    }
 %>
 </div>

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/resources/portal-widget-war/WEB-INF/portlet.xml
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/resources/portal-widget-war/WEB-INF/portlet.xml	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/resources/portal-widget-war/WEB-INF/portlet.xml	2007-11-20 13:49:23 UTC (rev 9034)
@@ -45,7 +45,7 @@
       <init-param>
          <description>Time until a query expires. Default value is 15 minutes.</description>
          <name>queryExpiration</name>
-         <value>900</value>
+         <value>15</value>
       </init-param>
       <supports>
          <mime-type>text/html</mime-type>

Modified: branches/JBoss_Portal_Branch_2_6/widget/src/resources/test/netvibes/json.response8
===================================================================
--- branches/JBoss_Portal_Branch_2_6/widget/src/resources/test/netvibes/json.response8	2007-11-20 01:34:26 UTC (rev 9033)
+++ branches/JBoss_Portal_Branch_2_6/widget/src/resources/test/netvibes/json.response8	2007-11-20 13:49:23 UTC (rev 9034)
@@ -1 +1,10 @@
-{"title":"Astronomy Picture of the Day","icon":{"0":"http:\/\/antwrp.gsfc.nasa.gov\/apod\/favicon.ico"},"metas":{"author":"Louis-Xavier Vignal (Netvibes)","description":"Each day a different image or photograph of our fascinating universe.","keywords":"astronomy, picture, science, spatial","inline":"true","apiVersion":"1.0","debugMode":"false"},"preferences":[]}
\ No newline at end of file
+{"title":"Astronomy Picture of the Day",
+"icon":{"0":"http:\/\/antwrp.gsfc.nasa.gov\/apod\/favicon.ico"},
+"metas":{
+"author":"Louis-Xavier Vignal (Netvibes)",
+"description":"Each day a different image or photograph of our fascinating universe.",
+"keywords":"astronomy, picture, science, spatial",
+"inline":"true",
+"apiVersion":"1.0",
+"debugMode":"false"},
+"preferences":[]}
\ No newline at end of file




More information about the portal-commits mailing list