diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/folder/FolderSelectionModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/folder/FolderSelectionModel.java
index 3bc6e12ac..804195576 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/folder/FolderSelectionModel.java
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/folder/FolderSelectionModel.java
@@ -18,47 +18,41 @@
*/
package com.arsdigita.cms.ui.folder;
-
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.cms.CMS;
-import com.arsdigita.cms.ItemSelectionModel;
+import com.arsdigita.ui.CcmObjectSelectionModel;
import org.apache.log4j.Category;
import org.librecms.contentsection.ContentSection;
-import java.math.BigDecimal;
/**
- * Keeps track of the selection of an item in a folder. The objects that
- * are selected by this model are all subclasses of {@link
+ * Keeps track of the selection of an item in a folder. The objects that are
+ * selected by this model are all subclasses of {@link
* com.arsdigita.cms.Folder}.
*
* @author David Lutterkort
* @version $Id$
*/
-public class FolderSelectionModel
- extends ItemSelectionModel {
+public class FolderSelectionModel extends CcmObjectSelectionModel {
public FolderSelectionModel(String name) {
- super(Category.class.getName(),
- Category.class.getName(),
- name);
+ super(Category.class.getName(), name);
}
public FolderSelectionModel(final SingleSelectionModel model) {
- super(Category.class.getName(),
- Category.class.getName(),
- model);
+ super(Category.class.getName(), model);
}
- public Object getSelectedKey(PageState s) {
+ @Override
+ public Long getSelectedKey(final PageState state) {
// FIXME: this code will go away once parameter models support init listeners
- Object result = super.getSelectedKey(s);
- if ( result == null ) {
- result = getRootFolderID(s);
- setSelectedKey(s, result);
+ Long result = super.getSelectedKey(state);
+ if (result == null) {
+ result = getRootFolderID(state);
+ setSelectedKey(state, result);
}
return result;
}
@@ -73,10 +67,10 @@ public class FolderSelectionModel
}
/**
- * Return the ID of the root folder. By default, this is the root folder
- * of the content section in which the current request is made. If this
- * model is to be used outside a content section, this method has to be
- * overriden appropriately.
+ * Return the ID of the root folder. By default, this is the root folder of
+ * the content section in which the current request is made. If this model
+ * is to be used outside a content section, this method has to be overriden
+ * appropriately.
*
* @param s represents the current request
* @return the ID of the root folder
@@ -90,8 +84,8 @@ public class FolderSelectionModel
}
/**
- * Return true, since this selection model will always have
- * a folder selected in it
+ * Return true, since this selection model will always have a folder
+ * selected in it
*/
public boolean isSelected(PageState s) {
return true;
diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/folder/ItemPath.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/folder/ItemPath.java
similarity index 54%
rename from ccm-cms/src/main/java/com/arsdigita/cms/ui/folder/ItemPath.java.off
rename to ccm-cms/src/main/java/com/arsdigita/cms/ui/folder/ItemPath.java
index 01057a6aa..83cbda1d3 100755
--- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/folder/ItemPath.java.off
+++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/folder/ItemPath.java
@@ -20,58 +20,67 @@ package com.arsdigita.cms.ui.folder;
import com.arsdigita.bebop.List;
import com.arsdigita.bebop.PageState;
-import com.arsdigita.cms.ContentItem;
-import com.arsdigita.cms.ItemCollection;
+import com.arsdigita.bebop.list.ListModel;
+import com.arsdigita.bebop.list.ListModelBuilder;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.util.LockableImpl;
+import org.libreccm.categorization.Category;
+import org.libreccm.cdi.utils.CdiUtil;
+import org.librecms.contentsection.ContentItem;
+import org.librecms.contentsection.ContentItemManager;
/**
- * Produce a list of the items starting from the selected item's root down
- * to the item itself.
+ * Produce a list of the items starting from the selected item's root down to
+ * the item itself.
*
+ * @author Jens Pelzetter
* @author David Lutterkort
- * @version $Id: ItemPath.java 1940 2009-05-29 07:15:05Z terry $
*/
public class ItemPath extends List {
public ItemPath(ItemSelectionModel folderSel) {
- super(new ListModelBuilder(folderSel));
+ super(new ItemPathListModelBuilder(folderSel));
setAttribute("type", "item-path");
setSelectionModel(folderSel);
}
- public static class ListModel
- implements com.arsdigita.bebop.list.ListModel {
- ItemCollection m_coll;
+ public static class ItemPathListModel implements ListModel {
- public ListModel(ContentItem i) {
- m_coll = i.getPathInfo(true);
+ private final java.util.List pathFolders;
+ private int index = -1;
+
+ public ItemPathListModel(final ContentItem item) {
+ pathFolders = CdiUtil.createCdiUtil().findBean(ContentItemManager.class).getItemFolders(item);
}
+ @Override
public boolean next() {
- return m_coll.next();
+ index++;
+ return index < pathFolders.size();
}
public Object getElement() {
- return m_coll.getName();
+ return pathFolders.get(index).getName();
}
public String getKey() {
- return m_coll.getID().toString();
+ return Long.toString(pathFolders.get(index).getObjectId());
}
}
- public static class ListModelBuilder extends LockableImpl
- implements com.arsdigita.bebop.list.ListModelBuilder {
+ public static class ItemPathListModelBuilder extends LockableImpl
+ implements ListModelBuilder {
ItemSelectionModel m_itemSel;
- public ListModelBuilder(ItemSelectionModel itemSel) {
+ public ItemPathListModelBuilder(ItemSelectionModel itemSel) {
m_itemSel = itemSel;
}
- public com.arsdigita.bebop.list.ListModel makeModel(List l, final PageState s) {
- return new ListModel((ContentItem) m_itemSel.getSelectedObject(s));
+ public com.arsdigita.bebop.list.ListModel makeModel(List l,
+ final PageState s) {
+ return new ItemPathListModel((ContentItem) m_itemSel.
+ getSelectedObject(s));
}
}
}
diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItem.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItem.java
index 403b22efa..8d06dc080 100644
--- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItem.java
+++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItem.java
@@ -265,7 +265,7 @@ public class ContentItem extends CcmObject implements Serializable,
if (result.isEmpty()) {
return Optional.empty();
} else {
- return Optional.of(result.get(0).getCategorizedObject());
+ return Optional.of(result.get(0).getCategory());
}
}
diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java
index 9e82d0f09..7dbfba6ce 100644
--- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java
+++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java
@@ -18,15 +18,20 @@
*/
package org.librecms.contentsection;
+import java.util.ArrayList;
+import java.util.Collections;
import org.libreccm.categorization.Category;
import org.libreccm.workflow.WorkflowTemplate;
import org.librecms.lifecycle.LifecycleDefinition;
import java.util.List;
import java.util.Optional;
+import java.util.stream.Collectors;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
+import org.libreccm.categorization.Categorization;
+import org.librecms.CmsConstants;
/**
*
@@ -46,19 +51,19 @@ public class ContentItemManager {
* {@link ContentSection#rootDocumentsFolder} of the provided content
* section. Otherwise an {@link IllegalArgumentException} is thrown.
*
- * @param The type of the content item.
- * @param name The name (URL stub) of the new content item.
+ * @param The type of the content item.
+ * @param name The name (URL stub) of the new content item.
* @param section The content section in which the item is generated.
- * @param folder The folder in which in the item is stored.
- * @param type The type of the new content item.
+ * @param folder The folder in which in the item is stored.
+ * @param type The type of the new content item.
*
* @return The new content item.
*/
public T createContentItem(
- final String name,
- final ContentSection section,
- final Category folder,
- final Class type) {
+ final String name,
+ final ContentSection section,
+ final Category folder,
+ final Class type) {
throw new UnsupportedOperationException();
}
@@ -74,24 +79,23 @@ public class ContentItemManager {
* {@link WorkflowTemplate} must be defined in the provided content section.
* Otherwise an {@link IllegalArgumentException} is thrown.
*
- * @param The type of the content item.
- * @param name The name (URL stub) of the new content item.
- * @param section The content section in which the item is
- * generated.
- * @param folder The folder in which in the item is stored.
+ * @param The type of the content item.
+ * @param name The name (URL stub) of the new content item.
+ * @param section The content section in which the item is generated.
+ * @param folder The folder in which in the item is stored.
* @param workflowTemplate
* @param lifecycleDefinition
- * @param type The type of the new content item.
+ * @param type The type of the new content item.
*
* @return The new content item.
*/
public T createContentItem(
- final String name,
- final ContentSection section,
- final Category folder,
- final WorkflowTemplate workflowTemplate,
- final LifecycleDefinition lifecycleDefinition,
- final Class type) {
+ final String name,
+ final ContentSection section,
+ final Category folder,
+ final WorkflowTemplate workflowTemplate,
+ final LifecycleDefinition lifecycleDefinition,
+ final Class type) {
throw new UnsupportedOperationException();
}
@@ -100,7 +104,7 @@ public class ContentItemManager {
* only moves the draft version of the item. The live version is moved after
* a the item is republished.
*
- * @param item The item to move.
+ * @param item The item to move.
* @param targetFolder The folder to which the item is moved.
*/
public void move(final ContentItem item, final Category targetFolder) {
@@ -111,11 +115,10 @@ public class ContentItemManager {
* Creates an copy of the draft version of the item in the provided
* {@code targetFolder}.
*
- * @param item The item to copy.
+ * @param item The item to copy.
* @param targetFolder The folder in which the copy is created. If the
- * target folder is the same folder as the folder of the
- * original item an index is appended to the name of the
- * item.
+ * target folder is the same folder as the folder of the original item an
+ * index is appended to the name of the item.
*/
public void copy(final ContentItem item, final Category targetFolder) {
throw new UnsupportedOperationException();
@@ -148,7 +151,7 @@ public class ContentItemManager {
* @param item The item
*
* @return {@code true} if the content item has a live version,
- * {@code false} if not.
+ * {@code false} if not.
*/
public boolean isLive(final ContentItem item) {
throw new UnsupportedOperationException();
@@ -157,53 +160,154 @@ public class ContentItemManager {
/**
* Retrieves the live version of the provided content item if any.
*
- * @param Type of the content item.
+ * @param Type of the content item.
* @param item The item of which the live version should be retrieved.
* @param type Type of the content item.
*
* @return The live version of an item. If the item provided is already the
- * live version the provided item is returned, otherwise the live
- * version is returned. If there is no live version an empty
- * {@link Optional} is returned.
+ * live version the provided item is returned, otherwise the live version is
+ * returned. If there is no live version an empty {@link Optional} is
+ * returned.
*/
public Optional getLiveVersion(
- final ContentItem item,
- final Class type) {
+ final ContentItem item,
+ final Class type) {
throw new UnsupportedOperationException();
}
/**
* Retrieves the pending versions of an item if there are any.
*
- * @param Type of the content item to retrieve.
+ * @param Type of the content item to retrieve.
* @param item The item of which the pending versions are retrieved.
* @param type Type of the content item to retrieve.
*
* @return A list of the pending versions of the item.
*/
public List getPendingVersions(
- final ContentItem item,
- final Class type) {
+ final ContentItem item,
+ final Class type) {
throw new UnsupportedOperationException();
}
/**
* Retrieves the draft version
*
- * @param Type of the item.
+ * @param Type of the item.
* @param item The item of which the draft version is retrieved.
* @param type Type of the item.
*
* @return The draft version of the provided content item. If the provided
- * item is the draft version the provided item is simply returned.
- * Otherwise the draft version is retrieved from the database and is
- * returned. Each content item has a draft version (otherwise
- * something is seriously wrong with the database) this method will
- * never return {@code null}.
+ * item is the draft version the provided item is simply returned. Otherwise
+ * the draft version is retrieved from the database and is returned. Each
+ * content item has a draft version (otherwise something is seriously wrong
+ * with the database) this method will
+ * never return {@code null}.
*/
public T getDraftVersion(final ContentItem item,
final Class type) {
throw new UnsupportedOperationException();
}
+ /**
+ * Return the path of an as String. The path of an item is the path of the
+ * folder category the item is a member of concatenated with the name of the
+ * item. The path is relative to the content section. For instance, the path
+ * of an item in the folder category
+ * {@code /research/computer-science/artifical-intelligence} and with the
+ * name {@code neural-nets} has the path
+ * {@code /research/computer-science/artificial-intelligence/neural-nets}.
+ *
+ * @param item The item which path is generated.
+ * @return The path of the content item
+ * @see #getItemPath(org.librecms.contentsection.ContentItem, boolean)
+ */
+ public String getItemPath(final ContentItem item) {
+ return getItemPath(item, false);
+ }
+
+ /**
+ * Return the path of an as String. The path of an item is the path of the
+ * folder category the item is a member of concatenated with the name of the
+ * item. The path is relative to the content section. For instance, the path
+ * of an item in the folder category
+ * {@code /research/computer-science/artifical-intelligence} and with the
+ * name {@code neural-nets} has the path
+ * {@code /research/computer-science/artificial-intelligence/neural-nets}.
+ * If the parameter {@code withContentSection} is set to {@code true} the
+ * the path will be prefixed with the name of the content section. For
+ * instance if the item {@link neural-nets} is part of the content section
+ * {@code info}, the path including the content section would be
+ * {@link info:/research/computer-science/artificial-intelligence/neural-nets}.
+ *
+ * @param item The item which path is generated.
+ * @param withContentSection Wether to include the content section into the
+ * path.
+ * @return The path of the content item
+ * @see #getItemPath(org.librecms.contentsection.ContentItem, boolean)
+ */
+ public String getItemPath(final ContentItem item,
+ final boolean withContentSection) {
+ final List result = item.getCategories().stream().
+ filter(categorization -> CmsConstants.CATEGORIZATION_TYPE_FOLDER.
+ equals(categorization.getType()))
+ .collect(Collectors.toList());
+
+ if (result.isEmpty()) {
+ return item.getDisplayName();
+ } else {
+ final List tokens = new ArrayList<>();
+ tokens.add(item.getDisplayName());
+
+ Category current = result.get(0).getCategory();
+ tokens.add(current.getName());
+
+ while (current.getParentCategory() != null) {
+ current = current.getParentCategory();
+ tokens.add(current.getName());
+ }
+
+ Collections.reverse(result);
+ final String path = String.join("/", tokens);
+
+ if (withContentSection) {
+ final String sectionName = item.getContentType().
+ getContentSection().getDisplayName();
+ return String.format(
+ "%s/%s", sectionName, path);
+ } else {
+ return String.format("/%s", path);
+ }
+ }
+ }
+
+ /**
+ * Creates as list of the folders in which is item is placed.
+ *
+ * @param item
+ * @return
+ */
+ public List getItemFolders(final ContentItem item) {
+ final List result = item.getCategories().stream().
+ filter(categorization -> CmsConstants.CATEGORIZATION_TYPE_FOLDER.
+ equals(categorization.getType()))
+ .collect(Collectors.toList());
+
+ final List folders = new ArrayList<>();
+ if (!result.isEmpty()) {
+ Category current = result.get(0).getCategory();
+ folders.add(current);
+
+ while(current.getParentCategory()!= null) {
+ current = current.getParentCategory();
+ folders.add(current);
+ }
+
+ Collections.reverse(folders);
+ return folders;
+ }
+
+ return folders;
+ }
+
}
diff --git a/ccm-core/src/main/java/com/arsdigita/ui/CcmObjectSelectionModel.java b/ccm-core/src/main/java/com/arsdigita/ui/CcmObjectSelectionModel.java
index 1c5bdd2c7..6078cf9f6 100644
--- a/ccm-core/src/main/java/com/arsdigita/ui/CcmObjectSelectionModel.java
+++ b/ccm-core/src/main/java/com/arsdigita/ui/CcmObjectSelectionModel.java
@@ -36,17 +36,17 @@ import org.libreccm.core.CcmObjectRepository;
*
*/
public class CcmObjectSelectionModel
- implements SingleSelectionModel {
+ implements SingleSelectionModel {
private final Class clazz;
private final SingleSelectionModel model;
public CcmObjectSelectionModel(final LongParameter parameter) {
- this(null, parameter);
+ this("", parameter);
}
public CcmObjectSelectionModel(final String parameterName) {
- this(null, new LongParameter(parameterName));
+ this("", new LongParameter(parameterName));
}
// public CcmObjectSelectionModel(final SingleSelectionModel model ) {
@@ -58,17 +58,48 @@ public class CcmObjectSelectionModel
this(clazz, new LongParameter(parameterName));
}
+ public CcmObjectSelectionModel(final String className,
+ final String parameterName) {
+ try {
+ clazz = (Class) Class.forName(className);
+ } catch (ClassNotFoundException ex) {
+ throw new RuntimeException(ex);
+ }
+ model = new ParameterSingleSelectionModel(new LongParameter(
+ parameterName));
+ }
+
public CcmObjectSelectionModel(final Class clazz,
final LongParameter parameter) {
this(clazz, new ParameterSingleSelectionModel<>(parameter));
}
+ public CcmObjectSelectionModel(final String className,
+ final LongParameter parameter) {
+ try {
+ clazz = (Class) Class.forName(className);
+ } catch (ClassNotFoundException ex) {
+ throw new RuntimeException(ex);
+ }
+ model = new ParameterSingleSelectionModel<>(parameter);
+ }
+
public CcmObjectSelectionModel(final Class clazz,
final SingleSelectionModel model) {
this.clazz = clazz;
this.model = model;
}
+ public CcmObjectSelectionModel(final String className,
+ final SingleSelectionModel model) {
+ try {
+ clazz = (Class) Class.forName(className);
+ } catch (ClassNotFoundException ex) {
+ throw new RuntimeException(ex);
+ }
+ this.model = model;
+ }
+
@Override
public boolean isSelected(final PageState state) {
return model.isSelected(state);
@@ -87,7 +118,7 @@ public class CcmObjectSelectionModel
public T getSelectedObject(final PageState state) {
final Long key = getSelectedKey(state);
final CcmObjectRepository repository = CdiUtil.createCdiUtil().findBean(
- CcmObjectRepository.class);
+ CcmObjectRepository.class);
@SuppressWarnings("unchecked")
final T object = (T) repository.findById(key);
return object;