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

@ -5,12 +5,12 @@
* modify it under the terms of the GNU Lesser General Public License * modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of * as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@ -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;
@ -71,28 +71,28 @@ import org.apache.log4j.Logger;
*/ */
public class ContentList extends AbstractComponent { public class ContentList extends AbstractComponent {
// extends SimpleComponent // extends SimpleComponent
public static final String versionId = "$Id: ContentList.java 1173 2006-06-14 13:54:39Z fabrice $"; public static final String versionId = "$Id: ContentList.java 1173 2006-06-14 13:54:39Z fabrice $";
private static Logger log = Logger.getLogger(ContentList.class);; private static Logger log = Logger.getLogger(ContentList.class);;
private static final String TAG_ITEMLISTS = "cms:contentLists"; private static final String TAG_ITEMLISTS = "cms:contentLists";
private static final String TAG_ITEMLIST = "cms:contentList"; private static final String TAG_ITEMLIST = "cms:contentList";
private static final String TAG_ITEMLIST_TYPE = "type"; private static final String TAG_ITEMLIST_TYPE = "type";
private static final String TAG_ITEM = "cms:item"; private static final String TAG_ITEM = "cms:item";
private static final String TAG_ITEM_ISINDEX = "name"; private static final String TAG_ITEM_ISINDEX = "name";
private static final String TAG_ITEM_ISINDEX_VALUE = "index"; private static final String TAG_ITEM_ISINDEX_VALUE = "index";
private static final String NAVIGATION_ROOT_NAME = "Navigation"; private static final String NAVIGATION_ROOT_NAME = "Navigation";
private static final String CATEGORYID_PARAM = "categoryID"; private static final String CATEGORYID_PARAM = "categoryID";
private static final String CONTENTITEM_CLASS_NAME = ContentItem.class.getName(); private static final String CONTENTITEM_CLASS_NAME = ContentItem.class.getName();
public ContentList() { public ContentList() {
super(); super();
} }
/** /**
* Generates the XML. * Generates the XML.
* *
@ -101,185 +101,215 @@ public class ContentList extends AbstractComponent {
*/ */
public Element generateXML(HttpServletRequest request, HttpServletResponse response) { public Element generateXML(HttpServletRequest request, HttpServletResponse response) {
//PageState state, Element parent //PageState state, Element parent
Element parent = new Element(TAG_ITEMLISTS, CMS.CMS_XML_NS); Element parent = new Element(TAG_ITEMLISTS, CMS.CMS_XML_NS);
//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
// 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();
}
}
} else {
log.warn("ContentList: item has no category, contentList will be empty.");
}
} 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);
}
}
}
// output the XML // now that we look at only one category, also mark the indexItem as such
ContentItem item; // but don't process it on top of what has already been done
Element itemElement; ACSObject indexItem = category.getIndexObject();
DomainObjectXMLRenderer renderer; if ((indexItem != null) && (indexItem instanceof ContentBundle)) {
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); /*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();
if (cIndexItem != null) {
renderer = new DomainObjectXMLRenderer(itemElement); indexItemIdString = cIndexItem.getID().toString();
// not sure these are necessary }
renderer.setWrapAttributes(true); }
renderer.setWrapRoot(false);
renderer.setWrapObjects(false); } else {
renderer.walk(item, SimpleXMLGenerator.ADAPTER_CONTEXT); log.warn("ContentList: item has no category, contentList will be empty.");
}
} 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)) {
/*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();
}
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; return parent;
} }
public void processCategory(Category category, String currentItemClassName, String currentItemIdString, HashMap items, HashMap sortKeys) { public void processCategory(Category category, String currentItemClassName, String currentItemIdString, HashMap items, HashMap sortKeys) {
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();
//log.debug("looking at bundle : "+item); //log.debug("looking at bundle : "+item);
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.");
} }
} }
} }
public void processItem(ContentItem item, String currentItemClassName, String currentItemIdString, HashMap items) { public void processItem(ContentItem item, String currentItemClassName, String currentItemIdString, HashMap items) {
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

@ -5,12 +5,12 @@
* modify it under the terms of the GNU Lesser General Public License * modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of * as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@ -38,11 +38,11 @@ import com.arsdigita.london.navigation.Navigation;
import com.arsdigita.xml.Element; import com.arsdigita.xml.Element;
/** /**
* GreetingItem component displays a list of items in a category, ordered by * GreetingItem component displays a list of items in a category, ordered by
* title. The provided links allow the list of items to be restricted by * title. The provided links allow the list of items to be restricted by
* a letter of the alphabet. * a letter of the alphabet.
* The number, type, and attributes of the returned items can be configured * The number, type, and attributes of the returned items can be configured
* from jsp page using setHowMany( int ), * setObjectType( String ), * from jsp page using setHowMany( int ), * setObjectType( String ),
* and addAttribute( String ) methods. The object type must be either that of * and addAttribute( String ) methods. The object type must be either that of
* ContentPage or extend the ContentPage. * ContentPage or extend the ContentPage.
* *
@ -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;
@ -62,30 +62,30 @@ public class GreetingItem extends AbstractComponent {
if (!ContentItem.VERSION.equals(item.getVersion())) { if (!ContentItem.VERSION.equals(item.getVersion())) {
item = item.getLiveVersion(); item = item.getLiveVersion();
} }
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
// //
// Note that the xml that is generated is only of use if you DO NOT CACHE index pages. // Note that the xml that is generated is only of use if you DO NOT CACHE index pages.
// cg. // cg.
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;
/* Fix by Jens Pelzetter, 2009-08-28 /* Fix by Jens Pelzetter, 2009-08-28
* bundle.getPrimaryInstance() does not about the preferred languages * bundle.getPrimaryInstance() does not about the preferred languages
* of the User Client, instead it returns the primary instance of * of the User Client, instead it returns the primary instance of
@ -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;
@ -32,13 +33,13 @@ import com.arsdigita.xml.Element;
* @version $Id: GreetingItem.java 285 2005-02-22 00:29:02Z sskracic $ * @version $Id: GreetingItem.java 285 2005-02-22 00:29:02Z sskracic $
*/ */
public class GreetingItemExtraXML extends AbstractComponent { public class GreetingItemExtraXML extends AbstractComponent {
private static final Logger s_log = Logger.getLogger(GreetingItemExtraXML.class); private static final Logger s_log = Logger.getLogger(GreetingItemExtraXML.class);
public static final String extraTag = "greetingItemExtraXML"; public static final String extraTag = "greetingItemExtraXML";
Map xmlGenerators = new HashMap(); Map xmlGenerators = new HashMap();
public void register(Page p) { public void register(Page p) {
super.register(p); super.register(p);
@ -62,26 +63,26 @@ public class GreetingItemExtraXML extends AbstractComponent {
xmlGenerators.put(type, genInstances); xmlGenerators.put(type, genInstances);
} }
} }
public Element generateXML(HttpServletRequest request, public Element generateXML(HttpServletRequest request,
HttpServletResponse response) { HttpServletResponse response) {
ContentItem item = getItem(); ContentItem item = getItem();
if (item == null) { if (item == null) {
return null; return null;
} }
List generators = (List) xmlGenerators.get(item.getClass().getName()); List generators = (List) xmlGenerators.get(item.getClass().getName());
if (s_log.isDebugEnabled()) { if (s_log.isDebugEnabled()) {
s_log.debug("Item : "+item.getName()+", type : "+item.BASE_DATA_OBJECT_TYPE+", no generators : "+(generators == null ? "null" : ""+generators.size())); s_log.debug("Item : "+item.getName()+", type : "+item.BASE_DATA_OBJECT_TYPE+", no generators : "+(generators == null ? "null" : ""+generators.size()));
} }
if (generators == null || generators.isEmpty()) { if (generators == null || generators.isEmpty()) {
return null; return null;
} }
Element content = Navigation.newElement(extraTag); Element content = Navigation.newElement(extraTag);
PageState state = PageState.getPageState(request); PageState state = PageState.getPageState(request);
for (Iterator i=generators.iterator(); i.hasNext(); ) { for (Iterator i=generators.iterator(); i.hasNext(); ) {
@ -91,12 +92,12 @@ public class GreetingItemExtraXML extends AbstractComponent {
} }
generator.generateXML(item, content, state); generator.generateXML(item, content, state);
} }
return content; return content;
} }
public ContentItem getItem() { public ContentItem getItem() {
ContentItem item = (ContentItem) getObject(); ContentItem item = (ContentItem) getObject();
if (null == item || !item.isLive()) { if (null == item || !item.isLive()) {
return null; return null;
@ -105,10 +106,18 @@ public class GreetingItemExtraXML extends AbstractComponent {
if (!ContentItem.VERSION.equals(item.getVersion())) { if (!ContentItem.VERSION.equals(item.getVersion())) {
item = item.getLiveVersion(); item = item.getLiveVersion();
} }
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

@ -5,12 +5,12 @@
* modify it under the terms of the GNU Lesser General Public License * modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of * as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version. * the License, or (at your option) any later version.
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
@ -41,9 +41,9 @@ import org.apache.log4j.Logger;
* @version $Revision: $ $Date: $ * @version $Revision: $ $Date: $
*/ */
public class NavigationRootIndexItem extends AbstractComponent { public class NavigationRootIndexItem extends AbstractComponent {
public static final String versionId = "$Id: $"; public static final String versionId = "$Id: $";
private static Logger log = Logger.getLogger(NavigationRootIndexItem.class);; private static Logger log = Logger.getLogger(NavigationRootIndexItem.class);;
private static final String TAG_PARENT = "navrootindex"; private static final String TAG_PARENT = "navrootindex";
@ -52,7 +52,7 @@ public class NavigationRootIndexItem extends AbstractComponent {
public NavigationRootIndexItem() { public NavigationRootIndexItem() {
super(); super();
} }
/** /**
* Generates the XML. * Generates the XML.
* *
@ -60,11 +60,20 @@ public class NavigationRootIndexItem extends AbstractComponent {
* @param parent The parent DOM element * @param parent The parent DOM element
*/ */
public Element generateXML(HttpServletRequest request, HttpServletResponse response) { public Element generateXML(HttpServletRequest request, HttpServletResponse response) {
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
@ -75,7 +84,7 @@ public class NavigationRootIndexItem extends AbstractComponent {
} catch (Exception e) { } catch (Exception e) {
log.warn("Could not get index ContentItem of the root navigation category.", e); log.warn("Could not get index ContentItem of the root navigation category.", e);
} }
return parentElement; return parentElement;
} }
} }

View File

@ -1,7 +1,7 @@
/* /*
* Copyright (C) 2001 ArsDigita Corporation. All Rights Reserved. * Copyright (C) 2001 ArsDigita Corporation. All Rights Reserved.
* *
* The contents of this file are subject to the ArsDigita Public * The contents of this file are subject to the ArsDigita Public
* License (the "License"); you may not use this file except in * License (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of * compliance with the License. You may obtain a copy of
* the License at http://www.arsdigita.com/ADPL.txt * the License at http://www.arsdigita.com/ADPL.txt
@ -43,32 +43,42 @@ import org.apache.log4j.Logger;
*/ */
public class RelatedItems extends AbstractComponent { public class RelatedItems extends AbstractComponent {
private static final Logger s_log = Logger.getLogger(RelatedItems.class); private static final Logger s_log = Logger.getLogger(RelatedItems.class);
private int m_howMany = 15; private int m_howMany = 15;
public void setHowMany(int howMany) { public void setHowMany(int howMany) {
Assert.unlocked(this); Assert.unlocked(this);
m_howMany = howMany; m_howMany = howMany;
} }
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;
} }
@ -83,27 +93,27 @@ public class RelatedItems extends AbstractComponent {
} }
item = (ContentPage)item.getLiveVersion(); item = (ContentPage)item.getLiveVersion();
} }
Element element = Navigation.newElement("relatedItems"); Element element = Navigation.newElement("relatedItems");
element.addAttribute("id", getIdAttr()); element.addAttribute("id", getIdAttr());
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;
} }
items.setRange(new Integer(1), new Integer(m_howMany)); items.setRange(new Integer(1), new Integer(m_howMany));
items.addOrder(RelatedItemsQuery.TITLE); items.addOrder(RelatedItemsQuery.TITLE);
while (items.next()) { while (items.next()) {
OID oid = new OID( items.getObjectType(), items.getWorkingID() ); OID oid = new OID( items.getObjectType(), items.getWorkingID() );
String path = Navigation.redirectURL(oid); String path = Navigation.redirectURL(oid);
Element itemEl = Navigation.newElement("relatedItem"); Element itemEl = Navigation.newElement("relatedItem");
itemEl.addAttribute("title", items.getTitle()); itemEl.addAttribute("title", items.getTitle());
itemEl.addAttribute("type", items.getTypeName()); itemEl.addAttribute("type", items.getTypeName());
itemEl.addAttribute("id", items.getItemID().toString()); itemEl.addAttribute("id", items.getItemID().toString());
@ -113,5 +123,5 @@ public class RelatedItems extends AbstractComponent {
} }
return element; return element;
} }
} }