Author: julien_viet
Date: 2011-08-16 02:45:32 -0400 (Tue, 16 Aug 2011)
New Revision: 7142
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/PageImpl.java
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/SiteImpl.java
portal/branches/api/component/api-impl/src/test/java/org/gatein/portal/api/impl/portal/NavigationTestCase.java
Log:
some more work on API
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-16
03:03:02 UTC (rev 7141)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java 2011-08-16
06:45:32 UTC (rev 7142)
@@ -31,7 +31,6 @@
import org.exoplatform.portal.mop.navigation.NavigationService;
import org.exoplatform.portal.mop.navigation.NodeContext;
import org.exoplatform.portal.mop.navigation.NodeModel;
-import org.exoplatform.portal.mop.navigation.NodeState;
import org.exoplatform.portal.mop.navigation.Scope;
import org.exoplatform.services.resources.ResourceBundleManager;
import org.exoplatform.web.application.RequestContext;
@@ -59,14 +58,14 @@
public class NavigationImpl implements Navigation, Identifiable<Navigation>
{
private final NodeContext<NavigationImpl> context;
- private Site site;
+ private SiteImpl site;
private Navigation.Id id;
private final GateInImpl gateIn;
private URI uri;
private String displayName;
private ResourceBundle bundle;
- public NavigationImpl(Site site, NodeContext<NavigationImpl> context, GateInImpl
gateIn)
+ public NavigationImpl(SiteImpl site, NodeContext<NavigationImpl> context,
GateInImpl gateIn)
{
this.context = context;
this.site = site;
@@ -157,8 +156,7 @@
String pageRef = context.getState().getPageRef();
if (pageRef != null)
{
- // return gateIn.get(gateIn.pageId(site.getId(), pageRef));
- throw new UnsupportedOperationException();
+ return site.pageRegistry.getPageByRef(pageRef);
}
else
{
@@ -168,10 +166,17 @@
public void setTargetPage(Page target)
{
- setTargetPage(target.getId());
+ if (target != null)
+ {
+ setTargetPageRef(target.getId());
+ }
+ else
+ {
+ setTargetPageRef(null);
+ }
}
- public void setTargetPage(Page.Id targetId)
+ public void setTargetPageRef(Page.Id targetId)
{
if (targetId != null)
{
@@ -368,12 +373,12 @@
static class NavigationNodeModel implements NodeModel<NavigationImpl>
{
- private final Site site;
+ private final SiteImpl site;
private final GateInImpl gateIn;
- NavigationNodeModel(Site siteId, GateInImpl gateIn)
+ NavigationNodeModel(SiteImpl site, GateInImpl gateIn)
{
- this.site = siteId;
+ this.site = site;
this.gateIn = gateIn;
}
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/PageImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/PageImpl.java 2011-08-16
03:03:02 UTC (rev 7141)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/PageImpl.java 2011-08-16
06:45:32 UTC (rev 7142)
@@ -39,10 +39,10 @@
private final Site.Id site;
private PageData pageData;
- public PageImpl(PageData pageData, Site.Id parent, GateInImpl gateIn)
+ public PageImpl(PageData pageData, Site.Id site, GateInImpl gateIn)
{
- super(gateIn.pageId(parent, pageData.getName()), pageData.getName(), gateIn);
- this.site = parent;
+ super(gateIn.pageId(site, pageData.getName()), pageData.getName(), gateIn);
+ this.site = site;
this.pageData = pageData;
}
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/SiteImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/SiteImpl.java 2011-08-16
03:03:02 UTC (rev 7141)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/SiteImpl.java 2011-08-16
06:45:32 UTC (rev 7142)
@@ -45,13 +45,20 @@
import org.gatein.portal.api.impl.util.GateInTypesResolver;
import java.lang.reflect.UndeclaredThrowableException;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
public abstract class SiteImpl extends IdentifiableImpl<Site, Site.Id> implements
Site
{
- private PageContainer pageRegistry;
+ /** . */
+ final PageContainer pageRegistry;
+
public SiteImpl(Site.Id siteId, String name, GateInImpl gateIn)
{
super(siteId, name, gateIn);
@@ -129,39 +136,77 @@
static class PageContainer implements HierarchicalContainer<String, Page>
{
+
+ /** . */
+ private static final Map<PageKey, PageImpl> EMPTY_CACHE =
Collections.emptyMap();
+
private final GateInImpl gateIn;
private final SiteImpl site;
private final Query<PageData> pageDataQuery;
+ /** A local cache so we return the same pages. */
+ private Map<PageKey, PageImpl> cache;
+
PageContainer(GateInImpl gateIn, SiteImpl site)
{
this.gateIn = gateIn;
this.site = site;
- pageDataQuery = new Query<PageData>(site.getType().getName(), null,
PageData.class);
+ this.pageDataQuery = new Query<PageData>(site.getType().getName(), null,
PageData.class);
+ this.cache = EMPTY_CACHE;
}
public boolean contains(String key)
{
- return getPageData(key) != null;
+ return getPageByName(key) != null;
}
- private PageData getPageData(String key)
+ /** . */
+ private static final Pattern PAGE_REF_PATTERN =
Pattern.compile("^([^:]+)::([^:]+)::([^:]+)$");
+
+ PageImpl getPageByRef(String pageRef)
{
- try
+ Matcher m = PAGE_REF_PATTERN.matcher(pageRef);
+ m.matches();
+ PageKey key = new PageKey(m.group(1), m.group(2), m.group(3));
+ return getPageData(key);
+ }
+
+ PageImpl getPageByName(String name)
+ {
+ SiteKey siteKey = site.getSiteKey();
+ PageKey key = new PageKey(siteKey.getTypeName(), siteKey.getName(), name);
+ return getPageData(key);
+ }
+
+ private PageImpl getPageData(PageKey key)
+ {
+ PageImpl page = cache.get(key);
+ if (page == null)
{
- gateIn.begin();
- SiteKey sk = site.getSiteKey();
- PageKey pk = new PageKey(sk.getTypeName(), sk.getName(), key);
- return gateIn.getDataStorage().getPage(pk);
+ try
+ {
+ gateIn.begin();
+ PageData data = gateIn.getDataStorage().getPage(key);
+ if (data != null)
+ {
+ page = new PageImpl(data, site.getId(), gateIn);
+ if (cache == EMPTY_CACHE)
+ {
+ cache = new HashMap<PageKey, PageImpl>();
+ }
+ cache.put(key, page);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new UndeclaredThrowableException(e);
+ }
+ finally
+ {
+ gateIn.end();
+ }
}
- catch (Exception e)
- {
- throw new UndeclaredThrowableException(e);
- }
- finally
- {
- gateIn.end();
- }
+ return page;
}
public Page createAndAdd(String key)
@@ -171,8 +216,7 @@
public Page get(String key)
{
- final PageData pageData = getPageData(key);
- return pageData != null ? new PageImpl(pageData, site.getId(), gateIn) : null;
+ return getPageByName(key);
}
public org.gatein.api.id.Id<Page> getIdForChild(String key)
@@ -197,7 +241,7 @@
public boolean contains(org.gatein.api.id.Id<Page> t)
{
- return getPageData(t.toString()) != null;
+ return getPageByName(t.toString()) != null;
}
};
}
Modified:
portal/branches/api/component/api-impl/src/test/java/org/gatein/portal/api/impl/portal/NavigationTestCase.java
===================================================================
---
portal/branches/api/component/api-impl/src/test/java/org/gatein/portal/api/impl/portal/NavigationTestCase.java 2011-08-16
03:03:02 UTC (rev 7141)
+++
portal/branches/api/component/api-impl/src/test/java/org/gatein/portal/api/impl/portal/NavigationTestCase.java 2011-08-16
06:45:32 UTC (rev 7142)
@@ -96,10 +96,10 @@
assertEquals("classic", id.getName());
//
- Navigation navigation = site.getNavigation();
- assertSame(site, navigation.getSite());
- assertNotNull(navigation);
- Iterator<Navigation> i = navigation.getAll().iterator();
+ Navigation rootNav = site.getNavigation();
+ assertSame(site, rootNav.getSite());
+ assertNotNull(rootNav);
+ Iterator<Navigation> i = rootNav.getAll().iterator();
assertFalse(i.hasNext());
}
@@ -110,19 +110,19 @@
//
Site site = gatein.getPortal(new Site.Id(Site.PORTAL, "classic"));
- Navigation navigation = site.getNavigation();
- Iterator<Navigation> i = navigation.getAll().iterator();
+ Navigation rootNav = site.getNavigation();
+ Iterator<Navigation> i = rootNav.getAll().iterator();
assertTrue(i.hasNext());
- Navigation home = i.next();
- assertSame(site, home.getSite());
- assertEquals("home", home.getName());
- assertSame(home, navigation.get("home"));
+ Navigation homeNav = i.next();
+ assertSame(site, homeNav.getSite());
+ assertEquals("home", homeNav.getName());
+ assertSame(homeNav, rootNav.get("home"));
assertFalse(i.hasNext());
}
public void testPage()
{
- root.add(null, "home");
+ NodeContext home = root.add(null, "home");
navService.saveNode(root, null);
//
@@ -132,9 +132,14 @@
assertNotNull(homePage);
//
- Navigation navigation = site.getNavigation();
- Navigation home = navigation.get("home");
- assertNull(home.getTargetPage());
- home.setTargetPage(homePage);
+ Navigation rootNav = site.getNavigation();
+ Navigation homeNav = rootNav.get("home");
+ assertNull(homeNav.getTargetPage());
+ homeNav.setTargetPage(homePage);
+ assertSame(homePage, homeNav.getTargetPage());
+
+ //
+ homeNav.setTargetPage((Page)null);
+ assertNull(null, homeNav.getTargetPage());
}
}