Author: chris.laprun(a)jboss.com
Date: 2011-08-09 09:34:10 -0400 (Tue, 09 Aug 2011)
New Revision: 7027
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/SiteImpl.java
Log:
- Implemented SiteImpl.getPageRegistry.
- Fixed PageImpl.setTitle.
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-09
09:40:24 UTC (rev 7026)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/PageImpl.java 2011-08-09
13:34:10 UTC (rev 7027)
@@ -22,6 +22,7 @@
package org.gatein.portal.api.impl.portal;
+import org.exoplatform.portal.pom.data.ModelDataStorage;
import org.exoplatform.portal.pom.data.PageData;
import org.gatein.api.id.Id;
import org.gatein.api.portal.Navigation;
@@ -36,13 +37,13 @@
public class PageImpl extends IdentifiableImpl<Page> implements Page
{
private final Id<? extends Site> site;
- private String title;
+ private PageData pageData;
public PageImpl(PageData pageData, Id<? extends Site> parent, GateInImpl
gateIn)
{
super(gateIn.pageId(parent, pageData.getName()), pageData.getName(), gateIn);
this.site = parent;
- this.title = pageData.getTitle();
+ this.pageData = pageData;
}
public Site getSite()
@@ -52,12 +53,44 @@
public String getTitle()
{
- return title;
+ return pageData.getTitle();
}
+ @Override
+ public String toString()
+ {
+ return "'" + getName() + "' Page titled '" +
getTitle() + "' id " + getId();
+ }
+
public void setTitle(String title)
{
- this.title = title;
+ try
+ {
+ getGateInImpl().begin();
+ final ModelDataStorage dataStorage = getGateInImpl().getDataStorage();
+
+ // recreate page with the new title
+ final PageData newPageData = new PageData(pageData.getStorageId(),
pageData.getId(), pageData.getName(), pageData.getIcon(),
+ pageData.getTemplate(), pageData.getFactoryId(), title,
pageData.getDescription(), pageData.getWidth(), pageData.getHeight(),
+ pageData.getAccessPermissions(), pageData.getChildren(),
pageData.getOwnerType(), pageData.getOwnerId(),
+ pageData.getEditPermission(), pageData.isShowMaxWindow());
+
+ // save new page
+ dataStorage.save(newPageData);
+
+ // remove previous data
+ dataStorage.remove(pageData);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ getGateInImpl().end();
+ }
+
+
}
public IterableIdentifiableCollection<Navigation> getInboundNavigations()
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-09
09:40:24 UTC (rev 7026)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/SiteImpl.java 2011-08-09
13:34:10 UTC (rev 7027)
@@ -22,6 +22,7 @@
package org.gatein.portal.api.impl.portal;
+import org.exoplatform.portal.config.Query;
import org.exoplatform.portal.mop.SiteKey;
import org.exoplatform.portal.mop.navigation.NavigationContext;
import org.exoplatform.portal.mop.navigation.NavigationService;
@@ -29,22 +30,32 @@
import org.exoplatform.portal.mop.navigation.NodeModel;
import org.exoplatform.portal.mop.navigation.Scope;
import org.exoplatform.portal.pom.data.OwnerKey;
+import org.exoplatform.portal.pom.data.PageData;
+import org.exoplatform.portal.pom.data.PageKey;
import org.gatein.api.id.Id;
import org.gatein.api.portal.Navigation;
import org.gatein.api.portal.Page;
import org.gatein.api.portal.Site;
import org.gatein.api.util.GateInTypesResolver;
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 java.util.List;
+
/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
public abstract class SiteImpl extends IdentifiableImpl implements Site
{
+ private PageContainer pageRegistry;
+
public SiteImpl(Id<? extends Site> siteId, String name, GateInImpl gateIn)
{
super(siteId, name, gateIn);
+ pageRegistry = new PageContainer(gateIn, this);
}
@Override
@@ -60,7 +71,7 @@
public HierarchicalContainer<String, Page> getPageRegistry()
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ return pageRegistry;
}
public Navigation getNavigation()
@@ -111,8 +122,116 @@
public Navigation createNavigationTo(Page node, Navigation parent)
{
- return null; //To change body of implemented methods use File | Settings | File
Templates.
+ throw new NotYetImplemented(); // todo
}
protected abstract SiteKey getSiteKey();
+
+ static class PageContainer implements HierarchicalContainer<String, Page>
+ {
+ private final GateInImpl gateIn;
+ private final Site site;
+ private final Query<PageData> pageDataQuery;
+
+ PageContainer(GateInImpl gateIn, SiteImpl site)
+ {
+ this.gateIn = gateIn;
+ this.site = site;
+ pageDataQuery = new Query<PageData>(site.getType().getName(), null,
PageData.class);
+ }
+
+ public boolean contains(String key)
+ {
+ return getPageData(key) != null;
+ }
+
+ private PageData getPageData(String key)
+ {
+ try
+ {
+ gateIn.begin();
+ return gateIn.getDataStorage().getPage(PageKey.create(key));
+ }
+ catch (Exception e)
+ {
+ return null;
+ }
+ finally
+ {
+ gateIn.end();
+ }
+ }
+
+ public Page createAndAdd(String key)
+ {
+ throw new NotYetImplemented(); // todo
+ }
+
+ public Page get(String key)
+ {
+ final PageData pageData = getPageData(key);
+ return pageData != null ? new PageImpl(pageData, site.getId(), gateIn) : null;
+ }
+
+ public Id<Page> getIdForChild(String key)
+ {
+ return site.getId().getIdForChild(key);
+ }
+
+ public <U extends Page> U createAndAdd(Id<U> id)
+ {
+ return (U)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(Id<Page> t)
+ {
+ return getPageData(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 <U extends Page> U get(Id<U> id)
+ {
+ return (U)get(id.toString());
+ }
+
+ public <U extends Page> boolean contains(Id<U> id)
+ {
+ return contains(id.toString());
+ }
+ }
}