Author: chris.laprun(a)jboss.com
Date: 2010-09-09 12:24:34 -0400 (Thu, 09 Sep 2010)
New Revision: 4127
Added:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPPortalStructureProvider.java
Modified:
portal/branches/wsrp2-integration/component/wsrp/pom.xml
Log:
- Started implementing PortalStructureProvider based on MOP operations.
Modified: portal/branches/wsrp2-integration/component/wsrp/pom.xml
===================================================================
--- portal/branches/wsrp2-integration/component/wsrp/pom.xml 2010-09-09 14:43:00 UTC (rev
4126)
+++ portal/branches/wsrp2-integration/component/wsrp/pom.xml 2010-09-09 16:24:34 UTC (rev
4127)
@@ -46,6 +46,10 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.gatein.mop</groupId>
+ <artifactId>mop-api</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.gatein.wsrp</groupId>
<artifactId>wsrp-integration-api</artifactId>
<scope>provided</scope>
Added:
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPPortalStructureProvider.java
===================================================================
---
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPPortalStructureProvider.java
(rev 0)
+++
portal/branches/wsrp2-integration/component/wsrp/src/main/java/org/gatein/portal/wsrp/MOPPortalStructureProvider.java 2010-09-09
16:24:34 UTC (rev 4127)
@@ -0,0 +1,134 @@
+/*
+ * JBoss, a division of Red Hat
+ * Copyright 2010, Red Hat Middleware, LLC, and individual
+ * contributors as indicated by the @authors tag. See the
+ * copyright.txt in the distribution for a full listing of
+ * individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.gatein.portal.wsrp;
+
+import org.chromattic.api.ChromatticSession;
+import org.exoplatform.commons.chromattic.ChromatticLifeCycle;
+import org.exoplatform.commons.chromattic.ChromatticManager;
+import org.gatein.common.NotYetImplemented;
+import org.gatein.common.util.ParameterValidation;
+import org.gatein.mop.api.workspace.ObjectType;
+import org.gatein.mop.api.workspace.Page;
+import org.gatein.mop.api.workspace.Site;
+import org.gatein.mop.api.workspace.Workspace;
+import org.gatein.mop.api.workspace.ui.UIComponent;
+import org.gatein.mop.api.workspace.ui.UIContainer;
+import org.gatein.wsrp.api.PortalStructureProvider;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ */
+public class MOPPortalStructureProvider implements PortalStructureProvider
+{
+ private final ChromatticLifeCycle lifeCycle;
+ private Map<String, String> pageIdToUUIDs;
+ private Map<String, String> windowIdToUUIDs;
+
+ public MOPPortalStructureProvider(ChromatticManager manager)
+ {
+ lifeCycle = manager.getLifeCycle("mop");
+ pageIdToUUIDs = new HashMap<String, String>();
+ windowIdToUUIDs = new HashMap<String, String>();
+ }
+
+ public List<String> getPageIdentifiers()
+ {
+ ChromatticSession session = lifeCycle.getChromattic().openSession();
+ Workspace workspace = session.findByPath(Workspace.class,
"/production/mop:workspace");
+ Collection<Site> sites = workspace.getSites(ObjectType.PORTAL_SITE);
+
+ for (Site site : sites)
+ {
+ Page page = site.getRootPage();
+ processPage(page);
+ }
+
+ LinkedList<String> identifiers = new
LinkedList<String>(pageIdToUUIDs.values());
+ Collections.sort(identifiers);
+ return identifiers;
+ }
+
+ private void processPage(Page page)
+ {
+ Collection<Page> children = page.getChildren();
+ if (ParameterValidation.existsAndIsNotEmpty(children))
+ {
+ for (Page child : children)
+ {
+ pageIdToUUIDs.put(child.getName(), child.getObjectId());
+ processPage(child);
+ }
+ }
+ }
+
+ public List<String> getWindowIndentifiersFor(String pageId)
+ {
+ ChromatticSession session = lifeCycle.getChromattic().openSession();
+ String uuid = pageIdToUUIDs.get(pageId);
+ ParameterValidation.throwIllegalArgExceptionIfNull(uuid, "UUID for " +
pageId);
+ Page page = session.findById(Page.class, uuid);
+
+ List<String> windows = new LinkedList<String>();
+ UIContainer container = page.getRootComponent();
+ processContainer(windows, container);
+
+ return windows;
+ }
+
+ private void processContainer(List<String> windows, UIContainer container)
+ {
+ List<UIComponent> components = container.getComponents();
+ for (UIComponent component : components)
+ {
+ ObjectType<? extends UIComponent> type = component.getObjectType();
+ if (ObjectType.WINDOW.equals(type))
+ {
+ String name = component.getName();
+ windowIdToUUIDs.put(name, component.getObjectId());
+ windows.add(name);
+ }
+ else if (ObjectType.CONTAINER.equals(type))
+ {
+ processContainer(windows, (UIContainer)component);
+ }
+ else
+ {
+ // ignore
+ }
+ }
+ }
+
+ public void assignPortletToWindow(String portletId, String windowId, String pageId)
+ {
+ throw new NotYetImplemented();
+ }
+}