Author: ssmiweve
Date: 2008-02-13 22:48:01 +0100 (Wed, 13 Feb 2008)
New Revision: 6114

Modified:
   branches/2.16/generic.sesam/war/src/main/conf/views.xml
   
branches/2.16/view-config-spi/src/main/java/no/sesat/search/view/SearchTabFactory.java
   
branches/2.16/view-config-spi/src/main/java/no/sesat/search/view/config/SearchTab.java
Log:
SEARCH-3654 - Generalized enrichment handling


Modified: branches/2.16/generic.sesam/war/src/main/conf/views.xml
===================================================================
--- branches/2.16/generic.sesam/war/src/main/conf/views.xml     2008-02-13 
17:37:18 UTC (rev 6113)
+++ branches/2.16/generic.sesam/war/src/main/conf/views.xml     2008-02-13 
21:48:01 UTC (rev 6114)
@@ -14,7 +14,7 @@
     <!-- "absolute-ordering" means that the navigator sources should be sorted 
according to the 
 prority attribute of the navigation hints -->
 
-    <tab id="default" enrichment-limit="0" enrichment-on-top="0" 
absolute-ordering="true">
+    <tab id="default" absolute-ordering="true">
         <layout>
             <include key="head-element" template="head/head"/>
             <include key="header"/>            

Modified: 
branches/2.16/view-config-spi/src/main/java/no/sesat/search/view/SearchTabFactory.java
===================================================================
--- 
branches/2.16/view-config-spi/src/main/java/no/sesat/search/view/SearchTabFactory.java
      2008-02-13 17:37:18 UTC (rev 6113)
+++ 
branches/2.16/view-config-spi/src/main/java/no/sesat/search/view/SearchTabFactory.java
      2008-02-13 21:48:01 UTC (rev 6114)
@@ -36,7 +36,6 @@
 import no.schibstedsok.commons.ioc.ContextWrapper;
 import no.sesat.search.site.config.AbstractConfigFactory;
 import no.sesat.search.view.navigation.NavigationConfig;
-import no.sesat.search.site.config.ResourceContext;
 import no.sesat.search.site.config.DocumentLoader;
 import no.sesat.search.site.config.ResourceContext;
 import no.sesat.search.site.Site;
@@ -325,7 +324,28 @@
                 final String allJavascript = 
parseString(tabE.getAttribute("javascript"), null);
                 final String[] javascript = allJavascript != null ? 
allJavascript.split(",") : new String[]{};
 
+                // enrichment placement hints
+                final NodeList placementsNodeList = 
tabE.getElementsByTagName("enrichment-placement");
+                final Collection<SearchTab.EnrichmentPlacementHint> placements 
= new ArrayList<SearchTab.EnrichmentPlacementHint>();
+                for(int j = 0 ; j < placementsNodeList.getLength(); ++j){
+                    final Element e = (Element) placementsNodeList.item(j);
+                    final String placementId = e.getAttribute("id");
+                    final int threshold = 
parseInt(e.getAttribute("threshold"), 0);
+                    final int max = parseInt(e.getAttribute("max"), 0);
+                    final Map<String,String> properties = new 
HashMap<String,String>();
+                    final NodeList nodeList = e.getChildNodes();
+                    for (int l = 0; l < nodeList.getLength(); l++) {
+                        final Node propNode = nodeList.item(l);
 
+                        if (propNode instanceof Element){
+                            final Element propE = (Element)propNode;
+                            properties.put(propE.getNodeName(), 
propE.getFirstChild().getNodeValue());
+                        }
+                    }
+                    
+                    placements.add(new 
SearchTab.EnrichmentPlacementHint(placementId, threshold, max, properties));
+                }
+
                 // enrichment hints
                 final NodeList enrichmentNodeList = 
tabE.getElementsByTagName("enrichment");
                 final Collection<SearchTab.EnrichmentHint> enrichments = new 
ArrayList<SearchTab.EnrichmentHint>();
@@ -407,15 +427,7 @@
                         tabE.getAttribute("rss-result-name"),
                         parseBoolean(tabE.getAttribute("rss-hidden"), false),
                         navConf,
-                        parseInt(tabE.getAttribute("enrichment-limit"), 
inherit != null
-                            ? inherit.getEnrichmentLimit()
-                            : -1),
-                        parseInt(tabE.getAttribute("enrichment-on-top"), 
inherit != null
-                            ? inherit.getEnrichmentOnTop()
-                            : -1),
-                        parseInt(tabE.getAttribute("enrichment-on-top-score"), 
inherit != null
-                            ? inherit.getEnrichmentOnTopScore()
-                            : -1),
+                        placements,
                         enrichments,
                         adCommand,
                         parseInt(tabE.getAttribute("ad-limit"), inherit != 
null ? inherit.getAdLimit() : -1),

Modified: 
branches/2.16/view-config-spi/src/main/java/no/sesat/search/view/config/SearchTab.java
===================================================================
--- 
branches/2.16/view-config-spi/src/main/java/no/sesat/search/view/config/SearchTab.java
      2008-02-13 17:37:18 UTC (rev 6113)
+++ 
branches/2.16/view-config-spi/src/main/java/no/sesat/search/view/config/SearchTab.java
      2008-02-13 21:48:01 UTC (rev 6114)
