Author: julien(a)jboss.com
Date: 2007-03-07 09:18:05 -0500 (Wed, 07 Mar 2007)
New Revision: 6573
Added:
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/GenericContent.java
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/GenericContentHandler.java
trunk/widget/src/main/org/jboss/portal/widget/Widget.java
trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
trunk/widget/src/main/org/jboss/portal/widget/WidgetProvider.java
trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidget.java
trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetFactory.java
trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetProvider.java
trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetRetrieval.java
trunk/widget/src/resources/widget-war/
trunk/widget/src/resources/widget-war/WEB-INF/
trunk/widget/src/resources/widget-war/WEB-INF/portlet-instances.xml
trunk/widget/src/resources/widget-war/WEB-INF/portlet.xml
trunk/widget/src/resources/widget-war/WEB-INF/web.xml
Removed:
trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetPortlet.java
trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetPortletInvoker.java
trunk/widget/src/resources/widget-invoker-sar/
Modified:
trunk/common/src/main/org/jboss/portal/common/util/Tools.java
trunk/core-cms/src/resources/portal-cms-sar/META-INF/jboss-service.xml
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/AbstractContentRenderer.java
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/GenericPortletContentRenderer.java
trunk/core/src/main/org/jboss/portal/core/model/content/ContentType.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderWindowCommand.java
trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
trunk/widget/build.xml
Log:
- added generic support for content portlet
- redone the google widget thing to integrate with new content contracts
Modified: trunk/common/src/main/org/jboss/portal/common/util/Tools.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/Tools.java 2007-03-07 03:44:28 UTC
(rev 6572)
+++ trunk/common/src/main/org/jboss/portal/common/util/Tools.java 2007-03-07 14:18:05 UTC
(rev 6573)
@@ -178,8 +178,35 @@
}
/**
- * Pipe an input stream in an output stream.
+ * @see #getBytes(java.io.InputStream, int)
+ * @param in the input stream
+ * @return the bytes read from the stream
+ * @throws IOException
+ * @throws IllegalArgumentException if the input stream is null
+ */
+ public static byte[] getBytes(InputStream in) throws IOException,
IllegalArgumentException
+ {
+ return getBytes(in, DEFAULT_BUFFER_SIZE);
+ }
+
+ /**
+ * Get the bytes from the provided input stream. No attempt will be made to close the
stream.
*
+ * @param in the input stream
+ * @param bufferSize the buffer size used to copy the bytes
+ * @return the bytes read from the stream
+ * @throws IOException
+ * @throws IllegalArgumentException if the input stream is null or the buffer size
< 1
+ */
+ public static byte[] getBytes(InputStream in, int bufferSize) throws IOException,
IllegalArgumentException
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ copy(in, out, bufferSize);
+ return out.toByteArray();
+ }
+
+ /**
+ * @see #copy(java.io.InputStream, java.io.OutputStream, int)
* @param in the incoming stream
* @param out the outcoming stream
* @throws IllegalArgumentException if an argument is null
@@ -190,7 +217,8 @@
}
/**
- * Pipe an incoming stream in an outcoming stream.
+ * Pipe an incoming stream in an outcoming stream until no bytes is available from the
input stream.
+ * No attempts will be made to close the streams.
*
* @param in the incoming stream
* @param out the outcoming stream
Added:
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/GenericContent.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/GenericContent.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/GenericContent.java 2007-03-07
14:18:05 UTC (rev 6573)
@@ -0,0 +1,74 @@
+/******************************************************************************
+ * 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.core.impl.model.content.generic;
+
+import org.jboss.portal.core.model.content.Content;
+import org.jboss.portal.core.model.content.spi.ContentState;
+import org.jboss.portal.core.impl.model.content.portlet.PortletContentHandler;
+import org.jboss.portal.common.util.LocalizedString;
+
+import java.util.Locale;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class GenericContent implements Content
+{
+
+ /** . */
+ private final ContentState state;
+
+ /** . */
+ private final GenericContentHandler handler;
+
+ /** . */
+ private final String contextId;
+
+ public GenericContent(GenericContentHandler handler, String contextId, ContentState
state)
+ {
+ this.handler = handler;
+ this.contextId = contextId;
+ this.state = state;
+ }
+
+ public LocalizedString getDisplayName()
+ {
+ return new LocalizedString(state.getURI() + " portlet", Locale.ENGLISH);
+ }
+
+ public boolean isMutable()
+ {
+ return true;
+ }
+
+ public String getURI()
+ {
+ return state.getURI();
+ }
+
+ public void setURI(String uri)
+ {
+ state.setURI(uri);
+ }
+}
Added:
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/GenericContentHandler.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/GenericContentHandler.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/content/generic/GenericContentHandler.java 2007-03-07
14:18:05 UTC (rev 6573)
@@ -0,0 +1,40 @@
+/******************************************************************************
+ * 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.core.impl.model.content.generic;
+
+import org.jboss.portal.core.impl.model.content.AbstractContentHandler;
+import org.jboss.portal.core.model.content.spi.ContentHandler;
+import org.jboss.portal.core.model.content.spi.ContentState;
+import org.jboss.portal.core.model.content.Content;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class GenericContentHandler extends AbstractContentHandler implements
ContentHandler
+{
+ public Content newContent(String contextId, ContentState state)
+ {
+ return new GenericContent(this, contextId, state);
+ }
+}
Modified: trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java 2007-03-07
03:44:28 UTC (rev 6572)
+++ trunk/core/src/main/org/jboss/portal/core/impl/model/portal/WindowImpl.java 2007-03-07
14:18:05 UTC (rev 6573)
@@ -230,7 +230,16 @@
ContentType contentType = getContentType();
//
- return context.getContentHandler(contentType);
+ ContentHandler handler = context.getContentHandler(contentType);
+
+ //
+ if (handler == null)
+ {
+ handler = context.getContentHandler(ContentType.GENERIC);
+ }
+
+ //
+ return handler;
}
}
}
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/AbstractContentRenderer.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/AbstractContentRenderer.java 2007-03-07
03:44:28 UTC (rev 6572)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/AbstractContentRenderer.java 2007-03-07
14:18:05 UTC (rev 6573)
@@ -63,6 +63,11 @@
this.registry = registry;
}
+ public ContentType getRegisteredContentType()
+ {
+ return registeredContentType;
+ }
+
protected void startService() throws Exception
{
registeredContentType = ContentType.create(contentType);
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/GenericPortletContentRenderer.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/GenericPortletContentRenderer.java 2007-03-07
03:44:28 UTC (rev 6572)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/content/GenericPortletContentRenderer.java 2007-03-07
14:18:05 UTC (rev 6573)
@@ -28,7 +28,9 @@
import org.jboss.portal.core.model.portal.Window;
import org.jboss.portal.core.model.portal.PortalObjectId;
import org.jboss.portal.core.model.content.Content;
+import org.jboss.portal.core.model.content.ContentType;
import org.jboss.portal.core.controller.ControllerContext;
+import org.jboss.portal.core.impl.model.content.ContentEditorRegistry;
import org.jboss.portal.portlet.PortletParametersStateString;
import org.jboss.portal.Mode;
import org.jboss.portal.theme.page.WindowResult;
@@ -75,9 +77,27 @@
protected Instance findInstance(RenderWindowCommand cmd)
{
- ControllerContext context = cmd.getControllerContext();
- InstanceContainer container = context.getController().getInstanceContainer();
- return container.getDefinition(instanceName);
+ String id = instanceName;
+
+ //
+ if (id == null)
+ {
+ Window window = cmd.getWindow();
+ ContentType contentType = window.getContentType();
+ id = ContentEditorRegistry.getInstance().getEditor(contentType);
+ }
+
+ //
+ if (id != null)
+ {
+ ControllerContext context = cmd.getControllerContext();
+ InstanceContainer container = context.getController().getInstanceContainer();
+ return container.getDefinition(id);
+ }
+ else
+ {
+ return null;
+ }
}
public Object renderWindow(RenderWindowCommand cmd) throws Exception
@@ -86,11 +106,17 @@
Window window = cmd.getWindow();
PortalObjectId windowId = window.getId();
+ // No content
+ Content content = window.getContent();
+ if (content == null)
+ {
+ return null;
+ }
+
// Initialize the navigational state with the URI when needed
PortletParametersStateString navigationalState =
(PortletParametersStateString)context.getAttribute(RenderWindowCommand.NAVIGATIONAL_STATE_SCOPE,
windowId);
if (navigationalState == null)
{
- Content content = window.getContent();
String uri = content.getURI();
navigationalState = new PortletParametersStateString();
navigationalState.setValue("uri", uri);
Modified: trunk/core/src/main/org/jboss/portal/core/model/content/ContentType.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/content/ContentType.java 2007-03-07
03:44:28 UTC (rev 6572)
+++ trunk/core/src/main/org/jboss/portal/core/model/content/ContentType.java 2007-03-07
14:18:05 UTC (rev 6573)
@@ -43,6 +43,9 @@
public static final ContentType PORTLET = new ContentType("portlet");
/** . */
+ public static final ContentType GENERIC = new ContentType("generic");
+
+ /** . */
private final String value;
private ContentType(String value)
@@ -91,6 +94,10 @@
{
return PORTLET;
}
+ else if ("generic".equals(value))
+ {
+ return GENERIC;
+ }
else if ("cms".equals(value))
{
return CMS;
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderWindowCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderWindowCommand.java 2007-03-07
03:44:28 UTC (rev 6572)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderWindowCommand.java 2007-03-07
14:18:05 UTC (rev 6573)
@@ -75,13 +75,18 @@
public Object execute() throws ControllerException
{
ContentRendererRegistry registry =
context.getController().getContentRendererRegistry();
-
ContentType contentType = window.getContentType();
-
ContentRenderer renderer = registry.getRenderer(contentType);
+ // Try generic renderer
if (renderer == null)
{
+ renderer = registry.getRenderer(ContentType.GENERIC);
+ }
+
+ //
+ if (renderer == null)
+ {
return null;
}
else
Modified: trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2007-03-07
03:44:28 UTC (rev 6572)
+++ trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2007-03-07
14:18:05 UTC (rev 6573)
@@ -563,6 +563,17 @@
proxy-type="attribute">portal:container=Instance</depends>
<attribute name="ContentType">portlet</attribute>
</mbean>
+ <mbean
+
code="org.jboss.portal.core.impl.model.content.generic.GenericContentHandler"
+ name="portal:service=ContentHandler,type=generic"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <xmbean/>
+ <depends
+ optional-attribute-name="Registry"
+
proxy-type="attribute">portal:container=PortalObject</depends>
+ <attribute name="ContentType">generic</attribute>
+ </mbean>
<!-- Customization manager -->
<mbean
@@ -943,6 +954,21 @@
optional-attribute-name="CustomizationManager"
proxy-type="attribute">portal:service=CustomizationManager</depends>
</mbean>
+ <mbean
+
code="org.jboss.portal.core.impl.model.portal.content.GenericPortletContentRenderer"
+ name="portal:service=ContentRenderer,type=generic"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <xmbean/>
+ <attribute name="ContentType">generic</attribute>
+ <attribute name="DecorateContent">true</attribute>
+ <depends
+ optional-attribute-name="Registry"
+
proxy-type="attribute">portal:service=ContentRendererRegistry</depends>
+ <depends
+ optional-attribute-name="CustomizationManager"
+
proxy-type="attribute">portal:service=CustomizationManager</depends>
+ </mbean>
<!-- The core controller -->
<mbean
Modified: trunk/core-cms/src/resources/portal-cms-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/core-cms/src/resources/portal-cms-sar/META-INF/jboss-service.xml 2007-03-07
03:44:28 UTC (rev 6572)
+++ trunk/core-cms/src/resources/portal-cms-sar/META-INF/jboss-service.xml 2007-03-07
14:18:05 UTC (rev 6573)
@@ -687,7 +687,6 @@
<xmbean/>
<attribute name="ContentType">cms</attribute>
<attribute name="DecorateContent">false</attribute>
- <attribute
name="InstanceName">CMSPortletInstance</attribute>
<depends
optional-attribute-name="Registry"
proxy-type="attribute">portal:service=ContentRendererRegistry</depends>
Modified: trunk/widget/build.xml
===================================================================
--- trunk/widget/build.xml 2007-03-07 03:44:28 UTC (rev 6572)
+++ trunk/widget/build.xml 2007-03-07 14:18:05 UTC (rev 6573)
@@ -89,12 +89,14 @@
&libraries;
<path id="library.classpath">
<path refid="jbossas/core.libs.classpath"/>
+ <path refid="jboss/backport.concurrent.classpath"/>
<path refid="apache.log4j.classpath"/>
</path>
<!-- Configure modules -->
<call target="configure-modules"/>
<path id="dependentmodule.classpath">
+ <path refid="jboss.portlet-api.classpath"/>
<path refid="jboss.portal-common.classpath"/>
<path refid="jboss.portal-jems.classpath"/>
<path refid="jboss.portal-server.classpath"/>
@@ -145,13 +147,23 @@
description="Generate all target output."
depends="compile">
- <!-- widget-invoker-lib.jar -->
+ <!-- widget-lib.jar -->
<mkdir dir="${build.lib}"/>
- <jar jarfile="${build.lib}/widget-invoker-lib.jar">
+ <jar jarfile="${build.lib}/widget-lib.jar">
<fileset dir="${build.classes}"/>
</jar>
+ <!-- widget.war -->
+ <mkdir dir="${build.resources}/widget-war/WEB-INF/lib"/>
+ <copy todir="${build.resources}/widget-war/WEB-INF/lib">
+ <fileset dir="${build.lib}"
includes="widget-lib.jar"/>
+ </copy>
+ <jar jarfile="${build.lib}/widget.war">
+ <fileset dir="${build.resources}/widget-war"/>
+ </jar>
+
<!-- widget-invoker.sar -->
+<!--
<mkdir dir="${build.resources}/widget-invoker-sar/lib"/>
<copy todir="${build.resources}/widget-invoker-sar/lib">
<fileset dir="${build.lib}"
includes="widget-invoker-lib.jar"/>
@@ -159,6 +171,7 @@
<jar jarfile="${build.lib}/widget-invoker.sar">
<fileset dir="${build.resources}/widget-invoker-sar"/>
</jar>
+-->
</target>
<!-- ================================================================== -->
@@ -197,14 +210,14 @@
description="Deploy."
depends="output">
<require file="${jboss.home}/server/${portal.deploy.dir}"/>
- <copy file="${build.lib}/widget-invoker.sar"
todir="${jboss.home}/server/${portal.deploy.dir}"/>
+ <copy file="${build.lib}/widget.war"
todir="${jboss.home}/server/${portal.deploy.dir}"/>
</target>
<target name="undeploy"
description="Undeploy."
depends="init">
<require file="${jboss.home}/server/${portal.deploy.dir}"/>
- <delete
file="${jboss.home}/server/${portal.deploy.dir}/widget-invoker.sar"/>
+ <delete
file="${jboss.home}/server/${portal.deploy.dir}/widget.war"/>
</target>
</project>
Added: trunk/widget/src/main/org/jboss/portal/widget/Widget.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/Widget.java (rev
0)
+++ trunk/widget/src/main/org/jboss/portal/widget/Widget.java 2007-03-07 14:18:05 UTC (rev
6573)
@@ -0,0 +1,42 @@
+/******************************************************************************
+ * 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.widget;
+
+import org.jboss.portal.common.util.LocalizedString;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface Widget
+{
+
+ String getId();
+
+ LocalizedString getTitle();
+
+ LocalizedString getDescription();
+
+ String render();
+
+}
Added: trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
(rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-07 14:18:05
UTC (rev 6573)
@@ -0,0 +1,113 @@
+/******************************************************************************
+ * 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.widget;
+
+import org.jboss.portal.widget.google.GoogleWidgetProvider;
+
+import javax.portlet.GenericPortlet;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.PortletException;
+import javax.portlet.PortletSecurityException;
+import javax.portlet.PortletURL;
+import javax.portlet.PortletMode;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class WidgetPortlet extends GenericPortlet
+{
+
+ /** . */
+ private static final PortletMode VIEW_CONTENT_MODE = new
PortletMode("view_content");
+
+ /** . */
+ private static final PortletMode EDIT_CONTENT_MODE = new
PortletMode("edit_content");
+
+ /** . */
+ private GoogleWidgetProvider provider = new GoogleWidgetProvider();
+
+ public void init() throws PortletException
+ {
+ provider.start();
+ }
+
+
+ public void processAction(ActionRequest req, ActionResponse resp) throws
PortletException, PortletSecurityException, IOException
+ {
+ }
+
+ public void render(RenderRequest req, RenderResponse resp) throws PortletException,
PortletSecurityException, IOException
+ {
+ if (VIEW_CONTENT_MODE.equals(req.getPortletMode()))
+ {
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+ String uri = req.getParameter("uri");
+ Widget widget = provider.getWidget(uri);
+ if (widget != null)
+ {
+ writer.print(widget.render());
+ }
+ else
+ {
+ writer.print("Widget is not available");
+ }
+ writer.close();
+ }
+ else if (EDIT_CONTENT_MODE.equals(req.getPortletMode()))
+ {
+ resp.setContentType("text/html");
+ PrintWriter writer = resp.getWriter();
+ Collection widgets = provider.getKeys();
+ writer.print("<ul>");
+ int size = 0;
+ for (Iterator i = widgets.iterator();i.hasNext() && size < 9;size++)
+ {
+ String key = (String)i.next();
+ Widget widget = provider.getWidget(key);
+ if (widget != null)
+ {
+ PortletURL url = resp.createActionURL();
+ url.setParameter("meta_action", "select");
+ url.setParameter("uri", widget.getId());
+ writer.print("<li><a href=\"" + url +
"\">" + widget.getTitle().getDefaultString() +
"</a></li>");
+ }
+ }
+ writer.print("/<ul>");
+ writer.close();
+ }
+ }
+
+ public void destroy()
+ {
+ provider.stop();
+ }
+}
Added: trunk/widget/src/main/org/jboss/portal/widget/WidgetProvider.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/WidgetProvider.java
(rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/WidgetProvider.java 2007-03-07 14:18:05
UTC (rev 6573)
@@ -0,0 +1,38 @@
+/******************************************************************************
+ * 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.widget;
+
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface WidgetProvider
+{
+
+ Collection getKeys();
+
+ Widget getWidget(String key);
+
+}
Added: trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidget.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidget.java
(rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidget.java 2007-03-07
14:18:05 UTC (rev 6573)
@@ -0,0 +1,157 @@
+/******************************************************************************
+ * 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.widget.google;
+
+import org.jboss.portal.common.util.LocalizedString;
+import org.jboss.portal.common.util.UUIDGenerator;
+import org.jboss.portal.widget.Widget;
+
+/**
+ * Getting list :
+ *
http://www.google.com/ig/directory?synd=open
+ *
+ * synd=open -> mandatory to get the embedable widgets
+ * &source=gghp ????
+ *
+ * &start= default=0 [->sa=N ??? ]
+ * &num= default=24
+ * &cat= default=all
(popular|news|tools|communication|funandgames|finance|sports|lifestyle|technology|new)
+ *
+ * <Module>
+ * <ModulePrefs
+ * title=""
+ * author=""
+ * author_email=""
+ * author_affiliation=""
+ * author_location=""
+ * screenshot=""
+ * thumbnail=""
+ * category=""
+ * description=""
+ * render_inline="optional"
+ * height=""
+ * scaling="true|false"
+ * scrolling="true|false">
+ * <UserPref
+ * name=""
+ * display_name=""
+ * default_value=""/>
+ *
+ * Getting javascript :
+ *
+ *
http://gmodules.com/ig/ifr?url=
+ * up_color=blue
+ * synd=open
+ * w=554
+ * h=205
+ * title=Date+%26+Time
+ * border=%23ffffff%7C3px%2C1px+solid+%23999999
+ * output=js
+ * +
+ * up_ + user pref name = value
+ *
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class GoogleWidget implements Widget
+{
+
+ /** . */
+ private static final UUIDGenerator generator = new UUIDGenerator();
+
+ /** . */
+ private final String url;
+
+ /** . */
+ private final LocalizedString title;
+
+ /** . */
+ private final LocalizedString description;
+
+ /** . */
+ private final int width;
+
+ /** . */
+ private final int height;
+
+ public GoogleWidget(String url,
+ LocalizedString title,
+ LocalizedString description,
+ int width,
+ int height)
+ {
+ this.url = url;
+ this.title = title;
+ this.description = description;
+ this.width = width;
+ this.height = height;
+ }
+
+ public String getId()
+ {
+ return url;
+ }
+
+ public LocalizedString getTitle()
+ {
+ return title;
+ }
+
+ public LocalizedString getDescription()
+ {
+ return description;
+ }
+
+ public String render()
+ {
+ String id = generator.generateKey();
+ String tmp = "http://gmodules.com/ig/ifr?url=" + url +
+ "&synd=open" +
+ "&w=" + width +
+ "&h=" + height +
+ "&title=" + title.getDefaultString() +
+// "&border=%23ffffff%7C3px%2C1px+solid+%23999999" +
+ "&border=%23ffffff%7C3px%2C1px+none+%23999999" +
+ "&output=js";
+
+ String clipper = "" +
+ "(function(){\n" +
+ "var a = document.getElementById('" + id + "');\n"
+
+ "var b = a.childNodes.item(2);\n" + // table
+ "var c = b.childNodes.item(0);\n" + // tbody
+ "var d = c.childNodes.item(0);\n" + // tr
+ "var e = c.childNodes.item(1);\n" + // tr
+ "var f = c.childNodes.item(3);\n" + // tr
+ "c.removeChild(d);\n" +
+ "c.removeChild(e);\n" +
+ "c.removeChild(f);\n" +
+ "})();";
+
+ return "<div id=\"" + id + "\">\n" +
+ "<script src=\"" + tmp +
"\"></script>\n" +
+ "<script>" + clipper + "</script>\n" +
+ "</div>\n";
+ }
+
+
+}
Added: trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetFactory.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetFactory.java
(rev 0)
+++
trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetFactory.java 2007-03-07
14:18:05 UTC (rev 6573)
@@ -0,0 +1,80 @@
+/******************************************************************************
+ * 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.widget.google;
+
+import org.jboss.portal.common.util.XML;
+import org.jboss.portal.common.util.LocalizedString;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.DocumentBuilder;
+import java.net.URL;
+import java.util.Iterator;
+import java.util.Locale;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class GoogleWidgetFactory
+{
+
+ /** . */
+ private final URL url;
+
+ public GoogleWidgetFactory(URL url)
+ {
+ if (url == null)
+ {
+ throw new IllegalArgumentException("No null URL");
+ }
+ this.url = url;
+ }
+
+ public URL getURL()
+ {
+ return url;
+ }
+
+ public GoogleWidget create() throws Exception
+ {
+ DocumentBuilderFactory factory = XML.getDocumentBuilderFactory();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.parse(url.toString());
+ Element moduleElt = doc.getDocumentElement();
+ Iterator modulePrefsEltIterator = XML.getChildrenIterator(moduleElt,
"ModulePrefs");
+ Element modulePrefsElt = (Element)modulePrefsEltIterator.next();
+ String titleAttr = modulePrefsElt.getAttribute("title");
+ String descriptionAttr = modulePrefsElt.getAttribute("description");
+ String widthAttr = modulePrefsElt.getAttribute("width");
+ String heightAttr = modulePrefsElt.getAttribute("height");
+
+
+ LocalizedString title = titleAttr != null ? new LocalizedString(titleAttr,
Locale.ENGLISH) : null;
+ LocalizedString description = descriptionAttr != null ? new
LocalizedString(descriptionAttr, Locale.ENGLISH) : null;
+ int width = (widthAttr != null && widthAttr.length() > 0) ?
Integer.parseInt(widthAttr) : 320;
+ int height = (heightAttr != null && heightAttr.length() > 0) ?
Integer.parseInt(heightAttr) : 200;
+ return new GoogleWidget(url.toString(), title, description, width, height);
+ }
+}
Deleted: trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetPortlet.java
===================================================================
---
trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetPortlet.java 2007-03-07
03:44:28 UTC (rev 6572)
+++
trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetPortlet.java 2007-03-07
14:18:05 UTC (rev 6573)
@@ -1,153 +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.widget.google;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.jboss.portal.common.util.XML;
-import org.jboss.portal.portlet.Portlet;
-import org.jboss.portal.portlet.PortletContext;
-import org.jboss.portal.portlet.support.info.MetaInfoSupport;
-import org.jboss.portal.portlet.support.info.SessionInfoSupport;
-import org.jboss.portal.portlet.support.info.CacheInfoSupport;
-import org.jboss.portal.portlet.support.info.SecurityInfoSupport;
-import org.jboss.portal.portlet.support.info.PreferencesInfoSupport;
-import org.jboss.portal.portlet.support.info.CapabilitiesInfoSupport;
-import org.jboss.portal.portlet.info.PortletInfo;
-import org.jboss.portal.portlet.info.CapabilitiesInfo;
-import org.jboss.portal.portlet.info.PreferencesInfo;
-import org.jboss.portal.portlet.info.MetaInfo;
-import org.jboss.portal.portlet.info.SecurityInfo;
-import org.jboss.portal.portlet.info.CacheInfo;
-import org.jboss.portal.portlet.info.SessionInfo;
-
-import java.util.Iterator;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class GoogleWidgetPortlet implements Portlet
-{
-
- /** . */
- private final String id;
-
- /** . */
- private final String title;
-
- /** . */
- private final String description;
-
- /** . */
- private final Info info;
-
- /** . */
- private final String content;
-
- public GoogleWidgetPortlet(String id, Document widgetDoc)
- {
- this.id = id;
- this.info = new Info();
-
- Element moduleElt = widgetDoc.getDocumentElement();
- Iterator modulePrefsEltIterator = XML.getChildrenIterator(moduleElt,
"ModulePrefs");
- Element modulePrefsElt = (Element)modulePrefsEltIterator.next();
-
- this.title = modulePrefsElt.getAttribute("title");
- this.description = modulePrefsElt.getAttribute("description");
-
- Iterator contentEltIterator = XML.getChildrenIterator(moduleElt,
"Content");
- Element contentElt = (Element)contentEltIterator.next();
-
- this.content = XML.asString(contentElt);
- }
-
-
- public PortletContext getContext()
- {
- return PortletContext.createPortletContext(id);
- }
-
- public PortletInfo getInfo()
- {
- return info;
- }
-
- public boolean isRemote()
- {
- return false;
- }
-
- public String getContent()
- {
- return content;
- }
-
- public String getTitle()
- {
- return title;
- }
-
- private class Info implements PortletInfo
- {
- public CapabilitiesInfo getCapabilities()
- {
- return new CapabilitiesInfoSupport();
- }
-
- public PreferencesInfo getPreferences()
- {
- return new PreferencesInfoSupport();
- }
-
- public MetaInfo getMeta()
- {
- MetaInfoSupport support = new MetaInfoSupport();
- support.setDisplayName(title);
- support.setDescription(description);
- return support;
- }
-
- public SecurityInfo getSecurity()
- {
- return new SecurityInfoSupport();
- }
-
- public CacheInfo getCache()
- {
- return new CacheInfoSupport();
- }
-
- public SessionInfo getSession()
- {
- return new SessionInfoSupport();
- }
-
- public Boolean isRemotable()
- {
- return Boolean.FALSE;
- }
- }
-
-}
Deleted:
trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetPortletInvoker.java
===================================================================
---
trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetPortletInvoker.java 2007-03-07
03:44:28 UTC (rev 6572)
+++
trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetPortletInvoker.java 2007-03-07
14:18:05 UTC (rev 6573)
@@ -1,234 +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.widget.google;
-
-import org.jboss.portal.portlet.PortletInvoker;
-import org.jboss.portal.portlet.PortletInvokerException;
-import org.jboss.portal.portlet.Portlet;
-import org.jboss.portal.portlet.PortletContext;
-import org.jboss.portal.portlet.InvokerUnavailableException;
-import org.jboss.portal.portlet.NoSuchPortletException;
-import org.jboss.portal.portlet.state.PropertyMap;
-import org.jboss.portal.portlet.state.PropertyChange;
-import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
-import org.jboss.portal.portlet.invocation.response.FragmentResponse;
-import org.jboss.portal.portlet.invocation.PortletInvocation;
-import org.jboss.portal.portlet.invocation.RenderInvocation;
-import org.jboss.portal.common.util.XML;
-import org.jboss.portal.jems.as.system.AbstractJBossService;
-import org.w3c.dom.Document;
-
-import javax.swing.text.html.HTMLEditorKit;
-import javax.swing.text.html.HTML;
-import javax.swing.text.MutableAttributeSet;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.DocumentBuilder;
-import java.util.Set;
-import java.util.List;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.StringTokenizer;
-import java.util.LinkedHashSet;
-import java.util.Iterator;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.HashSet;
-import java.net.URL;
-import java.net.MalformedURLException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class GoogleWidgetPortletInvoker extends AbstractJBossService implements
PortletInvoker
-{
-
- private volatile Map portletMap;
-
- private static class ParserAccessor extends HTMLEditorKit
- {
- public Parser getParser()
- {
- return super.getParser();
- }
- }
-
- public Map getPortletMap() throws PortletInvokerException
- {
- // Lazy create the map
- if (portletMap == null)
- {
- try
- {
- LinkedHashMap portletMap = new LinkedHashMap();
-
- // Find widget URLs
- URL url = new
URL("http://www.google.com/ig/directory");
- InputStream in = url.openStream();
- final LinkedHashSet urls = new LinkedHashSet();
- HTMLEditorKit.ParserCallback callback = new HTMLEditorKit.ParserCallback()
- {
- public void handleStartTag(HTML.Tag t, MutableAttributeSet attrSet, int
pos)
- {
- if (t == HTML.Tag.A)
- {
- try
- {
- String href = (String)attrSet.getAttribute(HTML.Attribute.HREF);
- URL url = new URL(href);
- String query = url.getQuery();
- if (query != null)
- {
- Map params = new HashMap();
- StringTokenizer st = new StringTokenizer(query,
"&");
- while (st.hasMoreTokens())
- {
- String pair = st.nextToken();
- int separator = pair.indexOf('=');
- if (separator != -1)
- {
- String left = pair.substring(0, separator);
- String right = pair.substring(separator + 1);
- params.put(left, right);
- }
- }
-
- //
- if (params.containsKey("url"))
- {
- url = new URL((String)params.get("url"));
- if (url.toString().endsWith(".xml"))
- {
- urls.add(url);
- }
- }
- }
- }
- catch (MalformedURLException ignore)
- {
- }
- }
- }
- };
- HTMLEditorKit.Parser parser = new ParserAccessor().getParser();
- parser.parse(new InputStreamReader(in, "UTF-8"), callback, true);
-
- // Now parse each
- for (Iterator i = urls.iterator();i.hasNext();)
- {
- URL widgetURL = (URL)i.next();
- DocumentBuilderFactory factory = XML.getDocumentBuilderFactory();
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(widgetURL.toString());
- try
- {
- GoogleWidgetPortlet portlet = new
GoogleWidgetPortlet(widgetURL.toString(), doc);
- portletMap.put(portlet.getContext().getId(), portlet);
- }
- catch (Exception e)
- {
- e.printStackTrace(); //To change body of catch statement use File |
Settings | File Templates.
- }
- }
-
- this.portletMap = portletMap;
- }
- catch (Exception e)
- {
- throw new InvokerUnavailableException(e);
- }
- }
-
- //
- Map portletMap = this.portletMap;
- if (portletMap == null)
- {
- portletMap = Collections.EMPTY_MAP;
- }
-
- //
- return portletMap;
- }
-
-
- public Set getPortlets() throws PortletInvokerException
- {
- return new HashSet(getPortletMap().values());
- }
-
- public Portlet getPortlet(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException
- {
- String targetId = portletContext.getId();
- GoogleWidgetPortlet portlet = (GoogleWidgetPortlet)getPortletMap().get(targetId);
- if (portlet == null)
- {
- throw new NoSuchPortletException(targetId);
- }
- return portlet;
- }
-
- public PortletInvocationResponse invoke(PortletInvocation invocation) throws
IllegalArgumentException, PortletInvokerException
- {
- if (invocation instanceof RenderInvocation)
- {
- PortletContext target =
(PortletContext)invocation.getAttribute(PortletInvocation.REQUEST_SCOPE,
PortletInvocation.PORTLET_CONTEXT_ATTRIBUTE);
- GoogleWidgetPortlet portlet = (GoogleWidgetPortlet)getPortlet(target);
- FragmentResponse resp = new FragmentResponse();
- resp.setContentType("text/html");
- resp.getWriter().print(portlet.getContent());
- resp.setTitle(portlet.getTitle());
- return resp;
- }
- else
- {
- throw new UnsupportedOperationException();
- }
- }
-
- public PortletContext createClone(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-
- public List destroyClones(List portletContexts) throws IllegalArgumentException,
PortletInvokerException, UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-
- public PropertyMap getProperties(PortletContext portletContext, Set keys) throws
IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-
- public PropertyMap getProperties(PortletContext portletContext) throws
IllegalArgumentException, PortletInvokerException, UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-
- public PortletContext setProperties(PortletContext portletContext, PropertyChange[]
changes) throws IllegalArgumentException, PortletInvokerException,
UnsupportedOperationException
- {
- throw new UnsupportedOperationException();
- }
-}
Added: trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetProvider.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetProvider.java
(rev 0)
+++
trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetProvider.java 2007-03-07
14:18:05 UTC (rev 6573)
@@ -0,0 +1,276 @@
+/******************************************************************************
+ * 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.widget.google;
+
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.io.InputStreamReader;
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.ByteArrayInputStream;
+import java.util.StringTokenizer;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.LinkedHashMap;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.ArrayList;
+
+import org.jboss.portal.widget.WidgetProvider;
+import org.jboss.portal.widget.Widget;
+import org.jboss.portal.common.util.Tools;
+import org.apache.log4j.Logger;
+
+import javax.swing.text.html.HTML;
+import javax.swing.text.html.HTMLEditorKit;
+import javax.swing.text.MutableAttributeSet;
+
+import edu.emory.mathcs.backport.java.util.concurrent.FutureTask;
+import edu.emory.mathcs.backport.java.util.concurrent.Callable;
+import edu.emory.mathcs.backport.java.util.concurrent.ExecutorService;
+import edu.emory.mathcs.backport.java.util.concurrent.ThreadPoolExecutor;
+import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
+import edu.emory.mathcs.backport.java.util.concurrent.LinkedBlockingDeque;
+import edu.emory.mathcs.backport.java.util.concurrent.locks.Lock;
+import edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantLock;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class GoogleWidgetProvider implements WidgetProvider
+{
+
+ /** . */
+ private static final Logger log = Logger.getLogger(GoogleWidgetProvider.class);
+
+ /** . */
+ private volatile FutureTask future;
+
+ /** . */
+ private final Lock lock = new ReentrantLock();
+
+ /** . */
+ private final ExecutorService executor = new ThreadPoolExecutor(3, 3, 0,
TimeUnit.SECONDS, new LinkedBlockingDeque());
+
+ public void start()
+ {
+ }
+
+ public void stop()
+ {
+ executor.shutdownNow();
+ }
+
+ private Map getMap()
+ {
+ try
+ {
+ lock.lock();
+ try
+ {
+ if (future == null)
+ {
+ future = new FutureTask(new Callable()
+ {
+ public Object call() throws Exception
+ {
+ WidgetBuilder map = new WidgetBuilder();
+ map.start();
+ return map;
+ }
+ });
+ executor.execute(future);
+ }
+ }
+ finally
+ {
+ lock.unlock();
+ }
+ WidgetBuilder wmap = (WidgetBuilder)future.get();
+ return wmap.map;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ return Collections.EMPTY_MAP;
+ }
+ }
+
+ public Collection getKeys()
+ {
+ return getMap().keySet();
+ }
+
+ public Widget getWidget(String key)
+ {
+ if (key == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ Map tmp = getMap();
+ GoogleWidgetRetrieval.List retrievals = (GoogleWidgetRetrieval.List)tmp.get(key);
+ if (retrievals != null)
+ {
+ GoogleWidgetRetrieval retrieval = retrievals.getRetrieval(key);
+ if (retrieval.getStatus() == GoogleWidgetRetrieval.AVAILABLE)
+ {
+ return retrieval.getWidget();
+ }
+ }
+
+ //
+ return null;
+ }
+
+ private class WidgetBuilder
+ {
+
+ /** . */
+ private Map map;
+
+ public void start()
+ {
+ try
+ {
+ // Find widget URLs
+ URL url = new
URL("http://www.google.com/ig/directory?synd=open");
+
+ // Read fully the URL content first
+ byte[] bytes = null;
+ InputStream in = null;
+ try
+ {
+ log.info("Retrieving " + url);
+ in = url.openStream();
+ bytes = Tools.getBytes(in);
+ log.info("Document " + url + " has been retrieved");
+ }
+ finally
+ {
+ Tools.safeClose(in);
+ }
+
+ //
+ final LinkedHashSet urls = new LinkedHashSet();
+ HTMLEditorKit.ParserCallback callback = new HTMLEditorKit.ParserCallback()
+ {
+ public void handleStartTag(HTML.Tag t, MutableAttributeSet attrSet, int
pos)
+ {
+ if (t == HTML.Tag.A)
+ {
+ try
+ {
+ String href = (String)attrSet.getAttribute(HTML.Attribute.HREF);
+ URL url = new URL(href);
+ String query = url.getQuery();
+ if (query != null)
+ {
+ Map params = new HashMap();
+ StringTokenizer st = new StringTokenizer(query,
"&");
+ while (st.hasMoreTokens())
+ {
+ String pair = st.nextToken();
+ int separator = pair.indexOf('=');
+ if (separator != -1)
+ {
+ String left = pair.substring(0, separator);
+ String right = pair.substring(separator + 1);
+ params.put(left, right);
+ }
+ }
+
+ //
+ if (params.containsKey("url"))
+ {
+ String tmp = (String)params.get("url");
+ if (tmp.endsWith(".xml"))
+ {
+ url = new URL(tmp);
+ urls.add(url);
+ }
+ }
+ }
+ }
+ catch (MalformedURLException ignore)
+ {
+ }
+ }
+ }
+ };
+ HTMLEditorKit.Parser parser = new ParserAccessor().getParser();
+ parser.parse(new InputStreamReader(new ByteArrayInputStream(bytes),
"UTF-8"), callback, true);
+
+ //
+ Map map = new LinkedHashMap();
+
+ // Now parse each
+ Collection tmp = new ArrayList(BATCH_SIZE);
+ for (Iterator i = urls.iterator();i.hasNext();)
+ {
+ URL widgetURL = (URL)i.next();
+ GoogleWidgetFactory widgetFactory = new GoogleWidgetFactory(widgetURL);
+
+ //
+ if (tmp.size() < BATCH_SIZE)
+ {
+ tmp.add(widgetFactory);
+ }
+ else
+ {
+ GoogleWidgetRetrieval.List retrievals = new
GoogleWidgetRetrieval.List(executor, tmp);
+ for (int j = 0;j < retrievals.getSize();j++)
+ {
+ GoogleWidgetFactory t = retrievals.getFactory(j);
+ map.put(t.getURL().toString(), retrievals);
+ log.info("Added widget for later retrieval" +
t.getURL());
+ }
+
+ //
+ tmp.clear();
+ tmp.add(widgetFactory);
+ }
+ }
+
+ //
+ this.map = Collections.unmodifiableMap(map);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private static final int BATCH_SIZE = 6;
+
+ private static class ParserAccessor extends HTMLEditorKit
+ {
+ public Parser getParser()
+ {
+ return super.getParser();
+ }
+ }
+}
Added: trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetRetrieval.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetRetrieval.java
(rev 0)
+++
trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetRetrieval.java 2007-03-07
14:18:05 UTC (rev 6573)
@@ -0,0 +1,202 @@
+/******************************************************************************
+ * 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.widget.google;
+
+import edu.emory.mathcs.backport.java.util.concurrent.FutureTask;
+import edu.emory.mathcs.backport.java.util.concurrent.Callable;
+import edu.emory.mathcs.backport.java.util.concurrent.CompletionService;
+import edu.emory.mathcs.backport.java.util.concurrent.ExecutorCompletionService;
+import edu.emory.mathcs.backport.java.util.concurrent.Future;
+import edu.emory.mathcs.backport.java.util.concurrent.Executor;
+import edu.emory.mathcs.backport.java.util.concurrent.locks.Lock;
+import edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantLock;
+
+import java.util.Collection;
+
+import org.apache.log4j.Logger;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class GoogleWidgetRetrieval
+{
+
+ /** . */
+ private static final Logger log = Logger.getLogger(GoogleWidgetRetrieval.class);
+
+ /** . */
+ public static int UNAVAILABLE = 0;
+
+ /** . */
+ public static int AVAILABLE = 1;
+
+ /** . */
+ private GoogleWidget widget;
+
+ public GoogleWidgetRetrieval(GoogleWidget widget)
+ {
+ this.widget = widget;
+ }
+
+ public GoogleWidget getWidget() throws IllegalStateException
+ {
+ if (widget == null)
+ {
+ throw new IllegalStateException("Widget not available");
+ }
+ return widget;
+ }
+
+ public int getStatus()
+ {
+ return widget != null ? AVAILABLE : UNAVAILABLE;
+ }
+
+ public static class List
+ {
+
+ /** . */
+ private final GoogleWidgetFactory[] factories;
+
+ /** . */
+ private final Executor executor;
+
+ /** . */
+ private final Lock lock = new ReentrantLock();
+
+ /** . */
+ private FutureTask future;
+
+ public List(Executor executor, Collection c)
+ {
+ this.executor = executor;
+ this.factories = (GoogleWidgetFactory[])c.toArray(new
GoogleWidgetFactory[c.size()]);
+ }
+
+ public int getSize()
+ {
+ return factories.length;
+ }
+
+ public GoogleWidgetFactory getFactory(int index)
+ {
+ return factories[index];
+ }
+
+ public GoogleWidgetRetrieval getRetrieval(String key)
+ {
+ for (int i = 0;i < factories.length;i++)
+ {
+ GoogleWidgetFactory factory = factories[i];
+ if (key.equals(factory.getURL().toString()))
+ {
+ return getRetrieval(i);
+ }
+ }
+ return null;
+ }
+
+ private class Fetcher implements Callable
+ {
+
+ /** . */
+ private final int index;
+
+ /** . */
+ private GoogleWidgetRetrieval retrieval;
+
+ public Fetcher(int index)
+ {
+ this.index = index;
+ }
+
+ public Object call() throws Exception
+ {
+ GoogleWidgetFactory factory = factories[index];
+ try
+ {
+ log.info("Creating widget " + factory.getURL());
+ GoogleWidget widget = factory.create();
+ retrieval = new GoogleWidgetRetrieval(widget);
+ }
+ catch (Exception e)
+ {
+ log.error("Widget " + factory.getURL() + " was not
retrievable", e);
+ retrieval = new GoogleWidgetRetrieval(null);
+ }
+ return this;
+ }
+ }
+
+ public GoogleWidgetRetrieval getRetrieval(int index)
+ {
+ //
+ lock.lock();
+ try
+ {
+ if (future == null)
+ {
+ future = new FutureTask(new Callable()
+ {
+ public Object call() throws Exception
+ {
+ log.info("Creating widget batch");
+ CompletionService completionService = new
ExecutorCompletionService(executor);
+ for (int i = 0; i < factories.length; i++)
+ {
+ completionService.submit(new Fetcher(i));
+ }
+ GoogleWidgetRetrieval[] retrievals = new
GoogleWidgetRetrieval[factories.length];
+ for (int i = 0; i < factories.length; i++)
+ {
+ Future future = completionService.take();
+ Fetcher fetcher = (Fetcher)future.get();
+ retrievals[fetcher.index] = fetcher.retrieval;
+ }
+ return retrievals;
+ }
+ });
+ executor.execute(future);
+ }
+ }
+ finally
+ {
+ lock.unlock();
+ }
+
+ try
+ {
+ //
+ GoogleWidgetRetrieval[] retrievals = (GoogleWidgetRetrieval[])future.get();
+
+ //
+ return retrievals[index];
+ }
+ catch (Exception e)
+ {
+ return new GoogleWidgetRetrieval(null);
+ }
+ }
+ }
+}
Added: trunk/widget/src/resources/widget-war/WEB-INF/portlet-instances.xml
===================================================================
--- trunk/widget/src/resources/widget-war/WEB-INF/portlet-instances.xml
(rev 0)
+++ trunk/widget/src/resources/widget-war/WEB-INF/portlet-instances.xml 2007-03-07
14:18:05 UTC (rev 6573)
@@ -0,0 +1,36 @@
+<?xml version="1.0" standalone="yes"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<!DOCTYPE deployments PUBLIC
+ "-//JBoss Portal//DTD Portlet Instances 2.6//EN"
+ "http://www.jboss.org/portal/dtd/portlet-instances_2_6.dtd">
+
+<deployments>
+ <deployment>
+ <instance>
+ <instance-id>GoogleWidgetPortletInstance</instance-id>
+ <portlet-ref>GoogleWidgetPortlet</portlet-ref>
+ </instance>
+ </deployment>
+</deployments>
\ No newline at end of file
Added: trunk/widget/src/resources/widget-war/WEB-INF/portlet.xml
===================================================================
--- trunk/widget/src/resources/widget-war/WEB-INF/portlet.xml (rev
0)
+++ trunk/widget/src/resources/widget-war/WEB-INF/portlet.xml 2007-03-07 14:18:05 UTC (rev
6573)
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<portlet-app
+
xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1...
http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
+ version="1.0">
+ <portlet>
+ <description>Google Widget Portlet</description>
+ <portlet-name>GoogleWidgetPortlet</portlet-name>
+ <display-name>Google Widget Portlet</display-name>
+ <portlet-class>org.jboss.portal.widget.WidgetPortlet</portlet-class>
+ <supports>
+ <mime-type>text/html</mime-type>
+ <portlet-mode>VIEW</portlet-mode>
+ </supports>
+ <portlet-info>
+ <title>Google Widget</title>
+ <keywords>widget</keywords>
+ </portlet-info>
+ </portlet>
+</portlet-app>
Added: trunk/widget/src/resources/widget-war/WEB-INF/web.xml
===================================================================
--- trunk/widget/src/resources/widget-war/WEB-INF/web.xml (rev 0)
+++ trunk/widget/src/resources/widget-war/WEB-INF/web.xml 2007-03-07 14:18:05 UTC (rev
6573)
@@ -0,0 +1,41 @@
+<?xml version="1.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. ~
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<web-app
+
xmlns="http://java.sun.com/xml/ns/j2ee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
+ version="2.4">
+ <context-param>
+ <param-name>org.jboss.portal.content_type</param-name>
+ <param-value>widget/google</param-value>
+ </context-param>
+ <context-param>
+ <param-name>org.jboss.portal.portlet_instance</param-name>
+ <param-value>GoogleWidgetPortletInstance</param-value>
+ </context-param>
+ <listener>
+
<listener-class>org.jboss.portal.core.servlet.jsp.ContentTypeRegistration</listener-class>
+ </listener>
+</web-app>