Adds more implementations for the category part of the cms frontend

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4627 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
baka 2017-03-14 17:37:58 +00:00
parent d6a391e6cd
commit 0144048f5c
8 changed files with 952 additions and 263 deletions

View File

@ -39,30 +39,39 @@ import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.bebop.util.GlobalizationUtil;
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.cms.ui.templates.CategoryTemplates;
import com.arsdigita.kernel.KernelConfig;
import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
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.util.Assert;
import com.arsdigita.web.Web;
import com.arsdigita.xml.Element;
import java.awt.image.Kernel;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Optional;
import org.apache.log4j.Logger;
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.configuration.ConfigurationManager;
import org.libreccm.core.CcmObject;
import org.libreccm.security.Permission;
import org.libreccm.security.PermissionChecker;
import org.libreccm.security.User;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentItemManager;
import org.librecms.contentsection.privileges.AdminPrivileges;
/**
@ -70,11 +79,12 @@ import org.librecms.contentsection.privileges.AdminPrivileges;
*
* @author Justin Ross <jross@redhat.com>
* @author Sören Bernstein <quasi@quasiweb.de>
* @version $Id: CategoryItemPane.java 1967 2009-08-29 21:05:51Z pboy $
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/
class CategoryItemPane extends BaseItemPane {
private static final Logger s_log = Logger.getLogger(CategoryItemPane.class);
private static final Logger LOGGER = LogManager.getLogger(
CategoryItemPane.class);
private final SingleSelectionModel m_model;
private final CategoryRequestLocal m_category;
private final SimpleContainer m_detailPane;
@ -119,8 +129,8 @@ class CategoryItemPane extends BaseItemPane {
//Move link
final ActionLink moveLink = new MoveLink(new Label(gz("cms.ui.category.move")));
final Form moveForm = new CategoryMoveForm(m_category, contextModel);
add(moveForm);
//final Form moveForm = new CategoryMoveForm(m_category, contextModel);
//add(moveForm);
ViewItemLink viewIndexLink = new ViewItemLink(new Label(gz(
"cms.ui.category.view_index_item")), "");
@ -138,27 +148,32 @@ class CategoryItemPane extends BaseItemPane {
// Quasimodo: BEGIN
// Localizations
/*
ActionLink addCategoryLocalizationLink = new ActionLink(new Label(gz( TODO
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 = (Kernel.getConfig()).getSupportedLanguagesTokenizer()
.countTokens();
long countLanguages =
m_category.getCategory(state)
.getCategoryLocalizationCollection().size();
if (m_category.getCategory(state).canEdit()
&& countLanguages < countSupportedLanguages) {
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;
} else {
}
}
return false;
}
}
};*/
};
/*
CategoryLocalizationAddForm addCategoryLocalizationForm =
new CategoryLocalizationAddForm(m_category);
@ -191,8 +206,8 @@ class CategoryItemPane extends BaseItemPane {
connect(indexLink, indexForm);
connect(indexForm);
connect(moveLink, moveForm);
connect(moveForm);
//connect(moveLink, moveForm);
//connect(moveForm);
connect(orderItemsLink, orderItemsForm);
connect(orderItemsForm);
@ -315,7 +330,7 @@ class CategoryItemPane extends BaseItemPane {
}
}
/*
// Quasimodo: BEGIN
// CategoryLocalizationSection
private class CategoryLocalizationSection extends Section {
@ -349,7 +364,7 @@ class CategoryItemPane extends BaseItemPane {
page.addComponentStateParam(m_editCategoryLocalizationForm, m_catLocaleParam);
}
}*/
}
private class SubcategorySection extends Section {
@ -379,7 +394,7 @@ class CategoryItemPane extends BaseItemPane {
@Override
public final boolean isVisible(final PageState state) {
return m_category.getCategory(state).getParent().isPresent();
return m_category.getCategory(state).getParentCategory().isVisible();
}
}
@ -392,7 +407,7 @@ class CategoryItemPane extends BaseItemPane {
final ActionGroup group = new ActionGroup();
setBody(group);
//group.setSubject(new CategoryTemplates(m_category)); TODO
group.setSubject(new CategoryTemplates(m_category));
// XXX secvis
//group.addAction(link);
}
@ -406,117 +421,117 @@ class CategoryItemPane extends BaseItemPane {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
Category cat = m_category.getCategory(ps);
return cat.getParent().isPresent() && permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES);
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();
}
});
*/
// 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();
// }
//
// });
//
}
}
@ -588,17 +603,19 @@ class CategoryItemPane extends BaseItemPane {
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);
boolean canEdit = false;
Optional<ContentItem> indexItem = manager.getIndexObject(m_category.getCategory(state);
Optional<CcmObject> indexItem = manager.getIndexObject(m_category.getCategory(state));
if (!indexItem.isPresent()) {
return "";
}
if (!permissionChecker.isPermitted("", indexItem.get())) {
return "";
} else {
BigDecimal draftID = indexItem.getDraftVersion().getID();
Long draftID = contentItemManager
.getDraftVersion((ContentItem) indexItem.get(), ContentItem.class)
.getObjectId();
return "item.jsp?item_id=" + draftID + "&set_tab="
+ ContentItemPage.AUTHORING_TAB;
}
@ -614,14 +631,21 @@ class CategoryItemPane extends BaseItemPane {
*/
@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;
}
ACSObject indexItem = m_category.getCategory(state).getDirectIndexObject();
if (indexItem == null) {
Optional<CcmObject> indexItem = manager.getIndexObject(m_category.getCategory(state));
if (!indexItem.isPresent()) {
return false;
} else {
return isItemEditable((ContentItem) indexItem, state);
return permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES, indexItem.get());
//return isItemEditable((ContentItem) indexItem, state);
}
}
};
@ -642,7 +666,7 @@ class CategoryItemPane extends BaseItemPane {
}
final Category category = m_category.getCategory(state);
if (!category.getParent().isPresent()) {
if (category.getParentCategory() == null) {
alternativeLabel.generateXML(state, parent);
} else {
super.generateXML(state, parent);

View File

@ -1,62 +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 com.arsdigita.categorization.Category;
import java.util.Iterator;
/**
* A {@link ListModel} that iterates over categories via an iterator
* @version $Id: CategoryIteratorListModel.java 2090 2010-04-17 08:04:14Z pboy $
*/
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.getID().toString();
}
}

