Generate URLs with Language extension if CMSConfig#useLanguageExtension is set to true

git-svn-id: https://svn.libreccm.org/ccm/trunk@4921 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2017-08-25 16:41:34 +00:00
parent 9b80ee7a9e
commit d44d86c958
3 changed files with 479 additions and 381 deletions

View File

@ -18,34 +18,40 @@
*/ */
package com.arsdigita.cms.contenttypes; package com.arsdigita.cms.contenttypes;
import com.arsdigita.cms.CMSConfig;
import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentPage; import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.contentassets.RelatedLink; import com.arsdigita.cms.contentassets.RelatedLink;
import com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfiles; import com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfiles;
import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataCollection;
import com.arsdigita.ui.UI; import com.arsdigita.ui.UI;
import com.arsdigita.xml.Element; import com.arsdigita.xml.Element;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
/** /**
* *
* @author Jens Pelzetter * @author Jens Pelzetter
* @version $Id$ * @version $Id: PublicPersonalProfileXmlUtil.java 4022 2016-04-22 11:39:43Z
* jensp $
*/ */
public class PublicPersonalProfileXmlUtil { public class PublicPersonalProfileXmlUtil {
private static final Logger LOGGER = Logger.getLogger(PublicPersonalProfileXmlUtil.class); private static final Logger LOGGER = Logger.getLogger(
PublicPersonalProfileXmlUtil.class);
private final com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfileConfig config = private final com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfileConfig config
PublicPersonalProfiles. = PublicPersonalProfiles
getConfig(); .getConfig();
public void createNavigation(final PublicPersonalProfile profile, public void createNavigation(final PublicPersonalProfile profile,
final Element root, final Element root,
@ -75,14 +81,12 @@ public class PublicPersonalProfileXmlUtil {
appUrl = String.format("%s/ccm%s", prefix, appPath); appUrl = String.format("%s/ccm%s", prefix, appPath);
} }
final Element navRoot = final Element navRoot = root.newChildElement("nav:categoryMenu",
root.newChildElement("nav:categoryMenu", "http://ccm.redhat.com/navigation");
"http://ccm.redhat.com/navigation");
navRoot.addAttribute("id", "categoryMenu"); navRoot.addAttribute("id", "categoryMenu");
final Element navList = final Element navList = navRoot.newChildElement("nav:category",
navRoot.newChildElement("nav:category", "http://ccm.redhat.com/navigation");
"http://ccm.redhat.com/navigation");
navList.addAttribute("AbstractTree", "AbstractTree"); navList.addAttribute("AbstractTree", "AbstractTree");
navList.addAttribute("description", ""); navList.addAttribute("description", "");
navList.addAttribute("id", ""); navList.addAttribute("id", "");
@ -95,11 +99,9 @@ public class PublicPersonalProfileXmlUtil {
navList.addAttribute("url", String.format("/ccm%s", navList.addAttribute("url", String.format("/ccm%s",
UI.getConfig().getRootPage())); UI.getConfig().getRootPage()));
if (config.getShowHomeNavEntry()) { if (config.getShowHomeNavEntry()) {
final Element navHome = final Element navHome = navList.newChildElement("nav:category",
navList.newChildElement("nav:category", "http://ccm.redhat.com/navigation");
"http://ccm.redhat.com/navigation");
navHome.addAttribute("AbstractTree", "AbstractTree"); navHome.addAttribute("AbstractTree", "AbstractTree");
navHome.addAttribute("description", ""); navHome.addAttribute("description", "");
navHome.addAttribute("id", profile.getID().toString()); navHome.addAttribute("id", profile.getID().toString());
@ -118,55 +120,63 @@ public class PublicPersonalProfileXmlUtil {
} else { } else {
navHome.addAttribute("title", homeLabel); navHome.addAttribute("title", homeLabel);
} }
navHome.addAttribute("url", String.format("%s/%s", if (CMSConfig.getInstanceOf().getUseLanguageExtension()) {
appUrl, navHome
profile.getProfileUrl())); .addAttribute("url",
//navHome.addAttribute("url", String.format("/ccm/%s", String.format("%s/%s/index.%s",
// UI.getConfig().getRootPage())); appUrl,
profile.getProfileUrl(),
GlobalizationHelper
.getNegotiatedLocale()
.getLanguage()));
} else {
navHome.addAttribute("url", String.format("%s/%s",
appUrl,
profile
.getProfileUrl()));
}
} }
//Get the available Navigation items //Get the available Navigation items
final PublicPersonalProfileNavItemCollection navItems = final PublicPersonalProfileNavItemCollection navItems
new PublicPersonalProfileNavItemCollection(); = new PublicPersonalProfileNavItemCollection();
/*navItems.addLanguageFilter(GlobalizationHelper.getNegotiatedLocale(). /*navItems.addLanguageFilter(GlobalizationHelper.getNegotiatedLocale().
getLanguage());*/ getLanguage());*/
navItems.addLanguageFilter(profile.getLanguage()); navItems.addLanguageFilter(profile.getLanguage());
final Map<String, PublicPersonalProfileNavItem> navItemMap = final Map<String, PublicPersonalProfileNavItem> navItemMap
new LinkedHashMap<String, PublicPersonalProfileNavItem>(); = new LinkedHashMap<String, PublicPersonalProfileNavItem>();
PublicPersonalProfileNavItem navItem; PublicPersonalProfileNavItem navItem;
while (navItems.next()) { while (navItems.next()) {
navItem = navItems.getNavItem(); navItem = navItems.getNavItem();
navItemMap.put(navItem.getKey(), navItem); navItemMap.put(navItem.getKey(), navItem);
} }
final Element pathElem = final Element pathElem = root.newChildElement("nav:categoryPath",
root.newChildElement("nav:categoryPath", "http://ccm.redhat.com/navigation");
"http://ccm.redhat.com/navigation"); final Element homeElem = pathElem.newChildElement("nav:category",
final Element homeElem = "http://ccm.redhat.com/navigation");
pathElem.newChildElement("nav:category",
"http://ccm.redhat.com/navigation");
//homeElem.addAttribute("url", String.format("%s/%s", //homeElem.addAttribute("url", String.format("%s/%s",
// appUrl, // appUrl,
// profile.getProfileUrl())); // profile.getProfileUrl()));
homeElem.addAttribute("url", String.format("/ccm%s", homeElem.addAttribute("url", String.format("/ccm%s",
UI.getConfig().getRootPage())); UI.getConfig().getRootPage()));
final Element profileElem = final Element profileElem = pathElem.newChildElement("nav:category",
pathElem.newChildElement("nav:category", "http://ccm.redhat.com/navigation");
"http://ccm.redhat.com/navigation");
profileElem.addAttribute("url", String.format("%s/%s", profileElem.addAttribute("url", String.format("%s/%s",
appUrl, appUrl,
profile.getProfileUrl())); profile.getProfileUrl()));
if (profile.getOwner() == null) { if (profile.getOwner() == null) {
profileElem.addAttribute("title", String.format("Profile %s", profile.getOID().toString())); profileElem.addAttribute("title", String.format("Profile %s",
} else { profile.getOID()
profileElem.addAttribute("title", profile.getOwner().getFullName()); .toString()));
} else {
profileElem.addAttribute("title", profile.getOwner().getFullName());
} }
//Get the related links of the profile //Get the related links of the profile
final DataCollection links = final DataCollection links = RelatedLink.getRelatedLinks(profile,
RelatedLink.getRelatedLinks(profile, PublicPersonalProfile.LINK_LIST_NAME);
PublicPersonalProfile.LINK_LIST_NAME);
links.addOrder(Link.ORDER); links.addOrder(Link.ORDER);
RelatedLink link; RelatedLink link;
String navLinkKey; String navLinkKey;
@ -174,7 +184,7 @@ public class PublicPersonalProfileXmlUtil {
final List<NavLink> navLinks = new ArrayList<NavLink>(); final List<NavLink> navLinks = new ArrayList<NavLink>();
while (links.next()) { while (links.next()) {
link = (RelatedLink) DomainObjectFactory.newInstance(links. link = (RelatedLink) DomainObjectFactory.newInstance(links.
getDataObject()); getDataObject());
navLinkKey = link.getTitle(); navLinkKey = link.getTitle();
navItem = navItemMap.get(navLinkKey); navItem = navItemMap.get(navLinkKey);
@ -186,43 +196,58 @@ public class PublicPersonalProfileXmlUtil {
final ContentItem targetItem = link.getTargetItem(); final ContentItem targetItem = link.getTargetItem();
//System.out.printf("targetItem.getClass.getName: %s\n", targetItem.getClass().getName()); //System.out.printf("targetItem.getClass.getName: %s\n", targetItem.getClass().getName());
if ((targetItem instanceof PublicPersonalProfile) if ((targetItem instanceof PublicPersonalProfile)
|| (targetItem instanceof ContentPage)) { || (targetItem instanceof ContentPage)) {
final ContentPage targetPage = (ContentPage) targetItem; final ContentPage targetPage = (ContentPage) targetItem;
if (!(targetPage.getContentBundle().hasInstance(profile.getLanguage(), if (!(targetPage.getContentBundle().hasInstance(profile
.getLanguage(),
false))) { false))) {
LOGGER.warn("No suitable language found. Continuing...\n"); LOGGER.warn("No suitable language found. Continuing...\n");
continue; continue;
} }
LOGGER.debug(String.format("Creating navigation entry for %s\n", LOGGER.debug(String.format("Creating navigation entry for %s\n",
navLinkKey)); navLinkKey));
navLinks.add(createNavLink(navItem, navLinkKey, targetItem)); navLinks.add(createNavLink(navItem, navLinkKey, targetItem));
} else { } else {
LOGGER.warn("targetItem is not a PublicPersonalProfile and not a content item"); LOGGER.warn(
"targetItem is not a PublicPersonalProfile and not a content item");
} }
} }
Collections.sort(navLinks); Collections.sort(navLinks);
for (NavLink navLink : navLinks) { for (NavLink navLink : navLinks) {
navElem = navElem = navList.newChildElement("nav:category",
navList.newChildElement("nav:category", "http://ccm.redhat.com/navigation");
"http://ccm.redhat.com/navigation");
navElem.addAttribute("AbstractTree", "AbstractTree"); navElem.addAttribute("AbstractTree", "AbstractTree");
navElem.addAttribute("description", ""); navElem.addAttribute("description", "");
//navHome.addAttribute("id", ""); //navHome.addAttribute("id", "");
if ((navPath != null) && navPath.equals(navLink.getKey())) { if ((navPath != null) && navPath.equals(navLink.getKey())) {
navElem.addAttribute("isSelected", "true"); navElem.addAttribute("isSelected", "true");
final Element currentPathElem = final Element currentPathElem = pathElem.newChildElement(
pathElem.newChildElement("nav:category", "nav:category",
"http://ccm.redhat.com/navigation"); "http://ccm.redhat.com/navigation");
currentPathElem.addAttribute("title", navLink.getNavItem().getLabel()); currentPathElem.addAttribute("title", navLink.getNavItem()
currentPathElem.addAttribute("url", .getLabel());
String.format("%s/%s/%s", if (CMSConfig.getInstanceOf().getUseLanguageExtension()) {
appUrl, currentPathElem.addAttribute(
profile.getProfileUrl(), "url",
navLink.getKey())); String.format("%s/%s/%s/index.%s",
appUrl,
profile.getProfileUrl(),
navLink.getKey(),
GlobalizationHelper
.getNegotiatedLocale()
.getLanguage()));
} else {
currentPathElem.addAttribute(
"url",
String.format("%s/%s/%s",
appUrl,
profile.getProfileUrl(),
navLink.getKey()));
}
} else { } else {
navElem.addAttribute("isSelected", "false"); navElem.addAttribute("isSelected", "false");
} }
@ -232,10 +257,24 @@ public class PublicPersonalProfileXmlUtil {
} else { } else {
navElem.addAttribute("title", navLink.getNavItem().getLabel()); navElem.addAttribute("title", navLink.getNavItem().getLabel());
} }
navElem.addAttribute("url", String.format("%s/%s/%s", if (CMSConfig.getInstanceOf().getUseLanguageExtension()) {
appUrl, navElem.addAttribute(
profile.getProfileUrl(), "url",
navLink.getKey())); String.format("%s/%s/%s/index.%s",
appUrl,
profile.getProfileUrl(),
navLink.getKey(),
GlobalizationHelper
.getNegotiatedLocale()
.getLanguage()));
} else {
navElem.addAttribute(
"url",
String.format("%s/%s/%s",
appUrl,
profile.getProfileUrl(),
navLink.getKey()));
}
navElem.addAttribute("navItem", navLink.getKey()); navElem.addAttribute("navItem", navLink.getKey());
@ -291,4 +330,5 @@ public class PublicPersonalProfileXmlUtil {
} }
} }
} }

View File

@ -20,6 +20,8 @@ package com.arsdigita.navigation.ui;
import com.arsdigita.navigation.Navigation; import com.arsdigita.navigation.Navigation;
import com.arsdigita.categorization.Category; import com.arsdigita.categorization.Category;
import com.arsdigita.cms.CMSConfig;
import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.xml.Element; import com.arsdigita.xml.Element;
import com.arsdigita.xml.XML; import com.arsdigita.xml.XML;
@ -62,7 +64,16 @@ public abstract class CategoryComponent extends AbstractComponent {
content.addAttribute("name", urlStub); content.addAttribute("name", urlStub);
} }
content.addAttribute("description", description); content.addAttribute("description", description);
content.addAttribute("url", url); if (CMSConfig.getInstanceOf().getUseLanguageExtension()) {
content.addAttribute("url",
String.format("%sindex.%s",
url,
GlobalizationHelper
.getNegotiatedLocale()
.getLanguage()));
} else {
content.addAttribute("url", url);
}
return content; return content;
} }