[portal-commits] JBoss Portal SVN: r5818 - in trunk: . build/ide/intellij/idea60/modules build/ide/intellij/idea60/modules/widget widget widget/src widget/src/main widget/src/main/org widget/src/main/org/jboss widget/src/main/org/jboss/portal widget/src/main/org/jboss/portal/widget widget/src/main/org/jboss/portal/widget/google widget/src/resources widget/src/resources/widget-invoker-sar widget/src/resources/widget-invoker-sar/META-INF

portal-commits at lists.jboss.org portal-commits at lists.jboss.org
Wed Dec 13 05:23:50 EST 2006


Author: julien at jboss.com
Date: 2006-12-13 05:23:45 -0500 (Wed, 13 Dec 2006)
New Revision: 5818

Added:
   trunk/build/ide/intellij/idea60/modules/widget/
   trunk/build/ide/intellij/idea60/modules/widget/widget.iml
   trunk/widget/
   trunk/widget/build.bat
   trunk/widget/build.sh
   trunk/widget/build.xml
   trunk/widget/src/
   trunk/widget/src/main/
   trunk/widget/src/main/org/
   trunk/widget/src/main/org/jboss/
   trunk/widget/src/main/org/jboss/portal/
   trunk/widget/src/main/org/jboss/portal/widget/
   trunk/widget/src/main/org/jboss/portal/widget/google/
   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/
   trunk/widget/src/resources/widget-invoker-sar/
   trunk/widget/src/resources/widget-invoker-sar/META-INF/
   trunk/widget/src/resources/widget-invoker-sar/META-INF/jboss-service.xml
Log:
Created a prototype of a portlet invoker that adapts google widgets as portlet called GoogleWidgetPortletInvoker

Added: trunk/build/ide/intellij/idea60/modules/widget/widget.iml
===================================================================
--- trunk/build/ide/intellij/idea60/modules/widget/widget.iml	2006-12-13 10:20:54 UTC (rev 5817)
+++ trunk/build/ide/intellij/idea60/modules/widget/widget.iml	2006-12-13 10:23:45 UTC (rev 5818)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module version="4" relativePaths="true" type="JAVA_MODULE">
+  <component name="ModuleRootManager" />
+  <component name="NewModuleRootManager" inherit-compiler-output="true">
+    <exclude-output />
+    <content url="file://$MODULE_DIR$/../../../../../../widget">
+      <sourceFolder url="file://$MODULE_DIR$/../../../../../../widget/src/main" isTestSource="false" />
+    </content>
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+    <orderEntry type="module" module-name="portlet" />
+    <orderEntry type="module" module-name="common" />
+    <orderEntry type="module" module-name="jems" />
+    <orderEntryProperties />
+  </component>
+</module>
+

Added: trunk/widget/build.bat
===================================================================
--- trunk/widget/build.bat	2006-12-13 10:20:54 UTC (rev 5817)
+++ trunk/widget/build.bat	2006-12-13 10:23:45 UTC (rev 5818)
@@ -0,0 +1,54 @@
+ at echo off
+rem
+rem  Invokes a script of the same name in the 'tools' module.
+rem  
+rem  The 'tools' module is expected to be a peer directory of the directory
+rem  in which this script lives.
+rem
+rem  @author Jason Dillon <jason at planet57.com>
+rem
+
+rem $Id: build.bat 1140 2005-11-25 23:38:58Z julien $
+
+setlocal
+
+set PROGNAME=%~nx0
+set DIRNAME=%~dp0
+
+rem Legacy shell support
+if x%PROGNAME%==x set PROGNAME=build.bat
+if x%DIRNAME%==x set DIRNAME=.\
+
+set MODULE_ROOT=%DIRNAME%
+if x%TOOLS_ROOT%==x set TOOLS_ROOT=%DIRNAME%..\tools
+set TARGET=%TOOLS_ROOT%\bin\build.bat
+set ARGS=%*
+
+rem Start'er up yo
+goto main
+
+:debug
+if not x%DEBUG%==x echo %PROGNAME%: %*
+goto :EOF
+
+:main
+call :debug PROGNAME=%PROGNAME%
+call :debug DIRNAME=%DIRNAME%
+call :debug TOOLS_ROOT=%TOOLS_ROOT%
+call :debug TARGET=%TARGET%
+
+if exist %TARGET% call :call-script & goto :EOF
+rem else fail, we can not go on
+
+echo %PROGNAME%: *ERROR* The target executable does not exist:
+echo %PROGNAME%:
+echo %PROGNAME%:    %TARGET%
+echo %PROGNAME%:
+echo %PROGNAME%: Please make sure you have checked out the 'tools' module
+echo %PROGNAME%: and make sure it is up to date.
+goto :EOF
+
+:call-script
+call :debug Executing %TARGET% %ARGS%
+call %TARGET% %ARGS%
+goto :EOF


