Author: julien_viet
Date: 2011-08-16 03:08:43 -0400 (Tue, 16 Aug 2011)
New Revision: 7143
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java
portal/branches/api/component/api-impl/src/test/java/org/gatein/portal/api/impl/portal/NavigationTestCase.java
Log:
more work about API
Modified:
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java
===================================================================
---
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java 2011-08-16
06:45:32 UTC (rev 7142)
+++
portal/branches/api/component/api-impl/src/main/java/org/gatein/portal/api/impl/portal/NavigationImpl.java 2011-08-16
07:08:43 UTC (rev 7143)
@@ -37,25 +37,22 @@
import org.exoplatform.web.url.navigation.NavigationResource;
import org.exoplatform.web.url.navigation.NodeURL;
import org.gatein.api.GateIn;
-import org.gatein.api.id.Identifiable;
import org.gatein.api.portal.Navigation;
import org.gatein.api.portal.Page;
import org.gatein.api.portal.Site;
-import org.gatein.api.util.IterableIdentifiableCollection;
-import org.gatein.common.NotYetImplemented;
import org.gatein.common.text.EntityEncoder;
import org.gatein.common.util.EmptyResourceBundle;
import org.gatein.portal.api.impl.GateInImpl;
-import org.gatein.portal.api.impl.util.AdaptedIterableIdentifiableCollection;
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;
import java.util.ResourceBundle;
/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
-public class NavigationImpl implements Navigation, Identifiable<Navigation>
+public class NavigationImpl implements Navigation
{
private final NodeContext<NavigationImpl> context;
private SiteImpl site;
@@ -83,7 +80,7 @@
s.append("-target->").append(pageRef);
}
- if (size() != 0)
+ if (context.getNodeCount() != 0)
{
loadChildrenIfNeeded();
s.append("\n|");
@@ -98,11 +95,6 @@
return s.toString();
}
- public NodeContext<NavigationImpl> getContext()
- {
- return context;
- }
-
public URI getURI()
{
if (uri != null)
@@ -131,7 +123,6 @@
}
}
-
private StringBuilder buildURI()
{
NavigationImpl parent = context.getParentNode();
@@ -150,7 +141,6 @@
}
}
-
public Page getTargetPage()
{
String pageRef = context.getState().getPageRef();
@@ -195,22 +185,10 @@
return site;
}
- public IterableIdentifiableCollection<Navigation> getAll()
+ public Collection<? extends Navigation> getChildren()
{
loadChildrenIfNeeded();
-
- return new AdaptedIterableIdentifiableCollection<NavigationImpl,
Navigation>(size(), context.iterator())
- {
- public Navigation adapt(NavigationImpl old)
- {
- return old;
- }
-
- public boolean contains(org.gatein.api.id.Id<Navigation> id)
- {
- return NavigationImpl.this.contains(id);
- }
- };
+ return context.getNodes();
}
private void loadChildrenIfNeeded()
@@ -230,64 +208,19 @@
}
}
- public int size()
+ public Navigation getChild(String name)
{
- return context.getNodeSize();
- }
-
- public boolean contains(String key)
- {
- return contains(getIdForChild(key));
- }
-
- public boolean contains(org.gatein.api.id.Id<Navigation> navigationId)
- {
- loadChildrenIfNeeded();
-
- return getChild(navigationId) != null;
- }
-
- private NodeContext<NavigationImpl>
getChild(org.gatein.api.id.Id<Navigation> navigationId)
- {
-// return context.get(navigationId.getComponent(GateInImpl.NAVIGATION_COMPONENT));
- throw new UnsupportedOperationException();
- }
-
- public Navigation createAndAdd(String key)
- {
- return createAndAdd(getIdForChild(key));
- }
-
- public Navigation createAndAdd(org.gatein.api.id.Id<Navigation> navigationId)
- {
- throw new NotYetImplemented(); // TODO
- }
-
- public Navigation get(String key)
- {
- return context.getNode(key);
- }
-
- public Navigation get(org.gatein.api.id.Id<Navigation> navigationId)
- {
- if (navigationId == null)
+ if (name == null)
{
return null;
}
else
{
loadChildrenIfNeeded();
- final NodeContext<NavigationImpl> child = getChild(navigationId);
- return child != null ? child.getNode() : null;
+ return context.getNode(name);
}
}
- public Navigation.Id getIdForChild(String key)
- {
-// return site.getIdForChild(key);
- throw new UnsupportedOperationException();
- }
-
public Navigation.Id getId()
{
if (id == null)
@@ -344,7 +277,6 @@
return RequestContext.getCurrentInstance().getLocale();
}
-
public ResourceBundle getBundle()
{
if (bundle == null)
Modified:
portal/branches/api/component/api-impl/src/test/java/org/gatein/portal/api/impl/portal/NavigationTestCase.java
===================================================================
---
portal/branches/api/component/api-impl/src/test/java/org/gatein/portal/api/impl/portal/NavigationTestCase.java 2011-08-16
06:45:32 UTC (rev 7142)
+++
portal/branches/api/component/api-impl/src/test/java/org/gatein/portal/api/impl/portal/NavigationTestCase.java 2011-08-16
07:08:43 UTC (rev 7143)
@@ -99,7 +99,7 @@
Navigation rootNav = site.getNavigation();
assertSame(site, rootNav.getSite());
assertNotNull(rootNav);
- Iterator<Navigation> i = rootNav.getAll().iterator();
+ Iterator<? extends Navigation> i = rootNav.getChildren().iterator();
assertFalse(i.hasNext());
}
@@ -111,18 +111,18 @@
//
Site site = gatein.getPortal(new Site.Id(Site.PORTAL, "classic"));
Navigation rootNav = site.getNavigation();
- Iterator<Navigation> i = rootNav.getAll().iterator();
+ Iterator<? extends Navigation> i = rootNav.getChildren().iterator();
assertTrue(i.hasNext());
Navigation homeNav = i.next();
assertSame(site, homeNav.getSite());
assertEquals("home", homeNav.getName());
- assertSame(homeNav, rootNav.get("home"));
+ assertSame(homeNav, rootNav.getChild("home"));
assertFalse(i.hasNext());
}
public void testPage()
{
- NodeContext home = root.add(null, "home");
+ root.add(null, "home");
navService.saveNode(root, null);
//
@@ -133,13 +133,13 @@
//
Navigation rootNav = site.getNavigation();
- Navigation homeNav = rootNav.get("home");
+ Navigation homeNav = rootNav.getChild("home");
assertNull(homeNav.getTargetPage());
homeNav.setTargetPage(homePage);
assertSame(homePage, homeNav.getTargetPage());
//
- homeNav.setTargetPage((Page)null);
+ homeNav.setTargetPage(null);
assertNull(null, homeNav.getTargetPage());
}
}