@@ -51,8 +51,6 @@
     // Attributes ----------------------------------------------------
 
     private final String id;
-    private final int enrichmentLimit;
-    private final int enrichmentOnTop;
     private final String adCommand;
     private final int adLimit;
     private final int adOnTop;
@@ -64,9 +62,9 @@
     private final boolean absoluteOrdering;
     private final boolean displayCss;
     private final boolean executeOnBlank;
-    private final Collection<EnrichmentHint> enrichments = new 
ArrayList<EnrichmentHint> ();
+    private final Collection<EnrichmentPlacementHint> placements = new 
ArrayList<EnrichmentPlacementHint>();
+    private final Collection<EnrichmentHint> enrichments = new 
ArrayList<EnrichmentHint>();
     private final String mode;
-    private final int enrichmentOnTopScore;
     private final List<String> css = new ArrayList<String>();
     private final List<String> javascript = new ArrayList<String>();
     private final Layout defaultLayout;
@@ -90,6 +88,7 @@
      * @param enrichmentLimit
      * @param enrichmentOnTop
      * @param enrichmentOnTopScore
+     * @param placements 
      * @param enrichments
      * @param adCommand
      * @param adLimit
@@ -112,9 +111,7 @@
                 final String rssResultName,
                 final boolean rssHidden,
                 final NavigationConfig navConf,
-                final int enrichmentLimit,
-                final int enrichmentOnTop,
-                final int enrichmentOnTopScore,
+                final Collection<EnrichmentPlacementHint> placements,
                 final Collection<EnrichmentHint> enrichments,
                 final String adCommand,
                 final int adLimit,
@@ -138,11 +135,7 @@
                 ? parentKey
                 : inherit != null ? inherit.parentKey : null;
         this.navigationConfig = navConf;
-        this.enrichmentLimit = enrichmentLimit >=0 || inherit == null ? 
enrichmentLimit : inherit.enrichmentLimit;
-        this.enrichmentOnTop = enrichmentOnTop >=0 || inherit == null ? 
enrichmentOnTop : inherit.enrichmentOnTop;
-        this.enrichmentOnTopScore = enrichmentOnTopScore >=0 || inherit == null
-                ? enrichmentOnTopScore
-                : inherit.enrichmentOnTopScore;
+        this.placements.addAll(placements);
         this.enrichments.addAll(enrichments);
         this.adCommand = adCommand != null && adCommand.trim().length() >0
                 ? adCommand
@@ -154,6 +147,7 @@
             // we cannot inherit navigators because there require a live 
reference to the applicable SearchTabFactory
             // but we do inherit enrichments and css
             this.enrichments.addAll(inherit.enrichments);
+            this.placements.addAll(inherit.placements);
             this.css.addAll(inherit.css);
             this.layouts.putAll(inherit.layouts);
         }
@@ -181,22 +175,6 @@
     }
 
     /**
-     * Getter for property enrichmentLimit.
-     * @return Value of property enrichmentLimit.
-     */
-    public int getEnrichmentLimit() {
-        return this.enrichmentLimit;
-    }
-
-    /**
-     * Getter for property enrichmentOnTop.
-     * @return Value of property enrichmentOnTop.
-     */
-    public int getEnrichmentOnTop() {
-        return this.enrichmentOnTop;
-    }
-
-    /**
      * Getter for property adCommand.
      * @return Value of property adCommand.
      */
@@ -326,6 +304,16 @@
         return displayCss;
     }
 
+    public EnrichmentPlacementHint getEnrichmentPlacement(final String id){
+
+        for(EnrichmentPlacementHint p : placements){
+            if(p.getId().equals(id)){
+                return p;
+            }
+        }
+        return null;
+    }
+    
     /**
      * Getter for property enrichments.
      * @return Value of property enrichments.
@@ -363,14 +351,6 @@
     }
 
     /**
-     * Getter for property enrichmentScoreOnTop.
-     * @return Value of property enrichmentScoreOnTop.
-     */
-    public int getEnrichmentOnTopScore() {
-        return this.enrichmentOnTopScore;
-    }
-
-    /**
      *
      * @return
      */
@@ -522,6 +502,39 @@
         }
 
     }
+    
+    /** Immutable POJO holdng Enrichment Placement properties for a given 
placement on a given tab. **/
+    public static final class EnrichmentPlacementHint implements Serializable {
+        private final String id;
+        private final int threshold;
+        private final int max;
+        private final Map<String,String> properties = new 
HashMap<String,String>();
+        
+        public EnrichmentPlacementHint(
+                final String id,
+                final int threshold,
+                final int max,
+                final Map<String,String> properties){
+            
+            this.id = id;
+            this.threshold = threshold;
+            this.max = max;
+            this.properties.putAll(properties);
+        }
+        
+        public String getId(){
+            return id;
+        }
+        public int getThreshold(){
+            return threshold;
+        }
+        public int getMax(){
+            return max;
+        }
+        public String getProperty(final String key){
+            return properties.get(key);
+        }
+    }
 
     /** POJO holding defaultLayout information for the given tab.
      * readLayout(Element) is the only way to mutate the bean and can only be 
called once.

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

Reply via email to