Remove depcrecated package com.arsdigita.cms.ui.category from ccm-cms

pull/28/head
Jens Pelzetter 2022-03-17 19:33:16 +01:00
parent db0f16f21b
commit 70e723f4d6
33 changed files with 3 additions and 5470 deletions

View File

@ -34,7 +34,6 @@ import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection;
import com.arsdigita.cms.dispatcher.CMSPage;
import com.arsdigita.cms.ui.category.CategoryAdminPane;
import com.arsdigita.cms.ui.folder.FolderAdminPane;
import com.arsdigita.cms.ui.workflow.WorkflowAdminPane;
import com.arsdigita.globalization.GlobalizedMessage;
@ -131,8 +130,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
private WorkflowAdminPane m_workflowPane;
private CategoryAdminPane m_categoryPane;
/**
* Creates the content section index page containing - a Navigaton bar for
* the various tasks (items, search, images, ....) - a breadcrumb - ....
@ -150,7 +147,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
m_browsePane = getBrowsePane();
m_searchPane = getSearchPane();
m_workflowPane = getWorkflowAdminPane();
m_categoryPane = getCategoryAdminPane();
// The panes
m_tabbedPane = createTabbedPane();
@ -180,11 +176,7 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
m_workflowPane,
permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_WORKFLOWS));
m_tabbedPane.setTabVisible(
state,
m_categoryPane,
permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_CATEGORIES));
}
}
@ -245,17 +237,7 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
return m_workflowPane;
}
/**
* Creates, and then caches, the category administration pane. Overriding
* this method to return null will prevent this tab from appearing.
*/
protected CategoryAdminPane getCategoryAdminPane() {
if (m_categoryPane == null) {
m_categoryPane = new CategoryAdminPane();
}
return m_categoryPane;
}
/**
* Adds the specified component, with the specified tab name, to the tabbed
@ -301,7 +283,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
tab(pane, "cms.ui.browse", getBrowsePane());
tab(pane, "cms.ui.search", getSearchPane());
tab(pane, "cms.ui.workflows", getWorkflowAdminPane());
tab(pane, "cms.ui.categories", getCategoryAdminPane());
return pane;
}
@ -346,10 +327,7 @@ public class ContentSectionPage extends CMSPage implements ActionListener {
// m_rolePane.reset(state);
} else if (pane == m_workflowPane) {
m_workflowPane.reset(state);
} else if (pane == m_categoryPane) {
m_categoryPane.reset(state);
}
}
}
/**

View File

@ -1,140 +0,0 @@
/*
* Copyright (C) 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.category;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.ParameterEvent;
import com.arsdigita.bebop.parameters.GlobalizedParameterListener;
import com.arsdigita.bebop.parameters.ParameterData;
import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ui.BaseForm;
import com.arsdigita.kernel.KernelConfig;
import org.libreccm.categorization.Category;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.l10n.LocalizedString;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.privileges.AdminPrivileges;
/**
* TODO Needs a description.
*
* @author Scott Seago
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/
class AddUseContextForm extends BaseForm {
private final SingleSelectionModel m_model;
private final Name m_useContext;
private final Name m_rootName;
private final Description m_rootDescription;
AddUseContextForm(final SingleSelectionModel model) {
super("useContext", gz("cms.ui.category.add_use_context"));
m_model = model;
m_useContext = new Name("useContext", 200, true);
addField(gz("cms.ui.category.use_context"), m_useContext);
m_rootName = new Name("rootName", 200, true);
addField(gz("cms.ui.name"), m_rootName);
m_rootDescription = new Description("rootName", 200, true);
addField(gz("cms.ui.description"), m_rootDescription);
addAction(new Finish());
addAction(new Cancel());
addSecurityListener(AdminPrivileges.ADMINISTER_CATEGORIES);
m_useContext.addValidationListener(new ValidationListener());
addProcessListener(new ProcessListener());
}
private class ValidationListener extends GlobalizedParameterListener {
public ValidationListener() {
super();
setError(GlobalizationUtil.globalize("cms.ui.category.use_context_must_be_unique"));
}
public final void validate(final ParameterEvent e)
throws FormProcessException {
ParameterData data = e.getParameterData();
final String name = (String) m_useContext.getValue(e.getPageState());
// XXX Do a dupe check ala commented code below
//if (true) {//Category.getRootForObject(CMS.getContext().getContentSection(),
//name) != null) {
// data.addError(getError());
//}
}
}
private class ProcessListener implements FormProcessListener {
public final void process(final FormSectionEvent e)
throws FormProcessException {
final PageState state = e.getPageState();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ConfigurationManager manager = cdiUtil.findBean(ConfigurationManager.class);
final KernelConfig config = manager.findConfiguration(KernelConfig.class);
final String useContext = (String) m_useContext.getValue(state);
final String rootName = (String) m_rootName.getValue(state);
final LocalizedString rootDescription = new LocalizedString();
rootDescription.putValue(config.getDefaultLocale(), (String) m_rootDescription.getValue(state));
Category root = new Category();
root.setName(rootName);
root.setDescription(rootDescription);
root.setAbstractCategory(true);
final ContentSection section =
CMS.getContext().getContentSection();
/* TODO Maybe trash
Category.setRootForObject(section, root, useContext);
PermissionService.setContext(root, section);
Category defaultRoot = Category.getRootForObject(section);
if (defaultRoot != null) {
ObjectPermissionCollection coll =
PermissionService.getDirectGrantedPermissions(defaultRoot.getOID());
while (coll.next()) {
PermissionService.grantPermission(new PermissionDescriptor(coll.getPrivilege(),
root.getOID(),
coll.getGranteeOID()));
}
}*/
//TODO Uncomment when CategoryUseContextModelBuilder works <--- Maybe obsolete?
//m_model.setSelectedKey(state, useContext == null ?
// CategoryUseContextModelBuilder.DEFAULT_USE_CONTEXT :
// useContext);
}
}
}

View File

@ -1,213 +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.category;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.ParameterEvent;
import com.arsdigita.bebop.event.ParameterListener;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.form.RadioGroup;
import com.arsdigita.bebop.form.TextArea;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.form.Widget;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.bebop.parameters.TrimmedStringParameter;
import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.cms.ui.BaseForm;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.web.Web;
import com.arsdigita.xml.Element;
import org.libreccm.categorization.Category;
import java.util.Collection;
/**
* A form which creates a new category. Extends the edit form for convenience.
*
*
* @author Michael Pih
* @author Stanislav Freidin &lt;sfreidin@redhat.com&gt;
* @author Justin Ross &lt;jross@redhat.com&gt;
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class BaseCategoryForm extends BaseForm {
private final static String NAME = "name";
private final static String DESCRIPTION = "description";
private final static String URL = "url";
private final static String IS_ABSTRACT = "isAbstract";
private final static String IS_VISIBLE = "isVisible";
private final static String IS_ENABLED = "isEnabled";
private final CategoryRequestLocal categoryRequestLocal;
private final TextField nameField;
private final TextArea descriptionArea;
private final RadioGroup isAbstractRadioGroup;
private final RadioGroup isVisibleRadioGroup;
private final RadioGroup isEnabledRadioGroup;
private Label script = new Label(new GlobalizedMessage(String
.format("<script src=\"%s/javascript/manipulate-input.js\"></script>",
Web.getWebappContextPath())),
false);
/**
* Constructor.
*/
protected BaseCategoryForm(final String key,
final GlobalizedMessage heading,
final CategoryRequestLocal parent) {
super(key, heading);
categoryRequestLocal = parent;
nameField = new TextField(new TrimmedStringParameter(NAME));
addField(gz("cms.ui.name"), nameField);
nameField.setSize(30);
nameField.setMaxLength(200);
nameField.addValidationListener(new NotNullValidationListener());
nameField.setOnFocus(String.format(
""
+ "if (this.form.%1$s.value == '') {"
+ " defaulting = true;"
+ " this.form.%1$s.value = urlize(this.value);"
+ "}",
URL));
nameField.setOnFocus(String.format(
""
+ "if (defaulting) {"
+ " this.form.%1$s.value = urlize(this.value)"
+ "}",
URL
));
// is abstract?
isAbstractRadioGroup = new RadioGroup(IS_ABSTRACT);
isAbstractRadioGroup.addOption(new Option("no", new Label(
gz("cms.ui.no"))));
isAbstractRadioGroup.addOption(new Option("yes", new Label(gz(
"cms.ui.yes"))));
addField(gz("cms.ui.category.is_not_abstract"), isAbstractRadioGroup);
// is visible
isVisibleRadioGroup = new RadioGroup(IS_VISIBLE);
isVisibleRadioGroup.addOption(new Option("no",
new Label(gz("cms.ui.no"))));
isVisibleRadioGroup.addOption(new Option("yes", new Label(gz(
"cms.ui.yes"))));
addField(gz("cms.ui.category.is_visible"), isVisibleRadioGroup);
// is enabled?
isEnabledRadioGroup = new RadioGroup(IS_ENABLED);
isEnabledRadioGroup.addOption(new Option("no",
new Label(gz("cms.ui.no"))));
isEnabledRadioGroup.addOption(new Option("yes", new Label(gz(
"cms.ui.yes"))));
addField(gz("cms.ui.category.is_enabled"), isEnabledRadioGroup);
descriptionArea = new TextArea(new TrimmedStringParameter(DESCRIPTION));
addField(gz("cms.ui.description"), descriptionArea);
descriptionArea.setWrap(TextArea.SOFT);
descriptionArea.setRows(5);
descriptionArea.setCols(40);
addAction(new Finish());
addAction(new Cancel());
}
protected CategoryRequestLocal getCategoryRequestLocal() {
return categoryRequestLocal;
}
protected TextField getNameField() {
return nameField;
}
protected TextArea getDescriptionArea() {
return descriptionArea;
}
protected RadioGroup getIsAbstractRadioGroup() {
return isAbstractRadioGroup;
}
protected RadioGroup getIsVisibleRadioGroup() {
return isVisibleRadioGroup;
}
protected RadioGroup getIsEnabledRadioGroup() {
return isEnabledRadioGroup;
}
@Override
public void generateXML(PageState ps, Element parent) {
script.generateXML(ps, parent);
super.generateXML(ps, parent);
}
private class NameUniqueListener implements ParameterListener {
private final CategoryRequestLocal m_category;
private final Widget m_widget;
private final int m_type;
final static int NAME_FIELD = 1;
NameUniqueListener(final CategoryRequestLocal category) {
this(category, nameField, NAME_FIELD);
}
NameUniqueListener(final CategoryRequestLocal category,
Widget widget, int type) {
m_category = category;
m_widget = widget;
m_type = type;
}
@Override
public final void validate(final ParameterEvent e)
throws FormProcessException {
final PageState state = e.getPageState();
final String title = (String) m_widget.getValue(state);
final Category parent = categoryRequestLocal.getCategory(state);
final Collection<Category> children = parent.getSubCategories();
for (final Category child : children) {
String compField = child.getName();
if (compField.equalsIgnoreCase(title)
&& (m_category == null
|| !m_category.getCategory(state).equals(child))) {
throw new FormProcessException(GlobalizationUtil.globalize(
"cms.ui.category.name_not_unique"));
}
}
}
}
}

View File

@ -1,207 +0,0 @@
/*
* Copyright (C) 2002-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.category;
import com.arsdigita.bebop.*;
import com.arsdigita.bebop.list.ListModel;
import com.arsdigita.bebop.list.ListModelBuilder;
import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.cms.CMS;
import com.arsdigita.util.LockableImpl;
import com.arsdigita.xml.Element;
import org.libreccm.categorization.Categorization;
import org.libreccm.categorization.Category;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.*;
import org.librecms.contentsection.privileges.AdminPrivileges;
import org.librecms.dispatcher.ItemResolver;
import java.util.Collection;
import java.util.Iterator;
import javax.servlet.ServletException;
/**
* A List of all objects currently categorized under this category
*
* @author Randy Graebner (randyg@redhat.com)
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/
public class CategorizedObjectsList extends SortableCategoryList {
//public final static String CATEGORIZED_OBJECTS = "co";
public CategorizedObjectsList(final CategoryRequestLocal category) {
super(category);
setModelBuilder(new CategorizedObjectsModelBuilder());
Label label = new Label(GlobalizationUtil.globalize("cms.ui.category.item.none"));
label.setFontWeight(Label.ITALIC);
setEmptyView(label);
}
/**
* This actually performs the sorting
*/
public void respond(PageState ps) throws ServletException {
/* TODO Reimplement sorting
final String event = ps.getControlEventName();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentItemRepository contentItemRepository = cdiUtil.findBean(ContentItemRepository.class);
final ContentItemManager contentItemManager = cdiUtil.findBean(ContentItemManager.class);
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
if (NEXT_EVENT.equals(event) || PREV_EVENT.equals(event)) {
final long selectedID = Long.parseLong(ps.getControlEventValue());
final Category parent = getCategory(ps);
final ContentItem selectedItem = contentItemRepository.findById(selectedID).get();
final Long selectedDraftId = contentItemManager.getDraftVersion(selectedItem, ContentItem.class).getObjectId();
if (permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES)) {
final Long swapId = getSwapID(parent, selectedID, event);
parent.swapSortKeys(selectedID, swapId);
final ContentItem swapItem = new ContentItem(swapId);
final BigDecimal swapDraftId = swapItem.getDraftVersion().getID();
final BigDecimal sortKey1 = parent.getSortKey(selectedItem);
final BigDecimal sortKey2 = parent.getSortKey(swapItem);
parent.setSortKey(new ContentItem(selectedDraftId), sortKey1);
parent.setSortKey(new ContentItem(swapDraftId), sortKey2);
}
} else {
super.respond(ps);
}*/
}
protected long getSwapID(Category category, long selectedID, String event) {
long priorID = -1;
long swapID = -1;
boolean foundSelectedID = false;
if (category != null && !category.getObjects().isEmpty()) {
//items.addEqualsFilter(ContentItem.VERSION, ContentItem.LIVE); TODO
//items.sort(true);
for (Categorization categorization : category.getObjects()) {
long thisID = categorization.getCategorizationId();
if (foundSelectedID && NEXT_EVENT.equals(event)) {
swapID = thisID;
break;
}
if (thisID == selectedID) {
foundSelectedID = true;
if (PREV_EVENT.equals(event)) {
swapID = priorID;
break;
}
}
priorID = thisID;
}
}
return swapID;
}
@Override
protected void generateLabelXML(PageState state, Element parent, Label label, String key, Object element) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
final ContentSectionManager contentSectionManager = cdiUtil.findBean(ContentSectionManager.class);
ContentItem item = (ContentItem) element;
boolean canEdit = permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES);
if (canEdit) {
ContentSection section = CMS.getContext().getContentSection();
ItemResolver resolver = contentSectionManager.getItemResolver(section);
Link link = new Link(
new Text(item.getDisplayName()),
resolver.generateItemURL(
state,
item.getObjectId(),
item.getDisplayName(),
section,
item.getVersion().name()
)
);
Component c = link;
c.generateXML(state, parent);
}
}
private class CategorizedObjectsModelBuilder extends LockableImpl
implements ListModelBuilder {
public final ListModel makeModel(final List list,
final PageState state) {
final Category category = getCategory(state);
if (category != null && !category.getObjects().isEmpty()) {
Collection<Categorization> items = category.getObjects();
//items.addEqualsFilter(ContentItem.VERSION, ContentItem.LIVE);
//items.sort(true);
return new CategorizedCollectionListModel(items);
} else {
return List.EMPTY_MODEL;
}
}
}
/**
* A {@link ListModel} that iterates over categorized objects via an
* iterator
*/
private static class CategorizedCollectionListModel implements ListModel {
private Iterator<Categorization> m_objs;
private Categorization m_object;
CategorizedCollectionListModel(Collection<Categorization> coll) {
m_objs = coll.iterator();
m_object = null;
}
@Override
public boolean next() {
if (m_objs.hasNext()) {
m_object = m_objs.next();
return true;
} else {
return false;
}
}
@Override
public Object getElement() {
return m_object;
}
@Override
public String getKey() {
return Long.toString(m_object.getCategorizationId());
}
}
}

