01: /******************************************************************************
02: * JBoss, a division of Red Hat *
03: * Copyright 2006, Red Hat Middleware, LLC, and individual *
04: * contributors as indicated by the @authors tag. See the *
05: * copyright.txt in the distribution for a full listing of *
06: * individual contributors. *
07: * *
08: * This is free software; you can redistribute it and/or modify it *
09: * under the terms of the GNU Lesser General Public License as *
10: * published by the Free Software Foundation; either version 2.1 of *
11: * the License, or (at your option) any later version. *
12: * *
13: * This software is distributed in the hope that it will be useful, *
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16: * Lesser General Public License for more details. *
17: * *
18: * You should have received a copy of the GNU Lesser General Public *
19: * License along with this software; if not, write to the Free *
20: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
21: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
22: ******************************************************************************/package org.jboss.portal.widget.netvibes.provider;
23:
24: import java.net.URL;
25: import java.util.Collection;
26: import java.util.Collections;
27: import java.util.List;
28:
29: import org.jboss.portal.common.util.CollectionBuilder;
30: import org.jboss.portal.widget.AbstractWidgetProvider;
31: import org.jboss.portal.widget.DirectoryQueryResult;
32: import org.jboss.portal.widget.ExpiringFutureTask;
33: import org.jboss.portal.widget.Widget;
34: import org.jboss.portal.widget.WidgetQuery;
35: import org.jboss.portal.widget.netvibes.directory.NetvibesWidgetCategory;
36:
37: /**
38: * @author <a href="mailto:emuckenh@redhat.com">Emanuel Muckenhuber</a>
39: * @version $Revision$
40: */
41:
42: public class NetvibesProvider extends AbstractWidgetProvider {
43:
44: /** The netvibes categories */
45: private static final Collection CATEGORIES = Collections
46: .unmodifiableList((List) CollectionBuilder
47: .arrayList()
48: .add(new NetvibesWidgetCategory("0", "All"))
49: .add(new NetvibesWidgetCategory("4", "News"))
50: .add(
51: new NetvibesWidgetCategory("5",
52: "Tools & Reference"))
53: .add(
54: new NetvibesWidgetCategory("6",
55: "Communication"))
56: .add(
57: new NetvibesWidgetCategory("7",
58: "Arts & Entertainment"))
59: .add(new NetvibesWidgetCategory("8", "Fun & Games"))
60: .add(new NetvibesWidgetCategory("9", "Shopping"))
61: .add(new NetvibesWidgetCategory("10", "Sports"))
62: .add(new NetvibesWidgetCategory("11", "Travels"))
63: .add(new NetvibesWidgetCategory("12", "Business"))
64: .add(new NetvibesWidgetCategory("13", "Lifestyle"))
65: .add(new NetvibesWidgetCategory("14", "Technology"))
66: .add(new NetvibesWidgetCategory("15", "Sciences"))
67: .get());
68:
69: public Collection getCategories() {
70: return CATEGORIES;
71: }
72:
73: @Override
74: protected void addDirectoryResult(WidgetQuery query) {
75: ExpiringFutureTask<DirectoryQueryResult> dt = new ExpiringFutureTask<DirectoryQueryResult>(
76: queryExpiration, new NetvibesDirectoryQueryMapEntry(
77: query, connectionTimeout));
78: ExpiringFutureTask<DirectoryQueryResult> e = queries
79: .putIfAbsent(query, dt);
80: if (e == null) {
81: e = dt;
82: executor.submit(e);
83: }
84: }
85:
86: @Override
87: protected void addWidget(URL url) {
88: ExpiringFutureTask<Widget> ft = new ExpiringFutureTask<Widget>(
89: entryExpiration, new NetvibesWidgetMapEntry(url));
90: ExpiringFutureTask<Widget> e = entries.putIfAbsent(url, ft);
91: if (e == null) {
92: e = ft;
93: executor.submit(e);
94: }
95: }
96: }
|