View File

@ -31,12 +31,18 @@ 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.categorization.Category;
import com.arsdigita.categorization.CategoryLocalization;
import com.arsdigita.categorization.CategoryLocalizationCollection;
import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.bebop.util.GlobalizationUtil;
import com.arsdigita.util.LockableImpl;
import org.libreccm.categorization.Category;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.l10n.LocalizedString;
import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.privileges.AdminPrivileges;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Locale;
/**
@ -46,6 +52,7 @@ import java.util.Locale;
* 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 {
@ -103,7 +110,7 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
public TableModel makeModel(Table table, PageState state) {
final Category category = m_category.getCategory(state);
if (category != null && category.hasLocalizations()) {
if (category != null) {
return new CategoryLocalizationTableModel(table, state, category);
} else {
return Table.EMPTY_MODEL;
@ -119,12 +126,14 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
final private int MAX_DESC_LENGTH = 25;
private Table m_table;
private CategoryLocalizationCollection m_categoryLocalizations;
private CategoryLocalization m_categoryLocalization;
private ArrayList<LocalizedString> localizedStringCollection;
private LocalizedString m_categoryLocalization;
private CategoryLocalizationTableModel(Table t, PageState ps, Category category) {
m_table = t;
m_categoryLocalizations = new CategoryLocalizationCollection(category);
localizedStringCollection = new ArrayList<>();
localizedStringCollection.add(category.getTitle());
localizedStringCollection.add(category.getDescription());
}
public int getColumnCount() {
@ -138,16 +147,16 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
* into m_categoryLocalization class variable.
*/
public boolean nextRow() {
if (m_categoryLocalizations != null && m_categoryLocalizations.next()) {
m_categoryLocalization = m_categoryLocalizations.getCategoryLocalization();
return true;
} else {
return false;
}
// if (m_categoryLocalizations != null && m_categoryLocalizations.next()) {
// m_categoryLocalization = m_categoryLocalizations.getCategoryLocalization();
// return true;
//
// } else {
//
// return false;
//
// }
}
/**
@ -156,25 +165,26 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
* @see com.arsdigita.bebop.table.TableModel#getElementAt(int)
*/
public Object getElementAt(int columnIndex) {
switch (columnIndex) {
case 0:
Locale clLocale = new Locale(m_categoryLocalization.getLocale());
return clLocale.getDisplayLanguage(/*Locale*/);
case 1:
return m_categoryLocalization.getName();
case 2:
String desc = m_categoryLocalization.getDescription();
if (desc != null && desc.length() > MAX_DESC_LENGTH) {
desc = desc.substring(MAX_DESC_LENGTH - 3).concat("...");
}
return desc;
case 3:
return m_categoryLocalization.getURL();
case 4:
return GlobalizationUtil.globalize("cms.ui.delete").localize();
default:
return null;
}
// switch (columnIndex) {
// case 0:
// Locale clLocale = new Locale(m_categoryLocalization.getLocale());
// return clLocale.getDisplayLanguage(/*Locale*/);
// case 1:
// return m_categoryLocalization.getName();
// case 2:
// String desc = m_categoryLocalization.getDescription();
// if (desc != null && desc.length() > MAX_DESC_LENGTH) {
// desc = desc.substring(MAX_DESC_LENGTH - 3).concat("...");
// }
// return desc;
// case 3:
// return m_categoryLocalization.getURL();
// case 4:
// return GlobalizationUtil.globalize("cms.ui.delete").localize();
// default:
// return null;
// }
}
/**
@ -182,7 +192,8 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
* @see com.arsdigita.bebop.table.TableModel#getKeyAt(int)
*/
public Object getKeyAt(int columnIndex) {
return m_categoryLocalization.getID();
return null;
// return m_categoryLocalization.getID();
}
}
@ -191,12 +202,13 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
public Component getComponent(Table table, PageState state, Object value,
boolean isSelected, final Object key,
int row, int column) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
if (m_category.getCategory(state).canEdit()) {
if (permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES, m_category.getCategory(state))) {
return new ControlLink(value.toString());
} else {
return new Label(value.toString());
return new Label(GlobalizationUtil.globalize(value.toString()));
}
}
}
@ -206,11 +218,13 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
public Component getComponent(Table table, PageState state, Object value,
boolean isSelected, Object key,
int row, int column) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
if (m_category.getCategory(state).canDelete()) {
if (permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES, m_category.getCategory(state))) {
ControlLink link = new ControlLink(value.toString());
link.setConfirmation((String) GlobalizationUtil.globalize(
"cms.ui.category.localization_confirm_delete").localize());
link.setConfirmation(GlobalizationUtil.globalize(
"cms.ui.category.localization_confirm_delete"));
return link;
} else {
return null;
@ -227,25 +241,25 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
PageState state = evt.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());
}
// // 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());
// }
}