View File

@ -1,117 +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.category;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.dispatcher.AccessDeniedException;
import com.arsdigita.util.Assert;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.categorization.Category;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.privileges.AdminPrivileges;
/**
* TODO Needs a description.
*
* @author Justin Ross &lt;jross@redhat.com&gt;
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
final class CategoryAddForm extends BaseCategoryForm {
private static final Logger LOGGER = LogManager.getLogger(
CategoryAddForm.class);
private final SingleSelectionModel<String> categorySelectionModel;
/**
* Constructor.
*/
public CategoryAddForm(final CategoryRequestLocal parent,
final SingleSelectionModel<String> model) {
super("AddSubcategories", gz("cms.ui.category.add"), parent);
categorySelectionModel = model;
addProcessListener(new ProcessListener());
}
private final class ProcessListener implements FormProcessListener {
@Override
public final void process(final FormSectionEvent event)
throws FormProcessException {
LOGGER.debug("Adding a category");
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil
.findBean(PermissionChecker.class);
final CategoryController controller = cdiUtil
.findBean(CategoryController.class);
final PageState state = event.getPageState();
final Category parent = getCategoryRequestLocal()
.getCategory(state);
final String name = (String) getNameField().getValue(state);
final String description = (String) getDescriptionArea()
.getValue(state);
// this seems anti-intuitive but the question is "can you place
// items in this category. If the user says "yes" then the
// category is not abstract
final boolean isAbstract = !"yes"
.equals(getIsAbstractRadioGroup().getValue(state));
Assert.exists(parent, "Category parent");
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Using parent category " + parent + " to "
+ "create new category");
}
if (permissionChecker
.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES, parent)) {
final Category category = controller.createCategory(parent,
name,
description,
isAbstract);
categorySelectionModel.setSelectedKey(state,
category.getUniqueId());
} else {
// XXX user a better exception here.
// PermissionException doesn't work for this case.
throw new AccessDeniedException();
}
}
}
}

View File

@ -1,54 +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.category;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.PageState;
import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
import com.arsdigita.toolbox.ui.SecurityContainer;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.security.Party;
import org.libreccm.security.PermissionChecker;
/**
* Container that wraps category admin access checks around UI components.
*
* @author Michael Pih (pihman@arsdigita.com)
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/
public class CategoryAdminContainer extends SecurityContainer {
private final ACSObjectSelectionModel m_object;
private final String m_priv;
public CategoryAdminContainer(Component c,
ACSObjectSelectionModel object,
String priv) {
super(c);
m_object = object;
m_priv = priv;
}
public boolean canAccess(Party party, PageState state) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
return permissionChecker.isPermitted(m_priv, m_object.getSelectedObject(state));
}
}

View File

@ -1,133 +0,0 @@
/*
* Copyright (C) 2017 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.category;
import org.libreccm.categorization.Categorization;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.categorization.CategoryRepository;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
import org.libreccm.categorization.DomainOwnership;
import org.libreccm.l10n.GlobalizationHelper;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentItemManager;
import org.librecms.contentsection.ContentItemVersion;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentSectionRepository;
import java.util.stream.Collectors;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
class CategoryAdminController {
@Inject
private CategoryManager categoryManager;
@Inject
private CategoryRepository categoryRepo;
@Inject
private ContentItemManager itemManager;
@Inject
private GlobalizationHelper globalizationHelper;
@Inject
private ContentSectionRepository sectionRepo;
@Transactional(Transactional.TxType.REQUIRED)
protected List<DomainOwnership> retrieveDomains(final ContentSection section) {
Objects.requireNonNull(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.getDomains());
}
@Transactional(Transactional.TxType.REQUIRED)
protected List<CategoryListItem> generateSubCategoryList(
final Category forCategory) {
Objects.requireNonNull(forCategory);
final Category category = categoryRepo
.findById(forCategory.getObjectId())
.orElseThrow(() -> new IllegalArgumentException(String
.format("No Category with ID %d in the datbase.",
forCategory.getObjectId())));
return category
.getSubCategories()
.stream()
.map(this::createCategoryListItem)
.collect(Collectors.toList());
}
private CategoryListItem createCategoryListItem(final Category category) {
final CategoryListItem item = new CategoryListItem();
item.setCategoryId(category.getObjectId());
final String label = globalizationHelper
.getValueFromLocalizedString(category.getTitle(), category::getName);
item.setLabel(label);
return item;
}
@Transactional
protected List<ContentItem> retrieveAssignedContentItems(
final Category fromCategory) {
final Category category = categoryRepo
.findById(fromCategory.getObjectId())
.orElseThrow(() -> new IllegalArgumentException(String
.format("No Category with ID %d in the datbase.",
fromCategory.getObjectId())));
return category
.getObjects()
.stream()
.map(Categorization::getCategorizedObject)
.filter(obj -> obj instanceof ContentItem)
.map(obj -> (ContentItem) obj)
.filter(item -> itemManager.isLive(item))
.filter(item -> item.getVersion() == ContentItemVersion.LIVE)
.collect(Collectors.toList());
}
}

View File

@ -1,504 +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.category;
import com.arsdigita.bebop.ActionLink;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.List;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.Tree;
import com.arsdigita.bebop.event.ChangeEvent;
import com.arsdigita.bebop.event.ChangeListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ui.BaseAdminPane;
import com.arsdigita.cms.ui.BaseDeleteForm;
import com.arsdigita.cms.ui.BaseTree;
import com.arsdigita.cms.ui.VisibilityComponent;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.toolbox.ui.ActionGroup;
import com.arsdigita.toolbox.ui.Section;
import com.arsdigita.xml.Element;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.categorization.Categorization;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryRepository;
import org.libreccm.categorization.Domain;
import org.libreccm.categorization.DomainOwnership;
import org.libreccm.categorization.DomainRepository;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.core.UnexpectedErrorException;
import org.libreccm.security.PermissionChecker;
import org.librecms.CmsConstants;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.privileges.AdminPrivileges;
/**
* A split pane for the Category Administration UI.
*
* @author Justin Ross &lt;jross@redhat.com&gt;
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public final class CategoryAdminPane extends BaseAdminPane<String> {
private static final Logger LOGGER = LogManager
.getLogger(CategoryAdminPane.class);
public static final String CONTEXT_SELECTED = "sel_context";
// private static final String DEFAULT_USE_CONTEXT = "<default>";
private final Label noCategorySystemsLabel;
private final SingleSelectionModel<String> selectedCategorySystem;
private final SingleSelectionModel<String> selectedCategory;
private final Tree categoryTree;
private final CategoryRequestLocal parentCategoryRequestLocal;
private final CategoryRequestLocal categoryRequestLocal;
public CategoryAdminPane() {
super();
selectedCategorySystem = new UseContextSelectionModel(
new StringParameter(
CONTEXT_SELECTED));
// Left column
// Use context section
List list = new List(new CategoryUseContextModelBuilder());
list.setSelectionModel(selectedCategorySystem);
list.addChangeListener(new ContextSelectionListener());
/* Category tree section */
categoryTree = new BaseTree(new CategoryTreeModelBuilder(
selectedCategorySystem));
categoryTree.addChangeListener(new SelectionListener());
selectedCategory = categoryTree.getSelectionModel();
super.setSelectionModel(selectedCategory);
setSelector(categoryTree);
/* setup use context form */
final Section contextSection = new Section();
contextSection.setHeading(new Label(gz("cms.ui.category.use_contexts")));
ActionGroup contextGroup = new ActionGroup();
contextSection.setBody(contextGroup);
contextGroup.setSubject(list);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
if (permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES)) {
ActionLink addContextAction = new ActionLink(new Label(gz(
"cms.ui.category.add_use_context")));
Form addContextForm = new AddUseContextForm(selectedCategorySystem);
getBody().add(addContextForm);
getBody().connect(addContextAction, addContextForm);
contextGroup
.addAction(new VisibilityComponent(addContextAction,
AdminPrivileges.ADMINISTER_CATEGORIES));
}
final Section categorySection = new Section();
categorySection.setHeading(new Label(gz("cms.ui.categories")));
ActionGroup categoryGroup = new ActionGroup();
categorySection.setBody(categoryGroup);
categoryGroup.setSubject(categoryTree);
final SimpleContainer leftContainer = new SimpleContainer();
leftContainer.add(contextSection);
leftContainer.add(categorySection);
setLeft(leftContainer);
parentCategoryRequestLocal = new ParentRequestLocal();
categoryRequestLocal = new SelectionRequestLocal();
setAdd(gz("cms.ui.category.add"),
new CategoryAddForm(categoryRequestLocal, selectedCategory));
setEdit(gz("cms.ui.category.edit"),
new CategoryEditForm(parentCategoryRequestLocal,
categoryRequestLocal));
setDelete(new DeleteLink(new Label(gz("cms.ui.category.delete"))),
new DeleteForm(
new SimpleContainer()));
setIntroPane(new Label(gz("cms.ui.category.intro")));
setItemPane(new CategoryItemPane(selectedCategory,
selectedCategorySystem,
categoryRequestLocal,
getAddLink(),
getEditLink(),
getDeleteLink()));
noCategorySystemsLabel = new Label(new GlobalizedMessage(
"cms.ui.category.no_category_systems_mapped",
CmsConstants.CMS_BUNDLE));
}
@Override
public void register(final Page page) {
super.register(page);
//page.addActionListener(new RootListener());
}
@Override
public void generateXML(final PageState state, final Element parent) {
if (isVisible(state)) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentSection section = CMS.getContext().getContentSection();
final CategoryAdminController controller = cdiUtil
.findBean(CategoryAdminController.class);
final java.util.List<DomainOwnership> ownerships
= controller
.retrieveDomains(section);
if (ownerships == null || ownerships.isEmpty()) {
final Element panelElem = parent
.newChildElement("bebop:layoutPanel",
BEBOP_XML_NS);
final Element bodyElem = panelElem.newChildElement("bebop:body",
BEBOP_XML_NS);
noCategorySystemsLabel.generateXML(state, bodyElem);
} else {
noCategorySystemsLabel.setVisible(state, false);
super.generateXML(state, parent);
}
}
}
// @Override
// public boolean isVisible(final PageState state) {
//
// final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
// final ContentSection section = CMS.getContext().getContentSection();
// final CategoryAdminController controller = cdiUtil
// .findBean(CategoryAdminController.class);
// final java.util.List<DomainOwnership> ownerships
// = controller
// .retrieveDomains(section);
//
// if (ownerships == null || ownerships.isEmpty()) {
// return false;
// } else {
// return super.isVisible(state);
// }
// }
private final class DeleteLink extends ActionLink {
private final Label m_alternativeLabel;
DeleteLink(Label label) {
super(label);
m_alternativeLabel = new Label(gz("cms.ui.category.undeletable"));
}
@Override
public void generateXML(final PageState state, final Element parent) {
if (isVisible(state)) {
super.generateXML(state, parent);
}
//Category cat = m_category.getCategory(state);
//String context = getUseContext(state);
//boolean isDefaultContext =
// (context == null) || DEFAULT_USE_CONTEXT.equals(context);
//if (cat.isRoot() || !cat.getChildren().isEmpty()) {
// m_alternativeLabel.generateXML(state, parent);
//} else {
//
//}
}
}
private final class DeleteForm extends BaseDeleteForm {
DeleteForm(final SimpleContainer prompt) {
super(prompt);
prompt.add(new Label(gz("cms.ui.category.delete_prompt")));
Label catLabel = new Label();
catLabel.addPrintListener(pe -> {
Label label = (Label) pe.getTarget();
Category cat = categoryRequestLocal.getCategory(pe
.getPageState());
java.util.List<Category> descendants = cat.getSubCategories();
java.util.List<Categorization> catObjects = cat.getObjects();
final StringBuilder builder = new StringBuilder(" ");
if (descendants.size() > 0) {
builder.append("This category has ");
builder.append(descendants.size());
builder.append(" descendant category(ies). ");
}
if (catObjects.size() > 0) {
builder.append("It has ").append(catObjects.size());
builder.append(" descendant object(s). ");
}
if (descendants.size() > 0 || catObjects.size() > 0) {
builder.append(
"Descendants will be orphaned, if this category is removed.");
}
label.setLabel(gz(builder.toString()));
});
prompt.add(catLabel);
}
@Override
public final void process(final FormSectionEvent event)
throws FormProcessException {
final PageState state = event.getPageState();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
final CategoryRepository repository = cdiUtil.findBean(
CategoryRepository.class);
final Category category = categoryRequestLocal.getCategory(state);
if (category == null) {
return;
}
// PermissionService.assertPermission(new PermissionDescriptor(PrivilegeDescriptor.DELETE,
// category,
// Kernel.getContext().
// getParty()));
permissionChecker.checkPermission(
AdminPrivileges.ADMINISTER_CATEGORIES, category);
// if (category.isRoot()) {
// Category root =
// Category.getRootForObject(CMS.getContext().getContentSection(),
// getUseContext(state));
// if (category.equals(root)) {
// Category.clearRootForObject(CMS.getContext().getContentSection(),
// getUseContext(state));
// }
// m_contextModel.setSelectedKey(state, DEFAULT_USE_CONTEXT);
// } else {
Category parent = category.getParentCategory();
selectedCategory.setSelectedKey(state, parent.getUniqueId());
// }
//category.deleteCategoryAndOrphan();
repository.delete(category);
}
}
private final class SelectionRequestLocal extends CategoryRequestLocal {
@Override
protected final Object initialValue(final PageState state) {
final String selectedCatetoryIdStr = selectedCategory
.getSelectedKey(state);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryRepository repository = cdiUtil.findBean(
CategoryRepository.class);
final Category category;
if (selectedCatetoryIdStr == null) {
category = null;
} else {
category = repository
.findById(Long.parseLong(selectedCatetoryIdStr))
.orElseThrow(() -> new UnexpectedErrorException(String
.format("No Category with ID %s in the database.",
selectedCatetoryIdStr)));
}
return category;
}
}
private final class ParentRequestLocal extends CategoryRequestLocal {
@Override
protected final Object initialValue(final PageState state) {
return categoryRequestLocal.getCategory(state).getParentCategory();
}
}
// private final class RootListener implements ActionListener {
//
// public final void actionPerformed(final ActionEvent e) {
// final PageState state = e.getPageState();
//
// if (!m_model.isSelected(state)) {
// final Category root =
// Category.getRootForObject(CMS.getContext().getContentSection(),
// getUseContext(state));
// if (root != null) {
// m_model.setSelectedKey(state, root.getID());
// }
// }
// }
//
// }
private class UseContextSelectionModel
extends ParameterSingleSelectionModel<String> {
public UseContextSelectionModel(final ParameterModel parameterModel) {
super(parameterModel);
}
@Override
public String getSelectedKey(final PageState state) {
String val = super.getSelectedKey(state);
if (val == null
|| val.isEmpty()
|| val.matches("\\s*")) {
final ContentSection section = CMS
.getContext()
.getContentSection();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryAdminController controller = cdiUtil
.findBean(CategoryAdminController.class);
final java.util.List<DomainOwnership> domainOwnerships
= controller
.retrieveDomains(section);
if (domainOwnerships == null || domainOwnerships.isEmpty()) {
val = null;
} else {
final Domain categorySystem = controller
.retrieveDomains(section).get(0).getDomain();
val = Long.toString(categorySystem.getObjectId());
state.setValue(getStateParameter(), val);
fireStateChanged(state);
}
}
return val;
}
}
public String getUseContext(final PageState state) {
final String selected = selectedCategorySystem.getSelectedKey(state);
return selected;
// if (DEFAULT_USE_CONTEXT.equals(selected)) {
//
//
//
// return null;
// } else {
// return selected;
// }
}
private class ContextSelectionListener implements ChangeListener {
@Override
public final void stateChanged(final ChangeEvent event) {
LOGGER.debug("Selection state changed; I may change "
+ "the body's visible pane");
final PageState state = event.getPageState();
getBody().reset(state);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Category root;
if (selectedCategorySystem.isSelected(state)) {
final String categorySystemIdStr = selectedCategorySystem
.getSelectedKey(state);
final DomainRepository domainRepo = cdiUtil
.findBean(DomainRepository.class);
final Domain categorySystem = domainRepo
.findById(Long.parseLong(categorySystemIdStr))
.orElseThrow(() -> new UnexpectedErrorException(String
.format("No Domain with ID %s in the database.",
categorySystemIdStr)));
root = categorySystem.getRoot();
// final String rootCategoryId = selectedCategorySystem
// .getSelectedKey(state);
//
//
// final Category root;
// if (DEFAULT_USE_CONTEXT.equals(rootCategoryId)) {
// final ContentSection section = CMS
// .getContext()
// .getContentSection();
//
// final CategoryAdminController controller = CdiUtil
// .createCdiUtil()
// .findBean(CategoryAdminController.class);
// final java.util.List<DomainOwnership> ownerships
// = controller
// .retrieveDomains(section);
// root = ownerships.get(0).getDomain().getRoot();
// } else {
// root = categoryRepo
// .findById(Long.parseLong(rootCategoryId))
// .orElseThrow(() -> new UnexpectedErrorException(String
// .format("No Category with ID %s in the database.",
// rootCategoryId)));
// }
} else {
final ContentSection section = CMS
.getContext()
.getContentSection();
final CategoryAdminController controller = CdiUtil
.createCdiUtil()
.findBean(CategoryAdminController.class);
final java.util.List<DomainOwnership> ownerships
= controller
.retrieveDomains(section);
root = ownerships.get(0).getDomain().getRoot();
}
if (root != null) {
selectedCategory.setSelectedKey(state, root.getUniqueId());
categoryTree.reset(state);
}
if (selectedCategory.isSelected(state)) {
LOGGER.debug("The selection model is selected; displaying "
+ "the item pane");
getBody().push(state, getItemPane());
}
}
}
}

