Ticket #131: Navigation Indexpage nicht (mehr) Subsite aware
Erste Version. Scheint aber schon gut zu funktionieren. Intensiver Test steht noch aus. Hinzugefügt: * SubsiteItemURLFinder ** Neuen Subsite-aware URLFinder geschreiben und eingebunden * Geändert: ItemURLFinder ** Teil der find Methode in getCategories ausgelagert git-svn-id: https://svn.libreccm.org/ccm/trunk@2222 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
ecf1f407a6
commit
6b8b421da0
|
|
@ -32,10 +32,13 @@ import com.arsdigita.kernel.URLFinderNotFoundException;
|
|||
import com.arsdigita.kernel.URLService;
|
||||
import com.arsdigita.persistence.DataAssociation;
|
||||
import com.arsdigita.persistence.DataAssociationCursor;
|
||||
import com.arsdigita.persistence.DataObject;
|
||||
import com.arsdigita.persistence.OID;
|
||||
import com.arsdigita.web.ParameterMap;
|
||||
import com.arsdigita.web.URL;
|
||||
import com.arsdigita.web.Web;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
|
@ -44,8 +47,8 @@ import org.apache.log4j.Logger;
|
|||
* necessary for ccm dispatcher to find a concrete content item for an url
|
||||
* provided by a client request.
|
||||
*
|
||||
* Specifically it is a helper class for {@link com.arsdigita.web.OIDRedirectServlet}
|
||||
* to map an OID to an URL.
|
||||
* Specifically it is a helper class for
|
||||
* {@link com.arsdigita.web.OIDRedirectServlet} to map an OID to an URL.
|
||||
*
|
||||
*/
|
||||
public class ItemURLFinder implements URLFinder {
|
||||
|
|
@ -67,13 +70,12 @@ public class ItemURLFinder implements URLFinder {
|
|||
|
||||
ContentItem item;
|
||||
try {
|
||||
item = (ContentItem)DomainObjectFactory
|
||||
item = (ContentItem) DomainObjectFactory
|
||||
.newInstance(oid);
|
||||
} catch (DataObjectNotFoundException ex) {
|
||||
throw new NoValidURLException(
|
||||
"cannot instantiate item " + oid +
|
||||
" message: " + ex.getMessage()
|
||||
);
|
||||
"cannot instantiate item " + oid
|
||||
+ " message: " + ex.getMessage());
|
||||
}
|
||||
|
||||
if (ContentItem.LIVE.equals(context)) {
|
||||
|
|
@ -87,8 +89,7 @@ public class ItemURLFinder implements URLFinder {
|
|||
} else {
|
||||
s_log.debug("Item was not live");
|
||||
throw new NoValidURLException(
|
||||
"item " + oid + " is not live"
|
||||
);
|
||||
"item " + oid + " is not live");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -109,13 +110,12 @@ public class ItemURLFinder implements URLFinder {
|
|||
|
||||
ContentItem item;
|
||||
try {
|
||||
item = (ContentItem)DomainObjectFactory
|
||||
item = (ContentItem) DomainObjectFactory
|
||||
.newInstance(oid);
|
||||
} catch (DataObjectNotFoundException ex) {
|
||||
throw new NoValidURLException(
|
||||
"cannot instantiate item " + oid +
|
||||
" message: " + ex.getMessage()
|
||||
);
|
||||
"cannot instantiate item " + oid
|
||||
+ " message: " + ex.getMessage());
|
||||
}
|
||||
|
||||
if (s_log.isDebugEnabled()) {
|
||||
|
|
@ -170,37 +170,37 @@ public class ItemURLFinder implements URLFinder {
|
|||
bundle = (ContentBundle) ((ContentBundle) parent).getDraftVersion();
|
||||
}
|
||||
if (bundle != null) {
|
||||
DataAssociationCursor categories =
|
||||
((DataAssociation) DomainServiceInterfaceExposer.
|
||||
get(bundle, Category.CATEGORIES)).cursor();
|
||||
// XXX pb (2010.12.15) ToDO
|
||||
// solution is currently not subsite aware!
|
||||
// provides an index url even if the category tree is not part
|
||||
// of subsite (which results in a resource not found exception)
|
||||
categories.addEqualsFilter("link." + Category.IS_INDEX, Boolean.TRUE);
|
||||
if (categories.next()) {
|
||||
List<DataObject> categories = getCategories(bundle);
|
||||
|
||||
/* For all associated categories, try to get a url. Stop at
|
||||
* first successful try.*/
|
||||
for(DataObject dobj:categories) {
|
||||
String url;
|
||||
Category indexCat = (Category) DomainObjectFactory.
|
||||
newInstance(categories.getDataObject());
|
||||
categories.close();
|
||||
newInstance(dobj);
|
||||
try {
|
||||
if (s_log.isDebugEnabled()) {
|
||||
s_log.debug(item + " is a Category index item. " +
|
||||
"Resolving URL for " + indexCat);
|
||||
s_log.debug(item + " is a Category index item. "
|
||||
+ "Resolving URL for " + indexCat);
|
||||
}
|
||||
return URLService.locate(indexCat.getOID(), context);
|
||||
url = URLService.locate(indexCat.getOID(), context);
|
||||
} catch (URLFinderNotFoundException ufnfe) {
|
||||
if (s_log.isDebugEnabled()) {
|
||||
s_log.debug("Could not find URLFinder for " + indexCat +
|
||||
", continuing with URL resolution for " + item,
|
||||
s_log.debug("Could not find URLFinder for " + indexCat
|
||||
+ ", continuing with URL resolution for " + item,
|
||||
ufnfe);
|
||||
}
|
||||
continue;
|
||||
} catch (NoValidURLException nvue) {
|
||||
if (s_log.isDebugEnabled()) {
|
||||
s_log.debug("Could not find valid URL for " + indexCat +
|
||||
", continuing with URL resolution for " + item,
|
||||
s_log.debug("Could not find valid URL for " + indexCat
|
||||
+ ", continuing with URL resolution for " + item,
|
||||
nvue);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
return url;
|
||||
|
||||
}
|
||||
}
|
||||
} else { // DRAFT context
|
||||
|
|
@ -233,8 +233,7 @@ public class ItemURLFinder implements URLFinder {
|
|||
if (sep == -1) {
|
||||
destination = URL.there(url, null);
|
||||
} else {
|
||||
final ParameterMap params = ParameterMap.fromString
|
||||
(url.substring(sep + 1));
|
||||
final ParameterMap params = ParameterMap.fromString(url.substring(sep + 1));
|
||||
|
||||
destination = URL.there(url.substring(0, sep), params);
|
||||
}
|
||||
|
|
@ -246,4 +245,25 @@ public class ItemURLFinder implements URLFinder {
|
|||
return destination.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all categories for a content bundle, where the content bundle is an
|
||||
* index item.
|
||||
*
|
||||
* @param bundle The content bundle to test for
|
||||
* @return a list of associated categories
|
||||
*/
|
||||
protected List<DataObject> getCategories(ContentBundle bundle) {
|
||||
List<DataObject> catList = new ArrayList<DataObject>();
|
||||
DataAssociationCursor categories =
|
||||
((DataAssociation) DomainServiceInterfaceExposer.
|
||||
get(bundle, Category.CATEGORIES)).cursor();
|
||||
categories.addEqualsFilter("link." + Category.IS_INDEX, Boolean.TRUE);
|
||||
|
||||
while(categories.next()) {
|
||||
catList.add(categories.getDataObject());
|
||||
}
|
||||
categories.close();
|
||||
|
||||
return catList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,24 +18,22 @@
|
|||
|
||||
package com.arsdigita.subsite;
|
||||
|
||||
import com.arsdigita.cms.ContentBundle;
|
||||
import com.arsdigita.cms.ContentPage;
|
||||
import com.arsdigita.db.DbHelper;
|
||||
|
||||
import com.arsdigita.domain.xml.TraversalHandler;
|
||||
import com.arsdigita.domain.DomainObject;
|
||||
|
||||
import com.arsdigita.domain.xml.TraversalHandler;
|
||||
import com.arsdigita.kernel.ACSObjectInstantiator;
|
||||
|
||||
import com.arsdigita.persistence.pdl.NameFilter;
|
||||
import com.arsdigita.persistence.pdl.ManifestSource;
|
||||
import com.arsdigita.kernel.URLService;
|
||||
import com.arsdigita.persistence.DataObject;
|
||||
|
||||
import com.arsdigita.runtime.RuntimeConfig;
|
||||
import com.arsdigita.runtime.PDLInitializer;
|
||||
import com.arsdigita.persistence.pdl.ManifestSource;
|
||||
import com.arsdigita.persistence.pdl.NameFilter;
|
||||
import com.arsdigita.runtime.CompoundInitializer;
|
||||
import com.arsdigita.runtime.DomainInitEvent;
|
||||
|
||||
import com.arsdigita.runtime.PDLInitializer;
|
||||
import com.arsdigita.runtime.RuntimeConfig;
|
||||
import com.arsdigita.subsite.dispatcher.SubsiteItemURLFinder;
|
||||
import com.arsdigita.templating.PatternStylesheetResolver;
|
||||
|
||||
import com.arsdigita.xml.XML;
|
||||
|
||||
/**
|
||||
|
|
@ -70,6 +68,11 @@ public class Initializer extends CompoundInitializer {
|
|||
XML.parse(Subsite.getConfig().getTraversalAdapters(),
|
||||
new TraversalHandler());
|
||||
|
||||
URLService.registerFinder(ContentPage.BASE_DATA_OBJECT_TYPE,
|
||||
new SubsiteItemURLFinder());
|
||||
URLService.registerFinder(ContentBundle.BASE_DATA_OBJECT_TYPE,
|
||||
new SubsiteItemURLFinder());
|
||||
|
||||
PatternStylesheetResolver.registerPatternGenerator(
|
||||
"subsite", new SubsitePatternGenerator()
|
||||
);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package com.arsdigita.subsite.dispatcher;
|
||||
|
||||
import com.arsdigita.categorization.Category;
|
||||
import com.arsdigita.cms.ContentBundle;
|
||||
import com.arsdigita.cms.dispatcher.ItemURLFinder;
|
||||
import com.arsdigita.domain.DomainObjectFactory;
|
||||
import com.arsdigita.persistence.DataObject;
|
||||
import com.arsdigita.subsite.Site;
|
||||
import com.arsdigita.subsite.Subsite;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sören Bernstein (quasimodo) <sbernstein@zes.uni-bremen.de>
|
||||
*/
|
||||
public class SubsiteItemURLFinder extends ItemURLFinder {
|
||||
|
||||
/**
|
||||
* Get all categories for a content bundle, where the content bundle is an
|
||||
* index item in the current subsite.
|
||||
*
|
||||
* @param bundle
|
||||
* @return a list of categories from this subsite
|
||||
*/
|
||||
@Override
|
||||
protected List<DataObject> getCategories(ContentBundle bundle) {
|
||||
|
||||
List<DataObject> categories = super.getCategories(bundle);
|
||||
List<DataObject> subsiteCategories = new ArrayList<DataObject>();
|
||||
|
||||
// If there is a current subsite, filter all categories which not belong
|
||||
// to this subsites root category
|
||||
if (Subsite.getContext().hasSite()) {
|
||||
Site site = Subsite.getContext().getSite();
|
||||
Category subsiteRootCat = site.getRootCategory();
|
||||
|
||||
if (subsiteRootCat != null) {
|
||||
for (DataObject dobj : categories) {
|
||||
Category cat = (Category) DomainObjectFactory.newInstance(dobj);
|
||||
if (subsiteRootCat.isMemberOfSubtree(cat)) {
|
||||
subsiteCategories.add(dobj);
|
||||
}
|
||||
}
|
||||
return subsiteCategories;
|
||||
}
|
||||
}
|
||||
return categories;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue