Removed depcrecated package com/arsdigita/cms/ui/type

pull/28/head
Jens Pelzetter 2022-03-16 19:44:23 +01:00
parent ad387198be
commit 01d8874193
13 changed files with 26 additions and 2369 deletions

View File

@ -36,12 +36,10 @@ import org.librecms.contentsection.ContentSection;
import com.arsdigita.cms.dispatcher.CMSPage; import com.arsdigita.cms.dispatcher.CMSPage;
import com.arsdigita.cms.ui.category.CategoryAdminPane; import com.arsdigita.cms.ui.category.CategoryAdminPane;
//ToDo NG import com.arsdigita.cms.ui.category.CategoryAdminPane;
import com.arsdigita.cms.ui.cse.ContentSoonExpiredPane; import com.arsdigita.cms.ui.cse.ContentSoonExpiredPane;
import com.arsdigita.cms.ui.folder.FolderAdminPane; import com.arsdigita.cms.ui.folder.FolderAdminPane;
import com.arsdigita.cms.ui.lifecycle.LifecycleAdminPane; import com.arsdigita.cms.ui.lifecycle.LifecycleAdminPane;
import com.arsdigita.cms.ui.role.RoleAdminPane; import com.arsdigita.cms.ui.role.RoleAdminPane;
import com.arsdigita.cms.ui.type.ContentTypeAdminPane;
import com.arsdigita.cms.ui.workflow.WorkflowAdminPane; import com.arsdigita.cms.ui.workflow.WorkflowAdminPane;
import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.toolbox.ui.LayoutPanel; import com.arsdigita.toolbox.ui.LayoutPanel;
@ -77,59 +75,73 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
* expansion from content item page. * expansion from content item page.
*/ */
public static final String SET_FOLDER = "set_folder"; public static final String SET_FOLDER = "set_folder";
/** /**
* The URL parameter that can be passed in in order to set the current * The URL parameter that can be passed in in order to set the current
* template (for setting the content type) * template (for setting the content type)
*/ */
public static final String SET_TEMPLATE = "set_template"; public static final String SET_TEMPLATE = "set_template";
/** /**
* The URL parameter that can be passed in in order to set the current tab. * The URL parameter that can be passed in in order to set the current tab.
* This is a KLUDGE right now because the TabbedDialog's current tab is * This is a KLUDGE right now because the TabbedDialog's current tab is
* selected with a local state parameter. * selected with a local state parameter.
*/ */
public static final String SET_TAB = "set_tab"; public static final String SET_TAB = "set_tab";
/** /**
* Index of the search tab * Index of the search tab
*/ */
public static final int SEARCH_TAB = 0; public static final int SEARCH_TAB = 0;
/** /**
* Index of the browse tab * Index of the browse tab
*/ */
public static final int BROWSE_TAB = 1; public static final int BROWSE_TAB = 1;
/** /**
* Index of the roles tab * Index of the roles tab
*/ */
public static final int ROLES_TAB = 2; public static final int ROLES_TAB = 2;
/** /**
* Index of the workflows tab * Index of the workflows tab
*/ */
public static final int WORKFLOW_TAB = 3; public static final int WORKFLOW_TAB = 3;
/** /**
* Index of the lifecycles tab * Index of the lifecycles tab
*/ */
public static final int LIFECYCLES_TAB = 4; public static final int LIFECYCLES_TAB = 4;
/** /**
* Index of the categories tab * Index of the categories tab
*/ */
public static final int CATEGORIES_TAB = 5; public static final int CATEGORIES_TAB = 5;
/** /**
* Index of the content types tab * Index of the content types tab
*/ */
public static final int CONTENTTYPES_TAB = 6; public static final int CONTENTTYPES_TAB = 6;
public static final int USER_ADMIN_TAB = 7; public static final int USER_ADMIN_TAB = 7;
private TabbedPane m_tabbedPane; private TabbedPane m_tabbedPane;
private FolderAdminPane m_folderPane; private FolderAdminPane m_folderPane;
private BrowsePane m_browsePane; private BrowsePane m_browsePane;
private ItemSearch m_searchPane; private ItemSearch m_searchPane;
// private AssetPane m_assetPane;
//ToDo NG private ImagesPane m_imagesPane;
private RoleAdminPane m_rolePane; private RoleAdminPane m_rolePane;
private WorkflowAdminPane m_workflowPane; private WorkflowAdminPane m_workflowPane;
private LifecycleAdminPane m_lifecyclePane; private LifecycleAdminPane m_lifecyclePane;
private CategoryAdminPane m_categoryPane; private CategoryAdminPane m_categoryPane;
private ContentTypeAdminPane m_typePane;
//private LayoutPanel m_userAdminPane;
private LayoutPanel m_csePane; private LayoutPanel m_csePane;
/** /**
@ -148,18 +160,11 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
m_folderPane = getFolderAdminPane(); m_folderPane = getFolderAdminPane();
m_browsePane = getBrowsePane(); m_browsePane = getBrowsePane();
m_searchPane = getSearchPane(); m_searchPane = getSearchPane();
m_assetPane = getAssetPane();
//ToDo NG m_imagesPane = getImagesPane();
m_rolePane = getRoleAdminPane(); m_rolePane = getRoleAdminPane();
m_workflowPane = getWorkflowAdminPane(); m_workflowPane = getWorkflowAdminPane();
m_lifecyclePane = getLifecycleAdminPane(); m_lifecyclePane = getLifecycleAdminPane();
m_categoryPane = getCategoryAdminPane(); m_categoryPane = getCategoryAdminPane();
m_typePane = getContentTypeAdminPane();
// userAdminPane removed, used to contain just one item (reset user
// folder) which moved to the FolderAdminPane
//m_userAdminPane = getUserAdminPane();
m_csePane = getCSEPane(); m_csePane = getCSEPane();
m_reportPane = getReportPane();
// The panes // The panes
m_tabbedPane = createTabbedPane(); m_tabbedPane = createTabbedPane();
@ -187,7 +192,8 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
m_tabbedPane.setTabVisible( m_tabbedPane.setTabVisible(
state, state,
m_workflowPane, m_workflowPane,
permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_WORKFLOWS)); permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_WORKFLOWS));
m_tabbedPane.setTabVisible( m_tabbedPane.setTabVisible(
state, state,
m_categoryPane, m_categoryPane,
@ -198,11 +204,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
m_lifecyclePane, m_lifecyclePane,
permissionChecker.isPermitted( permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_LIFECYLES)); AdminPrivileges.ADMINISTER_LIFECYLES));
m_tabbedPane.setTabVisible(
state,
m_typePane,
permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_CONTENT_TYPES));
m_tabbedPane.setTabVisible( m_tabbedPane.setTabVisible(
state, state,
@ -267,7 +268,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
// //
// return m_assetPane; // return m_assetPane;
// } // }
// ToDo NG // ToDo NG
// protected ImagesPane getImagesPane() { // protected ImagesPane getImagesPane() {
// if (m_imagesPane == null) { // if (m_imagesPane == null) {
@ -315,28 +315,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
return m_categoryPane; return m_categoryPane;
} }
/**
* Creates, and then caches, the content type administration pane.
* Overriding this method to return null will prevent this tab from
* appearing.
*
* @return
*/
protected ContentTypeAdminPane getContentTypeAdminPane() {
if (m_typePane == null) {
m_typePane = new ContentTypeAdminPane();
}
return m_typePane;
}
// protected LayoutPanel getUserAdminPane() {
// if (m_userAdminPane == null) {
// m_userAdminPane = new LayoutPanel();
// m_userAdminPane.setLeft(new SimpleComponent());
// m_userAdminPane.setBody(new UserAdminPane());
// }
// return m_userAdminPane;
// }
protected LayoutPanel getCSEPane() { protected LayoutPanel getCSEPane() {
if (m_csePane == null) { if (m_csePane == null) {
m_csePane = new LayoutPanel(); m_csePane = new LayoutPanel();
@ -346,7 +324,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
return m_csePane; return m_csePane;
} }
/** /**
* Adds the specified component, with the specified tab name, to the tabbed * Adds the specified component, with the specified tab name, to the tabbed
* pane only if it is not null. * pane only if it is not null.
@ -391,15 +368,12 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
//tab(pane, "cms.ui.folders", getFolderAdminPane()); //tab(pane, "cms.ui.folders", getFolderAdminPane());
tab(pane, "cms.ui.browse", getBrowsePane()); tab(pane, "cms.ui.browse", getBrowsePane());
tab(pane, "cms.ui.search", getSearchPane()); tab(pane, "cms.ui.search", getSearchPane());
tab(pane, "cms.ui.assets", getAssetPane());
// ToDo NG replace with media tab tab(pane, "cms.ui.images", getImagesPane()); // ToDo NG replace with media tab tab(pane, "cms.ui.images", getImagesPane());
tab(pane, "cms.ui.roles", getRoleAdminPane()); tab(pane, "cms.ui.roles", getRoleAdminPane());
tab(pane, "cms.ui.workflows", getWorkflowAdminPane()); tab(pane, "cms.ui.workflows", getWorkflowAdminPane());
tab(pane, "cms.ui.lifecycles", getLifecycleAdminPane()); tab(pane, "cms.ui.lifecycles", getLifecycleAdminPane());
tab(pane, "cms.ui.categories", getCategoryAdminPane()); tab(pane, "cms.ui.categories", getCategoryAdminPane());
tab(pane, "cms.ui.content_types", getContentTypeAdminPane());
tab(pane, "cms.ui.cse", getCSEPane()); tab(pane, "cms.ui.cse", getCSEPane());
tab(pane, "cms.ui.reports", getReportPane());
return pane; return pane;
} }
@ -436,9 +410,7 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
// } else if (pane == m_imagesPane) { // } else if (pane == m_imagesPane) {
// m_imagesPane.reset(state); // m_imagesPane.reset(state);
// } else // } else
if (pane == m_assetPane) { if (pane == m_folderPane) {
m_assetPane.reset(state);
} else if (pane == m_folderPane) {
m_folderPane.reset(state); m_folderPane.reset(state);
//ToDo NG } else if (pane == m_browsePane) { //ToDo NG } else if (pane == m_browsePane) {
// m_browsePane.reset(state); // m_browsePane.reset(state);
@ -450,10 +422,7 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
m_lifecyclePane.reset(state); m_lifecyclePane.reset(state);
} else if (pane == m_categoryPane) { } else if (pane == m_categoryPane) {
m_categoryPane.reset(state); m_categoryPane.reset(state);
} else if (pane == m_typePane) {
m_typePane.reset(state);
// } else if (pane == m_userAdminPane) {
//m_userAdminPane.reset(state);
} else if (pane == m_csePane) { } else if (pane == m_csePane) {
m_csePane.reset(state); m_csePane.reset(state);
} }

View File

@ -1,366 +0,0 @@
/*
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.type;
import com.arsdigita.bebop.ActionLink;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.GridPanel;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.ActionEvent;
import com.arsdigita.bebop.event.ActionListener;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSubmissionListener;
import com.arsdigita.bebop.event.PrintEvent;
import com.arsdigita.bebop.event.PrintListener;
import com.arsdigita.cms.CMS;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentType;
//ToDo import com.arsdigita.cms.SectionTemplateMapping;
import com.arsdigita.cms.ui.BaseAdminPane;
import com.arsdigita.cms.ui.BaseDeleteForm;
import com.arsdigita.globalization.GlobalizedMessage;
//ToDo insert later import com.arsdigita.cms.ui.ContentSectionPage;
import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
import com.arsdigita.toolbox.ui.ActionGroup;
import com.arsdigita.toolbox.ui.Cancellable;
import com.arsdigita.toolbox.ui.Section;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.core.UnexpectedErrorException;
import org.librecms.CmsConstants;
import org.librecms.contentsection.ContentSectionManager;
import org.librecms.contentsection.ContentTypeManager;
import org.librecms.contenttypes.ContentTypeInfo;
import java.util.List;
import java.util.TooManyListenersException;
/**
* This class contains the split pane for the ContentType administration
* interface.
*
* @author Jack Chung
* @author Michael Pih
* @author Stanislav Freidin
* @author Justin Ross <jross@redhat.com>
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public final class ContentTypeAdminPane extends BaseAdminPane<String> {
private static final Logger LOGGER = LogManager.getLogger(
ContentTypeAdminPane.class);
private final ACSObjectSelectionModel m_model;
private final ContentTypeRequestLocal m_type;
/**
* Constructs an admin pane. It is containing (a) a list of available
* content types in a given content section and adds a link to make
* additional content types available (out of a list of installed, but
* available in a given content section).
*/
public ContentTypeAdminPane() {
//
super(new Label(gz("cms.ui.types")),
new ContentTypeListModelBuilder()); //list with all Types avail.
m_model = new ACSObjectSelectionModel(getSelectionModel());
m_type = new SelectionRequestLocal();
ActionLink addTypeLink
= new ActionLink(new Label(gz("cms.ui.type.add")));
AddTypeContainer addTypeContainer = new AddTypeContainer();
getBody().add(addTypeContainer);
getBody().connect(addTypeLink, addTypeContainer);
addTypeLink.addActionListener(addTypeContainer);
setEdit(new ActionLink(new Label(gz("cms.ui.type.edit"))),
new EditType(m_model));
setDelete(new ActionLink(new Label(gz("cms.ui.type.delete"))),
new DeleteForm());
setIntroPane(new Label(gz("cms.ui.type.intro")));
setItemPane(new ContentTypeItemPane(m_model,
m_type,
getEditLink(),
getDeleteLink()));
addAction(new TypeSecurityContainer(addTypeLink), ActionGroup.ADD);
}
@Override
public void register(final Page page) {
super.register(page);
page.addActionListener(new ActionListener() {
/**
*
* @param event
*/
@Override
public void actionPerformed(final ActionEvent event) {
// ToDo
// final PageState state = event.getPageState();
// ContentType contentType = (ContentType) m_model.getSelectedObject(state);
// ContentSection section = CMS.getContext().getContentSection();
// if (contentType == null) {
// final String template = state.getRequest()
// .getParameter(ContentSectionPage
// .SET_TEMPLATE);
// if (template != null) {
// DataCollection da = SessionManager.getSession().retrieve(SectionTemplateMapping.BASE_DATA_OBJECT_TYPE);
// DomainCollection c = new DomainCollection(da);
// c.addEqualsFilter(SectionTemplateMapping.SECTION + "." + ACSObject.ID,
// section.getID());
// c.addEqualsFilter(SectionTemplateMapping.TEMPLATE + "." + ACSObject.ID,
// new BigDecimal(template));
// c.addOrder(SectionTemplateMapping.CONTENT_TYPE + "." + ContentType.LABEL);
// if (c.next()) {
// SectionTemplateMapping mapping =
// (SectionTemplateMapping) c.getDomainObject();
// contentType = mapping.getContentType();
// }
// c.close();
// }
// if (contentType == null) {
// ContentTypeCollection contentTypes = section.getContentTypes();
// contentTypes.addOrder("label asc");
// try {
// if (contentTypes.next()) {
// contentType = contentTypes.getContentType();
// }
// } finally {
// contentTypes.close();
// }
// }
// if (contentType != null) {
// m_model.setSelectedObject(state, contentType);
// getBody().push(state, getItemPane());
// }
//
//
// }
}
});
}
// ToDo (?) User Definied Content Types
// private class AddTypeContainer extends GridPanel implements ActionListener,
// FormProcessListener {
//
// private Label m_noTypesAvailable =
// new Label(gz("cms.ui.type.select.none"));
// private SelectType m_selectType;
//// User Definied Content Types private CreateType m_createType;
//
// /**
// *
// */
// AddTypeContainer() {
// super(1);
// Section selectSection = new Section();
// selectSection.setHeading(new Label(gz("cms.ui.type.select")));
// add(selectSection);
//
// GridPanel container = new GridPanel(1);
// container.add(m_noTypesAvailable);
// m_selectType = new SelectType();
// m_selectType.addSubmissionListener(new CancelListener(m_selectType));
// m_selectType.addProcessListener(this);
// container.add(m_selectType);
// selectSection.setBody(container);
//
// Section addSection = new Section() {
//
// @Override
// public final boolean isVisible(final PageState state) {
// return super.isVisible(state)
// && !ContentSection.getConfig().getHideUDCTUI();
// }
// };
// addSection.setHeading(new Label(gz("cms.ui.type.define")));
// m_createType = new CreateType(m_model);
// m_createType.addSubmissionListener(new CancelListener(m_createType));
// m_createType.addProcessListener(this);
// addSection.setBody(m_createType);
// add(addSection);
// }
//
// /**
// *
// * @param e
// */
// @Override
// public void actionPerformed(ActionEvent e) {
// PageState s = e.getPageState();
// ContentSection section = CMS.getContext().getContentSection();
// ContentTypeCollection contentTypes =
// section.getNotAssociatedContentTypes();
// boolean hasAvailableTypes = !contentTypes.isEmpty();
// m_selectType.setVisible(s, hasAvailableTypes);
// m_noTypesAvailable.setVisible(s, !hasAvailableTypes);
// }
//
// public final void process(final FormSectionEvent e)
// throws FormProcessException {
// final PageState state = e.getPageState();
// resetPane(state);
// }
// }
/**
* This class is essentially a copy of the CancelListener inside of
* ModalPanel. We could not use the one in ModalPanel because it was
* protected
*/
private final class CancelListener implements FormSubmissionListener {
Cancellable m_form;
CancelListener(final Cancellable form) {
m_form = form;
}
@Override
public void submitted(FormSectionEvent event)
throws FormProcessException {
PageState state = event.getPageState();
if (m_form.isCancelled(state)) {
getBody().pop(state);
throw new FormProcessException(new GlobalizedMessage(
"cms.ui.type.cancelled", CmsConstants.CMS_BUNDLE));
}
}
} // end private class
private void resetPane(final PageState state) {
getBody().reset(state);
if (getSelectionModel().isSelected(state)) {
LOGGER.debug("The selection model is selected; displaying "
+ "the item pane");
getBody().push(state, getItemPane());
}
}
private class SelectionRequestLocal extends ContentTypeRequestLocal {
@Override
protected final Object initialValue(final PageState state) {
ContentType contentType = (ContentType) m_model.getSelectedObject(
state);
return contentType;
}
}
private class DeleteForm extends BaseDeleteForm {
DeleteForm() {
super(new Label(gz("cms.ui.type.delete_prompt")));
addSubmissionListener(new TypeSecurityListener());
}
@Override
public final void process(final FormSectionEvent e)
throws FormProcessException {
final PageState state = e.getPageState();
final ContentSection section = CMS.getContext().getContentSection();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentSectionManager sectionManager = cdiUtil.findBean(
ContentSectionManager.class);
final ContentTypeManager typeManager = cdiUtil.findBean(
ContentTypeManager.class);
m_type.getContentType(state).getContentItemClass();
sectionManager.removeContentTypeFromSection(
typeManager.classNameToClass(m_type.getContentType(state)
.getContentItemClass()),
section);
getSelectionModel().clearSelection(state);
}
}
private class AddTypeContainer
extends GridPanel
implements ActionListener, FormProcessListener {
private final Label noTypesAvailableLabel
= new Label(gz("cms.ui.type.select.none"));
private final SelectType selectType;
public AddTypeContainer() {
super(1);
final Section selectSection = new Section();
selectSection.setHeading(new Label(gz("cms.ui.type.select")));
add(selectSection);
final GridPanel container = new GridPanel(1);
container.add(noTypesAvailableLabel);
selectType = new SelectType();
selectType.addSubmissionListener(new CancelListener(selectType));
selectType.addProcessListener(this);
container.add(selectType);
selectSection.setBody(container);
}
@Override
public void actionPerformed(final ActionEvent event) {
final PageState state = event.getPageState();
final ContentSection section = CMS.getContext().getContentSection();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentTypeAdminPaneController controller = cdiUtil
.findBean(ContentTypeAdminPaneController.class);
final List<ContentTypeInfo> contentTypes = controller
.getNotAssociatedContentTypes(section);
final boolean hasAvailableTypes = !contentTypes.isEmpty();
selectType.setVisible(state, hasAvailableTypes);
noTypesAvailableLabel.setVisible(state, !hasAvailableTypes);
}
@Override
public void process(final FormSectionEvent event)
throws FormProcessException {
final PageState state = event.getPageState();
resetPane(state);
}
}
}

View File

@ -1,247 +0,0 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.cms.ui.type;
import org.libreccm.workflow.Workflow;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentSectionManager;
import org.librecms.contentsection.ContentSectionRepository;
import org.librecms.contentsection.ContentType;
import org.librecms.contentsection.ContentTypeManager;
import org.librecms.contentsection.ContentTypeRepository;
import org.librecms.contenttypes.ContentTypeInfo;
import org.librecms.contenttypes.ContentTypesManager;
import org.librecms.lifecycle.LifecycleDefinition;
import java.nio.charset.IllegalCharsetNameException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
import java.util.ResourceBundle;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;
/**
* A controller class for the {@link ContentTypeAdminPane} and its associated
* classes. For now it only contains methods which require or transaction (which
* are controlled by the container now).
*
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
class ContentTypeAdminPaneController {
@Inject
private EntityManager entityManager;
@Inject
private ContentSectionRepository sectionRepo;
@Inject
private ContentSectionManager sectionManager;
@Inject
private ContentTypeRepository typeRepo;
@Inject
private ContentTypeManager typeManager;
@Inject
private ContentTypesManager typesManager;
@Transactional(Transactional.TxType.REQUIRED)
protected List<String[]> getTypeList(final ContentSection section) {
final List<ContentType> types = typeRepo.findByContentSection(section);
return types.stream()
.map(type -> generateListEntry(type))
.collect(Collectors.toList());
}
@Transactional
protected List<String> getContentItemClassesList(
final ContentSection ofSection
) {
final ContentSection section = sectionRepo.findById(
ofSection.getObjectId()
)
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No ContentSection with ID %d found.",
ofSection.getObjectId()
)
)
);
return section.getContentTypes()
.stream()
.map(type -> type.getContentItemClass())
.collect(Collectors.toList());
}
private String[] generateListEntry(final ContentType type) {
final String[] entry = new String[2];
entry[0] = Long.toString(type.getObjectId());
final ContentTypeInfo typeInfo = typesManager
.getContentTypeInfo(type.getContentItemClass());
final ResourceBundle labelBundle = ResourceBundle
.getBundle(typeInfo.getLabelBundle());
final String labelKey = typeInfo.getLabelKey();
entry[1] = labelBundle.getString(labelKey);
return entry;
}
@Transactional(Transactional.TxType.REQUIRED)
protected List<ContentTypeInfo> getNotAssociatedContentTypes(
final ContentSection section) {
final List<ContentTypeInfo> availableTypes = typesManager
.getAvailableContentTypes();
final List<ContentTypeInfo> associatedTypes = typeRepo
.findByContentSection(section)
.stream()
.map(type -> typesManager.getContentTypeInfo(type))
.collect(Collectors.toList());
return availableTypes
.stream()
.filter(typeInfo -> !associatedTypes.contains(typeInfo))
.collect(Collectors.toList());
}
@Transactional(Transactional.TxType.REQUIRED)
protected LifecycleDefinition getLifecycleDefinition(final ContentType type) {
final ContentType contentType = typeRepo
.findById(type.getObjectId())
.orElseThrow(() -> new IllegalCharsetNameException(String.format(
"No ContentType with Id %d in the database. "
+ "Where did that ID come from?",
type.getObjectId())));
return contentType.getDefaultLifecycle();
}
@Transactional(Transactional.TxType.REQUIRED)
protected Optional<String> getLifecycleDefinitionLabel(
final ContentType type,
final Locale locale) {
final LifecycleDefinition lifecycleDefinition = getLifecycleDefinition(
type);
if (lifecycleDefinition == null) {
return Optional.empty();
} else {
return Optional.of(lifecycleDefinition.getLabel().getValue(locale));
}
}
@Transactional(Transactional.TxType.REQUIRED)
protected Workflow getWorkflowTemplate(final ContentType type) {
final ContentType contentType = typeRepo
.findById(type.getObjectId())
.orElseThrow(() -> new IllegalCharsetNameException(String.format(
"No ContentType with Id %d in the database. "
+ "Where did that ID come from?",
type.getObjectId())));
return contentType.getDefaultWorkflow();
}
@Transactional(Transactional.TxType.REQUIRED)
protected Optional<String> getWorkflowTemplateName(final ContentType type,
final Locale locale) {
final Workflow workflowTemplate = getWorkflowTemplate(type);
if (workflowTemplate == null) {
return Optional.empty();
} else {
return Optional.of(workflowTemplate.getName().getValue(locale));
}
}
@Transactional(Transactional.TxType.REQUIRED)
protected List<LifecycleDefinition> getLifecycleDefinitions(
final ContentSection section) {
final ContentSection contentSection = sectionRepo
.findById(section.getObjectId())
.orElseThrow(() -> new IllegalArgumentException(String.format(
"No ContentSection with ID %d in the database. "
+ "Where did that ID come from?",
section.getObjectId())));
return new ArrayList<>(contentSection.getLifecycleDefinitions());
}
@Transactional(Transactional.TxType.REQUIRED)
protected List<Workflow> getWorkflowTemplates(
final ContentSection section) {
final ContentSection contentSection = sectionRepo
.findById(section.getObjectId())
.orElseThrow(() -> new IllegalArgumentException(String.format(
"No ContentSection with ID %d in the database. "
+ "Where did that ID come from?",
section.getObjectId())));
return new ArrayList<>(contentSection.getWorkflowTemplates());
}
@Transactional(Transactional.TxType.REQUIRED)
protected void addContentTypeToContentSection(
final String type, final ContentSection toSection
) {
Objects.requireNonNull(type);
Objects.requireNonNull(toSection);
final ContentSection section = sectionRepo
.findById(toSection.getObjectId())
.orElseThrow(
() -> new IllegalArgumentException(
String.format(
"No ContentSection identified by ID %d found.",
toSection.getObjectId()
)
)
);
sectionManager.addContentTypeToSection(
typeManager.classNameToClass(type),
section,
section.getLifecycleDefinitions().get(0),
section.getWorkflowTemplates().get(0)
);
}
}

View File

@ -1,355 +0,0 @@
/*
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.type;
import com.arsdigita.bebop.ActionLink;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.event.ActionEvent;
import com.arsdigita.bebop.event.ActionListener;
import com.arsdigita.bebop.form.Submit;
import com.arsdigita.cms.CMS;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentType;
import com.arsdigita.cms.ui.BaseItemPane;
import com.arsdigita.cms.ui.ContentSectionRequestLocal;
//ToDo import com.arsdigita.cms.ui.templates.SectionTemplatesListing;
//ToDo import com.arsdigita.cms.ui.templates.TemplateCreate;
import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
import com.arsdigita.toolbox.ui.ActionGroup;
import com.arsdigita.toolbox.ui.Cancellable;
import com.arsdigita.toolbox.ui.Section;
import com.arsdigita.util.UncheckedWrapperException;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.ContentSectionManager;
import org.librecms.contentsection.ContentTypeManager;
import org.librecms.contentsection.privileges.AdminPrivileges;
/**
*
* @author Justin Ross &lt;jross@redhat.com&gt;
* @author <a href="jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
final class ContentTypeItemPane extends BaseItemPane {
private final ACSObjectSelectionModel m_model;
private final ContentTypeRequestLocal m_type;
private final SimpleContainer m_detailPane;
// Only useful for user definied content types private final TypeElements m_elements;
// Only useful for user definied content types private final AddElement m_elementAddForm;
// ToDo private final SectionTemplatesListing m_templates;
private final TypePermissionsTable m_permissions;
ContentTypeItemPane(final ACSObjectSelectionModel model,
final ContentTypeRequestLocal type,
final ActionLink editLink,
final ActionLink deleteLink) {
m_model = model;
m_type = type;
m_detailPane = new SimpleContainer();
add(m_detailPane);
setDefault(m_detailPane);
// m_elements = new TypeElements(m_model);
// m_elementAddForm = new AddElement();
// ToDo
// m_templates = new SectionTemplatesListing(
// new ContentSectionRequestLocal(), m_type);
m_permissions = new TypePermissionsTable(
new ContentSectionRequestLocal(), m_type);
final ActionLink templateAddLink = new ActionLink(new Label(gz(
"cms.ui.type.template.add")));
// ToDo
// final TemplateCreate templateFormSection = new TemplateCreate(m_model);
// final Form templateForm = new CancellableForm("AddTemplate",
// templateFormSection.
// getSaveCancelSection().getCancelButton());
// templateForm.add(templateFormSection);
// add(templateForm);
// final AddTextElement textForm = new AddTextElement(m_model);
// add(textForm);
//
// final AddNumberElement numberForm = new AddNumberElement(m_model);
// add(numberForm);
//
// final AddDateElement dateForm = new AddDateElement(m_model);
// add(dateForm);
//
// final AddTextAssetElement assetForm = new AddTextAssetElement(m_model);
// add(assetForm);
//
// final AddImageElement imageForm = new AddImageElement(m_model);
// add(imageForm);
//
// final AddFileElement fileForm = new AddFileElement(m_model);
// add(fileForm);
//
// final AddContentItemElement itemForm
// = new AddContentItemElement(m_model);
// add(itemForm);
m_detailPane.add(new SummarySection(editLink, deleteLink));
// m_detailPane.add(new RelationAttributeSection());
m_detailPane.add(new TypeSecurityContainer(new ElementSection()));
m_detailPane.add(new TemplateSection(templateAddLink));
//m_detailPane.add(new PermissionsSection(permissionAddLink));
m_detailPane.add(new PermissionsSection());
// connect(templateAddLink, templateForm);
// connect(permissionAddLink, permissionsForm);
// final SingleSelect elementSelect
// = m_elementAddForm.getElementTypeSelect();
//
// connect(m_elementAddForm, elementSelect,
// AddElement.TEXT_ELEMENT, textForm);
// connect(textForm);
//
// connect(m_elementAddForm, elementSelect,
// AddElement.NUMBER_ELEMENT, numberForm);
// connect(numberForm);
//
// connect(m_elementAddForm, elementSelect,
// AddElement.DATE_ELEMENT, dateForm);
// connect(dateForm);
//
// connect(m_elementAddForm, elementSelect,
// AddElement.TEXT_ASSET_ELEMENT, assetForm);
// connect(assetForm);
//
// connect(m_elementAddForm, elementSelect,
// AddElement.IMAGE_ELEMENT, imageForm);
// connect(imageForm);
//
// connect(m_elementAddForm, elementSelect,
// AddElement.FILE_ELEMENT, fileForm);
// connect(fileForm);
//
// connect(m_elementAddForm, elementSelect,
// AddElement.CONTENT_ITEM_ELEMENT, itemForm);
// connect(itemForm);
}
// XXX A temporary, low-impact fix.
private class CancellableForm extends Form implements Cancellable {
private final Submit m_cancel;
CancellableForm(final String name, final Submit cancel) {
super(name);
m_cancel = cancel;
}
public final boolean isCancelled(final PageState state) {
return m_cancel.isSelected(state);
}
}
private class SummarySection extends Section {
SummarySection(final ActionLink editLink,
final ActionLink deleteLink) {
setHeading(new Label(gz("cms.ui.type.details")));
final ActionGroup group = new ActionGroup();
setBody(group);
group.setSubject(new ContentTypePropertyList(m_type));
group.addAction(new TypeSecurityContainer(editLink));
group.addAction(new TypeSecurityContainer(deleteLink));
}
}
private class ElementSection extends Section {
ElementSection() {
setHeading(new Label(gz("cms.ui.type.elements")));
final ActionGroup group = new ActionGroup();
setBody(group);
// group.setSubject(m_elements);
// group.addAction(m_elementAddForm);
}
@Override
public final boolean isVisible(final PageState state) {
// return m_model.isSelected(state) && isDynamicType(state)
// && !ContentSection.getConfig().getHideUDCTUI();
return false;
}
}
private class TemplateSection extends Section {
TemplateSection(final ActionLink templateAddLink) {
setHeading(new Label(gz("cms.ui.type.templates")));
final ActionGroup group = new ActionGroup();
setBody(group);
// ToDo group.setSubject(m_templates);
group.addAction(new TypeSecurityContainer(templateAddLink));
}
@Override
public final boolean isVisible(final PageState state) {
return m_model.isSelected(state) && !isDynamicType(state);
}
}
private class PermissionsSection extends Section {
public PermissionsSection() {
setHeading(new Label(gz("cms.ui.type.permissions")));
final ActionGroup group = new ActionGroup();
setBody(group);
group.setSubject(m_permissions);
//group.addAction(new TypeSecurityContainer(permissionsAddLink));
}
@Override
public final boolean isVisible(final PageState state) {
return m_model.isSelected(state) && !isDynamicType(state);
}
}
// private class RelationAttributeSection extends Section {
//
// RelationAttributeSection() {
// setHeading(new Label(gz("cms.ui.type.attributes")));
//
// setBody(new RelationAttributeList(m_type));
// }
//
// @Override
// public final boolean isVisible(final PageState state) {
//// ISt es möglich, den folgenden Code nur einmal zu haben?? Kann man auf die isVisible von RelationAttributeList
// // zurückgreifen??
// boolean retVal = false;
// ContentType ct = (ContentType) m_type.getContentType(state);
// ContentItem ci = null;
//
// try {
// Class<? extends ContentItem> clazz = Class.forName(ct.
// getClassName()).asSubclass(ContentItem.class);
// ci = clazz.newInstance();
// if (ci instanceof RelationAttributeInterface) {
// RelationAttributeInterface rai
// = (RelationAttributeInterface) ci;
// retVal = rai.hasRelationAttributes();
// }
// ci.delete();
// } catch (Exception ex) {
// //retVal = false;
// }
//
// return retVal;
// }
// }
@Override
public final void register(final Page page) {
super.register(page);
page.addActionListener(new ActionListener() {
@Override
public final void actionPerformed(final ActionEvent event) {
final PageState state = event.getPageState();
if (state.isVisibleOnPage(ContentTypeItemPane.this)
&& m_model.isSelected(state)
&& !userCanEdit(state)) {
// m_templates.getRemoveColumn().setVisible(state, false);
// m_templates.getDefaultColumn().setVisible(state, false);
// m_elements.getTable().getColumn(3).setVisible(state, false);
}
}
});
}
/**
* Unregister a content type from a content section.
*/
private void removeType(final PageState state) {
final ContentSection section = CMS.getContext().getContentSection();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentTypeManager typeManager = cdiUtil.findBean(
ContentTypeManager.class);
final ContentSectionManager sectionManager = cdiUtil.findBean(
ContentSectionManager.class);
final ContentType type = m_type.getContentType(state);
final Class<? extends ContentItem> typeClass;
try {
typeClass = (Class<? extends ContentItem>) Class.forName(
type.getContentItemClass());
} catch (ClassNotFoundException ex) {
throw new UncheckedWrapperException(ex);
}
sectionManager.removeContentTypeFromSection(typeClass, section);
}
/**
* Determine if the current user has access to edit the content type
*/
protected static boolean userCanEdit(final PageState state) {
final PermissionChecker permissionChecker = CdiUtil.createCdiUtil()
.findBean(PermissionChecker.class);
final ContentSection section = CMS.getContext().getContentSection();
return permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_CONTENT_TYPES, section);
}
/**
* utility method get the DataObject from the DataBase, returns true if it
* is a modifiable type, false otherwise.
*
* Because we don't have modifiable types aka User Definied Content Types in
* CCM NG yet, this method returns always false for now.
*/
protected final boolean isDynamicType(final PageState state) {
return false;
}
}

View File

@ -1,90 +0,0 @@
/*
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.type;
import com.arsdigita.bebop.List;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.list.ListModel;
import com.arsdigita.bebop.list.ListModelBuilder;
import com.arsdigita.cms.CMS;
import org.librecms.contentsection.ContentSection;
import com.arsdigita.util.LockableImpl;
import org.libreccm.cdi.utils.CdiUtil;
import java.util.NoSuchElementException;
/**
* Builds a dynamic list of content types for a content section.
*/
class ContentTypeListModelBuilder
extends LockableImpl
implements ListModelBuilder {
/**
*
* @param list
* @param state
*
* @return
*/
@Override
public ListModel makeModel(final List list, final PageState state) {
return new Model();
}
/**
*
*/
private class Model implements ListModel {
private final java.util.List<String[]> types;
private int index = -1;
Model() {
final ContentSection section = CMS.getContext().getContentSection();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentTypeAdminPaneController controller = cdiUtil.findBean(
ContentTypeAdminPaneController.class);
types = controller.getTypeList(section);
}
@Override
public boolean next() throws NoSuchElementException {
index++;
return index < types.size();
}
@Override
public Object getElement() {
return types.get(index)[1];
}
@Override
public String getKey() {
return types.get(index)[0];
}
}
}

View File

@ -1,141 +0,0 @@
/*
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.type;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.CMS;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentType;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.kernel.KernelConfig;
import com.arsdigita.toolbox.ui.Property;
import com.arsdigita.toolbox.ui.PropertyList;
import org.libreccm.cdi.utils.CdiUtil;
import java.util.Locale;
import org.librecms.CmsConstants;
import org.librecms.contenttypes.ContentTypeInfo;
import org.librecms.contenttypes.ContentTypesManager;
import java.util.List;
import java.util.Optional;
import java.util.ResourceBundle;
/**
* This component displays basic attributes of a content type including:
*
* label, description, default lifecycle definition, default workflow template
*
* @author Michael Pih
* @author <a href="mailto:jross@redhat.com">Justin Ross</a>
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class ContentTypePropertyList extends PropertyList {
private final ContentTypeRequestLocal m_type;
public ContentTypePropertyList(final ContentTypeRequestLocal type) {
m_type = type;
}
@Override
protected final List<Property> properties(final PageState state) {
final List<Property> props = super.properties(state);
final ContentType type = m_type.getContentType(state);
final ContentSection section = CMS.getContext().getContentSection();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentTypesManager typesManager = cdiUtil
.findBean(ContentTypesManager.class);
final ContentTypeInfo typeInfo = typesManager.getContentTypeInfo(type);
final KernelConfig kernelConfig = KernelConfig.getConfig();
final Locale defaultLocale = kernelConfig.getDefaultLocale();
final ResourceBundle labelBundle = ResourceBundle
.getBundle(typeInfo.getLabelBundle());
final ResourceBundle descBundle = ResourceBundle
.getBundle(typeInfo.getDescriptionBundle());
props.add(new Property(gz("cms.ui.name"),
labelBundle.getString(typeInfo.getLabelKey())));
props.add(new Property(gz("cms.ui.description"),
descBundle
.getString(typeInfo.getDescriptionKey())));
// props.add(new Property(gz("cms.ui.type.parent"),
// type.getParent().orElse(null)));
props.add(new Property(gz("cms.ui.type.lifecycle"),
getLifecycle(section, type)));
props.add(new Property(gz("cms.ui.type.workflow"),
getWorkflow(section, type)));
return props;
}
private String getLifecycle(final ContentSection section,
final ContentType type) {
final KernelConfig kernelConfig = KernelConfig.getConfig();
final Locale defaultLocale = kernelConfig.getDefaultLocale();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentTypeAdminPaneController controller = cdiUtil
.findBean(ContentTypeAdminPaneController.class);
final Optional<String> label = controller
.getLifecycleDefinitionLabel(type, defaultLocale);
if (label.isPresent()) {
return label.get();
} else {
return lz("cms.ui.type.lifecycle.none");
}
}
private String getWorkflow(final ContentSection section,
final ContentType type) {
final KernelConfig kernelConfig = KernelConfig.getConfig();
final Locale defaultLocale = kernelConfig.getDefaultLocale();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentTypeAdminPaneController controller = cdiUtil
.findBean(ContentTypeAdminPaneController.class);
final Optional<String> name = controller
.getWorkflowTemplateName(type, defaultLocale);
if (name.isPresent()) {
return name.get();
} else {
return lz("cms.ui.type.workflow.none");
}
}
private static GlobalizedMessage gz(final String key) {
return new GlobalizedMessage(key, CmsConstants.CMS_BUNDLE);
}
private static String lz(final String key) {
return (String) gz(key).localize();
}
}

View File

@ -1,34 +0,0 @@
/*
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.type;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.RequestLocal;
import org.librecms.contentsection.ContentType;
public abstract class ContentTypeRequestLocal extends RequestLocal {
@Override
protected abstract Object initialValue(final PageState state);
public final ContentType getContentType(final PageState state) {
return (ContentType) get(state);
}
}

View File

@ -1,386 +0,0 @@
/*
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.type;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.Text;
import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.PrintEvent;
import com.arsdigita.bebop.event.PrintListener;
import com.arsdigita.bebop.form.Hidden;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.form.SingleSelect;
import com.arsdigita.bebop.form.Submit;
import com.arsdigita.bebop.parameters.LongParameter;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.cms.CMS;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentType;
import org.librecms.lifecycle.LifecycleDefinition;
import com.arsdigita.cms.ui.CMSForm;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.kernel.KernelConfig;
import com.arsdigita.util.UncheckedWrapperException;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.workflow.Workflow;
import org.libreccm.workflow.WorkflowRepository;
import org.librecms.CmsConstants;
import org.librecms.contentsection.ContentTypeManager;
import org.librecms.contentsection.ContentTypeRepository;
import org.librecms.lifecycle.LifecycleDefinitionRepository;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.TooManyListenersException;
/**
* This class contains a form component to edit a content type
*
* @author Jack Chung (flattop@arsdigita.com)
* @author Michael Pih (pihman@arsdigita.com)
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class EditType extends CMSForm
implements FormInitListener, FormProcessListener {
private static final Logger LOGGER = LogManager.getLogger(EditType.class);
private final SingleSelectionModel<String> selectedTypeModel;
// Form widgets
private final Hidden idField;
// private TextField m_label;
// private TextArea m_description;
private final SingleSelect lifecycleSelect;
private final SingleSelect workflowSelect;
private final Submit submitButton;
private final Submit cancelButton;
/**
* @param selectedTypeModel The content type selection model. This tells the
* form which content type is selected.
*/
public EditType(final SingleSelectionModel<String> selectedTypeModel) {
super("EditContentType");
this.selectedTypeModel = selectedTypeModel;
idField = new Hidden(new LongParameter("id"));
idField.addValidationListener(new NotNullValidationListener());
super.add(idField);
// add(new Label(new GlobalizedMessage("cms.ui.type.label",
// CmsConstants.CMS_BUNDLE)));
// m_label = new TextField(new StringParameter("label"));
// m_label.addValidationListener(new NotNullValidationListener());
// m_label.setSize(40);
// m_label.setMaxLength(1000);
// add(m_label);
//
// add(new Label(new GlobalizedMessage("cms.ui.description",
// CmsConstants.CMS_BUNDLE)));
// m_description = new TextArea(new StringParameter("description"));
// m_description.addValidationListener(
// new StringLengthValidationListener(4000));
// m_description.setCols(40);
// m_description.setRows(5);
// m_description.setWrap(TextArea.SOFT);
// add(m_description);
super.add(new Label(new GlobalizedMessage("cms.ui.type.lifecycle",
CmsConstants.CMS_BUNDLE)));
lifecycleSelect = new SingleSelect(new LongParameter("lifecycle"));
try {
lifecycleSelect.addPrintListener(new SelectLifecyclePrintListener());
} catch (TooManyListenersException e) {
throw new UncheckedWrapperException("TooManyListeners: " + e
.getMessage(), e);
}
super.add(lifecycleSelect);
super.add(new Label(new GlobalizedMessage("cms.ui.type.workflow",
CmsConstants.CMS_BUNDLE)));
workflowSelect = new SingleSelect(new LongParameter("workflow"));
try {
workflowSelect.addPrintListener(new SelectWorkflowPrintListener());
} catch (TooManyListenersException ex) {
throw new UncheckedWrapperException("TooManyListeners: " + ex
.getMessage(), ex);
}
super.add(workflowSelect);
final SimpleContainer buttonContainer = new SimpleContainer();
submitButton = new Submit(new GlobalizedMessage("cms.ui.save",
CmsConstants.CMS_BUNDLE));
buttonContainer.add(submitButton);
cancelButton = new Submit(new GlobalizedMessage("cms.ui.cancel",
CmsConstants.CMS_BUNDLE));
buttonContainer.add(cancelButton);
super.add(buttonContainer, ColumnPanel.FULL_WIDTH | ColumnPanel.CENTER);
super.addInitListener(this);
super.addSubmissionListener(new TypeSecurityListener());
super.addProcessListener(this);
}
/**
* Returns true if the "cancel" button was submitted.
*
* @param state The page state
*
* @return True if the form was cancelled, false otherwise
*/
@Override
public boolean isCancelled(final PageState state) {
return cancelButton.isSelected(state);
}
/**
* Returns the "cancel" button on the form
*
* @return the cancel button on the form
*/
public Submit getCancelButton() {
return cancelButton;
}
/**
* Populates the form with the content type properties.
*
* @param event
*/
@Override
public void init(final FormSectionEvent event) {
final FormData data = event.getFormData();
final PageState state = event.getPageState();
// final ContentSection section = CMS.getContext().getContentSection();
//
// final KernelConfig kernelConfig = KernelConfig.getConfig();
final ContentType type = getContentType(state);
final long typeId = type.getObjectId();
// final String label = type.getLabel().getValue(kernelConfig
// .getDefaultLocale());
// final String description = type.getDescription().getValue(kernelConfig
// .getDefaultLocale());
data.put(idField.getName(), typeId);
// data.put(m_label.getName(), label);
// data.put(m_description.getName(), description);
final LifecycleDefinition cycle = type.getDefaultLifecycle();
if (cycle != null) {
data.put(lifecycleSelect.getName(), cycle.getDefinitionId());
}
final Workflow template = type.getDefaultWorkflow();
if (template != null) {
data.put(workflowSelect.getName(), template.getWorkflowId());
}
}
/**
* Fetches the currently selected content type from the single selection
* model.
*/
private ContentType getContentType(final PageState state) {
final String key = selectedTypeModel.getSelectedKey(state);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentTypeRepository typeRepo = cdiUtil.findBean(
ContentTypeRepository.class);
final Optional<ContentType> result;
try {
result = typeRepo.findByIdAndFetchAttributes(Long.parseLong(key),
"defaultLifecycle",
"defaultWorkflow");
} catch (NumberFormatException ex) {
throw new UncheckedWrapperException(String.format(
"The provided key \"%s\" is not a long.", key),
ex);
}
if (result.isPresent()) {
return result.get();
} else {
throw new UncheckedWrapperException(String.format(
"ContentType with ID %s not found.", key));
}
}
/**
* Edits the content type.
*
* @param event
*
* @throws FormProcessException
*/
@Override
public void process(final FormSectionEvent event) throws
FormProcessException {
final FormData data = event.getFormData();
// Get the current content section.
final ContentSection section = CMS.getContext().getContentSection();
// Read form variables.
final Long key = (Long) data.get(idField.getName());
// final String label = (String) data.get(m_label.getName());
// final String description = (String) data.get(m_description.getName());
final Long lifecycleId = (Long) data.get(lifecycleSelect.getName());
final Long workflowId = (Long) data.get(workflowSelect.getName());
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentTypeRepository typeRepo = cdiUtil.findBean(
ContentTypeRepository.class);
final LifecycleDefinitionRepository lifecycleDefRepo = cdiUtil.findBean(
LifecycleDefinitionRepository.class);
final WorkflowRepository workflowRepo = cdiUtil
.findBean(WorkflowRepository.class);
final ContentTypeManager typeManager = cdiUtil.findBean(
ContentTypeManager.class);
final Optional<ContentType> type = typeRepo.findById(key);
if (!type.isPresent()) {
LOGGER.error("Can't find ContentType with key {}", key);
throw new FormProcessException(new GlobalizedMessage(
"cms.ui.type.content_editing_failed",
CmsConstants.CMS_BUNDLE,
new Object[]{key}));
}
// final KernelConfig kernelConfig = KernelConfig.getConfig();
// type.get().getLabel().putValue(kernelConfig.getDefaultLocale(), label);
// type.get().getDescription().putValue(kernelConfig.getDefaultLocale(),
// description);
typeRepo.save(type.get());
// Handle default lifecycle and workflow.
final LifecycleDefinition defaultLifecycle;
if (lifecycleId == 0) {
defaultLifecycle = null;
} else {
defaultLifecycle = lifecycleDefRepo.findById(lifecycleId).get();
}
final Workflow defaultWorkflow;
if (workflowId == 0) {
defaultWorkflow = null;
} else {
defaultWorkflow = workflowRepo.findById(workflowId).get();
}
typeManager.setDefaultLifecycle(type.get(), defaultLifecycle);
typeManager.setDefaultWorkflow(type.get(), defaultWorkflow);
}
/**
* Print listener to generate the select widget for the list of lifecyle
* definitions.
*/
private class SelectLifecyclePrintListener implements PrintListener {
@Override
public void prepare(final PrintEvent event) {
final SingleSelect lifecycleSelect = (SingleSelect) event
.getTarget();
lifecycleSelect.clearOptions();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentTypeAdminPaneController controller = cdiUtil
.findBean(ContentTypeAdminPaneController.class);
// Get the current content section
ContentSection section = CMS.getContext().getContentSection();
lifecycleSelect.addOption(new Option(
"0",
new Label(new GlobalizedMessage("cms.ui.type.lifecycle.select",
CmsConstants.CMS_BUNDLE))));
final List<LifecycleDefinition> cycles = controller
.getLifecycleDefinitions(section);
final Locale defaultLocale = KernelConfig.getConfig()
.getDefaultLocale();
cycles.forEach(cycle -> {
lifecycleSelect.addOption(
new Option(Long.toString(cycle.getDefinitionId()),
new Text(cycle.getLabel().getValue(defaultLocale))));
});
}
}
/**
* Print listener to generate the select widget for the list of workflow
* templates.
*/
private class SelectWorkflowPrintListener implements PrintListener {
@Override
public void prepare(final PrintEvent event) {
final SingleSelect workflowSelect = (SingleSelect) event.getTarget();
workflowSelect.clearOptions();
// Get the current content section
ContentSection section = CMS.getContext().getContentSection();
workflowSelect.addOption(new Option(
"0",
new Label(new GlobalizedMessage("cms.ui.type.workflow.select",
CmsConstants.CMS_BUNDLE))));
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentTypeAdminPaneController controller = cdiUtil
.findBean(ContentTypeAdminPaneController.class);
final List<Workflow> templates = controller
.getWorkflowTemplates(section);
final Locale defaultLocale = KernelConfig.getConfig()
.getDefaultLocale();
templates.forEach(template -> {
workflowSelect.addOption(
new Option(
Long.toString(template.getWorkflowId()),
new Text(template.getName().getValue(defaultLocale))));
});
}
}
}

