Mulitlanguage Fähigkeit für Navigation

Ich konnte zwar nicht alle Stellen im laufenden System verifizieren, aber nach meinen Verständnis sollte die Unterstützung nun vollständig sein.

git-svn-id: https://svn.libreccm.org/ccm/trunk@271 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2009-10-01 09:06:10 +00:00
parent 8b99a67aa5
commit 2753d7f5d4
5 changed files with 280 additions and 217 deletions

View File

@ -24,9 +24,9 @@ import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ContentBundle;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.domain.DomainObjectXMLRenderer;
import com.arsdigita.kernel.ACSObject;
import com.arsdigita.london.navigation.ui.AbstractComponent;
import com.arsdigita.persistence.OID;
import com.arsdigita.xml.Element;
@ -106,115 +106,137 @@ public class ContentList extends AbstractComponent {
//if (isVisible(state)) {
String indexItemIdString = null;
String indexItemIdString = null;
// check if we are currently displaying an item
HashMap items = new HashMap();
HashMap sortKeys = new HashMap();
ContentItem currentItem = null;
try {
currentItem = CMS.getContext().getContentItem();
log.debug("ContentList: CMS.getContext().getContentItem() returned : "+currentItem);
} catch (IllegalStateException e) {
// we're dealing with a category
}
// check if we are currently displaying an item
HashMap items = new HashMap();
HashMap sortKeys = new HashMap();
ContentItem currentItem = null;
try {
currentItem = CMS.getContext().getContentItem();
log.debug("ContentList: CMS.getContext().getContentItem() returned : "+currentItem);
} catch (IllegalStateException e) {
// we're dealing with a category
}
if (currentItem != null) {
if (currentItem != null) {
// take the first category in the list, should do the trick????
Iterator categories = currentItem.getCategories(null);
if (categories.hasNext()) {
Category category = (Category) categories.next();
String currentItemClassName = currentItem.getClass().getName();
String currentItemIdString = currentItem.getID().toString();
log.debug("ContentList: looking at the first category of the item : "+category.getName());
// only navigation categories (not sure this was truely necessary in fact)
// if (getNavigationRootCategory().isMemberOfSubtree(category)) {
processCategory(category, currentItemClassName, currentItemIdString, items, sortKeys);
// }
// take the first category in the list, should do the trick????
Iterator categories = currentItem.getCategories(null);
if (categories.hasNext()) {
Category category = (Category) categories.next();
String currentItemClassName = currentItem.getClass().getName();
String currentItemIdString = currentItem.getID().toString();
log.debug("ContentList: looking at the first category of the item : "+category.getName());
// only navigation categories (not sure this was truely necessary in fact)
// if (getNavigationRootCategory().isMemberOfSubtree(category)) {
processCategory(category, currentItemClassName, currentItemIdString, items, sortKeys);
// }
// now that we look at only one category, also mark the indexItem as such
// but don't process it on top of what has already been done
ACSObject indexItem = category.getIndexObject();
if ((indexItem != null) && (indexItem instanceof ContentBundle)) {
ContentItem cIndexItem = ((ContentBundle) indexItem).getPrimaryInstance().getLiveVersion();
if (cIndexItem != null) {
indexItemIdString = cIndexItem.getID().toString();
}
// now that we look at only one category, also mark the indexItem as such
// but don't process it on top of what has already been done
ACSObject indexItem = category.getIndexObject();
if ((indexItem != null) && (indexItem instanceof ContentBundle)) {
/*Fix by Quasimodo*/
/* getPrimaryInstance doesn't negotiate the language of the content item */
/* ContentItem cIndexItem = ((ContentBundle) indexItem).getPrimaryInstance().getLiveVersion(); */
ContentItem cItem = ((ContentBundle) indexItem).negotiate(request.getLocales());
// If there is no matching language version for this content item
if(cItem == null) {
// get the primary instance instead (fallback)
cItem = ((ContentBundle) indexItem).getPrimaryInstance();
}
} else {
log.warn("ContentList: item has no category, contentList will be empty.");
ContentItem cIndexItem = cItem.getLiveVersion();
if (cIndexItem != null) {
indexItemIdString = cIndexItem.getID().toString();
}
}
} else {
// we're viewing a category. process it
//String categoryIdString = state.getRequest().getParameter(CATEGORYID_PARAM);
//Category category = new Category(new OID(Category.class.getName(), new BigDecimal(categoryIdString)));
Category category = getCategory();
log.debug("ContentList: getCategory returned : "+getCategory());
if (category != null) {
processCategory(category, null, null, items, sortKeys);
// process the index item, just in case it isn't in the lists
// above (ie inherited from parent category)
ACSObject indexItem = category.getIndexObject();
if ((indexItem != null) && (indexItem instanceof ContentBundle)) {
ContentItem cIndexItem = ((ContentBundle) indexItem).getPrimaryInstance().getLiveVersion();
//log.debug("indexItem : "+cIndexItem);
if (cIndexItem != null) {
processItem(cIndexItem, null, null, items);
indexItemIdString = cIndexItem.getID().toString();
}
//log.debug("indexItemIdString is : "+indexItemIdString);
}
}
log.warn("ContentList: item has no category, contentList will be empty.");
}
// output the XML
ContentItem item;
Element itemElement;
DomainObjectXMLRenderer renderer;
String itemIdString;
Iterator classes = items.keySet().iterator();
String className;
List list;
Element clElement;
while (classes.hasNext()) {
className = (String) classes.next();
list = (List) items.get(className);
//log.debug("looking at items of type : "+className);
} else {
// we're viewing a category. process it
//String categoryIdString = state.getRequest().getParameter(CATEGORYID_PARAM);
//Category category = new Category(new OID(Category.class.getName(), new BigDecimal(categoryIdString)));
Category category = getCategory();
log.debug("ContentList: getCategory returned : "+getCategory());
clElement = parent.newChildElement(TAG_ITEMLIST, CMS.CMS_XML_NS);
//exportAttributes(content); ???
clElement.addAttribute(TAG_ITEMLIST_TYPE, className);
if (category != null) {
for (int i=0; i<list.size(); i++) {
processCategory(category, null, null, items, sortKeys);
itemIdString = (String) list.get(i);
item = new ContentItem(new OID(ContentItem.class.getName(), new BigDecimal(itemIdString)));
//log.debug("adding to contentList : "+item.getDisplayName()+", id : "+itemIdString);
itemElement = clElement.newChildElement(TAG_ITEM, CMS.CMS_XML_NS);
// mark the item as being the index item, if it is
if (itemIdString.equals(indexItemIdString)) {
itemElement.addAttribute(TAG_ITEM_ISINDEX, TAG_ITEM_ISINDEX_VALUE);
// process the index item, just in case it isn't in the lists
// above (ie inherited from parent category)
ACSObject indexItem = category.getIndexObject();
if ((indexItem != null) && (indexItem instanceof ContentBundle)) {
/*Fix by Quasimodo*/
/* getPrimaryInstance doesn't negotiate the language of the content item */
/* ContentItem cIndexItem = ((ContentBundle) indexItem).getPrimaryInstance().getLiveVersion(); */
ContentItem cItem = ((ContentBundle) indexItem).negotiate(request.getLocales());
// If there is no matching language version for this content item
if(cItem == null) {
// get the primary instance instead (fallback)
cItem = ((ContentBundle) indexItem).getPrimaryInstance();
}
itemElement.addAttribute("sortKey", ""+sortKeys.get(item.getID().toString()));
renderer = new DomainObjectXMLRenderer(itemElement);
// not sure these are necessary
renderer.setWrapAttributes(true);
renderer.setWrapRoot(false);
renderer.setWrapObjects(false);
renderer.walk(item, SimpleXMLGenerator.ADAPTER_CONTEXT);
ContentItem cIndexItem = cItem.getLiveVersion();
//log.debug("indexItem : "+cIndexItem);
if (cIndexItem != null) {
processItem(cIndexItem, null, null, items);
indexItemIdString = cIndexItem.getID().toString();
}
//log.debug("indexItemIdString is : "+indexItemIdString);
}
}
}
// output the XML
ContentItem item;
Element itemElement;
DomainObjectXMLRenderer renderer;
String itemIdString;
Iterator classes = items.keySet().iterator();
String className;
List list;
Element clElement;
while (classes.hasNext()) {
className = (String) classes.next();
list = (List) items.get(className);
//log.debug("looking at items of type : "+className);
clElement = parent.newChildElement(TAG_ITEMLIST, CMS.CMS_XML_NS);
//exportAttributes(content); ???
clElement.addAttribute(TAG_ITEMLIST_TYPE, className);
for (int i=0; i<list.size(); i++) {
itemIdString = (String) list.get(i);
item = new ContentItem(new OID(ContentItem.class.getName(), new BigDecimal(itemIdString)));
//log.debug("adding to contentList : "+item.getDisplayName()+", id : "+itemIdString);
itemElement = clElement.newChildElement(TAG_ITEM, CMS.CMS_XML_NS);
// mark the item as being the index item, if it is
if (itemIdString.equals(indexItemIdString)) {
itemElement.addAttribute(TAG_ITEM_ISINDEX, TAG_ITEM_ISINDEX_VALUE);
}
itemElement.addAttribute("sortKey", ""+sortKeys.get(item.getID().toString()));
renderer = new DomainObjectXMLRenderer(itemElement);
// not sure these are necessary
renderer.setWrapAttributes(true);
renderer.setWrapRoot(false);
renderer.setWrapObjects(false);
renderer.walk(item, SimpleXMLGenerator.ADAPTER_CONTEXT);
}
}
//}
return parent;
@ -225,14 +247,14 @@ public class ContentList extends AbstractComponent {
log.debug("ContentList: processing category : "+category.getName());
// items don't come out properly ordered... adding "parent" as optional parameter gives back nothing
CategorizedCollection catcol = category.getObjects(CONTENTITEM_CLASS_NAME);
// DataCollection os = SessionManager.getSession().retrieve(CONTENTITEM_CLASS_NAME);
// DataCollection os = SessionManager.getSession().retrieve(CONTENTITEM_CLASS_NAME);
// os.addOrder("parent.categories.link.sortKey");
// CategorizedCollection catcol = new CategorizedCollection(os);
// catcol.
catcol.sort(true);
// catcol.
catcol.sort(true);
ContentItem item;
int sortKey = 0;
int sortKey = 0;
while (catcol.next()) {
item = (ContentItem) catcol.getDomainObject();
@ -240,20 +262,28 @@ public class ContentList extends AbstractComponent {
if (item instanceof ContentBundle) {
log.debug("looking at item : "+item);
/*Fix by Quasimodo*/
/* getPrimaryInstance doesn't negotiate the language of the content item */
/* item = ((ContentBundle) item).getPrimaryInstance(); */
item = ((ContentBundle) item).negotiate(DispatcherHelper.getRequest().getLocales());
// If there is no matching language version for this content item
if(item == null) {
// get the primary instance instead (fallback)
item = ((ContentBundle) item).getPrimaryInstance();
}
//This can cause item to become null, if there is no instance of it for the default language
if (item != null) {
processItem(item, currentItemClassName, currentItemIdString, items);
processItem(item, currentItemClassName, currentItemIdString, items);
}
}
log.debug("adding sortKey " + sortKey + " to item " + item);
log.debug("adding sortKey " + sortKey + " to item " + item);
// This item can be null, so check first...
if (item != null) {
sortKeys.put(item.getID().toString(), ""+sortKey);
sortKey++;
sortKeys.put(item.getID().toString(), ""+sortKey);
sortKey++;
} else {
log.warn("ContentList: Item " + sortKey + " in category \"" + category.getName() + "\" was null. Ignoring.");
log.warn("ContentList: Item " + sortKey + " in category \"" + category.getName() + "\" was null. Ignoring.");
}
}
}
@ -262,24 +292,24 @@ public class ContentList extends AbstractComponent {
log.debug("ContentList: processing item : "+item.getDisplayName());
// only take the live version (all versions are linked to categories, so avoid duplicate)
if (item.isLiveVersion() && item.isLive()) {
// only take the live version (all versions are linked to categories, so avoid duplicate)
if (item.isLiveVersion() && item.isLive()) {
String itemClassName = item.getClass().getName();
List list = (List) items.get(itemClassName);
String itemClassName = item.getClass().getName();
List list = (List) items.get(itemClassName);
if (list == null) {
list = new ArrayList();
items.put(itemClassName, list);
}
// We do not want to add the latest version of the item to our list. This reference may become
// stale if the item changes, meaning that search engines are directed to an item that is no longer
// available.
String itemIdString = item.getMaster().getID().toString();
if (!list.contains(itemIdString)) {
list.add(itemIdString);
}
if (list == null) {
list = new ArrayList();
items.put(itemClassName, list);
}
// We do not want to add the latest version of the item to our list. This reference may become
// stale if the item changes, meaning that search engines are directed to an item that is no longer
// available.
String itemIdString = item.getMaster().getID().toString();
if (!list.contains(itemIdString)) {
list.add(itemIdString);
}
}
}
}

View File

@ -53,7 +53,7 @@ public class GreetingItem extends AbstractComponent {
private static final Logger s_log = Logger.getLogger( GreetingItem.class );
public Element generateXML(HttpServletRequest request,
HttpServletResponse response) {
HttpServletResponse response) {
ContentItem item = (ContentItem)getObject();
if (null == item || !item.isLive()) {
return null;
@ -67,7 +67,7 @@ public class GreetingItem extends AbstractComponent {
Element content = Navigation.newElement("greetingItem");
Party currentParty = Kernel.getContext().getParty();
if (currentParty == null) {
currentParty = Kernel.getPublicUser();
currentParty = Kernel.getPublicUser();
}
// check if current user can edit the current index item (nb privilege is granted on draft item, but live item
// has draft as its permission context
@ -77,11 +77,11 @@ public class GreetingItem extends AbstractComponent {
PermissionDescriptor edit = new PermissionDescriptor(PrivilegeDescriptor.get(SecurityManager.CMS_EDIT_ITEM), item, currentParty);
if (PermissionService.checkPermission(edit)) {
content.addAttribute("canEdit", "true");
content.addAttribute("canEdit", "true");
}
PermissionDescriptor publish = new PermissionDescriptor(PrivilegeDescriptor.get(SecurityManager.CMS_PUBLISH), item, currentParty);
if (PermissionService.checkPermission(publish)) {
content.addAttribute("canPublish", "true");
content.addAttribute("canPublish", "true");
}
ContentBundle bundle = (ContentBundle)item;
@ -97,11 +97,16 @@ public class GreetingItem extends AbstractComponent {
*/
//ContentItem baseItem = bundle.getPrimaryInstance();
ContentItem baseItem = bundle.negotiate(request.getLocales());
// If there is no matching language version for this content item
if(baseItem == null) {
// get the primary instance instead (fallback)
baseItem = bundle.getPrimaryInstance();
}
Element itemEl = content.newChildElement("cms:item",
CMS.CMS_XML_NS);
CMS.CMS_XML_NS);
DomainObjectXMLRenderer renderer =
new DomainObjectXMLRenderer(itemEl);
new DomainObjectXMLRenderer(itemEl);
renderer.setWrapAttributes( true );
renderer.setWrapRoot( false );

View File

@ -21,6 +21,7 @@ import com.arsdigita.cms.ContentBundle;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentSectionConfig;
import com.arsdigita.cms.ExtraXMLGenerator;
import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.london.navigation.Navigation;
import com.arsdigita.xml.Element;
@ -64,7 +65,7 @@ public class GreetingItemExtraXML extends AbstractComponent {
}
public Element generateXML(HttpServletRequest request,
HttpServletResponse response) {
HttpServletResponse response) {
ContentItem item = getItem();
@ -107,7 +108,15 @@ public class GreetingItemExtraXML extends AbstractComponent {
}
ContentBundle bundle = (ContentBundle) item;
ContentItem baseItem = bundle.getPrimaryInstance();
/*Fix by Quasimodo*/
/* getPrimaryInstance doesn't negotiate the language of the content item */
/* ContentItem baseItem = bundle.getPrimaryInstance(); */
ContentItem baseItem = bundle.negotiate(DispatcherHelper.getRequest().getLocales());
// If there is no matching language version for this content item
if(baseItem == null) {
// get the primary instance instead (fallback)
baseItem = bundle.getPrimaryInstance();
}
return baseItem;
}

View File

@ -64,7 +64,16 @@ public class NavigationRootIndexItem extends AbstractComponent {
Element parentElement = Navigation.newElement(TAG_PARENT);
try {
ContentItem indexItem = ((ContentBundle) Navigation.getConfig().getDefaultCategoryRoot().getIndexObject()).getPrimaryInstance().getLiveVersion();
/*Fix by Quasimodo*/
/* getPrimaryInstance doesn't negotiate the language of the content item */
/* ContentItem indexItem = ((ContentBundle) Navigation.getConfig().getDefaultCategoryRoot().getIndexObject()).getPrimaryInstance().getLiveVersion(); */
ContentItem indexItem = ((ContentBundle) Navigation.getConfig().getDefaultCategoryRoot().getIndexObject()).negotiate(request.getLocales());
// if there is no matching language version for this content item
if(indexItem == null) {
// get the primary instance instead (fallback)
indexItem = ((ContentBundle) Navigation.getConfig().getDefaultCategoryRoot().getIndexObject()).getPrimaryInstance();
}
indexItem = indexItem.getLiveVersion();
Element itemElement = parentElement.newChildElement(TAG_ITEM, CMS.CMS_XML_NS);
DomainObjectXMLRenderer renderer = new DomainObjectXMLRenderer(itemElement);
// not sure these are necessary

View File

@ -54,21 +54,31 @@ public class RelatedItems extends AbstractComponent {
}
public Element generateXML(HttpServletRequest request,
HttpServletResponse response) {
HttpServletResponse response) {
Assert.locked(this);
NavigationModel model = getModel();
ACSObject obj = model.getObject();
// on category pages, we obtain a ContentBundle
if (obj instanceof ContentBundle) {
obj = ((ContentBundle) obj).getPrimaryInstance();
// on category pages, we obtain a ContentBundle
if (obj instanceof ContentBundle) {
/*Fix by Quasimodo*/
/* getPrimaryInstance doesn't negotiate the language of the content item */
/* obj = ((ContentBundle) obj).getPrimaryInstance(); */
ContentItem cItem = ((ContentBundle) obj).negotiate(request.getLocales());
// if there is no matching language version of the content item
if(cItem == null) {
// get the primary instance instead (fallback)
cItem = ((ContentBundle) obj).getPrimaryInstance();
}
obj = cItem;
}
if (!(obj instanceof ContentPage)) {
if (s_log.isInfoEnabled()) {
s_log.info("Cannot generate related items " +
"for non-content item " + obj);
"for non-content item " + obj);
}
return null;
}
@ -89,7 +99,7 @@ public class RelatedItems extends AbstractComponent {
RelatedItemsQueryFactory factory = RelatedItemsQueryFactory.getInstance();
RelatedItemsQuery items = factory.getRelatedItems(item,
getModel().getCategory());
getModel().getCategory());
if (items == null) {
return null;