Author: ssmiweve
Date: 2008-01-30 12:27:42 +0100 (Wed, 30 Jan 2008)
New Revision: 6066

Modified:
   
branches/2.16/data-model-api/src/main/java/no/sesat/search/datamodel/generic/StringDataObject.java
   
branches/2.16/data-model-api/src/main/java/no/sesat/search/datamodel/request/ParametersDataObject.java
   
branches/2.16/generic.sesam/view-control/src/main/java/no/sesat/search/view/navigation/AbstractUrlGenerator.java
   
branches/2.16/generic.sesam/view-control/src/main/java/no/sesat/search/view/navigation/BasicUrlGenerator.java
   
branches/2.16/generic.sesam/view-control/src/main/java/no/sesat/search/view/navigation/NewsCaseUrlGenerator.java
   
branches/2.16/view-control-spi/src/main/java/no/sesat/search/view/navigation/NavigationManager.java
   
branches/2.16/view-control-spi/src/main/java/no/sesat/search/view/navigation/OptionNavigationController.java
Log:
SEARCH-4121 - Bug i netts?\195?\184k ved bruk av " "
 the main fix is in NavigationManager.
 all the superfluous formatting during the feature freeze will no doubt bite my 
arse.


Modified: 
branches/2.16/data-model-api/src/main/java/no/sesat/search/datamodel/generic/StringDataObject.java
===================================================================
--- 
branches/2.16/data-model-api/src/main/java/no/sesat/search/datamodel/generic/StringDataObject.java
  2008-01-30 11:03:23 UTC (rev 6065)
+++ 
branches/2.16/data-model-api/src/main/java/no/sesat/search/datamodel/generic/StringDataObject.java
  2008-01-30 11:27:42 UTC (rev 6066)
@@ -13,8 +13,7 @@
  *
  *   You should have received a copy of the GNU Affero General Public License
  *   along with SESAT.  If not, see <http://www.gnu.org/licenses/>.
- */
-/*
+ *
  * StringDataObject.java
  *
  * Created on 23 January 2007, 12:43
@@ -24,8 +23,8 @@
 package no.sesat.search.datamodel.generic;
 
 import java.io.Serializable;
-import no.sesat.search.datamodel.generic.DataObject;
-import no.sesat.search.datamodel.*;
+import static no.sesat.search.datamodel.access.ControlLevel.VIEW_CONSTRUCTION;
+import no.sesat.search.datamodel.access.AccessDisallow;
 
 /**
  *
@@ -38,6 +37,7 @@
      * 
      * @return 
      */