View File

@ -1,211 +0,0 @@
/*
* Copyright (C) 2001-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.type;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.FormSubmissionListener;
import com.arsdigita.bebop.event.PrintEvent;
import com.arsdigita.bebop.event.PrintListener;
import com.arsdigita.bebop.form.CheckboxGroup;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.form.Submit;
import com.arsdigita.cms.CMS;
import org.librecms.contentsection.ContentSection;
import com.arsdigita.cms.ui.CMSForm;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.ui.admin.GlobalizationUtil;
import com.arsdigita.util.UncheckedWrapperException;
import org.libreccm.cdi.utils.CdiUtil;
import org.librecms.CmsConstants;
import org.librecms.contentsection.ContentSectionManager;
import org.librecms.contentsection.ContentTypeManager;
import org.librecms.contenttypes.ContentTypeInfo;
import org.librecms.contenttypes.ContentTypesManager;
import java.util.List;
import java.util.TooManyListenersException;
import java.util.stream.Collectors;
/**
* This class contains a form component to that allows adding already-existing
* content type to a content section.
*
* @author Jack Chung
* @author Michael Pih
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class SelectType extends CMSForm implements PrintListener,
FormSubmissionListener,
FormProcessListener {
private final static String TYPES = "types";
private CheckboxGroup m_typesCheckbox;
private Submit m_submit;
private Submit m_cancel;
public SelectType() {
super("ContentTypeSelect");
m_typesCheckbox = new CheckboxGroup(TYPES);
try {
m_typesCheckbox.addPrintListener(this);
} catch (TooManyListenersException e) {
throw new UncheckedWrapperException("TooManyListeners: " + e
.getMessage());
}
add(new Label(new GlobalizedMessage("cms.ui.type.available_types",
CmsConstants.CMS_BUNDLE)));
add(m_typesCheckbox);
SimpleContainer s = new SimpleContainer();
m_submit = new Submit("submit");
m_submit.setButtonLabel("Add Selected Content Types");
s.add(m_submit);
m_cancel = new Submit("cancel");
m_cancel.setButtonLabel("Cancel");
s.add(m_cancel);
add(s, ColumnPanel.FULL_WIDTH | ColumnPanel.CENTER);
addProcessListener(this);
addSubmissionListener(new TypeSecurityListener());
addSubmissionListener(this);
}
/**
* Generate a checkbox list of all content type not associated with the
* current content section
* @param event
*/
@Override
public void prepare(final PrintEvent event) {
final CheckboxGroup target = (CheckboxGroup) event.getTarget();
// Get the current content section
final ContentSection section = CMS.getContext().getContentSection();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentTypeAdminPaneController controller = cdiUtil
.findBean(ContentTypeAdminPaneController.class);
final ContentTypesManager typesManager = cdiUtil.findBean(
ContentTypesManager.class);
final List<ContentTypeInfo> availableTypes = typesManager
.getAvailableContentTypes();
final List<String> assignedTypes = controller
.getContentItemClassesList(section);
// = section.getContentTypes()
// .stream()
// .map(contentType -> contentType.getContentItemClass())
// .collect(Collectors.toList());
final List<ContentTypeInfo> notAssignedTypes = availableTypes.stream()
.filter(type -> !assignedTypes.contains(type.getContentItemClass()
.getName()))
.collect(Collectors.toList());
for (final ContentTypeInfo typeInfo : notAssignedTypes) {
addOption(target, typeInfo);
}
}
private void addOption(final CheckboxGroup target,
final ContentTypeInfo typeInfo) {
final Label label = new Label(new GlobalizedMessage(typeInfo
.getLabelKey(), typeInfo.getLabelBundle()));
target.addOption(new Option(typeInfo.getContentItemClass().getName(),
label));
}
/**
* Form submission listener. If the cancel button was pressed, do not
* process the form.
*
* @param event The submit event
*
* @throws com.arsdigita.bebop.FormProcessException
*/
@Override
public void submitted(final FormSectionEvent event) throws
FormProcessException {
PageState state = event.getPageState();
if (isCancelled(state)) {
throw new FormProcessException(GlobalizationUtil.globalize(
"cms.ui.cancelled"));
}
}
/**
* Returns true if this form was cancelled.
*
* @return true if the form was cancelled, false otherwise
*/
@Override
public boolean isCancelled(final PageState state) {
return m_cancel.isSelected(state);
}
/**
* Processes form listener which updates a life cycle
*
* @param event
*
* @throws com.arsdigita.bebop.FormProcessException
*/
@Override
public void process(final FormSectionEvent event)
throws FormProcessException {
final ContentSection section = CMS.getContext().getContentSection();
final FormData data = event.getFormData();
final String[] types = (String[]) data.get(TYPES);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
// final ContentTypeManager typeManager = cdiUtil.findBean(
// ContentTypeManager.class);
// final ContentSectionManager sectionManager = cdiUtil.findBean(
// ContentSectionManager.class);
final ContentTypeAdminPaneController controller = cdiUtil
.findBean(ContentTypeAdminPaneController.class);
if (types != null) {
for (String type : types) {
// sectionManager.addContentTypeToSection(
// typeManager.classNameToClass(type),
// section,
// section.getLifecycleDefinitions().get(0),
// section.getWorkflowTemplates().get(0));
controller.addContentTypeToContentSection(type, section);
}
}
}
}

