From e27f16659d2434b77da85a573511ad0808096902 Mon Sep 17 00:00:00 2001 From: jensp Date: Tue, 20 Dec 2011 18:07:11 +0000 Subject: [PATCH] =?UTF-8?q?PublicPersonalProfile=20jetzt=20vollst=C3=A4ndi?= =?UTF-8?q?g=20mehrsprachenf=C3=A4hig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: https://svn.libreccm.org/ccm/trunk@1384 8810af33-2d31-482b-a856-94f89814c4df --- .../PublicPersonalProfileXmlUtil.java | 96 ++++++----- .../ui/PublicPersonalProfileCreate.java | 2 +- .../PublicPersonalProfilesServlet.java | 150 +++++++++++++++--- .../cms/contenttypes/GenericPerson.java | 2 +- 4 files changed, 187 insertions(+), 63 deletions(-) diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileXmlUtil.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileXmlUtil.java index 1ca537ae9..46aba275b 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileXmlUtil.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileXmlUtil.java @@ -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 homeLabels = new HashMap(); @@ -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 navItemMap = - new HashMap(); + new HashMap(); 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); diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileCreate.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileCreate.java index ee19c5e88..fa3303dc0 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileCreate.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/ui/PublicPersonalProfileCreate.java @@ -236,6 +236,6 @@ public class PublicPersonalProfileCreate extends PageCreate { String.format("version = '%s'", ContentItem.DRAFT)); } - return profileUrl; + return GenericPerson.urlSave(profileUrl).toLowerCase(); } } diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/PublicPersonalProfilesServlet.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/PublicPersonalProfilesServlet.java index 9f0b4879a..d2155c576 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/PublicPersonalProfilesServlet.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/PublicPersonalProfilesServlet.java @@ -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) { @@ -200,24 +214,25 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet { com.arsdigita.cms.SecurityManager securityManager = Utilities. getSecurityManager(state); - + final boolean canEdit = securityManager.canAccess( state.getRequest(), com.arsdigita.cms.SecurityManager.PREVIEW_PAGES, 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()); } } } - + if (config.getEmbedded()) { final ContentSection section = profile.getContentSection(); @@ -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; + } } diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericPerson.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericPerson.java index 5c79e00ec..2f8c46a18 100644 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericPerson.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/GenericPerson.java @@ -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;