From: <ssk...@vh...> - 2005-11-21 12:27:09
|
Author: sskracic Date: 2005-11-21 13:25:18 +0100 (Mon, 21 Nov 2005) New Revision: 1006 Modified: trunk/ccm-ldn-navigation/application.xml trunk/ccm-ldn-navigation/src/com/arsdigita/london/navigation/cms/CMSNavigationModel.java Log: Two major changes: 1. if an item has no categories in the current root category, null is returned, instead of grabbing some random category in other (possibly non-navigational) domains. 2. the algorithm to find the "current root category" has been changed. If a template context is not set, the old behavior is retained, ie. you get the root category of the content section the item belongs to. However, if there is a non-null template context (set by the Subsite filter, for example), then root category is taken from the domain which has a mapping to the default navigation app instance (most likely it's /navigation/) with a context being equal the template context. With those two changes, 2 things are fixed: a. items that are not categorised against navigation tree show default navigation menu on the left side, and no BCT at all b. items displayed in subsite context has correct (ie. subsite aware) navigation menu on the left side and BCT. Modified: trunk/ccm-ldn-navigation/application.xml =================================================================== --- trunk/ccm-ldn-navigation/application.xml 2005-11-18 22:03:26 UTC (rev 1005) +++ trunk/ccm-ldn-navigation/application.xml 2005-11-21 12:25:18 UTC (rev 1006) @@ -3,7 +3,7 @@ name="ccm-ldn-navigation" prettyName="Navigation" version="6.3.0" - release="4" + release="5" webapp="ROOT"> <ccm:dependencies> <ccm:requires name="ccm-core" version="6.2.0" relation="ge"/> Modified: trunk/ccm-ldn-navigation/src/com/arsdigita/london/navigation/cms/CMSNavigationModel.java =================================================================== --- trunk/ccm-ldn-navigation/src/com/arsdigita/london/navigation/cms/CMSNavigationModel.java 2005-11-18 22:03:26 UTC (rev 1005) +++ trunk/ccm-ldn-navigation/src/com/arsdigita/london/navigation/cms/CMSNavigationModel.java 2005-11-21 12:25:18 UTC (rev 1006) @@ -23,14 +23,22 @@ import com.arsdigita.cms.CMS; import com.arsdigita.cms.ContentBundle; import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.TemplateContext; +import com.arsdigita.domain.DomainCollection; import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.domain.DomainServiceInterfaceExposer; import com.arsdigita.kernel.ACSObject; import com.arsdigita.london.navigation.GenericNavigationModel; +import com.arsdigita.london.navigation.Navigation; +import com.arsdigita.london.terms.Domain; import com.arsdigita.persistence.DataAssociation; import com.arsdigita.persistence.DataAssociationCursor; +import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.Filter; +import com.arsdigita.persistence.SessionManager; +import com.arsdigita.util.Assert; +import com.arsdigita.web.Application; import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; @@ -41,7 +49,11 @@ * return the current Content Item if any. The getCategory() method * will return the content item's default category, if any. * The getRootCategory() method will return the content section's - * root category, if any. + * root category, if any. If a non-null TemplateContext is set + * (by Subsite filter for example), the root category will not + * be fetched from content section, instead it will be taken from + * the domain which has a mapping with said context to the + * default navigation app (/navigation/). */ public class CMSNavigationModel extends GenericNavigationModel { @@ -55,6 +67,32 @@ return super.loadObject(); } + protected Category loadRootCategory() { + TemplateContext dispatcherContext = Navigation.getContext().getTemplateContext(); + if (dispatcherContext == null) { + return super.loadRootCategory(); + } + DataCollection objs = SessionManager.getSession() + .retrieve(Domain.BASE_DATA_OBJECT_TYPE); + Navigation navApp = (Navigation) Application.retrieveApplicationForPath( + Navigation.getConfig().getDefaultCategoryRootPath()); + Assert.exists(navApp, Navigation.class); + objs.addEqualsFilter("model.ownerUseContext.categoryOwner.id", navApp.getID()); + objs.addEqualsFilter("model.ownerUseContext.useContext", + dispatcherContext.getContext()); + Category root = null; + DomainCollection domains = new DomainCollection(objs); + if (domains.next()) { + root = ((Domain) domains.getDomainObject()).getModel(); + domains.close(); + } else { + // can't find domain, 404 + return null; + } + Assert.exists(root, Category.class); + return root; + } + protected Category[] loadCategoryPath() { Category cat = null; @@ -84,19 +122,8 @@ categories.close(); cat = (Category) DomainObjectFactory.newInstance( obj ); } else { - s_log.debug("we don't have any categories"); + s_log.debug("we don't have any categories in the subtree with that root cat"); categories.close(); - - assoc = (DataAssociation)DomainServiceInterfaceExposer - .get(bundle, "categories"); - categories = assoc.cursor(); - categories.addOrder("link.isDefault desc"); - if( categories.next() ) { - s_log.debug( "Got category from another tree" ); - DataObject obj = categories.getDataObject(); - categories.close(); - cat = (Category) DomainObjectFactory.newInstance( obj ); - } } } |