Verbesserung des Verhaltens von PublicPersonalProfile für Sprachumschaltung (Ticket 994) sowie Verbesserung des 404

Handlings in PublicPersonalProfile (Ticket 1000)


git-svn-id: https://svn.libreccm.org/ccm/trunk@1411 8810af33-2d31-482b-a856-94f89814c4df
master
jensp 2011-12-31 14:25:41 +00:00
parent ed23691edb
commit 6d9b30e682
15 changed files with 948 additions and 134 deletions

View File

@ -5,3 +5,20 @@ import com.arsdigita.web.Application;
object type PublicPersonalProfile extends Application {
reference key (publicpersonalprofile.application_id);
}
// Subquery for AbstractObjectList used as a filter
// to figure out which object have a match in the
// selected languages and don't have to match to a
// language independent content item
query getParentIDsOfMatchedItems {
BigDecimal parent;
do {
select parent_id
from cms_items
where version = 'live'
and language = :language
} map {
parent = parent_id;
}
}

View File

@ -24,7 +24,6 @@ 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.globalization.GlobalizationHelper;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.ui.UI;
import com.arsdigita.xml.Element;
@ -105,8 +104,9 @@ public class PublicPersonalProfileXmlUtil {
}
navHome.addAttribute("sortKey", "");
String homeLabel = homeLabels.get(GlobalizationHelper.
getNegotiatedLocale().getLanguage());
/*String homeLabel = homeLabels.get(GlobalizationHelper.
getNegotiatedLocale().getLanguage());*/
String homeLabel = homeLabels.get(profile.getLanguage());
if (homeLabel == null) {
navHome.addAttribute("title", "Home");
} else {
@ -122,8 +122,9 @@ public class PublicPersonalProfileXmlUtil {
//Get the available Navigation items
PublicPersonalProfileNavItemCollection navItems =
new PublicPersonalProfileNavItemCollection();
navItems.addLanguageFilter(GlobalizationHelper.getNegotiatedLocale().
getLanguage());
/*navItems.addLanguageFilter(GlobalizationHelper.getNegotiatedLocale().
getLanguage());*/
navItems.addLanguageFilter(profile.getLanguage());
final Map<String, PublicPersonalProfileNavItem> navItemMap =
new HashMap<String, PublicPersonalProfileNavItem>();
PublicPersonalProfileNavItem navItem;
@ -175,8 +176,13 @@ public class PublicPersonalProfileXmlUtil {
if (!(targetItem instanceof PublicPersonalProfile)
&& (targetItem instanceof ContentPage)) {
ContentPage targetPage = (ContentPage) targetItem;
if (!(targetPage.getContentBundle().hasInstance(GlobalizationHelper.
getNegotiatedLocale().getLanguage(),
/*if (!(targetPage.getContentBundle().hasInstance(GlobalizationHelper.
getNegotiatedLocale().getLanguage(),
false))) {
continue;
}*/
if (!(targetPage.getContentBundle().hasInstance(profile.
getLanguage(),
false))) {
continue;
}

View File

@ -31,6 +31,8 @@ import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.mimetypes.MimeType;
import com.arsdigita.util.UncheckedWrapperException;
import java.util.ArrayList;
import java.util.List;
import java.util.TooManyListenersException;
import org.apache.log4j.Logger;
@ -52,6 +54,7 @@ public class PublicPersonalProfileNavigationAddForm
private final String ITEM_SEARCH = "itemSearch";
private ItemSelectionModel itemModel;
private SimpleEditStep editStep;
private List<String> autoNavItemKeys = new ArrayList<String>();
public PublicPersonalProfileNavigationAddForm(
final ItemSelectionModel itemModel,
@ -92,18 +95,26 @@ public class PublicPersonalProfileNavigationAddForm
navItems.addLanguageFilter(GlobalizationHelper.
getNegotiatedLocale().
getLanguage());
if (showGenerated()) {
navItems.addFilter("generatorClass is not null");
/*if (showGenerated()) {
navItems.addFilter("generatorClass is not null");
} else {
navItems.addFilter("generatorClass is null");
}
navItems.addFilter("generatorClass is null");
}*/
PublicPersonalProfileNavItem navItem;
String label;
while (navItems.next()) {
navItem = navItems.getNavItem();
select.addOption(new Option(navItem.getKey(),
navItem.getLabel()));
if (navItem.getGeneratorClass() == null) {
label = navItem.getLabel();
} else {
label = String.format("%s (auto)",
navItem.getLabel());
autoNavItemKeys.add(navItem.getKey());
}
select.addOption(new Option(navItem.getKey(), label));
}
}
});
@ -114,33 +125,32 @@ public class PublicPersonalProfileNavigationAddForm
/*navItemSelect.addOption(new Option("", ""));
PublicPersonalProfileNavItemCollection navItems =
new PublicPersonalProfileNavItemCollection();
new PublicPersonalProfileNavItemCollection();
navItems.addLanguageFilter(GlobalizationHelper.getNegotiatedLocale().
getLanguage());
getLanguage());
if (showGenerated()) {
navItems.addFilter("generatorClass is not null");
navItems.addFilter("generatorClass is not null");
} else {
navItems.addFilter("generatorClass is null");
navItems.addFilter("generatorClass is null");
}
PublicPersonalProfileNavItem navItem;
while (navItems.next()) {
navItem = navItems.getNavItem();
navItem = navItems.getNavItem();
navItemSelect.addOption(new Option(navItem.getKey(),
navItem.getLabel()));
navItemSelect.addOption(new Option(navItem.getKey(),
navItem.getLabel()));
}*/
add(navItemSelect);
if (!showGenerated()) {
add(new Label((String) PublicPersonalProfileGlobalizationUtil.
globalize(
"publicpersonalprofile.ui.nav.select_target").
localize()));
itemSearch = new ItemSearchWidget(ITEM_SEARCH);
itemSearch.addValidationListener(this);
add(this.itemSearch);
}
//if (!showGenerated()) {
add(new Label((String) PublicPersonalProfileGlobalizationUtil.globalize(
"publicpersonalprofile.ui.nav.select_target").
localize()));
itemSearch = new ItemSearchWidget(ITEM_SEARCH);
itemSearch.addValidationListener(this);
add(this.itemSearch);
//}
}
@Override
@ -178,11 +188,15 @@ public class PublicPersonalProfileNavigationAddForm
link.setTargetType(Link.INTERNAL_LINK);
ContentItem targetItem;
if (showGenerated()) {
//For generated content the target is the profile itself.
//if (showGenerated()) {
//For generated content the target is the profile itself.
//targetItem = profile;
//} else {
targetItem = (ContentItem) data.get(ITEM_SEARCH);
//
//}
if (targetItem == null) {
targetItem = profile;
} else {
targetItem = (ContentItem) data.get(ITEM_SEARCH);
}
if (targetItem.getParent() instanceof ContentBundle) {
@ -200,7 +214,10 @@ public class PublicPersonalProfileNavigationAddForm
PageState state = fse.getPageState();
FormData data = fse.getFormData();
if (!showGenerated() && data.get(ITEM_SEARCH) == null) {
//if (!showGenerated() && data.get(ITEM_SEARCH) == null) {
if (!(autoNavItemKeys.contains(
(String) data.get(PublicPersonalProfileNavItem.KEY)))
&& data.get(ITEM_SEARCH) == null) {
data.addError(
new GlobalizedMessage(
"parameter_is_required",
@ -209,7 +226,7 @@ public class PublicPersonalProfileNavigationAddForm
}
protected boolean showGenerated() {
return false;
}
/*protected boolean showGenerated() {
return false;
}*/
}

View File

@ -16,8 +16,8 @@ public class PublicPersonalProfileNavigationGeneratedAddForm extends PublicPerso
super("PublicPersonalProfileNavGeneratedAddForm", itemModel, editStep);
}
@Override
/*@Override
public boolean showGenerated() {
return true;
}
}*/
}

View File

@ -38,7 +38,7 @@ public class PublicPersonalProfileNavigationStep extends SimpleEditStep {
new WorkflowLockedComponentAccess(editNavItemSheet, itemModel),
editNavItemSheet.getSaveCancelSection().getCancelButton());
BasicItemForm editGeneratedNavItemSheet =
/*BasicItemForm editGeneratedNavItemSheet =
new PublicPersonalProfileNavigationGeneratedAddForm(
itemModel,
this);
@ -48,7 +48,7 @@ public class PublicPersonalProfileNavigationStep extends SimpleEditStep {
localize(),
new WorkflowLockedComponentAccess(editGeneratedNavItemSheet,
itemModel),
editGeneratedNavItemSheet.getSaveCancelSection().getCancelButton());
editGeneratedNavItemSheet.getSaveCancelSection().getCancelButton());*/
PublicPersonalProfileNavigationTable navTable =
new PublicPersonalProfileNavigationTable(

View File

@ -26,6 +26,7 @@ import com.arsdigita.cms.dispatcher.ItemResolver;
import com.arsdigita.cms.dispatcher.Utilities;
import com.arsdigita.cms.ui.authoring.SimpleEditStep;
import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.kernel.Kernel;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.util.LockableImpl;
import java.math.BigDecimal;
@ -146,19 +147,32 @@ public class PublicPersonalProfileNavigationTable
PublicPersonalProfileNavItem navItem;
navItem = navItems.getNavItem(key, GlobalizationHelper.
getNegotiatedLocale().
getLanguage());
getNegotiatedLocale().getLanguage());
navItems.reset();
if ((navItem == null) && (Kernel.getConfig().languageIndependentItems())) {
navItem = navItems.getNavItem(key, GlobalizationHelper.
LANG_INDEPENDENT);
}
navItems.reset();
switch (columnIndex) {
case 0:
//return mockNav[index];
return navItem.getLabel();
case 1:
if (navItem.getGeneratorClass() == null) {
return targetItem;
return navItem.getLabel();
} else {
return String.format("%s (auto)", navItem.getLabel());
}
case 1:
/*if (navItem.getGeneratorClass() == null) {
return targetItem;
} else {
return null;
}*/
if (targetItem instanceof PublicPersonalProfile) {
return null;
} else {
return targetItem;
}
case 2:
return PublicPersonalProfileGlobalizationUtil.globalize(

View File

@ -19,7 +19,11 @@ public interface ContentGenerator {
* @param parent XML element to attach the content to
* @param person The person to be used as data source
* @param state The current page state.
* @param profileLanguage
*/
void generateContent(Element parent, GenericPerson person, PageState state);
void generateContent(Element parent,
GenericPerson person,
PageState state,
String profileLanguage);
}

View File

@ -37,6 +37,8 @@ import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.kernel.Kernel;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.Filter;
import com.arsdigita.persistence.FilterFactory;
import com.arsdigita.persistence.OID;
import com.arsdigita.persistence.Session;
import com.arsdigita.persistence.SessionManager;
@ -82,6 +84,270 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
final HttpServletResponse response,
final Application app) throws ServletException,
IOException {
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...");
final String pathStr = getPath(request);
logger.debug(String.format("path = %s", pathStr));
//Displays a text/plain page with a message.
if (pathStr.isEmpty()) {
logger.debug("pathInfo is null, responding with default...");
response.setContentType("text/plain");
response.getWriter().append("Please choose an application.");
} else {
final Path path;
try {
path = new Path(pathStr);
} catch (IllegalArgumentException ex) {
response.sendError(HttpServletResponse.SC_BAD_REQUEST,
ex.getMessage());
return;
}
final Page page = PageFactory.buildPage("PublicPersonalProfile",
"");
if (path.getAdmin()) {
showAdminPage(page, request, response);
return;
}
page.lock();
final Document document = page.buildDocument(request, response);
final Element root = document.getRootElement();
final Session session = SessionManager.getSession();
/*final DataCollection profiles = getProfiles(session,
path.getProfileOwner(),
path.getPreview(),
GlobalizationHelper.
getNegotiatedLocale().getLanguage());
if (profiles.isEmpty()) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
} else if (profiles.size() > 1) {
throw new IllegalStateException(
"More than one matching members found.");
}
profiles.next();
PublicPersonalProfile profile =
(PublicPersonalProfile) DomainObjectFactory.
newInstance(profiles.getDataObject());
profiles.close();*/
PublicPersonalProfile profile = getProfile(
session,
path.getProfileOwner(),
path.getPreview(),
GlobalizationHelper.getNegotiatedLocale().getLanguage());
if (profile == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
if (path.getNavPath() != null) {
final DataCollection links = RelatedLink.getRelatedLinks(
profile,
PublicPersonalProfile.LINK_LIST_NAME);
links.addFilter(String.format("linkTitle = '%s'",
path.getNavPath()));
if (links.isEmpty()) {
profile = getProfile(session,
path.getProfileOwner(),
path.getPreview(),
GlobalizationHelper.LANG_INDEPENDENT,
false);
} else {
links.next();
final RelatedLink link = (RelatedLink) DomainObjectFactory.
newInstance(
links.getDataObject());
links.close();
ContentItem item = link.getTargetItem();
if ((item instanceof ContentPage)
&& !(item instanceof PublicPersonalProfile)) {
ContentPage contentPage =
(ContentPage) item;
if (contentPage.getContentBundle().hasInstance(profile.
getLanguage(),
false)) {
contentPage =
(ContentPage) contentPage.getContentBundle().
getInstance(profile.getLanguage());
item = (ContentItem) contentPage;
} else {
profile =
getProfile(session,
path.getProfileOwner(),
path.getPreview(),
GlobalizationHelper.LANG_INDEPENDENT);
}
}
}
}
final PageState state = new PageState(page,
request,
response);
if (path.getPreview()) {
if (Kernel.getContext().getParty() == null) {
throw new LoginSignal(request);
} else {
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());
}
}
}
if (config.getEmbedded()) {
final ContentSection section =
profile.getContentSection();
final ItemResolver resolver = section.getItemResolver();
String context;
if (path.getPreview()) {
context = CMSDispatcher.PREVIEW;
} else {
context = ContentItem.LIVE;
}
final String url = String.format("/ccm%s", resolver.
generateItemURL(state,
profile,
section,
context));
throw new RedirectSignal(url, false);
}
Element profileElem =
root.newChildElement("ppp:profile", PPP_NS);
GenericPerson owner = profile.getOwner();
if (owner == null) {
throw new IllegalStateException(
"Failed to get owner of profile.");
}
Element profileOwnerName = profileElem.newChildElement(
"ppp:ownerName", PPP_NS);
profileOwnerName.setText(owner.getFullName());
//Add an attribute with the lang of the owner item of debugging.
profileOwnerName.addAttribute("ownerItemLang", owner.getLanguage());
final DataCollection images = ItemImageAttachment.
getImageAttachments(profile);
if (!images.isEmpty()) {
images.next();
final Element profileImageElem =
profileElem.newChildElement("ppp:profileImage",
PPP_NS);
final Element attachmentElem = profileImageElem.newChildElement(
"imageAttachments");
final ItemImageAttachment attachment =
new ItemImageAttachment(images.
getDataObject());
attachmentElem.addAttribute("oid", attachment.getOID().
toString());
final Element caption = attachmentElem.newChildElement(
"caption");
caption.setText(attachment.getCaption());
final ReusableImageAsset image = attachment.getImage();
final Element imageElem =
attachmentElem.newChildElement("image");
imageElem.addAttribute("oid", image.getOID().toString());
final Element widthElem = imageElem.newChildElement(
"width");
widthElem.setText(image.getWidth().toString());
final Element heightElem = imageElem.newChildElement(
"height");
heightElem.setText(image.getHeight().toString());
final Element descElem = imageElem.newChildElement(
"description");
descElem.setText(image.getDescription());
final Element nameElem = imageElem.newChildElement(
"name");
nameElem.setText(image.getName());
final Element idElem = imageElem.newChildElement("id");
idElem.setText(image.getID().toString());
final Element displayNameElem = imageElem.newChildElement(
"displayName");
displayNameElem.setText(image.getDisplayName());
images.close();
}
final PublicPersonalProfileXmlUtil util =
new PublicPersonalProfileXmlUtil();
String prefix =
DispatcherHelper.getDispatcherPrefix(request);
if (prefix == null) {
prefix = "";
}
util.createNavigation(profile,
root,
path.getNavPath(),
prefix,
app.getPath(),
path.getPreview());
if (path.getNavPath() == null) {
final PublicPersonalProfileXmlGenerator generator =
new PublicPersonalProfileXmlGenerator(
profile);
generator.generateXML(state, root, "");
} else {
if (path.getItemPath() == null) {
showNavItem(response, profile, path, root,
profileElem, state);
} else {
showItem(response, profile, path, root,
profileElem, state);
}
}
PresentationManager presentationManager = Templating.
getPresentationManager();
presentationManager.servePage(document, request, response);
}
}
//@Override
protected void olddoService(final HttpServletRequest request,
final HttpServletResponse response,
final Application app) throws ServletException,
IOException {
String path = "";
logger.debug("PublicPersonalProfileServlet is starting...");
@ -179,17 +445,19 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
profileOwner,
preview,
GlobalizationHelper.
getNegotiatedLocale().getLanguage());
getNegotiatedLocale().getLanguage(),
Kernel.getConfig().
languageIndependentItems());
/*if (profiles.isEmpty()) {
profiles = getProfiles(session,
profileOwner,
preview,
GlobalizationHelper.LANG_INDEPENDENT);
profiles = getProfiles(session,
profileOwner,
preview,
GlobalizationHelper.LANG_INDEPENDENT);
}*/
if (profiles.size() == 0) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
} else if (profiles.size() > 1) {
throw new IllegalStateException(
@ -337,7 +605,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
navPath));
if (links.size() == 0) {
response.setStatus(
response.sendError(
HttpServletResponse.SC_NOT_FOUND);
return;
} else {
@ -370,7 +638,8 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
generator.generateContent(
profileElem,
owner,
state);
state,
profile.getLanguage());
} else {
throw new ServletException(String.
@ -440,7 +709,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
Kernel.getConfig().
languageIndependentItems(),
GlobalizationHelper.LANG_INDEPENDENT));
response.setStatus(
response.sendError(
HttpServletResponse.SC_NOT_FOUND);
return;
}
@ -497,7 +766,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
Kernel.getConfig().
languageIndependentItems(),
GlobalizationHelper.LANG_INDEPENDENT));
response.setStatus(
response.sendError(
HttpServletResponse.SC_NOT_FOUND);
return;
}
@ -520,7 +789,7 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
"Item '%s' not found: ",
itemPath),
ex);
response.setStatus(
response.sendError(
HttpServletResponse.SC_NOT_FOUND);
return;
}
@ -694,12 +963,229 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
}
private void showNavItem(final HttpServletResponse response,
final PublicPersonalProfile profile,
final Path path,
final Element root,
final Element profileElem,
final PageState state) throws IOException,
ServletException {
final DataCollection links =
RelatedLink.getRelatedLinks(
profile,
PublicPersonalProfile.LINK_LIST_NAME);
links.addFilter(String.format("linkTitle = '%s'",
path.getNavPath()));
if (links.size() == 0) {
response.sendError(
HttpServletResponse.SC_NOT_FOUND);
return;
}
if (config.getShowPersonInfoEverywhere()) {
generateProfileOwnerXml(profileElem, profile.getOwner(), state);
}
final PublicPersonalProfileNavItemCollection navItems =
new PublicPersonalProfileNavItemCollection();
navItems.addLanguageFilter(profile.getLanguage());
navItems.addKeyFilter(path.getNavPath());
navItems.next();
links.next();
final RelatedLink link = (RelatedLink) DomainObjectFactory.newInstance(
links.getDataObject());
links.close();
ContentItem item = link.getTargetItem();
if ((item instanceof ContentPage)
&& !(item instanceof PublicPersonalProfile)) {
ContentPage contentPage =
(ContentPage) item;
/*logger.debug("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 ",
path.getNavPath(),
GlobalizationHelper.getNegotiatedLocale().
getLanguage(),
Kernel.getConfig().
languageIndependentItems(),
GlobalizationHelper.LANG_INDEPENDENT));
response.sendError(
HttpServletResponse.SC_NOT_FOUND);
return;
}*/
if (contentPage.getContentBundle().hasInstance(profile.getLanguage(),
false)) {
contentPage =
(ContentPage) contentPage.getContentBundle().
getInstance(profile.getLanguage());
item = (ContentItem) contentPage;
} else {
response.sendError(
HttpServletResponse.SC_NOT_FOUND);
return;
}
final Element contentPanelElem =
root.newChildElement("cms:contentPanel",
CMS.CMS_XML_NS);
final PublicPersonalProfileXmlGenerator generator =
new PublicPersonalProfileXmlGenerator(
item);
generator.generateXML(state,
contentPanelElem,
"");
}
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(profileElem,
profile.getOwner(),
state,
profile.getLanguage());
} else {
throw new ServletException(String.format(
"Class '%s' is not a ContentGenerator.",
navItems.getNavItem().
getGeneratorClass()));
}
} catch (InstantiationException ex) {
throw new ServletException(
"Failed to create generator", ex);
} catch (IllegalAccessException ex) {
throw new ServletException(
"Failed to create generator", ex);
} catch (IllegalArgumentException ex) {
throw new ServletException(
"Failed to create generator", ex);
} catch (InvocationTargetException ex) {
throw new ServletException(
"Failed to create generator", ex);
} catch (ClassNotFoundException ex) {
throw new ServletException(
"Failed to create generator", ex);
} catch (NoSuchMethodException ex) {
throw new ServletException(
"Failed to create generator", ex);
}
}
navItems.close();
}
private void showItem(final HttpServletResponse response,
final PublicPersonalProfile profile,
final Path path,
final Element root,
final Element profileElem,
final PageState state) throws IOException {
if (config.getShowPersonInfoEverywhere()) {
generateProfileOwnerXml(profileElem, profile.getOwner(), state);
}
final OID itemOid = OID.valueOf(path.getItemPath());
try {
ContentItem item =
(ContentItem) DomainObjectFactory.newInstance(
itemOid);
if (item instanceof ContentPage) {
ContentPage contentPage = (ContentPage) item;
/*logger.debug("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 ",
path.getItemPath(),
GlobalizationHelper.getNegotiatedLocale().
getLanguage(),
Kernel.getConfig().
languageIndependentItems(),
GlobalizationHelper.LANG_INDEPENDENT));
response.sendError(
HttpServletResponse.SC_NOT_FOUND);
return;
}*/
if (contentPage.getContentBundle().hasInstance(profile.
getLanguage(), false)) {
contentPage = (ContentPage) contentPage.getContentBundle().
getInstance(profile.getLanguage());
} else {
response.sendError(
HttpServletResponse.SC_NOT_FOUND);
return;
}
}
final Element contentPanelElem =
root.newChildElement("cms:contentPanel",
CMS.CMS_XML_NS);
final PublicPersonalProfileXmlGenerator generator =
new PublicPersonalProfileXmlGenerator(
item);
generator.generateXML(state,
contentPanelElem,
"");
} catch (DataObjectNotFoundException ex) {
logger.error(String.format(
"Item '%s' not found: ",
path.getItemPath()),
ex);
response.sendError(
HttpServletResponse.SC_NOT_FOUND);
return;
}
}
private DataCollection getProfiles(final Session session,
final String profileOwner,
final boolean preview,
final String language) {
DataCollection profiles =
session.retrieve(
final String language,
final boolean allowLangIndependent) {
final DataCollection profiles =
session.retrieve(
com.arsdigita.cms.contenttypes.PublicPersonalProfile.BASE_DATA_OBJECT_TYPE);
profiles.addFilter(String.format("profileUrl = '%s'",
profileOwner));
@ -711,8 +1197,150 @@ public class PublicPersonalProfilesServlet extends BaseApplicationServlet {
ContentItem.LIVE));
}
profiles.addFilter(String.format("language = '%s'", language));
if (allowLangIndependent) {
FilterFactory ff = profiles.getFilterFactory();
Filter filter = ff.or().
addFilter(ff.equals("language", language)).
addFilter(ff.and().
addFilter(ff.equals("language",
GlobalizationHelper.LANG_INDEPENDENT)).
addFilter(ff.notIn("parent",
"com.arsdigita.navigation.getParentIDsOfMatchedItems").
set("language", language)));
profiles.addFilter(filter);
} else {
profiles.addFilter(String.format("language = '%s'", language));
}
return profiles;
}
private PublicPersonalProfile getProfile(final Session session,
final String profileOwner,
final boolean preview,
final String language) {
return getProfile(session,
profileOwner,
preview,
language,
Kernel.getConfig().languageIndependentItems());
}
private PublicPersonalProfile getProfile(final Session session,
final String profileOwner,
final boolean preview,
final String language,
final boolean allowLangIndependent) {
final DataCollection profiles = getProfiles(session,
profileOwner,
preview,
language,
allowLangIndependent);
if (profiles.isEmpty()) {
return null;
} else if (profiles.size() > 1) {
throw new IllegalStateException(
"More than one matching members found.");
} else {
profiles.next();
PublicPersonalProfile profile =
(PublicPersonalProfile) DomainObjectFactory.
newInstance(profiles.getDataObject());
profiles.close();
return profile;
}
}
private String getPath(final HttpServletRequest request) {
String path = "";
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();
}
}
return path;
}
private class Path {
private final boolean admin;
private final boolean preview;
private final String profileOwner;
private final String navPath;
private final String itemPath;
public Path(final String path) {
final String[] pathTokens = path.split("/");
final int ownerTokenPos;
if (pathTokens.length < 1) {
throw new IllegalArgumentException(
"Illegal path. Missing profile owner.");
} else {
admin = ADMIN.equals(pathTokens[0]);
preview = PREVIEW.equals(pathTokens[0]);
if (preview) {
ownerTokenPos = 1;
} else {
ownerTokenPos = 0;
}
if (pathTokens.length < (ownerTokenPos + 1)) {
throw new IllegalArgumentException(
"Illegal path. Missing profile owner.");
} else {
profileOwner = pathTokens[ownerTokenPos];
}
if (pathTokens.length > (ownerTokenPos + 1)) {
navPath = pathTokens[ownerTokenPos + 1];
} else {
navPath = null;
}
if (pathTokens.length > (ownerTokenPos + 2)) {
itemPath = pathTokens[ownerTokenPos + 2];
} else {
itemPath = null;
}
}
}
public boolean getAdmin() {
return admin;
}
public boolean getPreview() {
return preview;
}
public String getProfileOwner() {
return profileOwner;
}
public String getNavPath() {
return navPath;
}
public String getItemPath() {
return itemPath;
}
}
}

