CCM NG: Current progress of the migration of the UI for ccm-cms

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4516 8810af33-2d31-482b-a856-94f89814c4df
jensp 2017-01-11 18:35:23 +00:00
parent 73af7b7a76
commit e1d81d005f
30 changed files with 2752 additions and 688 deletions

View File

@ -20,64 +20,59 @@ package com.arsdigita.cms.ui;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.CMS; import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentSection; import org.librecms.contentsection.ContentItem;
import com.arsdigita.cms.ContentType; import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentType;
import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.Template;
import com.arsdigita.cms.PageLocations; import com.arsdigita.cms.PageLocations;
import com.arsdigita.web.ParameterMap; import com.arsdigita.web.ParameterMap;
import com.arsdigita.web.URL; import com.arsdigita.web.URL;
import org.apache.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.List; import java.util.List;
/** /**
* <p>The context bar of the content section UI.</p> * <p>
* The context bar of the content section UI.</p>
* *
* @author Justin Ross &lt;jross@redhat.com&gt; * @author Justin Ross
* @version $Id: ContentItemContextBar.java 287 2005-02-22 00:29:02Z sskracic $ * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
class ContentItemContextBar extends ContentSectionContextBar { class ContentItemContextBar extends ContentSectionContextBar {
private static final Logger s_log = Logger.getLogger private final ItemSelectionModel itemSelectionModel;
(ContentItemContextBar.class);
private final ItemSelectionModel m_item; ContentItemContextBar(final ItemSelectionModel itemSelectionModel) {
ContentItemContextBar(final ItemSelectionModel item) {
super(); super();
m_item = item; this.itemSelectionModel = itemSelectionModel;
} }
@Override @Override
protected final List entries(final PageState state) { protected final List<Entry> entries(final PageState state) {
final List entries = super.entries(state); final List<Entry> entries = super.entries(state);
final ContentItem item = (ContentItem) m_item.getSelectedObject(state); final ContentItem item = itemSelectionModel.getSelectedObject(state);
final ContentSection section = CMS.getContext().getContentSection(); final ContentSection section = CMS.getContext().getContentSection();
boolean isTemplate =
item.getContentType().equals(ContentType.findByAssociatedObjectType(Template.BASE_DATA_OBJECT_TYPE));
final URL url = URL.there final URL url = URL.there(state.getRequest(),
(state.getRequest(), section.getPrimaryUrl() + "/"
section.getPath() + "/" + PageLocations.ITEM_PAGE, + PageLocations.ITEM_PAGE,
params(item)); params(item));
StringBuffer title = new StringBuffer(); final StringBuilder title = new StringBuilder();
if (isTemplate) {
title.append(localize("cms.ui.template"));
} else {
title.append(localize("cms.ui.content_item")); title.append(localize("cms.ui.content_item"));
}
title.append(": ") title.append(": ")
.append(item.getDisplayName()); .append(item.getDisplayName());
String language = item.getLanguage(); // final String language = item.getLanguage();
if (language != null) { // if (language != null) {
title.append(" (") // title.append(" (")
.append(language) // .append(language)
.append(")"); // .append(")");
} // }
entries.add(new Entry(title.toString(), url)); entries.add(new Entry(title.toString(), url));
@ -87,7 +82,7 @@ class ContentItemContextBar extends ContentSectionContextBar {
private static ParameterMap params(final ContentItem item) { private static ParameterMap params(final ContentItem item) {
final ParameterMap params = new ParameterMap(); final ParameterMap params = new ParameterMap();
params.setParameter(ContentItemPage.ITEM_ID, item.getID()); params.setParameter(ContentItemPage.ITEM_ID, item.getObjectId());
return params; return params;
} }
@ -95,4 +90,5 @@ class ContentItemContextBar extends ContentSectionContextBar {
private static String localize(final String key) { private static String localize(final String key) {
return (String) ContentSectionPage.globalize(key).localize(); return (String) ContentSectionPage.globalize(key).localize();
} }
} }

View File

@ -24,7 +24,6 @@ import com.arsdigita.cms.PageLocations;
import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.Folder;
import com.arsdigita.web.ParameterMap; import com.arsdigita.web.ParameterMap;
import com.arsdigita.web.URL; import com.arsdigita.web.URL;
@ -36,11 +35,6 @@ import java.util.List;
import java.util.Stack; import java.util.Stack;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.core.CcmObject;
import org.librecms.contentsection.ContentSectionManager;
import java.util.Optional;
/** /**
* The context bar of the content section UI. * The context bar of the content section UI.
@ -54,14 +48,14 @@ public class ContentSectionContextBar extends WorkspaceContextBar {
ContentSectionContextBar.class); ContentSectionContextBar.class);
@Override @Override
protected List entries(final PageState state) { protected List<Entry> entries(final PageState state) {
/* Include breadcrumb entries already set by content-center (i.e. the /* Include breadcrumb entries already set by content-center (i.e. the
* URL of the content center itself */ * URL of the content center itself */
final List entries = super.entries(state); final List<Entry> entries = super.entries(state);
final ContentSection section = CMS.getContext().getContentSection(); final ContentSection section = CMS.getContext().getContentSection();
final Stack folderEntryStack = new Stack(); final Stack<Entry> folderEntryStack = new Stack<>();
String currentFolderLabel = null; String currentFolderLabel = null;
ParameterMap params = new ParameterMap(); ParameterMap params = new ParameterMap();
boolean isTemplate = false; boolean isTemplate = false;

View File

