CCM NG: More classes refactored for CCM NG
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4224 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
407068e8a9
commit
172b99bb0a
|
|
@ -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 <a href="mailto:lutter@arsdigita.com">David Lutterkort</a>
|
||||
* @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);
|
||||
Long result = super.getSelectedKey(state);
|
||||
if (result == null) {
|
||||
result = getRootFolderID(s);
|
||||
setSelectedKey(s, result);
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -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 <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
* @author <a href="mailto:lutter@arsdigita.com">David Lutterkort</a>
|
||||
* @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<Category> 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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
@ -76,8 +81,7 @@ public class ContentItemManager {
|
|||
*
|
||||
* @param <T> 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 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
|
||||
|
|
@ -113,9 +117,8 @@ public class ContentItemManager {
|
|||
*
|
||||
* @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();
|
||||
|
|
@ -162,9 +165,9 @@ public class ContentItemManager {
|
|||
* @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 <T extends ContentItem> Optional<T> getLiveVersion(
|
||||
final ContentItem item,
|
||||
|
|
@ -195,10 +198,10 @@ public class ContentItemManager {
|
|||
* @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
|
||||
* 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
|
||||
* <b>never</b> return {@code null}.
|
||||
*/
|
||||
public <T extends ContentItem> T getDraftVersion(final ContentItem item,
|
||||
|
|
@ -206,4 +209,105 @@ public class ContentItemManager {
|
|||
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<Categorization> 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<String> 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<Category> getItemFolders(final ContentItem item) {
|
||||
final List<Categorization> result = item.getCategories().stream().
|
||||
filter(categorization -> CmsConstants.CATEGORIZATION_TYPE_FOLDER.
|
||||
equals(categorization.getType()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
final List<Category> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,11 +42,11 @@ public class CcmObjectSelectionModel<T extends CcmObject>
|
|||
private final SingleSelectionModel<Long> 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<T> model ) {
|
||||
|
|
@ -58,17 +58,48 @@ public class CcmObjectSelectionModel<T extends CcmObject>
|
|||
this(clazz, new LongParameter(parameterName));
|
||||
}
|
||||
|
||||
public CcmObjectSelectionModel(final String className,
|
||||
final String parameterName) {
|
||||
try {
|
||||
clazz = (Class<T>) Class.forName(className);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
model = new ParameterSingleSelectionModel(new LongParameter(
|
||||
parameterName));
|
||||
}
|
||||
|
||||
public CcmObjectSelectionModel(final Class<T> clazz,
|
||||
final LongParameter parameter) {
|
||||
this(clazz, new ParameterSingleSelectionModel<>(parameter));
|
||||
}
|
||||
|
||||
public CcmObjectSelectionModel(final String className,
|
||||
final LongParameter parameter) {
|
||||
try {
|
||||
clazz = (Class<T>) Class.forName(className);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
model = new ParameterSingleSelectionModel<>(parameter);
|
||||
}
|
||||
|
||||
public CcmObjectSelectionModel(final Class<T> clazz,
|
||||
final SingleSelectionModel<Long> model) {
|
||||
this.clazz = clazz;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public CcmObjectSelectionModel(final String className,
|
||||
final SingleSelectionModel<Long> model) {
|
||||
try {
|
||||
clazz = (Class<T>) Class.forName(className);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSelected(final PageState state) {
|
||||
return model.isSelected(state);
|
||||
|
|
|
|||
Loading…
Reference in New Issue