View File

@ -1,124 +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.category;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.GridPanel;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SaveCancelSection;
import com.arsdigita.bebop.event.ParameterEvent;
import com.arsdigita.bebop.event.ParameterListener;
import com.arsdigita.bebop.form.FormErrorDisplay;
import com.arsdigita.bebop.form.TextArea;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.bebop.parameters.TrimmedStringParameter;
import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.cms.ui.CMSForm;
import com.arsdigita.globalization.GlobalizedMessage;
import org.libreccm.categorization.Category;
/**
* A form which creates a new category. Extends the edit form for
* convenience.
*
* @author Michael Pih
* @author Stanislav Freidin &lt;sfreidin@redhat.com&gt;
*/
class CategoryBaseForm extends CMSForm {
final CategoryRequestLocal m_parent;
final FormErrorDisplay m_errors;
final TextField m_title;
final TextArea m_description;
final SaveCancelSection m_saveCancelSection;
/**
* Constructor.
*/
CategoryBaseForm(final String string, final CategoryRequestLocal parent) {
super("AddSubcategories");
m_parent = parent;
// Form header
Label header = new Label(gz("cms.ui.category.add"));
add(header, GridPanel.FULL_WIDTH);
// Form errors
m_errors = new FormErrorDisplay(this);
add(m_errors, GridPanel.FULL_WIDTH);
// Name
m_title = new TextField(new TrimmedStringParameter("name"));
m_title.setSize(30);
m_title.setMaxLength(30);
m_title.addValidationListener(new NotNullValidationListener());
m_title.addValidationListener(new TitleUniqueListener());
add(new Label(gz("cms.ui.name")));
add(m_title);
// Description
m_description = new TextArea(new TrimmedStringParameter("description"));
m_description.setWrap(TextArea.SOFT);
m_description.setRows(5);
m_description.setCols(40);
m_description.addValidationListener(new NotNullValidationListener());
add(new Label(gz("cms.ui.description")));
add(m_description);
// Save and cancel buttons
m_saveCancelSection = new SaveCancelSection();
add(m_saveCancelSection, GridPanel.FULL_WIDTH | GridPanel.LEFT);
}
public final boolean isCancelled(final PageState state) {
return m_saveCancelSection.getCancelButton().isSelected(state);
}
static GlobalizedMessage gz(final String key) {
return GlobalizationUtil.globalize(key);
}
static String lz(final String key) {
return (String) gz(key).localize();
}
class TitleUniqueListener implements ParameterListener {
public final void validate(final ParameterEvent e)
throws FormProcessException {
final PageState state = e.getPageState();
final String title = (String) m_title.getValue(state);
final Category parent = m_parent.getCategory(state);
final java.util.List<Category> children = parent.getSubCategories();
for (Category child : children) {
if (child.getName().equalsIgnoreCase(title)) {
throw new FormProcessException
(GlobalizationUtil.globalize("cms.ui.category.name_not_unique"));
}
}
}
}
}

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.category;
import com.arsdigita.bebop.Component;
import com.arsdigita.toolbox.ui.ComponentAccess;
public class CategoryComponentAccess extends ComponentAccess {
// XXX implement me!
// TODO This seems pretty useless...
// FIXME
public CategoryComponentAccess(Component c,
CategoryRequestLocal category) {
super(c);
}
}

View File

@ -1,112 +0,0 @@
/*
* Copyright (C) 2018 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.category;
import com.arsdigita.kernel.KernelConfig;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.categorization.CategoryRepository;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.l10n.LocalizedString;
import java.util.Objects;
import java.util.Optional;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.transaction.Transactional;
/**
* Service methods for the Category Admin Tab in the Content Center.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
class CategoryController {
@Inject
private CategoryManager categoryManager;
@Inject
private CategoryRepository categoryRepo;
@Inject
private ConfigurationManager confManager;
/**
* Creates a new category.
*
* @param parentCategory The parent category of the new category.
* @param name The name of the new category (URL fragment).
* @param description A description of the new category-
* @param isAbstract Is the new category abstract?
* @return The new category.
*/
@Transactional(Transactional.TxType.REQUIRED)
protected Category createCategory(final Category parentCategory,
final String name,
final String description,
final boolean isAbstract) {
Objects.requireNonNull(parentCategory);
Objects.requireNonNull(name);
if (name.isEmpty() || name.matches("\\s*")) {
throw new IllegalArgumentException(
"The name of a category can't be empty.");
}
final KernelConfig kernelConfig = confManager
.findConfiguration(KernelConfig.class);
final Category category = new Category();
category.setName(name);
final LocalizedString localizedDescription = new LocalizedString();
localizedDescription.putValue(kernelConfig.getDefaultLocale(),
description);
category.setDescription(localizedDescription);
category.setAbstractCategory(isAbstract);
categoryRepo.save(category);
categoryManager.addSubCategoryToCategory(category, parentCategory);
return category;
}
@Transactional(Transactional.TxType.REQUIRED)
protected Optional<Category> getParentCategory(final Category forCategory) {
Objects.requireNonNull(forCategory);
final Category category = categoryRepo
.findById(forCategory.getObjectId())
.orElseThrow(() -> new IllegalArgumentException(String
.format("No category with ID %d in the database.",
forCategory.getObjectId())));
if (category.getParentCategory() == null) {
return Optional.empty();
} else {
return categoryRepo
.findById(category.getParentCategory().getObjectId());
}
}
}

View File