View File

@ -34,7 +34,6 @@ import com.arsdigita.kernel.permissions.PermissionService;
import com.arsdigita.persistence.DataAssociation;
import com.arsdigita.persistence.DataAssociationCursor;
import com.arsdigita.persistence.DataObject;
import com.arsdigita.persistence.FilterFactory;
import com.arsdigita.persistence.OID;
import com.arsdigita.persistence.metadata.Property;
import com.arsdigita.util.Assert;

View File

@ -14,10 +14,9 @@ import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.kernel.Kernel;
import com.arsdigita.persistence.DataCollection;
import com.arsdigita.persistence.Filter;
import com.arsdigita.persistence.FilterFactory;
import com.arsdigita.persistence.OID;
import com.arsdigita.xml.Element;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Calendar;
@ -56,8 +55,10 @@ public class PersonalProjects implements ContentGenerator {
public void generateContent(final Element parent,
final GenericPerson person,
final PageState state) {
final List<SciProject> projects = collectProjects(person);
final PageState state,
final String profileLanguage) {
final List<SciProject> projects = collectProjects(person,
profileLanguage);
final Element personalProjectsElem = parent.newChildElement(
"personalProjects");
@ -87,45 +88,74 @@ public class PersonalProjects implements ContentGenerator {
}
}
private List<SciProject> collectProjects(final GenericPerson person) {
private List<SciProject> collectProjects(final GenericPerson person,
final String language) {
final List<SciProject> projects = new ArrayList<SciProject>();
/*final DataCollection collection = (DataCollection) person.get(
"organizationalunit");
if (Kernel.getConfig().languageIndependentItems()) {*/
/* FilterFactory ff = collection.getFilterFactory();
Filter filter = ff.or().*/
/*addFilter(ff.equals("language",
com.arsdigita.globalization.GlobalizationHelper.
getNegotiatedLocale().getLanguage())).*/
/*addFilter(ff.equals("language", language)).
addFilter(ff.and().
addFilter(ff.equals("language",
GlobalizationHelper.LANG_INDEPENDENT)).
addFilter(ff.notIn("parent",
"com.arsdigita.london.navigation.getParentIDsOfMatchedItems").
set("language",
com.arsdigita.globalization.GlobalizationHelper.
getNegotiatedLocale().getLanguage())));
collection.addFilter(filter);*/
/*collection.addFilter(
String.format("(language = '%s' or language = '%s')",
language,
GlobalizationHelper.LANG_INDEPENDENT));
} else {
/*collection.addEqualsFilter("language",
com.arsdigita.globalization.GlobalizationHelper.
getNegotiatedLocale().getLanguage());*/
/* collection.addEqualsFilter("language", language);
}*/
final List<BigDecimal> processed = new ArrayList<BigDecimal>();
final DataCollection collection = (DataCollection) person.get(
"organizationalunit");
if (Kernel.getConfig().languageIndependentItems()) {
FilterFactory ff = collection.getFilterFactory();
Filter filter = ff.or().
addFilter(ff.equals("language",
com.arsdigita.globalization.GlobalizationHelper.
getNegotiatedLocale().getLanguage())).
addFilter(ff.and().
addFilter(ff.equals("language",
GlobalizationHelper.LANG_INDEPENDENT)).
addFilter(ff.notIn("parent",
"com.arsdigita.london.navigation.getParentIDsOfMatchedItems").
set("language",
com.arsdigita.globalization.GlobalizationHelper.
getNegotiatedLocale().getLanguage())));
collection.addFilter(filter);
} else {
collection.addEqualsFilter("language",
com.arsdigita.globalization.GlobalizationHelper.
getNegotiatedLocale().getLanguage());
}
collection.addFilter(String.format("language = '%s'", language));
DomainObject obj;
while (collection.next()) {
obj = DomainObjectFactory.newInstance(collection.getDataObject());
if (obj instanceof SciProject) {
processed.add(((SciProject) obj).getParent().getID());
projects.add((SciProject) obj);
}
}
if (Kernel.getConfig().languageIndependentItems()) {
final DataCollection collectionLi = (DataCollection) person.get(
"organizationalunit");
collectionLi.addFilter(
String.format("language = '%s'",
GlobalizationHelper.LANG_INDEPENDENT));
while (collectionLi.next()) {
obj =
DomainObjectFactory.newInstance(collectionLi.getDataObject());
if (obj instanceof SciProject) {
if (!(processed.contains(((SciProject) obj).getParent().
getID()))) {
projects.add((SciProject) obj);
}
}
}
}
if (person.getAlias() != null) {
collectProjects(person.getAlias(), projects);
}
return projects;
}

View File

@ -11,6 +11,8 @@ import com.arsdigita.domain.DomainObjectFactory;
import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.kernel.Kernel;
import com.arsdigita.persistence.DataQuery;
import com.arsdigita.persistence.Filter;
import com.arsdigita.persistence.FilterFactory;
import com.arsdigita.persistence.OID;
import com.arsdigita.persistence.SessionManager;
import com.arsdigita.xml.Element;
@ -46,12 +48,13 @@ public class PersonalPublications implements ContentGenerator {
@Override
public void generateContent(final Element parent,
final GenericPerson person,
final PageState state) {
final PageState state,
final String language) {
final long start = System.currentTimeMillis();
final DataQuery allQuery = SessionManager.getSession().retrieveQuery(
"com.arsdigita.cms.contenttypes.getPublicationsForAuthor");
applyAuthorFilter(person, allQuery, true);
applyAuthorFilter(person, allQuery, true, language);
final Element personalPubsElem = parent.newChildElement(
"personalPublications");
@ -83,7 +86,8 @@ public class PersonalPublications implements ContentGenerator {
createGroupQuery(person,
entry.getKey(),
entry.getValue(),
groupQueries);
groupQueries,
language);
logger.debug(String.format("3: %d ms until now...", System.
currentTimeMillis() - start));
}
@ -92,7 +96,7 @@ public class PersonalPublications implements ContentGenerator {
final DataQuery miscQuery = SessionManager.getSession().
retrieveQuery(
"com.arsdigita.cms.contenttypes.getPublicationsForAuthor");
applyAuthorFilter(person, miscQuery, true);
applyAuthorFilter(person, miscQuery, true, language);
miscQuery.addFilter(miscFilter);
groupQueries.put(MISC, miscQuery);
logger.debug(String.format("4: %d ms until now...", System.
@ -192,7 +196,8 @@ public class PersonalPublications implements ContentGenerator {
private void applyAuthorFilter(final GenericPerson person,
final DataQuery query,
final boolean addOrders) {
final boolean addOrders,
final String language) {
final StringBuilder authorFilterBuilder = new StringBuilder();
authorFilterBuilder.append('(');
authorFilterBuilder.append(String.format("authorId = %s",
@ -208,23 +213,27 @@ public class PersonalPublications implements ContentGenerator {
/*query.addFilter(String.format("authorId = %s",
person.getID().toString()));*/
if (Kernel.getConfig().languageIndependentItems()) {
/*FilterFactory ff = query.getFilterFactory();
FilterFactory ff = query.getFilterFactory();
Filter filter = ff.or().
addFilter(ff.equals("language", com.arsdigita.globalization.GlobalizationHelper.getNegotiatedLocale().getLanguage())).
addFilter(ff.equals("language", language)).
addFilter(ff.and().
addFilter(ff.equals("language", GlobalizationHelper.LANG_INDEPENDENT)).
addFilter(ff.notIn("parent", "com.arsdigita.navigation.getParentIDsOfMatchedItems")
.set("language", com.arsdigita.globalization.GlobalizationHelper.getNegotiatedLocale().getLanguage())));
query.addFilter(filter);*/
query.addFilter(
String.format("(language = '%s' or language = '%s')",
GlobalizationHelper.getNegotiatedLocale().
getLanguage(),
GlobalizationHelper.LANG_INDEPENDENT));
.set("language", language)));
query.addFilter(filter);
/*query.addFilter(
String.format("(language = '%s' or language = '%s')",
GlobalizationHelper.getNegotiatedLocale().
getLanguage(),
GlobalizationHelper.LANG_INDEPENDENT));*/
/*query.addFilter(String.format("language = '%s' or language = '%s'",
language,
GlobalizationHelper.LANG_INDEPENDENT));*/
} else {
query.addEqualsFilter("language",
com.arsdigita.globalization.GlobalizationHelper.
getNegotiatedLocale().getLanguage());
/*query.addEqualsFilter("language",
com.arsdigita.globalization.GlobalizationHelper.
getNegotiatedLocale().getLanguage());*/
query.addEqualsFilter("language", language);
}
if (addOrders) {
final String[] orders = config.getOrder().split(",");
@ -236,7 +245,8 @@ public class PersonalPublications implements ContentGenerator {
private void addAliasToFilter(final StringBuilder builder,
final GenericPerson alias) {
builder.append(String.format("or authorId = %s", alias.getID().toString()));
builder.append(String.format("or authorId = %s",
alias.getID().toString()));
if (alias.getAlias() != null) {
addAliasToFilter(builder, alias.getAlias());
@ -430,10 +440,11 @@ public class PersonalPublications implements ContentGenerator {
private void createGroupQuery(final GenericPerson author,
final String groupName,
final List<String> typeTokens,
final Map<String, DataQuery> groupQueries) {
final Map<String, DataQuery> groupQueries,
final String language) {
final DataQuery query = SessionManager.getSession().retrieveQuery(
"com.arsdigita.cms.contenttypes.getPublicationsForAuthor");
applyAuthorFilter(author, query, true);
applyAuthorFilter(author, query, true, language);
applyFiltersForTypeTokens(typeTokens, query);
groupQueries.put(groupName, query);

View File

@ -172,6 +172,7 @@ query getPublicationsForAuthor {
String language;
Boolean reviewed;
String authors;
BigDecimal parent;
do {
select cms_pages.item_id,
@ -181,7 +182,8 @@ query getPublicationsForAuthor {
ct_publications.year,
cms_items.language,
ct_publications.reviewed,
ct_publications.authors
ct_publications.authors,
cms_items.parent_id
from cms_pages
join ct_publications on cms_pages.item_id = ct_publications.publication_id
join ct_publications_authorship on ct_publications.publication_id = ct_publications_authorship.publication_id
@ -196,6 +198,7 @@ query getPublicationsForAuthor {
language = ct_items.language;
reviewed = ct_publications.reviewed;
authors = ct_publications.authors;
parent = cms_items.parent_id;
}
}

View File

@ -2,6 +2,7 @@ package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.RelationAttributeCollection;
import com.arsdigita.cms.contenttypes.GenericContact;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitContactCollection;
@ -10,6 +11,7 @@ import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitSubordinateCollec
import com.arsdigita.cms.contenttypes.GenericPerson;
import com.arsdigita.cms.contenttypes.SciDepartment;
import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.xml.Element;
import java.math.BigDecimal;
import org.apache.log4j.Logger;
@ -172,11 +174,13 @@ public class SciDepartmentSummaryTab implements GenericOrgaUnitTab {
final long start = System.currentTimeMillis();
if (!(orgaunit instanceof SciDepartment)) {
throw new IllegalArgumentException(String.format("Can't process "
throw new IllegalArgumentException(String.format(
"Can't process "
+ "orgaunit '%s' as sub department because the orgaunit is "
+ "not a SciDepartment but of type '%s'.",
orgaunit.getName(),
orgaunit.getClass().getName()));
orgaunit.getClass().
getName()));
}
final SciDepartment subDepartment = (SciDepartment) orgaunit;
@ -195,8 +199,8 @@ public class SciDepartmentSummaryTab implements GenericOrgaUnitTab {
}
protected void generateHeadXml(final BigDecimal memberId,
final Element parent,
final PageState state) {
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final GenericPerson member = new GenericPerson(memberId);
logger.debug(String.format("Got domain object for member '%s' "
@ -207,8 +211,8 @@ public class SciDepartmentSummaryTab implements GenericOrgaUnitTab {
}
protected void generateHeadXml(final GenericPerson member,
final Element parent,
final PageState state) {
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final XmlGenerator generator = new XmlGenerator(member);
generator.setUseExtraXml(false);
@ -219,7 +223,7 @@ public class SciDepartmentSummaryTab implements GenericOrgaUnitTab {
System.currentTimeMillis() - start));
}
protected void generateContactsXml(final SciDepartment department,
protected void generateContactsXml(final SciDepartment department,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
@ -233,7 +237,10 @@ public class SciDepartmentSummaryTab implements GenericOrgaUnitTab {
final Element contactsElem = parent.newChildElement("contacts");
while (contacts.next()) {
generateContactXml(contacts.getContact(), contactsElem, state);
generateContactXml(contacts.getContact(),
contacts.getContactType(),
contactsElem,
state);
}
logger.debug(String.format("Generated XML for contacts of project '%s'"
+ " in %d ms.",
@ -242,18 +249,41 @@ public class SciDepartmentSummaryTab implements GenericOrgaUnitTab {
}
protected void generateContactXml(final GenericContact contact,
final String contactType,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final XmlGenerator generator = new XmlGenerator(contact);
generator.setUseExtraXml(false);
generator.setItemElemName("contact", "");
generator.addItemAttribute("contactType",
getContactTypeName(contactType));
generator.generateXML(state, parent, "");
logger.debug(String.format("Generated XML for contact '%s' in %d ms.",
contact.getName(),
System.currentTimeMillis() - start));
}
private String getContactTypeName(final String contactTypeKey) {
final RelationAttributeCollection relAttrs =
new RelationAttributeCollection();
relAttrs.addFilter(String.format("attribute = '%s'",
"GenericContactTypes"));
relAttrs.addFilter(String.format("attr_key = '%s'", contactTypeKey));
relAttrs.addFilter(String.format("lang = '%s'", GlobalizationHelper.
getNegotiatedLocale().getLanguage()));
if (relAttrs.isEmpty()) {
return contactTypeKey;
} else {
relAttrs.next();
final String result = relAttrs.getName();
relAttrs.close();
return result;
}
}
private class XmlGenerator extends SimpleXMLGenerator {
private final ContentItem item;

View File

@ -2,6 +2,7 @@ package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.RelationAttributeCollection;
import com.arsdigita.cms.contenttypes.GenericContact;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitContactCollection;
@ -10,6 +11,7 @@ import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitSubordinateCollec
import com.arsdigita.cms.contenttypes.GenericPerson;
import com.arsdigita.cms.contenttypes.SciInstitute;
import com.arsdigita.cms.dispatcher.SimpleXMLGenerator;
import com.arsdigita.globalization.GlobalizationHelper;
import com.arsdigita.xml.Element;
import java.math.BigDecimal;
import org.apache.log4j.Logger;
@ -272,7 +274,7 @@ public class SciInstituteSummaryTab implements GenericOrgaUnitTab {
System.currentTimeMillis() - start));
}
protected void generateContactsXml(final SciInstitute department,
protected void generateContactsXml(final SciInstitute department,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
@ -286,7 +288,10 @@ public class SciInstituteSummaryTab implements GenericOrgaUnitTab {
final Element contactsElem = parent.newChildElement("contacts");
while (contacts.next()) {
generateContactXml(contacts.getContact(), contactsElem, state);
generateContactXml(contacts.getContact(),
contacts.getContactType(),
contactsElem,
state);
}
logger.debug(String.format("Generated XML for contacts of project '%s'"
+ " in %d ms.",
@ -295,18 +300,41 @@ public class SciInstituteSummaryTab implements GenericOrgaUnitTab {
}
protected void generateContactXml(final GenericContact contact,
final String contactType,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final XmlGenerator generator = new XmlGenerator(contact);
generator.setUseExtraXml(false);
generator.setItemElemName("contact", "");
generator.addItemAttribute("contactType",
getContactTypeName(contactType));
generator.generateXML(state, parent, "");
logger.debug(String.format("Generated XML for contact '%s' in %d ms.",
contact.getName(),
System.currentTimeMillis() - start));
}
private String getContactTypeName(final String contactTypeKey) {
final RelationAttributeCollection relAttrs =
new RelationAttributeCollection();
relAttrs.addFilter(String.format("attribute = '%s'",
"GenericContactTypes"));
relAttrs.addFilter(String.format("attr_key = '%s'", contactTypeKey));
relAttrs.addFilter(String.format("lang = '%s'", GlobalizationHelper.
getNegotiatedLocale().getLanguage()));
if (relAttrs.isEmpty()) {
return contactTypeKey;
} else {
relAttrs.next();
final String result = relAttrs.getName();
relAttrs.close();
return result;
}
}
private class XmlGenerator extends SimpleXMLGenerator {
private final ContentItem item;

View File

@ -2,6 +2,7 @@ package com.arsdigita.cms.contenttypes.ui;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.RelationAttributeCollection;
import com.arsdigita.cms.contenttypes.GenericContact;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnit;
import com.arsdigita.cms.contenttypes.GenericOrganizationalUnitContactCollection;
@ -293,7 +294,10 @@ public class SciProjectSummaryTab implements GenericOrgaUnitTab {
final Element contactsElem = parent.newChildElement("contacts");
while (contacts.next()) {
generateContactXml(contacts.getContact(), contactsElem, state);
generateContactXml(contacts.getContact(),
contacts.getContactType(),
contactsElem,
state);
}
logger.debug(String.format("Generated XML for contacts of project '%s'"
+ " in %d ms.",
@ -302,18 +306,41 @@ public class SciProjectSummaryTab implements GenericOrgaUnitTab {
}
protected void generateContactXml(final GenericContact contact,
final String contactType,
final Element parent,
final PageState state) {
final long start = System.currentTimeMillis();
final XmlGenerator generator = new XmlGenerator(contact);
generator.setUseExtraXml(false);
generator.setItemElemName("contact", "");
generator.addItemAttribute("contactType",
getContactTypeName(contactType));
generator.generateXML(state, parent, "");
logger.debug(String.format("Generated XML for contact '%s' in %d ms.",
contact.getName(),
System.currentTimeMillis() - start));
}
private String getContactTypeName(final String contactTypeKey) {
final RelationAttributeCollection relAttrs =
new RelationAttributeCollection();
relAttrs.addFilter(String.format("attribute = '%s'",
"GenericContactTypes"));
relAttrs.addFilter(String.format("attr_key = '%s'", contactTypeKey));
relAttrs.addFilter(String.format("lang = '%s'", GlobalizationHelper.
getNegotiatedLocale().getLanguage()));
if (relAttrs.isEmpty()) {
return contactTypeKey;
} else {
relAttrs.next();
final String result = relAttrs.getName();
relAttrs.close();
return result;
}
}
protected void generateInvolvedOrgasXml(final SciProject project,
final Element parent,
final PageState state) {