PublicPersonalProfile: Navigation funktionsfähig, inkl. Anzeige der verknüpften Content-Items

git-svn-id: https://svn.libreccm.org/ccm/trunk@1054 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2011-08-06 19:08:07 +00:00
parent 2474aab6dd
commit 375fa32580
12 changed files with 237 additions and 18 deletions

View File

@ -2,4 +2,6 @@
<registry> <registry>
<config class="com.arsdigita.cms.contenttypes.PublicPersonalProfileConfig" <config class="com.arsdigita.cms.contenttypes.PublicPersonalProfileConfig"
storage="ccm-cms-publicpersonalprofile/profile.properties"/> storage="ccm-cms-publicpersonalprofile/profile.properties"/>
<config class="com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfileConfig"
storage="ccm-cms-publicpersonalprofile/navigation.properties"/>
</registry> </registry>

View File

@ -0,0 +1,30 @@
package com.arsdigita.cms.publicpersonalprofile;
import com.arsdigita.runtime.AbstractConfig;
import com.arsdigita.util.parameter.Parameter;
import com.arsdigita.util.parameter.StringParameter;
/**
*
* @author Jens Pelzetter
* @version $Id$
*/
public class PublicPersonalProfileConfig extends AbstractConfig {
private final Parameter homeNavItemLabels;
public PublicPersonalProfileConfig() {
homeNavItemLabels = new StringParameter(
"com.arsdigita.cms.publicpersonalprofile.navitem.home.labels",
Parameter.REQUIRED,
"en:Home, de:Allgemein");
register(homeNavItemLabels);
loadInfo();
}
public final String getHomeNavItemLabels() {
return (String) get(homeNavItemLabels);
}
}

View File

@ -0,0 +1,5 @@
com.arsdigita.cms.publicpersonalprofile.navitem.home.labels.title = The labels for the home link of a profile
com.arsdigita.cms.publicpersonalprofile.navitem.home.labels.purpose = The labels for the home link of a profile
com.arsdigita.cms.publicpersonalprofile.navitem.home.labels.example = en:Home,de:Start
com.arsdigita.cms.publicpersonalprofile.navitem.home.labels.format = [String]

View File

@ -0,0 +1,25 @@
package com.arsdigita.cms.publicpersonalprofile;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
/**
*
* @author Jens Pelzetter
* @version $Id$
*/
public class PublicPersonalProfileXmlGenerator extends SimpleXMLGenerator {
private ContentItem item;
public PublicPersonalProfileXmlGenerator(final ContentItem item) {
this.item = item;
}
@Override
public ContentItem getContentItem(final PageState state) {
return item;
}
}

View File

@ -15,6 +15,12 @@ public class PublicPersonalProfiles extends Application {
public static final String BASE_DATA_OBJECT_TYPE = public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfile"; "com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfile";
private static PublicPersonalProfileConfig config =
new PublicPersonalProfileConfig();
static {
config.load();
}
public PublicPersonalProfiles(final DataObject dobj) { public PublicPersonalProfiles(final DataObject dobj) {
super(dobj); super(dobj);
@ -30,6 +36,10 @@ public class PublicPersonalProfiles extends Application {
this(new OID(BASE_DATA_OBJECT_TYPE, id)); this(new OID(BASE_DATA_OBJECT_TYPE, id));
} }
public static PublicPersonalProfileConfig getConfig() {
return config;
}
@Override @Override
public String getServletPath() { public String getServletPath() {
return "/profiles/"; return "/profiles/";

View File

@ -1,5 +1,6 @@
package com.arsdigita.cms.publicpersonalprofile; package com.arsdigita.cms.publicpersonalprofile;
import com.arsdigita.cms.contenttypes.PublicPersonalProfileNavItem;
import com.arsdigita.db.DbHelper; import com.arsdigita.db.DbHelper;
import com.arsdigita.domain.DomainObject; import com.arsdigita.domain.DomainObject;
import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.domain.DomainObjectFactory;
@ -34,13 +35,13 @@ public class PublicPersonalProfilesInitializer extends CompoundInitializer {
DomainObjectFactory.registerInstantiator( DomainObjectFactory.registerInstantiator(
PublicPersonalProfiles.BASE_DATA_OBJECT_TYPE, PublicPersonalProfiles.BASE_DATA_OBJECT_TYPE,
new ACSObjectInstantiator() { new ACSObjectInstantiator() {
@Override @Override
public DomainObject doNewInstance( public DomainObject doNewInstance(
final DataObject dataObject) { final DataObject dataObject) {
return new PublicPersonalProfiles(dataObject); return new PublicPersonalProfiles(dataObject);
} }
}); });
} }
} }

View File

@ -1,5 +1,6 @@
package com.arsdigita.cms.publicpersonalprofile; package com.arsdigita.cms.publicpersonalprofile;
import com.arsdigita.cms.contenttypes.PublicPersonalProfileNavItem;
import com.arsdigita.domain.DomainObject; import com.arsdigita.domain.DomainObject;
import com.arsdigita.kernel.ACSObjectInstantiator; import com.arsdigita.kernel.ACSObjectInstantiator;
import com.arsdigita.kernel.Kernel; import com.arsdigita.kernel.Kernel;
@ -73,9 +74,9 @@ public class PublicPersonalProfilesLoader extends PackageLoader {
Application.createApplication( Application.createApplication(
PublicPersonalProfiles.BASE_DATA_OBJECT_TYPE, PublicPersonalProfiles.BASE_DATA_OBJECT_TYPE,
"profiles", "profiles",
"PublicPersonalProfiles", "PublicPersonalProfiles",
null); null);
} }
}.run(); }.run();