@ -1,174 +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.category;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.dispatcher.AccessDeniedException;
import com.arsdigita.kernel.KernelConfig;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryRepository;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.l10n.LocalizedString;
import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.privileges.AdminPrivileges;
/**
* TODO Needs a description.
*
* @author Justin Ross &lt;jross@redhat.com&gt;
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/
final class CategoryEditForm extends BaseCategoryForm {
private static final Logger LOGGER = LogManager.getLogger(
CategoryEditForm.class);
private static final String NO = "no";
private static final String YES = "yes";
private final CategoryRequestLocal selectedCategory;
public CategoryEditForm(final CategoryRequestLocal parent,
final CategoryRequestLocal selectedCategory) {
super("EditCategory", gz("cms.ui.category.edit"), parent);
this.selectedCategory = selectedCategory;
super.addInitListener(new InitListener());
super.addProcessListener(new ProcessListener());
}
private class InitListener implements FormInitListener {
@Override
public final void init(final FormSectionEvent event)
throws FormProcessException {
final PageState state = event.getPageState();
final Category category = selectedCategory.getCategory(state);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final GlobalizationHelper globalizationHelper = cdiUtil
.findBean(GlobalizationHelper.class);
getNameField().setValue(state, category.getName());
final LocalizedString description = category.getDescription();
getDescriptionArea()
.setValue(state,
globalizationHelper
.getValueFromLocalizedString(description));
// this seems anti-intuitive but the question is "can you place
// items in this category. If the user says "yes" then the
// category is not abstract
if (category.isAbstractCategory()) {
getIsAbstractRadioGroup().setValue(state, NO);
} else {
getIsAbstractRadioGroup().setValue(state, YES);
}
if (category.isVisible()) {
getIsVisibleRadioGroup().setValue(state, YES);
} else {
getIsVisibleRadioGroup().setValue(state, NO);
}
if (category.isEnabled()) {
getIsEnabledRadioGroup().setValue(state, YES);
} else {
getIsEnabledRadioGroup().setValue(state, NO);
}
}
}
private class ProcessListener implements FormProcessListener {
@Override
public final void process(final FormSectionEvent event)
throws FormProcessException {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
final ConfigurationManager manager = cdiUtil.findBean(
ConfigurationManager.class);
final KernelConfig config = manager.findConfiguration(
KernelConfig.class);
final CategoryRepository categoryRepository = cdiUtil.findBean(
CategoryRepository.class);
final PageState state = event.getPageState();
final Category category = selectedCategory.getCategory(state);
if (permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_CATEGORIES, category)) {
category.setName((String) getNameField().getValue(state));
final LocalizedString localizedDescription
= new LocalizedString();
localizedDescription
.putValue(config.getDefaultLocale(),
(String) getDescriptionArea().getValue(state));
category.setDescription(localizedDescription);
final String isAbstract = (String) getIsAbstractRadioGroup()
.getValue(state);
// this seems anti-intuitive but the question is "can you place
// items in this category. If the user says "yes" then the
// category is not abstract
if (YES.equals(isAbstract)) {
category.setAbstractCategory(false);
} else if (NO.equals(isAbstract)) {
category.setAbstractCategory(true);
}
final String isVisible = (String) getIsVisibleRadioGroup()
.getValue(state);
if (YES.equals(isVisible)) {
category.setVisible(true);
} else {
category.setVisible(false);
}
final String isEnabled = (String) getIsEnabledRadioGroup()
.getValue(state);
if (YES.equals(isEnabled)) {
category.setEnabled(true);
} else if (NO.equals(isEnabled)) {
category.setEnabled(false);
}
categoryRepository.save(category);
} else {
throw new AccessDeniedException();
}
}
}
}

View File

@ -1,758 +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.category;
import com.arsdigita.bebop.ActionLink;
import com.arsdigita.bebop.BaseLink;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Link;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.form.Submit;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ui.BaseItemPane;
import com.arsdigita.cms.ui.CMSForm;
import com.arsdigita.cms.ui.ContentItemPage;
import com.arsdigita.cms.ui.VisibilityComponent;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.kernel.KernelConfig;
import com.arsdigita.toolbox.ui.ActionGroup;
import com.arsdigita.toolbox.ui.Property;
import com.arsdigita.toolbox.ui.PropertyList;
import com.arsdigita.toolbox.ui.Section;
import com.arsdigita.xml.Element;
import java.util.Optional;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.core.CcmObject;
import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.security.PermissionChecker;
import org.librecms.CmsConstants;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentItemManager;
import org.librecms.contentsection.privileges.AdminPrivileges;
import org.librecms.contentsection.privileges.ItemPrivileges;
import java.util.List;
import java.util.Objects;
/**
* Edits a single category.
*
* @author Justin Ross &lt;jross@redhat.com&gt;
* @author Sören Bernstein <quasi@quasiweb.de>
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/
class CategoryItemPane extends BaseItemPane {
private static final Logger LOGGER = LogManager.getLogger(
CategoryItemPane.class);
private final SingleSelectionModel m_model;
private final CategoryRequestLocal m_category;
private final SimpleContainer m_detailPane;
public CategoryItemPane(final SingleSelectionModel model,
final SingleSelectionModel contextModel,
final CategoryRequestLocal category,
final ActionLink addLink,
final ActionLink editLink,
final ActionLink deleteLink) {
m_model = model;
m_category = category;
// Details
m_detailPane = new SimpleContainer();
add(m_detailPane);
setDefault(m_detailPane);
final ActionLink orderItemsLink = new ActionLink(new Label(
gz("cms.ui.category.categorized_objects"))) {
@Override
public boolean isVisible(PageState state) {
// update for live items only
if (!super.isVisible(state)) {
return false;
}
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryManager categoryManager = cdiUtil
.findBean(CategoryManager.class);
final Category category = m_category.getCategory(state);
return categoryManager.hasObjects(category);
}
};
final Form orderItemsForm = new OrderItemsForm(m_category);
final Form orderItemsForm2 = new OrderItemsForm(m_category);
add(orderItemsForm);
add(orderItemsForm2);
// Change index item
final ActionLink indexLink = new ActionLink(new Label(gz(
"cms.ui.category.change_index_item")));
final Form indexForm = new IndexItemSelectionForm(m_category);
add(indexForm);
//Move link
final ActionLink moveLink = new MoveLink(new Label(gz(
"cms.ui.category.move")));
final Form moveForm = new CategoryMoveForm(m_category, contextModel);
add(moveForm);
ViewItemLink viewIndexLink = new ViewItemLink(new Label(gz(
"cms.ui.category.view_index_item")), "");
EditItemLink editIndexLink = new EditItemLink(new Label(gz(
"cms.ui.category.edit_index_item")), "");
// Summary
m_detailPane.add(new SummarySection(editLink,
deleteLink,
indexLink,
moveLink,
viewIndexLink,
editIndexLink,
orderItemsLink));
// Quasimodo: BEGIN
// Localizations
ActionLink addCategoryLocalizationLink = new ActionLink(new Label(gz(
"cms.ui.category.localization_add"))) {
@Override
public boolean isVisible(PageState state) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ConfigurationManager manager = cdiUtil.findBean(
ConfigurationManager.class);
final KernelConfig config = manager.findConfiguration(
KernelConfig.class);
final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
// Only show addLanguage button, if there are langauges to add
int countSupportedLanguages = config.getSupportedLanguages()
.size();
final Category category = m_category.getCategory(state);
if (permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_CATEGORIES,
category)) {
if (category.getTitle().getAvailableLocales().size()
< countSupportedLanguages
|| category.getDescription().getAvailableLocales()
.size() < countSupportedLanguages) {
return true;
}
}
return false;
}
};
CategoryLocalizationAddForm addCategoryLocalizationForm
= new CategoryLocalizationAddForm(
m_category);
m_detailPane.add(new CategoryLocalizationSection(
addCategoryLocalizationLink));
add(addCategoryLocalizationForm);
connect(addCategoryLocalizationLink, addCategoryLocalizationForm);
connect(addCategoryLocalizationForm);
// Quasimodo: END
// Subcategories
m_detailPane.add(new SubcategorySection(addLink));
// Linked categories
final ActionLink linkAddLink = new ActionLink(new Label(gz(
"cms.ui.category.linked_add")));
final Form linkForm = new LinkForm(m_category);
add(linkForm);
linkAddLink.addActionListener(new NavigationListener(linkForm));
linkForm.addSubmissionListener(new CancelListener(linkForm));
m_detailPane.add(new LinkedCategorySection(linkAddLink));
// Templates
// m_detailPane.add(new AdminVisible(new CategoryTemplateSection()));
// Permissions
//m_detailPane.add(new PermissionsSection());
//m_detailPane.add(new Text("PermissionSection Placeholder"));
connect(indexLink, indexForm);
connect(indexForm);
connect(moveLink, moveForm);
connect(moveForm);
connect(orderItemsLink, orderItemsForm);
connect(orderItemsForm);
}
private class EditVisible extends VisibilityComponent {
EditVisible(final Component child) {
super(child, null);
}
@Override
public boolean hasPermission(PageState ps) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
return permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_CATEGORIES);
}
}
private class AdminVisible extends VisibilityComponent {
AdminVisible(final Component child) {
super(child, null);
}
@Override
public boolean hasPermission(PageState ps) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
return permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_CATEGORIES);
}
}
private class SummarySection extends Section {
SummarySection(final ActionLink editLink,
final ActionLink deleteLink,
final ActionLink indexLink,
final ActionLink moveLink,
final ActionLink orderItemsLink) {
setHeading(new Label(gz("cms.ui.category.details")));
final ActionGroup group = new ActionGroup();
setBody(group);
group.setSubject(new Properties());
group.addAction(new EditVisible(editLink), ActionGroup.EDIT);
group.addAction(new EditVisible(orderItemsLink));
group.addAction(new EditVisible(moveLink));
group.addAction(new EditVisible(indexLink));
group.addAction(new AdminVisible(deleteLink), ActionGroup.DELETE);
}
/*
* This alternative constructor sets two additional links, allowing
* the user to view and edit the content index item.
*/
SummarySection(final ActionLink editLink,
final ActionLink deleteLink,
final ActionLink indexLink,
final ActionLink moveLink,
final BaseLink viewIndexItem,
final BaseLink editIndexItem,
final ActionLink orderItemsLink) {
setHeading(new Label(gz("cms.ui.category.details")));
final ActionGroup group = new ActionGroup();
setBody(group);
group.setSubject(new Properties());
group.addAction(new EditVisible(editLink), ActionGroup.EDIT);
group.addAction(new EditVisible(orderItemsLink));
group.addAction(new EditVisible(indexLink));
group.addAction(new EditVisible(moveLink));
group.addAction(new EditVisible(viewIndexItem));
group.addAction(new EditVisible(editIndexItem));
group.addAction(new AdminVisible(deleteLink), ActionGroup.DELETE);
}
private class Properties extends PropertyList {
@Override
protected final java.util.List<Property> properties(
final PageState state) {
final java.util.List<Property> properties = super.properties(
state);
final Category category = m_category
.getCategory(state);
final String itemTitle;
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final GlobalizationHelper globalizationHelper = cdiUtil
.findBean(GlobalizationHelper.class);
if (category == null) {
itemTitle = "None";
} else {
final CategoryManager categoryManager = cdiUtil
.findBean(CategoryManager.class);
final List<CcmObject> indexObjects = categoryManager
.getIndexObject(category);
final Optional<ContentItem> indexItem = indexObjects
.stream()
.filter(obj -> obj instanceof ContentItem)
.map(obj -> (ContentItem) obj)
.findFirst();
if (indexItem.isPresent()) {
final ContentItem item = indexItem.get();
itemTitle = globalizationHelper
.getValueFromLocalizedString(item.getTitle(),
item::getDisplayName);
} else if (indexObjects.isEmpty()) {
itemTitle = "None";
} else {
final CcmObject indexObj = indexObjects.get(0);
itemTitle = Objects.toString(indexObj);
}
}
properties.add(new Property(gz("cms.ui.name"),
category.getName()));
properties.add(new Property(
gz("cms.ui.description"),
globalizationHelper
.getValueFromLocalizedString(category.getDescription())));
properties.add(new Property(
gz("cms.ui.category.is_not_abstract"),
category.isAbstractCategory()
? gz("cms.ui.no")
: gz("cms.ui.yes")));
properties.add(new Property(gz("cms.ui.cateogry.is_visible"),
category.isVisible()
? gz("cms.ui.yes")
: gz("cms.ui.no")));
properties.add(new Property(gz("cms.ui.category.is_enabled"),
category.isEnabled()
? gz("cms.ui.yes")
: gz("cms.ui.no")));
properties.add(new Property(gz("cms.ui.category.index_item"),
itemTitle));
return properties;
}
}
}
// Quasimodo: BEGIN
// CategoryLocalizationSection
private class CategoryLocalizationSection extends Section {
private CategoryLocalizationTable m_catLocalizationTable;
private CategoryLocalizationEditForm m_editCategoryLocalizationForm;
private StringParameter m_catLocaleParam;
private ParameterSingleSelectionModel m_catLocale;
CategoryLocalizationSection(ActionLink addLink) {
setHeading(new Label(gz("cms.ui.category.localizations")));
m_catLocaleParam = new StringParameter("catLocale");
m_catLocale = new ParameterSingleSelectionModel(m_catLocaleParam);
final ActionGroup group = new ActionGroup();
setBody(group);
m_catLocalizationTable = new CategoryLocalizationTable(m_category,
m_model,
m_catLocale);
group.setSubject(m_catLocalizationTable);
group.addAction(new AdminVisible(addLink), ActionGroup.ADD);
m_editCategoryLocalizationForm = new CategoryLocalizationEditForm(
m_category,
m_catLocale);
add(m_editCategoryLocalizationForm);
connect(m_editCategoryLocalizationForm);
connect(m_catLocalizationTable, 0, m_editCategoryLocalizationForm);
}
@Override
public void register(Page page) {
super.register(page);
page.addComponentStateParam(m_editCategoryLocalizationForm,
m_catLocaleParam);
}
}
private class SubcategorySection extends Section {
SubcategorySection(final ActionLink addLink) {
setHeading(new Label(gz("cms.ui.category.subcategories")));
final ActionGroup group = new ActionGroup();
setBody(group);
group.setSubject(new SubcategoryList(m_category, m_model));
group.addAction(new AdminVisible(addLink), ActionGroup.ADD);
}
}
private class LinkedCategorySection extends Section {
LinkedCategorySection(final ActionLink linkAddLink) {
setHeading(new Label(gz("cms.ui.category.linked")));
final ActionGroup group = new ActionGroup();
setBody(group);
group.setSubject(new CategoryLinks(m_category, m_model));
group.addAction(new EditVisible(linkAddLink), ActionGroup.EDIT);
}
@Override
public final boolean isVisible(final PageState state) {
final Category category = m_category.getCategory(state);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryController controller = cdiUtil
.findBean(CategoryController.class);
final Optional<Category> parentCategory = controller
.getParentCategory(category);
if (parentCategory.isPresent()) {
return parentCategory.get().isVisible();
} else {
return false;
}
}
}
private class CategoryTemplateSection extends Section {
CategoryTemplateSection() {
setHeading(new Label(gz("cms.ui.category.templates")));
final ActionGroup group = new ActionGroup();
setBody(group);
// group.setSubject(new CategoryTemplates(m_category));
// XXX secvis
//group.addAction(link);
}
}
// private class PermissionsSection extends Section {
//
// @Override
// public boolean isVisible(PageState ps) {
// final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
// final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
// Category cat = m_category.getCategory(ps);
// return cat.getParentCategory() != null && permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES);
// }
//
// PermissionsSection() {
// setHeading(new Label(gz("cms.ui.permissions")));
//
// final ActionGroup group = new ActionGroup();
// setBody(group);
//
//// PrivilegeDescriptor[] privs = new PrivilegeDescriptor[]{
//// PrivilegeDescriptor.EDIT,
//// Category.MAP_DESCRIPTOR,
//// PrivilegeDescriptor.DELETE,
//// PrivilegeDescriptor.ADMIN
//// };
////
//// HashMap privMap = new HashMap();
//// privMap.put("edit", "Edit");
//// privMap.put("delete", "Delete");
//// privMap.put(Category.MAP_DESCRIPTOR.getName(), "Categorize Items");
//// privMap.put("admin", "Admin");
////
//// final CMSPermissionsPane permPane = new CMSPermissionsPane(privs, privMap,
//// new ACSObjectSelectionModel(
//// m_model)) {
//// @Override
//// public void showAdmin(PageState ps) {
//// Assert.exists(m_model.getSelectedKey(ps));
////
//// super.showAdmin(ps);
//// getAdminListingPanel().setVisible(ps, false);
//// }
////
//// };
////
//// final ActionLink restoreDefault = new ActionLink(new Label(gz(
//// "cms.ui.restore_default_permissions"))) {
//// @Override
//// public boolean isVisible(PageState ps) {
//// Category cat = m_category.getCategory(ps);
//// return PermissionService.getContext(cat) == null;
//// }
////
//// };
////
//// final ActionLink useCustom = new ActionLink(new Label(gz(
//// "cms.ui.use_custom_permissions"))) {
//// @Override
//// public boolean isVisible(PageState ps) {
//// Category cat = m_category.getCategory(ps);
//// return PermissionService.getContext(cat) != null;
//// }
////
//// };
////
//// ActionListener al = new ActionListener() {
//// public void actionPerformed(ActionEvent event) {
//// PageState state = event.getPageState();
//// // if this is the root then we cannot revert to anything
//// // since there is not a parent
//// Category cat = m_category.getCategory(state);
//// if (!cat.canAdmin()) {
//// throw new com.arsdigita.cms.dispatcher.AccessDeniedException();
//// }
//// DataObject context = PermissionService.getContext(cat);
//// if (context != null) {
//// PermissionService.clonePermissions(cat);
//// } else {
//// ACSObject parent;
//// try {
//// parent = cat.getDefaultParentCategory();
//// } catch (CategoryNotFoundException ce) {
//// throw new IllegalStateException(
//// "link shouldn't exist for root categories");
//// }
//// PermissionService.setContext(cat, parent);
////
//// // revoke all direct permissions so category will only
//// // have inherited permissions
//// ObjectPermissionCollection perms =
//// PermissionService.getDirectGrantedPermissions(
//// cat.getOID());
//// while (perms.next()) {
//// PermissionService.revokePermission(
//// new PermissionDescriptor(
//// perms.getPrivilege(), cat.getOID(),
//// perms.getGranteeOID()));
//// }
//// }
//// permPane.reset(state);
//// }
////
//// }
////
//// restoreDefault.addActionListener(al);
//// useCustom.addActionListener(al);
////
//// SimpleContainer links = new SimpleContainer();
//// links.add(restoreDefault);
//// links.add(useCustom);
////
//// group.setSubject(permPane);
//// group.addAction(links);
////
//// m_model.addChangeListener(new ChangeListener() {
//// public void stateChanged(ChangeEvent e) {
//// PageState ps = e.getPageState();
//// }
////
//// });
////
// }
//
// }
private static class OrderItemsForm extends CMSForm {
public OrderItemsForm(CategoryRequestLocal category) {
super("orderItems", new SimpleContainer());
Label header = new Label(gz("cms.ui.category.categorized_objects"));
header.setFontWeight(Label.BOLD);
add(header);
add(new CategorizedObjectsList(category));
add(new Submit("Done"));
}
}
/*
* This private class creates a link to the index item for a category.
*/
private class ViewItemLink extends Link {
ViewItemLink(Component c, String s) {
super(c, s);
}
// Build the preview link. This uses a standard redirect link to find
// the content. The prepareURL method is called by the printwriter
@Override
protected String prepareURL(final PageState state, String location) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryManager manager = cdiUtil.findBean(
CategoryManager.class);
final Category category = m_category.getCategory(state);
final ContentItem indexItem = (ContentItem) manager
.getIndexObject(category)
.stream()
.findFirst()
.get();
return String.format("/redirect/?oid=%s",
Long.toString(indexItem.getObjectId()));
}
// We only show this link when an index item exists for this category
@Override
public boolean isVisible(PageState state) {
if (!super.isVisible(state)) {
return false;
}
final Category category = m_category.getCategory(state);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryManager categoryManager = cdiUtil
.findBean(CategoryManager.class);
return categoryManager.hasIndexObject(category);
}
};
private class EditItemLink extends Link {
EditItemLink(Component c, String s) {
super(c, s);
}
/**
* Build the preview link. This is based on code in the
* ContentSoonExpiredPane class. The prepareURL method of the parent is
* overwritten. This method is called by the printwriter
*/
@Override
protected String prepareURL(final PageState state, String location) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryManager manager = cdiUtil.findBean(
CategoryManager.class);
final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
final ContentItemManager contentItemManager = cdiUtil.findBean(
ContentItemManager.class);
Optional<CcmObject> indexItem = manager
.getIndexObject(m_category.getCategory(state))
.stream()
.findFirst();
if (!indexItem.isPresent()) {
return "";
}
if (!permissionChecker.isPermitted("", indexItem.get())) {
return "";
} else {
Long draftID = contentItemManager
.getDraftVersion((ContentItem) indexItem.get(),
ContentItem.class)
.getObjectId();
return "item.jsp?item_id=" + draftID + "&set_tab="
+ ContentItemPage.AUTHORING_TAB;
}
}
/**
* We only show this link when an index item exists for this category
* and the user is allowed to edit this item.
*
* @param state
*
* @return
*/
@Override
public boolean isVisible(PageState state) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryManager manager = cdiUtil.findBean(
CategoryManager.class);
final ContentItemManager contentItemManager = cdiUtil.findBean(
ContentItemManager.class);
final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
if (!super.isVisible(state)) {
return false;
}
Optional<CcmObject> indexItem = manager.getIndexObject(m_category
.getCategory(state))
.stream()
.findFirst();
if (!indexItem.isPresent()) {
return false;
} else {
return permissionChecker.isPermitted(ItemPrivileges.EDIT,
indexItem.get());
}
}
};
private class MoveLink extends ActionLink {
private final Label alternativeLabel;
public MoveLink(final Label label) {
super(label);
alternativeLabel = new Label(new GlobalizedMessage(
"cms.ui.category.cantmoved",
CmsConstants.CMS_BUNDLE));
}
@Override
public void generateXML(final PageState state, final Element parent) {
if (!isVisible(state)) {
return;
}
final Category category = m_category.getCategory(state);
if (category.getParentCategory() == null) {
alternativeLabel.generateXML(state, parent);
} else {
super.generateXML(state, parent);
}
}
}
}