View File

@ -23,7 +23,7 @@ import com.arsdigita.bebop.RequestLocal;
import org.libreccm.categorization.Category;
class CategoryRequestLocal extends RequestLocal {
public class CategoryRequestLocal extends RequestLocal {
public final Category getCategory(final PageState state) {
return (Category) get(state);

View File

@ -0,0 +1,370 @@
/*
* 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.templates;
import com.arsdigita.bebop.*;
import com.arsdigita.bebop.event.ActionEvent;
import com.arsdigita.bebop.event.ActionListener;
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.event.TableActionAdapter;
import com.arsdigita.bebop.event.TableActionEvent;
import com.arsdigita.bebop.form.Hidden;
import com.arsdigita.bebop.form.Option;
import com.arsdigita.bebop.form.SingleSelect;
import com.arsdigita.bebop.form.Submit;
import com.arsdigita.bebop.parameters.BigDecimalParameter;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.bebop.table.TableCellRenderer;
import com.arsdigita.bebop.table.TableColumn;
import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ui.CMSContainer;
import com.arsdigita.cms.ui.FormSecurityListener;
import com.arsdigita.cms.ui.category.CategoryComponentAccess;
import com.arsdigita.cms.ui.category.CategoryRequestLocal;
import com.arsdigita.kernel.ui.ACSObjectSelectionModel;
import com.arsdigita.util.Assert;
import com.arsdigita.util.UncheckedWrapperException;
import java.util.TooManyListenersException;
/**
* This component will eventually contain the full templates UI
* for content items. It is just a placeholder for now.
*
* @author Stanislav Freidin (sfreidin@arsdigita.com)
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
*/
public class CategoryTemplates extends CMSContainer {
private CategoryRequestLocal m_category;
private ACSObjectSelectionModel m_types;
private SingleSelectionModel m_contexts;
private CMSContainer m_display;
private CMSContainer m_assign;
public static final String ASSIGN_TEMPLATE = "assignTemplate";
/**
* TODO: Needs to be implemented and will then finally
* Construct a new CategoryTemplates component
*
* @param category the <code>CategoryRequestLocal</code> that will supply the
* current content item
*/
public CategoryTemplates(CategoryRequestLocal category) {
super();
m_category = category;
add(new Text("Placeholder"));
//
// m_types = new ACSObjectSelectionModel(new BigDecimalParameter("t"));
// m_contexts = new ParameterSingleSelectionModel(new StringParameter("c"));
//
// AssignForm form = new AssignForm("assign",
// m_types,
// m_contexts);
// form.addSubmissionListener
// (new FormSecurityListener(SecurityManager.CATEGORY_ADMIN));
//
// form.addProcessListener(new FormProcessListener() {
// public void process(FormSectionEvent e)
// throws FormProcessException {
//
// PageState state = e.getPageState();
//
// m_display.setVisible(state, false);
// m_assign.setVisible(state, true);
// }
// });
//
// CategoryTemplatesListingImpl l = new CategoryTemplatesListingImpl(category);
// SegmentedPanel st = new SegmentedPanel();
// st.addSegment(new Label("Assigned Templates"), l);
//
// m_display = new CMSContainer();
// m_display.add(form);
// m_display.add(st);
// add(m_display);
//
// SegmentedPanel sa = new SegmentedPanel();
// Label assignLabel = new Label("dummy");
// assignLabel.addPrintListener(new PrintListener() {
// public void prepare(PrintEvent e) {
// PageState s = e.getPageState();
// Label targetLabel = (Label)e.getTarget();
// Category category = m_category.getCategory(s);
// Assert.exists(category, "category");
// targetLabel.setLabel("Assign a template to " + category.getName());
// }
// });
// sa.addSegment(assignLabel,
// new AvailableTemplatesListing(m_category,
// m_types,
// m_contexts));
//
// ActionLink returnLink = new ActionLink("Return to template listing");
// returnLink.setClassAttr("actionLink");
// returnLink.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// PageState s = e.getPageState();
// m_display.setVisible(s, true);
// m_assign.setVisible(s, false);
// }
// });
//
// m_assign = new CMSContainer();
// m_assign.add(sa);
// m_assign.add(returnLink);
// add(m_assign);
}
@Override
public void register(Page p) {
super.register(p);
p.setVisibleDefault(m_assign, false);
p.addComponentStateParam(this, m_types.getStateParameter());
p.addComponentStateParam(this, m_contexts.getStateParameter());
}
/**
* Displays a list of templates which are currently assigned to
* the current item
*/
// protected class CategoryTemplatesListingImpl extends CategoryTemplatesListing {
//
// private CategoryComponentAccess m_access;
//
// public CategoryTemplatesListingImpl(CategoryRequestLocal category) {
// super(category);
// m_access = new CategoryComponentAccess(null, category);
// }
//
// public void assignLinkClicked(PageState s,
// Category category,
// String useContext) {
// }
//
// @Override
// public void register(Page p) {
// super.register(p);
//
// // Hide action columns if user has no access
//
// p.addActionListener(new ActionListener() {
// public void actionPerformed(ActionEvent e) {
// final PageState state = e.getPageState();
//
// if (state.isVisibleOnPage(CategoryTemplates.this)
// && !m_access.canAccess
// (state,
// CMS.getContext().getSecurityManager())) {
// getRemoveColumn().setVisible(state, false);
// }
// }
// });
// }
// }
//
// /**
// * Displays a list of templates for the given content item in the
// * given context, along with a link to select a template
// */
// protected class AvailableTemplatesListing extends TemplatesListing {
// TableColumn m_assignCol;
// ACSObjectSelectionModel m_type;
// CategoryRequestLocal m_category;
// SingleSelectionModel m_context;
//
// /**
// * Construct a new AvailableTemplatesListing
// *
// * @param contextModel the SingleSelectionModel that will define the
// * current use context
// */
// public AvailableTemplatesListing(CategoryRequestLocal category,
// ACSObjectSelectionModel type,
// SingleSelectionModel context) {
// m_type = type;
// m_category = category;
// m_context = context;
//
// // Add the "assign" column and corresponding action listener
// m_assignCol = addColumn("Assign",
// TemplateCollection.TEMPLATE, false,
// new AssignCellRenderer());
//
// addTableActionListener(new TableActionAdapter() {
// @Override
// public void cellSelected(TableActionEvent e) {
// PageState s = e.getPageState();
// TemplatesListing l = (TemplatesListing)e.getSource();
// int i = e.getColumn().intValue();
// TableColumn c = l.getColumnModel().get(i);
//
// // Safe to check pointer equality since the column is
// // created statically
// if(c == m_assignCol) {
// SectionTemplateMapping m =
// (SectionTemplateMapping)getMappingModel()
// .getSelectedObject(s);
// assignTemplate(s, m.getTemplate());
// }
// }
// });
// }
//
// /**
// * Get all the templates for the given type in the current section
// */
// protected TemplateCollection getTemplateCollection(PageState s) {
// ContentSection sec = ContentSectionServlet.getContentSection(s.getRequest());
// Assert.exists(sec, "content section");
//
// /*
// ContentItem item = m_category.getSelectedItem(s);
// Assert.exists(item, "item");
// */
//
// ContentType type = getContentType(s);
//
// TemplateCollection c = TemplateManagerFactory
// .getInstance().getTemplates(sec, type);
// /*
// c.addEqualsFilter(TemplateCollection.USE_CONTEXT,
// TemplateManager.PUBLIC_CONTEXT);
// */
// return c;
// }
//
// /**
// * Get the currently selected use context
// */
// protected ContentType getContentType(PageState s) {
// ContentType type = (ContentType)m_type.getSelectedObject(s);
// Assert.exists(type, "content type");
// return type;
// }
//
// /**
// * Assign a template to the current item
// */
// public void assignTemplate(PageState s, Template t) {
// Category category = m_category.getCategory(s);
// ContentType type = (ContentType)m_type.getSelectedObject(s);
// String useContext = (String)m_context.getSelectedKey(s);
// CategoryTemplateMapping map =
// CategoryTemplateMapping.getMapping(category, type, t,
// useContext);
// if(map == null) {
// map = new CategoryTemplateMapping();
// map.setCategory(category);
// map.setContentType(type);
// map.setUseContext(useContext);
// map.setTemplate(t);
// }
// map.setContentSection(ContentSectionServlet
// .getContentSection(s.getRequest()));
// map.save();
//
// m_display.setVisible(s, true);
// m_assign.setVisible(s, false);
// }
//
// /**
// * Render the "assign" link
// */
// protected class AssignCellRenderer implements TableCellRenderer {
//
// private ControlLink m_link;
//
// public AssignCellRenderer() {
// m_link = new ControlLink("Assign this template");
// m_link.setClassAttr("assignTemplateLink");
// }
//
// public Component getComponent(Table table, PageState state,
// Object value,
// boolean isSelected, Object key,
// int row, int column) {
// return m_link;
// }
// }
//
// }
//
// /**
// *
// */
// private class AssignForm extends Form {
//
// SingleSelect m_type;
// //SingleSelect m_context;
// Hidden m_context;
//
// public AssignForm(String name,
// final ACSObjectSelectionModel type,
// final SingleSelectionModel context) {
//
// super(name, new GridPanel(3));
//
// add(new Label("Content type:"));
// //add(new Label("Use context:"));
// //add(new Label(""));
//
// m_type = new SingleSelect(type.getStateParameter());
// try {
// m_type.addPrintListener(new PrintListener() {
// @Override
// public void prepare(PrintEvent event) {
// PageState state = event.getPageState();
// ContentSection section = ContentSectionServlet
// .getContentSection(state
// .getRequest());
//
// SingleSelect target = (SingleSelect)event.getTarget();
// target.clearOptions();
//
// ContentTypeCollection types = section.getContentTypes();
// types.addOrder(ContentType.LABEL);
//
// while (types.next()) {
// ContentType type = types.getContentType();
// target.addOption(new Option(type.getID().toString(),
// type.getName()));
// }
// }
// });
// } catch (TooManyListenersException ex) {
// throw new UncheckedWrapperException("This can never happen", ex);
// }
// add(m_type);
//
// // XXX no need for selecting template contexts currently
// m_context = new Hidden(context.getStateParameter());
// m_context.setDefaultValue(TemplateManager.PUBLIC_CONTEXT);
//
// add(m_context);
//
// add(new Submit("Assign template"));
// }
// }
}

View File

@ -0,0 +1,132 @@
/*
* 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.bebop;
import com.arsdigita.bebop.list.ListModel;
import com.arsdigita.bebop.list.ListModelBuilder;
import com.arsdigita.bebop.table.DefaultTableCellRenderer;
import com.arsdigita.bebop.table.DefaultTableColumnModel;
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.util.LockableImpl;
/**
* Displays a {@link ListModel} as a grid (that is, a {@link Table})
* of given width.
*
* @version $Id: Grid.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class Grid extends Table {
private int m_cols;
/**
* Constructs a new <code>Grid</code>.
* <p>
*
* @param builder the {@link ListModelBuilder} that provides
* the grid with data
*
* @param numCols the number of columns in the grid
*/
public Grid(ListModelBuilder builder, int numCols) {
super(new GridModelBuilder(builder, numCols), new DefaultTableColumnModel());
m_cols = numCols;
setHeader(null);
TableColumnModel cols = getColumnModel();
for(int i=0; i<numCols; i++) {
cols.add(new TableColumn(i));
}
setClassAttr("grid");
setWidth("100%");
// Ignore null values
setDefaultCellRenderer(new DefaultTableCellRenderer(true) {
@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);
else
return super.getComponent(table, state, value, isSelected, key, row, column);
}
});
}
/**
* @param builder the {@link ListModelBuilder} that provides
* the grid with data
*/
public void setModelBuilder(ListModelBuilder builder) {
super.setModelBuilder(new GridModelBuilder(builder, getColumnCount()));
}
/**
* @return the number of columns in the grid.
*/
public int getColumnCount() {
return m_cols;
}
/**
* Converts a ListModel to a TableModel
*/
private static class GridModelBuilder extends LockableImpl
implements TableModelBuilder {
private ListModelBuilder m_builder;
private int m_cols;
public GridModelBuilder(ListModelBuilder builder, int cols) {
super();
m_builder = builder;
m_cols = cols;
}
public TableModel makeModel(Table t, PageState s) {
//XXX FIXME: The creation of a new List() below is a
//Hack to compile all...remove and fix.
//This is because makeModel requires a List arg.
//Should add a List setter function to Grid class, and
//initialize to null, then pass in null below if necessary...
//Christian: I will let your review team ponder this
//proposed change, and if approved, please assign the
//ticket to me! -jbp
List l = new List();
ListModel m = m_builder.makeModel(l,s);
return new GridTableModel(m, m_cols);
}
@Override
public void lock() {
m_builder.lock();
super.lock();
}
}
}

