}
private ChannelCategoryBean addChildren(WebRequest request, PortletCategory category, List<IPortletDefinition> allChannels, IPerson user, String type, Locale locale) {
// construct a new channel category bean for this category
ChannelCategoryBean categoryBean = new ChannelCategoryBean(category);
categoryBean.setName(messageSource.getMessage(category.getName(), new Object[] {}, locale));
// add the direct child channels for this category
Set<IPortletDefinition> portlets = portletCategoryRegistry.getChildPortlets(category);
EntityIdentifier ei = user.getEntityIdentifier();
IAuthorizationPrincipal ap = AuthorizationService.instance().newPrincipal(ei.getKey(), ei.getType());
boolean isManage = type.equals(TYPE_MANAGE);
for(IPortletDefinition channelDef : portlets) {
if ((isManage && ap.canManage(channelDef.getPortletDefinitionId()
.getStringId()))
|| (!isManage && ap.canSubscribe(channelDef
.getPortletDefinitionId().getStringId()))) {
// construct a new channel bean from this channel
ChannelBean channel = getChannel(channelDef, request, locale);
categoryBean.addChannel(channel);
}
// remove the channel of the list of all channels
allChannels.remove(channelDef);
}
/* Now add child categories. */
for(PortletCategory childCategory : this.portletCategoryRegistry.getChildCategories(category)) {
// TODO subscribe check?
ChannelCategoryBean childCategoryBean = addChildren(request, childCategory, allChannels, user, type, locale);
categoryBean.addCategory(childCategoryBean);
}
return categoryBean;