Author: julien(a)jboss.com
Date: 2008-04-11 16:51:17 -0400 (Fri, 11 Apr 2008)
New Revision: 10540
Added:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/navstate/PageNavigationalState.java
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPageNavigationalState.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletControllerContext.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/navstate/PortalObjectNavigationalStateContext.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/navstate/NavigationalStateContext.java
Log:
start to integrate a bit the public nav state
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPageNavigationalState.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPageNavigationalState.java 2008-04-11
20:29:52 UTC (rev 10539)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPageNavigationalState.java 2008-04-11
20:51:17 UTC (rev 10540)
@@ -24,8 +24,10 @@
import org.jboss.portal.portlet.controller.state.PageNavigationalState;
import org.jboss.portal.portlet.controller.state.WindowNavigationalState;
+import org.jboss.portal.portlet.info.ParameterInfo;
+import org.jboss.portal.portlet.info.PortletInfo;
+import org.jboss.portal.portlet.info.NavigationInfo;
import org.jboss.portal.common.util.ParameterMap;
-import org.jboss.portal.common.NotYetImplemented;
import org.jboss.portal.core.navstate.NavigationalStateContext;
import org.jboss.portal.core.model.portal.Window;
@@ -43,26 +45,33 @@
{
/** . */
+ private static final String[] REMOVAL = new String[0];
+
+ /** . */
private final NavigationalStateContext navigationalStateContext;
/** . */
- private final Map<String, Window> windows;
+ private final ControllerPortletControllerContext controllerContext;
/** . */
private final boolean mutable;
/** . */
- private final Map<String, WindowNavigationalState> updates;
+ private Map<String, WindowNavigationalState> updates;
+ /** . */
+ private Map<QName, String[]> pageUpdates;
+
public ControllerPageNavigationalState(
NavigationalStateContext navigationalStateContext,
- Map<String, Window> windows,
+ ControllerPortletControllerContext controllerContext,
boolean mutable)
{
this.navigationalStateContext = navigationalStateContext;
- this.windows = windows;
+ this.controllerContext = controllerContext;
this.mutable = mutable;
- this.updates = new HashMap<String, WindowNavigationalState>();
+ this.updates = null;
+ this.pageUpdates = null;
}
public ControllerPageNavigationalState(
@@ -70,9 +79,10 @@
boolean mutable)
{
this.navigationalStateContext = that.navigationalStateContext;
- this.windows = new HashMap<String, Window>(that.windows);
+ this.controllerContext = that.controllerContext;
this.mutable = mutable;
- this.updates = new HashMap<String, WindowNavigationalState>(that.updates);
+ this.updates = that.updates != null ? new HashMap<String,
WindowNavigationalState>(that.updates) : null;
+ this.pageUpdates = that.pageUpdates != null ? new HashMap<QName,
String[]>(that.pageUpdates) : null;
}
/**
@@ -80,38 +90,86 @@
*/
public void flushUpdates()
{
- for (Map.Entry<String, WindowNavigationalState> entry : updates.entrySet())
+ if (updates != null)
{
- Window window = windows.get(entry.getKey());
- org.jboss.portal.core.model.portal.navstate.WindowNavigationalState wns = new
org.jboss.portal.core.model.portal.navstate.WindowNavigationalState(
- entry.getValue().getWindowState(),
- entry.getValue().getMode(),
- entry.getValue().getPortletNavigationalState());
- navigationalStateContext.setWindowNavigationalState(window.getId().toString(),
wns);
+ for (Map.Entry<String, WindowNavigationalState> entry :
updates.entrySet())
+ {
+ Window window = controllerContext.getWindow(entry.getKey());
+ org.jboss.portal.core.model.portal.navstate.WindowNavigationalState wns = new
org.jboss.portal.core.model.portal.navstate.WindowNavigationalState(
+ entry.getValue().getWindowState(),
+ entry.getValue().getMode(),
+ entry.getValue().getPortletNavigationalState());
+
navigationalStateContext.setWindowNavigationalState(window.getId().toString(), wns);
+ }
+
+ //
+ updates.clear();
}
//
- updates.clear();
+ if (pageUpdates != null)
+ {
+ org.jboss.portal.core.model.portal.navstate.PageNavigationalState storedPNS =
navigationalStateContext.getPageNavigationalState(controllerContext.getPageId());
+
+ //
+ Map<QName, String[]> parameters;
+ if (storedPNS != null)
+ {
+ parameters = new HashMap<QName, String[]>(storedPNS.getParameters());
+ }
+ else
+ {
+ parameters = new HashMap<QName, String[]>();
+ }
+
+ //
+ for (Map.Entry<QName, String[]> update : pageUpdates.entrySet())
+ {
+ String[] value = update.getValue();
+
+ //
+ if (value.length == 0)
+ {
+ parameters.remove(update.getKey());
+ }
+ else
+ {
+ parameters.put(update.getKey(), value);
+ }
+ }
+
+ //
+ navigationalStateContext.setPageNavigationalState(controllerContext.getPageId(),
new org.jboss.portal.core.model.portal.navstate.PageNavigationalState(parameters));
+
+ //
+ pageUpdates.clear();
+ }
}
public Set<String> getWindowIds()
{
- return windows.keySet();
+ return controllerContext.getWindowNames();
}
- public WindowNavigationalState getWindowNavigationalState(String s) throws
IllegalArgumentException
+ public WindowNavigationalState getWindowNavigationalState(String windowName) throws
IllegalArgumentException
{
- WindowNavigationalState update = updates.get(s);
+ WindowNavigationalState update = null;
//
+ if (updates != null)
+ {
+ update = updates.get(windowName);
+ }
+
+ //
if (update != null)
{
return update;
}
//
- Window window = windows.get(s);
+ Window window = controllerContext.getWindow(windowName);
//
org.jboss.portal.core.model.portal.navstate.WindowNavigationalState wns =
navigationalStateContext.getWindowNavigationalState(window.getId().toString());
@@ -126,7 +184,7 @@
return new WindowNavigationalState(wns.getContentState(), wns.getMode(),
wns.getWindowState());
}
- public void setWindowNavigationalState(String s, WindowNavigationalState
windowNavigationalState) throws IllegalArgumentException, IllegalStateException
+ public void setWindowNavigationalState(String windowName, WindowNavigationalState
windowNavigationalState) throws IllegalArgumentException, IllegalStateException
{
if (!mutable)
{
@@ -134,25 +192,125 @@
}
//
- updates.put(s, windowNavigationalState);
+ if (updates == null)
+ {
+ updates = new HashMap<String, WindowNavigationalState>();
+ }
+
+ //
+ updates.put(windowName, windowNavigationalState);
}
- public ParameterMap getPublicNavigationalState(String s) throws
IllegalArgumentException
+ /**
+ * For now we do not implement any kind of mapping between qnames, it's the basic
straightforward 1-1 mapping.
+ */
+ public ParameterMap getPublicNavigationalState(String windowName) throws
IllegalArgumentException
{
- return new ParameterMap();
+ PortletInfo info = controllerContext.getPortletInfo(windowName);
+
+ //
+ if (info != null)
+ {
+ ParameterMap publicNavigationalState = new ParameterMap();
+ for (ParameterInfo parameterInfo : info.getNavigation().getPublicParameters())
+ {
+ String[] parameterValue =
getPublicNavigationalState(parameterInfo.getName());
+
+ //
+ if (parameterValue != null)
+ {
+ String parameterId = parameterInfo.getId();
+
+ // We clone the value here so we keep the internal state not potentially
changed
+ publicNavigationalState.put(parameterId, parameterValue.clone());
+ }
+ }
+
+ //
+ return publicNavigationalState;
+ }
+
+ //
+ return null;
}
+ public void setPublicNavigationalState(String windowName, Map<String, String[]>
update)
+ {
+ if (!mutable)
+ {
+ throw new IllegalStateException("The page navigational state is not
modifiable");
+ }
+
+ //
+ PortletInfo info = controllerContext.getPortletInfo(windowName);
+
+ //
+ if (info != null)
+ {
+ NavigationInfo navigationInfo = info.getNavigation();
+ for (Map.Entry<String, String[]> entry : update.entrySet())
+ {
+ String id = entry.getKey();
+
+ //
+ ParameterInfo parameterInfo = navigationInfo.getPublicParameter(id);
+
+ //
+ if (parameterInfo != null)
+ {
+ QName name = parameterInfo.getName();
+ String[] value = entry.getValue();
+ if (value.length > 0)
+ {
+ setPublicNavigationalState(name, value);
+ }
+ else
+ {
+ removePublicNavigationalState(name);
+ }
+ }
+ }
+ }
+ }
+
public Set<QName> getPublicNames()
{
- return Collections.emptySet();
+ if (pageUpdates == null)
+ {
+ return Collections.emptySet();
+ }
+
+ //
+ return pageUpdates.keySet();
}
- public String[] getPublicNavigationalState(QName qName) throws
IllegalArgumentException
+ public String[] getPublicNavigationalState(QName name) throws
IllegalArgumentException
{
- return new String[0];
+ String[] value = null;
+
+ //
+ if (pageUpdates != null)
+ {
+ value = pageUpdates.get(name);
+ }
+
+ //
+ if (value == null)
+ {
+ org.jboss.portal.core.model.portal.navstate.PageNavigationalState storedPNS =
navigationalStateContext.getPageNavigationalState(controllerContext.getPageId());
+
+ //
+ if (storedPNS != null)
+ {
+ value = storedPNS.getParameter(name);
+ }
+ }
+
+ //
+ return value != null && value.length > 0 ? value : null;
}
- public void setPublicNavigationalState(QName qName, String[] strings) throws
IllegalArgumentException, IllegalStateException
+ public void setPublicNavigationalState(QName name, String[] value) throws
IllegalArgumentException, IllegalStateException
{
if (!mutable)
{
@@ -160,10 +318,16 @@
}
//
- throw new NotYetImplemented();
+ if (pageUpdates == null)
+ {
+ pageUpdates = new HashMap<QName, String[]>();
+ }
+
+ //
+ pageUpdates.put(name, value);
}
- public void removePublicNavigationalState(QName qName) throws
IllegalArgumentException, IllegalStateException
+ public void removePublicNavigationalState(QName name) throws IllegalArgumentException,
IllegalStateException
{
if (!mutable)
{
@@ -171,6 +335,9 @@
}
//
- throw new NotYetImplemented();
+ if (pageUpdates != null)
+ {
+ pageUpdates.put(name, REMOVAL);
+ }
}
}
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletControllerContext.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletControllerContext.java 2008-04-11
20:29:52 UTC (rev 10539)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/portlet/ControllerPortletControllerContext.java 2008-04-11
20:51:17 UTC (rev 10540)
@@ -50,6 +50,7 @@
import java.util.List;
import java.util.Map;
import java.util.HashMap;
+import java.util.Set;
/**
* @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
@@ -76,6 +77,9 @@
/** . */
private final CoreEventControllerContext eventControllerContext;
+ /** . */
+ private final String pageId;
+
public ControllerPortletControllerContext(
ControllerContext controllerContext,
Page page,
@@ -129,13 +133,29 @@
this.windows = windows;
this.infos = infos;
this.instances = instances;
+ this.pageId = page.getId().toString();
}
- public PortletInfo getPortletInfo(String windowId)
+ public String getPageId()
{
- return infos.get(windowId);
+ return pageId;
}
+ public Window getWindow(String windowName)
+ {
+ return windows.get(windowName);
+ }
+
+ public Set<String> getWindowNames()
+ {
+ return windows.keySet();
+ }
+
+ public PortletInfo getPortletInfo(String windowName)
+ {
+ return infos.get(windowName);
+ }
+
public PortletInvocationContext createPortletInvocationContext(String s,
PageNavigationalState pageNavigationalState)
{
Window window = windows.get(s);
Added:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/navstate/PageNavigationalState.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/navstate/PageNavigationalState.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/navstate/PageNavigationalState.java 2008-04-11
20:51:17 UTC (rev 10540)
@@ -0,0 +1,55 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.jboss.portal.core.model.portal.navstate;
+
+import javax.xml.namespace.QName;
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Collections;
+
+/**
+ * @author <a href="mailto:julien@jboss-portal.org">Julien
Viet</a>
+ * @version $Revision: 630 $
+ */
+public class PageNavigationalState implements Serializable
+{
+
+ /** . */
+ private final HashMap<QName, String[]> parameters;
+
+ public PageNavigationalState(Map<QName, String[]> parameters)
+ {
+ this.parameters = new HashMap<QName, String[]>(parameters);
+ }
+
+ public String[] getParameter(QName name)
+ {
+ return parameters.get(name);
+ }
+
+ public Map<QName, String[]> getParameters()
+ {
+ return Collections.unmodifiableMap(parameters);
+ }
+}
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/navstate/PortalObjectNavigationalStateContext.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/navstate/PortalObjectNavigationalStateContext.java 2008-04-11
20:29:52 UTC (rev 10539)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/navstate/PortalObjectNavigationalStateContext.java 2008-04-11
20:51:17 UTC (rev 10540)
@@ -185,16 +185,28 @@
public WindowNavigationalState getWindowNavigationalState(String windowId)
{
- NavigationalStateKey key = getKeyFrom(windowId);
+ NavigationalStateKey key = createWindowKey(windowId);
return (WindowNavigationalState)getAttribute(key);
}
public void setWindowNavigationalState(String windowId, WindowNavigationalState
windowNavigationalState)
{
- NavigationalStateKey key = getKeyFrom(windowId);
+ NavigationalStateKey key = createWindowKey(windowId);
setAttribute(key, windowNavigationalState);
}
+ public PageNavigationalState getPageNavigationalState(String pageId)
+ {
+ NavigationalStateKey key = createPageKey(pageId);
+ return (PageNavigationalState)getAttribute(key);
+ }
+
+ public void setPageNavigationalState(String pageId, PageNavigationalState
pageNavigationalState)
+ {
+ NavigationalStateKey key = createPageKey(pageId);
+ setAttribute(key, pageNavigationalState);
+ }
+
/**
* Apply the navigational state changes to the real storage.
*
@@ -276,8 +288,13 @@
return viewId != null ? viewId.toString() : "0";
}
- private NavigationalStateKey getKeyFrom(String windowId)
+ private NavigationalStateKey createWindowKey(String windowId)
{
return new NavigationalStateKey(WindowNavigationalState.class,
PortalObjectId.parse(windowId, PortalObjectPath.CANONICAL_FORMAT));
}
+
+ private NavigationalStateKey createPageKey(String pageId)
+ {
+ return new NavigationalStateKey(PageNavigationalState.class,
PortalObjectId.parse(pageId, PortalObjectPath.CANONICAL_FORMAT));
+ }
}
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/navstate/NavigationalStateContext.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/navstate/NavigationalStateContext.java 2008-04-11
20:29:52 UTC (rev 10539)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/navstate/NavigationalStateContext.java 2008-04-11
20:51:17 UTC (rev 10540)
@@ -24,6 +24,7 @@
import org.jboss.portal.common.invocation.AttributeResolver;
import org.jboss.portal.core.model.portal.navstate.WindowNavigationalState;
+import org.jboss.portal.core.model.portal.navstate.PageNavigationalState;
import java.util.Iterator;
@@ -53,6 +54,24 @@
void setWindowNavigationalState(String windowId, WindowNavigationalState
windowNavigationalState);
/**
+ * Retrieves the navigational state associated with the specified page identifier.
+ *
+ * @param pageId a String identifying the page which navigational state is to be
retrieved
+ * @return the navigational state associated with the specified window identifier or
<code>null</code> if the given
+ * page identifier is not known by this NavigationalStateContext or no
navigational state is associated
+ * with the given identifier.
+ */
+ PageNavigationalState getPageNavigationalState(String pageId);
+
+ /**
+ * Set the navigational state associated with the page identified by the given
identifier.
+ *
+ * @param pageId the page identifier
+ * @param pageNavigationalState the page navigational state
+ */
+ void setPageNavigationalState(String pageId, PageNavigationalState
pageNavigationalState);
+
+ /**
* Apply the navigational state changes made to this NavigationalStateContext.
*
* @return true if state changed