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.ContentBundle;
import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.dispatcher.SimpleXMLGenerator; import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.domain.DomainObjectXMLRenderer; import com.arsdigita.domain.DomainObjectXMLRenderer;
import com.arsdigita.kernel.ACSObject; import com.arsdigita.kernel.ACSObject;
import com.arsdigita.london.navigation.ui.AbstractComponent;
import com.arsdigita.persistence.OID; import com.arsdigita.persistence.OID;
import com.arsdigita.xml.Element; import com.arsdigita.xml.Element;
@ -106,115 +106,137 @@ public class ContentList extends AbstractComponent {
//if (isVisible(state)) { //if (isVisible(state)) {
String indexItemIdString = null; String indexItemIdString = null;
// check if we are currently displaying an item // check if we are currently displaying an item
HashMap items = new HashMap(); HashMap items = new HashMap();
HashMap sortKeys = new HashMap(); HashMap sortKeys = new HashMap();
ContentItem currentItem = null; ContentItem currentItem = null;
try { try {
currentItem = CMS.getContext().getContentItem(); currentItem = CMS.getContext().getContentItem();
log.debug("ContentList: CMS.getContext().getContentItem() returned : "+currentItem); log.debug("ContentList: CMS.getContext().getContentItem() returned : "+currentItem);
} catch (IllegalStateException e) { } catch (IllegalStateException e) {
// we're dealing with a category // we're dealing with a category
} }
if (currentItem != null) { if (currentItem != null) {
// take the first category in the list, should do the trick???? // take the first category in the list, should do the trick????
Iterator categories = currentItem.getCategories(null); Iterator categories = currentItem.getCategories(null);
if (categories.hasNext()) { if (categories.hasNext()) {
Category category = (Category) categories.next(); Category category = (Category) categories.next();
String currentItemClassName = currentItem.getClass().getName(); String currentItemClassName = currentItem.getClass().getName();
String currentItemIdString = currentItem.getID().toString(); String currentItemIdString = currentItem.getID().toString();
log.debug("ContentList: looking at the first category of the item : "+category.getName()); log.debug("ContentList: looking at the first category of the item : "+category.getName());
// only navigation categories (not sure this was truely necessary in fact) // only navigation categories (not sure this was truely necessary in fact)
// if (getNavigationRootCategory().isMemberOfSubtree(category)) { // if (getNavigationRootCategory().isMemberOfSubtree(category)) {
processCategory(category, currentItemClassName, currentItemIdString, items, sortKeys); processCategory(category, currentItemClassName, currentItemIdString, items, sortKeys);
// } // }
// now that we look at only one category, also mark the indexItem as such // 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 // but don't process it on top of what has already been done
ACSObject indexItem = category.getIndexObject(); ACSObject indexItem = category.getIndexObject();
if ((indexItem != null) && (indexItem instanceof ContentBundle)) { if ((indexItem != null) && (indexItem instanceof ContentBundle)) {
ContentItem cIndexItem = ((ContentBundle) indexItem).getPrimaryInstance().getLiveVersion();
if (cIndexItem != null) { /*Fix by Quasimodo*/
indexItemIdString = cIndexItem.getID().toString(); /* 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 { ContentItem cIndexItem = cItem.getLiveVersion();
log.warn("ContentList: item has no category, contentList will be empty.");
if (cIndexItem != null) {
indexItemIdString = cIndexItem.getID().toString();
}
} }
} else { } else {
// we're viewing a category. process it log.warn("ContentList: item has no category, contentList will be empty.");
//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);
}
}
} }
// output the XML } else {
ContentItem item; // we're viewing a category. process it
Element itemElement; //String categoryIdString = state.getRequest().getParameter(CATEGORYID_PARAM);
DomainObjectXMLRenderer renderer; //Category category = new Category(new OID(Category.class.getName(), new BigDecimal(categoryIdString)));
String itemIdString; Category category = getCategory();
Iterator classes = items.keySet().iterator(); log.debug("ContentList: getCategory returned : "+getCategory());
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); if (category != null) {
//exportAttributes(content); ???
clElement.addAttribute(TAG_ITEMLIST_TYPE, className);
for (int i=0; i<list.size(); i++) { processCategory(category, null, null, items, sortKeys);
itemIdString = (String) list.get(i); // process the index item, just in case it isn't in the lists
item = new ContentItem(new OID(ContentItem.class.getName(), new BigDecimal(itemIdString))); // above (ie inherited from parent category)
//log.debug("adding to contentList : "+item.getDisplayName()+", id : "+itemIdString); ACSObject indexItem = category.getIndexObject();
if ((indexItem != null) && (indexItem instanceof ContentBundle)) {
itemElement = clElement.newChildElement(TAG_ITEM, CMS.CMS_XML_NS); /*Fix by Quasimodo*/
/* getPrimaryInstance doesn't negotiate the language of the content item */
// mark the item as being the index item, if it is /* ContentItem cIndexItem = ((ContentBundle) indexItem).getPrimaryInstance().getLiveVersion(); */
if (itemIdString.equals(indexItemIdString)) { ContentItem cItem = ((ContentBundle) indexItem).negotiate(request.getLocales());
itemElement.addAttribute(TAG_ITEM_ISINDEX, TAG_ITEM_ISINDEX_VALUE); // 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())); ContentItem cIndexItem = cItem.getLiveVersion();
//log.debug("indexItem : "+cIndexItem);
if (cIndexItem != null) {
renderer = new DomainObjectXMLRenderer(itemElement); processItem(cIndexItem, null, null, items);
// not sure these are necessary indexItemIdString = cIndexItem.getID().toString();
renderer.setWrapAttributes(true); }
renderer.setWrapRoot(false); //log.debug("indexItemIdString is : "+indexItemIdString);
renderer.setWrapObjects(false);
renderer.walk(item, SimpleXMLGenerator.ADAPTER_CONTEXT);
} }
} }
}
// 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; return parent;
@ -225,14 +247,14 @@ public class ContentList extends AbstractComponent {
log.debug("ContentList: processing category : "+category.getName()); log.debug("ContentList: processing category : "+category.getName());
// items don't come out properly ordered... adding "parent" as optional parameter gives back nothing // items don't come out properly ordered... adding "parent" as optional parameter gives back nothing
CategorizedCollection catcol = category.getObjects(CONTENTITEM_CLASS_NAME); 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"); // os.addOrder("parent.categories.link.sortKey");
// CategorizedCollection catcol = new CategorizedCollection(os); // CategorizedCollection catcol = new CategorizedCollection(os);
// catcol. // catcol.
catcol.sort(true); catcol.sort(true);
ContentItem item; ContentItem item;
int sortKey = 0; int sortKey = 0;
while (catcol.next()) { while (catcol.next()) {
item = (ContentItem) catcol.getDomainObject(); item = (ContentItem) catcol.getDomainObject();
@ -240,20 +262,28 @@ public class ContentList extends AbstractComponent {
if (item instanceof ContentBundle) { if (item instanceof ContentBundle) {
log.debug("looking at item : "+item); 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(); item = ((ContentBundle) item).getPrimaryInstance();
}
//This can cause item to become null, if there is no instance of it for the default language //This can cause item to become null, if there is no instance of it for the default language
if (item != null) { 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... // This item can be null, so check first...
if (item != null) { if (item != null) {
sortKeys.put(item.getID().toString(), ""+sortKey); sortKeys.put(item.getID().toString(), ""+sortKey);
sortKey++; sortKey++;
} else { } 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()); log.debug("ContentList: processing item : "+item.getDisplayName());
// only take the live version (all versions are linked to categories, so avoid duplicate) // only take the live version (all versions are linked to categories, so avoid duplicate)
if (item.isLiveVersion() && item.isLive()) { if (item.isLiveVersion() && item.isLive()) {
String itemClassName = item.getClass().getName(); String itemClassName = item.getClass().getName();
List list = (List) items.get(itemClassName); List list = (List) items.get(itemClassName);
if (list == null) { if (list == null) {
list = new ArrayList(); list = new ArrayList();
items.put(itemClassName, list); 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);
}
} }
// 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 ); private static final Logger s_log = Logger.getLogger( GreetingItem.class );
public Element generateXML(HttpServletRequest request, public Element generateXML(HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
ContentItem item = (ContentItem)getObject(); ContentItem item = (ContentItem)getObject();
if (null == item || !item.isLive()) { if (null == item || !item.isLive()) {
return null; return null;
@ -67,7 +67,7 @@ public class GreetingItem extends AbstractComponent {
Element content = Navigation.newElement("greetingItem"); Element content = Navigation.newElement("greetingItem");
Party currentParty = Kernel.getContext().getParty(); Party currentParty = Kernel.getContext().getParty();
if (currentParty == null) { 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 // 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 // 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); PermissionDescriptor edit = new PermissionDescriptor(PrivilegeDescriptor.get(SecurityManager.CMS_EDIT_ITEM), item, currentParty);
if (PermissionService.checkPermission(edit)) { if (PermissionService.checkPermission(edit)) {
content.addAttribute("canEdit", "true"); content.addAttribute("canEdit", "true");
} }
PermissionDescriptor publish = new PermissionDescriptor(PrivilegeDescriptor.get(SecurityManager.CMS_PUBLISH), item, currentParty); PermissionDescriptor publish = new PermissionDescriptor(PrivilegeDescriptor.get(SecurityManager.CMS_PUBLISH), item, currentParty);
if (PermissionService.checkPermission(publish)) { if (PermissionService.checkPermission(publish)) {
content.addAttribute("canPublish", "true"); content.addAttribute("canPublish", "true");
} }
ContentBundle bundle = (ContentBundle)item; ContentBundle bundle = (ContentBundle)item;
@ -97,11 +97,16 @@ public class GreetingItem extends AbstractComponent {
*/ */
//ContentItem baseItem = bundle.getPrimaryInstance(); //ContentItem baseItem = bundle.getPrimaryInstance();
ContentItem baseItem = bundle.negotiate(request.getLocales()); 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", Element itemEl = content.newChildElement("cms:item",
CMS.CMS_XML_NS); CMS.CMS_XML_NS);
DomainObjectXMLRenderer renderer = DomainObjectXMLRenderer renderer =
new DomainObjectXMLRenderer(itemEl); new DomainObjectXMLRenderer(itemEl);
renderer.setWrapAttributes( true ); renderer.setWrapAttributes( true );
renderer.setWrapRoot( false ); renderer.setWrapRoot( false );

View File

@ -21,6 +21,7 @@ import com.arsdigita.cms.ContentBundle;
import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentSectionConfig; import com.arsdigita.cms.ContentSectionConfig;
import com.arsdigita.cms.ExtraXMLGenerator; import com.arsdigita.cms.ExtraXMLGenerator;
import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.london.navigation.Navigation; import com.arsdigita.london.navigation.Navigation;
import com.arsdigita.xml.Element; import com.arsdigita.xml.Element;
@ -64,7 +65,7 @@ public class GreetingItemExtraXML extends AbstractComponent {
} }
public Element generateXML(HttpServletRequest request, public Element generateXML(HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
ContentItem item = getItem(); ContentItem item = getItem();
@ -107,7 +108,15 @@ public class GreetingItemExtraXML extends AbstractComponent {
} }
ContentBundle bundle = (ContentBundle) item; 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; return baseItem;
} }

View File

@ -64,7 +64,16 @@ public class NavigationRootIndexItem extends AbstractComponent {
Element parentElement = Navigation.newElement(TAG_PARENT); Element parentElement = Navigation.newElement(TAG_PARENT);
try { 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); Element itemElement = parentElement.newChildElement(TAG_ITEM, CMS.CMS_XML_NS);
DomainObjectXMLRenderer renderer = new DomainObjectXMLRenderer(itemElement); DomainObjectXMLRenderer renderer = new DomainObjectXMLRenderer(itemElement);
// not sure these are necessary // not sure these are necessary

View File

@ -54,21 +54,31 @@ public class RelatedItems extends AbstractComponent {
} }
public Element generateXML(HttpServletRequest request, public Element generateXML(HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
Assert.locked(this); Assert.locked(this);
NavigationModel model = getModel(); NavigationModel model = getModel();
ACSObject obj = model.getObject(); ACSObject obj = model.getObject();
// on category pages, we obtain a ContentBundle // on category pages, we obtain a ContentBundle
if (obj instanceof ContentBundle) { if (obj instanceof ContentBundle) {
obj = ((ContentBundle) obj).getPrimaryInstance();
/*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 (!(obj instanceof ContentPage)) {
if (s_log.isInfoEnabled()) { if (s_log.isInfoEnabled()) {
s_log.info("Cannot generate related items " + s_log.info("Cannot generate related items " +
"for non-content item " + obj); "for non-content item " + obj);
} }
return null; return null;
} }
@ -89,7 +99,7 @@ public class RelatedItems extends AbstractComponent {
RelatedItemsQueryFactory factory = RelatedItemsQueryFactory.getInstance(); RelatedItemsQueryFactory factory = RelatedItemsQueryFactory.getInstance();
RelatedItemsQuery items = factory.getRelatedItems(item, RelatedItemsQuery items = factory.getRelatedItems(item,
getModel().getCategory()); getModel().getCategory());
if (items == null) { if (items == null) {
return null; return null;