Author: julien_viet
Date: 2011-08-16 03:43:36 -0400 (Tue, 16 Aug 2011)
New Revision: 7145
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:
more work
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
07:29:10 UTC (rev 7144)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java 2011-08-16
07:43:36 UTC (rev 7145)
@@ -146,7 +146,7 @@
String pageRef = context.getState().getPageRef();
if (pageRef != null)
{
- return site.pageRegistry.getPageByRef(pageRef);
+ return site.pages.getPageByRef(pageRef);
}
else
{
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
07:29:10 UTC (rev 7144)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/PageImpl.java 2011-08-16
07:43:36 UTC (rev 7145)
@@ -29,8 +29,6 @@
import org.gatein.portal.api.impl.GateInImpl;
import org.gatein.portal.api.impl.IdentifiableImpl;
-import java.util.Collection;
-
/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
public class PageImpl extends IdentifiableImpl<Page, Page.Id> implements Page
{
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
07:29:10 UTC (rev 7144)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/SiteImpl.java 2011-08-16
07:43:36 UTC (rev 7145)
@@ -35,19 +35,15 @@
import org.gatein.api.portal.Navigation;
import org.gatein.api.portal.Page;
import org.gatein.api.portal.Site;
-import org.gatein.api.util.HierarchicalContainer;
-import org.gatein.api.util.IterableIdentifiableCollection;
import org.gatein.api.util.Type;
import org.gatein.common.NotYetImplemented;
import org.gatein.portal.api.impl.GateInImpl;
import org.gatein.portal.api.impl.IdentifiableImpl;
-import org.gatein.portal.api.impl.util.AdaptedIterableIdentifiableCollection;
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;
@@ -57,12 +53,20 @@
{
/** . */
- final PageContainer pageRegistry;
+ private static final Map<PageKey, PageImpl> EMPTY_CACHE =
Collections.emptyMap();
+ /** . */
+ private static final Pattern PAGE_REF_PATTERN =
Pattern.compile("^([^:]+)::([^:]+)::([^:]+)$");
+
+ /** . */
+ final PageContainer pages;
+
public SiteImpl(Site.Id siteId, String name, GateInImpl gateIn)
{
super(siteId, name, gateIn);
- pageRegistry = new PageContainer(gateIn, this);
+
+ //
+ this.pages = new PageContainer();
}
@Override
@@ -76,11 +80,6 @@
return GateInTypesResolver.forName(key.getType(), Site.class);
}
- public HierarchicalContainer<String, Page> getPageRegistry()
- {
- return pageRegistry;
- }
-
public Navigation getNavigation()
{
GateInImpl gateIn = getGateInImpl();
@@ -134,35 +133,26 @@
protected abstract SiteKey getSiteKey();
- static class PageContainer implements HierarchicalContainer<String, Page>
+ public Page getPage(String pageName)
{
+ return pages.getPageByName(pageName);
+ }
- /** . */
- private static final Map<PageKey, PageImpl> EMPTY_CACHE =
Collections.emptyMap();
+ class PageContainer
+ {
- 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)
+ private PageContainer()
{
- this.gateIn = gateIn;
- this.site = site;
- this.pageDataQuery = new Query<PageData>(site.getType().getName(), null,
PageData.class);
+ this.pageDataQuery = new Query<PageData>(getType().getName(), null,
PageData.class);
this.cache = EMPTY_CACHE;
}
- public boolean contains(String key)
- {
- return getPageByName(key) != null;
- }
-
- /** . */
- private static final Pattern PAGE_REF_PATTERN =
Pattern.compile("^([^:]+)::([^:]+)::([^:]+)$");
-
PageImpl getPageByRef(String pageRef)
{
Matcher m = PAGE_REF_PATTERN.matcher(pageRef);
@@ -173,7 +163,7 @@
PageImpl getPageByName(String name)
{
- SiteKey siteKey = site.getSiteKey();
+ SiteKey siteKey = getSiteKey();
PageKey key = new PageKey(siteKey.getTypeName(), siteKey.getName(), name);
return getPageData(key);
}
@@ -189,7 +179,7 @@
PageData data = gateIn.getDataStorage().getPage(key);
if (data != null)
{
- page = new PageImpl(data, site.getId(), gateIn);
+ page = new PageImpl(data, getId(), gateIn);
if (cache == EMPTY_CACHE)
{
cache = new HashMap<PageKey, PageImpl>();
@@ -208,76 +198,5 @@
}
return page;
}
-
- public Page createAndAdd(String key)
- {
- throw new NotYetImplemented(); // todo
- }
-
- public Page get(String key)
- {
- return getPageByName(key);
- }
-
- public org.gatein.api.id.Id<Page> getIdForChild(String key)
- {
- return site.getId().getIdForChild(key);
- }
-
- public Page createAndAdd(org.gatein.api.id.Id<Page> id)
- {
- return createAndAdd(id.toString());
- }
-
- public IterableIdentifiableCollection<Page> getAll()
- {
- final List<PageData> pageList = getAllPageData();
- return new AdaptedIterableIdentifiableCollection<PageData,
Page>(pageList.size(), pageList.iterator())
- {
- public Page adapt(PageData old)
- {
- return new PageImpl(old, site.getId(), gateIn);
- }
-
- public boolean contains(org.gatein.api.id.Id<Page> t)
- {
- return getPageByName(t.toString()) != null;
- }
- };
- }
-
- private List<PageData> getAllPageData()
- {
- try
- {
- gateIn.begin();
-
- return gateIn.getDataStorage().find(pageDataQuery).getAll();
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- finally
- {
- gateIn.end();
- }
- }
-
- public int size()
- {
- // todo: optimize
- return getAllPageData().size();
- }
-
- public Page get(org.gatein.api.id.Id<Page> id)
- {
- return get(id.toString());
- }
-
- public boolean contains(org.gatein.api.id.Id<Page> id)
- {
- return contains(id.toString());
- }
}
}
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
07:29:10 UTC (rev 7144)
+++
portal/branches/api/component/api-impl/src/test/java/org/gatein/portal/api/impl/portal/NavigationTestCase.java 2011-08-16
07:43:36 UTC (rev 7145)
@@ -19,7 +19,6 @@
import org.gatein.api.portal.Navigation;
import org.gatein.api.portal.Page;
import org.gatein.api.portal.Site;
-import org.gatein.api.util.HierarchicalContainer;
import org.gatein.portal.api.impl.GateInImpl;
import java.util.Iterator;
@@ -127,8 +126,7 @@
//
Site site = gatein.getPortal(new Site.Id(Site.PORTAL, "classic"));
- HierarchicalContainer<String,Page> pages = site.getPageRegistry();
- Page homePage = pages.get("homepage");
+ Page homePage = site.getPage("homepage");
assertNotNull(homePage);
//