View File

@ -1,262 +0,0 @@
package com.arsdigita.cms.ui.type;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.ControlLink;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.Text;
import com.arsdigita.bebop.event.TableActionEvent;
import com.arsdigita.bebop.event.TableActionListener;
import com.arsdigita.bebop.table.RowData;
import com.arsdigita.bebop.table.TableCellRenderer;
import com.arsdigita.bebop.table.TableColumn;
import com.arsdigita.bebop.table.TableColumnModel;
import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.cms.CMS;
import org.librecms.contentsection.ContentType;
import com.arsdigita.cms.ui.ContentSectionRequestLocal;
import com.arsdigita.globalization.GlobalizedMessage;
import org.libreccm.security.Role;
import com.arsdigita.util.LockableImpl;
import java.util.List;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.security.PermissionChecker;
import org.libreccm.security.RoleRepository;
import org.librecms.CmsConstants;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.privileges.AdminPrivileges;
import java.util.Iterator;
/**
*
* ToDo, maybe not needed anymore...
*
* @author Jens Pelzetter
*/
public class TypePermissionsTable extends Table implements TableActionListener {
private final String TABLE_COL_ROLE = "table_col_role";
private final String TABLE_COL_CAN_USE = "table_col_can_use";
private final String TABLE_COL_ACTION = "table_col_action";
private final ContentTypeRequestLocal type;
public TypePermissionsTable(final ContentSectionRequestLocal section,
final ContentTypeRequestLocal type) {
super();
this.type = type;
setEmptyView(new Label(new GlobalizedMessage(
"cms.ui.type.permissions.none",
CmsConstants.CMS_BUNDLE)));
TableColumnModel columnModel = getColumnModel();
columnModel.add(new TableColumn(
0,
new GlobalizedMessage("cms.ui.type.permissions.role",
CmsConstants.CMS_BUNDLE).localize(),
TABLE_COL_ROLE));
columnModel.add(new TableColumn(
1,
new GlobalizedMessage("cms.ui.type.permissions_can_use",
CmsConstants.CMS_BUNDLE).localize(),
TABLE_COL_CAN_USE));
columnModel.add(new TableColumn(
2,
new GlobalizedMessage("cms.ui.type.permission.action",
CmsConstants.CMS_BUNDLE).localize(),
TABLE_COL_ACTION));
setModelBuilder(new TypePermissionsTableModelBuilder());
columnModel.get(0).setCellRenderer(new RoleCellRenderer());
columnModel.get(1).setCellRenderer(new CanUseCellRenderer());
columnModel.get(2).setCellRenderer(new ActionCellRenderer());
addTableActionListener(this);
}
@Override
public void cellSelected(final TableActionEvent event) {
final PageState state = event.getPageState();
final TableColumn column = getColumnModel().get(event.getColumn());
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final RoleRepository roleRepo = cdiUtil.findBean(RoleRepository.class);
final TypePermissionsTableController controller = cdiUtil.findBean(
TypePermissionsTableController.class);
if (TABLE_COL_ACTION.equals(column.getHeaderKey().toString())) {
final Role role = roleRepo.findById(Long.parseLong(
event.getRowKey().toString())).get();
ContentType contentType = getType().getContentType(state);
controller.toggleTypeUsePermission(contentType, role);
}
}
@Override
public void headSelected(final TableActionEvent event) {
//Nothing to do
}
private class TypePermissionsTableModelBuilder
extends LockableImpl
implements TableModelBuilder {
public TypePermissionsTableModelBuilder() {
}
@Override
public TableModel makeModel(final Table table, final PageState state) {
table.getRowSelectionModel().clearSelection(state);
return new TypePermissionsTableModel(table, state);
}
}
private class TypePermissionsTableModel implements TableModel {
private final Iterator<RowData<Long>> iterator;
private RowData<Long> currentRow;
public TypePermissionsTableModel(final Table table,
final PageState state) {
final ContentType contentType = ((TypePermissionsTable) table)
.getType()
.getContentType(state);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final TypePermissionsTableController controller = cdiUtil.findBean(
TypePermissionsTableController.class);
final ContentSection section = CMS.getContext().getContentSection();
final List<RowData<Long>> rows = controller.retrieveTypePermissions(
contentType, section);
iterator = rows.iterator();
}
@Override
public int getColumnCount() {
return 3;
}
@Override
public boolean nextRow() {
if (iterator.hasNext()) {
currentRow = iterator.next();
return true;
} else {
return false;
}
}
@Override
public Object getElementAt(final int columnIndex) {
switch (columnIndex) {
case 0:
return currentRow.getColData(0);
case 1:
return currentRow.getColData(1);
case 2:
if ("cms.ui.type.permissions.can_use.yes".equals(currentRow
.getColData(1))) {
return "cms.ui.type.permissions.actions.revoke";
} else {
return "cms.ui.type.permissions.can_use.grant";
}
default:
throw new IllegalArgumentException("Invalid column index.");
}
}
@Override
public Object getKeyAt(final int columnIndex) {
return currentRow.getRowKey();
}
}
private class RoleCellRenderer
extends LockableImpl
implements TableCellRenderer {
@Override
public Component getComponent(Table table,
PageState state,
Object value,
boolean isSelected,
Object key,
int row,
int column) {
return new Text(value.toString());
}
}
private class CanUseCellRenderer
extends LockableImpl
implements TableCellRenderer {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
final boolean isSelected,
final Object key,
final int row,
final int column) {
return new Label(new GlobalizedMessage(value.toString(),
CmsConstants.CMS_BUNDLE));
}
}
private class ActionCellRenderer
extends LockableImpl
implements TableCellRenderer {
@Override
public Component getComponent(final Table table,
final PageState state,
final Object value,
boolean isSelected,
final Object key,
final int row,
final int column) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
final ContentSection section = CMS.getContext().getContentSection();
if (permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_CONTENT_TYPES, section)) {
return new ControlLink(new Label(new GlobalizedMessage(
(String) value), CmsConstants.CMS_BUNDLE));
} else {
return new Text("");
}
}
}
private ContentTypeRequestLocal getType() {
return type;
}
}