View File

@ -1,246 +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.category;
import com.arsdigita.bebop.*;
import com.arsdigita.bebop.List;
import com.arsdigita.bebop.list.ListModel;
import com.arsdigita.bebop.list.ListModelBuilder;
import com.arsdigita.bebop.table.TableCellRenderer;
import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ui.CMSContainer;
import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
import com.arsdigita.util.Assert;
import com.arsdigita.util.LockableImpl;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.categorization.Categorization;
import org.libreccm.categorization.Category;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.core.CcmObject;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentSectionManager;
import org.librecms.dispatcher.ItemResolver;
import java.util.*;
import java.util.stream.Collectors;
/**
* Displays a list of items for the given category
*
* WARNING: The code to actually list the items is currently a travesty.
* It needs to be re-written from scratch, by using custom data queries.
* @version $Id: CategoryItemsBrowser.java 2090 2010-04-17 08:04:14Z pboy $
*/
public class CategoryItemsBrowser extends Grid {
private static final Logger LOGGER = LogManager.getLogger(
CategoryItemsBrowser.class);
private RequestLocal m_resolver;
private String m_context;
/**
* Construct a new CategoryItemsBrowser
* <p>
* The {@link SingleSelectionModel} which will provide the
* current category
*
* @param sel the {@link ACSObjectSelectionModel} which will maintain
* the current category
*
* @param numCols the number of columns in the browser
*
* @param context the context for the retrieved items. Should be
* "draft" or "live"
*/
public CategoryItemsBrowser(ACSObjectSelectionModel sel, int numCols,
String context) {
super(null, numCols);
super.setModelBuilder(new CategoryItemModelBuilder(sel));
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentSectionManager sectionManager = cdiUtil.findBean(ContentSectionManager.class);
m_context = context;
setRowSelectionModel(sel);
setEmptyView(new Label(GlobalizationUtil.globalize
("cms.ui.category.item.none")));
// Cache the item resolver
m_resolver = new RequestLocal() {
public Object initialValue(PageState s) {
ContentSection section =
CMS.getContext().getContentSection();
final ItemResolver itemResolver = sectionManager.getItemResolver(section);
LOGGER.warn("Item resolver is" + itemResolver.getClass());
return itemResolver;
}
};
setDefaultCellRenderer(new ItemSummaryCellRenderer());
}
/**
* @return the current context
*/
public String getContext() {
return m_context;
}
public void setContext(String context) {
Assert.isUnlocked(this);
m_context = context;
}
/**
* Iterates through all the children of the given Category
*/
private class CategoryItemModelBuilder extends LockableImpl
implements ListModelBuilder {
private ACSObjectSelectionModel m_sel;
public CategoryItemModelBuilder(ACSObjectSelectionModel sel) {
m_sel = sel;
}
// public DataQuery getDataQuery(PageState s) {
// Category cat = (Category)m_sel.getSelectedObject(s);
//
// ContentSection section = CMS.getContext().getContentSection();
// User user = (User)Kernel.getContext().getParty();
// OID oid = null;
// if (user != null) {
// oid = user.getOID();
// }
// // If the category is the root, list all items
// if(cat == null || (cat.equals(section.getRootCategory()))) {
// return ContentPage.getPagesInSectionQuery
// (section, getContext(), oid);
// } else {
// return ContentPage.getPagesInSectionQuery
// (section, getContext(), cat, oid);
// }
// }
@Override
public ListModel makeModel(List l, PageState state) {
Category category = (Category) m_sel.getSelectedObject(state);
java.util.List<ContentItem> objects = category
.getObjects()
.stream().map(Categorization::getCategorizedObject)
.filter(x -> x instanceof ContentItem)
.map(x -> (ContentItem) x)
.collect(Collectors.toList());
return new ContentItemListModel(objects);
}
private class ContentItemListModel implements ListModel {
private final Iterator<ContentItem> iterator;
private ContentItem current;
public ContentItemListModel(java.util.List<ContentItem> list) {
this.iterator = list.iterator();
}
@Override
public boolean next() {
if (iterator.hasNext()) {
current = iterator.next();
return true;
}
return false;
}
@Override
public Object getElement() {
return current;
}
@Override
public String getKey() {
return current.getItemUuid();
}
}
}
/**
* Renders a ContentItem in preview mode
*/
private class ItemSummaryCellRenderer
implements TableCellRenderer {
@Override
public Component getComponent(Table table, PageState state, Object value,
boolean isSelected, Object key,
int row, int column) {
// if(value == null)
return new Label(GlobalizationUtil.globalize("&nbsp;"), false);
// DomainObject d = DomainObjectFactory.newInstance((DataObject)value);
//
// Assert.isTrue(d instanceof ContentPage);
// ContentPage p = (ContentPage)d;
//
// CMSContainer box = new CMSContainer();
// Component c;
//
// ContentSection section =
// CMS.getContext().getContentSection();
//
// ItemResolver resolver = (ItemResolver)m_resolver.get(state);
//
// final String url = resolver.generateItemURL
// (state, p.getID(), p.getName(), section,
// resolver.getCurrentContext(state));
// c = new Link(p.getTitle(), url);
//
// c.setClassAttr("title");
// box.add(c);
//
// String summary = p.getSearchSummary();
// if(summary != null && summary.length() > 0) {
// c = new Label(summary);
// c.setClassAttr("summary");
// box.add(c);
// }
//
// ContentType t = p.getContentType();
// if(t != null) {
// c = new Label(t.getName());
// } else {
// c = new Label(GlobalizationUtil.globalize("cms.ui.category.item"));
// }
// c.setClassAttr("type");
// box.add(c);
//
// box.setClassAttr("itemSummary");
// return box;
}
}
}

View File

@ -1,63 +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.category;
import com.arsdigita.bebop.list.ListModel;
import org.libreccm.categorization.Category;
import java.util.Iterator;
/**
* A {@link ListModel} that iterates over categories via an iterator
*
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/
public class CategoryIteratorListModel implements ListModel {
private Iterator m_iter;
private Category m_cat;
/**
* Construct a new <code>CategoryIteratorListModel</code>
*
* @param iter an {@link Iterator} over all the categories
* which this model will supply
*/
public CategoryIteratorListModel(Iterator iter) {
m_iter = iter;
m_cat = null;
}
public boolean next() {
if(m_iter.hasNext()) {
m_cat = (Category)m_iter.next();
return true;
} else {
return false;
}
}
public Object getElement() {
return m_cat.getName();
}
public String getKey() {
return m_cat.getUniqueId();
}
}

View File

@ -1,134 +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.category;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.List;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.event.ActionEvent;
import com.arsdigita.bebop.event.ActionListener;
import com.arsdigita.bebop.list.ListModel;
import com.arsdigita.bebop.list.ListModelBuilder;
import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.LockableImpl;
import org.libreccm.categorization.Category;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.l10n.GlobalizationHelper;
import org.librecms.CmsConstants;
import java.util.ArrayList;
/**
* A List of all secondary parents of the current category.
*
* @author Stanislav Freidin (stas@arsdigita.com)
* @author Michael Pih (pihman@arsdigita.com)
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/
public class CategoryLinks extends List {
public final static String SUB_CATEGORY = "sc";
private final CategoryRequestLocal m_parent;
private final SingleSelectionModel m_model;
public CategoryLinks(final CategoryRequestLocal parent,
final SingleSelectionModel model) {
super(new ParameterSingleSelectionModel(new BigDecimalParameter(
SUB_CATEGORY)));
setIdAttr("category_links_list");
m_parent = parent;
m_model = model;
setModelBuilder(new LinkedCategoryModelBuilder());
// Select the category in the main tree when the
// user selects it here
addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final PageState state = e.getPageState();
final String id = (String) getSelectedKey(state);
if (id != null) {
m_model.setSelectedKey(state, id);
}
}
});
final Label label = new Label(new GlobalizedMessage(
"cms.ui.category.linked_none",
CmsConstants.CMS_BUNDLE));
label.setFontWeight(Label.ITALIC);
setEmptyView(label);
}
// Since this part is for non default parents, but there is only one... this is not needed anymore, i guess
private class LinkedCategoryModelBuilder extends LockableImpl
implements ListModelBuilder {
@Override
public ListModel makeModel(List list, PageState state) {
final Category category = m_parent.getCategory(state);
if (category != null && category.getParentCategory() != null) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryController controller = cdiUtil
.findBean(CategoryController.class);
final GlobalizationHelper globalizationHelper = cdiUtil
.findBean(GlobalizationHelper.class);
final Category parent = controller
.getParentCategory(category).get();
java.util.List<CategoryListItem> categories = new ArrayList<>();
final CategoryListItem parentItem = new CategoryListItem();
parentItem.setCategoryId(parent.getObjectId());
final String label = globalizationHelper
.getValueFromLocalizedString(parent.getTitle(),
parent::getName);
parentItem.setLabel(label);
categories.add(parentItem);
return new CategoryListModel(
categories,
parent.getObjectId());
// return new CategoryListModel(categories,
// category.getParentCategory()
// == null ? null : Long
// .parseLong(
// parent
// .getUniqueId()));
} else {
return List.EMPTY_MODEL;
}
}
}
}

View File

@ -1,109 +0,0 @@
/*
* Copyright (C) 2017 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.category;
import java.util.Objects;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class CategoryListItem implements Comparable<CategoryListItem> {
private long categoryId;
private String label;
public long getCategoryId() {
return categoryId;
}
public void setCategoryId(final long categoryId) {
this.categoryId = categoryId;
}
public String getLabel() {
return label;
}
public void setLabel(final String label) {
this.label = label;
}
@Override
public int compareTo(final CategoryListItem other) {
final int result = label.compareTo(other.getLabel());
if (result == 0) {
return Long.compare(categoryId, other.getCategoryId());
} else {
return result;
}
}
@Override
public int hashCode() {
int hash = 7;
hash = 67 * hash + (int) (categoryId ^ (categoryId >>> 32));
hash = 67 * hash + Objects.hashCode(label);
return hash;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof CategoryListItem)) {
return false;
}
final CategoryListItem other = (CategoryListItem) obj;
if (!other.canEqual(this)) {
return false;
}
if (categoryId != other.getCategoryId()) {
return false;
}
return Objects.equals(label, other.getLabel());
}
public boolean canEqual(final Object obj) {
return obj instanceof CategoryListItem;
}
@Override
public final String toString() {
return toString("");
}
public String toString(final String data) {
return String.format("%s{ "
+ "categoryId = %d,"
+ "label = \"%s\"%s"
+ " }",
super.toString(),
categoryId,
label,
data);
}
}

View File

@ -1,91 +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.category;
import java.util.List;
import com.arsdigita.bebop.list.ListModel;
import java.util.Iterator;
/**
* A {@link ListModel} that iterates over categories via a cursor.
*
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class CategoryListModel implements ListModel {
private final Iterator<CategoryListItem> iterator;
private CategoryListItem currentCategory;
private Long excludedCategoryId;
/**
* Constructs a new <code>CategoryListModel</code>
*
* @param categories
*/
public CategoryListModel(final List<CategoryListItem> categories) {
this(categories, null);
}
/**
* Constructs a new <code>CategoryListModel</code>
*/
public CategoryListModel(final List<CategoryListItem> categories,
final Long excludedCategoryId) {
iterator = categories.iterator();
this.excludedCategoryId = excludedCategoryId;
}
@Override
public boolean next() {
if (iterator.hasNext()) {
final CategoryListItem next = iterator.next();
if (excludedCategoryId != null
&& next.getCategoryId() == excludedCategoryId) {
return next();
} else {
currentCategory = next;
return true;
}
} else {
return false;
}
}
/**
* Reads the label of the {@link CategoryListItem}.
*
*
*/
@Override
public Object getElement() {
return currentCategory.getLabel();
}
@Override
public String getKey() {
return Long.toString(currentCategory.getCategoryId());
}
}

View File

@ -1,154 +0,0 @@
/*
* Copyright (C) 2008 Sören Bernstein 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.category;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
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.form.Option;
import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.dispatcher.AccessDeniedException;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.kernel.KernelConfig;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryRepository;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.configuration.ConfigurationManager;
import org.libreccm.security.PermissionChecker;
import org.librecms.CmsConstants;
import org.librecms.contentsection.privileges.AdminPrivileges;
import java.util.Collection;
import java.util.Locale;
/**
* Generates a form for creating new localisations for the given category.
*
* This class is part of the admin GUI of CCM and extends the standard form in
* order to present forms for managing the multi-language categories.
*
* @author Sören Bernstein <quasi@quasiweb.de>
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/
public class CategoryLocalizationAddForm extends CategoryLocalizationForm {
private static final Logger LOGGER = LogManager.getLogger(
CategoryLocalizationAddForm.class);
/**
* Creates a new instance of CategoryLocalizationAddForm
*/
public CategoryLocalizationAddForm(final CategoryRequestLocal category) {
super("AddCategoryLocalization",
gz("cms.ui.category.localization_add"), category);
super.addInitListener(new InitListener());
super.addProcessListener(new ProcessListener());
}
// Deaktivate this widget, if category is root
// public boolean isVisible(PageState state) {
// return !m_category.getCategory(state).isRoot();
// }
private class InitListener implements FormInitListener {
public final void init(final FormSectionEvent e)
throws FormProcessException {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ConfigurationManager manager = cdiUtil.findBean(
ConfigurationManager.class);
final KernelConfig config = manager.findConfiguration(
KernelConfig.class);
final PageState state = e.getPageState();
final Category category = m_category.getCategory(state);
// Select one entry
m_locale.addOption(new Option("",
new Label(new GlobalizedMessage(
"cms.ui.select_one",
CmsConstants.CMS_BUNDLE))),
state);
final Collection<String> locales = config.getSupportedLanguages();
if (locales != null) {
for (String locale : locales) {
m_locale.addOption(new Option(locale,
new Text(new Locale(locale)
.getDisplayLanguage())),
state);
}
}
}
}
private final class ProcessListener implements FormProcessListener {
public final void process(final FormSectionEvent e)
throws FormProcessException {
LOGGER.debug("Adding a categoryLocalization to category "
+ m_category);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
final CategoryRepository categoryRepository = cdiUtil.findBean(
CategoryRepository.class);
final PageState state = e.getPageState();
final Category category = m_category.getCategory(state);
final Locale locale = new Locale((String) m_locale.getValue(state));
final String title = (String) m_title.getValue(state);
final String description = (String) m_description.getValue(state);
// final String url = (String) m_url.getValue(state);
// final String isEnabled = (String) m_isEnabled.getValue(state);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Adding localization for locale " + locale
+ " to category " + category);
}
if (permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_CATEGORIES, category)) {
category.getTitle().putValue(locale, title);
category.getDescription().putValue(locale, description);
// category.setEnabled(isEnabled.equals("yes"));
categoryRepository.save(category);
} else {
// XXX user a better exception here.
// PermissionException doesn't work for this case.
throw new AccessDeniedException();
}
}
}
}