+    @AccessDisallow({VIEW_CONSTRUCTION})
     String getString();
     /**
      * 

Modified: 
branches/2.16/data-model-api/src/main/java/no/sesat/search/datamodel/request/ParametersDataObject.java
===================================================================
--- 
branches/2.16/data-model-api/src/main/java/no/sesat/search/datamodel/request/ParametersDataObject.java
      2008-01-30 11:03:23 UTC (rev 6065)
+++ 
branches/2.16/data-model-api/src/main/java/no/sesat/search/datamodel/request/ParametersDataObject.java
      2008-01-30 11:27:42 UTC (rev 6066)
@@ -23,13 +23,10 @@
 package no.sesat.search.datamodel.request;
 
 import java.util.Map;
-import no.sesat.search.datamodel.generic.DataObject;
 import no.sesat.search.datamodel.generic.MapDataObject;
 import no.sesat.search.datamodel.access.AccessAllow;
-import no.sesat.search.datamodel.access.AccessDisallow;
 import no.sesat.search.datamodel.generic.DataNode;
 import no.sesat.search.datamodel.generic.StringDataObject;
-import static no.sesat.search.datamodel.access.ControlLevel.*;
 
 /** The ParameterDataObject class is a container for all request based 
information.
  *  This mainly includes parameters, but also headers and attributes.

Modified: 
branches/2.16/generic.sesam/view-control/src/main/java/no/sesat/search/view/navigation/AbstractUrlGenerator.java
===================================================================
--- 
branches/2.16/generic.sesam/view-control/src/main/java/no/sesat/search/view/navigation/AbstractUrlGenerator.java
    2008-01-30 11:03:23 UTC (rev 6065)
+++ 
branches/2.16/generic.sesam/view-control/src/main/java/no/sesat/search/view/navigation/AbstractUrlGenerator.java
    2008-01-30 11:27:42 UTC (rev 6066)
@@ -31,6 +31,7 @@
  * The term url component is used to denote a part of a URL, be it a part of 
the path or a parameter.
  *
  * @author maek
+ * @version $Id$
  */
 public abstract class AbstractUrlGenerator implements UrlGenerator {
 
@@ -82,6 +83,7 @@
      * @param nav the navigator.
      * @param extraParameters any extra parameters that should go into the URL.
      *
+     * @param newValue 
      * @return the set of parameter names.
      */
     protected final Set<String> getUrlComponentNames(
@@ -109,7 +111,8 @@
      * @param nav the navigator
      * @param componentName the name of the url component.
      *
-     * @return the value.
+     * @param extraParameters 
+     * @return the value. UTF-8 URL ENCODED.
      */
     protected String getUrlComponentValue(
             final NavigationConfig.Nav nav,
@@ -131,7 +134,8 @@
         return dataModel;
     }
 
-    private String getFirstNotNull(String ... strings) {
+    private String getFirstNotNull(final String ... strings) {
+        
         for (final String string : strings) {
             if (string != null) {
                 return string;

Modified: 
branches/2.16/generic.sesam/view-control/src/main/java/no/sesat/search/view/navigation/BasicUrlGenerator.java
===================================================================
--- 
branches/2.16/generic.sesam/view-control/src/main/java/no/sesat/search/view/navigation/BasicUrlGenerator.java
       2008-01-30 11:03:23 UTC (rev 6065)
+++ 
branches/2.16/generic.sesam/view-control/src/main/java/no/sesat/search/view/navigation/BasicUrlGenerator.java
       2008-01-30 11:27:42 UTC (rev 6066)
@@ -34,6 +34,7 @@
  * components (e.g. /search/param1Value/?param2=param2value).
  *
  * @author maek
+ * @version $Id$
  * @since 2.16
  */
 public class BasicUrlGenerator extends AbstractUrlGenerator {
@@ -66,30 +67,37 @@
     }
 
     /**
-     * Returns the navigation URL for navigating nav to the given value. The 
navigation state is used to retrieve the
+     * Returns the navigation URL for navigating nav to the given 
encodedValue. The navigation state is used to retrieve the
      * state of all the other navigators on the page.
      *
-     * @param value the value.
+     * @param unencodedValue the unencoded value.
      * @param nav the navigator to navigate.
      *
      * @return the URL for the state.
      */
-    public final synchronized String getURL(final String value, final 
NavigationConfig.Nav nav) {
-        return doGetURL(value, nav, Collections.<String, String>emptyMap());
+    public final synchronized String getURL(
+            final String unencodedValue, 
+            final NavigationConfig.Nav nav) {
+        
+        return doGetURL(unencodedValue, nav, Collections.<String, 
String>emptyMap());
     }
 
     /**
-     * Returns the navigation URL for navigating nav to the given value. The 
navigation state is used to retrieve the
+     * Returns the navigation URL for navigating nav to the given 
encodedValue. The navigation state is used to retrieve the
      * state of all the other navigators on the page.
      *
-     * @param val the value.
+     * @param unencodedValue the unencoded value.
      * @param nav the navigator to navigate.
-     * @param extraComponents any extra components that should go into the URL.
+     * @param extraComponents any extra components that should go into the 
URL. these should be all unencoded.
      *
      * @return the URL for the state.
      */
-    public String getURL(final String val, final NavigationConfig.Nav nav, 
final Map<String, String> extraComponents) {
-        return doGetURL(val, nav ,extraComponents);
+    public String getURL(
+            final String unencodedValue, 
+            final NavigationConfig.Nav nav, 
+            final Map<String, String> extraComponents) {
+        
+        return doGetURL(unencodedValue, nav, extraComponents);
     }
 
     /**
@@ -103,7 +111,8 @@
      * @return List of path components.
      */
     protected List<String> getPathComponents(final NavigationConfig.Nav nav) {
-        return Collections.emptyList();
+        
+        return Collections.<String>emptyList();
     }
 
     /**
@@ -129,40 +138,52 @@
     }
 
     /**
-     * Appends the component as a path component. This implementetion adds the 
value plus a slash. Value may be null or
+     * Appends the component as a path component. This implementetion adds the 
encodedValue plus a slash. Value may be null or
      * empty.
      *
      * @param component the component.
      * @param value the value of the component.
      */
     protected void appendPathComponent(final String component, final String 
value) {
-        if (null != value)
+        if (null != value) {
             urlBuilder.append(value).append("/");
+        }
     }
 
     /**
-     * Appends the component and its value as a parameter component. This 
implementetion adds
-     * <tt>component=value&</tt> if the value isn't empty.
+     * Appends the component and its encodedValue as a parameter component. 
This implementetion adds
+     * <tt>component=encodedValue&</tt> if the encodedValue isn't empty.
      *
      * @param component the component.
-     * @param value the value of the component.
+     * @param encodedValue the encodedValue of the component.
      */
-    protected void appendParameterComponent(final String component, final 
String value) {
-        if (null != value && value.length() > 0) {
+    protected void appendParameterComponent(final String component, final 
String encodedValue) {
+        
+        if (null != encodedValue && encodedValue.length() > 0) {
             urlBuilder.append(component);
             urlBuilder.append("=");
-            urlBuilder.append(value);
+            urlBuilder.append(encodedValue);
             urlBuilder.append("&amp;");
         }
     }
 
+    /**
+     * 
+     * @param parameter the parameter's name/key.
+     * @param unencodedValue
+     * @param nav
+     * @param extraParameters
+     * @return the value to use for the parameter. UTF-8 URL ENCODED.
+     */
     protected String getParameterValue(
             final String parameter,
-            final String value,
+            final String unencodedValue,
             final NavigationConfig.Nav nav,
             final Map<String, String> extraParameters) {
 
-        return parameter.equals(nav.getField()) ? enc(value) : 
getUrlComponentValue(nav, parameter, extraParameters);
+        return parameter.equals(nav.getField()) 
+                ? enc(unencodedValue) 
+                : getUrlComponentValue(nav, parameter, extraParameters);
     }
 
     /**
@@ -175,28 +196,29 @@
     }
 
     private synchronized String doGetURL(
-            final String value,
+            final String unencodedValue,
             final NavigationConfig.Nav nav,
             final Map<String, String> extraParameters) {
 
         try {
 
             final List<String> pathComponents = getPathComponents(nav);
-            final Set<String> parameterComponents = 
getParameterComponents(nav, extraParameters.keySet(), value);
+            final Set<String> parameterComponents = 
getParameterComponents(nav, extraParameters.keySet(), unencodedValue);
 
             for (final String component : pathComponents) {
-                appendPathComponent(component, getParameterValue(component, 
value, nav, extraParameters));
+                appendPathComponent(component, getParameterValue(component, 
unencodedValue, nav, extraParameters));
             }
 
             urlBuilder.append('?');
 
             for (final String component : parameterComponents) {
-                appendParameterComponent(component, 
getParameterValue(component, value, nav, extraParameters));
+                appendParameterComponent(component, 
getParameterValue(component, unencodedValue, nav, extraParameters));
             }
 
             if (!pathComponents.contains(nav.getField()) && 
!parameterComponents.contains(nav.getField())) {
-                if (null != nav.getField())
-                    appendParameterComponent(nav.getField(), 
getParameterValue(nav.getField(), value, nav, extraParameters));
+                if (null != nav.getField()) {
+                    appendParameterComponent(nav.getField(), 
getParameterValue(nav.getField(), unencodedValue, nav, extraParameters));
+                }
             }
 
             return SEPARATOR_END.matcher(urlBuilder).replaceFirst("");

Modified: 
branches/2.16/generic.sesam/view-control/src/main/java/no/sesat/search/view/navigation/NewsCaseUrlGenerator.java
===================================================================
--- 
branches/2.16/generic.sesam/view-control/src/main/java/no/sesat/search/view/navigation/NewsCaseUrlGenerator.java
    2008-01-30 11:03:23 UTC (rev 6065)
+++ 
branches/2.16/generic.sesam/view-control/src/main/java/no/sesat/search/view/navigation/NewsCaseUrlGenerator.java
    2008-01-30 11:27:42 UTC (rev 6066)
@@ -25,6 +25,7 @@
  * A UrlGenerator for the news aggregator. Generates URL on the format 
/search/nyheter/person/Al+Gore.
  *
  * @author maek
+ * @version $Id$
  */
 public final class NewsCaseUrlGenerator extends BasicUrlGenerator {
 
@@ -35,11 +36,13 @@
     }
 
     @Override
-    protected void appendParameterComponent(final String parameter, final 
String value) {
+    protected void appendParameterComponent(final String parameter, final 
String encodedValue) {
+        
         if (! ("c".equals(parameter) || "q".equals(parameter))) {
-            super.appendParameterComponent(parameter, value);
+            super.appendParameterComponent(parameter, encodedValue);
         }
     }
+    
     @Override
     protected List<String> getPathComponents(NavigationConfig.Nav nav) {
         return PATH_COMPONENTS;

Modified: 
branches/2.16/view-control-spi/src/main/java/no/sesat/search/view/navigation/NavigationManager.java
===================================================================
--- 
branches/2.16/view-control-spi/src/main/java/no/sesat/search/view/navigation/NavigationManager.java
 2008-01-30 11:03:23 UTC (rev 6065)
+++ 
branches/2.16/view-control-spi/src/main/java/no/sesat/search/view/navigation/NavigationManager.java
 2008-01-30 11:27:42 UTC (rev 6066)
@@ -30,6 +30,7 @@
  * 
  * @author maek
  * @author Geir H. Pettersen(T-Rank)
+ * @version $Id$
  */
 public final class NavigationManager {
 
@@ -105,12 +106,14 @@
              * @param nav the navigator. 
              * @param parameterName the parameter.
              *
-             * @return the value of the parameter.
+             * @return the value of the parameter. UTF-8 URL ENCODED.
              */
             public String getParameterValue(final NavigationConfig.Nav nav, 
final String parameterName) {
                 final String value = parameters.get(parameterName);
 
-                // TODO: SEARCH-4105 - put this logic somewhere else to make 
things faster.
+                // TODO: SEARCH-4105 - put this logic somewhere else to make 
things faster. look at OptionNavigationController:152
+                //  or the c parameter should be put into 
nav.getStaticParameters() 
+                // (where it would be used in peference to here in 
AbstractUrlGenerator.getUrlComponentValue(..))
                 
                 // Overriding the tab with the one defined in the config.
                 if ("c".equals(parameterName) && null != nav.getTab()) {
@@ -118,7 +121,7 @@
                 }
 
                 if (null == value && null != 
dataModel.getParameters().getValue(parameterName)) {
-                    return 
dataModel.getParameters().getValue(parameterName).getString();
+                    return 
dataModel.getParameters().getValue(parameterName).getUtf8UrlEncoded();
                 }
 
                 return value;

Modified: 
branches/2.16/view-control-spi/src/main/java/no/sesat/search/view/navigation/OptionNavigationController.java
===================================================================
--- 
branches/2.16/view-control-spi/src/main/java/no/sesat/search/view/navigation/OptionNavigationController.java
        2008-01-30 11:03:23 UTC (rev 6065)
+++ 
branches/2.16/view-control-spi/src/main/java/no/sesat/search/view/navigation/OptionNavigationController.java
        2008-01-30 11:27:42 UTC (rev 6066)
@@ -18,6 +18,13 @@
  */
 package no.sesat.search.view.navigation;
 
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 import no.sesat.search.datamodel.DataModel;
 import no.sesat.search.datamodel.generic.StringDataObject;
 import no.sesat.search.datamodel.generic.StringDataObjectSupport;
@@ -26,12 +33,12 @@
 import no.sesat.search.result.ResultItem;
 import no.sesat.search.result.ResultList;
 
-import java.util.*;
 
 /**
  *
  * @author Geir H. Pettersen(T-Rank)
  * @author <a href="mailto:[EMAIL PROTECTED]">Magnus Eklund</a>
+ * @version $Id$
  */
 public class OptionNavigationController
         implements NavigationController, 
NavigationControllerFactory<OptionsNavigationConfig> {
@@ -111,10 +118,13 @@
           }
     }
 
-    private void addAll(final Collection<OptionsNavigationConfig.Option> 
optionsToAdd, final DataModel dataModel, final Context context) {
+    private void addAll(
+            final Collection<OptionsNavigationConfig.Option> optionsToAdd, 
+            final DataModel dataModel, 
+            final Context context) {
 
         final NavigationItem parentResult = 
dataModel.getNavigation().getNavigation(config.getParent().getId());
-            final StringDataObject optionSelectedValue = 
dataModel.getParameters().getValue(config.getParent().getField());
+        final StringDataObject optionSelectedValue = 
dataModel.getParameters().getValue(config.getParent().getField());
 
 
         boolean selectionDone = false;
@@ -125,6 +135,7 @@
                     ? dataModel.getSearch(option.getCommandName()).getResults()
                     : null;
 
+            // value is an unencoded value.
             String value = option.getValue();
             if (option.getValueRef() != null && searchResult != null) {
                 final String tmp = searchResult.getField(option.getValueRef());
@@ -134,32 +145,34 @@
             }
             if (value != null) {
 
+                final Map<String,String> urlParameters;
 
-
-                final Map<String, String> urlParameters;
-
                 if (option.getTab() != null) {
-                    urlParameters = new HashMap<String, String>(1);
+                    urlParameters = new HashMap<String,String>(1);
                     urlParameters.put("c", option.getTab());
                 } else {
-                    urlParameters = Collections.emptyMap();
+                    urlParameters = Collections.<String,String>emptyMap();
                 }
 
                 final NavigationItem navigator = new BasicNavigationItem(
                         option.getDisplayName(),
                         context.getUrlGenerator().getURL(value, 
config.getParent(), urlParameters),
                         -1);
+                
                 parentResult.addResult(navigator);
+                
                 if (!selectionDone
                         && (optionSelectedValue == null || 
"".equals(optionSelectedValue.getString()))
                         && isOptionDefaultSelected(searchResult, option)) {
 
                     navigator.setSelected(true);
                     selectionDone = true;
+                    
                 } else if (optionSelectedValue != null && 
optionSelectedValue.getString().equals(value)) {
                     navigator.setSelected(true);
                     selectionDone = true;
                 }
+                
                 if (option.isUseHitCount() && option.getCommandName() != null) 
{
                     
navigator.setHitCount(dataModel.getSearch(option.getCommandName()).getResults().getHitCount());
                 }

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

Reply via email to