View File

@ -0,0 +1,104 @@
/*
* 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.bebop;
import com.arsdigita.bebop.table.TableModel;
import com.arsdigita.bebop.list.ListModel;
import java.util.ArrayList;
/**
* Converts a linear ListModel to a grid of items.
* For example, <code>A B C D E F G</code> becomes:
*
* <code><pre>
* A D G
* B E .
* C F .
* </pre></code>
*
* The extraneous cells in the table are filled
* with <code>GridTableModel.PLACEHOLDER</code>.
*
* @version $Id: GridTableModel.java 287 2005-02-22 00:29:02Z sskracic $
*/
public class GridTableModel implements TableModel {
private ListModel m_items;
private int m_colHeight, m_cols, m_size, m_index;
private Object[] m_elements;
private Object[] m_keys;
/**
* Constructs a new <code>GridTableModel</code>.
* @param items a {@link ListModel} that represents the
* items
* @param cols the number of columns in the grid
*/
public GridTableModel(ListModel items, int cols) {
m_items = items;
m_cols = cols;
// Load the items into memory
ArrayList elements = new ArrayList(), keys = new ArrayList();
for(m_size=0; m_items.next(); m_size++) {
elements.add(m_items.getElement());
keys.add(m_items.getKey());
}
m_elements = elements.toArray();
m_keys = keys.toArray();
// Round up
m_colHeight = m_size / m_cols;
if(m_colHeight * m_cols < m_size) ++m_colHeight;
m_index = -1;
}
public int getColumnCount() {
return m_cols;
}
public boolean nextRow() {
if(m_index >= m_colHeight - 1)
return false;
++m_index;
return true;
}
private Object safeGet(Object[] a, int columnIndex) {
int i = m_index + m_colHeight*columnIndex;
if(i >= a.length)
return null;
else
return a[i];
}
public Object getElementAt(int columnIndex) {
return safeGet(m_elements, columnIndex);
}
public Object getKeyAt(int columnIndex) {
return safeGet(m_keys, columnIndex);
}
}

