Author: chris.laprun(a)jboss.com
Date: 2011-08-08 18:53:56 -0400 (Mon, 08 Aug 2011)
New Revision: 7014
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ContentRegistryImpl.java
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java
Log:
- Added implementation for getSite.
- Added more cases to get(Id).
- Renamed SITE_OWNER_COMPONENT to SITE_TYPE_COMPONENT.
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java 2011-08-08
22:51:54 UTC (rev 7013)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java 2011-08-08
22:53:56 UTC (rev 7014)
@@ -96,7 +96,7 @@
private static final String GROUP_CHARS = "\\w|-|_";
- public static final String SITE_OWNER_COMPONENT = "owner";
+ public static final String SITE_TYPE_COMPONENT = "type";
public static final String SITE_NAME_COMPONENT = "name";
public static final String APPLICATION_COMPONENT = "application";
public static final String PORTLET_COMPONENT = "portlet";
@@ -115,7 +115,7 @@
.withDefaultSeparator(".").build();
public static final Context SITE_CONTEXT =
GenericContext.builder().named("Site")
- .requiredComponent(SITE_OWNER_COMPONENT, Identifiable.class,
Pattern.compile(Site.PORTAL_TYPE_NAME + "|" + Site.GROUP_TYPE_NAME +
"|" + Site.DASHBOARD_TYPE_NAME))
+ .requiredComponent(SITE_TYPE_COMPONENT, Identifiable.class,
Pattern.compile(Site.PORTAL_TYPE_NAME + "|" + Site.GROUP_TYPE_NAME +
"|" + Site.DASHBOARD_TYPE_NAME))
.requiredComponent(SITE_NAME_COMPONENT, Site.class, Pattern.compile("(" +
GROUP_CHARS + "|\\/)+"))
.optionalComponent("page", Page.class,
Pattern.compile("\\w+"))
.withDefaultSeparator("::").build();
@@ -470,15 +470,13 @@
{
Class<T> type = id.getIdentifiableType();
- Object result;
+ Object result = null;
- // todo: fix the use canonical names to avoid classloader issues?
- String canonicalName = type.getCanonicalName();
- if (Portal.class.getCanonicalName().equals(canonicalName))
+ if (Portal.class.equals(type))
{
result = getPortal((Id<Portal>)id);
}
- else if (Page.class.getCanonicalName().equals(canonicalName))
+ else if (Page.class.equals(type))
{
try
{
@@ -495,6 +493,23 @@
end();
}
}
+ else if (Site.class.equals(type))
+ {
+ Id<Site> siteId = (Id<Site>)id;
+ result = getSite(siteId, null);
+ }
+ else if (Content.class.equals(type))
+ {
+ final IterableIdentifiableCollection<Portal> portals = getPortals();
+ for (Portal portal : portals)
+ {
+ result = portal.getContentRegistry().get((Id<? extends Content>)id);
+ if (result != null)
+ {
+ break;
+ }
+ }
+ }
else
{
// todo: finish support of other types
@@ -506,8 +521,25 @@
public <T extends Site> T getSite(Id<T> siteId, Type<T> type)
{
- // todo
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ final String siteType = siteId.getComponent(SITE_TYPE_COMPONENT);
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(siteType, "Site
type", "A valid Site Id");
+
+ if (Site.PORTAL.equals(siteType))
+ {
+ return (T)getPortal((Id<Portal>)siteId);
+ }
+ else if (Site.GROUP_TYPE_NAME.equals(siteType))
+ {
+ return (T)getGroupSite(groupId(siteId.getComponent(SITE_NAME_COMPONENT)));
+ }
+ else if (Site.DASHBOARD_TYPE_NAME.equals(siteType))
+ {
+ return (T)getDashboard(userId(siteId.getComponent(SITE_NAME_COMPONENT)));
+ }
+ else
+ {
+ throw new IllegalArgumentException("Unknown Site type: " + siteType);
+ }
}
public Id userId(String user)
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ContentRegistryImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ContentRegistryImpl.java 2011-08-08
22:51:54 UTC (rev 7013)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/content/ContentRegistryImpl.java 2011-08-08
22:53:56 UTC (rev 7014)
@@ -22,7 +22,6 @@
package org.gatein.portal.api.impl.content;
-import org.exoplatform.application.registry.Application;
import org.exoplatform.application.registry.ApplicationCategory;
import org.exoplatform.application.registry.ApplicationRegistryService;
import org.gatein.api.content.Category;
@@ -37,12 +36,16 @@
import org.gatein.api.util.IterableIdentifiableCollection;
import org.gatein.api.util.Query;
import org.gatein.pc.api.PortletContext;
+import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.federation.FederatingPortletInvoker;
import org.gatein.portal.api.impl.GateInImpl;
import org.gatein.portal.api.impl.portal.PortalImpl;
import org.gatein.portal.api.impl.util.AdaptedIterableCollection;
import org.gatein.portal.api.impl.util.AdaptedIterableIdentifiableCollection;
+import org.gatein.portal.api.impl.util.AggregatedIterableIdentifiableCollection;
import java.util.List;
+import java.util.Set;
/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
public class ContentRegistryImpl implements ContentRegistry
@@ -205,17 +208,7 @@
gateIn.begin();
if (Portlet.class.equals(type) || WSRP.class.equals(type))
{
- final PortletContext portletContext;
- if (!id.knowsComponent(GateInImpl.INVOKER_COMPONENT))
- {
- portletContext =
PortletContext.createPortletContext(id.getComponent(GateInImpl.APPLICATION_COMPONENT),
id.getComponent(GateInImpl.PORTLET_COMPONENT));
- regitryItem =
gateIn.getPortletInvoker().getFederatedInvoker("local").getPortletInvoker().getPortlet(portletContext);
- }
- else
- {
- portletContext = PortletContext.createPortletContext(id.toString());
- regitryItem = gateIn.getPortletInvoker().getPortlet(portletContext);
- }
+ regitryItem = getPortletFrom(id);
}
else if (Gadget.class.equals(type))
{
@@ -239,6 +232,23 @@
}
}
+ private <T extends Content> Object getPortletFrom(Id<T> id) throws
PortletInvokerException
+ {
+ PortletContext portletContext;
+ Object regitryItem;
+ if (!id.knowsComponent(GateInImpl.INVOKER_COMPONENT))
+ {
+ portletContext =
PortletContext.createPortletContext(id.getComponent(GateInImpl.APPLICATION_COMPONENT),
id.getComponent(GateInImpl.PORTLET_COMPONENT));
+ regitryItem =
gateIn.getPortletInvoker().getFederatedInvoker("local").getPortletInvoker().getPortlet(portletContext);
+ }
+ else
+ {
+ portletContext = PortletContext.createPortletContext(id.toString());
+ regitryItem = gateIn.getPortletInvoker().getPortlet(portletContext);
+ }
+ return regitryItem;
+ }
+
private <T extends Content> Content newContentFrom(Id id, Object registryItem,
Class<T> wanted)
{
Object result;
@@ -277,23 +287,119 @@
try
{
gateIn.begin();
- final List<Application> applications =
gateIn.getRegistryService().getAllApplications();
+ IterableIdentifiableCollection<? extends Content> localPortlets =
getLocalPortlets();
+ IterableIdentifiableCollection<? extends Content> gadgets = getGadgets();
+ IterableIdentifiableCollection<? extends Content> remotePortlets =
getRemotePortlets();
- return new AdaptedIterableIdentifiableCollection<Application,
Content>(applications.size(), applications.iterator())
+ final AggregatedIterableIdentifiableCollection result = new
AggregatedIterableIdentifiableCollection();
+ result.addCollection(localPortlets);
+ result.addCollection(remotePortlets);
+ result.addCollection(gadgets);
+ return result;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ gateIn.end();
+ }
+ }
+
+ public IterableIdentifiableCollection<Portlet> getLocalPortlets()
+ {
+ try
+ {
+ gateIn.begin();
+ final FederatingPortletInvoker portletInvoker = gateIn.getPortletInvoker();
+ final Set<org.gatein.pc.api.Portlet> initialLocalPortlets =
portletInvoker.getLocalPortlets();
+ return new AdaptedIterableIdentifiableCollection<org.gatein.pc.api.Portlet,
Portlet>(initialLocalPortlets.size(), initialLocalPortlets.iterator())
{
- public Content adapt(Application old)
+ public Portlet adapt(org.gatein.pc.api.Portlet old)
{
- final Id<? extends Content> id = GateInImpl.getContentIdFrom(old);
+ return
(Portlet)newContentFrom(GateInImpl.parsePortletId(old.getContext().getId()), old,
Portlet.class);
+ }
- return get(id);
+ public boolean contains(Id<Portlet> t)
+ {
+ try
+ {
+ return getPortletFrom(t) != null;
+ }
+ catch (PortletInvokerException e)
+ {
+ return false;
+ }
}
+ };
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ gateIn.end();
+ }
+ }
- public boolean contains(Id<Content> t)
+ public IterableIdentifiableCollection<WSRP> getRemotePortlets()
+ {
+ try
+ {
+ gateIn.begin();
+ final FederatingPortletInvoker portletInvoker = gateIn.getPortletInvoker();
+ final Set<org.gatein.pc.api.Portlet> initialRemotePortlets =
portletInvoker.getRemotePortlets();
+ return new AdaptedIterableIdentifiableCollection<org.gatein.pc.api.Portlet,
WSRP>(initialRemotePortlets.size(), initialRemotePortlets.iterator())
+ {
+ public WSRP adapt(org.gatein.pc.api.Portlet old)
{
+ return
(WSRP)newContentFrom(GateInImpl.parseWSRPPortletId(old.getContext().getId()), old,
WSRP.class);
+ }
+
+ public boolean contains(Id<WSRP> id)
+ {
try
{
- return gateIn.getRegistryService().getApplication(t.toString()) !=
null;
+ return getPortletFrom(id) != null;
}
+ catch (PortletInvokerException e)
+ {
+ return false;
+ }
+ }
+ };
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ gateIn.end();
+ }
+ }
+
+ public IterableIdentifiableCollection<Gadget> getGadgets()
+ {
+ try
+ {
+ gateIn.begin();
+ final List<org.exoplatform.application.gadget.Gadget> initialGadgets =
gateIn.getGadgetService().getAllGadgets();
+ return new
AdaptedIterableIdentifiableCollection<org.exoplatform.application.gadget.Gadget,
Gadget>(initialGadgets.size(), initialGadgets.iterator())
+ {
+ public Gadget adapt(org.exoplatform.application.gadget.Gadget old)
+ {
+ return (Gadget)newContentFrom(gateIn.gadgetId(old.getName()), old,
Gadget.class);
+ }
+
+ public boolean contains(Id<Gadget> id)
+ {
+ try
+ {
+ return gateIn.getGadgetService().getGadget(id.toString()) != null;
+ }
catch (Exception e)
{
return false;
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java 2011-08-08
22:51:54 UTC (rev 7013)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java 2011-08-08
22:53:56 UTC (rev 7014)
@@ -328,7 +328,7 @@
Locale locale = Util.getPortalRequestContext().getLocale();
bundle = rbMgr.getNavigationResourceBundle(
locale.getLanguage(),
- site.getComponent(GateInImpl.SITE_OWNER_COMPONENT),
+ site.getComponent(GateInImpl.SITE_TYPE_COMPONENT),
site.getComponent(GateInImpl.SITE_NAME_COMPONENT));
if (bundle == null)