PublicPersonalProfile:

- Application-Klasse und zugehörige Klassen (Initializer, Loader, Servlet) in PublicPersonalProfiles umbenannt, um 
  Namenskonflikte zu vermeiden.
- Erste Ansätze für Navigation


git-svn-id: https://svn.libreccm.org/ccm/trunk@1052 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2011-08-04 11:39:00 +00:00
parent 3809f03bc2
commit ba5b005257
8 changed files with 268 additions and 116 deletions

View File

@ -11,11 +11,11 @@
<table name="ct_public_personal_profiles"/> <table name="ct_public_personal_profiles"/>
<table name="publicpersonalprofile"/> <table name="publicpersonalprofile"/>
<initializer class="com.arsdigita.cms.contenttypes.PublicPersonalProfileInitializer"/> <initializer class="com.arsdigita.cms.contenttypes.PublicPersonalProfileInitializer"/>
<initializer class="com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfileInitializer"/> <initializer class="com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfilesInitializer"/>
</provides> </provides>
<scripts> <scripts>
<schema directory="ccm-cms-publicpersonalprofile"/> <schema directory="ccm-cms-publicpersonalprofile"/>
<data class="com.arsdigita.cms.contenttypes.PublicPersonalProfileLoader"/> <data class="com.arsdigita.cms.contenttypes.PublicPersonalProfileLoader"/>
<data class="com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfileLoader"/> <data class="com.arsdigita.cms.publicpersonalprofile.PublicPersonalProfilesLoader"/>
</scripts> </scripts>
</load> </load>

View File

