diff --git a/ccm-cms-publicpersonalprofile/src/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/PublicPersonalProfile.xml b/ccm-cms-publicpersonalprofile/src/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/PublicPersonalProfile.xml index 2baf7cb0b..624010723 100644 --- a/ccm-cms-publicpersonalprofile/src/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/PublicPersonalProfile.xml +++ b/ccm-cms-publicpersonalprofile/src/WEB-INF/traversal-adapters/com/arsdigita/cms/contenttypes/PublicPersonalProfile.xml @@ -17,7 +17,8 @@ - + + diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfile.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfile.java index 42c2c0c35..6e2c92eca 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfile.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfile.java @@ -1,6 +1,7 @@ package com.arsdigita.cms.contenttypes; import com.arsdigita.cms.ContentPage; +import com.arsdigita.cms.ExtraXMLGenerator; import com.arsdigita.domain.DataObjectNotFoundException; import java.math.BigDecimal; import com.arsdigita.persistence.OID; @@ -8,6 +9,7 @@ import com.arsdigita.persistence.DataObject; import com.arsdigita.persistence.DataCollection; import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.util.Assert; +import java.util.List; /** * @@ -81,4 +83,13 @@ public class PublicPersonalProfile extends ContentPage { public void setProfileUrl(String profileUrl) { set(PROFILE_URL, profileUrl); } + + @Override + public List getExtraXMLGenerators() { + final List generators = super.getExtraXMLGenerators(); + + generators.add(new PublicPersonalProfileExtraXmlGenerator()); + + return generators; + } } diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileExtraXmlGenerator.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileExtraXmlGenerator.java new file mode 100644 index 000000000..bbcc523bc --- /dev/null +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileExtraXmlGenerator.java @@ -0,0 +1,128 @@ +package com.arsdigita.cms.contenttypes; + +import com.arsdigita.bebop.Page; +import com.arsdigita.bebop.PageState; +import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.ExtraXMLGenerator; +import com.arsdigita.cms.contentassets.RelatedLink; +import com.arsdigita.cms.publicpersonalprofile.ContentGenerator; +import com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfileXmlGenerator; +import com.arsdigita.dispatcher.DispatcherHelper; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.util.UncheckedWrapperException; +import com.arsdigita.xml.Element; +import java.lang.reflect.InvocationTargetException; + +/** + * Generates the extra XML output for a profile for the embedded view. + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class PublicPersonalProfileExtraXmlGenerator implements ExtraXMLGenerator { + + public static final String SHOW_ITEM_PARAM = "showItem"; + + public void generateXML(final ContentItem item, + final Element element, + final PageState state) { + if (!(item instanceof PublicPersonalProfile)) { + throw new IllegalArgumentException( + "PublicPersonalProfileExtraXMLGenerator can only process PublicPersonalProfile Items"); + } + + final PublicPersonalProfile profile = (PublicPersonalProfile) item; + final String showItem = state.getRequest().getParameter(SHOW_ITEM_PARAM); + + final Element navigation = element.newChildElement("profileNavigation"); + final PublicPersonalProfileXmlUtil util = + new PublicPersonalProfileXmlUtil(); + util.createNavigation(profile, navigation, showItem); + + if ((showItem != null) && !showItem.trim().isEmpty()) { + final Element profileContent = element.newChildElement( + "profileContent"); + + final DataCollection links = + RelatedLink.getRelatedLinks(profile, + PublicPersonalProfile.LINK_LIST_NAME); + links.addFilter(String.format("linkTitle = '%s'", + showItem)); + + if (links.size() == 0) { + profileContent.newChildElement( + "notFound"); + } else { + PublicPersonalProfileNavItemCollection navItems = + new PublicPersonalProfileNavItemCollection(); + navItems.addLanguageFilter(DispatcherHelper.getNegotiatedLocale(). + getLanguage()); + navItems.addKeyFilter(showItem); + navItems.next(); + + if (navItems.getNavItem().getGeneratorClass() + != null) { + try { + Object generatorObj = + Class.forName(navItems.getNavItem(). + getGeneratorClass()).getConstructor(). + newInstance(); + + if (generatorObj instanceof ContentGenerator) { + final ContentGenerator generator = + (ContentGenerator) generatorObj; + + generator.generateContent(profileContent, profile. + getOwner()); + + } else { + throw new UncheckedWrapperException(String.format( + "Class '%s' is not a ContentGenerator.", + navItems.getNavItem(). + getGeneratorClass())); + } + + } catch (InstantiationException ex) { + throw new UncheckedWrapperException( + "Failed to create generator", ex); + } catch (IllegalAccessException ex) { + throw new UncheckedWrapperException( + "Failed to create generator", ex); + } catch (IllegalArgumentException ex) { + throw new UncheckedWrapperException( + "Failed to create generator", ex); + } catch (InvocationTargetException ex) { + throw new UncheckedWrapperException( + "Failed to create generator", ex); + } catch (ClassNotFoundException ex) { + throw new UncheckedWrapperException( + "Failed to create generator", ex); + } catch (NoSuchMethodException ex) { + throw new UncheckedWrapperException( + "Failed to create generator", ex); + } + } else { + + links.next(); + final RelatedLink link = + (RelatedLink) DomainObjectFactory. + newInstance(links.getDataObject()); + final ContentItem targetItem = link.getTargetItem(); + final PublicPersonalProfileXmlGenerator generator = + new PublicPersonalProfileXmlGenerator( + targetItem); + generator.generateXML(state, + profileContent, + ""); + } + + navItems.close(); + } + } + } + + public void addGlobalStateParams(final Page p) { + //Nothing yet + } +} diff --git a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileXmlUtil.java b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileXmlUtil.java new file mode 100644 index 000000000..a01fbdcf9 --- /dev/null +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/contenttypes/PublicPersonalProfileXmlUtil.java @@ -0,0 +1,137 @@ +package com.arsdigita.cms.contenttypes; + +import com.arsdigita.cms.contentassets.RelatedLink; +import com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfiles; +import com.arsdigita.dispatcher.DispatcherHelper; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.persistence.DataCollection; +import com.arsdigita.xml.Element; +import java.util.HashMap; +import java.util.Map; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +public class PublicPersonalProfileXmlUtil { + + private final com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfileConfig config = + PublicPersonalProfiles. + getConfig(); + + public void createNavigation(final PublicPersonalProfile profile, + final Element root, + final String navPath) { + String homeLabelsStr = config.getHomeNavItemLabels(); + + Map homeLabels = new HashMap(); + String[] homeLabelsArry = homeLabelsStr.split(","); + String[] homeLabelSplit; + for (String homeLabelEntry : homeLabelsArry) { + homeLabelSplit = homeLabelEntry.split(":"); + if (homeLabelSplit.length == 2) { + homeLabels.put(homeLabelSplit[0].trim(), + homeLabelSplit[1].trim()); + } else { + continue; + } + } + + Element navRoot = + root.newChildElement("nav:categoryMenu", + "http://ccm.redhat.com/london/navigation"); + navRoot.addAttribute("id", "categoryMenu"); + + Element navList = + navRoot.newChildElement("nav:category", + "http://ccm.redhat.com/london/navigation"); + navList.addAttribute("AbstractTree", "AbstractTree"); + navList.addAttribute("description", ""); + navList.addAttribute("id", ""); + navList.addAttribute("isSelected", "true"); + navList.addAttribute("sortKey", ""); + navList.addAttribute("title", "publicPersonalProfileNavList"); + navList.addAttribute("url", String.format("/ccm/%s", + profile.getProfileUrl())); + + Element navHome = + navList.newChildElement("nav:category", + "http://ccm.redhat.com/london/navigation"); + navHome.addAttribute("AbstractTree", "AbstractTree"); + navHome.addAttribute("description", ""); + navHome.addAttribute("id", profile.getID().toString()); + if (navPath == null) { + navHome.addAttribute("isSelected", "true"); + } else { + navHome.addAttribute("isSelected", "false"); + } + navHome.addAttribute("sortKey", ""); + String homeLabel = homeLabels.get(DispatcherHelper.getNegotiatedLocale(). + getLanguage()); + if (homeLabel == null) { + navHome.addAttribute("title", "Home"); + } else { + navHome.addAttribute("title", homeLabel); + } + navHome.addAttribute("url", String.format("/ccm/profiles/%s", + profile.getProfileUrl())); + + //Get the available Navigation items + PublicPersonalProfileNavItemCollection navItems = + new PublicPersonalProfileNavItemCollection(); + navItems.addLanguageFilter(DispatcherHelper.getNegotiatedLocale(). + getLanguage()); + final Map navItemMap = + new HashMap(); + PublicPersonalProfileNavItem navItem; + while (navItems.next()) { + navItem = navItems.getNavItem(); + navItemMap.put(navItem.getKey(), navItem); + } + + //Get the related links of the profiles + DataCollection links = + 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()); + + navLinkKey = link.getTitle(); + navItem = navItemMap.get(navLinkKey); + + if (navItem == null) { + //ToDo + } + + navElem = + navList.newChildElement("nav:category", + "http://ccm.redhat.com/london/navigation"); + navElem.addAttribute("AbstractTree", "AbstractTree"); + navElem.addAttribute("description", ""); + //navHome.addAttribute("id", ""); + if ((navPath != null) && navPath.equals(navLinkKey)) { + navElem.addAttribute("isSelected", "true"); + } else { + navElem.addAttribute("isSelected", "false"); + } + navElem.addAttribute("sortKey", ""); + if (navItem == null) { + navElem.addAttribute("title", navLinkKey); + } else { + navElem.addAttribute("title", navItem.getLabel()); + } + navElem.addAttribute("url", String.format("/ccm/profiles/%s/%s", + profile.getProfileUrl(), + navLinkKey)); + + navElem.addAttribute("navItem", navLinkKey); + + } + } +} 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 d5e3d1100..931dc06e1 100644 --- a/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/PublicPersonalProfilesServlet.java +++ b/ccm-cms-publicpersonalprofile/src/com/arsdigita/cms/publicpersonalprofile/PublicPersonalProfilesServlet.java @@ -17,10 +17,9 @@ import com.arsdigita.cms.contenttypes.GenericContactEntry; import com.arsdigita.cms.contenttypes.GenericContactEntryCollection; import com.arsdigita.cms.contenttypes.GenericPerson; import com.arsdigita.cms.contenttypes.GenericPersonContactCollection; -import com.arsdigita.cms.contenttypes.Link; import com.arsdigita.cms.contenttypes.PublicPersonalProfile; -import com.arsdigita.cms.contenttypes.PublicPersonalProfileNavItem; import com.arsdigita.cms.contenttypes.PublicPersonalProfileNavItemCollection; +import com.arsdigita.cms.contenttypes.PublicPersonalProfileXmlUtil; import com.arsdigita.cms.publicpersonalprofile.ui.PublicPersonalProfileNavItemsAddForm; import com.arsdigita.dispatcher.DispatcherHelper; import com.arsdigita.domain.DomainObjectFactory; @@ -39,8 +38,6 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.math.BigDecimal; import java.rmi.ServerException; -import java.util.HashMap; -import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -183,7 +180,8 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet { "ppp:ownerName", PPP_NS); profileOwnerName.setText(owner.getFullName()); - createNavigation(profile, root, navPath); + final PublicPersonalProfileXmlUtil util = new PublicPersonalProfileXmlUtil(); + util.createNavigation(profile, root, navPath); if (navPath == null) { final PublicPersonalProfileXmlGenerator generator = @@ -241,7 +239,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet { generator.generateContent(root, owner); } else { - throw new ServerException(String.format( + throw new ServletException(String.format( "Class '%s' is not a ContentGenerator.", navItems.getNavItem(). getGeneratorClass())); @@ -295,7 +293,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet { } - private void createNavigation(final PublicPersonalProfile profile, + /*private void createNavigation(final PublicPersonalProfile profile, final Element root, final String navPath) { String homeLabelsStr = config.getHomeNavItemLabels(); @@ -406,7 +404,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet { navLinkKey)); } - } + }*/ private void generateProfileOwnerXml(final Element profileElem, final GenericPerson owner,