Property changes on: trunk/widget/build.bat
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/widget/build.sh
===================================================================
--- trunk/widget/build.sh	2006-12-13 10:20:54 UTC (rev 5817)
+++ trunk/widget/build.sh	2006-12-13 10:23:45 UTC (rev 5818)
@@ -0,0 +1,49 @@
+#!/bin/sh
+##
+##  Invokes a script of the same name in the 'tools' module.
+##  
+##  The 'tools' module is expected to be a peer directory of the directory
+##  in which this script lives.
+##
+##  @author Jason Dillon <jason at planet57.com>
+##
+
+# $Id: build.sh 1140 2005-11-25 23:38:58Z julien $
+
+PROGNAME=`basename $0`
+DIRNAME=`dirname $0`
+
+# Buss it yo
+main() {
+    if [ "x$TOOLS_ROOT" = "x" ]; then
+	TOOLS_ROOT=`cd $DIRNAME/../tools && pwd`
+    fi
+
+    MODULE_ROOT=`cd $DIRNAME; pwd`
+    export TOOLS_ROOT MODULE_ROOT DEBUG TRACE
+
+    # Where is the target script?
+    target="$TOOLS_ROOT/bin/$PROGNAME"
+    if [ ! -f "$target" ]; then
+	echo "${PROGNAME}: *ERROR* The target executable does not exist:"
+        echo "${PROGNAME}:"
+        echo "${PROGNAME}:    $target"
+        echo "${PROGNAME}:"
+	echo "${PROGNAME}: Please make sure you have checked out the 'tools' module"
+	echo "${PROGNAME}: and make sure it is up to date."
+        exit 2
+    fi
+
+    # Get busy yo!
+    if [ "x$DEBUG" != "x" ]; then
+	echo "${PROGNAME}: Executing: /bin/sh $target $@"
+    fi
+    if [ "x$TRACE" = "x" ]; then
+	exec /bin/sh $target "$@"
+    else
+	exec /bin/sh -x $target "$@"
+    fi
+}
+
+# Lets get ready to rumble!
+main "$@"


