Author: gttersen
Date: 2007-05-06 18:11:30 +0200 (Sun, 06 May 2007)
New Revision: 5000

Added:
   
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
Modified:
   
branches/2.12/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/AbstractSearchCommand.java
Log:
NewsAggregator changes

Modified: 
branches/2.12/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/AbstractSearchCommand.java
===================================================================
--- 
branches/2.12/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/AbstractSearchCommand.java
   2007-05-06 10:04:25 UTC (rev 4999)
+++ 
branches/2.12/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/AbstractSearchCommand.java
   2007-05-06 16:11:30 UTC (rev 5000)
@@ -420,6 +420,7 @@
             executeQuery |= null != parameters.get("c") && 
parameters.get("c").equals("nc") && getTransformedQuery().trim().length() > 0;
             executeQuery |= null != parameters.get("c") && 
parameters.get("c").equals("nm") && getTransformedQuery().trim().length() > 0;
             executeQuery |= this instanceof NewsMyNewsSearchCommand;
+            executeQuery |= this instanceof NavigationCommand;
 
             executeQuery |= null != filter && filter.length() > 0;
             LOG.info("executeQuery==" + executeQuery

Added: 
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
                               (rev 0)
+++ 
branches/2.12/core-api/src/main/java/no/schibstedsok/searchportal/mode/command/NavigationCommand.java
       2007-05-06 16:11:30 UTC (rev 5000)
@@ -0,0 +1,310 @@
+package no.schibstedsok.searchportal.mode.command;
+
+import no.schibstedsok.searchportal.datamodel.generic.StringDataObject;
+import no.schibstedsok.searchportal.mode.config.NavigationCommandConfig;
+import no.schibstedsok.searchportal.result.FastSearchResult;
+import no.schibstedsok.searchportal.result.Modifier;
+import no.schibstedsok.searchportal.result.SearchResult;
+import org.apache.log4j.Logger;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+
+/**
+ * This is a command to help generating navigation urls in the view. I got 
tired of all
+ * the URL handling velocity code. Some of the effects from this is virtually 
impossible to
+ * code in velocity.
+ * <p/>
+ * This should be a multiResult resulthandler, but right now this just a 
waiting searchCommand.
+ * Usually there will be no real waiting since the calls on the results occur 
from velocity.
+ * <p/>
+ * As a bonus from using this, you don't need to data-model the commands that 
only are
+ * there for navigation.
+ *
+ * @author Geir H. Pettersen(T-Rank)
+ */
+public class NavigationCommand extends AbstractSearchCommand {
+    private static final Logger LOG = 
Logger.getLogger(NavigationCommand.class);
+
+    /**
+     * @param cxt The context to execute in.
+     */
+    public NavigationCommand(Context cxt) {
+        super(cxt);
+    }
+
+    public SearchResult execute() {
+        NavigationCommandConfig config = getSearchConfiguration();
+        return new ExtendedNavigationSearchResult(this, 
config.getExtendedNavigationConfig(), context);
+    }
+
+    @Override
+    public NavigationCommandConfig getSearchConfiguration() {
+        return (NavigationCommandConfig) super.getSearchConfiguration();
+    }
+
+    public static class ExtendedNavigationSearchResult extends 
FastSearchResult {
+        private ExtendedNavigation extendedNavigation;
+
+
+        public ExtendedNavigationSearchResult(NavigationCommand command, 
NavigationCommandConfig.ExtendedNavigationConfig extendedNavigationConfig, 
Context context) {
+            super(command);
+            this.extendedNavigation = new 
ExtendedNavigation(extendedNavigationConfig, context);
+        }
+
+        public ExtendedNavigation getExtendedNavigation() {
+            return extendedNavigation;
+        }
+    }
+
+    public static class ExtendedNavigation {
+        private NavigationCommandConfig.ExtendedNavigationConfig 
extendedNavigationConfig;
+        private Context context;
+
+
+        public 
ExtendedNavigation(NavigationCommandConfig.ExtendedNavigationConfig 
extendedNavigationConfig, Context context) {
+            this.extendedNavigationConfig = extendedNavigationConfig;
+            this.context = context;
+        }
+
+        public NavigationCommandConfig.Navigation getNavigation(String id) {
+            return extendedNavigationConfig.getNavigationMap().get(id);
+        }
+
+        /**
+         * Returns extended navigators for a name(id)
+         *
+         * @param name the id of the navigator to get.
+         * @return a list with extended navigators
+         */
+        public List<ExtendedNavigator> 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>();
+                    FastSearchResult fsr = null;
+                    if (navEntry.getCommandName() != null) {
+                        SearchResult searchResult = 
context.getRunningQuery().getSearchResult(navEntry.getCommandName());
+                        if (searchResult instanceof FastSearchResult) {
+                            fsr = (FastSearchResult) searchResult;
+                            List<Modifier> modifiers = 
fsr.getModifiers(navEntry.isRealNavigator() ? navEntry.getField() : name);
+                            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, value);
+                                    ExtendedNavigator navigator = new 
ExtendedNavigator(modifier.getName(), urlFragment, modifier.getCount());
+                                    if (!selectionDone) {
+                                        selectedValue = 
context.getDataModel().getParameters().getValue(navEntry.getField());
+                                        LOG.debug("Value = " + 
navEntry.getField() + ",Comparing " + (selectedValue == null ? "" : 
selectedValue.getString()) + " with " + value);
+                                        if (selectedValue != null && 
selectedValue.getString().equals(value)) {
+                                            navigator.setSelected(true);
+                                            selectionDone = true;
+                                        }
+                                    }
+                                    extendedNavigators.add(navigator);
+                                }
+                            }
+                        }
+                    }
+                    getOptionNavigators(navEntry, fsr, extendedNavigators, 
selectedValue);
+                    return extendedNavigators;
+                }
+
+            } catch (InterruptedException e) {
+                LOG.error("Could not get searchResult for " + 
navEntry.getCommandName(), e);
+            } catch (ExecutionException e) {
+                LOG.error("Could not get searchResult for " + 
navEntry.getCommandName(), e);
+            }
+            return null;
+        }
+
+
+        private void getOptionNavigators(NavigationCommandConfig.Nav navEntry, 
FastSearchResult fsr, List<ExtendedNavigator> extendedNavigators, 
StringDataObject selectedValue) {
+            // Only used by getNavigators. Mainly to split code.
+            if (extendedNavigators.size() > 0 && navEntry.getOptions().size() 
> 0) {
+                // Navigators already collected. Options is override
+                Iterator<ExtendedNavigator> it = extendedNavigators.iterator();
+                while (it.hasNext()) {
+                    boolean match = false;
+                    ExtendedNavigator navigator = it.next();
+                    // Double loop to find match in two lists. Not nice, but 
it works.
+                    for (NavigationCommandConfig.Option option : 
navEntry.getOptions()) {
+                        String value = option.getValue();
+                        if (navigator.name.equals(value)) {
+                            match = true;
+                            if (selectedValue == null && 
option.isDefaultSelect()) {
+                                navigator.setSelected(true);
+                            }
+                            if (option.getDisplayName() != null) {
+                                navigator.setName(option.getDisplayName());
+                            }
+                        }
+                    }
+                    if (!match) {
+                        it.remove();
+                    }
+                }
+            } else {
+                final StringDataObject optionSelectedValue = 
context.getDataModel().getParameters().getValue(navEntry.getField());
+                for (NavigationCommandConfig.Option option : 
navEntry.getOptions()) {
+                    String value = option.getValue();
+                    if (option.getValueRef() != null && fsr != null) {
+                        String tmp = fsr.getField(option.getValueRef());
+                        if (tmp != null && tmp.length() > 0) {
+                            value = tmp;
+                        }
+                    }
+                    if (value != null) {
+                        ExtendedNavigator navigator = new 
ExtendedNavigator(option.getDisplayName(), getUrlFragment(navEntry, value), -1);
+                        extendedNavigators.add(navigator);
+                        if (optionSelectedValue == null && 
option.isDefaultSelect()) {
+                            navigator.setSelected(true);
+                        } else if (optionSelectedValue != null && 
optionSelectedValue.getString().equals(value)) {
+                            navigator.setSelected(true);
+                        }
+                    }
+                }
+            }
+        }
+
+        /**
+         * Gets the url fragment you should use when navigating on this value.
+         *
+         * @param navigator the navigator you are using
+         * @param value     the specific field you are using
+         * @return a url fragemt to use
+         */
+        public String getUrlFragment(String navigator, String value) {
+            NavigationCommandConfig.Nav navEntry = 
extendedNavigationConfig.getNavMap().get(navigator);
+            return getUrlFragment(navEntry, value);
+        }
+
+        public String getUrlFragment(NavigationCommandConfig.Nav navEntry, 
String value) {
+            StringBuilder sb = new StringBuilder();
+            String tab = navEntry.getTab();
+            if (tab == null) {
+                tab = 
context.getDataModel().getParameters().getValue("c").getUtf8UrlEncoded();
+            }
+            sb.append("c=").append(tab);
+            if (!navEntry.isExcludeQuery()) {
+                
sb.append("&q=").append(context.getDataModel().getQuery().getUtf8UrlEncoded());
+            }
+            if (value != null && value.length() > 0) {
+                
sb.append('&').append(enc(navEntry.getField())).append('=').append(enc(value));
+            }
+            if (!navEntry.isOut()) {
+                addParentFragment(sb, navEntry);
+                for (NavigationCommandConfig.Navigation navigation : 
extendedNavigationConfig.getNavigationList()) {
+                    if (navigation != navEntry.getNavigation()) {
+                        addNavigationFragments(navigation, sb, navEntry);
+                    }
+                }
+            }
+            for (String key : navEntry.getStaticParameters().keySet()) {
+                addFragment(sb, navEntry, key, 
navEntry.getStaticParameters().get(key));
+            }
+            return sb.toString();
+        }
+
+        private void addNavigationFragments(NavigationCommandConfig.Navigation 
navigation, StringBuilder sb, NavigationCommandConfig.Nav navEntry) {
+            final Set<String> fieldFilterSet = new HashSet<String>();
+            for (NavigationCommandConfig.Nav nav : navigation.getNavList()) {
+                StringDataObject fieldValue = 
context.getDataModel().getParameters().getValue(nav.getField());
+                if (!fieldFilterSet.contains(nav.getField())) {
+                    addPreviousField(fieldValue, sb, navEntry, nav.getField());
+                    fieldFilterSet.add(nav.getField());
+                    for (String staticKey : 
nav.getStaticParameters().keySet()) {
+                        fieldValue = 
context.getDataModel().getParameters().getValue(staticKey);
+                        if (!fieldFilterSet.contains(staticKey)) {
+                            addPreviousField(fieldValue, sb, navEntry, 
staticKey);
+                        }
+                    }
+                }
+            }
+        }
+
+        private void addPreviousField(StringDataObject fieldValue, 
StringBuilder sb, NavigationCommandConfig.Nav navEntry, String fieldName) {
+            if (fieldValue != null && addFragment(sb, navEntry, fieldName, 
fieldValue.getString())) {
+                fieldValue = 
context.getDataModel().getParameters().getValue("nav_" + fieldName);
+                if (fieldValue != null) {
+                    addFragment(sb, navEntry, "nav_" + fieldName, 
fieldValue.getString());
+                }
+            }
+        }
+
+        private boolean addFragment(StringBuilder sb, 
NavigationCommandConfig.Nav nav, String id, String value) {
+            if (!nav.getNavigation().getResetNavSet().contains(id)) {
+                sb.append('&').append(enc(id)).append('=').append(enc(value));
+                return true;
+            }
+            return false;
+        }
+
+        private void addParentFragment(StringBuilder sb, 
NavigationCommandConfig.Nav navEntry) {
+            NavigationCommandConfig.Nav parentNav = navEntry.getParentNav();
+            if (parentNav != null) {
+                StringDataObject fieldValue = 
context.getDataModel().getParameters().getValue(parentNav.getField());
+                addPreviousField(fieldValue, sb, navEntry, 
parentNav.getField());
+                addParentFragment(sb, parentNav);
+            }
+        }
+
+        private String enc(String str) {
+            try {
+                return URLEncoder.encode(str, "UTF-8");
+            } catch (UnsupportedEncodingException e) {
+                LOG.fatal("UTF-8 encoding not available");
+            }
+            return str;
+        }
+    }
+
+    /**
+     * This is the interface class to velocity.
+     */
+    public static class ExtendedNavigator {
+        private String name;
+        private String urlFragment;
+        private int count;
+        private boolean selected = false;
+
+        public ExtendedNavigator(String displayName, String urlFragment, int 
count) {
+            this.name = displayName;
+            this.urlFragment = urlFragment;
+            this.count = count;
+        }
+
+        public void setSelected(boolean selected) {
+            this.selected = selected;
+        }
+
+        public boolean isSelected() {
+            return selected;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public String getUrlFragment() {
+            return urlFragment;
+        }
+
+        public int getCount() {
+            return count;
+        }
+    }
+}

