JBoss Portal SVN: r6585 - trunk/server/src/main/org/jboss/portal/server/deployment.
by portal-commits@lists.jboss.org
Author: thomas.heute(a)jboss.com
Date: 2007-03-07 17:08:39 -0500 (Wed, 07 Mar 2007)
New Revision: 6585
Modified:
trunk/server/src/main/org/jboss/portal/server/deployment/PortalWebAppFactory.java
Log:
JBoss Web Server included in JBoss 4.2.x is named stating with "JBossWeb/2"
Modified: trunk/server/src/main/org/jboss/portal/server/deployment/PortalWebAppFactory.java
===================================================================
--- trunk/server/src/main/org/jboss/portal/server/deployment/PortalWebAppFactory.java 2007-03-07 21:40:41 UTC (rev 6584)
+++ trunk/server/src/main/org/jboss/portal/server/deployment/PortalWebAppFactory.java 2007-03-07 22:08:39 UTC (rev 6585)
@@ -109,7 +109,7 @@
{
return TOMCAT5;
}
- else if (result.startsWith("JBoss Web Server/2"))
+ else if (result.startsWith("JBossWeb/2"))
{
return TOMCAT6;
}
17 years, 4 months
JBoss Portal SVN: r6584 - in trunk/core-admin/src: main/org/jboss/portal/core/admin/ui/portlet and 1 other directories.
by portal-commits@lists.jboss.org
Author: thomas.heute(a)jboss.com
Date: 2007-03-07 16:40:41 -0500 (Wed, 07 Mar 2007)
New Revision: 6584
Modified:
trunk/core-admin/src/bin/portal-admin-war/style.css
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/portlet/PortletContentEditorPortlet.java
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml
Log:
- PortletContentEditorPortlet displaying instances in a paged table
Modified: trunk/core-admin/src/bin/portal-admin-war/style.css
===================================================================
--- trunk/core-admin/src/bin/portal-admin-war/style.css 2007-03-07 19:19:00 UTC (rev 6583)
+++ trunk/core-admin/src/bin/portal-admin-war/style.css 2007-03-07 21:40:41 UTC (rev 6584)
@@ -86,11 +86,6 @@
/* Style a table for form layout */
.admin-ui table.form {
- border-spacing: 10px 4px;
- margin-left: -10px;
- margin-right: -10px;
- margin-top: -4px;
- margin-bottom: -4px;
}
.admin-ui table.form td.label {
Modified: trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/portlet/PortletContentEditorPortlet.java
===================================================================
--- trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/portlet/PortletContentEditorPortlet.java 2007-03-07 19:19:00 UTC (rev 6583)
+++ trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/portlet/PortletContentEditorPortlet.java 2007-03-07 21:40:41 UTC (rev 6584)
@@ -67,10 +67,15 @@
if (req.getPortletMode().equals(EDIT_CONTENT))
{
String uri = req.getParameter("uri");
+ String from = req.getParameter("from");
if (uri != null)
{
resp.setRenderParameter("uri", uri);
}
+ if (from != null)
+ {
+ resp.setRenderParameter("from", from);
+ }
}
}
@@ -79,68 +84,95 @@
if (req.getPortletMode().equals(EDIT_CONTENT))
{
String selectedURI = req.getParameter("uri");
-
+ String selectedFrom = req.getParameter("from");
+ int pagination = 10;
+ int from = 0;
+ if (selectedFrom != null)
+ {
+ from = new Integer(selectedFrom).intValue();
+ }
+
//
- PortletURL actionURL = resp.createActionURL();
- actionURL.setParameter("meta_action", "select");
-
- //
resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
// load insances this user has access to.
List available_instances = (List)instanceContainer.getDefinitions();
- Instance selectedInstance = null;
- writer.print("<form action=\"");
- writer.print(actionURL);
- writer.print("\" method=\"post\">\n");
- writer.println("<select name=\"uri\"size=\"20\">\n");
- for (int i = 0; i < available_instances.size(); i++)
+
+ writer.println("<script>");
+ writer.println("function togglediv(nr) {");
+ writer.println(" if (document.getElementById)");
+ writer.println(" {");
+ writer.println(" vista = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';");
+ writer.println(" document.getElementById(nr).style.display = vista;");
+ writer.println(" }");
+ writer.println("}");
+ writer.println("</script>");
+
+
+ writer.println("<br /><br /><table id=\"instancesTable2\">");
+ writer.println("<thead class=\"portlet-section-header\">");
+ writer.println(" <tr>");
+ writer.println(" <th>Portlet instances</th>");
+ writer.println(" </tr>");
+ writer.println("</thead>");
+ writer.println("<tbody>");
+ for (int i = from; i < Math.min(available_instances.size(), from + pagination); i++)
{
Instance instance = (Instance)available_instances.get(i);
- //
- writer.print("<option value=\"");
- writer.print(instance.getId());
- writer.print("\"");
+ PortletURL actionURL = resp.createActionURL();
+ actionURL.setParameter("meta_action", "select");
+ actionURL.setParameter("uri", instance.getId());
+ actionURL.setParameter("from", "" + from);
- //
- if (instance.getId().equals(selectedURI))
+ String trClass = instance.getId().equals(selectedURI) ? "portlet-section-selected" : (i % 2 == 0 ? "portlet-section-body" : "portlet-section-alternate");
+
+ writer.println(" <tr class=\" " + trClass + "\">");
+ writer.println(" <td>");
+ writer.println(" <a onmouseout=\"togglediv('menu"+ i + "');\" onmouseover=\"togglediv('menu"+ i + "');\" href=\"" + actionURL + "\">");
+ writer.println(instance.getId());
+ writer.println("</a>");
+ writer.println(" </td>");
+ writer.println(" </tr>");
+ }
+ writer.println(" </tbody>");
+ writer.println(" </table>");
+ writer.println(" <ul class=\"pagination\">");
+ for (int i=0; i<available_instances.size(); i += pagination)
+ {
+ String liClass = i == from ? "selected" : "";
+ PortletURL renderURL = resp.createRenderURL();
+ if (selectedURI != null)
{
- selectedInstance = instance;
- writer.print(" selected=\"selected\"");
+ renderURL.setParameter("uri", selectedURI);
}
-
- //
- writer.print(">");
- writer.print(instance.getId());
- writer.println("</option>\n");
+ renderURL.setParameter("from", "" + i);
+ writer.println(" <li class=\"" + liClass + "\">");
+ writer.println(" <a href=\"" + renderURL + "\">" + i + "</a>");
+ writer.println(" </li>");
}
- writer.println("</select>");
- writer.println("<input name=\"select\" value=\"Select\" type=\"submit\"/>");
- writer.print("</form>");
+ writer.println(" </ul>");
- //
- if (selectedInstance != null)
+ for (int i = from; i < Math.min(available_instances.size(), from + pagination); i++)
{
- writer.print("<div class=\"portlet-font\" style=\"float:left\">");
- writer.print("<div><span class=\"portlet-form-field-label\">Portlet instance:</span>" + selectedURI + "</div>");
+ Instance instance = (Instance)available_instances.get(i);
+
+ writer.print("<div style=\"display:none;\" id=\"menu" + i + "\">");
try
{
- Portlet portlet = selectedInstance.getPortlet();
- if (portlet != null)
- {
- MetaInfo metaInfo = portlet.getInfo().getMeta();
- writer.print("<div><span class=\"portlet-form-field-label\">Portlet name:</span>" + metaInfo.getMetaValue(MetaInfo.DISPLAY_NAME).getDefaultString() + "</div>");
- writer.print("<div><span class=\"portlet-form-field-label\">Portlet description:</span>" + metaInfo.getMetaValue(MetaInfo.DESCRIPTION).getDefaultString() + "</div>");
- writer.print("<div><span class=\"portlet-form-field-label\">Portlet title:</span>" + metaInfo.getMetaValue(MetaInfo.TITLE).getDefaultString() + "</div>");
- writer.print("<div><span class=\"portlet-form-field-label\">Portlet keywords:</span>" + metaInfo.getMetaValue(MetaInfo.KEYWORDS).getDefaultString() + "</div>");
- }
+ Portlet portlet = instance.getPortlet();
+ MetaInfo metaInfo = portlet.getInfo().getMeta();
+ writer.print("<div><span class=\"portlet-form-field-label\">Portlet name:</span>" + metaInfo.getMetaValue(MetaInfo.DISPLAY_NAME).getDefaultString() + "</div>");
+ writer.print("<div><span class=\"portlet-form-field-label\">Portlet description:</span>" + metaInfo.getMetaValue(MetaInfo.DESCRIPTION).getDefaultString() + "</div>");
+ writer.print("<div><span class=\"portlet-form-field-label\">Portlet title:</span>" + metaInfo.getMetaValue(MetaInfo.TITLE).getDefaultString() + "</div>");
+ writer.print("<div><span class=\"portlet-form-field-label\">Portlet keywords:</span>" + metaInfo.getMetaValue(MetaInfo.KEYWORDS).getDefaultString() + "</div>");
}
catch (PortletInvokerException e)
{
e.printStackTrace();
}
+ writer.print("</div>");
}
//
Modified: trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml
===================================================================
--- trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml 2007-03-07 19:19:00 UTC (rev 6583)
+++ trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml 2007-03-07 21:40:41 UTC (rev 6584)
@@ -64,9 +64,7 @@
<table class="form">
<tr>
<td class="label">
- <h:outputLabel for="windowName">
- <h:outputText value="Window Name: " styleClass="portlet-form-field-label"/>
- </h:outputLabel>
+ <span class="portlet-form-field-label">Window Name:</span>
</td>
<td class="widget">
<h:inputText id="windowName" value="#{assignWindowsAction.windowName}" styleClass="portlet-form-input-field"/>
@@ -75,7 +73,7 @@
</tr>
<tr>
<td class="label">
- <span class="portlet-form-field-label label">Content type:</span>
+ <span class="portlet-form-field-label">Content type:</span>
</td>
<td class="widget">
<h:selectOneMenu
@@ -88,18 +86,13 @@
<h:message for="instanceId" errorClass="portlet-msg-error"/>
</td>
</tr>
- <tr>
- <td class="label">
- <span class="portlet-form-field-label label">Portlet content:</span>
- </td>
- <td class="widget">
- </td>
- </tr>
</table>
</div>
</h:form>
-
- <div>
+ <br />
+ <span class="portlet-form-field-label">Portlet content:</span>
+ <br />
+ <div align="left">
<jbp:portlet
instanceId="#{portalobjectmgr.selectedContentEditorInstance}"
actionListener="#{portalobjectmgr.processEvent}"
17 years, 4 months
JBoss Portal SVN: r6583 - trunk/testsuite.
by portal-commits@lists.jboss.org
Author: bdaw
Date: 2007-03-07 14:19:00 -0500 (Wed, 07 Mar 2007)
New Revision: 6583
Modified:
trunk/testsuite/build.xml
Log:
- reenable identity module in teestsuite
Modified: trunk/testsuite/build.xml
===================================================================
--- trunk/testsuite/build.xml 2007-03-07 18:16:51 UTC (rev 6582)
+++ trunk/testsuite/build.xml 2007-03-07 19:19:00 UTC (rev 6583)
@@ -130,9 +130,9 @@
<antcall target="internal-test-module">
<param name="module" value="security"/>
</antcall>
- <!--antcall target="internal-test-module">
+ <antcall target="internal-test-module">
<param name="module" value="identity"/>
- </antcall-->
+ </antcall>
<antcall target="internal-test-module">
<param name="module" value="server"/>
</antcall>
17 years, 4 months
JBoss Portal SVN: r6582 - in trunk/common/src/main/org/jboss/portal: test/common and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-03-07 13:16:51 -0500 (Wed, 07 Mar 2007)
New Revision: 6582
Modified:
trunk/common/src/main/org/jboss/portal/common/util/URLTools.java
trunk/common/src/main/org/jboss/portal/test/common/URLToolsTestCase.java
Log:
improve a bit timeout stuff
Modified: trunk/common/src/main/org/jboss/portal/common/util/URLTools.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/URLTools.java 2007-03-07 17:54:30 UTC (rev 6581)
+++ trunk/common/src/main/org/jboss/portal/common/util/URLTools.java 2007-03-07 18:16:51 UTC (rev 6582)
@@ -60,7 +60,9 @@
/**
* Fetches content from an HTTP server performing a GET operation. If the status code is 200
- * then it will return a byte array of the body otherwise returns null.
+ * then it will return a byte array of the body otherwise returns null. The timeout values
+ * must not be negative integers, when it is equals to zero it means that it does not setup
+ * a timeout and use the default values.
*
* @param url the URL the URL of the resource
* @param soTimeoutMillis the socket connection timeout in millis
@@ -73,13 +75,27 @@
{
throw new IllegalArgumentException();
}
+ if (soTimeoutMillis < 0)
+ {
+ throw new IllegalArgumentException("No negative socket timeout");
+ }
+ if (connTimeoutMillis < 0)
+ {
+ throw new IllegalArgumentException("No negative connection timeout");
+ }
if ("http".equals(url.getProtocol()) || "https".equals(url.getProtocol()))
{
HttpClient client = new HttpClient();
// Yes deprecated but advocated way to do will not for with 2.0.2 which is what today JBoss AS ships
- client.setConnectionTimeout(connTimeoutMillis);
- client.setTimeout(soTimeoutMillis);
+ if (connTimeoutMillis > 0)
+ {
+ client.setConnectionTimeout(connTimeoutMillis);
+ }
+ if (soTimeoutMillis > 0)
+ {
+ client.setTimeout(soTimeoutMillis);
+ }
//
HttpMethod method = null;
Modified: trunk/common/src/main/org/jboss/portal/test/common/URLToolsTestCase.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/test/common/URLToolsTestCase.java 2007-03-07 17:54:30 UTC (rev 6581)
+++ trunk/common/src/main/org/jboss/portal/test/common/URLToolsTestCase.java 2007-03-07 18:16:51 UTC (rev 6582)
@@ -24,7 +24,10 @@
import junit.framework.TestCase;
import org.jboss.portal.common.util.URLTools;
+import org.apache.log4j.net.SocketServer;
+import java.net.URL;
+
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris Laprun</a>
* @version $Revision$
17 years, 4 months
JBoss Portal SVN: r6581 - in trunk: common/src/main/org/jboss/portal/common/util and 1 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-03-07 12:54:30 -0500 (Wed, 07 Mar 2007)
New Revision: 6581
Modified:
trunk/common/build.xml
trunk/common/src/main/org/jboss/portal/common/util/URLTools.java
trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetFactory.java
trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetProvider.java
Log:
added timeout on get retrieval
Modified: trunk/common/build.xml
===================================================================
--- trunk/common/build.xml 2007-03-07 16:38:02 UTC (rev 6580)
+++ trunk/common/build.xml 2007-03-07 17:54:30 UTC (rev 6581)
@@ -72,6 +72,7 @@
<path refid="apache.log4j.classpath"/>
<path refid="jboss.test.classpath"/>
<path refid="junit.junit.classpath"/>
+ <path refid="apache.httpclient.classpath"/>
<pathelement location="../tools/lib/cargo-core-uberjar-0.8.jar"/>
<pathelement location="../tools/lib/cargo-ant-0.8.jar"/>
<pathelement location="../tools/lib/ant-junit.jar"/>
Modified: trunk/common/src/main/org/jboss/portal/common/util/URLTools.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/URLTools.java 2007-03-07 16:38:02 UTC (rev 6580)
+++ trunk/common/src/main/org/jboss/portal/common/util/URLTools.java 2007-03-07 17:54:30 UTC (rev 6581)
@@ -22,7 +22,12 @@
******************************************************************************/
package org.jboss.portal.common.util;
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
+
import java.io.UnsupportedEncodingException;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder;
@@ -54,6 +59,51 @@
}
/**
+ * Fetches content from an HTTP server performing a GET operation. If the status code is 200
+ * then it will return a byte array of the body otherwise returns null.
+ *
+ * @param url the URL the URL of the resource
+ * @param soTimeoutMillis the socket connection timeout in millis
+ * @param connTimeoutMillis the connection timeout in millis
+ * @return
+ */
+ public static byte[] performGET(URL url, int soTimeoutMillis, int connTimeoutMillis) throws IllegalArgumentException, IOException
+ {
+ if (url == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if ("http".equals(url.getProtocol()) || "https".equals(url.getProtocol()))
+ {
+ HttpClient client = new HttpClient();
+
+ // Yes deprecated but advocated way to do will not for with 2.0.2 which is what today JBoss AS ships
+ client.setConnectionTimeout(connTimeoutMillis);
+ client.setTimeout(soTimeoutMillis);
+
+ //
+ HttpMethod method = null;
+ try
+ {
+ method = new GetMethod(url.toString());
+ int statusCode = client.executeMethod(method);
+ if (statusCode == 200)
+ {
+ return method.getResponseBody();
+ }
+ }
+ finally
+ {
+ if (method != null)
+ {
+ method.releaseConnection();
+ }
+ }
+ }
+ throw new IllegalArgumentException("Protocol " + url.getProtocol() + " not accepted");
+ }
+
+ /**
* @param url
* @return
* @since 2.4.2
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetFactory.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetFactory.java 2007-03-07 16:38:02 UTC (rev 6580)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetFactory.java 2007-03-07 17:54:30 UTC (rev 6581)
@@ -24,6 +24,7 @@
import org.jboss.portal.common.util.XML;
import org.jboss.portal.common.util.LocalizedString;
+import org.jboss.portal.common.util.URLTools;
import org.jboss.portal.widget.google.type.DataType;
import org.jboss.portal.widget.google.type.StringType;
import org.jboss.portal.widget.google.type.LocationType;
@@ -41,6 +42,7 @@
import java.util.Locale;
import java.util.Collection;
import java.util.ArrayList;
+import java.io.ByteArrayInputStream;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -70,7 +72,12 @@
{
DocumentBuilderFactory factory = XML.getDocumentBuilderFactory();
DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(url.toString());
+ byte[] bytes = URLTools.performGET(url, 5000, 5000);
+ if (bytes == null)
+ {
+ throw new Exception("Cannot retrieve document " + url);
+ }
+ Document doc = builder.parse(new ByteArrayInputStream(bytes));
Element moduleElt = doc.getDocumentElement();
//
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetProvider.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetProvider.java 2007-03-07 16:38:02 UTC (rev 6580)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetProvider.java 2007-03-07 17:54:30 UTC (rev 6581)
@@ -25,7 +25,6 @@
import java.net.URL;
import java.net.MalformedURLException;
import java.io.InputStreamReader;
-import java.io.InputStream;
import java.io.ByteArrayInputStream;
import java.util.StringTokenizer;
import java.util.HashMap;
@@ -39,7 +38,7 @@
import org.jboss.portal.widget.WidgetProvider;
import org.jboss.portal.widget.Widget;
-import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.util.URLTools;
import org.apache.log4j.Logger;
import javax.swing.text.html.HTML;
@@ -57,7 +56,6 @@
/**
* @todo first :
- * - add time out on URL retrieval
* - add content type filtering
* - finish implementation of preferences
* - use categorization
@@ -171,19 +169,13 @@
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);
+ byte[] bytes = URLTools.performGET(url, 5000, 5000);
+ if (bytes == null)
{
- log.info("Retrieving " + url);
- in = url.openStream();
- bytes = Tools.getBytes(in);
- log.info("Document " + url + " has been retrieved");
+ throw new Exception("Cannot retrieve " + url);
}
- finally
- {
- Tools.safeClose(in);
- }
+ log.info("Document " + url + " has been retrieved");
//
final LinkedHashSet urls = new LinkedHashSet();
17 years, 4 months
JBoss Portal SVN: r6580 - trunk/widget/src/main/org/jboss/portal/widget/google.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-03-07 11:38:02 -0500 (Wed, 07 Mar 2007)
New Revision: 6580
Modified:
trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetProvider.java
Log:
added todo list for widgets
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetProvider.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetProvider.java 2007-03-07 16:32:02 UTC (rev 6579)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetProvider.java 2007-03-07 16:38:02 UTC (rev 6580)
@@ -56,6 +56,19 @@
import edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantLock;
/**
+ * @todo first :
+ * - add time out on URL retrieval
+ * - add content type filtering
+ * - finish implementation of preferences
+ * - use categorization
+ * - add pagination
+ * - add configuration
+ * - add caching policy
+ * - add fetching policy
+ *
+ * @todo later but important :
+ * - implement widget retrieval defferring when it would be available later
+ *
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
17 years, 4 months
JBoss Portal SVN: r6579 - in trunk/widget/src/main/org/jboss/portal/widget: google and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-03-07 11:32:02 -0500 (Wed, 07 Mar 2007)
New Revision: 6579
Added:
trunk/widget/src/main/org/jboss/portal/widget/google/GGPreferenceInfo.java
trunk/widget/src/main/org/jboss/portal/widget/google/GGPreferencesInfo.java
trunk/widget/src/main/org/jboss/portal/widget/google/GGWidget.java
trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetFactory.java
trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetProvider.java
trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetRetrieval.java
Removed:
trunk/widget/src/main/org/jboss/portal/widget/google/GWidget.java
trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetFactory.java
trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetPreferenceInfo.java
trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetPreferencesInfo.java
trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetProvider.java
trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetRetrieval.java
Modified:
trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
Log:
renamed GW* to GG* standing for Google Gadget
Modified: trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-07 16:29:26 UTC (rev 6578)
+++ trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-07 16:32:02 UTC (rev 6579)
@@ -22,9 +22,9 @@
******************************************************************************/
package org.jboss.portal.widget;
-import org.jboss.portal.widget.google.GWidgetProvider;
-import org.jboss.portal.widget.google.GWidget;
-import org.jboss.portal.widget.google.GWidgetPreferenceInfo;
+import org.jboss.portal.widget.google.GGWidgetProvider;
+import org.jboss.portal.widget.google.GGWidget;
+import org.jboss.portal.widget.google.GGPreferenceInfo;
import org.jboss.portal.widget.google.type.DataType;
import javax.portlet.GenericPortlet;
@@ -55,7 +55,7 @@
private static final PortletMode EDIT_CONTENT_MODE = new PortletMode("edit_content");
/** . */
- private GWidgetProvider provider = new GWidgetProvider();
+ private GGWidgetProvider provider = new GGWidgetProvider();
public void init() throws PortletException
{
@@ -95,7 +95,7 @@
if ("select".equals(op))
{
String uri = req.getParameter("uri");
- GWidget widget = (GWidget)provider.getWidget(uri);
+ GGWidget widget = (GGWidget)provider.getWidget(uri);
if (widget != null)
{
PortletURL selectURL = resp.createActionURL();
@@ -108,7 +108,7 @@
writer.println("<from>");
for (Iterator i = widget.getPreferencesInfo().getPreferencesInfo().iterator();i.hasNext();)
{
- GWidgetPreferenceInfo prefInfo = (GWidgetPreferenceInfo)i.next();
+ GGPreferenceInfo prefInfo = (GGPreferenceInfo)i.next();
switch (prefInfo.getType().getOrdinal())
{
case DataType.ENUM:
Copied: trunk/widget/src/main/org/jboss/portal/widget/google/GGPreferenceInfo.java (from rev 6575, trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetPreferenceInfo.java)
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGPreferenceInfo.java (rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGPreferenceInfo.java 2007-03-07 16:32:02 UTC (rev 6579)
@@ -0,0 +1,82 @@
+/******************************************************************************
+ * 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.widget.google.type.DataType;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class GGPreferenceInfo
+{
+
+ /** . */
+ private final String name;
+
+ /** . */
+ private final DataType type;
+
+ /** . */
+ private final String displayName;
+
+ /** . */
+ private final boolean required;
+
+ /** . */
+ private final String defaultValue;
+
+ protected GGPreferenceInfo(String name, DataType type, String displayName, boolean required, String defaultValue)
+ {
+ this.name = name;
+ this.type = type;
+ this.displayName = displayName;
+ this.required = required;
+ this.defaultValue = defaultValue;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public DataType getType()
+ {
+ return type;
+ }
+
+ public String getDefaultValue()
+ {
+ return defaultValue;
+ }
+
+ public String getDisplayName()
+ {
+ return displayName;
+ }
+
+ public boolean isRequired()
+ {
+ return required;
+ }
+}
Copied: trunk/widget/src/main/org/jboss/portal/widget/google/GGPreferencesInfo.java (from rev 6575, trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetPreferencesInfo.java)
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGPreferencesInfo.java (rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGPreferencesInfo.java 2007-03-07 16:32:02 UTC (rev 6579)
@@ -0,0 +1,75 @@
+/******************************************************************************
+ * 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.util.Map;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.HashMap;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class GGPreferencesInfo
+{
+
+ public static final GGPreferencesInfo EMPTY_PREFS = new GGPreferencesInfo();
+
+ /** . */
+ private final Map content;
+
+ public GGPreferencesInfo(Collection prefInfos)
+ {
+ if (prefInfos == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ content = new HashMap(prefInfos.size());
+ for (Iterator i = prefInfos.iterator();i.hasNext();)
+ {
+ GGPreferenceInfo prefInfo = (GGPreferenceInfo)i.next();
+ content.put(prefInfo.getName(), prefInfo);
+ }
+ }
+
+ private GGPreferencesInfo()
+ {
+ content = null;
+ }
+
+ public Collection getPreferencesInfo()
+ {
+ return content == null ? Collections.EMPTY_SET : content.values();
+ }
+
+ public GGPreferenceInfo getPreferenceInfo(String name)
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ return content == null ? null : (GGPreferenceInfo)content.get(name);
+ }
+}
Copied: trunk/widget/src/main/org/jboss/portal/widget/google/GGWidget.java (from rev 6575, trunk/widget/src/main/org/jboss/portal/widget/google/GWidget.java)
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGWidget.java (rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGWidget.java 2007-03-07 16:32:02 UTC (rev 6579)
@@ -0,0 +1,181 @@
+/******************************************************************************
+ * 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;
+
+import java.util.Iterator;
+
+/**
+ * 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 GGWidget implements Widget
+{
+
+ /** . */
+ private static final UUIDGenerator generator = new UUIDGenerator();
+
+ /** . */
+ private final String url;
+
+ /** . */
+ private final GGPreferencesInfo prefsInfo;
+
+ /** . */
+ private final LocalizedString title;
+
+ /** . */
+ private final LocalizedString description;
+
+ /** . */
+ private final int width;
+
+ /** . */
+ private final int height;
+
+ public GGWidget(String url,
+ GGPreferencesInfo prefsInfo,
+ LocalizedString title,
+ LocalizedString description,
+ int width,
+ int height)
+ {
+ this.url = url;
+ this.prefsInfo = prefsInfo;
+ this.title = title;
+ this.description = description;
+ this.width = width;
+ this.height = height;
+ }
+
+ public String getId()
+ {
+ return url;
+ }
+
+ public GGPreferencesInfo getPreferencesInfo()
+ {
+ return prefsInfo;
+ }
+
+ public LocalizedString getTitle()
+ {
+ return title;
+ }
+
+ public LocalizedString getDescription()
+ {
+ return description;
+ }
+
+ public String render()
+ {
+ String id = generator.generateKey();
+ StringBuffer tmp = new StringBuffer("http://gmodules.com/ig/ifr?url=").append(url);
+
+ // Generate base params
+ tmp.append("&synd=open");
+ tmp.append("&w=").append(width);
+ tmp.append("&h=").append(height);
+ tmp.append("&title=").append(title.getDefaultString());
+ tmp.append("&border=%23ffffff%7C3px%2C1px+none+%23999999"); // "&border=%23ffffff%7C3px%2C1px+solid+%23999999"
+ tmp.append("&output=js");
+
+ // Append default values
+ for (Iterator i = prefsInfo.getPreferencesInfo().iterator();i.hasNext();)
+ {
+ GGPreferenceInfo prefInfo = (GGPreferenceInfo)i.next();
+ if (prefInfo.getDefaultValue() != null)
+ {
+ tmp.append("&_up").append(prefInfo.getName()).append("=").append(prefInfo.getDefaultValue());
+ }
+ }
+
+ //
+ 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";
+ }
+
+
+}
Copied: trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetFactory.java (from rev 6576, trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetFactory.java)
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetFactory.java (rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetFactory.java 2007-03-07 16:32:02 UTC (rev 6579)
@@ -0,0 +1,176 @@
+/******************************************************************************
+ * 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.jboss.portal.widget.google.type.DataType;
+import org.jboss.portal.widget.google.type.StringType;
+import org.jboss.portal.widget.google.type.LocationType;
+import org.jboss.portal.widget.google.type.HiddenType;
+import org.jboss.portal.widget.google.type.BoolType;
+import org.jboss.portal.widget.google.type.ListType;
+import org.jboss.portal.widget.google.type.EnumType;
+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;
+import java.util.Collection;
+import java.util.ArrayList;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class GGWidgetFactory
+{
+
+ /** . */
+ private final URL url;
+
+ public GGWidgetFactory(URL url)
+ {
+ if (url == null)
+ {
+ throw new IllegalArgumentException("No null URL");
+ }
+ this.url = url;
+ }
+
+ public URL getURL()
+ {
+ return url;
+ }
+
+ public GGWidget create() throws Exception
+ {
+ DocumentBuilderFactory factory = XML.getDocumentBuilderFactory();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.parse(url.toString());
+ Element moduleElt = doc.getDocumentElement();
+
+ //
+ Collection tmp = null;
+ Iterator userPrefsEltIterator = XML.getChildrenIterator(moduleElt, "UserPref");
+ while (userPrefsEltIterator.hasNext())
+ {
+ Element userPref = (Element)userPrefsEltIterator.next();
+ String nameAttr = userPref.getAttribute("name");
+ String displayNameAttr = userPref.getAttribute("displayName");
+ String urlParamAttr = userPref.getAttribute("urlparam");
+ String dataTypeAttr = userPref.getAttribute("datatype");
+ String requiredAttr = userPref.getAttribute("required");
+ String defaultValueAttr = userPref.getAttribute("default_value");
+
+ // We don't support that for now
+ if (urlParamAttr.length() > 0)
+ {
+ throw new Exception();
+ }
+
+ // String is default type when not specified
+ DataType dataType = StringType.getInstance();
+ if (dataTypeAttr.length() > 0)
+ {
+ int dataTypeOrdinal = DataType.parseDataTypeLiteral(dataTypeAttr);
+ switch(dataTypeOrdinal)
+ {
+ case DataType.HIDDEN:
+ dataType = HiddenType.getInstance();
+ break;
+ case DataType.BOOL:
+ dataType = BoolType.getInstance();
+ break;
+ case DataType.STRING:
+ dataType = StringType.getInstance();
+ break;
+ case DataType.LIST:
+ dataType = ListType.getInstance();
+ break;
+ case DataType.ENUM:
+ Collection values = new ArrayList();
+ for (Iterator i = XML.getChildrenIterator(userPref, "EnumValue");i.hasNext();)
+ {
+ Element enumValueElt = (Element)i.next();
+ String valueAttr = enumValueElt.getAttribute("value");
+ String displayValueAttr = enumValueElt.getAttribute("display_value");
+ EnumType.Value value = new EnumType.Value(valueAttr, displayValueAttr.length() > 0 ? displayValueAttr : null);
+ values.add(value);
+ }
+ dataType = new EnumType(values);
+ break;
+ case DataType.LOCATION:
+ dataType = LocationType.getInstance();
+ break;
+ }
+ }
+
+ //
+ GGPreferenceInfo prefInfo = new GGPreferenceInfo(
+ nameAttr,
+ dataType,
+ displayNameAttr.length() > 0 ? displayNameAttr : null,
+ requiredAttr.length() > 0 ? Boolean.valueOf(requiredAttr).booleanValue() : false,
+ defaultValueAttr.length() > 0 ? defaultValueAttr : null
+ );
+
+ //
+ if (tmp == null)
+ {
+ tmp = new ArrayList();
+ }
+ tmp.add(prefInfo);
+ }
+ GGPreferencesInfo prefsInfo = GGPreferencesInfo.EMPTY_PREFS;
+ if (tmp != null)
+ {
+ prefsInfo = new GGPreferencesInfo(tmp);
+ }
+
+ //
+ Iterator modulePrefsEltIterator = XML.getChildrenIterator(moduleElt, "ModulePrefs");
+ if (modulePrefsEltIterator.hasNext())
+ {
+ 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 GGWidget(url.toString(), prefsInfo, title, description, width, height);
+ }
+ else
+ {
+ throw new Exception(); // Basic for now
+ }
+ }
+}
Copied: trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetProvider.java (from rev 6575, trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetProvider.java)
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetProvider.java (rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetProvider.java 2007-03-07 16:32:02 UTC (rev 6579)
@@ -0,0 +1,275 @@
+/******************************************************************************
+ * 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.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 GGWidgetProvider implements WidgetProvider
+{
+
+ /** . */
+ private static final Logger log = Logger.getLogger(GGWidgetProvider.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();
+ GGWidgetRetrieval.List retrievals = (GGWidgetRetrieval.List)tmp.get(key);
+ if (retrievals != null)
+ {
+ GGWidgetRetrieval retrieval = retrievals.getRetrieval(key);
+ if (retrieval.getStatus() == GGWidgetRetrieval.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();
+ GGWidgetFactory widgetFactory = new GGWidgetFactory(widgetURL);
+
+ //
+ if (tmp.size() < BATCH_SIZE)
+ {
+ tmp.add(widgetFactory);
+ }
+ else
+ {
+ GGWidgetRetrieval.List retrievals = new GGWidgetRetrieval.List(executor, tmp);
+ for (int j = 0;j < retrievals.getSize();j++)
+ {
+ GGWidgetFactory 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();
+ }
+ }
+}
Copied: trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetRetrieval.java (from rev 6575, trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetRetrieval.java)
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetRetrieval.java (rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetRetrieval.java 2007-03-07 16:32:02 UTC (rev 6579)
@@ -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 GGWidgetRetrieval
+{
+
+ /** . */
+ private static final Logger log = Logger.getLogger(GGWidgetRetrieval.class);
+
+ /** . */
+ public static int UNAVAILABLE = 0;
+
+ /** . */
+ public static int AVAILABLE = 1;
+
+ /** . */
+ private GGWidget widget;
+
+ public GGWidgetRetrieval(GGWidget widget)
+ {
+ this.widget = widget;
+ }
+
+ public GGWidget 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 GGWidgetFactory[] 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 = (GGWidgetFactory[])c.toArray(new GGWidgetFactory[c.size()]);
+ }
+
+ public int getSize()
+ {
+ return factories.length;
+ }
+
+ public GGWidgetFactory getFactory(int index)
+ {
+ return factories[index];
+ }
+
+ public GGWidgetRetrieval getRetrieval(String key)
+ {
+ for (int i = 0;i < factories.length;i++)
+ {
+ GGWidgetFactory factory = factories[i];
+ if (key.equals(factory.getURL().toString()))
+ {
+ return getRetrieval(i);
+ }
+ }
+ return null;
+ }
+
+ private class Fetcher implements Callable
+ {
+
+ /** . */
+ private final int index;
+
+ /** . */
+ private GGWidgetRetrieval retrieval;
+
+ public Fetcher(int index)
+ {
+ this.index = index;
+ }
+
+ public Object call() throws Exception
+ {
+ GGWidgetFactory factory = factories[index];
+ try
+ {
+ log.info("Creating widget " + factory.getURL());
+ GGWidget widget = factory.create();
+ retrieval = new GGWidgetRetrieval(widget);
+ }
+ catch (Exception e)
+ {
+ log.error("Widget " + factory.getURL() + " was not retrievable", e);
+ retrieval = new GGWidgetRetrieval(null);
+ }
+ return this;
+ }
+ }
+
+ public GGWidgetRetrieval 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));
+ }
+ GGWidgetRetrieval[] retrievals = new GGWidgetRetrieval[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
+ {
+ //
+ GGWidgetRetrieval[] retrievals = (GGWidgetRetrieval[])future.get();
+
+ //
+ return retrievals[index];
+ }
+ catch (Exception e)
+ {
+ return new GGWidgetRetrieval(null);
+ }
+ }
+ }
+}
Deleted: trunk/widget/src/main/org/jboss/portal/widget/google/GWidget.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GWidget.java 2007-03-07 16:29:26 UTC (rev 6578)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GWidget.java 2007-03-07 16:32:02 UTC (rev 6579)
@@ -1,181 +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.common.util.LocalizedString;
-import org.jboss.portal.common.util.UUIDGenerator;
-import org.jboss.portal.widget.Widget;
-
-import java.util.Iterator;
-
-/**
- * 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 GWidget implements Widget
-{
-
- /** . */
- private static final UUIDGenerator generator = new UUIDGenerator();
-
- /** . */
- private final String url;
-
- /** . */
- private final GWidgetPreferencesInfo prefsInfo;
-
- /** . */
- private final LocalizedString title;
-
- /** . */
- private final LocalizedString description;
-
- /** . */
- private final int width;
-
- /** . */
- private final int height;
-
- public GWidget(String url,
- GWidgetPreferencesInfo prefsInfo,
- LocalizedString title,
- LocalizedString description,
- int width,
- int height)
- {
- this.url = url;
- this.prefsInfo = prefsInfo;
- this.title = title;
- this.description = description;
- this.width = width;
- this.height = height;
- }
-
- public String getId()
- {
- return url;
- }
-
- public GWidgetPreferencesInfo getPreferencesInfo()
- {
- return prefsInfo;
- }
-
- public LocalizedString getTitle()
- {
- return title;
- }
-
- public LocalizedString getDescription()
- {
- return description;
- }
-
- public String render()
- {
- String id = generator.generateKey();
- StringBuffer tmp = new StringBuffer("http://gmodules.com/ig/ifr?url=").append(url);
-
- // Generate base params
- tmp.append("&synd=open");
- tmp.append("&w=").append(width);
- tmp.append("&h=").append(height);
- tmp.append("&title=").append(title.getDefaultString());
- tmp.append("&border=%23ffffff%7C3px%2C1px+none+%23999999"); // "&border=%23ffffff%7C3px%2C1px+solid+%23999999"
- tmp.append("&output=js");
-
- // Append default values
- for (Iterator i = prefsInfo.getPreferencesInfo().iterator();i.hasNext();)
- {
- GWidgetPreferenceInfo prefInfo = (GWidgetPreferenceInfo)i.next();
- if (prefInfo.getDefaultValue() != null)
- {
- tmp.append("&_up").append(prefInfo.getName()).append("=").append(prefInfo.getDefaultValue());
- }
- }
-
- //
- 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";
- }
-
-
-}
Deleted: trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetFactory.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetFactory.java 2007-03-07 16:29:26 UTC (rev 6578)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetFactory.java 2007-03-07 16:32:02 UTC (rev 6579)
@@ -1,176 +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.common.util.XML;
-import org.jboss.portal.common.util.LocalizedString;
-import org.jboss.portal.widget.google.type.DataType;
-import org.jboss.portal.widget.google.type.StringType;
-import org.jboss.portal.widget.google.type.LocationType;
-import org.jboss.portal.widget.google.type.HiddenType;
-import org.jboss.portal.widget.google.type.BoolType;
-import org.jboss.portal.widget.google.type.ListType;
-import org.jboss.portal.widget.google.type.EnumType;
-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;
-import java.util.Collection;
-import java.util.ArrayList;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class GWidgetFactory
-{
-
- /** . */
- private final URL url;
-
- public GWidgetFactory(URL url)
- {
- if (url == null)
- {
- throw new IllegalArgumentException("No null URL");
- }
- this.url = url;
- }
-
- public URL getURL()
- {
- return url;
- }
-
- public GWidget create() throws Exception
- {
- DocumentBuilderFactory factory = XML.getDocumentBuilderFactory();
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(url.toString());
- Element moduleElt = doc.getDocumentElement();
-
- //
- Collection tmp = null;
- Iterator userPrefsEltIterator = XML.getChildrenIterator(moduleElt, "UserPref");
- while (userPrefsEltIterator.hasNext())
- {
- Element userPref = (Element)userPrefsEltIterator.next();
- String nameAttr = userPref.getAttribute("name");
- String displayNameAttr = userPref.getAttribute("displayName");
- String urlParamAttr = userPref.getAttribute("urlparam");
- String dataTypeAttr = userPref.getAttribute("datatype");
- String requiredAttr = userPref.getAttribute("required");
- String defaultValueAttr = userPref.getAttribute("default_value");
-
- // We don't support that for now
- if (urlParamAttr.length() > 0)
- {
- throw new Exception();
- }
-
- // String is default type when not specified
- DataType dataType = StringType.getInstance();
- if (dataTypeAttr.length() > 0)
- {
- int dataTypeOrdinal = DataType.parseDataTypeLiteral(dataTypeAttr);
- switch(dataTypeOrdinal)
- {
- case DataType.HIDDEN:
- dataType = HiddenType.getInstance();
- break;
- case DataType.BOOL:
- dataType = BoolType.getInstance();
- break;
- case DataType.STRING:
- dataType = StringType.getInstance();
- break;
- case DataType.LIST:
- dataType = ListType.getInstance();
- break;
- case DataType.ENUM:
- Collection values = new ArrayList();
- for (Iterator i = XML.getChildrenIterator(userPref, "EnumValue");i.hasNext();)
- {
- Element enumValueElt = (Element)i.next();
- String valueAttr = enumValueElt.getAttribute("value");
- String displayValueAttr = enumValueElt.getAttribute("display_value");
- EnumType.Value value = new EnumType.Value(valueAttr, displayValueAttr.length() > 0 ? displayValueAttr : null);
- values.add(value);
- }
- dataType = new EnumType(values);
- break;
- case DataType.LOCATION:
- dataType = LocationType.getInstance();
- break;
- }
- }
-
- //
- GWidgetPreferenceInfo prefInfo = new GWidgetPreferenceInfo(
- nameAttr,
- dataType,
- displayNameAttr.length() > 0 ? displayNameAttr : null,
- requiredAttr.length() > 0 ? Boolean.valueOf(requiredAttr).booleanValue() : false,
- defaultValueAttr.length() > 0 ? defaultValueAttr : null
- );
-
- //
- if (tmp == null)
- {
- tmp = new ArrayList();
- }
- tmp.add(prefInfo);
- }
- GWidgetPreferencesInfo prefsInfo = GWidgetPreferencesInfo.EMPTY_PREFS;
- if (tmp != null)
- {
- prefsInfo = new GWidgetPreferencesInfo(tmp);
- }
-
- //
- Iterator modulePrefsEltIterator = XML.getChildrenIterator(moduleElt, "ModulePrefs");
- if (modulePrefsEltIterator.hasNext())
- {
- 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 GWidget(url.toString(), prefsInfo, title, description, width, height);
- }
- else
- {
- throw new Exception(); // Basic for now
- }
- }
-}
Deleted: trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetPreferenceInfo.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetPreferenceInfo.java 2007-03-07 16:29:26 UTC (rev 6578)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetPreferenceInfo.java 2007-03-07 16:32:02 UTC (rev 6579)
@@ -1,82 +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.widget.google.type.DataType;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class GWidgetPreferenceInfo
-{
-
- /** . */
- private final String name;
-
- /** . */
- private final DataType type;
-
- /** . */
- private final String displayName;
-
- /** . */
- private final boolean required;
-
- /** . */
- private final String defaultValue;
-
- protected GWidgetPreferenceInfo(String name, DataType type, String displayName, boolean required, String defaultValue)
- {
- this.name = name;
- this.type = type;
- this.displayName = displayName;
- this.required = required;
- this.defaultValue = defaultValue;
- }
-
- public String getName()
- {
- return name;
- }
-
- public DataType getType()
- {
- return type;
- }
-
- public String getDefaultValue()
- {
- return defaultValue;
- }
-
- public String getDisplayName()
- {
- return displayName;
- }
-
- public boolean isRequired()
- {
- return required;
- }
-}
Deleted: trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetPreferencesInfo.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetPreferencesInfo.java 2007-03-07 16:29:26 UTC (rev 6578)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetPreferencesInfo.java 2007-03-07 16:32:02 UTC (rev 6579)
@@ -1,75 +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 java.util.Map;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.HashMap;
-import java.util.Collections;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class GWidgetPreferencesInfo
-{
-
- public static final GWidgetPreferencesInfo EMPTY_PREFS = new GWidgetPreferencesInfo();
-
- /** . */
- private final Map content;
-
- public GWidgetPreferencesInfo(Collection prefInfos)
- {
- if (prefInfos == null)
- {
- throw new IllegalArgumentException();
- }
- content = new HashMap(prefInfos.size());
- for (Iterator i = prefInfos.iterator();i.hasNext();)
- {
- GWidgetPreferenceInfo prefInfo = (GWidgetPreferenceInfo)i.next();
- content.put(prefInfo.getName(), prefInfo);
- }
- }
-
- private GWidgetPreferencesInfo()
- {
- content = null;
- }
-
- public Collection getPreferencesInfo()
- {
- return content == null ? Collections.EMPTY_SET : content.values();
- }
-
- public GWidgetPreferenceInfo getPreferenceInfo(String name)
- {
- if (name == null)
- {
- throw new IllegalArgumentException();
- }
- return content == null ? null : (GWidgetPreferenceInfo)content.get(name);
- }
-}
Deleted: trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetProvider.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetProvider.java 2007-03-07 16:29:26 UTC (rev 6578)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetProvider.java 2007-03-07 16:32:02 UTC (rev 6579)
@@ -1,275 +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 java.net.URL;
-import java.net.MalformedURLException;
-import java.io.InputStreamReader;
-import java.io.InputStream;
-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 GWidgetProvider implements WidgetProvider
-{
-
- /** . */
- private static final Logger log = Logger.getLogger(GWidgetProvider.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();
- GWidgetRetrieval.List retrievals = (GWidgetRetrieval.List)tmp.get(key);
- if (retrievals != null)
- {
- GWidgetRetrieval retrieval = retrievals.getRetrieval(key);
- if (retrieval.getStatus() == GWidgetRetrieval.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();
- GWidgetFactory widgetFactory = new GWidgetFactory(widgetURL);
-
- //
- if (tmp.size() < BATCH_SIZE)
- {
- tmp.add(widgetFactory);
- }
- else
- {
- GWidgetRetrieval.List retrievals = new GWidgetRetrieval.List(executor, tmp);
- for (int j = 0;j < retrievals.getSize();j++)
- {
- GWidgetFactory 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();
- }
- }
-}
Deleted: trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetRetrieval.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetRetrieval.java 2007-03-07 16:29:26 UTC (rev 6578)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetRetrieval.java 2007-03-07 16:32:02 UTC (rev 6579)
@@ -1,202 +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 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 GWidgetRetrieval
-{
-
- /** . */
- private static final Logger log = Logger.getLogger(GWidgetRetrieval.class);
-
- /** . */
- public static int UNAVAILABLE = 0;
-
- /** . */
- public static int AVAILABLE = 1;
-
- /** . */
- private GWidget widget;
-
- public GWidgetRetrieval(GWidget widget)
- {
- this.widget = widget;
- }
-
- public GWidget 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 GWidgetFactory[] 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 = (GWidgetFactory[])c.toArray(new GWidgetFactory[c.size()]);
- }
-
- public int getSize()
- {
- return factories.length;
- }
-
- public GWidgetFactory getFactory(int index)
- {
- return factories[index];
- }
-
- public GWidgetRetrieval getRetrieval(String key)
- {
- for (int i = 0;i < factories.length;i++)
- {
- GWidgetFactory factory = factories[i];
- if (key.equals(factory.getURL().toString()))
- {
- return getRetrieval(i);
- }
- }
- return null;
- }
-
- private class Fetcher implements Callable
- {
-
- /** . */
- private final int index;
-
- /** . */
- private GWidgetRetrieval retrieval;
-
- public Fetcher(int index)
- {
- this.index = index;
- }
-
- public Object call() throws Exception
- {
- GWidgetFactory factory = factories[index];
- try
- {
- log.info("Creating widget " + factory.getURL());
- GWidget widget = factory.create();
- retrieval = new GWidgetRetrieval(widget);
- }
- catch (Exception e)
- {
- log.error("Widget " + factory.getURL() + " was not retrievable", e);
- retrieval = new GWidgetRetrieval(null);
- }
- return this;
- }
- }
-
- public GWidgetRetrieval 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));
- }
- GWidgetRetrieval[] retrievals = new GWidgetRetrieval[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
- {
- //
- GWidgetRetrieval[] retrievals = (GWidgetRetrieval[])future.get();
-
- //
- return retrievals[index];
- }
- catch (Exception e)
- {
- return new GWidgetRetrieval(null);
- }
- }
- }
-}
17 years, 4 months
JBoss Portal SVN: r6578 - trunk/widget/src/main/org/jboss/portal/widget.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-03-07 11:29:26 -0500 (Wed, 07 Mar 2007)
New Revision: 6578
Modified:
trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
Log:
when widget is selected, display a form for prefs (but don't proces it now)
Modified: trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-07 16:20:57 UTC (rev 6577)
+++ trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-07 16:29:26 UTC (rev 6578)
@@ -23,6 +23,9 @@
package org.jboss.portal.widget;
import org.jboss.portal.widget.google.GWidgetProvider;
+import org.jboss.portal.widget.google.GWidget;
+import org.jboss.portal.widget.google.GWidgetPreferenceInfo;
+import org.jboss.portal.widget.google.type.DataType;
import javax.portlet.GenericPortlet;
import javax.portlet.RenderRequest;
@@ -92,7 +95,7 @@
if ("select".equals(op))
{
String uri = req.getParameter("uri");
- Widget widget = provider.getWidget(uri);
+ GWidget widget = (GWidget)provider.getWidget(uri);
if (widget != null)
{
PortletURL selectURL = resp.createActionURL();
@@ -100,6 +103,22 @@
selectURL.setParameter("uri", uri);
writer.println("<p>You selected widget " + widget.getTitle() + "</p>");
writer.println("<p><a href=\"" + selectURL + "\">Select</a> widget</p>");
+
+ // Prefs
+ writer.println("<from>");
+ for (Iterator i = widget.getPreferencesInfo().getPreferencesInfo().iterator();i.hasNext();)
+ {
+ GWidgetPreferenceInfo prefInfo = (GWidgetPreferenceInfo)i.next();
+ switch (prefInfo.getType().getOrdinal())
+ {
+ case DataType.ENUM:
+ // Todo
+ break;
+ default:
+ writer.println("<div>" + prefInfo.getName() + ": <input type=\"text\" name=\"" + prefInfo.getName() + "\"/></div>");
+ }
+ }
+ writer.println("</form>");
}
}
17 years, 4 months
JBoss Portal SVN: r6577 - in trunk/widget/src/main/org/jboss/portal/widget: google/type and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-03-07 11:20:57 -0500 (Wed, 07 Mar 2007)
New Revision: 6577
Modified:
trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
trunk/widget/src/main/org/jboss/portal/widget/google/type/EnumType.java
Log:
add widget selection in the edit content mode
Modified: trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-07 16:07:04 UTC (rev 6576)
+++ trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-07 16:20:57 UTC (rev 6577)
@@ -86,6 +86,24 @@
{
resp.setContentType("text/html");
PrintWriter writer = resp.getWriter();
+
+ //
+ String op = req.getParameter("op");
+ if ("select".equals(op))
+ {
+ String uri = req.getParameter("uri");
+ Widget widget = provider.getWidget(uri);
+ if (widget != null)
+ {
+ PortletURL selectURL = resp.createActionURL();
+ selectURL.setParameter("meta_action", "select");
+ selectURL.setParameter("uri", uri);
+ writer.println("<p>You selected widget " + widget.getTitle() + "</p>");
+ writer.println("<p><a href=\"" + selectURL + "\">Select</a> widget</p>");
+ }
+ }
+
+ //
Collection widgets = provider.getKeys();
writer.print("<ul>");
int size = 0;
@@ -95,12 +113,13 @@
Widget widget = provider.getWidget(key);
if (widget != null)
{
- PortletURL url = resp.createActionURL();
- url.setParameter("meta_action", "select");
+ PortletURL url = resp.createRenderURL();
+ url.setParameter("op", "select");
url.setParameter("uri", widget.getId());
writer.print("<li><a href=\"" + url + "\">" + widget.getTitle().getDefaultString() + "</a></li>");
}
}
+
writer.print("/<ul>");
writer.close();
}
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/type/EnumType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/EnumType.java 2007-03-07 16:07:04 UTC (rev 6576)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/EnumType.java 2007-03-07 16:20:57 UTC (rev 6577)
@@ -44,7 +44,7 @@
for (Iterator i = values.iterator();i.hasNext();)
{
Value value = (Value)i.next();
- values.add(value);
+ this.values.add(value);
}
}
17 years, 4 months
JBoss Portal SVN: r6576 - in trunk/widget/src/main/org/jboss/portal/widget/google: type and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-03-07 11:07:04 -0500 (Wed, 07 Mar 2007)
New Revision: 6576
Added:
trunk/widget/src/main/org/jboss/portal/widget/google/type/BoolType.java
trunk/widget/src/main/org/jboss/portal/widget/google/type/EnumType.java
trunk/widget/src/main/org/jboss/portal/widget/google/type/HiddenType.java
trunk/widget/src/main/org/jboss/portal/widget/google/type/ListType.java
trunk/widget/src/main/org/jboss/portal/widget/google/type/LocationType.java
trunk/widget/src/main/org/jboss/portal/widget/google/type/StringType.java
Modified:
trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetFactory.java
trunk/widget/src/main/org/jboss/portal/widget/google/type/DataType.java
Log:
support various data types
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetFactory.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetFactory.java 2007-03-07 15:40:11 UTC (rev 6575)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GWidgetFactory.java 2007-03-07 16:07:04 UTC (rev 6576)
@@ -25,6 +25,12 @@
import org.jboss.portal.common.util.XML;
import org.jboss.portal.common.util.LocalizedString;
import org.jboss.portal.widget.google.type.DataType;
+import org.jboss.portal.widget.google.type.StringType;
+import org.jboss.portal.widget.google.type.LocationType;
+import org.jboss.portal.widget.google.type.HiddenType;
+import org.jboss.portal.widget.google.type.BoolType;
+import org.jboss.portal.widget.google.type.ListType;
+import org.jboss.portal.widget.google.type.EnumType;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@@ -72,13 +78,13 @@
Iterator userPrefsEltIterator = XML.getChildrenIterator(moduleElt, "UserPref");
while (userPrefsEltIterator.hasNext())
{
- Element userPrefs = (Element)userPrefsEltIterator.next();
- String nameAttr = userPrefs.getAttribute("name");
- String displayNameAttr = userPrefs.getAttribute("displayName");
- String urlParamAttr = userPrefs.getAttribute("urlparam");
- String dataTypeAttr = userPrefs.getAttribute("datatype");
- String requiredAttr = userPrefs.getAttribute("required");
- String defaultValueAttr = userPrefs.getAttribute("default_value");
+ Element userPref = (Element)userPrefsEltIterator.next();
+ String nameAttr = userPref.getAttribute("name");
+ String displayNameAttr = userPref.getAttribute("displayName");
+ String urlParamAttr = userPref.getAttribute("urlparam");
+ String dataTypeAttr = userPref.getAttribute("datatype");
+ String requiredAttr = userPref.getAttribute("required");
+ String defaultValueAttr = userPref.getAttribute("default_value");
// We don't support that for now
if (urlParamAttr.length() > 0)
@@ -87,11 +93,40 @@
}
// String is default type when not specified
- DataType dataType = DataType.STRING_TYPE;
+ DataType dataType = StringType.getInstance();
if (dataTypeAttr.length() > 0)
{
- int dataTypeValue = DataType.parseDataTypeLiteral(dataTypeAttr);
- dataType = new DataType(dataTypeValue);
+ int dataTypeOrdinal = DataType.parseDataTypeLiteral(dataTypeAttr);
+ switch(dataTypeOrdinal)
+ {
+ case DataType.HIDDEN:
+ dataType = HiddenType.getInstance();
+ break;
+ case DataType.BOOL:
+ dataType = BoolType.getInstance();
+ break;
+ case DataType.STRING:
+ dataType = StringType.getInstance();
+ break;
+ case DataType.LIST:
+ dataType = ListType.getInstance();
+ break;
+ case DataType.ENUM:
+ Collection values = new ArrayList();
+ for (Iterator i = XML.getChildrenIterator(userPref, "EnumValue");i.hasNext();)
+ {
+ Element enumValueElt = (Element)i.next();
+ String valueAttr = enumValueElt.getAttribute("value");
+ String displayValueAttr = enumValueElt.getAttribute("display_value");
+ EnumType.Value value = new EnumType.Value(valueAttr, displayValueAttr.length() > 0 ? displayValueAttr : null);
+ values.add(value);
+ }
+ dataType = new EnumType(values);
+ break;
+ case DataType.LOCATION:
+ dataType = LocationType.getInstance();
+ break;
+ }
}
//
Added: trunk/widget/src/main/org/jboss/portal/widget/google/type/BoolType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/BoolType.java (rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/BoolType.java 2007-03-07 16:07:04 UTC (rev 6576)
@@ -0,0 +1,48 @@
+/******************************************************************************
+ * 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.type;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class BoolType extends DataType
+{
+
+ /** . */
+ private static final BoolType INSTANCE = new BoolType();
+
+ public static BoolType getInstance()
+ {
+ return INSTANCE;
+ }
+
+ private BoolType()
+ {
+ }
+
+ public int getOrdinal()
+ {
+ return BOOL;
+ }
+}
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/type/DataType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/DataType.java 2007-03-07 15:40:11 UTC (rev 6575)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/DataType.java 2007-03-07 16:07:04 UTC (rev 6576)
@@ -26,7 +26,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class DataType
+public abstract class DataType
{
/** . */
@@ -47,36 +47,8 @@
/** . */
public static final int LOCATION = 5;
- /** . */
- public static final DataType STRING_TYPE = new DataType(STRING);
+ public abstract int getOrdinal();
- /** . */
- private final int value;
-
- /** . */
- private final Object object;
-
- public DataType(int ordinal)
- {
- this(ordinal, null);
- }
-
- public DataType(int dataType, Object dataObject)
- {
- this.value = dataType;
- this.object = dataObject;
- }
-
- public int getValue()
- {
- return value;
- }
-
- public Object getObject()
- {
- return object;
- }
-
public static int parseDataTypeLiteral(String literal)
{
if ("string".equals(literal))
Added: trunk/widget/src/main/org/jboss/portal/widget/google/type/EnumType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/EnumType.java (rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/EnumType.java 2007-03-07 16:07:04 UTC (rev 6576)
@@ -0,0 +1,91 @@
+/******************************************************************************
+ * 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.type;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class EnumType extends DataType
+{
+
+ /** . */
+ private final ArrayList values;
+
+ public EnumType(Collection values)
+ {
+ this.values = new ArrayList(values.size());
+
+ // We just check that objects contained are of the right type
+ for (Iterator i = values.iterator();i.hasNext();)
+ {
+ Value value = (Value)i.next();
+ values.add(value);
+ }
+ }
+
+ public int getSize()
+ {
+ return values.size();
+ }
+
+ public Value getValue(int index)
+ {
+ return (Value)values.get(index);
+ }
+
+ public int getOrdinal()
+ {
+ return ENUM;
+ }
+
+ public static class Value
+ {
+
+ /** . */
+ private final String value;
+
+ /** . */
+ private final String displayValue;
+
+ public Value(String value, String displayValue)
+ {
+ this.value = value;
+ this.displayValue = displayValue;
+ }
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ public String getDisplayValue()
+ {
+ return displayValue;
+ }
+ }
+}
Added: trunk/widget/src/main/org/jboss/portal/widget/google/type/HiddenType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/HiddenType.java (rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/HiddenType.java 2007-03-07 16:07:04 UTC (rev 6576)
@@ -0,0 +1,48 @@
+/******************************************************************************
+ * 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.type;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class HiddenType extends DataType
+{
+
+ /** . */
+ private static final HiddenType INSTANCE = new HiddenType();
+
+ public static HiddenType getInstance()
+ {
+ return INSTANCE;
+ }
+
+ private HiddenType()
+ {
+ }
+
+ public int getOrdinal()
+ {
+ return HIDDEN;
+ }
+}
Added: trunk/widget/src/main/org/jboss/portal/widget/google/type/ListType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/ListType.java (rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/ListType.java 2007-03-07 16:07:04 UTC (rev 6576)
@@ -0,0 +1,48 @@
+/******************************************************************************
+ * 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.type;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ListType extends DataType
+{
+
+ /** . */
+ private static final ListType INSTANCE = new ListType();
+
+ public static ListType getInstance()
+ {
+ return INSTANCE;
+ }
+
+ private ListType()
+ {
+ }
+
+ public int getOrdinal()
+ {
+ return LIST;
+ }
+}
Added: trunk/widget/src/main/org/jboss/portal/widget/google/type/LocationType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/LocationType.java (rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/LocationType.java 2007-03-07 16:07:04 UTC (rev 6576)
@@ -0,0 +1,47 @@
+/******************************************************************************
+ * 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.type;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class LocationType extends DataType
+{
+
+ /** . */
+ private static final LocationType INSTANCE = new LocationType();
+
+ public static LocationType getInstance()
+ {
+ return INSTANCE;
+ }
+
+ {
+ }
+
+ public int getOrdinal()
+ {
+ return LOCATION;
+ }
+}
Added: trunk/widget/src/main/org/jboss/portal/widget/google/type/StringType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/StringType.java (rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/StringType.java 2007-03-07 16:07:04 UTC (rev 6576)
@@ -0,0 +1,48 @@
+/******************************************************************************
+ * 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.type;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class StringType extends DataType
+{
+
+ /** . */
+ private static final StringType INSTANCE = new StringType();
+
+ public static StringType getInstance()
+ {
+ return INSTANCE;
+ }
+
+ private StringType()
+ {
+ }
+
+ public int getOrdinal()
+ {
+ return STRING;
+ }
+}
17 years, 4 months