View File

@ -1,114 +0,0 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.cms.ui.type;
import org.librecms.contentsection.privileges.TypePrivileges;
import com.arsdigita.bebop.table.RowData;
import org.libreccm.security.PermissionChecker;
import org.libreccm.security.PermissionManager;
import org.libreccm.security.Role;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentSectionRepository;
import org.librecms.contentsection.ContentType;
import org.librecms.contentsection.ContentTypeRepository;
import java.util.List;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
public class TypePermissionsTableController {
@Inject
private PermissionChecker permissionChecker;
@Inject
private PermissionManager permissionManager;
@Inject
private ContentSectionRepository sectionRepo;
@Inject
private ContentTypeRepository typeRepo;
@Transactional(Transactional.TxType.REQUIRED)
public List<RowData<Long>> retrieveTypePermissions(
final ContentType type, final ContentSection section) {
//Ensure that we use a sane object for the type
return retrieveTypePermissions(type.getObjectId(), section);
}
@Transactional(Transactional.TxType.REQUIRED)
public List<RowData<Long>> retrieveTypePermissions(
final long typeId, final ContentSection section) {
final ContentType type = typeRepo.findById(typeId).get();
final ContentSection contentSection = sectionRepo
.findById(section.getObjectId())
.orElseThrow(() -> new IllegalArgumentException(String.format(
"No ContentSection with ID %d in the database. "
+ "Where did that Id come from?",
section.getObjectId())));
final List<Role> roles = contentSection.getRoles();
return roles.stream()
.map(role -> retrievePermissionsForRole(type, role))
.collect(Collectors.toList());
}
private RowData<Long> retrievePermissionsForRole(final ContentType type,
final Role role) {
final RowData<Long> rowData = new RowData<>(2);
rowData.setRowKey(role.getRoleId());
rowData.setColData(0, role.getName());
if (permissionChecker.isPermitted(TypePrivileges.USE_TYPE, type)) {
rowData.setColData(1, "cms.ui.type.permissions.can_use.yes");
} else {
rowData.setColData(1, "cms.ui.type.permissions.can_use.no");
}
return rowData;
}
public void toggleTypeUsePermission(final ContentType type,
final Role role) {
if (permissionChecker.isPermitted(TypePrivileges.USE_TYPE, type, role)) {
permissionManager.revokePrivilege(TypePrivileges.USE_TYPE,
role,
type);
} else {
permissionManager.grantPrivilege(TypePrivileges.USE_TYPE,
role,
type);
}
}
}

