Author: theute
Date: 2011-03-16 18:16:07 -0400 (Wed, 16 Mar 2011)
New Revision: 6060
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/common/src/main/java/org/exoplatform/commons/utils/Spliterator.java
epp/portal/branches/EPP_5_1_RH_Branch/component/common/src/test/java/org/exoplatform/commons/utils/TestSpliterator.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/SiteKey.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/SiteType.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/GenericScope.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/InvalidationManager.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/Invalidator.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/ListTree.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/Navigation.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationService.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationServiceEvent.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationServiceException.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationServiceImpl.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationServiceWrapper.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationState.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeContext.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeData.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeFilter.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeModel.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeState.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/Scope.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/VisitMode.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/NavigationPath.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNavigation.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNode.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilter.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodePredicate.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserPortal.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserPortalContext.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserPortalImpl.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/MOPAccess.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/NodeTask.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/data/NodeData.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/navigation/
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/navigation/Node.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/navigation/TestListTree.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/navigation/TestNavigationService.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/navigation/TestScope.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/user/
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/user/TestUserPortal.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/pom/
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/pom/data/
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/pom/data/TestModel.java
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/resources/portal/portal/large/
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/resources/portal/portal/large/navigation.xml
Removed:
epp/portal/branches/EPP_5_1_RH_Branch/portlet/exoadmin/src/main/webapp/groovy/navigation/webui/component/NewUIGroupManagement.gtmpl
epp/portal/branches/EPP_5_1_RH_Branch/portlet/web/src/main/java/org/exoplatform/portal/webui/component/UIPortalNavigationPortlet.java
epp/portal/branches/EPP_5_1_RH_Branch/portlet/web/src/main/webapp/WEB-INF/conf/portlet/web/PortalNavigationPortlet/webui/configuration.xml
epp/portal/branches/EPP_5_1_RH_Branch/portlet/web/src/main/webapp/groovy/portal/webui/component/UIPortalNavigation2.gtmpl
epp/portal/branches/EPP_5_1_RH_Branch/web/portal/src/main/webapp/groovy/portal/webui/page/UIPageSelector2.gtmpl
epp/portal/branches/EPP_5_1_RH_Branch/web/portal/src/main/webapp/groovy/portal/webui/portal/NewUIGroupManagement.gtmpl
epp/portal/branches/EPP_5_1_RH_Branch/web/portal/src/main/webapp/groovy/webui/core/UISitemap2.gtmpl
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/PageNavigationUtils.java
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/ParentChildPair.java
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPortalNavigation2.java
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPortalNodeSelector.java
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/page/PageUtils.java
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageSelector2.java
Log:
JBEPP-853: Performance issues with the shipped-in applications when the portal has many
nodes or pages
Forgot to add/delete files
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/common/src/main/java/org/exoplatform/commons/utils/Spliterator.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/common/src/main/java/org/exoplatform/commons/utils/Spliterator.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/common/src/main/java/org/exoplatform/commons/utils/Spliterator.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.commons.utils;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+/**
+ * An iterator that splits a string into chunks without requiring to allocate an array to
hold
+ * the various chunks of the splitted string.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class Spliterator implements Iterator<String>
+{
+
+ /** . */
+ private final String s;
+
+ /** . */
+ private final char separator;
+
+ /** . */
+ private int from;
+
+ /** . */
+ private Integer to;
+
+ /**
+ * Creates a spliterator.
+ *
+ * @param s the string to split
+ * @param separator the separator
+ * @throws NullPointerException if the string is null
+ */
+ public Spliterator(String s, char separator) throws NullPointerException
+ {
+ if (s == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //
+ this.s = s;
+ this.separator = separator;
+ this.from = 0;
+ this.to = null;
+ }
+
+ public boolean hasNext()
+ {
+ if (from == -1)
+ {
+ return false;
+ }
+ else
+ {
+ if (to == null)
+ {
+ to = s.indexOf(separator, from);
+ }
+ return true;
+ }
+ }
+
+ public String next()
+ {
+ if (hasNext())
+ {
+ String next;
+ if (to == -1)
+ {
+ next = s.substring(from);
+ from = -1;
+ }
+ else
+ {
+ next = s.substring(from, to);
+ from = to + 1;
+ }
+ to = null;
+ return next;
+ }
+ else
+ {
+ throw new NoSuchElementException();
+ }
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/common/src/test/java/org/exoplatform/commons/utils/TestSpliterator.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/common/src/test/java/org/exoplatform/commons/utils/TestSpliterator.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/common/src/test/java/org/exoplatform/commons/utils/TestSpliterator.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.commons.utils;
+
+import org.exoplatform.component.test.AbstractGateInTest;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestSpliterator extends AbstractGateInTest
+{
+
+ public void testEmptyString()
+ {
+ Spliterator i = new Spliterator("", ' ');
+ assertTrue(i.hasNext());
+ assertEquals("", i.next());
+ assertFalse(i.hasNext());
+ }
+
+ public void testSeparatorString()
+ {
+ Spliterator i = new Spliterator(" ", ' ');
+ assertTrue(i.hasNext());
+ assertEquals("", i.next());
+ assertTrue(i.hasNext());
+ assertEquals("", i.next());
+ assertFalse(i.hasNext());
+ }
+
+ public void testEntireString()
+ {
+ Spliterator i = new Spliterator("a", ' ');
+ assertTrue(i.hasNext());
+ assertEquals("a", i.next());
+ assertFalse(i.hasNext());
+ }
+
+ public void testNormal()
+ {
+ Spliterator i = new Spliterator("a b", ' ');
+ assertTrue(i.hasNext());
+ assertEquals("a", i.next());
+ assertTrue(i.hasNext());
+ assertEquals("b", i.next());
+ assertFalse(i.hasNext());
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/SiteKey.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/SiteKey.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/SiteKey.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop;
+
+import org.exoplatform.portal.config.model.PortalConfig;
+
+import java.io.Serializable;
+
+/**
+* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+* @version $Revision$
+*/
+public final class SiteKey implements Serializable
+{
+
+ public static SiteKey portal(String name)
+ {
+ return new SiteKey(SiteType.PORTAL, name);
+ }
+
+ public static SiteKey group(String name)
+ {
+ return new SiteKey(SiteType.GROUP, name);
+ }
+
+ public static SiteKey user(String name)
+ {
+ return new SiteKey(SiteType.USER, name);
+ }
+
+ /** . */
+ private final SiteType type;
+
+ /** . */
+ private final String name;
+
+ public SiteKey(SiteType type, String name)
+ {
+ if (type == null)
+ {
+ throw new NullPointerException("No null type can be provided");
+ }
+ if (name == null)
+ {
+ throw new NullPointerException("No null name can be provided");
+ }
+
+ //
+ this.type = type;
+ this.name = name;
+ }
+
+ // This will be used for transition in usage from PortalKey and SiteKey
+ public SiteKey(String type, String name)
+ {
+ if (PortalConfig.PORTAL_TYPE.equals(type))
+ {
+ this.type = SiteType.PORTAL;
+ }
+ else if (PortalConfig.GROUP_TYPE.equals(type))
+ {
+ this.type = SiteType.GROUP;
+ }
+ else if (PortalConfig.USER_TYPE.equals(type))
+ {
+ this.type = SiteType.USER;
+ }
+ else
+ {
+ throw new NullPointerException("No null name can be provided");
+ }
+
+ this.name = name;
+ }
+
+ public SiteType getType()
+ {
+ return type;
+ }
+
+ public String getTypeName()
+ {
+ return type.getName();
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return name.hashCode() ^ type.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+
+ // We need to use class equality here
+ if (obj != null && getClass().equals(obj.getClass()))
+ {
+ SiteKey that = (SiteKey)obj;
+ return type.equals(that.type) && name.equals(that.name);
+ }
+
+ //
+ return false;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "SiteKey[type=" + type.toString() + ",name=" + name +
"]";
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/SiteType.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/SiteType.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/SiteType.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public enum SiteType
+{
+
+ PORTAL, GROUP, USER ;
+
+ /** ; */
+ final String name;
+
+ SiteType()
+ {
+ this.name = name().toLowerCase();
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/GenericScope.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/GenericScope.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/GenericScope.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+* A flexible scope implementation.
+*/
+public class GenericScope implements Scope
+{
+
+ public static Scope branchShape(String[] path)
+ {
+ return branchShape(Arrays.asList(path), Scope.CHILDREN);
+ }
+
+ public static Scope branchShape(List<String> path)
+ {
+ return branchShape(path, Scope.CHILDREN);
+ }
+
+ public static Scope branchShape(String[] path, Scope federated)
+ {
+ return branchShape(Arrays.asList(path), federated);
+ }
+
+ /**
+ * <p>A scope with the shape of a tree branch following the rules:
+ * <ul>
+ * <li>the first node with depth 0 will have all of its children
visited</li>
+ * <li>any node above the root node that fits in the
<code>path</code> array will be matched
+ * only if the node name matches the corresponding value in the
<code>path</code> array. The last
+ * node whose depth is equals to the <code>path</code> list size will
have its visit mode value delegated
+ * to the <code>federated</code> scope argument with a depth of 0 and
the same other arguments, any other node
+ * will have all of its children visited.</li>
+ * <li>any other node will have its visit mode delegated to the
<code>federated</code> scope argument
+ * with the same arguments except the depth that will be subtracted the
<code>path</code> list argument size.</li>
+ * </ul></p>
+ *
+ * @param path the names that describing the tree path
+ * @param federated the federated scope
+ * @return the branch shape scope
+ * @throws NullPointerException if any argument is null
+ */
+ public static Scope branchShape(final List<String> path, final Scope federated)
throws NullPointerException
+ {
+ if (path == null)
+ {
+ throw new NullPointerException("no null path accepted");
+ }
+ if (federated == null)
+ {
+ throw new NullPointerException("no null federated scope accepted");
+ }
+ return new Scope()
+ {
+ public Visitor get()
+ {
+ return new Visitor()
+ {
+ public VisitMode visit(int depth, String id, String name, NodeState
state)
+ {
+ if (depth == 0)
+ {
+ return VisitMode.ALL_CHILDREN;
+ }
+ else if (depth > 0)
+ {
+ if (depth < path.size())
+ {
+ if ((name.equals(path.get(depth - 1))))
+ {
+ return VisitMode.ALL_CHILDREN;
+ }
+ else
+ {
+ return VisitMode.NO_CHILDREN;
+ }
+ }
+ else if (depth == path.size())
+ {
+ if ((name.equals(path.get(path.size() - 1))))
+ {
+ return federated.get().visit(0, id, name, state);
+ }
+ else
+ {
+ return VisitMode.NO_CHILDREN;
+ }
+ }
+ else
+ {
+ return federated.get().visit(depth - path.size(), id, name,
state);
+ }
+ }
+ throw new AssertionError();
+ }
+ };
+ }
+ };
+ }
+
+
+ /** . */
+ private final Visitor visitor;
+
+ /**
+ * Creates a new navigation scope. When the height is positive or null, the tree will
be pruned to the specified
+ * height, when the height is negative no pruning will occur.
+ *
+ * @param height the max height of the pruned tree
+ */
+ public GenericScope(final int height)
+ {
+ this.visitor = new Visitor()
+ {
+ public VisitMode visit(int depth, String id, String name, NodeState state)
+ {
+ if (height < 0 || depth < height)
+ {
+ return VisitMode.ALL_CHILDREN;
+ }
+ else
+ {
+ return VisitMode.NO_CHILDREN;
+ }
+ }
+ };
+ }
+
+ public Visitor get()
+ {
+ return visitor;
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/InvalidationManager.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/InvalidationManager.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/InvalidationManager.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.EventIterator;
+import javax.jcr.observation.EventListener;
+import javax.jcr.observation.ObservationManager;
+import java.util.LinkedList;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+class InvalidationManager
+{
+
+ /** . */
+ private final ObservationManager om;
+
+ /** . */
+ private LinkedList<Registration> registrations;
+
+ InvalidationManager(ObservationManager om)
+ {
+ this.om = om;
+ this.registrations = new LinkedList<Registration>();
+ }
+
+ void register(String nodeType, int eventTypes, Invalidator invalidator) throws
RepositoryException
+ {
+ Registration registration = new Registration(nodeType, invalidator);
+ om.addEventListener(registration, eventTypes, "/", true, null, new
String[]{nodeType}, false);
+ registrations.add(registration);
+ }
+
+ void close()
+ {
+ for (Registration registration : registrations)
+ {
+ try
+ {
+ om.removeEventListener(registration);
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private static class Registration implements EventListener
+ {
+
+ /** . */
+ private final String nodeType;
+
+ /** . */
+ private final Invalidator invalidator;
+
+ private Registration(String nodeType, Invalidator invalidator)
+ {
+ this.nodeType = nodeType;
+ this.invalidator = invalidator;
+ }
+
+ public void onEvent(EventIterator events)
+ {
+ while (events.hasNext())
+ {
+ try
+ {
+ Event event = events.nextEvent();
+ invalidator.invalidate(event.getType(), nodeType, event.getPath());
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/Invalidator.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/Invalidator.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/Invalidator.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+abstract class Invalidator
+{
+
+ abstract void invalidate(int eventType, String nodeType, String itemPath);
+
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/ListTree.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/ListTree.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/ListTree.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,699 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public abstract class ListTree<T extends ListTree<T, E>, E> implements
Iterable<E>
+{
+
+ /** . */
+ private String name;
+
+ /** . */
+ private T parent;
+
+ /** . */
+ private Map<String, T> map;
+
+ /** . */
+ private T next;
+
+ /** . */
+ private T previous;
+
+ /** . */
+ private T head;
+
+ /** . */
+ private T tail;
+
+ /** . */
+ private boolean hidden;
+
+ /** . */
+ private int count;
+
+ public ListTree(String name)
+ {
+ if (name == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //
+ this.name = name;
+ this.next = null;
+ this.previous = null;
+ this.head = null;
+ this.tail = null;
+ this.hidden = false;
+ this.count = -1;
+ }
+
+ public final int getSize()
+ {
+ return map == null ? -1 : map.size();
+ }
+
+ public final int getCount()
+ {
+ return count;
+ }
+
+ public final boolean isHidden()
+ {
+ return hidden;
+ }
+
+ public final T getNext()
+ {
+ return next;
+ }
+
+ public final T getPrevious()
+ {
+ return previous;
+ }
+
+ public final void setHidden(boolean hidden)
+ {
+ if (this.hidden != hidden)
+ {
+ if (parent != null)
+ {
+ if (hidden)
+ {
+ parent.count--;
+ }
+ else
+ {
+ parent.count++;
+ }
+ }
+ this.hidden = hidden;
+ }
+ }
+
+ public abstract E getElement();
+
+ public final String getName()
+ {
+ return name;
+ }
+
+ public final T getParent()
+ {
+ return parent;
+ }
+
+ public final void rename(String from, String to) throws NullPointerException,
IllegalStateException, IllegalArgumentException
+ {
+ if (from == null)
+ {
+ throw new NullPointerException();
+ }
+ if (to == null)
+ {
+ throw new NullPointerException();
+ }
+ if (map == null)
+ {
+ throw new IllegalStateException();
+ }
+
+ //
+ if (!from.equals(to))
+ {
+ if (map.containsKey(to))
+ {
+ throw new IllegalArgumentException("the node " + to + "
already exist");
+ }
+ T child = map.remove(from);
+ if (child == null)
+ {
+ throw new IllegalArgumentException("the node " + from + " +
does not exist");
+ }
+ if (child.hidden)
+ {
+ throw new IllegalArgumentException("the node " + from + " + is
hidden");
+ }
+ child.name = to;
+ map.put(to, child);
+ }
+ }
+
+ public final T remove(String name) throws NullPointerException, IllegalStateException
+ {
+ T child = get(name);
+ if (child != null)
+ {
+ child.remove();
+ return child;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public final boolean contains(String name) throws NullPointerException,
IllegalStateException
+ {
+ return get(name) != null;
+ }
+
+ public final T get(String name) throws NullPointerException, IllegalStateException
+ {
+ if (name == null)
+ {
+ throw new NullPointerException();
+ }
+ if (map == null)
+ {
+ throw new IllegalStateException("No children relationship");
+ }
+
+ //
+ T child = map.get(name);
+ return child == null || child.hidden ? null : child;
+ }
+
+ public final T getFirst()
+ {
+ if (map == null)
+ {
+ throw new IllegalStateException("no children");
+ }
+ return head;
+ }
+
+ public final T getLast()
+ {
+ if (map == null)
+ {
+ throw new IllegalStateException("no children");
+ }
+ return tail;
+ }
+
+ public final T get(int index) throws IllegalStateException, IndexOutOfBoundsException
+ {
+ if (map == null)
+ {
+ throw new IllegalStateException("no children");
+ }
+ if (index < 0)
+ {
+ throw new IndexOutOfBoundsException("No negative index allowed");
+ }
+
+ //
+ T current = head;
+ while (true)
+ {
+ while (current != null && current.hidden)
+ {
+ current = current.next;
+ }
+ if (current == null)
+ {
+ throw new IndexOutOfBoundsException("index " + index + " is
greater than the children size");
+ }
+ if (index == 0)
+ {
+ break;
+ }
+ else
+ {
+ current = current.next;
+ index--;
+ }
+ }
+ return current;
+ }
+
+ public final boolean hasTrees()
+ {
+ return map != null;
+ }
+
+ /**
+ * Insert the specified tree.
+ *
+ * @param index the index
+ * @param tree the tree
+ * @throws NullPointerException if the context is null
+ * @throws IllegalStateException if the children relationship does not exist
+ * @throws IllegalArgumentException if an existing child with the same name already
exist or if the context is hidden
+ * @throws IndexOutOfBoundsException if the index is negative or is greater than the
children size
+ */
+ public final void insert(Integer index, T tree) throws NullPointerException,
IllegalStateException, IllegalArgumentException, IndexOutOfBoundsException
+ {
+ if (tree == null)
+ {
+ throw new NullPointerException("No null tree accepted");
+ }
+ if (tree.hidden)
+ {
+ throw new IllegalArgumentException("Cannot insert hidden tree");
+ }
+ if (map == null)
+ {
+ throw new IllegalStateException("No trees relationship");
+ }
+ if (index != null && index < 0)
+ {
+ throw new IndexOutOfBoundsException("No negative index permitted");
+ }
+
+ //
+ T existing = map.get(tree.name);
+ if (existing != null && existing != tree)
+ {
+ throw new IllegalArgumentException("Tree " + tree.name + "
already in the map");
+ }
+
+ //
+ if (index != null)
+ {
+ T a = head;
+ if (index == 0)
+ {
+ insertFirst(tree);
+ }
+ else
+ {
+ while (index > 0)
+ {
+ while (a != null && a.hidden)
+ {
+ a = a.next;
+ }
+ if (a == null)
+ {
+ throw new IndexOutOfBoundsException();
+ }
+ index--;
+ a = a.next;
+ }
+
+ //
+ if (a == null)
+ {
+ insertLast(tree);
+ }
+ else if (a != tree)
+ {
+ a.insertBefore(tree);
+ }
+ }
+ }
+ else
+ {
+ T a = tail;
+ while (a != null && a.hidden)
+ {
+ a = a.previous;
+ }
+ if (a == null)
+ {
+ insertFirst(tree);
+ }
+ else if (a != tree)
+ {
+ a.insertAfter(tree);
+ }
+ }
+ }
+
+ public final Iterator<E> iterator()
+ {
+ return new Iterator<E>()
+ {
+ T next = head;
+ {
+ while (next != null && next.hidden)
+ {
+ next = next.next;
+ }
+ }
+ public boolean hasNext()
+ {
+ return next != null;
+ }
+ public E next()
+ {
+ if (next != null)
+ {
+ T tmp = next;
+ do
+ {
+ next = next.next;
+ }
+ while (next != null && next.hidden);
+ return tmp.getElement();
+ }
+ else
+ {
+ throw new NoSuchElementException();
+ }
+ }
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+ public final ListIterator<T> listIterator()
+ {
+ if (map == null)
+ {
+ return null;
+ }
+ return new ListIterator<T>()
+ {
+ T next = head;
+ T current = null;
+ T previous = null;
+ int index = 0;
+
+ public boolean hasNext()
+ {
+ return next != null;
+ }
+
+ public T next()
+ {
+ if (next != null)
+ {
+ current = next;
+
+ //
+ previous = next;
+ next = next.next;
+ index++;
+ return current;
+ }
+ else
+ {
+ throw new NoSuchElementException();
+ }
+ }
+
+ public boolean hasPrevious()
+ {
+ return previous != null;
+ }
+
+ public T previous()
+ {
+ if (previous != null)
+ {
+ current = previous;
+
+ //
+ next = previous;
+ previous = previous.previous;
+ index--;
+ return current;
+ }
+ else
+ {
+ throw new NoSuchElementException();
+ }
+ }
+
+ public int nextIndex()
+ {
+ return index;
+ }
+
+ public int previousIndex()
+ {
+ return index - 1;
+ }
+
+ public void remove()
+ {
+ if (current == null)
+ {
+ throw new IllegalStateException("no element to remove");
+ }
+ if (current == previous)
+ {
+ index--;
+ }
+ next = current.next;
+ previous = current.previous;
+ current.remove();
+ current = null;
+ }
+
+ public void set(T tree)
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void add(T tree)
+ {
+ if (previous == null)
+ {
+ insertFirst(tree);
+ }
+ else
+ {
+ previous.insertAfter(tree);
+ }
+ index++;
+ previous = tree;
+ next = tree.next;
+ }
+ };
+ }
+
+ protected final Iterable<T> getTrees()
+ {
+ if (map != null)
+ {
+ return new Iterable<T>()
+ {
+ public Iterator<T> iterator()
+ {
+ return listIterator();
+ }
+ };
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ protected final void setTrees(Iterable<T> children)
+ {
+ if (children == null)
+ {
+ if (map == null)
+ {
+ throw new IllegalStateException();
+ }
+ else
+ {
+ while (head != null)
+ {
+ head.remove();
+ }
+ this.map = null;
+ this.count = -1;
+ }
+ }
+ else
+ {
+ if (map == null)
+ {
+ @SuppressWarnings("unchecked") Map<String, T> map =
Collections.EMPTY_MAP;
+ this.map = map;
+ this.count = 0;
+ for (T child : children)
+ {
+ insertLast(child);
+ }
+ }
+ else
+ {
+ throw new IllegalStateException();
+ }
+ }
+ }
+
+ private void insertAfter(T tree)
+ {
+ if (this != tree)
+ {
+ if (tree.parent != null)
+ {
+ tree.remove();
+ }
+ tree.previous = (T)this;
+ tree.next = next;
+ if (next == null)
+ {
+ parent.tail = tree;
+ }
+ else
+ {
+ next.previous = tree;
+ }
+ next = tree;
+ if (parent.map == Collections.EMPTY_MAP)
+ {
+ parent.map = new HashMap<String, T>();
+ parent.count = 0;
+ }
+ if (!tree.hidden)
+ {
+ parent.count++;
+ }
+ parent.map.put(tree.name, tree);
+ tree.parent = parent;
+ }
+ }
+
+ private void insertBefore(T tree)
+ {
+ if (this != tree)
+ {
+ if (tree.parent != null)
+ {
+ tree.remove();
+ }
+ tree.previous = previous;
+ tree.next = (T)this;
+ if (previous == null)
+ {
+ parent.head = tree;
+ }
+ else
+ {
+ previous.next = tree;
+ }
+ previous = tree;
+ if (parent.map == Collections.EMPTY_MAP)
+ {
+ parent.map = new HashMap<String, T>();
+ parent.count = 0;
+ }
+ if (!tree.hidden)
+ {
+ parent.count++;
+ }
+ parent.map.put(tree.name, tree);
+ tree.parent = parent;
+ }
+ }
+
+ /**
+ * Insert the specified context at the first position among the children of this
context.
+ *
+ * @param tree the content to insert
+ */
+ private void insertFirst(T tree)
+ {
+ if (head == null)
+ {
+ if (tree.parent != null)
+ {
+ tree.remove();
+ }
+ head = tail = tree;
+ if (map == Collections.EMPTY_MAP)
+ {
+ map = new HashMap<String, T>();
+ count = 0;
+ }
+ if (!tree.hidden)
+ {
+ count++;
+ }
+ map.put(tree.name, tree);
+ tree.parent = (T)this;
+ }
+ else
+ {
+ head.insertBefore(tree);
+ }
+ }
+
+ private void insertLast(T context)
+ {
+ if (tail == null)
+ {
+ insertFirst(context);
+ }
+ else
+ {
+ tail.insertAfter(context);
+ }
+ }
+
+ private void remove()
+ {
+ if (previous == null)
+ {
+ parent.head = next;
+ }
+ else
+ {
+ previous.next = next;
+ }
+ if (next == null)
+ {
+ parent.tail = previous;
+ }
+ else
+ {
+ next.previous = previous;
+ }
+ if (!hidden)
+ {
+ parent.count--;
+ }
+ parent.map.remove(name);
+ parent = null;
+ previous = null;
+ next = null;
+ }
+
+ public String toString()
+ {
+ return getClass().getSimpleName() + "[name=" + getName() +
",element=" + getElement() + "]";
+ }
+}
+
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/Navigation.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/Navigation.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/Navigation.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+import org.exoplatform.portal.mop.SiteKey;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class Navigation
+{
+
+ /** . */
+ final String path;
+
+ /** . */
+ final SiteKey key;
+
+ /** . */
+ final NavigationState state;
+
+ /** . */
+ final String rootId;
+
+ Navigation(String path, SiteKey key, NavigationState state, String rootId)
+ {
+ if (path == null)
+ {
+ throw new NullPointerException();
+ }
+ if (key == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //
+ this.path = path;
+ this.key = key;
+ this.state = state;
+ this.rootId = rootId;
+ }
+
+ /**
+ * Returns the navigation key.
+ *
+ * @return the navigation key
+ */
+ public SiteKey getKey()
+ {
+ return key;
+ }
+
+ /**
+ * Returns the navigation state or null if the navigation is not entirely created
yet.
+ *
+ * @return the navigation state
+ */
+ public NavigationState getState()
+ {
+ return state;
+ }
+
+ String getRootId()
+ {
+ return rootId;
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationService.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationService.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationService.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+import org.exoplatform.portal.mop.SiteKey;
+
+/**
+ * <p>The navigation service takes care of managing the various portal navigations
and their nodes.</p>
+ *
+ * <p>In order to manage an efficient loading of the nodes, a {@link Scope} is used
to describe the set of nodes
+ * that should be retrieved when a loading operation is performed.</p>
+ *
+ * <p>The node operations does not provide a model per se, but instead use the
{@link NodeModel} interface to plug
+ * an API model. Various node operations are quite complex and any API in front of this
service would need to perform
+ * a manual, error prone and tedious synchronization. Instead the model interface allows
the navigation service to
+ * operate directly on an existing model.</p>
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public interface NavigationService
+{
+
+ /**
+ * Find and returns a navigation, if no such site exist, null is returned instead.
+ *
+ * @param key the navigation key
+ * @return the matching navigation
+ * @throws NullPointerException if the key is null
+ * @throws NavigationServiceException if the navigation could not be loaded
+ */
+ Navigation loadNavigation(SiteKey key) throws NullPointerException,
NavigationServiceException;
+
+ /**
+ * Create, update or destroy a navigation. When the navigation state is not null, the
navigation
+ * will be created or updated depending on whether or not the navigation already
exists. When
+ * the navigation state is null, the navigation will be destroyed.
+ *
+ * @param key they navigation key
+ * @param state the navigation state
+ * @return true if the intent succeeded
+ * @throws NullPointerException if the key is null
+ * @throws NavigationServiceException if the navigation could not be saved
+ */
+ boolean saveNavigation(SiteKey key, NavigationState state) throws
NullPointerException, NavigationServiceException;
+
+ /**
+ * Load a navigation node from a specified navigation. The returned node will be the
root node of the navigation.
+ *
+ * @param model the node model
+ * @param navigation the navigation
+ * @param scope the scope
+ * @param <N> the node model generic type
+ * @return the loaded node
+ * @throws NullPointerException if any argument is null
+ * @throws NavigationServiceException if the loading operation could not be performed
+ */
+ <N> N loadNode(NodeModel<N> model, Navigation navigation, Scope scope)
throws NullPointerException, NavigationServiceException;
+
+ /**
+ * Load a navigation node from a specified node. It will affect the node argument as
well as all its descendants
+ * when they are loaded according to the specified scope. The returned node is either
the same node or null
+ * if the node was skipped precisely.
+ *
+ * @param model the node model
+ * @param node the node
+ * @param scope the scope
+ * @param <N> the node model generic type
+ * @return the loaded node
+ * @throws NullPointerException if any argument is null
+ * @throws NavigationServiceException if the loading operation could not be performed
+ */
+ <N> N loadNode(NodeModel<N> model, N node, Scope scope) throws
NullPointerException, NavigationServiceException;
+
+ <N> void refresh(NodeModel<N> model, N node, Scope scope) throws
NullPointerException, NavigationServiceException;
+
+ <N> void saveNode(NodeModel<N> model, N node) throws NullPointerException,
NavigationServiceException;
+
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationServiceEvent.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationServiceEvent.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationServiceEvent.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class NavigationServiceEvent
+{
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationServiceException.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationServiceException.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationServiceException.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class NavigationServiceException extends Exception
+{
+ public NavigationServiceException()
+ {
+ }
+
+ public NavigationServiceException(String message)
+ {
+ super(message);
+ }
+
+ public NavigationServiceException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+
+ public NavigationServiceException(Throwable cause)
+ {
+ super(cause);
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationServiceImpl.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationServiceImpl.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationServiceImpl.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,1003 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+import org.chromattic.api.Chromattic;
+import org.exoplatform.portal.mop.Described;
+import org.exoplatform.portal.mop.SiteKey;
+import org.exoplatform.portal.mop.SiteType;
+import org.exoplatform.portal.mop.Visible;
+import org.exoplatform.portal.pom.config.POMSession;
+import org.exoplatform.portal.pom.config.POMSessionManager;
+import org.exoplatform.portal.pom.data.MappedAttributes;
+import org.exoplatform.portal.pom.data.Mapper;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
+import org.gatein.mop.api.Attributes;
+import org.gatein.mop.api.workspace.ObjectType;
+import org.gatein.mop.api.workspace.Site;
+import org.gatein.mop.api.workspace.Workspace;
+import org.gatein.mop.api.workspace.link.PageLink;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.EventListener;
+import javax.jcr.observation.EventListenerIterator;
+import javax.jcr.observation.ObservationManager;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.EnumMap;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import static org.exoplatform.portal.pom.config.Utils.split;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class NavigationServiceImpl implements NavigationService
+{
+
+ /** . */
+ private Map<SiteKey, Navigation> navigationKeyCache;
+
+ /** . */
+ private Map<String, SiteKey> navigationPathCache;
+
+ /** . */
+ private Map<String, NodeData> nodeIdCache;
+
+ /** . */
+ private Map<String, String> nodePathCache;
+
+ /** . */
+ private final POMSessionManager manager;
+
+ /** . */
+ private Session bridgeSession;
+
+ /** . */
+ private InvalidationManager invalidationManager;
+
+ /** . */
+ private static final EnumMap<SiteType, ObjectType<Site>> a = new
EnumMap<SiteType, ObjectType<Site>>(SiteType.class);
+
+ /** . */
+ final Logger log = LoggerFactory.getLogger(NavigationServiceImpl.class);
+
+ static
+ {
+ a.put(SiteType.PORTAL, ObjectType.PORTAL_SITE);
+ a.put(SiteType.GROUP, ObjectType.GROUP_SITE);
+ a.put(SiteType.USER, ObjectType.USER_SITE);
+ }
+
+ public NavigationServiceImpl(POMSessionManager manager)
+ {
+ if (manager == null)
+ {
+ throw new NullPointerException("No null pom session manager
allowed");
+ }
+ this.manager = manager;
+ this.navigationKeyCache = new ConcurrentHashMap<SiteKey, Navigation>(1000);
+ this.navigationPathCache = new ConcurrentHashMap<String, SiteKey>(1000);
+ this.nodeIdCache = new ConcurrentHashMap<String, NodeData>(1000);
+ this.nodePathCache = new ConcurrentHashMap<String, String>(1000);
+ this.invalidationManager = null;
+ }
+
+ public void start() throws Exception
+ {
+ Chromattic chromattic = manager.getLifeCycle().getChromattic();
+ Session session = chromattic.openSession().getJCRSession();
+ ObservationManager observationManager =
session.getWorkspace().getObservationManager();
+
+ invalidationManager = new InvalidationManager(observationManager);
+
+ //
+ final String NAVIGATION_CONTAINER = "mop:navigationcontainer";
+ final String NAVIGATION = "mop:navigation";
+ final String ATTRIBUTES = "mop:attributes";
+
+ //
+ invalidationManager.register(NAVIGATION_CONTAINER, Event.NODE_REMOVED +
Event.NODE_ADDED, new Invalidator()
+ {
+ @Override
+ void invalidate(int eventType, String nodeType, String itemPath)
+ {
+ if (nodeType.equals(NAVIGATION_CONTAINER))
+ {
+ switch (eventType)
+ {
+ case Event.NODE_REMOVED:
+ {
+ String nodeId = nodePathCache.remove(itemPath);
+ if (nodeId != null)
+ {
+ nodeIdCache.remove(nodeId);
+ }
+ String parentPath = parentPath(parentPath(itemPath));
+ String id = nodePathCache.remove(parentPath);
+ if (id != null)
+ {
+ nodeIdCache.remove(id);
+ }
+ String a = parentPath(parentPath(parentPath(itemPath)));
+ SiteKey sk = navigationPathCache.remove(a);
+ if (sk != null)
+ {
+ navigationKeyCache.remove(sk);
+ }
+ break;
+ }
+ case Event.NODE_ADDED:
+ {
+ String parentPath = parentPath(parentPath(itemPath));
+ String id = nodePathCache.remove(parentPath);
+ if (id != null)
+ {
+ nodeIdCache.remove(id);
+ }
+ String a = parentPath(parentPath(parentPath(itemPath)));
+ SiteKey sk = navigationPathCache.remove(a);
+ if (sk != null)
+ {
+ navigationKeyCache.remove(sk);
+ }
+ break;
+ }
+ }
+ }
+ }
+ });
+
+ //
+ invalidationManager.register(NAVIGATION, Event.PROPERTY_ADDED +
Event.PROPERTY_CHANGED + Event.PROPERTY_REMOVED, new Invalidator()
+ {
+ @Override
+ void invalidate(int eventType, String nodeType, String itemPath)
+ {
+ // Look for node
+ String nodePath = parentPath(itemPath);
+ String id = nodePathCache.remove(nodePath);
+ if (id != null)
+ {
+ nodeIdCache.remove(id);
+ }
+ }
+ });
+
+ //
+ invalidationManager.register(ATTRIBUTES, Event.NODE_ADDED + Event.NODE_REMOVED, new
Invalidator()
+ {
+ @Override
+ void invalidate(int eventType, String nodeType, String itemPath)
+ {
+ String nodePath = parentPath(parentPath(itemPath));
+
+ //
+ String id = nodePathCache.remove(nodePath);
+ if (id != null)
+ {
+ nodeIdCache.remove(id);
+ }
+
+ //
+ String navPath = parentPath(parentPath(parentPath(nodePath)));
+ SiteKey navigationKey = navigationPathCache.remove(navPath);
+ if (navigationKey != null)
+ {
+ navigationKeyCache.remove(navigationKey);
+ }
+ }
+ });
+
+ //
+ this.bridgeSession = session;
+ }
+
+ private String parentPath(String path)
+ {
+ int index = path.lastIndexOf('/');
+ return path.substring(0, index);
+ }
+
+ public void stop()
+ {
+ if (bridgeSession != null)
+ {
+ Session session = bridgeSession;
+ bridgeSession = null;
+
+ // Unregister
+ try
+ {
+ ObservationManager om = session.getWorkspace().getObservationManager();
+ EventListenerIterator i = om.getRegisteredEventListeners();
+ while (i.hasNext())
+ {
+ EventListener listener = i.nextEventListener();
+ om.removeEventListener(listener);
+ }
+ }
+ catch (RepositoryException e)
+ {
+ e.printStackTrace();
+ }
+
+ //
+ session.logout();
+ }
+ }
+
+ private NodeData getNodeData(POMSession session, String nodeId)
+ {
+ NodeData data;
+ if (session.isModified())
+ {
+ org.gatein.mop.api.workspace.Navigation navigation =
session.findObjectById(ObjectType.NAVIGATION, nodeId);
+ if (navigation != null)
+ {
+ data = new NodeData(navigation);
+ }
+ else
+ {
+ data = null;
+ }
+ }
+ else
+ {
+ data = nodeIdCache.get(nodeId);
+ if (data == null)
+ {
+ org.gatein.mop.api.workspace.Navigation navigation =
session.findObjectById(ObjectType.NAVIGATION, nodeId);
+ if (navigation != null)
+ {
+ data = new NodeData(navigation);
+ nodeIdCache.put(nodeId, data);
+ nodePathCache.put(session.pathOf(navigation), nodeId);
+ }
+ }
+ }
+ return data;
+ }
+
+ public Navigation loadNavigation(SiteKey key)
+ {
+ if (key == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //
+ Navigation data;
+ POMSession session = manager.getSession();
+ if (session.isModified())
+ {
+ data = findNavigation(session, key);
+ }
+ else
+ {
+ data = navigationKeyCache.get(key);
+ if (data == null)
+ {
+ data = findNavigation(session, key);
+ if (data != null)
+ {
+ navigationKeyCache.put(key, data);
+ navigationPathCache.put(data.path, key);
+ }
+ }
+ }
+
+ //
+ return data;
+ }
+
+ private Navigation findNavigation(POMSession session, SiteKey key)
+ {
+ Workspace workspace = session.getWorkspace();
+ ObjectType<Site> objectType = a.get(key.getType());
+ Site site = workspace.getSite(objectType, key.getName());
+ if (site != null)
+ {
+ org.gatein.mop.api.workspace.Navigation root = site.getRootNavigation();
+ org.gatein.mop.api.workspace.Navigation rootNode =
root.getChild("default");
+ String path = session.pathOf(site);
+ if (rootNode != null)
+ {
+
+ Integer priority =
rootNode.getAttributes().getValue(MappedAttributes.PRIORITY, 1);
+ String rootId = rootNode.getObjectId();
+ return new Navigation(path, key, new NavigationState(priority), rootId);
+ }
+ else
+ {
+ return new Navigation(path, key, null, null);
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public boolean saveNavigation(SiteKey key, NavigationState state) throws
NavigationServiceException
+ {
+ if (key == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //
+ POMSession session = manager.getSession();
+ ObjectType<Site> objectType = a.get(key.getType());
+ Workspace workspace = session.getWorkspace();
+ Site site = workspace.getSite(objectType, key.getName());
+ if (site == null)
+ {
+ throw new NavigationServiceException("The site " + key + " does
not exist");
+ }
+
+ //
+ if (state != null)
+ {
+ org.gatein.mop.api.workspace.Navigation root = site.getRootNavigation();
+ org.gatein.mop.api.workspace.Navigation rootNode =
root.getChild("default");
+ boolean created = rootNode == null;
+ if (created)
+ {
+ rootNode = root.addChild("default");
+ }
+ rootNode.getAttributes().setValue(MappedAttributes.PRIORITY,
state.getPriority());
+ return created;
+ }
+ else
+ {
+ org.gatein.mop.api.workspace.Navigation root = site.getRootNavigation();
+ org.gatein.mop.api.workspace.Navigation rootNode =
root.getChild("default");
+ boolean destroyed = rootNode != null;
+ if (destroyed)
+ {
+ rootNode.destroy();
+ }
+ return destroyed;
+ }
+ }
+
+ public <N> N loadNode(NodeModel<N> model, Navigation navigation, Scope
scope)
+ {
+ if (model == null)
+ {
+ throw new NullPointerException();
+ }
+ if (navigation == null)
+ {
+ throw new NullPointerException();
+ }
+ if (scope == null)
+ {
+ throw new NullPointerException();
+ }
+ String nodeId = navigation.rootId;
+ if (navigation.rootId != null)
+ {
+ POMSession session = manager.getSession();
+ Scope.Visitor visitor = scope.get();
+ NodeData data = getNodeData(session, nodeId);
+ if (data != null)
+ {
+ NodeContext<N> context = load(model, session, data, visitor, 0);
+ return context.node;
+ }
+ else
+ {
+ return null;
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ private <N> NodeContext<N> load(
+ NodeModel<N> model,
+ POMSession session,
+ NodeData data,
+ Scope.Visitor visitor,
+ int depth)
+ {
+ VisitMode visitMode = visitor.visit(depth, data.id, data.name, data.state);
+
+ //
+ NodeContext<N> context;
+ if (visitMode == VisitMode.ALL_CHILDREN)
+ {
+ ArrayList<NodeContext<N>> children = new
ArrayList<NodeContext<N>>(data.children.size());
+ for (String childId : data.children)
+ {
+ NodeData childData = getNodeData(session, childId);
+ if (childData != null)
+ {
+ NodeContext<N> childContext = load(model, session, childData,
visitor, depth + 1);
+ children.add(childContext);
+ }
+ else
+ {
+ throw new UnsupportedOperationException("Handle me
gracefully");
+ }
+ }
+
+ //
+ context = new NodeContext<N>(model, data);
+ context.setContexts(children);
+ }
+ else if (visitMode == VisitMode.NO_CHILDREN)
+ {
+ context = new NodeContext<N>(model, data);
+ }
+ else
+ {
+ context = new NodeContext<N>(model, data);
+ }
+
+ //
+ return context;
+ }
+
+ public <N> N loadNode(NodeModel<N> model, N node, Scope scope)
+ {
+ POMSession session = manager.getSession();
+ NodeContext<N> context = model.getContext(node);
+ Scope.Visitor visitor = scope.get();
+ return load(model, session, context, visitor, 0);
+ }
+
+ private <N> N load(NodeModel<N> model, POMSession session,
NodeContext<N> context, Scope.Visitor visitor, int depth)
+ {
+ String nodeId = context.getId();
+ NodeData data = getNodeData(session, nodeId);
+
+ //
+ if (data != null)
+ {
+ context.data = data;
+ visit(model, session, context, visitor, depth);
+ return context.node;
+ }
+
+ return null;
+ }
+
+ private <N> void visit(
+ NodeModel<N> model,
+ POMSession session,
+ NodeContext<N> context,
+ Scope.Visitor visitor,
+ int depth)
+ {
+ NodeData data = context.data;
+
+ //
+ VisitMode visitMode;
+ if (context.hasTrees())
+ {
+ visitMode = VisitMode.ALL_CHILDREN;
+ }
+ else
+ {
+ visitMode = visitor.visit(depth, data.id, data.name, data.state);
+ }
+
+ //
+ if (visitMode == VisitMode.ALL_CHILDREN)
+ {
+ Map<String, NodeContext<N>> previous = Collections.emptyMap();
+ if (context.hasTrees())
+ {
+ previous = new HashMap<String, NodeContext<N>>();
+ for (NodeContext<N> a : context.getContexts())
+ {
+ if (a.data != null)
+ {
+ previous.put(a.getId(), a);
+ }
+ }
+ context.setContexts(null);
+ }
+
+ //
+ ArrayList<NodeContext<N>> children = new
ArrayList<NodeContext<N>>(data.children.size());
+ for (String childId : data.children)
+ {
+ NodeData childData = getNodeData(session, childId);
+ if (childData != null)
+ {
+ NodeContext<N> childContext = previous.get(childId);
+ if (childContext != null)
+ {
+ childContext.data = childData;
+ visit(model, session, childContext, visitor, depth + 1);
+ }
+ else
+ {
+ childContext = load(model, session, childData, visitor, depth + 1);
+ }
+ children.add(childContext);
+ }
+ else
+ {
+ throw new UnsupportedOperationException("Handle me
gracefully");
+ }
+ }
+
+ //
+ context.setContexts(children);
+ }
+ else if (visitMode == VisitMode.NO_CHILDREN)
+ {
+ if (context.hasTrees())
+ {
+ context.setContexts(null);
+ }
+ }
+ else
+ {
+ throw new AssertionError();
+ }
+ }
+
+
+ public <N> void refresh(NodeModel<N> model, N node, Scope scope) throws
NullPointerException, NavigationServiceException
+ {
+ POMSession session = manager.getSession();
+ NodeContext<N> context = model.getContext(node);
+ refresh(model, session, context, scope.get(), 0);
+ }
+
+ private <N> void refresh(
+ NodeModel<N> model,
+ POMSession session,
+ NodeContext<N> context,
+ Scope.Visitor visitor,
+ int depth)
+ {
+
+ String id = context.data.getId();
+
+ NodeData from = context.data;
+
+ NodeData to = getNodeData(session, id);
+
+ if (to == null)
+ {
+ throw new UnsupportedOperationException("Handle me gracefully");
+ }
+
+ //
+ if (context.hasTrees())
+ {
+ Iterable<NodeContext<N>> children = context.getContexts();
+
+ // Remove what we need
+ for (Iterator<NodeContext<N>> it =
children.iterator();it.hasNext();)
+ {
+ NodeContext<N> child = it.next();
+ if (child.data == null || !to.children.contains(child.data.getId()))
+ {
+ it.remove();
+ }
+ else
+ {
+ // We do nothing for now
+ }
+ }
+ }
+ else
+ {
+ throw new UnsupportedOperationException("Handle me gracefully");
+ }
+
+ // Update data now
+ context.data = to;
+ }
+
+ public <N> void saveNode(NodeModel<N> model, N node)
+ {
+ POMSession session = manager.getSession();
+ NodeContext<N> context = model.getContext(node);
+
+ //
+ SaveContext<N> save = new SaveContext<N>(context);
+
+ //
+ save.phase0(session);
+
+ //
+ save.phase1(session);
+
+ //
+ save.phase2(session);
+
+ //
+ save.phase3(session);
+
+ //
+ save.phase4(session);
+
+ //
+ save.phase5(session);
+
+ //
+ save.phase6(session);
+ }
+
+ private static class SaveContext<N>
+ {
+
+ /** . */
+ private final NodeContext<N> context;
+
+ /** . */
+ private final List<SaveContext<N>> children;
+
+ /** The list of actual children ids, maintained during the phases. */
+ private List<String> childrenIds;
+
+ /** . */
+ private SaveContext<N> parent;
+
+ /** The related navigation object. */
+ private org.gatein.mop.api.workspace.Navigation navigation;
+
+ private SaveContext(NodeContext<N> context)
+ {
+ List<SaveContext<N>> children;
+ if (context.hasTrees())
+ {
+ children = new ArrayList<SaveContext<N>>();
+ for (NodeContext<N> childCtx : context.getContexts())
+ {
+ SaveContext<N> child = new SaveContext<N>(childCtx);
+ children.add(child);
+ child.parent = this;
+ }
+ }
+ else
+ {
+ children = Collections.emptyList();
+ }
+
+ //
+ ArrayList<String> bilto;
+ if (context.data != null)
+ {
+ bilto = new ArrayList<String>(context.data.children);
+ }
+ else
+ {
+ bilto = new ArrayList<String>();
+ }
+
+ //
+ this.context = context;
+ this.children = children;
+ this.childrenIds = bilto;
+ this.navigation = null;
+ }
+
+ static abstract class Finder<N>
+ {
+
+ final SaveContext<N> any(SaveContext<N> context)
+ {
+ SaveContext<N> root = context;
+ while (root.parent != null)
+ {
+ root = root.parent;
+ }
+ return descendants(root);
+ }
+
+ final SaveContext<N> descendants(SaveContext<N> context)
+ {
+ SaveContext<N> found = null;
+ if (accept(context))
+ {
+ found = context;
+ }
+ else
+ {
+ int size = context.children.size();
+ for (int i = 0;i < size;i++)
+ {
+ found = descendants(context.children.get(i));
+ if (found != null)
+ {
+ break;
+ }
+ }
+ }
+ return found;
+ }
+
+ abstract boolean accept(SaveContext<N> context);
+ }
+
+ // Remove orphans
+ void phase0(POMSession session)
+ {
+ if (context.hasTrees())
+ {
+ if (context.data != null)
+ {
+ for (final String childId : context.data.children)
+ {
+ // Is it still here ?
+ boolean found = false;
+ for (NodeContext<N> childContext : context.getContexts())
+ {
+ if (childContext.data != null &&
childContext.data.id.equals(childId))
+ {
+ found = true;
+ }
+ }
+
+ //
+ if (!found)
+ {
+ Finder<N> finder = new Finder<N>()
+ {
+ boolean accept(SaveContext<N> context)
+ {
+ return context.context.data != null &&
context.context.data.getId().equals(childId);
+ }
+ };
+ if (finder.any(this) == null)
+ {
+ org.gatein.mop.api.workspace.Navigation navigation =
session.findObjectById(ObjectType.NAVIGATION, childId);
+ navigation.destroy();
+ }
+ else
+ {
+ // It's a move operation
+ }
+ childrenIds.remove(childId);
+ }
+ }
+ }
+ }
+
+ //
+ for (SaveContext<N> child : children)
+ {
+ child.phase0(session);
+ }
+ }
+
+ // Create new nodes and associates with navigation object
+ void phase1(POMSession session)
+ {
+ if (context.data == null)
+ {
+ throw new IllegalArgumentException();
+ }
+ else
+ {
+ navigation = session.findObjectById(ObjectType.NAVIGATION, context.getId());
+
+ //
+ for (SaveContext<N> child : children)
+ {
+ if (child.context.data == null)
+ {
+ org.gatein.mop.api.workspace.Navigation added =
navigation.addChild(child.context.getName());
+ child.context.data = new NodeData(added);
+ childrenIds.add(added.getObjectId());
+ }
+ }
+ }
+
+ //
+ for (SaveContext<N> child : children)
+ {
+ child.phase1(session);
+ }
+ }
+
+ // Rename nodes
+ void phase2(POMSession session)
+ {
+ if (!context.data.name.equals(context.getName()))
+ {
+ navigation.setName(context.getName());
+ }
+
+ //
+ for (SaveContext<N> child : children)
+ {
+ child.phase2(session);
+ }
+ }
+
+ // Update state
+ void phase3(POMSession session)
+ {
+ NodeState state = context.state;
+ if (state != null)
+ {
+ Workspace workspace = navigation.getSite().getWorkspace();
+ String reference = state.getPageRef();
+ if (reference != null)
+ {
+ String[] pageChunks = split("::", reference);
+ ObjectType<? extends Site> siteType =
Mapper.parseSiteType(pageChunks[0]);
+ Site site = workspace.getSite(siteType, pageChunks[1]);
+ org.gatein.mop.api.workspace.Page target =
site.getRootPage().getChild("pages").getChild(pageChunks[2]);
+ PageLink link = navigation.linkTo(ObjectType.PAGE_LINK);
+ link.setPage(target);
+ }
+ else
+ {
+ PageLink link = navigation.linkTo(ObjectType.PAGE_LINK);
+ link.setPage(null);
+ }
+
+ //
+ Described described = navigation.adapt(Described.class);
+ described.setName(state.getLabel());
+
+ //
+ Visible visible = navigation.adapt(Visible.class);
+ visible.setVisibility(state.getVisibility());
+
+ //
+ visible.setStartPublicationDate(state.getStartPublicationDate());
+ visible.setEndPublicationDate(state.getEndPublicationDate());
+
+ //
+ Attributes attrs = navigation.getAttributes();
+ attrs.setValue(MappedAttributes.URI, state.getURI());
+ attrs.setValue(MappedAttributes.ICON, state.getIcon());
+ }
+
+ //
+ for (SaveContext<N> child : children)
+ {
+ child.phase3(session);
+ }
+ }
+
+ // Move nodes
+ void phase4(POMSession session)
+ {
+
+ if (context.hasTrees())
+ {
+ for (NodeContext<N> childCtx : context.getContexts())
+ {
+ final String childId = childCtx.data.id;
+ if (!context.data.children.contains(childId))
+ {
+ if (!childrenIds.contains(childId))
+ {
+ Finder<N> finder = new Finder<N>()
+ {
+ boolean accept(SaveContext<N> context)
+ {
+ return context.context.data.getId().equals(childId);
+ }
+ };
+ SaveContext<N> movedCtx = finder.any(this);
+ org.gatein.mop.api.workspace.Navigation moved =
movedCtx.navigation;
+ navigation.getChildren().add(moved);
+ childrenIds.add(childId);
+ }
+ }
+ }
+ }
+
+ //
+ for (SaveContext<N> child : children)
+ {
+ child.phase4(session);
+ }
+ }
+
+ // Reorder nodes
+ void phase5(POMSession session)
+ {
+ if (context.hasTrees())
+ {
+ final ArrayList<String> orders = new ArrayList<String>();
+ for (NodeContext<N> foo : context.getContexts())
+ {
+ orders.add(foo.data.id);
+ }
+
+ //
+ if (!childrenIds.equals(orders))
+ {
+ // Now sort children according to the order provided by the container
+ // need to replace that with Collections.sort once the set(int index, E
element) is implemented in Chromattic lists
+ org.gatein.mop.api.workspace.Navigation[] a =
navigation.getChildren().toArray(new
org.gatein.mop.api.workspace.Navigation[navigation.getChildren().size()]);
+ Arrays.sort(a, new
Comparator<org.gatein.mop.api.workspace.Navigation>()
+ {
+ public int compare(org.gatein.mop.api.workspace.Navigation o1,
org.gatein.mop.api.workspace.Navigation o2)
+ {
+ int i1 = orders.indexOf(o1.getObjectId());
+ int i2 = orders.indexOf(o2.getObjectId());
+ return i1 - i2;
+ }
+ });
+ for (int j = 0; j < a.length; j++)
+ {
+ navigation.getChildren().add(j, a[j]);
+ }
+ }
+ }
+
+ //
+ for (SaveContext<N> child : children)
+ {
+ child.phase5(session);
+ }
+ }
+
+ // Update model
+ void phase6(POMSession session)
+ {
+ Set<String> childMap;
+ if (context.hasTrees())
+ {
+ // todo : I think we have a bug here :-)
+ childMap = new LinkedHashSet<String>();
+ }
+ else
+ {
+ childMap = context.data.children;
+ }
+
+ //
+ String id = context.data.id;
+ String name = context.getName();
+ NodeState state = context.getState();
+
+ //
+ context.data = new NodeData(id, name, state, childMap);
+
+ //
+ for (SaveContext<N> child : children)
+ {
+ child.phase6(session);
+ }
+ }
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationServiceWrapper.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationServiceWrapper.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationServiceWrapper.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.container.component.RequestLifeCycle;
+import org.exoplatform.portal.mop.SiteKey;
+import org.exoplatform.portal.pom.config.POMSessionManager;
+import org.exoplatform.services.organization.OrganizationService;
+import org.picocontainer.Startable;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class NavigationServiceWrapper implements Startable, NavigationService
+{
+
+ /** . */
+ private final NavigationServiceImpl service;
+
+ public NavigationServiceWrapper(POMSessionManager manager, OrganizationService
organization)
+ {
+ this.service = new NavigationServiceImpl(manager);
+ }
+
+ public void start()
+ {
+ RequestLifeCycle.begin(PortalContainer.getInstance());
+ try
+ {
+ service.start();
+ }
+ catch (Exception e)
+ {
+ service.log.error("Could not start navigation service", e);
+ }
+ finally
+ {
+ RequestLifeCycle.end();
+ }
+ }
+
+ public void stop()
+ {
+ RequestLifeCycle.begin(PortalContainer.getInstance());
+ try
+ {
+ service.stop();
+ }
+ finally
+ {
+ RequestLifeCycle.end();
+ }
+ }
+
+ public Navigation loadNavigation(SiteKey key)
+ {
+ return service.loadNavigation(key);
+ }
+
+ public boolean saveNavigation(SiteKey key, NavigationState state) throws
NavigationServiceException
+ {
+ return service.saveNavigation(key, state);
+ }
+
+ public <N> N loadNode(NodeModel<N> model, Navigation navigation, Scope
scope)
+ {
+ return service.loadNode(model, navigation, scope);
+ }
+
+ public <N> N loadNode(NodeModel<N> model, N node, Scope scope)
+ {
+ return service.loadNode(model, node, scope);
+ }
+
+ public <N> void refresh(NodeModel<N> model, N node, Scope scope) throws
NullPointerException, NavigationServiceException
+ {
+ service.refresh(model, node, scope);
+ }
+
+ public <N> void saveNode(NodeModel<N> model, N node)
+ {
+ service.saveNode(model, node);
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationState.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationState.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NavigationState.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class NavigationState
+{
+
+ /** . */
+ private final Integer priority;
+
+ public NavigationState(Integer priority)
+ {
+ this.priority = priority;
+ }
+
+ /**
+ * Returns the navigation priority.
+ *
+ * @return the navigation priority
+ */
+ public Integer getPriority()
+ {
+ return priority;
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeContext.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeContext.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeContext.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,271 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+import java.util.AbstractCollection;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Iterator;
+
+/**
+ * The context of a node.
+ */
+public final class NodeContext<N> extends ListTree<NodeContext<N>, N>
+{
+
+ /** . */
+ final N node;
+
+ /** node data representing persistent state. */
+ NodeData data;
+
+ /** The new state if any. */
+ NodeState state;
+
+ NodeContext(NodeModel<N> model, NodeData data)
+ {
+ super(data.getName());
+
+ //
+ this.node = model.create(this);
+ this.data = data;
+ this.state = data.getState();
+ }
+
+ NodeContext(NodeModel<N> model, String name, NodeState state)
+ {
+ super(name);
+
+ //
+ this.node = model.create(this);
+ this.data = null;
+ this.state = state;
+ }
+
+ /**
+ * Applies a filter recursively.
+ *
+ * @param filter the filter to apply
+ */
+ public void filter(NodeFilter filter)
+ {
+ filter(0, filter);
+ }
+
+ private void filter(int depth, NodeFilter filter)
+ {
+ boolean accept = filter.accept(depth, getId(), getName(), state);
+ setHidden(!accept);
+ if (hasTrees())
+ {
+ for (NodeContext<N> node : getTrees())
+ {
+ node.filter(depth + 1, filter);
+ }
+ }
+ }
+
+ public N getElement()
+ {
+ return node;
+ }
+
+ public String getId()
+ {
+ return data != null ? data.getId() : null;
+ }
+
+ public void setName(String name)
+ {
+ NodeContext<N> parent = getParent();
+ if (parent == null)
+ {
+ throw new IllegalStateException("Cannot rename a node when its parent is
not visible");
+ }
+ else
+ {
+ parent.rename(getName(), name);
+ }
+ }
+
+ /**
+ * Returns the total number of nodes.
+ *
+ * @return the total number of nodes
+ */
+ public int getNodeSize()
+ {
+ if (hasTrees())
+ {
+ return getSize();
+ }
+ else
+ {
+ return data.children.size();
+ }
+ }
+
+ /**
+ * Returns the node count defined by:
+ * <ul>
+ * <li>when the node has a children relationship, the number of non hidden
nodes</li>
+ * <li>when the node has not a children relationship, the total number of
nodes</li>
+ * </ul>
+ *
+ * @return the node count
+ */
+ public int getNodeCount()
+ {
+ if (hasTrees())
+ {
+ return getCount();
+ }
+ else
+ {
+ return data.children.size();
+ }
+ }
+
+ public NodeState getState()
+ {
+ if (state != null)
+ {
+ return state;
+ }
+ else if (data != null)
+ {
+ return data.getState();
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public void setState(NodeState state)
+ {
+ this.state = state;
+ }
+
+ public N getParentNode()
+ {
+ NodeContext<N> parent = getParent();
+ return parent != null ? parent.node : null;
+ }
+
+ public N getNode(String name) throws NullPointerException
+ {
+ NodeContext<N> child = get(name);
+ return child != null ? child.node: null;
+ }
+
+ public N getNode(int index)
+ {
+ NodeContext<N> child = get(index);
+ return child != null ? child.node: null;
+ }
+
+ /** . */
+ private Collection<N> nodes;
+
+ public Collection<N> getNodes()
+ {
+ if (hasTrees())
+ {
+ if (nodes == null)
+ {
+ nodes = new AbstractCollection<N>()
+ {
+ public Iterator<N> iterator()
+ {
+ return NodeContext.this.iterator();
+ }
+ public int size()
+ {
+ return getNodeCount();
+ }
+ };
+ }
+ return nodes;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public N addNode(NodeModel<N> model, String name)
+ {
+ if (model == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //
+ NodeContext<N> nodeContext = new NodeContext<N>(model, name, new
NodeState.Builder().capture());
+ nodeContext.setContexts(Collections.<NodeContext<N>>emptyList());
+ insert(null, nodeContext);
+ return nodeContext.node;
+ }
+
+ public void addNode(NodeModel<N> model, Integer index, N child)
+ {
+ if (model == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //
+ NodeContext<N> nodeContext = model.getContext(child);
+ insert(index, nodeContext);
+ }
+
+ public boolean removeNode(NodeModel<N> model, String name)
+ {
+ if (model == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //
+ return remove(name) != null;
+ }
+
+ NodeContext<N> getRoot()
+ {
+ NodeContext<N> root = this;
+ while (root.getParent() != null)
+ {
+ root = root.getParent();
+ }
+ return root;
+ }
+
+ Iterable<NodeContext<N>> getContexts()
+ {
+ return getTrees();
+ }
+
+ void setContexts(Iterable<NodeContext<N>> contexts)
+ {
+ setTrees(contexts);
+ }
+
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeData.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeData.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeData.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,148 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+import org.exoplatform.portal.mop.Described;
+import org.exoplatform.portal.mop.Visibility;
+import org.exoplatform.portal.mop.Visible;
+import org.exoplatform.portal.pom.data.MappedAttributes;
+import org.exoplatform.portal.pom.data.Mapper;
+import org.gatein.mop.api.Attributes;
+import org.gatein.mop.api.workspace.Navigation;
+import org.gatein.mop.api.workspace.ObjectType;
+import org.gatein.mop.api.workspace.Site;
+import org.gatein.mop.api.workspace.link.Link;
+import org.gatein.mop.api.workspace.link.PageLink;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.Date;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.Set;
+
+/**
+ * An immutable node data class.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+class NodeData implements Serializable
+{
+
+ /** . */
+ final String id;
+
+ /** . */
+ final String name;
+
+ /** . */
+ final NodeState state;
+
+ /** . */
+ final Set<String> children;
+
+ NodeData(String id, String name, NodeState state, Set<String> children)
+ {
+ this.id = id;
+ this.name = name;
+ this.state = state;
+ this.children = Collections.unmodifiableSet(children);
+ }
+
+ NodeData(Navigation nav)
+ {
+ LinkedHashSet<String> children = new LinkedHashSet<String>();
+ for (Navigation child : nav.getChildren())
+ {
+ children.add(child.getObjectId());
+ }
+
+ //
+ String label = null;
+ if (nav.isAdapted(Described.class))
+ {
+ Described described = nav.adapt(Described.class);
+ label = described.getName();
+ }
+
+ //
+ Visibility visibility = Visibility.DISPLAYED;
+ Date startPublicationDate = null;
+ Date endPublicationDate = null;
+ if (nav.isAdapted(Visible.class))
+ {
+ Visible visible = nav.adapt(Visible.class);
+ visibility = visible.getVisibility();
+ startPublicationDate = visible.getStartPublicationDate();
+ endPublicationDate = visible.getEndPublicationDate();
+ }
+
+ //
+ String pageRef = null;
+ Link link = nav.getLink();
+ if (link instanceof PageLink)
+ {
+ PageLink pageLink = (PageLink)link;
+ org.gatein.mop.api.workspace.Page target = pageLink.getPage();
+ if (target != null)
+ {
+ Site site = target.getSite();
+ ObjectType<? extends Site> siteType = site.getObjectType();
+ pageRef = Mapper.getOwnerType(siteType) + "::" + site.getName() +
"::" + target.getName();
+ }
+ }
+
+ //
+ Attributes attrs = nav.getAttributes();
+
+ //
+ NodeState state = new NodeState(
+ attrs.getValue(MappedAttributes.URI),
+ label,
+ attrs.getValue(MappedAttributes.ICON),
+ startPublicationDate != null ? startPublicationDate.getTime() : -1,
+ endPublicationDate != null ? endPublicationDate.getTime() : -1,
+ visibility,
+ pageRef
+ );
+
+ //
+ this.id = nav.getObjectId();
+ this.name = nav.getName();
+ this.state = state;
+ this.children = Collections.unmodifiableSet(children);
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public NodeState getState()
+ {
+ return state;
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeFilter.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeFilter.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeFilter.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+/**
+ * A filter for nodes.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public interface NodeFilter
+{
+
+ boolean accept(int depth, String id, String name, NodeState state);
+
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeModel.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeModel.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeModel.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public interface NodeModel<N>
+{
+
+ /**
+ * Returns the context of a node.
+ *
+ * @param node the node
+ * @return the node context
+ */
+ NodeContext<N> getContext(N node);
+
+ /**
+ * Create a node wrapping a context.
+ *
+ * @param context the node context
+ * @return the node instance
+ */
+ N create(NodeContext<N> context);
+
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeState.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeState.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/NodeState.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,265 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+import org.exoplatform.portal.mop.Visibility;
+
+import java.util.Date;
+
+/**
+ * The state of a node.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class NodeState
+{
+
+ public static class Builder
+ {
+
+ /** . */
+ private String uri;
+
+ /** . */
+ private String label;
+
+ /** . */
+ private String icon;
+
+ /** . */
+ private long startPublicationTime;
+
+ /** . */
+ private long endPublicationTime;
+
+ /** . */
+ private Visibility visibility;
+
+ /** . */
+ private String pageRef;
+
+ public Builder()
+ {
+ this.uri = null;
+ this.icon = null;
+ this.label = null;
+ this.startPublicationTime = -1;
+ this.endPublicationTime = -1;
+ this.visibility = null;
+ this.pageRef = null;
+ }
+
+ /**
+ * Creates a builder from a specified state.
+ *
+ * @param state the state to copy
+ * @throws NullPointerException if the stateis null
+ */
+ public Builder(NodeState state) throws NullPointerException
+ {
+ if (state == null)
+ {
+ throw new NullPointerException();
+ }
+ this.uri = state.uri;
+ this.label = state.label;
+ this.icon = state.icon;
+ this.startPublicationTime = state.startPublicationTime;
+ this.endPublicationTime = state.endPublicationTime;
+ this.visibility = state.visibility;
+ this.pageRef = state.pageRef;
+ }
+
+ public String getURI()
+ {
+ return uri;
+ }
+
+ public Builder setURI(String uri)
+ {
+ this.uri = uri;
+ return this;
+ }
+
+ public String getLabel()
+ {
+ return label;
+ }
+
+ public Builder setLabel(String label)
+ {
+ this.label = label;
+ return this;
+ }
+
+ public String getIcon()
+ {
+ return icon;
+ }
+
+ public Builder setIcon(String icon)
+ {
+ this.icon = icon;
+ return this;
+ }
+
+ public long getStartPublicationTime()
+ {
+ return startPublicationTime;
+ }
+
+ public Builder setStartPublicationTime(long startPublicationTime)
+ {
+ this.startPublicationTime = startPublicationTime;
+ return this;
+ }
+
+ public long getEndPublicationTime()
+ {
+ return endPublicationTime;
+ }
+
+ public Builder setEndPublicationTime(long endPublicationTime)
+ {
+ this.endPublicationTime = endPublicationTime;
+ return this;
+ }
+
+ public Visibility getVisibility()
+ {
+ return visibility;
+ }
+
+ public Builder setVisibility(Visibility visibility)
+ {
+ this.visibility = visibility;
+ return this;
+ }
+
+ public String getPageRef()
+ {
+ return pageRef;
+ }
+
+ public Builder setPageRef(String pageRef)
+ {
+ this.pageRef = pageRef;
+ return this;
+ }
+
+ public NodeState capture()
+ {
+ return new NodeState(
+ uri,
+ label,
+ icon,
+ startPublicationTime,
+ endPublicationTime,
+ visibility,
+ pageRef
+ );
+ }
+ }
+
+ /** . */
+ private final String uri;
+
+ /** . */
+ private final String label;
+
+ /** . */
+ private final String icon;
+
+ /** . */
+ private final long startPublicationTime;
+
+ /** . */
+ private final long endPublicationTime;
+
+ /** . */
+ private final Visibility visibility;
+
+ /** . */
+ private final String pageRef;
+
+ public NodeState(
+ String uri,
+ String label,
+ String icon,
+ long startPublicationTime,
+ long endPublicationTime,
+ Visibility visibility,
+ String pageRef)
+ {
+ this.uri = uri;
+ this.label = label;
+ this.icon = icon;
+ this.startPublicationTime = startPublicationTime;
+ this.endPublicationTime = endPublicationTime;
+ this.visibility = visibility;
+ this.pageRef = pageRef;
+ }
+
+ public String getURI()
+ {
+ return uri;
+ }
+
+ public String getLabel()
+ {
+ return label;
+ }
+
+ public String getIcon()
+ {
+ return icon;
+ }
+
+ public long getStartPublicationTime()
+ {
+ return startPublicationTime;
+ }
+
+ Date getStartPublicationDate()
+ {
+ return startPublicationTime != -1 ? new Date(startPublicationTime) : null;
+ }
+
+ public long getEndPublicationTime()
+ {
+ return endPublicationTime;
+ }
+
+ Date getEndPublicationDate()
+ {
+ return endPublicationTime != -1 ? new Date(endPublicationTime) : null;
+ }
+
+ public Visibility getVisibility()
+ {
+ return visibility;
+ }
+
+ public String getPageRef()
+ {
+ return pageRef;
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/Scope.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/Scope.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/Scope.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+import org.exoplatform.portal.mop.Visibility;
+
+/**
+ * <p>The scope describes a set of nodes, the scope implementation should be
stateless and should be shared
+ * between many threads.</p>
+ *
+ * <p>A scope is responsible for provided a {@link Visitor} object that is used to
determine which node should
+ * be loaded when a node loading operation occurs. Visitors are not thread safe, as a
consequence
+ * the {@link #get()} operation should create a new visitor instance on each call, unless
the visitor itself is stateless
+ * by nature.</p>
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public interface Scope
+{
+
+ Scope SINGLE = new GenericScope(0);
+
+ Scope CHILDREN = new GenericScope(1);
+
+ Scope GRANDCHILDREN = new GenericScope(2);
+
+ Scope ALL = new GenericScope(-1);
+
+ Visitor get();
+
+ /**
+ * A scope visitor responsible for determining the loading of a node.
+ */
+ public interface Visitor
+ {
+ /**
+ * Returns the visit mode for the specified node.
+ *
+ * @param depth the relative depth to the root of the loading
+ * @param id the node persistent id
+ * @param name the node name
+ * @param state the node state
+ * @return the visit mode
+ */
+ VisitMode visit(int depth, String id, String name, NodeState state);
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/VisitMode.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/VisitMode.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/navigation/VisitMode.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+/**
+ * Describes how a node should be loaded by a loading operation.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class VisitMode
+{
+
+ /**
+ * Include node but its children should be left appart.
+ */
+ public static final VisitMode NO_CHILDREN = new VisitMode("NO_CHILDREN");
+
+ /**
+ * Include node and its children.
+ */
+ public static final VisitMode ALL_CHILDREN = new VisitMode("ALL_CHILDREN");
+
+ /** . */
+ private final String name;
+
+ private VisitMode(String name)
+ {
+ this.name = name;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "VisitMode[" + name + "]";
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/NavigationPath.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/NavigationPath.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/NavigationPath.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.user;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class NavigationPath
+{
+
+ /** . */
+ private final UserNavigation navigation;
+
+ /** . */
+ private final UserNode target;
+
+ public NavigationPath(UserNavigation navigation, UserNode target)
+ {
+ this.navigation = navigation;
+ this.target = target;
+ }
+
+ public UserNavigation getNavigation()
+ {
+ return navigation;
+ }
+
+ public UserNode getTarget()
+ {
+ return target;
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNavigation.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNavigation.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNavigation.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.user;
+
+import org.exoplatform.portal.mop.SiteKey;
+import org.exoplatform.portal.mop.navigation.Navigation;
+import org.exoplatform.portal.mop.navigation.NavigationState;
+import org.exoplatform.portal.mop.navigation.NodeContext;
+import org.exoplatform.portal.mop.navigation.NodeModel;
+import org.gatein.common.util.EmptyResourceBundle;
+
+import java.util.ResourceBundle;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class UserNavigation
+{
+
+ /** . */
+ final UserPortalImpl portal;
+
+ /** . */
+ final Navigation navigation;
+
+ /** . */
+ private final boolean modifiable;
+
+ /** . */
+ ResourceBundle bundle;
+
+ /** . */
+ final NodeModel<UserNode> model = new NodeModel<UserNode>()
+ {
+ public NodeContext<UserNode> getContext(UserNode node)
+ {
+ return node.context;
+ }
+ public UserNode create(NodeContext<UserNode> context)
+ {
+ if (bundle == null)
+ {
+ bundle = portal.bundleResolver.getBundle(UserNavigation.this);
+ if (bundle == null)
+ {
+ bundle = EmptyResourceBundle.INSTANCE;
+ }
+ }
+ return new UserNode(UserNavigation.this, context);
+ }
+ };
+
+ UserNavigation(UserPortalImpl portal, Navigation navigation, boolean modifiable)
+ {
+ if (navigation == null)
+ {
+ throw new NullPointerException();
+ }
+ if (navigation.getState() == null)
+ {
+ throw new IllegalArgumentException("No state for navigation " +
navigation.getKey());
+ }
+
+ //
+ this.portal = portal;
+ this.navigation = navigation;
+ this.modifiable = modifiable;
+ }
+
+ public SiteKey getKey()
+ {
+ return navigation.getKey();
+ }
+
+ public int getPriority()
+ {
+ Integer priority = navigation.getState().getPriority();
+ return priority != null ? priority : 1;
+ }
+
+ public NavigationState getState()
+ {
+ return navigation.getState();
+ }
+
+ public boolean isModifiable()
+ {
+ return modifiable;
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNode.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNode.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNode.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,338 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.user;
+
+import org.exoplatform.commons.utils.ExpressionUtil;
+import org.exoplatform.portal.mop.Visibility;
+import org.exoplatform.portal.mop.navigation.NavigationServiceException;
+import org.exoplatform.portal.mop.navigation.NodeContext;
+import org.exoplatform.portal.mop.navigation.NodeFilter;
+import org.exoplatform.portal.mop.navigation.NodeState;
+import org.gatein.common.text.EntityEncoder;
+
+import java.util.Collection;
+import java.util.Collections;
+
+/**
+ * A navigation node as seen by a user.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class UserNode
+{
+
+ /** . */
+ final UserNavigation navigation;
+
+ /** . */
+ final NodeContext<UserNode> context;
+
+ /** . */
+ private String resolvedLabel;
+
+ /** . */
+ private String encodedResolvedLabel;
+
+ /** . */
+ private String uri;
+
+ UserNode(UserNavigation navigation, NodeContext<UserNode> context)
+ {
+ this.navigation = navigation;
+ this.context = context;
+ this.resolvedLabel = null;
+ this.encodedResolvedLabel = null;
+ this.uri = null;
+ }
+
+ public String getId()
+ {
+ return context.getId();
+ }
+
+ public UserNode filter(NodeFilter filter)
+ {
+ context.filter(filter);
+ return this;
+ }
+
+ public String getName()
+ {
+ return context.getName();
+ }
+
+ public void setName(String name)
+ {
+ context.setName(name);
+ }
+
+ public String getURI()
+ {
+ if (uri == null)
+ {
+ uri = buildURI().toString();
+ }
+ return uri;
+ }
+
+ private StringBuilder buildURI()
+ {
+ UserNode parent = context.getParentNode();
+ if (parent != null)
+ {
+ StringBuilder builder = parent.buildURI();
+ if (builder.length() > 0)
+ {
+ builder.append('/');
+ }
+ return builder.append(context.getName());
+ }
+ else
+ {
+ return new StringBuilder();
+ }
+ }
+
+ public String getLabel()
+ {
+ return context.getState().getLabel();
+ }
+
+ public void setLabel(String label)
+ {
+ this.resolvedLabel = null;
+ this.encodedResolvedLabel = null;
+
+ //
+ context.setState(new
NodeState.Builder(context.getState()).setLabel(label).capture());
+ }
+
+ public String getIcon()
+ {
+ return context.getState().getIcon();
+ }
+
+ public void setIcon(String icon)
+ {
+ context.setState(new
NodeState.Builder(context.getState()).setIcon(icon).capture());
+ }
+
+ public long getStartPublicationTime()
+ {
+ return context.getState().getStartPublicationTime();
+ }
+
+ public void setStartPublicationTime(long startPublicationTime)
+ {
+ context.setState(new
NodeState.Builder(context.getState()).setStartPublicationTime(startPublicationTime).capture());
+ }
+
+ public long getEndPublicationTime()
+ {
+ return context.getState().getEndPublicationTime();
+ }
+
+ public void setEndPublicationTime(long endPublicationTime)
+ {
+ context.setState(new
NodeState.Builder(context.getState()).setEndPublicationTime(endPublicationTime).capture());
+ }
+
+ public Visibility getVisibility()
+ {
+ return context.getState().getVisibility();
+ }
+
+ public void setVisibility(Visibility visibility)
+ {
+ context.setState(new
NodeState.Builder(context.getState()).setVisibility(visibility).capture());
+ }
+
+ public String getPageRef()
+ {
+ return context.getState().getPageRef();
+ }
+
+ public void setPageRef(String pageRef)
+ {
+ context.setState(new
NodeState.Builder(context.getState()).setPageRef(pageRef).capture());
+ }
+
+ public String getResolvedLabel()
+ {
+ if (resolvedLabel == null)
+ {
+ String resolvedLabel;
+ if (navigation.bundle != null && context.getState().getLabel() != null)
+ {
+ resolvedLabel = ExpressionUtil.getExpressionValue(navigation.bundle,
context.getState().getLabel());
+ }
+ else
+ {
+ resolvedLabel = null;
+ }
+
+ //
+ if (resolvedLabel == null)
+ {
+ resolvedLabel = getLabel();
+ }
+
+ //
+ this.resolvedLabel = resolvedLabel;
+ }
+ return resolvedLabel;
+ }
+
+ public String getEncodedResolvedLabel()
+ {
+ if (encodedResolvedLabel == null)
+ {
+ encodedResolvedLabel = EntityEncoder.FULL.encode(getResolvedLabel());
+ }
+ return encodedResolvedLabel;
+ }
+
+ public UserNode getParent()
+ {
+ return context.getParentNode();
+ }
+
+ /**
+ * Returns true if the children relationship determined.
+ *
+ * @return ture if node has children
+ */
+ public boolean hasChildrenRelationship()
+ {
+ return context.getNodes() != null;
+ }
+
+ /**
+ * Returns the number of children.
+ *
+ * @return the number of children
+ */
+ public int getChildrenCount()
+ {
+ return context.getNodeCount();
+ }
+
+ public int getChildrenSize()
+ {
+ return context.getNodeSize();
+ }
+
+ public Collection<UserNode> getChildren()
+ {
+ Collection<UserNode> children = context.getNodes();
+ return children != null ? children : Collections.<UserNode>emptyList();
+ }
+
+ /**
+ * Returns a child by its name or null if the child does not exist or the children
relationship has not been loaded.
+ *
+ * @param childName the child name
+ * @return the corresponding user node
+ * @throws NullPointerException if the child name is null
+ */
+ public UserNode getChild(String childName) throws NullPointerException
+ {
+ if (context.getNodes() != null)
+ {
+ return context.getNode(childName);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ /**
+ * Returns a child by its index or null if the children relationship has not been
loaded.
+ *
+ * @param childIndex the child index
+ * @return the corresponding user node
+ * @throws IndexOutOfBoundsException if the children relationship is loaded and the
index is outside of its bounds
+ */
+ public UserNode getChild(int childIndex) throws IndexOutOfBoundsException
+ {
+ if (context.getNodes() != null)
+ {
+ return context.getNode(childIndex);
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public void addChild(UserNode child)
+ {
+ context.addNode(navigation.model, null, child);
+ }
+
+ public void addChild(int index, UserNode child)
+ {
+ context.addNode(navigation.model, index, child);
+ }
+
+ public UserNode addChild(String childName)
+ {
+ return context.addNode(navigation.model, childName);
+ }
+
+ public boolean removeChild(String childName)
+ {
+ return context.removeNode(navigation.model, childName);
+ }
+
+ public void save() throws NavigationServiceException
+ {
+ navigation.portal.navigationService.saveNode(navigation.model, this);
+ }
+
+ // Keep this internal for now
+ UserNode find(String nodeId)
+ {
+ UserNode found = null;
+ if (context.getId().equals(nodeId))
+ {
+ found = this;
+ }
+ else
+ {
+ Collection<UserNode> children = context.getNodes();
+ if (children != null)
+ {
+ for (UserNode child : children)
+ {
+ UserNode a = child.find(nodeId);
+ if (a != null)
+ {
+ found = a;
+ break;
+ }
+ }
+ }
+ }
+ return found;
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilter.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilter.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodeFilter.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.user;
+
+import org.exoplatform.portal.config.UserACL;
+import org.exoplatform.portal.config.UserPortalConfigService;
+import org.exoplatform.portal.mop.Visibility;
+import org.exoplatform.portal.mop.navigation.NodeFilter;
+import org.exoplatform.portal.mop.navigation.NodeState;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+class UserNodeFilter implements NodeFilter
+{
+
+ /** . */
+ private final UserPortalImpl userPortal;
+
+ /** . */
+ private final UserNodePredicate predicate;
+
+ public UserNodeFilter(UserPortalImpl userPortal, UserNodePredicate predicate)
+ {
+ if (userPortal == null)
+ {
+ throw new NullPointerException();
+ }
+ if (predicate == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //
+ this.userPortal = userPortal;
+ this.predicate = predicate;
+ }
+
+ public boolean accept(int depth, String id, String name, NodeState state)
+ {
+ Visibility visibility = state.getVisibility();
+
+ // Correct null -> displayed
+ if (visibility == null)
+ {
+ visibility = Visibility.DISPLAYED;
+ }
+
+ // If a visibility is specified then we use it
+ if (predicate.visibility != null &&
!predicate.visibility.contains(visibility))
+ {
+ return false;
+ }
+
+ //
+ if (predicate.authorizationCheck)
+ {
+ if (visibility == Visibility.SYSTEM)
+ {
+ UserACL acl = userPortal.acl;
+ String userName = userPortal.userName;
+ if (!acl.getSuperUser().equals(userName))
+ {
+ return false;
+ }
+ }
+ else
+ {
+ String pageRef = state.getPageRef();
+ if (pageRef != null)
+ {
+ UserPortalConfigService upcs = userPortal.service;
+ try
+ {
+ if (upcs.getPage(pageRef, userPortal.userName) == null)
+ {
+ return false;
+ }
+ }
+ catch (Exception e)
+ {
+ // Log me
+ return false;
+ }
+ }
+ }
+ }
+
+ // Now make the custom checks
+ switch (visibility)
+ {
+ case SYSTEM:
+ break;
+ case TEMPORAL:
+ if (predicate.temporalCheck)
+ {
+ long now = System.currentTimeMillis();
+ if (state.getStartPublicationTime() != -1 && now <
state.getStartPublicationTime())
+ {
+ return false;
+ }
+ if (state.getEndPublicationTime() != -1 && now >
state.getEndPublicationTime())
+ {
+ return false;
+ }
+ }
+ break;
+ }
+
+ //
+ return true;
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodePredicate.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodePredicate.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserNodePredicate.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.user;
+
+import org.exoplatform.commons.utils.Safe;
+import org.exoplatform.portal.mop.Visibility;
+
+import java.util.EnumSet;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class UserNodePredicate
+{
+
+ /** . */
+ final Set<Visibility> visibility;
+
+ /** . */
+ final boolean authorizationCheck;
+
+ /** . */
+ final boolean temporalCheck;
+
+ public UserNodePredicate(Builder builder)
+ {
+ if (builder == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //
+ this.visibility = Safe.unmodifiableSet(builder.withVisibility);
+ this.authorizationCheck = builder.withAuthorizationCheck;
+ this.temporalCheck = builder.withTemporalCheck;
+ }
+
+ public Set<Visibility> getVisibility()
+ {
+ return visibility;
+ }
+
+ public boolean getAuthorizationCheck()
+ {
+ return authorizationCheck;
+ }
+
+ public boolean getTemporalCheck()
+ {
+ return temporalCheck;
+ }
+
+ public static Builder builder()
+ {
+ return new Builder();
+ }
+
+ public static Builder builder(UserNodePredicate predicate)
+ {
+ return new Builder(predicate);
+ }
+
+ public static class Builder
+ {
+
+ /** . */
+ private Set<Visibility> withVisibility = null;
+
+ /** . */
+ private boolean withAuthorizationCheck = false;
+
+ /** . */
+ private boolean withTemporalCheck = false;
+
+ private Builder()
+ {
+ this.withVisibility = null;
+ this.withAuthorizationCheck = false;
+ this.withTemporalCheck = false;
+ }
+
+ private Builder(UserNodePredicate predicate)
+ {
+ this.withVisibility = predicate.visibility;
+ this.withAuthorizationCheck = predicate.authorizationCheck;
+ this.withTemporalCheck = predicate.temporalCheck;
+ }
+
+ public Builder withVisibility(Visibility first, Visibility... rest)
+ {
+ withVisibility = EnumSet.of(first, rest);
+ return this;
+ }
+
+ public Builder withVisibility(Visibility first)
+ {
+ withVisibility = EnumSet.of(first);
+ return this;
+ }
+
+ public Builder withoutVisibility()
+ {
+ withVisibility = null;
+ return this;
+ }
+
+ public Builder withTemporalCheck()
+ {
+ this.withTemporalCheck = true;
+ return this;
+ }
+
+ public Builder withoutTemporalCheck()
+ {
+ this.withTemporalCheck = false;
+ return this;
+ }
+
+ public Builder withAuthorizationCheck()
+ {
+ this.withAuthorizationCheck = true;
+ return this;
+ }
+
+ public Builder withoutAuthorizationChek()
+ {
+ this.withAuthorizationCheck = false;
+ return this;
+ }
+
+ public UserNodePredicate build()
+ {
+ return new UserNodePredicate(this);
+ }
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserPortal.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserPortal.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserPortal.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,119 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.user;
+
+import org.exoplatform.portal.mop.SiteKey;
+import org.exoplatform.portal.mop.Visibility;
+import org.exoplatform.portal.mop.navigation.NodeFilter;
+import org.exoplatform.portal.mop.navigation.Scope;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public interface UserPortal
+{
+
+ /**
+ * The default navigation predicate.
+ */
+ UserNodePredicate NAVIGATION = UserNodePredicate.builder().
+ withVisibility(Visibility.DISPLAYED, Visibility.TEMPORAL).
+ withAuthorizationCheck().
+ withTemporalCheck().
+ build();
+
+ /**
+ * Returns the sorted list of current user navigations.
+ *
+ * @return the current user navigations
+ * @throws Exception any exception
+ */
+ List<UserNavigation> getNavigations() throws Exception;
+
+ /**
+ * Returns a user navigation for a specified site key, null is returned when such
navigation does not exist.
+ *
+ * @param key the site key
+ * @return the corresponding user navigation
+ * @throws Exception any exception
+ */
+ UserNavigation getNavigation(SiteKey key) throws Exception;
+
+ /**
+ * Load a user node from a specified user navigation with a custom scope.
+ * The returned node is the root node of the navigation.
+ *
+ * @param navigation the user navigation
+ * @param scope the scope
+ * @return the user node
+ * @throws Exception any exception
+ */
+ UserNode getNode(UserNavigation navigation, Scope scope) throws Exception;
+
+ /**
+ * Load a user node from a specified user node with a custom scope. The node argument
will be modified according
+ * to the scope. The returned node is either the same node argument or null if the
node was discarded.
+ *
+ * @param node the user node
+ * @param scope the scope
+ * @return the user node
+ * @throws Exception any exception
+ */
+ UserNode getNode(UserNode node, Scope scope) throws Exception;
+
+ /**
+ * Returns the default navigation path.
+ *
+ * @return the default navigation path
+ * @throws Exception any exception
+ */
+ NavigationPath getDefaultPath() throws Exception;
+
+ /**
+ * Resolves and returns a navigation path among all user navigations for a specified
path.
+ *
+ * @param path the path
+ * @return the navigation path
+ * @throws Exception any exception
+ */
+ NavigationPath resolvePath(String path) throws Exception;
+
+ /**
+ * Resolves and returns a navigation path for the specified navigation and for a
specified path.
+ *
+ * @param navigation the navigation
+ * @param path the path
+ * @return the navigation path
+ * @throws Exception any exception
+ */
+ NavigationPath resolvePath(UserNavigation navigation, String path) throws Exception;
+
+ /**
+ * Create a filter for the current user with the specified predicate.
+ *
+ * @param predicate the predicate to use
+ * @return the scope
+ */
+ NodeFilter createFilter(UserNodePredicate predicate);
+
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserPortalContext.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserPortalContext.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserPortalContext.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.user;
+
+import java.util.ResourceBundle;
+
+/**
+ * The context of a user within its portal.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public interface UserPortalContext
+{
+
+ /**
+ * A context that always return null.
+ */
+ UserPortalContext NULL_CONTEXT = new UserPortalContext()
+ {
+ public ResourceBundle getBundle(UserNavigation navigation)
+ {
+ return null;
+ }
+ };
+
+ /**
+ * Provide an opportunity to use a resource bundle for a specified navigation. It no
such bundle can be found then null
+ * can be returned.
+ *
+ * @param navigation the navigation that will be localized
+ * @return the resource bundle to use
+ */
+ ResourceBundle getBundle(UserNavigation navigation);
+
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserPortalImpl.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserPortalImpl.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/mop/user/UserPortalImpl.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,382 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.user;
+
+import org.exoplatform.portal.config.UserACL;
+import org.exoplatform.portal.config.UserPortalConfigService;
+import org.exoplatform.portal.config.model.PortalConfig;
+import org.exoplatform.portal.mop.SiteKey;
+import org.exoplatform.portal.mop.SiteType;
+import org.exoplatform.portal.mop.navigation.Navigation;
+import org.exoplatform.portal.mop.navigation.NavigationServiceException;
+import org.exoplatform.portal.mop.navigation.NavigationService;
+import org.exoplatform.portal.mop.navigation.NodeFilter;
+import org.exoplatform.portal.mop.navigation.NodeState;
+import org.exoplatform.portal.mop.navigation.Scope;
+import org.exoplatform.portal.mop.navigation.VisitMode;
+import org.exoplatform.services.organization.Group;
+import org.exoplatform.services.organization.OrganizationService;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class UserPortalImpl implements UserPortal
+{
+
+ /** . */
+ final UserPortalConfigService service;
+
+ /** . */
+ final NavigationService navigationService;
+
+ /** . */
+ private final OrganizationService organizationService;
+
+ /** . */
+ final UserACL acl;
+
+ /** . */
+ private final PortalConfig portal;
+
+ /** . */
+ final UserPortalContext bundleResolver;
+
+ /** . */
+ final String userName;
+
+ /** . */
+ private List<UserNavigation> navigations;
+
+ /** . */
+ private final String portalName;
+
+ public UserPortalImpl(
+ UserPortalConfigService service,
+ NavigationService navigationService,
+ OrganizationService organizationService,
+ UserACL acl,
+ String portalName,
+ PortalConfig portal,
+ String userName,
+ UserPortalContext bundleResolver)
+ {
+ // So we don't care about testing nullity
+ if (bundleResolver == null)
+ {
+ bundleResolver = UserPortalContext.NULL_CONTEXT;
+ }
+
+ //
+ this.service = service;
+ this.navigationService = navigationService;
+ this.organizationService = organizationService;
+ this.acl = acl;
+ this.portalName = portalName;
+ this.portal = portal;
+ this.userName = userName;
+ this.bundleResolver = bundleResolver;
+ this.navigations = null;
+ }
+
+ //
+
+ public UserPortalContext getBundleResolver()
+ {
+ return bundleResolver;
+ }
+
+ /**
+ * Returns an immutable sorted list of the valid navigations related to the user.
+ *
+ * @return the navigations
+ * @throws Exception any exception
+ */
+ public List<UserNavigation> getNavigations() throws Exception
+ {
+ if (navigations == null)
+ {
+ List<UserNavigation> navigations = new
ArrayList<UserNavigation>(userName == null ? 1 : 10);
+ Navigation portalNav = navigationService.loadNavigation(new
SiteKey(SiteType.PORTAL, portalName));
+ navigations.add(new UserNavigation(
+ this,
+ portalNav,
+ acl.hasEditPermissionOnNavigation(portalNav.getKey())));
+
+ //
+ if (userName != null)
+ {
+ // Add user nav if any
+ Navigation userNavigation =
navigationService.loadNavigation(SiteKey.user(userName));
+ if (userNavigation != null && userNavigation.getState() != null)
+ {
+ navigations.add(new UserNavigation(this, userNavigation, true));
+ }
+
+ //
+ Collection<?> groups;
+ if (acl.getSuperUser().equals(userName))
+ {
+ groups = organizationService.getGroupHandler().getAllGroups();
+ }
+ else
+ {
+ groups =
organizationService.getGroupHandler().findGroupsOfUser(userName);
+ }
+ for (Object group : groups)
+ {
+ Group m = (Group)group;
+ String groupId = m.getId().trim();
+ if (!groupId.equals(acl.getGuestsGroup()))
+ {
+ Navigation groupNavigation =
navigationService.loadNavigation(SiteKey.group(groupId));
+ if (groupNavigation != null && groupNavigation.getState() !=
null)
+ {
+ navigations.add(new UserNavigation(
+ this,
+ groupNavigation,
+ acl.hasEditPermissionOnNavigation(groupNavigation.getKey())));
+ }
+ }
+ }
+
+ // Sort the list finally
+ Collections.sort(navigations, new Comparator<UserNavigation>()
+ {
+ public int compare(UserNavigation nav1, UserNavigation nav2)
+ {
+ return nav1.getPriority() - nav2.getPriority();
+ }
+ });
+ }
+
+ //
+ this.navigations = Collections.unmodifiableList(navigations);
+ }
+ return navigations;
+ }
+
+ public UserNavigation getNavigation(SiteKey key) throws Exception
+ {
+ for (UserNavigation navigation : getNavigations())
+ {
+ if (navigation.getKey().equals(key))
+ {
+ return navigation;
+ }
+ }
+
+ //
+ return null;
+ }
+
+ public UserNode getNode(UserNavigation userNavigation, Scope scope) throws Exception
+ {
+ return navigationService.loadNode(userNavigation.model, userNavigation.navigation,
scope);
+ }
+
+ public UserNode getNode(UserNode node, Scope scope) throws Exception
+ {
+ UserNavigation navigation = node.navigation;
+ return navigationService.loadNode(navigation.model, node, scope);
+ }
+
+ private class MatchingScope implements Scope
+ {
+ final UserNavigation userNavigation;
+ final String[] match;
+ int score;
+ String id;
+ UserNode userNode;
+ private NavigationPath path;
+
+ MatchingScope(UserNavigation userNavigation, String[] match)
+ {
+ this.userNavigation = userNavigation;
+ this.match = match;
+ }
+
+ void resolve() throws NavigationServiceException
+ {
+ UserNode node = navigationService.loadNode(userNavigation.model,
userNavigation.navigation, this);
+ if (score > 0)
+ {
+ userNode = node.find(id);
+ path = new NavigationPath(userNavigation, userNode);
+ }
+ else
+ {
+ path = new NavigationPath(userNavigation, null);
+ }
+ }
+
+ public Visitor get()
+ {
+ return new Visitor()
+ {
+ public VisitMode visit(int depth, String id, String name, NodeState state)
+ {
+ if (depth == 0 && "default".equals(name))
+ {
+ score = 0;
+ MatchingScope.this.id = null;
+ return VisitMode.ALL_CHILDREN;
+ }
+ else if (depth <= match.length && name.equals(match[depth -
1]))
+ {
+ score++;
+ MatchingScope.this.id = id;
+ return VisitMode.ALL_CHILDREN;
+ }
+ else
+ {
+ return VisitMode.NO_CHILDREN;
+ }
+ }
+ };
+ }
+ }
+
+ public NavigationPath getDefaultPath() throws Exception
+ {
+ for (UserNavigation userNavigation : getNavigations())
+ {
+ Navigation navigation = userNavigation.navigation;
+ if (navigation.getState() != null)
+ {
+ UserNode root = navigationService.loadNode(userNavigation.model, navigation,
Scope.CHILDREN);
+ for (UserNode node : root.getChildren())
+ {
+ return new NavigationPath(userNavigation, node);
+ }
+ }
+ }
+
+ //
+ return null;
+ }
+
+ public NavigationPath resolvePath(String path) throws Exception
+ {
+ if (path == null)
+ {
+ throw new NullPointerException("No null path accepted");
+ }
+
+ // Get navigations
+ List<UserNavigation> navigations = getNavigations();
+
+ // Split into segments
+ if (path.length() > 0 && path.charAt(0) == '/')
+ {
+ path = path.substring(1);
+ }
+ final String[] segments = path.split("/");
+
+ // Find the first navigation available or return null
+ if (path.length() == 0)
+ {
+ return getDefaultPath();
+ }
+
+ //
+ MatchingScope best = null;
+ for (UserNavigation navigation : navigations)
+ {
+ MatchingScope scope = new MatchingScope(navigation, segments);
+ scope.resolve();
+ if (scope.score == segments.length)
+ {
+ best = scope;
+ break;
+ }
+ else
+ {
+ if (best == null)
+ {
+ best = scope;
+ }
+ else
+ {
+ if (scope.score > best.score)
+ {
+ best = scope;
+ }
+ }
+ }
+ }
+
+ //
+ if (best != null && best.score > 0)
+ {
+ return new NavigationPath(best.userNavigation, best.userNode);
+ }
+ else
+ {
+ return getDefaultPath();
+ }
+ }
+
+ public NavigationPath resolvePath(UserNavigation navigation, String path) throws
Exception
+ {
+ if (path == null)
+ {
+ throw new NullPointerException("No null path accepted");
+ }
+
+ //
+ if (path.length() > 0 && path.charAt(0) == '/')
+ {
+ path = path.substring(1);
+ }
+ if (path.length() == 0)
+ {
+ return null;
+ }
+ final String[] segments = path.split("/");
+
+ //
+
+ //
+ MatchingScope scope = new MatchingScope(navigation, segments);
+ scope.resolve();
+
+ //
+ if (scope.score > 0)
+ {
+ return scope.path;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public NodeFilter createFilter(UserNodePredicate predicate)
+ {
+ return new UserNodeFilter(this, predicate);
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/MOPAccess.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/MOPAccess.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/MOPAccess.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.pom.config.tasks;
+
+import org.chromattic.api.query.QueryResult;
+import org.exoplatform.commons.utils.ListAccess;
+import org.exoplatform.portal.config.Query;
+import org.exoplatform.portal.pom.config.POMSession;
+import org.exoplatform.portal.pom.config.POMSessionManager;
+import org.exoplatform.portal.pom.config.POMTask;
+import org.exoplatform.portal.pom.data.Mapper;
+import org.exoplatform.portal.pom.data.NavigationData;
+import org.exoplatform.portal.pom.data.PageData;
+import org.gatein.mop.api.workspace.Navigation;
+import org.gatein.mop.api.workspace.ObjectType;
+import org.gatein.mop.api.workspace.Page;
+import org.gatein.mop.api.workspace.Site;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public abstract class MOPAccess<E, I> implements ListAccess<E>
+{
+
+ /** . */
+ private final POMSessionManager mgr;
+
+ /** . */
+ private final ObjectType<Site> ownerType;
+
+ /** . */
+ private final String ownerId;
+
+ /** . */
+ private final String title;
+
+ /** . */
+ private Integer size;
+
+ MOPAccess(POMSessionManager mgr, Query<E> query)
+ {
+ String ownerType = query.getOwnerType();
+ ObjectType<Site> siteType = null;
+ if (ownerType != null)
+ {
+ siteType = Mapper.parseSiteType(ownerType);
+ }
+
+ //
+ this.mgr = mgr;
+ this.ownerType = siteType;
+ this.ownerId = query.getOwnerId();
+ this.title = query.getTitle();
+ this.size = null;
+ }
+
+ public E[] load(final int index, final int length) throws Exception,
IllegalArgumentException
+ {
+ return mgr.execute(new POMTask<E[]>()
+ {
+ public E[] run(POMSession session) throws Exception
+ {
+ QueryResult<I> res = findW(session, ownerType, ownerId, title, index,
length);
+ E[] elements = createT(length);
+ int index = 0;
+ while (res.hasNext() && index < length)
+ {
+ I internal = res.next();
+ E external = convert(session, internal);
+ elements[index++] = external;
+ }
+ return elements;
+ }
+ public String toString()
+ {
+ return MOPAccess.this.getClass().getSimpleName() + "[offset=" +
index + ",limit=" + length + "]";
+ }
+ });
+ }
+
+ public int getSize() throws Exception
+ {
+ if (size == null)
+ {
+ size = mgr.execute(new POMTask<Integer>()
+ {
+ public Integer run(POMSession session) throws Exception
+ {
+ QueryResult res = findW(session, ownerType, ownerId, title, 0, 1);
+ return res.hits();
+ }
+ public String toString()
+ {
+ return MOPAccess.this.getClass().getSimpleName() + "[size]";
+ }
+ });
+ if (size == null)
+ {
+ size = 0;
+ }
+ }
+ return size;
+ }
+
+ protected abstract QueryResult<I> findW(
+ POMSession session,
+ ObjectType<Site> siteType,
+ String ownerId,
+ String title, int offset, int limit);
+
+ protected abstract E[] createT(int length);
+
+ protected abstract E convert(POMSession session, I internal);
+
+ public static class PageAccess extends MOPAccess<PageData, Page>
+ {
+
+ public PageAccess(POMSessionManager mgr, Query<PageData> pageDataQuery)
+ {
+ super(mgr, pageDataQuery);
+ }
+
+ @Override
+ protected QueryResult<Page> findW(POMSession session, ObjectType<Site>
siteType, String ownerId, String title, int offset, int limit)
+ {
+ return session.findObjects(ObjectType.PAGE, siteType, ownerId, title, offset,
limit);
+ }
+
+ @Override
+ protected PageData convert(POMSession session, Page internal)
+ {
+ return new Mapper(session).load(internal);
+ }
+
+ @Override
+ protected PageData[] createT(int length)
+ {
+ return new PageData[length];
+ }
+ }
+
+ public static class NavigationAccess extends MOPAccess<NavigationData,
Navigation>
+ {
+
+ public NavigationAccess(POMSessionManager mgr, Query<NavigationData>
navigationDataQuery)
+ {
+ super(mgr, navigationDataQuery);
+ }
+
+ @Override
+ protected QueryResult<Navigation> findW(POMSession session,
ObjectType<Site> siteType, String ownerId, String title, int offset, int limit)
+ {
+ return session.findObjects(ObjectType.NAVIGATION, siteType, ownerId, title,
offset, limit);
+ }
+
+ @Override
+ protected NavigationData[] createT(int length)
+ {
+ return new NavigationData[length];
+ }
+
+ @Override
+ protected NavigationData convert(POMSession session, Navigation internal)
+ {
+ return new Mapper(session).load(internal);
+ }
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/NodeTask.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/NodeTask.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/config/tasks/NodeTask.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.pom.config.tasks;
+
+import org.exoplatform.portal.mop.Described;
+import org.exoplatform.portal.mop.Visibility;
+import org.exoplatform.portal.mop.Visible;
+import org.exoplatform.portal.pom.config.POMSession;
+import org.exoplatform.portal.pom.config.cache.CacheableDataTask;
+import org.exoplatform.portal.pom.config.cache.DataAccessMode;
+import org.exoplatform.portal.pom.data.MappedAttributes;
+import org.exoplatform.portal.pom.data.Mapper;
+import org.exoplatform.portal.pom.data.NavigationKey;
+import org.exoplatform.portal.pom.data.NodeData;
+import org.gatein.mop.api.Attributes;
+import org.gatein.mop.api.workspace.Navigation;
+import org.gatein.mop.api.workspace.ObjectType;
+import org.gatein.mop.api.workspace.Site;
+import org.gatein.mop.api.workspace.Workspace;
+import org.gatein.mop.api.workspace.link.Link;
+import org.gatein.mop.api.workspace.link.PageLink;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public abstract class NodeTask<K extends Serializable> implements
CacheableDataTask<K, NodeData>
+{
+
+ public abstract static class KeyType<K>
+ {
+
+ public static final KeyType<String> STRING = new KeyType<String>()
+ {
+ @Override
+ protected Navigation load(POMSession session, String key)
+ {
+ return session.findObjectById(ObjectType.NAVIGATION, key);
+ }
+ };
+
+ public static final KeyType<NavigationKey> NAVIGATION = new
KeyType<NavigationKey>()
+ {
+ @Override
+ protected Navigation load(POMSession session, NavigationKey key)
+ {
+ ObjectType<Site> siteType = Mapper.parseSiteType(key.getType());
+ Workspace workspace = session.getWorkspace();
+ Site site = workspace.getSite(siteType, key.getId());
+ Navigation nav = site.getRootNavigation();
+ return nav.getChild("default");
+ }
+ };
+
+ protected abstract Navigation load(POMSession session, K key);
+
+ }
+
+ /** . */
+ protected final KeyType<K> keyType;
+
+ /** . */
+ protected final K key;
+
+ protected NodeTask(KeyType<K> keyType, K key)
+ {
+ if (keyType == null)
+ {
+ throw new NullPointerException("No null key type accepted");
+ }
+ if (key == null)
+ {
+ throw new NullPointerException("No null key accepted");
+ }
+
+ //
+ this.keyType = keyType;
+ this.key = key;
+ }
+
+ public final K getKey()
+ {
+ return key;
+ }
+
+ public final Class<NodeData> getValueType()
+ {
+ return NodeData.class;
+ }
+
+ public static class Load<K extends Serializable> extends NodeTask<K>
+ {
+
+ public Load(KeyType<K> keyType, K key)
+ {
+ super(keyType, key);
+ }
+
+ public DataAccessMode getAccessMode()
+ {
+ return DataAccessMode.READ;
+ }
+
+ public NodeData run(POMSession session) throws Exception
+ {
+ Navigation src = keyType.load(session, key);
+
+ //
+ Attributes attrs = src.getAttributes();
+ Described described = src.adapt(Described.class);
+ Visible visible = src.adapt(Visible.class);
+
+ //
+ String pageReference = null;
+ Link link = src.getLink();
+ if (link instanceof PageLink)
+ {
+ PageLink pageLink = (PageLink)link;
+ org.gatein.mop.api.workspace.Page target = pageLink.getPage();
+ if (target != null)
+ {
+ Site site = target.getSite();
+ ObjectType<? extends Site> siteType = site.getObjectType();
+ pageReference = Mapper.getOwnerType(siteType) + "::" +
site.getName() + "::" + target.getName();
+ }
+ }
+
+ //
+ return new NodeData(
+ src.getObjectId(),
+ attrs.getValue(MappedAttributes.URI),
+ described.getName(),
+ attrs.getValue(MappedAttributes.ICON),
+ src.getName(),
+ visible.getStartPublicationDate(),
+ visible.getEndPublicationDate(),
+ visible.getVisibility() != null ? visible.getVisibility() :
Visibility.DISPLAYED,
+ pageReference,
+ new String[0]
+ );
+ }
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/data/NodeData.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/data/NodeData.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/main/java/org/exoplatform/portal/pom/data/NodeData.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,147 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.pom.data;
+
+import org.exoplatform.portal.mop.Visibility;
+
+import java.util.Date;
+
+/**
+* @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+* @version $Revision$
+*/
+public class NodeData extends ModelData
+{
+
+ /** . */
+ private final String uri;
+
+ /** . */
+ private final String label;
+
+ /** . */
+ private final String icon;
+
+ /** . */
+ private final String name;
+
+ /** . */
+ private final Date startPublicationDate;
+
+ /** . */
+ private final Date endPublicationDate;
+
+ /** . */
+ private final Visibility visibility;
+
+ /** . */
+ private final String pageReference;
+
+ /** . */
+ private final String[] children;
+
+ public NodeData(
+ String uri,
+ String label,
+ String icon,
+ String name,
+ Date startPublicationDate,
+ Date endPublicationDate,
+ Visibility visibility,
+ String pageReference,
+ String[] children)
+ {
+ this(null, uri, label, icon, name, startPublicationDate, endPublicationDate,
visibility, pageReference, children);
+ }
+
+ public NodeData(
+ String storageId,
+ String uri,
+ String label,
+ String icon,
+ String name,
+ Date startPublicationDate,
+ Date endPublicationDate,
+ Visibility visibility,
+ String pageReference,
+ String[] children)
+ {
+ super(storageId, null);
+
+ //
+ this.uri = uri;
+ this.label = label;
+ this.icon = icon;
+ this.name = name;
+ this.startPublicationDate = startPublicationDate;
+ this.endPublicationDate = endPublicationDate;
+ this.visibility = visibility;
+ this.pageReference = pageReference;
+ this.children = children;
+ }
+ public String getURI()
+ {
+ return uri;
+ }
+
+ public String getLabel()
+ {
+ return label;
+ }
+
+ public String getIcon()
+ {
+ return icon;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Date getStartPublicationDate()
+ {
+ return startPublicationDate;
+ }
+
+ public Date getEndPublicationDate()
+ {
+ return endPublicationDate;
+ }
+
+ public Visibility getVisibility()
+ {
+ return visibility;
+ }
+
+ public String getPageReference()
+ {
+ return pageReference;
+ }
+
+ public int getChildrenCount()
+ {
+ return children.length;
+ }
+
+ public String getChildRef(int index)
+ {
+ return children[index];
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/navigation/Node.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/navigation/Node.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/navigation/Node.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,140 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+import java.util.Collection;
+
+/**
+ * Represents a navigation node.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class Node
+{
+
+ /** . */
+ public static final NodeModel<Node> MODEL = new NodeModel<Node>()
+ {
+ public NodeContext<Node> getContext(Node node)
+ {
+ return node.context;
+ }
+
+ public Node create(NodeContext<Node> context)
+ {
+ return new Node(context);
+ }
+ };
+
+ /** . */
+ final NodeContext<Node> context;
+
+ Node(NodeContext<Node> context)
+ {
+ this.context = context;
+ }
+
+ public String getId()
+ {
+ return context.getId();
+ }
+
+ public String getName()
+ {
+ return context.getName();
+ }
+
+ public void setName(String name)
+ {
+ context.setName(name);
+ }
+
+ public NodeContext getContext()
+ {
+ return context;
+ }
+
+ public NodeState getState()
+ {
+ return context.getState();
+ }
+
+ public void setState(NodeState state)
+ {
+ context.setState(state);
+ }
+
+ public Node getParent()
+ {
+ return context.getParentNode();
+ }
+
+ public Collection<Node> getChildren()
+ {
+ return context.getNodes();
+ }
+
+ public Node getChild(String childName)
+ {
+ return context.getNode(childName);
+ }
+
+ public Node getChild(int childIndex)
+ {
+ return context.getNode(childIndex);
+ }
+
+ public void addChild(Node child)
+ {
+ context.addNode(MODEL, null, child);
+ }
+
+ public void addChild(int index, Node child)
+ {
+ context.addNode(MODEL, index, child);
+ }
+
+ public Node addChild(String childName)
+ {
+ return context.addNode(MODEL, childName);
+ }
+
+ public boolean removeChild(String childName)
+ {
+ return context.removeNode(MODEL, childName);
+ }
+
+ public int getChildrenCount()
+ {
+ return context.getNodeCount();
+ }
+
+ public void filter(NodeFilter filter)
+ {
+ context.filter(filter);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Node[" + context.getName() + "]";
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/navigation/TestListTree.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/navigation/TestListTree.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/navigation/TestListTree.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,896 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+import junit.framework.TestCase;
+import org.exoplatform.portal.mop.navigation.ListTree;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.ListIterator;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestListTree extends TestCase
+{
+
+ public static class IntegerTree extends ListTree<IntegerTree, Integer>
+ {
+
+ /** . */
+ private final int value;
+
+ public IntegerTree(int value, String name)
+ {
+ super(name);
+
+ //
+ this.value = value;
+ }
+
+ @Override
+ public Integer getElement()
+ {
+ return value;
+ }
+ }
+
+ private static IntegerTree hidden(String name, int value, IntegerTree... trees)
+ {
+ IntegerTree tree = shown(name, value, trees);
+ tree.setHidden(true);
+ return tree;
+ }
+
+ private static IntegerTree shown(String name, int value, IntegerTree... trees)
+ {
+ IntegerTree tree = new IntegerTree(value, name);
+ if (trees != null)
+ {
+ tree.setTrees(Arrays.asList(trees));
+ }
+ return tree;
+ }
+
+ private void assertChildren(IntegerTree tree, Integer... expected)
+ {
+ List<Integer> children = new ArrayList<Integer>();
+ for (int child : tree)
+ {
+ children.add(child);
+ }
+ assertEquals(Arrays.asList(expected), children);
+ }
+
+ private void assertAllChildren(IntegerTree tree, Integer... expected)
+ {
+ List<Integer> children = new ArrayList<Integer>();
+ for (IntegerTree child : tree.getTrees())
+ {
+ children.add(child.getElement());
+ }
+ assertEquals(Arrays.asList(expected), children);
+ }
+
+ private void assertAllChildren(IntegerTree tree)
+ {
+ assertAllChildren(tree, new Integer[0]);
+ assertAllChildren(tree, new String[0]);
+ }
+
+ private void assertAllChildren(IntegerTree tree, String... expected)
+ {
+ List<String> children = new ArrayList<String>();
+ for (IntegerTree child : tree.getTrees())
+ {
+ children.add(child.getName());
+ }
+ assertEquals(Arrays.asList(expected), children);
+ }
+
+ public void testInsert1()
+ {
+ IntegerTree root = shown("", 0);
+ assertChildren(root);
+ assertAllChildren(root);
+
+ //
+ root = shown("", 0);
+ root.insert(0, shown("a", 1));
+ assertChildren(root, 1);
+ assertAllChildren(root, 1);
+ assertAllChildren(root, "a");
+
+ //
+ root = shown("", 0);
+ root.insert(null, shown("a", 1));
+ assertChildren(root, 1);
+ assertAllChildren(root, 1);
+ assertAllChildren(root, "a");
+ }
+
+ public void testInsert2()
+ {
+ IntegerTree root = shown("", 0, hidden("a", 1));
+ assertChildren(root);
+ assertAllChildren(root, 1);
+ assertAllChildren(root, "a");
+
+ //
+ root = shown("", 0, hidden("a", 1));
+ root.insert(0, shown("b", 2));
+ assertChildren(root, 2);
+ assertAllChildren(root, 2, 1);
+ assertAllChildren(root, "b", "a");
+
+ //
+ root = shown("", 0, hidden("a", 1));
+ root.insert(null, shown("b", 2));
+ assertChildren(root, 2);
+ assertAllChildren(root, 2, 1);
+ assertAllChildren(root, "b", "a");
+ }
+
+ public void testInsert3()
+ {
+ IntegerTree root = shown("", 0, shown("a", 1),
hidden("b", 2));
+ assertChildren(root, 1);
+ assertAllChildren(root, 1, 2);
+ assertAllChildren(root, "a", "b");
+
+ //
+ root = shown("", 0, shown("a", 1), hidden("b", 2));
+ root.insert(0, shown("c", 3));
+ assertChildren(root, 3, 1);
+ assertAllChildren(root, 3, 1, 2);
+ assertAllChildren(root, "c", "a", "b");
+
+ //
+ root = shown("", 0, shown("a", 1), hidden("b", 2));
+ root.insert(1, shown("c", 3));
+ assertChildren(root, 1, 3);
+ assertAllChildren(root, 1, 3, 2);
+ assertAllChildren(root, "a", "c", "b");
+
+ //
+ root = shown("", 0, shown("a", 1), hidden("b", 2));
+ root.insert(null, shown("c", 3));
+ assertChildren(root, 1, 3);
+ assertAllChildren(root, 1, 3, 2);
+ assertAllChildren(root, "a", "c", "b");
+ }
+
+ public void testInsert4()
+ {
+ IntegerTree root = shown("", 0, shown("a", 1),
hidden("b", 2), shown("c", 3));
+ assertChildren(root, 1, 3);
+ assertAllChildren(root, 1, 2, 3);
+ assertAllChildren(root, "a", "b", "c");
+
+ //
+ root = shown("", 0, shown("a", 1), hidden("b", 2),
shown("c", 3));
+ root.insert(0, shown("d", 4));
+ assertChildren(root, 4, 1, 3);
+ assertAllChildren(root, 4, 1, 2, 3);
+ assertAllChildren(root, "d", "a", "b",
"c");
+
+ //
+ root = shown("", 0, shown("a", 1), hidden("b", 2),
shown("c", 3));
+ root.insert(1, shown("d", 4));
+ assertChildren(root, 1, 4, 3);
+ assertAllChildren(root, 1, 4, 2, 3);
+ assertAllChildren(root, "a", "d", "b",
"c");
+
+ //
+ root = shown("", 0, shown("a", 1), hidden("b", 2),
shown("c", 3));
+ root.insert(2, shown("d", 4));
+ assertChildren(root, 1, 3, 4);
+ assertAllChildren(root, 1, 2, 3, 4);
+ assertAllChildren(root, "a", "b", "c",
"d");
+
+ //
+ root = shown("", 0, shown("a", 1), hidden("b", 2),
shown("c", 3));
+ root.insert(null, shown("d", 4));
+ assertChildren(root, 1, 3, 4);
+ assertAllChildren(root, 1, 2, 3, 4);
+ assertAllChildren(root, "a", "b", "c",
"d");
+ }
+
+ public void testInsertDuplicate()
+ {
+ IntegerTree root = shown("", 0, shown("a", 1));
+ assertChildren(root, 1);
+ assertAllChildren(root, 1);
+ assertAllChildren(root, "a");
+
+ //
+ try
+ {
+ root.insert(0, shown("a", 2));
+ fail();
+ }
+ catch (IllegalArgumentException ignore)
+ {
+ assertAllChildren(root, 1);
+ assertAllChildren(root, "a");
+ }
+ }
+
+ public void testInsertWithNoChildren()
+ {
+ IntegerTree root = shown("", 0, (IntegerTree[])null);
+ assertFalse(root.hasTrees());
+
+ //
+ try
+ {
+ root.insert(0, shown("a", 1));
+ fail();
+ }
+ catch (IllegalStateException ignore)
+ {
+ assertFalse(root.hasTrees());
+ }
+ }
+
+ public void testInsertMove1()
+ {
+ IntegerTree a = shown("a", 1);
+ IntegerTree b = shown("b", 2);
+ IntegerTree root1 = shown("", 0, a, b);
+
+ //
+ root1.insert(0, b);
+ assertAllChildren(root1, 2, 1);
+ }
+
+ public void testInsertMove2()
+ {
+ IntegerTree a = shown("a", 1);
+ IntegerTree root1 = shown("", 0, a);
+
+ //
+ root1.insert(null, a);
+ assertAllChildren(root1, 1);
+
+ //
+ root1.insert(0, a);
+ assertAllChildren(root1, 1);
+ }
+
+ public void testInsertMove3()
+ {
+ IntegerTree a = shown("a", 1);
+ IntegerTree root1 = shown("", 0, a);
+ IntegerTree root2 = shown("", 0);
+
+ //
+ root2.insert(0, a);
+ assertAllChildren(root1);
+ assertAllChildren(root2, 1);
+ assertAllChildren(root2, "a");
+ assertSame(root2, a.getParent());
+ }
+
+ public void testInsertReorder1()
+ {
+ IntegerTree a = shown("a", 1);
+ IntegerTree root1 = shown("", 0, a);
+
+ //
+ root1.insert(0, a);
+ assertAllChildren(root1, 1);
+ assertAllChildren(root1, "a");
+ assertSame(root1, a.getParent());
+ }
+
+ public void testInsertReorder2()
+ {
+ IntegerTree a = shown("a", 1);
+ IntegerTree root1 = shown("", 0, a, shown("b", 2));
+
+ //
+ root1.insert(2, a);
+ assertAllChildren(root1, 2, 1);
+ assertAllChildren(root1, "b", "a");
+ assertSame(root1, a.getParent());
+
+ //
+ root1.insert(0, a);
+ assertAllChildren(root1, 1, 2);
+ assertAllChildren(root1, "a", "b");
+ assertSame(root1, a.getParent());
+ }
+
+ public void testGetByKey()
+ {
+ IntegerTree root = shown("", 0, shown("a", 1),
hidden("b", 2), shown("c", 3));
+ assertAllChildren(root, 1, 2, 3);
+ assertAllChildren(root, "a", "b", "c");
+
+ //
+ assertEquals(1, (int)root.get("a").getElement());
+ assertNull(root.get("b"));
+ assertNull(root.get("d"));
+ }
+
+ public void testGetByKeyWithNoChildren()
+ {
+ IntegerTree root = shown("", 0, (IntegerTree[])null);
+ assertFalse(root.hasTrees());
+
+ //
+ try
+ {
+ root.get("a");
+ fail();
+ }
+ catch (IllegalStateException ignore)
+ {
+ assertFalse(root.hasTrees());
+ }
+ }
+
+ public void testRemove()
+ {
+ IntegerTree root = shown("", 0, hidden("a", 1),
shown("b", 2), shown("c", 3));
+ assertAllChildren(root, 1, 2, 3);
+ assertAllChildren(root, "a", "b", "c");
+
+ //
+ assertNull(root.remove("a"));
+ assertAllChildren(root, 1, 2, 3);
+ assertAllChildren(root, "a", "b", "c");
+
+ //
+ IntegerTree b = root.remove("b");
+ assertNull(b.getParent());
+ assertNull(b.getPrevious());
+ assertNull(b.getNext());
+ assertEquals(2, (int)b.getElement());
+ assertAllChildren(root, 1, 3);
+ assertAllChildren(root, "a", "c");
+ }
+
+ public void testRemoveLast()
+ {
+ IntegerTree root = shown("", 0, shown("a", 1),
shown("b", 2));
+ assertAllChildren(root, 1, 2);
+ assertAllChildren(root, "a", "b");
+
+ //
+ assertEquals(2, (int)root.remove("b").getElement());
+ assertAllChildren(root, 1);
+ assertAllChildren(root, "a");
+ assertEquals(1, (int)root.getLast().getElement());
+ }
+
+ public void testRemoveWithNoChildren()
+ {
+ IntegerTree root = shown("", 0, (IntegerTree[])null);
+ assertFalse(root.hasTrees());
+
+ //
+ try
+ {
+ root.remove("a");
+ fail();
+ }
+ catch (IllegalStateException ignore)
+ {
+ assertFalse(root.hasTrees());
+ }
+ }
+
+ public void testRename()
+ {
+ IntegerTree root = shown("", 0, shown("a", 1),
hidden("b", 2), shown("c", 3));
+ assertAllChildren(root, 1, 2, 3);
+ assertAllChildren(root, "a", "b", "c");
+
+ //
+ root.rename("a", "a");
+ assertAllChildren(root, 1, 2, 3);
+ assertAllChildren(root, "a", "b", "c");
+
+ //
+ root.rename("a", "d");
+ assertAllChildren(root, 1, 2, 3);
+ assertAllChildren(root, "d", "b", "c");
+ }
+
+ public void testRenameWithNoChildren()
+ {
+ IntegerTree root = shown("", 0, (IntegerTree[])null);
+ assertFalse(root.hasTrees());
+
+ //
+ try
+ {
+ root.rename("a", "b");
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ assertFalse(root.hasTrees());
+ }
+ }
+
+ public void testRenameWithNonExisting()
+ {
+ IntegerTree root = shown("", 0, shown("a", 1),
hidden("b", 2), shown("c", 3));
+ assertAllChildren(root, 1, 2, 3);
+ assertAllChildren(root, "a", "b", "c");
+
+ //
+ try
+ {
+ root.rename("d", "e");
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ assertAllChildren(root, 1, 2, 3);
+ assertAllChildren(root, "a", "b", "c");
+ }
+ }
+
+ public void testRenameWithExisting()
+ {
+ IntegerTree root = shown("", 0, shown("a", 1),
hidden("b", 2), shown("c", 3));
+ assertAllChildren(root, 1, 2, 3);
+ assertAllChildren(root, "a", "b", "c");
+
+ //
+ try
+ {
+ root.rename("a", "c");
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ assertAllChildren(root, 1, 2, 3);
+ assertAllChildren(root, "a", "b", "c");
+ }
+ }
+
+ public void testRenameHidden()
+ {
+ IntegerTree root = shown("", 0, shown("a", 1),
hidden("b", 2), shown("c", 3));
+ assertAllChildren(root, 1, 2, 3);
+ assertAllChildren(root, "a", "b", "c");
+
+ //
+ try
+ {
+ root.rename("b", "d");
+ fail();
+ }
+ catch (IllegalArgumentException e)
+ {
+ assertAllChildren(root, 1, 2, 3);
+ assertAllChildren(root, "a", "b", "c");
+ }
+ }
+
+ public void testGetByIndex1()
+ {
+ IntegerTree root = shown("", 0, shown("a", 1),
hidden("b", 2), shown("c", 3));
+
+ //
+ assertEquals(1, (int)root.get(0).getElement());
+ assertEquals(3, (int)root.get(1).getElement());
+ try
+ {
+ root.get(2);
+ fail();
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ }
+ }
+
+ public void testGetByIndex2()
+ {
+ IntegerTree root = shown("", 0, hidden("a", 1),
shown("b", 2), hidden("c", 3));
+
+ //
+ assertEquals(2, (int)root.get(0).getElement());
+ try
+ {
+ root.get(1);
+ fail();
+ }
+ catch (IndexOutOfBoundsException e)
+ {
+ }
+ }
+
+ public void testGetByIndexWithNoChildren()
+ {
+ IntegerTree root = shown("", 0, (IntegerTree[])null);
+
+ //
+ try
+ {
+ root.get(0);
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ }
+ }
+
+ public void testIteratorRemove()
+ {
+ IntegerTree root = shown("", 0, shown("a", 1));
+ Iterator<IntegerTree> it = root.getTrees().iterator();
+
+ //
+ try
+ {
+ it.remove();
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ }
+
+ //
+ IntegerTree a = it.next();
+ it.remove();
+ assertNull(a.getParent());
+ assertFalse(it.hasNext());
+ assertAllChildren(root);
+ }
+
+ public void testListIterator1()
+ {
+ IntegerTree a = shown("a", 1);
+ IntegerTree root = shown("", 0, a);
+
+ //
+ ListIterator<IntegerTree> i = root.listIterator();
+ assertTrue(i.hasNext());
+ assertEquals(0, i.nextIndex());
+ assertFalse(i.hasPrevious());
+ assertEquals(-1, i.previousIndex());
+
+ //
+ assertSame(a, i.next());
+ assertFalse(i.hasNext());
+ assertEquals(1, i.nextIndex());
+ assertTrue(i.hasPrevious());
+ assertEquals(0, i.previousIndex());
+
+ //
+ assertSame(a, i.previous());
+ assertTrue(i.hasNext());
+ assertEquals(0, i.nextIndex());
+ assertFalse(i.hasPrevious());
+ assertEquals(-1, i.previousIndex());
+ }
+
+ public void testListIterator2()
+ {
+ IntegerTree a = shown("a", 1);
+ IntegerTree b = shown("b", 2);
+ IntegerTree root = shown("", 0, a, b);
+
+ //
+ ListIterator<IntegerTree> i = root.listIterator();
+ assertTrue(i.hasNext());
+ assertEquals(0, i.nextIndex());
+ assertFalse(i.hasPrevious());
+ assertEquals(-1, i.previousIndex());
+ assertSame(a, i.next());
+ assertTrue(i.hasNext());
+ assertEquals(1, i.nextIndex());
+ assertTrue(i.hasPrevious());
+ assertEquals(0, i.previousIndex());
+ assertSame(b, i.next());
+ assertFalse(i.hasNext());
+ assertEquals(2, i.nextIndex());
+ assertTrue(i.hasPrevious());
+ assertEquals(1, i.previousIndex());
+ i.remove();
+ assertFalse(i.hasNext());
+ assertEquals(1, i.nextIndex());
+ assertTrue(i.hasPrevious());
+ assertEquals(0, i.previousIndex());
+ }
+
+ public void testListIterator3()
+ {
+ // Remove middle
+ IntegerTree a = shown("a", 1);
+ IntegerTree b = shown("b", 2);
+ IntegerTree c = shown("c", 3);
+ IntegerTree root = shown("", 0, a, b, c);
+ ListIterator<IntegerTree> i = root.listIterator();
+ i.next();
+ i.next();
+ i.remove();
+ assertTrue(i.hasNext());
+ assertEquals(1, i.nextIndex());
+ assertTrue(i.hasPrevious());
+ assertEquals(0, i.previousIndex());
+ assertSame(c, i.next());
+
+ // Remove middle
+ root = shown("", 0, a = shown("a", 1), b = shown("b",
2), c = shown("c", 3));
+ i = root.listIterator();
+ i.next();
+ i.next();
+ i.next();
+ i.previous();
+ i.previous();
+ i.remove();
+ assertTrue(i.hasNext());
+ assertEquals(1, i.nextIndex());
+ assertTrue(i.hasPrevious());
+ assertEquals(0, i.previousIndex());
+ assertSame(c, i.next());
+
+ // Remove middle
+ root = shown("", 0, a = shown("a", 1), b = shown("b",
2), c = shown("c", 3));
+ i = root.listIterator();
+ i.next();
+ i.next();
+ i.remove();
+ assertTrue(i.hasNext());
+ assertEquals(1, i.nextIndex());
+ assertTrue(i.hasPrevious());
+ assertEquals(0, i.previousIndex());
+ assertSame(a, i.previous());
+
+ // Remove middle
+ root = shown("", 0, a = shown("a", 1), b = shown("b",
2), c = shown("c", 3));
+ i = root.listIterator();
+ i.next();
+ i.next();
+ i.next();
+ i.previous();
+ i.previous();
+ i.remove();
+ assertTrue(i.hasNext());
+ assertEquals(1, i.nextIndex());
+ assertTrue(i.hasPrevious());
+ assertEquals(0, i.previousIndex());
+ assertSame(a, i.previous());
+ }
+
+ public void testCount()
+ {
+ IntegerTree root = shown("", 0, (IntegerTree[])null);
+ assertEquals(-1, root.getCount());
+ IntegerTree a = shown("a", 1);
+ root.setTrees(Collections.singleton(a));
+ assertEquals(1, root.getCount());
+ a.setHidden(true);
+ assertEquals(0, root.getCount());
+ a.remove("a");
+ assertEquals(0, root.getCount());
+ root.setTrees(null);
+ assertEquals(-1, root.getCount());
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public void testListIteratorNavigation()
+ {
+ IntegerTree root = shown("", 0, shown("1", 1),
shown("2", 2), shown("3", 3), shown("4", 4),
shown("5", 5));
+ ListIterator<IntegerTree> it = root.listIterator();
+ assertTrue(it.hasNext());
+ assertTrue(!it.hasPrevious());
+ assertEquals(-1, it.previousIndex());
+ assertEquals(0, it.nextIndex());
+ assertEquals(1, it.next().value);
+ assertTrue(it.hasNext());
+ assertTrue(it.hasPrevious());
+ assertEquals(0, it.previousIndex());
+ assertEquals(1, it.nextIndex());
+ assertEquals(1, it.previous().value);
+ assertTrue(it.hasNext());
+ assertTrue(!it.hasPrevious());
+ assertEquals(-1, it.previousIndex());
+ assertEquals(0, it.nextIndex());
+ assertEquals(1, it.next().value);
+ assertTrue(it.hasNext());
+ assertTrue(it.hasPrevious());
+ assertEquals(0, it.previousIndex());
+ assertEquals(1, it.nextIndex());
+ assertEquals(2, it.next().value);
+ assertTrue(it.hasNext());
+ assertTrue(it.hasPrevious());
+ assertEquals(1, it.previousIndex());
+ assertEquals(2, it.nextIndex());
+ assertEquals(2, it.previous().value);
+ assertTrue(it.hasNext());
+ assertTrue(it.hasPrevious());
+ assertEquals(0, it.previousIndex());
+ assertEquals(1, it.nextIndex());
+ assertEquals(2, it.next().value);
+ assertTrue(it.hasNext());
+ assertTrue(it.hasPrevious());
+ assertEquals(1, it.previousIndex());
+ assertEquals(2, it.nextIndex());
+ assertEquals(3, it.next().value);
+ assertTrue(it.hasNext());
+ assertTrue(it.hasPrevious());
+ assertEquals(2, it.previousIndex());
+ assertEquals(3, it.nextIndex());
+ assertEquals(4, it.next().value);
+ assertTrue(it.hasNext());
+ assertTrue(it.hasPrevious());
+ assertEquals(3, it.previousIndex());
+ assertEquals(4, it.nextIndex());
+ assertEquals(5, it.next().value);
+ assertTrue(!it.hasNext());
+ assertTrue(it.hasPrevious());
+ assertEquals(4, it.previousIndex());
+ assertEquals(5, it.nextIndex());
+ assertEquals(5, it.previous().value);
+ assertTrue(it.hasNext());
+ assertTrue(it.hasPrevious());
+ assertEquals(3, it.previousIndex());
+ assertEquals(4, it.nextIndex());
+ assertEquals(4, it.previous().value);
+ assertTrue(it.hasNext());
+ assertTrue(it.hasPrevious());
+ assertEquals(2, it.previousIndex());
+ assertEquals(3, it.nextIndex());
+ assertEquals(3, it.previous().value);
+ assertTrue(it.hasNext());
+ assertTrue(it.hasPrevious());
+ assertEquals(1, it.previousIndex());
+ assertEquals(2, it.nextIndex());
+ assertEquals(2, it.previous().value);
+ assertTrue(it.hasNext());
+ assertTrue(it.hasPrevious());
+ assertEquals(0, it.previousIndex());
+ assertEquals(1, it.nextIndex());
+ assertEquals(1, it.previous().value);
+ assertTrue(it.hasNext());
+ assertTrue(!it.hasPrevious());
+ assertEquals(-1, it.previousIndex());
+ assertEquals(0, it.nextIndex());
+ }
+
+ /*
+ @Override
+ @SuppressWarnings("unchecked")
+ public void testListIteratorSet() {
+ list.add((E) "1");
+ list.add((E) "2");
+ list.add((E) "3");
+ list.add((E) "4");
+ list.add((E) "5");
+
+ ListIterator<E> it = list.listIterator();
+ assertEquals("1", it.next());
+ it.set((E) "a");
+ assertEquals("a", it.previous());
+ it.set((E) "A");
+ assertEquals("A", it.next());
+ assertEquals("2", it.next());
+ it.set((E) "B");
+ assertEquals("3", it.next());
+ assertEquals("4", it.next());
+ it.set((E) "D");
+ assertEquals("5", it.next());
+ it.set((E) "E");
+ assertEquals("[A, B, 3, D, E]", list.toString());
+ }
+ */
+
+ public void testListIteratorRemove()
+ {
+ IntegerTree root = shown("", 0, shown("1", 1),
shown("2", 2), shown("3", 3), shown("4", 4),
shown("5", 5));
+ ListIterator<IntegerTree> it = root.listIterator();
+ try
+ {
+ it.remove();
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // expected
+ }
+ assertEquals(1, it.next().value);
+ assertEquals(2, it.next().value);
+ assertAllChildren(root, 1, 2, 3, 4, 5);
+ it.remove();
+ assertAllChildren(root, 1, 3, 4, 5);
+ assertEquals(3, it.next().value);
+ assertEquals(3, it.previous().value);
+ assertEquals(1, it.previous().value);
+ it.remove();
+ assertAllChildren(root, 3, 4, 5);
+ assertTrue(!it.hasPrevious());
+ assertEquals(3, it.next().value);
+ it.remove();
+ assertAllChildren(root, 4, 5);
+ try
+ {
+ it.remove();
+ fail();
+ }
+ catch (IllegalStateException e)
+ {
+ // expected
+ }
+ assertEquals(4, it.next().value);
+ assertEquals(5, it.next().value);
+ it.remove();
+ assertAllChildren(root, 4);
+ assertEquals(4, it.previous().value);
+ it.remove();
+ assertAllChildren(root);
+ }
+
+ public void testListIteratorAdd()
+ {
+ IntegerTree root = shown("", 0);
+ ListIterator<IntegerTree> it = root.listIterator();
+ it.add(shown("a", 1));
+ assertEquals(0, it.previousIndex());
+ assertEquals(1, it.nextIndex());
+ assertAllChildren(root, 1);
+ it.add(shown("c", 3));
+ assertEquals(1, it.previousIndex());
+ assertEquals(2, it.nextIndex());
+ assertAllChildren(root, 1, 3);
+ it.add(shown("e", 5));
+ assertEquals(2, it.previousIndex());
+ assertEquals(3, it.nextIndex());
+ assertAllChildren(root, 1, 3, 5);
+ assertEquals(5, it.previous().value);
+ assertEquals(1, it.previousIndex());
+ assertEquals(2, it.nextIndex());
+ it.add(shown("d", 4));
+ assertEquals(2, it.previousIndex());
+ assertEquals(3, it.nextIndex());
+ assertAllChildren(root, 1, 3, 4, 5);
+ assertEquals(4, it.previous().value);
+ assertEquals(1, it.previousIndex());
+ assertEquals(2, it.nextIndex());
+ assertEquals(3, it.previous().value);
+ assertEquals(0, it.previousIndex());
+ assertEquals(1, it.nextIndex());
+ it.add(shown("b", 2));
+ assertEquals(1, it.previousIndex());
+ assertEquals(2, it.nextIndex());
+ assertAllChildren(root, 1, 2, 3, 4, 5);
+ }
+
+ public void testListIteratorMove()
+ {
+ IntegerTree root = shown("", 0, shown("a", 1),
shown("b", 2), shown("c", 3));
+ ListIterator<IntegerTree> it = root.listIterator();
+ it.add(root.get(2));
+ assertAllChildren(root, 3, 1, 2);
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/navigation/TestNavigationService.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/navigation/TestNavigationService.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/navigation/TestNavigationService.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,1077 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+import junit.framework.AssertionFailedError;
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.portal.config.AbstractPortalTest;
+import org.exoplatform.portal.config.DataStorage;
+import org.exoplatform.portal.config.model.PageNavigation;
+import org.exoplatform.portal.config.model.PortalConfig;
+import org.exoplatform.portal.mop.Described;
+import org.exoplatform.portal.mop.SiteKey;
+import org.exoplatform.portal.mop.SiteType;
+import org.exoplatform.portal.mop.Visibility;
+import org.exoplatform.portal.pom.config.POMSessionManager;
+import org.exoplatform.portal.pom.data.MappedAttributes;
+import org.gatein.mop.api.workspace.ObjectType;
+import org.gatein.mop.api.workspace.Site;
+import org.gatein.mop.core.api.MOPService;
+
+import javax.jcr.NodeIterator;
+import javax.jcr.Session;
+import java.util.Iterator;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestNavigationService extends AbstractPortalTest
+{
+
+ /** . */
+ private POMSessionManager mgr;
+
+ /** . */
+ private NavigationServiceImpl service;
+
+ private DataStorage dataStorage;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ //
+ PortalContainer container = PortalContainer.getInstance();
+ mgr =
(POMSessionManager)container.getComponentInstanceOfType(POMSessionManager.class);
+ service = new NavigationServiceImpl(mgr);
+ dataStorage =
(DataStorage)container.getComponentInstanceOfType(DataStorage.class);
+ //
+ begin();
+ }
+
+
+ @Override
+ protected void end(boolean save)
+ {
+ if (save)
+ {
+ try
+ {
+ startService();
+ super.end(save);
+ }
+ finally
+ {
+ stopService();
+ }
+ }
+ else
+ {
+ super.end(save);
+ }
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ end();
+ super.tearDown();
+ }
+
+ private void startService()
+ {
+ try
+ {
+ begin();
+ service.start();
+ end();
+ }
+ catch (Exception e)
+ {
+ AssertionFailedError afe = new AssertionFailedError();
+ afe.initCause(e);
+ throw afe;
+ }
+ }
+
+ private void stopService()
+ {
+ begin();
+ service.stop();
+ end();
+ }
+
+ public void testNonExistingSite() throws Exception
+ {
+ assertNull(service.loadNavigation(SiteKey.portal("non_existing")));
+ }
+
+ public void testNavigationInvalidationByRootId() throws Exception
+ {
+ mgr.getPOMService().getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"get_navigation");
+ end(true);
+
+ //
+ begin();
+ SiteKey key = new SiteKey(SiteType.PORTAL, "get_navigation");
+ Navigation nav = service.loadNavigation(key);
+ assertNotNull(nav);
+ assertEquals(key, nav.getKey());
+ assertNull(nav.getState());
+ end();
+
+ //
+ begin();
+ mgr.getPOMService().getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"get_navigation").getRootNavigation().addChild("default");
+ end(true);
+
+ //
+ begin();
+ nav = service.loadNavigation(key);
+ assertNotNull(nav);
+ assertEquals(1, (int)nav.getState().getPriority());
+ assertEquals(key, nav.getKey());
+ assertNotNull(nav.getRootId());
+ end();
+
+ //
+ begin();
+ mgr.getPOMService().getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"get_navigation").getRootNavigation().getChild("default").destroy();
+ end(true);
+
+ //
+ begin();
+ nav = service.loadNavigation(key);
+ assertNotNull(nav);
+ assertEquals(key, nav.getKey());
+ assertNull(nav.getState());
+ }
+
+ public void testNavigationInvalidationByPriority()
+ {
+ mgr.getPOMService().getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"invalidation_by_priority_change").getRootNavigation().addChild("default");
+ end(true);
+
+ //
+ begin();
+ SiteKey key = new SiteKey(SiteType.PORTAL,
"invalidation_by_priority_change");
+ Navigation nav = service.loadNavigation(key);
+ assertEquals(1, (int)nav.getState().getPriority());
+ end();
+
+ //
+ begin();
+ Site site =
mgr.getPOMService().getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"invalidation_by_priority_change");
+
site.getRootNavigation().getChild("default").getAttributes().setValue(MappedAttributes.PRIORITY,
2);
+ end(true);
+
+ //
+ begin();
+ nav = service.loadNavigation(key);
+ assertEquals(2, (int)nav.getState().getPriority());
+ end();
+
+ //
+ begin();
+ site =
mgr.getPOMService().getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"invalidation_by_priority_change");
+
site.getRootNavigation().getChild("default").getAttributes().setValue(MappedAttributes.PRIORITY,
4);
+ end(true);
+
+ //
+ begin();
+ nav = service.loadNavigation(key);
+ assertEquals(4, (int)nav.getState().getPriority());
+ end();
+
+ //
+ begin();
+ site =
mgr.getPOMService().getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"invalidation_by_priority_change");
+
site.getRootNavigation().getChild("default").getAttributes().setValue(MappedAttributes.PRIORITY,
null);
+ end(true);
+
+ //
+ begin();
+ nav = service.loadNavigation(key);
+ assertEquals(1, (int)nav.getState().getPriority());
+ }
+
+ public void testSaveNavigation() throws Exception
+ {
+ Navigation nav =
service.loadNavigation(SiteKey.portal("save_navigation"));
+ assertNull(nav);
+
+ //
+ mgr.getPOMService().getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"save_navigation");
+ end(true);
+
+ //
+ begin();
+ nav = service.loadNavigation(SiteKey.portal("save_navigation"));
+ assertNotNull(nav);
+ assertEquals(SiteKey.portal("save_navigation"), nav.getKey());
+ assertNull(nav.getState());
+ assertNull(nav.getRootId());
+
+ //
+ assertTrue(service.saveNavigation(nav.getKey(), new NavigationState(5)));
+ nav = service.loadNavigation(SiteKey.portal("save_navigation"));
+ assertNotNull(nav.getState());
+ assertEquals(5, nav.getState().getPriority().intValue());
+ end(true);
+
+ //
+ begin();
+ nav = service.loadNavigation(SiteKey.portal("save_navigation"));
+ assertNotNull(nav);
+ assertEquals(SiteKey.portal("save_navigation"), nav.getKey());
+ assertEquals(5, (int)nav.getState().getPriority());
+ assertNotNull(nav.getRootId());
+
+ //
+ assertTrue(service.saveNavigation(nav.getKey(), null));
+ nav = service.loadNavigation(SiteKey.portal("save_navigation"));
+ assertNull(nav.getState());
+ assertNull(nav.getRootId());
+ end(true);
+
+ //
+ begin();
+ nav = service.loadNavigation(SiteKey.portal("save_navigation"));
+ assertNotNull(nav);
+ assertNull(nav.getState());
+ assertNull(nav.getRootId());
+
+ //
+ assertFalse(service.saveNavigation(nav.getKey(), null));
+ }
+
+
+ public void testLoadSingleScope() throws Exception
+ {
+ Navigation nav = service.loadNavigation(SiteKey.portal("classic"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.SINGLE);
+ assertNull(root.getChildren());
+ assertEquals("default", root.getName());
+ try
+ {
+ root.getChild(0);
+ fail();
+ }
+ catch (IllegalStateException ignore)
+ {
+ }
+ }
+
+ public void testLoadChildrenScope() throws Exception
+ {
+ Navigation nav = service.loadNavigation(SiteKey.portal("classic"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ assertEquals("default", root.getName());
+ Iterator<? extends Node> i = root.getChildren().iterator();
+ assertTrue(i.hasNext());
+ Node home = i.next();
+ assertSame(home, root.getChild(0));
+ assertNull(home.getChildren());
+ assertEquals("home", home.getName());
+ assertTrue(i.hasNext());
+ Node webexplorer = i.next();
+ assertNull(webexplorer.getChildren());
+ assertSame(webexplorer, root.getChild(1));
+ assertEquals("webexplorer", webexplorer.getName());
+ assertFalse(i.hasNext());
+ }
+
+ public void testLoadCustomScope() throws Exception
+ {
+ Navigation nav = service.loadNavigation(SiteKey.portal("large"));
+ Node root = service.loadNode(Node.MODEL, nav, new Scope()
+ {
+ public Visitor get()
+ {
+ return new Visitor()
+ {
+ public VisitMode visit(int depth, String id, String name, NodeState
state)
+ {
+ boolean use = false;
+ switch (depth)
+ {
+ case 0:
+ use = "default".equals(name);
+ break;
+ case 1:
+ use = "b".equals(name);
+ break;
+ case 2:
+ use = "d".equals(name);
+ break;
+ }
+ return use ? VisitMode.ALL_CHILDREN : VisitMode.NO_CHILDREN;
+ }
+ };
+ }
+ });
+ assertNull(root.getChild("a").getChildren());
+ Node b = root.getChild("b");
+ Node d = b.getChild("d");
+ assertNull(d.getChild("e").getChildren());
+ }
+
+ public void testLoadNode() throws Exception
+ {
+ Navigation nav = service.loadNavigation(SiteKey.portal("large"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ Node a = root.getChild("a");
+ assertNotNull(a);
+ assertNull(a.getChildren());
+ assertSame(a, service.loadNode(Node.MODEL, a, Scope.CHILDREN));
+ assertNotNull(a.getChildren());
+ assertEquals(1, a.getChildren().size());
+ Node c = a.getChild("c");
+ assertEquals("c", c.getName());
+ assertSame(a, c.getParent());
+ assertSame(a, service.loadNode(Node.MODEL, a, Scope.SINGLE));
+ assertNotNull(a.getChildren());
+ assertEquals(1, a.getChildren().size());
+ assertSame(c, a.getChild("c"));
+ assertNotNull(c.getParent());
+ }
+
+ public void testState() throws Exception
+ {
+ Navigation nav = service.loadNavigation(SiteKey.portal("test"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.ALL);
+ assertEquals(5, root.getChildrenCount());
+ Node child1 = root.getChild("node_name");
+ Node child2 = root.getChild("node_name4");
+ assertEquals("node_name", child1.getName());
+ assertEquals("node_uri", child1.getContext().getState().getURI());
+ assertEquals("node_label", child1.getContext().getState().getLabel());
+ assertEquals("portal::test::test1",
child1.getContext().getState().getPageRef());
+ assertEquals(Visibility.TEMPORAL, child1.getContext().getState().getVisibility());
+ assertEquals(953602380000L,
child1.getContext().getState().getStartPublicationTime());
+ assertEquals(1237599180000L,
child1.getContext().getState().getEndPublicationTime());
+ assertEquals("node_name4", child2.getName());
+ assertEquals("node_uri", child2.getContext().getState().getURI());
+ assertEquals("node_label4", child2.getContext().getState().getLabel());
+ assertEquals("portal::test::test1",
child2.getContext().getState().getPageRef());
+ assertEquals(Visibility.DISPLAYED,
child2.getContext().getState().getVisibility());
+ }
+
+ public void testHiddenNode() throws Exception
+ {
+ MOPService mop = mgr.getPOMService();
+ Site portal = mop.getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"hidden_node");
+ org.gatein.mop.api.workspace.Navigation defaultNav =
portal.getRootNavigation().addChild("default");
+ defaultNav.addChild("a");
+ defaultNav.addChild("b");
+ end(true);
+
+ //
+ begin();
+ Navigation nav = service.loadNavigation(SiteKey.portal("hidden_node"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ root.filter(new NodeFilter()
+ {
+ public boolean accept(int depth, String id, String name, NodeState state)
+ {
+ return !(depth == 1 && "a".equals(name));
+ }
+ });
+
+ //
+ assertEquals(1, root.getChildren().size());
+ assertNull(root.getChild("a"));
+ assertEquals("b", root.getChild(0).getName());
+ try
+ {
+ root.getChild(1);
+ fail();
+ }
+ catch (IndexOutOfBoundsException ignore)
+ {
+ }
+ }
+
+ public void testNodeInvalidationByRemoval() throws Exception
+ {
+ //
+ MOPService mop = mgr.getPOMService();
+ Site portal = mop.getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"invalidation_by_removal");
+ portal.getRootNavigation().addChild("default");
+ end(true);
+
+ //
+ begin();
+ Navigation nav =
service.loadNavigation(SiteKey.portal("invalidation_by_removal"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.SINGLE);
+ assertNotNull(root);
+ end();
+
+ //
+ begin();
+ mop.getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"invalidation_by_removal").getRootNavigation().getChild("default").destroy();
+ end(true);
+
+ //
+ begin();
+ root = service.loadNode(Node.MODEL, nav, Scope.SINGLE);
+ assertNull(root);
+ }
+
+ public void testNodeInvalidationByChild() throws Exception
+ {
+ // Create a navigation
+ MOPService mop = mgr.getPOMService();
+ Site portal = mop.getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"invalidation_by_child");
+ portal.getRootNavigation().addChild("default");
+ end(true);
+
+ // Put the navigation in the cache
+ begin();
+ Navigation nav =
service.loadNavigation(SiteKey.portal("invalidation_by_child"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ Iterator<? extends Node> iterator = root.getChildren().iterator();
+ assertFalse(iterator.hasNext());
+ end();
+
+ //
+ begin();
+ mop.getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"invalidation_by_child").getRootNavigation().getChild("default").addChild("new");
+ end(true);
+
+ //
+ begin();
+ root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ iterator = root.getChildren().iterator();
+ iterator.next();
+ assertFalse(iterator.hasNext());
+ end();
+
+ //
+ begin();
+ mop.getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"invalidation_by_child").getRootNavigation().getChild("default").getChild("new").destroy();
+ end(true);
+
+ //
+ begin();
+ root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ iterator = root.getChildren().iterator();
+ assertFalse(iterator.hasNext());
+ }
+
+ public void testNodeInvalidationByProperty() throws Exception
+ {
+ // Create a navigation
+ MOPService mop = mgr.getPOMService();
+ Site portal = mop.getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"invalidation_by_propertychange");
+ portal.getRootNavigation().addChild("default");
+ end(true);
+
+ //
+ begin();
+ Navigation nav =
service.loadNavigation(SiteKey.portal("invalidation_by_propertychange"));
+ Node defaultNode = service.loadNode(Node.MODEL, nav, Scope.SINGLE);
+ assertNull(defaultNode.getContext().getState().getLabel());
+ end();
+
+ //
+ begin();
+ Described defaultDescribed =
mop.getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"invalidation_by_propertychange").getRootNavigation().getChild("default").adapt(Described.class);
+ defaultDescribed.setName("bilto");
+ end(true);
+
+ //
+ begin();
+ defaultNode = service.loadNode(Node.MODEL, nav, Scope.SINGLE);
+ assertEquals("bilto", defaultNode.getContext().getState().getLabel());
+ end();
+
+ //
+ begin();
+ defaultDescribed = mop.getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"invalidation_by_propertychange").getRootNavigation().getChild("default").adapt(Described.class);
+ defaultDescribed.setName("bilta");
+ end(true);
+
+ //
+ begin();
+ defaultNode = service.loadNode(Node.MODEL, nav, Scope.SINGLE);
+ assertEquals("bilta", defaultNode.getContext().getState().getLabel());
+ end();
+
+ //
+ begin();
+ defaultDescribed = mop.getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"invalidation_by_propertychange").getRootNavigation().getChild("default").adapt(Described.class);
+ defaultDescribed.setName(null);
+ end(true);
+
+ //
+ begin();
+ defaultNode = service.loadNode(Node.MODEL, nav, Scope.SINGLE);
+ assertNull(defaultNode.getContext().getState().getLabel());
+ }
+
+ public void testNodeInvalidationByAttribute() throws Exception
+ {
+ //
+ MOPService mop = mgr.getPOMService();
+ Site portal = mop.getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"invalidation_by_attribute");
+ portal.getRootNavigation().addChild("default");
+ end(true);
+
+ //
+ begin();
+ Navigation nav =
service.loadNavigation(SiteKey.portal("invalidation_by_attribute"));
+ Node defaultNode = service.loadNode(Node.MODEL, nav, Scope.SINGLE);
+ assertNull(defaultNode.getContext().getState().getURI());
+ end();
+
+ //
+ begin();
+ mop.getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"invalidation_by_attribute").getRootNavigation().getChild("default").getAttributes().setValue(MappedAttributes.URI,
"foo_uri");
+ end(true);
+
+ //
+ begin();
+ defaultNode = service.loadNode(Node.MODEL, nav, Scope.SINGLE);
+ assertEquals("foo_uri", defaultNode.getContext().getState().getURI());
+ end();
+
+ //
+ begin();
+ mop.getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"invalidation_by_attribute").getRootNavigation().getChild("default").getAttributes().setValue(MappedAttributes.URI,
"bar_uri");
+ end(true);
+
+ //
+ begin();
+ defaultNode = service.loadNode(Node.MODEL, nav, Scope.SINGLE);
+ assertEquals("bar_uri", defaultNode.getContext().getState().getURI());
+ end();
+
+ //
+ begin();
+ mop.getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"invalidation_by_attribute").getRootNavigation().getChild("default").getAttributes().setValue(MappedAttributes.URI,
null);
+ end(true);
+
+ //
+ begin();
+ defaultNode = service.loadNode(Node.MODEL, nav, Scope.SINGLE);
+ assertNull(defaultNode.getContext().getState().getURI());
+ }
+
+ public void testPendingChangesBypassCache() throws Exception
+ {
+ MOPService mop = mgr.getPOMService();
+ Site portal = mop.getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"pending_changes_bypass_cache");
+ portal.getRootNavigation().addChild("default");
+ end(true);
+
+ //
+ begin();
+ Navigation nav =
service.loadNavigation(SiteKey.portal("pending_changes_bypass_cache"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ root.addChild("foo");
+ service.saveNode(Node.MODEL, root);
+
+ //
+ root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ assertNotNull(root.getChild("foo"));
+ }
+
+ public void testAddChild() throws Exception
+ {
+ MOPService mop = mgr.getPOMService();
+ Site portal = mop.getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"add_child");
+ portal.getRootNavigation().addChild("default");
+ end(true);
+
+ //
+ begin();
+ Navigation nav = service.loadNavigation(SiteKey.portal("add_child"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ assertEquals(0, root.getChildrenCount());
+
+ //
+ Node foo = root.addChild("foo");
+ assertNull(foo.getId());
+ assertEquals("foo", foo.getName());
+ assertSame(foo, root.getChild("foo"));
+ assertEquals(1, root.getChildrenCount());
+ service.saveNode(Node.MODEL, root);
+ end(true);
+
+ //
+ begin();
+ root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ foo = root.getChild("foo");
+ assertNotNull(foo);
+ assertEquals(1, root.getChildrenCount());
+ assertEquals("foo", foo.getName());
+ }
+
+ public void testRemoveChild() throws Exception
+ {
+ MOPService mop = mgr.getPOMService();
+ Site portal = mop.getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"remove_child");
+
portal.getRootNavigation().addChild("default").addChild("foo");
+ end(true);
+
+ //
+ begin();
+ Navigation nav = service.loadNavigation(SiteKey.portal("remove_child"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ Node foo = root.getChild("foo");
+ assertNotNull(foo.getId());
+ assertEquals("foo", foo.getName());
+ assertSame(foo, root.getChild("foo"));
+
+ //
+ assertTrue(root.removeChild("foo"));
+ assertNull(root.getChild("foo"));
+ service.saveNode(Node.MODEL, root);
+ end(true);
+
+ //
+ begin();
+ root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ foo = root.getChild("foo");
+ assertNull(foo);
+ }
+
+ public void testReorderChild() throws Exception
+ {
+ MOPService mop = mgr.getPOMService();
+ Site portal = mop.getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"reorder_child");
+ org.gatein.mop.api.workspace.Navigation rootNavigation =
portal.getRootNavigation().addChild("default");
+ rootNavigation.addChild("foo");
+ rootNavigation.addChild("bar");
+ end(true);
+
+ //
+ begin();
+ Navigation nav =
service.loadNavigation(SiteKey.portal("reorder_child"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ Iterator<Node> i = root.getChildren().iterator();
+ Node foo = i.next();
+ assertNotNull(foo.getId());
+ assertEquals("foo", foo.getName());
+ assertSame(foo, root.getChild("foo"));
+ Node bar = i.next();
+ assertNotNull(bar.getId());
+ assertEquals("bar", bar.getName());
+ assertSame(bar, root.getChild("bar"));
+ assertFalse(i.hasNext());
+
+ //
+ root.addChild(foo);
+ service.saveNode(Node.MODEL, root);
+ end(true);
+
+ //
+ begin();
+ root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ i = root.getChildren().iterator();
+ bar = i.next();
+ assertNotNull(bar.getId());
+ assertEquals("bar", bar.getName());
+ assertSame(bar, root.getChild("bar"));
+ foo = i.next();
+ assertNotNull(foo.getId());
+ assertEquals("foo", foo.getName());
+ assertSame(foo, root.getChild("foo"));
+ assertFalse(i.hasNext());
+ }
+
+ public void _testReorderChild2() throws Exception
+ {
+ MOPService mop = mgr.getPOMService();
+ Site portal = mop.getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"reorder_child_2");
+ org.gatein.mop.api.workspace.Navigation rootNavigation =
portal.getRootNavigation().addChild("default");
+ rootNavigation.addChild("foo");
+ rootNavigation.addChild("bar");
+ rootNavigation.addChild("juu");
+ end(true);
+
+ //
+ begin();
+ Navigation nav =
service.loadNavigation(SiteKey.portal("reorder_child_2"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ assertEquals("bar", root.getChild(1).getName());
+ assertTrue(root.removeChild("bar"));
+ service.saveNode(Node.MODEL, root);
+ end(true);
+
+ //
+ begin();
+ root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ root.addChild("daa");
+ Node tab3 = root.getChild(2);
+ assertEquals("daa", tab3.getName());
+ service.saveNode(Node.MODEL, root);
+ end(true);
+
+ //
+ begin();
+ root = new NavigationServiceImpl(mgr).loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ for (Node child : root.getChildren())
+ {
+ System.out.println("child : " + child.getId());
+ }
+ tab3 = root.getChild(2);
+ assertEquals("daa", tab3.getName());
+
+ root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ for (Node child : root.getChildren())
+ {
+ System.out.println("child : " + child.getId());
+ }
+ tab3 = root.getChild(2);
+ assertEquals("daa", tab3.getName());
+ }
+
+ public void _testWeirdBug() throws Exception
+ {
+ MOPService mop = mgr.getPOMService();
+ Site portal = mop.getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"reorder_child_2");
+ org.gatein.mop.api.workspace.Navigation rootNavigation =
portal.getRootNavigation().addChild("default");
+ rootNavigation.addChild("foo");
+ rootNavigation.addChild("bar");
+ rootNavigation.addChild("juu");
+ end(true);
+
+ //
+ begin();
+ portal = mop.getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"reorder_child_2");
+ rootNavigation = portal.getRootNavigation().getChild("default");
+ rootNavigation.getChild("bar").destroy();
+ end(true);
+
+ //
+ begin();
+ portal = mop.getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"reorder_child_2");
+ rootNavigation = portal.getRootNavigation().getChild("default");
+ rootNavigation.addChild("daa");
+ end(true);
+
+ //
+ begin();
+ portal = mop.getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"reorder_child_2");
+ rootNavigation = portal.getRootNavigation().getChild("default");
+ org.gatein.mop.api.workspace.Navigation daa = rootNavigation.getChildren().get(2);
+ assertEquals("daa", daa.getName());
+ }
+
+ public void _testWeirdBug2() throws Exception
+ {
+ MOPService mop = mgr.getPOMService();
+ Session session = mop.getModel().getSession().getJCRSession();
+ javax.jcr.Node container = session.getRootNode().
+ getNode("mop:workspace/mop:portalsites").
+ addNode("mop:reorder_child_2").
+ getNode("mop:rootnavigation/mop:children").
+ addNode("mop:default").
+ getNode("mop:children");
+ container.addNode("mop:foo");
+ container.addNode("mop:bar");
+ container.addNode("mop:juu");
+ end(true);
+
+ //
+ begin();
+ session = mop.getModel().getSession().getJCRSession();
+ container =
session.getRootNode().getNode("mop:workspace/mop:portalsites/mop:reorder_child_2/mop:rootnavigation/mop:children/mop:default/mop:children");
+ container.getNode("mop:bar").remove();
+ end(true);
+
+ //
+ begin();
+ session = mop.getModel().getSession().getJCRSession();
+ container =
session.getRootNode().getNode("mop:workspace/mop:portalsites/mop:reorder_child_2/mop:rootnavigation/mop:children/mop:default/mop:children");
+ container.addNode("mop:daa");
+ container.orderBefore("mop:daa", null);
+ end(true);
+
+ //
+ begin();
+ container =
session.getRootNode().getNode("mop:workspace/mop:portalsites/mop:reorder_child_2/mop:rootnavigation/mop:children/mop:default/mop:children");
+ NodeIterator it = container.getNodes();
+ assertEquals("mop:foo", it.nextNode().getName());
+ assertEquals("mop:juu", it.nextNode().getName());
+ assertEquals("mop:daa", it.nextNode().getName());
+ assertFalse(it.hasNext());
+ }
+
+ public void testMoveChild() throws Exception
+ {
+ MOPService mop = mgr.getPOMService();
+ Site portal = mop.getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"move_child");
+ org.gatein.mop.api.workspace.Navigation rootNavigation =
portal.getRootNavigation().addChild("default");
+ rootNavigation.addChild("foo").addChild("juu");
+ rootNavigation.addChild("bar");
+ end(true);
+
+ //
+ begin();
+ Navigation nav = service.loadNavigation(SiteKey.portal("move_child"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.ALL);
+ Node foo = root.getChild("foo");
+ Node bar = root.getChild("bar");
+ Node juu = foo.getChild("juu");
+ bar.addChild(juu);
+ service.saveNode(Node.MODEL, root);
+ end(true);
+
+ //
+ begin();
+ root = service.loadNode(Node.MODEL, nav, Scope.ALL);
+ foo = root.getChild("foo");
+ juu = foo.getChild("juu");
+ assertNull(juu);
+ bar = root.getChild("bar");
+ juu = bar.getChild("juu");
+ assertNotNull(juu);
+ }
+
+ public void testRenameNode() throws Exception
+ {
+ MOPService mop = mgr.getPOMService();
+ Site portal = mop.getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"rename_node");
+ org.gatein.mop.api.workspace.Navigation rootNavigation =
portal.getRootNavigation().addChild("default");
+ rootNavigation.addChild("foo");
+ end(true);
+
+ //
+ begin();
+ Navigation nav = service.loadNavigation(SiteKey.portal("rename_node"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.ALL);
+ Node foo = root.getChild("foo");
+ foo.setName("foo");
+ service.saveNode(Node.MODEL, root);
+ end(true);
+
+ //
+ begin();
+ nav = service.loadNavigation(SiteKey.portal("rename_node"));
+ root = service.loadNode(Node.MODEL, nav, Scope.ALL);
+ foo = root.getChild("foo");
+ foo.setName("bar");
+ assertEquals("bar", foo.getName());
+ assertSame(foo, root.getChild("bar"));
+ service.saveNode(Node.MODEL, root);
+ assertEquals("bar", foo.getName());
+ assertSame(foo, root.getChild("bar"));
+ end(true);
+
+ //
+ begin();
+ root = service.loadNode(Node.MODEL, nav, Scope.ALL);
+ Node bar = root.getChild("bar");
+ assertNotNull(bar);
+ assertSame(bar, root.getChild("bar"));
+
+ //
+ root.addChild("foo");
+ try
+ {
+ bar.setName("foo");
+ fail();
+ }
+ catch (IllegalArgumentException ignore)
+ {
+ }
+ }
+
+ public void testSaveChildren() throws Exception
+ {
+ MOPService mop = mgr.getPOMService();
+ Site portal = mop.getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"save_children");
+ org.gatein.mop.api.workspace.Navigation rootNavigation =
portal.getRootNavigation().addChild("default");
+ rootNavigation.addChild("1");
+ rootNavigation.addChild("2");
+ rootNavigation.addChild("3");
+ rootNavigation.addChild("4");
+ rootNavigation.addChild("5");
+ end(true);
+
+ //
+ begin();
+ Navigation nav =
service.loadNavigation(SiteKey.portal("save_children"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ root.removeChild("5");
+ root.removeChild("2");
+ root.addChild(0, root.getChild("3"));
+ root.addChild(1, root.addChild("."));
+ service.saveNode(Node.MODEL, root);
+ Iterator<Node> i = root.getChildren().iterator();
+ assertEquals("3", i.next().getName());
+ assertEquals(".", i.next().getName());
+ assertEquals("1", i.next().getName());
+ assertEquals("4", i.next().getName());
+ assertFalse(i.hasNext());
+ end(true);
+
+ //
+ begin();
+ root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ i = root.getChildren().iterator();
+ assertEquals("3", i.next().getName());
+ assertEquals(".", i.next().getName());
+ assertEquals("1", i.next().getName());
+ assertEquals("4", i.next().getName());
+ assertFalse(i.hasNext());
+ }
+
+ public void testSaveRecursive() throws Exception
+ {
+ MOPService mop = mgr.getPOMService();
+ Site portal = mop.getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"save_recursive");
+ org.gatein.mop.api.workspace.Navigation rootNavigation =
portal.getRootNavigation().addChild("default");
+ rootNavigation.addChild("foo");
+ end(true);
+
+ //
+ begin();
+ Navigation nav =
service.loadNavigation(SiteKey.portal("save_recursive"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.ALL);
+ Node foo = root.getChild("foo");
+ Node bar = foo.addChild("bar");
+ bar.addChild("juu");
+ service.saveNode(Node.MODEL, root);
+ end(true);
+
+ //
+ begin();
+ root = service.loadNode(Node.MODEL, nav, Scope.ALL);
+ foo = root.getChild("foo");
+ bar = foo.getChild("bar");
+ assertNotNull(bar.getId());
+ Node juu = bar.getChild("juu");
+ assertNotNull(juu.getId());
+ }
+
+ public void testSaveState() throws Exception
+ {
+ MOPService mop = mgr.getPOMService();
+ Site portal = mop.getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"save_state");
+ portal.getRootNavigation().addChild("default");
+ end(true);
+
+ //
+ begin();
+ Navigation nav = service.loadNavigation(SiteKey.portal("save_state"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.SINGLE);
+ NodeState state = root.getState();
+ assertNull(state.getURI());
+ assertNull(state.getLabel());
+ assertEquals(-1, state.getStartPublicationTime());
+ assertEquals(-1, state.getEndPublicationTime());
+ long now = System.currentTimeMillis();
+ root.setState(new
NodeState.Builder().setURI("foo").setEndPublicationTime(now).setLabel("bar").capture());
+ service.saveNode(Node.MODEL, root);
+ end(true);
+
+ //
+ begin();
+ root = service.loadNode(Node.MODEL, nav, Scope.ALL);
+ state = root.getState();
+ assertEquals("foo", state.getURI());
+ assertEquals("bar", state.getLabel());
+ assertEquals(-1, state.getStartPublicationTime());
+ assertEquals(now, state.getEndPublicationTime());
+ assertNull(state.getVisibility());
+ }
+
+ public void testSaveStateOverwrite() throws Exception
+ {
+ MOPService mop = mgr.getPOMService();
+ Site portal = mop.getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"save_state_overwrite");
+ portal.getRootNavigation().addChild("default");
+ end(true);
+
+ //
+ begin();
+ Navigation nav =
service.loadNavigation(SiteKey.portal("save_state_overwrite"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ root.addChild("foo");
+ service.saveNode(Node.MODEL, root);
+ end(true);
+
+ //
+ begin();
+ root.addChild("bar");
+ service.saveNode(Node.MODEL, root);
+ end(true);
+
+ //
+ begin();
+ nav = service.loadNavigation(SiteKey.portal("save_state_overwrite"));
+ root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ assertEquals(2, root.getChildren().size());
+ }
+
+ public void testDelayBetweenServices() throws Exception
+ {
+ PortalConfig portalConfig = new PortalConfig();
+ portalConfig.setName("testPortalNavigation");
+ dataStorage.create(portalConfig);
+
+ PageNavigation pageNav = new PageNavigation();
+ pageNav.setOwnerType("portal");
+ pageNav.setOwnerId("testPortalNavigation");
+
+ dataStorage.create(pageNav);
+
+ pageNav = dataStorage.getPageNavigation("portal",
"testPortalNavigation");
+ assertNotNull(pageNav);
+ assertEquals("portal", pageNav.getOwnerType());
+ assertEquals("testPortalNavigation", pageNav.getOwnerId());
+
+ Navigation navigation =
service.loadNavigation(SiteKey.portal("testPortalNavigation"));
+
+ assertNotNull(navigation);
+ assertEquals(SiteType.PORTAL, navigation.getKey().getType());
+ assertEquals("testPortalNavigation", navigation.getKey().getName());
+ }
+
+ public void testRecreateNode() throws Exception
+ {
+ MOPService mop = mgr.getPOMService();
+ Site portal = mop.getModel().getWorkspace().addSite(ObjectType.PORTAL_SITE,
"recreate_node");
+
portal.getRootNavigation().addChild("default").addChild("foo");
+ end(true);
+
+ //
+ begin();
+ Navigation nav =
service.loadNavigation(SiteKey.portal("recreate_node"));
+ Node root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ String fooId = root.getChild("foo").getId();
+ assertTrue(root.removeChild("foo"));
+ assertNull(root.addChild("foo").getId());
+ service.saveNode(Node.MODEL, root);
+ end(true);
+
+ //
+ begin();
+ root = service.loadNode(Node.MODEL, nav, Scope.CHILDREN);
+ assertNotNull(root.getChild("foo").getId());
+ assertNotSame(fooId, root.getChild("foo").getId());
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/navigation/TestScope.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/navigation/TestScope.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/navigation/TestScope.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.navigation;
+
+import org.exoplatform.component.test.AbstractKernelTest;
+import org.exoplatform.portal.mop.Visibility;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestScope extends AbstractKernelTest
+{
+
+ public void testBranchShape()
+ {
+ NodeState nodeState = new NodeState(null, "", null, -1, -1,
Visibility.DISPLAYED, "portal::classic::home");
+
+ //
+ Scope scope1 = GenericScope.branchShape(new String[]{"a"},
Scope.CHILDREN);
+ Scope.Visitor visitor1 = scope1.get();
+ assertEquals(VisitMode.ALL_CHILDREN, visitor1.visit(0, "0", "",
nodeState));
+ assertEquals(VisitMode.ALL_CHILDREN, visitor1.visit(1, "1",
"a", nodeState));
+ assertEquals(VisitMode.NO_CHILDREN, visitor1.visit(1, "2", "b",
nodeState));
+
+ //
+ Scope scope2 = GenericScope.branchShape(new String[]{"a"},
Scope.SINGLE);
+ Scope.Visitor visitor2 = scope2.get();
+ assertEquals(VisitMode.ALL_CHILDREN, visitor2.visit(0, "0", "",
nodeState));
+ assertEquals(VisitMode.NO_CHILDREN, visitor2.visit(1, "1", "a",
nodeState));
+ assertEquals(VisitMode.NO_CHILDREN, visitor2.visit(1, "2", "b",
nodeState));
+
+ //
+ Scope scope3 = GenericScope.branchShape(new String[]{"a","c"},
Scope.SINGLE);
+ Scope.Visitor visitor3 = scope3.get();
+ assertEquals(VisitMode.ALL_CHILDREN, visitor3.visit(0, "0", "",
nodeState));
+ assertEquals(VisitMode.ALL_CHILDREN, visitor3.visit(1, "1",
"a", nodeState));
+ assertEquals(VisitMode.NO_CHILDREN, visitor3.visit(1, "2", "b",
nodeState));
+ assertEquals(VisitMode.NO_CHILDREN, visitor3.visit(2, "3", "c",
nodeState));
+ assertEquals(VisitMode.NO_CHILDREN, visitor3.visit(2, "4", "d",
nodeState));
+
+ //
+ Scope scope4 = GenericScope.branchShape(new String[]{"a"},
GenericScope.branchShape(new String[]{"b"}, Scope.CHILDREN));
+ Scope.Visitor visitor4 = scope4.get();
+ assertEquals(VisitMode.ALL_CHILDREN, visitor4.visit(0, "0", "",
nodeState));
+ assertEquals(VisitMode.ALL_CHILDREN, visitor4.visit(1, "1",
"a", nodeState));
+ assertEquals(VisitMode.ALL_CHILDREN, visitor4.visit(2, "2",
"b", nodeState));
+ assertEquals(VisitMode.NO_CHILDREN, visitor4.visit(2, "3", "c",
nodeState));
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/user/TestUserPortal.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/user/TestUserPortal.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/mop/user/TestUserPortal.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,1457 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.mop.user;
+
+import junit.framework.AssertionFailedError;
+
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.portal.config.AbstractPortalTest;
+import org.exoplatform.portal.config.DataStorage;
+import org.exoplatform.portal.config.UserPortalConfig;
+import org.exoplatform.portal.config.UserPortalConfigService;
+import org.exoplatform.portal.config.model.PortalConfig;
+import org.exoplatform.portal.mop.SiteKey;
+import org.exoplatform.portal.mop.Visibility;
+import org.exoplatform.portal.mop.navigation.GenericScope;
+import org.exoplatform.portal.mop.navigation.NodeFilter;
+import org.exoplatform.portal.mop.navigation.Scope;
+import org.exoplatform.portal.pom.config.POMDataStorage;
+import org.exoplatform.portal.pom.config.POMSessionManager;
+import org.exoplatform.services.listener.Event;
+import org.exoplatform.services.listener.Listener;
+import org.exoplatform.services.listener.ListenerService;
+import org.exoplatform.services.organization.OrganizationService;
+import org.exoplatform.services.security.Authenticator;
+import org.exoplatform.services.security.ConversationState;
+import org.gatein.common.i18n.MapResourceBundle;
+import org.gatein.mop.api.workspace.ObjectType;
+import org.gatein.mop.api.workspace.Site;
+
+import java.util.Collection;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.TimeZone;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestUserPortal extends AbstractPortalTest
+{
+
+ /** . */
+ private UserPortalConfigService userPortalConfigSer_;
+
+ /** . */
+ private OrganizationService orgService_;
+
+ /** . */
+ private DataStorage storage_;
+
+ /** . */
+ private POMSessionManager mgr;
+
+ /** . */
+ private Authenticator authenticator;
+
+ /** . */
+ private ListenerService listenerService;
+
+ /** . */
+ private LinkedList<Event> events;
+
+ /** . */
+ private boolean registered;
+
+ /** . */
+ private POMDataStorage mopStorage;
+
+ public TestUserPortal(String name)
+ {
+ super(name);
+
+ //
+ registered = false;
+ }
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ Listener listener = new Listener()
+ {
+ @Override
+ public void onEvent(Event event) throws Exception
+ {
+ events.add(event);
+ }
+ };
+
+ PortalContainer container = getContainer();
+ userPortalConfigSer_ =
+
(UserPortalConfigService)container.getComponentInstanceOfType(UserPortalConfigService.class);
+ orgService_ =
(OrganizationService)container.getComponentInstanceOfType(OrganizationService.class);
+ mgr =
(POMSessionManager)container.getComponentInstanceOfType(POMSessionManager.class);
+ authenticator =
(Authenticator)container.getComponentInstanceOfType(Authenticator.class);
+ listenerService =
(ListenerService)container.getComponentInstanceOfType(ListenerService.class);
+ events = new LinkedList<Event>();
+ storage_ = (DataStorage)container.getComponentInstanceOfType(DataStorage.class);
+ mopStorage =
(POMDataStorage)container.getComponentInstanceOfType(POMDataStorage.class);
+
+ // Register only once for all unit tests
+ if (!registered)
+ {
+ // I'm using this due to crappy design of
+ // org.exoplatform.services.listener.ListenerService
+ listenerService.addListener(DataStorage.PAGE_CREATED, listener);
+ listenerService.addListener(DataStorage.PAGE_REMOVED, listener);
+ listenerService.addListener(DataStorage.PAGE_UPDATED, listener);
+ listenerService.addListener(DataStorage.NAVIGATION_CREATED, listener);
+ listenerService.addListener(DataStorage.NAVIGATION_REMOVED, listener);
+ listenerService.addListener(DataStorage.NAVIGATION_UPDATED, listener);
+ }
+ }
+
+ private static Map<SiteKey, UserNavigation> toMap(UserPortalConfig cfg) throws
Exception
+ {
+ return toMap(cfg.getUserPortal().getNavigations());
+ }
+
+ private static Map<SiteKey, UserNavigation> toMap(List<UserNavigation>
navigations)
+ {
+ Map<SiteKey, UserNavigation> map = new HashMap<SiteKey,
UserNavigation>();
+ for (UserNavigation nav : navigations)
+ {
+ map.put(nav.getKey(), nav);
+ }
+ return map;
+ }
+
+/*
+ public void testUpdatePortalConfig()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("classic", "root");
+ assertNotNull(userPortalCfg);
+ PortalConfig portalCfg = userPortalCfg.getPortalConfig();
+ assertNotNull(portalCfg);
+ assertEquals(PortalConfig.PORTAL_TYPE, portalCfg.getType());
+ assertEquals("classic", portalCfg.getName());
+ assertEquals("en", portalCfg.getLocale());
+ portalCfg.setLocale("fr");
+
+ storage_.save(portalCfg);
+
+ userPortalCfg = userPortalConfigSer_.getUserPortalConfig("classic",
"root");
+ portalCfg = userPortalCfg.getPortalConfig();
+ assertEquals("fr", portalCfg.getLocale());
+ }
+ }.execute("root");
+ }
+
+*/
+
+ public void testRootGetUserPortalConfig()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("classic", getUserId());
+ Map<SiteKey, UserNavigation> navigations = toMap(userPortalCfg);
+ assertEquals(5, navigations.size());
+ assertTrue(navigations.containsKey(SiteKey.portal("classic")));
+ assertTrue(navigations.containsKey(SiteKey.user("root")));
+
assertTrue(navigations.containsKey(SiteKey.group("/platform/administrators")));
+
assertTrue(navigations.containsKey(SiteKey.group("/organization/management/executive-board")));
+
assertTrue(navigations.containsKey(SiteKey.group("/organization/management/executive-board")));
+
assertTrue(navigations.containsKey(SiteKey.group("/platform/users")));
+
+ // Now try with the specific api
+ UserNavigation rootNav =
userPortalCfg.getUserPortal().getNavigation(SiteKey.user("root"));
+ assertNotNull(rootNav);
+ assertEquals(SiteKey.user("root"), rootNav.getKey());
+ }
+ }.execute("root");
+ }
+
+ public void testFilter()
+ {
+ UnitTest test = new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("classic", getUserId());
+ UserPortal portal = userPortalCfg.getUserPortal();
+ UserNavigation nav =
portal.getNavigation(SiteKey.portal("classic"));
+
+ //
+ UserNode root = portal.getNode(nav, Scope.ALL);
+ NodeFilter filter =
portal.createFilter(UserNodePredicate.builder().build());
+ root.filter(filter);
+ assertNotNull(root.getChild("home"));
+ assertNotNull(root.getChild("webexplorer"));
+ }
+ };
+
+ //
+ test.execute("root");
+ test.execute(null);
+ }
+
+ public void testFilterWithVisibility()
+ {
+ UnitTest test = new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("system", getUserId());
+ UserPortal portal = userPortalCfg.getUserPortal();
+ UserNavigation nav =
portal.getNavigation(SiteKey.portal("system"));
+
+ //
+ UserNode root = portal.getNode(nav, Scope.ALL);
+ NodeFilter filter =
portal.createFilter(UserNodePredicate.builder().withVisibility(Visibility.DISPLAYED).build());
+ root.filter(filter);
+ assertNotNull(root.getChild("home"));
+ assertNotNull(root.getChild("sitemap"));
+ assertNull(root.getChild("groupnavigation"));
+
+ //
+ root = portal.getNode(nav, Scope.ALL);
+ filter =
portal.createFilter(UserNodePredicate.builder().withVisibility(Visibility.DISPLAYED,
Visibility.SYSTEM).build());
+ root.filter(filter);
+ assertNotNull(root.getChild("home"));
+ assertNotNull(root.getChild("sitemap"));
+ assertNotNull(root.getChild("groupnavigation"));
+ }
+ };
+
+ //
+ test.execute("root");
+ }
+
+ public void testFilterWithAuthorizationCheck()
+ {
+ class Check extends UnitTest
+ {
+
+ /** . */
+ boolean pass = true;
+
+ @Override
+ protected void execute() throws Exception
+ {
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("classic", getUserId());
+ UserPortal portal = userPortalCfg.getUserPortal();
+ UserNavigation nav =
portal.getNavigation(SiteKey.group("/platform/administrators"));
+
+ //
+ UserNode root = portal.getNode(nav, Scope.ALL);
+ NodeFilter filter =
portal.createFilter(UserNodePredicate.builder().withAuthorizationCheck().build());
+ root.filter(filter);
+ pass &= root.getChild("administration") != null;
+ pass &=
root.getChild("administration").getChild("communityManagement") !=
null;
+ }
+ }
+
+ //
+ Check root = new Check();
+ root.execute("root");
+ assertTrue(root.pass);
+
+ //
+ Check anon = new Check();
+ anon.execute("john");
+ assertFalse(anon.pass);
+ }
+
+/*
+ public void testJohnGetUserPortalConfig()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("classic", "john");
+ assertNotNull(userPortalCfg);
+ PortalConfig portalCfg = userPortalCfg.getPortalConfig();
+ assertNotNull(portalCfg);
+ assertEquals(PortalConfig.PORTAL_TYPE, portalCfg.getType());
+ assertEquals("classic", portalCfg.getName());
+ assertNotNull(userPortalCfg.getNavigations());
+ Map<String, PageNavigation> navigations = toMap(userPortalCfg);
+ assertEquals("expected to have 5 navigations instead of " +
navigations, 5, navigations.size());
+ assertTrue(navigations.containsKey("portal::classic"));
+
assertTrue(navigations.containsKey("group::/platform/administrators"));
+
assertTrue(navigations.containsKey("group::/organization/management/executive-board"));
+ assertTrue(navigations.containsKey("group::/platform/users"));
+ assertTrue(navigations.containsKey("user::john"));
+ }
+ }.execute("john");
+ }
+
+ public void testMaryGetUserPortalConfig()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("classic", "mary");
+ assertNotNull(userPortalCfg);
+ PortalConfig portalCfg = userPortalCfg.getPortalConfig();
+ assertNotNull(portalCfg);
+ assertEquals(PortalConfig.PORTAL_TYPE, portalCfg.getType());
+ assertEquals("classic", portalCfg.getName());
+ assertNotNull(userPortalCfg.getNavigations());
+ Map<String, PageNavigation> navigations = toMap(userPortalCfg);
+ assertEquals(3, navigations.size());
+ assertTrue(navigations.containsKey("portal::classic"));
+ assertTrue(navigations.containsKey("group::/platform/users"));
+ assertTrue(navigations.containsKey("user::mary"));
+ }
+ }.execute("mary");
+ }
+
+ public void testGuestGetUserPortalConfig()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("classic", null);
+ assertNotNull(userPortalCfg);
+ PortalConfig portalCfg = userPortalCfg.getPortalConfig();
+ assertNotNull(portalCfg);
+ assertEquals(PortalConfig.PORTAL_TYPE, portalCfg.getType());
+ assertEquals("classic", portalCfg.getName());
+ assertNotNull(userPortalCfg.getNavigations());
+ Map<String, PageNavigation> navigations = toMap(userPortalCfg);
+ assertEquals("" + navigations, 1, navigations.size());
+ assertTrue(navigations.containsKey("portal::classic"));
+ }
+ }.execute(null);
+ }
+
+*/
+
+ public void testNavigationOrder()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("classic", getUserId());
+ UserPortal userPortal = userPortalCfg.getUserPortal();
+ List<UserNavigation> navigations = userPortal.getNavigations();
+ assertEquals("expected to have 5 navigations instead of " +
navigations, 5, navigations.size());
+ assertEquals(SiteKey.portal("classic"),
navigations.get(0).getKey()); // 1
+ assertEquals(SiteKey.group("/platform/administrators"),
navigations.get(1).getKey()); // 2
+ assertEquals(SiteKey.user("root"), navigations.get(2).getKey()); //
3
+
assertEquals(SiteKey.group("/organization/management/executive-board"),
navigations.get(3).getKey()); // 4
+ assertEquals(SiteKey.group("/platform/users"),
navigations.get(4).getKey()); // 5
+ }
+ }.execute("root");
+ }
+
+ public void testPathResolution()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("classic", getUserId());
+ UserPortal userPortal = userPortalCfg.getUserPortal();
+
+ //
+ NavigationPath nav = userPortal.resolvePath("/");
+ assertEquals(SiteKey.portal("classic"),
nav.getNavigation().getKey());
+ UserNode target = nav.getTarget();
+ assertEquals("home", target.getName());
+ assertEquals("default", target.getParent().getName());
+ assertNull(target.getParent().getParent());
+
+ //
+ nav = userPortal.resolvePath("/foo");
+ assertEquals(SiteKey.portal("classic"),
nav.getNavigation().getKey());
+ target = nav.getTarget();
+ assertEquals("home", target.getName());
+ assertEquals("default", target.getParent().getName());
+ assertNull(target.getParent().getParent());
+
+ //
+ nav = userPortal.resolvePath("/home");
+ assertEquals(SiteKey.portal("classic"),
nav.getNavigation().getKey());
+ target = nav.getTarget();
+ assertEquals("home", target.getName());
+ assertEquals("default", target.getParent().getName());
+ assertNull(target.getParent().getParent());
+
+ //
+ nav =
userPortal.resolvePath("/administration/communityManagement");
+ assertEquals(SiteKey.group("/platform/administrators"),
nav.getNavigation().getKey());
+ target = nav.getTarget();
+ assertEquals("communityManagement", target.getName());
+ assertEquals("administration", target.getParent().getName());
+ assertEquals("default", target.getParent().getParent().getName());
+ assertNull(target.getParent().getParent().getParent());
+ }
+ }.execute("root");
+ }
+
+ public void testPathResolutionPerNavigation()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("classic", getUserId());
+ UserPortal userPortal = userPortalCfg.getUserPortal();
+ UserNavigation navigation =
userPortal.getNavigation(SiteKey.group("/platform/administrators"));
+
+ //
+ NavigationPath path = userPortal.resolvePath(navigation, "/");
+ assertNull(path);
+
+ //
+ path = userPortal.resolvePath(navigation, "/foo");
+ assertNull(path);
+
+ //
+ path = userPortal.resolvePath(navigation, "/administration");
+ assertNotNull(path);
+ assertEquals("administration", path.getTarget().getName());
+
+ //
+ path = userPortal.resolvePath(navigation,
"/administration/communityManagement");
+ assertNotNull(path);
+ assertEquals("communityManagement", path.getTarget().getName());
+ }
+ }.execute("root");
+ }
+
+ public void testLabel()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ UserPortalContext userPortalContext = new UserPortalContext()
+ {
+ final MapResourceBundle bundle;
+
+ {
+ Map<String, Object> map = new HashMap<String, Object>();
+ map.put("portal.classic.home", "foo");
+ map.put("portal.classic.emoh", "bar");
+ bundle = new MapResourceBundle(map);
+ }
+
+ public ResourceBundle getBundle(UserNavigation navigation)
+ {
+ return bundle;
+ }
+ };
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("classic", getUserId(),
userPortalContext);
+ UserPortal userPortal = userPortalCfg.getUserPortal();
+
+ //
+ NavigationPath path = userPortal.resolvePath("/home");
+ assertEquals("#{portal.classic.home}",
path.getTarget().getLabel());
+ assertEquals("foo", path.getTarget().getResolvedLabel());
+
+ // Note that we don't save otherwise that may affect other tests
+ // this is fine for this test I think
+ path.getTarget().setLabel("#{portal.classic.emoh}");
+ assertEquals("bar", path.getTarget().getResolvedLabel());
+ }
+ }.execute("root");
+ }
+
+ public void testLoadNode()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("classic", getUserId());
+ UserPortal userPortal = userPortalCfg.getUserPortal();
+ UserNavigation navigation =
userPortal.getNavigation(SiteKey.group("/platform/administrators"));
+
+ //
+ UserNode root = userPortal.getNode(navigation, Scope.SINGLE);
+ assertEquals("default", root.getName());
+ assertEquals(1, root.getChildrenCount());
+ assertEquals(0, root.getChildren().size());
+ assertFalse(root.hasChildrenRelationship());
+
+ //
+ root = userPortal.getNode(navigation, Scope.CHILDREN);
+ assertEquals("default", root.getName());
+ assertEquals(1, root.getChildrenCount());
+ assertEquals(1, root.getChildren().size());
+ assertTrue(root.hasChildrenRelationship());
+ Iterator<UserNode> children = root.getChildren().iterator();
+ UserNode administration = children.next();
+ assertEquals("administration", administration.getName());
+ assertEquals(5, administration.getChildrenCount());
+ assertEquals(0, administration.getChildren().size());
+ assertFalse(administration.hasChildrenRelationship());
+
+ //
+ administration = userPortal.getNode(administration, Scope.CHILDREN);
+ assertEquals("administration", administration.getName());
+ assertEquals(5, administration.getChildrenCount());
+ assertEquals(5, administration.getChildren().size());
+ assertTrue(administration.hasChildrenRelationship());
+
+ //
+ UserNode registry = administration.getChildren().iterator().next();
+ assertEquals("registry", registry.getName());
+ assertEquals(0, registry.getChildrenCount());
+ assertEquals(0, registry.getChildren().size());
+ assertFalse(registry.hasChildrenRelationship());
+
+ // I'm too lazy to check the remaining nodes...
+ }
+ }.execute("root");
+ }
+
+ public void testPublicationTime()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("test", getUserId());
+ UserPortal userPortal = userPortalCfg.getUserPortal();
+ UserNavigation navigation =
userPortal.getNavigation(SiteKey.portal("test"));
+
+ UserNode root = userPortal.getNode(navigation, Scope.ALL);
+ NodeFilter filter =
userPortal.createFilter(UserNodePredicate.builder().withTemporalCheck().build());
+ root.filter(filter);
+ GregorianCalendar start = new GregorianCalendar(2000, 2, 21, 1, 33, 0);
+ start.setTimeZone(TimeZone.getTimeZone("UTC"));
+ GregorianCalendar end = new GregorianCalendar(2050, 2, 21, 1, 33, 0);
+ end.setTimeZone(TimeZone.getTimeZone("UTC"));
+
+ assertEquals(3, root.getChildrenCount());
+
+ UserNode node1 = root.getChild("node_name1");
+ assertNotNull(node1);
+ assertEquals(start.getTimeInMillis(), node1.getStartPublicationTime());
+ assertEquals(end.getTimeInMillis(), node1.getEndPublicationTime());
+
+ UserNode node2 = root.getChild("node_name3");
+ assertNotNull(node2);
+ assertEquals(-1, node2.getStartPublicationTime());
+ assertEquals(end.getTimeInMillis(), node2.getEndPublicationTime());
+
+ UserNode node3 = root.getChild("node_name4");
+ assertNotNull(node3);
+ assertEquals(-1, node3.getStartPublicationTime());
+ assertEquals(-1, node3.getEndPublicationTime());
+ }
+ }.execute("root");
+ }
+
+ public void testSave()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ storage_.create(new PortalConfig("portal",
"usernode_recursive"));
+ end(true);
+
+ //
+ begin();
+ Site site =
mgr.getPOMService().getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"usernode_recursive");
+ site.getRootNavigation().addChild("default");
+ end(true);
+
+ //
+ begin();
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("usernode_recursive", getUserId());
+ UserPortal userPortal = userPortalCfg.getUserPortal();
+ UserNavigation navigation =
userPortal.getNavigation(SiteKey.portal("usernode_recursive"));
+ UserNode root = userPortal.getNode(navigation, Scope.CHILDREN);
+ root.addChild("foo");
+ root.save();
+ end(true);
+
+ //
+ begin();
+ root = userPortal.getNode(navigation, Scope.ALL);
+ root.addChild("bar");
+ root.getChild("foo").addChild("juu");
+ root.save();
+ end(true);
+
+ //
+ begin();
+ userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("usernode_recursive", getUserId());
+ userPortal = userPortalCfg.getUserPortal();
+ navigation =
userPortal.getNavigation(SiteKey.portal("usernode_recursive"));
+ root = userPortal.getNode(navigation, Scope.ALL);
+ assertNotNull(root.getChild("bar"));
+ UserNode foo = root.getChild("foo");
+ assertNotNull(foo.getChild("juu"));
+
+ root.removeChild("foo");
+ root.addChild("foo");
+ root.save();
+ end(true);
+
+ begin();
+ root = userPortal.getNode(navigation, Scope.ALL);
+ foo = root.getChild("foo");
+ assertNull(foo.getChild("juu"));
+ }
+ }.execute("root");
+ }
+
+ public void testNodeExtension()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ storage_.create(new PortalConfig("portal",
"node_extension"));
+ end(true);
+
+ //
+ begin();
+ Site site =
mgr.getPOMService().getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"node_extension");
+ site.getRootNavigation().addChild("default");
+ end(true);
+
+ begin();
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("node_extension", getUserId());
+ UserPortal userPortal = userPortalCfg.getUserPortal();
+ UserNavigation navigation =
userPortal.getNavigation(SiteKey.portal("node_extension"));
+ UserNode root = userPortal.getNode(navigation, Scope.CHILDREN);
+ root.addChild("foo");
+ root.save();
+ end(true);
+
+ begin();
+ assertSame(root, userPortal.getNode(root, Scope.GRANDCHILDREN));
+ UserNode foo = root.getChild("foo");
+ assertNotNull(foo);
+ foo.addChild("foo1");
+ root.save();
+ end(true);
+
+ begin();
+ assertSame(foo, userPortal.getNode(foo, Scope.GRANDCHILDREN));
+ UserNode foo1 = foo.getChild("foo1");
+ assertNotNull(foo1);
+ foo1.addChild("foo2");
+ root.save();
+ end(true);
+
+ begin();
+ root = userPortal.getNode(navigation, Scope.ALL);
+ foo1 = root.getChild("foo").getChild("foo1");
+ assertNotNull(foo1);
+ assertNotNull(foo1.getChild("foo2"));
+ }
+ }.execute("root");
+ }
+
+ public void testCacheInvalidation()
+ {
+
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ storage_.create(new PortalConfig("portal",
"cache_invalidation"));
+ end(true);
+
+ //
+ begin();
+ Site site =
mgr.getPOMService().getModel().getWorkspace().getSite(ObjectType.PORTAL_SITE,
"cache_invalidation");
+ site.getRootNavigation().addChild("default");
+ end(true);
+
+ begin();
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("cache_invalidation",
"root");
+ UserPortal userPortal = userPortalCfg.getUserPortal();
+ UserNavigation navigation =
userPortal.getNavigation(SiteKey.portal("cache_invalidation"));
+ UserNode root = userPortal.getNode(navigation, Scope.CHILDREN);
+ root.addChild("foo");
+
+ root.save();
+ root = userPortal.getNode(navigation, Scope.CHILDREN);
+ assertNotNull(root.getChild("foo")); // should Cache be invalidated
right after save()
+ }
+ }.execute("root");
+ }
+
+ public void testInfiniteLoop()
+ {
+ new UnitTest()
+ {
+ @Override
+ protected void execute() throws Exception
+ {
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("classic", getUserId());
+ UserPortal portal = userPortalCfg.getUserPortal();
+ UserNavigation nav =
portal.getNavigation(SiteKey.group("/platform/administrators"));
+
+ //
+ UserNode root = portal.getNode(nav, Scope.GRANDCHILDREN);
+ root = portal.getNode(root, Scope.GRANDCHILDREN);
+ Collection<UserNode> children = root.getChildren();
+ int level = 0;
+ for (UserNode child : children)
+ {
+ println(child, level);
+ }
+ }
+
+ private void println(UserNode node, int level)
+ {
+ System.out.println(level + " ====> " + node.getURI());
+ Collection<UserNode> children = node.getChildren();
+ UserNode temp = null;
+ Iterator<UserNode> it = children.iterator();
+ while (it.hasNext())
+ {
+ UserNode child = it.next();
+ System.out.println(child.getName());
+ if (child == temp)
+ {
+ child = it.next();
+ fail("There is infinite loop");
+ }
+ temp = child;
+ println(child, level + 1);
+ }
+ }
+ }.execute("root");
+ }
+/*
+ public void testCreateUserPortalConfig()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ userPortalConfigSer_.createUserPortalConfig(PortalConfig.PORTAL_TYPE,
"jazz", "test");
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("jazz", "root");
+ assertNotNull(userPortalCfg);
+ PortalConfig portalCfg = userPortalCfg.getPortalConfig();
+ assertNotNull(portalCfg);
+ assertEquals(PortalConfig.PORTAL_TYPE, portalCfg.getType());
+ assertEquals("jazz", portalCfg.getName());
+ assertNotNull(userPortalCfg.getNavigations());
+ Map<String, PageNavigation> navigations = toMap(userPortalCfg);
+ assertEquals("expected to have 5 navigations instead of " +
navigations, 5, navigations.size());
+ assertTrue(navigations.containsKey("portal::jazz"));
+
assertTrue(navigations.containsKey("group::/platform/administrators"));
+
assertTrue(navigations.containsKey("group::/organization/management/executive-board"));
+ assertTrue(navigations.containsKey("group::/platform/users"));
+ assertTrue(navigations.containsKey("user::root"));
+
+ queryPage();
+ }
+
+ private void queryPage()
+ {
+ Query<Page> query = new Query<Page>("portal", null,
null, null, Page.class);
+ try
+ {
+ storage_.find(query);
+ }
+ catch (Exception ex)
+ {
+ assertTrue("Exception while querying pages with new portal",
false);
+ }
+ }
+
+ }.execute("root");
+ }
+
+ public void testRemoveUserPortalConfig()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ userPortalConfigSer_.createUserPortalConfig(PortalConfig.PORTAL_TYPE,
"jazz", "test");
+ UserPortalConfig userPortalCfg =
userPortalConfigSer_.getUserPortalConfig("jazz", "root");
+ assertNotNull(userPortalCfg);
+ saveMOP();
+ userPortalConfigSer_.removeUserPortalConfig("jazz");
+ saveMOP();
+ assertNull(userPortalConfigSer_.getUserPortalConfig("jazz",
"root"));
+ }
+ }.execute("root");
+ }
+
+ public void testRootGetMakableNavigations()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ Set<String> navigations = new
HashSet<String>(userPortalConfigSer_.getMakableNavigations("root",
false));
+ Set<String> expectedNavigations =
+ new HashSet<String>(Arrays.asList("/platform/users",
"/organization/management/human-resources",
+ "/partners", "/customers",
"/organization/communication",
"/organization/management/executive-board",
+ "/organization/management",
"/organization/operations", "/organization", "/platform",
+ "/organization/communication/marketing",
"/platform/guests",
+ "/organization/communication/press-and-media",
"/platform/administrators",
+ "/organization/operations/sales",
"/organization/operations/finances"));
+ assertEquals(expectedNavigations, navigations);
+ }
+ }.execute(null);
+ }
+
+ public void testJohnGetMakableNavigations()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ Set<String> navigations = new
HashSet<String>(userPortalConfigSer_.getMakableNavigations("john",
false));
+ Set<String> expectedNavigations =
Collections.singleton("/organization/management/executive-board");
+ assertEquals(expectedNavigations, navigations);
+ }
+ }.execute(null);
+ }
+
+ public void testMaryGetMakableNavigations()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ Set<String> navigations = new
HashSet<String>(userPortalConfigSer_.getMakableNavigations("mary",
false));
+ Set<String> expectedNavigations = Collections.emptySet();
+ assertEquals(expectedNavigations, navigations);
+ }
+ }.execute(null);
+ }
+
+ public void testRootGetPage()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ assertEquals("group::/platform/administrators::newAccount",
userPortalConfigSer_.getPage(
+ "group::/platform/administrators::newAccount",
null).getPageId());
+
assertEquals("group::/organization/management/executive-board::newStaff",
userPortalConfigSer_.getPage(
+ "group::/organization/management/executive-board::newStaff",
null).getPageId());
+ }
+ }.execute("root");
+ }
+
+ public void testJohnGetPage()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ assertEquals(null,
userPortalConfigSer_.getPage("group::/platform/administrators::newAccount",
null));
+
assertEquals("group::/organization/management/executive-board::newStaff",
userPortalConfigSer_.getPage(
+ "group::/organization/management/executive-board::newStaff",
null).getPageId());
+ }
+ }.execute("john");
+ }
+
+ public void testMaryGetPage()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ assertEquals(null,
userPortalConfigSer_.getPage("group::/platform/administrators::newAccount",
null));
+ assertEquals(null, userPortalConfigSer_.getPage(
+ "group::/organization/management/executive-board::newStaff",
null));
+ }
+ }.execute("mary");
+ }
+
+ public void testAnonymousGetPage()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ assertEquals(null,
userPortalConfigSer_.getPage("group::/platform/administrators::newAccount",
null));
+ assertEquals(null, userPortalConfigSer_.getPage(
+ "group::/organization/management/executive-board::newStaff",
null));
+ }
+ }.execute(null);
+ }
+
+ public void testRemovePage()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ Page page = new Page();
+ page.setOwnerType("group");
+ page.setOwnerId("/platform/administrators");
+ page.setName("newAccount");
+ assertTrue(events.isEmpty());
+ storage_.remove(page);
+ assertEquals(1, events.size());
+ Event event = events.removeFirst();
+ assertEquals(DataStorage.PAGE_REMOVED, event.getEventName());
+ Page p = ((Page)event.getData());
+ assertEquals("group", p.getOwnerType());
+ assertEquals("/platform/administrators", p.getOwnerId());
+ assertEquals("newAccount", p.getName());
+ assertEquals(null,
userPortalConfigSer_.getPage("group::/platform/administrators::newAccount"));
+ }
+ }.execute(null);
+ }
+
+ public void testCreatePage()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ Page page = new Page();
+ page.setOwnerType("group");
+ page.setOwnerId("/platform/administrators");
+ page.setName("whatever");
+ assertTrue(events.isEmpty());
+ storage_.create(page);
+ assertEquals(1, events.size());
+ Event event = events.removeFirst();
+ assertEquals(DataStorage.PAGE_CREATED, event.getEventName());
+ Page p = ((Page)event.getData());
+ assertEquals("group", p.getOwnerType());
+ assertEquals("/platform/administrators", p.getOwnerId());
+ assertEquals("whatever", p.getName());
+
assertNotNull(userPortalConfigSer_.getPage("group::/platform/administrators::whatever"));
+ }
+ }.execute(null);
+ }
+
+ // Julien : see who added that and find out is test is relevant or not
+
+ public void testClonePage()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ Page page = new Page();
+ page.setOwnerType("group");
+ page.setOwnerId("/platform/administrators");
+ page.setName("whatever");
+ page.setTitle("testTitle");
+ storage_.create(page);
+
+ String newName = "newPage";
+ Page newPage = storage_.clonePage(page.getPageId(), page.getOwnerType(),
page.getOwnerId(), newName);
+
+ assertEquals(newName, newPage.getName());
+ assertEquals(page.getTitle(), newPage.getTitle());
+ }
+ }.execute(null);
+ }
+
+ public void testUpdatePage()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ Page page = new Page();
+ page.setOwnerType("group");
+ page.setOwnerId("/platform/administrators");
+ page.setName("newAccount");
+ page.setShowMaxWindow(true);
+ page.setTitle("newAccount title");
+ assertTrue(events.isEmpty());
+ storage_.create(page);
+ assertEquals(1, events.size());
+ Event event = events.removeFirst();
+ assertEquals(DataStorage.PAGE_CREATED, event.getEventName());
+ Page p = ((Page)event.getData());
+ assertEquals("group", p.getOwnerType());
+ assertEquals("/platform/administrators", p.getOwnerId());
+ assertEquals("newAccount", p.getName());
+ assertEquals("newAccount title", p.getTitle());
+ assertTrue(p.isShowMaxWindow());
+
+ p.setShowMaxWindow(false);
+ storage_.save(p);
+ p =
userPortalConfigSer_.getPage("group::/platform/administrators::newAccount");
+ assertFalse(p.isShowMaxWindow());
+ p.setShowMaxWindow(true);
+ storage_.save(p);
+ p =
userPortalConfigSer_.getPage("group::/platform/administrators::newAccount");
+ assertTrue(p.isShowMaxWindow());
+ p.setShowMaxWindow(false);
+ storage_.save(p);
+ p =
userPortalConfigSer_.getPage("group::/platform/administrators::newAccount");
+ assertFalse(p.isShowMaxWindow());
+ p.setShowMaxWindow(true);
+ storage_.save(p);
+ p =
userPortalConfigSer_.getPage("group::/platform/administrators::newAccount");
+ assertTrue(p.isShowMaxWindow());
+
+ Page p2 =
userPortalConfigSer_.getPage("group::/platform/administrators::newAccount");
+ assertEquals("group", p2.getOwnerType());
+ assertEquals("/platform/administrators", p2.getOwnerId());
+ assertEquals("newAccount", p2.getName());
+ // assertFalse(p2.isShowMaxWindow());
+ p2.setTitle("newAccount title 1");
+ p2.setShowMaxWindow(true);
+ storage_.save(p2);
+
+ Page p3 =
userPortalConfigSer_.getPage("group::/platform/administrators::newAccount");
+ assertEquals("newAccount title 1", p3.getTitle());
+ // assertTrue(p3.isShowMaxWindow());
+
+ }
+ }.execute(null);
+ }
+
+ public void testRemoveNavigation()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ PageNavigation navigation = new PageNavigation();
+ navigation.setOwnerType("group");
+ navigation.setOwnerId("/platform/administrators");
+ assertTrue(events.isEmpty());
+ storage_.remove(navigation);
+ assertEquals(1, events.size());
+ Event event = events.removeFirst();
+ assertEquals(DataStorage.NAVIGATION_REMOVED, event.getEventName());
+ PageNavigation n = ((PageNavigation)event.getData());
+ assertEquals("group", n.getOwnerType());
+ assertEquals("/platform/administrators", n.getOwnerId());
+ assertEquals(null, storage_.getPageNavigation("group",
"/platform/administrators"));
+ }
+ }.execute(null);
+ }
+
+ public void testCreateNavigation()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ PageNavigation navigation = new PageNavigation();
+ navigation.setOwnerType("group");
+ navigation.setOwnerId("/platform/administrators");
+ storage_.remove(navigation);
+ assertNotNull(events.removeLast());
+ assertTrue(events.isEmpty());
+ storage_.create(navigation);
+ assertEquals(1, events.size());
+ Event event = events.removeFirst();
+ assertEquals(DataStorage.NAVIGATION_CREATED, event.getEventName());
+ PageNavigation n = ((PageNavigation)event.getData());
+ assertEquals("group", n.getOwnerType());
+ assertEquals("/platform/administrators", n.getOwnerId());
+ PageNavigation n2 = storage_.getPageNavigation("group",
"/platform/administrators");
+ assertEquals("group", n2.getOwnerType());
+ assertEquals("/platform/administrators", n2.getOwnerId());
+ }
+ }.execute(null);
+ }
+
+ */
+/*
+ public void testCreateMultipleNavigations(){
+ for(int i =0; i < 10; i++){
+ createNavigation(null, "group",
"/platform/administrators" + i);
+ }
+ }
+
+ private void createNavigation(final String user, final String ownerType, final
String ownerId)
+ {
+ new UnitTest()
+ {
+
+ public void execute() throws Exception
+ {
+ createNavigationInSeperatedThread();
+ }
+
+ private void createNavigationInSeperatedThread()
+ {
+ Thread task = new Thread()
+ {
+ public void run()
+ {
+ PageNavigation navigation = new PageNavigation();
+ navigation.setOwnerType(ownerType);
+ navigation.setOwnerId(ownerId);
+ try
+ {
+ userPortalConfigSer_.create(navigation);
+ Event event = events.removeFirst();
+ assertEquals(DataStorage.CREATE_NAVIGATION_EVENT,
event.getEventName());
+ PageNavigation n1 = (PageNavigation)event.getSource();
+ assertEquals(ownerType, n1.getOwnerType());
+ assertEquals(ownerId, n1.getOwnerId());
+ PageNavigation n2 = storage_.getPageNavigation(ownerType,
ownerId);
+ assertEquals(ownerType, n2.getOwnerType());
+ assertEquals(ownerId, n2.getOwnerId());
+ }
+ catch (Exception ex)
+ {
+ assertTrue("Failed while create '" + ownerType +
" ' navigation for owner: " + ownerId, false);
+ ex.printStackTrace();
+ }
+ }
+ };
+
+ task.start();
+ try
+ {
+ task.sleep(200);
+ }
+ catch (InterruptedException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }.execute(user);
+ }
+ *//*
+
+
+ public void testUpdateNavigation()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ PageNavigation navigation = new PageNavigation();
+ navigation.setOwnerType("group");
+ navigation.setOwnerId("/platform/administrators");
+ navigation.setPriority(3);
+ assertTrue(events.isEmpty());
+ storage_.save(navigation);
+ assertEquals(1, events.size());
+ Event event = events.removeFirst();
+ assertEquals(DataStorage.NAVIGATION_UPDATED, event.getEventName());
+ PageNavigation n = ((PageNavigation)event.getData());
+ assertEquals("group", n.getOwnerType());
+ assertEquals("/platform/administrators", n.getOwnerId());
+ assertEquals(3, n.getPriority());
+ PageNavigation n2 = storage_.getPageNavigation("group",
"/platform/administrators");
+ assertEquals("group", n2.getOwnerType());
+ assertEquals("/platform/administrators", n2.getOwnerId());
+ assertEquals(3, n2.getPriority());
+ }
+ }.execute(null);
+ }
+
+ public void testRenewPage()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ Page clone = storage_.clonePage("portal::test::test4",
"portal", "test", "test5");
+ assertNotNull(clone);
+ assertEquals("portal", clone.getOwnerType());
+ assertEquals("test", clone.getOwnerId());
+ assertEquals("test5", clone.getName());
+
+ //
+ Application<Portlet> app =
(Application<Portlet>)clone.getChildren().get(0);
+ Portlet prefs2 = storage_.load(app.getState(), ApplicationType.PORTLET);
+ assertEquals(new PortletBuilder().add("template",
+
"par:/groovy/groovy/webui/component/UIBannerPortlet.gtmpl").build(), prefs2);
+
+ // Update prefs of original page
+ PortletPreferences prefs = new PortletPreferences();
+ prefs.setWindowId("portal#test:/web/BannerPortlet/banner");
+ storage_.save(prefs);
+
+ //
+ prefs2 = storage_.load(app.getState(), ApplicationType.PORTLET);
+ assertEquals(new PortletBuilder().add("template",
+
"par:/groovy/groovy/webui/component/UIBannerPortlet.gtmpl").build(), prefs2);
+ }
+ }.execute(null);
+ }
+
+ public void testCreateFromTemplate()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ Page clone = userPortalConfigSer_.createPageTemplate("dashboard",
"portal", "test");
+ assertNotNull(clone);
+ assertEquals("portal", clone.getOwnerType());
+ assertEquals("test", clone.getOwnerId());
+
+ //
+ assertEquals(1, clone.getChildren().size());
+
+ //
+ Application<Portlet> app =
(Application<Portlet>)clone.getChildren().get(0);
+ assertEquals("Dashboard", app.getTitle());
+ assertNotNull(app.getState());
+ assertEquals("dashboard/DashboardPortlet",
storage_.getId(app.getState()));
+ // assertEquals("portal", app.getInstanceState().getOwnerType());
+ // assertEquals("test", app.getInstanceState().getOwnerId());
+ Portlet prefs2 = storage_.load(app.getState(), ApplicationType.PORTLET);
+ assertNull(prefs2);
+ }
+ }.execute(null);
+ }
+
+ public void testOverwriteUserLayout()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ mgr.clearCache();
+
+ PortalConfig cfg = storage_.getPortalConfig(PortalConfig.USER_TYPE,
"overwritelayout");
+ assertNotNull(cfg);
+
+ Container container = cfg.getPortalLayout();
+ assertNotNull(container);
+ assertEquals(2, container.getChildren().size());
+ assertTrue(container.getChildren().get(0) instanceof PageBody);
+ assertTrue(((Application)container.getChildren().get(1)).getType() ==
ApplicationType.PORTLET);
+ Application<Portlet> pa =
(Application<Portlet>)container.getChildren().get(1);
+ ApplicationState<Portlet> state = pa.getState();
+ assertEquals("overwrite_application_ref/overwrite_portlet_ref",
storage_.getId(state));
+ }
+ }.execute(null);
+ }
+
+ public void testUserTemplate()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ assertNull(storage_.getPortalConfig(PortalConfig.USER_TYPE,
"user"));
+ assertNull(storage_.getPortalConfig(PortalConfig.USER_TYPE,
"julien"));
+
+ //
+ UserHandler userHandler = orgService_.getUserHandler();
+ User user = userHandler.createUserInstance("julien");
+ user.setPassword("default");
+ user.setFirstName("default");
+ user.setLastName("default");
+ user.setEmail("exo(a)exoportal.org");
+ userHandler.createUser(user, true);
+
+ //
+ PortalConfig cfg = storage_.getPortalConfig(PortalConfig.USER_TYPE,
"julien");
+ assertNotNull(cfg);
+ Container container = cfg.getPortalLayout();
+ assertNotNull(container);
+ assertEquals(2, container.getChildren().size());
+ assertTrue(container.getChildren().get(0) instanceof PageBody);
+ assertTrue(((Application)container.getChildren().get(1)).getType() ==
ApplicationType.PORTLET);
+ Application<Portlet> pa =
(Application<Portlet>)container.getChildren().get(1);
+ ApplicationState state = pa.getState();
+ assertEquals("foo/bar", storage_.getId(pa.getState()));
+ }
+ }.execute(null);
+ }
+
+ public void testGroupTemplate()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ String groupName = "groupTest";
+ assertNull(storage_.getPortalConfig(PortalConfig.GROUP_TYPE, groupName));
+
+ //
+ GroupHandler groupHandler = orgService_.getGroupHandler();
+ Group group = groupHandler.createGroupInstance();
+ group.setGroupName(groupName);
+ group.setDescription("this is a group for test");
+ groupHandler.addChild(null, group, true);
+
+ //
+ PortalConfig cfg = storage_.getPortalConfig(PortalConfig.GROUP_TYPE,
"/" + groupName);
+ assertNotNull(cfg);
+ Container container = cfg.getPortalLayout();
+ assertNotNull(container);
+ assertEquals(4, container.getChildren().size());
+ assertTrue(container.getChildren().get(2) instanceof PageBody);
+ assertTrue(((Application)container.getChildren().get(1)).getType() ==
ApplicationType.PORTLET);
+
+ groupHandler.removeGroup(group, true);
+ }
+ }.execute(null);
+ }
+
+ public void testCacheUserPortalConfig()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ mgr.clearCache();
+ DataCache cache = mgr.getDecorator(DataCache.class);
+ long readCount0 = cache.getReadCount();
+ userPortalConfigSer_.getUserPortalConfig("classic", null);
+ long readCount1 = cache.getReadCount();
+ assertTrue(readCount1 > readCount0);
+ userPortalConfigSer_.getUserPortalConfig("classic", null);
+ long readCount2 = cache.getReadCount();
+ assertEquals(readCount1, readCount2);
+ }
+ }.execute(null);
+ }
+
+ public void testCachePage()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ mgr.clearCache();
+ DataCache cache = mgr.getDecorator(DataCache.class);
+ long readCount0 = cache.getReadCount();
+ userPortalConfigSer_.getPage("portal::test::test1");
+ long readCount1 = cache.getReadCount();
+ assertTrue(readCount1 > readCount0);
+ userPortalConfigSer_.getPage("portal::test::test1");
+ long readCount2 = cache.getReadCount();
+ assertEquals(readCount1, readCount2);
+ }
+ }.execute(null);
+ }
+
+ public void testCachePageNavigation()
+ {
+ new UnitTest()
+ {
+ public void execute() throws Exception
+ {
+ mgr.clearCache();
+ DataCache cache = mgr.getDecorator(DataCache.class);
+ long readCount0 = cache.getReadCount();
+ storage_.getPageNavigation("portal", "test");
+ long readCount1 = cache.getReadCount();
+ assertTrue(readCount1 > readCount0);
+ storage_.getPageNavigation("portal", "test");
+ long readCount2 = cache.getReadCount();
+ assertEquals(readCount1, readCount2);
+ }
+ }.execute(null);
+ }
+
+ */
+
+ private abstract class UnitTest
+ {
+
+ /** . */
+ private String userId;
+
+ protected final void execute(String userId)
+ {
+ Throwable failure = null;
+
+ //
+ begin();
+
+ //
+ ConversationState conversationState = null;
+ if (userId != null)
+ {
+ try
+ {
+ conversationState = new
ConversationState(authenticator.createIdentity(userId));
+ }
+ catch (Exception e)
+ {
+ failure = e;
+ }
+ }
+
+ //
+ if (failure == null)
+ {
+ // Clear cache for test
+ mgr.clearCache();
+
+ //
+ this.userId = userId;
+ ConversationState.setCurrent(conversationState);
+ try
+ {
+ execute();
+ }
+ catch (Exception e)
+ {
+ failure = e;
+ log.error("Test failed", e);
+ }
+ finally
+ {
+ this.userId = null;
+ ConversationState.setCurrent(null);
+ end();
+ }
+ }
+
+ // Report error as a junit assertion failure
+ if (failure != null)
+ {
+ AssertionFailedError err = new AssertionFailedError();
+ err.initCause(failure);
+ throw err;
+ }
+ }
+
+ public final String getUserId()
+ {
+ return userId;
+ }
+
+ protected abstract void execute() throws Exception;
+
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/pom/data/TestModel.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/pom/data/TestModel.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/java/org/exoplatform/portal/pom/data/TestModel.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * 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.exoplatform.portal.pom.data;
+
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.portal.config.AbstractPortalTest;
+import org.exoplatform.portal.config.DataStorage;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class TestModel extends AbstractPortalTest
+{
+
+ /** . */
+ private ModelDataStorage storage;
+
+ @Override
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ //
+ PortalContainer container = PortalContainer.getInstance();
+ storage =
(ModelDataStorage)container.getComponentInstanceOfType(ModelDataStorage.class);
+
+ //
+ begin();
+ }
+
+ @Override
+ protected void tearDown() throws Exception
+ {
+ end();
+ super.tearDown();
+ }
+
+ public void testLoadNodeData() throws Exception
+ {
+
+ NodeData a = storage.loadNode(new NavigationKey("user",
"root"));
+ assertNotNull(a);
+ assertEquals("default", a.getName());
+
+ //
+ String id = a.getStorageId();
+ NodeData b = storage.loadNode(id);
+ assertEquals("default", a.getName());
+ assertEquals(id, b.getStorageId());
+ }
+}
Added:
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/resources/portal/portal/large/navigation.xml
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/resources/portal/portal/large/navigation.xml
(rev 0)
+++
epp/portal/branches/EPP_5_1_RH_Branch/component/portal/src/test/resources/portal/portal/large/navigation.xml 2011-03-16
22:16:07 UTC (rev 6060)
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Copyright (C) 2009 eXo Platform SAS.
+
+ 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.
+
+-->
+
+<node-navigation>
+ <owner-type>portal</owner-type>
+ <owner-id>large</owner-id>
+ <priority>1</priority>
+
+ <page-nodes>
+ <node>
+ <uri>a</uri>
+ <name>a</name>
+ <label>A</label>
+ <node>
+ <uri>c</uri>
+ <name>c</name>
+ <label>C</label>
+ </node>
+ </node>
+ <node>
+ <uri>b</uri>
+ <name>b</name>
+ <label>B</label>
+ <node>
+ <uri>d</uri>
+ <name>d</name>
+ <label>D</label>
+ <node>
+ <uri>e</uri>
+ <name>e</name>
+ <label>E</label>
+ </node>
+ </node>
+ </node>
+ </page-nodes>
+</node-navigation>
Deleted:
epp/portal/branches/EPP_5_1_RH_Branch/portlet/exoadmin/src/main/webapp/groovy/navigation/webui/component/NewUIGroupManagement.gtmpl
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/portlet/exoadmin/src/main/webapp/groovy/navigation/webui/component/NewUIGroupManagement.gtmpl 2011-03-16
22:01:59 UTC (rev 6059)
+++
epp/portal/branches/EPP_5_1_RH_Branch/portlet/exoadmin/src/main/webapp/groovy/navigation/webui/component/NewUIGroupManagement.gtmpl 2011-03-16
22:16:07 UTC (rev 6060)
@@ -1,107 +0,0 @@
-
-
-<div class="UIGroupManagement UIManagement">
- <div class="UIManagementBlock GroupManagement">
- <div class="Image FloatLeft"><img
src="/exoadmin/skin/navigation/webui/component/background/GroupImage.gif"></div>
- <div class="Label FloatLeft">Administrator</div>
- <div class="EditLayoutBox FloatLeft"><a href="#"
class="EditLayout">Edit Layout</a></div>
- <div class="EditIcoBox FloatLeft"><a href="#"
class="EditIco">Edit Navigation</a></div>
- <div class="DeleteIcoBox FloatLeft"><a href="#"
class="DeleteIco">Delete</a></div>
- <div class="ClearLeft"><span></span></div>
- </div>
- <div class="UIManagementBlock GroupManagement">
- <div class="Image FloatLeft"><img
src="/exoadmin/skin/navigation/webui/component/background/GroupImage.gif"></div>
- <div class="Label FloatLeft">Administrator</div>
- <div class="EditLayoutBox FloatLeft"><a href="#"
class="EditLayout">Edit Layout</a></div>
- <div class="EditIcoBox FloatLeft"><a href="#"
class="EditIco">Edit Navigation</a></div>
- <div class="DeleteIcoBox FloatLeft"><a href="#"
class="DeleteIco">Delete</a></div>
- <div class="ClearLeft"><span></span></div>
- </div>
- <div class="UIManagementBlock GroupManagement">
- <div class="Image FloatLeft"><img
src="/exoadmin/skin/navigation/webui/component/background/GroupImage.gif"></div>
- <div class="Label FloatLeft">Administrator</div>
- <div class="EditLayoutBox FloatLeft"><a href="#"
class="EditLayout">Edit Layout</a></div>
- <div class="EditIcoBox FloatLeft"><a href="#"
class="EditIco">Edit Navigation</a></div>
- <div class="DeleteIcoBox FloatLeft"><a href="#"
class="DeleteIco">Delete</a></div>
- <div class="ClearLeft"><span></span></div>
- </div>
-
- <div class="UIAction ManagerButton">
- <table class="ActionContainer">
- <tr>
- <td>
- <div class="ActionButton AddBtn">
- <div class="ButtonLeft">
- <div class="ButtonRight">
- <div class="ButtonMiddle">
- <a href="#">Add Site</a>
- </div>
- </div>
- </div>
- </div>
- <div class="ActionButton CancelBtn">
- <div class="ButtonLeft">
- <div class="ButtonRight">
- <div class="ButtonMiddle">
- <a href="#">Cancel</a>
- </div>
- </div>
- </div>
- </div>
- </td>
- </tr>
- </table>
- </div>
-
-</div>
-
-
-<!-- <div class="NewUIGroupManagement"
id="<%=uicomponent.getId();%>">
- <%
- import org.exoplatform.portal.config.model.PageNavigation;
- navigations = uicomponent.getNavigations();
- %>
-
- <%/*Begin ItemDetailList:*/%>
- <div style="margin:0px 0px 0px 0px">
- <div class="ItemDetailContainer" style="border:1px solid
#C7C7C7">
- <% for(navigation in navigations) {
- deleteLink =
uicomponent.event("DeleteNavigation",String.valueOf(navigation.getId()));
- editLink =
uicomponent.event("EditNavigation",String.valueOf(navigation.getId()));%>
- <div class="ItemDetail" style="width:100%;border-bottom:1px
solid #E9E7E7;height:20px;padding-top:5px">
- <div style="float:left;width:70%;padding-left:10px">
- <%= navigation.getOwnerId() %>
- </div>
- <div style="float:right;width:29%">
- <a href="<%=editLink%>">Edit Navigation</a> | <a
href="<%=deleteLink%>">Delete Navigation</a>
- </div>
- <div style="clear:both"></div>
- </div>
- <% } %>
-
- </div>
- </div>
- <%/*End ItemDetailList*/%>
- <div class="UIAction">
- <table class="ActionContainer">
- <tr>
- <td>
- <div
onclick="<%=uicomponent.event("AddNewPortal")%>"
class="ActionButton LightBlueStyle">
- <div class="ButtonLeft">
- <div class="ButtonRight">
- <div class="ButtonMiddle">
- <a
href="javascript:void(0);"><%=_ctx.appRes(uicomponent.getId() +
".action.addNewPortal")%></a>
- </div>
- </div>
- </div>
- </div>
- </td>
- </tr>
- </table>
- </div>
- %uicomponent.renderChildren();%>
-</div>
-
--->
-
-
Deleted:
epp/portal/branches/EPP_5_1_RH_Branch/portlet/web/src/main/java/org/exoplatform/portal/webui/component/UIPortalNavigationPortlet.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/portlet/web/src/main/java/org/exoplatform/portal/webui/component/UIPortalNavigationPortlet.java 2011-03-16
22:01:59 UTC (rev 6059)
+++
epp/portal/branches/EPP_5_1_RH_Branch/portlet/web/src/main/java/org/exoplatform/portal/webui/component/UIPortalNavigationPortlet.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -1,50 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * 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.exoplatform.portal.webui.component;
-
-import org.exoplatform.portal.webui.navigation.UIPortalNavigation2;
-import org.exoplatform.webui.application.WebuiRequestContext;
-import org.exoplatform.webui.application.portlet.PortletRequestContext;
-import org.exoplatform.webui.config.annotation.ComponentConfig;
-import org.exoplatform.webui.config.annotation.ComponentConfigs;
-import org.exoplatform.webui.config.annotation.EventConfig;
-import org.exoplatform.webui.core.UIPortletApplication;
-import org.exoplatform.webui.core.lifecycle.UIApplicationLifecycle;
-
-import javax.portlet.PortletPreferences;
-import javax.portlet.PortletRequest;
-
-@ComponentConfigs({
- @ComponentConfig(lifecycle = UIApplicationLifecycle.class),
- @ComponentConfig(type = UIPortalNavigation2.class, id =
"UIHorizontalNavigation", events = @EventConfig(listeners =
UIPortalNavigation2.SelectNodeActionListener.class))})
-public class UIPortalNavigationPortlet extends UIPortletApplication
-{
- public UIPortalNavigationPortlet() throws Exception
- {
- PortletRequestContext context =
(PortletRequestContext)WebuiRequestContext.getCurrentInstance();
- PortletRequest prequest = context.getRequest();
- PortletPreferences prefers = prequest.getPreferences();
- String template = prefers.getValue("template",
"app:/groovy/portal/webui/component/UIPortalNavigation2.gtmpl");
-
- UIPortalNavigation2 portalNavigation = addChild(UIPortalNavigation2.class,
"UIHorizontalNavigation", null);
- portalNavigation.setUseAjax(Boolean.valueOf(prefers.getValue("useAJAX",
"true")));
- portalNavigation.setTemplate(template);
- }
-}
\ No newline at end of file
Deleted:
epp/portal/branches/EPP_5_1_RH_Branch/portlet/web/src/main/webapp/WEB-INF/conf/portlet/web/PortalNavigationPortlet/webui/configuration.xml
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/portlet/web/src/main/webapp/WEB-INF/conf/portlet/web/PortalNavigationPortlet/webui/configuration.xml 2011-03-16
22:01:59 UTC (rev 6059)
+++
epp/portal/branches/EPP_5_1_RH_Branch/portlet/web/src/main/webapp/WEB-INF/conf/portlet/web/PortalNavigationPortlet/webui/configuration.xml 2011-03-16
22:16:07 UTC (rev 6060)
@@ -1,30 +0,0 @@
-<!--
-
- Copyright (C) 2009 eXo Platform SAS.
-
- 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.
-
--->
-
-<webui-configuration>
- <application>
-
<ui-component-root>org.exoplatform.portal.webui.component.UIPortalNavigationPortlet</ui-component-root>
-
<state-manager>org.exoplatform.webui.application.portlet.ParentAppStateManager</state-manager>
- <application-lifecycle-listeners>
-
<listener>org.exoplatform.portal.application.PortletStatisticLifecycle</listener>
- </application-lifecycle-listeners>
- </application>
-</webui-configuration>
Deleted:
epp/portal/branches/EPP_5_1_RH_Branch/portlet/web/src/main/webapp/groovy/portal/webui/component/UIPortalNavigation2.gtmpl
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/portlet/web/src/main/webapp/groovy/portal/webui/component/UIPortalNavigation2.gtmpl 2011-03-16
22:01:59 UTC (rev 6059)
+++
epp/portal/branches/EPP_5_1_RH_Branch/portlet/web/src/main/webapp/groovy/portal/webui/component/UIPortalNavigation2.gtmpl 2011-03-16
22:16:07 UTC (rev 6060)
@@ -1,237 +0,0 @@
-<%
- import org.exoplatform.portal.config.model.PageNode;
- import org.exoplatform.portal.config.model.PageNavigation;
- import org.exoplatform.web.application.JavascriptManager;
- import org.exoplatform.portal.webui.util.Util;
-
- def rcontext = _ctx.getRequestContext();
- JavascriptManager jsmanager = rcontext.getJavascriptManager();
- jsmanager.importJavascript('eXo.webui.UIHorizontalTabs');
- jsmanager.importJavascript('eXo.portal.UIPortalNavigation2');
- jsmanager.addOnLoadJavascript('eXo.portal.UIPortalNavigation2.onLoad');
-
- jsmanager.addOnLoadJavascript('eXo.portal.UIPortalNavigation2.loadScroll');
- //jsmanager.addOnResizeJavascript('eXo.portal.UIPortalNavigation2.initScroll');
-
- navigations = uicomponent.getNavigations();
- PageNode mySiteRoot =
createRootNode(_ctx.appRes("UIPortalNavigation.Root.MySite"));
- PageNode mySpaceRoot =
createRootNode(_ctx.appRes("UIPortalNavigation.Root.MySpace"));
-
- for(nav in navigations) {
- String ownerType = nav.getOwnerType();
- if (ownerType.equals("portal")) {
- addNodesToRoot(mySiteRoot, nav.getNodes());
- } else if (ownerType.equals("group")) {
- addNodesToRoot(mySpaceRoot, nav.getNodes());
- }
- }
-
- public PageNode createRootNode(String name) {
- PageNode node = new PageNode();
- node.setShowPublicationDate(false);
- node.setVisible(true) ;
- node.setModifiable(false);
- node.setLabel(name);
- node.setName(name);
- return node;
- }
-
- public void addNodesToRoot(PageNode root, ArrayList<PageNode> nodes) {
- for(PageNode ele : nodes) {
- root.getChildren().add(ele);
- }
- }
-
- public void renderChildrenContainer(PageNavigation nav, PageNode node) {
- print """
- <div class="MenuItemContainer" style="display: none;">
- <div class="MenuItemDecorator">
- <div class="LeftTopMenuDecorator">
- <div class="RightTopMenuDecorator">
- <div
class="CenterTopMenuDecorator"><span></span></div>
- </div>
- </div>
-
- <div class="LeftMiddleMenuDecorator">
- <div class="RightMiddleMenuDecorator">
- <div class="CenterMiddleMenuDecorator">
- """;
- for(child in node.getChildren()) {
- renderChildNode(nav, child);
- }
- print """
- </div>
- </div>
- </div>
- <div class="LeftBottomMenuDecorator">
- <div class="RightBottomMenuDecorator">
- <div
class="CenterBottomMenuDecorator"><span></span></div>
- </div>
- </div>
- </div>
- </div>
- """;
- }
-
- public void renderChildNode(PageNavigation nav, PageNode node) {
- PageNode selectedNode = uicomponent.getSelectedPageNode();
- PageNavigation selectedNav = uicomponent.getSelectedNavigation();
- String tabStyleNavigation = "NormalItem"; // OverItem
- if(selectedNode != null && selectedNav != null &&
- selectedNav.getId () == nav.getId() &&
- node.getUri() == selectedNode.getUri()) {
- tabStyleNavigation = "SelectedItem";
- }
-
- String icon = node.getIcon();
- if(icon == null) icon = "DefaultPageIcon";
- String arrowIcon = "";
- if (node.getChildren() != null && node.getChildren().size() > 0) arrowIcon =
"ArrowIcon";
-
- String label = node.resolvedLabel;
- String title = "";
- if(label.length() > 40) {
- title = label;
- label = label.substring(0,37) + "...";
- }
-
- String pageURI = Util.getPortalRequestContext().getPortalURI() + node.getUri();
- if(node.pageReference != null) {
- if(uicomponent.isUseAjax()) {
- String onclickEvt = uicomponent.event("SelectNode", nav.getId() +
"::" + node.getUri()) + ";return false;";
- print """
- <div class="MenuItem $tabStyleNavigation">
- <div class="$arrowIcon" title="$title">
- <div class="ItemIcon $icon">
- <a href="$pageURI"
onclick="$onclickEvt">$label</a>
- </div>
- </div>
- """;
- } else {
- print """
- <div class="MenuItem $tabStyleNavigation">
- <div class="$arrowIcon" title="$title">
- <div class="ItemIcon $icon">
- <a href="$pageURI">$label</a>
- </div>
- </div>
- """;
- }
- } else {
- print """
- <div class="MenuItem $tabStyleNavigation">
- <div class="$arrowIcon" title="$title">
- <div class="ItemIcon $icon">
- <a href="$pageURI">$label</a>
- </div>
- </div>
- """;
- }
-
- if (node.getChildren() != null && node.getChildren().size() > 0) {
- renderChildrenContainer(nav, node);
- }
-
- print "</div>";
- }
-%>
-
-<div class="UINavigationBar">
- <div class="LeftNavigationBar">
- <div class="RightNavigationBar">
- <div class="MiddleNavigationBar">
- <div class="UIHorizontalTabs">
- <div class="TabsContainer">
- <%
- PageNavigation selectedNav = uicomponent.getSelectedNavigation();
- PageNode selectedNode = uicomponent.getSelectedPageNode();
- if(navigations != null) {
- Hashtable<String, Boolean> usedNavs = new Hashtable<String,
Boolean>();
- for(nav in navigations) {
- ArrayList<PageNode> pageNodes = new ArrayList<PageNode>();
- String navOwnerType = nav.getOwnerType();
- if (usedNavs.get(navOwnerType)) {
- continue;
- } else if (navOwnerType.equals("portal")) {
- pageNodes.add(mySiteRoot);
- usedNavs.put(navOwnerType, true);
- } else if (navOwnerType.equals("group")) {
- pageNodes.add(mySpaceRoot);
- usedNavs.put(navOwnerType, true);
- } else {
- pageNodes = nav.getNodes();
- }
-
- for(PageNode node in pageNodes) {
- String tabStyleNavigation = "NormalNavigationTab";
- if(selectedNode != null && selectedNav != null &&
- selectedNav.getId() == nav.getId() &&
- node.getUri() == selectedNode.getUri()) {
- tabStyleNavigation = "SelectedNavigationTab";
- }
- String icon = node.getIcon();
- if(icon == null) icon = "DefaultPageIcon";
- %>
-
- <div class="UITab">
- <div class="$tabStyleNavigation">
- <div class="LeftTab">
- <div class="RightTab">
- <div class="MiddleTab">
- <div class="TabIcon">
- <%
- String arrowIcon = "";
- if (node.getChildren() != null && node.getChildren().size() > 0) {
- arrowIcon = "DropDownArrowIcon";
- }
- String iconType = node.getIcon();
- if(iconType == null) iconType = "DefaultPageIcon";
- %>
- <div class="$arrowIcon">
- <%
- String pageURI = Util.getPortalRequestContext().getPortalURI() +
node.getUri() ;
- String label = node.resolvedLabel ;
- if(label.length() > 30) label = label.substring(0,29) +
"..." ;
- if(node.pageReference != null) {
- if(uicomponent.isUseAjax()) {
- String onclickEvt =
uicomponent.event("SelectNode", nav.getId() + "::" + node.getUri()) +
";return false;" ;
- %>
- <a class="TabLabel ${iconType}"
onclick="$onclickEvt" href="$pageURI">$label</a>
- <%
- } else {
- %>
- <a class="TabLabel ${iconType}"
href="$pageURI">$label</a>
- <% }
- } else {%>
- <a class="TabLabel ${iconType}">$label</a>
- <%}%>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <%
- /*Render Popup Menu*/
- if (node.getChildren() != null && node.getChildren().size() > 0)
{
- renderChildrenContainer(nav, node);
- }
- %>
- </div>
-
- <%
- }
- }
- }
- %>
- <div class="ScrollButtons">
- <div class="ScrollLeftButton" title="<%=
_ctx.appRes("UIPortalNavigation.Label.Previous") %>">
- <div class="ScrollRightButton" title="<%=
_ctx.appRes("UIPortalNavigation.Label.Next")
%>"><span></span></div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
-</div>
\ No newline at end of file
Deleted:
epp/portal/branches/EPP_5_1_RH_Branch/web/portal/src/main/webapp/groovy/portal/webui/page/UIPageSelector2.gtmpl
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/web/portal/src/main/webapp/groovy/portal/webui/page/UIPageSelector2.gtmpl 2011-03-16
22:01:59 UTC (rev 6059)
+++
epp/portal/branches/EPP_5_1_RH_Branch/web/portal/src/main/webapp/groovy/portal/webui/page/UIPageSelector2.gtmpl 2011-03-16
22:16:07 UTC (rev 6060)
@@ -1,127 +0,0 @@
-<%
- import org.exoplatform.portal.config.model.Page;
- import org.exoplatform.webui.core.UIPopupWindow;
- import org.exoplatform.webui.form.UIForm;
- import org.exoplatform.webui.form.UIFormInputSet;
-
-
- Page page = uicomponent.getPage();
- String name = "";
- String title = "";
- String pageId = "";
- if(page != null) {
- name = page.getName();
- pageId = page.getPageId();
- title = page.getTitle();
- if (pageId == null) pageId = "";
- if (name == null) name = "";
- if (title == null) title = "";
- if(title.length() > 30) title = title.substring(0,29) + "...";
- }
-
-
- UIPopupWindow uipopup = uicomponent.getChild(UIPopupWindow.class);
-
- def rcontext = _ctx.getRequestContext();
- rcontext.getJavascriptManager().importJavascript('eXo.webui.UIPopupWindow');
-
- UIFormInputSet uiform = uicomponent.getChild(UIFormInputSet.class);
-%>
-<div class="UIPageSelector"
id="<%=uicomponent.getId();%>">
- <div class="PageSelectorTitle">
- <div class="Icon
BlueInfoBox16x16Icon"><span></span></div>
- <div
class="Title"><%=_ctx.appRes(uicomponent.getId()+".label.currentSelectedPage")%></div>
- <div class="ClearLeft"><span></span></div>
- </div>
- <div class="UIFormInfo">
- <div class="FormInfoBG">
- <div class="FormInfoIcon UIForm">
- <table class="UIPropertyInfo UIFormGrid">
- <tr>
- <td
class="FieldLabel"><%=_ctx.appRes(uicomponent.getId()+".header.id")%>:</td>
- <td class="FieldComponent">
- <% if(page != null) { %>
- $pageId
- <% } %>
- </td>
- </tr>
- <tr>
- <td
class="FieldLabel"><%=_ctx.appRes(uicomponent.getId()+".label.name")%>:</td>
- <td class="FieldComponent">
- <% if(page == null) { %>
- <% uiform.renderChild("pageName");%>
- <% } else { %>
- $name
- <% } %>
- </td>
- </tr>
- <tr>
- <td
class="FieldLabel"><%=_ctx.appRes(uicomponent.getId()+".label.title")%>:</td>
- <td class="FieldComponent">
- <% if(page == null) { %>
- <% uiform.renderChild("pageTitle");%>
- <% } else { %>
- $title
- <% } %>
- </td>
- </tr>
- </table>
- </div>
- </div>
- </div>
- <div class="UIAction">
- <table class="ActionContainer">
- <tr>
- <td>
- <%
- String clearPageEvent = "javascript:void(0);";
- String css = "FloatBlockHidden ActionButton SimpleStyle";
- def uiForm = uicomponent.getAncestorOfType(UIForm.class);
- createPageEvent = uiForm.event("CreatePage");
- if(page != null) {
- clearPageEvent = uiForm.event("ClearPage");
- css = "ActionButton SimpleStyle";
- }
- %>
- <div onclick="<%=clearPageEvent%>"
class="<%=css%>">
- <div class="ButtonLeft">
- <div class="ButtonRight">
- <div class="ButtonMiddle">
- <div class="DustBin16x16Icon Icon"
title="<%=_ctx.appRes(uicomponent.getId()+".label.clearPage")%>">
- <a
href="javascript:void(0);"><%=_ctx.appRes(uicomponent.getId() +
".label.clearPage")%></a>
- </div>
- </div>
- </div>
- </div>
- </div>
- <% if(page == null) { %>
- <div onclick="<%=createPageEvent%>" class="ActionButton
SimpleStyle">
- <div class="ButtonLeft">
- <div class="ButtonRight">
- <div class="ButtonMiddle">
- <div class="GreenPlusPage16x16Icon Icon"
title="<%=_ctx.appRes(uicomponent.getId()+".label.createPage")%>">
- <a
href="javascript:void(0);"><%=_ctx.appRes(uicomponent.getId() +
".label.createPage")%></a>
- </div>
- </div>
- </div>
- </div>
- </div>
- <% } %>
-
- <div class="ActionButton SimpleStyle" onclick="javascript:
eXo.webui.UIPopupWindow.show('<%=uicomponent.getChild(UIPopupWindow.class).getId();%>');">
- <div class="ButtonLeft">
- <div class="ButtonRight">
- <div class="ButtonMiddle">
- <div class="Icon SelectPageIcon"
title="<%=_ctx.appRes(uicomponent.getId()+".label.searchandSelectPage")%>">
- <a
href="javascript:void(0);"><%=_ctx.appRes(uicomponent.getId()+".label.searchandSelectPage")%></a>
- </div>
- </div>
- </div>
- </div>
- </div>
-
- </td>
- </tr>
- </table>
- </div>
-</div>
Deleted:
epp/portal/branches/EPP_5_1_RH_Branch/web/portal/src/main/webapp/groovy/portal/webui/portal/NewUIGroupManagement.gtmpl
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/web/portal/src/main/webapp/groovy/portal/webui/portal/NewUIGroupManagement.gtmpl 2011-03-16
22:01:59 UTC (rev 6059)
+++
epp/portal/branches/EPP_5_1_RH_Branch/web/portal/src/main/webapp/groovy/portal/webui/portal/NewUIGroupManagement.gtmpl 2011-03-16
22:16:07 UTC (rev 6060)
@@ -1,45 +0,0 @@
-<div class="NewUIGroupManagement"
id="<%=uicomponent.getId();%>">
- <%
- import org.exoplatform.portal.config.model.PageNavigation;
- navigations = uicomponent.getNavigations();
- %>
-
- <%/*Begin ItemDetailList:*/%>
- <div style="margin:0px 0px 0px 0px">
- <div class="ItemDetailContainer" style="border:1px solid
#C7C7C7">
- <% for(navigation in navigations) {
-deleteLink =
uicomponent.event("DeleteNavigation",String.valueOf(navigation.getId()));
-editLink =
uicomponent.event("EditNavigation",String.valueOf(navigation.getId()));%>
- <div class="ItemDetail" style="width:100%;border-bottom:1px solid
#E9E7E7;height:20px;padding-top:5px">
- <div style="float:left;width:70%;padding-left:10px">
- <%= navigation.getOwnerId() %>
- </div>
- <div style="float:right;width:29%">
- <a href="<%=editLink%>">Edit Navigation</a> | <a
href="<%=deleteLink%>">Delete Navigation</a>
- </div>
- <div style="clear:both"></div>
- </div>
- <% } %>
-
- </div>
- </div>
- <%/*End ItemDetailList*/%>
- <div class="UIAction">
- <table class="ActionContainer">
- <tr>
- <td>
- <div onclick="<%=uicomponent.event("AddNewPortal")%>"
class="ActionButton LightBlueStyle">
- <div class="ButtonLeft">
- <div class="ButtonRight">
- <div class="ButtonMiddle">
- <a
href="javascript:void(0);"><%=_ctx.appRes(uicomponent.getId() +
".action.addNewPortal")%></a>
- </div>
- </div>
- </div>
- </div>
- </td>
- </tr>
- </table>
- </div>
-
-</div>
\ No newline at end of file
Deleted:
epp/portal/branches/EPP_5_1_RH_Branch/web/portal/src/main/webapp/groovy/webui/core/UISitemap2.gtmpl
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/web/portal/src/main/webapp/groovy/webui/core/UISitemap2.gtmpl 2011-03-16
22:01:59 UTC (rev 6059)
+++
epp/portal/branches/EPP_5_1_RH_Branch/web/portal/src/main/webapp/groovy/webui/core/UISitemap2.gtmpl 2011-03-16
22:16:07 UTC (rev 6060)
@@ -1,7 +0,0 @@
-<%
- import org.exoplatform.portal.webui.navigation.UIPortalNavigation;
-
- def uiPortalNavigation = uicomponent.getChild(UIPortalNavigation.class);
- uiPortalNavigation.loadTreeNodes();
- uicomponent.renderChildren();
-%>
\ No newline at end of file
Deleted:
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/PageNavigationUtils.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/PageNavigationUtils.java 2011-03-16
22:01:59 UTC (rev 6059)
+++
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/PageNavigationUtils.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -1,478 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * 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.exoplatform.portal.webui.navigation;
-
-import org.exoplatform.container.ExoContainer;
-import org.exoplatform.portal.config.UserACL;
-import org.exoplatform.portal.config.UserPortalConfigService;
-import org.exoplatform.portal.config.model.PageNavigation;
-import org.exoplatform.portal.config.model.PageNode;
-import org.exoplatform.portal.config.model.PortalConfig;
-import org.exoplatform.portal.mop.Visibility;
-import org.exoplatform.services.resources.ResourceBundleManager;
-import org.exoplatform.webui.application.WebuiRequestContext;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Locale;
-import java.util.ResourceBundle;
-
-/**
- * Created by The eXo Platform SARL
- * Author : Nhu Dinh Thuan
- * nhudinhthuan(a)exoplatform.com
- * Jun 27, 2007
- */
-public class PageNavigationUtils
-{
-
- public static void removeNode(List<PageNode> list, String uri)
- {
- if (list == null)
- return;
- for (PageNode pageNode : list)
- {
- if (pageNode.getUri().equalsIgnoreCase(uri))
- {
- list.remove(pageNode);
- return;
- }
- }
- }
-
- /**
- * This method returns a pair of PageNode, one is the PageNode specified by the uri,
- * another is its parent. Value return is 2-element array
- *
- * 1. The element indexed 1 is the page node specified by the uri
- *
- * 2. The element indexed 0 is its parent
- *
- * @deprecated Returning 2-element array would makes it difficult to understand,
handle the code.
- * Method searchParentChildPairByUri should be used instead.
- *
- * @param node
- * @param uri
- * @return
- */
- @Deprecated
- public static PageNode[] searchPageNodesByUri(PageNode node, String uri)
- {
- if (node.getUri().equals(uri))
- return new PageNode[]{null, node};
- if (node.getChildren() == null)
- return null;
- List<PageNode> children = node.getChildren();
- for (PageNode ele : children)
- {
- PageNode[] returnNodes = searchPageNodesByUri(ele, uri);
- if (returnNodes != null)
- {
- if (returnNodes[0] == null)
- returnNodes[0] = node;
- return returnNodes;
- }
- }
- return null;
- }
-
- @Deprecated
- public static PageNode[] searchPageNodesByUri(PageNavigation nav, String uri)
- {
- if (nav.getNodes() == null)
- return null;
- List<PageNode> nodes = nav.getNodes();
- for (PageNode ele : nodes)
- {
- PageNode[] returnNodes = searchPageNodesByUri(ele, uri);
- if (returnNodes != null)
- return returnNodes;
- }
- return null;
- }
-
- /**
- * This method returns a pair of a node matching the parsed uri and the parent of this
node.
- *
- * @param nav
- * @param uri
- * @return
- */
- public static ParentChildPair searchParentChildPairByUri(PageNavigation nav, String
uri)
- {
- List<PageNode> nodes = nav.getNodes();
-
- if(nodes == null)
- {
- return null;
- }
-
- for(PageNode ele : nodes)
- {
- ParentChildPair parentChildPair = searchParentChildPairUnderNode(ele, uri);
- if(parentChildPair != null)
- {
- return parentChildPair;
- }
- }
-
- return null;
- }
-
- //TODO: Split the uri and use optimzed method
<code>searchParentChildPairByPath</code>
- public static ParentChildPair searchParentChildPairUnderNode(PageNode rootNode, String
uri)
- {
- if(uri.equals(rootNode.getUri()))
- {
- return new ParentChildPair(null, rootNode);
- }
-
- List<PageNode> nodes = rootNode.getNodes();
- if(nodes == null)
- {
- return null;
- }
-
- for(PageNode node : nodes)
- {
- ParentChildPair parentChildPair = searchParentChildPairUnderNode(node, uri);
- if(parentChildPair != null)
- {
- if(parentChildPair.getParentNode() == null)
- {
- parentChildPair.setParentNode(rootNode);
- }
- return parentChildPair;
- }
- }
-
- return null;
- }
-
- /**
- * Search a pair of page node (specified by the path) and its parent
- *
- * @param rootNode
- * @param path
- * @return
- */
- public static ParentChildPair searchParentChildPairByPath(PageNode rootNode, String[]
path)
- {
- if(path.length == 0)
- {
- throw new IllegalArgumentException("The input path must have unzero
length");
- }
-
- if(!rootNode.getName().equals(path[0]))
- {
- return null;
- }
- else
- {
- if(path.length == 1)
- {
- return new ParentChildPair(null, rootNode);
- }
-
- PageNode tempNode = rootNode;
-
- PageNode parentNode = null;
- PageNode childNode = null;
- for(int i = 1; i< path.length; i++)
- {
- childNode = tempNode.getChild(path[i]);
- if(childNode == null)
- {
- return null;
- }
- else
- {
- parentNode = tempNode;
- }
- }
-
- return new ParentChildPair(parentNode, childNode);
- }
- }
-
- public static PageNode searchPageNodeByUri(PageNode node, String uri)
- {
- if (node.getUri().equals(uri))
- return node;
- if (node.getChildren() == null)
- return null;
- List<PageNode> children = node.getChildren();
- for (PageNode ele : children)
- {
- PageNode returnNode = searchPageNodeByUri(ele, uri);
- if (returnNode != null)
- return returnNode;
- }
- return null;
- }
-
- public static PageNode searchPageNodeByUri(PageNavigation nav, String uri)
- {
- if (nav.getNodes() == null)
- return null;
- List<PageNode> nodes = nav.getNodes();
- for (PageNode ele : nodes)
- {
- PageNode returnNode = searchPageNodeByUri(ele, uri);
- if (returnNode != null)
- return returnNode;
- }
- return null;
- }
-
- public static Object searchParentNode(PageNavigation nav, String uri)
- {
- if (nav.getNodes() == null)
- return null;
- int last = uri.lastIndexOf("/");
- String parentUri = "";
- if (last > -1)
- parentUri = uri.substring(0, uri.lastIndexOf("/"));
- for (PageNode ele : nav.getNodes())
- {
- if (ele.getUri().equals(uri))
- return nav;
- }
- if (parentUri.equals(""))
- return null;
- return searchPageNodeByUri(nav, parentUri);
- }
-
- // Still keep this method to have compatibility with legacy code
- public static PageNavigation filter(PageNavigation nav, String userName) throws
Exception
- {
- return filterNavigation(nav, userName, false, false);
- }
-
- /**
- *
- * @param nav
- * @param userName
- * @param acceptNonDisplayedNode
- * @param acceptNodeWithoutPage
- * @return
- * @throws Exception
- */
- public static PageNavigation filterNavigation(PageNavigation nav, String userName,
boolean acceptNonDisplayedNode, boolean acceptNodeWithoutPage) throws Exception
- {
- PageNavigation filter = nav.clone();
- filter.setNodes(new ArrayList<PageNode>());
-
- WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
- ExoContainer container =
context.getApplication().getApplicationServiceContainer();
- UserPortalConfigService userService =
-
(UserPortalConfigService)container.getComponentInstanceOfType(UserPortalConfigService.class);
- UserACL userACL = (UserACL)container.getComponentInstanceOfType(UserACL.class);
-
- for (PageNode node : nav.getNodes())
- {
- PageNode newNode = filterNodeNavigation(node, userName, acceptNonDisplayedNode,
acceptNodeWithoutPage, userService, userACL);
- if (newNode != null)
- filter.addNode(newNode);
- }
- return filter;
- }
-
- /**
- * use {@link #filterNavigation(PageNavigation, String, boolean, boolean)}
- *
- * @param nav
- * @param userName
- * @param acceptNonDisplayedNode
- * @return
- * @throws Exception
- */
- @Deprecated
- public static PageNavigation filterNavigation(PageNavigation nav, String userName,
boolean acceptNonDisplayedNode) throws Exception
- {
- return filterNavigation(nav, userName, acceptNonDisplayedNode, true);
- }
-
- /**
- * Use {@link #filterNodeNavigation(PageNode, String, boolean, boolean,
UserPortalConfigService, UserACL)}
- * @param startNode
- * @param userName
- * @param acceptNonDisplayedNode
- * @param userService
- * @param userACL
- * @return
- * @throws Exception
- */
- @Deprecated
- private static PageNode filterNodeNavigation(PageNode startNode, String userName,
boolean acceptNonDisplayedNode,
- UserPortalConfigService userService, UserACL userACL) throws Exception {
- PageNode cloneStartNode = filterNodeNavigation(startNode, userName,
acceptNonDisplayedNode, false, userService, userACL);
- return cloneStartNode;
- }
-
- /**
- * PageNode won't be processed in following cases:
- *
- * Case 1: Node 's visibility is SYSTEM and the user is not superuser or he is
superuser but acceptNonDisplayNode = false
- *
- * Case 2: Node 's visibility is not SYSTEM but the node is not display and the
acceptNonDisplayedNode = false
- *
- * Case 3: Node has non null pageReference but the associated Page does not exist and
not accept this node is without page
- *
- *
- * @param startNode
- * @param userName
- * @param acceptNonDisplayedNode
- * @param acceptNodeWithoutPage
- * @param userService
- * @param userACL
- * @return
- * @throws Exception
- */
- private static PageNode filterNodeNavigation(PageNode startNode, String userName,
boolean acceptNonDisplayedNode, boolean acceptNodeWithoutPage,
- UserPortalConfigService userService, UserACL userACL) throws Exception
- {
-
- Visibility nodeVisibility = startNode.getVisibility();
- String pageReference = startNode.getPageReference();
-
- boolean doNothingCase_1 = nodeVisibility == Visibility.SYSTEM &&
(!userACL.getSuperUser().equals(userName) || !acceptNonDisplayedNode);
- boolean doNothingCase_2 = nodeVisibility != Visibility.SYSTEM &&
!startNode.isDisplay() && !acceptNonDisplayedNode;
- boolean doNothingCase_3 = (pageReference != null) &&
(userService.getPage(pageReference, userName) == null) && !acceptNodeWithoutPage;
-
-
-
- if (doNothingCase_1 || doNothingCase_2 || doNothingCase_3)
- {
- return null;
- }
-
- PageNode cloneStartNode = startNode.clone();
- ArrayList<PageNode> filteredChildren = new ArrayList<PageNode>();
-
- List<PageNode> children = startNode.getChildren();
-
- if (children != null)
- {
- for (PageNode child : children)
- {
- PageNode filteredChildNode = filterNodeNavigation(child, userName,
acceptNonDisplayedNode, acceptNodeWithoutPage, userService, userACL);
- if (filteredChildNode != null)
- {
- filteredChildren.add(filteredChildNode);
- }
- }
- }
-
- //If are only accepting displayed nodes and If the node has no child and it does
not point to any Page, then null is return
- if (!acceptNonDisplayedNode && filteredChildren.size() == 0 &&
cloneStartNode.getPageReference() == null)
- {
- return null;
- }
- cloneStartNode.setChildren(filteredChildren);
- return cloneStartNode;
- }
-
- public static PageNode filter(PageNode node, String userName, boolean
acceptNonDisplayedNode) throws Exception
- {
- WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
- ExoContainer container =
context.getApplication().getApplicationServiceContainer();
- UserPortalConfigService userService =
-
(UserPortalConfigService)container.getComponentInstanceOfType(UserPortalConfigService.class);
- UserACL userACL = (UserACL)container.getComponentInstanceOfType(UserACL.class);
-
- return filterNodeNavigation(node, userName, acceptNonDisplayedNode, userService,
userACL);
- }
-
- public static void localizePageNavigation(PageNavigation nav, Locale locale,
ResourceBundleManager i18nManager)
- {
- if (nav.getOwnerType().equals(PortalConfig.USER_TYPE))
- return;
- ResourceBundle res =
- i18nManager.getNavigationResourceBundle(locale.getLanguage(),
nav.getOwnerType(), nav.getOwnerId());
- for (PageNode node : nav.getNodes())
- {
- resolveLabel(res, node);
- }
- }
-
- private static void resolveLabel(ResourceBundle res, PageNode node)
- {
- node.setResolvedLabel(res);
- if (node.getChildren() == null)
- return;
- for (PageNode childNode : node.getChildren())
- {
- resolveLabel(res, childNode);
- }
- }
-
- public static PageNavigation findNavigationByID(List<PageNavigation>
all_Navigations, int id)
- {
- for (PageNavigation nav : all_Navigations)
- {
- if (nav.getId() == id)
- {
- return nav;
- }
- }
- return null;
- }
-
- public static void sortPageNavigation(List<PageNavigation> navigations)
- {
- Collections.sort(navigations, new PageNavigationComparator());
- }
-
- /**
- *
- * @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
- * @version $Id$
- *
- */
- public static class PageNavigationComparator implements
Comparator<PageNavigation>
- {
- public int compare(PageNavigation firstNav, PageNavigation secondNav)
- {
- int firstNavPriority = firstNav.getPriority();
- int secondNavPriority = secondNav.getPriority();
-
- if (firstNavPriority == secondNavPriority)
- {
- String firstNavId = firstNav.getOwnerId();
- String secondNavId = secondNav.getOwnerId();
- return firstNavId.compareTo(secondNavId);
- }
- else
- {
- if (firstNavPriority < secondNavPriority)
- {
- return -1;
- }
- else
- {
- return 1;
- }
- }
- }
- }
-}
Deleted:
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/ParentChildPair.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/ParentChildPair.java 2011-03-16
22:01:59 UTC (rev 6059)
+++
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/ParentChildPair.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2010 eXo Platform SAS.
- *
- * 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.exoplatform.portal.webui.navigation;
-
-import org.exoplatform.portal.config.model.PageNode;
-
-/**
- * This class wrappes a pair of PageNode and its parent.
- *
- * @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
- * @version $Id$
- *
- */
-public class ParentChildPair
-{
- private PageNode parentNode;
-
- private PageNode childNode;
-
- public ParentChildPair(PageNode _parentNode, PageNode _childNode)
- {
- this.parentNode = _parentNode;
- this.childNode = _childNode;
- }
-
- public PageNode getParentNode()
- {
- return parentNode;
- }
-
- public PageNode getChildNode()
- {
- return childNode;
- }
-
- public void setParentNode(PageNode _parentNode)
- {
- this.parentNode = _parentNode;
- }
-
- public void setChildNode(PageNode _childNode)
- {
- this.childNode = _childNode;
- }
-}
Deleted:
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPortalNavigation2.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPortalNavigation2.java 2011-03-16
22:01:59 UTC (rev 6059)
+++
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPortalNavigation2.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -1,187 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * 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.exoplatform.portal.webui.navigation;
-
-import org.exoplatform.portal.config.model.PageNavigation;
-import org.exoplatform.portal.config.model.PageNode;
-import org.exoplatform.portal.webui.portal.PageNodeEvent;
-import org.exoplatform.portal.webui.portal.UIPortal;
-import org.exoplatform.portal.webui.util.Util;
-import org.exoplatform.webui.application.WebuiRequestContext;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.event.Event;
-import org.exoplatform.webui.event.EventListener;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class UIPortalNavigation2 extends UIComponent
-{
- private boolean useAJAX = true;
-
- protected PageNode selectedNode_;
-
- protected Object selectedParent_;
-
- private String template;
-
- @Override
- public String getTemplate()
- {
- return template != null ? template : super.getTemplate();
- }
-
- public void setTemplate(String template)
- {
- this.template = template;
- }
-
- public UIComponent getViewModeUIComponent()
- {
- return null;
- }
-
- public void setUseAjax(boolean bl)
- {
- useAJAX = bl;
- }
-
- public boolean isUseAjax()
- {
- return useAJAX;
- }
-
- public List<PageNavigation> getNavigations() throws Exception
- {
- WebuiRequestContext context = WebuiRequestContext.getCurrentInstance();
- List<PageNavigation> result = new ArrayList<PageNavigation>();
- for (PageNavigation nav : Util.getUIPortal().getNavigations())
- {
- result.add(PageNavigationUtils.filter(nav, context.getRemoteUser()));
- }
- return result;
- }
-
- public PageNavigation getSelectedNavigation() throws Exception
- {
- PageNavigation nav = Util.getUIPortal().getSelectedNavigation();
- if (nav != null)
- return nav;
- if (Util.getUIPortal().getNavigations().size() < 1)
- return null;
- return Util.getUIPortal().getNavigations().get(0);
- }
-
- public Object getSelectedParent()
- {
- return selectedParent_;
- }
-
- public PageNode getSelectedPageNode() throws Exception
- {
- if (selectedNode_ != null)
- return selectedNode_;
- selectedNode_ = Util.getUIPortal().getSelectedNode();
- return selectedNode_;
- }
-
- public boolean isSelectedNode(PageNode node)
- {
- if (selectedNode_ != null && node.getUri().equals(selectedNode_.getUri()))
- return true;
- if (selectedParent_ == null || selectedParent_ instanceof PageNavigation)
- return false;
- PageNode pageNode = (PageNode)selectedParent_;
- return node.getUri().equals(pageNode.getUri());
- }
-
- public void processRender(WebuiRequestContext context) throws Exception
- {
- UIPortal uiPortal = Util.getUIPortal();
- if ((uiPortal.getSelectedNode() != null) && (uiPortal.getSelectedNode() !=
selectedNode_))
- {
- setSelectedPageNode(uiPortal.getSelectedNode());
- }
- super.processRender(context);
- }
-
- private void setSelectedPageNode(PageNode selectedNode) throws Exception
- {
- selectedNode_ = selectedNode;
- selectedParent_ = null;
- String seletctUri = selectedNode.getUri();
- int index = seletctUri.lastIndexOf("/");
- String parentUri = null;
- if (index > 0)
- parentUri = seletctUri.substring(0, seletctUri.lastIndexOf("/"));
- List<PageNavigation> pageNavs = getNavigations();
- for (PageNavigation pageNav : pageNavs)
- {
- if (PageNavigationUtils.searchPageNodeByUri(pageNav, selectedNode.getUri()) !=
null)
- {
- if (parentUri == null || parentUri.length() < 1)
- selectedParent_ = pageNav;
- else
- selectedParent_ = PageNavigationUtils.searchPageNodeByUri(pageNav,
parentUri);
- break;
- }
- }
- }
-
- static public class SelectNodeActionListener extends
EventListener<UIPortalNavigation2>
- {
- public void execute(Event<UIPortalNavigation2> event) throws Exception
- {
- UIPortalNavigation2 uiNavigation = event.getSource();
- UIPortal uiPortal = Util.getUIPortal();
- String uri = event.getRequestContext().getRequestParameter(OBJECTID);
- int index = uri.lastIndexOf("::");
- String id = uri.substring(index + 2);
- PageNavigation selectNav = null;
- if (index <= 0)
- {
- selectNav = uiPortal.getSelectedNavigation();
- }
- else
- {
- String navId = uri.substring(0, index);
-
- //TODO: Minh Hoang TO
- //selectNav = uiPortal.getPageNavigation(Integer.parseInt(navId));
- selectNav = uiPortal.getSelectedNavigation();
- }
- PageNode selectNode = PageNavigationUtils.searchPageNodeByUri(selectNav, id);
- uiNavigation.selectedNode_ = selectNode;
- String parentUri = null;
- index = uri.lastIndexOf("/");
- if (index > 0)
- parentUri = uri.substring(0, index);
- if (parentUri == null || parentUri.length() < 1)
- uiNavigation.selectedParent_ = selectNav;
- else
- uiNavigation.selectedParent_ =
PageNavigationUtils.searchPageNodeByUri(selectNav, parentUri);
-
- PageNodeEvent<UIPortal> pnevent;
- pnevent = new PageNodeEvent<UIPortal>(uiPortal,
PageNodeEvent.CHANGE_PAGE_NODE, uri);
- uiPortal.broadcast(pnevent, Event.Phase.PROCESS);
- }
- }
-
-}
Deleted:
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPortalNodeSelector.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPortalNodeSelector.java 2011-03-16
22:01:59 UTC (rev 6059)
+++
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/navigation/UIPortalNodeSelector.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -1,806 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * 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.exoplatform.portal.webui.navigation;
-
-import org.exoplatform.portal.application.PortalRequestContext;
-import org.exoplatform.portal.config.UserPortalConfig;
-import org.exoplatform.portal.config.UserPortalConfigService;
-import org.exoplatform.portal.config.model.Page;
-import org.exoplatform.portal.config.model.PageNavigation;
-import org.exoplatform.portal.config.model.PageNode;
-import org.exoplatform.portal.webui.util.Util;
-import org.exoplatform.web.application.ApplicationMessage;
-import org.exoplatform.webui.application.WebuiRequestContext;
-import org.exoplatform.webui.config.annotation.ComponentConfig;
-import org.exoplatform.webui.config.annotation.ComponentConfigs;
-import org.exoplatform.webui.config.annotation.EventConfig;
-import org.exoplatform.webui.core.UIApplication;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.core.UIContainer;
-import org.exoplatform.webui.core.UIRightClickPopupMenu;
-import org.exoplatform.webui.core.UITree;
-import org.exoplatform.webui.core.model.SelectItemOption;
-import org.exoplatform.webui.event.Event;
-import org.exoplatform.webui.event.EventListener;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Created by The eXo Platform SARL Author : chungnv nguyenchung136(a)yahoo.com
- * Jun 23, 2006 10:07:15 AM
- */
-@ComponentConfigs({
- @ComponentConfig(template =
"system:/groovy/portal/webui/navigation/UIPortalNodeSelector.gtmpl", events =
{@EventConfig(listeners = UIPortalNodeSelector.ChangeNodeActionListener.class)}),
- @ComponentConfig(id = "PortalNodePopupMenu", type =
UIRightClickPopupMenu.class, template =
"system:/groovy/webui/core/UIRightClickPopupMenu.gtmpl", events = {
- @EventConfig(listeners = UIPortalNodeSelector.AddNodeActionListener.class),
- @EventConfig(listeners = UIPortalNodeSelector.EditPageNodeActionListener.class),
- @EventConfig(listeners =
UIPortalNodeSelector.EditSelectedNodeActionListener.class),
- @EventConfig(listeners = UIPortalNodeSelector.CopyNodeActionListener.class),
- @EventConfig(listeners = UIPortalNodeSelector.CutNodeActionListener.class),
- @EventConfig(listeners = UIPortalNodeSelector.CloneNodeActionListener.class),
- @EventConfig(listeners = UIPortalNodeSelector.PasteNodeActionListener.class),
- @EventConfig(listeners = UIPortalNodeSelector.MoveUpActionListener.class),
- @EventConfig(listeners = UIPortalNodeSelector.MoveDownActionListener.class),
- @EventConfig(listeners = UIPortalNodeSelector.DeleteNodeActionListener.class,
confirm = "UIPageNodeSelector.deleteNavigation")}),
- @ComponentConfig(id = "UIPortalNodeSelectorPopupMenu", type =
UIRightClickPopupMenu.class, template =
"system:/groovy/webui/core/UIRightClickPopupMenu.gtmpl", events = {})})
-public class UIPortalNodeSelector extends UIContainer
-{
-
- private List<PageNavigation> navigations;
-
- private SelectedNode selectedNode;
-
- private SelectedNode copyNode;
-
- private String portalName;
-
- private List<PageNavigation> deleteNavigations = new
ArrayList<PageNavigation>();
-
- public UIPortalNodeSelector() throws Exception
- {
- addChild(UIRightClickPopupMenu.class, "UIPortalNodeSelectorPopupMenu",
null).setRendered(false);
-
- UITree uiTree = addChild(UITree.class, null, "TreeNodeSelector");
- uiTree.setIcon("DefaultPageIcon");
- uiTree.setSelectedIcon("DefaultPageIcon");
- uiTree.setBeanIdField("uri");
- uiTree.setBeanLabelField("encodedResolvedLabel");
- uiTree.setBeanIconField("icon");
-
- UIRightClickPopupMenu uiPopupMenu = createUIComponent(UIRightClickPopupMenu.class,
"PortalNodePopupMenu", null);
- uiPopupMenu.setActions(new String[]{"AddNode", "EditPageNode",
"EditSelectedNode", "CopyNode", "CloneNode",
- "CutNode", "DeleteNode", "MoveUp",
"MoveDown"});
- uiTree.setUIRightClickPopupMenu(uiPopupMenu);
- }
-
- public void loadNavigations(String portalName, String ownerType) throws Exception
- {
- this.portalName = portalName;
- navigations = new ArrayList<PageNavigation>();
- List<PageNavigation> pnavigations = getExistedNavigation(portalName,
ownerType);
- for (PageNavigation nav : pnavigations)
- {
- if (nav.isModifiable())
- navigations.add(nav);
- }
-
- updateUI();
-
- selectNavigation();
- }
-
- public void loadNavigationByNavId(Integer navId, List<PageNavigation>
navigations) throws Exception
- {
- this.navigations = navigations;
-
- selectNavigation(navId);
- }
-
- private void updateUI()
- {
- if (navigations == null || navigations.size() < 1)
- {
- getChild(UITree.class).setSibbling(null);
- return;
- }
-
- List<SelectItemOption<String>> options = new
ArrayList<SelectItemOption<String>>();
- for (PageNavigation navigation : navigations)
- { // navigation.getOwnerId()
- options.add(new SelectItemOption<String>(navigation.getOwnerType() +
":" + navigation.getOwnerId(), String
- .valueOf(navigation.getId())));
- }
- }
-
- private void selectNavigation()
- {
- if (navigations == null || navigations.size() < 1)
- return;
- if (selectedNode == null)
- {
- PageNavigation navigation = navigations.get(0);
- selectedNode = new SelectedNode(navigation, null, null);
- if (navigation.getNodes().size() > 0)
- selectedNode.setNode(navigation.getNodes().get(0));
- }
- selectNavigation(selectedNode.getPageNavigation().getId());
- if (selectedNode.getNode() != null)
- selectPageNodeByUri(selectedNode.getNode().getUri());
- }
-
- public void selectNavigation(int id)
- {
- for (int i = 0; i < navigations.size(); i++)
- {
- if (navigations.get(i).getId() != id)
- continue;
- selectedNode = new SelectedNode(navigations.get(i), null, null);
- selectPageNodeByUri(null);
- UITree uiTree = getChild(UITree.class);
- uiTree.setSibbling(navigations.get(i).getNodes());
- }
- }
-
- public void selectPageNodeByUri(String uri)
- {
- if (selectedNode == null)
- return;
- UITree tree = getChild(UITree.class);
- List<?> sibbling = tree.getSibbling();
- tree.setSibbling(null);
- tree.setParentSelected(null);
- selectedNode.setNode(searchPageNodeByUri(selectedNode.getPageNavigation(), uri));
- if (selectedNode.getNode() != null)
- {
- tree.setSelected(selectedNode.getNode());
- tree.setChildren(selectedNode.getNode().getChildren());
- return;
- }
- tree.setSelected(null);
- tree.setChildren(null);
- tree.setSibbling(sibbling);
- }
-
- public PageNode searchPageNodeByUri(PageNavigation pageNav, String uri)
- {
- if (pageNav == null || uri == null)
- return null;
- List<PageNode> pageNodes = pageNav.getNodes();
- UITree uiTree = getChild(UITree.class);
- for (PageNode ele : pageNodes)
- {
- PageNode returnPageNode = searchPageNodeByUri(ele, uri, uiTree);
- if (returnPageNode == null)
- continue;
- if (uiTree.getSibbling() == null)
- uiTree.setSibbling(pageNodes);
- return returnPageNode;
- }
- return null;
- }
-
- private PageNode searchPageNodeByUri(PageNode pageNode, String uri, UITree tree)
- {
- if (pageNode.getUri().equals(uri))
- return pageNode;
- List<PageNode> children = pageNode.getChildren();
- if (children == null)
- return null;
- for (PageNode ele : children)
- {
- PageNode returnPageNode = searchPageNodeByUri(ele, uri, tree);
- if (returnPageNode == null)
- continue;
- if (tree.getSibbling() == null)
- tree.setSibbling(children);
- if (tree.getParentSelected() == null)
- tree.setParentSelected(pageNode);
- selectedNode.setParentNode(pageNode);
- return returnPageNode;
- }
- return null;
- }
-
- public List<PageNavigation> getPageNavigations()
- {
- if (navigations == null)
- navigations = new ArrayList<PageNavigation>();
- return navigations;
- }
-
- public void addPageNavigation(PageNavigation navigation)
- {
- if (navigations == null)
- navigations = new ArrayList<PageNavigation>();
- navigations.add(navigation);
- updateUI();
- }
-
- public void deletePageNavigation(PageNavigation navigation)
- {
- if (navigations == null || navigations.size() < 1)
- return;
- navigations.remove(navigation);
- deleteNavigations.add(navigation);
- selectedNode = null;
- selectNavigation();
- updateUI();
- }
-
- public PageNavigation getPageNavigation(int id)
- {
- for (PageNavigation ele : getPageNavigations())
- {
- if (ele.getId() == id)
- return ele;
- }
- return null;
- }
-
- public void processRender(WebuiRequestContext context) throws Exception
- {
- UIRightClickPopupMenu uiPopupMenu = getChild(UIRightClickPopupMenu.class);
- if (uiPopupMenu != null)
- {
- if (navigations == null || navigations.size() < 1)
- uiPopupMenu.setRendered(false);
- else
- uiPopupMenu.setRendered(true);
- }
- super.processRender(context);
- }
-
- public SelectedNode getCopyNode()
- {
- return copyNode;
- }
-
- public void setCopyNode(SelectedNode copyNode)
- {
- this.copyNode = copyNode;
- }
-
- private List<PageNavigation> getExistedNavigation(String portalName, String
ownerType) throws Exception
- {
- PortalRequestContext prContext = Util.getPortalRequestContext();
- UserPortalConfigService configService =
getApplicationComponent(UserPortalConfigService.class);
- UserPortalConfig config = configService.getUserPortalConfig(portalName,
prContext.getRemoteUser());
- List<PageNavigation> navis = config.getNavigations();
- if (ownerType != null)
- {
- Iterator<PageNavigation> itr = navis.iterator();
- while (itr.hasNext())
- {
- PageNavigation nav = itr.next();
- if (!nav.getOwnerType().equals(ownerType))
- itr.remove();
- }
- }
-
- return navis;
- }
-
- static public class ChangeNodeActionListener extends EventListener<UITree>
- {
- public void execute(Event<UITree> event) throws Exception
- {
- String uri = event.getRequestContext().getRequestParameter(OBJECTID);
- UIPortalNodeSelector uiPortalNodeSelector = event.getSource().getParent();
- uiPortalNodeSelector.selectPageNodeByUri(uri);
- }
- }
-
- static public class AddNodeActionListener extends
EventListener<UIRightClickPopupMenu>
- {
- public void execute(Event<UIRightClickPopupMenu> event) throws Exception
- {
- // String uri =
event.getRequestContext().getRequestParameter(UIComponent.OBJECTID);
- // UIRightClickPopupMenu uiPopupMenu = event.getSource();
- // UIPortalNodeSelector uiPortalNodeSelector =
uiPopupMenu.getAncestorOfType(UIPortalNodeSelector.class);
- // if (uiPortalNodeSelector.getSelectedNavigation() == null) {
- // UIApplication uiApp =
Util.getPortalRequestContext().getUIApplication();
- // uiApp.addMessage(new
ApplicationMessage("UIPageNodeSelector.msg.NoPageNavigation", null));
- //
- //
event.getRequestContext().addUIComponentToUpdateByAjax(uiPortalNodeSelector.getParent());
- // return;
- // }
- //
- // UIPortalApplication uiApp =
uiPortalNodeSelector.getAncestorOfType(UIPortalApplication.class);
- // UIMaskWorkspace uiMaskWS =
uiApp.getChildById(UIPortalApplication.UI_MASK_WS_ID);
- // event.getRequestContext().addUIComponentToUpdateByAjax(uiMaskWS);
- //
event.getRequestContext().addUIComponentToUpdateByAjax(uiPortalNodeSelector.getParent());
- // UIPageNodeForm2 uiNodeForm =
uiMaskWS.createUIComponent(UIPageNodeForm2.class, null, null);
- // uiNodeForm.setValues(null);
- // uiMaskWS.setUIComponent(uiNodeForm);
- // uiMaskWS.setShow(true);
- //
- // Object parent = null;
- // List<PageNode> pageNodes =
uiPortalNodeSelector.getSelectedNavigation().getNodes();
- // if (uri != null && uri.trim().length() > 0) {
- // for (PageNode pageNode : pageNodes) {
- // parent = PageNavigationUtils.searchPageNodeByUri(pageNode, uri);
- // if (parent != null)
- // break;
- // }
- // }
- // if (parent == null)
- // parent = uiPortalNodeSelector.getSelectedNavigation();
- // uiNodeForm.setSelectedParent(parent);
- }
- }
-
- static public class EditPageNodeActionListener extends
EventListener<UIRightClickPopupMenu>
- {
- public void execute(Event<UIRightClickPopupMenu> event) throws Exception
- {
- // UIRightClickPopupMenu uiPopupMenu = event.getSource();
- // String uri =
event.getRequestContext().getRequestParameter(UIComponent.OBJECTID);
- // PortalRequestContext pcontext =
(PortalRequestContext)event.getRequestContext();
- // UIPortalNodeSelector uiPortalNodeSelector =
uiPopupMenu.getAncestorOfType(UIPortalNodeSelector.class) ;
- // PageNavigation currentNav =
uiPortalNodeSelector.getSelectedNavigation();
- // PageNode selectNode =
PageNavigationUtils.searchPageNodeByUri(currentNav, uri);
- //
- // uiPortalNodeSelector.selectPageNodeByUri(uri);
- // UIPortalApplication uiPortalApp = Util.getUIPortalApplication() ;
- // UIPageManagement2 uiManagement = uiPortalNodeSelector.getParent();
- //
- // UIWorkingWorkspace uiWorkingWS =
uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
- // pcontext.addUIComponentToUpdateByAjax(uiWorkingWS) ;
- // pcontext.setFullRender(true);
- //
- // UserPortalConfigService portalConfigService =
uiPopupMenu.getApplicationComponent(UserPortalConfigService.class);
- // Page page = null;
- // if(selectNode.getPageReference() != null) page =
portalConfigService.getPage(selectNode.getPageReference(), pcontext.getRemoteUser());
- // if(page == null) {
- // Class<?> [] childrenToRender = {UIPortalNodeSelector.class,
UIPortalNavigationControlBar.class };
- // uiManagement.setRenderedChildrenOfTypes(childrenToRender);
- // if(selectNode.getPageReference() != null &&
portalConfigService.getPage(selectNode.getPageReference()) != null) {
- // uiPortalApp.addMessage(new
ApplicationMessage("UIPageBrowser.msg.edit.NotEditPage", new String[]{})) ;
- // } else {
- // uiPortalApp.addMessage(new
ApplicationMessage("UIPageBrowser.msg.PageNotExist", new String[]{})) ;
- // }
- // return;
- // }
- //
- // if(!page.isModifiable()){
- // Class<?> [] childrenToRender = {UIPortalNodeSelector.class,
UIPortalNavigationControlBar.class};
- // uiManagement.setRenderedChildrenOfTypes(childrenToRender);
- // uiPortalApp.addMessage(new
ApplicationMessage("UIPageNodeSelector.msg.Invalid-editPermission", null)) ;
- // return;
- // }
- //
- // UIMaskWorkspace uiMaskWS =
uiPortalApp.getChildById(UIPortalApplication.UI_MASK_WS_ID) ;
- // UIPageForm2 uiPageForm =
uiMaskWS.createUIComponent(UIPageForm2.class);
- // uiPageForm.removeChild(UIPageTemplateOptions.class);
- //
- // UIPage uiPage = Util.toUIPage(page, uiMaskWS);
- // uiPageForm.setValues(uiPage);
- // uiMaskWS.setUIComponent(uiPageForm);
- // uiMaskWS.setWindowSize(640, 400);
- // uiMaskWS.setShow(true);
- // pcontext.addUIComponentToUpdateByAjax(uiMaskWS);
- // Class<?> [] childrenToRender = {UIPortalNodeSelector.class,
UIPortalNavigationControlBar.class};
- // uiManagement.setRenderedChildrenOfTypes(childrenToRender);
- }
- }
-
- static public class EditSelectedNodeActionListener extends
EventListener<UIRightClickPopupMenu>
- {
- public void execute(Event<UIRightClickPopupMenu> event) throws Exception
- {
- // UIRightClickPopupMenu popupMenu = event.getSource();
- // UIComponent parent = popupMenu.getParent();
- // UIPortalNodeSelector uiPortalNodeSelector = parent.getParent();
- // UIPortalApplication uiApp =
uiPortalNodeSelector.getAncestorOfType(UIPortalApplication.class);
- // UIMaskWorkspace uiMaskWS =
uiApp.getChildById(UIPortalApplication.UI_MASK_WS_ID) ;
- // event.getRequestContext().addUIComponentToUpdateByAjax(uiMaskWS);
- //
event.getRequestContext().addUIComponentToUpdateByAjax(uiPortalNodeSelector.<UIPageManagement2>getParent());
- //
- // String uri =
event.getRequestContext().getRequestParameter(UIComponent.OBJECTID);
- // PageNavigation selectedNav =
uiPortalNodeSelector.getSelectedNavigation();
- // Object obj = PageNavigationUtils.searchParentNode(selectedNav, uri);
- // PageNode selectedNode =
PageNavigationUtils.searchPageNodeByUri(selectedNav, uri);
- // String pageId = selectedNode.getPageReference();
- // UserPortalConfigService service =
parent.getApplicationComponent(UserPortalConfigService.class);
- // PortalRequestContext pcontext = Util.getPortalRequestContext();
- // UIPortalApplication uiPortalApp =
parent.getAncestorOfType(UIPortalApplication.class);
- // Page node = (pageId != null) ? service.getPage(pageId) : null ;
- // if(node != null) {
- // UserACL userACL = parent.getApplicationComponent(UserACL.class) ;
- // if(!userACL.hasPermission(node, pcontext.getRemoteUser())) {
- // uiPortalApp.addMessage(new
ApplicationMessage("UIPageBrowser.msg.UserNotPermission", new String[]{pageId},
1)) ;;
- // return;
- // }
- // }
- //
- // UIPageNodeForm2 uiNodeForm =
uiMaskWS.createUIComponent(UIPageNodeForm2.class, null, null);
- // uiMaskWS.setUIComponent(uiNodeForm);
- // uiNodeForm.setValues(selectedNode);
- // uiNodeForm.setSelectedParent(obj);
- }
- }
-
- static public class CopyNodeActionListener extends
EventListener<UIRightClickPopupMenu>
- {
- public void execute(Event<UIRightClickPopupMenu> event) throws Exception
- {
- String uri =
event.getRequestContext().getRequestParameter(UIComponent.OBJECTID);
- UIPortalNodeSelector uiPortalNodeSelector =
event.getSource().getAncestorOfType(UIPortalNodeSelector.class);
- //UIPageManagement2 uiManagement = uiPortalNodeSelector.getParent();
- Class<?>[] childrenToRender = new
Class<?>[]{UIPortalNodeSelector.class};
- //uiManagement.setRenderedChildrenOfTypes(childrenToRender);
- //event.getRequestContext().addUIComponentToUpdateByAjax(uiManagement);
-
- PageNavigation nav = uiPortalNodeSelector.getSelectedNavigation();
- if (nav == null)
- return;
- PageNode[] pageNodes = PageNavigationUtils.searchPageNodesByUri(nav, uri);
- if (pageNodes == null)
- return;
- SelectedNode selectedNode = new SelectedNode(nav, pageNodes[0], pageNodes[1]);
- selectedNode.setDeleteNode(false);
- uiPortalNodeSelector.setCopyNode(selectedNode);
- event.getSource().setActions(
- new String[]{"AddNode", "EditPageNode",
"EditSelectedNode", "CopyNode", "CloneNode",
"CutNode",
- "PasteNode", "DeleteNode", "MoveUp",
"MoveDown"});
- }
- }
-
- static public class CutNodeActionListener extends
UIPortalNodeSelector.CopyNodeActionListener
- {
- public void execute(Event<UIRightClickPopupMenu> event) throws Exception
- {
- super.execute(event);
- UIPortalNodeSelector uiPortalNodeSelector =
event.getSource().getAncestorOfType(UIPortalNodeSelector.class);
- if (uiPortalNodeSelector.getCopyNode() == null)
- return;
- uiPortalNodeSelector.getCopyNode().setDeleteNode(true);
- }
- }
-
- static public class CloneNodeActionListener extends
UIPortalNodeSelector.CopyNodeActionListener
- {
- public void execute(Event<UIRightClickPopupMenu> event) throws Exception
- {
- super.execute(event);
- UIPortalNodeSelector uiPortalNodeSelector =
event.getSource().getAncestorOfType(UIPortalNodeSelector.class);
- uiPortalNodeSelector.getCopyNode().setCloneNode(true);
- }
- }
-
- static public class PasteNodeActionListener extends
EventListener<UIRightClickPopupMenu>
- {
- public void execute(Event<UIRightClickPopupMenu> event) throws Exception
- {
- String targetUri =
event.getRequestContext().getRequestParameter(UIComponent.OBJECTID);
- UIRightClickPopupMenu uiPopupMenu = event.getSource();
- UIPortalNodeSelector uiPortalNodeSelector =
uiPopupMenu.getAncestorOfType(UIPortalNodeSelector.class);
- //UIPageManagement2 uiManagement = uiPortalNodeSelector.getParent();
- Class<?>[] childrenToRender = new
Class<?>[]{UIPortalNodeSelector.class};
- //uiManagement.setRenderedChildrenOfTypes(childrenToRender);
- //event.getRequestContext().addUIComponentToUpdateByAjax(uiManagement);
- SelectedNode selectedNode = uiPortalNodeSelector.getCopyNode();
- if (selectedNode == null)
- return;
-
- PageNode newNode = selectedNode.getNode().clone();
- PageNavigation targetNav = uiPortalNodeSelector.getSelectedNavigation();
- PageNode targetNode = PageNavigationUtils.searchPageNodeByUri(targetNav,
targetUri);
-
- if (targetNode != null && newNode.getUri().equals(targetNode.getUri()))
- {
- UIApplication uiApp = Util.getPortalRequestContext().getUIApplication();
- uiApp.addMessage(new
ApplicationMessage("UIPageNodeSelector.msg.paste.sameSrcAndDes", null));
- return;
- }
-
- if (isExistChild(targetNode, newNode) || (targetNode == null &&
isExitChild(targetNav, newNode)))
- {
- UIApplication uiApp = Util.getPortalRequestContext().getUIApplication();
- uiApp.addMessage(new
ApplicationMessage("UIPageNodeSelector.msg.paste.sameName", null));
- return;
- }
- if (selectedNode.isDeleteNode())
- {
- if (selectedNode.getParentNode() != null)
- {
-
selectedNode.getParentNode().getChildren().remove(selectedNode.getNode());
- }
- else
- {
-
selectedNode.getPageNavigation().getNodes().remove(selectedNode.getNode());
- }
- }
- event.getRequestContext().addUIComponentToUpdateByAjax(uiPortalNodeSelector);
- uiPortalNodeSelector.setCopyNode(null);
- UITree uitree = uiPortalNodeSelector.getChild(UITree.class);
- UIRightClickPopupMenu popup = uitree.getUIRightClickPopupMenu();
- popup.setActions(new String[]{"AddNode", "EditPageNode",
"EditSelectedNode", "CopyNode", "CutNode",
- "CloneNode", "DeleteNode", "MoveUp",
"MoveDown"});
-
- UserPortalConfigService service =
uiPopupMenu.getApplicationComponent(UserPortalConfigService.class);
- if (targetNode == null)
- {
- newNode.setUri(newNode.getName());
- targetNav.addNode(newNode);
- if (selectedNode.isCloneNode())
- {
- clonePageFromNode(newNode, targetNav.getOwnerType(),
targetNav.getOwnerId(), service);
- }
- return;
- }
- setNewUri(targetNode, newNode);
- targetNode.getChildren().add(newNode);
- if (selectedNode.isCloneNode())
- {
- clonePageFromNode(newNode, targetNav.getOwnerType(), targetNav.getOwnerId(),
service);
- }
- uiPortalNodeSelector.selectPageNodeByUri(targetNode.getUri());
- }
-
- private void clonePageFromNode(PageNode node, String ownerType, String ownerId,
UserPortalConfigService service)
- throws Exception
- {
- String pageId = node.getPageReference();
- if (pageId != null)
- {
- Page page = service.getPage(pageId);
- if (page != null)
- {
- String newName = "page" + node.hashCode();
- page = service.renewPage(pageId, newName, ownerType, ownerId);
- node.setPageReference(page.getPageId());
- }
- }
- List<PageNode> children = node.getChildren();
- if (children == null || children.size() < 1)
- return;
- for (PageNode ele : children)
- {
- clonePageFromNode(ele, ownerType, ownerId, service);
- }
- }
-
- private void setNewUri(PageNode parent, PageNode child)
- {
- String newUri = (parent != null) ? parent.getUri() + "/" +
child.getName() : child.getName();
- child.setUri(newUri);
- List<PageNode> children = child.getChildren();
- if (children != null)
- for (PageNode node : children)
- setNewUri(child, node);
- }
-
- private boolean isExistChild(PageNode parent, PageNode child)
- {
- if (parent == null)
- return false;
- List<PageNode> nodes = parent.getChildren();
- if (nodes == null)
- {
- parent.setChildren(new ArrayList<PageNode>());
- return false;
- }
- for (PageNode node : nodes)
- {
- if (node.getName().equals(child.getName()))
- return true;
- }
- return false;
- }
-
- private boolean isExitChild(PageNavigation nav, PageNode child)
- {
- List<PageNode> nodes = nav.getNodes();
- if (nodes.size() == 0)
- return false;
- for (PageNode node : nodes)
- {
- if (node.getName().equals(child.getName()))
- return true;
- }
- return false;
- }
- }
-
- static public class MoveUpActionListener extends
EventListener<UIRightClickPopupMenu>
- {
- public void execute(Event<UIRightClickPopupMenu> event) throws Exception
- {
- moveNode(event, -1);
- }
-
- protected void moveNode(Event<UIRightClickPopupMenu> event, int i)
- {
- String uri =
event.getRequestContext().getRequestParameter(UIComponent.OBJECTID);
- UIPortalNodeSelector uiPortalNodeSelector =
event.getSource().getAncestorOfType(UIPortalNodeSelector.class);
-
event.getRequestContext().addUIComponentToUpdateByAjax(uiPortalNodeSelector.getParent());
- PageNavigation nav = uiPortalNodeSelector.getSelectedNavigation();
- PageNode targetNode = PageNavigationUtils.searchPageNodeByUri(nav, uri);
- Object parentNode = PageNavigationUtils.searchParentNode(nav, uri);
- List<PageNode> children = new ArrayList<PageNode>();
- if (parentNode instanceof PageNavigation)
- {
- children = ((PageNavigation)parentNode).getNodes();
- }
- else if (parentNode instanceof PageNode)
- {
- children = ((PageNode)parentNode).getChildren();
- }
- int k = children.indexOf(targetNode);
- if (k < 0)
- return;
- if (k == 0 && i == -1)
- return;
- if (k == children.size() - 1 && i == 1)
- return;
- children.remove(k);
- children.add(k + i, targetNode);
- }
- }
-
- static public class MoveDownActionListener extends
UIPortalNodeSelector.MoveUpActionListener
- {
- public void execute(Event<UIRightClickPopupMenu> event) throws Exception
- {
- super.moveNode(event, 1);
- }
- }
-
- static public class DeleteNodeActionListener extends
EventListener<UIRightClickPopupMenu>
- {
- public void execute(Event<UIRightClickPopupMenu> event) throws Exception
- {
- // String uri =
event.getRequestContext().getRequestParameter(UIComponent.OBJECTID);
- // PortalRequestContext pcontext =
(PortalRequestContext)event.getRequestContext() ;
- // UIPortalNodeSelector uiPortalNodeSelector =
event.getSource().getAncestorOfType(UIPortalNodeSelector.class);
- // UIPageManagement2 uiManagement = uiPortalNodeSelector.getParent();
- // Class<?> [] childrenToRender = new
Class<?>[]{UIPortalNodeSelector.class, UIPortalNavigationControlBar.class };
- // uiManagement.setRenderedChildrenOfTypes(childrenToRender);
- // pcontext.addUIComponentToUpdateByAjax(uiManagement);
- //
- // PageNavigation nav = uiPortalNodeSelector.getSelectedNavigation();
- // if(nav == null) return;
- //
- // PageNode [] pageNodes = PageNavigationUtils.searchPageNodesByUri(nav,
uri);
- // if(pageNodes == null) return;
- //
- // UIPortalApplication uiPortalApp =
event.getSource().getAncestorOfType(UIPortalApplication.class);
- // UIWorkingWorkspace uiWorkspace =
uiPortalApp.getChildById(UIPortalApplication.UI_WORKING_WS_ID);
- // pcontext.setFullRender(true) ;
- // pcontext.addUIComponentToUpdateByAjax(uiWorkspace);
- // if(pageNodes[0] == null) {
- // nav.getNodes().remove(pageNodes[1]);
- // return;
- // }
- // pageNodes[0].getChildren().remove(pageNodes[1]);
- // uiPortalNodeSelector.selectPageNodeByUri(pageNodes[0].getUri());
- }
- }
-
- public SelectedNode getSelectedNode()
- {
- return selectedNode;
- }
-
- public PageNavigation getSelectedNavigation()
- {
- return selectedNode == null ? null : selectedNode.getPageNavigation();
- }
-
- public PageNode getSelectedPageNode()
- {
- return selectedNode == null ? null : selectedNode.getNode();
- }
-
- public String getUpLevelUri()
- {
- return selectedNode.getParentNode().getUri();
- }
-
- public List<PageNavigation> getDeleteNavigations()
- {
- return deleteNavigations;
- }
-
- public String getPortalName()
- {
- return portalName;
- }
-
- public void setPortalName(String portalName)
- {
- this.portalName = portalName;
- }
-
- public static class SelectedNode
- {
-
- private PageNavigation nav;
-
- private PageNode parentNode;
-
- private PageNode node;
-
- private boolean deleteNode = false;
-
- private boolean cloneNode = false;
-
- public SelectedNode(PageNavigation nav, PageNode parentNode, PageNode node)
- {
- this.nav = nav;
- this.parentNode = parentNode;
- this.node = node;
- }
-
- public PageNavigation getPageNavigation()
- {
- return nav;
- }
-
- public void setPageNavigation(PageNavigation nav)
- {
- this.nav = nav;
- }
-
- public PageNode getParentNode()
- {
- return parentNode;
- }
-
- public void setParentNode(PageNode parentNode)
- {
- this.parentNode = parentNode;
- }
-
- public PageNode getNode()
- {
- return node;
- }
-
- public void setNode(PageNode node)
- {
- this.node = node;
- }
-
- public boolean isDeleteNode()
- {
- return deleteNode;
- }
-
- public void setDeleteNode(boolean deleteNode)
- {
- this.deleteNode = deleteNode;
- }
-
- public boolean isCloneNode()
- {
- return cloneNode;
- }
-
- public void setCloneNode(boolean b)
- {
- cloneNode = b;
- }
- }
-
-}
Deleted:
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/page/PageUtils.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/page/PageUtils.java 2011-03-16
22:01:59 UTC (rev 6059)
+++
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/page/PageUtils.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -1,97 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * 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.exoplatform.portal.webui.page;
-
-import org.exoplatform.portal.config.DataStorage;
-import org.exoplatform.portal.config.UserPortalConfigService;
-import org.exoplatform.portal.config.model.PageNavigation;
-import org.exoplatform.portal.config.model.PageNode;
-import org.exoplatform.portal.config.model.PortalConfig;
-import org.exoplatform.portal.webui.portal.UIPortal;
-import org.exoplatform.portal.webui.util.Util;
-import org.exoplatform.portal.webui.workspace.UIPortalApplication;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Created by The eXo Platform SAS
- * Author : Pham Thanh Tung
- * thanhtungty(a)gmail.com
- * Feb 19, 2008
- */
-public class PageUtils
-{
-
- /**
- * This method create new Page and PageNode from an existing page and add created
PageNode to children of parentNode
- *
- */
- public static void createNodeFromPageTemplate(String nodeName, String nodeLabel,
String pageId, PageNode parentNode)
- throws Exception
- {
-
- UIPortalApplication uiPortalApp = Util.getUIPortalApplication();
- UserPortalConfigService configService =
uiPortalApp.getApplicationComponent(UserPortalConfigService.class);
- String accessUser = Util.getPortalRequestContext().getRemoteUser();
- PageNode node =
- configService.createNodeFromPageTemplate(nodeName, nodeLabel, pageId,
PortalConfig.USER_TYPE, accessUser);
- node.setUri(parentNode.getUri() + "/" + node.getName());
- if (parentNode.getChildren() == null)
- parentNode.setChildren(new ArrayList<PageNode>());
- parentNode.getChildren().add(node);
- }
-
- /**
- * This method create new Page and PageNode from an existing page and add created
PageNode to user PageNavigation.
- * It also saves changes to database and UIPortal
- *
- */
- public static void createNodeFromPageTemplate(String nodeName, String nodeLabel,
String pageId, PageNavigation navi)
- throws Exception
- {
-
- UIPortal uiPortal = Util.getUIPortal();
- UserPortalConfigService configService =
uiPortal.getApplicationComponent(UserPortalConfigService.class);
- String accessUser = Util.getPortalRequestContext().getRemoteUser();
- PageNode node =
- configService.createNodeFromPageTemplate(nodeName, nodeLabel, pageId,
PortalConfig.USER_TYPE, accessUser);
-
- node.setUri(node.getName());
- navi.addNode(node);
-
- DataStorage dataService = uiPortal.getApplicationComponent(DataStorage.class);
- dataService.save(navi);
- setNavigation(uiPortal.getNavigations(), navi);
- }
-
- private static void setNavigation(List<PageNavigation> navs, PageNavigation
nav)
- {
- for (int i = 0; i < navs.size(); i++)
- {
- if (navs.get(i).getId() == nav.getId())
- {
- navs.set(i, nav);
- return;
- }
- }
- }
-
-}
Deleted:
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageSelector2.java
===================================================================
---
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageSelector2.java 2011-03-16
22:01:59 UTC (rev 6059)
+++
epp/portal/branches/EPP_5_1_RH_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/page/UIPageSelector2.java 2011-03-16
22:16:07 UTC (rev 6060)
@@ -1,186 +0,0 @@
-/**
- * Copyright (C) 2009 eXo Platform SAS.
- *
- * 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.exoplatform.portal.webui.page;
-
-import org.exoplatform.portal.config.UserACL;
-import org.exoplatform.portal.config.UserPortalConfigService;
-import org.exoplatform.portal.config.model.Page;
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-import org.exoplatform.web.application.ApplicationMessage;
-import org.exoplatform.webui.application.WebuiRequestContext;
-import org.exoplatform.webui.config.annotation.ComponentConfig;
-import org.exoplatform.webui.config.annotation.ComponentConfigs;
-import org.exoplatform.webui.config.annotation.EventConfig;
-import org.exoplatform.webui.core.UIApplication;
-import org.exoplatform.webui.core.UIComponent;
-import org.exoplatform.webui.core.UIRepeater;
-import org.exoplatform.webui.core.UIVirtualList;
-import org.exoplatform.webui.event.Event;
-import org.exoplatform.webui.event.EventListener;
-import org.exoplatform.webui.form.UIForm;
-import org.exoplatform.webui.form.UIFormInput;
-import org.exoplatform.webui.form.UIFormInputContainer;
-import org.exoplatform.webui.form.UIFormInputSet;
-import org.exoplatform.webui.form.UIFormPopupWindow;
-import org.exoplatform.webui.form.UIFormStringInput;
-import org.exoplatform.webui.form.validator.IdentifierValidator;
-import org.exoplatform.webui.form.validator.MandatoryValidator;
-import org.exoplatform.webui.form.validator.StringLengthValidator;
-
-import java.util.List;
-
-/**
- * Author : Dang Van Minh minhdv81(a)yahoo.com Jun 14, 2006
- */
-@ComponentConfigs({
- @ComponentConfig(template =
"system:/groovy/portal/webui/page/UIPageSelector2.gtmpl"),
- @ComponentConfig(id = "SelectPage", type = UIPageBrowser.class, template =
"system:/groovy/portal/webui/page/UIPageBrowser.gtmpl", events =
@EventConfig(listeners = UIPageSelector2.SelectPageActionListener.class))})
-public class UIPageSelector2 extends UIFormInputContainer<String>
-{
-
- private Page page_;
-
- private static Log logger = ExoLogger.getExoLogger(UIPageSelector2.class);
-
- public UIPageSelector2() throws Exception
- {
- super("UIPageSelector2", null);
- UIFormPopupWindow uiPopup = addChild(UIFormPopupWindow.class, null,
"PopupPageSelector2");
- uiPopup.setWindowSize(900, 400);
- uiPopup.setRendered(false);
- UIPageBrowser uiPageBrowser = createUIComponent(UIPageBrowser.class,
"SelectPage", null);
- uiPopup.setUIComponent(uiPageBrowser);
-
- UIFormInputSet uiInputSet = new UIFormInputSet("PageNodeSetting");
-
- uiInputSet.addChild(new UIFormStringInput("pageId", "pageId",
null));
- uiInputSet.addChild(new UIFormStringInput("pageName",
"pageName", null).addValidator(StringLengthValidator.class,
- 3,
30).addValidator(IdentifierValidator.class).addValidator(MandatoryValidator.class));
- uiInputSet.addChild(new UIFormStringInput("pageTitle",
"pageTitle", null).addValidator(
- StringLengthValidator.class, 3, 120));
-
- addChild(uiInputSet);
- UIVirtualList uiVirtualList = uiPageBrowser.getChild(UIVirtualList.class);
- configureVirtualList(uiVirtualList);
- }
-
- private static void configureVirtualList(UIVirtualList vList)
- {
- UIRepeater repeater;
- try
- {
- repeater = (UIRepeater)vList.getUIComponent();
- repeater.configure("pageId", UIPageBrowser.BEAN_FIELD, new
String[]{"SelectPage"});
- }
- catch (ClassCastException clCastEx)
- {
- logger.info("Could not upcast to UIRepeater", clCastEx);
- }
- }
-
- public void configure(String iname, String bfield)
- {
- setId(iname);
- setName(iname);
- setBindingField(bfield);
- }
-
- public UIFormInput<?> setValue(String value) throws Exception
- {
- WebuiRequestContext ctx = WebuiRequestContext.getCurrentInstance();
- UserPortalConfigService service =
getApplicationComponent(UserPortalConfigService.class);
- Page page = service.getPage(value, ctx.getRemoteUser());
- page_ = page;
- super.setValue(value);
- return this;
- }
-
- public Page getPage()
- {
- return page_;
- }
-
- public void setPage(Page page)
- {
- page_ = page;
- }
-
- public Class<String> getTypeValue()
- {
- return String.class;
- }
-
- public void processDecode(WebuiRequestContext context) throws Exception
- {
- super.processDecode(context);
- UIPageBrowser uiPageBrowser = findFirstComponentOfType(UIPageBrowser.class);
- uiPageBrowser.processDecode(context);
-
- UIFormInputSet uiInputSet = getChild(UIFormInputSet.class);
-
- List<UIComponent> children = uiInputSet.getChildren();
- for (UIComponent ele : children)
- {
- ele.processDecode(context);
- }
- // UIFormStringInput uiPageId = getChildById("pageId");
- // uiPageId.processDecode(context);
- //
- // UIFormStringInput uiPageName = getChildById("pageName");
- // uiPageName.processDecode(context);
- //
- // UIFormStringInput uiPageTitle = getChildById("pageTitle");
- // uiPageTitle.processDecode(context);
- }
-
- static public class SelectPageActionListener extends
EventListener<UIPageBrowser>
- {
- public void execute(Event<UIPageBrowser> event) throws Exception
- {
- UIPageBrowser uiPageBrowser = event.getSource();
- String id = event.getRequestContext().getRequestParameter(OBJECTID);
- WebuiRequestContext ctx = event.getRequestContext();
- UIApplication uiApp = ctx.getUIApplication();
- UIPageSelector2 uiPageSelector =
uiPageBrowser.getAncestorOfType(UIPageSelector2.class);
- UserPortalConfigService service =
uiPageBrowser.getApplicationComponent(UserPortalConfigService.class);
- UserACL userACL = uiPageBrowser.getApplicationComponent(UserACL.class);
- if (!userACL.hasPermission(service.getPage(id)))
- {
- uiApp.addMessage(new
ApplicationMessage("UIPageBrowser.msg.NoPermission", new String[]{id}));;
- }
- uiPageSelector.setValue(id);
- uiPageBrowser.feedDataWithQuery(null);
-
- UIForm uiForm = uiPageSelector.getAncestorOfType(UIForm.class);
- if (uiForm != null)
- {
- ctx.addUIComponentToUpdateByAjax(uiForm.getParent());
- }
- else
- {
- ctx.addUIComponentToUpdateByAjax(uiPageSelector.getParent());
- }
- UIFormPopupWindow uiPopup = uiPageSelector.getChild(UIFormPopupWindow.class);
- uiPopup.setShow(false);
- }
- }
-
-}