|
From: <mb...@re...> - 2004-11-17 11:04:31
|
Author: mbooth
Date: 2004-11-17 11:56:55 +0100 (Wed, 17 Nov 2004)
New Revision: 106
Added:
ccm-ldn-navigation/trunk/src/com/arsdigita/london/navigation/DomainNavigationModel.java
Modified:
ccm-ldn-navigation/trunk/application.xml
ccm-ldn-navigation/trunk/src/com/arsdigita/london/navigation/ui/category/AbstractList.java
ccm-ldn-navigation/trunk/src/com/arsdigita/london/navigation/ui/category/AbstractTree.java
Log:
Add DomainNavigationModel, which allows you to specific a particular domain.
Fix a bug in AbstractTree which would generate invalid URLs for a widget included in a navigation app which pulls out categories not in the current app.
Modified: ccm-ldn-navigation/trunk/application.xml
===================================================================
--- ccm-ldn-navigation/trunk/application.xml 2004-11-17 10:51:56 UTC (rev 105)
+++ ccm-ldn-navigation/trunk/application.xml 2004-11-17 10:56:55 UTC (rev 106)
@@ -11,6 +11,7 @@
<ccm:requires name="ccm-core" version="6.1.0"/>
<ccm:requires name="ccm-cms" version="6.1.0"/>
<ccm:requires name="ccm-ldn-util" version="1.4.1"/>
+ <ccm:requires name="ccm-ldn-terms" version="1.0.1"/>
</ccm:dependencies>
<ccm:contacts>
Added: ccm-ldn-navigation/trunk/src/com/arsdigita/london/navigation/DomainNavigationModel.java
===================================================================
--- ccm-ldn-navigation/trunk/src/com/arsdigita/london/navigation/DomainNavigationModel.java 2004-11-17 10:51:56 UTC (rev 105)
+++ ccm-ldn-navigation/trunk/src/com/arsdigita/london/navigation/DomainNavigationModel.java 2004-11-17 10:56:55 UTC (rev 106)
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+package com.arsdigita.london.navigation;
+
+import com.arsdigita.categorization.Category;
+import com.arsdigita.kernel.ACSObject;
+
+import com.arsdigita.london.terms.Domain;
+
+import org.apache.log4j.Logger;
+
+/**
+ * The Domain navigation model returns the
+ * root category of a specified Domain
+ */
+public class DomainNavigationModel extends AbstractNavigationModel {
+ private static final Logger s_log =
+ Logger.getLogger( DomainNavigationModel.class );
+
+ private String m_domainKey;
+
+ public DomainNavigationModel( String domainKey ) {
+ m_domainKey = domainKey;
+ }
+
+ private Category getDomainRoot() {
+ Domain domain = Domain.retrieve( m_domainKey );
+ Category root = domain.getModel();
+
+ if( s_log.isDebugEnabled() ) {
+ s_log.debug( "Got root category " + root.getOID().toString() +
+ " for domain " + m_domainKey );
+ }
+
+ return root;
+ }
+
+ protected ACSObject loadObject() {
+ return null;
+ }
+
+ protected Category loadCategory() {
+ return getDomainRoot();
+ }
+
+ protected Category[] loadCategoryPath() {
+ return new Category[]{ getDomainRoot() };
+ }
+
+ protected Category loadRootCategory() {
+ return getDomainRoot();
+ }
+}
Modified: ccm-ldn-navigation/trunk/src/com/arsdigita/london/navigation/ui/category/AbstractList.java
===================================================================
--- ccm-ldn-navigation/trunk/src/com/arsdigita/london/navigation/ui/category/AbstractList.java 2004-11-17 10:51:56 UTC (rev 105)
+++ ccm-ldn-navigation/trunk/src/com/arsdigita/london/navigation/ui/category/AbstractList.java 2004-11-17 10:56:55 UTC (rev 106)
@@ -31,12 +31,15 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.log4j.Logger;
+
/**
* Abstract class for displaying a list of categories
*/
public abstract class AbstractList extends CategoryComponent {
+ private static final Logger s_log = Logger.getLogger( AbstractList.class );
private String m_name;
@@ -49,6 +52,12 @@
public Element generateXML(HttpServletRequest request,
HttpServletResponse response) {
Category cat = getCategory(getModel());
+
+ if( s_log.isDebugEnabled() ) {
+ String catStr = (null == cat) ? "null" : cat.getOID().toString();
+ s_log.debug( "Got category: " + catStr );
+
+ }
if (cat == null) {
return null;
Modified: ccm-ldn-navigation/trunk/src/com/arsdigita/london/navigation/ui/category/AbstractTree.java
===================================================================
--- ccm-ldn-navigation/trunk/src/com/arsdigita/london/navigation/ui/category/AbstractTree.java 2004-11-17 10:51:56 UTC (rev 105)
+++ ccm-ldn-navigation/trunk/src/com/arsdigita/london/navigation/ui/category/AbstractTree.java 2004-11-17 10:56:55 UTC (rev 106)
@@ -24,12 +24,12 @@
import com.arsdigita.categorization.Category;
import com.arsdigita.categorization.CategoryCollection;
+import com.arsdigita.web.Application;
+import com.arsdigita.web.URL;
+import com.arsdigita.web.Web;
import com.arsdigita.xml.Element;
import com.arsdigita.xml.XML;
-import com.arsdigita.web.Web;
-import com.arsdigita.web.URL;
-
import java.util.Set;
import java.util.TreeSet;
import java.util.Map;
@@ -66,8 +66,28 @@
}
String url = null;
- if (Web.getContext().getApplication() instanceof Navigation) {
- url = "";
+ Application app = Web.getContext().getApplication();
+ if (app instanceof Navigation) {
+ // Check the current category is actually in the current
+ // application's category hierarchy
+
+ Category root = Category.getRootForObject( app );
+
+ CategoryCollection rootPath = root.getDefaultAscendants();
+ CategoryCollection path = cat.getDefaultAscendants();
+
+ boolean common = true;
+ while( common && rootPath.next() ) {
+ if( ! path.next() ||
+ ! rootPath.getID().equals( path.getID() ) )
+ {
+ common = false;
+ }
+ }
+ rootPath.close();
+ path.close();
+
+ if( common ) url = "";
}
return generateNodeXML(request,
|