Author: ssmiweve
Date: 2008-01-22 20:38:45 +0100 (Tue, 22 Jan 2008)
New Revision: 6007
Added:
trunk/view-control-spi/src/main/java/no/sesat/search/view/navigation/NavigationHelper.java
Modified:
trunk/core-api/src/main/java/no/sesat/search/view/velocity/VelocityEngineFactory.java
Log:
undo of r5974. class was incorrectly marked deprecated.
Modified:
trunk/core-api/src/main/java/no/sesat/search/view/velocity/VelocityEngineFactory.java
===================================================================
---
trunk/core-api/src/main/java/no/sesat/search/view/velocity/VelocityEngineFactory.java
2008-01-22 14:44:52 UTC (rev 6006)
+++
trunk/core-api/src/main/java/no/sesat/search/view/velocity/VelocityEngineFactory.java
2008-01-22 19:38:45 UTC (rev 6007)
@@ -47,6 +47,7 @@
import no.sesat.search.site.config.Spi;
import no.sesat.search.site.config.UrlResourceLoader;
+import no.sesat.search.view.navigation.NavigationHelper;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.velocity.Template;
@@ -146,6 +147,8 @@
context.put("number", new NumberTool());
// date tool
context.put("date", new DateTool());
+ // navigation helper
+ context.put("navigationHelper", new NavigationHelper());
// boomerang
context.put("boomerang", new Boomerang());
Copied:
trunk/view-control-spi/src/main/java/no/sesat/search/view/navigation/NavigationHelper.java
(from rev 5973,
trunk/view-control-spi/src/main/java/no/sesat/search/view/navigation/NavigationHelper.java)
===================================================================
---
trunk/view-control-spi/src/main/java/no/sesat/search/view/navigation/NavigationHelper.java
(rev 0)
+++
trunk/view-control-spi/src/main/java/no/sesat/search/view/navigation/NavigationHelper.java
2008-01-22 19:38:45 UTC (rev 6007)
@@ -0,0 +1,101 @@
+/* Copyright (2007) Schibsted Søk AS
+ * This file is part of SESAT.
+ *
+ * SESAT is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published
by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SESAT is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with SESAT. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * NavigationHelper.java
+ *
+ * Created on 12/06/2007, 17:13:43
+ *
+ */
+
+package no.sesat.search.view.navigation;
+
+import no.sesat.search.datamodel.DataModel;
+import no.sesat.search.result.BasicNavigationItem;
+import no.sesat.search.result.NavigationItem;
+
+/**
+ * All public methods require take a datamodel argument. This datamodel must
in VIEW_CONSTRUCTION state.
+ * It essentially means that this helper class can only be used from
jsp/velocity code.
+ *
+ * @author Geir H. Pettersen(T-Rank)
+ * @author mick
+ * @version $Id$
+ *
+ */
+public final class NavigationHelper {
+
+ // Constants -----------------------------------------------------
+ public static String removeQuery(final String url) {
+ return url.replaceAll("(&)?q=[^&]*", "");
+ }
+
+ /**
+ * @todo move into domain? (NavigationItem & BasicNavigationItem)
+ */
+ public static NavigationConfig.Nav getFirstNotSelected(DataModel dm,
NavigationConfig.Nav nav) {
+
+ if (dm.getParameters().getValue(nav.getId()) != null
+ && !nav.getChildNavs().isEmpty()
+ && !nav.getChildNavs().get(0).isVirtual()) {
+
+ return getFirstNotSelected(dm, nav.getChildNavs().get(0));
+
+ } else {
+
+ final int navResultSize = null != nav.getId()
+ && null != dm.getNavigation().getNavigation(nav.getId())
+ && null !=
dm.getNavigation().getNavigation(nav.getId()).getResults()
+ ?
dm.getNavigation().getNavigation(nav.getId()).getResults().size()
+ : 0;
+
+// TODO: Specification is a mess, so this becomes ugly. See history in
prio-198 & SEARCH-3320.
+// TODO: Haven't found a general way to solve this. Special case for Oslo.
+// TODO: New JIRA created to resolve this: SEARCH-3451
+// return 1 == navResultSize && !nav.getChildNavs().isEmpty()
+// ? getFirstNotSelected(dm, nav.getChildNavs().get(0))
+// : nav;
+
+
+ return 1 == navResultSize && !nav.getChildNavs().isEmpty() &&
(nav.isAutoNavigation() || isOslo(dm, nav))
+ ? getFirstNotSelected(dm, nav.getChildNavs().get(0))
+ : nav;
+ }
+ }
+
+ public static NavigationItem getSingleNavigationItem(DataModel dm, final
String navId, final String value) {
+ final NavigationItem item = dm.getNavigation().getNavigation(navId);
+
+ if (item != null && item.getChildByTitle(value) != null) {
+
+ return item.getChildByTitle(value);
+ } else {
+ final BasicNavigationItem navigationItem = new
BasicNavigationItem();
+
+ navigationItem.setHitCount(0);
+ navigationItem.setTitle(value);
+
+ return navigationItem;
+ }
+ }
+
+ public String getResetUrl(final DataModel dm, final String navId) {
+ return dm.getNavigation().getNavigation("reset_" + navId).getUrl();
+ }
+
+ private static boolean isOslo(DataModel dm, NavigationConfig.Nav nav) {
+ return
dm.getNavigation().getNavigation(nav.getId()).getResults().get(0).getTitle().equalsIgnoreCase("oslo");
+ }
+}
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits