Author: julien(a)jboss.com
Date: 2007-01-22 09:20:16 -0500 (Mon, 22 Jan 2007)
New Revision: 6063
Added:
trunk/core/src/main/org/jboss/portal/core/WindowInterceptor.java
trunk/core/src/main/org/jboss/portal/core/WindowManipulator.java
Removed:
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PageNavigationInterceptor.java
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObject.java
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderPageCommand.java
trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
Log:
- added window manipulator prototype which helps to manipulate window state of a page
- removed unused PageNavigationInterceptor
Added: trunk/core/src/main/org/jboss/portal/core/WindowInterceptor.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/WindowInterceptor.java
(rev 0)
+++ trunk/core/src/main/org/jboss/portal/core/WindowInterceptor.java 2007-01-22 14:20:16
UTC (rev 6063)
@@ -0,0 +1,183 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, 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;
+
+import org.jboss.portal.core.controller.ControllerInterceptor;
+import org.jboss.portal.core.controller.ControllerCommand;
+import org.jboss.portal.core.model.portal.command.RenderPageCommand;
+import org.jboss.portal.core.model.portal.command.InvokePortletWindowRenderCommand;
+import org.jboss.portal.core.model.portal.Window;
+import org.jboss.portal.core.model.portal.Page;
+import org.jboss.portal.core.model.portal.PortalObject;
+import org.jboss.portal.common.invocation.InvocationException;
+import org.jboss.portal.theme.navigation.WindowNavigationalState;
+import org.jboss.portal.WindowState;
+
+import java.util.Iterator;
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class WindowInterceptor extends ControllerInterceptor
+{
+ public Object invoke(ControllerCommand cmd) throws Exception, InvocationException
+ {
+ if (cmd instanceof InvokePortletWindowRenderCommand)
+ {
+ // Update state
+ cmd.invokeNext();
+
+ //
+ InvokePortletWindowRenderCommand ipwrc = (InvokePortletWindowRenderCommand)cmd;
+ Window targetWindow = ipwrc.getWindow();
+ Collection windows =
targetWindow.getParent().getChildren(PortalObject.TYPE_WINDOW);
+ WindowManipulator manipulator = new
WindowManipulator(cmd.getContext().getAttributeResolver(ControllerCommand.NAVIGATIONAL_STATE_SCOPE),
windows);
+ WindowState ws = ipwrc.getWindowState();
+
+ //
+ if (WindowState.NORMAL.equals(ws))
+ {
+ String regionName = manipulator.getRegionName(targetWindow);
+ if (regionName != null)
+ {
+ for (Iterator i =
manipulator.getWindows(regionName).iterator();i.hasNext();)
+ {
+ Window currentWindow = (Window)i.next();
+ if (currentWindow.getId().equals(targetWindow.getId()))
+ {
+ // Do nothing
+ }
+ else
+ {
+ WindowNavigationalState wns =
manipulator.getNavigationalState(currentWindow);
+ wns.setWindowState(WindowState.MINIMIZED);
+ }
+ }
+ }
+ }
+ else if (WindowState.MINIMIZED.equals(ws))
+ {
+ String regionName = manipulator.getRegionName(targetWindow);
+ if (regionName != null)
+ {
+ // Find the window following the minimized one
+ Window nextWindow = null;
+ for (Iterator i =
manipulator.getWindows(regionName).iterator();i.hasNext();)
+ {
+ Window currentWindow = (Window)i.next();
+
+ // Keep a ref on the first window for later use
+ if (nextWindow == null)
+ {
+ nextWindow = currentWindow;
+ }
+
+ //
+ if (currentWindow.getId().equals(targetWindow.getId()))
+ {
+ // Try to get the next window otherwise it means it's the last
window
+ // and we'll use the window we saved at the first iteration
+ if (i.hasNext())
+ {
+ nextWindow = (Window)i.next();
+ }
+
+ //
+ break;
+ }
+ }
+
+ // Normalize the next window
+ if (nextWindow != null)
+ {
+ WindowNavigationalState wns =
manipulator.getNavigationalState(nextWindow);
+ wns.setWindowState(WindowState.NORMAL);
+ }
+ }
+ }
+ }
+ if (cmd instanceof RenderPageCommand)
+ {
+ RenderPageCommand rpc = (RenderPageCommand)cmd;
+ WindowManipulator manipulator = new
WindowManipulator(cmd.getContext().getAttributeResolver(ControllerCommand.NAVIGATIONAL_STATE_SCOPE),
rpc.getWindows());
+
+ // Filter window state for normal and minimized
+ for (Iterator i = manipulator.getRegionNames().iterator();i.hasNext();)
+ {
+ boolean foundNormal = false;
+ Window firstWindow = null;
+ String regionName = (String)i.next();
+ for (Iterator j =
manipulator.getWindows(regionName).iterator();j.hasNext();)
+ {
+ Window window = (Window)j.next();
+
+ // Keep a ref on first window which can be used later
+ if (firstWindow == null)
+ {
+ firstWindow = window;
+ }
+
+ //
+ WindowNavigationalState wns = manipulator.getNavigationalState(window);
+ WindowState ws = wns.getWindowState();
+ if (WindowState.NORMAL.equals(ws))
+ {
+ if (foundNormal)
+ {
+ wns.setWindowState(WindowState.MINIMIZED);
+ }
+ else
+ {
+ foundNormal = true;
+ }
+ }
+ else if (WindowState.MINIMIZED.equals(ws))
+ {
+ //
+ }
+ else
+ {
+ ws = WindowState.MINIMIZED;
+ wns.setWindowState(ws);
+ }
+ }
+
+ //
+ if (foundNormal == false && firstWindow != null)
+ {
+ WindowNavigationalState wns =
manipulator.getNavigationalState(firstWindow);
+ wns.setWindowState(WindowState.NORMAL);
+ }
+ }
+
+ //
+ return cmd.invokeNext();
+ }
+ else
+ {
+ return cmd.invokeNext();
+ }
+ }
+}
Added: trunk/core/src/main/org/jboss/portal/core/WindowManipulator.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/WindowManipulator.java
(rev 0)
+++ trunk/core/src/main/org/jboss/portal/core/WindowManipulator.java 2007-01-22 14:20:16
UTC (rev 6063)
@@ -0,0 +1,122 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, 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;
+
+import org.jboss.portal.common.invocation.AttributeResolver;
+import org.jboss.portal.theme.ThemeConstants;
+import org.jboss.portal.theme.navigation.WindowNavigationalState;
+import org.jboss.portal.core.model.portal.Window;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.TreeMap;
+import java.util.SortedMap;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class WindowManipulator
+{
+
+ private Map regionMap;
+
+ private AttributeResolver navStateResolver;
+
+ public WindowManipulator(AttributeResolver navStateResolver, Collection windows)
+ {
+ this.navStateResolver = navStateResolver;
+
+ // Build appropriate structure
+ regionMap = new HashMap();
+ for (Iterator i = windows.iterator();i.hasNext();)
+ {
+ try
+ {
+ Window window = (Window)i.next();
+ String region =
window.getDeclaredProperty(ThemeConstants.PORTAL_PROP_REGION);
+ Integer order = new
Integer(window.getDeclaredProperty(ThemeConstants.PORTAL_PROP_ORDER));
+
+ //
+ SortedMap windowMap = (SortedMap)regionMap.get(region);
+ if (windowMap == null)
+ {
+ windowMap = new TreeMap();
+ regionMap.put(region, windowMap);
+ }
+ windowMap.put(order, window);
+ }
+ catch (NumberFormatException ignore)
+ {
+ }
+ }
+ }
+
+ public String getRegionName(Window window)
+ {
+ for (Iterator i = regionMap.entrySet().iterator();i.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry)i.next();
+ SortedMap windows = (SortedMap)entry.getValue();
+ for (Iterator j = windows.values().iterator();j.hasNext();)
+ {
+ Window window2 = (Window)j.next();
+ if (window.getId().equals(window2.getId()))
+ {
+ return (String)entry.getKey();
+ }
+ }
+ }
+ return null;
+ }
+
+ public Set getRegionNames()
+ {
+ return regionMap.keySet();
+ }
+
+ public Collection getWindows(String regionName)
+ {
+ return ((Map)regionMap.get(regionName)).values();
+ }
+
+ public WindowNavigationalState getNavigationalState(Window window)
+ {
+ WindowNavigationalState wns =
(WindowNavigationalState)navStateResolver.getAttribute(window.getId() +
"_window");
+ if (wns == null)
+ {
+ wns = new WindowNavigationalState();
+ navStateResolver.setAttribute(window.getId() + "_window", wns);
+ }
+ return wns;
+ }
+
+ public void setNavigationalState(Window window, WindowNavigationalState windowNS)
+ {
+ navStateResolver.setAttribute(window.getId() + "_window", windowNS);
+ }
+
+}
Deleted:
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PageNavigationInterceptor.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PageNavigationInterceptor.java 2007-01-22
12:57:06 UTC (rev 6062)
+++
trunk/core/src/main/org/jboss/portal/core/aspects/controller/PageNavigationInterceptor.java 2007-01-22
14:20:16 UTC (rev 6063)
@@ -1,61 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, 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.aspects.controller;
-
-import org.apache.log4j.Logger;
-import org.jboss.portal.common.invocation.InvocationException;
-import org.jboss.portal.core.controller.ControllerCommand;
-import org.jboss.portal.core.controller.ControllerInterceptor;
-
-/**
- * Ensure that the page navigational state holder is present.
- *
- * @author <a href="mailto:mholzner@novell.com">Martin Holzner</a>
- * @version $Revision$
- */
-public class PageNavigationInterceptor extends ControllerInterceptor
-{
-
- private static final Logger log = Logger.getLogger(PageNavigationInterceptor.class);
-
- public Object invoke(ControllerCommand cmd) throws Exception, InvocationException
- {
-// if (cmd instanceof WindowCommand || cmd instanceof PageCommand)
-// {
-// //
-// PortalObject target = ((PortalObjectCommand)cmd).getTarget();
-// while (target != null && PortalObject.TYPE_PAGE != target.getType()
&& target.getParent() != null)
-// {
-// target = target.getParent();
-// }
-//
-// if (target == null || target.getType() != PortalObject.TYPE_PAGE)
-// {
-// throw new InvocationException("Could not determine the page of this
request");
-// }
-// }
-
- return cmd.invokeNext();
- }
-}
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2007-01-22
12:57:06 UTC (rev 6062)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2007-01-22
14:20:16 UTC (rev 6063)
@@ -27,6 +27,7 @@
import org.jboss.portal.core.model.portal.NoSuchPortalObjectException;
import org.jboss.portal.core.model.portal.PortalObject;
import org.jboss.portal.core.model.portal.PortalObjectId;
+import org.jboss.portal.common.NotYetImplemented;
import java.util.ArrayList;
import java.util.Collection;
@@ -34,6 +35,7 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.NoSuchElementException;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -163,101 +165,148 @@
protected abstract PortalObjectImpl cloneObject();
+ public Collection getChildren(int type)
+ {
+ return getChildren(new Integer(type));
+ }
+
public Collection getChildren()
{
+ return getChildren(null);
+ }
+
+ public Collection getChildren(final Integer type)
+ {
if (collection == null)
{
collection = new Collection()
{
- public int size()
+ public void clear()
{
- return objectNode.getChildren().size();
+ throw new UnsupportedOperationException();
}
- public void clear()
+ public boolean add(Object o)
{
throw new UnsupportedOperationException();
}
- public boolean isEmpty()
+ public boolean remove(Object o)
{
- return objectNode.getChildren().isEmpty();
+ throw new UnsupportedOperationException();
}
- public Object[] toArray()
+ public boolean addAll(Collection c)
{
- return toArray(new Object[0]);
+ throw new UnsupportedOperationException();
}
- public boolean add(Object o)
+ public boolean removeAll(Collection c)
{
throw new UnsupportedOperationException();
}
- public boolean contains(Object o)
+ public boolean retainAll(Collection c)
{
throw new UnsupportedOperationException();
}
- public boolean remove(Object o)
+ public boolean containsAll(Collection c)
{
- throw new UnsupportedOperationException();
+ throw new NotYetImplemented();
}
- public boolean addAll(Collection c)
+ public boolean contains(Object o)
{
- throw new UnsupportedOperationException();
+ throw new NotYetImplemented();
}
- public boolean containsAll(Collection c)
+ public boolean isEmpty()
{
- throw new UnsupportedOperationException();
+ return objectNode.getChildren().isEmpty();
}
- public boolean removeAll(Collection c)
+ public int size()
{
- throw new UnsupportedOperationException();
+ if (type == null)
+ {
+ return objectNode.getChildren().size();
+ }
+ else
+ {
+ int count = 0;
+ for (Iterator i = iterator();i.hasNext();)
+ {
+ i.next();
+ count++;
+ }
+ return count;
+ }
}
- public boolean retainAll(Collection c)
+ public Object[] toArray()
{
- throw new UnsupportedOperationException();
+ return toArray(new Object[0]);
}
public Iterator iterator()
{
- final Iterator iterator = objectNode.getChildren().values().iterator();
+ return iterator(type);
+ }
+
+ public Object[] toArray(Object a[])
+ {
+ ArrayList tmp = new ArrayList(objectNode.getChildren().size());
+ for (Iterator i = iterator(); i.hasNext();)
+ {
+ PortalObject child = (PortalObject)i.next();
+ tmp.add(child);
+ }
+ return tmp.toArray(a);
+ }
+
+ public Iterator iterator(final Integer type)
+ {
return new Iterator()
{
+ Iterator iterator = objectNode.getChildren().values().iterator();
+ PortalObject next = null;
public void remove()
{
throw new UnsupportedOperationException();
}
-
public boolean hasNext()
{
- return iterator.hasNext();
+ if (next == null)
+ {
+ while (next == null && iterator.hasNext())
+ {
+ ObjectNode node = (ObjectNode)iterator.next();
+ PortalObject object = node.getObject();
+ if (type == null || object.getType() == type.intValue())
+ {
+ next = object;
+ }
+ }
+ }
+ return next != null;
}
-
public Object next()
{
- ObjectNode next = (ObjectNode)iterator.next();
- return next.getObject();
+ if (next == null)
+ {
+ hasNext();
+ }
+ if (next == null)
+ {
+ throw new NoSuchElementException();
+ }
+ PortalObject next = this.next;
+ this.next = null;
+ return next;
}
};
}
-
- public Object[] toArray(Object a[])
- {
- ArrayList tmp = new ArrayList(objectNode.getChildren().size());
- for (Iterator i = objectNode.getChildren().values().iterator();
i.hasNext();)
- {
- ObjectNode childObjectNode = (ObjectNode)i.next();
- PortalObjectImpl childPortalObject = childObjectNode.getObject();
- tmp.add(childPortalObject);
- }
- return tmp.toArray(a);
- }
};
}
return collection;
Modified: trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObject.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObject.java 2007-01-22
12:57:06 UTC (rev 6062)
+++ trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObject.java 2007-01-22
14:20:16 UTC (rev 6063)
@@ -95,6 +95,13 @@
Collection getChildren();
/**
+ * Return all the children of this object filtered with a particular type.
+ *
+ * @return the children
+ */
+ Collection getChildren(int type);
+
+ /**
* Return the parent object.
*
* @return the parent object.
Modified:
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderPageCommand.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderPageCommand.java 2007-01-22
12:57:06 UTC (rev 6062)
+++
trunk/core/src/main/org/jboss/portal/core/model/portal/command/RenderPageCommand.java 2007-01-22
14:20:16 UTC (rev 6063)
@@ -129,7 +129,7 @@
super.create();
// All windows on the page
- windows = new ArrayList(getPage().getChildren());
+ windows = new ArrayList(getPage().getChildren(PortalObject.TYPE_WINDOW));
//
LayoutService layoutService =
context.getController().getPageService().getLayoutService();
Modified: trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2007-01-22
12:57:06 UTC (rev 6062)
+++ trunk/core/src/resources/portal-core-sar/META-INF/jboss-service.xml 2007-01-22
14:20:16 UTC (rev 6063)
@@ -134,13 +134,6 @@
<xmbean/>
</mbean>
<mbean
-
code="org.jboss.portal.core.aspects.controller.PageNavigationInterceptor"
- name="portal:service=Interceptor,type=Command,name=PageNavigation"
- xmbean-dd=""
- xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
- <xmbean/>
- </mbean>
- <mbean
code="org.jboss.portal.core.aspects.controller.PageCustomizerInterceptor"
name="portal:service=Interceptor,type=Command,name=PageCustomizer"
xmbean-dd=""
@@ -176,7 +169,6 @@
<depends-list optional-attribute-name="InterceptorNames">
<depends-list-element>portal:service=Interceptor,type=Command,name=PortalNode</depends-list-element>
<depends-list-element>portal:service=Interceptor,type=Command,name=PolicyEnforcement</depends-list-element>
-
<depends-list-element>portal:service=Interceptor,type=Command,name=PageNavigation</depends-list-element>
<depends-list-element>portal:service=Interceptor,type=Command,name=PageCustomizer</depends-list-element>
<depends-list-element>portal:service=Interceptor,type=Command,name=Ajax</depends-list-element>
<depends-list-element>portal:service=Interceptor,type=Command,name=EventBroadcaster</depends-list-element>