Property changes on: trunk/widget/build.sh
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/widget/build.xml
===================================================================
--- trunk/widget/build.xml	2006-12-13 10:20:54 UTC (rev 5817)
+++ trunk/widget/build.xml	2006-12-13 10:23:45 UTC (rev 5818)
@@ -0,0 +1,210 @@
+<?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.                  ~
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<!DOCTYPE project [
+   <!ENTITY libraries  SYSTEM "../thirdparty/libraries.ent">
+   <!ENTITY buildmagic SYSTEM "../tools/etc/buildfragments/buildmagic.ent">
+   <!ENTITY tools      SYSTEM "../tools/etc/buildfragments/tools.ent">
+   <!ENTITY modules    SYSTEM "../tools/etc/buildfragments/modules.ent">
+   <!ENTITY defaults   SYSTEM "../tools/etc/buildfragments/defaults.ent">
+   <!ENTITY targets    SYSTEM "../tools/etc/buildfragments/targets.ent">
+   ]>
+
+<!-- $Id: build.xml 5448 2006-10-13 19:29:17Z chris.laprun at jboss.com $ -->
+
+<!--+======================================================================+-->
+<!--| JBoss Portal (The OpenSource Portal) Build File                      |-->
+<!--|                                                                      |-->
+<!--| Distributable under LGPL license.                                    |-->
+<!--| See terms of license at http://www.gnu.org.                          |-->
+<!--|                                                                      |-->
+<!--| This file has been designed to work with the 'tools' module and      |-->
+<!--| Buildmagic extentions.                                               |-->
+<!--+======================================================================+-->
+
+<project default="main" name="JBoss Portal">
+
+   <!--+====================================================================+-->
+   <!--| Setup                                                              |-->
+   <!--|                                                                    |-->
+   <!--| Include the common build elements.                                 |-->
+   <!--|                                                                    |-->
+   <!--| This defines several different targets, properties and paths.      |-->
+   <!--| It also sets up the basic extention tasks amoung other things.     |-->
+   <!--+====================================================================+-->
+
+   &buildmagic;
+   &modules;
+   &defaults;
+   &tools;
+   &targets;
+
+   <!-- ================================================================== -->
+   <!-- Initialization                                                     -->
+   <!-- ================================================================== -->
+
+   <!--
+      | Initialize the build system.  Must depend on '_buildmagic:init'.
+      | Other targets should depend on 'init' or things will mysteriously fail.
+    -->
+
+   <target name="init" unless="init.disable" depends="_buildmagic:init">
+   </target>
+
+   <!--+====================================================================+-->
+   <!--| Configuration                                                      |-->
+   <!--|                                                                    |-->
+   <!--| This target is invoked by the Buildmagic initialization logic      |-->
+   <!--| and should contain module specific configuration elements.         |-->
+   <!--+====================================================================+-->
+
+   <target name="configure" unless="configure.disable">
+
+      <!-- Configure some properties -->
+      <property name="jboss-junit-configuration" value=""/>
+      <property name="junit.formatter.usefile" value="true"/>
+
+      <!-- Configure thirdparty libraries -->
+      &libraries;
+      <path id="library.classpath">
+         <path refid="jbossas/core.libs.classpath"/>
+         <path refid="apache.log4j.classpath"/>
+      </path>
+
+      <!-- Configure modules -->
+      <call target="configure-modules"/>
+      <path id="dependentmodule.classpath">
+         <path refid="jboss.portal-common.classpath"/>
+         <path refid="jboss.portal-jems.classpath"/>
+         <path refid="jboss.portal-server.classpath"/>
+         <path refid="jboss.portal-portlet.classpath"/>
+      </path>
+
+      <!--+=======================================+-->
+      <!--| Override any default properties here. |-->
+      <!--+=======================================+-->
+
+      <!-- Configure defaults & build tools -->
+      <call target="configure-defaults"/>
+      <call target="configure-tools"/>
+
+      <!--+=======================================+-->
+      <!--| Define module specific elements here. |-->
+      <!--+=======================================+-->
+      <property name="javadoc.private" value="true"/>
+      <property name="javadoc.protected" value="false"/>
+
+   </target>
+
+   <!--+====================================================================+-->
+   <!--| Compile                                                            |-->
+   <!--|                                                                    |-->
+   <!--| This target should depend on other compile-* targets for each      |-->
+   <!--| different type of compile that needs to be performed, short of     |-->
+   <!--| documentation compiles.                                            |-->
+   <!--+====================================================================+-->
+
+   <target name="compile"
+           description="Compile all source files."
+           depends="_default:compile-classes,
+               _default:compile-etc,
+               _default:compile-resources">
+      <!-- Add module specific elements here. -->
+   </target>
+
+   <!--+====================================================================+-->
+   <!--| Generate Output                                                    |-->
+   <!--|                                                                    |-->
+   <!--| Generates the target output for this module. Target output is      |-->
+   <!--| the output which is ment to be released or used by external        |-->
+   <!--| modules.                                                           |-->
+   <!--+====================================================================+-->
+
+   <target name="output"
+           description="Generate all target output."
+           depends="compile">
+
+      <!-- widget-invoker-lib.jar -->
+      <mkdir dir="${build.lib}"/>
+      <jar jarfile="${build.lib}/widget-invoker-lib.jar">
+         <fileset dir="${build.classes}"/>
+      </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"/>
+      </copy>
+      <jar jarfile="${build.lib}/widget-invoker.sar">
+         <fileset dir="${build.resources}/widget-invoker-sar"/>
+      </jar>
+   </target>
+
+   <!-- ================================================================== -->
+   <!-- Cleaning                                                           -->
+   <!-- ================================================================== -->
+
+   <!-- Clean up all build output -->
+   <target name="clean" depends="_default:clean">
+      <!-- Add module specific elements here. -->
+   </target>
+
+   <!--+====================================================================+-->
+   <!--| Documents                                                          |-->
+   <!--|                                                                    |-->
+   <!--| Generate all documentation for this module.                        |-->
+   <!--+====================================================================+-->
+
+   <target name="docs" depends="_default:docs">
+      <!-- Add module specific elements here. -->
+   </target>
+
+   <!-- ================================================================== -->
+   <!-- Misc.                                                              -->
+   <!-- ================================================================== -->
+
+   <target name="main" depends="most"/>
+   <target name="all" depends="_default:all"/>
+   <target name="most" depends="_default:most"/>
+   <target name="help" depends="_default:help"/>
+
+   <!-- ================================================================== -->
+   <!-- Deployment                                                         -->
+   <!-- ================================================================== -->
+
+   <target name="deploy"
+           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}"/>
+   </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"/>
+   </target>
+
+</project>