@ -19,53 +19,57 @@
package com.arsdigita.cms.ui; package com.arsdigita.cms.ui;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.ContentCenter;
import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.toolbox.ui.ContextBar; import com.arsdigita.toolbox.ui.ContextBar;
import com.arsdigita.web.URL; import com.arsdigita.web.URL;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.web.ApplicationManager;
import org.libreccm.web.ApplicationRepository; import org.libreccm.web.ApplicationRepository;
import org.libreccm.web.ApplicationType;
import org.libreccm.web.CcmApplication; import org.libreccm.web.CcmApplication;
import org.librecms.CmsConstants; import org.librecms.CmsConstants;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* <p>The context bar of the content center UI.</p> * <p>
* The context bar of the content center UI.</p>
* *
* @author Justin Ross &lt;jross@redhat.com&gt; * @author Justin Ross
* @version $Id$ * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
// Made public (instead of unspecified) in 6.6.8 // Made public (instead of unspecified) in 6.6.8
public class WorkspaceContextBar extends ContextBar { public class WorkspaceContextBar extends ContextBar {
/** A logger instance, primarily to assist debugging . */ /**
private static final Logger s_log = Logger.getLogger * A logger instance, primarily to assist debugging .
(WorkspaceContextBar.class); */
private static final Logger LOGGER = LogManager.getLogger(
WorkspaceContextBar.class);
/** /**
* *
* @param state * @param state
*
* @return * @return
*/ */
@Override @Override
protected List entries(final PageState state) { protected List<Entry> entries(final PageState state) {
final List entries = super.entries(state); final List<Entry> entries = super.entries(state);
final String centerTitle = (String) new GlobalizedMessage("cms.ui.content_center", CmsConstants.CMS_BUNDLE).localize(); final String centerTitle = (String) new GlobalizedMessage(
"cms.ui.content_center", CmsConstants.CMS_BUNDLE).localize();
final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ApplicationRepository appRepo = cdiUtil.findBean(ApplicationRepository.class); final ApplicationRepository appRepo = cdiUtil.findBean(
final List<CcmApplication> apps = appRepo.findByType(CmsConstants.CONTENT_SECTION_APP_TYPE); ApplicationRepository.class);
final List<CcmApplication> apps = appRepo.findByType(
CmsConstants.CONTENT_SECTION_APP_TYPE);
final String centerPath = apps.get(0).getPrimaryUrl(); final String centerPath = apps.get(0).getPrimaryUrl();
if (s_log.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
s_log.debug("Got Url: " + centerPath); LOGGER.debug("Got Url: " + centerPath);
} }
final URL url = URL.there(state.getRequest(), centerPath); final URL url = URL.there(state.getRequest(), centerPath);

View File

@ -0,0 +1,367 @@
/*
* 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.item;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;
import com.arsdigita.bebop.PageState;
import org.libreccm.categorization.Category;
import com.arsdigita.cms.CMS;
import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentSection;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.dispatcher.CMSDispatcher;
import com.arsdigita.cms.dispatcher.ItemResolver;
import org.librecms.lifecycle.Lifecycle;
import com.arsdigita.cms.ui.CMSContainer;
import org.libreccm.security.User;
import com.arsdigita.toolbox.ui.FormatStandards;
import com.arsdigita.util.Assert;
import com.arsdigita.util.GraphSet;
import com.arsdigita.util.Graphs;
import com.arsdigita.util.UncheckedWrapperException;
import com.arsdigita.web.Web;
import org.libreccm.workflow.Task;
import org.libreccm.workflow.TaskComment;
import org.libreccm.workflow.Workflow;
import com.arsdigita.xml.Element;
import org.libreccm.auditing.CcmRevision;
import org.libreccm.categorization.CategoryManager;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.l10n.GlobalizationHelper;
import org.libreccm.security.Shiro;
import org.librecms.contentsection.ContentItemRepository;
import org.librecms.contentsection.ContentSectionManager;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.Locale;
import java.util.stream.Collectors;
/**
* This panel displays basic details about a content item such as attributes and
* associations.
*
* Container: {@link com.arsdigita.cms.ui.ContentItemPage}
*
* This panel uses an {@link com.arsdigita.cms.dispatcher.XMLGenerator} to
* convert content items into XML.
*
* @author Michael Pih
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class Summary extends CMSContainer {
private static final String SUMMARY = "itemAdminSummary";
private static final String RESTART_WORKFLOW = "restartWorkflow";
private final ItemSelectionModel itemSelectionModel;
public Summary(final ItemSelectionModel itemSelectionModel) {
super();
this.itemSelectionModel = itemSelectionModel;
}
/**
* Generate XML representation of an item summary.
*
* @param state The page state
* @param parent The parent DOM element
*
* @pre ( state != null )
* @pre ( parent != null )
*/
@Override
public void generateXML(PageState state, Element parent) {
if (isVisible(state)) {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final GlobalizationHelper globalizationHelper = cdiUtil.findBean(
GlobalizationHelper.class);
final Locale language = globalizationHelper.getNegotiatedLocale();
// Determine the item's environment
final ContentItem item = getContentItem(state);
final ContentSection section = getContentSection(state);
final Shiro shiro = cdiUtil.findBean(Shiro.class);
final User user = shiro.getUser();
// Setup xml element for item's properties
final Element itemElement = new Element("cms:itemSummary",
CMS.CMS_XML_NS);
// Determine item's name / url stub
itemElement.addAttribute("name", item.getDisplayName());
// obviously getName() here gets the 'semantically meaningful name'
// from database using class DataType. It is not localizable! And
// it is not really 'semantically meaningful'
final String objectType = item.getClass().getName();
// Quasimodo: ObjectType for summary
itemElement.addAttribute("objectType", objectType);
itemElement.addAttribute("description",
item.getDescription().getValue(language));
itemElement.addAttribute("title",
item.getTitle().getValue(language));
// subject category
final Element subjectCategoriesElement = new Element(
"cms:subjectCategories", CMS.CMS_XML_NS);
itemElement.addContent(subjectCategoriesElement);
// URL
final Element linkElement = new Element("cms:linkSummary",
CMS.CMS_XML_NS);
try {
linkElement.addAttribute(
"url",
String.format("%s/redirect?oid=%s",
Web.getWebappContextPath(),
URLEncoder.encode(item.getUuid(), "UTF-8")));
} catch (UnsupportedEncodingException ex) {
throw new UncheckedWrapperException(ex);
}
//"/redirect?oid=" + URLEncoder.encode(item.getDraftVersion().getOID().toString()));
// WORKFLOW
final Element workflowElement = new Element("cms:workflowSummary",
CMS.CMS_XML_NS);
final Workflow workflow = item.getWorkflow();
if (workflow == null) {
workflowElement.addAttribute("noWorkflow", "1");
} else {
workflowElement.addAttribute("name",
workflow.getName().getValue(
language));
final List<Task> tasks = workflow.getTasks();
final GraphSet graph = new GraphSet();
for (final Task task : tasks) {
final List<Task> dependsOn = task.getDependsOn();
final StringBuilder builder = new StringBuilder();
for (final Task dep : dependsOn) {
graph.addEdge(task, dep, null);
builder.append(dep.getLabel().getValue(language));
}
final int len = builder.length();
if (len >= 2) {
builder.setLength(len - 2);
} else {
graph.addNode(task);
}
}
final List<Task> taskList = new ArrayList<>();
outer:
while (graph.nodeCount() > 0) {
@SuppressWarnings("unchecked")
final List<Task> list = Graphs.getSinkNodes(graph);
for (final Task task : list) {
taskList.add(0, task);
graph.removeNode(task);
continue outer;
}
// break loop if no nodes removed
break;
}
for (final Task task : taskList) {
Element taskElement = new Element("cms:task",
CMS.CMS_XML_NS);
taskElement.addAttribute("name",
task.getLabel().getValue(language));
taskElement.addAttribute("state",
task.getTaskState().toString());
for (final TaskComment comment : task.getComments()) {
final Element commentElement = new Element(
"cms:taskComment", CMS.CMS_XML_NS);
final User author = comment.getAuthor();
final String authorName;
if (author == null) {
authorName = "Anonymous";
} else {
authorName = author.getName();
}
commentElement.addAttribute("author", authorName);
commentElement.addAttribute("comment",
comment.getComment());
taskElement.addContent(commentElement);
}
workflowElement.addContent(taskElement);
}
}
// Revision History (we are using to "transaction" for XML elememts
// here because this used by the old API and we don't want to brake
// the XSL.
final Element revisionsElement = new Element(
"cms:transactionSummary",
CMS.CMS_XML_NS);
final ContentItemRepository itemRepo = cdiUtil.findBean(
ContentItemRepository.class);
final List<CcmRevision> revisions = itemRepo.retrieveRevisions(
item, item.getObjectId());
if (revisions != null && !revisions.isEmpty()) {
revisionsElement.addAttribute(
"creationDate",
FormatStandards.formatDate(revisions.get(0)
.getRevisionDate()));
revisionsElement.addAttribute(
"lastModifiedDate",
FormatStandards
.formatDate(revisions.get(revisions.size() - 1)
.getRevisionDate()));
final ContentSectionManager sectionManager = cdiUtil.findBean(
ContentSectionManager.class);
final ItemResolver itemResolver = sectionManager
.getItemResolver(section);
for (final CcmRevision revision : revisions) {
final Element revisionElement = new Element(
"cms:transaction", CMS.CMS_XML_NS);
revisionElement.addAttribute(
"date",
FormatStandards.formatDate(revision.getRevisionDate()));
final String authorName;
if (revision.getUserName() == null
|| revision.getUserName().trim().isEmpty()) {
authorName = "Anonymous";
} else {
authorName = revision.getUserName();
}
revisionElement.addAttribute("author", authorName);
final String url = String.format(
"%s?revision=%d",
itemResolver.generateItemURL(
state,
item,
section,
CMSDispatcher.PREVIEW),
revision.getId());
revisionElement.addAttribute("url", url);
revisionsElement.addContent(revisionElement);
}
}
// CATEGORY
final Element categoriesElement = new Element(
"cms:categorySummary", CMS.CMS_XML_NS);
final List<Category> categories = item.getCategories().stream()
.map(categorization -> categorization.getCategory())
.collect(Collectors.toList());
final CategoryManager categoryManager = cdiUtil.findBean(
CategoryManager.class);
for (final Category category : categories) {
final Element categoryElement = new Element("cms:category",
CMS.CMS_XML_NS);
categoryElement.setText(categoryManager
.getCategoryPath(category));
categoriesElement.addContent(categoryElement);
}
// LIFECYCLE
final Element lifecycleElement = new Element("cms:lifecycleSummary",
CMS.CMS_XML_NS);
final Lifecycle lifecycle = item.getLifecycle();
if (lifecycle == null) {
lifecycleElement.addAttribute("noLifecycle", "1");
} else {
lifecycleElement.addAttribute(
"name",
lifecycle.getDefinition().getLabel().getValue(language));
lifecycleElement.addAttribute(
"startDate",
FormatStandards.formatDate(lifecycle.getStartDateTime()));
final Date endDate = lifecycle.getEndDateTime();
if (endDate == null) {
lifecycleElement.addAttribute("endDateString",
"last forever");
} else {
lifecycleElement.addAttribute(
"endDateString",
String.format("expire on %s",
FormatStandards.formatDate(endDate)));
lifecycleElement.addAttribute(
"endDate", FormatStandards.formatDate(endDate));
}
lifecycleElement.addAttribute(
"hasBegun", Boolean.toString(lifecycle.isStarted()));
lifecycleElement.addAttribute(
"hasEnded", Boolean.toString(lifecycle.isFinished()));
}
parent.addContent(itemElement);
parent.addContent(categoriesElement);
parent.addContent(linkElement);
parent.addContent(lifecycleElement);
parent.addContent(workflowElement);
parent.addContent(revisionsElement);
}
}
/**
* Fetch the selected content item.
*
* @param state The page state
*
* @return The selected item
*/
protected ContentItem getContentItem(final PageState state) {
final ContentItem item = itemSelectionModel.getSelectedObject(state);
Assert.exists(item);
return item;
}
/**
* Fetch the current content section.
*
* @param state The page state
*
* @return The content section
*/
protected ContentSection getContentSection(final PageState state) {
return CMS.getContext().getContentSection();
}
}

View File

@ -1,455 +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.item;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletException;
import com.arsdigita.bebop.PageState;
import com.arsdigita.categorization.Category;
import com.arsdigita.categorization.CategoryCollection;
import com.arsdigita.cms.CMS;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.ContentPage;
import com.arsdigita.cms.ContentSection;
import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.SecurityManager;
import com.arsdigita.cms.dispatcher.CMSDispatcher;
import com.arsdigita.cms.lifecycle.Lifecycle;
import com.arsdigita.cms.ui.CMSContainer;
import com.arsdigita.cms.util.SecurityConstants;
import com.arsdigita.cms.workflow.CMSEngine;
import com.arsdigita.cms.workflow.CMSTask;
import com.arsdigita.domain.DataObjectNotFoundException;
import com.arsdigita.domain.DomainServiceInterfaceExposer;
import com.arsdigita.kernel.ACSObject;
import com.arsdigita.kernel.User;
import com.arsdigita.kernel.permissions.PermissionDescriptor;
import com.arsdigita.kernel.permissions.PermissionService;
import com.arsdigita.kernel.permissions.PrivilegeDescriptor;
import com.arsdigita.persistence.Filter;
import com.arsdigita.toolbox.ui.FormatStandards;
import com.arsdigita.util.Assert;
import com.arsdigita.util.GraphSet;
import com.arsdigita.util.Graphs;
import com.arsdigita.util.UncheckedWrapperException;
import com.arsdigita.versioning.Transaction;
import com.arsdigita.versioning.TransactionCollection;
import com.arsdigita.versioning.Versions;
import com.arsdigita.web.RedirectSignal;
import com.arsdigita.web.Web;
import com.arsdigita.web.WebContext;
import com.arsdigita.workflow.simple.Engine;
import com.arsdigita.workflow.simple.Task;
import com.arsdigita.workflow.simple.TaskCollection;
import com.arsdigita.workflow.simple.TaskComment;
import com.arsdigita.workflow.simple.Workflow;
import com.arsdigita.workflow.simple.WorkflowTemplate;
import com.arsdigita.xml.Element;
import java.io.UnsupportedEncodingException;
/**
* <p>
* This panel displays basic details about a content item such as attributes and associations.</p>
*
* <p>
* Container: {@link com.arsdigita.cms.ui.ContentItemPage}
*
* <p>
* This panel uses an {@link com.arsdigita.cms.dispatcher.XMLGenerator} to convert content items
* into XML.</p>
*
* @author Michael Pih (pihman@arsdigita.com)
* @version $Id: Summary.java 1940 2009-05-29 07:15:05Z terry $
*/
public class Summary extends CMSContainer {
private static final String SUMMARY = "itemAdminSummary";
private static final String RESTART_WORKFLOW = "restartWorkflow";
private final ItemSelectionModel m_item;
public Summary(ItemSelectionModel m) {
super();
m_item = m;
}
/**
* Generate XML representation of an item summary.
*
* @param state The page state
* @param parent The parent DOM element
*
* @pre ( state != null )
* @pre ( parent != null )
*/
@Override
public void generateXML(PageState state, Element parent) {
if (isVisible(state)) {
// Determine the item's environment
ContentItem item = getContentItem(state);
ContentSection section = getContentSection(state);
User user = Web.getWebContext().getUser();
// Setup xml element for item's properties
Element itemElement = new Element("cms:itemSummary", CMS.CMS_XML_NS);
// Determine item's name / url stub
itemElement.addAttribute("name", item.getName());
// obviously getName() here gets the 'semantically meaningful name'
// from database using class DataType. It is not localizable! And
// it is not really 'semantically meaningful'
String objectType = item.getObjectType().getName();
// Quasimodo: ObjectType for summary
itemElement.addAttribute("objectType", objectType);
// NOT USED - CUSTOMIZED SUMMARY
// Take advantage of caching in the CMS Dispatcher.
// XMLGenerator xmlGenerator = section.getXMLGenerator();
// xmlGenerator.generateXML(state, parent, SUMMARY);
String descriptionAttribute = "";
if (objectType.equals("NewsItem") || objectType.equals("Article")) {
descriptionAttribute = "lead";
} else if (objectType.equals("FileStorageItem") || objectType.equals("Minutes")) {
descriptionAttribute = "description";
} else if (objectType.equals("Job")) {
descriptionAttribute = "jobDescription";
} else if (objectType.equals("MultiPartArticle") || objectType.equals("Agenda")
|| objectType.equals("PressRelease") || objectType.equals("Service")) {
descriptionAttribute = "summary";
}
if (!descriptionAttribute.equals("")) {
itemElement.addAttribute("description", (String) DomainServiceInterfaceExposer.get(
item, descriptionAttribute));
}
try {
ContentPage page = new ContentPage(item.getID());
itemElement.addAttribute("title", page.getTitle());
} catch (DataObjectNotFoundException ex) {
//
}
// subject category
Element subjectsElement = new Element("cms:subjectCategories", CMS.CMS_XML_NS);
itemElement.addContent(subjectsElement);
Category itemCategory = null;
Category subjectCategory = Category.getRootForObject(section, "subject");
if (subjectCategory != null) {
CategoryCollection categories = item.getCategoryCollection();
while (categories.next()) {
Category category = categories.getCategory();
CategoryCollection parents = category.getDefaultAscendants();
parents.addOrder(Category.DEFAULT_ANCESTORS);
if (parents.next()) {
Category parentCategory = parents.getCategory();
if (parentCategory.equals(subjectCategory)) {
Element subjectElement = new Element("cms:subjectCategory",
CMS.CMS_XML_NS);
subjectElement.addAttribute("name", category.getName());
subjectElement.setText(category.getPreferredQualifiedName(" -&gt; ",
true));
subjectsElement.addContent(subjectElement);
}
parents.close();
}
}
}
// URL
Element linkElement = new Element("cms:linkSummary", CMS.CMS_XML_NS);
try {
linkElement.addAttribute("url",
String.format("%s/redirect?oid=%s",
Web.getWebappContextPath(),
URLEncoder.encode(item.getDraftVersion()
.getOID()
.toString(), "utf-8")));
} catch (UnsupportedEncodingException ex) {
throw new UncheckedWrapperException(ex);
}
//"/redirect?oid=" + URLEncoder.encode(item.getDraftVersion().getOID().toString()));
// WORKFLOW
Element workflowElement = new Element("cms:workflowSummary", CMS.CMS_XML_NS);
Workflow workflow = Workflow.getObjectWorkflow(item);
SecurityManager sm = CMS.getContext().getSecurityManager();
if (canWorkflowBeExtended(user, item, workflow)) {
// control event for restarting workflow in edit mode
try {
state.setControlEvent(this, RESTART_WORKFLOW, item.getID().toString());
workflowElement.addAttribute("restartWorkflowURL", state.stateAsURL());
state.clearControlEvent();
} catch (java.io.IOException ex) {
//
}
}
if (workflow == null) {
workflowElement.addAttribute("noWorkflow", "1");
} else {
workflowElement.addAttribute("name", workflow.getDisplayName());
TaskCollection tc = workflow.getTaskCollection();
GraphSet g = new GraphSet();
while (tc.next()) {
Task t = tc.getTask();
final TaskCollection deps = t.getRequiredTasks();
final StringBuffer buffer = new StringBuffer();
while (deps.next()) {
Task dep = deps.getTask();
g.addEdge(t, dep, null);
buffer.append(dep.getLabel() + ", ");
}
final int len = buffer.length();
if (len >= 2) {
buffer.setLength(len - 2);
} else {
g.addNode(t);
}
deps.close();
}
List taskList = new ArrayList();
outer:
while (g.nodeCount() > 0) {
List l = Graphs.getSinkNodes(g);
for (Iterator it = l.iterator(); it.hasNext();) {
Task t = (Task) it.next();
taskList.add(0, t);
g.removeNode(t);
continue outer;
}
// break loop if no nodes removed
break;
}
Iterator tasks = taskList.iterator();
while (tasks.hasNext()) {
Task task = (Task) tasks.next();
Element taskElement = new Element("cms:task", CMS.CMS_XML_NS);
taskElement.addAttribute("name", task.getDisplayName());
taskElement.addAttribute("state", task.getStateString());
Iterator comments = task.getComments();
while (comments.hasNext()) {
TaskComment comment = (TaskComment) comments.next();
Element commentElement = new Element("cms:taskComment", CMS.CMS_XML_NS);
User author = comment.getUser();
String authorName = "Anonymous";
if (author != null) {
authorName = author.getDisplayName();
}
commentElement.addAttribute("author", authorName);
commentElement.addAttribute("comment", comment.getComment());
commentElement.addAttribute("date", FormatStandards.formatDate(comment
.getDate()));
taskElement.addContent(commentElement);
}
workflowElement.addContent(taskElement);
}
}
// REVISION HISTORY
Element transactionElement = new Element("cms:transactionSummary", CMS.CMS_XML_NS);
transactionElement.addAttribute("creationDate", FormatStandards.formatDate(item
.getCreationDate()));
transactionElement.addAttribute("lastModifiedDate", FormatStandards.formatDate(item
.getLastModifiedDate()));
TransactionCollection transactions = Versions.getTaggedTransactions(item.getOID());
while (transactions.next()) {
Transaction transaction = transactions.getTransaction();
Element element = new Element("cms:transaction", CMS.CMS_XML_NS);
element.addAttribute("date", FormatStandards.formatDate(transaction.getTimestamp()));
String authorName = "Anonymous";
User author = transaction.getUser();
if (author != null) {
authorName = author.getDisplayName();
}
element.addAttribute("author", authorName);
String url = section.getItemResolver().generateItemURL(state, item, section,
CMSDispatcher.PREVIEW)
+ "?transID=" + transaction.getID();
element.addAttribute("url", url);
transactionElement.addContent(element);
}
transactions.close();
// CATEGORY
Element categoryElement = new Element("cms:categorySummary", CMS.CMS_XML_NS);
CategoryCollection categories = item.getCategoryCollection();
while (categories.next()) {
Category category = categories.getCategory();
Element element = new Element("cms:category", CMS.CMS_XML_NS);
element.setText(category.getPreferredQualifiedName(" -&gt; ", true));
categoryElement.addContent(element);
}
categories.close();
// LIFECYCLE
Element lifecycleElement = new Element("cms:lifecycleSummary", CMS.CMS_XML_NS);
Lifecycle lifecycle = item.getLifecycle();
if (lifecycle == null) {
lifecycleElement.addAttribute("noLifecycle", "1");
} else {
lifecycleElement.addAttribute("name", lifecycle.getLabel());
lifecycleElement.addAttribute("startDate", FormatStandards.formatDate(lifecycle
.getStartDate()));
java.util.Date endDate = lifecycle.getEndDate();
if (endDate == null) {
lifecycleElement.addAttribute("endDateString", "last forever");
} else {
lifecycleElement.addAttribute("endDateString", "expire on " + FormatStandards
.formatDate(endDate));
lifecycleElement.addAttribute("endDate", FormatStandards.formatDate(endDate));
}
lifecycleElement.addAttribute("hasBegun", (new Boolean(lifecycle.hasBegun()))
.toString());
lifecycleElement.addAttribute("hasEnded", (new Boolean(lifecycle.hasEnded()))
.toString());
}
parent.addContent(itemElement);
parent.addContent(categoryElement);
parent.addContent(linkElement);
parent.addContent(lifecycleElement);
parent.addContent(workflowElement);
parent.addContent(transactionElement);
}
}
/**
* Fetch the selected content item.
*
* @param state The page state
*
* @return The selected item
*
* @pre ( state != null )
*/
protected ContentItem getContentItem(PageState state) {
ContentItem item = (ContentItem) m_item.getSelectedObject(state);
Assert.exists(item);
return item;
}
/**
* Fetch the current content section.
*
* @param state The page state
*
* @return The content section
*
* @pre ( state != null )
*/
protected ContentSection getContentSection(PageState state) {
ContentSection section = CMS.getContext().getContentSection();
return section;
}
public void respond(PageState state) throws ServletException {
String key = state.getControlEventName();
String value = state.getControlEventValue();
if (RESTART_WORKFLOW.equals(key)) {
User user = Web.getWebContext().getUser();
ContentItem item = getContentItem(state);
ContentSection section = item.getContentSection();
Workflow w = Workflow.getObjectWorkflow(item);
if (canWorkflowBeExtended(user, item, w)) {
WorkflowTemplate template = w.getWorkflowTemplate();
if (template != null) {
template.extendWorkflow(w);
w.save();
}
// lock the next task
Engine engine = Engine.getInstance(CMSEngine.CMS_ENGINE_TYPE);
Iterator i = engine.getEnabledTasks(user, w.getID()).iterator();
if (i.hasNext()) {
CMSTask task = (CMSTask) i.next();
if (!task.isLocked()) {
task.lock(user);
}
}
}
String redirectURL = Web.getConfig().getDispatcherServletPath() + item
.getContentSection().getPath() + "/admin/item.jsp?item_id=" + item.getID()
+ "&set_tab=1";
throw new RedirectSignal(redirectURL, true);
} else {
throw new ServletException("Unknown control event: " + key);
}
}
/*
* Checks if workflow can be extended
*/
protected boolean canWorkflowBeExtended(User user, ContentItem item, Workflow workflow) {
boolean canBeExtended = true;
if (workflow == null) {
canBeExtended = false;
} else if (!workflow.isFinished()) {
canBeExtended = false;
} else if (workflow.getWorkflowTemplate() == null) {
canBeExtended = false;
} else {
TaskCollection templates = item.getContentSection().getWorkflowTemplates();
Filter f = templates.addInSubqueryFilter("id",
"com.arsdigita.cms.getWorkflowTemplateUserFilter");
f.set("userId", Web.getWebContext().getUser().getID());
templates.addEqualsFilter(ACSObject.ID, workflow.getWorkflowTemplate().getID());
PrivilegeDescriptor pd = PrivilegeDescriptor.get(SecurityConstants.CMS_WORKFLOW_ADMIN);
PermissionDescriptor perm = new PermissionDescriptor(pd, item, user);
if (!(templates.next() || PermissionService.checkPermission(perm))) {
canBeExtended = false;
}
templates.close();
}
return canBeExtended;
}
}

View File

@ -24,12 +24,10 @@ import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.event.ActionEvent; import com.arsdigita.bebop.event.ActionEvent;
import com.arsdigita.bebop.event.ActionListener; import com.arsdigita.bebop.event.ActionListener;
import com.arsdigita.categorization.Category;
import com.arsdigita.categorization.CategoryCollection; import org.librecms.contentsection.ContentItem;
import com.arsdigita.cms.CMS; import org.librecms.lifecycle.Lifecycle;
import com.arsdigita.cms.CMSConfig;
import com.arsdigita.cms.ContentItem;
import com.arsdigita.cms.lifecycle.Lifecycle;
import com.arsdigita.cms.ui.BaseItemPane; import com.arsdigita.cms.ui.BaseItemPane;
import com.arsdigita.cms.ui.ContentItemPage; import com.arsdigita.cms.ui.ContentItemPage;
import com.arsdigita.cms.ui.item.ContentItemRequestLocal; import com.arsdigita.cms.ui.item.ContentItemRequestLocal;
@ -37,101 +35,110 @@ import com.arsdigita.toolbox.ui.LayoutPanel;
import com.arsdigita.web.RedirectSignal; import com.arsdigita.web.RedirectSignal;
import com.arsdigita.web.URL; import com.arsdigita.web.URL;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.security.PermissionChecker;
import org.librecms.contentsection.privileges.ItemPrivileges;
/** /**
* @author Michael Pih * @author Michael Pih
* @author Jack Chung * @author Jack Chung
* @author Justin Ross &lt;jross@redhat.com&gt; * @author Justin Ross &lt;jross@redhat.com&gt;
* @author Jens Pelzetter jens@jp-digital.de * @author <a href="mailto:jens.pelzetter@goolemail.com">Jens Pelzetter</a>
* @version $Id: ItemLifecycleAdminPane.java 1942 2009-05-29 07:53:23Z terry $
*/ */
public class ItemLifecycleAdminPane extends BaseItemPane { public class ItemLifecycleAdminPane extends BaseItemPane {
private static final Logger s_log = Logger.getLogger( private static final Logger LOGGER = LogManager.getLogger(
ItemLifecycleAdminPane.class); ItemLifecycleAdminPane.class);
private final ContentItemRequestLocal m_item; private final ContentItemRequestLocal selectedItem;
private final LifecycleRequestLocal m_lifecycle; private final LifecycleRequestLocal selectedLifecycle;
private final LayoutPanel m_introPane; private final LayoutPanel introPane;
private final LayoutPanel m_detailPane; private final LayoutPanel detailPane;
private final LayoutPanel m_selectPane; private final LayoutPanel selectPane;
private final LayoutPanel m_lockedPane; private final LayoutPanel lockedPane;
private final LayoutPanel m_errorPane; private final LayoutPanel errorPane;
private final LayoutPanel m_cantPublishPane; private final LayoutPanel cantPublishPane;
public ItemLifecycleAdminPane(final ContentItemRequestLocal item) { public ItemLifecycleAdminPane(final ContentItemRequestLocal selectedItem) {
m_item = item; this.selectedItem = selectedItem;
m_lifecycle = new ItemLifecycleRequestLocal(); selectedLifecycle = new ItemLifecycleRequestLocal();
m_introPane = new LayoutPanel(); introPane = new LayoutPanel();
add(m_introPane); add(introPane);
final Label message = new Label(gz("cms.ui.item.lifecycle.intro")); final Label message = new Label(gz("cms.ui.item.lifecycle.intro"));
m_introPane.setBody(message); introPane.setBody(message);
m_detailPane = new LayoutPanel(); detailPane = new LayoutPanel();
add(m_detailPane); add(detailPane);
final ItemLifecycleItemPane itemPane = final ItemLifecycleItemPane itemPane = new ItemLifecycleItemPane(
new ItemLifecycleItemPane(m_item, selectedItem, selectedLifecycle);
m_lifecycle); detailPane.setBody(itemPane);
m_detailPane.setBody(itemPane);
m_selectPane = new LayoutPanel(); selectPane = new LayoutPanel();
add(m_selectPane); add(selectPane);
final ItemLifecycleSelectForm selectForm = final ItemLifecycleSelectForm selectForm = new ItemLifecycleSelectForm(
new ItemLifecycleSelectForm(m_item); selectedItem);
m_selectPane.setBody(selectForm); selectPane.setBody(selectForm);
m_lockedPane = new LayoutPanel(); lockedPane = new LayoutPanel();
add(m_lockedPane); add(lockedPane);
final Label lockedMsg = new Label(gz( final Label lockedMsg = new Label(gz(
"cms.ui.item.lifecycle.publish_locked")); "cms.ui.item.lifecycle.publish_locked"));
m_lockedPane.setBody(lockedMsg); lockedPane.setBody(lockedMsg);
final ControlLink lockedUpdateLink = new ControlLink(new Label(gz( final ControlLink lockedUpdateLink = new ControlLink(new Label(gz(
"cms.ui.item.lifecycle.publish_locked.update"))); "cms.ui.item.lifecycle.publish_locked.update")));
lockedUpdateLink.addActionListener(new ActionListener() { lockedUpdateLink.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent event) { public void actionPerformed(final ActionEvent event) {
throw new RedirectSignal( throw new RedirectSignal(
URL.getDispatcherPath() URL.getDispatcherPath()
+ ContentItemPage.getItemURL( + ContentItemPage.getItemURL(
item.getContentItem(event.getPageState()), selectedItem.getContentItem(event.getPageState()),
ContentItemPage.PUBLISHING_TAB), ContentItemPage.PUBLISHING_TAB),
true); true);
} }
});
m_lockedPane.setBottom(lockedUpdateLink);
m_errorPane = new LayoutPanel(); });
add(m_errorPane); lockedPane.setBottom(lockedUpdateLink);
errorPane = new LayoutPanel();
add(errorPane);
final Label errorMsg = new Label(gz("cms.ui.lifecycle.publish.error")); final Label errorMsg = new Label(gz("cms.ui.lifecycle.publish.error"));
m_errorPane.setBody(errorMsg); errorPane.setBody(errorMsg);
m_cantPublishPane = new LayoutPanel(); cantPublishPane = new LayoutPanel();
add(m_cantPublishPane); add(cantPublishPane);
final Label cantPublish = new Label(gz("cms.ui.lifecycle.publish.not_possible_abstract_category")); final Label cantPublish = new Label(gz(
m_cantPublishPane.setBody(cantPublish); "cms.ui.lifecycle.publish.not_possible_abstract_category"));
cantPublishPane.setBody(cantPublish);
connect(selectForm, m_detailPane); connect(selectForm, detailPane);
} }
private class ItemLifecycleRequestLocal extends LifecycleRequestLocal { private class ItemLifecycleRequestLocal extends LifecycleRequestLocal {
@Override
protected final Object initialValue(final PageState state) { protected final Object initialValue(final PageState state) {
final ContentItem item = m_item.getContentItem(state); final ContentItem item = selectedItem.getContentItem(state);
final Lifecycle lifecycle = item.getLifecycle(); final Lifecycle lifecycle = item.getLifecycle();
s_log.debug("Returning lifecycle " + lifecycle); LOGGER.debug("Returning lifecycle " + lifecycle);
return lifecycle; return lifecycle;
} }
} }
@Override
public final void register(final Page page) { public final void register(final Page page) {
super.register(page); super.register(page);
@ -140,44 +147,50 @@ public class ItemLifecycleAdminPane extends BaseItemPane {
private class VisibilityListener implements ActionListener { private class VisibilityListener implements ActionListener {
public final void actionPerformed(final ActionEvent e) { @Override
s_log.debug("Determining which pane to show"); public final void actionPerformed(final ActionEvent event) {
LOGGER.debug("Determining which pane to show");
final PageState state = e.getPageState(); final PageState state = event.getPageState();
if (CMSConfig.getInstanceOf().getThreadedPublishing() // if (CMSConfig.getConfig().isThreadPublishing()
&& PublishLock.getInstance().isLocked(m_item.getContentItem( // && PublishLock.getInstance().isLocked(m_item.getContentItem(
state))) { // state))) {
if (PublishLock.getInstance().hasError(m_item.getContentItem( // if (PublishLock.getInstance().hasError(m_item.getContentItem(
state))) { // state))) {
push(state, m_errorPane); // push(state, m_errorPane);
} else { // } else {
push(state, m_lockedPane); // push(state, m_lockedPane);
state.getResponse().addIntHeader("Refresh", 5); // state.getResponse().addIntHeader("Refresh", 5);
} // }
} else if(isAssignedToAbstractCategory(m_item.getContentItem(state))) { // } else
push(state, m_cantPublishPane); if (isAssignedToAbstractCategory(selectedItem.getContentItem(state))) {
push(state, cantPublishPane);
} else { } else {
if (state.isVisibleOnPage(ItemLifecycleAdminPane.this)) { if (state.isVisibleOnPage(ItemLifecycleAdminPane.this)) {
if (m_lifecycle.getLifecycle(state) == null) { if (selectedLifecycle.getLifecycle(state) == null) {
if (hasPermission(state)) { if (hasPermission(state)) {
push(state, m_selectPane); push(state, selectPane);
} else { } else {
push(state, m_introPane); push(state, introPane);
} }
} else { } else {
push(state, m_detailPane); push(state, detailPane);
} }
} }
} }
} }
} }
private boolean hasPermission(final PageState state) { private boolean hasPermission(final PageState state) {
final ContentItem item = m_item.getContentItem(state); final ContentItem item = selectedItem.getContentItem(state);
return CMS.getContext().getSecurityManager().canAccess( final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
state.getRequest(), SCHEDULE_PUBLICATION, item); final PermissionChecker permissionChecker = cdiUtil.findBean(
PermissionChecker.class);
return permissionChecker.isPermitted(ItemPrivileges.PUBLISH, item);
} }
/** /**
@ -186,25 +199,19 @@ public class ItemLifecycleAdminPane extends BaseItemPane {
* A category is abstract if not items can assigned to it. * A category is abstract if not items can assigned to it.
* *
* @param item * @param item
* @return {@code true} if assigned to a abstract category, {@code false} if not. *
* @return {@code true} if assigned to a abstract category, {@code false} if
* not.
*/ */
private boolean isAssignedToAbstractCategory(final ContentItem item) { private boolean isAssignedToAbstractCategory(final ContentItem item) {
final CategoryCollection categories = item.getCategoryCollection(); final long count = item.getCategories().stream()
.filter(categorization -> {
return categorization.getCategory().isAbstractCategory();
})
.count();
boolean result = false; return count > 0;
Category category;
while(categories.next()) {
category = categories.getCategory();
if (category.isAbstract()) {
result = true;
break;
}
} }
categories.close();
return result;
}
} }

View File

@ -0,0 +1,31 @@
/*
* 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.lifecycle;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.RequestLocal;
import org.librecms.lifecycle.Lifecycle;
public abstract class LifecycleRequestLocal extends RequestLocal {
public final Lifecycle getLifecycle(final PageState state) {
return (Lifecycle) get(state);
}
}

View File

@ -20,16 +20,23 @@ package com.arsdigita.cms.ui.type;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
import com.arsdigita.cms.CMS; import com.arsdigita.cms.CMS;
import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.ContentType; import org.librecms.contentsection.ContentType;
import org.librecms.lifecycle.LifecycleDefinition; import org.librecms.lifecycle.LifecycleDefinition;
import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.kernel.KernelConfig; import com.arsdigita.kernel.KernelConfig;
import com.arsdigita.toolbox.ui.Property;
import com.arsdigita.toolbox.ui.PropertyList; import com.arsdigita.toolbox.ui.PropertyList;
import java.util.Locale; import java.util.Locale;
import org.libreccm.workflow.WorkflowTemplate; import org.libreccm.workflow.WorkflowTemplate;
import org.librecms.CmsConstants; import org.librecms.CmsConstants;
import java.util.List;
/** /**
* This component displays basic attributes of a content type * This component displays basic attributes of a content type
* including: * including:
@ -50,8 +57,8 @@ class ContentTypePropertyList extends PropertyList {
} }
@Override @Override
protected final java.util.List properties(final PageState state) { protected final List<Property> properties(final PageState state) {
final java.util.List props = super.properties(state); final List<Property> props = super.properties(state);
final ContentType type = m_type.getContentType(state); final ContentType type = m_type.getContentType(state);
final ContentSection section = final ContentSection section =
CMS.getContext().getContentSection(); CMS.getContext().getContentSection();

View File

@ -38,6 +38,7 @@ import org.librecms.workflow.CmsTask;
import org.libreccm.security.User; import org.libreccm.security.User;
import com.arsdigita.toolbox.ui.ActionGroup; import com.arsdigita.toolbox.ui.ActionGroup;
import com.arsdigita.toolbox.ui.Property;
import com.arsdigita.toolbox.ui.PropertyList; import com.arsdigita.toolbox.ui.PropertyList;
import com.arsdigita.toolbox.ui.Section; import com.arsdigita.toolbox.ui.Section;

View File

@ -39,6 +39,7 @@ import org.librecms.workflow.CmsTask;
import org.libreccm.security.User; import org.libreccm.security.User;
import com.arsdigita.toolbox.ui.ActionGroup; import com.arsdigita.toolbox.ui.ActionGroup;
import com.arsdigita.toolbox.ui.Property;
import com.arsdigita.toolbox.ui.PropertyList; import com.arsdigita.toolbox.ui.PropertyList;
import com.arsdigita.toolbox.ui.Section; import com.arsdigita.toolbox.ui.Section;
import com.arsdigita.util.LockableImpl; import com.arsdigita.util.LockableImpl;

View File

@ -60,6 +60,8 @@ public class CmsConstants {
public static final String ASSET_ID = "asset_id"; public static final String ASSET_ID = "asset_id";
public static final String IMAGE_ID = "image_id"; public static final String IMAGE_ID = "image_id";
public final static String SCHEDULE_PUBLICATION = "schedule_publication";
private CmsConstants() { private CmsConstants() {
//Nothing //Nothing
} }

View File

@ -24,24 +24,23 @@ import com.arsdigita.bebop.RequestLocal;
import com.arsdigita.web.URL; import com.arsdigita.web.URL;
import com.arsdigita.util.Assert; import com.arsdigita.util.Assert;
import com.arsdigita.xml.Element; import com.arsdigita.xml.Element;
import java.util.Iterator; import java.util.Iterator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.log4j.Logger;
/** /**
* <p>A context bar.</p> * <p>A context bar.</p>
* *
* @author Justin Ross &lt;jross@redhat.com&gt; * @author Justin Ross
* @version $Id$ * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
public abstract class ContextBar extends SimpleComponent { public abstract class ContextBar extends SimpleComponent {
private static final Logger s_log = Logger.getLogger(ContextBar.class); private static final RequestLocal ENTRIES = new RequestLocal() {
@Override
private static final RequestLocal s_entries = new RequestLocal() {
protected final Object initialValue(final PageState state) { protected final Object initialValue(final PageState state) {
return new ArrayList(); return new ArrayList<>();
} }
}; };
@ -49,17 +48,19 @@ public abstract class ContextBar extends SimpleComponent {
super(); super();
} }
protected List entries(final PageState state) { @SuppressWarnings("unchecked")
return (List) s_entries.get(state); protected List<Entry> entries(final PageState state) {
return (List<Entry>) ENTRIES.get(state);
} }
@Override
public final void generateXML(final PageState state, final Element parent) { public final void generateXML(final PageState state, final Element parent) {
if (isVisible(state)) { if (isVisible(state)) {
final Element nav = parent.newChildElement final Element nav = parent.newChildElement
("bebop:contextBar", BEBOP_XML_NS); ("bebop:contextBar", BEBOP_XML_NS);
for (Iterator iter = entries(state).iterator(); iter.hasNext(); ) { for (Iterator<Entry> iter = entries(state).iterator(); iter.hasNext(); ) {
((Entry) iter.next()).generateXML(state, nav); iter.next().generateXML(state, nav);
} }
} }
} }

View File

@ -0,0 +1,62 @@
/*
* Copyright (C) 2017 LibreCCM Foundation.
*
* 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., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package com.arsdigita.toolbox.ui;
import com.arsdigita.bebop.Component;
import com.arsdigita.bebop.PageState;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.Assert;
import com.arsdigita.xml.Element;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public final class Property {
private final String title;
private final String value;
public Property(final String title, final String value) {
super();
Assert.exists(title, "String title");
this.title = title;
this.value = value;
}
public Property(final GlobalizedMessage title, final String value) {
this(title.localize().toString(), value);
}
public Property(final GlobalizedMessage title, final GlobalizedMessage value) {
this(title.localize().toString(), value.localize().toString());
}
public Property(final String title, final GlobalizedMessage value) {
this(title, value.localize().toString());
}
public void generateXML(final PageState state, final Element parent) {
final Element elem = parent.newChildElement("bebop:property",
Component.BEBOP_XML_NS);
elem.addAttribute("title", title);
elem.addAttribute("value", value);
}
}

View File

@ -24,79 +24,45 @@ import com.arsdigita.bebop.RequestLocal;
import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.util.Assert; import com.arsdigita.util.Assert;
import com.arsdigita.xml.Element; import com.arsdigita.xml.Element;
import java.util.Iterator; import java.util.Iterator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.log4j.Logger;
/** /**
* <p>A context bar.</p>
* *
* @author Justin Ross &lt;jross@redhat.com&gt; * @author Justin Ross
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/ */
public abstract class PropertyList extends SimpleComponent { public abstract class PropertyList extends SimpleComponent {
private static final Logger s_log = Logger.getLogger(PropertyList.class); private static final RequestLocal PROPERTIES = new RequestLocal() {
private static final RequestLocal s_props = new RequestLocal() { @Override
protected final Object initialValue(final PageState state) { protected final Object initialValue(final PageState state) {
return new ArrayList(); return new ArrayList<>();
} }
}; };
public PropertyList() { public PropertyList() {
super(); super();
} }
protected List properties(final PageState state) { @SuppressWarnings("unchecked")
return (List) s_props.get(state); protected List<Property> properties(final PageState state) {
return (List<Property>) PROPERTIES.get(state);
} }
@Override
public final void generateXML(final PageState state, final Element parent) { public final void generateXML(final PageState state, final Element parent) {
if (isVisible(state)) { if (isVisible(state)) {
final Element nav = parent.newChildElement final Element nav = parent.newChildElement("bebop:propertyList",
("bebop:propertyList", BEBOP_XML_NS); BEBOP_XML_NS);
for (Iterator iter = properties(state).iterator(); properties(state).forEach(property -> property.generateXML(state,
iter.hasNext(); ) { nav));
((Property) iter.next()).generateXML(state, nav);
}
} }
} }
public static final class Property {
private final String m_title;
private final String m_value;
public Property(final String title, final String value) {
super();
Assert.exists(title, "String title");
m_title = title;
m_value = value;
}
public Property(final GlobalizedMessage title, final String value) {
this(title.localize().toString(), value);
}
public Property(final GlobalizedMessage title,
final GlobalizedMessage value) {
this(title.localize().toString(), value.localize().toString());
}
public Property(final String title, final GlobalizedMessage value) {
this(title, value.localize().toString());
}
public void generateXML(final PageState state,
final Element parent) {
final Element elem = parent.newChildElement
("bebop:property", BEBOP_XML_NS);
elem.addAttribute("title", m_title);
elem.addAttribute("value", m_value);
}
}
} }

View File

@ -25,7 +25,9 @@ import org.hibernate.envers.query.AuditQuery;
import org.libreccm.core.AbstractEntityRepository; import org.libreccm.core.AbstractEntityRepository;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
/** /**
* *
@ -82,6 +84,14 @@ public abstract class AbstractAuditedEntityRepository<K, T>
return auditReader.getRevisions(entity.getClass(), objectId); return auditReader.getRevisions(entity.getClass(), objectId);
} }
/**
* Retrieves the first revision of the given entity.
*
* @param entity The entity.
* @param objectId The primary key of the entity.
*
* @return The first revision of the entity.
*/
public CcmRevision retrieveFirstRevision(final T entity, public CcmRevision retrieveFirstRevision(final T entity,
final Long objectId) { final Long objectId) {
final List<Number> revisions = retrieveRevisionNumbersOfEntity( final List<Number> revisions = retrieveRevisionNumbersOfEntity(
@ -90,6 +100,33 @@ public abstract class AbstractAuditedEntityRepository<K, T>
return auditReader.findRevision(CcmRevision.class, revisions.get(0)); return auditReader.findRevision(CcmRevision.class, revisions.get(0));
} }
/**
* Retrieves all revisions of the given entity. The list of revisions is
* ordered from the oldest revision to the newest revision.
*
* @param entity The entity.
* @param objectId The primary key of the entity.
*
* @return A list of all revisions of the provided entity.
*/
public List<CcmRevision> retrieveRevisions(final T entity,
final Long objectId) {
final List<Number> revisionNumbers = retrieveRevisionNumbersOfEntity(
entity, objectId);
return revisionNumbers.stream()
.map(revisionNumber -> auditReader.findRevision(CcmRevision.class,
revisionNumber))
.collect(Collectors.toList());
}
/**
* Retrieves the current revision of an entity.
*
* @param entity The entity.
* @param objectId the primary key the entity.
* @return The most current revision of the entity.
*/
public CcmRevision retrieveCurrentRevision(final T entity, public CcmRevision retrieveCurrentRevision(final T entity,
final Long objectId) { final Long objectId) {
final List<Number> revisions = retrieveRevisionNumbersOfEntity( final List<Number> revisions = retrieveRevisionNumbersOfEntity(