CategoryLocalization

EditForm angebunden. Verknüpfung funktioniert, mit einer Ausnahme: der Parameter für die Sprachvariante wird noch nicht erkann und erzeugt daher einen Assert-Fehler.

git-svn-id: https://svn.libreccm.org/ccm/trunk@1808 8810af33-2d31-482b-a856-94f89814c4df
master
quasi 2012-08-08 16:08:10 +00:00
parent b3105ac2e8
commit 8aea372fd5
4 changed files with 376 additions and 304 deletions

View File

@ -25,6 +25,7 @@ import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.Label; import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Link; import com.arsdigita.bebop.Link;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.SimpleContainer; import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.SingleSelectionModel; import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.event.ActionEvent; import com.arsdigita.bebop.event.ActionEvent;
@ -32,6 +33,7 @@ import com.arsdigita.bebop.event.ActionListener;
import com.arsdigita.bebop.event.ChangeEvent; import com.arsdigita.bebop.event.ChangeEvent;
import com.arsdigita.bebop.event.ChangeListener; import com.arsdigita.bebop.event.ChangeListener;
import com.arsdigita.bebop.form.Submit; import com.arsdigita.bebop.form.Submit;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.categorization.CategorizedCollection; import com.arsdigita.categorization.CategorizedCollection;
import com.arsdigita.categorization.Category; import com.arsdigita.categorization.Category;
import com.arsdigita.categorization.CategoryCollection; import com.arsdigita.categorization.CategoryCollection;
@ -80,6 +82,8 @@ class CategoryItemPane extends BaseItemPane {
private final SingleSelectionModel m_model; private final SingleSelectionModel m_model;
private final CategoryRequestLocal m_category; private final CategoryRequestLocal m_category;
private final SimpleContainer m_detailPane; private final SimpleContainer m_detailPane;
private final StringParameter m_catLocaleParam = new StringParameter("catLocale");
private final ParameterSingleSelectionModel m_catLocale;
public CategoryItemPane(final SingleSelectionModel model, public CategoryItemPane(final SingleSelectionModel model,
final CategoryRequestLocal category, final CategoryRequestLocal category,
@ -88,9 +92,9 @@ class CategoryItemPane extends BaseItemPane {
final ActionLink deleteLink) { final ActionLink deleteLink) {
m_model = model; m_model = model;
m_category = category; m_category = category;
m_catLocale = new ParameterSingleSelectionModel(m_catLocaleParam);
// Details // Details
m_detailPane = new SimpleContainer(); m_detailPane = new SimpleContainer();
add(m_detailPane); add(m_detailPane);
setDefault(m_detailPane); setDefault(m_detailPane);
@ -145,7 +149,8 @@ class CategoryItemPane extends BaseItemPane {
m_category.getCategory(state) m_category.getCategory(state)
.getCategoryLocalizationCollection().size(); .getCategoryLocalizationCollection().size();
if (countLanguages < countSupportedLanguages) { if (m_category.getCategory(state).canEdit()
&& countLanguages < countSupportedLanguages) {
return true; return true;
} else { } else {
return false; return false;
@ -339,14 +344,14 @@ class CategoryItemPane extends BaseItemPane {
final ActionGroup group = new ActionGroup(); final ActionGroup group = new ActionGroup();
setBody(group); setBody(group);
m_catLocalizationTable = new CategoryLocalizationTable(m_category, m_model); m_catLocalizationTable = new CategoryLocalizationTable(m_category, m_model, m_catLocale);
group.setSubject(m_catLocalizationTable); group.setSubject(m_catLocalizationTable);
group.addAction(new AdminVisible(addLink), ActionGroup.ADD); group.addAction(new AdminVisible(addLink), ActionGroup.ADD);
m_editCategoryLocalizationForm = new CategoryLocalizationEditForm(m_category, "de"); m_editCategoryLocalizationForm = new CategoryLocalizationEditForm(m_category, m_catLocale);
add(m_editCategoryLocalizationForm);
connect(m_editCategoryLocalizationForm); connect(m_editCategoryLocalizationForm);
connect(m_catLocalizationTable, 0, m_editCategoryLocalizationForm); connect(m_catLocalizationTable, 0, m_editCategoryLocalizationForm);
} }
} }
@ -593,6 +598,7 @@ class CategoryItemPane extends BaseItemPane {
* and the user is allowed to edit this item. * and the user is allowed to edit this item.
* *
* @param state * @param state
*
* @return * @return
*/ */
@Override @Override
@ -614,6 +620,7 @@ class CategoryItemPane extends BaseItemPane {
* *
* @param item * @param item
* @param state * @param state
*
* @return * @return
*/ */
private boolean isItemEditable(ContentItem item, PageState state) { private boolean isItemEditable(ContentItem item, PageState state) {

View File

@ -20,6 +20,7 @@ package com.arsdigita.cms.ui.category;
import com.arsdigita.bebop.FormProcessException; import com.arsdigita.bebop.FormProcessException;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.event.FormInitListener; import com.arsdigita.bebop.event.FormInitListener;
import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormProcessListener;
import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.event.FormSectionEvent;
@ -44,19 +45,16 @@ public class CategoryLocalizationEditForm extends CategoryLocalizationForm {
private static final Logger s_log = Logger.getLogger private static final Logger s_log = Logger.getLogger
(CategoryLocalizationEditForm.class); (CategoryLocalizationEditForm.class);
private final String m_categoryLocalizationLocale; private final SingleSelectionModel m_catLocale;
/** /**
* Creates a new instance of CategoryLocalizationEditForm * Creates a new instance of CategoryLocalizationEditForm
*/ */
public CategoryLocalizationEditForm(final CategoryRequestLocal category, public CategoryLocalizationEditForm(final CategoryRequestLocal category, SingleSelectionModel catLocale) {
final String locale) {
super("EditCategoryLocalization", gz( super("EditCategoryLocalization", gz(
"cms.ui.category.localization_edit"), category); "cms.ui.category.localization_edit"), category);
// Speichere Locale ab m_catLocale = catLocale;
m_categoryLocalizationLocale = locale;
addInitListener(new InitListener()); addInitListener(new InitListener());
addProcessListener(new ProcessListener()); addProcessListener(new ProcessListener());
@ -73,19 +71,20 @@ public class CategoryLocalizationEditForm extends CategoryLocalizationForm {
final PageState state = e.getPageState(); final PageState state = e.getPageState();
final Category category = m_category.getCategory(state); final Category category = m_category.getCategory(state);
final String categoryLocalizationLocale = (String) m_catLocale.getSelectedKey(state);
// Hide Locale-Widget and lock it (read-only) // Hide Locale-Widget and lock it (read-only)
m_locale.addOption(new Option(m_categoryLocalizationLocale, m_locale.addOption(new Option(categoryLocalizationLocale,
new Locale(m_categoryLocalizationLocale).getDisplayLanguage()), state); new Locale(categoryLocalizationLocale).getDisplayLanguage()), state);
// m_locale.setValue(state, m_categoryLocalizationLocale); m_locale.setValue(state, categoryLocalizationLocale);
// m_locale.setVisible(state, false); // m_locale.setVisible(state, false);
m_locale.lock(); m_locale.lock();
m_name.setValue(state, category.getName((String) m_locale.getValue(state))); m_name.setValue(state, category.getName(categoryLocalizationLocale));
m_description.setValue(state, category.getDescription( m_description.setValue(state, category.getDescription(categoryLocalizationLocale));
(String) m_locale.getValue(state))); m_url.setValue(state, category.getURL(categoryLocalizationLocale));
m_url.setValue(state, category.getURL((String) m_locale.getValue(state)));
if (category.isEnabled((String) m_locale.getValue(state))) { if (category.isEnabled(categoryLocalizationLocale)) {
m_isEnabled.setValue(state, "yes"); m_isEnabled.setValue(state, "yes");
} else { } else {
m_isEnabled.setValue(state, "no"); m_isEnabled.setValue(state, "no");

View File

@ -21,13 +21,11 @@ package com.arsdigita.cms.ui.category;
import com.arsdigita.bebop.Component; import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.ControlLink; import com.arsdigita.bebop.ControlLink;
import com.arsdigita.bebop.Label; import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Link;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SingleSelectionModel; import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.Table; import com.arsdigita.bebop.Table;
import com.arsdigita.bebop.event.TableActionEvent; import com.arsdigita.bebop.event.TableActionEvent;
import com.arsdigita.bebop.event.TableActionListener; import com.arsdigita.bebop.event.TableActionListener;
import com.arsdigita.bebop.table.DefaultTableCellRenderer;
import com.arsdigita.bebop.table.TableCellRenderer; import com.arsdigita.bebop.table.TableCellRenderer;
import com.arsdigita.bebop.table.TableColumn; import com.arsdigita.bebop.table.TableColumn;
import com.arsdigita.bebop.table.TableColumnModel; import com.arsdigita.bebop.table.TableColumnModel;
@ -36,13 +34,7 @@ import com.arsdigita.bebop.table.TableModelBuilder;
import com.arsdigita.categorization.Category; import com.arsdigita.categorization.Category;
import com.arsdigita.categorization.CategoryLocalization; import com.arsdigita.categorization.CategoryLocalization;
import com.arsdigita.categorization.CategoryLocalizationCollection; import com.arsdigita.categorization.CategoryLocalizationCollection;
import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.SecurityManager;
import com.arsdigita.cms.dispatcher.ItemResolver;
import com.arsdigita.cms.dispatcher.Utilities;
import com.arsdigita.cms.util.GlobalizationUtil; import com.arsdigita.cms.util.GlobalizationUtil;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.util.LockableImpl; import com.arsdigita.util.LockableImpl;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Locale; import java.util.Locale;
@ -61,17 +53,18 @@ public class CategoryLocalizationTable extends Table implements TableActionListe
private final SingleSelectionModel m_model; private final SingleSelectionModel m_model;
private final String TABLE_COL_LANG = "table_col_lang"; private final String TABLE_COL_LANG = "table_col_lang";
private final String TABLE_COL_DEL = "table_col_del"; private final String TABLE_COL_DEL = "table_col_del";
private final SingleSelectionModel m_catLocale;
/** /**
* Creates a new instance of CategoryLocalizationTable * Creates a new instance of CategoryLocalizationTable
*/ */
public CategoryLocalizationTable(final CategoryRequestLocal category, public CategoryLocalizationTable(final CategoryRequestLocal category, final SingleSelectionModel model, SingleSelectionModel catLocale) {
final SingleSelectionModel model) {
super(); super();
m_category = category; m_category = category;
m_model = model; m_model = model;
m_catLocale = catLocale;
// if table is empty: // if table is empty:
setEmptyView(new Label(GlobalizationUtil.globalize( setEmptyView(new Label(GlobalizationUtil.globalize(
@ -196,25 +189,15 @@ TableColumnModel tab_model = getColumnModel();
private class EditCellRenderer extends LockableImpl implements TableCellRenderer { private class EditCellRenderer extends LockableImpl implements TableCellRenderer {
public Component getComponent(Table table, PageState state, Object value, public Component getComponent(Table table, PageState state, Object value,
boolean isSelected, Object key, boolean isSelected, final Object key,
int row, int column) { int row, int column) {
// if (canEdit) { if (m_category.getCategory(state).canEdit()) {
// CategoryLocalization cl; return new ControlLink(value.toString());
} else {
// try { return new Label(value.toString());
// cl = new CategoryLocalization((BigDecimal) key); }
// } catch (DataObjectNotFoundException ex) {
// return new Label(value.toString());
// }
// ContentSection section = CMS.getContext().getContentSection();
// ItemResolver resolver = section.getItemResolver();
// return new Link(value.toString(), resolver.generateItemURL(state, cl, section, cl.getVersion()));
ControlLink link = new ControlLink(value.toString());
return link;
} }
} }
@ -224,10 +207,14 @@ TableColumnModel tab_model = getColumnModel();
boolean isSelected, Object key, boolean isSelected, Object key,
int row, int column) { int row, int column) {
if (m_category.getCategory(state).canDelete()) {
ControlLink link = new ControlLink(value.toString()); ControlLink link = new ControlLink(value.toString());
link.setConfirmation((String) GlobalizationUtil.globalize( link.setConfirmation((String) GlobalizationUtil.globalize(
"cms.ui.category.localization_confirm_delete").localize()); "cms.ui.category.localization_confirm_delete").localize());
return link; return link;
} else {
return null;
}
} }
} }
@ -252,6 +239,7 @@ TableColumnModel tab_model = getColumnModel();
// Edit // Edit
if (col.getHeaderKey().toString().equals(TABLE_COL_LANG)) { if (col.getHeaderKey().toString().equals(TABLE_COL_LANG)) {
m_catLocale.setSelectedKey(state, categoryLocalization.getLocale());
} }
// Delete // Delete

View File

@ -106,15 +106,18 @@ public class Category extends ACSObject {
private static final Logger s_log = Logger.getLogger(Category.class); private static final Logger s_log = Logger.getLogger(Category.class);
/** /**
* @see ObjectType * @see ObjectType
**/ *
*/
public static final String BASE_DATA_OBJECT_TYPE = public static final String BASE_DATA_OBJECT_TYPE =
"com.arsdigita.categorization.Category"; "com.arsdigita.categorization.Category";
private static final String BASE_DATA_OBJECT_PACKAGE = private static final String BASE_DATA_OBJECT_PACKAGE =
"com.arsdigita.categorization"; "com.arsdigita.categorization";
/** /**
* The <code>PrivilegeDescriptor corresponding</code> to the privilege to * The
* <code>PrivilegeDescriptor corresponding</code> to the privilege to
* map subcategories and objects to this category * map subcategories and objects to this category
**/ *
*/
public static final PrivilegeDescriptor MAP_DESCRIPTOR = public static final PrivilegeDescriptor MAP_DESCRIPTOR =
new PrivilegeDescriptor( new PrivilegeDescriptor(
"map_to_category"); "map_to_category");
@ -128,38 +131,64 @@ public class Category extends ACSObject {
public static final String ROOT_USE_CONTEXT = "rootUseContext"; public static final String ROOT_USE_CONTEXT = "rootUseContext";
public static final String OWNER_USE_CONTEXT = "ownerUseContext"; public static final String OWNER_USE_CONTEXT = "ownerUseContext";
// category-category mapping types // category-category mapping types
/** An attribute name for the underlying data object. */ /**
* An attribute name for the underlying data object.
*/
public static final String CHILD = "child"; public static final String CHILD = "child";
/** An attribute name for the underlying data object. */ /**
* An attribute name for the underlying data object.
*/
public static final String PARENTS = "parents"; public static final String PARENTS = "parents";
/** An attribute name for the underlying data object. */ /**
* An attribute name for the underlying data object.
*/
public static final String RELATED = "related"; public static final String RELATED = "related";
public static final String PREFERRED = "preferred"; public static final String PREFERRED = "preferred";
/** An attribute name for the underlying data object. */ /**
* An attribute name for the underlying data object.
*/
public static final String REL_TYPE = "relationType"; public static final String REL_TYPE = "relationType";
/** An attribute name for the underlying data object. */ /**
* An attribute name for the underlying data object.
*/
public static final String SORT_KEY = "sortKey"; public static final String SORT_KEY = "sortKey";
public static final String IS_DEFAULT = "isDefault"; public static final String IS_DEFAULT = "isDefault";
public static final String IS_INDEX = "isIndex"; public static final String IS_INDEX = "isIndex";
public static final String PARENT_CATEGORY = "parentCategory"; public static final String PARENT_CATEGORY = "parentCategory";
public static final String CATEGORY_ID = "categoryID"; public static final String CATEGORY_ID = "categoryID";
// these are some constants to use in the code // these are some constants to use in the code
/** An attribute name for the underlying data object. */ /**
* An attribute name for the underlying data object.
*/
public static final String NAME = "name"; public static final String NAME = "name";
/** An attribute name for the underlying data object. */ /**
* An attribute name for the underlying data object.
*/
public static final String DESCRIPTION = "description"; public static final String DESCRIPTION = "description";
/** An attribute name for the underlying data object. */ /**
* An attribute name for the underlying data object.
*/
public static final String URL = "url"; public static final String URL = "url";
/** An attribute name for the underlying data object. */ /**
* An attribute name for the underlying data object.
*/
public static final String IS_ENABLED = "isEnabled"; public static final String IS_ENABLED = "isEnabled";
/** An attribute name for the underlying data object. */ /**
* An attribute name for the underlying data object.
*/
public static final String IS_ABSTRACT = "isAbstract"; public static final String IS_ABSTRACT = "isAbstract";
/** An attribute name for the underlying data object. */ /**
* An attribute name for the underlying data object.
*/
public static final String DEFAULT_ANCESTORS = "defaultAncestors"; public static final String DEFAULT_ANCESTORS = "defaultAncestors";
/** An attribute name for the underlying data object. */ /**
* An attribute name for the underlying data object.
*/
public static final String IGNORE_PARENT_INDEX_ITEM = public static final String IGNORE_PARENT_INDEX_ITEM =
"ignoreParentIndexItem"; "ignoreParentIndexItem";
/** An attribute name for the underlying data object. */ /**
* An attribute name for the underlying data object.
*/
private static final String PURPOSES = "purposes"; private static final String PURPOSES = "purposes";
// this contains association names from the pdl file // this contains association names from the pdl file
public final static String CHILD_OBJECTS = "childObjects"; public final static String CHILD_OBJECTS = "childObjects";
@ -183,7 +212,8 @@ public class Category extends ACSObject {
/** /**
* Returns the model name of {@link #BASE_DATA_OBJECT_TYPE}. * Returns the model name of {@link #BASE_DATA_OBJECT_TYPE}.
**/ *
*/
public static String getBaseDataObjectPackage() { public static String getBaseDataObjectPackage() {
return BASE_DATA_OBJECT_PACKAGE; return BASE_DATA_OBJECT_PACKAGE;
} }
@ -192,7 +222,8 @@ public class Category extends ACSObject {
* Initializes the category with the specified data object. * Initializes the category with the specified data object.
* *
* @param categoryObjectData the data object * @param categoryObjectData the data object
**/ *
*/
public Category(DataObject categoryObjectData) { public Category(DataObject categoryObjectData) {
super(categoryObjectData); super(categoryObjectData);
} }
@ -202,7 +233,8 @@ public class Category extends ACSObject {
* Category(Category.BSE_DATA_OBJECT_TYPE)}. * Category(Category.BSE_DATA_OBJECT_TYPE)}.
* *
* @see com.arsdigita.domain.DomainObject#DomainObject(String) * @see com.arsdigita.domain.DomainObject#DomainObject(String)
**/ *
*/
public Category() { public Category() {
this(BASE_DATA_OBJECT_TYPE); this(BASE_DATA_OBJECT_TYPE);
} }
@ -216,7 +248,8 @@ public class Category extends ACSObject {
* @see com.arsdigita.domain.DomainObject#DomainObject(String) * @see com.arsdigita.domain.DomainObject#DomainObject(String)
* @see com.arsdigita.persistence.DataObject * @see com.arsdigita.persistence.DataObject
* @see com.arsdigita.persistence.metadata.ObjectType * @see com.arsdigita.persistence.metadata.ObjectType
**/ *
*/
public Category(String typeName) { public Category(String typeName) {
super(typeName); super(typeName);
} }
@ -229,7 +262,8 @@ public class Category extends ACSObject {
* *
* @see com.arsdigita.domain.DomainObject#DomainObject(ObjectType) * @see com.arsdigita.domain.DomainObject#DomainObject(ObjectType)
* @see com.arsdigita.persistence.DataObject * @see com.arsdigita.persistence.DataObject
**/ *
*/
public Category(ObjectType type) { public Category(ObjectType type) {
super(type); super(type);
} }
@ -239,12 +273,14 @@ public class Category extends ACSObject {
* storage mechanism. * storage mechanism.
* *
* @param oid the OID for the data object to retrieve * @param oid the OID for the data object to retrieve
*
* @throws DataObjectNotFoundException if this OID is invalid or has been * @throws DataObjectNotFoundException if this OID is invalid or has been
* deleted. * deleted.
* *
* @see com.arsdigita.domain.DomainObject#DomainObject(OID) * @see com.arsdigita.domain.DomainObject#DomainObject(OID)
* @see com.arsdigita.persistence.DataObject * @see com.arsdigita.persistence.DataObject
**/ *
*/
public Category(OID oid) { public Category(OID oid) {
super(oid); super(oid);
} }
@ -295,6 +331,7 @@ public class Category extends ACSObject {
* @param categoryID the category ID * @param categoryID the category ID
* @param name the category name * @param name the category name
* @param description the category description * @param description the category description
*
* @exception DataObjectNotFoundException if this OID is * @exception DataObjectNotFoundException if this OID is
* invalid or has been deleted. * invalid or has been deleted.
* *
@ -315,6 +352,7 @@ public class Category extends ACSObject {
* @param name the category name * @param name the category name
* @param description the category description * @param description the category description
* @param url URL component used when browsing categories. * @param url URL component used when browsing categories.
*
* @exception DataObjectNotFoundException if this OID is * @exception DataObjectNotFoundException if this OID is
* invalid or has been deleted. * invalid or has been deleted.
* *
@ -370,14 +408,15 @@ public class Category extends ACSObject {
/** /**
* Quasimodo: * Quasimodo:
* Returns the localized name or the name key if localized version don't exist * Returns the localized name or the name key if localized version don't
* exist
* *
* @return the category name. * @return the category name.
*/ */
public String getName(String locale) { public String getName(String locale) {
// Test for localized version // Test for localized version
if (!locale.isEmpty() && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection. if (locale != null && !locale.isEmpty() && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection.
localizationExists(locale)) { localizationExists(locale)) {
// Return value of isEnabled from localized version, so categories could be disabled depending on locale // Return value of isEnabled from localized version, so categories could be disabled depending on locale
@ -404,6 +443,7 @@ public class Category extends ACSObject {
/** /**
* Returns the display name of the category. This overrides the parent * Returns the display name of the category. This overrides the parent
* implementation. * implementation.
*
* @return the category name. * @return the category name.
*/ */
public String getDisplayName(String locale) { public String getDisplayName(String locale) {
@ -413,6 +453,7 @@ public class Category extends ACSObject {
/** /**
* Returns the display name of the category. This overrides the parent * Returns the display name of the category. This overrides the parent
* implementation. * implementation.
*
* @return the category name. * @return the category name.
*/ */
@Override @Override
@ -464,12 +505,15 @@ public class Category extends ACSObject {
} }
/** /**
* Returns the name of the <b>preferred</b> category along with its default ancestors. * Returns the name of the <b>preferred</b> category along with its default
* Equivalent to #getQualifiedName(String,boolean) if this Category is not a synonym. * ancestors.
* Equivalent to #getQualifiedName(String,boolean) if this Category is not a
* synonym.
* Synonym name is appended in parentheses. * Synonym name is appended in parentheses.
* *
* @param delimiter string to separate category names * @param delimiter string to separate category names
* @param includeRoot should root category be shown * @param includeRoot should root category be shown
*
* @return category path * @return category path
*/ */
public String getPreferredQualifiedName(String delimiter, public String getPreferredQualifiedName(String delimiter,
@ -495,7 +539,7 @@ public class Category extends ACSObject {
* *
* @param delimiter The string to use to seperate the parents from * @param delimiter The string to use to seperate the parents from
* the children. * the children.
*
* @param includeRoot This indicates whether or not the root category should * @param includeRoot This indicates whether or not the root category should
* be included in the URL. * be included in the URL.
*/ */
@ -549,7 +593,8 @@ public class Category extends ACSObject {
* Returns the description of the category. * Returns the description of the category.
* *
* Quasimodo: * Quasimodo:
* Returns localized version of description or description key if localized version don't exist * Returns localized version of description or description key if localized
* version don't exist
* *
* @return the category description. * @return the category description.
*/ */
@ -557,7 +602,7 @@ public class Category extends ACSObject {
// Test for localized version // Test for localized version
// HACK // HACK
if (!locale.isEmpty() && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection. if (locale != null && !locale.isEmpty() && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection.
localizationExists(locale)) { localizationExists(locale)) {
// Return value of isEnabled from localized version, so categories could be disabled depending on locale // Return value of isEnabled from localized version, so categories could be disabled depending on locale
@ -576,6 +621,7 @@ public class Category extends ACSObject {
/** /**
* Returns the description of the category. * Returns the description of the category.
*
* @return the category name. * @return the category name.
*/ */
public String getDescription() { public String getDescription() {
@ -587,7 +633,9 @@ public class Category extends ACSObject {
* Returns a string repesenting the default ancestors of the category * Returns a string repesenting the default ancestors of the category
* *
* It can be useful and more efficient then working with the * It can be useful and more efficient then working with the
* CategoryCollection returned by @see getDefaultAscendants() when comparing * CategoryCollection returned by
*
* @see getDefaultAscendants() when comparing
* ids whose position in the path is known. * ids whose position in the path is known.
* (Added by Chris Gilbert) * (Added by Chris Gilbert)
*/ */
@ -623,14 +671,15 @@ public class Category extends ACSObject {
* Returns the URL component of the category. * Returns the URL component of the category.
* *
* Quasimodo: * Quasimodo:
* Returns the localized version of the URL or URL-key if localized version don't exist * Returns the localized version of the URL or URL-key if localized version
* don't exist
* *
* @return URL component used when browsing categories * @return URL component used when browsing categories
*/ */
public String getURL(String locale) { public String getURL(String locale) {
// Test for localized version // Test for localized version
if (!locale.isEmpty() && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection. if (locale != null && !locale.isEmpty() && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection.
localizationExists(locale)) { localizationExists(locale)) {
// Return value of isEnabled from localized version, so categories could be disabled depending on locale // Return value of isEnabled from localized version, so categories could be disabled depending on locale
@ -696,16 +745,12 @@ public class Category extends ACSObject {
*/ */
public boolean isEnabled(String locale) { public boolean isEnabled(String locale) {
// If locale is empty return global status // If not gloebally disabled and locale is not null or empty, test for localized version
// or if globally disabled, return category as disabled if (locale != null &&
if (locale.isEmpty() || ((Boolean) get(IS_ENABLED)).booleanValue() == false) { !locale.isEmpty() &&
return ((Boolean) get(IS_ENABLED)).booleanValue(); ((Boolean) get(IS_ENABLED)).booleanValue() == true &&
} m_categoryLocalizationCollection != null &&
m_categoryLocalizationCollection.localizationExists(locale)) {
// Test for localized version
// HACK
if (!locale.isEmpty() && m_categoryLocalizationCollection != null && m_categoryLocalizationCollection.
localizationExists(locale)) {
// Return value of isEnabled from localized version, so categories could be disabled depending on locale // Return value of isEnabled from localized version, so categories could be disabled depending on locale
boolean isEnabled = m_categoryLocalizationCollection.isEnabled(); boolean isEnabled = m_categoryLocalizationCollection.isEnabled();
@ -715,10 +760,8 @@ public class Category extends ACSObject {
} else { } else {
// Return value of Category.getConfig().getShowInternalName() // In any other case return global status
// This will disable all categories without selected locale, if Category.getConfig().getShowInternalName() == false return ((Boolean) get(IS_ENABLED)).booleanValue();
return Category.getConfig().getShowInternalName();
} }
} }
@ -783,7 +826,8 @@ public class Category extends ACSObject {
* Determine whether this category should have a default index item * Determine whether this category should have a default index item
* associated with it (i.e.it's parent category). * associated with it (i.e.it's parent category).
* *
* @return <code>true</code> if the parent index item should be ignored (no default index item) * @return <code>true</code> if the parent index item should be ignored (no
* default index item)
* <code>false</code> otherwise. * <code>false</code> otherwise.
*/ */
public boolean ignoreParentIndexItem() { public boolean ignoreParentIndexItem() {
@ -794,7 +838,8 @@ public class Category extends ACSObject {
* Set whether this category should have a default index item * Set whether this category should have a default index item
* associated with it (i.e.it's parent category). * associated with it (i.e.it's parent category).
* *
* @param ignoreParentIndexItem <code>true</code> if the parent index item should be ignored (no default index item) * @param ignoreParentIndexItem <code>true</code> if the parent index item
* should be ignored (no default index item)
* <code>false</code> otherwise * <code>false</code> otherwise
*/ */
public void setIgnoreParentIndexItem(boolean ignoreParentIndexItem) { public void setIgnoreParentIndexItem(boolean ignoreParentIndexItem) {
@ -803,7 +848,8 @@ public class Category extends ACSObject {
/** /**
* @deprecated use the "use context" APIs instead * @deprecated use the "use context" APIs instead
**/ *
*/
public Collection getPurposes() { public Collection getPurposes() {
DataAssociationCursor purposeCur = ((DataAssociation) get(PURPOSES)). DataAssociationCursor purposeCur = ((DataAssociation) get(PURPOSES)).
cursor(); cursor();
@ -820,8 +866,10 @@ public class Category extends ACSObject {
* Adds the specified purpose to this category. * Adds the specified purpose to this category.
* *
* @param purpose The purpose * @param purpose The purpose
*
* @deprecated use the "use context" APIs instead * @deprecated use the "use context" APIs instead
**/ *
*/
public void addPurpose(CategoryPurpose purpose) { public void addPurpose(CategoryPurpose purpose) {
add(PURPOSES, purpose); add(PURPOSES, purpose);
} }
@ -830,8 +878,10 @@ public class Category extends ACSObject {
* Removes the specified purpose from this category. * Removes the specified purpose from this category.
* *
* @param purpose the purpose * @param purpose the purpose
*
* @deprecated use the "use context" APIs instead * @deprecated use the "use context" APIs instead
**/ *
*/
public void removePurpose(CategoryPurpose purpose) { public void removePurpose(CategoryPurpose purpose) {
remove(PURPOSES, purpose); remove(PURPOSES, purpose);
} }
@ -941,7 +991,8 @@ public class Category extends ACSObject {
* *
* <p>If the category to be deleted is not the default parent of the child * <p>If the category to be deleted is not the default parent of the child
* category, this method deletes the mapping but it does not delete that * category, this method deletes the mapping but it does not delete that
* section of the subtree (similar to the way a UNIX <code>rm -r</code> * section of the subtree (similar to the way a UNIX
* <code>rm -r</code>
* works on symbolic links). * works on symbolic links).
*/ */
public void deleteCategorySubtree() { public void deleteCategorySubtree() {
@ -1055,7 +1106,8 @@ public class Category extends ACSObject {
* *
* @pre !isAbstract() * @pre !isAbstract()
* @pre canMap() * @pre canMap()
**/ *
*/
public void addChild(ACSObject object) { public void addChild(ACSObject object) {
addMapping(object, "child"); addMapping(object, "child");
} }
@ -1075,16 +1127,19 @@ public class Category extends ACSObject {
* categories and becomes a CHILD category.</p> * categories and becomes a CHILD category.</p>
* *
* @param category The related category * @param category The related category
*
* @pre canMap() * @pre canMap()
* *
**/ *
*/
public void addRelatedCategory(Category category) { public void addRelatedCategory(Category category) {
addMapping(category, RELATED); addMapping(category, RELATED);
} }
/** /**
* Add a preferred category, which marks the current category as a synonym. * Add a preferred category, which marks the current category as a synonym.
* When a synonym category is selected, preferred category should be used instead * When a synonym category is selected, preferred category should be used
* instead
* i.e. assigned to the item. * i.e. assigned to the item.
*/ */
public void addPreferredCategory(Category preferred) { public void addPreferredCategory(Category preferred) {
@ -1179,9 +1234,11 @@ public class Category extends ACSObject {
* is no longer a child of a category. This actually deletes the mapping. * is no longer a child of a category. This actually deletes the mapping.
* *
* @param acsObj the domain object to uncategorize * @param acsObj the domain object to uncategorize
*
* @pre canMap() * @pre canMap()
* @throws NullPointerException if <code>acsObj</code> is null * @throws NullPointerException if <code>acsObj</code> is null
**/ *
*/
public void removeChild(ACSObject acsObj) { public void removeChild(ACSObject acsObj) {
if (acsObj == null) { if (acsObj == null) {
throw new NullPointerException("acsObj"); throw new NullPointerException("acsObj");
@ -1198,7 +1255,8 @@ public class Category extends ACSObject {
* Removes the specified child category. * Removes the specified child category.
* *
* @throws NullPointerException if category is null * @throws NullPointerException if category is null
**/ *
*/
public void removeChild(Category category) { public void removeChild(Category category) {
Assert.exists(category, Category.class); Assert.exists(category, Category.class);
@ -1305,7 +1363,8 @@ public class Category extends ACSObject {
/** /**
* Determines whether the category has child objects. * Determines whether the category has child objects.
* *
* @return <code>true</code> if the category does not have any child objects; * @return <code>true</code> if the category does not have any child
* objects;
* <code>false</code> otherwise. * <code>false</code> otherwise.
*/ */
public boolean hasChildObjects() { public boolean hasChildObjects() {
@ -1361,6 +1420,7 @@ public class Category extends ACSObject {
* @param parent the category that will become the new * @param parent the category that will become the new
* default category. Pass in null to clear the current * default category. Pass in null to clear the current
* default parent. * default parent.
*
* @exception CategoryNotFoundException if the passed in category is * @exception CategoryNotFoundException if the passed in category is
* not a parent of this category. * not a parent of this category.
* *
@ -1647,7 +1707,9 @@ public class Category extends ACSObject {
* filter, if desired. * filter, if desired.
* *
* @param relation The type of relation to retrieve. * @param relation The type of relation to retrieve.
* @pre relation == Category.CHILD || relation == Category.RELATED || relation == Category.PREFERRED *
* @pre relation == Category.CHILD || relation == Category.RELATED ||
* relation == Category.PREFERRED
*/ */
public DataAssociationCursor getRelatedCategories(String relation) { public DataAssociationCursor getRelatedCategories(String relation) {
Assert.isTrue(relation.equals(CHILD) || relation.equals(RELATED) Assert.isTrue(relation.equals(CHILD) || relation.equals(RELATED)
@ -1677,7 +1739,8 @@ public class Category extends ACSObject {
* *
* @see #getDescendants() * @see #getDescendants()
* @throws NullPointerException if objectType is null * @throws NullPointerException if objectType is null
**/ *
*/
public CategoryCollection getChildren() { public CategoryCollection getChildren() {
return new CategoryCollection(getRelatedCategories(CHILD)); return new CategoryCollection(getRelatedCategories(CHILD));
} }
@ -1688,7 +1751,8 @@ public class Category extends ACSObject {
* *
* @see #getObjects(String, String) * @see #getObjects(String, String)
* @throws NullPointerException if objectType is null * @throws NullPointerException if objectType is null
**/ *
*/
public CategorizedCollection getObjects(String objectType) { public CategorizedCollection getObjects(String objectType) {
return getObjects(objectType, null); return getObjects(objectType, null);
} }
@ -1698,7 +1762,8 @@ public class Category extends ACSObject {
* *
* @param objectType the return collection will only contain objects of this * @param objectType the return collection will only contain objects of this
* type * type
* @param path the fragment of the PDL join path leading from the specified * @param path the fragment of the PDL join path leading from the
* specified
* object type to the <code>Category</code> object type. The common case * object type to the <code>Category</code> object type. The common case
* for CMS is to pass <code>"parent"</code> as the value of * for CMS is to pass <code>"parent"</code> as the value of
* <code>path</code>. The common scenario for many other applications is to * <code>path</code>. The common scenario for many other applications is to
@ -1708,7 +1773,8 @@ public class Category extends ACSObject {
* @pre objectType!=null && path!=null * @pre objectType!=null && path!=null
* @post return != null * @post return != null
* @throws NullPointerException if either parameter is null * @throws NullPointerException if either parameter is null
**/ *
*/
public CategorizedCollection getObjects(String objectType, String path) { public CategorizedCollection getObjects(String objectType, String path) {
if (objectType == null) { if (objectType == null) {
throw new NullPointerException("objectType"); throw new NullPointerException("objectType");
@ -1757,7 +1823,8 @@ public class Category extends ACSObject {
/** /**
* Returns the parent categories for this category (the categories under * Returns the parent categories for this category (the categories under
* which this category is categorized). * which this category is categorized).
**/ *
*/
public CategoryCollection getParents() { public CategoryCollection getParents() {
return new CategoryCollection(((DataAssociation) get(PARENTS)).cursor()); return new CategoryCollection(((DataAssociation) get(PARENTS)).cursor());
} }
@ -1793,8 +1860,10 @@ public class Category extends ACSObject {
* result. * result.
* *
* @param acsObject the item to search for * @param acsObject the item to search for
*
* @return <code>true</code> if the object appears mapped somewhere in * @return <code>true</code> if the object appears mapped somewhere in
* the subtree; <code>false</code> otherwise. * the subtree; <code>false</code> otherwise.
*
* @pre acsObject != null * @pre acsObject != null
*/ */
public boolean isMemberOfSubtree(ACSObject acsObject) { public boolean isMemberOfSubtree(ACSObject acsObject) {
@ -1918,8 +1987,10 @@ public class Category extends ACSObject {
* is the current category (hence the array will always have length >= * is the current category (hence the array will always have length >=
* 1). If the path is bad, this returns <code>null</code>. * 1). If the path is bad, this returns <code>null</code>.
* *
* This one may be patched to work with localized URLs. I didn't do it for now * This one may be patched to work with localized URLs. I didn't do it for
* because I don't know where it is called and if it's really needed to patch. * now
* because I don't know where it is called and if it's really needed to
* patch.
* Quasimodo * Quasimodo
* *
*/ */
@ -2004,7 +2075,8 @@ public class Category extends ACSObject {
/** /**
* Returns a collection of root categories to which this object is mapped. * Returns a collection of root categories to which this object is mapped.
**/ *
*/
public static RootCategoryCollection getRootCategories(ACSObject acsObj) { public static RootCategoryCollection getRootCategories(ACSObject acsObj) {
return new RootCategoryCollection(getRootCategoriesAssoc(acsObj)); return new RootCategoryCollection(getRootCategoriesAssoc(acsObj));
} }
@ -2012,7 +2084,8 @@ public class Category extends ACSObject {
/** /**
* Retrieves the root category associated with an object in the given use * Retrieves the root category associated with an object in the given use
* context. * context.
**/ *
*/
public static Category getRootForObject(ACSObject object, String context) { public static Category getRootForObject(ACSObject object, String context) {
DataCollection cats = getRootCategoriesAssoc(object); DataCollection cats = getRootCategoriesAssoc(object);
@ -2062,9 +2135,11 @@ public class Category extends ACSObject {
* *
* <p>If <em>acsObj</em> is already mapped to some other category in the * <p>If <em>acsObj</em> is already mapped to some other category in the
* specified use context, then the existing triple's category value is * specified use context, then the existing triple's category value is
* updated to <code>rootCat</code>. Otherwise, a new triple is added.</p> * updated to
* <code>rootCat</code>. Otherwise, a new triple is added.</p>
* *
* <p>In theory, <code>rootCat</code> should be a root category, i.e. it * <p>In theory,
* <code>rootCat</code> should be a root category, i.e. it
* should have no parents. This method does not check if this is indeed the * should have no parents. This method does not check if this is indeed the
* case.</p> * case.</p>
* *
@ -2116,16 +2191,19 @@ public class Category extends ACSObject {
} }
/** /**
* Calls {@link #clearRootForObject(ACSObject, String)} with the null context. * Calls {@link #clearRootForObject(ACSObject, String)} with the null
* context.
* *
* @see #clearRootForObject(ACSObject, String) * @see #clearRootForObject(ACSObject, String)
**/ *
*/
public static void clearRootForObject(ACSObject object) { public static void clearRootForObject(ACSObject object) {
clearRootForObject(object, null); clearRootForObject(object, null);
} }
/** /**
* Removes any root category associated with the object in the specified context. * Removes any root category associated with the object in the specified
* context.
* *
* @param object the object to remove the root category from * @param object the object to remove the root category from
*/ */