diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/BaseForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/BaseForm.java index 9c69fd08a..b1b991738 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/BaseForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/BaseForm.java @@ -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; diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java index d9d7343ac..81c00d596 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java @@ -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(); } /** diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ContentItemRequestLocal.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemRequestLocal.java similarity index 97% rename from ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ContentItemRequestLocal.java rename to ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemRequestLocal.java index f37cb5643..e33167548 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ContentItemRequestLocal.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemRequestLocal.java @@ -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; diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/FormSecurityListener.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/FormSecurityListener.java index e9e0577b4..97240dfa4 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/FormSecurityListener.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/FormSecurityListener.java @@ -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; diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/ApplyWorkflowFormSection.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/ApplyWorkflowFormSection.java deleted file mode 100755 index ad1cd176f..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/ApplyWorkflowFormSection.java +++ /dev/null @@ -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 Jens Pelzetter - */ -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 and 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 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); - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/AuthoringKitWizard.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/AuthoringKitWizard.java index d94bc038c..ddb77af3b 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/AuthoringKitWizard.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/AuthoringKitWizard.java @@ -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) { diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/CreationComponent.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/CreationComponent.java deleted file mode 100755 index b636a5d88..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/CreationComponent.java +++ /dev/null @@ -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(); - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/CreationSelector.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/CreationSelector.java deleted file mode 100755 index c33963da1..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/CreationSelector.java +++ /dev/null @@ -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. - * - * Important: 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: - * - *
- *   // The member variable m_parent points to the CreationSelector
- *   SomeContentItem item = somehowCreateTheItem(state);
- *   item.setParent(m_parent.getFolder(state));
- *   m_parent.editItem(state, item);
- * 
- * - * If the creation component wishes to cancel the creation process, it should - * call - * - *
m_parent.redirectBack(state);
- * - * The component may also call - * - *
m_parent.getContentSection(state);
- * - * in order to get the current content section. - * - * @author unknown - * @author Jens Pelzetter - */ -public class CreationSelector extends MetaForm { - - private static final Logger LOGGER = LogManager.getLogger( - CreationSelector.class); - - private final SingleSelectionModel 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 CreationSelector. 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 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 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 createClass = kit - .getCreateComponent(); - final Object[] vals; - - try { - final ItemSelectionModel itemSelectionModel - = new ItemSelectionModel( - type, itemIdParameter); - vals = new Object[]{itemSelectionModel, - this, - selectedLanguageParam}; - - final Constructor 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); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/PageCreateForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/PageCreateForm.java deleted file mode 100755 index 7f54e11e2..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/PageCreateForm.java +++ /dev/null @@ -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 Jens Pelzetter - */ -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); - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/CustomizedPreviewLink.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/CustomizedPreviewLink.java deleted file mode 100644 index a998672e6..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/CustomizedPreviewLink.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.arsdigita.cms.ui.item; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.cms.ui.ContentItemPage; - -/** - *

- * 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. - *

- *

- * An implementation may return {@code null}. In this case - * {@link ContentItemPage} will use the default preview URL. - *

- * - * @author Jens Pelzetter - * @version $Id$ - */ -public interface CustomizedPreviewLink { - - String getPreviewUrl(PageState state); - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguages.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguages.java deleted file mode 100755 index b9088cb74..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguages.java +++ /dev/null @@ -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 Jens Pelzetter - */ -public class ItemLanguages extends LayoutPanel { - - private final ItemSelectionModel selectionModel; -// private final SingleSelectionModel selectedLanguage; - private final LanguageWidget languageWidget; - private final StringParameter selectedLanguageParam; - // private final Submit changeSubmit; - private final Submit createSubmit; - - /** - * Constructs a new ItemLanguages. - * - * @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 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 creatableLangs = l10NManager.creatableLocales( - item).stream() - .map(locale -> locale.toString()) - .collect(Collectors.toList()); - final List 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(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguagesController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguagesController.java deleted file mode 100644 index 411739f8e..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguagesController.java +++ /dev/null @@ -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 Jens Pelzetter - */ -@RequestScoped -class ItemLanguagesController { - - @Inject - private ContentItemRepository itemRepo; - - @Inject - private ContentItemL10NManager itemL10NManager; - - @Inject - private GlobalizationHelper globalizationHelper; - - protected List> retrieveLanguageVariants( - final ContentItem item) { - return retrieveLanguageVariants(item.getObjectId()); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected List> 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 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 createRow(final ContentItem item, - final Locale lang) { - final RowData 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); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguagesTable.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguagesTable.java deleted file mode 100755 index efff8f26e..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguagesTable.java +++ /dev/null @@ -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 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 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 - } - - } - ); - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguagesTableModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguagesTableModel.java deleted file mode 100644 index 8ba74ad03..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguagesTableModel.java +++ /dev/null @@ -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 Jens Pelzetter - */ -class ItemLanguagesTableModel implements TableModel { - - private final Iterator> iterator; - private RowData curentRow; - - protected ItemLanguagesTableModel(final List> 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(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguagesTableModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguagesTableModelBuilder.java deleted file mode 100644 index 599700e33..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemLanguagesTableModelBuilder.java +++ /dev/null @@ -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 Jens Pelzetter - */ -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> rows = controller.retrieveLanguageVariants( - item); - - return new ItemLanguagesTableModel(rows); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemWorkflowRequestLocal.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemWorkflowRequestLocal.java deleted file mode 100755 index 003d717a8..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemWorkflowRequestLocal.java +++ /dev/null @@ -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); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemWorkflowRequestLocalHelper.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemWorkflowRequestLocalHelper.java deleted file mode 100644 index d8f10b622..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/ItemWorkflowRequestLocalHelper.java +++ /dev/null @@ -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 Jens Pelzetter - */ -@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; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/Summary.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/Summary.java deleted file mode 100755 index 324b7d2c5..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/item/Summary.java +++ /dev/null @@ -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 Jens Pelzetter - */ -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 tasks = workflow.getTasks(); - final GraphSet graph = new GraphSet(); - - for (final Task task : tasks) { - final List 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 taskList = new ArrayList<>(); - outer: - while (graph.nodeCount() > 0) { - @SuppressWarnings("unchecked") - final List 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 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 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(); - } - -} diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/AuthoringKit.java b/ccm-cms/src/main/java/org/librecms/contenttypes/AuthoringKit.java index 3d5018b58..50c7bd6ad 100644 --- a/ccm-cms/src/main/java/org/librecms/contenttypes/AuthoringKit.java +++ b/ccm-cms/src/main/java/org/librecms/contenttypes/AuthoringKit.java @@ -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;