diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/FlatItemList.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/FlatItemList.java index 522b564b9..06a2b68af 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/FlatItemList.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/FlatItemList.java @@ -41,7 +41,6 @@ import com.arsdigita.cms.CMS; import org.librecms.contentsection.ContentSection; import com.arsdigita.cms.ui.authoring.CreationSelector; -import com.arsdigita.cms.ui.authoring.news.NewItemForm; import com.arsdigita.cms.ui.folder.FolderCreateForm; import com.arsdigita.cms.ui.folder.FolderEditorForm; import com.arsdigita.cms.ui.folder.FolderManipulator; @@ -51,7 +50,6 @@ import com.arsdigita.cms.ui.folder.FolderSelectionModel; import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.toolbox.ui.ActionGroup; -import com.arsdigita.ui.CcmObjectSelectionModel; import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.security.PermissionChecker; @@ -84,8 +82,6 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener, private final FolderRequestLocal folderRequestLocal; - private final NewItemForm newItemForm; - private final SingleSelectionModel typeSelectionModel; private final CreationSelector creationSelector; @@ -177,10 +173,6 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener, editFolderAction.addActionListener(this); browseActions.addAction(editFolderAction); - newItemForm = new SectionNewItemForm("newItem"); - newItemForm.addProcessListener(this); - browseActions.addAction(newItemForm); - permissionsSegment = addSegment(); permissionsSegment.setIdAttr("folder-permissions"); @@ -283,7 +275,6 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener, } createFolderAction.setVisible(state, newItem); - newItemForm.setVisible(state, newItem); final boolean editItem = permissionChecker.isPermitted( ItemPrivileges.EDIT, folder); @@ -350,11 +341,7 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener, public void process(final FormSectionEvent event) { final PageState state = event.getPageState(); final Object source = event.getSource(); - if (source == newItemForm) { - final Long typeID = newItemForm.getTypeID(state); - typeSelectionModel.setSelectedKey(state, typeID); - newItemMode(state); - } else if (source == folderCreator || source == folderEditor) { + if (source == folderCreator || source == folderEditor) { browseMode(state); } else if (source == folderManipulator.getItemView()) { // Hide everything except for the browseSeg @@ -439,19 +426,6 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener, // } } - private static class SectionNewItemForm extends NewItemForm { - - public SectionNewItemForm(final String name) { - super(name); - } - - @Override - public ContentSection getContentSection(final PageState state) { - return CMS.getContext().getContentSection(); - } - - } - /** * Getting the GlobalizedMessage using a CMS Class targetBundle. * diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/article/ArticlePropertiesStep.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/article/ArticlePropertiesStep.java deleted file mode 100755 index d991c8fde..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/article/ArticlePropertiesStep.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * Copyright (C) 2002-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.article; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.ItemSelectionModel; - -import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; -import com.arsdigita.cms.ui.authoring.BasicPageForm; -import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; - -import org.librecms.CmsConstants; - -import java.util.Objects; - -/** - * Authoring step to edit the simple attributes of the Article content type (and - * its subclasses). The attributes edited are 'name', 'title', 'article date', - * 'location', 'lead', and 'article type'. This authoring step replaces the - * {@code com.arsdigita.ui.authoring.PageEdit} step for this type. - */ -public class ArticlePropertiesStep extends GenericArticlePropertiesStep { - - /** - * The name of the editing sheet added to this step - */ - public final static String EDIT_SHEET_NAME = "edit"; - - private final StringParameter selectedLanguageParam; - - public ArticlePropertiesStep(final ItemSelectionModel itemModel, - final AuthoringKitWizard parent, - final StringParameter selectedLanguageParam) { - - super(itemModel, parent, selectedLanguageParam); - - Objects.requireNonNull(selectedLanguageParam); - - this.selectedLanguageParam = selectedLanguageParam; - } - - @Override - protected void createEditSheet(final ItemSelectionModel itemModel, - final StringParameter selectedLanguageParam) { - - final BasicPageForm editSheet = new ArticlePropertyForm( - itemModel, - this, - selectedLanguageParam); - add(EDIT_SHEET_NAME, - new GlobalizedMessage("cms.ui.edit", CmsConstants.CMS_BUNDLE), - new WorkflowLockedComponentAccess(editSheet, itemModel), - editSheet.getSaveCancelSection().getCancelButton()); - } - - @Override - protected void setDisplayComponent( - final ItemSelectionModel itemModel) { - setDisplayComponent(getArticlePropertySheet(itemModel, - selectedLanguageParam)); - } - - /** - * Returns a component that displays the properties of the Article specified - * by the ItemSelectionModel passed in. - * - * @param itemModel The ItemSelectionModel to use - * @param selectedLanguageParam - * - * @pre itemModel != null - * @return A component to display the state of the basic properties of the - * release - */ - public static Component getArticlePropertySheet( - final ItemSelectionModel itemModel, - final StringParameter selectedLanguageParam) { - - final DomainObjectPropertySheet sheet - = (DomainObjectPropertySheet) getGenericArticlePropertySheet( - itemModel, - selectedLanguageParam); - - sheet.add(new GlobalizedMessage("cms.contenttypes.ui.lead", - CmsConstants.CMS_BUNDLE), - "description"); - - return sheet; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/article/ArticlePropertyForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/article/ArticlePropertyForm.java deleted file mode 100755 index 64420f5f1..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/article/ArticlePropertyForm.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright (C) 2002-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.article; - -import com.arsdigita.bebop.FormData; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormInitListener; -import com.arsdigita.bebop.event.FormProcessListener; -import com.arsdigita.bebop.event.FormSubmissionListener; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.TextArea; -import com.arsdigita.bebop.parameters.NotEmptyValidationListener; -import com.arsdigita.bebop.parameters.ParameterModel; -import com.arsdigita.bebop.parameters.StringInRangeValidationListener; -import com.arsdigita.bebop.parameters.StringParameter; - -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.kernel.KernelConfig; - -import org.librecms.CMSConfig; -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.contenttypes.Article; - -import java.util.Locale; -import java.util.Objects; - -/** - * Form to edit the basic properties of an article. This form can be extended to - * create forms for Article subclasses. - */ -public class ArticlePropertyForm extends GenericArticlePropertyForm - implements FormProcessListener, FormInitListener, FormSubmissionListener { - - public static final String LEAD = "lead"; - - private final ArticlePropertiesStep propertiesStep; - private final StringParameter selectedLanguageParam; - - /** - * Creates a new form to edit the Article object specified by the item - * selection model passed in. - * - * @param itemModel The ItemSelectionModel to use to obtain the - * Article to work on - * @param selectedLanguageParam - */ - public ArticlePropertyForm(final ItemSelectionModel itemModel, - final StringParameter selectedLanguageParam) { - this(itemModel, null, selectedLanguageParam); - } - - /** - * Creates a new form to edit the Article object specified by the item - * selection model passed in. - * - * @param itemModel The ItemSelectionModel to use to obtain the - * Article to work on - * @param propertiesStep The ArticlePropertiesStep which controls - * this form. - * @param selectedLanguageParam - */ - public ArticlePropertyForm( - final ItemSelectionModel itemModel, - final ArticlePropertiesStep propertiesStep, - final StringParameter selectedLanguageParam) { - - super(itemModel, propertiesStep, selectedLanguageParam); - - Objects.requireNonNull(selectedLanguageParam); - - this.propertiesStep = propertiesStep; - this.selectedLanguageParam = selectedLanguageParam; - addSubmissionListener(this); - } - - /** - * Adds widgets to the form. - */ - @Override - protected void addWidgets() { - super.addWidgets(); - - ParameterModel leadParam = new StringParameter(LEAD); - if (CMSConfig.getConfig().isMandatoryDescriptions()) { - leadParam.addParameterListener( - new NotEmptyValidationListener( - new GlobalizedMessage( - "cms.contenttypes.ui.description_missing", - CmsConstants.CMS_BUNDLE))); - } - leadParam - .addParameterListener(new StringInRangeValidationListener(0, - 1000)); - TextArea lead = new TextArea(leadParam); - lead.setLabel(new GlobalizedMessage("cms.contenttypes.ui.lead", - CmsConstants.CMS_BUNDLE)); - lead.setHint(new GlobalizedMessage("cms.contenttypes.ui.lead_hint", - CmsConstants.CMS_BUNDLE)); - lead.setCols(40); - lead.setRows(5); - add(lead); - } - - @Override - public void validate(final FormSectionEvent event) throws - FormProcessException { - super.validate(event); - } - - /** - * Form initialisation hook. Fills widgets with data. - * - * @param event - */ - @Override - public void init(final FormSectionEvent event) { - final FormData data = event.getFormData(); - final PageState state = event.getPageState(); - final Article article = (Article) super.initBasicWidgets(event); - - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - - data.put(LEAD, article.getDescription().getValue(selectedLocale)); - } - - /** - * Cancels streamlined editing. - */ - @Override - public void submitted(final FormSectionEvent event) { - if (propertiesStep != null && getSaveCancelSection().getCancelButton() - .isSelected(event.getPageState())) { - propertiesStep.cancelStreamlinedCreation(event.getPageState()); - } - } - - /** - * Form processing hook. Saves Event object. - * - * @param event - */ - @Override - public void process(final FormSectionEvent event) { - final FormData data = event.getFormData(); - final PageState state = event.getPageState(); - - final Article article = (Article) super.processBasicWidgets(event); - - // save only if save button was pressed - if (article != null - && getSaveCancelSection().getSaveButton() - .isSelected(event.getPageState())) { - - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - - article - .getDescription() - .putValue(selectedLocale, (String) data.get(LEAD)); - - final ContentItemRepository itemRepo = CdiUtil - .createCdiUtil() - .findBean(ContentItemRepository.class); - itemRepo.save(article); - } - if (propertiesStep != null) { - propertiesStep.maybeForwardToNextStep(event.getPageState()); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/article/ArticleTextBody.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/article/ArticleTextBody.java deleted file mode 100755 index 7704c4590..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/article/ArticleTextBody.java +++ /dev/null @@ -1,159 +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.article; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.form.SingleSelect; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; -import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil; -import com.arsdigita.cms.ui.authoring.TextBody; - -import org.librecms.contenttypes.Article; - -import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; -import com.arsdigita.kernel.KernelConfig; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.contentsection.ContentItemRepository; - -import java.util.Locale; - -/** - * Displays the current text body of the article and allows the user to edit it, - * by uploading a file or entering text in a text box. - * - * The {@link com.arsdigita.bebop.PropertySheet} class is often used as the - * display component in the default authoring kit steps of this class. - * - * @author Stanislav Freidin (sfreidin@arsdigita.com) - * @author Jens Pelzetter - */ -public class ArticleTextBody extends TextBody { - - private final AuthoringKitWizard authoringKitWizard; - private final ItemSelectionModel itemSelectionModel; - private final StringParameter selectedLanguageParam; - - /** - * Construct a new GenericArticleBody component - * - * @param itemSelectionModel The {@link ItemSelectionModel} which will be - * responsible for loading the current item - * - * @param authoringKitWizard The parent wizard which contains the form. - * The form may use the wizard's methods, such - * as stepForward and stepBack, in its process - * listener. - * @param selectedLanguageParam - */ - public ArticleTextBody(final ItemSelectionModel itemSelectionModel, - final AuthoringKitWizard authoringKitWizard, - final StringParameter selectedLanguageParam) { - - super(itemSelectionModel, selectedLanguageParam); - this.itemSelectionModel = itemSelectionModel; - this.authoringKitWizard = authoringKitWizard; - this.selectedLanguageParam = selectedLanguageParam; - - // Rest the component when it is hidden - authoringKitWizard - .getList() - .addActionListener(event -> reset(event.getPageState())); - - // Set the right component access on the forms - final Component uploadComponent = getComponent(FILE_UPLOAD); - if (uploadComponent != null) { - setComponentAccess(FILE_UPLOAD, - new WorkflowLockedComponentAccess( - uploadComponent, itemSelectionModel)); - } - final Component textEntryComponent = getComponent(TEXT_ENTRY); - setComponentAccess(TEXT_ENTRY, - new WorkflowLockedComponentAccess( - textEntryComponent, itemSelectionModel)); - } - - /** - * Adds the options for the mime type select widget of - * GenericArticleForm and sets the default mime type. - * - * @param mimeSelect - */ - @Override - protected void setMimeTypeOptions(final SingleSelect mimeSelect) { - mimeSelect.addOption(new Option("text/html", "HTML Text")); - mimeSelect.setOptionSelected("text/html"); - } - - /** - * Updates the text for the currently selected locale. - * - * @param state the current page state - * @param text the new text for the currently selected locale - */ - @Override - protected void updateText(final PageState state, - final String text) { - - final Article article = getSelectedArticle(state); - - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - - article.getText().putValue(selectedLocale, text); - - final ContentItemRepository itemRepo = CdiUtil - .createCdiUtil() - .findBean(ContentItemRepository.class); - itemRepo.save(article); - } - - /** - * Get the current {@link Article} - * - * @param state The current page state. - * - * @return The currently selected article. - */ - protected Article getSelectedArticle(final PageState state) { - - return (Article) itemSelectionModel.getSelectedObject(state); - } - - @Override - protected String getTextPropertyName() { - return "text"; - } - - @Override - public String getText(final PageState state) { - - final Article article = getSelectedArticle(state); - - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - - return article.getText().getValue(selectedLocale); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/article/GenericArticlePropertiesStep.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/article/GenericArticlePropertiesStep.java deleted file mode 100755 index 9205bd1ad..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/article/GenericArticlePropertiesStep.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (C) 2002-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.article; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.PageState; - -import com.arsdigita.bebop.parameters.StringParameter; - -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; -import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; -import com.arsdigita.cms.ui.authoring.BasicPageForm; -import com.arsdigita.cms.ui.authoring.SimpleEditStep; -import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.librecms.CMSConfig; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentItem; - -import java.text.DateFormat; -import java.util.Objects; - -/** - * Authoring step to edit the simple attributes of the GenericArticle content - * type (and its subclasses). The attributes edited are 'name', 'title', - * 'article date', 'location', and 'article type'. This authoring step replaces - * the {@code com.arsdigita.ui.authoring.PageEdit} step for this type. - */ -public class GenericArticlePropertiesStep extends SimpleEditStep { - - /** - * The name of the editing sheet added to this step - */ - public static final String EDIT_SHEET_NAME = "edit"; - - private DomainObjectPropertySheet domainObjectPropertySheet; - - private final StringParameter selectedLanguageParam; - - public GenericArticlePropertiesStep( - final ItemSelectionModel itemModel, - final AuthoringKitWizard parent, - final StringParameter selectedLanguageParam) { - - super(itemModel, parent, selectedLanguageParam); - - Objects.requireNonNull(selectedLanguageParam); - - this.selectedLanguageParam = selectedLanguageParam; - - setDefaultEditKey(EDIT_SHEET_NAME); - createEditSheet(itemModel, selectedLanguageParam); - - setDisplayComponent(itemModel); - } - - protected void createEditSheet(final ItemSelectionModel itemModel, - final StringParameter selectedLanguageParam) { - - final BasicPageForm editSheet = new GenericArticlePropertyForm( - itemModel, - this, - selectedLanguageParam); - add(EDIT_SHEET_NAME, - new GlobalizedMessage("cms.ui.edit", CmsConstants.CMS_BUNDLE), - new WorkflowLockedComponentAccess(editSheet, itemModel), - editSheet.getSaveCancelSection().getCancelButton()); - } - - protected void setDisplayComponent(final ItemSelectionModel itemModel) { - setDisplayComponent(getGenericArticlePropertySheet( - itemModel, - selectedLanguageParam)); - } - - protected StringParameter getSelectedLanguageParam() { - return selectedLanguageParam; - } - - /** - * Returns a component that displays the properties of the Article specified - * by the ItemSelectionModel passed in. - * - * @param itemModel The ItemSelectionModel to use - * @param selectedLanguageParam - * - * @pre itemModel != null - * @return A component to display the state of the basic properties of the - * release - */ - public static Component getGenericArticlePropertySheet( - final ItemSelectionModel itemModel, - final StringParameter selectedLanguageParam) { - - final DomainObjectPropertySheet sheet = new DomainObjectPropertySheet( - itemModel, - false, - selectedLanguageParam); - - sheet.add(new GlobalizedMessage("cms.contenttypes.ui.title", - CmsConstants.CMS_BUNDLE), - "title"); - sheet.add(new GlobalizedMessage("cms.contenttypes.ui.name", - CmsConstants.CMS_BUNDLE), - "name"); - if (!CMSConfig.getConfig().isHideLaunchDate()) { - sheet.add(new GlobalizedMessage("cms.contenttypes.ui.launch_date", - CmsConstants.CMS_BUNDLE), - "launchDate", - new DomainObjectPropertySheet.AttributeFormatter() { - - @Override - public String format(final Object item, - final String attribute, - final PageState state) { - final ContentItem page = (ContentItem) item; - if (page.getLaunchDate() != null) { - return DateFormat - .getDateInstance(DateFormat.LONG) - .format(page.getLaunchDate()); - } else { - return (String) new GlobalizedMessage( - "cms.ui.unknown", - CmsConstants.CMS_BUNDLE) - .localize(); - } - } - - }); - } - return sheet; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/article/GenericArticlePropertyForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/article/GenericArticlePropertyForm.java deleted file mode 100755 index dbfedcbd9..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/article/GenericArticlePropertyForm.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (C) 2002-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.article; - -import com.arsdigita.bebop.FormData; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.event.FormInitListener; -import com.arsdigita.bebop.event.FormProcessListener; -import com.arsdigita.bebop.event.FormSubmissionListener; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.ItemSelectionModel; - -import org.librecms.contenttypes.Article; - -import com.arsdigita.cms.ui.authoring.BasicPageForm; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.contentsection.ContentItemRepository; - -/** - * Form to edit the basic properties of an article. This form can be extended to - * create forms for Article subclasses. - */ -public class GenericArticlePropertyForm extends BasicPageForm - implements FormProcessListener, FormInitListener, FormSubmissionListener { - - private GenericArticlePropertiesStep propertiesStep; - - /** - * Creates a new form to edit the Article object specified by the item - * selection model passed in. - * - * @param itemModel The ItemSelectionModel to use to obtain the Article to - * work on - * @param selectedLanguageParam - */ - public GenericArticlePropertyForm( - final ItemSelectionModel itemModel, - final StringParameter selectedLanguageParam) { - - this(itemModel, null, selectedLanguageParam); - } - - /** - * Creates a new form to edit the GenericArticle object specified by the - * item selection model passed in. - * - * @param itemModel The ItemSelectionModel to use to obtain the - * GenericArticle to work on - * @param step The GenericArticlePropertiesStep which controls this - * form. - * @param selectedLanguageParam - */ - public GenericArticlePropertyForm( - final ItemSelectionModel itemModel, - final GenericArticlePropertiesStep step, - final StringParameter selectedLanguageParam) { - - super(ID, itemModel, selectedLanguageParam); - propertiesStep = step; - addSubmissionListener(this); - } - - /** - * Adds widgets to the form. - */ - @Override - protected void addWidgets() { - super.addWidgets(); - } - - @Override - public void validate(final FormSectionEvent event) - throws FormProcessException { - - super.validate(event); - } - - /** - * Form initialisation hook. Fills widgets with data. - * - * @param event - */ - @Override - public void init(final FormSectionEvent event) { - // Do some initialization hook stuff - final FormData data = event.getFormData(); - final Article article = (Article) super.initBasicWidgets(event); - } - - /** - * Cancels streamlined editing. - * - * @param event - */ - @Override - public void submitted(final FormSectionEvent event) { - if (propertiesStep != null - && getSaveCancelSection().getCancelButton().isSelected(event - .getPageState())) { - propertiesStep.cancelStreamlinedCreation(event.getPageState()); - } - } - - /** - * Form processing hook. Saves Event object. - * - * @param event - */ - @Override - public void process(final FormSectionEvent event) { - - final Article article = (Article) super.processBasicWidgets(event); - - // save only if save button was pressed - if (article != null - && getSaveCancelSection().getSaveButton().isSelected(event - .getPageState())) { - - final ContentItemRepository itemRepo = CdiUtil - .createCdiUtil() - .findBean(ContentItemRepository.class); - - itemRepo.save(article); - } - if (propertiesStep != null) { - propertiesStep.maybeForwardToNextStep(event.getPageState()); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/event/EventPropertiesStep.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/event/EventPropertiesStep.java deleted file mode 100755 index a26917db9..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/event/EventPropertiesStep.java +++ /dev/null @@ -1,290 +0,0 @@ -/* - * Copyright (C) 2002-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.event; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.parameters.StringParameter; - -import com.arsdigita.cms.ItemSelectionModel; - -import org.librecms.contenttypes.Event; - -import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; -import com.arsdigita.cms.ui.authoring.BasicPageForm; -import com.arsdigita.cms.ui.authoring.SimpleEditStep; -import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.toolbox.ToolboxConstants; -import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.configuration.ConfigurationManager; -import org.libreccm.core.UnexpectedErrorException; -import org.libreccm.l10n.GlobalizationHelper; -import org.librecms.CmsConstants; -import org.librecms.contenttypes.EventConfig; - -import java.beans.BeanInfo; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.text.DateFormat; -import java.util.Arrays; -import java.util.Date; -import java.util.Optional; - -/** - * Authoring step to view/edit the simple attributes of the Event content type - * (and its subclasses). - * - * The attributes edited are {@code name}, {@code title}, {@code lead}, - * {@code startdate}, {@code starttime}, {@code end date}, - * {@code endtime},{@code event date} (literal description of date), - * {@code location}, {@code main contributor} {@code event type}, - * {@code map link}, and {@code cost}. - * - * This authoring step replaces the {@code com.arsdigita.ui.authoring.PageEdit} - * step for this type. - */ -public class EventPropertiesStep extends SimpleEditStep { - - /** - * The name of the editing sheet added to this step - */ - public static String EDIT_SHEET_NAME = "edit"; - - /** - * - * @param itemSelectionModel - * @param authoringKitWizard - * @param selectedLanguageParam - */ - public EventPropertiesStep(final ItemSelectionModel itemSelectionModel, - final AuthoringKitWizard authoringKitWizard, - final StringParameter selectedLanguageParam) { - - super(itemSelectionModel, authoringKitWizard, selectedLanguageParam); - - setDefaultEditKey(EDIT_SHEET_NAME); - BasicPageForm editSheet; - - editSheet = new EventPropertyForm(itemSelectionModel, - this, - selectedLanguageParam); - add(EDIT_SHEET_NAME, - new GlobalizedMessage("cms.ui.edit", CmsConstants.CMS_BUNDLE), - new WorkflowLockedComponentAccess(editSheet, itemSelectionModel), - editSheet.getSaveCancelSection().getCancelButton()); - - setDisplayComponent(getEventPropertySheet(itemSelectionModel, - selectedLanguageParam)); - } - - /** - * Returns a component that displays the properties of the Event specified - * by the ItemSelectionModel passed in. - * - * @param itemSelectionModel The ItemSelectionModel to use - * @param selectedLanguageParam - * - * @return A component to display the state of the basic properties of the - * release - * - */ - public static Component getEventPropertySheet( - final ItemSelectionModel itemSelectionModel, - final StringParameter selectedLanguageParam) { - - final DomainObjectPropertySheet sheet = new DomainObjectPropertySheet( - itemSelectionModel, - false, - selectedLanguageParam); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ConfigurationManager confManager = cdiUtil - .findBean(ConfigurationManager.class); - final EventConfig eventConfig = confManager - .findConfiguration(EventConfig.class); - - sheet.add(new GlobalizedMessage("cms.contenttypes.ui.title", - CmsConstants.CMS_BUNDLE), - "title"); - sheet.add(new GlobalizedMessage("cms.contenttypes.ui.name", - CmsConstants.CMS_BUNDLE), - "name"); - sheet.add(new GlobalizedMessage("cms.contenttypes.ui.event.lead", - CmsConstants.CMS_BUNDLE), - "description"); - - sheet.add(new GlobalizedMessage("cms.contenttypes.ui.event.start_time", - CmsConstants.CMS_BUNDLE), - "startDate", - new DateTimeAttributeFormatter()); - - sheet.add(new GlobalizedMessage("cms.contenttypes.ui.event.end_time", - CmsConstants.CMS_BUNDLE), - "endDate", - new DateTimeAttributeFormatter()); - if (!eventConfig.isHideDateDescription()) { - sheet.add( - new GlobalizedMessage( - "cms.contenttypes.ui.event.date_description", - CmsConstants.CMS_BUNDLE), - "eventDate"); - } - - sheet.add(new GlobalizedMessage("cms.contenttypes.ui.event.location", - CmsConstants.CMS_BUNDLE), - "location"); - - if (!eventConfig.isHideMainContributor()) { - sheet.add( - new GlobalizedMessage( - "cms.contenttypes.ui.event.main_contributor", - CmsConstants.CMS_BUNDLE), - "mainContributor"); - } - if (!eventConfig.isHideEventType()) { - sheet.add( - new GlobalizedMessage("cms.contenttypes.ui.event.event_type", - CmsConstants.CMS_BUNDLE), - "eventType"); - } - if (!eventConfig.isHideLinkToMap()) { - sheet.add( - new GlobalizedMessage("cms.contenttypes.ui.event.link_to_map", - CmsConstants.CMS_BUNDLE), - "mapLink"); - } - if (!eventConfig.isHideCost()) { - sheet.add(new GlobalizedMessage("cms.contenttypes.ui.event.cost", - CmsConstants.CMS_BUNDLE), - "cost"); - } - return sheet; - } - - /** - * Private class which implements an AttributeFormatter interface for date - * values. Its format(...) class returns a string representation for either - * a false or a true value. - */ - private static class DateTimeAttributeFormatter - implements DomainObjectPropertySheet.AttributeFormatter { - - /** - * Constructor, does nothing. - */ - public DateTimeAttributeFormatter() { - } - - /** - * Formatter for the value of an attribute. - * - * It currently relays on the prerequisite that the passed in property - * attribute is in fact a date property. No type checking yet! - * - * Note: the format method has to be executed at each page request. Take - * care to properly adjust globalization and localization here! - * - * @param obj Object containing the attribute to format. - * @param attribute Name of the attribute to retrieve and format - * @param state PageState of the request - * - * @return A String representation of the retrieved boolean attribute of - * the domain object. - */ - @Override - public String format(final Object obj, - final String attribute, - final PageState state) { - - if (obj != null && obj instanceof Event) { - - final BeanInfo beanInfo; - try { - beanInfo = Introspector.getBeanInfo(Event.class); - } catch (IntrospectionException ex) { - throw new UnexpectedErrorException(ex); - } - final Optional propertyDescriptor = Arrays - .stream(beanInfo.getPropertyDescriptors()) - .filter(current -> attribute.equals(current.getName())) - .findAny(); - - if (propertyDescriptor.isPresent()) { - - final GlobalizationHelper globalizationHelper = CdiUtil - .createCdiUtil().findBean(GlobalizationHelper.class); - - final Method readMethod = propertyDescriptor - .get() - .getReadMethod(); - - final Object result; - try { - result = readMethod.invoke(obj); - } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { - throw new UnexpectedErrorException(ex); - } - - if (result == null) { - return (String) new GlobalizedMessage( - "toolbox.ui.na", ToolboxConstants.TOOLBOX_BUNDLE) - .localize(); - } else if (result instanceof Date) { - return DateFormat - .getDateTimeInstance( - DateFormat.LONG, - DateFormat.SHORT, - globalizationHelper.getNegotiatedLocale()) - .format((Date) result); - } else { - throw new IllegalArgumentException(String - .format( - "Value is not an instance of \"%s\" but is an " - + "instance of \"%s\".", - Date.class.getName(), - result.getClass().getName())); - } - - } else { - return (String) new GlobalizedMessage( - "toolbox.ui.na", - ToolboxConstants.TOOLBOX_BUNDLE) - .localize(); - } - - } else { - - return (String) new GlobalizedMessage( - "toolbox.ui.na", - ToolboxConstants.TOOLBOX_BUNDLE) - .localize(); - } - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/event/EventPropertyForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/event/EventPropertyForm.java deleted file mode 100755 index a24b99f01..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/event/EventPropertyForm.java +++ /dev/null @@ -1,596 +0,0 @@ -/* - * Copyright (C) 2002-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.event; - -import com.arsdigita.bebop.FormData; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormInitListener; -import com.arsdigita.bebop.event.FormProcessListener; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.event.FormSubmissionListener; -import com.arsdigita.bebop.form.TextArea; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.bebop.form.Time; -import com.arsdigita.bebop.parameters.DateParameter; -import com.arsdigita.bebop.parameters.NotNullValidationListener; -import com.arsdigita.bebop.parameters.ParameterModel; -import com.arsdigita.bebop.parameters.StringInRangeValidationListener; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.parameters.TimeParameter; -import com.arsdigita.bebop.parameters.TrimmedStringParameter; -import com.arsdigita.cms.ItemSelectionModel; - -import org.librecms.contenttypes.Event; - -import com.arsdigita.cms.ui.CMSDHTMLEditor; -import com.arsdigita.cms.ui.authoring.BasicPageForm; -import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.kernel.KernelConfig; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.configuration.ConfigurationManager; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.contenttypes.EventConfig; - -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.Locale; -import java.util.Objects; - -/** - * Form to edit the basic properties of an {@link Event} object. - * - * Used by {@link EventPropertiesStep} authoring kit step. - * - * This form can be extended to create forms for Event subclasses. - * - */ -public class EventPropertyForm - extends BasicPageForm - implements FormProcessListener, - FormInitListener, - FormSubmissionListener { - - private final static Logger LOGGER = LogManager - .getLogger(EventPropertyForm.class); - - /** - * Name of this form - */ - public static final String ID = "event_edit"; - - private EventPropertiesStep eventPropertiesStep; - /** - * event date parameter name - */ - public static final String START_DATE = "startDate"; - public static final String END_DATE = "endDate"; - public static final String START_TIME = "startTime"; - public static final String END_TIME = "endTime"; - public static final String EVENT_DATE = "eventDate"; - /** - * location parameter name - */ - public static final String LOCATION = "location"; - /** - * lead parameter name - */ - public static final String LEAD = "lead"; - /** - * Main contributor parameter name - */ - public static final String MAIN_CONTRIBUTOR = "main_contributor"; - /** - * Event type parameter name - */ - public static final String EVENT_TYPE = "event_type"; - /** - * Map link parameter name - */ - public static final String MAP_LINK = "map_link"; - /** - * cost parameter name - */ - public static final String COST = "cost"; - - private final StringParameter selectedLanguageParam; - - /* DateWidgets have to be accessible later on */ - private com.arsdigita.bebop.form.Date startDateField; - private com.arsdigita.bebop.form.Date endDateField; - - /** - * Creates a new form to edit the Event object specified by the item - * selection model passed in. - * - * @param itemSelectionModel The ItemSelectionModel to use to obtain the - * Event to work on - * @param selectedLanguageParam - * - */ - public EventPropertyForm(final ItemSelectionModel itemSelectionModel, - final StringParameter selectedLanguageParam) { - this(itemSelectionModel, null, selectedLanguageParam); - } - - /** - * Creates a new form to edit the Event object specified by the item - * selection model passed in. - * - * @param itemSelectionModel The ItemSelectionModel to use to obtain the - * Event to work on - * @param eventPropertiesStep The EventPropertiesStep which controls this - * form. - * @param selectedLanguageParam - * - */ - public EventPropertyForm(final ItemSelectionModel itemSelectionModel, - final EventPropertiesStep eventPropertiesStep, - final StringParameter selectedLanguageParam) { - - super(ID, itemSelectionModel, selectedLanguageParam); - - Objects.requireNonNull(selectedLanguageParam); - - this.eventPropertiesStep = eventPropertiesStep; - this.selectedLanguageParam = selectedLanguageParam; - addSubmissionListener(this); - } - - /** - * Adds widgets to the form. - * - */ - @Override - protected void addWidgets() { - - super.addWidgets(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ConfigurationManager confManager = cdiUtil - .findBean(ConfigurationManager.class); - final EventConfig eventConfig = confManager - .findConfiguration(EventConfig.class); - - /* Summary (lead) */ - final ParameterModel leadParam = new StringParameter(LEAD); - if (!eventConfig.isLeadTextOptional()) { - leadParam.addParameterListener(new NotNullValidationListener()); - } - final TextArea lead = new TextArea(leadParam); - lead.setLabel(new GlobalizedMessage("cms.contenttypes.ui.event.lead", - CmsConstants.CMS_BUNDLE)); - lead.setCols(50); - lead.setRows(5); - add(lead); - - /* Start date and time */ - final ParameterModel eventStartDateParam = new DateParameter(START_DATE); - eventStartDateParam - .addParameterListener(new NotNullValidationListener()); - // Use bebop date instead of java.util.date - startDateField = new com.arsdigita.bebop.form.Date(eventStartDateParam); - startDateField.setLabel(new GlobalizedMessage( - "cms.contenttypes.ui.event.start_date", - CmsConstants.CMS_BUNDLE)); - // Set the upper und lower boundary of the year select box - startDateField - .setYearRange( - eventConfig.getStartYear(), - GregorianCalendar.getInstance().get(Calendar.YEAR) - + eventConfig.getEndYearDelta()); - add(startDateField); - - final ParameterModel eventStartTimeParam = new TimeParameter(START_TIME); - if (!eventConfig.isStartTimeOptional()) { - eventStartTimeParam.addParameterListener( - new NotNullValidationListener()); - } - final Time startTime = new Time(eventStartTimeParam); - startTime - .setLabel( - new GlobalizedMessage("cms.contenttypes.ui.event.start_time", - CmsConstants.CMS_BUNDLE)); - add(startTime); - - /* End date and time */ - final ParameterModel eventEndDateParam = new DateParameter(END_DATE); - // Use bebop date instead of java.util.date - endDateField = new com.arsdigita.bebop.form.Date(eventEndDateParam); - endDateField - .setLabel( - new GlobalizedMessage("cms.contenttypes.ui.event.end_date", - CmsConstants.CMS_BUNDLE)); - endDateField - .setHint( - new GlobalizedMessage("cms.contenttypes.ui.event.end_date_hint", - CmsConstants.CMS_BUNDLE)); - endDateField - .setYearRange(eventConfig.getStartYear(), - GregorianCalendar.getInstance().get(Calendar.YEAR) - + eventConfig.getEndYearDelta()); - add(endDateField); - - final ParameterModel eventEndTimeParam = new TimeParameter(END_TIME); - final Time endTime = new Time(eventEndTimeParam); - endTime - .setLabel( - new GlobalizedMessage("cms.contenttypes.ui.event.end_time", - CmsConstants.CMS_BUNDLE)); - endTime - .setHint( - new GlobalizedMessage("cms.contenttypes.ui.event.end_time_hint", - CmsConstants.CMS_BUNDLE)); - add(endTime); - - - /* optional additional / literal date description */ - if (!eventConfig.isHideDateDescription()) { - final ParameterModel eventDateParam - = new StringParameter(EVENT_DATE); - if (eventConfig.isUseHtmlDateDescription()) { - CMSDHTMLEditor eventDate = new CMSDHTMLEditor(eventDateParam); - eventDate.setLabel( - new GlobalizedMessage( - "cms.contenttypes.ui.event.date_description", - CmsConstants.CMS_BUNDLE)); - eventDate.setHint(new GlobalizedMessage( - "cms.contenttypes.ui.event.date_description_hint", - CmsConstants.CMS_BUNDLE)); - eventDate.setCols(40); - eventDate.setRows(8); - add(eventDate); - } else { - eventDateParam.addParameterListener( - new StringInRangeValidationListener(0, 100)); - TextArea eventDate = new TextArea(eventDateParam); - eventDate - .setLabel(new GlobalizedMessage( - "cms.contenttypes.ui.event.date_description", - CmsConstants.CMS_BUNDLE)); - eventDate.setHint(new GlobalizedMessage( - "cms.contenttypes.ui.event.date_description_hint", - CmsConstants.CMS_BUNDLE)); - eventDate.setCols(50); - eventDate.setRows(2); - add(eventDate); - } - } - - - /* extensive description of location */ - final ParameterModel locationParam = new StringParameter(LOCATION); - final CMSDHTMLEditor location = new CMSDHTMLEditor(locationParam); - location - .setLabel( - new GlobalizedMessage("cms.contenttypes.ui.event.location", - CmsConstants.CMS_BUNDLE)); - location - .setHint(new GlobalizedMessage( - "cms.contenttypes.ui.event.location_hint", - CmsConstants.CMS_BUNDLE)); - location.setCols(40); - location.setRows(8); - add(location); - - - /* optional: main contributor */ - if (!eventConfig.isHideMainContributor()) { - final ParameterModel mainContributorParam - = new StringParameter(MAIN_CONTRIBUTOR); - final CMSDHTMLEditor mainContributor - = new CMSDHTMLEditor(mainContributorParam); - mainContributor.setLabel( - new GlobalizedMessage( - "cms.contenttypes.ui.event.main_contributor", - CmsConstants.CMS_BUNDLE)); - mainContributor.setHint( - new GlobalizedMessage( - "cms.contenttypes.ui.event.main_contributor_hint", - CmsConstants.CMS_BUNDLE)); - mainContributor.setCols(40); - mainContributor.setRows(10); - add(mainContributor); - } - - - /* optional: event type */ - if (!eventConfig.isHideEventType()) { - final ParameterModel eventTypeParam - = new StringParameter(EVENT_TYPE); - final TextField eventType = new TextField(eventTypeParam); - eventType.setLabel( - new GlobalizedMessage( - "cms.contenttypes.ui.event.event_type", - CmsConstants.CMS_BUNDLE)); - eventType.setHint( - new GlobalizedMessage( - "cms.contenttypes.ui.event.event_type_hint", - CmsConstants.CMS_BUNDLE)); - eventType.setSize(30); - eventType.setMaxLength(30); - add(eventType); - } - - - /* optional: link to map */ - if (!eventConfig.isHideLinkToMap()) { - final ParameterModel mapLinkParam = new StringParameter(MAP_LINK); - final TextArea mapLink = new TextArea(mapLinkParam); - mapLink.setLabel(new GlobalizedMessage( - "cms.contenttypes.ui.event.link_to_map", - CmsConstants.CMS_BUNDLE)); - mapLink.setHint(new GlobalizedMessage( - "cms.contenttypes.ui.event.link_to_map_hint", - CmsConstants.CMS_BUNDLE)); - mapLink.setCols(40); - mapLink.setRows(2); - add(mapLink); - } - - - /* optional: costs */ - if (!eventConfig.isHideCost()) { - final ParameterModel costParam = new TrimmedStringParameter(COST); - final TextField cost = new TextField(costParam); - cost.setLabel( - new GlobalizedMessage( - "cms.contenttypes.ui.event.cost", - CmsConstants.CMS_BUNDLE)); - cost.setHint(new GlobalizedMessage( - "cms.contenttypes.ui.event.cost_hint", - CmsConstants.CMS_BUNDLE)); - cost.setSize(30); - cost.setMaxLength(30); - add(cost); - } - - } - - /** - * - * @param event - * - * @throws FormProcessException - */ - @Override - public void validate(final FormSectionEvent event) - throws FormProcessException { - - super.validate(event); - - final FormData data = event.getFormData(); - java.util.Date startDate = data.getDate(START_DATE); - java.util.Date endDate = data.getDate(END_DATE); - - if (endDate != null) { - if (startDate == null || startDate.compareTo(endDate) > 0) { - throw new FormProcessException( - "End date must be after start date", - new GlobalizedMessage( - "cms.contenttypes.ui.event.end_date_after_start_date", - CmsConstants.CMS_BUNDLE) - ); - } - } - } - - /** - * Form initialisation hook. Fills widgets with data. - * - * @param event - */ - @Override - public void init(final FormSectionEvent event) { - // Do some initialization hook stuff - final FormData data = event.getFormData(); - final PageState state = event.getPageState(); - final Event item = (Event) super.initBasicWidgets(event); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ConfigurationManager confManager = cdiUtil - .findBean(ConfigurationManager.class); - final EventConfig eventConfig = confManager - .findConfiguration(EventConfig.class); - - // Start date should always be set - final java.util.Date startDate; - if (item.getStartDate() == null) { - // new Date is initialised to current time - startDate = new java.util.Date(); - } else { - startDate = item.getStartDate(); - } - startDateField.addYear(startDate); - - // End date can be null - final java.util.Date endDate; - if (item.getEndDate() == null) { - // new Date is initialised to current time - endDate = new java.util.Date(); - } else { - endDate = item.getEndDate(); - } - endDateField.addYear(endDate); - - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - - data.put(LEAD, item.getDescription().getValue(selectedLocale)); - data.put(START_DATE, startDate); - data.put(START_TIME, startDate); - data.put(END_DATE, endDate); - data.put(END_TIME, endDate); - if (!eventConfig.isHideDateDescription()) { - data.put(EVENT_DATE, - item.getEventDate().getValue(selectedLocale)); - } - data.put(LOCATION, item.getLocation().getValue(selectedLocale)); - if (!eventConfig.isHideMainContributor()) { - data.put(MAIN_CONTRIBUTOR, - item.getMainContributor().getValue(selectedLocale)); - } - if (!eventConfig.isHideEventType()) { - data.put(EVENT_TYPE, - item.getEventType().getValue(selectedLocale)); - } - if (!eventConfig.isHideLinkToMap()) { - data.put(MAP_LINK, item.getMapLink()); - } - if (!eventConfig.isHideCost()) { - data.put(COST, - item.getCost().getValue(selectedLocale)); - } - } - - /** - * Cancels streamlined editing. - * - * @param event - */ - @Override - public void submitted(final FormSectionEvent event) { - if (eventPropertiesStep != null - && getSaveCancelSection() - .getCancelButton() - .isSelected(event.getPageState())) { - eventPropertiesStep.cancelStreamlinedCreation(event.getPageState()); - } - } - - /** - * Form processing hook. Saves Event object. - * - * @param event - */ - @Override - public void process(final FormSectionEvent event) { - - final FormData data = event.getFormData(); - - final Event item = (Event) super.processBasicWidgets(event); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ConfigurationManager confManager = cdiUtil - .findBean(ConfigurationManager.class); - final EventConfig eventConfig = confManager - .findConfiguration(EventConfig.class); - final PageState state = event.getPageState(); - - // save only if save button was pressed - if (item != null - && getSaveCancelSection().getSaveButton().isSelected(state)) { - - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - - final java.util.Date startDate = (java.util.Date) data - .get(START_DATE); - final java.util.Date startTime = (java.util.Date) data - .get(START_TIME); - final java.util.Date endDate = (java.util.Date) data.get(END_DATE); - final java.util.Date endTime = (java.util.Date) data.get(END_TIME); - - final Calendar startDateCal = Calendar.getInstance(); - final Calendar startTimeCal = Calendar.getInstance(); - final Calendar endDateCal = Calendar.getInstance(); - final Calendar endTimeCal = Calendar.getInstance(); - startDateCal.setTime(startDate); - startTimeCal.setTime(startTime); - endDateCal.setTime(endDate); - endTimeCal.setTime(endTime); - - final int startYear = startDateCal.get(Calendar.YEAR); - final int startMonth = startDateCal.get(Calendar.MONTH); - final int startDay = startDateCal.get(Calendar.DAY_OF_MONTH); - final int startHour = startTimeCal.get(Calendar.HOUR_OF_DAY); - final int startMinute = startTimeCal.get(Calendar.MINUTE); - - final int endYear = endDateCal.get(Calendar.YEAR); - final int endMonth = endDateCal.get(Calendar.MONTH); - final int endDay = endDateCal.get(Calendar.DAY_OF_MONTH); - final int endHour = endTimeCal.get(Calendar.HOUR_OF_DAY); - final int endMinute = endTimeCal.get(Calendar.MINUTE); - - final Calendar startDateTimeCal = Calendar.getInstance(); - final Calendar endDateTimeCal = Calendar.getInstance(); - - startDateTimeCal.set(Calendar.YEAR, startYear); - startDateTimeCal.set(Calendar.MONTH, startMonth); - startDateTimeCal.set(Calendar.DAY_OF_MONTH, startDay); - startDateTimeCal.set(Calendar.HOUR_OF_DAY, startHour); - startDateTimeCal.set(Calendar.MINUTE, startMinute); - - endDateTimeCal.set(Calendar.YEAR, endYear); - endDateTimeCal.set(Calendar.MONTH, endMonth); - endDateTimeCal.set(Calendar.DAY_OF_MONTH, endDay); - endDateTimeCal.set(Calendar.HOUR_OF_DAY, endHour); - endDateTimeCal.set(Calendar.MINUTE, endMinute); - - final java.util.Date startDateTime = startDateTimeCal.getTime(); - final java.util.Date endDateTime = endDateTimeCal.getTime(); - - item.setStartDate(startDateTime); - item.setEndDate(endDateTime); - //date_description - if (!eventConfig.isHideDateDescription()) { - item.getEventDate().putValue(selectedLocale, - (String) data.get(EVENT_DATE)); - } - - if (!eventConfig.isHideMainContributor()) { - item - .getMainContributor() - .putValue(selectedLocale, - (String) data.get(MAIN_CONTRIBUTOR)); - } - if (!eventConfig.isHideEventType()) { - item - .getEventType() - .putValue(selectedLocale, - (String) data.get(EVENT_TYPE)); - } - if (!eventConfig.isHideLinkToMap()) { - item.setMapLink((String) data.get(MAP_LINK)); - } - item.getLocation().putValue(selectedLocale, - (String) data.get(LOCATION)); - item.getDescription().putValue(selectedLocale, - (String) data.get(LEAD)); - if (!eventConfig.isHideCost()) { - item.getCost().putValue(selectedLocale, - (String) data.get(COST)); - } - - final ContentItemRepository itemRepo = cdiUtil - .findBean(ContentItemRepository.class); - - itemRepo.save(item); - } - if (eventPropertiesStep != null) { - eventPropertiesStep.maybeForwardToNextStep(event.getPageState()); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/event/EventTextBody.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/event/EventTextBody.java deleted file mode 100644 index 202de8a2e..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/event/EventTextBody.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright (C) 2021 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.authoring.event; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.form.SingleSelect; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; -import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil; -import com.arsdigita.cms.ui.authoring.TextBody; -import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; -import com.arsdigita.kernel.KernelConfig; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.contenttypes.Event; - -import java.util.Locale; - -import static com.arsdigita.cms.ui.authoring.TextBody.*; - -/** - * - * @author Jens Pelzetter - */ -public class EventTextBody extends TextBody { - - private final ItemSelectionModel itemSelectionModel; - private final StringParameter selectedLanguageParam; - - public EventTextBody(final ItemSelectionModel itemSelectionModel, - final AuthoringKitWizard authoringKitWizard, - final StringParameter selectedLanguageParam) { - - super(itemSelectionModel, selectedLanguageParam); - - this.itemSelectionModel = itemSelectionModel; - this.selectedLanguageParam = selectedLanguageParam; - - // Rest the component when it is hidden - authoringKitWizard - .getList() - .addActionListener(event -> reset(event.getPageState())); - - // Set the right component access on the forms - final Component uploadComponent = getComponent(FILE_UPLOAD); - if (uploadComponent != null) { - setComponentAccess(FILE_UPLOAD, - new WorkflowLockedComponentAccess( - uploadComponent, itemSelectionModel)); - } - final Component textEntryComponent = getComponent(TEXT_ENTRY); - setComponentAccess(TEXT_ENTRY, - new WorkflowLockedComponentAccess( - textEntryComponent, itemSelectionModel)); - } - - /** - * Adds the options for the mime type select widget of - * GenericArticleForm and sets the default mime type. - * - * @param mimeSelect - */ - @Override - protected void setMimeTypeOptions(final SingleSelect mimeSelect) { - mimeSelect.addOption(new Option("text/html", "HTML Text")); - mimeSelect.setOptionSelected("text/html"); - } - - protected Event getSelectedEvent(final PageState state) { - - return (Event) itemSelectionModel.getSelectedItem(state); - } - - @Override - protected String getTextPropertyName() { - - return "text"; - } - - @Override - public String getText(final PageState state) { - - final Event event = getSelectedEvent(state); - - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - - return event.getText().getValue(selectedLocale); - - } - - @Override - protected void updateText(final PageState state, final String text) { - - final Event event = getSelectedEvent(state); - - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - - event.getText().putValue(selectedLocale, text); - final ContentItemRepository itemRepo = CdiUtil - .createCdiUtil() - .findBean(ContentItemRepository.class); - itemRepo.save(event); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleCreateForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleCreateForm.java deleted file mode 100644 index 19c964fda..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleCreateForm.java +++ /dev/null @@ -1,181 +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.authoring.multipartarticle; - -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.FormInitListener; -import com.arsdigita.bebop.event.FormProcessListener; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.event.FormSubmissionListener; -import com.arsdigita.bebop.event.FormValidationListener; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.authoring.ApplyWorkflowFormSection; -import com.arsdigita.cms.ui.authoring.CreationComponent; -import com.arsdigita.cms.ui.authoring.CreationSelector; -import com.arsdigita.cms.ui.authoring.LanguageWidget; -import com.arsdigita.globalization.GlobalizedMessage; - -import java.util.Date; - -import org.librecms.CMSConfig; -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.Folder; -import org.librecms.contenttypes.MultiPartArticle; - -import java.util.Locale; - -/** - * A form which will create a MultiPartArticle or one of its subclasses. - * - * @author Dave Turner - * @author Jens Pelzetter - */ -public class MultiPartArticleCreateForm - extends MultiPartArticleForm - implements FormInitListener, - FormProcessListener, - FormSubmissionListener, - FormValidationListener, - CreationComponent { - - private final CreationSelector creationSelector; - private ApplyWorkflowFormSection workflowSection; - - public MultiPartArticleCreateForm( - final ItemSelectionModel itemSelectionModel, - final CreationSelector creationSelector, - final StringParameter selectedLanguageParam) { - - super("MultiPartArticleCreate", - itemSelectionModel, - selectedLanguageParam); - - this.creationSelector = creationSelector; - workflowSection.setCreationSelector(creationSelector); - workflowSection.setContentType(itemSelectionModel.getContentType()); - addSubmissionListener(this); - getSaveCancelSection() - .getSaveButton() - .setButtonLabel(new GlobalizedMessage("cms.ui.create", - CmsConstants.CMS_BUNDLE)); - } - - @Override - protected void addWidgets() { - workflowSection = new ApplyWorkflowFormSection(); - add(workflowSection, ColumnPanel.INSERT); - add(new Label(new GlobalizedMessage("cms.ui.language.field", - CmsConstants.CMS_BUNDLE))); - add(new LanguageWidget(LANGUAGE)); - super.addWidgets(); - } - - /** - * Return the ApplyWorkflowFormSection associated with this - * CreationComponent. - * - * @return the ApplyWorkflowFormSection associated with this - * CreationComponent. - */ - @Override - public ApplyWorkflowFormSection getWorkflowSection() { - return workflowSection; - } - - @Override - public void init(final FormSectionEvent event) throws FormProcessException { - // this is currently a no-op - } - - @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( - "Submission cancelled", - new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.submission_cancelled", - CmsConstants.CMS_BUNDLE) - ); - } - } - - @Override - public void validate(final FormSectionEvent event) - throws FormProcessException { - - final Folder folder = creationSelector.getFolder(event.getPageState()); - if (!validateNameUniqueness(folder, event)) { - throw new FormProcessException( - "An item with this name already exists", - new GlobalizedMessage( - "cms.contenttypes.ui.mparticle." - + "an_item_with_this_name_already_exists", - CmsConstants.CMS_BUNDLE) - ); - } - } - - @Override - public 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); - - final Locale locale = new Locale((String) data.get(LANGUAGE)); - - final MultiPartArticle article = createArticle(state, - (String) data.get(NAME), - section, - folder, - locale); - article.getTitle().putValue(locale, (String) data.get(TITLE)); - if (!CMSConfig.getConfig().isHideLaunchDate()) { - article.setLaunchDate((Date) data.get(LAUNCH_DATE)); - } - article - .getSummary() - .putValue(locale, (String) data.get(SUMMARY)); - - workflowSection.applyWorkflow(state, article); - - final CdiUtil cdiUtil =CdiUtil.createCdiUtil(); - final ContentItemRepository itemRepo = cdiUtil - .findBean(ContentItemRepository.class); - itemRepo.save(article); - - creationSelector.editItem(state, article); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleEdit.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleEdit.java deleted file mode 100755 index eb855dacb..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleEdit.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2002-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.multipartarticle; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.parameters.StringParameter; - - -import com.arsdigita.cms.ItemSelectionModel; - - -import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; -import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; -import com.arsdigita.cms.ui.authoring.SimpleEditStep; -import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.librecms.CMSConfig; -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.configuration.ConfigurationManager; -import org.librecms.CmsConstants; - - -/** - * A MultiPartArticle editing component. - * - * @author Dave Turner - * @author Jens Pelzetter - */ -public class MultiPartArticleEdit extends SimpleEditStep { - - - /** - * Constructor. - * - * @param itemSelectionModel the ItemSelectionModel which holds the - * current MutliPartArticle - * @param authoringKitWizard the parent wizard which contains the form - * @param selectedLanguageParam - */ - public MultiPartArticleEdit(final ItemSelectionModel itemSelectionModel, - final AuthoringKitWizard authoringKitWizard, - final StringParameter selectedLanguageParam) { - - super(itemSelectionModel, authoringKitWizard, selectedLanguageParam); - - setDefaultEditKey("edit"); - final MultiPartArticleForm form = new MultiPartArticleEditForm( - itemSelectionModel, - this, - selectedLanguageParam); - add("edit", - new GlobalizedMessage("cms.ui.edit", - CmsConstants.CMS_BUNDLE), - new WorkflowLockedComponentAccess(form, itemSelectionModel), - form.getSaveCancelSection().getCancelButton() - ); - - setDisplayComponent(getMultiPartArticlePropertiesSheet( - itemSelectionModel, - selectedLanguageParam)); - } - - public Component getMultiPartArticlePropertiesSheet( - final ItemSelectionModel itemSelectionModel, - final StringParameter selectedLanguageParam) { - - final DomainObjectPropertySheet sheet = new DomainObjectPropertySheet( - itemSelectionModel, - false, - selectedLanguageParam); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ConfigurationManager confManager = cdiUtil - .findBean(ConfigurationManager.class); - final CMSConfig cmsConfig = confManager - .findConfiguration(CMSConfig.class); - - sheet.add(new GlobalizedMessage("cms.contenttypes.ui.title", - CmsConstants.CMS_BUNDLE), - "title"); - sheet.add(new GlobalizedMessage("cms.contenttypes.ui.name", - CmsConstants.CMS_BUNDLE), - "name"); - if (!cmsConfig.isHideLaunchDate()) { - sheet.add(new GlobalizedMessage("cms.contenttypes.ui.launch_date", - CmsConstants.CMS_BUNDLE), - "launchDate", - new LaunchDateAttributeFormatter()); - } - sheet.add(new GlobalizedMessage("cms.contenttypes.ui.summary", - CmsConstants.CMS_BUNDLE), - "summary"); - - return sheet; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleEditForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleEditForm.java deleted file mode 100755 index a7c7fa2db..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleEditForm.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright (C) 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.multipartarticle; - -import com.arsdigita.bebop.FormData; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.event.FormSubmissionListener; -import com.arsdigita.bebop.parameters.StringParameter; - -import org.librecms.contentsection.Folder; - -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil; - -import org.librecms.contenttypes.MultiPartArticle; - -import com.arsdigita.cms.ui.authoring.SimpleEditStep; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentItemManager; -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.contentsection.FolderManager; -import org.librecms.contentsection.FolderRepository; - -import java.util.Locale; -import java.util.Optional; - -/** - * Worker class to create the multipart article's edit form. - * - */ -public class MultiPartArticleEditForm extends MultiPartArticleForm - implements FormSubmissionListener { - - private final ItemSelectionModel itemSelectionModel; - private final SimpleEditStep editStep; - private final StringParameter selectedLanguageParam; - - /** - * Constructor. - * - * @param itemSelectionModel - * @param editStep - * @param selectedLanguageParam - */ - public MultiPartArticleEditForm(final ItemSelectionModel itemSelectionModel, - final SimpleEditStep editStep, - final StringParameter selectedLanguageParam) { - - super("MultiPartArticleEditForm", - itemSelectionModel, - selectedLanguageParam); - - addSubmissionListener(this); - this.itemSelectionModel = itemSelectionModel; - this.editStep = editStep; - this.selectedLanguageParam = selectedLanguageParam; - } - - @Override - public void init(final FormSectionEvent event) throws FormProcessException { - super.initBasicWidgets(event); - } - - /** - * Cancels streamlined editing. - * - * @param event - */ - @Override - public void submitted(final FormSectionEvent event) { - - if (getSaveCancelSection() - .getCancelButton() - .isSelected(event.getPageState())) { - editStep.cancelStreamlinedCreation(event.getPageState()); - } - } - - @Override - public void process(final FormSectionEvent event) - throws FormProcessException { - - final MultiPartArticle article = super.processBasicWidgets(event); - - final PageState state = event.getPageState(); - -// final MultiPartArticle article = (MultiPartArticle) itemSelectionModel -// .getSelectedObject(state); - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentItemRepository itemRepo = cdiUtil - .findBean(ContentItemRepository.class); - itemRepo.save(article); - - editStep.maybeForwardToNextStep(event.getPageState()); - } - - @Override - public void validate(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - final FormData data = event.getFormData(); - - final MultiPartArticle article = (MultiPartArticle) itemSelectionModel - .getSelectedObject(state); - - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - - final String newName = (String) data.get(MultiPartArticleForm.NAME); - final MultiPartArticleFormController controller = CdiUtil - .createCdiUtil() - .findBean(MultiPartArticleFormController.class); - final String oldName = controller.getName(article, selectedLocale); - - final boolean valid; - if (newName.equalsIgnoreCase(oldName)) { - valid = true; - } else { - final Optional folder = controller.getArticleFolder(article); - if (folder.isPresent()) { - valid = validateNameUniqueness(folder.get(), event); - } else { - valid = true; - } - } - - if (!valid) { - throw new FormProcessException( - "An item with name already exists", - new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.an_item_with_name_already_exists", - CmsConstants.CMS_BUNDLE)); - } - } - - private Folder getParentFolder(final MultiPartArticle article) { - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final FolderRepository folderRepo = cdiUtil - .findBean(FolderRepository.class); - final FolderManager folderManager = cdiUtil - .findBean(FolderManager.class); - - final ContentItemManager itemManager = cdiUtil - .findBean(ContentItemManager.class); - - final Optional folder = itemManager.getItemFolder(article); - - if (folder.isPresent()) { - return folder.get(); - } else { - return null; - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleForm.java deleted file mode 100644 index fa373a7c4..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleForm.java +++ /dev/null @@ -1,359 +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.authoring.multipartarticle; - -import com.arsdigita.bebop.ColumnPanel; -import com.arsdigita.bebop.Embedded; -import com.arsdigita.bebop.FormData; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.FormSection; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SaveCancelSection; -import com.arsdigita.bebop.event.FormInitListener; -import com.arsdigita.bebop.event.FormProcessListener; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.event.FormValidationListener; -import com.arsdigita.bebop.form.TextArea; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.bebop.parameters.DateParameter; -import com.arsdigita.bebop.parameters.NotEmptyValidationListener; -import com.arsdigita.bebop.parameters.NotNullValidationListener; -import com.arsdigita.bebop.parameters.ParameterModel; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.parameters.TrimmedStringParameter; -import com.arsdigita.bebop.parameters.URLTokenValidationListener; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.web.Web; -import com.arsdigita.xml.Element; - -import java.util.Date; -import java.util.Locale; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.librecms.CMSConfig; -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentItemManager; -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.Folder; -import org.librecms.contenttypes.MultiPartArticle; - -/** - * A form for editing MultiPartArticle and subclasses. - * - * @author Dave Turner - * @author Jens Pelzetter - */ -public abstract class MultiPartArticleForm - extends FormSection - implements FormInitListener, - FormProcessListener, - FormValidationListener { - - private final ItemSelectionModel itemSelectionModel; - private final StringParameter selectedLanguageParam; - private SaveCancelSection saveCancelSection; - /** - * Constant property, placeholder for a JavaScript element. - */ - private final Embedded m_script = new Embedded( - String.format("" - + "", - Web.getWebappContextPath()), - false); - - public static final String NAME = "name"; - public static final String TITLE = "title"; - public static final String SUMMARY = "summary"; - public static final String LAUNCH_DATE = "launch_date"; - public static final String LANGUAGE = "language"; - - private static final Logger LOGGER = LogManager.getLogger( - MultiPartArticleForm.class); - - public MultiPartArticleForm(final String formName, - final ItemSelectionModel itemSelectionModel, - final StringParameter selectedLanguageParam) { - - super(new ColumnPanel(2)); - - this.itemSelectionModel = itemSelectionModel; - this.selectedLanguageParam = selectedLanguageParam; - - ColumnPanel panel = (ColumnPanel) getPanel(); - panel.setBorder(false); - panel.setPadColor("#FFFFFF"); - panel.setColumnWidth(1, "20%"); - panel.setColumnWidth(2, "80%"); - panel.setWidth("100%"); - - addWidgets(); - - addSaveCancelSection(); - - addInitListener(this); - addProcessListener(this); - addValidationListener(this); - } - - public void addSaveCancelSection() { - saveCancelSection = new SaveCancelSection(); - add(saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT); - } - - public SaveCancelSection getSaveCancelSection() { - return saveCancelSection; - } - - protected void addWidgets() { - - // add(new Label(GlobalizationUtil - // .globalize("cms.contenttypes.ui.title"))); - final TextField titleWidget = new TextField(new TrimmedStringParameter( - TITLE)); - titleWidget.setLabel(new GlobalizedMessage("cms.contenttypes.ui.title", - CmsConstants.CMS_BUNDLE)); - titleWidget.addValidationListener(new NotNullValidationListener()); - titleWidget.setOnFocus(String.format( - "if (this.form.%s.value == '') { " - + " defaulting = true; this.form.%s.value = urlize(this.value); }", - NAME, NAME)); - titleWidget.setOnKeyUp(String.format( - "if (defaulting) { this.form.%s.value = urlize(this.value) }", - NAME)); - add(titleWidget); - - //add(new Label(GlobalizationUtil - // .globalize("cms.contenttypes.ui.name"))); - final TextField nameWidget = new TextField(new TrimmedStringParameter( - NAME)); - nameWidget.setLabel(new GlobalizedMessage("cms.contenttypes.ui.name", - CmsConstants.CMS_BUNDLE)); - nameWidget.addValidationListener(new NotNullValidationListener()); - nameWidget.addValidationListener(new URLTokenValidationListener()); - nameWidget.setOnFocus("defaulting = false"); - nameWidget.setOnBlur(String.format( - "if (this.value == '') { " - + "defaulting = true; this.value = urlize(this.form.%s.value) " - + "}", - TITLE)); - add(nameWidget); - - if (!CMSConfig.getConfig().isHideLaunchDate()) { - //add(new Label(GlobalizationUtil - // .globalize("cms.ui.authoring.page_launch_date"))); - final ParameterModel launchDateParam - = new DateParameter(LAUNCH_DATE); - com.arsdigita.bebop.form.Date launchDate - = new com.arsdigita.bebop.form.Date( - launchDateParam); - if (CMSConfig.getConfig().isRequireLaunchDate()) { - launchDate.addValidationListener(new NotNullValidationListener( - new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.no_launch_date", - CmsConstants.CMS_BUNDLE))); - // if launch date is required, help user by suggesting today's date - launchDateParam.setDefaultValue(new Date()); - } - launchDate.setLabel(new GlobalizedMessage( - "cms.ui.authoring.page_launch_date", - CmsConstants.CMS_BUNDLE)); - add(launchDate); - } - - //add(new Label(GlobalizationUtil - // .globalize("cms.contenttypes.ui.summary"))); - final TextArea summaryWidget = new TextArea( - new TrimmedStringParameter(SUMMARY)); - if (CMSConfig.getConfig().isMandatoryDescriptions()) { - summaryWidget - .addValidationListener(new NotEmptyValidationListener( - new GlobalizedMessage( - "cms.contenttypes.ui.description_missing", - CmsConstants.CMS_BUNDLE))); - } - summaryWidget.setLabel(new GlobalizedMessage( - "cms.contenttypes.ui.summary", - CmsConstants.CMS_BUNDLE)); - summaryWidget.setRows(5); - summaryWidget.setCols(30); - summaryWidget.setHint(new GlobalizedMessage( - "cms.contenttypes.ui.summary_hint", - CmsConstants.CMS_BUNDLE)); - add(summaryWidget); - } - - @Override - public abstract void init(final FormSectionEvent event) - throws FormProcessException; - - @Override - public abstract void process(final FormSectionEvent event) - throws FormProcessException; - - @Override - public abstract void validate(final FormSectionEvent event) - throws FormProcessException; - - /** - * Utility method to initialise the name/title/summary widgets. - * - * @param event - * - * @return - */ - public MultiPartArticle initBasicWidgets(final FormSectionEvent event) { - - final FormData data = event.getFormData(); - final PageState state = event.getPageState(); - final MultiPartArticle article = (MultiPartArticle) itemSelectionModel - .getSelectedObject(state); - - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - final MultiPartArticleFormController controller = CdiUtil - .createCdiUtil() - .findBean(MultiPartArticleFormController.class); - - if (article != null) { - data.put(NAME, controller.getName(article, selectedLocale)); - data.put(TITLE, controller.getTitle(article, selectedLocale)); - if (!CMSConfig.getConfig().isHideLaunchDate()) { - data.put(LAUNCH_DATE, article.getLaunchDate()); - } - data.put(SUMMARY, controller.getSummary(article, selectedLocale)); - } - - return article; - } - - /** - * Utility method to process the name/title/summary widgets. - * - * @param event - * - * @return - */ - public MultiPartArticle processBasicWidgets(final FormSectionEvent event) { - - final FormData data = event.getFormData(); - final PageState state = event.getPageState(); - final MultiPartArticle article = (MultiPartArticle) itemSelectionModel - .getSelectedObject(state); - - if (article != null) { - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - - article.getName().putValue(selectedLocale, - (String) data.get(NAME)); - article.getTitle().putValue(selectedLocale, - (String) data.get(TITLE)); - if (!CMSConfig.getConfig().isHideLaunchDate()) { - article.setLaunchDate((Date) data.get(LAUNCH_DATE)); - } - article.getSummary().putValue(selectedLocale, - (String) data.get(SUMMARY)); - } - - return article; - } - - /** - * Ensure that the name of an item is unique within a folder. - * - * @param folder the folder in which to check - * @param event the FormSectionEvent which was passed to the validation - * listener - * - * @return true if the name is not null and unique, false otherwise - */ - public boolean validateNameUniqueness(final Folder folder, - final FormSectionEvent event) { - - final FormData data = event.getFormData(); - final String name = (String) data.get(NAME); - - if (name != null) { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentItemRepository itemRepo = cdiUtil - .findBean(ContentItemRepository.class); - - final long result = itemRepo.countByNameInFolder(folder, name); - - return result == 0; - } - - // false if name == null - return false; - } - - /** - * Utility method to create a new MultiPartArticle and update the selected - * model. This can be called in the process method of a ProcessListener. - * - * @param state the current page state - * @param name - * @param section - * @param folder - * @param locale Initial locale of the article. - * - * @return the new content item (or a proper subclass) - * - * @throws com.arsdigita.bebop.FormProcessException - */ - public MultiPartArticle createArticle(final PageState state, - final String name, - final ContentSection section, - final Folder folder, - final Locale locale) - throws FormProcessException { - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentItemManager itemManager = cdiUtil - .findBean(ContentItemManager.class); - - final MultiPartArticle article = itemManager - .createContentItem(name, - section, - folder, - MultiPartArticle.class, - locale); - - if (itemSelectionModel.getSelectedKey(state) == null) { - itemSelectionModel.setSelectedKey(state, article.getObjectId()); - } - - return article; - } - - @Override - public void generateXML(final PageState state, final Element parent) { - - m_script.generateXML(state, parent); - super.generateXML(state, parent); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleFormController.java deleted file mode 100644 index 001fecdac..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleFormController.java +++ /dev/null @@ -1,120 +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.authoring.multipartarticle; - -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ContentItemManager; -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.contentsection.Folder; -import org.librecms.contenttypes.MultiPartArticle; - -import java.util.Locale; -import java.util.Objects; -import java.util.Optional; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.transaction.Transactional; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -public class MultiPartArticleFormController { - - @Inject - private ContentItemRepository itemRepo; - - @Inject - private ContentItemManager itemManager; - - @Transactional(Transactional.TxType.REQUIRED) - protected Optional getArticleFolder(final MultiPartArticle article) { - - final Optional mpa = itemRepo.findById( - article.getObjectId() - ); - - if (mpa.isPresent()) { - return itemManager.getItemFolder(mpa.get()); - } else { - return Optional.empty(); - } - } - - @Transactional(Transactional.TxType.REQUIRED) - public String getName( - final MultiPartArticle fromMpa, final Locale forLocale - ) { - Objects.requireNonNull(fromMpa); - Objects.requireNonNull(forLocale); - final MultiPartArticle mpa = itemRepo - .findById(fromMpa.getObjectId(), MultiPartArticle.class) - .orElseThrow( - () -> new IllegalArgumentException( - String.format( - "No MultiPartArticle with ID %d available", - fromMpa.getObjectId() - ) - ) - ); - return mpa.getName().getValue(forLocale); - } - - @Transactional(Transactional.TxType.REQUIRED) - public String getTitle( - final MultiPartArticle fromMpa, final Locale forLocale - ) { - Objects.requireNonNull(fromMpa); - Objects.requireNonNull(forLocale); - final MultiPartArticle mpa = itemRepo - .findById(fromMpa.getObjectId(), MultiPartArticle.class) - .orElseThrow( - () -> new IllegalArgumentException( - String.format( - "No MultiPartArticle with ID %d available", - fromMpa.getObjectId() - ) - ) - ); - - return mpa.getTitle().getValue(forLocale); - } - - @Transactional(Transactional.TxType.REQUIRED) - public String getSummary( - final MultiPartArticle fromMpa, final Locale forLocale - ) { - Objects.requireNonNull(fromMpa); - Objects.requireNonNull(forLocale); - final MultiPartArticle mpa = itemRepo - .findById(fromMpa.getObjectId(), MultiPartArticle.class) - .orElseThrow( - () -> new IllegalArgumentException( - String.format( - "No MultiPartArticle with ID %d available", - fromMpa.getObjectId() - ) - ) - ); - return mpa.getSummary().getValue(forLocale); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleSectionStepController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleSectionStepController.java deleted file mode 100644 index 185fc0b63..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleSectionStepController.java +++ /dev/null @@ -1,209 +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.authoring.multipartarticle; - -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.contenttypes.MultiPartArticle; -import org.librecms.contenttypes.MultiPartArticleSection; -import org.librecms.contenttypes.MultiPartArticleSectionManager; -import org.librecms.contenttypes.MultiPartArticleSectionRepository; - -import java.util.List; -import java.util.Locale; -import java.util.Objects; -import java.util.stream.Collectors; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.transaction.Transactional; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -class MultiPartArticleSectionStepController { - - @Inject - private ContentItemRepository itemRepo; - - @Inject - private MultiPartArticleSectionRepository sectionRepo; - - @Inject - private MultiPartArticleSectionManager sectionManager; - - @Transactional(Transactional.TxType.REQUIRED) - protected List retrieveSections( - final MultiPartArticle forArticle) { - - final MultiPartArticle article = itemRepo - .findById(forArticle.getObjectId(), - MultiPartArticle.class) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No MultiPartArticle with ID %d in the database.", - forArticle.getObjectId()))); - - //Ensure that the sections are loaded - return article - .getSections() - .stream() - .sorted((section1, section2) -> { - return Integer.compare(section1.getRank(), section2.getRank()); - }) - .collect(Collectors.toList()); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void addSection(final MultiPartArticle article, - final MultiPartArticleSection section) { - - final MultiPartArticle theArticle = itemRepo - .findById(article.getObjectId(), - MultiPartArticle.class) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No MultiPartArticle with ID %d in the database.", - article.getObjectId()))); - - sectionManager.addSectionToMultiPartArticle(section, theArticle); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void removeSection(final MultiPartArticle article, - final MultiPartArticleSection section) { - - final MultiPartArticle theArticle = itemRepo - .findById(article.getObjectId(), - MultiPartArticle.class) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No MultiPartArticle with ID %d in the database.", - article.getObjectId()))); - - final MultiPartArticleSection theSection = sectionRepo - .findById(section.getSectionId()) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No MultiPartArticleSection with ID %d in the database.", - section.getSectionId()))); - - sectionManager.removeSectionFromMultiPartArticle(theSection, - theArticle); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void moveToFirst(final MultiPartArticle article, - final MultiPartArticleSection section) { - - final MultiPartArticle theArticle = itemRepo - .findById(article.getObjectId(), - MultiPartArticle.class) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No MultiPartArticle with ID %d in the database.", - article.getObjectId()))); - - final MultiPartArticleSection theSection = sectionRepo - .findById(section.getSectionId()) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No MultiPartArticleSection with ID %d in the database.", - section.getSectionId()))); - - sectionManager.moveToFirst(theArticle, theSection); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void moveAfter(final MultiPartArticle article, - final MultiPartArticleSection section, - final MultiPartArticleSection after) { - - final MultiPartArticle theArticle = itemRepo - .findById(article.getObjectId(), - MultiPartArticle.class) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No MultiPartArticle with ID %d in the database.", - article.getObjectId()))); - - sectionManager.moveSectionAfter(theArticle, section, after); - } - - @Transactional(Transactional.TxType.REQUIRED) - public String getSectionTitle( - final MultiPartArticleSection ofSection, final Locale forLocale - ) { - Objects.requireNonNull(ofSection); - Objects.requireNonNull(forLocale); - - final MultiPartArticleSection section = sectionRepo - .findById(ofSection.getSectionId()) - .orElseThrow( - () -> new IllegalArgumentException( - String.format( - "No section with ID %d available.", ofSection - .getSectionId() - ) - ) - ); - return section.getTitle().getValue(forLocale); - } - - @Transactional(Transactional.TxType.REQUIRED) - public String getSectionText( - final MultiPartArticleSection ofSection, final Locale forLocale - ) { - Objects.requireNonNull(ofSection); - Objects.requireNonNull(forLocale); - - final MultiPartArticleSection section = sectionRepo - .findById(ofSection.getSectionId()) - .orElseThrow( - () -> new IllegalArgumentException( - String.format( - "No section with ID %d available.", ofSection - .getSectionId() - ) - ) - ); - return section.getText().getValue(forLocale); - } - - @Transactional(Transactional.TxType.REQUIRED) - public void updateSection( - final MultiPartArticleSection section, - final String title, - final String text, - final boolean pageBreak, - final Locale locale - ) { - Objects.requireNonNull(section); - Objects.requireNonNull(locale); - - final MultiPartArticleSection update = sectionRepo - .findById(section.getSectionId()) - .orElseThrow( - () -> new IllegalArgumentException( - String.format( - "No section with ID %d available.", - section.getSectionId() - ) - ) - ); - update.getTitle().putValue(locale, title); - update.getText().putValue(locale, title); - update.setPageBreak(pageBreak); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleSectionsStep.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleSectionsStep.java deleted file mode 100644 index b4ff8fff1..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/MultiPartArticleSectionsStep.java +++ /dev/null @@ -1,403 +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.authoring.multipartarticle; - -import com.arsdigita.bebop.ActionLink; -import com.arsdigita.bebop.ColumnPanel; -import com.arsdigita.bebop.Container; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.Page; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SingleSelectionModel; -import com.arsdigita.bebop.event.TableActionEvent; -import com.arsdigita.bebop.event.TableActionListener; -import com.arsdigita.bebop.parameters.LongParameter; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.authoring.ResettableContainer; -import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; -import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.security.PermissionChecker; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.privileges.ItemPrivileges; -import org.librecms.contenttypes.MultiPartArticle; -import org.librecms.contenttypes.MultiPartArticleSection; - -import java.util.Locale; - -/** - * Authoring kit step to manage the sections of a MultiPartArticle. Process is - * implemented with three main components that manipulate the currently selected - * MultiPartArticle and sections. The visibility of these components is managed - * by this class. - * - * Note: This class was originally called {@code MultiPartArticleViewSections}. - * Starting with version 7.0.0 all authoring step classes should end with - * {@code Step} to make them easily identifiable. - * - * @author Dave Turner - * * @author Jens Pelzetter - */ -public class MultiPartArticleSectionsStep extends ResettableContainer { - - /* id keys for each editing panel */ - public static final String SECTION_TABLE = "sec_tbl"; - public static final String SECTION_EDIT = "sec_edt"; - public static final String SECTION_PREVIEW = "sec_prv"; - public static final String SECTION_DELETE = "sec_del"; - - public static final String DATA_TABLE = "dataTable"; - public static final String ACTION_LINK = "actionLink"; - - private final AuthoringKitWizard authoringKitWizard; - private final ItemSelectionModel selectedArticleModel; - private final StringParameter selectedLanguageParam; - private SectionSelectionModel selectedSectionModel; - private SectionSelectionModel moveSectionModel; - private LongParameter moveSectionParam; - - private SectionTable sectionTable; - private SectionEditForm sectionEditForm; - private SectionPreviewPanel sectionPreviewPanel; - private SectionDeleteForm sectionDeleteForm; - - private ActionLink beginLink; - private Label moveSectionLabel; - - private final String typeIdStr; - - public MultiPartArticleSectionsStep( - final ItemSelectionModel selectedArticleModel, - final AuthoringKitWizard authoringKitWizard, - final StringParameter selectedLanguageParam) { - - super(); - this.selectedArticleModel = selectedArticleModel; - this.authoringKitWizard = authoringKitWizard; - this.selectedLanguageParam = selectedLanguageParam; - - typeIdStr = authoringKitWizard - .getContentType() - .getContentItemClass() - .getName(); - - addWidgets(); - } - - private void addWidgets() { - // create the components and set default visibility - add(buildSectionTable(), true); - add(buildSectionEdit(), false); - add(buildSectionDelete(), false); - } - - /** - * Builds a {@link Container} to hold a {@link SectionTable} and a link to - * add a new {@link MultiPartArticleSection}. - * - * @return A {@link Container} for the table of sections. - */ - protected Container buildSectionTable() { - - final ColumnPanel panel = new ColumnPanel(1); - panel.setKey(SECTION_TABLE + typeIdStr); - panel.setBorderColor("#FFFFFF"); - panel.setPadColor("#FFFFFF"); - - moveSectionParam = new LongParameter("moveSection"); - moveSectionModel = new SectionSelectionModel<>(moveSectionParam); - - sectionTable = new SectionTable(selectedArticleModel, - moveSectionModel, - selectedLanguageParam); - sectionTable.setClassAttr(DATA_TABLE); - - // selected section is based on the selection in the SectionTable - @SuppressWarnings("unchecked") - final SingleSelectionModel rowSelectionModel = sectionTable - .getRowSelectionModel(); - selectedSectionModel = new SectionSelectionModel<>( - MultiPartArticleSection.class, rowSelectionModel); - - sectionTable.setSectionModel(selectedSectionModel); - - final Label emptyView = new Label(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.no_sections_yet", - CmsConstants.CMS_BUNDLE)); - sectionTable.setEmptyView(emptyView); - - moveSectionLabel = new Label(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.section.title", - CmsConstants.CMS_BUNDLE)); - moveSectionLabel.addPrintListener(event -> { - final PageState state = event.getPageState(); - final Label target = (Label) event.getTarget(); - - if (moveSectionModel.getSelectedKey(state) != null) { - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - - final MultiPartArticleSectionStepController controller = CdiUtil - .createCdiUtil() - .findBean(MultiPartArticleSectionStepController.class); - - final Object[] parameterObj = { - controller.getSectionTitle( - moveSectionModel - .getSelectedSection(state), - selectedLocale - ) - }; - - target.setLabel(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.move_section_name", - CmsConstants.CMS_BUNDLE, - parameterObj)); - } - }); - panel.add(moveSectionLabel, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT); - - beginLink = new ActionLink(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.move_to_beginning", - CmsConstants.CMS_BUNDLE)); - panel.add(beginLink); - - beginLink.addActionListener(event -> { - final PageState state = event.getPageState(); - final MultiPartArticle article - = (MultiPartArticle) selectedArticleModel - .getSelectedObject(state); - final MultiPartArticleSection section = moveSectionModel - .getSelectedSection(state); - - final MultiPartArticleSectionStepController controller = CdiUtil - .createCdiUtil() - .findBean(MultiPartArticleSectionStepController.class); - - controller.moveToFirst(article, section); - }); - - moveSectionModel.addChangeListener(event -> { - final PageState state = event.getPageState(); - - if (moveSectionModel.getSelectedKey(state) == null) { - beginLink.setVisible(state, false); - moveSectionLabel.setVisible(state, false); - } else { - beginLink.setVisible(state, true); - moveSectionLabel.setVisible(state, true); - -// final Locale selectedLocale = SelectedLanguageUtil -// .selectedLocale(state, selectedLanguageParam); -// -// final Object[] parameterObj = { -// moveSectionModel -// .getSelectedSection(state) -// .getTitle() -// .getValue(selectedLocale) -// }; -// -// moveSectionLabel -// .setLabel(new GlobalizedMessage( -// "cms.contenttypes.ui.mparticle.move_section_name", -// CmsConstants.CMS_BUNDLE, -// parameterObj), -// state); - } - }); - - // handle clicks to preview or delete a Section - sectionTable.addTableActionListener(new TableActionListener() { - - @Override - public void cellSelected(final TableActionEvent event) { - final PageState state = event.getPageState(); - final TableColumn column = sectionTable - .getColumnModel() - .get(event.getColumn() - .intValue()); - - if (column.getModelIndex() == SectionTable.COL_INDEX_DELETE) { - onlyShowComponent(state, SECTION_DELETE + typeIdStr); - } else if (column.getModelIndex() == SectionTable.COL_INDEX_EDIT) { - onlyShowComponent(state, SECTION_EDIT + typeIdStr); - } - } - - @Override - public void headSelected(final TableActionEvent event) { - //Nothing - } - - }); - - panel.add(sectionTable); - panel.add(buildAddLink()); - - return panel; - } - - /** - * Builds a container to hold a SectionEditForm and a link to return to the - * section list. - * - * @return - */ - protected Container buildSectionEdit() { - - final ColumnPanel panel = new ColumnPanel(1); - panel.setKey(SECTION_EDIT + typeIdStr); - panel.setBorderColor("#FFFFFF"); - panel.setPadColor("#FFFFFF"); - - // display an appropriate title - panel.add(new Label(event -> { - final PageState state = event.getPageState(); - final Label target = (Label) event.getTarget(); - - if (selectedSectionModel.getSelectedKey(state) == null) { - target.setLabel(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.add_section", - CmsConstants.CMS_BUNDLE)); - } else { - target.setLabel(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.edit_section", - CmsConstants.CMS_BUNDLE)); - } - })); - - sectionEditForm = new SectionEditForm(selectedArticleModel, - selectedSectionModel, - this, - selectedLanguageParam); - - panel.add(sectionEditForm); - panel.add(buildViewAllLink()); - panel.add(buildAddLink()); - - return panel; - } - - /** - * Builds a container to hold the component to confirm deletion of a - * section. - * - * @return - */ - protected Container buildSectionDelete() { - - final ColumnPanel panel = new ColumnPanel(1); - panel.setKey(SECTION_DELETE + typeIdStr); - panel.setBorderColor("#FFFFFF"); - panel.setPadColor("#FFFFFF"); - - panel.add(new Label(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.delete_section", - CmsConstants.CMS_BUNDLE))); - sectionDeleteForm = new SectionDeleteForm(selectedArticleModel, - selectedSectionModel, - selectedLanguageParam); - sectionDeleteForm.addSubmissionListener(event -> { - - final PageState state = event.getPageState(); - onlyShowComponent(state, SECTION_TABLE + typeIdStr); - }); - - panel.add(sectionDeleteForm); - panel.add(buildViewAllLink()); - - return panel; - } - - /** - * Utility method to create a link to display the section list. - * - * @return - */ - protected ActionLink buildViewAllLink() { - final ActionLink viewAllLink = new ActionLink( - new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.view_all_sections", - CmsConstants.CMS_BUNDLE)); - viewAllLink.setClassAttr(ACTION_LINK); - viewAllLink.addActionListener(event -> { - onlyShowComponent(event.getPageState(), - SECTION_TABLE + typeIdStr); - }); - - return viewAllLink; - } - - /** - * Utility method to create a link to display the section list. - * - * @return - */ - protected ActionLink buildAddLink() { - final ActionLink addLink = new ActionLink( - new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.add_new_section", - CmsConstants.CMS_BUNDLE)) { - - @Override - public boolean isVisible(final PageState state) { - - final PermissionChecker permissionChecker = CdiUtil - .createCdiUtil() - .findBean(PermissionChecker.class); - final ContentItem item = selectedArticleModel - .getSelectedItem(state); - - return super.isVisible(state) - && permissionChecker.isPermitted(ItemPrivileges.EDIT, - item); - } - - }; - addLink.setClassAttr(ACTION_LINK); - addLink.addActionListener(event -> { - final PageState state = event.getPageState(); - selectedSectionModel.clearSelection(state); - onlyShowComponent(state, SECTION_EDIT + typeIdStr); - }); - - return addLink; - - } - - @Override - public void register(final Page page) { - - super.register(page); - - page.addGlobalStateParam(moveSectionParam); - page.setVisibleDefault(beginLink, false); - page.setVisibleDefault(moveSectionLabel, false); - } - - public String getTypeIDStr() { - return typeIdStr; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionDeleteForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionDeleteForm.java deleted file mode 100755 index b5707bdd5..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionDeleteForm.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (C) 2002-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.multipartarticle; - -import com.arsdigita.bebop.ColumnPanel; -import com.arsdigita.bebop.Form; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SaveCancelSection; -import com.arsdigita.bebop.event.FormInitListener; -import com.arsdigita.bebop.event.FormProcessListener; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.event.FormSubmissionListener; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.librecms.contenttypes.MultiPartArticle; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; -import org.librecms.contenttypes.MultiPartArticleSection; - -import java.util.Locale; - -/** - * A form to confirm deletion of a single section of a MultiPartArticle. - * - * @author Dave Turner - * @author Jens Pelzetter - */ -public class SectionDeleteForm extends Form - implements FormInitListener, FormSubmissionListener, FormProcessListener { - - private final static Logger LOGGER = LogManager - .getLogger(SectionDeleteForm.class.getName()); - - private final ItemSelectionModel selectedArticleModel; - private final SectionSelectionModel selectedSectionModel; - private final SaveCancelSection saveCancelSection; - private final Label sectionNameLabel; - - private final StringParameter selectedLanguageParam; - - public SectionDeleteForm( - final ItemSelectionModel selectedArticleModel, - final SectionSelectionModel selectedSectionModel, - final StringParameter selectedLanguageParam) { - - super("SectionDeleteForm", new ColumnPanel(2)); - this.selectedArticleModel = selectedArticleModel; - this.selectedSectionModel = selectedSectionModel; - this.selectedLanguageParam = selectedLanguageParam; - - final ColumnPanel panel = (ColumnPanel) super.getPanel(); - panel.setBorder(false); - panel.setPadColor("#FFFFFF"); - panel.setColumnWidth(1, "20%"); - panel.setColumnWidth(2, "80%"); - panel.setWidth("100%"); - - sectionNameLabel = new Label(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.section_name")); - super.add(sectionNameLabel, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT); - - saveCancelSection = new SaveCancelSection(); - saveCancelSection - .getSaveButton() - .setButtonLabel(new GlobalizedMessage("cms.ui.delete", - CmsConstants.CMS_BUNDLE)); - super.add(saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT); - - super.addInitListener(this); - super.addSubmissionListener(this); - super.addProcessListener(this); - } - - @Override - public void init(final FormSectionEvent event) throws FormProcessException { - - final PageState state = event.getPageState(); - - final MultiPartArticleSection section = selectedSectionModel - .getSelectedSection(state); - - if (section == null) { - LOGGER.error("No section selected"); - } else { - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - - final MultiPartArticleSectionStepController controller = CdiUtil - .createCdiUtil() - .findBean(MultiPartArticleSectionStepController.class); - - sectionNameLabel.setLabel( - controller.getSectionTitle(section, selectedLocale), - state - ); - } - } - - @Override - public void submitted(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - if (saveCancelSection - .getCancelButton() - .isSelected(state)) { - - throw new FormProcessException( - "Submission cancelled", - new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.submission_cancelled", - CmsConstants.CMS_BUNDLE)); - } - } - - @Override - public void process(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - final MultiPartArticle article = (MultiPartArticle) selectedArticleModel - .getSelectedObject(state); - final MultiPartArticleSection section = selectedSectionModel - .getSelectedSection(state); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final MultiPartArticleSectionStepController controller = cdiUtil - .findBean(MultiPartArticleSectionStepController.class); - - controller.removeSection(article, section); - - LOGGER.info("section {} deleted", - selectedSectionModel.getSelectedKey(state)); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionEditForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionEditForm.java deleted file mode 100755 index 6ac5140d7..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionEditForm.java +++ /dev/null @@ -1,340 +0,0 @@ -/* - * Copyright (C) 2002-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.multipartarticle; - -import com.arsdigita.bebop.ColumnPanel; -import com.arsdigita.bebop.Form; -import com.arsdigita.bebop.FormData; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SaveCancelSection; -import com.arsdigita.bebop.event.FormInitListener; -import com.arsdigita.bebop.event.FormProcessListener; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.event.FormSubmissionListener; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.bebop.form.CheckboxGroup; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.parameters.NotNullValidationListener; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.parameters.TrimmedStringParameter; -import com.arsdigita.cms.ItemSelectionModel; - -import org.librecms.contenttypes.MultiPartArticle; - -import com.arsdigita.cms.ui.CMSDHTMLEditor; -import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; -import org.librecms.contenttypes.MultiPartArticleSection; -import org.librecms.contenttypes.MultiPartArticleSectionRepository; - -import java.util.Locale; - -/** - * Form to edit an ArticleSection for a MultiPartArticle. - * - * @author Dave Turner - * @author Jens Pelzetter - */ -public class SectionEditForm extends Form { - - public static final String TITLE = "title"; - public static final String TEXT = "text"; - public static final String IMAGE = "image"; - public static final String PAGE_BREAK = "pageBreak"; - - private static final String TEXT_PARAM = "textParam"; - private static final String IMAGE_PARAM = "imageParam"; - - private final ItemSelectionModel selectedArticleModel; - private final SectionSelectionModel selectedSectionModel; - private final StringParameter selectedLanguageParam; - - private MultiPartArticleSectionsStep sectionsStep; - - private SaveCancelSection saveCancelSection; - - public SectionEditForm( - final ItemSelectionModel selectedArticleModel, - final SectionSelectionModel selectedSectionModel, - final StringParameter selectedLanguageParam) { - - this(selectedArticleModel, - selectedSectionModel, - null, - selectedLanguageParam); - } - - public SectionEditForm( - final ItemSelectionModel selectedArticleModel, - final SectionSelectionModel selectedSectionModel, - final MultiPartArticleSectionsStep sectionsStep, - final StringParameter selectedLanguageParam) { - - super("SectionEditForm", new ColumnPanel(2)); - this.selectedArticleModel = selectedArticleModel; - this.selectedSectionModel = selectedSectionModel; - this.sectionsStep = sectionsStep; - this.selectedLanguageParam = selectedLanguageParam; - - super.setMethod(Form.POST); - super.setEncType("multipart/form-data"); - - final ColumnPanel panel = (ColumnPanel) super.getPanel(); - panel.setBorder(false); - panel.setPadColor("#FFFFFF"); - panel.setColumnWidth(1, "20%"); - panel.setColumnWidth(2, "80%"); - panel.setWidth("100%"); - - addWidgets(); - saveCancelSection = new SaveCancelSection(); - add(saveCancelSection, ColumnPanel.FULL_WIDTH | ColumnPanel.LEFT); - - addInitListener(new SectionInitListener()); - addSubmissionListener(new SectionSubmissionListener()); - addProcessListener(new SectionProcessListener()); - } - - public SaveCancelSection getSaveCancelSection() { - return saveCancelSection; - } - - /** - * Add form widgets for a Section. - */ - private void addWidgets() { - - final TextField titleWidget = new TextField( - new TrimmedStringParameter(TITLE)); - titleWidget.addValidationListener(new NotNullValidationListener()); - titleWidget.setLabel( - new GlobalizedMessage("cms.contenttypes.ui.mparticle.section.title", - CmsConstants.CMS_BUNDLE)); - add(titleWidget); - - final CMSDHTMLEditor textWidget = new CMSDHTMLEditor( - new TrimmedStringParameter(TEXT)); - textWidget.setLabel( - new GlobalizedMessage("cms.contenttypes.ui.mparticle.section.text", - CmsConstants.CMS_BUNDLE)); - textWidget.setRows(40); - textWidget.setCols(70); - textWidget.setWrap(CMSDHTMLEditor.SOFT); - add(textWidget, ColumnPanel.LEFT | ColumnPanel.FULL_WIDTH); - - final CheckboxGroup pageBreak = new CheckboxGroup(PAGE_BREAK); - pageBreak.addOption( - new Option("true", - new Label(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.section.create_break", - CmsConstants.CMS_BUNDLE)))); - add(pageBreak); - } - - /** - * Utility method to create a Section from the form data supplied. - * - * @param event - * @param article - * - * @return - */ - protected MultiPartArticleSection createSection(final FormSectionEvent event, - final MultiPartArticle article) { - - final PageState state = event.getPageState(); - final FormData data = event.getFormData(); - - final MultiPartArticleSection section = new MultiPartArticleSection(); - - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - - section.getTitle().putValue(selectedLocale, (String) data.get(TITLE)); - - return section; - } - - /** - * Initialise the form. If there is a selected section, ie. this is an - * 'edit' step rather than a 'create new' step, load the data into the form - * fields. - */ - private class SectionInitListener implements FormInitListener { - - @Override - public void init(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - final FormData data = event.getFormData(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final MultiPartArticleSectionRepository sectionRepo = cdiUtil - .findBean(MultiPartArticleSectionRepository.class); - - if (selectedSectionModel.getSelectedKey(state) != null) { - - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - final MultiPartArticleSectionStepController controller = CdiUtil - .createCdiUtil() - .findBean(MultiPartArticleSectionStepController.class); - - final MultiPartArticleSection section = selectedSectionModel - .getSelectedSection(state); - - data.put( - TITLE, controller.getSectionTitle(section, selectedLocale) - ); - data.put( - TEXT, controller.getSectionText(section, selectedLocale) - ); - - if (section.isPageBreak()) { - data.put(PAGE_BREAK, new Object[]{"true"}); - } - } - } - - } - - /** - * Called on form submission. Check to see if the user clicked the cancel - * button. If they did, don't continue with the form. - */ - private class SectionSubmissionListener implements FormSubmissionListener { - - @Override - public void submitted(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - if (saveCancelSection - .getCancelButton() - .isSelected(state) - && sectionsStep != null) { - - sectionsStep.onlyShowComponent( - state, - MultiPartArticleSectionsStep.SECTION_TABLE - + sectionsStep.getTypeIDStr()); - - throw new FormProcessException( - "Submission cancelled", - new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.submission_cancelled", - CmsConstants.CMS_BUNDLE) - ); - } - } - - } - - /** - * Called after form has been validated. Create the new ArticleSection and - * assign it to the current MultiPartArticle. - */ - private class SectionProcessListener implements FormProcessListener { - - @Override - public void process(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - final FormData data = event.getFormData(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final MultiPartArticleSectionStepController controller = cdiUtil - .findBean(MultiPartArticleSectionStepController.class); - final MultiPartArticleSectionRepository sectionRepo = cdiUtil - .findBean(MultiPartArticleSectionRepository.class); - - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - - final MultiPartArticle article - = (MultiPartArticle) selectedArticleModel - .getSelectedItem(state); - - // get the selected section to update or create a new one - final MultiPartArticleSection section; - if (selectedSectionModel.getSelectedKey(state) == null) { - section = new MultiPartArticleSection(); - - } else { - section = selectedSectionModel.getSelectedSection(state); - } - -// section.getTitle().putValue(selectedLocale, -// (String) data.get(TITLE)); - final Object[] pageBreakVal = (Object[]) data.get(PAGE_BREAK); - final boolean pageBreak; - if (pageBreakVal == null - || pageBreakVal.length == 0 - || !"true".equals(pageBreakVal[0])) { - pageBreak = false; - } else { - pageBreak = true; - } -// section.setPageBreak(pageBreak); - - final String text; - if (data.get(TEXT) == null) { - text = ""; - } else { - text = (String) data.get(TEXT); - } -// section.getText().putValue(selectedLocale, text); - -// sectionRepo.save(section); - if (selectedSectionModel.getSelectedKey(state) == null) { - section.getTitle().putValue(selectedLocale, - (String) data.get(TITLE)); - section.setPageBreak(pageBreak); - section.getText().putValue(selectedLocale, text); - - controller.addSection(article, section); - } else { - controller.updateSection( - section, - (String) data.get(TITLE), - text, - pageBreak, - selectedLocale - ); - } - - if (sectionsStep != null) { - sectionsStep - .onlyShowComponent(state, - MultiPartArticleSectionsStep.SECTION_TABLE - + sectionsStep.getTypeIDStr()); - } - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionPreviewPanel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionPreviewPanel.java deleted file mode 100755 index d453033b8..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionPreviewPanel.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2002-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.multipartarticle; - -import com.arsdigita.bebop.BoxPanel; - -public class SectionPreviewPanel extends BoxPanel -{ - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionSelectionModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionSelectionModel.java deleted file mode 100644 index 41a4e6253..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionSelectionModel.java +++ /dev/null @@ -1,168 +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.authoring.multipartarticle; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.ParameterSingleSelectionModel; -import com.arsdigita.bebop.SingleSelectionModel; -import com.arsdigita.bebop.event.ChangeListener; -import com.arsdigita.bebop.parameters.LongParameter; -import com.arsdigita.bebop.parameters.ParameterModel; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.core.UnexpectedErrorException; -import org.librecms.contenttypes.MultiPartArticleSection; -import org.librecms.contenttypes.MultiPartArticleSectionRepository; - -/** - * A {@link SingleSelectionModel} implementation for - * {@link MultiPartArticleSection}s. - * - * @param - * - * @author Jens Pelzetter - */ -public class SectionSelectionModel - implements SingleSelectionModel { - - private final Class clazz; - private final SingleSelectionModel model; - - public SectionSelectionModel(final LongParameter parameter) { - this(MultiPartArticleSection.class.getName(), parameter); - } - - public SectionSelectionModel(final String parameterName) { - this(MultiPartArticleSection.class.getName(), - new LongParameter(parameterName)); - } - - public SectionSelectionModel(final Class clazz, - final String parameterName) { - this(clazz, new LongParameter(parameterName)); - } - - @SuppressWarnings("unchecked") - public SectionSelectionModel(final String className, - final String parameterName) { - - try { - clazz = (Class) Class.forName(className); - } catch (ClassNotFoundException ex) { - throw new UnexpectedErrorException(ex); - } - - model = new ParameterSingleSelectionModel<>( - new LongParameter(parameterName)); - } - - public SectionSelectionModel(final Class clazz, - final LongParameter parameter) { - this(clazz, new ParameterSingleSelectionModel<>(parameter)); - } - - @SuppressWarnings("unchecked") - public SectionSelectionModel(final String className, - final LongParameter parameter) { - - try { - clazz = (Class) Class.forName(className); - } catch (ClassNotFoundException ex) { - throw new UnexpectedErrorException(ex); - } - model = new ParameterSingleSelectionModel<>(parameter); - } - - public SectionSelectionModel(final Class clazz, - final SingleSelectionModel model) { - this.clazz = clazz; - this.model = model; - } - - @SuppressWarnings("unchecked") - public SectionSelectionModel(final String className, - final SingleSelectionModel model) { - - try { - clazz = (Class) Class.forName(className); - } catch (ClassNotFoundException ex) { - throw new UnexpectedErrorException(ex); - } - this.model = model; - } - - @Override - public boolean isSelected(final PageState state) { - return model.isSelected(state); - } - - @Override - public Long getSelectedKey(final PageState state) { - final Object key = model.getSelectedKey(state); - if (key == null) { - return null; - } else if (key instanceof Long) { - return (Long) key; - } else if (key instanceof String) { - return Long.parseLong((String) key); - } else { - return Long.parseLong(key.toString()); - } - } - - @Override - public void setSelectedKey(final PageState state, final Long key) { - model.setSelectedKey(state, key); - } - - public T getSelectedSection(final PageState state) { - final Long key = getSelectedKey(state); - final MultiPartArticleSectionRepository sectionRepo = CdiUtil - .createCdiUtil() - .findBean(MultiPartArticleSectionRepository.class); - @SuppressWarnings("unchecked") - final T object = (T) sectionRepo.findById(key).get(); - return object; - } - - @Override - public void clearSelection(final PageState state) { - - model.clearSelection(state); - } - - @Override - public void addChangeListener(final ChangeListener changeListener) { - - model.addChangeListener(changeListener); - } - - @Override - public void removeChangeListener(final ChangeListener changeListener) { - - model.removeChangeListener(changeListener); - } - - @Override - public ParameterModel getStateParameter() { - - return model.getStateParameter(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionTable.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionTable.java deleted file mode 100755 index 0a5b3db7d..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionTable.java +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright (C) 2002-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.multipartarticle; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.ControlLink; -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 org.librecms.contentsection.ContentItem; - -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.librecms.contenttypes.MultiPartArticle; - -import com.arsdigita.util.LockableImpl; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.security.PermissionChecker; -import org.librecms.CmsConstants; -import org.librecms.contentsection.privileges.ItemPrivileges; -import org.librecms.contenttypes.MultiPartArticleSection; -import org.librecms.contenttypes.MultiPartArticleSectionRepository; - -import java.util.Objects; - -/** - * A table that displays the sections for the currently selected - * MultiPartArticle. - * - * @author Dave Turner - * @author Jens Pelzetter - */ -public class SectionTable extends Table { - - /** - * Index of the title column - */ - public static final int COL_INDEX_TITLE = 0; - /** - * Index of the page break column - */ - public static final int COL_PAGE_BREAK = 1; - /** - * Index of the edit column. - */ - public static final int COL_INDEX_EDIT = 2; - /** - * Index of the move column - */ - public static final int COL_INDEX_MOVE = 3; - /** - * Index of the delete column - */ - public static final int COL_INDEX_DELETE = 4; - - private ItemSelectionModel selectedArticleModel; - private SectionSelectionModel selectedSectionModel; - private SectionSelectionModel moveSectionModel; - - /** - * Constructor. Create an instance of this class. - * - * @param selectedArticleModel a selection model that returns the - * MultiPartArticle which holds the sections to - * display. - * @param moveSectionModel - * @param selectedLanguageParam - */ - public SectionTable( - final ItemSelectionModel selectedArticleModel, - final SectionSelectionModel moveSectionModel, - final StringParameter selectedLanguageParam) { - - super(); - this.selectedArticleModel = selectedArticleModel; - this.moveSectionModel = moveSectionModel; - - final TableColumnModel model = getColumnModel(); - model.add(new TableColumn( - COL_INDEX_TITLE, - new Label(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.section_table.header_section", - CmsConstants.CMS_BUNDLE)))); - model.add(new TableColumn( - COL_PAGE_BREAK, - new Label(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.section_table.header_page_break", - CmsConstants.CMS_BUNDLE)))); - model.add(new TableColumn( - COL_INDEX_EDIT, - new Label(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.section_table.header_edit", - CmsConstants.CMS_BUNDLE)))); - model.add(new TableColumn( - COL_INDEX_MOVE, - new Label(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.section_table.header_move", - CmsConstants.CMS_BUNDLE)))); - model.add(new TableColumn( - COL_INDEX_DELETE, - new Label(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.section_table.header_delete", - CmsConstants.CMS_BUNDLE)))); - - model.get(COL_INDEX_EDIT).setCellRenderer(new SectionTableCellRenderer(true)); - model.get(COL_INDEX_MOVE).setCellRenderer(new SectionTableCellRenderer(true)); - model.get(COL_INDEX_DELETE).setCellRenderer(new SectionTableCellRenderer(true)); - - super.setModelBuilder( - new SectionTableModelBuilder(selectedArticleModel, - moveSectionModel, - selectedLanguageParam)); - - super.addTableActionListener(new TableActionListener() { - - @Override - public void cellSelected(final TableActionEvent event) { - - final PageState state = event.getPageState(); - - final TableColumn column = getColumnModel() - .get(event.getColumn()); - - if (column.getModelIndex() == COL_INDEX_MOVE) { - - if (moveSectionModel.getSelectedKey(state) == null) { - moveSectionModel.setSelectedKey( - state, - selectedSectionModel.getSelectedKey(state)); - } else { - final MultiPartArticle article - = (MultiPartArticle) selectedArticleModel - .getSelectedObject(state); - - final Long sectionId = moveSectionModel - .getSelectedKey(state); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final MultiPartArticleSectionRepository sectionRepo - = cdiUtil - .findBean( - MultiPartArticleSectionRepository.class); - final MultiPartArticleSectionStepController controller - = cdiUtil - .findBean( - MultiPartArticleSectionStepController.class); - final MultiPartArticleSection section = sectionRepo - .findById(sectionId) - .orElseThrow(() -> new IllegalArgumentException( - String - .format( - "No MultiPartArticleSection with ID %d in " - + "the database.", - sectionId))); - - final Long destId = Long - .parseLong((String) event.getRowKey()); - final MultiPartArticleSection destSection = sectionRepo - .findById(destId) - .orElseThrow(() -> new IllegalArgumentException( - String.format( - "No MultiPartArticleSection with ID %d in " - + "the database.", - destId))); - - controller.moveAfter(article, section, destSection); - -// // if sect is lower in rank than the dest -// // then move below is default behavior -// int rank = destSection.getRank(); -// if (section.getRank() > rank) { -// // otherwise, add one to get "move below" -// rank++; -// } -// -// section.setRank(rank); -// sectionRepo.save(section); - moveSectionModel.setSelectedKey(state, null); - } - } - } - - @Override - public void headSelected(final TableActionEvent event) { - // do nothing - } - - }); - } - - public void setSectionModel( - final SectionSelectionModel selectedSectionModel) { - - Objects.requireNonNull(selectedSectionModel); - - this.selectedSectionModel = selectedSectionModel; - } - - private class SectionTableCellRenderer - extends LockableImpl - implements TableCellRenderer { - - private boolean active; - - public SectionTableCellRenderer() { - this(false); - } - - public SectionTableCellRenderer(final boolean active) { - this.active = active; - } - - @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 PermissionChecker permissionChecker = cdiUtil - .findBean(PermissionChecker.class); - - final ContentItem article = selectedArticleModel.getSelectedObject( - state); - - boolean createLink = active - && permissionChecker - .isPermitted(ItemPrivileges.EDIT, article); - - final Component ret; - if (value instanceof Label) { - if (createLink) { - ret = new ControlLink((Component) value); - } else { - ret = (Component) value; - } - } else if (value instanceof String) { - // Backwards compatibility, should be removed asap! - if (createLink) { - ret = new ControlLink(value.toString()); - } else { - ret = new Text(value.toString()); - } - } else { - ret = new Label(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.section_table.link_not_defined", - CmsConstants.CMS_BUNDLE), - false); - } - - return ret; - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionTableModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionTableModel.java deleted file mode 100644 index de8084d7a..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionTableModel.java +++ /dev/null @@ -1,168 +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.authoring.multipartarticle; - -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.table.TableColumnModel; -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; -import org.librecms.contenttypes.MultiPartArticle; -import org.librecms.contenttypes.MultiPartArticleSection; - -import java.util.Iterator; -import java.util.List; -import java.util.Locale; - -class SectionTableModel implements TableModel { - - private final TableColumnModel columnModel; - private final SectionTable sectionTable; - private final PageState pageState; - private final StringParameter selectedLanguageParam; - private final SectionSelectionModel moveSectionModel; - - private final Iterator iterator; - private MultiPartArticleSection currentSection; - - /** - * Constructor. - * - * @param sectionTable - * @param pageState - * @param article - * @param moveSectionModel - */ - public SectionTableModel( - final Table sectionTable, - final PageState pageState, - final StringParameter selectedLanguageParam, - final MultiPartArticle article, - final SectionSelectionModel moveSectionModel) { - - this.pageState = pageState; - this.selectedLanguageParam = selectedLanguageParam; - this.sectionTable = (SectionTable) sectionTable; - this.moveSectionModel = moveSectionModel; - - columnModel = sectionTable.getColumnModel(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final MultiPartArticleSectionStepController controller = cdiUtil - .findBean(MultiPartArticleSectionStepController.class); - - final List sections = controller - .retrieveSections(article); - iterator = sections.iterator(); - } - - /** - * Return the number of columns this TableModel has. - */ - @Override - public int getColumnCount() { - return columnModel.size(); - } - - /** - * Move to the next row and return true if the model is now positioned on a - * valid row. - */ - @Override - public boolean nextRow() { - - if (iterator.hasNext()) { - currentSection = iterator.next(); - return true; - } else { - return false; - } - } - - /** - * Return the data element for the given column and the current row. - */ - @Override - public Object getElementAt(final int columnIndex) { - - if (columnModel == null) { - return null; - } - - final MultiPartArticleSectionStepController controller = CdiUtil - .createCdiUtil() - .findBean(MultiPartArticleSectionStepController.class); - - switch (columnIndex) { - case SectionTable.COL_INDEX_TITLE: - return controller.getSectionTitle( - currentSection, - SelectedLanguageUtil.selectedLocale( - pageState, selectedLanguageParam - ) - ) - ; - case SectionTable.COL_PAGE_BREAK: - if (currentSection.isPageBreak()) { - return new Label( - new GlobalizedMessage("cms.ui.yes", - CmsConstants.CMS_BUNDLE)); - } else { - return new Label( - new GlobalizedMessage("cms.ui.no", - CmsConstants.CMS_BUNDLE)); - } - case SectionTable.COL_INDEX_EDIT: - return new Label(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.section_table.link_edit", - CmsConstants.CMS_BUNDLE)); - case SectionTable.COL_INDEX_DELETE: - return new Label(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.section_table.link_delete", - CmsConstants.CMS_BUNDLE)); - case SectionTable.COL_INDEX_MOVE: - if (moveSectionModel.getSelectedKey(pageState) == null) { - return new Label(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.section_table.link_move", - CmsConstants.CMS_BUNDLE)); - } else { - return new Label(new GlobalizedMessage( - "cms.contenttypes.ui.mparticle.section_table.link_move_below", - CmsConstants.CMS_BUNDLE)); - } - default: - return null; - } - } - - /** - * Return the key for the given column and the current row. - */ - @Override - public Object getKeyAt(final int columnIndex) { - return currentSection.getSectionId(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionTableModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionTableModelBuilder.java deleted file mode 100644 index 030b9cffd..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/multipartarticle/SectionTableModelBuilder.java +++ /dev/null @@ -1,80 +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.authoring.multipartarticle; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.bebop.table.TableModelBuilder; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.util.LockableImpl; - -import org.librecms.contenttypes.MultiPartArticle; -import org.librecms.contenttypes.MultiPartArticleSection; - -/** - * The model builder to generate a suitable model for the SectionTable - */ -class SectionTableModelBuilder extends LockableImpl implements TableModelBuilder { - - private final ItemSelectionModel selectedArticleModel; - private final SectionSelectionModel moveSectionModel; - - private final StringParameter selectedLanguageParam; - - /** - * Private class constructor. - * - * @param selectedArticleModel - * @param moveSectionModel - */ - public SectionTableModelBuilder( - final ItemSelectionModel selectedArticleModel, - final SectionSelectionModel moveSectionModel, - final StringParameter selectedLanguageParam) { - - this.selectedArticleModel = selectedArticleModel; - this.moveSectionModel = moveSectionModel; - this.selectedLanguageParam = selectedLanguageParam; - } - - /** - * - * @param table - * @param state - * - * @return - */ - @Override - public TableModel makeModel(final Table table, - final PageState state) { - - table.getRowSelectionModel().clearSelection(state); - MultiPartArticle article - = (MultiPartArticle) selectedArticleModel - .getSelectedObject(state); - return new SectionTableModel(table, - state, - selectedLanguageParam, - article, - moveSectionModel); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/news/NewItemForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/news/NewItemForm.java deleted file mode 100755 index 9e7a9f4d0..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/news/NewItemForm.java +++ /dev/null @@ -1,207 +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.news; - -import com.arsdigita.bebop.BoxPanel; -import com.arsdigita.bebop.Form; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -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.SingleSelect; -import com.arsdigita.bebop.form.Submit; -import com.arsdigita.bebop.parameters.LongParameter; -import com.arsdigita.cms.ui.ItemSearch; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.util.UncheckedWrapperException; -import com.arsdigita.xml.Element; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.security.PermissionChecker; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.ContentType; -import org.librecms.contentsection.ContentTypeRepository; - -import java.util.List; -import java.util.TooManyListenersException; - -import org.librecms.contenttypes.ContentTypeInfo; -import org.librecms.contenttypes.ContentTypesManager; - -/** - * A form element which displays a select box of all content types available - * under the given content section, and forwards to the item creation UI when - * the user selects a content type to instantiate. - * - * @author Stanislav Freidin (sfreidin@arsdigtia.com) - * @author Jens Pelzetter - */ -public abstract class NewItemForm extends Form { - - public static final String TYPE_ID = "tid"; - - private final SingleSelect typeSelect; - private final Submit submit; - private final Label emptyLabel; - private final Label createLabel; - - public NewItemForm(final String name) { - this(name, BoxPanel.HORIZONTAL); - } - - /** - * Construct a new NewItemForm. It sets a vertical BoxPanel as the component - * container. - * - * @param name the name attribute of the form. - * @param orientation - */ - public NewItemForm(final String name, final int orientation) { - - super(name, new BoxPanel(BoxPanel.VERTICAL)); - setIdAttr("new_item_form"); - - final BoxPanel panel = new BoxPanel(orientation); - panel.setWidth("2%"); - panel.setBorder(0); - - // create and add an "empty" component - emptyLabel = new Label( - new GlobalizedMessage("cms.ui.authoring.no_types_registered", - CmsConstants.CMS_BUNDLE), - false); - emptyLabel.setIdAttr("empty_label"); - panel.add(emptyLabel); - - createLabel = new Label( - new GlobalizedMessage("cms.ui.authoring.create_new", - CmsConstants.CMS_BUNDLE), - false); - createLabel.setIdAttr("create_label"); - panel.add(createLabel); - - typeSelect = new SingleSelect(new LongParameter(TYPE_ID), - OptionGroup.SortMode.ALPHABETICAL_ASCENDING); - try { - typeSelect.addPrintListener(new PrintListener() { - - // Read the content section's content types and add them as options - @Override - public void prepare(final PrintEvent event) { - final OptionGroup target = (OptionGroup) event - .getTarget(); - target.clearOptions(); - final PageState state = event.getPageState(); - - // gather the content types of this section into a list - final ContentSection section = getContentSection(state); -// final ContentType parentType; - final List typesCollection; - final Long singleTypeID = (Long) state.getValue( - new LongParameter(ItemSearch.SINGLE_TYPE_PARAM)); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final NewItemFormController controller = cdiUtil.findBean( - NewItemFormController.class); - final ContentTypeRepository typeRepo = cdiUtil.findBean( - ContentTypeRepository.class); - final ContentTypesManager typesManager = cdiUtil.findBean( - ContentTypesManager.class); - final PermissionChecker permissionChecker = cdiUtil - .findBean(PermissionChecker.class); - - typesCollection = controller.getContentTypes(section); - - for (final ContentType type : typesCollection) { - final ContentTypeInfo typeInfo = typesManager - .getContentTypeInfo(type.getContentItemClass()); - final String value = Long.toString(type.getObjectId()); - final Label label = new Label( - new GlobalizedMessage(typeInfo.getLabelKey(), - typeInfo.getLabelBundle())); - target.addOption( - new Option(value, label)); - } - } - - }); - } catch (TooManyListenersException ex) { - throw new UncheckedWrapperException("Too many listeners.", ex); - } - - panel.add(typeSelect); - - submit = new Submit("new", - new GlobalizedMessage("cms.ui.authoring.go", - CmsConstants.CMS_BUNDLE)); - panel.add(submit); - - add(panel); - } - - public abstract ContentSection getContentSection(PageState state); - - /** - * - * @param state - * - * @return - */ - public Long getTypeID(final PageState state) { - return (Long) typeSelect.getValue(state); - } - - /** - * - * @return - */ - public final SingleSelect getTypeSelect() { - return typeSelect; - } - - /** - * Generate XML - show/hide labels/widgets - * - * @param state - * @param parent - */ - @Override - public void generateXML(final PageState state, final Element parent) { - - if (isVisible(state)) { - final ContentSection section = getContentSection(state); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final NewItemFormController controller = cdiUtil.findBean( - NewItemFormController.class); - boolean isEmpty = !controller.hasContentTypes(section); - - createLabel.setVisible(state, !isEmpty); - typeSelect.setVisible(state, !isEmpty); - submit.setVisible(state, !isEmpty); - emptyLabel.setVisible(state, isEmpty); - - super.generateXML(state, parent); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/news/NewItemFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/news/NewItemFormController.java deleted file mode 100644 index 478226cbb..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/news/NewItemFormController.java +++ /dev/null @@ -1,124 +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.authoring.news; - -import org.libreccm.l10n.GlobalizationHelper; - -import java.util.Collections; -import java.util.List; - -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.ContentSectionRepository; - -import java.util.Objects; -import java.util.Optional; -import java.util.stream.Collectors; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.persistence.EntityManager; -import javax.persistence.TypedQuery; -import javax.transaction.Transactional; - -import org.libreccm.security.PermissionChecker; -import org.libreccm.security.Role; -import org.libreccm.security.RoleRepository; -import org.libreccm.security.Shiro; -import org.libreccm.security.User; -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.contentsection.ContentType; -import org.librecms.contentsection.ContentTypeRepository; -import org.librecms.contenttypes.News; - -import java.util.Locale; - -/** - * Controller class for the {@link NewItemForm}. - * - * @author Jens Pelzetter - */ -@RequestScoped -class NewItemFormController { - - @Inject - private EntityManager entityManager; - - @Inject - private Shiro shiro; - - @Inject - private PermissionChecker permissionChecker; - - @Inject - private RoleRepository roleRepo; - - @Inject - private ContentSectionRepository sectionRepo; - - @Inject - private ContentTypeRepository typeRepo; - - @Transactional(Transactional.TxType.REQUIRED) - protected boolean hasContentTypes(final ContentSection section) { - Objects.requireNonNull(section, "Can't work with null for the section."); - - final Optional user = shiro.getUser(); - if (!user.isPresent()) { - return false; - } - - final List roles = user.get().getRoleMemberships().stream() - .map(membership -> membership.getRole()) - .collect(Collectors.toList()); - - final TypedQuery query = entityManager.createNamedQuery( - "ContentSection.hasUsableContentTypes", Boolean.class); - query.setParameter("section", section); - query.setParameter("roles", roles); - query.setParameter("isSysAdmin", permissionChecker.isPermitted("*")); - - return query.getSingleResult(); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected List getContentTypes(final ContentSection section) { - Objects.requireNonNull(section); - - final Optional user = shiro.getUser(); - if (!user.isPresent()) { - return Collections.EMPTY_LIST; - } - - final List roles = user.get().getRoleMemberships().stream() - .map(membership -> membership.getRole()) - .collect(Collectors.toList()); - - final TypedQuery query = entityManager.createNamedQuery( - "ContentSection.findUsableContentTypes", - ContentType.class); - query.setParameter("section", section); - query.setParameter("roles", roles); - query.setParameter("isSysAdmin", permissionChecker.isPermitted("*")); - - return query.getResultList(); - } - - - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/news/NewsController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/news/NewsController.java deleted file mode 100644 index 716cd2a8c..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/news/NewsController.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2021 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.authoring.news; - -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.contenttypes.News; - -import java.util.Date; -import java.util.Locale; -import java.util.Objects; - -import javax.inject.Inject; -import javax.transaction.Transactional; - -/** - * - * @author Jens Pelzetter - */ -public class NewsController { - - @Inject - private ContentItemRepository itemRepo; - - @Transactional - protected String getDescription( - final News fromNews, final Locale forLocale - ) { - Objects.requireNonNull(fromNews); - final News news = itemRepo - .findById(fromNews.getObjectId(), News.class) - .orElseThrow( - () -> new IllegalArgumentException( - String.format( - "No News with ID %d available.", fromNews.getObjectId() - ) - ) - ); - - return news.getDescription().getValue(forLocale); - } - - @Transactional - protected String getText(final News fromNews, final Locale forLocale) { - Objects.requireNonNull(fromNews); - final News news = itemRepo - .findById(fromNews.getObjectId(), News.class) - .orElseThrow( - () -> new IllegalArgumentException( - String.format( - "No News with ID %d available", - fromNews.getObjectId() - ) - ) - ); - - return news.getText().getValue(forLocale); - } - - @Transactional - protected void updateText( - final News ofNews, - final Locale forLocale, - final String text - ) { - Objects.requireNonNull(ofNews); - final News news = itemRepo - .findById(ofNews.getObjectId(), News.class) - .orElseThrow( - () -> new IllegalArgumentException( - String.format( - "No News with ID %d available", - ofNews.getObjectId() - ) - ) - ); - - news.getText().putValue(forLocale, text); - itemRepo.save(news); - } - - @Transactional - protected void update( - final News news, - final Date releaseDate, - final Locale locale, - final String description - ) { - Objects.requireNonNull(news); - final News update = itemRepo - .findById(news.getObjectId(), News.class) - .orElseThrow( - () -> new IllegalArgumentException( - String.format( - "No News with ID %d available", - news.getObjectId() - ) - ) - ); - - update.setReleaseDate(releaseDate); - update.getDescription().putValue(locale, description); - itemRepo.save(update); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/news/NewsPropertiesStep.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/news/NewsPropertiesStep.java deleted file mode 100755 index 021af1c9c..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/news/NewsPropertiesStep.java +++ /dev/null @@ -1,218 +0,0 @@ -/* - * Copyright (C) 2002-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.news; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.parameters.StringParameter; - -import com.arsdigita.cms.ItemSelectionModel; - -import org.librecms.contenttypes.News; - -import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; -import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; -import com.arsdigita.cms.ui.authoring.BasicPageForm; -import com.arsdigita.cms.ui.authoring.SimpleEditStep; -import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.core.UnexpectedErrorException; -import org.libreccm.l10n.GlobalizationHelper; -import org.librecms.CmsConstants; - -import java.beans.BeanInfo; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.text.DateFormat; -import java.util.Arrays; -import java.util.Objects; -import java.util.Optional; - -/** - * Authoring step to edit the simple attributes of the News content type (and - * its subclasses). The attributes edited are {@code name}, {@code title}, - * {@code lead} and {@code item date}. This authoring step replaces the - * {@link com.arsdigita.ui.authoring.PageEdit} step for this type. - * - * @see com.arsdigita.cms.contenttypes.NewsItem - * - */ -public class NewsPropertiesStep extends SimpleEditStep { - - /** - * The name of the editing sheet added to this step - */ - public static String EDIT_SHEET_NAME = "edit"; - - public NewsPropertiesStep(final ItemSelectionModel itemModel, - final AuthoringKitWizard parent, - final StringParameter selectedLanguageParam) { - - super(itemModel, parent, selectedLanguageParam); - - Objects.requireNonNull(selectedLanguageParam); - - setDefaultEditKey(EDIT_SHEET_NAME); - BasicPageForm editSheet; - - editSheet = new NewsPropertyForm(itemModel, this, selectedLanguageParam); - add(EDIT_SHEET_NAME, - new GlobalizedMessage("cms.ui.edit", CmsConstants.CMS_BUNDLE), - new WorkflowLockedComponentAccess(editSheet, itemModel), - editSheet.getSaveCancelSection().getCancelButton()); - - setDisplayComponent(getNewsDomainObjectPropertySheet( - itemModel, - selectedLanguageParam)); - } - - /** - * Returns a component that displays the properties of the NewsItem - * specified by the ItemSelectionModel passed in. - * - * @param itemModel The ItemSelectionModel to use - * @param selectedLanguageParam - * - * @pre itemModel != null - * @return A component to display the state of the basic properties of the - * item - * - */ - public static Component getNewsDomainObjectPropertySheet( - final ItemSelectionModel itemModel, - final StringParameter selectedLanguageParam) { - - final DomainObjectPropertySheet sheet = new DomainObjectPropertySheet( - itemModel, - false, - selectedLanguageParam); - - sheet.add(new GlobalizedMessage("cms.contenttypes.ui.title", - CmsConstants.CMS_BUNDLE), - "title"); - sheet.add(new GlobalizedMessage("cms.contenttypes.ui.name", - CmsConstants.CMS_BUNDLE), - "name"); - sheet.add(new GlobalizedMessage("cms.contenttypes.ui.newsitem.lead", - CmsConstants.CMS_BUNDLE), - "description"); - - // Show news item on homepage? - sheet.add(new GlobalizedMessage( - "cms.contenttypes.ui.newsitem.date", - CmsConstants.CMS_BUNDLE), - "releaseDate", - new NewsItemDateAttributeFormatter()); - - return sheet; - } - - /** - * Private class which implements an AttributeFormatter interface for - * NewsItem's date values. Its format(...) class returns a string - * representation for either a false or a true value. - */ - private static class NewsItemDateAttributeFormatter - implements DomainObjectPropertySheet.AttributeFormatter { - - /** - * Constructor, does nothing. - */ - public NewsItemDateAttributeFormatter() { - } - - /** - * Formatter for the value of an attribute. - * - * It currently relays on the prerequisite that the passed in property - * attribute is in fact a date property. No type checking yet! - * - * Note: the format method has to be executed at each page request. Take - * care to properly adjust globalization and localization here! - * - * @param obj Object containing the attribute to format. - * @param attribute Name of the attribute to retrieve and format - * @param state PageState of the request - * - * @return A String representation of the retrieved boolean attribute of - * the domain object. - */ - public String format(final Object obj, - final String attribute, - final PageState state) { - - if (obj != null && obj instanceof News) { - - final News newsItem = (News) obj; - final BeanInfo beanInfo; - try { - beanInfo = Introspector.getBeanInfo(obj.getClass()); - } catch (IntrospectionException ex) { - throw new UnexpectedErrorException(ex); - } - final Optional propertyDescriptor = Arrays - .stream(beanInfo.getPropertyDescriptors()) - .filter(current -> attribute.equals(current.getName())) - .findAny(); - - if (propertyDescriptor.isPresent()) { - final GlobalizationHelper globalizationHelper = CdiUtil - .createCdiUtil().findBean(GlobalizationHelper.class); - - final Method readMethod = propertyDescriptor - .get() - .getReadMethod(); - - final Object result; - try { - result = readMethod.invoke(obj); - } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { - throw new UnexpectedErrorException(ex); - } - - return DateFormat - .getDateInstance( - DateFormat.LONG, - globalizationHelper.getNegotiatedLocale()) - .format(result); - - } else { - return (String) new GlobalizedMessage( - "cms.ui.unknown", - CmsConstants.CMS_BUNDLE) - .localize(); - } - - } else { - return (String) new GlobalizedMessage("cms.ui.unknown", - CmsConstants.CMS_BUNDLE) - .localize(); - } - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/news/NewsPropertyForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/news/NewsPropertyForm.java deleted file mode 100755 index 0a6ae4515..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/news/NewsPropertyForm.java +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright (C) 2002-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.news; - -import com.arsdigita.bebop.FormData; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormInitListener; -import com.arsdigita.bebop.event.FormProcessListener; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.event.FormSubmissionListener; -import com.arsdigita.bebop.form.TextArea; -import com.arsdigita.bebop.parameters.DateParameter; -import com.arsdigita.bebop.parameters.NotNullValidationListener; -import com.arsdigita.bebop.parameters.ParameterModel; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.ItemSelectionModel; - -import org.librecms.contenttypes.News; - -import com.arsdigita.cms.ui.authoring.BasicPageForm; -import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.configuration.ConfigurationManager; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.contenttypes.NewsConfig; - -import java.util.Calendar; -import java.util.Date; -import java.util.GregorianCalendar; -import java.util.Locale; -import java.util.Objects; - -/** - * Form to edit the basic properties of a {@link News} item. These are name, - * title, item date and reference code. Used by {@link NewsPropertiesStep} - * authoring kit step. - * - * This form can be extended to create forms for NewsItem subclasses. - * - */ -public class NewsPropertyForm extends BasicPageForm - implements FormProcessListener, FormInitListener, FormSubmissionListener { - - private NewsPropertiesStep propertiesStep; - /** - * lead parameter name - */ - public static final String LEAD = "lead"; - /** - * Item date parameter name - */ - public static final String NEWS_DATE = "news_date"; - public static final String IS_HOMEPAGE = "isHomepage"; - /** - * Name of this form - */ - public static final String ID = "news_item_edit"; - - private final StringParameter selectedLanguageParam; - - private com.arsdigita.bebop.form.Date releaseDateSelector; - - /** - * Creates a new form to edit the NewsItem object specified by the item - * selection model passed in. - * - * @param itemSelectionModel The ItemSelectionModel to use to obtain the - * NewsItem to work on - * @param selectedLanguageParam - */ - public NewsPropertyForm(final ItemSelectionModel itemSelectionModel, - final StringParameter selectedLanguageParam) { - - this(itemSelectionModel, null, selectedLanguageParam); - } - - /** - * Creates a new form to edit the NewsItem object specified by the item - * selection model passed in. - * - * @param itemSelectionModel The ItemSelectionModel to use to obtain the - * NewsItem to work on - * @param propertiesStep The NewsPropertiesStep which controls this - * form. - * @param selectedLanguageParam - */ - public NewsPropertyForm(final ItemSelectionModel itemSelectionModel, - final NewsPropertiesStep propertiesStep, - final StringParameter selectedLanguageParam) { - - super(ID, itemSelectionModel, selectedLanguageParam); - - Objects.requireNonNull(selectedLanguageParam); - - this.propertiesStep = propertiesStep; - this.selectedLanguageParam = selectedLanguageParam; - addSubmissionListener(this); - } - - /** - * Adds widgets to the form. - */ - @Override - protected void addWidgets() { - - super.addWidgets(); - - final ParameterModel leadParam = new StringParameter(LEAD); - final TextArea lead = new TextArea(leadParam); - lead.setLabel(new GlobalizedMessage( - "cms.contenttypes.ui.newsitem.lead", - CmsConstants.CMS_BUNDLE)); - lead.setCols(50); - lead.setRows(5); - add(lead); - - final ConfigurationManager confManager = CdiUtil - .createCdiUtil() - .findBean(ConfigurationManager.class); - final NewsConfig newsConfig = confManager - .findConfiguration(NewsConfig.class); - - final int startYear = newsConfig.getStartYear(); - final int endYearDelta = newsConfig.getEndYearDelta(); - final int currentYear = GregorianCalendar - .getInstance() - .get(Calendar.YEAR); - final int endYear = currentYear + endYearDelta; - - final ParameterModel newsDateParam = new DateParameter(NEWS_DATE); - newsDateParam.addParameterListener(new NotNullValidationListener()); - releaseDateSelector = new com.arsdigita.bebop.form.Date(newsDateParam); - releaseDateSelector.setYearRange(startYear, endYear); - releaseDateSelector.setLabel(new GlobalizedMessage( - "cms.contenttypes.ui.newsitem.date", - CmsConstants.CMS_BUNDLE)); - add(releaseDateSelector); - } - - /** - * Form initialisation hook. Fills widgets with data. - * - * @param event - */ - @Override - public void init(final FormSectionEvent event) { - final FormData data = event.getFormData(); - final PageState state = event.getPageState(); - final News item = (News) super.initBasicWidgets(event); - - // set a default item date, if none set - final java.util.Date releaseDate; - if (item.getReleaseDate() == null) { - // new Date is initialised to current time - releaseDate = new java.util.Date(); - } else { - releaseDate = item.getReleaseDate(); - } - - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - - releaseDateSelector.addYear(releaseDate); - data.put(NEWS_DATE, releaseDate); - final NewsController controller = CdiUtil - .createCdiUtil() - .findBean(NewsController.class); - data.put(LEAD, controller.getDescription(item, selectedLocale)); - } - - /** - * Cancels streamlined editing. - * - * @param event - */ - @Override - public void submitted(final FormSectionEvent event) { - if (propertiesStep != null - && getSaveCancelSection() - .getCancelButton() - .isSelected(event.getPageState())) { - propertiesStep.cancelStreamlinedCreation(event.getPageState()); - } - } - - /** - * Form processing hook. Saves NewsItem object. - * - * @param event - */ - @Override - public void process(final FormSectionEvent event) { - - final FormData data = event.getFormData(); - final PageState state = event.getPageState(); - - final News item = (News) super.processBasicWidgets(event); - - // save only if save button was newsed - if (item != null - && getSaveCancelSection() - .getSaveButton() - .isSelected(event.getPageState())) { - - final NewsController controller = CdiUtil - .createCdiUtil() - .findBean(NewsController.class); - - final Date releaseDate = (java.util.Date) data.get(NEWS_DATE); - final String description = (String) data.get(LEAD); - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - controller.update(item, releaseDate, selectedLocale, description); - } - if (propertiesStep != null) { - propertiesStep.maybeForwardToNextStep(event.getPageState()); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/news/NewsTextBody.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/news/NewsTextBody.java deleted file mode 100644 index ca3d50771..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/news/NewsTextBody.java +++ /dev/null @@ -1,109 +0,0 @@ -package com.arsdigita.cms.ui.authoring.news; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.form.SingleSelect; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; -import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil; -import com.arsdigita.cms.ui.authoring.TextBody; -import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; -import com.arsdigita.kernel.KernelConfig; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.contenttypes.News; - -import java.util.Locale; - -import static com.arsdigita.cms.ui.authoring.TextBody.*; - -/** - * - * @author Jens Pelzetter - */ -public class NewsTextBody extends TextBody { - - private final ItemSelectionModel itemSelectionModel; - private final StringParameter selectedLanguageParam; - - public NewsTextBody(final ItemSelectionModel itemSelectionModel, - final AuthoringKitWizard authoringKitWizard, - final StringParameter selectedLanguageParam) { - - super(itemSelectionModel, selectedLanguageParam); - - this.itemSelectionModel = itemSelectionModel; - this.selectedLanguageParam = selectedLanguageParam; - - // Rest the component when it is hidden - authoringKitWizard - .getList() - .addActionListener(event -> reset(event.getPageState())); - - // Set the right component access on the forms - final Component uploadComponent = getComponent(FILE_UPLOAD); - if (uploadComponent != null) { - setComponentAccess(FILE_UPLOAD, - new WorkflowLockedComponentAccess( - uploadComponent, itemSelectionModel)); - } - final Component textEntryComponent = getComponent(TEXT_ENTRY); - setComponentAccess(TEXT_ENTRY, - new WorkflowLockedComponentAccess( - textEntryComponent, itemSelectionModel)); - } - - /** - * Adds the options for the mime type select widget of - * GenericArticleForm and sets the default mime type. - * - * @param mimeSelect - */ - @Override - protected void setMimeTypeOptions(final SingleSelect mimeSelect) { - mimeSelect.addOption(new Option("text/html", "HTML Text")); - mimeSelect.setOptionSelected("text/html"); - } - - protected News getSelectedNews(final PageState state) { - - return (News) itemSelectionModel.getSelectedItem(state); - } - - @Override - protected String getTextPropertyName() { - return "text"; - } - - @Override - public String getText(final PageState state) { - - final News news = getSelectedNews(state); - - final NewsController controller = CdiUtil - .createCdiUtil() - .findBean(NewsController.class); - return controller.getText( - news, - SelectedLanguageUtil.selectedLocale(state, selectedLanguageParam) - ); - } - - @Override - protected void updateText(final PageState state, final String text) { - - final News news = getSelectedNews(state); - - final Locale selectedLocale = SelectedLanguageUtil - .selectedLocale(state, selectedLanguageParam); - - final NewsController controller = CdiUtil - .createCdiUtil() - .findBean(NewsController.class); - controller.updateText(news, selectedLocale, text); - } - -} diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/Article.java b/ccm-cms/src/main/java/org/librecms/contenttypes/Article.java index 9a5c10dcb..276623ff3 100644 --- a/ccm-cms/src/main/java/org/librecms/contenttypes/Article.java +++ b/ccm-cms/src/main/java/org/librecms/contenttypes/Article.java @@ -18,9 +18,6 @@ */ package org.librecms.contenttypes; -import com.arsdigita.cms.ui.authoring.article.ArticlePropertiesStep; -import com.arsdigita.cms.ui.authoring.article.ArticleTextBody; -import com.arsdigita.cms.ui.authoring.PageCreateForm; import java.io.Serializable; import java.util.Objects; @@ -34,7 +31,6 @@ import javax.persistence.Table; import org.hibernate.envers.Audited; import org.libreccm.l10n.LocalizedString; -import org.librecms.CmsConstants; import static org.librecms.CmsConstants.*; @@ -55,26 +51,6 @@ import javax.xml.bind.annotation.XmlRootElement; @Table(name = "ARTICLES", schema = DB_SCHEMA) @ContentTypeDescription(labelBundle = "org.librecms.contenttypes.Article", descriptionBundle = "org.librecms.contenttypes.Article") -@AuthoringKit( - createComponent = PageCreateForm.class, - steps = { - @AuthoringStep( - component = ArticlePropertiesStep.class, - labelBundle = CmsConstants.CMS_BUNDLE, - labelKey = "cms.contenttypes.shared.basic_properties.title", - descriptionBundle = CmsConstants.CMS_BUNDLE, - descriptionKey = "cms.contenttypes.shared.basic_properties" - + ".description", - order = 1), - @AuthoringStep( - component = ArticleTextBody.class, - labelBundle = CmsConstants.CMS_BUNDLE, - labelKey = "cms.contenttypes.shared.body_text.title", - descriptionBundle = CmsConstants.CMS_BUNDLE, - descriptionKey = "cms.contenttypes.shared.body_text.description", - order = 2 - ) - }) @MvcAuthoringKit( createStep = MvcArticleCreateStep.class, authoringSteps = { diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/Event.java b/ccm-cms/src/main/java/org/librecms/contenttypes/Event.java index 36c4479af..7769f5c5f 100644 --- a/ccm-cms/src/main/java/org/librecms/contenttypes/Event.java +++ b/ccm-cms/src/main/java/org/librecms/contenttypes/Event.java @@ -18,9 +18,6 @@ */ package org.librecms.contenttypes; -import com.arsdigita.cms.ui.authoring.event.EventPropertiesStep; -import com.arsdigita.cms.ui.authoring.event.EventTextBody; -import com.arsdigita.cms.ui.contenttypes.EventCreateForm; import java.io.Serializable; import java.util.Date; @@ -39,7 +36,6 @@ import javax.persistence.TemporalType; import org.hibernate.envers.Audited; import org.libreccm.l10n.LocalizedString; -import org.librecms.CmsConstants; import org.librecms.contentsection.ContentItem; import org.librecms.ui.contentsections.documents.MvcAuthoringKit; @@ -58,27 +54,6 @@ import static org.librecms.CmsConstants.DB_SCHEMA; @Table(name = "EVENTS", schema = DB_SCHEMA) @ContentTypeDescription(labelBundle = "org.librecms.contenttypes.Event", descriptionBundle = "org.librecms.contenttypes.Event") -@AuthoringKit( - createComponent = EventCreateForm.class, - steps = { - @AuthoringStep( - component = EventPropertiesStep.class, - labelBundle = CmsConstants.CMS_BUNDLE, - labelKey = "cms.contenttypes.shared.basic_properties.title", - descriptionBundle = CmsConstants.CMS_BUNDLE, - descriptionKey = "cms.contenttypes.shared.basic_properties" - + ".description", - order = 1 - ), - @AuthoringStep( - component = EventTextBody.class, - labelBundle = CmsConstants.CMS_BUNDLE, - labelKey = "cms.contenttypes.shared.body_text.title", - descriptionBundle = CmsConstants.CMS_BUNDLE, - descriptionKey = "cms.contenttypes.shared.body_text.description", - order = 2 - ) - }) @MvcAuthoringKit( createStep = MvcEventCreateStep.class, authoringSteps = { diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/MultiPartArticle.java b/ccm-cms/src/main/java/org/librecms/contenttypes/MultiPartArticle.java index b02c26cb1..40725b73b 100644 --- a/ccm-cms/src/main/java/org/librecms/contenttypes/MultiPartArticle.java +++ b/ccm-cms/src/main/java/org/librecms/contenttypes/MultiPartArticle.java @@ -18,13 +18,9 @@ */ package org.librecms.contenttypes; -import com.arsdigita.cms.ui.authoring.multipartarticle.MultiPartArticleCreateForm; -import com.arsdigita.cms.ui.authoring.multipartarticle.MultiPartArticleEdit; -import com.arsdigita.cms.ui.authoring.multipartarticle.MultiPartArticleSectionsStep; import org.hibernate.envers.Audited; import org.libreccm.l10n.LocalizedString; -import org.librecms.CmsConstants; import org.librecms.contentsection.ContentItem; import org.librecms.ui.contentsections.documents.MvcAuthoringKit; import org.librecms.ui.contenttypes.mpa.MvcMpaCreateStep; @@ -59,28 +55,6 @@ import static org.librecms.CmsConstants.*; labelBundle = "org.librecms.contenttypes.MultiPartArticle", descriptionBundle = "org.librecms.contenttypes.MultiPartArticle" ) -@AuthoringKit( - createComponent = MultiPartArticleCreateForm.class, - steps = { - @AuthoringStep( - component = MultiPartArticleEdit.class, - labelBundle = CmsConstants.CMS_BUNDLE, - labelKey = "cms.contenttypes.shared.basic_properties.title", - descriptionBundle = CmsConstants.CMS_BUNDLE, - descriptionKey = "cms.contenttypes.shared.basic_properties" - + ".description", - order = 1 - ), - @AuthoringStep( - component = MultiPartArticleSectionsStep.class, - labelBundle = CmsConstants.CMS_BUNDLE, - labelKey = "mparticle.authoring.body_text.label", - descriptionBundle = CmsConstants.CMS_BUNDLE, - descriptionKey = "mparticle.authoring.body_text.description", - order = 2 - ) - } -) @MvcAuthoringKit( createStep = MvcMpaCreateStep.class, authoringSteps = { diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/News.java b/ccm-cms/src/main/java/org/librecms/contenttypes/News.java index 18a9d90a0..2aa842678 100644 --- a/ccm-cms/src/main/java/org/librecms/contenttypes/News.java +++ b/ccm-cms/src/main/java/org/librecms/contenttypes/News.java @@ -18,13 +18,9 @@ */ package org.librecms.contenttypes; -import com.arsdigita.cms.ui.authoring.news.NewsPropertiesStep; -import com.arsdigita.cms.ui.authoring.news.NewsTextBody; -import com.arsdigita.cms.ui.contenttypes.NewsCreateForm; import org.hibernate.envers.Audited; import org.libreccm.l10n.LocalizedString; -import org.librecms.CmsConstants; import org.librecms.contentsection.ContentItem; import org.librecms.ui.contentsections.documents.MvcAuthoringKit; import org.librecms.ui.contenttypes.news.MvcNewsCreateStep; @@ -57,27 +53,6 @@ import static org.librecms.CmsConstants.*; @Table(name = "NEWS", schema = DB_SCHEMA) @ContentTypeDescription(labelBundle = "org.librecms.contenttypes.News", descriptionBundle = "org.librecms.contenttypes.News") -@AuthoringKit( - createComponent = NewsCreateForm.class, - steps = { - @AuthoringStep( - component = NewsPropertiesStep.class, - labelBundle = CmsConstants.CMS_BUNDLE, - labelKey = "cms.contenttypes.shared.basic_properties.title", - descriptionBundle = CmsConstants.CMS_BUNDLE, - descriptionKey = "cms.contenttypes.shared.basic_properties" - + ".description", - order = 1) - , - @AuthoringStep( - component = NewsTextBody.class, - labelBundle = CmsConstants.CMS_BUNDLE, - labelKey = "cms.contenttypes.shared.body_text.title", - descriptionBundle = CmsConstants.CMS_BUNDLE, - descriptionKey = "cms.contenttypes.shared.body_text.description", - order = 2 - ) - }) @MvcAuthoringKit( createStep = MvcNewsCreateStep.class, authoringSteps = {