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.kernel.URLService;
|
||||||
import com.arsdigita.persistence.DataAssociation;
|
import com.arsdigita.persistence.DataAssociation;
|
||||||
import com.arsdigita.persistence.DataAssociationCursor;
|
import com.arsdigita.persistence.DataAssociationCursor;
|
||||||
|
import com.arsdigita.persistence.DataObject;
|
||||||
import com.arsdigita.persistence.OID;
|
import com.arsdigita.persistence.OID;
|
||||||
import com.arsdigita.web.ParameterMap;
|
import com.arsdigita.web.ParameterMap;
|
||||||
import com.arsdigita.web.URL;
|
import com.arsdigita.web.URL;
|
||||||
import com.arsdigita.web.Web;
|
import com.arsdigita.web.Web;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
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
|
* necessary for ccm dispatcher to find a concrete content item for an url
|
||||||
* provided by a client request.
|
* provided by a client request.
|
||||||
*
|
*
|
||||||
* Specifically it is a helper class for {@link com.arsdigita.web.OIDRedirectServlet}
|
* Specifically it is a helper class for
|
||||||
* to map an OID to an URL.
|
* {@link com.arsdigita.web.OIDRedirectServlet} to map an OID to an URL.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ItemURLFinder implements URLFinder {
|
public class ItemURLFinder implements URLFinder {
|
||||||
|
|
@ -71,9 +74,8 @@ public class ItemURLFinder implements URLFinder {
|
||||||
.newInstance(oid);
|
.newInstance(oid);
|
||||||
} catch (DataObjectNotFoundException ex) {
|
} catch (DataObjectNotFoundException ex) {
|
||||||
throw new NoValidURLException(
|
throw new NoValidURLException(
|
||||||
"cannot instantiate item " + oid +
|
"cannot instantiate item " + oid
|
||||||
" message: " + ex.getMessage()
|
+ " message: " + ex.getMessage());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ContentItem.LIVE.equals(context)) {
|
if (ContentItem.LIVE.equals(context)) {
|
||||||
|
|
@ -87,8 +89,7 @@ public class ItemURLFinder implements URLFinder {
|
||||||
} else {
|
} else {
|
||||||
s_log.debug("Item was not live");
|
s_log.debug("Item was not live");
|
||||||
throw new NoValidURLException(
|
throw new NoValidURLException(
|
||||||
"item " + oid + " is not live"
|
"item " + oid + " is not live");
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,9 +114,8 @@ public class ItemURLFinder implements URLFinder {
|
||||||
.newInstance(oid);
|
.newInstance(oid);
|
||||||
} catch (DataObjectNotFoundException ex) {
|
} catch (DataObjectNotFoundException ex) {
|
||||||
throw new NoValidURLException(
|
throw new NoValidURLException(
|
||||||
"cannot instantiate item " + oid +
|
"cannot instantiate item " + oid
|
||||||
" message: " + ex.getMessage()
|
+ " message: " + ex.getMessage());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s_log.isDebugEnabled()) {
|
if (s_log.isDebugEnabled()) {
|
||||||
|
|
@ -170,37 +170,37 @@ public class ItemURLFinder implements URLFinder {
|
||||||
bundle = (ContentBundle) ((ContentBundle) parent).getDraftVersion();
|
bundle = (ContentBundle) ((ContentBundle) parent).getDraftVersion();
|
||||||
}
|
}
|
||||||
if (bundle != null) {
|
if (bundle != null) {
|
||||||
DataAssociationCursor categories =
|
List<DataObject> categories = getCategories(bundle);
|
||||||
((DataAssociation) DomainServiceInterfaceExposer.
|
|
||||||
get(bundle, Category.CATEGORIES)).cursor();
|
/* For all associated categories, try to get a url. Stop at
|
||||||
// XXX pb (2010.12.15) ToDO
|
* first successful try.*/
|
||||||
// solution is currently not subsite aware!
|
for(DataObject dobj:categories) {
|
||||||
// provides an index url even if the category tree is not part
|
String url;
|
||||||
// of subsite (which results in a resource not found exception)
|
|
||||||
categories.addEqualsFilter("link." + Category.IS_INDEX, Boolean.TRUE);
|
|
||||||
if (categories.next()) {
|
|
||||||
Category indexCat = (Category) DomainObjectFactory.
|
Category indexCat = (Category) DomainObjectFactory.
|
||||||
newInstance(categories.getDataObject());
|
newInstance(dobj);
|
||||||
categories.close();
|
|
||||||
try {
|
try {
|
||||||
if (s_log.isDebugEnabled()) {
|
if (s_log.isDebugEnabled()) {
|
||||||
s_log.debug(item + " is a Category index item. " +
|
s_log.debug(item + " is a Category index item. "
|
||||||
"Resolving URL for " + indexCat);
|
+ "Resolving URL for " + indexCat);
|
||||||
}
|
}
|
||||||
return URLService.locate(indexCat.getOID(), context);
|
url = URLService.locate(indexCat.getOID(), context);
|
||||||
} catch (URLFinderNotFoundException ufnfe) {
|
} catch (URLFinderNotFoundException ufnfe) {
|
||||||
if (s_log.isDebugEnabled()) {
|
if (s_log.isDebugEnabled()) {
|
||||||
s_log.debug("Could not find URLFinder for " + indexCat +
|
s_log.debug("Could not find URLFinder for " + indexCat
|
||||||
", continuing with URL resolution for " + item,
|
+ ", continuing with URL resolution for " + item,
|
||||||
ufnfe);
|
ufnfe);
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
} catch (NoValidURLException nvue) {
|
} catch (NoValidURLException nvue) {
|
||||||
if (s_log.isDebugEnabled()) {
|
if (s_log.isDebugEnabled()) {
|
||||||
s_log.debug("Could not find valid URL for " + indexCat +
|
s_log.debug("Could not find valid URL for " + indexCat
|
||||||
", continuing with URL resolution for " + item,
|
+ ", continuing with URL resolution for " + item,
|
||||||
nvue);
|
nvue);
|
||||||
}
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
return url;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else { // DRAFT context
|
} else { // DRAFT context
|
||||||
|
|
@ -233,8 +233,7 @@ public class ItemURLFinder implements URLFinder {
|
||||||
if (sep == -1) {
|
if (sep == -1) {
|
||||||
destination = URL.there(url, null);
|
destination = URL.there(url, null);
|
||||||
} else {
|
} else {
|
||||||
final ParameterMap params = ParameterMap.fromString
|
final ParameterMap params = ParameterMap.fromString(url.substring(sep + 1));
|
||||||
(url.substring(sep + 1));
|
|
||||||
|
|
||||||
destination = URL.there(url.substring(0, sep), params);
|
destination = URL.there(url.substring(0, sep), params);
|
||||||
}
|
}
|
||||||
|
|
@ -246,4 +245,25 @@ public class ItemURLFinder implements URLFinder {
|
||||||
return destination.toString();
|
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;
|
package com.arsdigita.subsite;
|
||||||
|
|
||||||
|
import com.arsdigita.cms.ContentBundle;
|
||||||
|
import com.arsdigita.cms.ContentPage;
|
||||||
import com.arsdigita.db.DbHelper;
|
import com.arsdigita.db.DbHelper;
|
||||||
|
|
||||||
import com.arsdigita.domain.xml.TraversalHandler;
|
|
||||||
import com.arsdigita.domain.DomainObject;
|
import com.arsdigita.domain.DomainObject;
|
||||||
|
import com.arsdigita.domain.xml.TraversalHandler;
|
||||||
import com.arsdigita.kernel.ACSObjectInstantiator;
|
import com.arsdigita.kernel.ACSObjectInstantiator;
|
||||||
|
import com.arsdigita.kernel.URLService;
|
||||||
import com.arsdigita.persistence.pdl.NameFilter;
|
|
||||||
import com.arsdigita.persistence.pdl.ManifestSource;
|
|
||||||
import com.arsdigita.persistence.DataObject;
|
import com.arsdigita.persistence.DataObject;
|
||||||
|
import com.arsdigita.persistence.pdl.ManifestSource;
|
||||||
import com.arsdigita.runtime.RuntimeConfig;
|
import com.arsdigita.persistence.pdl.NameFilter;
|
||||||
import com.arsdigita.runtime.PDLInitializer;
|
|
||||||
import com.arsdigita.runtime.CompoundInitializer;
|
import com.arsdigita.runtime.CompoundInitializer;
|
||||||
import com.arsdigita.runtime.DomainInitEvent;
|
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.templating.PatternStylesheetResolver;
|
||||||
|
|
||||||
import com.arsdigita.xml.XML;
|
import com.arsdigita.xml.XML;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -70,6 +68,11 @@ public class Initializer extends CompoundInitializer {
|
||||||
XML.parse(Subsite.getConfig().getTraversalAdapters(),
|
XML.parse(Subsite.getConfig().getTraversalAdapters(),
|
||||||
new TraversalHandler());
|
new TraversalHandler());
|
||||||
|
|
||||||
|
URLService.registerFinder(ContentPage.BASE_DATA_OBJECT_TYPE,
|
||||||
|
new SubsiteItemURLFinder());
|
||||||
|
URLService.registerFinder(ContentBundle.BASE_DATA_OBJECT_TYPE,
|
||||||
|
new SubsiteItemURLFinder());
|
||||||
|
|
||||||
PatternStylesheetResolver.registerPatternGenerator(
|
PatternStylesheetResolver.registerPatternGenerator(
|
||||||
"subsite", new SubsitePatternGenerator()
|
"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