Author: gttersen
Date: 2007-05-16 14:03:42 +0200 (Wed, 16 May 2007)
New Revision: 5099

Modified:
   
branches/2.12/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/NavigationCommand.java
   
branches/2.12/search-command-config-spi/src/main/java/no/schibstedsok/searchportal/mode/config/NavigationCommandConfig.java
Log:
NewsAggregator fixed navigation bug

Modified: 
branches/2.12/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/NavigationCommand.java
===================================================================
--- 
branches/2.12/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/NavigationCommand.java
       2007-05-16 12:01:29 UTC (rev 5098)
+++ 
branches/2.12/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/NavigationCommand.java
       2007-05-16 12:03:42 UTC (rev 5099)
@@ -11,9 +11,11 @@
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.ListIterator;
 import java.util.Set;
 import java.util.concurrent.ExecutionException;
 
@@ -84,13 +86,13 @@
          * @param name the id of the navigator to get.
          * @return a list with extended navigators
          */
-        public List<ExtendedNavigator> getNavigators(String name) {
+        public NavigatorList getNavigators(String name) {
             NavigationCommandConfig.Nav navEntry = 
extendedNavigationConfig.getNavMap().get(name);
             try {
                 if (navEntry != null) {
                     boolean selectionDone = false;
                     StringDataObject selectedValue = 
context.getDataModel().getParameters().getValue(name);
-                    List<ExtendedNavigator> extendedNavigators = new 
ArrayList<ExtendedNavigator>();
+                    NavigatorList extendedNavigators = new NavigatorList(new 
ArrayList<ExtendedNavigator>());
                     FastSearchResult fsr = null;
                     if (navEntry.getCommandName() != null) {
                         SearchResult searchResult = 
context.getRunningQuery().getSearchResult(navEntry.getCommandName());
@@ -100,12 +102,11 @@
                             if (modifiers != null && modifiers.size() > 0) {
                                 for (Modifier modifier : modifiers) {
                                     final String navigatorName = 
modifier.getNavigator() == null ? null : modifier.getNavigator().getName();
-                                    final String value = 
navEntry.isRealNavigator() && navigatorName != null ? navigatorName : 
modifier.getName();
                                     final String urlFragment = 
getUrlFragment(navEntry, modifier.getName(), navigatorName);
-                                    ExtendedNavigator navigator = new 
ExtendedNavigator(modifier.getName(), urlFragment, modifier.getCount());
+                                    final ExtendedNavigator navigator = new 
ExtendedNavigator(modifier.getName(), urlFragment, modifier.getCount());
                                     if (!selectionDone) {
                                         selectedValue = 
context.getDataModel().getParameters().getValue(navEntry.getField());
-                                        if (selectedValue != null && 
selectedValue.getString().equals(value)) {
+                                        if (selectedValue != null && 
selectedValue.getString().equals(modifier.getName())) {
                                             navigator.setSelected(true);
                                             selectionDone = true;
                                         }
@@ -285,6 +286,143 @@
         }
     }
 
+    public static class NavigatorList implements List<ExtendedNavigator> {
+        private List<ExtendedNavigator> proxiedList;
+        private boolean dirty = true;
+        private ExtendedNavigator selectedItem;
+
+        public NavigatorList(List<ExtendedNavigator> proxiedList) {
+            this.proxiedList = proxiedList;
+        }
+
+        public ExtendedNavigator getSelected() {
+            findSelection();
+            return selectedItem;
+        }
+
+        private void findSelection() {
+            if (dirty) {
+                selectedItem = null;
+                for (ExtendedNavigator extendedNavigator : proxiedList) {
+                    if (extendedNavigator.isSelected()) {
+                        selectedItem = extendedNavigator;
+                        break;
+                    }
+                }
+            }
+            dirty = false;
+        }
+
+        public boolean hasSelection() {
+            findSelection();
+            return selectedItem != null;
+        }
+
+        public int size() {
+            return proxiedList.size();
+        }
+
+        public boolean isEmpty() {
+            return proxiedList.isEmpty();
+        }
+
+        public boolean contains(Object o) {
+            return proxiedList.contains(o);
+        }
+
+        public Iterator<ExtendedNavigator> iterator() {
+            dirty = true;
+            return proxiedList.iterator();
+        }
+
+        public Object[] toArray() {
+            return proxiedList.toArray();
+        }
+
+        public <T> T[] toArray(T[] a) {
+            return proxiedList.toArray(a);
+        }
+
+        public boolean add(ExtendedNavigator t) {
+            dirty = true;
+            return proxiedList.add(t);
+        }
+
+        public boolean remove(Object o) {
+            return proxiedList.remove(o);
+        }
+
+        public boolean containsAll(Collection<?> c) {
+            return proxiedList.containsAll(c);
+        }
+
+        public boolean addAll(Collection<? extends ExtendedNavigator> c) {
+            dirty = true;
+            return proxiedList.addAll(c);
+        }
+
+        public boolean addAll(int index, Collection<? extends 
ExtendedNavigator> c) {
+            dirty = true;
+            return proxiedList.addAll(index, c);
+        }
+
+        public boolean removeAll(Collection<?> c) {
+            dirty = true;
+            return proxiedList.removeAll(c);
+        }
+
+        public boolean retainAll(Collection<?> c) {
+            dirty = true;
+            return proxiedList.retainAll(c);
+        }
+
+        public void clear() {
+            dirty = true;
+            proxiedList.clear();
+        }
+
+        public ExtendedNavigator get(int index) {
+            return proxiedList.get(index);
+        }
+
+        public ExtendedNavigator set(int index, ExtendedNavigator element) {
+            dirty = true;
+            return proxiedList.set(index, element);
+        }
+
+        public void add(int index, ExtendedNavigator element) {
+            dirty = true;
+            proxiedList.add(index, element);
+        }
+
+        public ExtendedNavigator remove(int index) {
+            dirty = true;
+            return proxiedList.remove(index);
+        }
+
+        public int indexOf(Object o) {
+            return proxiedList.indexOf(o);
+        }
+
+        public int lastIndexOf(Object o) {
+            return proxiedList.lastIndexOf(o);
+        }
+
+        public ListIterator<ExtendedNavigator> listIterator() {
+            dirty = true;
+            return proxiedList.listIterator();
+        }
+
+        public ListIterator<ExtendedNavigator> listIterator(int index) {
+            dirty = true;
+            return proxiedList.listIterator(index);
+        }
+
+        public List<ExtendedNavigator> subList(int fromIndex, int toIndex) {
+            return proxiedList.subList(fromIndex, toIndex);
+        }
+    }
+
     /**
      * This is the interface class to velocity.
      */

Modified: 
branches/2.12/search-command-config-spi/src/main/java/no/schibstedsok/searchportal/mode/config/NavigationCommandConfig.java
===================================================================
--- 
branches/2.12/search-command-config-spi/src/main/java/no/schibstedsok/searchportal/mode/config/NavigationCommandConfig.java
 2007-05-16 12:01:29 UTC (rev 5098)
+++ 
branches/2.12/search-command-config-spi/src/main/java/no/schibstedsok/searchportal/mode/config/NavigationCommandConfig.java
 2007-05-16 12:03:42 UTC (rev 5099)
@@ -122,9 +122,7 @@
         private HashMap<String, Nav> navMap;
         private Set<String> resetNavSet;
         private static final String RESET_NAV_ELEMENT = "reset-nav";
-        private Nav selectedNav;
 
-
         public Navigation() {
         }
 
@@ -178,14 +176,6 @@
             }
         }
 
-        public Nav getSelectedNav() {
-            return selectedNav;
-        }
-
-        public void setSelectedNav(Nav selectedNav) {
-            this.selectedNav = selectedNav;
-        }
-
         public String getId() {
             return id;
         }

_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits

Reply via email to