View File

@ -1,133 +0,0 @@
/*
* Copyright (C) 2008 Sören Bernstein 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.category;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.PageState;
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.form.Option;
import com.arsdigita.dispatcher.AccessDeniedException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryRepository;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.privileges.AdminPrivileges;
import java.util.Locale;
/**
* Generates a form for editing an existing localisation for the given category.
*
* This class is part of the admin GUI of CCM and extends the standard form
* in order to present forms for managing the multi-language categories.
*
* @author Sören Bernstein <quasi@quasiweb.de>
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/
public class CategoryLocalizationEditForm extends CategoryLocalizationForm {
private static final Logger LOGGER = LogManager.getLogger(
CategoryLocalizationAddForm.class);
private final SingleSelectionModel m_catLocale;
/**
* Creates a new instance of CategoryLocalizationEditForm
*/
public CategoryLocalizationEditForm(final CategoryRequestLocal category, SingleSelectionModel catLocale) {
super("EditCategoryLocalization", gz(
"cms.ui.category.localization_edit"), category);
m_catLocale = catLocale;
addInitListener(new InitListener());
addProcessListener(new ProcessListener());
}
/**
* please add: purpose of this class
*/
private class InitListener implements FormInitListener {
public final void init(final FormSectionEvent e)
throws FormProcessException {
final PageState state = e.getPageState();
final Category category = m_category.getCategory(state);
final String categoryLocalizationLocale = (String) m_catLocale.getSelectedKey(state);
final Locale locale = new Locale(categoryLocalizationLocale);
// Hide Locale-Widget and lock it (read-only)
m_locale.addOption(new Option(categoryLocalizationLocale,
new Text(locale.getDisplayLanguage())), state);
m_locale.setValue(state, categoryLocalizationLocale);
// m_locale.setVisible(state, false);
m_locale.lock();
m_title.setValue(state, category.getTitle().getValue(locale));
m_description.setValue(state, category.getDescription().getValue(locale));
// m_url.setValue(state, category.getName());
// if (category.isEnabled()) {
// m_isEnabled.setValue(state, "yes");
// } else {
// m_isEnabled.setValue(state, "no");
// }
}
}
/**
* ##todo: document purpose of this
*/
private class ProcessListener implements FormProcessListener {
public final void process(final FormSectionEvent e)
throws FormProcessException {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
final CategoryRepository categoryRepository = cdiUtil.findBean(CategoryRepository.class);
final PageState state = e.getPageState();
final Category category = m_category.getCategory(state);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Editing localization for locale " + m_locale +
" for category " + category);
}
if (permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES, category)) {
final Locale locale = new Locale((String) m_locale.getValue(state));
category.getTitle().putValue(locale, (String) m_title.getValue(state));
category.getDescription().putValue(locale, (String) m_description.getValue(state));
// category.setName((String) m_url.getValue(state));
// category.setEnabled("yes".equals(m_isEnabled.getValue(state)));
categoryRepository.save(category);
} else {
throw new AccessDeniedException();
}
}
}
}

View File

@ -1,254 +0,0 @@
/*
* Copyright (C) 2008 Sören Bernstein 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.category;
import com.arsdigita.bebop.Embedded;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.ParameterEvent;
import com.arsdigita.bebop.event.ParameterListener;
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.RadioGroup;
import com.arsdigita.bebop.form.SingleSelect;
import com.arsdigita.bebop.form.TextArea;
import com.arsdigita.bebop.form.TextField;
import com.arsdigita.bebop.form.Widget;
import com.arsdigita.bebop.parameters.NotNullValidationListener;
import com.arsdigita.bebop.parameters.ParameterData;
import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringInRangeValidationListener;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.bebop.parameters.TrimmedStringParameter;
import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.cms.ui.BaseForm;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.web.Web;
import com.arsdigita.xml.Element;
import org.apache.logging.log4j.LogManager;
import org.libreccm.categorization.Category;
import java.util.List;
import java.util.TooManyListenersException;
/**
* Base class for CategoryLocalizationAddForm and CategoryLocalizationEditForm.
*
* This class is part of the admin GUI of CCM and extends the standard form in order to present
* forms for managing the multi-language categories.
*
* @author Sören Bernstein <quasi@quasiweb.de>
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/
public class CategoryLocalizationForm extends BaseForm {
private static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(
CategoryLocalizationForm.class);
final CategoryRequestLocal m_category;
final SingleSelect m_locale;
final TextField m_title;
final TextArea m_description;
//final TextField m_url;
// final Hidden m_url;
// final RadioGroup m_isEnabled;
// private Embedded m_script = new Embedded(String.format(
// "<script language=\"javascript\" src=\"%s/javascript/manipulate-input.js\">" + "</script>",
// Web.getWebappContextPath()),
// false);
private final static String LOCALE = "locale";
private final static String TITLE = "title";
private final static String DESCRIPTION = "description";
private final static String URL = "url";
private final static String IS_ENABLED = "isEnabled";
/**
* Creates a new instance of CategoryLocalizationForm.
*
* @param key
* @param heading
* @param category
*/
public CategoryLocalizationForm(final String key,
final GlobalizedMessage heading,
final CategoryRequestLocal category) {
super(key, heading);
m_category = category;
// Parameter-Model for SingleSelect
ParameterModel localeParam = new StringParameter(LOCALE);
localeParam.addParameterListener(new StringInRangeValidationListener(0, 2));
m_locale = new SingleSelect(localeParam);
m_locale.addValidationListener(e -> {
// the --select one-- option is not allowed
ParameterData data = e.getParameterData();
String code = (String) data.getValue();
if (code == null || code.length() == 0) {
data.addError(
GlobalizationUtil.globalize(
"cms.ui.category.localization_error_locale"));
}
});
addField(gz("cms.ui.category.localization_locale"), m_locale);
m_title = new TextField(new TrimmedStringParameter(TITLE));
addField(gz("cms.ui.title"), m_title);
m_title.setSize(30);
m_title.setMaxLength(200);
m_title.addValidationListener(new NotNullValidationListener());
m_title.setOnFocus("if (this.form." + URL + ".value == '') { "
+ " defaulting = true; this.form." + URL
+ ".value = urlize(this.value); }");
m_title.setOnKeyUp("if (defaulting) { this.form." + URL + ".value = urlize(this.value) }");
// is enabled?
// m_isEnabled = new RadioGroup(IS_ENABLED);
// m_isEnabled.addOption(new Option("no", new Label(gz("cms.ui.no"))));
// m_isEnabled.addOption(new Option("yes", new Label(gz("cms.ui.yes"))));
// addField(gz("cms.ui.category.is_enabled"), m_isEnabled);
m_description = new TextArea(new TrimmedStringParameter(DESCRIPTION));
addField(gz("cms.ui.description"), m_description);
m_description.setWrap(TextArea.SOFT);
m_description.setRows(5);
m_description.setCols(40);
// URL
// JavaScript auto-url generation is off by default.
// It is turned on under the following circumstances
//
// * If the url is null, upon starting edit of the title
// * If the url is null, upon finishing edit of name
//
// The rationale is that, auto-url generation is useful
// if the url is currently null, but once a name has been
// created you don't want to subsequently change it since
// it breaks URLs & potentially overwrites the user's
// customizations.
// m_url = new TextField(new TrimmedStringParameter(URL));
// m_url.setSize(30);
// m_url.setMaxLength(200);
// m_url.addValidationListener(new NotNullValidationListener());
// m_url.setOnFocus("defaulting = false");
// m_url.setOnBlur("if (this.value == '') "
// + "{ defaulting = true; this.value = urlize(this.form." + TITLE
// + ".value) } " + "else { this.value = urlize(this.value); }");
// addField(gz("cms.ui.category.url"), m_url);
//jensp 2014-09-16: Localisation of URLs is not useful but causes problems when resolving
//the URLs. Also, a category is the same resource for every language variant therefore
//the URL should be the same.
//Changed field to Hidden, initalised with URL of category itself.
// m_url = new Hidden(new TrimmedStringParameter(URL));
// try {
// m_url.addPrintListener(new PrintListener() {
//
// @Override
// public void prepare(final PrintEvent event) {
// final Hidden target = (Hidden) event.getTarget();
// final PageState state = event.getPageState();
//
// final Category cat = m_category.getCategory(state);
//
// target.setValue(state, cat.getName());
// }
//
// });
// } catch (TooManyListenersException | IllegalArgumentException ex) {
// LOGGER.fatal(ex);
// }
// addField(gz("cms.ui.category.url"), m_url);
addAction(new Finish());
addAction(new Cancel());
}
@Override
public void generateXML(PageState ps, Element parent) {
// m_script.generateXML(ps, parent);
super.generateXML(ps, parent);
}
/**
* Purpose:
*
* XXXToDo: Should be extended with the function: Names have to be unambiguous in the selected
* language
*/
class NameUniqueListener implements ParameterListener {
private final CategoryRequestLocal m_category;
private final Widget m_widget;
private final int m_type;
final static int NAME_FIELD = 1;
public final static int URL_FIELD = 2;
NameUniqueListener(final CategoryRequestLocal category) {
this(category, m_title, NAME_FIELD);
}
NameUniqueListener(final CategoryRequestLocal category,
Widget widget, int type) {
m_category = category;
m_widget = widget;
m_type = type;
}
/**
* Purpose:
*
* XXX provisional, has to be adapted
*
* @param e
*
* @throws com.arsdigita.bebop.FormProcessException
*/
@Override
public final void validate(final ParameterEvent e)
throws FormProcessException {
final PageState state = e.getPageState();
final String title = (String) m_widget.getValue(state);
final Category category = m_category.getCategory(state);
final List<Category> children = category.getSubCategories();
for (Category child : children) {
String compField = child.getName();
if (compField.equalsIgnoreCase(title)
|| !m_category.getCategory(state).equals(child)) {
throw new FormProcessException(GlobalizationUtil.globalize("cms.ui.category.name_not_unique"));
}
}
}
}
}

View File

@ -1,313 +0,0 @@
/*
* Copyright (C) 2008 Sören Bernstein 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.category;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.ControlLink;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.event.TableActionEvent;
import com.arsdigita.bebop.event.TableActionListener;
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.bebop.util.GlobalizationUtil;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.LockableImpl;
import org.libreccm.categorization.Category;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.l10n.GlobalizedMessagesUtil;
import org.libreccm.security.PermissionChecker;
import org.librecms.CmsConstants;
import org.librecms.contentsection.privileges.AdminPrivileges;
import java.util.Iterator;
import java.util.List;
/**
* Lists all existing localizations for a selected category.
*
* This class is part of the admin GUI of CCM and extends the standard form in
* order to present forms for managing the multi-language categories.
*
* @author Sören Bernstein <quasi@quasiweb.de>
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/
public class CategoryLocalizationTable extends Table implements
TableActionListener {
private static final String TABLE_COL_LANG = "table_col_lang";
private static final String TABLE_COL_DEL = "table_col_del";
private static final int COL_LOCALE = 0;
private static final int COL_TITLE = 1;
private static final int COL_DESCRIPTION = 2;
private static final int COL_EDIT = 3;
private static final int COL_DEL = 4;
private final CategoryRequestLocal m_category;
private final SingleSelectionModel m_model;
private final SingleSelectionModel m_catLocale;
/**
* Creates a new instance of CategoryLocalizationTable
*/
public CategoryLocalizationTable(final CategoryRequestLocal category,
final SingleSelectionModel model,
final SingleSelectionModel catLocale) {
super();
m_category = category;
m_model = model;
m_catLocale = catLocale;
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final GlobalizationHelper globalizationHelper = cdiUtil
.findBean(GlobalizationHelper.class);
final GlobalizedMessagesUtil messagesUtil = globalizationHelper
.getGlobalizedMessagesUtil(CmsConstants.CMS_BUNDLE);
// if table is empty:
setEmptyView(new Label(messagesUtil
.getGlobalizedMessage("cms.ui.category.localization_none")));
final TableColumnModel columnModel = getColumnModel();
// define columns
columnModel.add(new TableColumn(
COL_LOCALE,
messagesUtil.getGlobalizedMessage(
"cms.ui.category.localization.locale"),
TABLE_COL_LANG));
columnModel.add(new TableColumn(
COL_TITLE,
messagesUtil
.getGlobalizedMessage("cms.ui.category.localization_title")));
columnModel.add(new TableColumn(
COL_DESCRIPTION,
messagesUtil.getGlobalizedMessage(
"cms.ui.category.localization_description")));
columnModel.add(new TableColumn(
COL_EDIT,
messagesUtil
.getGlobalizedMessage("cms.ui.category.localization_edit")));
columnModel.add(new TableColumn(
COL_DEL,
messagesUtil
.getGlobalizedMessage("cms.ui.category.localization_action"),
TABLE_COL_DEL));
super.setModelBuilder(new CategoryLocalizationTableModelBuilder());
columnModel.get(0).setCellRenderer(new EditCellRenderer());
columnModel.get(4).setCellRenderer(new DeleteCellRenderer());
super.addTableActionListener(this);
}
private class CategoryLocalizationTableModelBuilder extends LockableImpl
implements TableModelBuilder {
@Override
public TableModel makeModel(final Table table, final PageState state) {
final Category category = m_category.getCategory(state);
if (category == null) {
return Table.EMPTY_MODEL;
} else {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryLocalizationTableController controller = cdiUtil
.findBean(CategoryLocalizationTableController.class);
final List<CategoryLocalizationTableRow> rows = controller
.getCategoryLocalizations(category);
return new CategoryLocalizationTableModel(table, rows);
}
}
}
private class CategoryLocalizationTableModel implements TableModel {
private final Table table;
private final Iterator<CategoryLocalizationTableRow> iterator;
private CategoryLocalizationTableRow currentRow;
private CategoryLocalizationTableModel(
final Table table,
final List<CategoryLocalizationTableRow> rows) {
this.table = table;
iterator = rows.iterator();
}
@Override
public int getColumnCount() {
return table.getColumnModel().size();
}
@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 COL_LOCALE:
return currentRow.getLocale();
case COL_TITLE:
return currentRow.getTitle();
case COL_DESCRIPTION:
return currentRow.getDescription();
case COL_EDIT:
return new GlobalizedMessage("cms.ui.edit",
CmsConstants.CMS_BUNDLE);
case COL_DEL:
return new GlobalizedMessage("cms.ui.delete",
CmsConstants.CMS_BUNDLE);
default:
throw new IllegalArgumentException("Illegal Column Index");
}
}
/**
*
* @see com.arsdigita.bebop.table.TableModel#getKeyAt(int)
*/
@Override
public Object getKeyAt(final int columnIndex) {
return currentRow.getLocale();
}
}
private class EditCellRenderer 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) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
if (permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_CATEGORIES, m_category.getCategory(
state))) {
return new ControlLink(value.toString());
} else {
return new Label(GlobalizationUtil.globalize(value.toString()));
}
}
}
private class DeleteCellRenderer 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) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
if (permissionChecker.isPermitted(
AdminPrivileges.ADMINISTER_CATEGORIES, m_category.getCategory(
state))) {
ControlLink link = new ControlLink(value.toString());
link.setConfirmation(GlobalizationUtil.globalize(
"cms.ui.category.localization_confirm_delete"));
return link;
} else {
return null;
}
}
}
/**
* Provide implementation to TableActionListener method. Code that comes
* into picture when a link on the table is clicked. Handles edit and delete
* event.
*/
@Override
public void cellSelected(final TableActionEvent event) {
PageState state = event.getPageState();
// // Get selected CategoryLocalization
// CategoryLocalization categoryLocalization =
// new CategoryLocalization(new BigDecimal(evt.getRowKey().toString()));
//
// // Get Category
// Category category = m_category.getCategory(state);
//
// // Get selected column
// TableColumn col = getColumnModel().get(evt.getColumn().intValue());
//
// // Edit
// if (col.getHeaderKey().toString().equals(TABLE_COL_LANG)) {
// m_catLocale.setSelectedKey(state, categoryLocalization.getLocale());
// }
//
// // Delete
// if (col.getHeaderKey().toString().equals(TABLE_COL_DEL)) {
// category.delLanguage(categoryLocalization.getLocale());
// }
}
/**
* provide Implementation to TableActionListener method. Does nothing in our
* case.
*/
@Override
public void headSelected(final TableActionEvent event) {
//Nothing
}
}

