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.google.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.google.info.GGWidgetCategoryInfo;
36:
37: public final class GGProvider extends AbstractWidgetProvider {
38: /** The google categories */
39: private static final Collection CATEGORIES = Collections
40: .unmodifiableList((List) CollectionBuilder.arrayList().add(
41: new GGWidgetCategoryInfo("all", "Popular")).add(
42: new GGWidgetCategoryInfo("news", "News")).add(
43: new GGWidgetCategoryInfo("tools", "Tools")).add(
44: new GGWidgetCategoryInfo("communication",
45: "Communication")).add(
46: new GGWidgetCategoryInfo("funandgames",
47: "Fun & Games")).add(
48: new GGWidgetCategoryInfo("finance", "Finance"))
49: .add(new GGWidgetCategoryInfo("sports", "Sports"))
50: .add(
51: new GGWidgetCategoryInfo("lifestyle",
52: "Lifestyle")).add(
53: new GGWidgetCategoryInfo("technology",
54: "Technology")).add(
55: new GGWidgetCategoryInfo("politics",
56: "Politics"))
57: .add(new GGWidgetCategoryInfo("new", "New stuff"))
58: .get());
59:
60: public Collection getCategories() {
61: return CATEGORIES;
62: }
63:
64: @Override
65: protected final void addDirectoryResult(WidgetQuery query) {
66: ExpiringFutureTask<DirectoryQueryResult> dt = new ExpiringFutureTask<DirectoryQueryResult>(
67: queryExpiration, new GGDirectoryQueryMapEntry(query,
68: connectionTimeout));
69: ExpiringFutureTask<DirectoryQueryResult> e = queries
70: .putIfAbsent(query, dt);
71: if (e == null) {
72: e = dt;
73: executor.submit(e);
74: }
75: }
76:
77: @Override
78: protected final void addWidget(URL url) {
79: ExpiringFutureTask<Widget> ft = new ExpiringFutureTask<Widget>(
80: entryExpiration, new GGWidgetMapEntry(url));
81: ExpiringFutureTask<Widget> e = entries.putIfAbsent(url, ft);
82: if (e == null) {
83: e = ft;
84: executor.submit(e);
85: }
86: }
87: }
|