View File

@ -2,9 +2,15 @@ package com.arsdigita.cms.publicpersonalprofile;
import com.arsdigita.bebop.Page; import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageFactory; import com.arsdigita.bebop.PageFactory;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.contentassets.RelatedLink;
import com.arsdigita.cms.contenttypes.GenericPerson; import com.arsdigita.cms.contenttypes.GenericPerson;
import com.arsdigita.cms.contenttypes.Link;
import com.arsdigita.cms.contenttypes.PublicPersonalProfile; import com.arsdigita.cms.contenttypes.PublicPersonalProfile;
import com.arsdigita.cms.contenttypes.PublicPersonalProfileNavItem;
import com.arsdigita.cms.contenttypes.PublicPersonalProfileNavItemCollection;
import com.arsdigita.dispatcher.DispatcherHelper;
import com.arsdigita.domain.DomainObjectFactory; import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.persistence.DataCollection; import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.Session; import com.arsdigita.persistence.Session;
@ -16,6 +22,8 @@ import com.arsdigita.web.BaseApplicationServlet;
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.util.HashMap;
import java.util.Map;
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;
@ -82,7 +90,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
Label label;*/ Label label;*/
page = PageFactory.buildPage("PublicPersonalProfile", page = PageFactory.buildPage("PublicPersonalProfile",
"Hello World from profiles"); "");
/*form = new Form("HelloWorld");*/ /*form = new Form("HelloWorld");*/
if (pathTokens.length < 1) { if (pathTokens.length < 1) {
@ -157,7 +165,33 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
} }
profileElem.setText(owner.getFullName()); profileElem.setText(owner.getFullName());
createNavigation(profile, root); createNavigation(profile, root, navPath);
if (navPath == null) {
//ToDo: Show start page.
} else {
final DataCollection links =
RelatedLink.getRelatedLinks(profile,
PublicPersonalProfile.LINK_LIST_NAME);
links.addFilter(String.format("linkTitle = '%s'", navPath));
if (links.size() == 0) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
} else {
links.next();
final RelatedLink link =
(RelatedLink) DomainObjectFactory.
newInstance(links.getDataObject());
final ContentItem item = link.getTargetItem();
final PublicPersonalProfileXmlGenerator generator =
new PublicPersonalProfileXmlGenerator(
item);
generator.generateXML(new PageState(page, request,
response),
root, "");
}
}
} }
@ -171,7 +205,25 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
} }
private void createNavigation(final PublicPersonalProfile profile, private void createNavigation(final PublicPersonalProfile profile,
final Element root) { final Element root,
final String navPath) {
PublicPersonalProfileConfig config = PublicPersonalProfiles.getConfig();
String homeLabelsStr = config.getHomeNavItemLabels();
Map<String, String> homeLabels = new HashMap<String, String>();
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 = Element navRoot =
root.newChildElement("nav:categoryMenu", root.newChildElement("nav:categoryMenu",
"http://ccm.redhat.com/london/navigation"); "http://ccm.redhat.com/london/navigation");
@ -195,11 +247,77 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
navHome.addAttribute("AbstractTree", "AbstractTree"); navHome.addAttribute("AbstractTree", "AbstractTree");
navHome.addAttribute("description", ""); navHome.addAttribute("description", "");
navHome.addAttribute("id", profile.getID().toString()); navHome.addAttribute("id", profile.getID().toString());
navHome.addAttribute("isSelected", "true"); if (navPath == null) {
navHome.addAttribute("isSelected", "true");
} else {
navHome.addAttribute("isSelected", "false");
}
navHome.addAttribute("sortKey", ""); navHome.addAttribute("sortKey", "");
navHome.addAttribute("title", "Allgemein"); 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/%s", navHome.addAttribute("url", String.format("/ccm/%s",
profile.getProfileUrl())); profile.getProfileUrl()));
//Get the available Navigation items
PublicPersonalProfileNavItemCollection navItems =
new PublicPersonalProfileNavItemCollection();
navItems.addLanguageFilter(DispatcherHelper.getNegotiatedLocale().
getLanguage());
final Map<String, PublicPersonalProfileNavItem> navItemMap =
new HashMap<String, PublicPersonalProfileNavItem>();
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));
}
} }
} }

View File

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>PublicPersonalProfiles</servlet-name>
<servlet-class>com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfilesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PublicPersonalProfiles</servlet-name>
<url-pattern>/profiles/*</url-pattern>
</servlet-mapping>
</web-app>

View File

@ -1,10 +1,10 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<xsl:stylesheet <xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:import href="../../../../packages/bebop/xsl/bebop.xsl"/> <xsl:import href="../../../../packages/bebop/xsl/bebop.xsl"/>
<xsl:import href="../../../../packages/ui/xsl/ui.xsl"/> <xsl:import href="../../../../packages/ui/xsl/ui.xsl"/>
<xsl:import href="../../../../packages/content-section/xsl/cms-public.xsl"/> <xsl:import href="../../../../packages/content-section/xsl/cms-public.xsl"/>
<xsl:import href="../../../../packages/content-section/xsl/cms-item.xsl"/> <xsl:import href="../../../../packages/content-section/xsl/cms-item.xsl"/>
</xsl:stylesheet> </xsl:stylesheet>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8?>
<xsl:stylesheet
xmlns:bebop="http://www.arsdigita.com/bebop/1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<!-- <xsl:import href="../../../packages/bebop/xsl/bebop.xsl"/>
<xsl:import href="../../../packages/ui/xsl/ui.xsl"/>-->
</xsl:stylesheet>