Added: 
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
                         (rev 0)
+++ 
branches/2.12/search-command-config-spi/src/main/java/no/schibstedsok/searchportal/mode/config/NavigationCommandConfig.java
 2007-05-06 16:11:30 UTC (rev 5000)
@@ -0,0 +1,490 @@
+package no.schibstedsok.searchportal.mode.config;
+
+import no.schibstedsok.searchportal.mode.config.CommandConfig.Controller;
+import no.schibstedsok.searchportal.site.config.AbstractDocumentFactory;
+import static 
no.schibstedsok.searchportal.site.config.AbstractDocumentFactory.ParseType;
+import org.apache.log4j.Logger;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * This is a command to help generating navigation urls in the view. I got 
tired of all
+ * the URL handling velocity code.
+ * <p/>
+ * This should be a multiResult resulthandler, but right now this just a 
waiting searchCommand.
+ * Usually there will be no real waiting since the calls on the results occur 
from velocity.
+ * <p/>
+ * As a bonus from using this, you don't need to data-model the commands that 
only are
+ * there for navigation.
+ *
+ * @author Geir H. Pettersen(T-Rank)
+ */
[EMAIL PROTECTED]("NavigationCommand")
+public class NavigationCommandConfig extends CommandConfig {
+    private static final Logger LOG = 
Logger.getLogger(NavigationCommandConfig.class);
+    private ExtendedNavigationConfig extendedNavigationConfig;
+    private static final String NAVIGATION_ELEMENT = "navigation";
+    private static final String NAV_ELEMENT = "nav";
+
+    public NavigationCommandConfig() {
+    }
+
+    public NavigationCommandConfig(SearchConfiguration sc) {
+        if (sc instanceof NavigationCommandConfig) {
+            extendedNavigationConfig = ((NavigationCommandConfig) 
sc).getExtendedNavigationConfig();
+        }
+    }
+
+    public ExtendedNavigationConfig getExtendedNavigationConfig() {
+        return extendedNavigationConfig;
+    }
+
+    public void setExtendedNavigationConfig(ExtendedNavigationConfig 
extendedNavigationConfig) {
+        this.extendedNavigationConfig = extendedNavigationConfig;
+    }
+
+    private static List<Element> getDirectChildren(Element element, String 
elementName) {
+        ArrayList<Element> children = new ArrayList<Element>();
+        if (element != null) {
+            NodeList childNodes = element.getChildNodes();
+            for (int i = 0; i < childNodes.getLength(); i++) {
+                Node childNode = childNodes.item(i);
+                if (childNode instanceof Element && 
childNode.getNodeName().equals(elementName)) {
+                    children.add((Element) childNode);
+                }
+            }
+        }
+        return children;
+    }
+
+
+    @Override
+    public CommandConfig readSearchConfiguration(final Element element, final 
SearchConfiguration inherit) {
+        super.readSearchConfiguration(element, inherit);
+        LOG.debug("------------- Reading search configuration ------------");
+        List<Element> navigationElements = getDirectChildren(element, 
NAVIGATION_ELEMENT);
+        HashMap<String, Nav> navMap = new HashMap<String, Nav>();
+        HashMap<String, Navigation> navigationMap = new HashMap<String, 
Navigation>();
+        List<Navigation> navigationList = new 
ArrayList<Navigation>(navigationElements.size());
+        for (Element navigationElement : navigationElements) {
+            Navigation navigation = new Navigation(navigationElement, navMap);
+            navigationList.add(navigation);
+            if (navigation.getId() != null) {
+                navigationMap.put(navigation.getId(), navigation);
+            }
+        }
+        extendedNavigationConfig = new ExtendedNavigationConfig(navMap, 
navigationMap, navigationList);
+        LOG.debug("-------------------------------------------------------");
+        return this;
+    }
+
+    /**
+     * Clients may want to access this config to get info on available 
navigations.
+     */
+    public static class ExtendedNavigationConfig {
+        private HashMap<String, Nav> navMap;
+        private HashMap<String, Navigation> navigationMap;
+        private List<Navigation> navigationList;
+
+        public ExtendedNavigationConfig(HashMap<String, Nav> navMap, 
HashMap<String, Navigation> navigationMap, List<Navigation> navigationList) {
+            this.navigationMap = navigationMap;
+            this.navMap = navMap;
+            this.navigationList = navigationList;
+        }
+
+        public HashMap<String, Nav> getNavMap() {
+            return navMap;
+        }
+
+        public HashMap<String, Navigation> getNavigationMap() {
+            return navigationMap;
+        }
+
+        public List<Navigation> getNavigationList() {
+            return navigationList;
+        }
+    }
+
+    public static class Navigation {
+        private String id;
+        private String commandName;
+        private String tab;
+        private boolean out = false;
+        private List<Nav> navList;
+        private HashMap<String, Nav> navMap;
+        private Set<String> resetNavSet;
+        private static final String RESET_NAV_ELEMENT = "reset-nav";
+        private Nav selectedNav;
+
+
+        public Navigation() {
+        }
+
+        public Navigation(Element navigationElement, HashMap<String, Nav> 
navMap) {
+            AbstractDocumentFactory.fillBeanProperty(this, null, "id", 
ParseType.String, navigationElement, null);
+            AbstractDocumentFactory.fillBeanProperty(this, null, 
"commandName", ParseType.String, navigationElement, null);
+            AbstractDocumentFactory.fillBeanProperty(this, null, "tab", 
ParseType.String, navigationElement, null);
+            AbstractDocumentFactory.fillBeanProperty(this, null, "out", 
ParseType.Boolean, navigationElement, null);
+
+            final List<Element> navElements = 
getDirectChildren(navigationElement, NAV_ELEMENT);
+            navList = new ArrayList<Nav>(navElements.size());
+            this.navMap = new HashMap<String, Nav>();
+            for (Element navElement : navElements) {
+                Nav nav = new Nav(this, navElement);
+                navList.add(nav);
+                updateNavMap(nav, navMap);
+                updateNavMap(nav, this.navMap);
+            }
+            final List<Element> resetNavElements = 
getDirectChildren(navigationElement, RESET_NAV_ELEMENT);
+            resetNavSet = new HashSet<String>(resetNavElements.size());
+            for (Element resetNavElement : resetNavElements) {
+                String id = resetNavElement.getAttribute("id");
+                if (id != null) {
+                    resetNavSet.add(id);
+                }
+            }
+        }
+
+        private void updateNavMap(Nav nav, HashMap<String, Nav> navMap) {
+            navMap.put(nav.getId(), nav);
+            if (nav.getChildNavs() != null && nav.getChildNavs().size() > 0) {
+                for (Nav subNav : nav.getChildNavs()) {
+                    updateNavMap(subNav, navMap);
+                }
+            }
+        }
+
+        public Nav getSelectedNav() {
+            return selectedNav;
+        }
+
+        public void setSelectedNav(Nav selectedNav) {
+            this.selectedNav = selectedNav;
+        }
+
+        public String getId() {
+            return id;
+        }
+
+        public void setId(String id) {
+            this.id = id;
+        }
+
+        public HashMap<String, Nav> getNavMap() {
+            return navMap;
+        }
+
+        public List<Nav> getNavList() {
+            return navList;
+        }
+
+        public Set<String> getResetNavSet() {
+            return resetNavSet;
+        }
+
+        public void setNavList(List<Nav> navList) {
+            this.navList = navList;
+        }
+
+        public String getTab() {
+            return tab;
+        }
+
+        public void setTab(String tab) {
+            this.tab = tab;
+        }
+
+        public String getCommandName() {
+            return commandName;
+        }
+
+        public void setCommandName(String commandName) {
+            this.commandName = commandName;
+        }
+
+        public boolean isOut() {
+            return out;
+        }
+
+        public void setOut(boolean out) {
+            this.out = out;
+        }
+
+        public String toString() {
+            return "\nNavigation{" +
+                    "commandName='" + commandName + '\'' +
+                    ", tab='" + tab + '\'' +
+                    ", out=" + out +
+                    ", navList=" + navList +
+                    ", resetNavSet=" + resetNavSet +
+                    '}';
+        }
+    }
+
+    public static class Nav {
+        private static final String OPTION_ELEMENT = "option";
+        private static final String STATIC_PARAMETER_ELEMENT = 
"static-parameter";
+        private String id;
+        private String commandName;
+        private String field;
+        private String tab;
+        private boolean out;
+        private boolean realNavigator;
+
+        private List<Option> options;
+        private Map<String, String> staticParameters;
+        private List<Nav> childNavs;
+        private Navigation navigation;
+        private Nav parentNav;
+        private boolean excludeQuery = false;
+
+        private Nav(Nav parentNav, Navigation navigation, Element navElement) {
+            this.navigation = navigation;
+            this.parentNav = parentNav;
+            AbstractDocumentFactory.fillBeanProperty(this, null, 
"commandName", ParseType.String, navElement, navigation.getCommandName());
+            AbstractDocumentFactory.fillBeanProperty(this, null, "id", 
ParseType.String, navElement, null);
+            AbstractDocumentFactory.fillBeanProperty(this, null, "field", 
ParseType.String, navElement, id);
+            AbstractDocumentFactory.fillBeanProperty(this, null, "tab", 
ParseType.String, navElement, navigation.getTab());
+            AbstractDocumentFactory.fillBeanProperty(this, null, "out", 
ParseType.Boolean, navElement, Boolean.toString(navigation.isOut()));
+            AbstractDocumentFactory.fillBeanProperty(this, null, 
"excludeQuery", ParseType.Boolean, navElement, "false");
+            AbstractDocumentFactory.fillBeanProperty(this, null, 
"realNavigator", ParseType.Boolean, navElement, "true");
+
+            final List<Element> childNavElements = 
getDirectChildren(navElement, NAV_ELEMENT);
+            if (childNavElements.size() > 0) {
+                childNavs = new ArrayList<Nav>(childNavElements.size());
+                for (Element childNavElement : childNavElements) {
+                    childNavs.add(new Nav(this, this.navigation, 
childNavElement));
+                }
+            }
+            final List<Element> optionElements = getDirectChildren(navElement, 
OPTION_ELEMENT);
+            options = new ArrayList<Option>(optionElements.size());
+            for (Element optionElement : optionElements) {
+                options.add(new Option(optionElement));
+            }
+            final List<Element> staticParamElements = 
getDirectChildren(navElement, STATIC_PARAMETER_ELEMENT);
+            staticParameters = new HashMap<String, String>();
+            for (Element staticParamElement : staticParamElements) {
+                String name = staticParamElement.getAttribute("name");
+                String value = staticParamElement.getAttribute("value");
+                if (name != null && value != null) {
+                    staticParameters.put(name, value);
+                }
+            }
+            LOG.debug("Added " + this);
+        }
+
+        private Nav(Navigation navigation, Element navElement) {
+            this(null, navigation, navElement);
+        }
+
+        public Nav getParentNav() {
+            return parentNav;
+        }
+
+        public Navigation getNavigation() {
+            return navigation;
+        }
+
+        public List<Nav> getChildNavs() {
+            return childNavs;
+        }
+
+        public boolean isRealNavigator() {
+            return realNavigator;
+        }
+
+        public void setRealNavigator(boolean realNavigator) {
+            this.realNavigator = realNavigator;
+        }
+
+        public List<Option> getOptions() {
+            return options;
+        }
+
+        public void setOptions(List<Option> options) {
+            this.options = options;
+        }
+
+        public Map<String, String> getStaticParameters() {
+            return staticParameters;
+        }
+
+        public void setStaticParameters(Map<String, String> staticParameters) {
+            this.staticParameters = staticParameters;
+        }
+
+        public void setExcludeQuery(boolean excludeQuery) {
+            this.excludeQuery = excludeQuery;
+        }
+
+        public boolean isExcludeQuery() {
+            return excludeQuery;
+        }
+
+        public String getId() {
+            return id;
+        }
+
+        public void setId(String id) {
+            this.id = id;
+        }
+
+        public String getTab() {
+            return tab;
+        }
+
+        public void setTab(String tab) {
+            this.tab = tab;
+        }
+
+        public boolean isOut() {
+            return out;
+        }
+
+        public void setOut(boolean out) {
+            this.out = out;
+        }
+
+        public String getCommandName() {
+            return commandName;
+        }
+
+        public void setCommandName(String commandName) {
+            this.commandName = commandName;
+        }
+
+        public String getField() {
+            return field;
+        }
+
+        public void setField(String field) {
+            this.field = field;
+        }
+
+
+        public String toString() {
+            return "Nav{" +
+                    "id='" + id + '\'' +
+                    ", commandName='" + commandName + '\'' +
+                    ", field='" + field + '\'' +
+                    ", options=" + options +
+                    ", staticParameters=" + staticParameters +
+                    '}';
+        }
+    }
+
+    public static class Option {
+        private String value;
+        private String displayName;
+        private String valueRef;
+        private boolean realNavigator;
+        private boolean defaultSelect;
+
+        public Option() {
+        }
+
+        private Option(Element optionElement) {
+            AbstractDocumentFactory.fillBeanProperty(this, null, "value", 
ParseType.String, optionElement, null);
+            AbstractDocumentFactory.fillBeanProperty(this, null, 
"displayName", ParseType.String, optionElement, null);
+            AbstractDocumentFactory.fillBeanProperty(this, null, "valueRef", 
ParseType.String, optionElement, null);
+            AbstractDocumentFactory.fillBeanProperty(this, null, 
"realNavigator", ParseType.Boolean, optionElement, "false");
+            AbstractDocumentFactory.fillBeanProperty(this, null, 
"defaultSelect", ParseType.Boolean, optionElement, "false");
+        }
+
+        public boolean isDefaultSelect() {
+            return defaultSelect;
+        }
+
+        public void setDefaultSelect(boolean defaultSelect) {
+            this.defaultSelect = defaultSelect;
+        }
+
+        public boolean isRealNavigator() {
+            return realNavigator;
+        }
+
+        public void setRealNavigator(boolean realNavigator) {
+            this.realNavigator = realNavigator;
+        }
+
+        public String getValue() {
+            return value;
+        }
+
+        public void setValue(String value) {
+            this.value = value;
+        }
+
+        public String getDisplayName() {
+            return displayName;
+        }
+
+        public void setDisplayName(String displayName) {
+            this.displayName = displayName;
+        }
+
+        public String getValueRef() {
+            return valueRef;
+        }
+
+        public void setValueRef(String valueRef) {
+            this.valueRef = valueRef;
+        }
+
+        public String toString() {
+            return "Option{" +
+                    "value='" + value + '\'' +
+                    ", displayName='" + displayName + '\'' +
+                    ", valueRef='" + valueRef + '\'' +
+                    '}';
+        }
+    }
+
+//    <navigation tab="nc" out="true" command-name="newsSearch">
+//        <nav id="people" field="newsCase">
+//            <static-parameter name="type" value="person"/>
+//        </nav>
+//        <nav id="cases" field="newsCase">
+//            <static-parameter name="type" value="sak"/>
+//        </nav>
+//    </navigation>
+//    <navigation command-name="newsSearch">
+//        <nav id="year">
+//            <nav id="yearmonth">
+//                <nav id="yearmonthday"/>
+//            </nav>
+//        </nav>
+//    </navigation>
+//    <navigation command-name="newsSearch">
+//        <nav id="publisher"/>
+//    </navigation>
+//    <navigation>
+//        <nav id="clusterId"/>
+//    </navigation>
+//    <navigation>
+//        <nav id="sort">
+//            <option value="ascending" display-name="elst først"/>
+//            <option value="descending" display-name="nyest først"/>
+//            <option value="relevance" display-name="relevance"/>
+//        </nav>
+//    </navigation>
+//    <navigation command-name="newsSearch">
+//        <nav field="offset">
+//            <option display-name="neste" value-ref="offset"/>
+//        </nav>
+//    </navigation>
+//    <navigation command-name="newNewsSearchNavigator">
+//        <nav id="medium" command-name="newNewsSearchNavigator"/>
+//        <nav id="sources" command-name="newsSearchNavigator"/>
+//        <nav id="countries" command-name="newsSearchNavigator"/>
+//    </navigation>
+
+}

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

Reply via email to