Property changes on: trunk/widget/build.xml
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetPortlet.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetPortlet.java	2006-12-13 10:20:54 UTC (rev 5817)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetPortlet.java	2006-12-13 10:23:45 UTC (rev 5818)
@@ -0,0 +1,153 @@
+/******************************************************************************
+ * 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 at 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;
+      }
+   }
+
+}

Added: trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetPortletInvoker.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetPortletInvoker.java	2006-12-13 10:20:54 UTC (rev 5817)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GoogleWidgetPortletInvoker.java	2006-12-13 10:23:45 UTC (rev 5818)
@@ -0,0 +1,234 @@
+/******************************************************************************
+ * 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 at 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/resources/widget-invoker-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/widget/src/resources/widget-invoker-sar/META-INF/jboss-service.xml	2006-12-13 10:20:54 UTC (rev 5817)
+++ trunk/widget/src/resources/widget-invoker-sar/META-INF/jboss-service.xml	2006-12-13 10:23:45 UTC (rev 5818)
@@ -0,0 +1,51 @@
+<?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.                  ~
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+
+<server>
+
+   <!--  -->
+   <mbean
+      code="org.jboss.portal.widget.google.GoogleWidgetPortletInvoker"
+      name="portal:service=PortletInvoker,type=GoogleWidget"
+      xmbean-dd=""
+      xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+      <xmbean/>
+   </mbean>
+
+   <!-- Register the portlet invoker on the federating portlet invoker -->
+   <mbean
+      code="org.jboss.portal.federation.impl.PortletInvokerRegistrationService"
+      name="portal:service=PortletInvokerRegistration,id=googlewidget"
+      xmbean-dd=""
+      xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+      <xmbean/>
+      <attribute name="Id">googlewidget</attribute>
+      <depends
+         optional-attribute-name="PortletInvoker"
+         proxy-type="attribute">portal:service=PortletInvoker,type=GoogleWidget</depends>
+      <depends
+         optional-attribute-name="FederatingPortletInvoker"
+         proxy-type="attribute">portal:service=PortletInvoker,type=Federating</depends>
+   </mbean>
+</server>




More information about the portal-commits mailing list