Author: thomas.heute(a)jboss.com
Date: 2008-08-20 15:25:05 -0400 (Wed, 20 Aug 2008)
New Revision: 11721
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/netvibes/provider/NetvibesProvider.java
branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesQuery.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
Log:
JBPORTAL-2126: Netvibes API has changed, need to adapt to the new one
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 2008-08-20
19:10:21 UTC (rev 11720)
+++
branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/AbstractWidgetProvider.java 2008-08-20
19:25:05 UTC (rev 11721)
@@ -65,7 +65,7 @@
private boolean fetchWidgetsOnDirectoryLookup = false;
/** The connection timeout */
- protected int connectionTimeout = 5000;
+ protected int connectionTimeout = 10000;
/** Eviction thread timing */
protected long timing = TimeUnit.MILLISECONDS.convert(60, TimeUnit.SECONDS);
Modified:
branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesProvider.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesProvider.java 2008-08-20
19:10:21 UTC (rev 11720)
+++
branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesProvider.java 2008-08-20
19:25:05 UTC (rev 11721)
@@ -22,21 +22,27 @@
******************************************************************************/
package org.jboss.portal.widget.netvibes.provider;
+import java.net.MalformedURLException;
import java.net.URL;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import org.jboss.portal.common.util.CollectionBuilder;
+import org.jboss.portal.common.net.URLTools;
import org.jboss.portal.widget.AbstractWidgetProvider;
import org.jboss.portal.widget.DirectoryQueryResult;
import org.jboss.portal.widget.ExpiringFutureTask;
import org.jboss.portal.widget.Widget;
import org.jboss.portal.widget.WidgetQuery;
import org.jboss.portal.widget.netvibes.directory.NetvibesWidgetCategory;
+import org.jboss.portal.widget.netvibes.json.JSONArray;
+import org.jboss.portal.widget.netvibes.json.JSONException;
+import org.jboss.portal.widget.netvibes.json.JSONObject;
/**
* @author <a href="mailto:emuckenh@redhat.com">Emanuel
Muckenhuber</a>
+ * @author <a href="mailto:theute@redhat.com">Thomas Heute</a>
* @version $Revision$
*/
@@ -44,25 +50,40 @@
{
/** The netvibes categories */
- private static final Collection CATEGORIES =
Collections.unmodifiableList((List)CollectionBuilder.arrayList()
- .add(new NetvibesWidgetCategory("0", "All"))
- .add(new NetvibesWidgetCategory("4", "News"))
- .add(new NetvibesWidgetCategory("5", "Tools &
Reference"))
- .add(new NetvibesWidgetCategory("6", "Communication"))
- .add(new NetvibesWidgetCategory("7", "Arts &
Entertainment"))
- .add(new NetvibesWidgetCategory("8", "Fun & Games"))
- .add(new NetvibesWidgetCategory("9", "Shopping"))
- .add(new NetvibesWidgetCategory("10", "Sports"))
- .add(new NetvibesWidgetCategory("11", "Travels"))
- .add(new NetvibesWidgetCategory("12", "Business"))
- .add(new NetvibesWidgetCategory("13", "Lifestyle"))
- .add(new NetvibesWidgetCategory("14", "Technology"))
- .add(new NetvibesWidgetCategory("15", "Sciences"))
- .get());
+ private Collection<NetvibesWidgetCategory> categories;
- public Collection getCategories()
+ public Collection<NetvibesWidgetCategory> getCategories()
{
- return CATEGORIES;
+ if (categories == null)
+ {
+ List<NetvibesWidgetCategory> list = new
ArrayList<NetvibesWidgetCategory>();
+ try
+ {
+ URL url = new
URL("http://api.eco.netvibes.com/categories?format=json");
+ byte[] bytes = URLTools.getContent(url, connectionTimeout,
connectionTimeout);
+ // Create JSONObject
+ JSONObject jsonResponse = new JSONObject(new String(bytes));
+
+ JSONArray array = jsonResponse.getJSONArray("categories");
+
+ for (int i=0; i<array.length(); i++)
+ {
+ JSONObject object = array.getJSONObject(i);
+ list.add(new NetvibesWidgetCategory(object.getString("id"),
object.getString("label")));
+ }
+ // TODO: Do not cache forever the list of categories
+ categories = Collections.unmodifiableList(list);
+ }
+ catch (MalformedURLException e)
+ {
+ e.printStackTrace();
+ }
+ catch (JSONException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ return categories;
}
@Override
Modified:
branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesQuery.java
===================================================================
---
branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesQuery.java 2008-08-20
19:10:21 UTC (rev 11720)
+++
branches/JBoss_Portal_Branch_2_6/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesQuery.java 2008-08-20
19:25:05 UTC (rev 11721)
@@ -133,18 +133,18 @@
public URL buildQueryURL() throws MalformedURLException
{
// Building url - and only allow UWA compatible widgets (type=uwa)
- StringBuffer buffer = new
StringBuffer("http://eco.netvibes.com/rss-partner.php?synd=jboss&... +
type);
+ StringBuffer buffer = new
StringBuffer("http://api.eco.netvibes.com/search/?type=" + type);
if( start > 0 )
{
- buffer.append("&start=").append(start);
+ buffer.append("&page=").append(start);
}
if (count > 0)
{
- buffer.append("&count=").append(count);
+ buffer.append("&limit=").append(count);
}
if (cat != null)
{
- buffer.append("&cat=").append(cat);
+ buffer.append("&category=").append(cat);
}
if(sort != null)
{
@@ -152,7 +152,7 @@
}
if (q != null)
{
-
buffer.append("&q=").append(FastURLEncoder.getUTF8Instance().encode(q));
+
buffer.append("&query=").append(FastURLEncoder.getUTF8Instance().encode(q));
}
return new URL(buffer.toString());
}
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 2008-08-20
19:10:21 UTC (rev 11720)
+++
branches/JBoss_Portal_Branch_2_6/widget/src/resources/portal-widget-netvibes-war/WEB-INF/jsp/edit_content.jsp 2008-08-20
19:25:05 UTC (rev 11721)
@@ -67,12 +67,12 @@
String catTerm = request.getParameter("cat");
if (catTerm == null)
{
- catTerm = "0"; // all
+ NetvibesWidgetCategory category =
(NetvibesWidgetCategory)provider.getCategories().iterator().next();
+ catTerm = category.getId();
}
// Compute query
- int queryStart = currentPage * numberOfResults;
- NetvibesQuery query = new NetvibesQuery(queryStart, numberOfResults + 1, catTerm, sort,
queryTerm);
+ NetvibesQuery query = new NetvibesQuery(currentPage, numberOfResults, catTerm, sort,
queryTerm);
DirectoryQueryResult queryResults = provider.search(query);
boolean uriPickMethod = false;
@@ -239,7 +239,7 @@
<tr class="<%= rowClass %>">
<td>
<a
- href="<%= selectURL %>"><%= result.getTitle() %>
+ href="<%= selectURL %>"><%= (result.getTitle() != null)
? result.getTitle() : "Untitled" %>
</a>
</td>
</tr>
@@ -274,7 +274,7 @@
</td>
<td style="text-align: right;">
<% // next page
- if ( queryResults.resultSize() > numberOfResults )
+ if ( queryResults.resultSize() == numberOfResults )
{
PortletURL nextURL = renderResponse.createRenderURL();
nextURL.setParameter("cat", catTerm);
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 2008-08-20
19:10:21 UTC (rev 11720)
+++
branches/JBoss_Portal_Branch_2_6/widget/src/resources/portal-widget-netvibes-war/WEB-INF/portlet.xml 2008-08-20
19:25:05 UTC (rev 11721)
@@ -35,7 +35,7 @@
<init-param>
<description>Connection timeout when retreiving gadgets from google
directory (in milliseconds)</description>
<name>connectionTimeout</name>
- <value>5000</value>
+ <value>10000</value>
</init-param>
<init-param>
<description>Time until a Widget expires and gets refreshed (in minutes).
Default value is 6 hours.</description>