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;
import com.arsdigita.cms.CMSConfig;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.contentassets.RelatedLink;
import com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfiles;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.ui.UI;
import com.arsdigita.xml.Element;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
/**
*
* @author Jens Pelzetter
* @version $Id$
* @version $Id: PublicPersonalProfileXmlUtil.java 4022 2016-04-22 11:39:43Z
* jensp $
*/
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 =
PublicPersonalProfiles.
getConfig();
private final com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfileConfig config
= PublicPersonalProfiles
.getConfig();
public void createNavigation(final PublicPersonalProfile profile,
final Element root,
@ -75,13 +81,11 @@ public class PublicPersonalProfileXmlUtil {
appUrl = String.format("%s/ccm%s", prefix, appPath);
}
final Element navRoot =
root.newChildElement("nav:categoryMenu",
final Element navRoot = root.newChildElement("nav:categoryMenu",
"http://ccm.redhat.com/navigation");
navRoot.addAttribute("id", "categoryMenu");
final Element navList =
navRoot.newChildElement("nav:category",
final Element navList = navRoot.newChildElement("nav:category",
"http://ccm.redhat.com/navigation");
navList.addAttribute("AbstractTree", "AbstractTree");
navList.addAttribute("description", "");
@ -95,10 +99,8 @@ public class PublicPersonalProfileXmlUtil {
navList.addAttribute("url", String.format("/ccm%s",
UI.getConfig().getRootPage()));
if (config.getShowHomeNavEntry()) {
final Element navHome =
navList.newChildElement("nav:category",
final Element navHome = navList.newChildElement("nav:category",
"http://ccm.redhat.com/navigation");
navHome.addAttribute("AbstractTree", "AbstractTree");
navHome.addAttribute("description", "");
@ -118,32 +120,40 @@ public class PublicPersonalProfileXmlUtil {
} else {
navHome.addAttribute("title", homeLabel);
}
if (CMSConfig.getInstanceOf().getUseLanguageExtension()) {
navHome
.addAttribute("url",
String.format("%s/%s/index.%s",
appUrl,
profile.getProfileUrl(),
GlobalizationHelper
.getNegotiatedLocale()
.getLanguage()));
} else {
navHome.addAttribute("url", String.format("%s/%s",
appUrl,
profile.getProfileUrl()));
//navHome.addAttribute("url", String.format("/ccm/%s",
// UI.getConfig().getRootPage()));
profile
.getProfileUrl()));
}
}
//Get the available Navigation items
final PublicPersonalProfileNavItemCollection navItems =
new PublicPersonalProfileNavItemCollection();
final PublicPersonalProfileNavItemCollection navItems
= new PublicPersonalProfileNavItemCollection();
/*navItems.addLanguageFilter(GlobalizationHelper.getNegotiatedLocale().
getLanguage());*/
navItems.addLanguageFilter(profile.getLanguage());
final Map<String, PublicPersonalProfileNavItem> navItemMap =
new LinkedHashMap<String, PublicPersonalProfileNavItem>();
final Map<String, PublicPersonalProfileNavItem> navItemMap
= new LinkedHashMap<String, PublicPersonalProfileNavItem>();
PublicPersonalProfileNavItem navItem;
while (navItems.next()) {
navItem = navItems.getNavItem();
navItemMap.put(navItem.getKey(), navItem);
}
final Element pathElem =
root.newChildElement("nav:categoryPath",
final Element pathElem = root.newChildElement("nav:categoryPath",
"http://ccm.redhat.com/navigation");
final Element homeElem =
pathElem.newChildElement("nav:category",
final Element homeElem = pathElem.newChildElement("nav:category",
"http://ccm.redhat.com/navigation");
//homeElem.addAttribute("url", String.format("%s/%s",
// appUrl,
@ -151,21 +161,21 @@ public class PublicPersonalProfileXmlUtil {
homeElem.addAttribute("url", String.format("/ccm%s",
UI.getConfig().getRootPage()));
final Element profileElem =
pathElem.newChildElement("nav:category",
final Element profileElem = pathElem.newChildElement("nav:category",
"http://ccm.redhat.com/navigation");
profileElem.addAttribute("url", String.format("%s/%s",
appUrl,
profile.getProfileUrl()));
if (profile.getOwner() == null) {
profileElem.addAttribute("title", String.format("Profile %s", profile.getOID().toString()));
profileElem.addAttribute("title", String.format("Profile %s",
profile.getOID()
.toString()));
} else {
profileElem.addAttribute("title", profile.getOwner().getFullName());
}
//Get the related links of the profile
final DataCollection links =
RelatedLink.getRelatedLinks(profile,
final DataCollection links = RelatedLink.getRelatedLinks(profile,
PublicPersonalProfile.LINK_LIST_NAME);
links.addOrder(Link.ORDER);
RelatedLink link;
@ -189,7 +199,8 @@ public class PublicPersonalProfileXmlUtil {
|| (targetItem instanceof ContentPage)) {
final ContentPage targetPage = (ContentPage) targetItem;
if (!(targetPage.getContentBundle().hasInstance(profile.getLanguage(),
if (!(targetPage.getContentBundle().hasInstance(profile
.getLanguage(),
false))) {
LOGGER.warn("No suitable language found. Continuing...\n");
continue;
@ -199,30 +210,44 @@ public class PublicPersonalProfileXmlUtil {
navLinkKey));
navLinks.add(createNavLink(navItem, navLinkKey, targetItem));
} 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);
for (NavLink navLink : navLinks) {
navElem =
navList.newChildElement("nav:category",
navElem = navList.newChildElement("nav:category",
"http://ccm.redhat.com/navigation");
navElem.addAttribute("AbstractTree", "AbstractTree");
navElem.addAttribute("description", "");
//navHome.addAttribute("id", "");
if ((navPath != null) && navPath.equals(navLink.getKey())) {
navElem.addAttribute("isSelected", "true");
final Element currentPathElem =
pathElem.newChildElement("nav:category",
final Element currentPathElem = pathElem.newChildElement(
"nav:category",
"http://ccm.redhat.com/navigation");
currentPathElem.addAttribute("title", navLink.getNavItem().getLabel());
currentPathElem.addAttribute("url",
currentPathElem.addAttribute("title", navLink.getNavItem()
.getLabel());
if (CMSConfig.getInstanceOf().getUseLanguageExtension()) {
currentPathElem.addAttribute(
"url",
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 {
navElem.addAttribute("isSelected", "false");
}
@ -232,10 +257,24 @@ public class PublicPersonalProfileXmlUtil {
} else {
navElem.addAttribute("title", navLink.getNavItem().getLabel());
}
navElem.addAttribute("url", String.format("%s/%s/%s",
if (CMSConfig.getInstanceOf().getUseLanguageExtension()) {
navElem.addAttribute(
"url",
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());
@ -291,4 +330,5 @@ public class PublicPersonalProfileXmlUtil {
}
}
}

View File

@ -28,6 +28,7 @@ import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.CMS;
import com.arsdigita.cms.CMSConfig;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ContentSection;
@ -68,34 +69,38 @@ import com.arsdigita.web.LoginSignal;
import com.arsdigita.web.RedirectSignal;
import com.arsdigita.xml.Document;
import com.arsdigita.xml.Element;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.math.BigDecimal;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import com.arsdigita.cms.ReusableImageAsset;
/**
* Servlet for the PublicPersonalProfile application.
*
* @author Jens Pelzetter
* @version $Id$
* @version $Id: PublicPersonalProfilesServlet.java 3917 2016-03-11 18:59:52Z
* jensp $
*/
public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
private static final long serialVersionUID = -1495852395804455609L;
private static final Logger logger =
Logger.getLogger(
private static final Logger logger = Logger.getLogger(
PublicPersonalProfilesServlet.class);
private static final String ADMIN = "admin";
private static final String PREVIEW = "preview";
private static final String PPP_NS =
"http://www.arsdigita.com/PublicPersonalProfile/1.0";
private static final String PPP_NS
= "http://www.arsdigita.com/PublicPersonalProfile/1.0";
public static final String SELECTED_NAV_ITEM = "selectedNavItem";
private final PublicPersonalProfileConfig config =
PublicPersonalProfiles.getConfig();
private final PublicPersonalProfileConfig config = PublicPersonalProfiles
.getConfig();
@Override
protected void doService(final HttpServletRequest request,
@ -109,6 +114,40 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
logger.debug("Extracting path from pathInfo by removing leading and "
+ "trailing slashes...");
if (CMSConfig.getInstanceOf().getUseLanguageExtension()) {
final String pathInfo = request.getPathInfo();
if (!pathInfo.matches("(.*)/index\\.[a-zA-Z]{2}")) {
final String lang;
if (GlobalizationHelper.getSelectedLocale(request) == null) {
lang = GlobalizationHelper
.getNegotiatedLocale()
.getLanguage();
} else {
lang = GlobalizationHelper
.getSelectedLocale(request)
.getLanguage();
}
final StringBuffer redirectTo = new StringBuffer();
if (DispatcherHelper.getWebappContext() != null
&& !DispatcherHelper.getWebappContext().trim().isEmpty()) {
redirectTo.append(DispatcherHelper.getWebappContext());
}
redirectTo
.append("/ccm")
.append(app.getPath())
.append(pathInfo)
.append("index")
.append(".")
.append(lang);
response.setHeader("Location", redirectTo.toString());
response.sendError(HttpServletResponse.SC_MOVED_PERMANENTLY);
return;
}
}
final String pathStr = getPath(request);
logger.debug(String.format("path = %s", pathStr));
@ -178,19 +217,17 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
if ((item instanceof ContentPage)
&& !(item instanceof PublicPersonalProfile)) {
ContentPage contentPage =
(ContentPage) item;
ContentPage contentPage = (ContentPage) item;
if (contentPage.getContentBundle().hasInstance(profile.
getLanguage(),
false)) {
contentPage =
(ContentPage) contentPage.getContentBundle().
contentPage = (ContentPage) contentPage
.getContentBundle().
getInstance(profile.getLanguage());
item = (ContentItem) contentPage;
} else {
profile =
getProfile(session,
profile = getProfile(session,
path.getProfileOwner(),
path.getPreview(),
GlobalizationHelper.LANG_INDEPENDENT);
@ -208,8 +245,8 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
throw new LoginSignal(request);
} else {
com.arsdigita.cms.SecurityManager securityManager =
Utilities.
com.arsdigita.cms.SecurityManager securityManager
= Utilities.
getSecurityManager(state);
final boolean canEdit = securityManager.canAccess(
@ -219,7 +256,8 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
if (!canEdit) {
throw new AccessDeniedException("user "
+ Kernel.getContext().
+ Kernel
.getContext().
getParty().getOID()
+ " doesn't have the "
+ com.arsdigita.cms.SecurityManager.EDIT_ITEM
@ -250,8 +288,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
throw new RedirectSignal(url, false);
}
Element profileElem =
root.newChildElement("ppp:profile", PPP_NS);
Element profileElem = root.newChildElement("ppp:profile", PPP_NS);
GenericPerson owner = profile.getOwner();
if (owner == null) {
throw new IllegalStateException(
@ -267,13 +304,13 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
getImageAttachments(profile);
if (!images.isEmpty()) {
images.next();
final Element profileImageElem =
profileElem.newChildElement("ppp:profileImage",
final Element profileImageElem = profileElem.newChildElement(
"ppp:profileImage",
PPP_NS);
final Element attachmentElem = profileImageElem.newChildElement(
"imageAttachments");
final ItemImageAttachment attachment =
new ItemImageAttachment(images.
final ItemImageAttachment attachment = new ItemImageAttachment(
images.
getDataObject());
attachmentElem.addAttribute("oid", attachment.getOID().
toString());
@ -281,8 +318,8 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
"caption");
caption.setText(attachment.getCaption());
final ReusableImageAsset image = attachment.getImage();
final Element imageElem =
attachmentElem.newChildElement("image");
final Element imageElem = attachmentElem
.newChildElement("image");
imageElem.addAttribute("oid", image.getOID().toString());
final Element widthElem = imageElem.newChildElement(
"width");
@ -305,10 +342,9 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
images.close();
}
final PublicPersonalProfileXmlUtil util =
new PublicPersonalProfileXmlUtil();
String prefix =
DispatcherHelper.getDispatcherPrefix(request);
final PublicPersonalProfileXmlUtil util
= new PublicPersonalProfileXmlUtil();
String prefix = DispatcherHelper.getDispatcherPrefix(request);
if (prefix == null) {
prefix = "";
}
@ -320,10 +356,12 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
path.getPreview());
if (path.getNavPath() == null) {
final PublicPersonalProfileXmlGenerator generator =
new PublicPersonalProfileXmlGenerator(
final PublicPersonalProfileXmlGenerator generator
= new PublicPersonalProfileXmlGenerator(
profile);
final Element itemRoot = root.newChildElement("nav:greetingItem", "http://ccm.redhat.com/navigation");
final Element itemRoot = root
.newChildElement("nav:greetingItem",
"http://ccm.redhat.com/navigation");
generator.generateXML(state, itemRoot, "");
} else {
if (path.getItemPath() == null) {
@ -438,12 +476,12 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
profiles.addFilter(String.format("version = '%s'",
ContentItem.LIVE));
}*/
DataCollection profiles = getProfiles(session,
profileOwner,
preview,
GlobalizationHelper.
getNegotiatedLocale().getLanguage(),
getNegotiatedLocale()
.getLanguage(),
Kernel.getConfig().
languageIndependentItems());
@ -453,7 +491,6 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
preview,
GlobalizationHelper.LANG_INDEPENDENT);
}*/
if (profiles.size() == 0) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
@ -466,9 +503,9 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
response);
profiles.next();
PublicPersonalProfile profile =
(PublicPersonalProfile) DomainObjectFactory.
newInstance(profiles.getDataObject());
PublicPersonalProfile profile
= (PublicPersonalProfile) DomainObjectFactory
.newInstance(profiles.getDataObject());
profiles.close();
if (preview) {
@ -476,8 +513,8 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
throw new LoginSignal(request);
} else {
com.arsdigita.cms.SecurityManager securityManager =
Utilities.
com.arsdigita.cms.SecurityManager securityManager
= Utilities.
getSecurityManager(state);
final boolean canEdit = securityManager.canAccess(
@ -492,15 +529,16 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
+ " doesn't have the "
+ com.arsdigita.cms.SecurityManager.EDIT_ITEM
+ " privilege on "
+ profile.getOID().
+ profile
.getOID().
toString());
}
}
}
if (config.getEmbedded()) {
final ContentSection section =
profile.getContentSection();
final ContentSection section = profile
.getContentSection();
final ItemResolver resolver = section.getItemResolver();
String context;
@ -519,8 +557,8 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
throw new RedirectSignal(url, false);
}
Element profileElem =
root.newChildElement("ppp:profile", PPP_NS);
Element profileElem = root.newChildElement("ppp:profile",
PPP_NS);
GenericPerson owner = profile.getOwner();
if (owner == null) {
throw new IllegalStateException(
@ -540,8 +578,9 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
final Element attachmentElem = profileImageElem.
newChildElement("imageAttachments");
final ItemImageAttachment attachment =
new ItemImageAttachment(images.
final ItemImageAttachment attachment
= new ItemImageAttachment(
images.
getDataObject());
attachmentElem.addAttribute("oid", attachment.getOID().
toString());
@ -549,8 +588,8 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
"caption");
caption.setText(attachment.getCaption());
final ReusableImageAsset image = attachment.getImage();
final Element imageElem =
attachmentElem.newChildElement("image");
final Element imageElem = attachmentElem
.newChildElement("image");
imageElem.addAttribute("oid", image.getOID().toString());
final Element widthElem = imageElem.newChildElement(
"width");
@ -573,10 +612,10 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
images.close();
}
final PublicPersonalProfileXmlUtil util =
new PublicPersonalProfileXmlUtil();
String prefix =
DispatcherHelper.getDispatcherPrefix(request);
final PublicPersonalProfileXmlUtil util
= new PublicPersonalProfileXmlUtil();
String prefix = DispatcherHelper
.getDispatcherPrefix(request);
if (prefix == null) {
prefix = "";
}
@ -588,15 +627,15 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
preview);
if (navPath == null) {
final PublicPersonalProfileXmlGenerator generator =
new PublicPersonalProfileXmlGenerator(
final PublicPersonalProfileXmlGenerator generator
= new PublicPersonalProfileXmlGenerator(
profile);
generator.generateXML(state, root, "");
} else {
if (itemPath == null) {
final DataCollection links =
RelatedLink.getRelatedLinks(
final DataCollection links = RelatedLink
.getRelatedLinks(
profile,
PublicPersonalProfile.LINK_LIST_NAME);
links.addFilter(String.format("linkTitle = '%s'",
@ -612,8 +651,8 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
state);
}
PublicPersonalProfileNavItemCollection navItems =
new PublicPersonalProfileNavItemCollection();
PublicPersonalProfileNavItemCollection navItems
= new PublicPersonalProfileNavItemCollection();
navItems.addLanguageFilter(GlobalizationHelper.
getNegotiatedLocale().
getLanguage());
@ -623,15 +662,15 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
if (navItems.getNavItem().getGeneratorClass()
!= null) {
try {
Object generatorObj =
Class.forName(navItems.getNavItem().
Object generatorObj = Class.forName(
navItems.getNavItem().
getGeneratorClass()).
getConstructor().
newInstance();
if (generatorObj instanceof ContentGenerator) {
final ContentGenerator generator =
(ContentGenerator) generatorObj;
final ContentGenerator generator
= (ContentGenerator) generatorObj;
generator.generateContent(
profileElem,
@ -669,33 +708,35 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
} else {
links.next();
final RelatedLink link =
(RelatedLink) DomainObjectFactory.
newInstance(links.getDataObject());
final RelatedLink link
= (RelatedLink) DomainObjectFactory
.newInstance(links.getDataObject());
links.close();
ContentItem item =
link.getTargetItem();
ContentItem item = link.getTargetItem();
if (item instanceof ContentPage) {
ContentPage contentPage =
(ContentPage) item;
ContentPage contentPage
= (ContentPage) item;
logger.
error("contentPage.getContentBundle().hasInstance(GlobalizationHelper.getNegotiatedLocale().getLanguage()) = "
error(
"contentPage.getContentBundle().hasInstance(GlobalizationHelper.getNegotiatedLocale().getLanguage()) = "
+ contentPage.
getContentBundle().
hasInstance(GlobalizationHelper.
getNegotiatedLocale().
getLanguage()));
hasInstance(
GlobalizationHelper.
getNegotiatedLocale()
.getLanguage()));
if (contentPage.getContentBundle().
hasInstance(GlobalizationHelper.
getNegotiatedLocale().
getLanguage())) {
contentPage =
(ContentPage) contentPage.
contentPage
= (ContentPage) contentPage.
getContentBundle().
getInstance(GlobalizationHelper.
getNegotiatedLocale().
getLanguage());
getInstance(
GlobalizationHelper.
getNegotiatedLocale()
.getLanguage());
item = (ContentItem) contentPage;
} else {
logger.error(
@ -704,8 +745,8 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
"Item '%s' not found in a suitable language variant. Negotiated langauge: %s, langugage independent items allowed is %s, language independent code is %s ",
itemPath,
GlobalizationHelper.
getNegotiatedLocale().
getLanguage(),
getNegotiatedLocale()
.getLanguage(),
Kernel.getConfig().
languageIndependentItems(),
GlobalizationHelper.LANG_INDEPENDENT));
@ -715,12 +756,11 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
}
}
final Element contentPanelElem = root.
newChildElement("cms:contentPanel",
CMS.CMS_XML_NS);
final PublicPersonalProfileXmlGenerator generator =
new PublicPersonalProfileXmlGenerator(
final PublicPersonalProfileXmlGenerator generator
= new PublicPersonalProfileXmlGenerator(
item);
generator.generateXML(state,
contentPanelElem,
@ -737,22 +777,25 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
final OID itemOid = OID.valueOf(itemPath);
try {
ContentItem item =
(ContentItem) DomainObjectFactory.
newInstance(itemOid);
ContentItem item
= (ContentItem) DomainObjectFactory
.newInstance(itemOid);
if (item instanceof ContentPage) {
ContentPage contentPage = (ContentPage) item;
logger.
error("contentPage.getContentBundle().hasInstance(GlobalizationHelper.getNegotiatedLocale().getLanguage()) = "
error(
"contentPage.getContentBundle().hasInstance(GlobalizationHelper.getNegotiatedLocale().getLanguage()) = "
+ contentPage.getContentBundle().
hasInstance(GlobalizationHelper.
getNegotiatedLocale().getLanguage()));
getNegotiatedLocale()
.getLanguage()));
if (contentPage.getContentBundle().
hasInstance(GlobalizationHelper.
getNegotiatedLocale().getLanguage())) {
contentPage = (ContentPage) contentPage.
getContentBundle().getInstance(GlobalizationHelper.
getContentBundle().getInstance(
GlobalizationHelper.
getNegotiatedLocale().
getLanguage());
item = (ContentItem) contentPage;
@ -774,13 +817,12 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
}
}
final Element contentPanelElem = root.
newChildElement("cms:contentPanel",
CMS.CMS_XML_NS);
final PublicPersonalProfileXmlGenerator generator =
new PublicPersonalProfileXmlGenerator(
final PublicPersonalProfileXmlGenerator generator
= new PublicPersonalProfileXmlGenerator(
item);
generator.generateXML(state,
contentPanelElem,
@ -820,8 +862,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
"profileOwner");
if ((owner.getSurname() != null)
&& !owner.getSurname().trim().isEmpty()) {
Element surname =
profileOwnerElem.newChildElement("surname");
Element surname = profileOwnerElem.newChildElement("surname");
surname.setText(owner.getSurname());
}
if ((owner.getGivenName() != null)
@ -880,8 +921,8 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
final Element contactElem = profileOwnerElem.newChildElement("contact");
final Element entriesElem = contactElem.newChildElement("entries");
final GenericContactEntryCollection entries =
contact.getContactEntries();
final GenericContactEntryCollection entries = contact
.getContactEntries();
Element entryElem;
GenericContactEntry entry;
while (entries.next()) {
@ -922,6 +963,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
* @param page
* @param request
* @param response
*
* @throws ServletException
*/
private void showAdminPage(final Page page,
@ -937,8 +979,8 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
final StringParameter navItemKeyParam = new StringParameter(
"selectedNavItem");
final ParameterSingleSelectionModel navItemSelect =
new ParameterSingleSelectionModel(
final ParameterSingleSelectionModel navItemSelect
= new ParameterSingleSelectionModel(
navItemKeyParam);
page.addGlobalStateParam(navItemKeyParam);
@ -946,11 +988,11 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
final BoxPanel box = new BoxPanel(BoxPanel.VERTICAL);
final FormSection tableSection = new FormSection(box);
final PublicPersonalProfileNavItemsAddForm addForm =
new PublicPersonalProfileNavItemsAddForm(
final PublicPersonalProfileNavItemsAddForm addForm
= new PublicPersonalProfileNavItemsAddForm(
navItemSelect);
final PublicPersonalProfileNavItemsTable table =
new PublicPersonalProfileNavItemsTable(
final PublicPersonalProfileNavItemsTable table
= new PublicPersonalProfileNavItemsTable(
navItemSelect);
box.add(table);
@ -976,8 +1018,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
final Element profileElem,
final PageState state) throws IOException,
ServletException {
final DataCollection links =
RelatedLink.getRelatedLinks(
final DataCollection links = RelatedLink.getRelatedLinks(
profile,
PublicPersonalProfile.LINK_LIST_NAME);
links.addFilter(String.format("linkTitle = '%s'",
@ -993,8 +1034,8 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
generateProfileOwnerXml(profileElem, profile.getOwner(), state);
}
final PublicPersonalProfileNavItemCollection navItems =
new PublicPersonalProfileNavItemCollection();
final PublicPersonalProfileNavItemCollection navItems
= new PublicPersonalProfileNavItemCollection();
navItems.addLanguageFilter(profile.getLanguage());
navItems.addKeyFilter(path.getNavPath());
navItems.next();
@ -1008,8 +1049,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
if ((item instanceof ContentPage)
&& !(item instanceof PublicPersonalProfile)) {
ContentPage contentPage =
(ContentPage) item;
ContentPage contentPage = (ContentPage) item;
/*logger.debug("contentPage.getContentBundle().hasInstance(GlobalizationHelper.getNegotiatedLocale().getLanguage()) = "
+ contentPage.getContentBundle().
hasInstance(GlobalizationHelper.getNegotiatedLocale().
@ -1036,10 +1076,10 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
HttpServletResponse.SC_NOT_FOUND);
return;
}*/
if (contentPage.getContentBundle().hasInstance(profile.getLanguage(),
if (contentPage.getContentBundle()
.hasInstance(profile.getLanguage(),
false)) {
contentPage =
(ContentPage) contentPage.getContentBundle().
contentPage = (ContentPage) contentPage.getContentBundle().
getInstance(profile.getLanguage());
item = (ContentItem) contentPage;
} else {
@ -1048,13 +1088,13 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
return;
}
final Element itemRoot = root.newChildElement("nav:greetingItem", "http://ccm.redhat.com/navigation");
final Element itemRoot = root.newChildElement("nav:greetingItem",
"http://ccm.redhat.com/navigation");
//final Element itemRoot =
// root.newChildElement("cms:contentPanel",
// CMS.CMS_XML_NS);
final PublicPersonalProfileXmlGenerator generator =
new PublicPersonalProfileXmlGenerator(
final PublicPersonalProfileXmlGenerator generator
= new PublicPersonalProfileXmlGenerator(
item);
generator.generateXML(state,
itemRoot,
@ -1063,15 +1103,14 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
if (navItems.getNavItem().getGeneratorClass() != null) {
try {
Object generatorObj =
Class.forName(navItems.getNavItem().
Object generatorObj = Class.forName(navItems.getNavItem().
getGeneratorClass()).
getConstructor().
newInstance();
if (generatorObj instanceof ContentGenerator) {
final ContentGenerator generator =
(ContentGenerator) generatorObj;
final ContentGenerator generator
= (ContentGenerator) generatorObj;
generator.generateContent(profileElem,
profile.getOwner(),
@ -1122,8 +1161,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
final OID itemOid = OID.valueOf(path.getItemPath());
try {
ContentItem item =
(ContentItem) DomainObjectFactory.newInstance(
ContentItem item = (ContentItem) DomainObjectFactory.newInstance(
itemOid);
if (item instanceof ContentPage) {
@ -1164,14 +1202,14 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
}
}
final Element itemRoot = root.newChildElement("nav:greetingItem", "http://ccm.redhat.com/navigation");
final Element itemRoot = root.newChildElement("nav:greetingItem",
"http://ccm.redhat.com/navigation");
//final Element itemRoot =
// root.newChildElement("cms:contentPanel",
// CMS.CMS_XML_NS);
final PublicPersonalProfileXmlGenerator generator =
new PublicPersonalProfileXmlGenerator(
final PublicPersonalProfileXmlGenerator generator
= new PublicPersonalProfileXmlGenerator(
item);
generator.generateXML(state,
itemRoot,
@ -1192,8 +1230,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
final boolean preview,
final String language,
final boolean allowLangIndependent) {
final DataCollection profiles =
session.retrieve(
final DataCollection profiles = session.retrieve(
com.arsdigita.cms.contenttypes.PublicPersonalProfile.BASE_DATA_OBJECT_TYPE);
final FilterFactory filterFactory = profiles.getFilterFactory();
@ -1238,7 +1275,6 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
// } else {
// profiles.addFilter(String.format("language = '%s'", language));
// }
return profiles;
}
@ -1271,9 +1307,9 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
"More than one matching members found.");
} else {
profiles.next();
PublicPersonalProfile profile =
(PublicPersonalProfile) DomainObjectFactory.
newInstance(profiles.getDataObject());
PublicPersonalProfile profile
= (PublicPersonalProfile) DomainObjectFactory
.newInstance(profiles.getDataObject());
profiles.close();
return profile;
@ -1281,26 +1317,36 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
}
private String getPath(final HttpServletRequest request) {
String path = "";
if (request.getPathInfo() != null) {
if ("/".equals(request.getPathInfo())) {
path = "";
} else if (request.getPathInfo().startsWith("/")
&& request.getPathInfo().endsWith("/")) {
path = request.getPathInfo().substring(1, request.getPathInfo().
length() - 1);
} else if (request.getPathInfo().startsWith("/")) {
path = request.getPathInfo().substring(1);
} else if (request.getPathInfo().endsWith("/")) {
path = request.getPathInfo().substring(0, request.getPathInfo().
length() - 1);
} else {
path = request.getPathInfo();
}
String pathInfo = request.getPathInfo();
if (CMSConfig.getInstanceOf().getUseLanguageExtension()
&& pathInfo.matches("(.*)/index\\.[a-zA-Z]{2}")) {
final String lang = pathInfo.substring(pathInfo.length() - 2);
pathInfo = pathInfo
.substring(0, pathInfo.length() - "index.$$".length());
GlobalizationHelper.setSelectedLocale(lang);
}
return path;
if ("/".equals(request.getPathInfo())) {
return "";
} else if (pathInfo.startsWith("/")
&& pathInfo.endsWith("/")) {
return pathInfo.substring(1, pathInfo.
length() - 1);
} else if (pathInfo.startsWith("/")) {
return pathInfo.substring(1);
} else if (pathInfo.endsWith("/")) {
return pathInfo.substring(0, pathInfo.
length() - 1);
} else {
return pathInfo;
}
} else {
return "";
}
}
private class Path {
@ -1371,4 +1417,5 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
}
}
}

View File

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