View File

@ -1,77 +0,0 @@
/*
* Copyright (C) 2018 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.category;
import org.libreccm.categorization.Category;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
import javax.transaction.Transactional;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@RequestScoped
class CategoryLocalizationTableController {
@Transactional(Transactional.TxType.REQUIRED)
protected List<CategoryLocalizationTableRow> getCategoryLocalizations(
final Category forCategory) {
final Map<Locale, CategoryLocalizationTableRow> localizations
= new HashMap<>();
final Set<Locale> locales = new HashSet<>();
locales.addAll(forCategory.getTitle().getAvailableLocales());
locales.addAll(forCategory.getDescription().getAvailableLocales());
return locales
.stream()
.map(locale -> generateRow(locale, forCategory))
.sorted()
.collect(Collectors.toList());
}
private CategoryLocalizationTableRow generateRow(final Locale locale,
final Category category) {
final CategoryLocalizationTableRow row
= new CategoryLocalizationTableRow(
locale);
if (category.getTitle().hasValue(locale)) {
row.setTitle(category.getTitle().getValue(locale));
}
if (category.getDescription().hasValue(locale)) {
row.setDescription(category.getDescription().getValue(locale));
}
return row;
}
}

View File

@ -1,120 +0,0 @@
/*
* Copyright (C) 2018 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.category;
import java.util.Locale;
import java.util.Objects;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
class CategoryLocalizationTableRow
implements Comparable<CategoryLocalizationTableRow> {
private final Locale locale;
private String title;
private String description;
public CategoryLocalizationTableRow(final Locale locale) {
this.locale = locale;
}
public Locale getLocale() {
return locale;
}
public String getTitle() {
return title;
}
public void setTitle(final String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(final String description) {
this.description = description;
}
@Override
public int compareTo(final CategoryLocalizationTableRow other) {
return locale.toString().compareTo(other.getLocale().toString());
}
@Override
public int hashCode() {
int hash = 7;
hash = 53 * hash + Objects.hashCode(locale);
hash = 53 * hash + Objects.hashCode(title);
hash = 53 * hash + Objects.hashCode(description);
return hash;
}
@Override
public boolean equals(final Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof CategoryLocalizationTableRow)) {
return false;
}
final CategoryLocalizationTableRow other
= (CategoryLocalizationTableRow) obj;
if (!other.canEqual(this)) {
return false;
}
if (!Objects.equals(title, other.getTitle())) {
return false;
}
if (!Objects.equals(description, other.getDescription())) {
return false;
}
return Objects.equals(locale, other.getLocale());
}
public boolean canEqual(final Object obj) {
return obj instanceof CategoryLocalizationTableRow;
}
@Override
public String toString() {
return toString("");
}
public String toString(final String data) {
return String.format("%s{ "
+ "locale = \"%s\", "
+ "title = \"%s\", "
+ "description = \"%s\"%s"
+ " }",
super.toString(),
Objects.toString(locale),
title,
description,
data);
}
}

View File

@ -1,180 +0,0 @@
/*
* Copyright (C) 2013 Jens Pelzetter 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.category;
import com.arsdigita.bebop.*;
import com.arsdigita.bebop.event.ChangeEvent;
import com.arsdigita.bebop.event.ChangeListener;
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.Submit;
import com.arsdigita.bebop.parameters.ParameterModel;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.cms.ui.BaseTree;
import com.arsdigita.cms.ui.CMSForm;
import com.arsdigita.cms.ui.FormSecurityListener;
import com.arsdigita.util.Assert;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.categorization.CategoryRepository;
import org.libreccm.cdi.utils.CdiUtil;
import org.librecms.contentsection.privileges.AdminPrivileges;
import java.math.BigDecimal;
import java.util.Optional;
/**
*
* @author Jens Pelzetter <jens@jp-digital.de>
*/
public class CategoryMoveForm extends CMSForm {
public static final String CONTEXT_SELECTED = "sel_context";
//private static final String DEFAULT_USE_CONTEXT =
// CategoryUseContextModelBuilder.DEFAULT_USE_CONTEXT;
private final CategoryRequestLocal selectedCategory;
private final SaveCancelSection saveCancelSection;
private final ChangeListener changeListener;
private final SingleSelectionModel selectionModel;
private final Tree categoryTree;
public CategoryMoveForm(final CategoryRequestLocal selectedCategory,
final SingleSelectionModel contextModel) {
super("MoveCategory");
setMethod(Form.POST);
this.selectedCategory = selectedCategory;
final Label header = new Label(GlobalizationUtil.globalize("cms.ui.category.move"));
//final Label header = new Label();
header.addPrintListener(new PrintListener() {
@Override
public void prepare(final PrintEvent event) {
final String[] args = new String[1];
args[0] = selectedCategory.getCategory(event.getPageState()).getName();
final Label target = (Label) event.getTarget();
target.setLabel(GlobalizationUtil.globalize("cms.ui.move.category", args));
}
});
header.setFontWeight(Label.BOLD);
add(header, ColumnPanel.FULL_WIDTH);
changeListener = new TreeChangeListener();
selectionModel = new ParameterSingleSelectionModel(new StringParameter("selectedCategory"));
categoryTree = new BaseTree(new CategoryTreeModelBuilder(contextModel));
categoryTree.addChangeListener(changeListener);
add(categoryTree);
saveCancelSection = new SaveCancelSection();
add(saveCancelSection);
addInitListener(new InitListener());
addProcessListener(new ProcessListener());
addSubmissionListener(new FormSecurityListener(AdminPrivileges.ADMINISTER_CATEGORIES));
}
protected Submit getCancelButton() {
return saveCancelSection.getCancelButton();
}
protected Category getCategory(final PageState state) {
final Category category = selectedCategory.getCategory(state);
Assert.exists(category);
return category;
}
private class TreeChangeListener implements ChangeListener {
public TreeChangeListener() {
//Nothing
}
@Override
public void stateChanged(final ChangeEvent event) {
//Nothing for now
}
}
private class InitListener implements FormInitListener {
public InitListener() {
//Nothing
}
@Override
public void init(final FormSectionEvent event) throws FormProcessException {
//Nothing
}
}
private class ProcessListener implements FormProcessListener {
public ProcessListener() {
//Nothing
}
@Override
public void process(final FormSectionEvent event) throws FormProcessException {
final PageState state = event.getPageState();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryRepository categoryRepository = cdiUtil.findBean(CategoryRepository.class);
final CategoryManager categoryManager = cdiUtil.findBean(CategoryManager.class);
if (saveCancelSection.getSaveButton().isSelected(state)
&& !(categoryTree.getSelectedKey(state).equals(selectedCategory.getCategory(state).getUniqueId()))) {
final Category categoryToMove = selectedCategory.getCategory(state);
final String targetKey = (String) categoryTree.getSelectedKey(state);
final Optional<Category> categoryOptional = categoryRepository.findById(Long.parseLong(targetKey));
if (categoryOptional.isPresent()) {
final Category target = categoryOptional.get();
final Category parent = categoryToMove.getParentCategory();
categoryManager.removeSubCategoryFromCategory(categoryToMove, parent);
categoryRepository.save(parent);
categoryManager.addSubCategoryToCategory(categoryToMove, target);
categoryToMove.setParentCategory(target);
categoryRepository.save(target);
categoryRepository.save(categoryToMove);
} else {
throw new FormProcessException(GlobalizationUtil.globalize("Category with id" + targetKey + " does not exist!"));
}
}
categoryTree.clearSelection(state);
categoryTree.clearExpansionState(state);
}
}
}

View File

@ -1,31 +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.category;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.RequestLocal;
import org.libreccm.categorization.Category;
public class CategoryRequestLocal extends RequestLocal {
public final Category getCategory(final PageState state) {
return (Category) get(state);
}
}

View File

@ -1,116 +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.category;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.Tree;
import com.arsdigita.bebop.tree.TreeModel;
import com.arsdigita.bebop.tree.TreeModelBuilder;
import com.arsdigita.cms.CMS;
import com.arsdigita.util.LockableImpl;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryTreeModelLite;
import org.libreccm.categorization.Domain;
import org.libreccm.categorization.DomainOwnership;
import org.libreccm.categorization.DomainRepository;
import org.libreccm.cdi.utils.CdiUtil;
import org.librecms.contentsection.ContentSection;
/**
* Lists category tree.
*
* @author Tri Tran (tri@arsdigita.com)
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/
class CategoryTreeModelBuilder extends LockableImpl
implements TreeModelBuilder {
// private static String DEFAULT_USE_CONTEXT = "<default>";
private final SingleSelectionModel<String> selectedCategorySystem;
public CategoryTreeModelBuilder() {
this(null);
}
public CategoryTreeModelBuilder(
final SingleSelectionModel<String> selectedCategorySystem) {
super();
this.selectedCategorySystem = selectedCategorySystem;
}
@Override
public final TreeModel makeModel(final Tree tree, final PageState state) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final Category root;
if (selectedCategorySystem.getSelectedKey(state) == null) {
final ContentSection section = CMS.getContext().getContentSection();
final CategoryAdminController controller = cdiUtil
.findBean(CategoryAdminController.class);
final java.util.List<DomainOwnership> ownerships
= controller
.retrieveDomains(section);
if (ownerships == null || ownerships.isEmpty()) {
root = null;
} else {
root = ownerships.get(0).getDomain().getRoot();
}
} else {
final DomainRepository domainRepo = cdiUtil
.findBean(DomainRepository.class);
final Domain categorySystem = domainRepo
.findById(Long.parseLong(selectedCategorySystem
.getSelectedKey(state)))
.orElseThrow(() -> new IllegalArgumentException(String
.format("No Domain with ID %s in the database.",
selectedCategorySystem.getSelectedKey(state))));
root = categorySystem.getRoot();
}
// if (DEFAULT_USE_CONTEXT.equals(selectedCategorySystem.getSelectedKey(
// state))) {
// final ContentSection section = CMS
// .getContext()
// .getContentSection();
//
// final CategoryAdminController controller = cdiUtil
// .findBean(CategoryAdminController.class);
// final java.util.List<DomainOwnership> ownerships
// = controller
// .retrieveDomains(section);
// root = ownerships.get(0).getDomain().getRoot();
// } else {
// final CategoryRepository categoryRepo = cdiUtil
// .findBean(CategoryRepository.class);
// root = categoryRepo
// .findById(Long.parseLong((String) m_contextModel
// .getSelectedKey(state)))
// .orElseThrow(() -> new UnexpectedErrorException(String
// .format("No Category with ID %s in the database.",
// m_contextModel.getSelectedKey(state))));
// }
return new CategoryTreeModelLite(root);
}
}

View File

@ -1,102 +0,0 @@
/*
* Copyright (C) 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.category;
import com.arsdigita.bebop.List;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.list.AbstractListModelBuilder;
import com.arsdigita.bebop.list.ListModel;
import com.arsdigita.cms.CMS;
import org.libreccm.categorization.Domain;
import org.libreccm.categorization.DomainOwnership;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.l10n.GlobalizationHelper;
import org.librecms.contentsection.ContentSection;
import java.util.Iterator;
/**
* Builds a list of category use contexts for the current content section.
*
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
* @author Scott Seago
*/
class CategoryUseContextModelBuilder extends AbstractListModelBuilder {
@Override
public final ListModel makeModel(final List list, final PageState state) {
return new Model();
}
private class Model implements ListModel {
private final Iterator<DomainOwnership> roots;
private DomainOwnership current;
public Model() {
final ContentSection section = CMS
.getContext()
.getContentSection();
final CategoryAdminController controller = CdiUtil
.createCdiUtil()
.findBean(CategoryAdminController.class);
roots = controller.retrieveDomains(section).iterator();
current = null;
}
@Override
public boolean next() {
if (roots.hasNext()) {
current = roots.next();
return true;
} else {
return false;
}
}
@Override
public Object getElement() {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final GlobalizationHelper globalizationHelper = cdiUtil
.findBean(GlobalizationHelper.class);
final Domain categorySystem = current.getDomain();
if (categorySystem
.getTitle()
.hasValue(globalizationHelper.getNegotiatedLocale())) {
return globalizationHelper
.getValueFromLocalizedString(current.getDomain().getTitle());
} else {
return categorySystem.getDomainKey();
}
}
@Override
public String getKey() {
return Long.toString(current.getDomain().getObjectId());
}
}
}

View File

@ -1,89 +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.category;
import com.arsdigita.bebop.list.ListModel;
import org.librecms.contentsection.ContentItem;
import java.util.Iterator;
import java.util.List;
/**
* A {@link ListModel} that iterates over content items via a cursor.
*
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/
public final class ContentItemListModel implements ListModel {
private ContentItem m_contentItem;
private long m_excludedID;
private Iterator<ContentItem> iterator;
/**
* Constructs a new <code>ContentItemListModel</code>
*/
public ContentItemListModel(List<ContentItem> coll) {
this(coll, -1); //Hopefully a decent replacement for null in BigDecimal. Negative ids would be weird...
}
/**
* Constructs a new <code>ContentItemListModel</code>
*/
public ContentItemListModel(List<ContentItem> coll,
long excludedID) {
m_excludedID = excludedID;
m_contentItem = null;
iterator = coll.iterator();
}
public boolean next() {
if (iterator.hasNext()) {
final ContentItem contentItem = iterator.next();
if (Long.parseLong(contentItem.getItemUuid()) == m_excludedID) {
return next();
} else {
m_contentItem = contentItem;
return true;
}
} else {
return false;
}
}
private ContentItem getContentItem() {
if ( m_contentItem == null ) {
throw new IllegalStateException("call next() first");
}
return m_contentItem;
}
/**
* Reads the name of the content item.
*
*/
public Object getElement() {
return getContentItem().getName();
}
public String getKey() {
return getContentItem().getItemUuid();
}
}

