Author: sshafroi
Date: 2008-05-08 14:25:19 +0200 (Thu, 08 May 2008)
New Revision: 6591
Removed:
trunk/generic.sesam/result-handler-config/src/main/java/no/sesat/search/result/handler/AddCategoryNavigationResultHandlerConfig.java
trunk/generic.sesam/result-handler-control/src/main/java/no/sesat/search/result/handler/AddCategoryNavigationResultHandler.java
Modified:
trunk/generic.sesam/view-control/src/main/java/no/sesat/search/view/navigation/TreeNavigationController.java
trunk/generic.sesam/war/src/main/templates/VM_sesat_library.vm
trunk/result-spi/src/main/java/no/sesat/search/result/BasicNavigationItem.java
trunk/result-spi/src/main/java/no/sesat/search/result/NavigationItem.java
Log:
SKER4736 - Replace the AddCategoryNavigationResultHandler with the
TreeNavigator.
Deleted:
trunk/generic.sesam/result-handler-config/src/main/java/no/sesat/search/result/handler/AddCategoryNavigationResultHandlerConfig.java
===================================================================
---
trunk/generic.sesam/result-handler-config/src/main/java/no/sesat/search/result/handler/AddCategoryNavigationResultHandlerConfig.java
2008-05-08 10:11:02 UTC (rev 6590)
+++
trunk/generic.sesam/result-handler-config/src/main/java/no/sesat/search/result/handler/AddCategoryNavigationResultHandlerConfig.java
2008-05-08 12:25:19 UTC (rev 6591)
@@ -1,74 +0,0 @@
-/* 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/>.
- */
-package no.sesat.search.result.handler;
-
-import no.sesat.search.result.handler.AbstractResultHandlerConfig.Controller;
-import org.apache.log4j.Logger;
-import org.w3c.dom.Element;
-
-/**
- * @author Geir H. Pettersen (T-Rank)
- * @version $Id$
- */
[EMAIL PROTECTED]("AddCategoryNavigationResultHandler")
-public final class AddCategoryNavigationResultHandlerConfig extends
AbstractResultHandlerConfig {
-
- private static final Logger LOG =
Logger.getLogger(AddCategoryNavigationResultHandlerConfig.class);
- private String categoriesXml = "categories.xml";
- private String categoryFields;
-
- /**
- * @return
- */
- public String getCategoriesXml() {
- return categoriesXml;
- }
-
- /**
- * @param categoriesXml
- */
- public void setCategoriesXml(String categoriesXml) {
- this.categoriesXml = categoriesXml;
- }
-
- /**
- * @return
- */
- public String getCategoryFields() {
- return categoryFields;
- }
-
- /**
- * @param categoryFields
- */
- public void setCategoryFields(String categoryFields) {
- this.categoryFields = categoryFields;
- }
-
- @Override
- public AddCategoryNavigationResultHandlerConfig readResultHandler(Element
element) {
-
- super.readResultHandler(element);
- setCategoryFields(element.getAttribute("category-fields"));
- final String categoryXml = element.getAttribute("categories-xml");
- if (categoryXml != null && categoryXml.length() > 0) {
- setCategoriesXml(categoryXml);
- }
- return this;
- }
-
-}
Deleted:
trunk/generic.sesam/result-handler-control/src/main/java/no/sesat/search/result/handler/AddCategoryNavigationResultHandler.java
===================================================================
---
trunk/generic.sesam/result-handler-control/src/main/java/no/sesat/search/result/handler/AddCategoryNavigationResultHandler.java
2008-05-08 10:11:02 UTC (rev 6590)
+++
trunk/generic.sesam/result-handler-control/src/main/java/no/sesat/search/result/handler/AddCategoryNavigationResultHandler.java
2008-05-08 12:25:19 UTC (rev 6591)
@@ -1,202 +0,0 @@
-/* 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/>.
- */
-package no.sesat.search.result.handler;
-
-
-import no.sesat.search.datamodel.DataModel;
-import no.sesat.search.datamodel.generic.StringDataObject;
-import no.sesat.search.result.FastSearchResult;
-import no.sesat.search.result.Modifier;
-import no.sesat.search.site.config.DocumentLoader;
-import org.apache.log4j.Logger;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @author Geir H. Pettersen (T-Rank)
- * @version $Id$
- */
-public final class AddCategoryNavigationResultHandler implements ResultHandler
{
-
- private static final String CMD_ELEMENT_CATEGORY = "category";
- private static final String CMD_ATTR_DISPLAY_NAME = "display-name";
- private static final String CMD_ATTR_ID = "id";
-
- private static final Logger LOG =
Logger.getLogger(AddCategoryNavigationResultHandler.class);
- private static List<Category> categoryList;
-
- private final AddCategoryNavigationResultHandlerConfig config;
-
- /**
- * @param config
- */
- public AddCategoryNavigationResultHandler(final ResultHandlerConfig
config) {
- this.config = (AddCategoryNavigationResultHandlerConfig) config;
- }
-
-
- /**
- * @param cxt
- * @param datamodel
- */
- public void handleResult(Context cxt, DataModel datamodel) {
- try {
- if (cxt.getSearchResult() instanceof FastSearchResult) {
- if (categoryList == null) {
- // This could happen more than once, but synchronize
overhead would be on every call, so it ok.
- categoryList = parseCategories(cxt, datamodel);
- }
- addCategoryNavigators(datamodel, (FastSearchResult)
cxt.getSearchResult(), categoryList);
- } else {
- LOG.error("Can not use " +
AddCategoryNavigationResultHandler.class.getName() + " on a generic
searchResult. Must be a " + FastSearchResult.class.getName());
- }
- } catch (ParserConfigurationException e) {
- LOG.error("Could not parse categories.", e);
- }
- }
-
- private void addCategoryNavigators(DataModel datamodel, FastSearchResult
searchResult, List<Category> categoryList) {
- if (categoryList != null && categoryList.size() > 0) {
- final String[] categoryFields = getCategoryFieldArray();
- if (categoryFields.length > 0) {
- for (String categoryField : categoryFields) {
- Category selectedCategory = null;
- StringDataObject selectedFieldData =
datamodel.getParameters().getValue(categoryField);
- for (Category category : categoryList) {
- searchResult.addModifier(categoryField, new
Modifier(category.getDisplayName(), -1, null));
- if (selectedFieldData != null &&
selectedFieldData.getString().equals(category.getDisplayName())) {
- selectedCategory = category;
- }
- }
- if (selectedCategory != null &&
selectedCategory.getSubCategories() != null) {
- categoryList = selectedCategory.getSubCategories();
- } else {
- break;
- }
- }
- }
- }
- }
-
- private List<Category> parseCategories(Context cxt, DataModel datamodel)
throws ParserConfigurationException {
- Document doc = getDocument(cxt, datamodel);
- final Element root = doc.getDocumentElement();
- return parseCategories(root);
- }
-
- private Document getDocument(Context cxt, DataModel dataModel) throws
ParserConfigurationException {
- final DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
- factory.setValidating(false);
- final DocumentBuilder builder = factory.newDocumentBuilder();
- DocumentLoader documentLoader =
cxt.newDocumentLoader(dataModel.getSite(), config.getCategoriesXml(), builder);
- documentLoader.abut();
- return documentLoader.getDocument();
- }
-
- /**
- * @param categoriesElement
- * @return
- */
- public List<Category> parseCategories(Element categoriesElement) {
- List<Element> categoryElements = getDirectChildren(categoriesElement,
CMD_ELEMENT_CATEGORY);
- return parseCategories(categoryElements);
- }
-
- private List<Category> parseCategories(List<Element> categoryElements) {
- if (categoryElements != null && categoryElements.size() > 0) {
- final List<Category> categoryList = new ArrayList<Category>();
- for (Element categoryElement : categoryElements) {
- categoryList.add(parseCategory(categoryElement));
- }
- return categoryList;
- } else {
- return null;
- }
- }
-
- private Category parseCategory(Element categoryElement) {
- String id = categoryElement.getAttribute(CMD_ATTR_ID);
- String displayName =
categoryElement.getAttribute(CMD_ATTR_DISPLAY_NAME);
- List<Category> subCategories =
parseCategories(getDirectChildren(categoryElement, CMD_ELEMENT_CATEGORY));
- return new Category(id, displayName, subCategories);
- }
-
- private 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;
- }
-
- private String[] getCategoryFieldArray() {
- return config.getCategoryFields().split(",");
- }
-
- private static final class Category {
- private final String id;
- private final String displayName;
- private final List<Category> subCategories;
-
- public Category(String id, String displayName) {
- this(id, displayName, null);
- }
-
- public Category(String id, String displayName, List<Category>
subCategories) {
- this.id = id;
- this.displayName = displayName;
- this.subCategories = subCategories;
- }
-
- public String getId() {
- return id;
- }
-
- public String getDisplayName() {
- return displayName;
- }
-
- public List<Category> getSubCategories() {
- return subCategories;
- }
-
- @Override
- public String toString() {
- return "Category{" +
- "id='" + id + '\'' +
- ", displayName='" + displayName + '\'' +
- ", hasSubCategories=" + (subCategories != null &&
subCategories.size() > 0) +
- '}';
- }
- }
-
-
-}
Modified:
trunk/generic.sesam/view-control/src/main/java/no/sesat/search/view/navigation/TreeNavigationController.java
===================================================================
---
trunk/generic.sesam/view-control/src/main/java/no/sesat/search/view/navigation/TreeNavigationController.java
2008-05-08 10:11:02 UTC (rev 6590)
+++
trunk/generic.sesam/view-control/src/main/java/no/sesat/search/view/navigation/TreeNavigationController.java
2008-05-08 12:25:19 UTC (rev 6591)
@@ -64,12 +64,12 @@
i.setSelected(true);
item.addResult(i);
- getNavigationItemsHelper(context, i, nav.getChildNavs());
+ getNavigationItemsHelper(context, i, nav.getChildNavs(), 1);
return item;
}
- private void getNavigationItemsHelper(final Context context,
NavigationItem item, List<NavigationConfig.Nav> children) {
+ private void getNavigationItemsHelper(final Context context,
NavigationItem item, List<NavigationConfig.Nav> children, int depth) {
if (children.isEmpty()) {
return;
@@ -80,10 +80,10 @@
if(child instanceof TreeNavigationConfig) {
final String url =
context.getUrlGenerator().getURL(((TreeNavigationConfig)child).getValue(),
child);
final BasicNavigationItem i = new
BasicNavigationItem(((TreeNavigationConfig)child).getName(), url, -1);
-
+ i.setDepth(depth);
final StringDataObject selectedValue =
context.getDataModel().getParameters().getValue(child.getField());
- if (selectedValue != null &&
selectedValue.getString().equals(i.getTitle())) {
+ if (selectedValue != null &&
selectedValue.getString().equals(((TreeNavigationConfig)child).getValue())) {
i.setSelected(true);
}
@@ -93,7 +93,7 @@
if (i.isSelected()) {
StringDataObject selectedSubItem =
context.getDataModel().getParameters().getValue(child.getField());
if (selectedSubItem != null &&
((TreeNavigationConfig)child).getValue().equals(selectedSubItem.getString())) {
- getNavigationItemsHelper(context, i,
child.getChildNavs());
+ getNavigationItemsHelper(context, i,
child.getChildNavs(), depth +1);
}
}
}
Modified: trunk/generic.sesam/war/src/main/templates/VM_sesat_library.vm
===================================================================
--- trunk/generic.sesam/war/src/main/templates/VM_sesat_library.vm
2008-05-08 10:11:02 UTC (rev 6590)
+++ trunk/generic.sesam/war/src/main/templates/VM_sesat_library.vm
2008-05-08 12:25:19 UTC (rev 6591)
@@ -95,4 +95,47 @@
<a href="$option.url">#htmlescape($option.title)</a>
#end
#end
-#end
\ No newline at end of file
+#end
+
+#macro(treeNavigation $nav $title)
+ #set ($top = $datamodel.navigation.getNavigation($nav))
+ <div class="cellHead">$title</div>
+ #set($aImg = '<img src="/images/backArrow.gif" alt="" />')
+ #foreach($branch in $top.getChildrenRecursive())
+ #if(!$branch.isChildSelected() && $branch.isSelected() )
+ <div class="cellHoldActive">
+ <div class="cellLeft"><span
class="subText${branch.depth}">$branch.title</div>
+ </div>
+ #else
+ <div class="cellHold">
+ <div class="cellLeft"><span
class="subText${branch.depth}">#newsSimpleNavigationLink($branch '')</div>
+ </div>
+ #end
+ #set($top = $branch)
+ #end
+#end
+
+#macro(treeNavigationOnlySelectedBranch $nav $title)
+ #set ($top = $datamodel.navigation.getNavigation($nav))
+ <div class="cellHead">$title</div>
+ #set($aImg = '<img src="/images/backArrow.gif" alt="" />')
+ #foreach($branch in $top.getSelectedBranch())
+ #if($branch.isChildSelected())
+ <div class="cellHold">
+ <div class="cellLeft">$aImg #newsSimpleNavigationLink($branch
'')</div>
+ </div>
+ #else
+ <div class="cellHoldActive">
+ <div class="cellLeft">$branch.getTitle()</div>
+ </div>
+ #end
+ #set($top = $branch)
+ #end
+
+ #foreach($leaf in $top.results)
+ <div class="cellHold">
+ <div class="cellLeft">#newsSimpleNavigationLink($leaf '')</div>
+ </div>
+ <div class="liner"></div>
+ #end
+#end
Modified:
trunk/result-spi/src/main/java/no/sesat/search/result/BasicNavigationItem.java
===================================================================
---
trunk/result-spi/src/main/java/no/sesat/search/result/BasicNavigationItem.java
2008-05-08 10:11:02 UTC (rev 6590)
+++
trunk/result-spi/src/main/java/no/sesat/search/result/BasicNavigationItem.java
2008-05-08 12:25:19 UTC (rev 6591)
@@ -33,6 +33,7 @@
public class BasicNavigationItem extends BasicResultList<NavigationItem>
implements NavigationItem{
private boolean selected = false;
+ private int depth = 0;
public BasicNavigationItem(){}
@@ -95,6 +96,39 @@
return res;
}
+ /**
+ * Create a list off all children collected recursivly (Depth first).
+ *
+ * @return
+ */
+ public List<NavigationItem> getChildrenRecursive() {
+ Vector<NavigationItem> res = new Vector<NavigationItem>();
+ getChildrenRecursiveHelper(res, this);
+ return res;
+ }
+
+ private void getChildrenRecursiveHelper(List<NavigationItem> res,
NavigationItem nav) {
+ for(NavigationItem child : nav.getResults()) {
+ res.add(child);
+ getChildrenRecursiveHelper(res, child);
+ }
+ }
+
+ public int getDepth() {
+ return depth;
+ }
+
+ /**
+ * The depth of this element. (Used when elements are organized in tree
like struktures
+ *
+ * @param d Depth of element.
+ *
+ * @return this
+ */
+ public void setDepth(int d) {
+ depth = d;
+ }
+
private NavigationItem getChildSelectedImpl() {
// XXX Geir's original work had a dirty flag here to cache this result.
Modified:
trunk/result-spi/src/main/java/no/sesat/search/result/NavigationItem.java
===================================================================
--- trunk/result-spi/src/main/java/no/sesat/search/result/NavigationItem.java
2008-05-08 10:11:02 UTC (rev 6590)
+++ trunk/result-spi/src/main/java/no/sesat/search/result/NavigationItem.java
2008-05-08 12:25:19 UTC (rev 6591)
@@ -35,4 +35,12 @@
boolean isChildSelected();
NavigationItem getSelectedChild();
NavigationItem getChildByTitle(String title);
+
+ /**
+ * The depth of this element. (Used when elements are organized in tree
like struktures)
+ * (This might not be the global depth of the navigation item)
+ *
+ * @return Depth of this element.
+ */
+ int getDepth();
}
_______________________________________________
Kernel-commits mailing list
[email protected]
http://sesat.no/mailman/listinfo/kernel-commits