Author: chris.laprun(a)jboss.com
Date: 2008-04-10 20:31:22 -0400 (Thu, 10 Apr 2008)
New Revision: 10530
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/aspects/controller/NavigationalStateInterceptor.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/ajax/AjaxInterceptor.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/ajax/AjaxResponseHandler.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:
- Moved methods from PortalObjectNavigationalStateContext to NavigationalStateContext.
- Implemented PortalObjectNavigationalStateContext.getKeys.
- Use NavigationalStateContext instead of implementation.
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/aspects/controller/NavigationalStateInterceptor.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/aspects/controller/NavigationalStateInterceptor.java 2008-04-11
00:20:29 UTC (rev 10529)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/aspects/controller/NavigationalStateInterceptor.java 2008-04-11
00:31:22 UTC (rev 10530)
@@ -27,7 +27,7 @@
import org.jboss.portal.core.controller.ControllerContext;
import org.jboss.portal.core.controller.ControllerInterceptor;
import org.jboss.portal.core.controller.ControllerResponse;
-import org.jboss.portal.core.model.portal.navstate.PortalObjectNavigationalStateContext;
+import org.jboss.portal.core.navstate.NavigationalStateContext;
/**
* Apply navigational state changes.
@@ -45,7 +45,7 @@
ControllerContext controllerContext = cmd.getControllerContext();
if (controllerContext.getDepth() == 1 && controllerContext.getType() ==
ControllerContext.CLASSIC_TYPE)
{
- PortalObjectNavigationalStateContext ctx =
(PortalObjectNavigationalStateContext)controllerContext.getAttributeResolver(ControllerCommand.NAVIGATIONAL_STATE_SCOPE);
+ NavigationalStateContext ctx =
(NavigationalStateContext)controllerContext.getAttributeResolver(ControllerCommand.NAVIGATIONAL_STATE_SCOPE);
ctx.applyChanges();
}
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/ajax/AjaxInterceptor.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/ajax/AjaxInterceptor.java 2008-04-11
00:20:29 UTC (rev 10529)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/ajax/AjaxInterceptor.java 2008-04-11
00:31:22 UTC (rev 10530)
@@ -27,7 +27,7 @@
import org.jboss.portal.core.controller.ControllerContext;
import org.jboss.portal.core.controller.ControllerInterceptor;
import org.jboss.portal.core.controller.ControllerResponse;
-import org.jboss.portal.core.model.portal.navstate.PortalObjectNavigationalStateContext;
+import org.jboss.portal.core.navstate.NavigationalStateContext;
import org.jboss.portal.core.theme.PageRendition;
import org.jboss.portal.server.AbstractServerURL;
import org.jboss.portal.server.ServerInvocationContext;
@@ -44,13 +44,12 @@
*/
public class AjaxInterceptor extends ControllerInterceptor
{
- /**
- * Luca Stancapiano - 29 - 09 -2007
- * targetContextPath is used to assign a context path when
- * default portal-ajax path cannot to be used or if it is changed through context-root
property into jboss-web.xml
- * */
+ /**
+ * Luca Stancapiano - 29 - 09 -2007 targetContextPath is used to assign a context path
when default portal-ajax path
+ * cannot to be used or if it is changed through context-root property into
jboss-web.xml
+ */
private String targetContextPath = "/portal-ajax";
-
+
public ControllerResponse invoke(ControllerCommand cmd) throws Exception,
InvocationException
{
ControllerResponse response = (ControllerResponse)cmd.invokeNext();
@@ -68,7 +67,7 @@
Map pageProps = rendition.getPageResult().getProperties();
//
- PortalObjectNavigationalStateContext ctx =
(PortalObjectNavigationalStateContext)controllerContext.getAttributeResolver(ControllerCommand.NAVIGATIONAL_STATE_SCOPE);
+ NavigationalStateContext ctx =
(NavigationalStateContext)controllerContext.getAttributeResolver(ControllerCommand.NAVIGATIONAL_STATE_SCOPE);
String viewId = ctx.getViewId();
//
@@ -95,7 +94,7 @@
//
return response;
}
-
+
public String getTargetContextPath()
{
return targetContextPath;
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/ajax/AjaxResponseHandler.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/ajax/AjaxResponseHandler.java 2008-04-11
00:20:29 UTC (rev 10529)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/controller/ajax/AjaxResponseHandler.java 2008-04-11
00:31:22 UTC (rev 10530)
@@ -48,9 +48,9 @@
import org.jboss.portal.core.model.portal.command.response.UpdateWindowResponse;
import org.jboss.portal.core.model.portal.command.view.ViewPageCommand;
import org.jboss.portal.core.model.portal.content.WindowRendition;
-import org.jboss.portal.core.model.portal.navstate.PortalObjectNavigationalStateContext;
import org.jboss.portal.core.model.portal.navstate.WindowNavigationalState;
import org.jboss.portal.core.navstate.NavigationalStateChange;
+import org.jboss.portal.core.navstate.NavigationalStateContext;
import org.jboss.portal.core.navstate.NavigationalStateKey;
import org.jboss.portal.core.navstate.NavigationalStateObjectChange;
import org.jboss.portal.core.theme.WindowContextFactory;
@@ -185,7 +185,7 @@
Page page = (Page)window.getParent();
//
- PortalObjectNavigationalStateContext ctx =
(PortalObjectNavigationalStateContext)controllerContext.getAttributeResolver(ControllerCommand.NAVIGATIONAL_STATE_SCOPE);
+ NavigationalStateContext ctx =
(NavigationalStateContext)controllerContext.getAttributeResolver(ControllerCommand.NAVIGATIONAL_STATE_SCOPE);
// The windows marked dirty during the request
Set dirtyWindowIds = new HashSet();
@@ -253,10 +253,9 @@
//
if (!fullRefresh)
{
- ArrayList refreshedWindows = new ArrayList();
- for (Iterator i = page.getChildren(PortalObject.WINDOW_MASK).iterator();
i.hasNext();)
+ ArrayList<PortalObject> refreshedWindows = new
ArrayList<PortalObject>();
+ for (PortalObject child : page.getChildren(PortalObject.WINDOW_MASK))
{
- PortalObject child = (PortalObject)i.next();
PortalObjectId childId = child.getId();
if (dirtyWindowIds.contains(childId))
{
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
00:20:29 UTC (rev 10529)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/model/portal/navstate/PortalObjectNavigationalStateContext.java 2008-04-11
00:31:22 UTC (rev 10530)
@@ -25,11 +25,13 @@
import org.jboss.logging.Logger;
import org.jboss.portal.WindowState;
import org.jboss.portal.common.invocation.AttributeResolver;
+import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.core.model.portal.PortalObjectPath;
import org.jboss.portal.core.navstate.NavigationalStateContext;
import org.jboss.portal.core.navstate.NavigationalStateKey;
import org.jboss.portal.core.navstate.NavigationalStateObjectChange;
-import org.jboss.portal.core.model.portal.PortalObjectId;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Set;
@@ -41,7 +43,7 @@
public class PortalObjectNavigationalStateContext implements NavigationalStateContext
{
/** . */
- private Logger logger = Logger.getLogger(PortalObjectNavigationalStateContext.class);
+ private static final Logger logger =
Logger.getLogger(PortalObjectNavigationalStateContext.class);
/** . */
private static final String VIEW_ID_KEY = "view_id";
@@ -50,7 +52,7 @@
private AttributeResolver store;
/** The changes. */
- private LinkedHashMap changes;
+ private LinkedHashMap<NavigationalStateKey, NavigationalStateObjectChange>
changes;
public PortalObjectNavigationalStateContext(AttributeResolver store)
{
@@ -59,7 +61,14 @@
public Set getKeys()
{
- throw new UnsupportedOperationException("todo");
+ Set storeKeys = store.getKeys();
+ Set<String> keys = new HashSet<String>(storeKeys.size() +
changes.size());
+ keys.addAll(storeKeys);
+ for (NavigationalStateKey key : changes.keySet())
+ {
+ keys.add(key.getId().toString());
+ }
+ return keys;
}
public Object getAttribute(Object attrKey) throws IllegalArgumentException
@@ -69,7 +78,7 @@
// Browse changes first
if (changes != null)
{
- NavigationalStateObjectChange change =
(NavigationalStateObjectChange)changes.get(nsKey);
+ NavigationalStateObjectChange change = changes.get(nsKey);
if (change != null)
{
switch (change.getType())
@@ -96,7 +105,7 @@
Class typeClass = wantedKey.getType();
if (typeClass != WindowNavigationalState.class)
{
- throw new IllegalArgumentException("Cannot handle the type " +
typeClass.getName());
+ throw new IllegalArgumentException("Can only set WindowNavigationalSate
attributes, was given " + typeClass.getName());
}
//
@@ -105,7 +114,7 @@
// Look first the old ns in the changes
if (changes != null)
{
- NavigationalStateObjectChange change =
(NavigationalStateObjectChange)changes.get(wantedKey);
+ NavigationalStateObjectChange change = changes.get(wantedKey);
if (change != null)
{
// Discard any change done so far
@@ -161,7 +170,7 @@
{
if (changes == null)
{
- changes = new LinkedHashMap();
+ changes = new LinkedHashMap<NavigationalStateKey,
NavigationalStateObjectChange>();
}
//
@@ -169,11 +178,23 @@
}
}
- public Iterator getChanges()
+ public Iterator<NavigationalStateObjectChange> getChanges()
{
return changes.values().iterator();
}
+ public WindowNavigationalState getWindowNavigationalState(String windowId)
+ {
+ NavigationalStateKey key = getKeyFrom(windowId);
+ return (WindowNavigationalState)getAttribute(key);
+ }
+
+ public void setWindowNavigationalState(String windowId, WindowNavigationalState
windowNavigationalState)
+ {
+ NavigationalStateKey key = getKeyFrom(windowId);
+ setAttribute(key, windowNavigationalState);
+ }
+
/**
* Apply the navigational state changes to the real storage.
*
@@ -184,9 +205,8 @@
if (changes != null && changes.size() > 0)
{
Object maximizedKey = null;
- for (Iterator i = changes.values().iterator(); i.hasNext();)
+ for (NavigationalStateObjectChange change : changes.values())
{
- NavigationalStateObjectChange change =
(NavigationalStateObjectChange)i.next();
if (change.getNewValue() instanceof WindowNavigationalState)
{
WindowNavigationalState wns =
(WindowNavigationalState)change.getNewValue();
@@ -210,10 +230,8 @@
if (maximizedKey != null)
{
Set keys = store.getKeys();
- Iterator it = keys.iterator();
- while (it.hasNext())
+ for (Object key : keys)
{
- Object key = it.next();
Object object = store.getAttribute(key);
if (object instanceof WindowNavigationalState)
{
@@ -235,11 +253,11 @@
Integer viewId = (Integer)store.getAttribute(VIEW_ID_KEY);
if (viewId == null)
{
- viewId = new Integer(0);
+ viewId = 0;
}
else
{
- viewId = new Integer(viewId.intValue() + 1);
+ viewId = viewId + 1;
}
store.setAttribute(VIEW_ID_KEY, viewId);
@@ -252,14 +270,14 @@
}
}
- /**
- * Returns the current view id.
- *
- * @return the view id
- */
public String getViewId()
{
Integer viewId = (Integer)store.getAttribute(VIEW_ID_KEY);
return viewId != null ? viewId.toString() : "0";
}
+
+ private NavigationalStateKey getKeyFrom(String windowId)
+ {
+ return new NavigationalStateKey(WindowNavigationalState.class,
PortalObjectId.parse(windowId, 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
00:20:29 UTC (rev 10529)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/navstate/NavigationalStateContext.java 2008-04-11
00:31:22 UTC (rev 10530)
@@ -23,11 +23,53 @@
package org.jboss.portal.core.navstate;
import org.jboss.portal.common.invocation.AttributeResolver;
+import org.jboss.portal.core.model.portal.navstate.WindowNavigationalState;
+import java.util.Iterator;
+
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
*/
public interface NavigationalStateContext extends AttributeResolver
{
+ /**
+ * Retrieves the navigational state associated with the specified window identifier.
+ *
+ * @param windowId a String identifying the window which navigational state is to be
retrieved
+ * @return the navigational state associated with the specified window identifier or
<code>null</code> if the given
+ * window identifier is not known by this NavigationalStateContext or no
navigational state is associated
+ * with the given identifier.
+ */
+ WindowNavigationalState getWindowNavigationalState(String windowId);
+
+ /**
+ * Set the navigational state associated with the window identified by the given
identifier.
+ *
+ * @param windowId the window identifier
+ * @param windowNavigationalState the window navigational state
+ */
+ void setWindowNavigationalState(String windowId, WindowNavigationalState
windowNavigationalState);
+
+ /**
+ * Apply the navigational state changes made to this NavigationalStateContext.
+ *
+ * @return true if state changed
+ */
+ boolean applyChanges();
+
+ /**
+ * Returns the current view id.
+ *
+ * @return the view id
+ */
+ String getViewId();
+
+ /**
+ * Retrieve an iterator over the current changes.
+ *
+ * @return an iterator over the current changes.
+ */
+ Iterator<? extends NavigationalStateChange> getChanges();
}