Many small changes, now all classes in category package compile. Needs to be checked in detail

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4674 8810af33-2d31-482b-a856-94f89814c4df
ccm-docs
baka 2017-04-14 14:23:59 +00:00
parent ba515675e6
commit fba9416f86
11 changed files with 615 additions and 463 deletions

View File

@ -38,8 +38,12 @@ import com.arsdigita.util.UncheckedWrapperException;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.libreccm.categorization.Category; import org.libreccm.categorization.Category;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.categorization.CategoryRepository;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.core.CcmObject; import org.libreccm.core.CcmObject;
import javax.enterprise.inject.spi.CDI;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -217,10 +221,10 @@ public abstract class CategoryForm extends Form
OptionGroup target = (OptionGroup) e.getTarget(); OptionGroup target = (OptionGroup) e.getTarget();
target.clearOptions(); target.clearOptions();
PageState state = e.getPageState(); PageState state = e.getPageState();
Category root = getRootCategory(state); // Category root = getRootCategory(state);
if (root == null) { // if (root == null) {
return; // return;
} // }
// exclude children of the excluded category (as per javadoc on // exclude children of the excluded category (as per javadoc on
// getExcludedCategory() method. This prevents attempts // getExcludedCategory() method. This prevents attempts
@ -234,8 +238,8 @@ public abstract class CategoryForm extends Form
} }
CategoryMap assigned = getAssignedCategories(state); CategoryMap assigned = getAssignedCategories(state);
SortedMap sortedCats = new TreeMap(); SortedMap sortedCats = new TreeMap();
java.util.List<Category> children = root.getSubCategories(); // java.util.List<Category> children = root.getSubCategories();
children.forEach(x -> sortedCats.put(x.getName(), x.getUniqueId())); // children.forEach(x -> sortedCats.put(x.getName(), x.getUniqueId()));
Iterator it = sortedCats.entrySet().iterator(); Iterator it = sortedCats.entrySet().iterator();
Map.Entry entry; Map.Entry entry;
@ -243,7 +247,7 @@ public abstract class CategoryForm extends Form
String id; String id;
boolean notExcluded; boolean notExcluded;
boolean notAlreadyAssigned; boolean notAlreadyAssigned;
boolean notRoot; // boolean notRoot;
while (it.hasNext()) { while (it.hasNext()) {
entry = (Map.Entry) it.next(); entry = (Map.Entry) it.next();
@ -252,9 +256,9 @@ public abstract class CategoryForm extends Form
notExcluded = !excluded.containsKey(id); notExcluded = !excluded.containsKey(id);
notAlreadyAssigned = !assigned.containsKey(id); notAlreadyAssigned = !assigned.containsKey(id);
notRoot = !id.equals(root.getUniqueId()); // notRoot = !id.equals(root.getUniqueId());
if (notExcluded && notAlreadyAssigned && notRoot) { if (notExcluded && notAlreadyAssigned) {// && notRoot) {
target.addOption(new Option(id, new Text(path))); target.addOption(new Option(id, new Text(path)));
} }
@ -317,10 +321,10 @@ public abstract class CategoryForm extends Form
* @return the root category which should be used to populate the lists * @return the root category which should be used to populate the lists
* of assigned and unassigned categories * of assigned and unassigned categories
*/ */
public Category getRootCategory(PageState state) { // public Category getRootCategory(PageState state) {
return null; // return null;
// return CMS.getContext().getContentSection().getRootCategory(); // return CMS.getContext().getContentSection().getRootCategory();
} // }
/** /**
* Return a category which should be excluded from the list of * Return a category which should be excluded from the list of
@ -361,10 +365,20 @@ public abstract class CategoryForm extends Form
// Process the form: assign/unassign categories // Process the form: assign/unassign categories
@Override @Override
public void process(FormSectionEvent e) throws FormProcessException { public void process(FormSectionEvent e) throws FormProcessException {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryRepository categoryRepository = cdiUtil.findBean(CategoryRepository.class);
final CategoryManager categoryManager = cdiUtil.findBean(CategoryManager.class);
PageState state = e.getPageState(); PageState state = e.getPageState();
FormData data = e.getFormData(); FormData data = e.getFormData();
BigDecimal id; BigDecimal id;
if (m_assign.isSelected(state)) {
Category cat = new Category();
assignCategory(state, cat);
}
// if (m_assign.isSelected(state)) { // if (m_assign.isSelected(state)) {
// id = (BigDecimal) data.get(FREE); // id = (BigDecimal) data.get(FREE);
// //
@ -481,22 +495,9 @@ public abstract class CategoryForm extends Form
* @return the full path to a category * @return the full path to a category
*/ */
public static String getCategoryPath(Category c) { public static String getCategoryPath(Category c) {
return c.getName(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
// final StringBuffer s = new StringBuffer(); final CategoryManager categoryManager = cdiUtil.findBean(CategoryManager.class);
// final CategoryCollection ancestors = c.getDefaultAscendants(); return categoryManager.getCategoryPath(c);
// ancestors.addOrder(Category.DEFAULT_ANCESTORS);
//
// boolean isFirst = true;
//
// while (ancestors.next()) {
// if (!isFirst) {
// s.append(SEPARATOR);
// }
// s.append(ancestors.getCategory().getName());
// isFirst = false;
// }
//
// return s.toString();
} }
/** /**

View File

@ -30,6 +30,15 @@ import com.arsdigita.cms.ui.VisibilityComponent;
import com.arsdigita.toolbox.ui.ActionGroup; import com.arsdigita.toolbox.ui.ActionGroup;
import com.arsdigita.toolbox.ui.Section; import com.arsdigita.toolbox.ui.Section;
import com.arsdigita.xml.Element; import com.arsdigita.xml.Element;
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.cdi.utils.CdiUtil;
import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.privileges.AdminPrivileges;
import java.math.BigDecimal; import java.math.BigDecimal;
/** /**
@ -41,9 +50,9 @@ import java.math.BigDecimal;
public final class CategoryAdminPane extends BaseAdminPane { public final class CategoryAdminPane extends BaseAdminPane {
public static final String CONTEXT_SELECTED = "sel_context"; public static final String CONTEXT_SELECTED = "sel_context";
private static final String DEFAULT_USE_CONTEXT = private static final String DEFAULT_USE_CONTEXT = "<default>";
CategoryUseContextModelBuilder.DEFAULT_USE_CONTEXT; private static final Logger LOGGER = LogManager.getLogger(
private static final Logger s_log = Logger.getLogger(CategoryAdminPane.class); CategoryAdminPane.class);
private final SingleSelectionModel m_contextModel; private final SingleSelectionModel m_contextModel;
private final Tree m_categoryTree; private final Tree m_categoryTree;
private final SingleSelectionModel m_model; private final SingleSelectionModel m_model;
@ -57,9 +66,9 @@ public final class CategoryAdminPane extends BaseAdminPane {
/* Left column */ /* Left column */
/* Use context section */ /* Use context section */
List list = new List(new CategoryUseContextModelBuilder()); //List list = new List(new CategoryUseContextModelBuilder());
list.setSelectionModel(m_contextModel); //list.setSelectionModel(m_contextModel);
list.addChangeListener(new ContextSelectionListener()); //list.addChangeListener(new ContextSelectionListener());
/* Category tree section */ /* Category tree section */
m_categoryTree = new BaseTree(new CategoryTreeModelBuilder(m_contextModel)); m_categoryTree = new BaseTree(new CategoryTreeModelBuilder(m_contextModel));
@ -74,16 +83,19 @@ public final class CategoryAdminPane extends BaseAdminPane {
contextSection.setHeading(new Label(gz("cms.ui.category.use_contexts"))); contextSection.setHeading(new Label(gz("cms.ui.category.use_contexts")));
ActionGroup contextGroup = new ActionGroup(); ActionGroup contextGroup = new ActionGroup();
contextSection.setBody(contextGroup); contextSection.setBody(contextGroup);
contextGroup.setSubject(list); //contextGroup.setSubject(list);
if (CMS.getConfig().getAllowCategoryCreateUseContext()) { 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( ActionLink addContextAction = new ActionLink(new Label(gz(
"cms.ui.category.add_use_context"))); "cms.ui.category.add_use_context")));
Form addContextForm = new AddUseContextForm(m_contextModel); Form addContextForm = new AddUseContextForm(m_contextModel);
getBody().add(addContextForm); getBody().add(addContextForm);
getBody().connect(addContextAction, addContextForm); getBody().connect(addContextAction, addContextForm);
contextGroup.addAction(new VisibilityComponent(addContextAction, contextGroup.addAction(new VisibilityComponent(addContextAction,
SecurityManager.CATEGORY_ADMIN)); AdminPrivileges.ADMINISTER_CATEGORIES));
} }
final Section categorySection = new Section(); final Section categorySection = new Section();
@ -127,7 +139,7 @@ public final class CategoryAdminPane extends BaseAdminPane {
public void register(final Page page) { public void register(final Page page) {
super.register(page); super.register(page);
page.addActionListener(new RootListener()); //page.addActionListener(new RootListener());
} }
private final class DeleteLink extends ActionLink { private final class DeleteLink extends ActionLink {
@ -145,16 +157,16 @@ public final class CategoryAdminPane extends BaseAdminPane {
return; return;
} }
Category cat = m_category.getCategory(state); //Category cat = m_category.getCategory(state);
String context = getUseContext(state); //String context = getUseContext(state);
boolean isDefaultContext = //boolean isDefaultContext =
(context == null) || DEFAULT_USE_CONTEXT.equals(context); // (context == null) || DEFAULT_USE_CONTEXT.equals(context);
if (cat.isRoot() || !cat.getChildren().isEmpty()) { //if (cat.isRoot() || !cat.getChildren().isEmpty()) {
m_alternativeLabel.generateXML(state, parent); // m_alternativeLabel.generateXML(state, parent);
} else { //} else {
super.generateXML(state, parent); super.generateXML(state, parent);
} //}
} }
} }
@ -165,66 +177,71 @@ public final class CategoryAdminPane extends BaseAdminPane {
super(prompt); super(prompt);
prompt.add(new Label(gz("cms.ui.category.delete_prompt"))); prompt.add(new Label(gz("cms.ui.category.delete_prompt")));
Label catLabel = new Label(); Label catLabel = new Label();
catLabel.addPrintListener(new PrintListener() { // catLabel.addPrintListener(new PrintListener() {
public void prepare(PrintEvent pe) { // public void prepare(PrintEvent pe) {
Label label = (Label) pe.getTarget(); // Label label = (Label) pe.getTarget();
Category cat = // Category cat =
m_category.getCategory(pe.getPageState()); // m_category.getCategory(pe.getPageState());
CategoryCollection descendants = cat.getDescendants(); // CategoryCollection descendants = cat.getDescendants();
final long nDescendants = descendants.size() - 1; // final long nDescendants = descendants.size() - 1;
descendants.close(); // descendants.close();
CategorizedCollection descObjects = // CategorizedCollection descObjects =
cat.getDescendantObjects(); // cat.getDescendantObjects();
final long nDescObjects = descObjects.size(); // final long nDescObjects = descObjects.size();
descObjects.close(); // descObjects.close();
StringBuffer sb = new StringBuffer(" "); // StringBuffer sb = new StringBuffer(" ");
if (nDescendants > 0) { // if (nDescendants > 0) {
sb.append("This category has "); // sb.append("This category has ");
sb.append(nDescendants); // sb.append(nDescendants);
sb.append(" descendant category(ies). "); // sb.append(" descendant category(ies). ");
} // }
if (nDescObjects > 0) { // if (nDescObjects > 0) {
sb.append("It has ").append(nDescObjects); // sb.append("It has ").append(nDescObjects);
sb.append(" descendant object(s). "); // sb.append(" descendant object(s). ");
} // }
if (nDescendants > 0 || nDescObjects > 0) { // if (nDescendants > 0 || nDescObjects > 0) {
sb.append("Descendants will be orphaned, if this category is removed."); // sb.append("Descendants will be orphaned, if this category is removed.");
} // }
label.setLabel(sb.toString()); // label.setLabel(sb.toString());
} // }
//
}); // });
prompt.add(catLabel); prompt.add(catLabel);
} }
public final void process(final FormSectionEvent e) public final void process(final FormSectionEvent e)
throws FormProcessException { throws FormProcessException {
final PageState state = e.getPageState(); final PageState state = e.getPageState();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
final CategoryRepository repository = cdiUtil.findBean(CategoryRepository.class);
final Category category = m_category.getCategory(state); final Category category = m_category.getCategory(state);
if (category == null) { if (category == null) {
return; return;
} }
PermissionService.assertPermission(new PermissionDescriptor(PrivilegeDescriptor.DELETE, // PermissionService.assertPermission(new PermissionDescriptor(PrivilegeDescriptor.DELETE,
category, // category,
Kernel.getContext(). // Kernel.getContext().
getParty())); // getParty()));
permissionChecker.checkPermission(AdminPrivileges.ADMINISTER_CATEGORIES, category);
if (category.isRoot()) { // if (category.isRoot()) {
Category root = // Category root =
Category.getRootForObject(CMS.getContext().getContentSection(), // Category.getRootForObject(CMS.getContext().getContentSection(),
getUseContext(state)); // getUseContext(state));
if (category.equals(root)) { // if (category.equals(root)) {
Category.clearRootForObject(CMS.getContext().getContentSection(), // Category.clearRootForObject(CMS.getContext().getContentSection(),
getUseContext(state)); // getUseContext(state));
} // }
m_contextModel.setSelectedKey(state, DEFAULT_USE_CONTEXT); // m_contextModel.setSelectedKey(state, DEFAULT_USE_CONTEXT);
} else { // } else {
Category parent = category.getDefaultParentCategory(); Category parent = category.getParentCategory();
m_model.setSelectedKey(state, parent.getID()); m_model.setSelectedKey(state, parent.getUniqueId());
} // }
category.deleteCategoryAndOrphan(); //category.deleteCategoryAndOrphan();
repository.delete(category);
} }
} }
@ -234,11 +251,12 @@ public final class CategoryAdminPane extends BaseAdminPane {
@Override @Override
protected final Object initialValue(final PageState state) { protected final Object initialValue(final PageState state) {
final String id = m_model.getSelectedKey(state).toString(); final String id = m_model.getSelectedKey(state).toString();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final CategoryRepository repository = cdiUtil.findBean(CategoryRepository.class);
if (id == null) { if (id == null) {
return null; return null;
} else { } else {
return new Category(new BigDecimal(id)); return repository.findById(Long.parseLong(id));
} }
} }
@ -248,27 +266,27 @@ public final class CategoryAdminPane extends BaseAdminPane {
@Override @Override
protected final Object initialValue(final PageState state) { protected final Object initialValue(final PageState state) {
return m_category.getCategory(state).getDefaultParentCategory(); return m_category.getCategory(state).getParentCategory();
} }
} }
private final class RootListener implements ActionListener { // private final class RootListener implements ActionListener {
//
public final void actionPerformed(final ActionEvent e) { // public final void actionPerformed(final ActionEvent e) {
final PageState state = e.getPageState(); // final PageState state = e.getPageState();
//
if (!m_model.isSelected(state)) { // if (!m_model.isSelected(state)) {
final Category root = // final Category root =
Category.getRootForObject(CMS.getContext().getContentSection(), // Category.getRootForObject(CMS.getContext().getContentSection(),
getUseContext(state)); // getUseContext(state));
if (root != null) { // if (root != null) {
m_model.setSelectedKey(state, root.getID()); // m_model.setSelectedKey(state, root.getID());
} // }
} // }
} // }
//
} // }
private class UseContextSelectionModel extends ParameterSingleSelectionModel { private class UseContextSelectionModel extends ParameterSingleSelectionModel {
@ -297,25 +315,25 @@ public final class CategoryAdminPane extends BaseAdminPane {
public class ContextSelectionListener implements ChangeListener { public class ContextSelectionListener implements ChangeListener {
public final void stateChanged(final ChangeEvent e) { public final void stateChanged(final ChangeEvent e) {
s_log.debug("Selection state changed; I may change " + "the body's visible pane"); LOGGER.debug("Selection state changed; I may change " + "the body's visible pane");
final PageState state = e.getPageState(); final PageState state = e.getPageState();
getBody().reset(state); getBody().reset(state);
if (m_contextModel.isSelected(state)) { // if (m_contextModel.isSelected(state)) {
final Category root = // final Category root =
Category.getRootForObject(CMS.getContext().getContentSection(), // Category.getRootForObject(CMS.getContext().getContentSection(),
getUseContext(state)); // getUseContext(state));
//
if (root != null) { // if (root != null) {
m_model.setSelectedKey(state, root.getID()); // m_model.setSelectedKey(state, root.getID());
//m_categoryTree.reset(state); // //m_categoryTree.reset(state);
} // }
//
} // }
if (m_model.isSelected(state)) { if (m_model.isSelected(state)) {
s_log.debug("The selection model is selected; displaying " + "the item pane"); LOGGER.debug("The selection model is selected; displaying " + "the item pane");
getBody().push(state, getItemPane()); getBody().push(state, getItemPane());
} }

View File

@ -193,7 +193,7 @@ class CategoryItemPane extends BaseItemPane {
// Permissions // Permissions
//m_detailPane.add(new PermissionsSection()); //m_detailPane.add(new PermissionsSection());
m_detailPane.add(new Text("PermissionSection Placeholder")); //m_detailPane.add(new Text("PermissionSection Placeholder"));
connect(indexLink, indexForm); connect(indexLink, indexForm);
connect(indexForm); connect(indexForm);
@ -406,127 +406,127 @@ class CategoryItemPane extends BaseItemPane {
} }
private class PermissionsSection extends Section { // 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 // @Override
// public boolean isVisible(PageState ps) { // public boolean isVisible(PageState ps) {
// final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
// final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
// Category cat = m_category.getCategory(ps); // Category cat = m_category.getCategory(ps);
// return PermissionService.getContext(cat) == null; // return cat.getParentCategory() != null && permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES);
// } // }
// //
// }; // PermissionsSection() {
// setHeading(new Label(gz("cms.ui.permissions")));
// //
// final ActionLink useCustom = new ActionLink(new Label(gz( // final ActionGroup group = new ActionGroup();
// "cms.ui.use_custom_permissions"))) { // setBody(group);
// @Override
// public boolean isVisible(PageState ps) {
// Category cat = m_category.getCategory(ps);
// return PermissionService.getContext(cat) != null;
// }
// //
// }; //// PrivilegeDescriptor[] privs = new PrivilegeDescriptor[]{
// //// PrivilegeDescriptor.EDIT,
// ActionListener al = new ActionListener() { //// Category.MAP_DESCRIPTOR,
// public void actionPerformed(ActionEvent event) { //// PrivilegeDescriptor.DELETE,
// PageState state = event.getPageState(); //// PrivilegeDescriptor.ADMIN
// // if this is the root then we cannot revert to anything //// };
// // since there is not a parent ////
// Category cat = m_category.getCategory(state); //// HashMap privMap = new HashMap();
// if (!cat.canAdmin()) { //// privMap.put("edit", "Edit");
// throw new com.arsdigita.cms.dispatcher.AccessDeniedException(); //// privMap.put("delete", "Delete");
// } //// privMap.put(Category.MAP_DESCRIPTOR.getName(), "Categorize Items");
// DataObject context = PermissionService.getContext(cat); //// privMap.put("admin", "Admin");
// if (context != null) { ////
// PermissionService.clonePermissions(cat); //// final CMSPermissionsPane permPane = new CMSPermissionsPane(privs, privMap,
// } else { //// new ACSObjectSelectionModel(
// ACSObject parent; //// m_model)) {
// try { //// @Override
// parent = cat.getDefaultParentCategory(); //// public void showAdmin(PageState ps) {
// } catch (CategoryNotFoundException ce) { //// Assert.exists(m_model.getSelectedKey(ps));
// throw new IllegalStateException( ////
// "link shouldn't exist for root categories"); //// super.showAdmin(ps);
// } //// getAdminListingPanel().setVisible(ps, false);
// PermissionService.setContext(cat, parent); //// }
// ////
// // revoke all direct permissions so category will only //// };
// // have inherited permissions ////
// ObjectPermissionCollection perms = //// final ActionLink restoreDefault = new ActionLink(new Label(gz(
// PermissionService.getDirectGrantedPermissions( //// "cms.ui.restore_default_permissions"))) {
// cat.getOID()); //// @Override
// while (perms.next()) { //// public boolean isVisible(PageState ps) {
// PermissionService.revokePermission( //// Category cat = m_category.getCategory(ps);
// new PermissionDescriptor( //// return PermissionService.getContext(cat) == null;
// perms.getPrivilege(), cat.getOID(), //// }
// perms.getGranteeOID())); ////
// } //// };
// } ////
// permPane.reset(state); //// 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();
//// }
////
//// });
////
// } // }
// //
// } // }
//
// 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 { private static class OrderItemsForm extends CMSForm {

View File

@ -0,0 +1,246 @@
/*
* 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,195 +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.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 org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.librecms.contentsection.ContentSection;
import org.librecms.dispatcher.ItemResolver;
/**
* 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
* {@link com.arsdigita.cms.ContentItem#DRAFT} or {@link com.arsdigita.cms.ContentItem#LIVE}
*/
public CategoryItemsBrowser(ACSObjectSelectionModel sel, int numCols,
String context) {
super(null, numCols);
super.setModelBuilder(new CategoryItemModelBuilder(sel));
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 = section.getItemResolver();
LOGGER.warn("Item resolver is" + itemResolver.getClass());
return itemResolver;
}
};
setDefaultCellRenderer(new ItemSummaryCellRenderer());
}
/**
* @return the current context
*/
public String getContext() {
return m_context;
}
/**
* @param context the new context for the items. Should be
* {@link com.arsdigita.cms.ContentItem#DRAFT} or {@link com.arsdigita.cms.ContentItem#LIVE}
*/
public void setContext(String context) {
Assert.isUnlocked(this);
m_context = context;
}
/**
* Iterates through all the children of the given Category
*/
private class CategoryItemModelBuilder
extends DataQueryListModelBuilder {
private ACSObjectSelectionModel m_sel;
public CategoryItemModelBuilder(ACSObjectSelectionModel sel) {
super(ContentPage.QUERY_PAGE + "." + ACSObject.ID,
ContentPage.QUERY_PAGE);
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);
}
}
}
/**
* 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("&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

@ -57,7 +57,7 @@ public class CategoryLinks extends List {
m_parent = parent; m_parent = parent;
m_model = model; m_model = model;
//setModelBuilder(new LinkedCategoryModelBuilder()); setModelBuilder(new LinkedCategoryModelBuilder());
// Select the category in the main tree when the // Select the category in the main tree when the
// user selects it here // user selects it here
@ -79,24 +79,23 @@ public class CategoryLinks extends List {
} }
// Since this part is for non default parents, but there is only one... this is not needed anymore, i guess // 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 private class LinkedCategoryModelBuilder extends LockableImpl
implements ListModelBuilder { implements ListModelBuilder {
public ListModel makeModel(List list, PageState state) { public ListModel makeModel(List list, PageState state) {
final Category category = m_parent.getCategory(state); final Category category = m_parent.getCategory(state);
if (category != null && category.getParent().isPresent()) { if (category != null && category.getParentCategory() != null) {
Collection<Category> categories = new HashSet<>(); java.util.List<Category> categories = new java.util.ArrayList<>();
categories.add(category.getParentCategory()); categories.add(category.getParentCategory());
return new CategoryCollectionListModel return new CategoryListModel
(categories, (categories,
parent == null ? null : parent.getID()); category.getParentCategory() == null ? null : Long.parseLong(category.getParentCategory().getUniqueId()));
} else { } else {
return List.EMPTY_MODEL; return List.EMPTY_MODEL;
} }
} }
}*/ }
} }

View File

@ -18,10 +18,10 @@
*/ */
package com.arsdigita.cms.ui.category; package com.arsdigita.cms.ui.category;
import java.util.List;
import com.arsdigita.bebop.list.ListModel; import com.arsdigita.bebop.list.ListModel;
import org.libreccm.categorization.Category; import org.libreccm.categorization.Category;
import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
/** /**
@ -29,7 +29,7 @@ import java.util.Iterator;
* *
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a> * @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/ */
public final class CategoryCollectionListModel implements ListModel { public final class CategoryListModel implements ListModel {
private Category m_cat; private Category m_cat;
private long m_excludedID; private long m_excludedID;
@ -37,16 +37,16 @@ public final class CategoryCollectionListModel implements ListModel {
/** /**
* Constructs a new <code>CategoryCollectionListModel</code> * Constructs a new <code>CategoryListModel</code>
*/ */
public CategoryCollectionListModel(Collection<Category> coll) { public CategoryListModel(List<Category> coll) {
this(coll, -1); //Hopefully a decent replacement for null in BigDecimal. Negative ids would be weird... this(coll, -1); //Hopefully a decent replacement for null in BigDecimal. Negative ids would be weird...
} }
/** /**
* Constructs a new <code>CategoryCollectionListModel</code> * Constructs a new <code>CategoryListModel</code>
*/ */
public CategoryCollectionListModel(Collection<Category> coll, public CategoryListModel(List<Category> coll,
long excludedID) { long excludedID) {
m_excludedID = excludedID; m_excludedID = excludedID;

View File

@ -124,7 +124,6 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
*/ */
private class CategoryLocalizationTableModel implements TableModel { private class CategoryLocalizationTableModel implements TableModel {
final private int MAX_DESC_LENGTH = 25;
private Table m_table; private Table m_table;
private ArrayList<LocalizedString> localizedStringCollection; private ArrayList<LocalizedString> localizedStringCollection;
private LocalizedString m_categoryLocalization; private LocalizedString m_categoryLocalization;

View File

@ -0,0 +1,89 @@
/*
* 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

@ -126,8 +126,9 @@ public class LinkForm extends CategoryForm implements Cancellable {
* there are not two objects in the same category with the same URL. * there are not two objects in the same category with the same URL.
*/ */
protected final String getItemURL(final PageState state) { protected final String getItemURL(final PageState state) {
return m_category.getCategory(state).getName(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
//return m_category.getCategory(state).getURL(); final CategoryManager categoryManager = cdiUtil.findBean(CategoryManager.class);
return categoryManager.getCategoryPath(m_category.getCategory(state));
} }
protected final CcmObject getObject(final PageState state) { protected final CcmObject getObject(final PageState state) {

View File

@ -30,8 +30,6 @@ import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.util.LockableImpl; import com.arsdigita.util.LockableImpl;
import org.libreccm.categorization.Category; import org.libreccm.categorization.Category;
import java.util.Collection;
/** /**
* A List of all subcategories of the current category. * A List of all subcategories of the current category.
* *
@ -80,12 +78,8 @@ public class SubcategoryList extends SortableCategoryList {
final Category category = m_parent.getCategory(state); final Category category = m_parent.getCategory(state);
if (category != null && !category.getSubCategories().isEmpty()) { if (category != null && !category.getSubCategories().isEmpty()) {
Collection<Category> children = category.getSubCategories(); java.util.List<Category> children = category.getSubCategories();
//String order = ContentSection.getConfig().getCategoryTreeOrder(); FIXME Collections are not sorted return new CategoryListModel(children);
//order = Category.SORT_KEY.equals(order) ? "link." + order : order;
//children.addOrder(order);
// children.addOrder("link." + Category.SORT_KEY);
return new CategoryCollectionListModel(children);
} else { } else {
return List.EMPTY_MODEL; return List.EMPTY_MODEL;
} }