Author: thomas.heute(a)jboss.com
Date: 2008-08-19 13:56:52 -0400 (Tue, 19 Aug 2008)
New Revision: 11705
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/content/generic/InternalGenericContentProvider.java
branches/JBoss_Portal_Branch_2_7/widget/src/main/org/jboss/portal/widget/AbstractWidgetProvider.java
branches/JBoss_Portal_Branch_2_7/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesProvider.java
branches/JBoss_Portal_Branch_2_7/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesQuery.java
branches/JBoss_Portal_Branch_2_7/widget/src/resources/portal-widget-netvibes-war/WEB-INF/jsp/edit_content.jsp
Log:
JBPORTAL-2126: Fixed Netvibes support with the new API
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/content/generic/InternalGenericContentProvider.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/content/generic/InternalGenericContentProvider.java 2008-08-19
13:56:03 UTC (rev 11704)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/content/generic/InternalGenericContentProvider.java 2008-08-19
17:56:52 UTC (rev 11705)
@@ -250,7 +250,10 @@
}
invocation.setNavigationalState(ParametersStateString.create(parameterMap2));
- parameterMap.put(id_parameters, paramNames.toArray(new
String[paramNames.size()]));
+ if (paramNames.size() != 0)
+ {
+ parameterMap.put(id_parameters, paramNames.toArray(new
String[paramNames.size()]));
+ }
}
invocation.setPublicNavigationalState(parameterMap);
}
Modified:
branches/JBoss_Portal_Branch_2_7/widget/src/main/org/jboss/portal/widget/AbstractWidgetProvider.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/widget/src/main/org/jboss/portal/widget/AbstractWidgetProvider.java 2008-08-19
13:56:03 UTC (rev 11704)
+++
branches/JBoss_Portal_Branch_2_7/widget/src/main/org/jboss/portal/widget/AbstractWidgetProvider.java 2008-08-19
17:56:52 UTC (rev 11705)
@@ -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_7/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesProvider.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesProvider.java 2008-08-19
13:56:03 UTC (rev 11704)
+++
branches/JBoss_Portal_Branch_2_7/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesProvider.java 2008-08-19
17:56:52 UTC (rev 11705)
@@ -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_7/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesQuery.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesQuery.java 2008-08-19
13:56:03 UTC (rev 11704)
+++
branches/JBoss_Portal_Branch_2_7/widget/src/main/org/jboss/portal/widget/netvibes/provider/NetvibesQuery.java 2008-08-19
17:56:52 UTC (rev 11705)
@@ -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_7/widget/src/resources/portal-widget-netvibes-war/WEB-INF/jsp/edit_content.jsp
===================================================================
---
branches/JBoss_Portal_Branch_2_7/widget/src/resources/portal-widget-netvibes-war/WEB-INF/jsp/edit_content.jsp 2008-08-19
13:56:03 UTC (rev 11704)
+++
branches/JBoss_Portal_Branch_2_7/widget/src/resources/portal-widget-netvibes-war/WEB-INF/jsp/edit_content.jsp 2008-08-19
17:56:52 UTC (rev 11705)
@@ -67,7 +67,8 @@
String catTerm = request.getParameter("cat");
if (catTerm == null)
{
- catTerm = "0"; // all
+ NetvibesWidgetCategory category =
(NetvibesWidgetCategory)provider.getCategories().iterator().next();
+ catTerm = category.getId();
}
// Compute query
@@ -239,7 +240,7 @@
<tr class="<%= rowClass %>">
<td>
<a
- href="<%= selectURL %>"><%= result.getTitle() %>
+ href="<%= selectURL %>"><%= (result.getTitle() != null)
? result.getTitle() : "Untitled" %>
</a>
</td>
</tr>