@ -162,6 +162,7 @@ public class PublicPersonalProfileCreate extends PageCreate {
PublicPersonalProfile profile = new PublicPersonalProfile(item. PublicPersonalProfile profile = new PublicPersonalProfile(item.
getOID()); getOID());
profile.setOwner(owner); profile.setOwner(owner);
profile.setProfileUrl(owner.getSurname().toLowerCase());
profile.save(); profile.save();
m_parent.editItem(state, item); m_parent.editItem(state, item);

View File

@ -8,11 +8,16 @@ import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.FormValidationListener;
import com.arsdigita.bebop.parameters.ParameterModel; import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.contenttypes.PublicPersonalProfile; import com.arsdigita.cms.contenttypes.PublicPersonalProfile;
import com.arsdigita.cms.ui.authoring.BasicPageForm; import com.arsdigita.cms.ui.authoring.BasicPageForm;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.SessionManager;
/** /**
* *
@ -22,10 +27,12 @@ import com.arsdigita.cms.ui.authoring.BasicPageForm;
public class PublicPersonalProfilePropertyForm public class PublicPersonalProfilePropertyForm
extends BasicPageForm extends BasicPageForm
implements FormProcessListener, implements FormProcessListener,
FormInitListener { FormInitListener,
FormValidationListener {
private PublicPersonalProfilePropertiesStep step; private PublicPersonalProfilePropertiesStep step;
public static final String ID = "PublicPersonalProfile_edit"; public static final String ID = "PublicPersonalProfile_edit";
private ItemSelectionModel itemModel;
public PublicPersonalProfilePropertyForm(ItemSelectionModel itemModel) { public PublicPersonalProfilePropertyForm(ItemSelectionModel itemModel) {
this(itemModel, null); this(itemModel, null);
@ -36,6 +43,8 @@ public class PublicPersonalProfilePropertyForm
PublicPersonalProfilePropertiesStep step) { PublicPersonalProfilePropertiesStep step) {
super(ID, itemModel); super(ID, itemModel);
this.step = step; this.step = step;
this.itemModel = itemModel;
addValidationListener(this);
} }
@Override @Override
@ -71,10 +80,36 @@ public class PublicPersonalProfilePropertyForm
if ((profile != null) if ((profile != null)
&& getSaveCancelSection().getSaveButton().isSelected(state)) { && getSaveCancelSection().getSaveButton().isSelected(state)) {
profile.setProfileUrl((String) data.get( profile.setProfileUrl(((String) data.get(
PublicPersonalProfile.PROFILE_URL)); PublicPersonalProfile.PROFILE_URL)).toLowerCase());
profile.save(); profile.save();
} }
} }
@Override
public void validate(FormSectionEvent fse) throws FormProcessException {
final PageState state = fse.getPageState();
final FormData data = fse.getFormData();
String profilesUrl = (String) data.get(PublicPersonalProfile.PROFILE_URL);
if ((profilesUrl == null) || profilesUrl.isEmpty()) {
data.addError(PublicPersonalProfileGlobalizationUtil.globalize("publicpersonalprofile.ui.profile_url.required"));
}
DataCollection profiles = SessionManager.getSession().retrieve(PublicPersonalProfile.BASE_DATA_OBJECT_TYPE);
profiles.addFilter(String.format("profileUrl = '%s'", ((String)data.get(PublicPersonalProfile.PROFILE_URL)).toLowerCase()));
profiles.addFilter(String.format("version = '%s'", ContentItem.DRAFT));
if (profiles.size() > 1) {
data.addError(PublicPersonalProfileGlobalizationUtil.globalize("publicpersonalprofile.ui.profile_url.already_in_use"));
} else if(profiles.size() == 1) {
profiles.next();
PublicPersonalProfile profile = (PublicPersonalProfile) DomainObjectFactory.newInstance(profiles.getDataObject());
if (!(profile.getID().equals(itemModel.getSelectedItem(state).getID()))) {
data.addError(PublicPersonalProfileGlobalizationUtil.globalize("publicpersonalprofile.ui.profile_url.already_in_use"));
}
}
}
} }

View File

@ -1,89 +0,0 @@
package com.arsdigita.cms.publicpersonalprofile;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageFactory;
import com.arsdigita.templating.PresentationManager;
import com.arsdigita.templating.Templating;
import com.arsdigita.web.Application;
import com.arsdigita.web.BaseApplicationServlet;
import com.arsdigita.xml.Document;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
/**
*
* @author Jens Pelzetter
* @version $Id$
*/
public class PublicPersonalProfileServlet extends BaseApplicationServlet {
private static final long serialVersionUID = -1495852395804455609L;
private static final Logger logger =
Logger.getLogger(
PublicPersonalProfileServlet.class);
@Override
protected void doService(final HttpServletRequest request,
final HttpServletResponse response,
final Application app) throws ServletException,
IOException {
String path = "";
logger.debug("PublicPersonalProfileServlet is starting...");
logger.debug(String.format("pathInfo = '%s'", request.getPathInfo()));
logger.debug("Extracting path from pathInfo by removing leading and "
+ "trailing slashes...");
if (request.getPathInfo() != null) {
if ("/".equals(request.getPathInfo())) {
path = "";
} else if (request.getPathInfo().startsWith("/")
&& request.getPathInfo().endsWith("/")) {
path = request.getPathInfo().substring(1, request.getPathInfo().
length() - 1);
} else if (request.getPathInfo().startsWith("/")) {
path = request.getPathInfo().substring(1);
} else if (request.getPathInfo().endsWith("/")) {
path = request.getPathInfo().substring(0, request.getPathInfo().
length() - 1);
} else {
path = request.getPathInfo();
}
}
logger.debug(String.format("path = %s", path));
//Displays a text/plain page with a message.
if (path.isEmpty()) {
logger.debug("pathInfo is null, responding with default...");
response.setContentType("text/plain");
response.getWriter().append("Please choose an application.");
} else {
Page page;
Form form;
Label label;
page = PageFactory.buildPage("SciPublications",
"Hello World from profiles");
form = new Form("HelloWorld");
label = new Label(String.format("Hello World! From profiles, path = %s", path));
form.add(label);
page.add(form);
page.lock();
Document document = page.buildDocument(request, response);
PresentationManager presentationManager = Templating.
getPresentationManager();
presentationManager.servePage(document, request, response);
}
}
}

View File

@ -11,21 +11,21 @@ import java.math.BigDecimal;
* @author Jens Pelzetter * @author Jens Pelzetter
* @version $Id$ * @version $Id$
*/ */
public class PublicPersonalProfile extends Application { 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";
public PublicPersonalProfile(final DataObject dobj) { public PublicPersonalProfiles(final DataObject dobj) {
super(dobj); super(dobj);
} }
public PublicPersonalProfile(final OID oid) public PublicPersonalProfiles(final OID oid)
throws DataObjectNotFoundException { throws DataObjectNotFoundException {
super(oid); super(oid);
} }
public PublicPersonalProfile(final BigDecimal id) public PublicPersonalProfiles(final BigDecimal id)
throws DataObjectNotFoundException { throws DataObjectNotFoundException {
this(new OID(BASE_DATA_OBJECT_TYPE, id)); this(new OID(BASE_DATA_OBJECT_TYPE, id));
} }

View File

@ -17,9 +17,9 @@ import com.arsdigita.runtime.RuntimeConfig;
* @author Jens Pelzetter * @author Jens Pelzetter
* @version $Id$ * @version $Id$
*/ */
public class PublicPersonalProfileInitializer extends CompoundInitializer { public class PublicPersonalProfilesInitializer extends CompoundInitializer {
public PublicPersonalProfileInitializer() { public PublicPersonalProfilesInitializer() {
final String jdbcUrl = RuntimeConfig.getConfig().getJDBCURL(); final String jdbcUrl = RuntimeConfig.getConfig().getJDBCURL();
final int database = DbHelper.getDatabaseFromURL(jdbcUrl); final int database = DbHelper.getDatabaseFromURL(jdbcUrl);
@ -33,13 +33,13 @@ public class PublicPersonalProfileInitializer extends CompoundInitializer {
super.init(event); super.init(event);
DomainObjectFactory.registerInstantiator( DomainObjectFactory.registerInstantiator(
PublicPersonalProfile.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 PublicPersonalProfile(dataObject); return new PublicPersonalProfiles(dataObject);
} }
}); });
} }

View File

@ -17,11 +17,11 @@ import org.apache.log4j.Logger;
* @author Jens Pelzetter * @author Jens Pelzetter
* @version $Id$ * @version $Id$
*/ */
public class PublicPersonalProfileLoader extends PackageLoader { public class PublicPersonalProfilesLoader extends PackageLoader {
private static final Logger logger = private static final Logger logger =
Logger.getLogger( Logger.getLogger(
PublicPersonalProfileLoader.class); PublicPersonalProfilesLoader.class);
@Override @Override
public void run(final ScriptContext ctx) { public void run(final ScriptContext ctx) {
@ -35,9 +35,9 @@ public class PublicPersonalProfileLoader extends PackageLoader {
/*ApplicationSetup setup = new ApplicationSetup(logger); /*ApplicationSetup setup = new ApplicationSetup(logger);
setup.setApplicationObjectType( setup.setApplicationObjectType(
PublicPersonalProfile.BASE_DATA_OBJECT_TYPE); PublicPersonalProfiles.BASE_DATA_OBJECT_TYPE);
setup.setKey("profiles"); setup.setKey("profiles");
setup.setTitle("PublicPersonalProfile"); setup.setTitle("PublicPersonalProfiles");
setup.setDescription("Display public personal profiles"); setup.setDescription("Display public personal profiles");
setup.setInstantiator(new ACSObjectInstantiator() { setup.setInstantiator(new ACSObjectInstantiator() {
@ -45,7 +45,7 @@ public class PublicPersonalProfileLoader extends PackageLoader {
@Override @Override
public DomainObject doNewInstance( public DomainObject doNewInstance(
final DataObject dataObject) { final DataObject dataObject) {
return new PublicPersonalProfile(dataObject); return new PublicPersonalProfiles(dataObject);
} }
}); });
@ -53,7 +53,7 @@ public class PublicPersonalProfileLoader extends PackageLoader {
type.save(); type.save();
if (!Application.isInstalled( if (!Application.isInstalled(
PublicPersonalProfile.BASE_DATA_OBJECT_TYPE, PublicPersonalProfiles.BASE_DATA_OBJECT_TYPE,
"/profiles/")) { "/profiles/")) {
/*Application app = Application.createRootApplication(type, /*Application app = Application.createRootApplication(type,
"profiles", "profiles",
@ -68,11 +68,11 @@ public class PublicPersonalProfileLoader extends PackageLoader {
ApplicationType type = ApplicationType type =
new ApplicationType("PublicPersonalProfile", new ApplicationType("PublicPersonalProfile",
PublicPersonalProfile.BASE_DATA_OBJECT_TYPE); PublicPersonalProfiles.BASE_DATA_OBJECT_TYPE);
type.setDescription("PublicPersonalProfile Viewer"); type.setDescription("PublicPersonalProfile Viewer");
Application.createApplication( Application.createApplication(
PublicPersonalProfile.BASE_DATA_OBJECT_TYPE, PublicPersonalProfiles.BASE_DATA_OBJECT_TYPE,
"profiles", "profiles",
"PublicPersonalProfiles", "PublicPersonalProfiles",
null); null);

View File

@ -0,0 +1,205 @@
package com.arsdigita.cms.publicpersonalprofile;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageFactory;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.contenttypes.GenericPerson;
import com.arsdigita.cms.contenttypes.PublicPersonalProfile;
import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.Session;
import com.arsdigita.persistence.SessionManager;
import com.arsdigita.templating.PresentationManager;
import com.arsdigita.templating.Templating;
import com.arsdigita.web.Application;
import com.arsdigita.web.BaseApplicationServlet;
import com.arsdigita.xml.Document;
import com.arsdigita.xml.Element;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
/**
*
* @author Jens Pelzetter
* @version $Id$
*/
public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
private static final long serialVersionUID = -1495852395804455609L;
private static final Logger logger =
Logger.getLogger(
PublicPersonalProfilesServlet.class);
private static final String PREVIEW = "preview";
@Override
protected void doService(final HttpServletRequest request,
final HttpServletResponse response,
final Application app) throws ServletException,
IOException {
String path = "";
logger.debug("PublicPersonalProfileServlet is starting...");
logger.debug(String.format("pathInfo = '%s'", request.getPathInfo()));
logger.debug("Extracting path from pathInfo by removing leading and "
+ "trailing slashes...");
if (request.getPathInfo() != null) {
if ("/".equals(request.getPathInfo())) {
path = "";
} else if (request.getPathInfo().startsWith("/")
&& request.getPathInfo().endsWith("/")) {
path = request.getPathInfo().substring(1, request.getPathInfo().
length() - 1);
} else if (request.getPathInfo().startsWith("/")) {
path = request.getPathInfo().substring(1);
} else if (request.getPathInfo().endsWith("/")) {
path = request.getPathInfo().substring(0, request.getPathInfo().
length() - 1);
} else {
path = request.getPathInfo();
}
}
logger.debug(String.format("path = %s", path));
//Displays a text/plain page with a message.
if (path.isEmpty()) {
logger.debug("pathInfo is null, responding with default...");
response.setContentType("text/plain");
response.getWriter().append("Please choose an application.");
} else {
final String[] pathTokens = path.split("/");
boolean preview = false;;
String profileOwner = "";
String navPath = null;
Page page;
/*Form form;
Label label;*/
page = PageFactory.buildPage("PublicPersonalProfile",
"Hello World from profiles");
/*form = new Form("HelloWorld");*/
if (pathTokens.length < 1) {
//ToDo: Fehlerbehandlung?
} else {
if ((pathTokens.length > 1)
&& PREVIEW.equals(pathTokens[0])) {
preview = true;
profileOwner = pathTokens[1];
if (pathTokens.length > 2) {
navPath = pathTokens[2];
}
} else {
profileOwner = pathTokens[0];
if (pathTokens.length > 1) {
navPath = pathTokens[1];
}
}
}
/*form.add(new Label(String.format("Member: %s", member)));
if (pathTokens.length > 1) {
for(int i = 1; i < pathTokens.length; i++) {
form.add(new Label(String.format("%d: %s", i, pathTokens[i])));
}
}
label = new Label(String.format(
"Hello World! From profiles, path = %s", path));
form.add(label);
page.add(form);*/
page.lock();
Document document = page.buildDocument(request, response);
Element root = document.getRootElement();
Element test = root.newChildElement("test");
test.setText("test");
final Session session = SessionManager.getSession();
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));
}
if (profiles.size() == 0) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return;
} else if (profiles.size() > 1) {
throw new IllegalStateException(
"More than one matching members found...");
} else {
profiles.next();
PublicPersonalProfile profile =
(PublicPersonalProfile) DomainObjectFactory.
newInstance(profiles.getDataObject());
Element profileElem = root.newChildElement("profile");
GenericPerson owner = profile.getOwner();
if (owner == null) {
throw new IllegalStateException(
"Failed to get owner of profile.");
}
profileElem.setText(owner.getFullName());
createNavigation(profile, root);
}
PresentationManager presentationManager = Templating.
getPresentationManager();
presentationManager.servePage(document, request, response);
}
}
private void createNavigation(final PublicPersonalProfile profile,
final Element root) {
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());
navHome.addAttribute("isSelected", "true");
navHome.addAttribute("sortKey", "");
navHome.addAttribute("title", "Allgemein");
navHome.addAttribute("url", String.format("/ccm/%s",
profile.getProfileUrl()));
}
}