Removed depcrecated package com.arsdigita.cms.ui.item and several other depcrecated classes
parent
0da48fc6d6
commit
0ca8ef950e
|
|
@ -33,7 +33,6 @@ import com.arsdigita.bebop.parameters.NotEmptyValidationListener;
|
|||
import com.arsdigita.bebop.parameters.NotNullValidationListener;
|
||||
import com.arsdigita.bebop.parameters.StringLengthValidationListener;
|
||||
import com.arsdigita.bebop.parameters.TrimmedStringParameter;
|
||||
import com.arsdigita.cms.ui.item.ContentItemRequestLocal;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.toolbox.ui.Cancellable;
|
||||
import com.arsdigita.toolbox.ui.Section;
|
||||
|
|
|
|||
|
|
@ -41,10 +41,6 @@ import com.arsdigita.cms.ItemSelectionModel;
|
|||
import com.arsdigita.cms.PageLocations;
|
||||
import com.arsdigita.cms.dispatcher.CMSPage;
|
||||
import com.arsdigita.cms.ui.authoring.WizardSelector;
|
||||
import com.arsdigita.cms.ui.item.ContentItemRequestLocal;
|
||||
import com.arsdigita.cms.ui.item.CustomizedPreviewLink;
|
||||
import com.arsdigita.cms.ui.item.ItemLanguages;
|
||||
import com.arsdigita.cms.ui.item.Summary;
|
||||
import com.arsdigita.cms.ui.workflow.ItemWorkflowAdminPane;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.kernel.KernelConfig;
|
||||
|
|
@ -162,14 +158,10 @@ public class ContentItemPage extends CMSPage implements ActionListener {
|
|||
|
||||
private final ContentItemRequestLocal itemRequestLocal;
|
||||
|
||||
private final Summary summaryPane;
|
||||
|
||||
private final ItemWorkflowAdminPane workflowPane;
|
||||
|
||||
private final WizardSelector wizardPane;
|
||||
|
||||
private final ItemLanguages languagesPane;
|
||||
|
||||
private final Link previewLink;
|
||||
|
||||
private final GlobalNavigation globalNavigation;
|
||||
|
|
@ -285,11 +277,7 @@ public class ContentItemPage extends CMSPage implements ActionListener {
|
|||
add(globalNavigation);
|
||||
|
||||
// Create panels.
|
||||
summaryPane = new Summary(itemSelectionModel);
|
||||
wizardPane = new WizardSelector(itemSelectionModel, typeSelectionModel);
|
||||
languagesPane = new ItemLanguages(itemSelectionModel,
|
||||
// selectedLanguageModel,
|
||||
selectedLanguageParam);
|
||||
workflowPane = new ItemWorkflowAdminPane(itemId); // Make this use m_item XXX
|
||||
|
||||
// Create tabbed pane.
|
||||
|
|
@ -298,11 +286,9 @@ public class ContentItemPage extends CMSPage implements ActionListener {
|
|||
|
||||
tabbedPane.setIdAttr("page-body");
|
||||
|
||||
tabbedPane.addTab(new Label(gz("cms.ui.item.summary")), summaryPane);
|
||||
tabbedPane.
|
||||
addTab(new Label(gz("cms.ui.item.authoring")), wizardPane);
|
||||
tabbedPane.addTab(new Label(gz("cms.ui.item.languages")),
|
||||
languagesPane);
|
||||
|
||||
tabbedPane.addTab(new Label(gz("cms.ui.item.workflow")),
|
||||
workflowPane);
|
||||
|
||||
|
|
@ -603,20 +589,8 @@ public class ContentItemPage extends CMSPage implements ActionListener {
|
|||
* Fetch the preview URL.
|
||||
*/
|
||||
private String getPreviewURL(final PageState state) {
|
||||
final ContentItem item = itemRequestLocal.getContentItem(state);
|
||||
|
||||
if (item instanceof CustomizedPreviewLink) {
|
||||
final String previewLink = ((CustomizedPreviewLink) item).
|
||||
getPreviewUrl(
|
||||
state);
|
||||
if ((previewLink == null) || previewLink.isEmpty()) {
|
||||
return getDefaultPreviewLink(state, item);
|
||||
} else {
|
||||
return previewLink;
|
||||
}
|
||||
} else {
|
||||
return getDefaultPreviewLink(state, item);
|
||||
}
|
||||
final ContentItem item = itemRequestLocal.getContentItem(state);
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
package com.arsdigita.cms.ui.item;
|
||||
package com.arsdigita.cms.ui;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.RequestLocal;
|
||||
|
|
@ -25,7 +25,6 @@ import com.arsdigita.bebop.event.FormSubmissionListener;
|
|||
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
|
||||
import com.arsdigita.cms.ui.item.ContentItemRequestLocal;
|
||||
import com.arsdigita.dispatcher.AccessDeniedException;
|
||||
|
||||
import com.arsdigita.util.Assert;
|
||||
|
|
|
|||
|
|
@ -1,296 +0,0 @@
|
|||
/*
|
||||
* 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.authoring;
|
||||
|
||||
import com.arsdigita.bebop.ColumnPanel;
|
||||
import com.arsdigita.bebop.Container;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.FormSection;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.event.FormInitListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.event.ParameterEvent;
|
||||
import com.arsdigita.bebop.form.RadioGroup;
|
||||
import com.arsdigita.bebop.parameters.LongParameter;
|
||||
import com.arsdigita.bebop.parameters.NotNullValidationListener;
|
||||
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentType;
|
||||
import org.librecms.contentsection.Folder;
|
||||
|
||||
import com.arsdigita.cms.ui.workflow.WorkflowsOptionPrintListener;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
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.libreccm.workflow.Workflow;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.contentsection.privileges.ItemPrivileges;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.TooManyListenersException;
|
||||
|
||||
/**
|
||||
* A FormSection which will allow users with
|
||||
* SecrityConstants.APPLY_ALTERNATE_WORFLOWS permission to choose a different
|
||||
* workflow to apply to a new item.
|
||||
*
|
||||
* @author Stanislav Freidin (stas@arsdigita.com)
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ApplyWorkflowFormSection
|
||||
extends FormSection
|
||||
implements FormInitListener {
|
||||
|
||||
private static final Logger LOGGER = LogManager
|
||||
.getLogger(ApplyWorkflowFormSection.class);
|
||||
|
||||
private RadioGroup radioGroup;
|
||||
private CreationSelector creationSelector;
|
||||
private ContentType contentType;
|
||||
private ApplyWorkflowPrintListener printListener;
|
||||
|
||||
/**
|
||||
* Construct a new ApplyWorkflowFormSection
|
||||
*/
|
||||
public ApplyWorkflowFormSection() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new ApplyWorkflowFormSection
|
||||
*
|
||||
* @param type
|
||||
*/
|
||||
public ApplyWorkflowFormSection(final ContentType type) {
|
||||
this(type, new ColumnPanel(2, true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new ApplyWorkflowFormSection
|
||||
*
|
||||
* @param type
|
||||
* @param panel Container to use for this FormSection
|
||||
*/
|
||||
public ApplyWorkflowFormSection(final ContentType type,
|
||||
final Container panel) {
|
||||
super(panel);
|
||||
|
||||
radioGroup = new RadioGroup(new LongParameter("workflowSelect"));
|
||||
radioGroup.setClassAttr("vertical");
|
||||
contentType = type;
|
||||
printListener = new ApplyWorkflowPrintListener();
|
||||
|
||||
try {
|
||||
// should we filter on WorkflowDefinitions where this user
|
||||
// is assigned to at least one initial task, or should we
|
||||
// assume that users with "alternate workflow" permission
|
||||
// are advanced enough to know what they're doing?
|
||||
radioGroup.addPrintListener(printListener);
|
||||
} catch (TooManyListenersException ex) {
|
||||
LOGGER.error("Too many listeners", ex);
|
||||
}
|
||||
|
||||
super.add(new Label(new GlobalizedMessage("cms.ui.authoring.workflow",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
radioGroup.addValidationListener(new NotNullValidationListener() {
|
||||
|
||||
@Override
|
||||
public void validate(final ParameterEvent event) {
|
||||
final PageState state = event.getPageState();
|
||||
if (!ApplyWorkflowFormSection.this.isVisible(state)) {
|
||||
return;
|
||||
}
|
||||
super.validate(event);
|
||||
}
|
||||
|
||||
});
|
||||
super.add(radioGroup);
|
||||
super.addInitListener(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises the workflow selection widget to the default workflow for the
|
||||
* content type.
|
||||
*
|
||||
* @param event
|
||||
*
|
||||
* @throws com.arsdigita.bebop.FormProcessException
|
||||
*/
|
||||
@Override
|
||||
public void init(final FormSectionEvent event) throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ApplyWorkflowController controller = cdiUtil
|
||||
.findBean(ApplyWorkflowController.class);
|
||||
final Long workflowTemplateId = controller
|
||||
.getDefaultWorkflowId(contentType);
|
||||
if (workflowTemplateId != null) {
|
||||
radioGroup.setValue(state, workflowTemplateId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the CreationSelector which should be the same as that of the
|
||||
* creation component. This cannot be set in the constructor since for most
|
||||
* creation components, addWidgets() is called via the superclass
|
||||
* constructor, so this member will not yet be set.
|
||||
*
|
||||
* @param creationSelector CreationSelector to use for this FormSection
|
||||
*/
|
||||
public void setCreationSelector(final CreationSelector creationSelector) {
|
||||
this.creationSelector = creationSelector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the ContentType for the creation component.
|
||||
*
|
||||
* @param contentType ContentType to use for this FormSection
|
||||
*/
|
||||
public void setContentType(final ContentType contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not this component is visible. The additional visibility
|
||||
* requirement is that the user must have the
|
||||
* SecurityConstants.APPLY_ALTERNATE_WORKFLOWS privilege on the parent
|
||||
* folder.
|
||||
*
|
||||
* @param state The PageState
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean isVisible(final PageState state) {
|
||||
boolean result = false;
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final PermissionChecker permissionChecker = cdiUtil
|
||||
.findBean(PermissionChecker.class);
|
||||
|
||||
if (super.isVisible(state)
|
||||
&& permissionChecker
|
||||
.isPermitted(ItemPrivileges.APPLY_ALTERNATE_WORKFLOW,
|
||||
creationSelector.getFolder(state))) {
|
||||
|
||||
return !printListener.getCollection(state).isEmpty();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public Long getSelectedWorkflowTemplateId(final PageState state) {
|
||||
return (Long) radioGroup.getValue(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the proper initial workflow to the item. If the user has
|
||||
* SecurityConstants.APPLY_ALTERNATE_WORKFLOWS permission on the parent
|
||||
* folder <em>and</em> a workflow has been chosen, use this workflow.
|
||||
* Otherwise use the default workflow for the content type.
|
||||
*
|
||||
* @param state The PageState
|
||||
* @param item The new ContentItem
|
||||
*/
|
||||
public void applyWorkflow(final PageState state, final ContentItem item) {
|
||||
|
||||
final Long workflowTemplateId = (Long) radioGroup.getValue(state);
|
||||
final Folder folder = creationSelector.getFolder(state);
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ApplyWorkflowController controller = cdiUtil
|
||||
.findBean(ApplyWorkflowController.class);
|
||||
|
||||
if (workflowTemplateId != null) {
|
||||
controller.applyWorkflow(item, folder, workflowTemplateId);
|
||||
}
|
||||
|
||||
// final WorkflowTemplate template;
|
||||
//
|
||||
// final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
// final PermissionChecker permissionChecker = cdiUtil
|
||||
// .findBean(PermissionChecker.class);
|
||||
// final WorkflowTemplateRepository templateRepo = cdiUtil
|
||||
// .findBean(WorkflowTemplateRepository.class);
|
||||
//
|
||||
// if (flowId != null
|
||||
// && permissionChecker.isPermitted(
|
||||
// ItemPrivileges.APPLY_ALTERNATE_WORKFLOW, folder)) {
|
||||
// template = templateRepo
|
||||
// .findById(flowId)
|
||||
// .orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
// "No WorkflowTemplate with ID %d in database. "
|
||||
// + "Where did that ID come from?")));
|
||||
// } else {
|
||||
// template = item.getContentType().getDefaultWorkflow();
|
||||
// }
|
||||
//
|
||||
// if (template != null) {
|
||||
//
|
||||
// final WorkflowManager workflowManager = cdiUtil
|
||||
// .findBean(WorkflowManager.class);
|
||||
//
|
||||
// final Workflow workflow = workflowManager.createWorkflow(template,
|
||||
// item);
|
||||
// workflowManager.start(workflow);
|
||||
//
|
||||
// if (!workflow.getTasks().isEmpty()) {
|
||||
//
|
||||
// if (workflow.getTasks().get(0) instanceof AssignableTask) {
|
||||
//
|
||||
// final AssignableTaskManager taskManager = cdiUtil
|
||||
// .findBean(AssignableTaskManager.class);
|
||||
// final AssignableTask task = (AssignableTask) workflow
|
||||
// .getTasks()
|
||||
// .get(0);
|
||||
// taskManager.lockTask(task);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private class ApplyWorkflowPrintListener
|
||||
extends WorkflowsOptionPrintListener {
|
||||
|
||||
@Override
|
||||
protected ContentSection getContentSection(final PageState state) {
|
||||
|
||||
return creationSelector.getContentSection(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Workflow> getCollection(final PageState state) {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ApplyWorkflowController controller = cdiUtil
|
||||
.findBean(ApplyWorkflowController.class);
|
||||
|
||||
final ContentSection section = creationSelector
|
||||
.getContentSection(state);
|
||||
|
||||
return controller.getWorkflowTemplates(section);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -39,7 +39,6 @@ import org.librecms.contentsection.ContentType;
|
|||
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.cms.ui.ContentItemPage;
|
||||
import com.arsdigita.cms.ui.item.ItemWorkflowRequestLocal;
|
||||
import com.arsdigita.cms.ui.workflow.AssignedTaskSection;
|
||||
import com.arsdigita.cms.ui.workflow.AssignedTaskTable;
|
||||
import com.arsdigita.cms.ui.workflow.TaskFinishForm;
|
||||
|
|
@ -107,6 +106,7 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
|
|||
AuthoringKitWizard.class,
|
||||
StringParameter.class
|
||||
};
|
||||
|
||||
private static final Class<?>[] USER_DEFINED_ARGS = new Class<?>[]{
|
||||
ItemSelectionModel.class,
|
||||
AuthoringKitWizard.class,
|
||||
|
|
@ -114,17 +114,29 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
|
|||
};
|
||||
|
||||
private final Object[] values;
|
||||
|
||||
private final ContentTypeInfo typeInfo;
|
||||
|
||||
private final AuthoringKitInfo kitInfo;
|
||||
|
||||
private final ItemSelectionModel selectionModel;
|
||||
|
||||
private final WorkflowRequestLocal workflowRequestLocal;
|
||||
|
||||
private final AssignedTaskTable assignedTaskTable;
|
||||
|
||||
private final SequentialMap labels;
|
||||
|
||||
private final List list;
|
||||
|
||||
private String defaultKey;
|
||||
|
||||
private final GridPanel leftPanel;
|
||||
|
||||
private final ModalPanel bodyPanel;
|
||||
|
||||
private final SimpleContainer stepsContainer;
|
||||
|
||||
private final TaskFinishForm taskFinishForm;
|
||||
|
||||
private final StringParameter selectedLanguageParam;
|
||||
|
|
@ -134,15 +146,17 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
|
|||
* item creation mode or item editing mode.
|
||||
*/
|
||||
public static final String IS_EDITING = "is_edit";
|
||||
|
||||
/**
|
||||
* The key for the item creation step.
|
||||
*/
|
||||
public static final String CREATION = "_creation_";
|
||||
|
||||
private final static String SEC_PAGE_EDIT_DYN
|
||||
= "com.arsdigita.cms.ui.authoring.SecondaryPageEditDynamic";
|
||||
= "com.arsdigita.cms.ui.authoring.SecondaryPageEditDynamic";
|
||||
|
||||
private final static String PAGE_EDIT_DYN
|
||||
= "com.arsdigita.cms.ui.authoring.PageEditDynamic";
|
||||
= "com.arsdigita.cms.ui.authoring.PageEditDynamic";
|
||||
|
||||
/**
|
||||
* Construct a new AuthoringKitWizard. Add all the steps in the authoring
|
||||
|
|
@ -173,17 +187,11 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
|
|||
kitInfo = typeInfo.getAuthoringKit();
|
||||
this.selectionModel = selectionModel;
|
||||
values = new Object[]{selectionModel, this, selectedLanguageParam};
|
||||
workflowRequestLocal = new ItemWorkflowRequestLocal();
|
||||
labels = new SequentialMap();
|
||||
|
||||
leftPanel = new GridPanel(1);
|
||||
setLeft(leftPanel);
|
||||
|
||||
assignedTaskTable = new AssignedTaskTable(workflowRequestLocal);
|
||||
|
||||
leftPanel.add(new AssignedTaskSection(workflowRequestLocal,
|
||||
assignedTaskTable));
|
||||
|
||||
final Section stepSection = new Section(
|
||||
new GlobalizedMessage("cms.ui.authoring.steps",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
|
|
@ -334,15 +342,8 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
|
|||
taskFinishForm = new TaskFinishForm(new TaskSelectionRequestLocal());
|
||||
bodyPanel.add(taskFinishForm);
|
||||
|
||||
bodyPanel.connect(assignedTaskTable, 2, taskFinishForm);
|
||||
bodyPanel.connect(taskFinishForm);
|
||||
|
||||
taskFinishForm
|
||||
.addProcessListener(
|
||||
event -> assignedTaskTable
|
||||
.getRowSelectionModel()
|
||||
.clearSelection(event.getPageState())
|
||||
);
|
||||
}
|
||||
|
||||
private final class StepListener implements ChangeListener {
|
||||
|
|
@ -548,6 +549,7 @@ public class AuthoringKitWizard extends LayoutPanel implements Resettable {
|
|||
private final class StepComponent extends SimpleContainer {
|
||||
|
||||
private final Object key;
|
||||
|
||||
private Object nextKey;
|
||||
|
||||
public StepComponent(final Object key) {
|
||||
|
|
|
|||
|
|
@ -1,64 +0,0 @@
|
|||
/*
|
||||
* 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.authoring;
|
||||
|
||||
import com.arsdigita.bebop.Container;
|
||||
import com.arsdigita.bebop.SaveCancelSection;
|
||||
import com.arsdigita.bebop.event.FormProcessListener;
|
||||
|
||||
/**
|
||||
* Interface which item creation components should implement. It's
|
||||
* currently an optional interface, but user defined content types
|
||||
* will not work unless they inherit from a type whose creation
|
||||
* component implements this. This interface currently only defines
|
||||
* methods which are essential to the operation of UDCT creation
|
||||
* components.
|
||||
*
|
||||
* @author Scott Seago (sseago@redhat.com)
|
||||
*/
|
||||
public interface CreationComponent extends Container, FormProcessListener {
|
||||
|
||||
/**
|
||||
* Instantiate and add the save/cancel section for this CreationComponent.
|
||||
*/
|
||||
void addSaveCancelSection();
|
||||
|
||||
/**
|
||||
* Return the save/cancel section for this CreationComponent.
|
||||
*
|
||||
* @return the save/cancel section for this CreationComponent.
|
||||
*/
|
||||
SaveCancelSection getSaveCancelSection();
|
||||
|
||||
/**
|
||||
* Removes the specified process listener from the
|
||||
* list of process listeners (if it had previously been added).
|
||||
*
|
||||
* @param listener the process listener to remove
|
||||
*/
|
||||
void removeProcessListener(FormProcessListener listener);
|
||||
|
||||
/**
|
||||
* Return the ApplyWorkflowFormSection associated with this CreationComponent.
|
||||
*
|
||||
* @return the ApplyWorkflowFormSection associated with this CreationComponent.
|
||||
*/
|
||||
ApplyWorkflowFormSection getWorkflowSection();
|
||||
|
||||
}
|
||||
|
|
@ -1,288 +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.authoring;
|
||||
|
||||
import com.arsdigita.bebop.ColumnPanel;
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.Form;
|
||||
import com.arsdigita.bebop.FormSection;
|
||||
import com.arsdigita.bebop.MetaForm;
|
||||
import com.arsdigita.bebop.Page;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SingleSelectionModel;
|
||||
import com.arsdigita.bebop.form.FormErrorDisplay;
|
||||
import com.arsdigita.bebop.parameters.LongParameter;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.cms.ui.ContentItemPage;
|
||||
import com.arsdigita.util.UncheckedWrapperException;
|
||||
import com.arsdigita.web.RedirectSignal;
|
||||
import com.arsdigita.web.URL;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentType;
|
||||
import org.librecms.contentsection.ContentTypeManager;
|
||||
import org.librecms.contentsection.ContentTypeRepository;
|
||||
import org.librecms.contentsection.Folder;
|
||||
import org.librecms.contentsection.FolderRepository;
|
||||
import org.librecms.contenttypes.AuthoringKitInfo;
|
||||
import org.librecms.contenttypes.ContentTypeInfo;
|
||||
import org.librecms.contenttypes.ContentTypesManager;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* An invisible component which contains all the possible creation components.
|
||||
* The components are loaded from the database at construction time. The
|
||||
* selector uses a {@link SingleSelectionModel} in order to get the ID of the
|
||||
* current content type.
|
||||
*
|
||||
* <strong>Important:</strong> This component is passed in the constructor to
|
||||
* every authoring kit creation component (such as {@link PageCreate}). The
|
||||
* creation component is supposed to follow the following pattern:
|
||||
*
|
||||
* <blockquote><pre>
|
||||
* // The member variable m_parent points to the CreationSelector
|
||||
* SomeContentItem item = somehowCreateTheItem(state);
|
||||
* item.setParent(m_parent.getFolder(state));
|
||||
* m_parent.editItem(state, item);
|
||||
* </pre></blockquote>
|
||||
*
|
||||
* If the creation component wishes to cancel the creation process, it should
|
||||
* call
|
||||
*
|
||||
* <blockquote><pre>m_parent.redirectBack(state);</pre></blockquote>
|
||||
*
|
||||
* The component may also call
|
||||
*
|
||||
* <blockquote><pre>m_parent.getContentSection(state);</pre></blockquote>
|
||||
*
|
||||
* in order to get the current content section.
|
||||
*
|
||||
* @author unknown
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class CreationSelector extends MetaForm {
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
CreationSelector.class);
|
||||
|
||||
private final SingleSelectionModel<Long> typeSelectionModel;
|
||||
private final StringParameter selectedLanguageParam;
|
||||
|
||||
private static final Class[] ARGUMENTS = new Class[]{
|
||||
ItemSelectionModel.class,
|
||||
CreationSelector.class,
|
||||
StringParameter.class
|
||||
};
|
||||
|
||||
private Object[] values;
|
||||
|
||||
private final ItemSelectionModel itemSelectionModel;
|
||||
private final LongParameter itemIdParameter;
|
||||
|
||||
public static final String ITEM_ID = "iid";
|
||||
|
||||
/**
|
||||
* Constructs a new <code>CreationSelector</code>. Load all the possible
|
||||
* creation components from the database and stick them in the Map.
|
||||
*
|
||||
* @param typeSelectionModel the {@link SingleSelectionModel} which will
|
||||
* supply a BigDecimal ID of the content type to
|
||||
* instantiate
|
||||
*
|
||||
* @param selectedLanguageParam
|
||||
*/
|
||||
public CreationSelector(final SingleSelectionModel<Long> typeSelectionModel,
|
||||
final StringParameter selectedLanguageParam) {
|
||||
|
||||
super("pageCreate");
|
||||
|
||||
this.typeSelectionModel = typeSelectionModel;
|
||||
this.selectedLanguageParam = selectedLanguageParam;
|
||||
|
||||
itemIdParameter = new LongParameter(ITEM_ID);
|
||||
itemSelectionModel = new ItemSelectionModel(itemIdParameter);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param state
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Form buildForm(final PageState state) {
|
||||
final Long typeId = typeSelectionModel.getSelectedKey(state);
|
||||
final Component component;
|
||||
final Form returnForm = new Form("pageCreate");
|
||||
final FormErrorDisplay formErrorDisplay = new FormErrorDisplay(this);
|
||||
formErrorDisplay.setStateParamsAreRegistered(false);
|
||||
returnForm.add(formErrorDisplay, ColumnPanel.FULL_WIDTH
|
||||
| ColumnPanel.LEFT);
|
||||
|
||||
if (typeId != null) {
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ContentTypeRepository typeRepo = cdiUtil.findBean(
|
||||
ContentTypeRepository.class);
|
||||
final ContentTypeManager typeManager = cdiUtil.findBean(
|
||||
ContentTypeManager.class);
|
||||
final ContentTypesManager typesManager = cdiUtil.findBean(
|
||||
ContentTypesManager.class);
|
||||
|
||||
final Optional<ContentType> type = typeRepo.findById(typeId);
|
||||
if (!type.isPresent()) {
|
||||
throw new UncheckedWrapperException(String.format(
|
||||
"Type with id %d not found.", typeId));
|
||||
}
|
||||
final ContentTypeInfo typeInfo = typesManager
|
||||
.getContentTypeInfo(type.get());
|
||||
final AuthoringKitInfo kit = typeInfo.getAuthoringKit();
|
||||
component = instantiateKitComponent(kit, type.get());
|
||||
if (component != null) {
|
||||
returnForm.add(component);
|
||||
returnForm.setMethod(Form.POST);
|
||||
returnForm.setEncType("multipart/form-data");
|
||||
}
|
||||
}
|
||||
return returnForm;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the item_id parameter.
|
||||
*
|
||||
* @param page
|
||||
*/
|
||||
@Override
|
||||
public void register(final Page page) {
|
||||
super.register(page);
|
||||
page.addComponentStateParam(this, itemIdParameter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the creation component.
|
||||
*
|
||||
* @param kit
|
||||
* @param type
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected Component instantiateKitComponent(final AuthoringKitInfo kit,
|
||||
final ContentType type) {
|
||||
final Class<? extends FormSection> createClass = kit
|
||||
.getCreateComponent();
|
||||
final Object[] vals;
|
||||
|
||||
try {
|
||||
final ItemSelectionModel itemSelectionModel
|
||||
= new ItemSelectionModel(
|
||||
type, itemIdParameter);
|
||||
vals = new Object[]{itemSelectionModel,
|
||||
this,
|
||||
selectedLanguageParam};
|
||||
|
||||
final Constructor<? extends FormSection> constructor = createClass
|
||||
.getConstructor(ARGUMENTS);
|
||||
final Component component = (Component) constructor
|
||||
.newInstance(vals);
|
||||
return component;
|
||||
} catch (IllegalAccessException
|
||||
| IllegalArgumentException
|
||||
| InstantiationException
|
||||
| NoSuchMethodException
|
||||
| SecurityException
|
||||
| InvocationTargetException ex) {
|
||||
LOGGER.error("Failed to instantiate creation component \"{}\".",
|
||||
kit.getCreateComponent().getName());
|
||||
LOGGER.error("Exception: ", ex);
|
||||
throw new UncheckedWrapperException(String.format(
|
||||
"Failed to instantiate creation component \"%s\".",
|
||||
kit.getCreateComponent().getName()),
|
||||
ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the currently selected folder. Creation components will place new
|
||||
* items in this folder.
|
||||
*
|
||||
* @param state represents the current request
|
||||
*
|
||||
* @return the currently selected folder, in which new items should be
|
||||
* placed.
|
||||
*/
|
||||
public final Folder getFolder(final PageState state) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the currently selected content section. New items created by
|
||||
* creation components will belong to this section. This is the content
|
||||
* section to which the folder returned by {@link #getFolder getFolder}
|
||||
* belongs.
|
||||
*
|
||||
* @param state represents the current request
|
||||
*
|
||||
* @return the currently selected content section.
|
||||
*/
|
||||
public final ContentSection getContentSection(final PageState state) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final CreationSelectorController controller = cdiUtil
|
||||
.findBean(CreationSelectorController.class);
|
||||
|
||||
return controller.getContentSectionForFolder(getFolder(state));
|
||||
}
|
||||
|
||||
/**
|
||||
* Forward to the item editing UI. The creation component of an authoring
|
||||
* kit may call this method to indicate that the creation process is
|
||||
* complete.
|
||||
*
|
||||
* @param state the page state
|
||||
* @param item the newly created item
|
||||
*/
|
||||
public void editItem(final PageState state, final ContentItem item) {
|
||||
final ContentSection section = getContentSection(state);
|
||||
|
||||
final String nodeUrl = String.join("", URL.getDispatcherPath(),
|
||||
section.getPrimaryUrl(),
|
||||
"/");
|
||||
final String target = ContentItemPage.getItemURL(
|
||||
nodeUrl, item.getObjectId(), ContentItemPage.AUTHORING_TAB, true);
|
||||
|
||||
throw new RedirectSignal(target, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel item editing and go back to where the user came from
|
||||
*
|
||||
* @param state the page state
|
||||
*/
|
||||
public void redirectBack(final PageState state) {
|
||||
typeSelectionModel.clearSelection(state);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,316 +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.authoring;
|
||||
|
||||
import com.arsdigita.bebop.ColumnPanel;
|
||||
import com.arsdigita.bebop.FormData;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.event.FormSubmissionListener;
|
||||
import com.arsdigita.bebop.event.PrintEvent;
|
||||
import com.arsdigita.bebop.event.PrintListener;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
|
||||
import org.librecms.contentsection.ContentSection;
|
||||
import org.librecms.contentsection.ContentType;
|
||||
import org.librecms.contentsection.Folder;
|
||||
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.kernel.KernelConfig;
|
||||
import com.arsdigita.util.Assert;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.libreccm.workflow.Workflow;
|
||||
import org.libreccm.workflow.WorkflowRepository;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contentsection.ContentItemInitializer;
|
||||
import org.librecms.contentsection.ContentItemRepository;
|
||||
import org.librecms.contenttypes.ContentTypeInfo;
|
||||
import org.librecms.contenttypes.ContentTypesManager;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* A form which will create a new document (that is subclasses of class
|
||||
* ContentPage).
|
||||
*
|
||||
* Used to create a new document / content item. Creates widgets to select the
|
||||
* workflow, and language. It displays the type of document as well. Super class
|
||||
* adds additional widgets (title and name/URL) to complete the form.
|
||||
*
|
||||
* It's a pane which is part of a more complex page, additionally containing
|
||||
* folder structure, content items in the folder, permissions, etc.
|
||||
*
|
||||
* @author Stanislav Freidin (stas@arsdigita.com)
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class PageCreateForm
|
||||
extends BasicPageForm
|
||||
implements FormSubmissionListener, CreationComponent {
|
||||
|
||||
/**
|
||||
* The state parameter which specifies the content section
|
||||
*/
|
||||
public static final String SECTION_ID = "sid";
|
||||
|
||||
private final CreationSelector creationSelector;
|
||||
private ApplyWorkflowFormSection workflowSection;
|
||||
private final StringParameter selectedLanguageParam;
|
||||
|
||||
private LanguageWidget languageWidget;
|
||||
|
||||
/**
|
||||
* Construct a new PageCreationForm
|
||||
*
|
||||
* @param itemModel The {@link ItemSelectionModel} which will be
|
||||
* responsible for loading the current item
|
||||
* @param creationSelector The {@link CreationSelector} parent. This
|
||||
* class should call either the {@link
|
||||
* CreationSelector#redirectBack(PageState)} or {@link
|
||||
* CreationSelector#editItem(PageState, ContentItem)} methods on the parent
|
||||
* eventually
|
||||
* @param selectedLanguageParam
|
||||
*/
|
||||
public PageCreateForm(final ItemSelectionModel itemModel,
|
||||
final CreationSelector creationSelector,
|
||||
final StringParameter selectedLanguageParam) {
|
||||
|
||||
super("PageCreate", itemModel, selectedLanguageParam);
|
||||
|
||||
this.creationSelector = creationSelector;
|
||||
this.selectedLanguageParam = selectedLanguageParam;
|
||||
|
||||
workflowSection.setCreationSelector(creationSelector);
|
||||
super.addSubmissionListener(this);
|
||||
|
||||
super.getSaveCancelSection().getSaveButton()
|
||||
.setButtonLabel(new GlobalizedMessage("cms.ui.create",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add various widgets to the form. Child classes should override this
|
||||
* method to perform all their widget-adding needs.
|
||||
*/
|
||||
@Override
|
||||
protected void addWidgets() {
|
||||
|
||||
/* Retrieve Content Type */
|
||||
final ContentType type = getItemSelectionModel().getContentType();
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ContentTypesManager typesManager = cdiUtil
|
||||
.findBean(ContentTypesManager.class);
|
||||
final ContentTypeInfo typeInfo = typesManager.getContentTypeInfo(type);
|
||||
|
||||
/* Add workflow selection based on configured Content Type */
|
||||
workflowSection = new ApplyWorkflowFormSection(type);
|
||||
add(workflowSection, ColumnPanel.INSERT);
|
||||
/* content type */
|
||||
add(new Label(new GlobalizedMessage("cms.ui.authoring.content_type",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
final Label typeOutput = new Label(
|
||||
new ContentTypePrintListener(typeInfo));
|
||||
add(typeOutput);
|
||||
/* language selection */
|
||||
add(new Label(new GlobalizedMessage("cms.ui.language.field",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
languageWidget = new LanguageWidget(LANGUAGE);
|
||||
add(languageWidget);
|
||||
// add(new LanguageWidget(LANGUAGE));
|
||||
|
||||
/* Additional widgets from super type: title and name (url) */
|
||||
super.addWidgets();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the ApplyWorkflowFormSection associated with this
|
||||
* CreationComponent.
|
||||
*
|
||||
* @return the ApplyWorkflowFormSection associated with this
|
||||
* CreationComponent.
|
||||
*/
|
||||
@Override
|
||||
public ApplyWorkflowFormSection getWorkflowSection() {
|
||||
return workflowSection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new item id.
|
||||
*
|
||||
* @param event
|
||||
*
|
||||
* @throws com.arsdigita.bebop.FormProcessException
|
||||
*/
|
||||
@Override
|
||||
public void init(final FormSectionEvent event) throws FormProcessException {
|
||||
|
||||
//Init language widget with default language.
|
||||
final PageState state = event.getPageState();
|
||||
languageWidget.setValue(state, KernelConfig.getConfig().getDefaultLanguage());
|
||||
}
|
||||
|
||||
/**
|
||||
* If the Cancel button was pressed, hide self and show the display
|
||||
* component.
|
||||
*
|
||||
* @param event
|
||||
*
|
||||
* @throws com.arsdigita.bebop.FormProcessException
|
||||
*/
|
||||
@Override
|
||||
public void submitted(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
|
||||
if (getSaveCancelSection().getCancelButton().isSelected(state)) {
|
||||
creationSelector.redirectBack(state);
|
||||
|
||||
throw new FormProcessException(
|
||||
new GlobalizedMessage("cms.ui.authoring.submission_cancelled",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate inputs to ensure name uniqueness. Note: We can't call
|
||||
* {@code super.validate(FormSectionEvent)} here because the super method
|
||||
* {@link BasicPageForm#validate(com.arsdigita.bebop.event.FormSectionEvent)}
|
||||
* tries to access things which on existing yet.
|
||||
*
|
||||
* @param event
|
||||
*
|
||||
* @throws com.arsdigita.bebop.FormProcessException
|
||||
*/
|
||||
@Override
|
||||
public void validate(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final Folder folder = creationSelector.getFolder(event.getPageState());
|
||||
validateNameUniqueness(folder, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Class specific implementation if FormProcessListener (as inherited from
|
||||
* BasicItemForm), saves fields to the database.
|
||||
*
|
||||
* @param event
|
||||
*
|
||||
* @throws FormProcessException
|
||||
*/
|
||||
@Override
|
||||
public final void process(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final FormData data = event.getFormData();
|
||||
final PageState state = event.getPageState();
|
||||
final ContentSection section = creationSelector.getContentSection(state);
|
||||
final Folder folder = creationSelector.getFolder(state);
|
||||
|
||||
Assert.exists(section, ContentSection.class);
|
||||
|
||||
final Long selectedWorkflowTemplateId = workflowSection
|
||||
.getSelectedWorkflowTemplateId(state);
|
||||
|
||||
final Locale locale = new Locale((String) data.get(LANGUAGE));
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
|
||||
final ContentItem item;
|
||||
if (selectedWorkflowTemplateId == null) {
|
||||
item = createContentPage(state,
|
||||
(String) data.get(NAME),
|
||||
section,
|
||||
folder,
|
||||
getItemInitializer(data, state),
|
||||
locale);
|
||||
} else {
|
||||
final WorkflowRepository workflowRepo = cdiUtil
|
||||
.findBean(WorkflowRepository.class);
|
||||
final Workflow workflowTemplate = workflowRepo
|
||||
.findById(selectedWorkflowTemplateId)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No WorkflowTemplate with ID %d in the database.",
|
||||
selectedWorkflowTemplateId)));
|
||||
|
||||
item = createContentItemPage(state,
|
||||
(String) data.get(NAME),
|
||||
section,
|
||||
folder,
|
||||
workflowTemplate,
|
||||
getItemInitializer(data, state),
|
||||
locale);
|
||||
}
|
||||
|
||||
// item.getName().putValue(locale, (String) data.get(NAME));
|
||||
item.getTitle().putValue(locale, (String) data.get(TITLE));
|
||||
|
||||
final ContentItemRepository itemRepo = cdiUtil
|
||||
.findBean(ContentItemRepository.class);
|
||||
itemRepo.save(item);
|
||||
|
||||
state.setValue(selectedLanguageParam, locale.toString());
|
||||
|
||||
creationSelector.editItem(state, item);
|
||||
}
|
||||
|
||||
protected ContentItemInitializer<?> getItemInitializer(
|
||||
final FormData data, final PageState state) {
|
||||
|
||||
return item -> {
|
||||
};
|
||||
}
|
||||
|
||||
protected StringParameter getSelectedLanguageParam() {
|
||||
return selectedLanguageParam;
|
||||
}
|
||||
|
||||
private class ContentTypePrintListener implements PrintListener {
|
||||
|
||||
private final ContentTypeInfo typeInfo;
|
||||
|
||||
public ContentTypePrintListener(final ContentTypeInfo typeInfo) {
|
||||
this.typeInfo = typeInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void prepare(final PrintEvent event) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final GlobalizationHelper globalizationHelper = cdiUtil
|
||||
.findBean(GlobalizationHelper.class);
|
||||
final ResourceBundle bundle = ResourceBundle
|
||||
.getBundle(typeInfo.getLabelBundle(),
|
||||
globalizationHelper.getNegotiatedLocale());
|
||||
|
||||
final String typeLabel = bundle.getString(typeInfo.getLabelKey());
|
||||
|
||||
final Label target = (Label) event.getTarget();
|
||||
target.setLabel(typeLabel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
package com.arsdigita.cms.ui.item;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.cms.ui.ContentItemPage;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* This interface is implemented by "meta" content items which need to
|
||||
* customise their preview link. An example is a content item which serves
|
||||
* as an access point to an application.
|
||||
* </p>
|
||||
* <p>
|
||||
* An implementation may return {@code null}. In this case
|
||||
* {@link ContentItemPage} will use the default preview URL.
|
||||
* </p>
|
||||
*
|
||||
* @author Jens Pelzetter
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface CustomizedPreviewLink {
|
||||
|
||||
String getPreviewUrl(PageState state);
|
||||
|
||||
}
|
||||
|
|
@ -1,229 +0,0 @@
|
|||
/*
|
||||
* 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.item;
|
||||
|
||||
import com.arsdigita.bebop.BoxPanel;
|
||||
import com.arsdigita.bebop.Form;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SingleSelectionModel;
|
||||
import com.arsdigita.bebop.event.FormProcessListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.event.PrintEvent;
|
||||
import com.arsdigita.bebop.event.PrintListener;
|
||||
import com.arsdigita.bebop.form.Option;
|
||||
import com.arsdigita.bebop.form.OptionGroup;
|
||||
import com.arsdigita.bebop.form.Submit;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.cms.ui.ContentItemPage;
|
||||
import com.arsdigita.cms.ui.authoring.LanguageWidget;
|
||||
|
||||
import org.librecms.util.LanguageUtil;
|
||||
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.toolbox.ui.ActionGroup;
|
||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
||||
import com.arsdigita.toolbox.ui.Section;
|
||||
import com.arsdigita.util.Pair;
|
||||
import com.arsdigita.web.RedirectSignal;
|
||||
import com.arsdigita.web.URL;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.librecms.contentsection.ContentItemL10NManager;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.TooManyListenersException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.libreccm.core.UnexpectedErrorException;
|
||||
import org.librecms.CmsConstants;
|
||||
|
||||
/**
|
||||
* Displays the "Language instances" pane, with all the language instances in
|
||||
* the Bundle.
|
||||
*
|
||||
* @author Alan Pevec (apevec@redhat.com)
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
public class ItemLanguages extends LayoutPanel {
|
||||
|
||||
private final ItemSelectionModel selectionModel;
|
||||
// private final SingleSelectionModel<String> selectedLanguage;
|
||||
private final LanguageWidget languageWidget;
|
||||
private final StringParameter selectedLanguageParam;
|
||||
// private final Submit changeSubmit;
|
||||
private final Submit createSubmit;
|
||||
|
||||
/**
|
||||
* Constructs a new <code>ItemLanguages</code>.
|
||||
*
|
||||
* @param selectionModel the {@link ItemSelectionModel} which will
|
||||
* supply the current item
|
||||
* @param selectedLanguage {@link SingleSelectionModel} for the
|
||||
* selected language.
|
||||
* @param selectedLanguageParam
|
||||
*/
|
||||
public ItemLanguages(final ItemSelectionModel selectionModel,
|
||||
// final SingleSelectionModel<String> selectedLanguage,
|
||||
final StringParameter selectedLanguageParam) {
|
||||
|
||||
this.selectionModel = selectionModel;
|
||||
// this.selectedLanguage = selectedLanguage;
|
||||
this.selectedLanguageParam = selectedLanguageParam;
|
||||
|
||||
final Section section = new Section(gz("cms.ui.item.languages"));
|
||||
setBody(section);
|
||||
|
||||
final ActionGroup group = new ActionGroup();
|
||||
section.setBody(group);
|
||||
|
||||
group.setSubject(new ItemLanguagesTable(selectionModel,
|
||||
// selectedLanguage,
|
||||
selectedLanguageParam));
|
||||
|
||||
final Form form = new Form("newLanguage", new BoxPanel(
|
||||
BoxPanel.HORIZONTAL)) {
|
||||
|
||||
@Override
|
||||
public boolean isVisible(final PageState state) {
|
||||
final ContentItem item = selectionModel.getSelectedItem(state);
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ContentItemL10NManager l10NManager = cdiUtil.findBean(
|
||||
ContentItemL10NManager.class);
|
||||
return !l10NManager.creatableLocales(item).isEmpty();
|
||||
}
|
||||
|
||||
};
|
||||
group.addAction(form);
|
||||
|
||||
form.setRedirecting(true);
|
||||
languageWidget = new LanguageWidget("language_widget") {
|
||||
|
||||
@Override
|
||||
protected void setupOptions() {
|
||||
// Don't do anything.
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
try {
|
||||
languageWidget.addPrintListener(new OptionPrinter());
|
||||
} catch (TooManyListenersException ex) {
|
||||
throw new UnexpectedErrorException(ex);
|
||||
}
|
||||
|
||||
form.add(languageWidget);
|
||||
// changeSubmit = new Submit("change", gz("cms.ui.item.language.change"));
|
||||
// form.add(changeSubmit);
|
||||
createSubmit = new Submit("create", gz("cms.ui.item.language.add"));
|
||||
form.add(createSubmit);
|
||||
form.addProcessListener(new ProcessListener());
|
||||
}
|
||||
|
||||
/**
|
||||
* Offers only languages not yet present in the bundle.
|
||||
*/
|
||||
private class OptionPrinter implements PrintListener {
|
||||
|
||||
@Override
|
||||
public final void prepare(final PrintEvent event) {
|
||||
final PageState state = event.getPageState();
|
||||
final OptionGroup target = (OptionGroup) event.getTarget();
|
||||
target.clearOptions();
|
||||
final ContentItem item = selectionModel.getSelectedItem(state);
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final LanguageUtil languageUtil = cdiUtil.findBean(
|
||||
LanguageUtil.class);
|
||||
final ContentItemL10NManager l10NManager = cdiUtil.findBean(
|
||||
ContentItemL10NManager.class);
|
||||
|
||||
final List<String> creatableLangs = l10NManager.creatableLocales(
|
||||
item).stream()
|
||||
.map(locale -> locale.toString())
|
||||
.collect(Collectors.toList());
|
||||
final List<Pair> languages = languageUtil
|
||||
.convertToG11N(creatableLangs);
|
||||
|
||||
for (final Pair pair : languages) {
|
||||
final String langCode = (String) pair.getKey();
|
||||
final GlobalizedMessage langName
|
||||
= (GlobalizedMessage) pair
|
||||
.getValue();
|
||||
target.addOption(new Option(langCode, new Label(langName)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new language instance to the bundle.
|
||||
*/
|
||||
private class ProcessListener implements FormProcessListener {
|
||||
|
||||
@Override
|
||||
public final void process(final FormSectionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
final String language = (String) languageWidget.getValue(state);
|
||||
final ContentItem item = selectionModel.getSelectedItem(state);
|
||||
|
||||
if (createSubmit.isSelected(state)) {
|
||||
|
||||
final ItemLanguagesController controller = cdiUtil
|
||||
.findBean(ItemLanguagesController.class);
|
||||
|
||||
controller.addLanguage(item, language);
|
||||
|
||||
// redirect to ContentItemPage.AUTHORING_TAB of the new instance
|
||||
state.setValue(selectedLanguageParam, language);
|
||||
final String langParam = String
|
||||
.format("&%s=%s",
|
||||
ContentItemPage.SELECTED_LANGUAGE,
|
||||
language);
|
||||
final String target = String.join(
|
||||
"",
|
||||
URL.getDispatcherPath(),
|
||||
controller.getItemEditUrl(item),
|
||||
langParam);
|
||||
|
||||
throw new RedirectSignal(target, true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static final GlobalizedMessage gz(final String key) {
|
||||
return new GlobalizedMessage(key, CmsConstants.CMS_BUNDLE);
|
||||
}
|
||||
|
||||
protected static final String lz(final String key) {
|
||||
return (String) gz(key).localize();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,141 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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.cms.ui.item;
|
||||
|
||||
import com.arsdigita.bebop.table.RowData;
|
||||
import com.arsdigita.cms.ui.ContentItemPage;
|
||||
|
||||
import org.libreccm.l10n.GlobalizationHelper;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contentsection.ContentItemL10NManager;
|
||||
import org.librecms.contentsection.ContentItemRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
class ItemLanguagesController {
|
||||
|
||||
@Inject
|
||||
private ContentItemRepository itemRepo;
|
||||
|
||||
@Inject
|
||||
private ContentItemL10NManager itemL10NManager;
|
||||
|
||||
@Inject
|
||||
private GlobalizationHelper globalizationHelper;
|
||||
|
||||
protected List<RowData<String>> retrieveLanguageVariants(
|
||||
final ContentItem item) {
|
||||
return retrieveLanguageVariants(item.getObjectId());
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected List<RowData<String>> retrieveLanguageVariants(final long itemId) {
|
||||
|
||||
final ContentItem item = itemRepo
|
||||
.findById(itemId)
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No ContentItem with ID %d in the database.", itemId)));
|
||||
|
||||
final List<Locale> availableLangs = new ArrayList<>(itemL10NManager
|
||||
.availableLanguages(item));
|
||||
availableLangs.sort((locale1, locale2) -> {
|
||||
return locale1.toString().compareTo(locale2.toString());
|
||||
});
|
||||
|
||||
return availableLangs.stream()
|
||||
.map(lang -> createRow(item, lang))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private RowData<String> createRow(final ContentItem item,
|
||||
final Locale lang) {
|
||||
final RowData<String> row = new RowData<>(2);
|
||||
row.setRowKey(lang.toString());
|
||||
row.setColData(0, lang.getDisplayName(globalizationHelper
|
||||
.getNegotiatedLocale()));
|
||||
row.setColData(1, item.getTitle().getValue(lang));
|
||||
|
||||
return row;
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected int countLanguageVariants(final ContentItem item) {
|
||||
|
||||
final ContentItem contentItem = itemRepo
|
||||
.findById(item.getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No ContentItem with ID %d in the database.",
|
||||
item.getObjectId())));
|
||||
|
||||
return itemL10NManager.availableLanguages(contentItem).size();
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void addLanguage(final ContentItem item, final String language) {
|
||||
|
||||
final ContentItem contentItem = itemRepo
|
||||
.findById(item.getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No ContentItem with ID %d in the database.",
|
||||
item.getObjectId())));
|
||||
|
||||
itemL10NManager.addLanguage(contentItem, new Locale(language));
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected void removeLanguage(final ContentItem item,
|
||||
final String language) {
|
||||
|
||||
final ContentItem contentItem = itemRepo
|
||||
.findById(item.getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No ContentItem with ID %d in the database.",
|
||||
item.getObjectId())));
|
||||
|
||||
itemL10NManager.removeLanguage(contentItem, new Locale(language));
|
||||
}
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected String getItemEditUrl(final ContentItem item) {
|
||||
|
||||
final ContentItem contentItem = itemRepo
|
||||
.findById(item.getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String.format(
|
||||
"No ContentItem with ID %d in the database.",
|
||||
item.getObjectId())));
|
||||
|
||||
return ContentItemPage.getItemURL(contentItem,
|
||||
ContentItemPage.AUTHORING_TAB);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,229 +0,0 @@
|
|||
/*
|
||||
* 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.item;
|
||||
|
||||
import com.arsdigita.bebop.Component;
|
||||
import com.arsdigita.bebop.ControlLink;
|
||||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.Table;
|
||||
import com.arsdigita.bebop.Text;
|
||||
import com.arsdigita.bebop.event.TableActionEvent;
|
||||
import com.arsdigita.bebop.event.TableActionListener;
|
||||
import com.arsdigita.bebop.parameters.StringParameter;
|
||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
||||
import com.arsdigita.bebop.table.TableColumn;
|
||||
import com.arsdigita.bebop.table.TableColumnModel;
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.cms.ui.ContentItemPage;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.kernel.KernelConfig;
|
||||
import com.arsdigita.web.RedirectSignal;
|
||||
import com.arsdigita.web.URL;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.librecms.CmsConstants;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.util.LanguageUtil;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Displays a list of all language instances of an item.
|
||||
*
|
||||
*/
|
||||
public class ItemLanguagesTable extends Table {
|
||||
|
||||
public static final int COL_LANGUAGE = 0;
|
||||
public static final int COL_TITLE = 1;
|
||||
public static final int COL_DELETE = 2;
|
||||
|
||||
private final ItemSelectionModel itemSelectionModel;
|
||||
// private final SingleSelectionModel<String> langSelectionModel;
|
||||
private final StringParameter selectedLanguageParam;
|
||||
// private final TableColumn deleteColumn;
|
||||
|
||||
/**
|
||||
* Construct a new {@code ItemLanguagesTable} which shows all language
|
||||
* variants of an item.
|
||||
*
|
||||
* @param itemSelectionModel the ItemSelectionModel that supplies the
|
||||
* current item
|
||||
* @param langSelectionModel the single selection model which stores the
|
||||
* selected language.
|
||||
*/
|
||||
public ItemLanguagesTable(final ItemSelectionModel itemSelectionModel,
|
||||
// final SingleSelectionModel<String> langSelectionModel,
|
||||
final StringParameter selectedLanguageParam) {
|
||||
super();
|
||||
setIdAttr("item_languages_table");
|
||||
|
||||
this.itemSelectionModel = itemSelectionModel;
|
||||
// this.langSelectionModel = langSelectionModel;
|
||||
this.selectedLanguageParam = selectedLanguageParam;
|
||||
setModelBuilder(new ItemLanguagesTableModelBuilder(itemSelectionModel));
|
||||
|
||||
final TableColumnModel columnModel = getColumnModel();
|
||||
columnModel.add(new TableColumn(COL_LANGUAGE,
|
||||
new Label(new GlobalizedMessage(
|
||||
"cms.ui.language.header",
|
||||
CmsConstants.CMS_BUNDLE))));
|
||||
columnModel.add(new TableColumn(COL_TITLE,
|
||||
new Label(new GlobalizedMessage(
|
||||
"cms.ui.language.title",
|
||||
CmsConstants.CMS_BUNDLE))));
|
||||
columnModel.add(new TableColumn(COL_DELETE,
|
||||
new Label(new GlobalizedMessage(
|
||||
"cms.ui.action",
|
||||
CmsConstants.CMS_BUNDLE))));
|
||||
|
||||
columnModel.get(COL_LANGUAGE).setCellRenderer(new TableCellRenderer() {
|
||||
|
||||
@Override
|
||||
public Component getComponent(final Table table,
|
||||
final PageState state,
|
||||
final Object value,
|
||||
final boolean isSelected,
|
||||
final Object key,
|
||||
final int row,
|
||||
final int column) {
|
||||
|
||||
final Locale locale = new Locale((String) value);
|
||||
final String selectedLanguage = (String) state
|
||||
.getValue(selectedLanguageParam);
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final LanguageUtil langUtil = cdiUtil.findBean(
|
||||
LanguageUtil.class);
|
||||
|
||||
final Label label = new Label(langUtil.getLangFull(locale));
|
||||
|
||||
// if (langSelectionModel.getSelectedKey(state).equals(key)) {
|
||||
if (selectedLanguage.equals(key)) {
|
||||
// Current variant, no link
|
||||
return label;
|
||||
} else {
|
||||
return new ControlLink(label);
|
||||
|
||||
// final String target = ContentItemPage.getItemURL(
|
||||
// itemSelectionModel.getSelectedItem(state),
|
||||
// ContentItemPage.AUTHORING_TAB);
|
||||
// return new Link(label, target);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
columnModel.get(COL_DELETE)
|
||||
.setCellRenderer(new TableCellRenderer() {
|
||||
|
||||
@Override
|
||||
public Component getComponent(final Table table,
|
||||
final PageState state,
|
||||
final Object value,
|
||||
final boolean isSelected,
|
||||
final Object key,
|
||||
final int row,
|
||||
final int column
|
||||
) {
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ItemLanguagesController controller = cdiUtil
|
||||
.findBean(ItemLanguagesController.class);
|
||||
final ContentItem item = itemSelectionModel
|
||||
.getSelectedItem(state);
|
||||
|
||||
if (key
|
||||
.equals(KernelConfig.getConfig().getDefaultLanguage())
|
||||
|| controller.countLanguageVariants(item) <= 1) {
|
||||
return new Text(" ");
|
||||
} else {
|
||||
final ControlLink link = new ControlLink(new Label(
|
||||
new GlobalizedMessage("cms.ui.delete",
|
||||
CmsConstants.CMS_BUNDLE)));
|
||||
link.setConfirmation(new GlobalizedMessage(
|
||||
"cms.ui.delete.confirmation",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
|
||||
return link;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
addTableActionListener(
|
||||
new TableActionListener() {
|
||||
|
||||
@Override
|
||||
public void cellSelected(final TableActionEvent event)
|
||||
throws FormProcessException {
|
||||
|
||||
final PageState state = event.getPageState();
|
||||
final ContentItem item = itemSelectionModel
|
||||
.getSelectedItem(state);
|
||||
final String selectedLanguage = (String) event.getRowKey();
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ItemLanguagesController controller = cdiUtil
|
||||
.findBean(ItemLanguagesController.class);
|
||||
|
||||
switch (event.getColumn()) {
|
||||
case COL_LANGUAGE: {
|
||||
state.setValue(selectedLanguageParam, selectedLanguage);
|
||||
final String langParam = String
|
||||
.format("&%s=%s",
|
||||
ContentItemPage.SELECTED_LANGUAGE,
|
||||
selectedLanguage);
|
||||
final String target = String.join(
|
||||
"",
|
||||
URL.getDispatcherPath(),
|
||||
controller.getItemEditUrl(item),
|
||||
langParam);
|
||||
throw new RedirectSignal(target, true);
|
||||
}
|
||||
case COL_DELETE: {
|
||||
if (selectedLanguage.equals(state.getValue(
|
||||
selectedLanguageParam))) {
|
||||
state.setValue(selectedLanguageParam,
|
||||
KernelConfig.getConfig()
|
||||
.getDefaultLanguage());
|
||||
}
|
||||
controller.removeLanguage(item, selectedLanguage);
|
||||
}
|
||||
default:
|
||||
//Nothing to do
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void headSelected(final TableActionEvent event
|
||||
) {
|
||||
//Nothing
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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.cms.ui.item;
|
||||
|
||||
import com.arsdigita.bebop.Label;
|
||||
import com.arsdigita.bebop.table.RowData;
|
||||
import com.arsdigita.bebop.table.TableModel;
|
||||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
|
||||
import org.librecms.CmsConstants;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
class ItemLanguagesTableModel implements TableModel {
|
||||
|
||||
private final Iterator<RowData<String>> iterator;
|
||||
private RowData<String> curentRow;
|
||||
|
||||
protected ItemLanguagesTableModel(final List<RowData<String>> rows) {
|
||||
iterator = rows.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean nextRow() {
|
||||
if (iterator.hasNext()) {
|
||||
curentRow = iterator.next();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getElementAt(final int columnIndex) {
|
||||
switch (columnIndex) {
|
||||
case ItemLanguagesTable.COL_LANGUAGE:
|
||||
return curentRow.getColData(0);
|
||||
case ItemLanguagesTable.COL_TITLE:
|
||||
return curentRow.getColData(1);
|
||||
case ItemLanguagesTable.COL_DELETE:
|
||||
return new Label(new GlobalizedMessage("cms.ui.delete",
|
||||
CmsConstants.CMS_BUNDLE));
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid column index.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getKeyAt(final int columnIndex) {
|
||||
return curentRow.getRowKey();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2016 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.cms.ui.item;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.Table;
|
||||
import com.arsdigita.bebop.table.RowData;
|
||||
import com.arsdigita.bebop.table.TableModel;
|
||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
||||
import com.arsdigita.cms.ItemSelectionModel;
|
||||
import com.arsdigita.util.LockableImpl;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
class ItemLanguagesTableModelBuilder
|
||||
extends LockableImpl
|
||||
implements TableModelBuilder {
|
||||
|
||||
private final ItemSelectionModel itemSelectionModel;
|
||||
|
||||
protected ItemLanguagesTableModelBuilder(
|
||||
final ItemSelectionModel itemSelectionModel) {
|
||||
this.itemSelectionModel = itemSelectionModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableModel makeModel(final Table table, final PageState state) {
|
||||
final ContentItem item = itemSelectionModel.getSelectedItem(state);
|
||||
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ItemLanguagesController controller = cdiUtil.findBean(ItemLanguagesController.class);
|
||||
final List<RowData<String>> rows = controller.retrieveLanguageVariants(
|
||||
item);
|
||||
|
||||
return new ItemLanguagesTableModel(rows);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* 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.item;
|
||||
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.cms.CMS;
|
||||
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
|
||||
import com.arsdigita.cms.ui.workflow.WorkflowRequestLocal;
|
||||
|
||||
import org.libreccm.cdi.utils.CdiUtil;
|
||||
|
||||
public class ItemWorkflowRequestLocal extends WorkflowRequestLocal {
|
||||
|
||||
@Override
|
||||
protected final Object initialValue(final PageState state) {
|
||||
|
||||
final ContentItem item = CMS.getContext().getContentItem();
|
||||
|
||||
// return item.getWorkflow();
|
||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||
final ItemWorkflowRequestLocalHelper helper = cdiUtil
|
||||
.findBean(ItemWorkflowRequestLocalHelper.class);
|
||||
|
||||
return helper.findWorkflowForContentItem(item);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* 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.cms.ui.item;
|
||||
|
||||
import org.hibernate.LazyInitializationException;
|
||||
import org.libreccm.workflow.Workflow;
|
||||
import org.libreccm.workflow.WorkflowRepository;
|
||||
import org.librecms.contentsection.ContentItem;
|
||||
import org.librecms.contentsection.ContentItemRepository;
|
||||
|
||||
import javax.enterprise.context.RequestScoped;
|
||||
import javax.inject.Inject;
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
/**
|
||||
* Helper class for {@link ItemWorkflowRequestLocal} to avoid a
|
||||
* {@link LazyInitializationException} when accessing the workflow of current
|
||||
* content item.
|
||||
*
|
||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||
*/
|
||||
@RequestScoped
|
||||
class ItemWorkflowRequestLocalHelper {
|
||||
|
||||
@Inject
|
||||
private ContentItemRepository itemRepo;
|
||||
|
||||
@Inject
|
||||
private WorkflowRepository workflowRepo;
|
||||
|
||||
@Transactional(Transactional.TxType.REQUIRED)
|
||||
protected Workflow findWorkflowForContentItem(final ContentItem item) {
|
||||
|
||||
final ContentItem contentItem = itemRepo
|
||||
.findById(item.getObjectId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No ContentItem with ID %d in the database.",
|
||||
item.getObjectId())));
|
||||
|
||||
final Workflow workflow;
|
||||
if (contentItem.getWorkflow() == null) {
|
||||
workflow = null;
|
||||
} else {
|
||||
workflow = workflowRepo
|
||||
.findById(contentItem.getWorkflow().getWorkflowId())
|
||||
.orElseThrow(() -> new IllegalArgumentException(String
|
||||
.format("No Workflow with ID %d in the database.",
|
||||
contentItem.getWorkflow().getWorkflowId())));
|
||||
}
|
||||
|
||||
return workflow;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,372 +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.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 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.libreccm.workflow.TaskDependency;
|
||||
import org.librecms.contentsection.ContentItemRepository;
|
||||
import org.librecms.contentsection.ContentSectionManager;
|
||||
import org.librecms.dispatcher.ItemResolver;
|
||||
|
||||
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().get();
|
||||
|
||||
// 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<TaskDependency> blockingTasks = task
|
||||
.getBlockingTasks();
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (final TaskDependency blocking : blockingTasks) {
|
||||
graph.addEdge(task, blocking, null);
|
||||
builder.append(blocking
|
||||
.getBlockingTask()
|
||||
.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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -19,7 +19,6 @@
|
|||
package org.librecms.contenttypes;
|
||||
|
||||
import com.arsdigita.bebop.FormSection;
|
||||
import com.arsdigita.cms.ui.authoring.PageCreateForm;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
|
|
|
|||
Loading…
Reference in New Issue