Author: julien(a)jboss.com
Date: 2007-01-18 18:48:10 -0500 (Thu, 18 Jan 2007)
New Revision: 6041
Added:
trunk/common/src/main/org/jboss/portal/common/util/CopyOnWriteRegistry.java
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/AbstractContentEditor.java
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/ContentEditorRegistry.java
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/ContentEditorRegistryService.java
Modified:
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/Configurator.java
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/PortletContentEditor.java
trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
trunk/core/src/resources/portal-core-war/WEB-INF/jboss-portlet.xml
trunk/core/src/resources/portal-core-war/WEB-INF/jsp/dashboard/editpage.jsp
Log:
- added a CopyOnWriteRegistry as I am tired to always write the same code
- added registry for content editors with editor for portlet content
Added: trunk/common/src/main/org/jboss/portal/common/util/CopyOnWriteRegistry.java
===================================================================
--- trunk/common/src/main/org/jboss/portal/common/util/CopyOnWriteRegistry.java
(rev 0)
+++ trunk/common/src/main/org/jboss/portal/common/util/CopyOnWriteRegistry.java 2007-01-18
23:48:10 UTC (rev 6041)
@@ -0,0 +1,120 @@
+/******************************************************************************
+ * 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.common.util;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Set;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class CopyOnWriteRegistry
+{
+
+ /** . */
+ private volatile Map content;
+
+ public CopyOnWriteRegistry()
+ {
+ content = new HashMap();
+ }
+
+ /**
+ * Register an object.
+ *
+ * @param key the registration key
+ * @param object the registered object
+ * @return true if the registration was made
+ * @throws IllegalArgumentException if the one argument is null
+ */
+ public synchronized boolean register(Object key, Object object) throws
IllegalArgumentException
+ {
+ if (key == null)
+ {
+ throw new IllegalArgumentException("No null key accepted");
+ }
+ if (object == null)
+ {
+ throw new IllegalArgumentException("No null value accepted");
+ }
+ if (content.containsKey(key))
+ {
+ return false;
+ }
+ Map tmp = new HashMap(content);
+ tmp.put(key, object);
+ content = tmp;
+ return true;
+ }
+
+ /**
+ * Unregister an object.
+ *
+ * @param key the registration key
+ * @return true if the unregistration was made
+ * @throws IllegalArgumentException if the key is null
+ */
+ public synchronized boolean unregister(Object key) throws IllegalArgumentException
+ {
+ if (key == null)
+ {
+ throw new IllegalArgumentException("No null key accepted");
+ }
+ if (content.containsKey(key))
+ {
+ Map tmp = new HashMap(content);
+ tmp.remove(key);
+ content = tmp;
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Return the known keys.
+ *
+ * @return the keys
+ */
+ public Set getKeys()
+ {
+ return Collections.unmodifiableSet(content.keySet());
+ }
+
+ /**
+ *
+ * @param key the registration key
+ * @return the registeted object
+ * @throws IllegalArgumentException if the key is null
+ */
+ public Object get(Object key) throws IllegalArgumentException
+ {
+ if (key == null)
+ {
+ throw new IllegalArgumentException("No null key accepted");
+ }
+ return content.get(key);
+ }
+}
Added:
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/AbstractContentEditor.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/AbstractContentEditor.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/AbstractContentEditor.java 2007-01-18
23:48:10 UTC (rev 6041)
@@ -0,0 +1,74 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.portlet.dashboard;
+
+import org.jboss.portal.core.model.content.ContentType;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractContentEditor extends AbstractJBossService implements
ContentEditor
+{
+
+ /** . */
+ private String contentType;
+
+ /** . */
+ private ContentType registeredContentType;
+
+ /** . */
+ private ContentEditorRegistry registry;
+
+ public String getContentType()
+ {
+ return contentType;
+ }
+
+ public void setContentType(String contentType)
+ {
+ this.contentType = contentType;
+ }
+
+ public ContentEditorRegistry getRegistry()
+ {
+ return registry;
+ }
+
+ public void setRegistry(ContentEditorRegistry registry)
+ {
+ this.registry = registry;
+ }
+
+ protected void startService() throws Exception
+ {
+ registeredContentType = ContentType.create(contentType);
+ registry.registerEditor(registeredContentType, this);
+ }
+
+ protected void stopService() throws Exception
+ {
+ registry.unregisterEditor(registeredContentType);
+ }
+}
Modified: trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/Configurator.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/Configurator.java 2007-01-18
23:00:28 UTC (rev 6040)
+++
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/Configurator.java 2007-01-18
23:48:10 UTC (rev 6041)
@@ -22,7 +22,6 @@
package org.jboss.portal.core.portlet.dashboard;
import org.jboss.logging.Logger;
-import org.jboss.portal.core.model.instance.InstanceContainer;
import org.jboss.portal.core.model.portal.Page;
import org.jboss.portal.core.model.portal.PageContainer;
import org.jboss.portal.core.model.portal.Portal;
@@ -30,6 +29,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.content.ContentType;
import org.jboss.portal.theme.LayoutService;
import org.jboss.portal.theme.PortalLayout;
import org.jboss.portal.theme.PortalTheme;
@@ -63,31 +63,25 @@
{
private Logger log = Logger.getLogger(Configurator.class);
- private InstanceContainer instanceContainer;
-
private PortalObjectContainer portalObjectContainer;
private LayoutService layoutService;
private ThemeService themeService;
+ private ContentEditorRegistry contentEditorRegistry;
+
public void init()
throws PortletException
{
super.init();
- instanceContainer =
(InstanceContainer)getPortletContext().getAttribute("InstanceContainer");
-
+ //
portalObjectContainer =
(PortalObjectContainer)getPortletContext().getAttribute("PortalObjectContainer");
-
layoutService =
(LayoutService)getPortletContext().getAttribute("LayoutService");
-
themeService =
(ThemeService)getPortletContext().getAttribute("ThemeService");
+ contentEditorRegistry =
(ContentEditorRegistry)getPortletContext().getAttribute("ContentEditorRegistry");
- if (instanceContainer == null)
- {
- throw new PortletException("No InstanceContainer found");
- }
if (portalObjectContainer == null)
{
throw new PortletException("No PortalObjectContainer found");
@@ -100,6 +94,10 @@
{
throw new PortletException("No ThemeService found");
}
+ if (contentEditorRegistry == null)
+ {
+ throw new PortletException("No ContentEditorRegistry found");
+ }
}
private PortalObjectId dashboardId = PortalObjectId.parse("/dashboard",
PortalObjectId.CANONICAL_FORMAT);
@@ -129,9 +127,6 @@
page = portal.getDefaultPage();
}
- // load insances this user has access to.
- List available_instances = (List)instanceContainer.getDefinitions();
-
resp.setContentType("text/html");
try
{
@@ -186,7 +181,7 @@
PortalTheme currentTheme = themeService.getTheme(themeId, true);
// dispatch
- req.setAttribute("available_instances", available_instances);
+ req.setAttribute("registry", contentEditorRegistry);
req.setAttribute("pages", pages);
req.setAttribute("currentPage", page.getName());
req.setAttribute("layouts", layouts);
@@ -226,7 +221,7 @@
String toRegion = actionRequest.getParameter("toRegion");
AddWindowContext ctx = new AddWindowContext(page, toRegion);
- PortletContentEditor editor = new PortletContentEditor();
+ ContentEditor editor = contentEditorRegistry.getEditor(ContentType.PORTLET);
editor.add(actionRequest, ctx);
actionResponse.setRenderParameter("editPageSelect", editPage);
Added:
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/ContentEditorRegistry.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/ContentEditorRegistry.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/ContentEditorRegistry.java 2007-01-18
23:48:10 UTC (rev 6041)
@@ -0,0 +1,39 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.portlet.dashboard;
+
+import org.jboss.portal.core.model.content.ContentType;
+
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ContentEditorRegistry
+{
+ Set getRegisteredContentTypes();
+ void registerEditor(ContentType contentType, ContentEditor editor);
+ void unregisterEditor(ContentType contentType);
+ ContentEditor getEditor(ContentType contentType);
+}
Added:
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/ContentEditorRegistryService.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/ContentEditorRegistryService.java
(rev 0)
+++
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/ContentEditorRegistryService.java 2007-01-18
23:48:10 UTC (rev 6041)
@@ -0,0 +1,65 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.core.portlet.dashboard;
+
+import org.jboss.portal.core.model.content.ContentType;
+import org.jboss.portal.common.util.CopyOnWriteRegistry;
+import org.jboss.portal.jems.as.system.AbstractJBossService;
+
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class ContentEditorRegistryService extends AbstractJBossService implements
ContentEditorRegistry
+{
+
+ /** . */
+ private final CopyOnWriteRegistry registry;
+
+ public ContentEditorRegistryService()
+ {
+ registry = new CopyOnWriteRegistry();
+ }
+
+ public Set getRegisteredContentTypes()
+ {
+ return registry.getKeys();
+ }
+
+ public void registerEditor(ContentType contentType, ContentEditor editor)
+ {
+ registry.register(contentType, editor);
+ }
+
+ public void unregisterEditor(ContentType contentType)
+ {
+ registry.unregister(contentType);
+ }
+
+ public ContentEditor getEditor(ContentType contentType)
+ {
+ return (ContentEditor)registry.get(contentType);
+ }
+}
Modified:
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/PortletContentEditor.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/PortletContentEditor.java 2007-01-18
23:00:28 UTC (rev 6040)
+++
trunk/core/src/main/org/jboss/portal/core/portlet/dashboard/PortletContentEditor.java 2007-01-18
23:48:10 UTC (rev 6041)
@@ -24,6 +24,7 @@
import org.jboss.portal.core.model.content.ContentType;
import org.jboss.portal.core.model.instance.Instance;
+import org.jboss.portal.core.model.instance.InstanceContainer;
import org.jboss.portal.core.impl.model.content.portlet.PortletContent;
import javax.portlet.RenderRequest;
@@ -35,12 +36,26 @@
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
-public class PortletContentEditor implements ContentEditor
+public class PortletContentEditor extends AbstractContentEditor
{
+ /** . */
+ private InstanceContainer instanceContainer;
+
+ public InstanceContainer getInstanceContainer()
+ {
+ return instanceContainer;
+ }
+
+ public void setInstanceContainer(InstanceContainer instanceContainer)
+ {
+ this.instanceContainer = instanceContainer;
+ }
+
public void show(RenderRequest req, PrintWriter writer)
{
- List available_instances =
(List)req.getAttribute("available_instances");
+ // load insances this user has access to.
+ List available_instances = (List)instanceContainer.getDefinitions();
writer.println("<select name=\"available_instances\"
multiple=\"true\" size=\"20\">\n");
for (int i = 0; i < available_instances.size(); i++)
{
Modified: trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2007-01-18
23:00:28 UTC (rev 6040)
+++ trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2007-01-18
23:48:10 UTC (rev 6041)
@@ -1099,9 +1099,32 @@
xmbean-dd=""
xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
<xmbean/>
- <depends
optional-attribute-name="InterceptedDeployer">jboss.web:service=WebServer</depends>
<depends
+
optional-attribute-name="InterceptedDeployer">jboss.web:service=WebServer</depends>
+ <depends
optional-attribute-name="Deployer"
proxy-type="attribute">portal:deployer=PortalWebApp</depends>
</mbean>
+
+ <mbean
+
code="org.jboss.portal.core.portlet.dashboard.ContentEditorRegistryService"
+ name="portal:registry=ContentEditor"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <xmbean/>
+ </mbean>
+ <mbean
+ code="org.jboss.portal.core.portlet.dashboard.PortletContentEditor"
+ name="portal:service=ContentEditor,type=portlet"
+ xmbean-dd=""
+ xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+ <xmbean/>
+ <depends
+ optional-attribute-name="Registry"
+
proxy-type="attribute">portal:registry=ContentEditor</depends>
+ <depends
+ optional-attribute-name="InstanceContainer"
+ proxy-type="attribute">portal:container=Instance</depends>
+ <attribute name="ContentType">portlet</attribute>
+ </mbean>
</server>
Modified: trunk/core/src/resources/portal-core-war/WEB-INF/jboss-portlet.xml
===================================================================
--- trunk/core/src/resources/portal-core-war/WEB-INF/jboss-portlet.xml 2007-01-18 23:00:28
UTC (rev 6040)
+++ trunk/core/src/resources/portal-core-war/WEB-INF/jboss-portlet.xml 2007-01-18 23:48:10
UTC (rev 6041)
@@ -150,4 +150,9 @@
<service-class>org.jboss.portal.federation.FederatingPortletInvoker</service-class>
<service-ref>:service=PortletInvoker,type=Federating</service-ref>
</service>
+ <service>
+ <service-name>ContentEditorRegistry</service-name>
+
<service-class>org.jboss.portal.core.portlet.dashboard.ContentEditorRegistry</service-class>
+ <service-ref>:registry=ContentEditor</service-ref>
+ </service>
</portlet-app>
Modified: trunk/core/src/resources/portal-core-war/WEB-INF/jsp/dashboard/editpage.jsp
===================================================================
--- trunk/core/src/resources/portal-core-war/WEB-INF/jsp/dashboard/editpage.jsp 2007-01-18
23:00:28 UTC (rev 6040)
+++ trunk/core/src/resources/portal-core-war/WEB-INF/jsp/dashboard/editpage.jsp 2007-01-18
23:48:10 UTC (rev 6041)
@@ -9,8 +9,9 @@
<%@ page import="java.util.TreeSet" %>
<%@ page import="org.jboss.portal.core.model.content.ContentType" %>
<%@ page
import="org.jboss.portal.core.impl.model.content.portlet.PortletContent" %>
-<%@ page
import="org.jboss.portal.core.portlet.dashboard.PortletContentEditor" %>
<%@ page import="java.io.PrintWriter" %>
+<%@ page
import="org.jboss.portal.core.portlet.dashboard.ContentEditorRegistry" %>
+<%@ page import="org.jboss.portal.core.portlet.dashboard.ContentEditor"
%>
<%@ page language="java"
extends="org.jboss.portal.core.servlet.jsp.PortalJsp" %>
<%@ taglib
uri="http://java.sun.com/portlet" prefix="portlet"
%>
<%@ taglib uri="/WEB-INF/portal-lib.tld" prefix="n" %>
@@ -222,7 +223,8 @@
</td>
<td class="portlet-section-body" valign="top"
align="right"><b>Available Content</b><br/>
<%
- PortletContentEditor editor = new PortletContentEditor();
+ ContentEditorRegistry registry =
(ContentEditorRegistry)request.getAttribute("registry");
+ ContentEditor editor = registry.getEditor(ContentType.PORTLET);
PrintWriter writer = new PrintWriter(out);
editor.show(renderRequest, writer);
writer.flush();