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