View File

@ -0,0 +1,107 @@
/*
* 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 org.libreccm.categorization;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.tree.TreeModel;
import com.arsdigita.bebop.tree.TreeNode;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Iterator;
/**
* Implements the {@link com.arsdigita.bebop.tree.TreeModel} interface for
* categories.
*
* @author Daniel Berrange
* @version $Revision: #17 $ $DateTime: 2004/08/16 18:10:38 $
*/
public class CategoryTreeModelLite implements TreeModel {
private static final Logger LOGGER = LogManager.getLogger(
CategoryTreeModelLite.class);
// String m_order = null;
final Category category;
/**
* Initializes with the passed in the root Category.
*
* @param root the root category for this TreeModel
*/
// public CategoryTreeModelLite(Category root) {
// this(root, null);
// }
/**
* Initializes with the passed in the root Category.
*
* @param root the root category for this TreeModel
*/
public CategoryTreeModelLite(Category root) {
// super(root.getUniqueId(),
// "com.arsdigita.categorization.getRootCategory",
// "com.arsdigita.categorization.getSubCategories");
// m_order = order;
category = root;
}
// @Override
// protected DataQueryTreeIterator getDataQueryTreeIterator(DataQueryTreeNode node,
// String getSubCategories) {
// return new CategoryTreeIterator(node, getSubCategories, m_order);
// }
@Override
public TreeNode getRoot(PageState data) {
return null;
}
@Override
public boolean hasChildren(TreeNode n, PageState data) {
return false;
}
@Override
public Iterator<TreeNode> getChildren(TreeNode n, PageState data) {
return null;
}
// private static class CategoryTreeIterator extends DataQueryTreeIterator {
//
// public CategoryTreeIterator(DataQueryTreeNode node, String getSubCategories, String order) {
// super(node, getSubCategories);
// if (order != null) {
// addOrder(order);
// }
// }
//
// @Override
// public Object next() {
// DataQueryTreeNode node = (DataQueryTreeNode) super.next();
//
// // m_nodes.getLink
// node.setValue(Category.IS_ABSTRACT,
// (Boolean) m_nodes.get(Category.IS_ABSTRACT));
// return node;
// }
//
// }
}