PublicPersonalProfile jetzt vollständig mehrsprachenfähig
git-svn-id: https://svn.libreccm.org/ccm/trunk@1384 8810af33-2d31-482b-a856-94f89814c4dfmaster
parent
b3b2306ce1
commit
e27f16659d
|
|
@ -15,10 +15,11 @@
|
|||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
|
||||
package com.arsdigita.cms.contenttypes;
|
||||
|
||||
// import com.arsdigita.cms.CMS;
|
||||
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.dispatcher.DispatcherHelper;
|
||||
|
|
@ -38,14 +39,15 @@ import java.util.Map;
|
|||
public class PublicPersonalProfileXmlUtil {
|
||||
|
||||
private final com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfileConfig config =
|
||||
PublicPersonalProfiles.getConfig();
|
||||
PublicPersonalProfiles.
|
||||
getConfig();
|
||||
|
||||
public void createNavigation(final PublicPersonalProfile profile,
|
||||
final Element root,
|
||||
final String navPath,
|
||||
final String prefix,
|
||||
final String appPath,
|
||||
final boolean previewMode) {
|
||||
final Element root,
|
||||
final String navPath,
|
||||
final String prefix,
|
||||
final String appPath,
|
||||
final boolean previewMode) {
|
||||
String homeLabelsStr = config.getHomeNavItemLabels();
|
||||
|
||||
Map<String, String> homeLabels = new HashMap<String, String>();
|
||||
|
|
@ -55,7 +57,7 @@ public class PublicPersonalProfileXmlUtil {
|
|||
homeLabelSplit = homeLabelEntry.split(":");
|
||||
if (homeLabelSplit.length == 2) {
|
||||
homeLabels.put(homeLabelSplit[0].trim(),
|
||||
homeLabelSplit[1].trim());
|
||||
homeLabelSplit[1].trim());
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -70,12 +72,12 @@ public class PublicPersonalProfileXmlUtil {
|
|||
|
||||
Element navRoot =
|
||||
root.newChildElement("nav:categoryMenu",
|
||||
"http://ccm.redhat.com/navigation");
|
||||
"http://ccm.redhat.com/navigation");
|
||||
navRoot.addAttribute("id", "categoryMenu");
|
||||
|
||||
Element navList =
|
||||
navRoot.newChildElement("nav:category",
|
||||
"http://ccm.redhat.com/navigation");
|
||||
"http://ccm.redhat.com/navigation");
|
||||
navList.addAttribute("AbstractTree", "AbstractTree");
|
||||
navList.addAttribute("description", "");
|
||||
navList.addAttribute("id", "");
|
||||
|
|
@ -86,13 +88,13 @@ public class PublicPersonalProfileXmlUtil {
|
|||
appUrl,
|
||||
profile.getProfileUrl()));*/
|
||||
navList.addAttribute("url", String.format("/ccm/%s",
|
||||
UI.getConfig().getRootPage()));
|
||||
UI.getConfig().getRootPage()));
|
||||
|
||||
|
||||
if (config.getShowHomeNavEntry()) {
|
||||
Element navHome =
|
||||
navList.newChildElement("nav:category",
|
||||
"http://ccm.redhat.com/navigation");
|
||||
"http://ccm.redhat.com/navigation");
|
||||
navHome.addAttribute("AbstractTree", "AbstractTree");
|
||||
navHome.addAttribute("description", "");
|
||||
navHome.addAttribute("id", profile.getID().toString());
|
||||
|
|
@ -103,26 +105,27 @@ public class PublicPersonalProfileXmlUtil {
|
|||
}
|
||||
navHome.addAttribute("sortKey", "");
|
||||
|
||||
String homeLabel = homeLabels.get(GlobalizationHelper.getNegotiatedLocale().getLanguage());
|
||||
String homeLabel = homeLabels.get(GlobalizationHelper.
|
||||
getNegotiatedLocale().getLanguage());
|
||||
if (homeLabel == null) {
|
||||
navHome.addAttribute("title", "Home");
|
||||
} else {
|
||||
navHome.addAttribute("title", homeLabel);
|
||||
}
|
||||
navHome.addAttribute("url", String.format("%s/%s",
|
||||
appUrl,
|
||||
profile.getProfileUrl()));
|
||||
appUrl,
|
||||
profile.getProfileUrl()));
|
||||
//navHome.addAttribute("url", String.format("/ccm/%s",
|
||||
// UI.getConfig().getRootPage()));
|
||||
}
|
||||
|
||||
//Get the available Navigation items
|
||||
PublicPersonalProfileNavItemCollection navItems =
|
||||
new PublicPersonalProfileNavItemCollection();
|
||||
new PublicPersonalProfileNavItemCollection();
|
||||
navItems.addLanguageFilter(GlobalizationHelper.getNegotiatedLocale().
|
||||
getLanguage());
|
||||
final Map<String, PublicPersonalProfileNavItem> navItemMap =
|
||||
new HashMap<String, PublicPersonalProfileNavItem>();
|
||||
new HashMap<String, PublicPersonalProfileNavItem>();
|
||||
PublicPersonalProfileNavItem navItem;
|
||||
while (navItems.next()) {
|
||||
navItem = navItems.getNavItem();
|
||||
|
|
@ -130,34 +133,36 @@ public class PublicPersonalProfileXmlUtil {
|
|||
}
|
||||
|
||||
final Element pathElem =
|
||||
root.newChildElement("nav:categoryPath",
|
||||
"http://ccm.redhat.com/navigation");
|
||||
root.newChildElement("nav:categoryPath",
|
||||
"http://ccm.redhat.com/navigation");
|
||||
final Element homeElem =
|
||||
pathElem.newChildElement("nav:category",
|
||||
"http://ccm.redhat.com/navigation");
|
||||
pathElem.newChildElement("nav:category",
|
||||
"http://ccm.redhat.com/navigation");
|
||||
//homeElem.addAttribute("url", String.format("%s/%s",
|
||||
// appUrl,
|
||||
// profile.getProfileUrl()));
|
||||
homeElem.addAttribute("url", String.format("/ccm/%s",
|
||||
UI.getConfig().getRootPage()));
|
||||
UI.getConfig().getRootPage()));
|
||||
|
||||
final Element profileElem = pathElem.newChildElement("nav:category",
|
||||
"http://ccm.redhat.com/navigation");
|
||||
final Element profileElem =
|
||||
pathElem.newChildElement("nav:category",
|
||||
"http://ccm.redhat.com/navigation");
|
||||
profileElem.addAttribute("url", String.format("%s/%s",
|
||||
appUrl,
|
||||
profile.getProfileUrl()));
|
||||
appUrl,
|
||||
profile.getProfileUrl()));
|
||||
profileElem.addAttribute("title", profile.getOwner().getFullName());
|
||||
|
||||
//Get the related links of the profiles
|
||||
DataCollection links =
|
||||
RelatedLink.getRelatedLinks(profile,
|
||||
PublicPersonalProfile.LINK_LIST_NAME);
|
||||
RelatedLink.getRelatedLinks(profile,
|
||||
PublicPersonalProfile.LINK_LIST_NAME);
|
||||
links.addOrder(Link.ORDER);
|
||||
RelatedLink link;
|
||||
String navLinkKey;
|
||||
Element navElem;
|
||||
while (links.next()) {
|
||||
link = (RelatedLink) DomainObjectFactory.newInstance(links.getDataObject());
|
||||
link = (RelatedLink) DomainObjectFactory.newInstance(links.
|
||||
getDataObject());
|
||||
|
||||
navLinkKey = link.getTitle();
|
||||
navItem = navItemMap.get(navLinkKey);
|
||||
|
|
@ -166,23 +171,34 @@ public class PublicPersonalProfileXmlUtil {
|
|||
//ToDo
|
||||
}
|
||||
|
||||
ContentItem targetItem = link.getTargetItem();
|
||||
if (!(targetItem instanceof PublicPersonalProfile)
|
||||
&& (targetItem instanceof ContentPage)) {
|
||||
ContentPage targetPage = (ContentPage) targetItem;
|
||||
if (!(targetPage.getContentBundle().hasInstance(GlobalizationHelper.
|
||||
getNegotiatedLocale().getLanguage(),
|
||||
false))) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
navElem =
|
||||
navList.newChildElement("nav:category",
|
||||
"http://ccm.redhat.com/navigation");
|
||||
navList.newChildElement("nav:category",
|
||||
"http://ccm.redhat.com/navigation");
|
||||
navElem.addAttribute("AbstractTree", "AbstractTree");
|
||||
navElem.addAttribute("description", "");
|
||||
//navHome.addAttribute("id", "");
|
||||
if ((navPath != null) && navPath.equals(navLinkKey)) {
|
||||
navElem.addAttribute("isSelected", "true");
|
||||
final Element currentPathElem =
|
||||
pathElem.newChildElement("nav:category",
|
||||
"http://ccm.redhat.com/navigation");
|
||||
pathElem.newChildElement("nav:category",
|
||||
"http://ccm.redhat.com/navigation");
|
||||
currentPathElem.addAttribute("title", navItem.getLabel());
|
||||
currentPathElem.addAttribute("url",
|
||||
String.format("%s/%s/%s",
|
||||
appUrl,
|
||||
profile.getProfileUrl(),
|
||||
navLinkKey));
|
||||
String.format("%s/%s/%s",
|
||||
appUrl,
|
||||
profile.getProfileUrl(),
|
||||
navLinkKey));
|
||||
} else {
|
||||
navElem.addAttribute("isSelected", "false");
|
||||
}
|
||||
|
|
@ -193,9 +209,9 @@ public class PublicPersonalProfileXmlUtil {
|
|||
navElem.addAttribute("title", navItem.getLabel());
|
||||
}
|
||||
navElem.addAttribute("url", String.format("%s/%s/%s",
|
||||
appUrl,
|
||||
profile.getProfileUrl(),
|
||||
navLinkKey));
|
||||
appUrl,
|
||||
profile.getProfileUrl(),
|
||||
navLinkKey));
|
||||
|
||||
navElem.addAttribute("navItem", navLinkKey);
|
||||
|
||||
|
|
|
|||
|
|
@ -236,6 +236,6 @@ public class PublicPersonalProfileCreate extends PageCreate {
|
|||
String.format("version = '%s'", ContentItem.DRAFT));
|
||||
}
|
||||
|
||||
return profileUrl;
|
||||
return GenericPerson.urlSave(profileUrl).toLowerCase();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
import com.arsdigita.cms.CMS;
|
||||
import com.arsdigita.cms.ContentItem;
|
||||
import com.arsdigita.cms.ContentPage;
|
||||
import com.arsdigita.cms.ContentSection;
|
||||
import com.arsdigita.cms.ReusableImageAsset;
|
||||
import com.arsdigita.cms.contentassets.ItemImageAttachment;
|
||||
|
|
@ -162,17 +163,30 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
|||
|
||||
final Session session = SessionManager.getSession();
|
||||
|
||||
DataCollection profiles =
|
||||
session.retrieve(
|
||||
com.arsdigita.cms.contenttypes.PublicPersonalProfile.BASE_DATA_OBJECT_TYPE);
|
||||
/*DataCollection profiles =
|
||||
session.retrieve(
|
||||
com.arsdigita.cms.contenttypes.PublicPersonalProfile.BASE_DATA_OBJECT_TYPE);
|
||||
profiles.addFilter(String.format("profileUrl = '%s'",
|
||||
profileOwner));
|
||||
profileOwner));
|
||||
if (preview) {
|
||||
profiles.addFilter(String.format("version = '%s'",
|
||||
ContentItem.DRAFT));
|
||||
profiles.addFilter(String.format("version = '%s'",
|
||||
ContentItem.DRAFT));
|
||||
} else {
|
||||
profiles.addFilter(String.format("version = '%s'",
|
||||
ContentItem.LIVE));
|
||||
profiles.addFilter(String.format("version = '%s'",
|
||||
ContentItem.LIVE));
|
||||
}*/
|
||||
|
||||
DataCollection profiles = getProfiles(session,
|
||||
profileOwner,
|
||||
preview,
|
||||
GlobalizationHelper.
|
||||
getNegotiatedLocale().getLanguage());
|
||||
|
||||
if (profiles.isEmpty()) {
|
||||
profiles = getProfiles(session,
|
||||
profileOwner,
|
||||
preview,
|
||||
GlobalizationHelper.LANG_INDEPENDENT);
|
||||
}
|
||||
|
||||
if (profiles.size() == 0) {
|
||||
|
|
@ -207,13 +221,14 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
|||
profile);
|
||||
|
||||
if (!canEdit) {
|
||||
throw new AccessDeniedException("user " + Kernel.
|
||||
getContext().getParty().getOID()
|
||||
+ " doesn't have the "
|
||||
+ com.arsdigita.cms.SecurityManager.EDIT_ITEM
|
||||
+ " privilege on "
|
||||
+ profile.getOID().
|
||||
toString());
|
||||
throw new AccessDeniedException("user "
|
||||
+ Kernel.
|
||||
getContext().getParty().getOID()
|
||||
+ " doesn't have the "
|
||||
+ com.arsdigita.cms.SecurityManager.EDIT_ITEM
|
||||
+ " privilege on "
|
||||
+ profile.getOID().
|
||||
toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -392,8 +407,47 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
|||
(RelatedLink) DomainObjectFactory.
|
||||
newInstance(links.getDataObject());
|
||||
links.close();
|
||||
final ContentItem item =
|
||||
link.getTargetItem();
|
||||
ContentItem item =
|
||||
link.getTargetItem();
|
||||
|
||||
if (item instanceof ContentPage) {
|
||||
ContentPage contentPage =
|
||||
(ContentPage) item;
|
||||
logger.error("contentPage.getContentBundle().hasInstance(GlobalizationHelper.getNegotiatedLocale().getLanguage()) = "
|
||||
+ contentPage.
|
||||
getContentBundle().
|
||||
hasInstance(GlobalizationHelper.
|
||||
getNegotiatedLocale().
|
||||
getLanguage()));
|
||||
if (contentPage.getContentBundle().
|
||||
hasInstance(GlobalizationHelper.
|
||||
getNegotiatedLocale().
|
||||
getLanguage())) {
|
||||
contentPage =
|
||||
(ContentPage) contentPage.
|
||||
getContentBundle().
|
||||
getInstance(GlobalizationHelper.
|
||||
getNegotiatedLocale().
|
||||
getLanguage());
|
||||
item = (ContentItem) contentPage;
|
||||
} else {
|
||||
logger.error(
|
||||
String.format(
|
||||
"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(),
|
||||
Kernel.getConfig().
|
||||
languageIndependentItems(),
|
||||
GlobalizationHelper.LANG_INDEPENDENT));
|
||||
response.setStatus(
|
||||
HttpServletResponse.SC_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final Element contentPanelElem = root.
|
||||
newChildElement("cms:contentPanel",
|
||||
CMS.CMS_XML_NS);
|
||||
|
|
@ -415,10 +469,42 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
|||
|
||||
final OID itemOid = OID.valueOf(itemPath);
|
||||
try {
|
||||
final ContentItem item =
|
||||
(ContentItem) DomainObjectFactory.
|
||||
ContentItem item =
|
||||
(ContentItem) DomainObjectFactory.
|
||||
newInstance(itemOid);
|
||||
|
||||
if (item instanceof ContentPage) {
|
||||
ContentPage contentPage = (ContentPage) item;
|
||||
logger.error("contentPage.getContentBundle().hasInstance(GlobalizationHelper.getNegotiatedLocale().getLanguage()) = "
|
||||
+ contentPage.getContentBundle().
|
||||
hasInstance(GlobalizationHelper.
|
||||
getNegotiatedLocale().getLanguage()));
|
||||
if (contentPage.getContentBundle().
|
||||
hasInstance(GlobalizationHelper.
|
||||
getNegotiatedLocale().getLanguage())) {
|
||||
contentPage = (ContentPage) contentPage.
|
||||
getContentBundle().getInstance(GlobalizationHelper.
|
||||
getNegotiatedLocale().
|
||||
getLanguage());
|
||||
item = (ContentItem) contentPage;
|
||||
} else {
|
||||
logger.error(
|
||||
String.format(
|
||||
"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(),
|
||||
Kernel.getConfig().
|
||||
languageIndependentItems(),
|
||||
GlobalizationHelper.LANG_INDEPENDENT));
|
||||
response.setStatus(
|
||||
HttpServletResponse.SC_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final Element contentPanelElem = root.
|
||||
newChildElement("cms:contentPanel",
|
||||
CMS.CMS_XML_NS);
|
||||
|
|
@ -608,4 +694,26 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
|
|||
presentationManager.servePage(document, request, response);
|
||||
|
||||
}
|
||||
|
||||
private DataCollection getProfiles(final Session session,
|
||||
final String profileOwner,
|
||||
final boolean preview,
|
||||
final String language) {
|
||||
DataCollection profiles =
|
||||
session.retrieve(
|
||||
com.arsdigita.cms.contenttypes.PublicPersonalProfile.BASE_DATA_OBJECT_TYPE);
|
||||
profiles.addFilter(String.format("profileUrl = '%s'",
|
||||
profileOwner));
|
||||
if (preview) {
|
||||
profiles.addFilter(String.format("version = '%s'",
|
||||
ContentItem.DRAFT));
|
||||
} else {
|
||||
profiles.addFilter(String.format("version = '%s'",
|
||||
ContentItem.LIVE));
|
||||
}
|
||||
|
||||
profiles.addFilter(String.format("language = '%s'", language));
|
||||
|
||||
return profiles;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -248,7 +248,7 @@ public class GenericPerson extends ContentPage implements
|
|||
}
|
||||
|
||||
// Replace all special chars that are not yet replaced with a dash
|
||||
return out.replaceAll("[^A-Za-z0-9-]", "_");
|
||||
return out.replaceAll("[^A-Za-z0-9-]", "_").toLowerCase();
|
||||
}
|
||||
|
||||
return in;
|
||||
|
|
|
|||
Loading…
Reference in New Issue