JBoss Portal SVN: r6625 - in trunk/core-admin/src: resources/portal-admin-war/WEB-INF/jsf and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-03-10 15:58:50 -0500 (Sat, 10 Mar 2007)
New Revision: 6625
Modified:
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml
Log:
since we are not tied by the form for the portal layout submission, rearrange the widgets so we have a better layout
Modified: trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java
===================================================================
--- trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java 2007-03-10 20:33:28 UTC (rev 6624)
+++ trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java 2007-03-10 20:58:50 UTC (rev 6625)
@@ -691,7 +691,7 @@
{
FacesContext faces = FacesContext.getCurrentInstance();
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "No window name!", null);
- faces.addMessage("layoutForm:windowName", message);
+ faces.addMessage("windowName", message);
throw new AbortProcessingException();
}
@@ -701,7 +701,7 @@
{
FacesContext faces = FacesContext.getCurrentInstance();
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Duplicate window name found on this page!", null);
- faces.addMessage("layoutForm:windowName", message);
+ faces.addMessage("windowName", message);
throw new AbortProcessingException();
}
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-10 20:33:28 UTC (rev 6624)
+++ trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml 2007-03-10 20:58:50 UTC (rev 6625)
@@ -13,54 +13,72 @@
<h3>You are editing the page layout</h3>
- <h:form id="layoutForm">
<div style="float:left;padding:0 2em 0 2em">
- <table>
- <c:forEach items="#{portalobjectmgr.regionNames}" var="regionName" varStatus="status">
- <tbody>
- <c:choose>
- <c:when test="#{status.index > 0}">
- <tr>
- <td colspan="3" class="portlet-form-field-label" style="border-width:0px;border-top:1px dashed #d5d5d5">#{regionName} Region</td>
- </tr>
- </c:when>
- <c:otherwise>
- <tr>
- <td colspan="3" class="portlet-form-field-label">#{regionName} Region</td>
- </tr>
- </c:otherwise>
- </c:choose>
- <tr>
- <td>
- <div>
- <h:commandButton value="Up" id="u_#{regionName}" actionListener="#{assignWindowsAction.execute}" styleClass="portlet-form-button"/>
- </div>
- <div>
- <h:commandButton value="Down" id="d_#{regionName}" actionListener="#{assignWindowsAction.execute}" styleClass="portlet-form-button"/>
- </div>
- </td>
- <td>
- <h:selectManyListbox
- value="#{assignWindowsAction.assignedWindows[regionName]}"
- size="7"
- styleClass="windowList portlet-form-field">
- <f:selectItems value="#{portalobjectmgr.windowItemsMap[regionName]}"/>
- </h:selectManyListbox>
- </td>
- <td>
- <div>
- <h:commandButton value="->" id="l_#{regionName}" actionListener="#{assignWindowsAction.execute}" styleClass="portlet-form-button"/>
- </div>
- </td>
- </tr>
- </tbody>
- </c:forEach>
- </table>
+ <h:form id="layoutForm">
+ <table>
+ <c:forEach items="#{portalobjectmgr.regionNames}" var="regionName" varStatus="status">
+ <tbody>
+ <c:choose>
+ <c:when test="#{status.index > 0}">
+ <tr>
+ <td colspan="3" class="portlet-form-field-label" style="border-width:0px;border-top:1px dashed #d5d5d5">#{regionName} Region</td>
+ </tr>
+ </c:when>
+ <c:otherwise>
+ <tr>
+ <td colspan="3" class="portlet-form-field-label">#{regionName} Region</td>
+ </tr>
+ </c:otherwise>
+ </c:choose>
+ <tr>
+ <td>
+ <div>
+ <h:commandButton value="Up" id="u_#{regionName}" actionListener="#{assignWindowsAction.execute}" styleClass="portlet-form-button"/>
+ </div>
+ <div>
+ <h:commandButton value="Down" id="d_#{regionName}" actionListener="#{assignWindowsAction.execute}" styleClass="portlet-form-button"/>
+ </div>
+ </td>
+ <td>
+ <h:selectManyListbox
+ value="#{assignWindowsAction.assignedWindows[regionName]}"
+ size="7"
+ styleClass="windowList portlet-form-field">
+ <f:selectItems value="#{portalobjectmgr.windowItemsMap[regionName]}"/>
+ </h:selectManyListbox>
+ </td>
+ <td>
+ <div>
+ <h:commandButton value="->" id="l_#{regionName}" actionListener="#{assignWindowsAction.execute}" styleClass="portlet-form-button"/>
+ </div>
+ </td>
+ </tr>
+ </tbody>
+ </c:forEach>
+ </table>
+ </h:form>
</div>
<div style="float:left">
<table class="form">
<tr>
<td class="label">
+ <span class="portlet-form-field-label">Content type:</span>
+ </td>
+ <td class="widget">
+ <h:form id="abc">
+ <h:selectOneMenu
+ id="instanceId"
+ value="#{portalobjectmgr.selectedContentType}"
+ styleClass="portlet-form-field contentType">
+ <f:selectItems value="#{portalobjectmgr.availableContentTypes}"/>
+ </h:selectOneMenu>
+ <h:commandButton value="Change" styleClass="portlet-form-button"/>
+ <h:message for="instanceId" errorClass="portlet-msg-error"/>
+ </h:form>
+ </td>
+ </tr>
+ <tr>
+ <td class="label">
<span class="portlet-form-field-label">Window Name:</span>
</td>
<td class="widget">
@@ -81,35 +99,24 @@
</tr>
<tr>
<td class="label">
- <span class="portlet-form-field-label">Content type:</span>
+ <span class="portlet-form-field-label">Portlet content:</span>
</td>
<td class="widget">
- <h:selectOneMenu
- id="instanceId"
- value="#{portalobjectmgr.selectedContentType}"
- styleClass="portlet-form-field contentType">
- <f:selectItems value="#{portalobjectmgr.availableContentTypes}"/>
- </h:selectOneMenu>
- <h:commandButton value="Update" styleClass="portlet-form-button"/>
- <h:message for="instanceId" errorClass="portlet-msg-error"/>
+ <div align="left">
+ <jbp:portlet
+ instanceId="#{portalobjectmgr.selectedContentEditorInstance}"
+ actionListener="#{portalobjectmgr.processEvent}"
+ supportedModes="edit_content"
+ supportedWindowStates="normal"
+ initialMode="edit_content"
+ initialWindowState="normal"
+ onClick="url.setParameter('windowName', document.getElementById('windowName').value).setParameter('targetRegion', document.getElementById('targetRegion').value);"/>
+ </div>
</td>
</tr>
</table>
</div>
- </h:form>
<br />
- <span class="portlet-form-field-label">Portlet content:</span>
- <br />
- <div align="left">
- <jbp:portlet
- instanceId="#{portalobjectmgr.selectedContentEditorInstance}"
- actionListener="#{portalobjectmgr.processEvent}"
- supportedModes="edit_content"
- supportedWindowStates="normal"
- initialMode="edit_content"
- initialWindowState="normal"
- onClick="url.setParameter('windowName', document.getElementById('layoutForm:windowName').value).setParameter('targetRegion', document.getElementById('layoutForm:targetRegion').value);"/>
- </div>
</ui:define>
19 years, 1 month
JBoss Portal SVN: r6624 - in trunk: core-admin/src/resources/portal-admin-war/WEB-INF/jsf and 3 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-03-10 15:33:28 -0500 (Sat, 10 Mar 2007)
New Revision: 6624
Modified:
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
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editWindow.xhtml
trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/CMSPortlet.java
trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSContentEditorPortlet.java
trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
Log:
resurrect edit_content portlet mode as it is better to use it to distinguish between preferences and content editing
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-10 19:16:04 UTC (rev 6623)
+++ trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/portlet/PortletContentEditorPortlet.java 2007-03-10 20:33:28 UTC (rev 6624)
@@ -51,6 +51,9 @@
{
/** . */
+ private final PortletMode EDIT_CONTENT = new PortletMode("edit_content");
+
+ /** . */
private InstanceContainer instanceContainer;
public void init() throws PortletException
@@ -61,7 +64,7 @@
public void processAction(ActionRequest req, ActionResponse resp) throws PortletException, PortletSecurityException, IOException
{
- if (req.getPortletMode().equals(PortletMode.EDIT))
+ if (req.getPortletMode().equals(EDIT_CONTENT))
{
String uri = req.getParameter("uri");
if (uri != null)
@@ -71,8 +74,20 @@
}
}
- protected void doEdit(RenderRequest req, RenderResponse resp) throws PortletException, PortletSecurityException, IOException
+ protected void doDispatch(RenderRequest req, RenderResponse resp) throws PortletException, PortletSecurityException, IOException
{
+ if (EDIT_CONTENT.equals(req.getPortletMode()))
+ {
+ doEditContent(req, resp);
+ }
+ else
+ {
+ super.doDispatch(req, resp);
+ }
+ }
+
+ protected void doEditContent(RenderRequest req, RenderResponse resp) throws PortletException, PortletSecurityException, IOException
+ {
String selectedURI = req.getParameter("uri");
//
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-10 19:16:04 UTC (rev 6623)
+++ trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml 2007-03-10 20:33:28 UTC (rev 6624)
@@ -104,9 +104,9 @@
<jbp:portlet
instanceId="#{portalobjectmgr.selectedContentEditorInstance}"
actionListener="#{portalobjectmgr.processEvent}"
- supportedModes="edit"
+ supportedModes="edit_content"
supportedWindowStates="normal"
- initialMode="edit"
+ initialMode="edit_content"
initialWindowState="normal"
onClick="url.setParameter('windowName', document.getElementById('layoutForm:windowName').value).setParameter('targetRegion', document.getElementById('layoutForm:targetRegion').value);"/>
</div>
Modified: trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editWindow.xhtml
===================================================================
--- trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editWindow.xhtml 2007-03-10 19:16:04 UTC (rev 6623)
+++ trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editWindow.xhtml 2007-03-10 20:33:28 UTC (rev 6624)
@@ -15,9 +15,9 @@
actionListener="#{portalobjectmgr.processEvent}"
instanceId="#{portalobjectmgr.selectedContentEditorInstance}"
renderParameters="#{portalobjectmgr.renderParameters}"
- supportedModes="edit"
+ supportedModes="edit_content"
supportedWindowStates="normal"
- initialMode="edit"
+ initialMode="edit_content"
initialWindowState="normal"/>
</div>
Modified: trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/CMSPortlet.java
===================================================================
--- trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/CMSPortlet.java 2007-03-10 19:16:04 UTC (rev 6623)
+++ trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/CMSPortlet.java 2007-03-10 20:33:28 UTC (rev 6624)
@@ -40,6 +40,7 @@
import javax.portlet.PortletConfig;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
+import javax.portlet.PortletMode;
import org.apache.log4j.Logger;
import org.jboss.portal.cms.CMS;
@@ -135,6 +136,9 @@
public static final String REQUEST_PROPERTY_USE_GLOBAL_URLS = "cms.use_global_urls";
/** . */
+ private static final PortletMode EDIT_CONTENT = new PortletMode("edit_content");
+
+ /** . */
private CMS CMSService;
/** . */
@@ -309,14 +313,30 @@
prd.include(req, resp);
}
+ protected void doDispatch(RenderRequest req, RenderResponse resp) throws PortletException, PortletSecurityException, IOException
+ {
+ if (EDIT_CONTENT.equals(req.getPortletMode()))
+ {
+ doEditContent(req, resp);
+ }
+ else
+ {
+ super.doDispatch(req, resp);
+ }
+ }
+
+ protected void doEditContent(RenderRequest req, RenderResponse resp) throws IOException, PortletException
+ {
+ hack.render(req, resp);
+ }
+
public void doEdit(RenderRequest req, RenderResponse resp) throws IOException, PortletException
{
-// resp.setContentType("text/html");
-// resp.setTitle("Edit");
+ resp.setContentType("text/html");
+ resp.setTitle("Edit");
// // TODO: Allow users to modify start page preferences.
-// PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher(CMS_JSP_PATH + "/edit.jsp");
-// prd.include(req, resp);
- hack.render(req, resp);
+ PortletRequestDispatcher prd = getPortletContext().getRequestDispatcher(CMS_JSP_PATH + "/edit.jsp");
+ prd.include(req, resp);
}
/**
Modified: trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSContentEditorPortlet.java
===================================================================
--- trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSContentEditorPortlet.java 2007-03-10 19:16:04 UTC (rev 6623)
+++ trunk/core-cms/src/main/org/jboss/portal/core/cms/ui/admin/CMSContentEditorPortlet.java 2007-03-10 20:33:28 UTC (rev 6624)
@@ -47,6 +47,9 @@
/** . */
private CMS cmsService;
+
+ /** . */
+ private static final PortletMode EDIT_CONTENT = new PortletMode("edit_content");
public void init() throws PortletException
{
@@ -55,7 +58,7 @@
public void processAction(ActionRequest req, ActionResponse resp) throws PortletException, PortletSecurityException, IOException
{
- if (req.getPortletMode().equals(PortletMode.EDIT))
+ if (req.getPortletMode().equals(EDIT_CONTENT))
{
String uri = req.getParameter("uri");
String path = req.getParameter("path");
@@ -71,8 +74,20 @@
}
}
- protected void doEdit(RenderRequest req, RenderResponse resp) throws PortletException, PortletSecurityException, IOException
+ protected void doDispatch(RenderRequest req, RenderResponse resp) throws PortletException, PortletSecurityException, IOException
{
+ if (EDIT_CONTENT.equals(req.getPortletMode()))
+ {
+ doEditContent(req, resp);
+ }
+ else
+ {
+ super.doDispatch(req, resp);
+ }
+ }
+
+ protected void doEditContent(RenderRequest req, RenderResponse resp) throws PortletException, PortletSecurityException, IOException
+ {
resp.setContentType("text/html");
String sPath = req.getParameter("path");
Modified: trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-10 19:16:04 UTC (rev 6623)
+++ trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-10 20:33:28 UTC (rev 6624)
@@ -34,6 +34,7 @@
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.PortletMode;
import java.io.IOException;
import java.io.PrintWriter;
@@ -45,6 +46,9 @@
{
/** . */
+ private final PortletMode EDIT_CONTENT = new PortletMode("edit_content");
+
+ /** . */
private GGProvider provider = new GGProvider();
public void init() throws PortletException
@@ -75,8 +79,20 @@
}
- protected void doEdit(RenderRequest req, RenderResponse resp) throws PortletException, PortletSecurityException, IOException
+ protected void doDispatch(RenderRequest req, RenderResponse resp) throws PortletException, PortletSecurityException, IOException
{
+ if (EDIT_CONTENT.equals(req.getPortletMode()))
+ {
+ doEditContent(req, resp);
+ }
+ else
+ {
+ super.doDispatch(req, resp);
+ }
+ }
+
+ protected void doEditContent(RenderRequest req, RenderResponse resp) throws PortletException, PortletSecurityException, IOException
+ {
resp.setContentType("text/html");
//
19 years, 1 month
JBoss Portal SVN: r6623 - in trunk/core-admin/src: main/org/jboss/portal/core/faces and 1 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-03-10 14:16:04 -0500 (Sat, 10 Mar 2007)
New Revision: 6623
Modified:
trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java
trunk/core-admin/src/main/org/jboss/portal/core/faces/JSFInvocation.java
trunk/core-admin/src/main/org/jboss/portal/core/faces/UIPortlet.java
trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml
Log:
improved the JSF portlet component to add the capability to add javascript handling before a portlet URL is submitted to the server which allows to add additional parameters in the portlet URL
Modified: trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java
===================================================================
--- trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java 2007-03-10 00:20:00 UTC (rev 6622)
+++ trunk/core-admin/src/main/org/jboss/portal/core/admin/ui/PortalObjectManagerBean.java 2007-03-10 19:16:04 UTC (rev 6623)
@@ -38,6 +38,7 @@
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
+import javax.faces.event.AbortProcessingException;
import javax.faces.model.SelectItem;
import org.jboss.logging.Logger;
@@ -49,6 +50,7 @@
import org.jboss.portal.core.model.portal.PortalObjectContainer;
import org.jboss.portal.core.model.portal.PortalObjectId;
import org.jboss.portal.core.model.portal.Window;
+import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
import org.jboss.portal.core.model.content.ContentType;
import org.jboss.portal.core.model.content.Content;
import org.jboss.portal.core.admin.ui.actions.WindowComparator;
@@ -602,6 +604,34 @@
}
}
+ public List getRegionItems()
+ {
+ try
+ {
+ Map windows = getWindows((Page)getSelectedObject());
+
+ //
+ ArrayList regions = new ArrayList(windows.keySet());
+ Collections.sort(regions);
+ for (int i = 0; i < regions.size();i++)
+ {
+ String regionName = (String)regions.get(i);
+ SelectItem regionItem = new SelectItem(regionName, regionName);
+ regions.set(i, regionItem);
+ }
+
+ //
+ return regions;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+
+ //
+ return Collections.EMPTY_LIST;
+ }
+ }
+
public Map getWindowItemsMap() throws Exception
{
Map windowMap = getWindows((Page)getSelectedObject());
@@ -644,15 +674,41 @@
if (uris != null && uris.length > 0)
{
String uri = uris[0];
-
PortalObject po = getSelectedObject();
switch(po.getType())
{
case PortalObject.TYPE_WINDOW:
+ {
Window window = (Window)po;
window.getContent().setURI(uri);
break;
+ }
case PortalObject.TYPE_PAGE:
+ {
+ // Validate window name
+ String windowName = ((String[])actionParams.get("windowName"))[0];
+ if (windowName.trim().length() == 0)
+ {
+ FacesContext faces = FacesContext.getCurrentInstance();
+ FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "No window name!", null);
+ faces.addMessage("layoutForm:windowName", message);
+ throw new AbortProcessingException();
+ }
+
+ // Check for duplicate window name
+ Page page = (Page)getSelectedObject();
+ if (page.getWindow(windowName) != null)
+ {
+ FacesContext faces = FacesContext.getCurrentInstance();
+ FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Duplicate window name found on this page!", null);
+ faces.addMessage("layoutForm:windowName", message);
+ throw new AbortProcessingException();
+ }
+
+ // Get the target region
+ String targetRegion = ((String[])actionParams.get("targetRegion"))[0];
+
+ //
selectedContentURI = uri;
selectedContentParameters.clear();
for (Iterator i = actionParams.entrySet().iterator();i.hasNext();)
@@ -666,9 +722,54 @@
selectedContentParameters.put(paramName, paramValue);
}
}
+
+ try
+ {
+ Window window = page.createWindow(windowName, selectedContentType, uri);
+ Content content = window.getContent();
+ for (Iterator i = selectedContentParameters.entrySet().iterator();i.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)i.next();
+ String paramName = (String)entry.getKey();
+ String paramValue = (String)entry.getValue();
+ content.setParameter(paramName, paramValue);
+ }
+
+ //
+ window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_REGION, targetRegion);
+ window.setDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER, "" + Integer.MAX_VALUE);
+
+ // Get the windows belonging to the selected region sorted by order
+ List windows = new ArrayList();
+ for (Iterator i = page.getChildren(PortalObject.WINDOW_MASK).iterator();i.hasNext();)
+ {
+ Window tmp = (Window)i.next();
+ if (targetRegion.equals(tmp.getProperty(ThemeConstants.PORTAL_PROP_REGION)))
+ {
+ windows.add(tmp);
+ }
+ }
+
+ // Sort windows
+ Collections.sort(windows, new WindowComparator());
+
+ // Add the created one
+ windows.add(window);
+
+ // Update the order states
+ for (int i = 0;i < windows.size();i++)
+ {
+ Window tmp = (Window)windows.get(i);
+ tmp.setDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER, "" + i);
+ }
+ }
+ catch (DuplicatePortalObjectException unexpected)
+ {
+ unexpected.printStackTrace();
+ }
break;
+ }
}
-
}
}
}
Modified: trunk/core-admin/src/main/org/jboss/portal/core/faces/JSFInvocation.java
===================================================================
--- trunk/core-admin/src/main/org/jboss/portal/core/faces/JSFInvocation.java 2007-03-10 00:20:00 UTC (rev 6622)
+++ trunk/core-admin/src/main/org/jboss/portal/core/faces/JSFInvocation.java 2007-03-10 19:16:04 UTC (rev 6623)
@@ -26,7 +26,6 @@
import org.jboss.portal.portlet.StateString;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.PortletParameters;
-import org.jboss.portal.portlet.PortletParametersStateString;
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.portlet.invocation.RenderInvocation;
import org.jboss.portal.portlet.invocation.ActionInvocation;
Modified: trunk/core-admin/src/main/org/jboss/portal/core/faces/UIPortlet.java
===================================================================
--- trunk/core-admin/src/main/org/jboss/portal/core/faces/UIPortlet.java 2007-03-10 00:20:00 UTC (rev 6622)
+++ trunk/core-admin/src/main/org/jboss/portal/core/faces/UIPortlet.java 2007-03-10 19:16:04 UTC (rev 6623)
@@ -87,6 +87,9 @@
/** The initial mode value if not null, otherwise VIEW is used. */
private String initialMode;
+ /** . */
+ private String onClick;
+
/** The internal nav state. */
private PortletParameters internalNavState;
@@ -211,6 +214,16 @@
this.initialMode = initialMode;
}
+ public String getOnClick()
+ {
+ return onClick;
+ }
+
+ public void setOnClick(String onClick)
+ {
+ this.onClick = onClick;
+ }
+
WindowState getInternalWindowState()
{
if (internalWindowState == null)
@@ -340,7 +353,7 @@
}
//
- Object values[] = new Object[10];
+ Object values[] = new Object[11];
values[0] = super.saveState(faces);
values[1] = instanceId;
values[2] = opaqueValue;
@@ -351,6 +364,7 @@
values[7] = initialMode;
values[8] = internalNavState;
values[9] = internalMode;
+ values[10] = onClick;
return values;
}
@@ -370,6 +384,7 @@
initialMode = (String)values[7];
internalNavState = (PortletParameters)values[8];
internalMode = (Mode)values[9];
+ onClick = (String)values[10];
}
public void decode(FacesContext faces)
@@ -472,8 +487,82 @@
FragmentResponse fragment = (FragmentResponse)pir;
ResponseWriter writer = faces.getResponseWriter();
writer.startElement("div", this);
+ writer.writeAttribute("id", "bilto", null);
writer.write(fragment.getContent());
writer.endElement("div");
+
+ //
+ if (onClick != null)
+ {
+ writer.startElement("script", this);
+ writer.write(
+
+ "var isIE = /msie/i.test(navigator.userAgent);\n" +
+
+ "function attachEvent(elm, eventName, eventHandler) {\n" +
+ " if (isIE) {\n" +
+ " elm.attachEvent(\"on\" + eventName, eventHandler);\n" +
+ " } else {\n" +
+ " elm.addEventListener(eventName, eventHandler, false);\n" +
+ " }\n" +
+ "}\n" +
+
+ "function getEventTarget(event) {\n" +
+ " var targetElement = isIE ? event.srcElement : event.target;\n" +
+ " while (targetElement.nodeType == 3 && targetElement.parentNode != null) {\n" +
+ " targetElement = targetElement.parentNode;\n" +
+ " }\n" +
+ " return targetElement;\n" +
+ "}\n" +
+
+ "\n" +
+
+ "function PortletURL(url) {\n" +
+ " this.params = new Array();\n" +
+ " this.url = url;\n" +
+ " this.setParameter = function(name, value) {;\n" +
+ " this.params[name] = value;\n" +
+ " return this;\n" +
+ " }\n" +
+ " this.toString = function() {;\n" +
+ " var tmp = this.url;\n" +
+ " for (var i in this.params) {\n" +
+ " tmp = tmp + ('&' + i + '=' + this.params[i]);\n" +
+ " };\n" +
+ " return tmp;\n" +
+ " }\n" +
+ "}\n" +
+
+ "function fx(event) {\n" +
+ " var target = getEventTarget(event);\n" +
+ " if (target.nodeName == 'INPUT' && target.type == 'submit') {\n" +
+ " var current = target.parentNode;\n" +
+ " while (current.nodeName != 'FORM' && current.nodeName != 'BODY') {\n" +
+ " current = current.parentNode;\n" +
+ " }\n" +
+ " if (current.nodeName == 'FORM') {\n" +
+ " var action = current.action;\n" +
+ " var portletURL = new PortletURL(action);\n" +
+ " (function(url){" + onClick + "})(portletURL);\n" +
+ " current.action = portletURL.toString();\n" +
+ " } else {\n" +
+ " // Really can't do nothing for now\n" +
+ " }\n" +
+ " }\n" +
+ " else if (target.nodeName == 'A') {\n" +
+ " var href = target.href;\n" +
+ " var portletURL = new PortletURL(href);\n" +
+ " (function(url){" + onClick + "})(portletURL);\n" +
+ " target.href = portletURL.toString();\n" +
+ " }\n" +
+ " \n" +
+ "}\n" +
+
+ "var elt = document.getElementById('bilto');\n" +
+ "attachEvent(elt, 'click', fx);\n"
+ );
+ writer.endElement("script");
+ }
writer.flush();
}
}
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-10 00:20:00 UTC (rev 6622)
+++ trunk/core-admin/src/resources/portal-admin-war/WEB-INF/jsf/editPageLayout.xhtml 2007-03-10 19:16:04 UTC (rev 6623)
@@ -51,9 +51,6 @@
<div>
<h:commandButton value="->" id="l_#{regionName}" actionListener="#{assignWindowsAction.execute}" styleClass="portlet-form-button"/>
</div>
- <div>
- <h:commandButton value="<-" id="r_#{regionName}" actionListener="#{assignWindowsAction.execute}" styleClass="portlet-form-button"/>
- </div>
</td>
</tr>
</tbody>
@@ -73,6 +70,17 @@
</tr>
<tr>
<td class="label">
+ <span class="portlet-form-field-label">Target Region:</span>
+ </td>
+ <td class="widget">
+ <h:selectOneMenu id="targetRegion" styleClass="portlet-form-input-field">
+ <f:selectItems value="#{portalobjectmgr.regionItems}"/>
+ </h:selectOneMenu>
+ <h:message for="targetRegion" errorClass="portlet-msg-error"/>
+ </td>
+ </tr>
+ <tr>
+ <td class="label">
<span class="portlet-form-field-label">Content type:</span>
</td>
<td class="widget">
@@ -99,7 +107,8 @@
supportedModes="edit"
supportedWindowStates="normal"
initialMode="edit"
- initialWindowState="normal"/>
+ initialWindowState="normal"
+ onClick="url.setParameter('windowName', document.getElementById('layoutForm:windowName').value).setParameter('targetRegion', document.getElementById('layoutForm:targetRegion').value);"/>
</div>
</ui:define>
19 years, 1 month
JBoss Portal SVN: r6622 - in trunk/wsrp/src: main/org/jboss/portal/wsrp/consumer and 2 other directories.
by portal-commits@lists.jboss.org
Author: chris.laprun(a)jboss.com
Date: 2007-03-09 19:20:00 -0500 (Fri, 09 Mar 2007)
New Revision: 6622
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/MockConsumerRegistry.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistry.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java
trunk/wsrp/src/main/org/jboss/portal/wsrp/portlet/consumers/WSRPConsumerConfigurationPortlet.java
trunk/wsrp/src/resources/portal-wsrp-war/WEB-INF/jsp/consumers/consumer.jsp
trunk/wsrp/src/resources/portal-wsrp-war/WEB-INF/jsp/consumers/view.jsp
Log:
- Fixed improper initialization of RegistrationInfo: should remove requiresRegistration (and nullRegistration) at some point.
- Added ConsumerRegistry.deactivateConsumer method.
- Added register and deregister methods on ProducerInfo (should make refresh use register). Needs testing.
- Fixed typo in persistentExpirationCacheSeconds name
- Started adding register/deregister/activate/deactivate support in WSRP admin portlet (doesn't work well so far).
Modified: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/MockConsumerRegistry.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/MockConsumerRegistry.java 2007-03-09 22:40:51 UTC (rev 6621)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/MockConsumerRegistry.java 2007-03-10 00:20:00 UTC (rev 6622)
@@ -45,7 +45,12 @@
private Map consumers = new HashMap(3);
private final static RegistrationInfo NULL_REGISTRATION_INFO = new RegistrationInfo();
+ static
+ {
+ NULL_REGISTRATION_INFO.setRequiresRegistration(false);
+ }
+
public MockConsumerRegistry()
{
consumers.put("inDB", new MockWSRPConsumer("inDB"));
@@ -96,4 +101,9 @@
{
return NULL_REGISTRATION_INFO;
}
+
+ public void deactivateConsumerWith(String id) throws ConsumerException
+ {
+ // do nothing
+ }
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistry.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistry.java 2007-03-09 22:40:51 UTC (rev 6621)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistry.java 2007-03-10 00:20:00 UTC (rev 6622)
@@ -56,4 +56,6 @@
void updateProducerInfo(ProducerInfo producerInfo);
RegistrationInfo getDefaultRegistrationInfo();
+
+ void deactivateConsumerWith(String id) throws ConsumerException;
}
\ No newline at end of file
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java 2007-03-09 22:40:51 UTC (rev 6621)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ConsumerRegistryService.java 2007-03-10 00:20:00 UTC (rev 6622)
@@ -156,6 +156,7 @@
if (nullRegistration == null)
{
nullRegistration = new RegistrationInfo();
+ nullRegistration.setRequiresRegistration(false);
session.persist(nullRegistration);
}
}
@@ -175,30 +176,19 @@
// if the consumer associated with the given id is already registered, don't do anything
if (federatingPortletInvoker.getFederatedInvoker(id) == null)
{
- WSRPConsumer consumer = getConsumer(id);
+ startOrStopConsumer(id, true);
+ }
+ }
- if (consumer == null)
- {
- throw new ConsumerException("Consumer with id '" + id + "' doesn't exist!");
- }
+ public void deactivateConsumerWith(String id) throws ConsumerException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(id, "Consumer identifier", "deactivateConsumerWith");
- WSRPConsumerService service = new WSRPConsumerService();
- service.setConsumer(consumer);
- service.setFederatingPortletInvoker(federatingPortletInvoker);
-
- try
- {
- service.start();
- }
- catch (Exception e)
- {
- throw new ConsumerException("Couldn't start Consumer service '" + id + "'", e);
- }
-
- // update ProducerInfo
- updateProducerInfo(service.getConsumer().getProducerInfo());
+ // only process if there is a registered Consumer with the specified id
+ if (federatingPortletInvoker.getFederatedInvoker(id) != null)
+ {
+ startOrStopConsumer(id, false);
}
-
}
public void updateProducerInfo(ProducerInfo producerInfo)
@@ -239,4 +229,37 @@
{
return nullRegistration;
}
+
+ private void startOrStopConsumer(String id, boolean start)
+ {
+ WSRPConsumer consumer = getConsumer(id);
+
+ if (consumer == null)
+ {
+ throw new ConsumerException("Consumer with id '" + id + "' doesn't exist!");
+ }
+
+ WSRPConsumerService service = new WSRPConsumerService();
+ service.setConsumer(consumer);
+ service.setFederatingPortletInvoker(federatingPortletInvoker);
+
+ try
+ {
+ if (start)
+ {
+ service.start();
+ }
+ else
+ {
+ service.stop();
+ }
+ }
+ catch (Exception e)
+ {
+ throw new ConsumerException("Couldn't " + (start ? "start" : "stop") + " Consumer service '" + id + "'", e);
+ }
+
+ // update ProducerInfo
+ updateProducerInfo(service.getConsumer().getProducerInfo());
+ }
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java 2007-03-09 22:40:51 UTC (rev 6621)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/ProducerInfo.java 2007-03-10 00:20:00 UTC (rev 6622)
@@ -77,7 +77,7 @@
private String persistentId;
/** The cache expiration duration (in seconds) for cached values */
- private Integer persitentExpirationCacheSeconds;
+ private Integer persistentExpirationCacheSeconds;
/** The activated status of the associated Consumer */
private boolean persistentActive;
@@ -226,6 +226,8 @@
log.debug("ProducerInfo refresh needed for producer '" + persistentId + "'");
serviceDescription = getServiceDescription();
+ // todo: use register() here!
+
// do we need to call initCookie or not?
requiresInitCookie = serviceDescription.getRequiresInitCookie();
@@ -454,7 +456,7 @@
private boolean useCache()
{
- return persitentExpirationCacheSeconds != null && persitentExpirationCacheSeconds.intValue() > 0;
+ return persistentExpirationCacheSeconds != null && persistentExpirationCacheSeconds.intValue() > 0;
}
private void resetCacheTimerIfNeeded()
@@ -462,7 +464,7 @@
if (useCache())
{
// reset expiration time
- expirationTimeMillis = System.currentTimeMillis() + (persitentExpirationCacheSeconds.intValue() * 1000);
+ expirationTimeMillis = System.currentTimeMillis() + (persistentExpirationCacheSeconds.intValue() * 1000);
}
}
@@ -477,12 +479,12 @@
public Integer getExpirationCacheSeconds()
{
- return persitentExpirationCacheSeconds;
+ return persistentExpirationCacheSeconds;
}
public void setExpirationCacheSeconds(Integer expirationCacheSeconds)
{
- this.persitentExpirationCacheSeconds = expirationCacheSeconds;
+ this.persistentExpirationCacheSeconds = expirationCacheSeconds;
}
private ServiceDescription getServiceDescription() throws PortletInvokerException
@@ -563,7 +565,11 @@
public void resetRegistration() throws PortletInvokerException
{
- persistentRegistrationInfo.resetRegistration();
+ if (persistentRegistrationInfo != null)
+ {
+ persistentRegistrationInfo.resetRegistration();
+ }
+
refresh(true);
}
@@ -604,4 +610,78 @@
throw new RuntimeException(e);
}
}
+
+ public void register() throws PortletInvokerException
+ {
+ register(null);
+ }
+
+ private void register(ServiceDescription serviceDescription) throws PortletInvokerException
+ {
+ if (persistentRegistrationInfo == null)
+ {
+ persistentRegistrationInfo = new RegistrationInfo(this);
+ }
+
+ if (!persistentRegistrationInfo.isRegistrationValid())
+ {
+
+ if (serviceDescription == null)
+ {
+ serviceDescription = getServiceDescription();
+ }
+
+ // check if the configured registration information is correct and if we can get the service description
+ if (persistentRegistrationInfo.initialize(serviceDescription, getId()))
+ {
+ try
+ {
+ log.debug("Attempting registration");
+ RegistrationContext registrationContext = persistentEndpointInfo.getRegistrationService()
+ .register(persistentRegistrationInfo.getRegistrationData());
+
+ if (registrationContext == null)
+ {
+ setActive(false);
+ throw new PortletInvokerException("Received null response after registration from producer '" + persistentId + "'");
+ }
+
+ persistentRegistrationInfo.setRegistrationContext(registrationContext);
+ log.info("Successfully registered with handle: '" + registrationContext.getRegistrationHandle() + "'");
+ }
+ catch (Exception e)
+ {
+ persistentRegistrationInfo.resetRegistration();
+ setActive(false);
+ throw new PortletInvokerException("Couldn't register with producer '" + persistentId + "'", e);
+ }
+ }
+ else
+ {
+ log.info("Consumer is not ready to be registered with producer because of missing or invalid registration information.");
+ setActive(false);
+ throw new PortletInvokerException("Consumer is not ready to be registered with producer because of missing or invalid registration information.");
+ }
+ }
+ }
+
+ public void deregister() throws PortletInvokerException
+ {
+ if (persistentRegistrationInfo != null && persistentRegistrationInfo.isRegistrationValid())
+ {
+ try
+ {
+ persistentEndpointInfo.getRegistrationService().deregister(getRegistrationContext());
+ }
+ catch (Exception e)
+ {
+ throw new PortletInvokerException("Couldn't deregister with producer '" + persistentId + "'", e);
+ }
+ finally
+ {
+ persistentRegistrationInfo.resetRegistration();
+ }
+ }
+
+ }
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java 2007-03-09 22:40:51 UTC (rev 6621)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/consumer/RegistrationInfo.java 2007-03-10 00:20:00 UTC (rev 6622)
@@ -58,7 +58,7 @@
private String consumerName;
private String registrationHandle;
private byte[] registrationState;
- private boolean requiresRegistration;
+ private boolean requiresRegistration; // todo: remove
private Map registrationProperties;
private transient RegistrationData registrationData;
@@ -74,7 +74,7 @@
public RegistrationInfo()
{
consumerName = WSRPConstants.DEFAULT_CONSUMER_NAME;
- requiresRegistration = false;
+ requiresRegistration = true;
}
Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/portlet/consumers/WSRPConsumerConfigurationPortlet.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/portlet/consumers/WSRPConsumerConfigurationPortlet.java 2007-03-09 22:40:51 UTC (rev 6621)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/portlet/consumers/WSRPConsumerConfigurationPortlet.java 2007-03-10 00:20:00 UTC (rev 6622)
@@ -23,7 +23,9 @@
package org.jboss.portal.wsrp.portlet.consumers;
+import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.wsrp.consumer.ConsumerRegistry;
+import org.jboss.portal.wsrp.consumer.ProducerInfo;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
@@ -52,7 +54,11 @@
public static final String OP_LIST = "list";
public static final String OP_ACTIVATE = "activate";
public static final String OP_CONFIGURE = "configure";
+ public static final String OP_REGISTER = "register";
+ private static final String OP_ERROR = "error";
public static final String ID = "id";
+ public static final String ACTIVATE = "activate";
+ public static final String REGISTER = "register";
public static final String CONSUMER = "consumer";
public static final String CONSUMERS_REGISTRY = "ConsumersRegistry";
public static final String OP_EDIT = "editConsumer";
@@ -82,6 +88,7 @@
{
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(JSP_PATH + "view.jsp");
rd.include(request, response);
+ return;
}
// configure a specific consumer
@@ -97,6 +104,7 @@
PortletRequestDispatcher rd = getPortletContext().getRequestDispatcher(JSP_PATH + "consumer.jsp");
rd.include(request, response);
+ return;
}
if (NOT_SUPPORTED.equals(op))
@@ -106,8 +114,18 @@
PortletURL url = response.createRenderURL();
url.setParameter(OP, OP_LIST);
printWriter.println("<a href='" + url + "'>back</a>");
+ return;
}
+ if (OP_ERROR.equals(op))
+ {
+ PrintWriter printWriter = response.getWriter();
+ printWriter.print(request.getParameter("message"));
+ PortletURL url = response.createRenderURL();
+ url.setParameter(OP, OP_LIST);
+ printWriter.println("<br/><a href='" + url + "'>back</a>");
+ return;
+ }
}
public void processAction(ActionRequest request, ActionResponse response) throws PortletException, PortletSecurityException, IOException
@@ -115,19 +133,73 @@
String op = request.getParameter(OP);
if (op == null)
{
- op = OP_LIST;
+ return;
}
+ String id = request.getParameter(ID);
+ if (id == null)
+ {
+ response.setRenderParameter(OP, OP_ERROR);
+ response.setRenderParameter("message", "No Consumer identifier was provided for the request!");
+ return;
+ }
+
if (OP_ACTIVATE.equals(op))
{
- response.setRenderParameter(OP, NOT_SUPPORTED);
- response.setRenderParameter("method", "activate");
+ String activate = request.getParameter(ACTIVATE);
+ if (activate != null)
+ {
+ boolean start = Boolean.parseBoolean(activate);
+ if (start)
+ {
+ registry.activateConsumerWith(id);
+ }
+ else
+ {
+ registry.deactivateConsumerWith(id);
+ }
+ }
+
+ return;
}
+ if (OP_REGISTER.equals(op))
+ {
+ String regString = request.getParameter(REGISTER);
+ if (regString != null)
+ {
+ boolean register = Boolean.parseBoolean(regString);
+
+ try
+ {
+ ProducerInfo info = registry.getConsumer(id).getProducerInfo();
+ if (register)
+ {
+ info.register();
+ }
+ else
+ {
+ info.deregister();
+ }
+
+ response.setRenderParameter(OP, OP_CONFIGURE);
+ response.setRenderParameter(ID, id);
+ }
+ catch (PortletInvokerException e)
+ {
+ response.setRenderParameter(OP, OP_ERROR);
+ response.setRenderParameter("message", e.getLocalizedMessage());
+ }
+ }
+
+ return;
+ }
+
if (OP_EDIT.equals(op))
{
response.setRenderParameter(OP, NOT_SUPPORTED);
response.setRenderParameter("method", "modifying consumer information");
+ return;
}
}
}
\ No newline at end of file
Modified: trunk/wsrp/src/resources/portal-wsrp-war/WEB-INF/jsp/consumers/consumer.jsp
===================================================================
--- trunk/wsrp/src/resources/portal-wsrp-war/WEB-INF/jsp/consumers/consumer.jsp 2007-03-09 22:40:51 UTC (rev 6621)
+++ trunk/wsrp/src/resources/portal-wsrp-war/WEB-INF/jsp/consumers/consumer.jsp 2007-03-10 00:20:00 UTC (rev 6622)
@@ -154,6 +154,21 @@
</td>
</tr>
<%
+}
+else
+{
+%>
+<tr>
+ <td colspan="2">
+ <a href="<portlet:actionURL>
+ <portlet:param name="<%=WSRPConsumerConfigurationPortlet.OP%>" value="<%=WSRPConsumerConfigurationPortlet.OP_REGISTER%>"/>
+ <portlet:param name="<%=WSRPConsumerConfigurationPortlet.ID%>" value="<%=consumer.getProducerId()%>"/>
+ </portlet:actionURL>">
+ <input type="submit" name="registerConsumer" value="Register" class="portlet-form-button"/>
+ </a>
+ </td>
+</tr>
+<%
}
%>
<tr>
Modified: trunk/wsrp/src/resources/portal-wsrp-war/WEB-INF/jsp/consumers/view.jsp
===================================================================
--- trunk/wsrp/src/resources/portal-wsrp-war/WEB-INF/jsp/consumers/view.jsp 2007-03-09 22:40:51 UTC (rev 6621)
+++ trunk/wsrp/src/resources/portal-wsrp-war/WEB-INF/jsp/consumers/view.jsp 2007-03-10 00:20:00 UTC (rev 6622)
@@ -1,5 +1,6 @@
<%@ page import="org.jboss.portal.wsrp.WSRPConsumer" %>
<%@ page import="org.jboss.portal.wsrp.consumer.ConsumerRegistry" %>
+<%@ page import="org.jboss.portal.wsrp.consumer.RegistrationInfo" %>
<%@ page import="org.jboss.portal.wsrp.portlet.consumers.WSRPConsumerConfigurationPortlet" %>
<%@ page import="java.util.Iterator" %>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
@@ -30,9 +31,13 @@
WSRPConsumer consumer = (WSRPConsumer)consumers.next();
String id = consumer.getProducerId();
style = (rowIndex % 2 == 0) ? evenStyle : oddStyle;
+ boolean isActive = consumer.getProducerInfo().isActive();
+ RegistrationInfo regInfo = consumer.getProducerInfo().getRegistrationInfo();
+ boolean isRegistered = (regInfo != null && regInfo.isRegistrationValid());
%>
<tr>
- <td class="<%=style%>">x</td>
+ <td class="<%=style%>"><%= isActive ? "x" : ""%>
+ </td>
<td class="<%=style%>"><a href="<portlet:renderURL>
<portlet:param name="<%=WSRPConsumerConfigurationPortlet.OP%>" value="<%=WSRPConsumerConfigurationPortlet.OP_CONFIGURE%>" />
<portlet:param name="<%=WSRPConsumerConfigurationPortlet.ID%>" value="<%=id%>"/>
@@ -40,15 +45,27 @@
</a>
</td>
<td class="<%=style%>">
+ <a href="<portlet:renderURL>
+ <portlet:param name="<%=WSRPConsumerConfigurationPortlet.OP%>" value="<%=WSRPConsumerConfigurationPortlet.OP_CONFIGURE%>" />
+ <portlet:param name="<%=WSRPConsumerConfigurationPortlet.ID%>" value="<%=id%>"/>
+ </portlet:renderURL>">configure</a> |
<a href="<portlet:actionURL>
- <portlet:param name="<%=WSRPConsumerConfigurationPortlet.OP%>" value="<%=WSRPConsumerConfigurationPortlet.OP_ACTIVATE%>"/>
- <portlet:param name="<%=WSRPConsumerConfigurationPortlet.ID%>" value="<%=id%>"/>
- <portlet:param name="activate" value="false"/>
- </portlet:actionURL>">deactivate</a> |
- <a href="<portlet:renderURL>
- <portlet:param name="<%=WSRPConsumerConfigurationPortlet.OP%>" value="<%=WSRPConsumerConfigurationPortlet.OP_CONFIGURE%>" />
- <portlet:param name="<%=WSRPConsumerConfigurationPortlet.ID%>" value="<%=id%>"/>
- </portlet:renderURL>">configure</a>
+ <portlet:param name="<%=WSRPConsumerConfigurationPortlet.OP%>" value="<%=WSRPConsumerConfigurationPortlet.OP_ACTIVATE%>"/>
+ <portlet:param name="<%=WSRPConsumerConfigurationPortlet.ID%>" value="<%=id%>"/>
+ <portlet:param name="<%=WSRPConsumerConfigurationPortlet.ACTIVATE%>" value="<%=isActive ? "false" : "true"%>"/>
+ </portlet:actionURL>"><%=isActive ? "de" : ""%>activate</a>
+ <%
+ if (isActive)
+ {
+ %>
+ | <a href="<portlet:actionURL>
+ <portlet:param name="<%=WSRPConsumerConfigurationPortlet.OP%>" value="<%=WSRPConsumerConfigurationPortlet.OP_REGISTER%>"/>
+ <portlet:param name="<%=WSRPConsumerConfigurationPortlet.ID%>" value="<%=id%>"/>
+ <portlet:param name="<%=WSRPConsumerConfigurationPortlet.REGISTER%>" value="<%=isRegistered ? "false" : "true"%>"/>
+ </portlet:actionURL>"><%=isRegistered ? "de" : ""%>register</a>
+ <%
+ }
+ %>
</td>
</tr>
<%
19 years, 1 month
JBoss Portal SVN: r6621 - in trunk/widget/src/resources/widget-war/WEB-INF: jsp and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-03-09 17:40:51 -0500 (Fri, 09 Mar 2007)
New Revision: 6621
Added:
trunk/widget/src/resources/widget-war/WEB-INF/jsp/
trunk/widget/src/resources/widget-war/WEB-INF/jsp/edit.jsp
Log:
added query support and cat support in the UI
Added: trunk/widget/src/resources/widget-war/WEB-INF/jsp/edit.jsp
===================================================================
--- trunk/widget/src/resources/widget-war/WEB-INF/jsp/edit.jsp (rev 0)
+++ trunk/widget/src/resources/widget-war/WEB-INF/jsp/edit.jsp 2007-03-09 22:40:51 UTC (rev 6621)
@@ -0,0 +1,102 @@
+<%@ page import="org.jboss.portal.widget.google.provider.GGQueryResult" %>
+<%@ page import="org.jboss.portal.widget.google.provider.GGProvider" %>
+<%@ page import="java.util.Iterator" %>
+<%@ page import="org.jboss.portal.widget.google.GGWidget" %>
+<%@ page import="org.jboss.portal.widget.google.GGPreferenceInfo" %>
+<%@ page import="org.jboss.portal.widget.google.type.DataType" %>
+<%@ page import="org.jboss.portal.widget.google.GGWidgetCategoryInfo" %>
+<%@ page import="org.jboss.portal.widget.google.provider.GGQuery" %>
+<%@ page language="java"%>
+<%@ taglib uri="http://java.sun.com/portlet" prefix="p" %>
+<%@ page isELIgnored="false" %>
+
+<portlet:defineObjects/>
+<div>
+
+<%
+ // Get useful request attributes
+ GGWidget selWidget = (GGWidget)request.getAttribute("selectedWidget");
+ GGProvider provider = (GGProvider)request.getAttribute("provider");
+
+ // Get query term
+ String queryTerm = request.getParameter("query");
+ if (queryTerm == null)
+ {
+ queryTerm = "";
+ }
+
+ // Get category term
+ String catTerm = request.getParameter("cat");
+ if (catTerm == null)
+ {
+ catTerm = "";
+ }
+
+ // Compute query
+ GGQuery query = new GGQuery(0, catTerm, queryTerm);
+ GGQueryResult result = provider.search(query);
+%>
+
+
+<form action="<p:renderURL></p:renderURL>" method="post">
+ <input type="text" name="query"/>
+ <select name="cat">
+ <option value=""> </option>
+ <%
+ for (Iterator i = provider.getCategories().iterator(); i.hasNext();)
+ {
+ GGWidgetCategoryInfo cat = (GGWidgetCategoryInfo)i.next();
+ boolean selected = cat.getName().equals(catTerm);
+ %>
+ <option value="<%= cat.getName() %>" <%= selected ? "selected=\"selected\"" : "" %>><%= cat.getDisplayName() %></option>
+ <%
+ }
+ %>
+ </select>
+ <input type="submit"/>
+</form>
+
+<%
+ if (selWidget != null)
+ {
+%>
+<p>You have selected the widget <%= selWidget.getTitle().getDefaultString() %></p>
+<p>
+ <form action="<p:actionURL><p:param name="meta_action" value="select"/><p:param name="uri" value="<%= selWidget.getId() %>"/></p:actionURL>" method="post">
+ <%
+ for (Iterator i = selWidget.getPreferencesInfo().getPreferencesInfo().iterator(); i.hasNext();)
+ {
+ GGPreferenceInfo prefInfo = (GGPreferenceInfo)i.next();
+ switch (prefInfo.getType().getOrdinal())
+ {
+ case DataType.ENUM:
+ // Todo
+ break;
+ default:
+ %>
+ <div><%= prefInfo.getName() %>: <input type="text" name="param.<%= prefInfo.getName() %>" value="<%= prefInfo.getDefaultValue() != null ? prefInfo.getDefaultValue() : "" %>"/></div>
+ <%
+ }
+ }
+ %>
+ <input type="submit"/>
+ </form>
+</p>
+<%
+ }
+%>
+
+<ul>
+ <%
+ for (Iterator i = result.getWidgetIterator();i.hasNext();)
+ {
+ GGWidget widget = (GGWidget)i.next();
+ %>
+ <li><a href="<p:renderURL><p:param name="op" value="select"/><p:param name="uri" value="<%= widget.getId() %>"/><p:param name="cat" value="<%= catTerm %>"/></p:renderURL>"><%= widget.getTitle().getDefaultString() %></a></li>
+ <%
+ }
+ %>
+</ul>
+
+</div>
+
\ No newline at end of file
19 years, 1 month
JBoss Portal SVN: r6620 - in trunk/widget/src/main/org/jboss/portal/widget: google and 1 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-03-09 17:40:11 -0500 (Fri, 09 Mar 2007)
New Revision: 6620
Added:
trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetCategoryInfo.java
Modified:
trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGProvider.java
Log:
added query support and cat support in the UI
Modified: trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-09 22:04:30 UTC (rev 6619)
+++ trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-09 22:40:11 UTC (rev 6620)
@@ -23,24 +23,19 @@
package org.jboss.portal.widget;
import org.jboss.portal.widget.google.GGWidget;
-import org.jboss.portal.widget.google.GGPreferenceInfo;
import org.jboss.portal.widget.google.provider.GGProvider;
-import org.jboss.portal.widget.google.provider.GGQueryResult;
-import org.jboss.portal.widget.google.type.DataType;
+import org.jboss.portal.widget.google.provider.GGQuery;
import javax.portlet.GenericPortlet;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletSecurityException;
-import javax.portlet.PortletURL;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletRequestDispatcher;
import java.io.IOException;
import java.io.PrintWriter;
-import java.util.Collection;
-import java.util.Iterator;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
Added: trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetCategoryInfo.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetCategoryInfo.java (rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetCategoryInfo.java 2007-03-09 22:40:11 UTC (rev 6620)
@@ -0,0 +1,62 @@
+/******************************************************************************
+ * 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;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class GGWidgetCategoryInfo
+{
+
+ /** . */
+ private final String name;
+
+ /** . */
+ private final String displayName;
+
+
+ public GGWidgetCategoryInfo(String name, String displayName)
+ {
+ if (name == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (displayName == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ this.name = name;
+ this.displayName = displayName;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getDisplayName()
+ {
+ return displayName;
+ }
+}
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGProvider.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGProvider.java 2007-03-09 22:04:30 UTC (rev 6619)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGProvider.java 2007-03-09 22:40:11 UTC (rev 6620)
@@ -34,9 +34,11 @@
import java.net.URL;
import java.net.MalformedURLException;
import java.util.Collections;
+import java.util.Collection;
import org.jboss.portal.widget.google.GGWidget;
-import org.jboss.portal.widget.google.provider.GGWidgetBuilder;
+import org.jboss.portal.widget.google.GGWidgetCategoryInfo;
+import org.jboss.portal.common.util.CollectionBuilder;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -60,6 +62,19 @@
/** . */
private ExecutorService executor;
+ /** . */
+ private static final Collection CATEGORIES = Collections.unmodifiableList(new CollectionBuilder()
+ .add(new GGWidgetCategoryInfo("all", "Popular"))
+ .add(new GGWidgetCategoryInfo("news", "News"))
+ .add(new GGWidgetCategoryInfo("communication", "Communication"))
+ .add(new GGWidgetCategoryInfo("funandgames", "Fun & Games"))
+ .add(new GGWidgetCategoryInfo("finance", "Finance"))
+ .add(new GGWidgetCategoryInfo("sports", "Sports"))
+ .add(new GGWidgetCategoryInfo("lifestyle", "Lifestyle"))
+ .add(new GGWidgetCategoryInfo("technology", "Technology"))
+ .add(new GGWidgetCategoryInfo("new", "New stuff"))
+ .toArrayList());
+
public void start()
{
executor = new ThreadPoolExecutor(4, 4, 0, TimeUnit.SECONDS, new LinkedBlockingDeque());
@@ -71,6 +86,11 @@
executor = null;
}
+ public Collection getCategories()
+ {
+ return CATEGORIES;
+ }
+
public GGWidget getWidget(String id)
{
if (id == null)
19 years, 1 month
JBoss Portal SVN: r6619 - in trunk/widget/src/main/org/jboss/portal/widget: google/provider and 1 other directory.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-03-09 17:04:30 -0500 (Fri, 09 Mar 2007)
New Revision: 6619
Modified:
trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResult.java
Log:
update widget portlet to use JSP for presentation
Modified: trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-09 19:53:29 UTC (rev 6618)
+++ trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-09 22:04:30 UTC (rev 6619)
@@ -36,6 +36,7 @@
import javax.portlet.PortletURL;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
+import javax.portlet.PortletRequestDispatcher;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;
@@ -82,9 +83,11 @@
protected void doEdit(RenderRequest req, RenderResponse resp) throws PortletException, PortletSecurityException, IOException
{
resp.setContentType("text/html");
- PrintWriter writer = resp.getWriter();
//
+ req.setAttribute("provider", provider);
+
+ //
String op = req.getParameter("op");
if ("select".equals(op))
{
@@ -92,50 +95,13 @@
GGWidget 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>");
-
- // Prefs
- writer.println("<form action=\"" + selectURL + "\" method=\"post\">");
- for (Iterator i = widget.getPreferencesInfo().getPreferencesInfo().iterator();i.hasNext();)
- {
- GGPreferenceInfo prefInfo = (GGPreferenceInfo)i.next();
- switch (prefInfo.getType().getOrdinal())
- {
- case DataType.ENUM:
- // Todo
- break;
- default:
- writer.println("<div>" + prefInfo.getName() + ": <input type=\"text\" name=\"param." + prefInfo.getName() + "\"" +
- (prefInfo.getDefaultValue() != null ? (" value=\"" + prefInfo.getDefaultValue() + "\"") : "") + "/></div>");
- }
- }
- writer.println("<input type=\"submit\"/>");
- writer.println("</form>");
+ req.setAttribute("selectedWidget", widget);
}
}
//
- GGQueryResult result = provider.search(GGProvider.INITIAL_QUERY);
- writer.print("<ul>");
- int size = 0;
- for (Iterator i = result.getWidgets();i.hasNext() && size < 9;size++)
- {
- Widget widget = (Widget)i.next();
- if (widget != null)
- {
- 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();
+ PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/edit.jsp");
+ dispatcher.include(req, resp);
}
public void destroy()
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResult.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResult.java 2007-03-09 19:53:29 UTC (rev 6618)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResult.java 2007-03-09 22:04:30 UTC (rev 6619)
@@ -60,7 +60,7 @@
return query;
}
- public Iterator getWidgets()
+ public Iterator getWidgetIterator()
{
return new WidgetIterator();
}
19 years, 1 month
JBoss Portal SVN: r6618 - trunk/widget/src/main/org/jboss/portal/widget/google/provider.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-03-09 14:53:29 -0500 (Fri, 09 Mar 2007)
New Revision: 6618
Modified:
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGProvider.java
Log:
minor
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGProvider.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGProvider.java 2007-03-09 19:50:16 UTC (rev 6617)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGProvider.java 2007-03-09 19:53:29 UTC (rev 6618)
@@ -55,7 +55,7 @@
private final ConcurrentMap searches = new ConcurrentHashMap();
/** . */
- private Context context = new Context();
+ private final Context context = new Context();
/** . */
private ExecutorService executor;
19 years, 1 month
JBoss Portal SVN: r6617 - in trunk/widget/src/main/org/jboss/portal/widget/google: provider and 1 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-03-09 14:50:16 -0500 (Fri, 09 Mar 2007)
New Revision: 6617
Modified:
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/provider/GGQuery.java
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResult.java
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResultBuilder.java
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetBuilder.java
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
Log:
changed access modifiers when needed and made some class final
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/GGPreferenceInfo.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGPreferenceInfo.java 2007-03-09 19:48:05 UTC (rev 6616)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGPreferenceInfo.java 2007-03-09 19:50:16 UTC (rev 6617)
@@ -28,7 +28,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class GGPreferenceInfo
+public final class GGPreferenceInfo
{
/** . */
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/GGPreferencesInfo.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGPreferencesInfo.java 2007-03-09 19:48:05 UTC (rev 6616)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGPreferencesInfo.java 2007-03-09 19:50:16 UTC (rev 6617)
@@ -32,7 +32,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class GGPreferencesInfo
+public final class GGPreferencesInfo
{
public static final GGPreferencesInfo EMPTY_PREFS = new GGPreferencesInfo();
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQuery.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQuery.java 2007-03-09 19:48:05 UTC (rev 6616)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQuery.java 2007-03-09 19:50:16 UTC (rev 6617)
@@ -26,7 +26,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class GGQuery
+public final class GGQuery
{
/** . */
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResult.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResult.java 2007-03-09 19:48:05 UTC (rev 6616)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResult.java 2007-03-09 19:50:16 UTC (rev 6617)
@@ -32,7 +32,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class GGQueryResult
+public final class GGQueryResult
{
/** . */
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResultBuilder.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResultBuilder.java 2007-03-09 19:48:05 UTC (rev 6616)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResultBuilder.java 2007-03-09 19:50:16 UTC (rev 6617)
@@ -33,7 +33,6 @@
import java.util.Map;
import java.util.HashMap;
import java.util.StringTokenizer;
-import java.util.Collection;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Collections;
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetBuilder.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetBuilder.java 2007-03-09 19:48:05 UTC (rev 6616)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetBuilder.java 2007-03-09 19:50:16 UTC (rev 6617)
@@ -52,7 +52,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class GGWidgetBuilder implements ObjectLoader
+class GGWidgetBuilder implements ObjectLoader
{
/** . */
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/type/BoolType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/BoolType.java 2007-03-09 19:48:05 UTC (rev 6616)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/BoolType.java 2007-03-09 19:50:16 UTC (rev 6617)
@@ -26,7 +26,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class BoolType extends DataType
+public final class BoolType extends DataType
{
/** . */
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-09 19:48:05 UTC (rev 6616)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/EnumType.java 2007-03-09 19:50:16 UTC (rev 6617)
@@ -30,7 +30,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class EnumType extends DataType
+public final class EnumType extends DataType
{
/** . */
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/type/HiddenType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/HiddenType.java 2007-03-09 19:48:05 UTC (rev 6616)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/HiddenType.java 2007-03-09 19:50:16 UTC (rev 6617)
@@ -26,7 +26,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class HiddenType extends DataType
+public final class HiddenType extends DataType
{
/** . */
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/type/ListType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/ListType.java 2007-03-09 19:48:05 UTC (rev 6616)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/ListType.java 2007-03-09 19:50:16 UTC (rev 6617)
@@ -26,7 +26,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class ListType extends DataType
+public final class ListType extends DataType
{
/** . */
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/type/LocationType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/LocationType.java 2007-03-09 19:48:05 UTC (rev 6616)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/LocationType.java 2007-03-09 19:50:16 UTC (rev 6617)
@@ -26,7 +26,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class LocationType extends DataType
+public final class LocationType extends DataType
{
/** . */
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/type/StringType.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/type/StringType.java 2007-03-09 19:48:05 UTC (rev 6616)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/type/StringType.java 2007-03-09 19:50:16 UTC (rev 6617)
@@ -26,7 +26,7 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class StringType extends DataType
+public final class StringType extends DataType
{
/** . */
19 years, 1 month
JBoss Portal SVN: r6616 - in trunk/widget/src/main/org/jboss/portal/widget: google and 1 other directories.
by portal-commits@lists.jboss.org
Author: julien(a)jboss.com
Date: 2007-03-09 14:48:05 -0500 (Fri, 09 Mar 2007)
New Revision: 6616
Added:
trunk/widget/src/main/org/jboss/portal/widget/google/provider/
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGProvider.java
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQuery.java
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResult.java
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResultBuilder.java
trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetBuilder.java
Removed:
trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetBatch.java
trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetFactory.java
trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetProvider.java
Modified:
trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
trunk/widget/src/main/org/jboss/portal/widget/google/GGPreferenceInfo.java
Log:
- added query support for widget provider
- rewrote the widget fetching part in order to handle queries
Modified: trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-09 08:05:41 UTC (rev 6615)
+++ trunk/widget/src/main/org/jboss/portal/widget/WidgetPortlet.java 2007-03-09 19:48:05 UTC (rev 6616)
@@ -22,9 +22,10 @@
******************************************************************************/
package org.jboss.portal.widget;
-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.provider.GGProvider;
+import org.jboss.portal.widget.google.provider.GGQueryResult;
import org.jboss.portal.widget.google.type.DataType;
import javax.portlet.GenericPortlet;
@@ -48,7 +49,7 @@
{
/** . */
- private GGWidgetProvider provider = new GGWidgetProvider();
+ private GGProvider provider = new GGProvider();
public void init() throws PortletException
{
@@ -88,7 +89,7 @@
if ("select".equals(op))
{
String uri = req.getParameter("uri");
- GGWidget widget = (GGWidget)provider.getWidget(uri);
+ GGWidget widget = provider.getWidget(uri);
if (widget != null)
{
PortletURL selectURL = resp.createActionURL();
@@ -118,13 +119,12 @@
}
//
- Collection widgets = provider.getKeys();
+ GGQueryResult result = provider.search(GGProvider.INITIAL_QUERY);
writer.print("<ul>");
int size = 0;
- for (Iterator i = widgets.iterator();i.hasNext() && size < 9;size++)
+ for (Iterator i = result.getWidgets();i.hasNext() && size < 9;size++)
{
- String key = (String)i.next();
- Widget widget = provider.getWidget(key);
+ Widget widget = (Widget)i.next();
if (widget != null)
{
PortletURL url = resp.createRenderURL();
Modified: trunk/widget/src/main/org/jboss/portal/widget/google/GGPreferenceInfo.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGPreferenceInfo.java 2007-03-09 08:05:41 UTC (rev 6615)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGPreferenceInfo.java 2007-03-09 19:48:05 UTC (rev 6616)
@@ -46,7 +46,7 @@
/** . */
private final String defaultValue;
- protected GGPreferenceInfo(String name, DataType type, String displayName, boolean required, String defaultValue)
+ public GGPreferenceInfo(String name, DataType type, String displayName, boolean required, String defaultValue)
{
this.name = name;
this.type = type;
Deleted: trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetBatch.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetBatch.java 2007-03-09 08:05:41 UTC (rev 6615)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetBatch.java 2007-03-09 19:48:05 UTC (rev 6616)
@@ -1,64 +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.apache.log4j.Logger;
-import org.jboss.portal.common.concurrent.loader.ObjectBatch;
-import org.jboss.portal.common.concurrent.loader.LoadingPolicy;
-import org.jboss.portal.common.concurrent.loader.LoaderContext;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class GGWidgetBatch
-{
-
- /** . */
- private static final Logger log = Logger.getLogger(GGWidgetBatch.class);
-
- /** . */
- private final ObjectBatch batch;
-
- public GGWidgetBatch(GGWidgetFactory[] factories)
- {
- this.batch = new ObjectBatch(factories, LoadingPolicy.LOAD_ALL_ASYNC);
- }
-
- public int getSize()
- {
- return batch.getSize();
- }
-
- public GGWidget getWidget(LoaderContext loaderContext, int index)
- {
- try
- {
- return (GGWidget)batch.getObject(loaderContext, index);
- }
- catch (InterruptedException e)
- {
- return null;
- }
- }
-}
Deleted: trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetFactory.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetFactory.java 2007-03-09 08:05:41 UTC (rev 6615)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetFactory.java 2007-03-09 19:48:05 UTC (rev 6616)
@@ -1,200 +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.common.util.URLTools;
-import org.jboss.portal.common.concurrent.loader.ObjectLoader;
-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;
-import java.io.ByteArrayInputStream;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class GGWidgetFactory implements ObjectLoader
-{
-
- /** . */
- 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 Object load()
- {
- try
- {
- return create();
- }
- catch (Exception e)
- {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
-
- //
- return null;
- }
- }
-
- public GGWidget create() throws Exception
- {
- DocumentBuilderFactory factory = XML.getDocumentBuilderFactory();
- DocumentBuilder builder = factory.newDocumentBuilder();
- 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();
-
- //
- 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
- }
- }
-}
Deleted: trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetProvider.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetProvider.java 2007-03-09 08:05:41 UTC (rev 6615)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetProvider.java 2007-03-09 19:48:05 UTC (rev 6616)
@@ -1,284 +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.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.URLTools;
-import org.jboss.portal.common.concurrent.loader.ObjectBatch;
-import org.jboss.portal.common.concurrent.loader.ObjectLoader;
-import org.jboss.portal.common.concurrent.loader.LoadingPolicy;
-import org.jboss.portal.common.concurrent.loader.LoaderContext;
-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.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.ExecutorCompletionService;
-
-/**
- * @todo first :
- * - add content type filtering
- * - finish implementation of preferences
- * - use categorization
- * - add pagination
- * - add configuration
- * - add caching policy
- * - add fetching policy
- * - add markup caching in the portlet
- *
- * @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 $
- */
-public class GGWidgetProvider implements WidgetProvider
-{
-
- /** . */
- private static final Logger log = Logger.getLogger(GGWidgetProvider.class);
-
- /** . */
- private ObjectBatch batch;
-
- /** . */
- private ExecutorService executor;
-
- /** . */
- private LoaderContext loaderContext;
-
- public GGWidgetProvider()
- {
- }
-
- public void start()
- {
- executor = new ThreadPoolExecutor(4, 4, 0, TimeUnit.SECONDS, new LinkedBlockingDeque());
- loaderContext = new LoaderContext(new ExecutorCompletionService(executor));
- batch = new ObjectBatch(new ObjectLoader[]{new WidgetBuilder()}, LoadingPolicy.LOAD_ONE);
- }
-
- public void stop()
- {
- executor.shutdownNow();
- executor = null;
- loaderContext = null;
- batch = null;
- }
-
- private Map getMap()
- {
- try
- {
- return (Map)batch.getObject(loaderContext, 0);
- }
- catch (InterruptedException e)
- {
- return null;
- }
- }
-
- public Collection getKeys()
- {
- Map map = getMap();
- if (map == null)
- {
- return Collections.EMPTY_SET;
- }
- return map.keySet();
- }
-
- public Widget getWidget(String key)
- {
- if (key == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- Map map = getMap();
- if (map == null)
- {
- return null;
- }
-
- //
- GGWidgetBatch batch = (GGWidgetBatch)map.get(key);
- if (batch != null)
- {
- for (int i = 0;i < batch.getSize();i++)
- {
- GGWidget widget = batch.getWidget(loaderContext, i);
- if (widget != null && widget.getId().equals(key))
- {
- return widget;
- }
- }
- }
-
- //
- return null;
- }
-
- private class WidgetBuilder implements ObjectLoader
- {
-
- public Object load()
- {
- try
- {
- // Find widget URLs
- URL url = new URL("http://www.google.com/ig/directory?synd=open");
-
- // Read fully the URL content first
- log.info("Retrieving " + url);
- byte[] bytes = URLTools.performGET(url, 5000, 5000);
- if (bytes == null)
- {
- throw new Exception("Cannot retrieve " + url);
- }
- log.info("Document " + url + " has been retrieved");
-
- //
- 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
- {
- GGWidgetFactory[] factories = (GGWidgetFactory[])tmp.toArray(new GGWidgetFactory[tmp.size()]);
- GGWidgetBatch retrievals = new GGWidgetBatch(factories);
- for (int j = 0;j < factories.length;j++)
- {
- String furl = factories[j].getURL().toString();
- map.put(furl, retrievals);
- log.info("Added widget for later retrieval" + furl);
- }
-
- //
- tmp.clear();
- tmp.add(widgetFactory);
- }
- }
-
- //
- return Collections.unmodifiableMap(map);
- }
- catch (Exception e)
- {
- e.printStackTrace();
- return null;
- }
- }
- }
-
- private static final int BATCH_SIZE = 6;
-
- private static class ParserAccessor extends HTMLEditorKit
- {
- public Parser getParser()
- {
- return super.getParser();
- }
- }
-}
Added: trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGProvider.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGProvider.java (rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGProvider.java 2007-03-09 19:48:05 UTC (rev 6616)
@@ -0,0 +1,214 @@
+/******************************************************************************
+ * 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.provider;
+
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentMap;
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+import edu.emory.mathcs.backport.java.util.concurrent.Callable;
+import edu.emory.mathcs.backport.java.util.concurrent.FutureTask;
+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 java.net.URL;
+import java.net.MalformedURLException;
+import java.util.Collections;
+
+import org.jboss.portal.widget.google.GGWidget;
+import org.jboss.portal.widget.google.provider.GGWidgetBuilder;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class GGProvider
+{
+
+ /** . */
+ public static final GGQuery INITIAL_QUERY = new GGQuery(0, null, null);
+
+ /** The different descriptors. */
+ private final ConcurrentMap entries = new ConcurrentHashMap();
+
+ /** The query searches. */
+ private final ConcurrentMap searches = new ConcurrentHashMap();
+
+ /** . */
+ private Context context = new Context();
+
+ /** . */
+ private ExecutorService executor;
+
+ public void start()
+ {
+ executor = new ThreadPoolExecutor(4, 4, 0, TimeUnit.SECONDS, new LinkedBlockingDeque());
+ }
+
+ public void stop()
+ {
+ executor.shutdownNow();
+ executor = null;
+ }
+
+ public GGWidget getWidget(String id)
+ {
+ if (id == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ try
+ {
+ URL url = new URL(id);
+ return context.getWidgetEntry(url).getWidget();
+ }
+ catch (MalformedURLException e)
+ {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public GGQueryResult search(GGQuery query)
+ {
+ if (query == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ QueryEntry tmp = new QueryEntry(query);
+ QueryEntry entry = (QueryEntry)searches.putIfAbsent(query, tmp);
+ if (entry == null)
+ {
+ entry = tmp;
+ entry.retrieve();
+ }
+ return entry.getResult();
+ }
+
+ public class Context
+ {
+ GGProvider.GGWidgetEntry getWidgetEntry(URL url)
+ {
+ GGProvider.GGWidgetEntry tmp = new GGProvider.GGWidgetEntry(url);
+ GGProvider.GGWidgetEntry entry = (GGProvider.GGWidgetEntry)entries.putIfAbsent(url, tmp);
+ if (entry == null)
+ {
+ entry = tmp;
+ entry.retrieve();
+ }
+ return entry;
+ }
+ }
+
+ public class GGWidgetEntry implements Callable
+ {
+
+ /** The widget id. */
+ private final URL url;
+
+ /** . */
+ private FutureTask future;
+
+ public GGWidgetEntry(URL url)
+ {
+ this.url = url;
+ this.future = new FutureTask(this);
+ }
+
+ public void retrieve()
+ {
+ executor.submit(future);
+ }
+
+ public GGWidget getWidget()
+ {
+ try
+ {
+ return (GGWidget)future.get();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ return null;
+ }
+ }
+
+ public Object call()
+ {
+ try
+ {
+ GGWidgetBuilder builder = new GGWidgetBuilder(url);
+ return builder.create();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ return null;
+ }
+ }
+ }
+
+ private class QueryEntry implements Callable
+ {
+
+ /** . */
+ private final GGQuery query;
+
+ /** . */
+ private FutureTask future;
+
+ public QueryEntry(GGQuery query)
+ {
+ this.query = query;
+ this.future = new FutureTask(this);
+ }
+
+ public void retrieve()
+ {
+ executor.submit(future);
+ }
+
+ public GGQueryResult getResult()
+ {
+ try
+ {
+ return (GGQueryResult)future.get();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ return new GGQueryResult(query, Collections.EMPTY_LIST);
+ }
+ }
+
+ public Object call()
+ {
+ GGQueryResultBuilder builder = new GGQueryResultBuilder(query);
+ return builder.build(context);
+ }
+ }
+}
Added: trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQuery.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQuery.java (rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQuery.java 2007-03-09 19:48:05 UTC (rev 6616)
@@ -0,0 +1,112 @@
+/******************************************************************************
+ * 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.provider;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class GGQuery
+{
+
+ /** . */
+ private int start;
+
+ /** Zero or negative means it is not used. */
+ private int num = 24;
+
+ /** . */
+ private String cat;
+
+ /** . */
+ private String q;
+
+ /** . */
+ private int hashCode;
+
+ public GGQuery(int start, String cat, String q)
+ {
+ if (start < 0)
+ {
+ throw new IllegalArgumentException("No negative start");
+ }
+ if (cat != null && cat.length() == 0)
+ {
+ cat = null;
+ }
+ if (q != null && q.length() == 0)
+ {
+ q = null;
+ }
+
+ //
+ this.start = start;
+ this.num = 10;
+ this.cat = cat;
+ this.q = q;
+ this.hashCode = start + (cat == null ? 0 : 1 + cat.hashCode()) + (q == null ? 0 : 1 + q.hashCode());
+ }
+
+
+ public int getStart()
+ {
+ return start;
+ }
+
+ public int getNum()
+ {
+ return num;
+ }
+
+ public String getCat()
+ {
+ return cat;
+ }
+
+ public String getQ()
+ {
+ return q;
+ }
+
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj instanceof GGQuery)
+ {
+ GGQuery that = (GGQuery)obj;
+ return
+ (this.start == that.start) &&
+ (this.cat == null ? that.cat == null : this.cat.equals(that.cat)) &&
+ (this.q == null ? that.q == null : this.q.equals(that.q));
+ }
+ return false;
+ }
+
+ public int hashCode()
+ {
+ return hashCode;
+ }
+}
Added: trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResult.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResult.java (rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResult.java 2007-03-09 19:48:05 UTC (rev 6616)
@@ -0,0 +1,113 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.widget.google.provider;
+
+import org.jboss.portal.widget.google.GGWidget;
+
+import java.util.List;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class GGQueryResult
+{
+
+ /** . */
+ private final GGQuery query;
+
+ /** . */
+ private List widgetEntries;
+
+ GGQueryResult(GGQuery query, List widgetEntries)
+ {
+ if (query == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (widgetEntries == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ this.query = query;
+ this.widgetEntries = widgetEntries;
+ }
+
+ public GGQuery getQuery()
+ {
+ return query;
+ }
+
+ public Iterator getWidgets()
+ {
+ return new WidgetIterator();
+ }
+
+ private class WidgetIterator implements Iterator
+ {
+
+ Iterator iterator = widgetEntries.iterator();
+
+ GGWidget next;
+
+ public boolean hasNext()
+ {
+ if (next == null)
+ {
+ findNext();
+ }
+ return next != null;
+ }
+
+ public Object next()
+ {
+ if (next == null)
+ {
+ findNext();
+ }
+ if (next == null)
+ {
+ throw new NoSuchElementException();
+ }
+ GGWidget tmp = next;
+ next = null;
+ return tmp;
+ }
+
+ void findNext()
+ {
+ while (iterator.hasNext() && next == null)
+ {
+ GGProvider.GGWidgetEntry entry = (GGProvider.GGWidgetEntry)iterator.next();
+ next = entry.getWidget();
+ }
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+}
Added: trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResultBuilder.java
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResultBuilder.java (rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGQueryResultBuilder.java 2007-03-09 19:48:05 UTC (rev 6616)
@@ -0,0 +1,179 @@
+/******************************************************************************
+ * 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.provider;
+
+import org.jboss.portal.common.util.URLTools;
+
+import javax.swing.text.html.HTMLEditorKit;
+import javax.swing.text.html.HTML;
+import javax.swing.text.MutableAttributeSet;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.StringTokenizer;
+import java.util.Collection;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.Collections;
+import java.util.List;
+import java.io.InputStreamReader;
+import java.io.ByteArrayInputStream;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+class GGQueryResultBuilder
+{
+
+ /** . */
+ private final GGQuery query;
+
+ public GGQueryResultBuilder(GGQuery query)
+ {
+ if (query == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ this.query = query;
+ }
+
+ private URL getURLQuery() throws MalformedURLException
+ {
+ StringBuffer buffer = new StringBuffer("http://www.google.com/ig/directory?synd=open");
+ if (query.getStart() > 0)
+ {
+ buffer.append("&start=").append(query.getStart());
+ }
+ if (query.getNum() > 0)
+ {
+ buffer.append("&num=").append(query.getNum());
+ }
+ if (query.getCat() != null)
+ {
+ buffer.append("&cat=").append(query.getCat());
+ }
+ if (query.getQ() != null)
+ {
+ buffer.append("&q=").append(query.getQ());
+ }
+ return new URL(buffer.toString());
+ }
+
+ public GGQueryResult build(GGProvider.Context context)
+ {
+ try
+ {
+ // Find widget URLs
+ URL url = getURLQuery() ;
+
+ // Read fully the URL content first
+ // log.info("Retrieving " + url);
+ byte[] bytes = URLTools.performGET(url, 5000, 5000);
+ if (bytes == null)
+ {
+ throw new Exception("Cannot retrieve " + url);
+ }
+ // log.info("Document " + url + " has been retrieved");
+
+ //
+ 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);
+
+ // Now parse each
+ List widgetEntries = new ArrayList(urls.size());
+ for (Iterator i = urls.iterator();i.hasNext();)
+ {
+ URL widgetURL = (URL)i.next();
+ GGProvider.GGWidgetEntry entry = context.getWidgetEntry(widgetURL);
+ widgetEntries.add(entry);
+ }
+
+ //
+ return new GGQueryResult(query, widgetEntries);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+
+ return new GGQueryResult(query, Collections.EMPTY_LIST);
+ }
+
+ private static class ParserAccessor extends HTMLEditorKit
+ {
+ public Parser getParser()
+ {
+ return super.getParser();
+ }
+ }
+
+}
Copied: trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetBuilder.java (from rev 6605, trunk/widget/src/main/org/jboss/portal/widget/google/GGWidgetFactory.java)
===================================================================
--- trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetBuilder.java (rev 0)
+++ trunk/widget/src/main/org/jboss/portal/widget/google/provider/GGWidgetBuilder.java 2007-03-09 19:48:05 UTC (rev 6616)
@@ -0,0 +1,203 @@
+/******************************************************************************
+ * 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.provider;
+
+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.common.concurrent.loader.ObjectLoader;
+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.jboss.portal.widget.google.GGWidget;
+import org.jboss.portal.widget.google.GGPreferenceInfo;
+import org.jboss.portal.widget.google.GGPreferencesInfo;
+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;
+import java.io.ByteArrayInputStream;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class GGWidgetBuilder implements ObjectLoader
+{
+
+ /** . */
+ private final URL url;
+
+ public GGWidgetBuilder(URL url)
+ {
+ if (url == null)
+ {
+ throw new IllegalArgumentException("No null URL");
+ }
+ this.url = url;
+ }
+
+ public URL getURL()
+ {
+ return url;
+ }
+
+
+ public Object load()
+ {
+ try
+ {
+ return create();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+
+ //
+ return null;
+ }
+ }
+
+ public GGWidget create() throws Exception
+ {
+ DocumentBuilderFactory factory = XML.getDocumentBuilderFactory();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ 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();
+
+ //
+ 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
+ }
+ }
+}
19 years, 1 month