View File

@ -1,280 +0,0 @@
/*
* Copyright (C) 2002-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.category;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.FormData;
import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Link;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SaveCancelSection;
import com.arsdigita.bebop.Text;
import com.arsdigita.bebop.event.FormSectionEvent;
import com.arsdigita.bebop.event.PrintEvent;
import com.arsdigita.bebop.form.FormErrorDisplay;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.form.RadioGroup;
import com.arsdigita.bebop.form.Submit;
import com.arsdigita.bebop.parameters.ParameterData;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ui.CMSForm;
import com.arsdigita.cms.ui.FormSecurityListener;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.categorization.CategoryRepository;
import org.libreccm.categorization.ObjectNotAssignedToCategoryException;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.core.CcmObject;
import org.libreccm.core.UnexpectedErrorException;
import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.l10n.GlobalizedMessagesUtil;
import org.librecms.CmsConstants;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentItemManager;
import org.librecms.contentsection.ContentItemRepository;
import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentSectionManager;
import org.librecms.contentsection.privileges.AdminPrivileges;
import org.librecms.dispatcher.ItemResolver;
import java.util.List;
import java.util.Optional;
import java.util.TooManyListenersException;
/**
* Allows the user to select an index item to display when the front end user is
* browsing by Category
*
* @author Randy Graebner (randyg@alum.mit.edu)
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class IndexItemSelectionForm extends CMSForm {
private static final Logger LOGGER = LogManager.getLogger(
IndexItemSelectionForm.class);
private static final String NULL_OPTION_VALUE = "";
private static final String NONE_OPTION_VALUE = "None";
private final CategoryRequestLocal selectedCategory;
private RadioGroup optionsGroup;
private final SaveCancelSection saveCancelSection;
public IndexItemSelectionForm(final CategoryRequestLocal selectedCategory) {
super("EditCategory");
super.setMethod(Form.POST);
this.selectedCategory = selectedCategory;
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final GlobalizationHelper globalizationHelper = cdiUtil
.findBean(GlobalizationHelper.class);
final GlobalizedMessagesUtil messagesUtil = globalizationHelper
.getGlobalizedMessagesUtil(CmsConstants.CMS_BUNDLE);
// Form header
final Label header = new Label(messagesUtil
.getGlobalizedMessage("cms.ui.category.select_index_item"));
header.setFontWeight(Label.BOLD);
super.add(header, ColumnPanel.FULL_WIDTH);
// Form errors
final FormErrorDisplay errorsDisplay = new FormErrorDisplay(this);
super.add(errorsDisplay, ColumnPanel.FULL_WIDTH);
// Option Group
optionsGroup = new RadioGroup(new StringParameter("items"));
try {
optionsGroup.addPrintListener(this::printOptionsGroup);
} catch (TooManyListenersException ex) {
LOGGER.error("Error adding init listener to Radio Group", ex);
throw new UnexpectedErrorException(ex);
}
optionsGroup.setLayout(RadioGroup.VERTICAL);
super.add(optionsGroup);
// Save and cancel buttons
saveCancelSection = new SaveCancelSection();
super.add(saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
super.addSubmissionListener(new FormSecurityListener(
AdminPrivileges.ADMINISTER_CATEGORIES));
// Process listener
super.addProcessListener(this::process);
}
private void printOptionsGroup(final PrintEvent event) {
final RadioGroup group = (RadioGroup) event.getTarget();
final PageState state = event.getPageState();
final Category category = getCategory(event.getPageState());
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryAdminController controller = cdiUtil
.findBean(CategoryAdminController.class);
final ContentItemManager itemManager = cdiUtil
.findBean(ContentItemManager.class);
final CategoryManager categoryManager = cdiUtil
.findBean(CategoryManager.class);
final ContentSectionManager sectionManager = cdiUtil
.findBean(ContentSectionManager.class);
final GlobalizationHelper globalizationHelper = cdiUtil
.findBean(GlobalizationHelper.class);
final GlobalizedMessagesUtil messagesUtil = globalizationHelper
.getGlobalizedMessagesUtil(CmsConstants.CMS_BUNDLE);
group.clearOptions();
// option for NO index Object
group.addOption(
new Option(NONE_OPTION_VALUE,
new Label(messagesUtil
.getGlobalizedMessage("cms.ui.category.non_option"))));
// option for inheriting from the parent category
if (category.getParentCategory() != null) {
group.addOption(
new Option(NULL_OPTION_VALUE,
new Label(messagesUtil
.getGlobalizedMessage(
"cms.ui.category.inherit_parent"))));
}
final ContentSection section = CMS.getContext()
.getContentSection();
final ItemResolver itemResolver = sectionManager
.getItemResolver(section);
final List<ContentItem> assignedItems = controller
.retrieveAssignedContentItems(category);
for (final ContentItem item : assignedItems) {
final Link link = new Link(
new Text(item.getDisplayName()),
itemResolver.generateItemURL(
state,
item.getObjectId(),
item.getDisplayName(),
section,
item.getVersion().name()
)
);
//add the option with the link
group.addOption(new Option(Long.toString(item.getObjectId()), link));
}
// get currently selected item
final Optional<CcmObject> optionalIndexObject = categoryManager
.getIndexObject(category)
.stream()
.findFirst();
if (optionalIndexObject.isPresent()) {
final ContentItem indexItem
= (ContentItem) optionalIndexObject
.get();
final ContentItem liveItem = itemManager
.getLiveVersion(indexItem, ContentItem.class)
.get();
group.setValue(
state,
Long.toString(liveItem.getObjectId()));
} else {
final String value;
if (category.getParentCategory() == null) {
value = NULL_OPTION_VALUE;
} else {
value = NONE_OPTION_VALUE;
}
group.setValue(state, value);
}
}
private void process(final FormSectionEvent event)
throws FormProcessException {
final FormData data = event.getFormData();
final ParameterData param = data
.getParameter(optionsGroup.getParameterModel().getName());
final String selectedValue = (String) param.getValue();
final Category category = getCategory(event.getPageState());
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryManager categoryManager = cdiUtil
.findBean(CategoryManager.class);
final CategoryRepository categoryRepository = cdiUtil
.findBean(CategoryRepository.class);
final ContentItemManager contentItemManager = cdiUtil
.findBean(ContentItemManager.class);
final ContentItemRepository contentItemRepository = cdiUtil
.findBean(ContentItemRepository.class);
if (selectedValue != null) {
final Optional<ContentItem> optionalItem = contentItemRepository
.findById(Long.parseLong(selectedValue));
if (optionalItem.isPresent()) {
final ContentItem item = contentItemManager
.getLiveVersion(optionalItem.get(),
ContentItem.class)
.get();
try {
categoryManager.setIndexObject(category, item);
categoryRepository.save(category);
} catch (ObjectNotAssignedToCategoryException ex) {
throw new FormProcessException(ex);
}
}
}
}
/**
* Get the cancel button.
*
* @return The cancel button
*/
protected Submit getCancelButton() {
return saveCancelSection.getCancelButton();
}
/**
* Fetch the selected category.
*
* @param state The page state
*
* @return The selected category
*
* @pre ( state != null )
*/
protected Category getCategory(final PageState state) {
return selectedCategory.getCategory(state);
}
}

View File

@ -1,137 +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.category;
import com.arsdigita.bebop.ColumnPanel;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.form.Submit;
import com.arsdigita.cms.ui.CategoryForm;
import com.arsdigita.cms.ui.FormSecurityListener;
import com.arsdigita.toolbox.ui.Cancellable;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.core.CcmObject;
import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.privileges.AdminPrivileges;
/**
* A form which edits secondary parents
*
* @author Michael Pih
* @author Stanislav Freidin
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/
public class LinkForm extends CategoryForm implements Cancellable {
private static final Logger LOGGER = LogManager.getLogger(
LinkForm.class);
private final CategoryRequestLocal m_category;
private final Submit m_cancelButton;
public LinkForm(final CategoryRequestLocal category) {
super("LinkForm");
m_category = category;
m_cancelButton = new Submit("Finish");
add(m_cancelButton, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT);
setAssignedCaption("Linked Categories");
addSubmissionListener
(new FormSecurityListener(AdminPrivileges.ADMINISTER_CATEGORIES));
}
public final boolean isCancelled(final PageState state) {
return m_cancelButton.isSelected(state);
}
/**
* Load all categories which are assigned to the current item.
*/
protected void initAssignedCategories(PageState state, CategoryMap m) {
final Category category = m_category.getCategory(state);
m.add(category.getParentCategory());
/*final BigDecimal parentID = category.getDefaultParentCategory().getID();
CategoryCollection links = category.getParents();
while ( links.next() ) {
Category cat = links.getCategory();
if ( !cat.getID().equals(parentID) ) {
m.add(cat);
}
}
links.close();*/
}
/**
* Assign a secondary parent.
*/
public void assignCategory(PageState state, Category category) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
final CategoryManager categoryManager = cdiUtil.findBean(CategoryManager.class);
final Category child = m_category.getCategory(state);
if (permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES, category)) {
categoryManager.addSubCategoryToCategory(child, category);
}
}
/**
* Unassign a secondary parent.
*/
public void unassignCategory(PageState state, Category category) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
final CategoryManager categoryManager = cdiUtil.findBean(CategoryManager.class);
final Category child = m_category.getCategory(state);
if (permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES, category)) {
categoryManager.removeSubCategoryFromCategory(child, category);
}
}
/**
* The category cannot be its own parent. Its children cannot
* be parents either.
*/
@Override
public Category getExcludedCategory(PageState state) {
return m_category.getCategory(state);
}
/**
* This method returns the URL for the given item to make sure that
* there are not two objects in the same category with the same URL.
*/
protected final String getItemURL(final PageState state) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryManager categoryManager = cdiUtil.findBean(CategoryManager.class);
return categoryManager.getCategoryPath(m_category.getCategory(state));
}
protected final CcmObject getObject(final PageState state) {
return (Category) m_category.getCategory(state);
}
}

View File

@ -1,108 +0,0 @@
/*
* Copyright (C) 2002-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.category;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.cms.ui.SortableList;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.categorization.Category;
import javax.servlet.ServletException;
/**
* This list offers the option for the code to provide the developer
* with links to sort the given categories.
*
* NOTE: This UI currently does not scale well with large numbers of
* items since it just lists all of them. It would probably be nice
* to integrate a paginator as well to as to allow the user to move an
* item in large distances and to insert an item in the middle. Right
* now, when you add an item it is just placed at the end. However,
* if you want the item to appear in the middle then you must hit the
* "up" arrow n/2 times where n is the number of items in the list.
* This clearly is not a good setup.
*
* @author Randy Graebner (randyg@alum.mit.edu)
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/
abstract class SortableCategoryList extends SortableList {
private static final Logger LOGGER = LogManager.getLogger
(SortableCategoryList.class);
public final static String CHILDREN = "ch";
private final CategoryRequestLocal m_parent;
/**
* This just makes a standard
* {@link SortableList}
*/
public SortableCategoryList(final CategoryRequestLocal parent) {
super(new ParameterSingleSelectionModel
(new BigDecimalParameter(CHILDREN)), false);
m_parent = parent;
setIdAttr("categorized_objects_list");
}
protected final Category getCategory(final PageState state) {
return m_parent.getCategory(state);
}
/**
* This actually performs the sorting
*/
public void respond(PageState ps) throws ServletException {
String event = ps.getControlEventName();
/* TODO Do actual sorting
if (NEXT_EVENT.equals(event) || PREV_EVENT.equals(event)) {
try {
ACSObject child =
(ACSObject)DomainObjectFactory.newInstance
(new OID(ACSObject.BASE_DATA_OBJECT_TYPE,
new BigDecimal(ps.getControlEventValue())));
Category parent = m_parent.getCategory(ps);
if (CMS.getContext().getSecurityManager().canAccess
(SecurityManager.CATEGORY_ADMIN)) {
if (NEXT_EVENT.equals(event)) {
parent.swapWithNext(child);
} else {
parent.swapWithPrevious(child);
}
parent.save();
}
} catch (DataObjectNotFoundException e) {
s_log.error("Trying to create categories with state = " + ps, e);
throw new ServletException(e);
}
} else {
super.respond(ps);
}*/
}
}

View File

@ -1,138 +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.category;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.List;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.event.ActionEvent;
import com.arsdigita.bebop.list.ListModel;
import com.arsdigita.bebop.list.ListModelBuilder;
import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.LockableImpl;
import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.cdi.utils.CdiUtil;
import org.librecms.CmsConstants;
/**
* A List of all subcategories of the current category.
*
*
* @author Stanislav Freidin (stas@arsdigita.com)
* @author Michael Pih (pihman@arsdigita.com)
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class SubcategoryList extends SortableCategoryList {
private final CategoryRequestLocal parentCategory;
private final SingleSelectionModel<String> selectedCategoryId;
public SubcategoryList(
final CategoryRequestLocal parentCategory,
final SingleSelectionModel<String> selectedCategoryId) {
super(parentCategory);
this.parentCategory = parentCategory;
this.selectedCategoryId = selectedCategoryId;
super.setIdAttr("subcategories_list");
setModelBuilder(new SubcategoryModelBuilder());
// Select the category in the main tree when the
// user selects it here
super.addActionListener(this::actionPerformed);
Label label = new Label(new GlobalizedMessage(
"cms.ui.category.subcategory.none",
CmsConstants.CMS_BUNDLE));
label.setFontWeight(Label.ITALIC);
setEmptyView(label);
}
/**
* Select the category in the main tree when the user selects it here
*
* @param event
*/
private void actionPerformed(final ActionEvent event) {
final PageState state = event.getPageState();
final String categoryId = (String) getSelectedKey(state);
if (categoryId != null) {
selectedCategoryId.setSelectedKey(state, categoryId);
}
}
public ListModel makeMake(final List list, final PageState state) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryManager categoryManager = cdiUtil
.findBean(CategoryManager.class);
final Category category = parentCategory.getCategory(state);
if (category != null
&& categoryManager.hasSubCategories(category)) {
final CategoryAdminController controller = cdiUtil.findBean(
CategoryAdminController.class);
final java.util.List<CategoryListItem> children = controller
.generateSubCategoryList(category);
return new CategoryListModel(children);
} else {
return List.EMPTY_MODEL;
}
}
private class SubcategoryModelBuilder extends LockableImpl
implements ListModelBuilder {
@Override
public ListModel makeModel(final List list, final PageState state) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryManager categoryManager = cdiUtil
.findBean(CategoryManager.class);
final Category category = parentCategory.getCategory(state);
if (category != null
&& categoryManager.hasSubCategories(category)) {
final CategoryAdminController controller = cdiUtil.findBean(
CategoryAdminController.class);
final java.util.List<CategoryListItem> children = controller
.generateSubCategoryList(category);
return new CategoryListModel(children);
} else {
return List.EMPTY_MODEL;
}
}
}
}