Author: chris.laprun(a)jboss.com
Date: 2011-07-15 17:24:39 -0400 (Fri, 15 Jul 2011)
New Revision: 6873
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/NavigationImpl.java
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/PortalImpl.java
Log:
- Fixed loading of root Navigation in PortalImpl and started implementing Navigation.
- Implemented Portal.getPriority.
- Adapted for API changes.
- Modified Context to also handle Page Ids.
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-07-15
10:00:09 UTC (rev 6872)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/GateInImpl.java 2011-07-15
21:24:39 UTC (rev 6873)
@@ -30,7 +30,9 @@
import org.exoplatform.portal.config.Query;
import org.exoplatform.portal.mop.SiteType;
import org.exoplatform.portal.mop.navigation.NavigationService;
+import org.exoplatform.portal.pom.data.DashboardData;
import org.exoplatform.portal.pom.data.ModelDataStorage;
+import org.exoplatform.portal.pom.data.PageData;
import org.exoplatform.portal.pom.data.PortalData;
import org.exoplatform.portal.pom.data.PortalKey;
import org.gatein.api.GateIn;
@@ -43,6 +45,7 @@
import org.gatein.api.id.Context;
import org.gatein.api.id.Id;
import org.gatein.api.id.Identifiable;
+import org.gatein.api.portal.Page;
import org.gatein.api.portal.Portal;
import org.gatein.api.portal.Site;
import org.picocontainer.Startable;
@@ -56,8 +59,12 @@
public class GateInImpl implements GateIn, Startable
{
private static final Query<PortalData> PORTALS = new
Query<PortalData>(SiteType.PORTAL.getName(), null, PortalData.class);
+ private static final Query<DashboardData> DASHBOARDS = new
Query<DashboardData>(SiteType.USER.getName(), null, DashboardData.class);
+ private static final Query<PageData> GROUPS = new
Query<PageData>(SiteType.GROUP.getName(), null, PageData.class);
public static final Context CONTEXT =
Context.builder().requiredComponent("owner", Site.class,
Pattern.compile("\\w+"))
- .requiredComponent("name", Portal.class,
Pattern.compile("\\w+")).withDefaultSeparator("::").build();
+ .requiredComponent("portal", Portal.class,
Pattern.compile("\\w+"))
+ .optionalComponent("page", Page.class,
Pattern.compile("\\w+"))
+ .withDefaultSeparator("::").build();
private ExoContainer container;
private ModelDataStorage dataStorage;
private NavigationService navigationService;
@@ -99,7 +106,7 @@
public Portal getDefaultPortal()
{
- return getPortal(portalId(Site.Type.PORTAL, "classic")); // todo: check
+ return getPortal(siteId(Site.Type.PORTAL, "classic")); // todo: check
}
public IterableResult<Site> getSites()
@@ -152,7 +159,7 @@
return type.cast(result);
}
- public <T extends Site> Site getSite(Id<Site> siteId, Site.Type<T>
type)
+ public <T extends Site> T getSite(Id<T> siteId, Site.Type<T> type)
{
return null; //To change body of implemented methods use File | Settings | File
Templates.
}
@@ -192,9 +199,9 @@
return null; //To change body of implemented methods use File | Settings | File
Templates.
}
- public Id<Portal> portalId(Site.Type siteType, String portalName)
+ public <T extends Site> Id<T> siteId(Site.Type<T> siteType, String
portalName)
{
- return Id.create(CONTEXT, Portal.class, siteType.getName(), portalName);
+ return Id.create(CONTEXT, siteType.getValueType(), siteType.getName(),
portalName);
}
public void start()
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/NavigationImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/NavigationImpl.java 2011-07-15
10:00:09 UTC (rev 6872)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/NavigationImpl.java 2011-07-15
21:24:39 UTC (rev 6873)
@@ -23,44 +23,85 @@
package org.gatein.portal.api.impl;
import org.exoplatform.portal.mop.navigation.NodeContext;
+import org.exoplatform.portal.mop.navigation.NodeModel;
+import org.exoplatform.portal.mop.navigation.NodeState;
import org.gatein.api.Filter;
+import org.gatein.api.GateIn;
import org.gatein.api.IterableResult;
import org.gatein.api.Query;
+import org.gatein.api.id.Context;
+import org.gatein.api.id.Id;
+import org.gatein.api.id.Identifiable;
import org.gatein.api.portal.Navigation;
import org.gatein.api.portal.Page;
import org.gatein.api.portal.Site;
+import java.util.Iterator;
+import java.util.regex.Pattern;
+
/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
-public class NavigationImpl extends IdentifiableImpl<Navigation> implements
Navigation
+public class NavigationImpl implements Navigation, Identifiable<Navigation>
{
- public NavigationImpl(NodeContext<?> navigation, GateInImpl gateIn)
+ private final NodeContext<NavigationImpl> context;
+ private Id<? extends Site> site;
+ private Id<Navigation> id;
+ private final GateInImpl gateIn;
+
+ private final static Context CONTEXT =
Context.builder().requiredComponent("navigation", Navigation.class,
Pattern.compile("[a-z0-9]+")).build();
+
+ public NavigationImpl(Id<Site> siteId, NodeContext<NavigationImpl>
context, GateInImpl gateIn)
{
- super(null, navigation.getName(), gateIn);
+ this.context = context;
+ this.site = siteId;
+ this.gateIn = gateIn;
}
+ @Override
+ public String toString()
+ {
+ String s = "Navigation@" + getId() + " target:" +
context.getState().getPageRef() + "\nchildren:\n";
+ Iterator<NavigationImpl> children = context.iterator();
+ while (children.hasNext())
+ {
+ s += " " + children.next() + "\n";
+ }
+ return s;
+ }
+
+ public NodeContext<NavigationImpl> getContext()
+ {
+ return context;
+ }
+
public Page getTargetPage()
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ return null;
}
public void setTargetPage(Page target)
{
- //To change body of implemented methods use File | Settings | File Templates.
+ setTargetPage(target.getId());
}
+ public void setTargetPage(Id<Page> targetId)
+ {
+ context.setState(new
NodeState.Builder(context.getState()).pageRef(targetId.toString()).build());
+ }
+
public Site getSite()
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ return getGateIn().get(site);
}
public IterableResult<Navigation> getAll()
{
+// context.getNodes()
return null; //To change body of implemented methods use File | Settings | File
Templates.
}
public int size()
{
- return 0; //To change body of implemented methods use File | Settings | File
Templates.
+ return context.getNodeSize();
}
public boolean contains(String key)
@@ -87,4 +128,51 @@
{
return null; //To change body of implemented methods use File | Settings | File
Templates.
}
+
+ public Id<Navigation> getId()
+ {
+ if (id == null)
+ {
+ id = Id.create(CONTEXT, Navigation.class, context.getId());
+ }
+
+ return id;
+ }
+
+ public String getName()
+ {
+ return context.getName();
+ }
+
+ public String getDisplayName()
+ {
+ return getName();
+ }
+
+ public GateIn getGateIn()
+ {
+ return gateIn;
+ }
+
+ static class NavigationNodeModel implements NodeModel<NavigationImpl>
+ {
+ private final Id<Site> siteId;
+ private final GateInImpl gateIn;
+
+ NavigationNodeModel(Id<Site> siteId, GateInImpl gateIn)
+ {
+ this.siteId = siteId;
+ this.gateIn = gateIn;
+ }
+
+ public NodeContext<NavigationImpl> getContext(NavigationImpl node)
+ {
+ return node.context;
+ }
+
+ public NavigationImpl create(NodeContext<NavigationImpl> context)
+ {
+ return new NavigationImpl(siteId, context, gateIn);
+ }
+ }
}
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/PortalImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/PortalImpl.java 2011-07-15
10:00:09 UTC (rev 6872)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/PortalImpl.java 2011-07-15
21:24:39 UTC (rev 6873)
@@ -25,7 +25,7 @@
import org.exoplatform.portal.mop.SiteKey;
import org.exoplatform.portal.mop.navigation.NavigationContext;
import org.exoplatform.portal.mop.navigation.NavigationService;
-import org.exoplatform.portal.mop.navigation.NodeContext;
+import org.exoplatform.portal.mop.navigation.NavigationState;
import org.exoplatform.portal.mop.navigation.NodeModel;
import org.exoplatform.portal.mop.navigation.Scope;
import org.exoplatform.portal.pom.data.PortalData;
@@ -42,7 +42,7 @@
public PortalImpl(PortalData portal, GateInImpl gateIn)
{
- super(gateIn.portalId(Site.Type.forName(portal.getKey().getType()),
portal.getKey().getId()), portal.getName(), gateIn);
+ super(gateIn.siteId(Site.Type.forName(portal.getKey().getType()),
portal.getKey().getId()), portal.getName(), gateIn);
}
public ContentRegistry getContentRegistry()
@@ -57,21 +57,21 @@
public Navigation getNavigation()
{
- NavigationService service = getGateInImpl().getNavigationService();
+ GateInImpl gateIn = getGateInImpl();
+ NavigationService service = gateIn.getNavigationService();
try
{
- getGateInImpl().begin();
+ gateIn.begin();
NavigationContext navigation =
service.loadNavigation(SiteKey.portal(getName()));
- //
- NodeContext<?> node = service.loadNode(NodeModel.SELF_MODEL, navigation,
Scope.SINGLE, null).getNode();
+ NodeModel<NavigationImpl> nodeModel = new
NavigationImpl.NavigationNodeModel(getId(), gateIn);
- return new NavigationImpl(node, getGateInImpl());
+ return service.loadNode(nodeModel, navigation, Scope.CHILDREN, null).getNode();
}
finally
{
- getGateInImpl().end();
+ gateIn.end();
}
}
@@ -87,6 +87,20 @@
public int getPriority()
{
- return 0; //To change body of implemented methods use File | Settings | File
Templates.
+ GateInImpl gateIn = getGateInImpl();
+ NavigationService service = gateIn.getNavigationService();
+
+ try
+ {
+ gateIn.begin();
+ NavigationContext navigation =
service.loadNavigation(SiteKey.portal(getName()));
+
+ NavigationState state = navigation.getState();
+ return state != null ? state.getPriority() : 1;
+ }
+ finally
+ {
+ gateIn.end();
+ }
}
}