View File

@ -1,55 +0,0 @@
/*
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.type;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.CMS;
import org.libreccm.security.Party;
import com.arsdigita.toolbox.ui.SecurityContainer;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.privileges.AdminPrivileges;
/**
*
* @author <a href="mailto:jross@redhat.com">Justin Ross</a>
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public final class TypeSecurityContainer extends SecurityContainer {
public TypeSecurityContainer(final Component component) {
super(component);
}
@Override
protected final boolean canAccess(final Party party,
final PageState state) {
final PermissionChecker permissionChecker = CdiUtil.createCdiUtil().findBean(PermissionChecker.class);
final ContentSection section = CMS.getContext().getContentSection();
return permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_CONTENT_TYPES, section);
}
}

View File

@ -1,51 +0,0 @@
/*
* Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
package com.arsdigita.cms.ui.type;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.FormSubmissionListener;
import com.arsdigita.cms.CMS;
import com.arsdigita.dispatcher.AccessDeniedException;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.privileges.AdminPrivileges;
/**
*
* @author Justin Ross &lt;jross@redhat.com&gt;
* @autor <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
final class TypeSecurityListener implements FormSubmissionListener {
@Override
public final void submitted(final FormSectionEvent event)
throws FormProcessException {
final ContentSection section = CMS.getContext().getContentSection();
final PermissionChecker permissionChecker = CdiUtil.createCdiUtil().findBean(PermissionChecker.class);
if (!permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_CONTENT_TYPES, section)) {
throw new AccessDeniedException();
}
}
}