From 198c7d7b83b5a0552b460adf86b68746b0fa3987 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Mon, 14 Mar 2022 20:03:05 +0100 Subject: [PATCH 01/63] Removed legacy components from ccm-cms-profile-site --- .../ui/ProfileSiteItemController.java | 130 ------------------ .../ui/ProfileSiteItemCreate.java | 93 ------------- .../ui/ProfileSiteItemInterestsForm.java | 121 ---------------- .../ui/ProfileSiteItemInterestsStep.java | 94 ------------- .../ui/ProfileSiteItemMiscForm.java | 121 ---------------- .../ui/ProfileSiteItemMiscStep.java | 94 ------------- .../ui/ProfileSiteItemPositionForm.java | 121 ---------------- .../ui/ProfileSiteItemPositionStep.java | 94 ------------- .../ui/ProfileSiteItemPropertiesStep.java | 129 ----------------- .../ui/ProfileSiteItemPropertyForm.java | 117 ---------------- .../librecms/profilesite/ProfileSiteItem.java | 44 ------ 11 files changed, 1158 deletions(-) delete mode 100644 ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemController.java delete mode 100644 ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemCreate.java delete mode 100644 ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemInterestsForm.java delete mode 100644 ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemInterestsStep.java delete mode 100644 ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemMiscForm.java delete mode 100644 ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemMiscStep.java delete mode 100644 ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemPositionForm.java delete mode 100644 ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemPositionStep.java delete mode 100644 ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemPropertiesStep.java delete mode 100644 ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemPropertyForm.java diff --git a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemController.java b/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemController.java deleted file mode 100644 index 6d4ed905e..000000000 --- a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemController.java +++ /dev/null @@ -1,130 +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.contenttypes.ui; - -import org.librecms.assets.Person; -import org.librecms.contentsection.AssetRepository; -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.profilesite.ProfileSiteItem; - -import java.util.Locale; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.transaction.Transactional; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -class ProfileSiteItemController { - - public static final String OWNER = "owner"; - - public static final String POSITION = "position"; - - public static final String INTERSETS = "interests"; - - public static final String MISC = "misc"; - - @Inject - private AssetRepository assetRepository; - - @Inject - private ContentItemRepository itemRepository; - - @Transactional(Transactional.TxType.REQUIRED) - public void setOwner(final long profileSiteItemId, final long ownerId) { - final ProfileSiteItem profileSiteItem = itemRepository - .findById(profileSiteItemId, ProfileSiteItem.class) - .orElseThrow( - () -> new IllegalArgumentException( - String.format( - "No ProfileSiteItem with ID %d found.", - profileSiteItemId - ) - ) - ); - - final Person owner = assetRepository - .findById(ownerId, Person.class) - .orElseThrow( - () -> new IllegalArgumentException( - String.format( - "No Person with ID %d found.", ownerId - ) - ) - ); - - profileSiteItem.setOwner(owner); - itemRepository.save(profileSiteItem); - } - - public void setPosition( - final long profileSiteItemId, final String position, final Locale locale - ) { - final ProfileSiteItem profileSiteItem = itemRepository - .findById(profileSiteItemId, ProfileSiteItem.class) - .orElseThrow( - () -> new IllegalArgumentException( - String.format( - "No ProfileSiteItem with ID %d found.", - profileSiteItemId - ) - ) - ); - profileSiteItem.getPosition().putValue(locale, position); - } - - public void setInterests( - final long profileSiteItemId, - final String interests, - final Locale locale - ) { - final ProfileSiteItem profileSiteItem = itemRepository - .findById(profileSiteItemId, ProfileSiteItem.class) - .orElseThrow( - () -> new IllegalArgumentException( - String.format( - "No ProfileSiteItem with ID %d found.", - profileSiteItemId - ) - ) - ); - profileSiteItem.getInterests().putValue(locale, interests); - } - - public void setMisc( - final long profileSiteItemId, final String misc, final Locale locale - ) { - final ProfileSiteItem profileSiteItem = itemRepository - .findById(profileSiteItemId, ProfileSiteItem.class) - .orElseThrow( - () -> new IllegalArgumentException( - String.format( - "No ProfileSiteItem with ID %d found.", - profileSiteItemId - ) - ) - ); - profileSiteItem.getMisc().putValue(locale, misc); - } - -} diff --git a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemCreate.java b/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemCreate.java deleted file mode 100644 index 2f02dcccd..000000000 --- a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemCreate.java +++ /dev/null @@ -1,93 +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.contenttypes.ui; - -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.parameters.StringParameter; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.assets.AssetSearchWidget; -import com.arsdigita.cms.ui.authoring.CreationSelector; -import com.arsdigita.cms.ui.authoring.PageCreateForm; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.librecms.assets.Person; -import org.librecms.contentsection.ContentItemInitializer; -import org.librecms.profilesite.ProfileSiteConstants; -import org.librecms.profilesite.ProfileSiteItem; - -import java.util.Locale; - -/** - * - * @author Jens Pelzetter - */ -public class ProfileSiteItemCreate extends PageCreateForm { - - private final static String OWNER_SEARCH = "owner"; - - private AssetSearchWidget ownerSearch; - - public ProfileSiteItemCreate( - final ItemSelectionModel itemModel, - final CreationSelector creationSelector, - final StringParameter selectedLanguageParam - ) { - super(itemModel, creationSelector, selectedLanguageParam); - } - - @Override - public void addWidgets() { - ownerSearch = new AssetSearchWidget(OWNER_SEARCH, Person.class); - ownerSearch.setLabel( - new GlobalizedMessage( - "profile_site.owner.label", ProfileSiteConstants.BUNDLE - ) - ); - add(ownerSearch); - } - - @Override - public void validate(final FormSectionEvent event) - throws FormProcessException { - super.validate(event); - final FormData formData = event.getFormData(); - - if (!formData.containsKey(OWNER_SEARCH) - || formData.get(OWNER_SEARCH) == null) { - formData.addError( - new GlobalizedMessage( - "profile_site.owner.not_selected", - ProfileSiteConstants.BUNDLE - ) - ); - } - } - - @Override - protected ContentItemInitializer getItemInitializer( - final FormData formData, final PageState state - ) { - return (item) -> item.setOwner((Person) formData.get(OWNER_SEARCH)); - } - - -} diff --git a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemInterestsForm.java b/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemInterestsForm.java deleted file mode 100644 index a0f7f25f7..000000000 --- a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemInterestsForm.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.contenttypes.ui; - -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.form.TextArea; -import com.arsdigita.bebop.parameters.ParameterModel; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.authoring.BasicItemForm; -import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.profilesite.ProfileSiteConstants; -import org.librecms.profilesite.ProfileSiteItem; - -import java.util.Locale; - -/** - * - * @author Jens Pelzetter - */ -public class ProfileSiteItemInterestsForm - extends BasicItemForm - implements FormProcessListener, FormInitListener { - - private final StringParameter selectedLangParam; - - public ProfileSiteItemInterestsForm( - final ItemSelectionModel itemModel, - final StringParameter selectedLangParam - ) { - super("ProfileSiteItemEditInterests", itemModel, selectedLangParam); - this.selectedLangParam = selectedLangParam; - } - - @Override - public void addWidgets() { - add( - new Label( - new GlobalizedMessage( - "profile_site_item.ui.interests", - ProfileSiteConstants.BUNDLE - ) - ) - ); - final ParameterModel interestsParam = new StringParameter( - ProfileSiteItemController.POSITION); - final TextArea interests = new TextArea(interestsParam); - interests.setCols(80); - interests.setRows(8); - add(interests); - } - - @Override - public void init(final FormSectionEvent event) throws FormProcessException { - final PageState state = event.getPageState(); - final FormData data = event.getFormData(); - final ProfileSiteItem profile - = (ProfileSiteItem) getItemSelectionModel() - .getSelectedItem(state); - - data.put(ProfileSiteItemController.POSITION, profile.getInterests()); - - setVisible(state, true); - } - - @Override - public void process(final FormSectionEvent event) - throws FormProcessException { - final PageState state = event.getPageState(); - final FormData data = event.getFormData(); - final ProfileSiteItem profile - = (ProfileSiteItem) getItemSelectionModel() - .getSelectedItem(state); - - if ((profile != null) - && getSaveCancelSection().getSaveButton().isSelected(state)) { - - final ProfileSiteItemController controller = CdiUtil - .createCdiUtil() - .findBean(ProfileSiteItemController.class); - - final Locale selectedLocale = SelectedLanguageUtil.selectedLocale( - state, selectedLangParam - ); - - controller.setInterests( - profile.getObjectId(), - (String) data.get(ProfileSiteItemController.POSITION), - selectedLocale - ); - } - - init(event); - } - -} diff --git a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemInterestsStep.java b/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemInterestsStep.java deleted file mode 100644 index db9e51832..000000000 --- a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemInterestsStep.java +++ /dev/null @@ -1,94 +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.contenttypes.ui; - -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.BasicItemForm; -import com.arsdigita.cms.ui.authoring.SimpleEditStep; -import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; - -import org.librecms.profilesite.ProfileSiteConstants; - -/** - * - * @author Jens Pelzetter - */ -public class ProfileSiteItemInterestsStep extends SimpleEditStep { - - private String EDIT_POSITION_SHEET_NAME = "editInterests"; - - public ProfileSiteItemInterestsStep( - final ItemSelectionModel itemModel, - final AuthoringKitWizard parent, - final StringParameter selectedLangParam - ) { - this(itemModel, parent, selectedLangParam, null); - } - - public ProfileSiteItemInterestsStep( - final ItemSelectionModel itemModel, - final AuthoringKitWizard parent, - final StringParameter selectedLangParam, - final String prefix - ) { - super(itemModel, parent, selectedLangParam, prefix); - - final BasicItemForm editInterestsForm = new ProfileSiteItemInterestsForm( - itemModel, selectedLangParam - ); - add( - EDIT_POSITION_SHEET_NAME, - new GlobalizedMessage( - "profile_site_site.ui.interests.edit", - ProfileSiteConstants.BUNDLE - ), - new WorkflowLockedComponentAccess(parent, itemModel), - editInterestsForm.getSaveCancelSection().getCancelButton() - ); - - setDisplayComponent(getProfileSiteItemInterestsSheet( - itemModel, selectedLangParam) - ); - } - - public static final Component getProfileSiteItemInterestsSheet( - final ItemSelectionModel itemModel, - final StringParameter selectedLangParam - ) { - final DomainObjectPropertySheet sheet = new DomainObjectPropertySheet( - itemModel, false, selectedLangParam - ); - - sheet.add( - new GlobalizedMessage( - "profile_site_item.ui.interests", - ProfileSiteConstants.BUNDLE - ), - ProfileSiteItemController.POSITION - ); - - return sheet; - } - -} diff --git a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemMiscForm.java b/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemMiscForm.java deleted file mode 100644 index 3d351c32b..000000000 --- a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemMiscForm.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.contenttypes.ui; - -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.form.TextArea; -import com.arsdigita.bebop.parameters.ParameterModel; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.authoring.BasicItemForm; -import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.profilesite.ProfileSiteConstants; -import org.librecms.profilesite.ProfileSiteItem; - -import java.util.Locale; - -/** - * - * @author Jens Pelzetter - */ -public class ProfileSiteItemMiscForm - extends BasicItemForm - implements FormProcessListener, FormInitListener { - - private final StringParameter selectedLangParam; - - public ProfileSiteItemMiscForm( - final ItemSelectionModel itemModel, - final StringParameter selectedLangParam - ) { - super("ProfileSiteItemEditMisc", itemModel, selectedLangParam); - this.selectedLangParam = selectedLangParam; - } - - @Override - public void addWidgets() { - add( - new Label( - new GlobalizedMessage( - "profile_site_item.ui.misc", - ProfileSiteConstants.BUNDLE - ) - ) - ); - final ParameterModel miscParam = new StringParameter( - ProfileSiteItemController.POSITION); - final TextArea misc = new TextArea(miscParam); - misc.setCols(80); - misc.setRows(8); - add(misc); - } - - @Override - public void init(final FormSectionEvent event) throws FormProcessException { - final PageState state = event.getPageState(); - final FormData data = event.getFormData(); - final ProfileSiteItem profile - = (ProfileSiteItem) getItemSelectionModel() - .getSelectedItem(state); - - data.put(ProfileSiteItemController.POSITION, profile.getMisc()); - - setVisible(state, true); - } - - @Override - public void process(final FormSectionEvent event) - throws FormProcessException { - final PageState state = event.getPageState(); - final FormData data = event.getFormData(); - final ProfileSiteItem profile - = (ProfileSiteItem) getItemSelectionModel() - .getSelectedItem(state); - - if ((profile != null) - && getSaveCancelSection().getSaveButton().isSelected(state)) { - - final ProfileSiteItemController controller = CdiUtil - .createCdiUtil() - .findBean(ProfileSiteItemController.class); - - final Locale selectedLocale = SelectedLanguageUtil.selectedLocale( - state, selectedLangParam - ); - - controller.setMisc( - profile.getObjectId(), - (String) data.get(ProfileSiteItemController.POSITION), - selectedLocale - ); - } - - init(event); - } - -} diff --git a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemMiscStep.java b/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemMiscStep.java deleted file mode 100644 index 654820940..000000000 --- a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemMiscStep.java +++ /dev/null @@ -1,94 +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.contenttypes.ui; - -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.BasicItemForm; -import com.arsdigita.cms.ui.authoring.SimpleEditStep; -import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; - -import org.librecms.profilesite.ProfileSiteConstants; - -/** - * - * @author Jens Pelzetter - */ -public class ProfileSiteItemMiscStep extends SimpleEditStep { - - private String EDIT_POSITION_SHEET_NAME = "editMisc"; - - public ProfileSiteItemMiscStep( - final ItemSelectionModel itemModel, - final AuthoringKitWizard parent, - final StringParameter selectedLangParam - ) { - this(itemModel, parent, selectedLangParam, null); - } - - public ProfileSiteItemMiscStep( - final ItemSelectionModel itemModel, - final AuthoringKitWizard parent, - final StringParameter selectedLangParam, - final String prefix - ) { - super(itemModel, parent, selectedLangParam, prefix); - - final BasicItemForm editMiscForm = new ProfileSiteItemMiscForm( - itemModel, selectedLangParam - ); - add( - EDIT_POSITION_SHEET_NAME, - new GlobalizedMessage( - "profile_site_site.ui.misc.edit", - ProfileSiteConstants.BUNDLE - ), - new WorkflowLockedComponentAccess(parent, itemModel), - editMiscForm.getSaveCancelSection().getCancelButton() - ); - - setDisplayComponent(getProfileSiteItemMiscSheet( - itemModel, selectedLangParam) - ); - } - - public static final Component getProfileSiteItemMiscSheet( - final ItemSelectionModel itemModel, - final StringParameter selectedLangParam - ) { - final DomainObjectPropertySheet sheet = new DomainObjectPropertySheet( - itemModel, false, selectedLangParam - ); - - sheet.add( - new GlobalizedMessage( - "profile_site_item.ui.misc", - ProfileSiteConstants.BUNDLE - ), - ProfileSiteItemController.POSITION - ); - - return sheet; - } - -} diff --git a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemPositionForm.java b/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemPositionForm.java deleted file mode 100644 index 1c6c7e7db..000000000 --- a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemPositionForm.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.contenttypes.ui; - -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.form.TextArea; -import com.arsdigita.bebop.parameters.ParameterModel; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.authoring.BasicItemForm; -import com.arsdigita.cms.ui.authoring.SelectedLanguageUtil; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.profilesite.ProfileSiteConstants; -import org.librecms.profilesite.ProfileSiteItem; - -import java.util.Locale; - -/** - * - * @author Jens Pelzetter - */ -public class ProfileSiteItemPositionForm - extends BasicItemForm - implements FormProcessListener, FormInitListener { - - private final StringParameter selectedLangParam; - - public ProfileSiteItemPositionForm( - final ItemSelectionModel itemModel, - final StringParameter selectedLangParam - ) { - super("ProfileSiteItemEditPosition", itemModel, selectedLangParam); - this.selectedLangParam = selectedLangParam; - } - - @Override - public void addWidgets() { - add( - new Label( - new GlobalizedMessage( - "profile_site_item.ui.position", - ProfileSiteConstants.BUNDLE - ) - ) - ); - final ParameterModel positionParam = new StringParameter( - ProfileSiteItemController.POSITION); - final TextArea position = new TextArea(positionParam); - position.setCols(80); - position.setRows(8); - add(position); - } - - @Override - public void init(final FormSectionEvent event) throws FormProcessException { - final PageState state = event.getPageState(); - final FormData data = event.getFormData(); - final ProfileSiteItem profile - = (ProfileSiteItem) getItemSelectionModel() - .getSelectedItem(state); - - data.put(ProfileSiteItemController.POSITION, profile.getPosition()); - - setVisible(state, true); - } - - @Override - public void process(final FormSectionEvent event) - throws FormProcessException { - final PageState state = event.getPageState(); - final FormData data = event.getFormData(); - final ProfileSiteItem profile - = (ProfileSiteItem) getItemSelectionModel() - .getSelectedItem(state); - - if ((profile != null) - && getSaveCancelSection().getSaveButton().isSelected(state)) { - - final ProfileSiteItemController controller = CdiUtil - .createCdiUtil() - .findBean(ProfileSiteItemController.class); - - final Locale selectedLocale = SelectedLanguageUtil.selectedLocale( - state, selectedLangParam - ); - - controller.setPosition( - profile.getObjectId(), - (String) data.get(ProfileSiteItemController.POSITION), - selectedLocale - ); - } - - init(event); - } - -} diff --git a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemPositionStep.java b/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemPositionStep.java deleted file mode 100644 index a0d549999..000000000 --- a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemPositionStep.java +++ /dev/null @@ -1,94 +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.contenttypes.ui; - -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.BasicItemForm; -import com.arsdigita.cms.ui.authoring.SimpleEditStep; -import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; - -import org.librecms.profilesite.ProfileSiteConstants; - -/** - * - * @author Jens Pelzetter - */ -public class ProfileSiteItemPositionStep extends SimpleEditStep { - - private String EDIT_POSITION_SHEET_NAME = "editPosition"; - - public ProfileSiteItemPositionStep( - final ItemSelectionModel itemModel, - final AuthoringKitWizard parent, - final StringParameter selectedLangParam - ) { - this(itemModel, parent, selectedLangParam, null); - } - - public ProfileSiteItemPositionStep( - final ItemSelectionModel itemModel, - final AuthoringKitWizard parent, - final StringParameter selectedLangParam, - final String prefix - ) { - super(itemModel, parent, selectedLangParam, prefix); - - final BasicItemForm editPositionForm = new ProfileSiteItemPositionForm( - itemModel, selectedLangParam - ); - add( - EDIT_POSITION_SHEET_NAME, - new GlobalizedMessage( - "profile_site_site.ui.position.edit", - ProfileSiteConstants.BUNDLE - ), - new WorkflowLockedComponentAccess(parent, itemModel), - editPositionForm.getSaveCancelSection().getCancelButton() - ); - - setDisplayComponent(getProfileSiteItemPositionSheet( - itemModel, selectedLangParam) - ); - } - - public static final Component getProfileSiteItemPositionSheet( - final ItemSelectionModel itemModel, - final StringParameter selectedLangParam - ) { - final DomainObjectPropertySheet sheet = new DomainObjectPropertySheet( - itemModel, false, selectedLangParam - ); - - sheet.add( - new GlobalizedMessage( - "profile_site_item.ui.position", - ProfileSiteConstants.BUNDLE - ), - ProfileSiteItemController.POSITION - ); - - return sheet; - } - -} diff --git a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemPropertiesStep.java b/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemPropertiesStep.java deleted file mode 100644 index fcab7902e..000000000 --- a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemPropertiesStep.java +++ /dev/null @@ -1,129 +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.contenttypes.ui; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SegmentedPanel; -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.authoring.SimpleEditStep; -import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.toolbox.ui.DomainObjectPropertySheet; - -import org.librecms.assets.Person; -import org.librecms.profilesite.ProfileSiteConstants; -import org.librecms.profilesite.ProfileSiteItem; - -/** - * - * @author Jens Pelzetter - */ -public class ProfileSiteItemPropertiesStep extends SimpleEditStep { - - public static final String EDIT_SHEET_NAME = "editProfileSiteItem"; - - public ProfileSiteItemPropertiesStep( - final ItemSelectionModel itemModel, - final AuthoringKitWizard parent, - final StringParameter selectedLangParam - ) { - super(itemModel, parent, selectedLangParam); - - setDefaultEditKey(EDIT_SHEET_NAME); - - final SimpleEditStep basicProperties = new SimpleEditStep( - itemModel, parent, selectedLangParam, EDIT_SHEET_NAME - ); - final BasicPageForm editBasicSheet = new ProfileSiteItemPropertyForm( - itemModel, this, selectedLangParam - ); - - basicProperties.add( - EDIT_SHEET_NAME, - new GlobalizedMessage( - ProfileSiteConstants.BUNDLE, - "profile_site.ui.edit_basic_properties" - ), - new WorkflowLockedComponentAccess(editBasicSheet, itemModel), - editBasicSheet.getSaveCancelSection().getCancelButton() - ); - - basicProperties.setDisplayComponent( - getProfileSiteItemPropertiesSheet(itemModel, selectedLangParam) - ); - - final SegmentedPanel segmentedPanel = new SegmentedPanel(); - segmentedPanel.addSegment( - new Label( - new GlobalizedMessage( - ProfileSiteConstants.BUNDLE, - "profile_site.ui.basic_properties" - ) - ), - basicProperties - ); - - setDisplayComponent(segmentedPanel); - } - - public static Component getProfileSiteItemPropertiesSheet( - final ItemSelectionModel itemModel, - final StringParameter selectedLangParam - ) { - final DomainObjectPropertySheet sheet = new DomainObjectPropertySheet( - itemModel, false, selectedLangParam - ); - - sheet.add( - new GlobalizedMessage( - ProfileSiteConstants.BUNDLE, "profile_site.ui.OWNER" - ), - ProfileSiteItemController.OWNER, - new OwnerFormatter() - ); - - return sheet; - } - - private static class OwnerFormatter - implements DomainObjectPropertySheet.AttributeFormatter { - - @Override - public String format( - final Object obj, final String attribute, final PageState state - ) { - final ProfileSiteItem profileSiteItem = (ProfileSiteItem) obj; - - final Person owner = profileSiteItem.getOwner(); - - if (owner == null) { - return ""; - } else { - return owner.getDisplayName(); - } - } - - } - -} diff --git a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemPropertyForm.java b/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemPropertyForm.java deleted file mode 100644 index 092cb18e6..000000000 --- a/ccm-cms-profile/src/main/java/com/arsdigita/cms/contenttypes/ui/ProfileSiteItemPropertyForm.java +++ /dev/null @@ -1,117 +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.contenttypes.ui; - -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.FormSectionEvent; -import com.arsdigita.bebop.event.FormValidationListener; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.assets.AssetSearchWidget; -import com.arsdigita.cms.ui.authoring.BasicPageForm; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.assets.Person; -import org.librecms.profilesite.ProfileSiteConstants; -import org.librecms.profilesite.ProfileSiteItem; - - -/** - * - * @author Jens Pelzetter - */ -public class ProfileSiteItemPropertyForm - extends BasicPageForm - implements FormInitListener, FormProcessListener, FormValidationListener { - - public static final String ID = "PublicPersonalProfile_edit"; - - private static final String OWNER_SEARCH = "ownerSearch"; - - private final ItemSelectionModel itemModel; - - public ProfileSiteItemPropertyForm( - final ItemSelectionModel itemModel, - final ProfileSiteItemPropertiesStep step, - final StringParameter selectedLangParam - ) { - super(ID, itemModel, selectedLangParam); - this.itemModel = itemModel; - addValidationListener(this); - } - - @Override - public void addWidgets() { - super.addWidgets(); - - final AssetSearchWidget ownerSearch = new AssetSearchWidget( - OWNER_SEARCH, Person.class - ); - add(ownerSearch); - } - - @Override - public void init(final FormSectionEvent event) throws FormProcessException { - final FormData formData = event.getFormData(); - final ProfileSiteItem profileSiteItem = (ProfileSiteItem) super - .initBasicWidgets(event); - formData.put(OWNER_SEARCH, profileSiteItem.getOwner()); - } - - @Override - public void validate(final FormSectionEvent event) - throws FormProcessException { - super.validate(event); - - final FormData formData = event.getFormData(); - if (!formData.containsKey(OWNER_SEARCH) - || formData.get(OWNER_SEARCH) == null) { - formData.addError( - new GlobalizedMessage( - "profile_site.owner.not_selected", - ProfileSiteConstants.BUNDLE - ) - ); - } - } - - @Override - public void process(final FormSectionEvent event) - throws FormProcessException { - - final ProfileSiteItem profileSiteItem = (ProfileSiteItem) super - .processBasicWidgets(event); - final FormData formData = event.getFormData(); - final Person owner = (Person) formData.get(OWNER_SEARCH); - - final ProfileSiteItemController controller = CdiUtil - .createCdiUtil() - .findBean(ProfileSiteItemController.class); - controller.setOwner(profileSiteItem.getObjectId(), owner.getObjectId()); - - init(event); - } - - - -} diff --git a/ccm-cms-profile/src/main/java/org/librecms/profilesite/ProfileSiteItem.java b/ccm-cms-profile/src/main/java/org/librecms/profilesite/ProfileSiteItem.java index 2f5718e77..63fb2d471 100644 --- a/ccm-cms-profile/src/main/java/org/librecms/profilesite/ProfileSiteItem.java +++ b/ccm-cms-profile/src/main/java/org/librecms/profilesite/ProfileSiteItem.java @@ -18,17 +18,10 @@ */ package org.librecms.profilesite; -import com.arsdigita.cms.contenttypes.ui.ProfileSiteItemCreate; -import com.arsdigita.cms.contenttypes.ui.ProfileSiteItemInterestsStep; -import com.arsdigita.cms.contenttypes.ui.ProfileSiteItemMiscStep; -import com.arsdigita.cms.contenttypes.ui.ProfileSiteItemPositionStep; -import com.arsdigita.cms.contenttypes.ui.ProfileSiteItemPropertiesStep; import org.libreccm.l10n.LocalizedString; import org.librecms.assets.Person; import org.librecms.contentsection.ContentItem; -import org.librecms.contenttypes.AuthoringKit; -import org.librecms.contenttypes.AuthoringStep; import org.librecms.contenttypes.ContentTypeDescription; import java.util.Objects; @@ -53,43 +46,6 @@ import static org.librecms.profilesite.ProfileSiteConstants.*; labelBundle = "org.librecms.profilesite.ProfileSiteItem", descriptionBundle = "org.librecms.profilesite.ProfileSiteItem" ) -@AuthoringKit( - createComponent = ProfileSiteItemCreate.class, - steps = { - @AuthoringStep( - component = ProfileSiteItemPropertiesStep.class, - labelBundle = ProfileSiteConstants.BUNDLE, - labelKey = "profile_site_item.basic_properties.label", - descriptionBundle = ProfileSiteConstants.BUNDLE, - descriptionKey = "profile_site_item.basic_properties.description", - order = 1 - ), - @AuthoringStep( - component = ProfileSiteItemPositionStep.class, - labelBundle = ProfileSiteConstants.BUNDLE, - labelKey = "profile_site_item.position.label", - descriptionBundle = ProfileSiteConstants.BUNDLE, - descriptionKey = "profile_site_item.position.description", - order = 2 - ), - @AuthoringStep( - component = ProfileSiteItemInterestsStep.class, - labelBundle = ProfileSiteConstants.BUNDLE, - labelKey = "profile_site_item.interests.label", - descriptionBundle = ProfileSiteConstants.BUNDLE, - descriptionKey = "profile_site_item.interests.description", - order = 3 - ), - @AuthoringStep( - component = ProfileSiteItemMiscStep.class, - labelBundle = ProfileSiteConstants.BUNDLE, - labelKey = "profile_site_item.misc.label", - descriptionBundle = ProfileSiteConstants.BUNDLE, - descriptionKey = "profile_site_item.misc.description", - order = 4 - ) - } -) public class ProfileSiteItem extends ContentItem { private static final long serialVersionUID = 1L; From 7ce68f3cd7600bb2b3b8087ebe670740f6e0f716 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Tue, 15 Mar 2022 20:21:30 +0100 Subject: [PATCH 02/63] Removed several old classes --- .../java/com/arsdigita/cms/ContentCenter.java | 33 -- .../arsdigita/cms/ContentCenterServlet.java | 307 ------------ .../cms/ContentItemXMLRenderer.java.off | 155 ------ .../dispatcher/ContentSectionDispatcher.java | 8 +- .../DefaultTemplateResolver.java.off | 246 ---------- .../cms/dispatcher/FileDispatcher.java | 99 ---- .../dispatcher/SimpleXMLGenerator.java.off | 445 ------------------ .../cms/dispatcher/TemplateResolver.java.off | 97 ---- .../java/com/arsdigita/cms/ui/BaseTree.java | 63 --- .../cms/ui/ContentItemContextBar.java | 120 ----- .../com/arsdigita/cms/ui/ContentItemPage.java | 7 +- .../cms/ui/ContentSectionContextBar.java | 154 ------ .../arsdigita/cms/ui/ContentSectionPage.java | 10 +- .../com/arsdigita/cms/ui/ImagesPane.java.todo | 265 ----------- .../java/com/arsdigita/cms/ui/ReportPane.java | 171 ------- .../assets/forms/AbstractBinaryAssetForm.java | 198 -------- .../AbstractBinaryAssetFormController.java | 98 ---- .../ui/assets/forms/AbstractBookmarkForm.java | 141 ------ .../forms/AbstractBookmarkFormController.java | 77 --- .../forms/AbstractContactableEntityForm.java | 434 ----------------- ...stractContactableEntityFormController.java | 210 --------- .../cms/ui/assets/forms/AudioForm.java | 128 ----- .../ui/assets/forms/AudioFormController.java | 82 ---- .../cms/ui/assets/forms/BookmarkForm.java | 182 ------- .../assets/forms/BookmarkFormController.java | 36 -- .../assets/forms/ExternalAudioAssetForm.java | 104 ---- .../ExternalAudioAssetFormController.java | 81 ---- .../assets/forms/ExternalVideoAssetForm.java | 100 ---- .../ExternalVideoAssetFormController.java | 83 ---- .../cms/ui/assets/forms/FileAssetForm.java | 40 -- .../assets/forms/FileAssetFormController.java | 35 -- .../cms/ui/assets/forms/ImageForm.java | 133 ------ .../ui/assets/forms/ImageFormController.java | 95 ---- .../ui/assets/forms/LegalMetadataForm.java | 143 ------ .../forms/LegalMetadataFormController.java | 93 ---- .../cms/ui/assets/forms/OrganizationForm.java | 95 ---- .../forms/OrganizationFormController.java | 65 --- .../cms/ui/assets/forms/PersonForm.java | 323 ------------- .../ui/assets/forms/PersonFormController.java | 183 ------- .../ui/assets/forms/PostalAddressForm.java | 111 ----- .../forms/PostalAddressFormController.java | 82 ---- .../cms/ui/assets/forms/RelatedLinkForm.java | 58 --- .../cms/ui/assets/forms/SideNoteForm.java | 102 ---- .../assets/forms/SideNoteFormController.java | 67 --- .../cms/ui/assets/forms/VideoForm.java | 130 ----- .../ui/assets/forms/VideoFormController.java | 98 ---- .../ui/assets/searchpage/AssetSearchPage.java | 185 -------- .../searchpage/AssetSearchPageController.java | 85 ---- .../assets/searchpage/ResultsTableModel.java | 76 --- .../ui/assets/searchpage/ResultsTableRow.java | 64 --- .../AbstractContentItemComponentForm.java | 97 ---- .../CategorizedItemComponentForm.java | 50 -- .../pagemodel/CategoryTreeComponentForm.java | 111 ----- .../FixedContentItemComponentForm.java | 123 ----- .../pagemodel/GreetingItemComponentForm.java | 50 -- .../ui/pagemodel/ItemListComponentForm.java | 207 -------- .../london/terms/ui/CategorySubtree.java | 161 ------- .../terms/ui/CategorySubtreeController.java | 50 -- ccm-cms/src/main/java/org/librecms/Cms.java | 61 +-- .../java/org/librecms/assets/AssetType.java | 11 +- .../librecms/assets/AssetTypesManager.java | 2 - .../java/org/librecms/assets/AudioAsset.java | 6 +- .../java/org/librecms/assets/Bookmark.java | 12 +- .../librecms/assets/ExternalAudioAsset.java | 12 +- .../librecms/assets/ExternalVideoAsset.java | 14 +- .../java/org/librecms/assets/FileAsset.java | 21 +- .../main/java/org/librecms/assets/Image.java | 15 +- .../org/librecms/assets/LegalMetadata.java | 2 - .../org/librecms/assets/Organization.java | 12 +- .../main/java/org/librecms/assets/Person.java | 10 +- .../org/librecms/assets/PostalAddress.java | 11 +- .../java/org/librecms/assets/RelatedLink.java | 2 - .../java/org/librecms/assets/SideNote.java | 2 - .../java/org/librecms/assets/VideoAsset.java | 6 +- .../java/org/libreccm/modules/Module.java | 1 + .../org/libreccm/web/ApplicationType.java | 2 + 76 files changed, 68 insertions(+), 7380 deletions(-) delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ContentCenter.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ContentCenterServlet.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ContentItemXMLRenderer.java.off delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/DefaultTemplateResolver.java.off delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/FileDispatcher.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/SimpleXMLGenerator.java.off delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/TemplateResolver.java.off delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/BaseTree.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemContextBar.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionContextBar.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/ImagesPane.java.todo delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/ReportPane.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractBinaryAssetForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractBinaryAssetFormController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractBookmarkForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractBookmarkFormController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractContactableEntityForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractContactableEntityFormController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AudioForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AudioFormController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/BookmarkForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/BookmarkFormController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalAudioAssetForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalAudioAssetFormController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalVideoAssetForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalVideoAssetFormController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/FileAssetForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/FileAssetFormController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ImageForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ImageFormController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/LegalMetadataForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/LegalMetadataFormController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/OrganizationForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/OrganizationFormController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/PersonForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/PersonFormController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/PostalAddressForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/PostalAddressFormController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/RelatedLinkForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/SideNoteForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/SideNoteFormController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/VideoForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/VideoFormController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/searchpage/AssetSearchPage.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/searchpage/AssetSearchPageController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/searchpage/ResultsTableModel.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/searchpage/ResultsTableRow.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/AbstractContentItemComponentForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/CategorizedItemComponentForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/CategoryTreeComponentForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/FixedContentItemComponentForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/GreetingItemComponentForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/ItemListComponentForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/london/terms/ui/CategorySubtree.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/london/terms/ui/CategorySubtreeController.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ContentCenter.java b/ccm-cms/src/main/java/com/arsdigita/cms/ContentCenter.java deleted file mode 100644 index 73eb958ae..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ContentCenter.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2016 LibreCCM Foundation. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package com.arsdigita.cms; - -import org.libreccm.web.CcmApplication; - -/** - * - * @author Jens Pelzetter - */ -public class ContentCenter extends CcmApplication { - - private static final long serialVersionUID = 6672720141286517654L; - - - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ContentCenterServlet.java b/ccm-cms/src/main/java/com/arsdigita/cms/ContentCenterServlet.java deleted file mode 100644 index 6333b9db6..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ContentCenterServlet.java +++ /dev/null @@ -1,307 +0,0 @@ -/* - * Copyright (C) 2016 LibreCCM Foundation. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package com.arsdigita.cms; - -import com.arsdigita.bebop.Page; -import com.arsdigita.cms.dispatcher.CMSPage; -import com.arsdigita.cms.ui.CMSApplicationPage; -import com.arsdigita.cms.ui.contentcenter.MainPage; - -import com.arsdigita.dispatcher.DispatcherHelper; -import com.arsdigita.dispatcher.RequestContext; -import com.arsdigita.kernel.security.Util; -import com.arsdigita.templating.PresentationManager; -import com.arsdigita.templating.Templating; -import com.arsdigita.ui.login.LoginHelper; -import com.arsdigita.web.ApplicationFileResolver; -import com.arsdigita.web.BaseApplicationServlet; -import com.arsdigita.web.LoginSignal; -import com.arsdigita.web.WebConfig; -import com.arsdigita.xml.Document; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.shiro.authz.AuthorizationException; -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.security.PermissionChecker; -import org.libreccm.security.Shiro; -import org.libreccm.web.CcmApplication; -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.ContentSectionRepository; -import org.librecms.contentsection.privileges.ItemPrivileges; - -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * CMS ContentCenter (content-center) application servlet serves all request - * made within the Content Center application. - * - * @author Peter Boy - * @author Jens Pelzetter - */ -@WebServlet(urlPatterns = "/content-center/*") -public class ContentCenterServlet extends BaseApplicationServlet { - - private static final long serialVersionUID = 16543266935651171L; - - /** - * URL (pathinfo) -> Page object mapping. Based on it (and the http request - * url) the doService method to selects a page to display - */ - private final Map pages = new HashMap<>(); - - /** - * Path to directory containg ccm-cms template files - */ - private String m_templatePath; - /** - * Resolvers to find templates (JSP) and other stuff stored in file system. - */ - private ApplicationFileResolver m_resolver; - - private static final Logger LOGGER = LogManager.getLogger( - ContentCenterServlet.class); - - /** - * Use parent's class initialisation extension point to perform additional - * initialisation tasks. - */ - @Override - protected void doInit() { - LOGGER.info("starting doInit method"); - - // NEW STUFF here used to process the pages in this servlet - // Addresses previously noted in WEB-INF/resources/content-center-map.xml - // Obviously not required. - - - addPage("/", new MainPage()); // index page at address ~/cc - addPage("/index", new MainPage()); - - -// addPage("/item-search", new CMSItemSearchPage()); - // Old style - //addPage("/item-search", new ItemSearchPage()); - //addPage("/searchredirect", new CMSSearchResultRedirector()); - - // STUFF to use for JSP extension, i.e. jsp's to try for URLs which are not - // handled by the this servlet directly. - /** - * Set Template base path for JSP's - */ - // ToDo: Make it configurable by an appropriate config registry entry! - // m_templatePath = CMS.getConfig().getTemplateRoot(); - m_templatePath = "/templates/ccm-cms/content-center"; - /** - * Set TemplateResolver class - */ - m_resolver = WebConfig.getConfig().getResolver(); - } - - @Override - protected void doService(final HttpServletRequest sreq, - final HttpServletResponse sresp, - final CcmApplication app) throws ServletException, - IOException { - LOGGER.info("starting doService method"); - - // ContentCenter workspace = (ContentCenter) app; - - /* Check user and privilegies */ - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final Shiro shiro = cdiUtil.findBean(Shiro.class); - if (!shiro.getSubject().isAuthenticated()) { - throw new LoginSignal(sreq); // send to login page - } - final PermissionChecker permissionChecker = cdiUtil.findBean( - PermissionChecker.class); - final ContentSectionRepository sectionRepo = cdiUtil.findBean( - ContentSectionRepository.class); - final List sections = sectionRepo.findAll(); - boolean hasAccess = false; - for (final ContentSection section : sections) { - if (permissionChecker.isPermitted(ItemPrivileges.EDIT, - section.getRootDocumentsFolder())) { - hasAccess = true; - break; - } - } - - if (!hasAccess) { // user has no access privilege - throw new AuthorizationException( - "User is not entitled to access any content section"); - // throw new LoginSignal(sreq); // send to login page - } - - // New way to fetch the page - String pathInfo = sreq.getPathInfo(); - if (pathInfo.length() > 1 && pathInfo.endsWith("/")) { - /* NOTE: ServletAPI specifies, pathInfo may be empty or will - * start with a '/' character. It currently carries a - * trailing '/' if a "virtual" page, i.e. not a real jsp, but - * result of a servlet mapping. But Application requires url - * NOT to end with a trailing '/' for legacy free applications. */ - pathInfo = pathInfo.substring(0, pathInfo.length() - 1); - } - - // An empty remaining URL or a URL which doesn't end in trailing slash: - // probably want to redirect. - // Probably DEPRECATED with new access method or only relevant for jsp - // extension - // if (m_trailingSlashList.contains(url) && !originalUrl.endsWith("/")) { - // DispatcherHelper.sendRedirect(sresp, originalUrl + "/"); - // return; - // } - final Page page = pages.get(pathInfo); - if (page != null) { - - // Check user access. - checkUserAccess(sreq, sresp); - - if (page instanceof CMSPage) { - // backwards compatibility fix until migration completed - final CMSPage cmsPage = (CMSPage) page; - final RequestContext ctx = DispatcherHelper.getRequestContext(); - cmsPage.init(); - cmsPage.dispatch(sreq, sresp, ctx); - } else { - final CMSApplicationPage cmsAppPage = (CMSApplicationPage) page; - cmsAppPage.init(sreq, sresp, app); - // Serve the page. - final Document doc = cmsAppPage.buildDocument(sreq, sresp); - - PresentationManager pm = Templating.getPresentationManager(); - pm.servePage(doc, sreq, sresp); - } - - } else { - // Fall back on the JSP application dispatcher. - // NOTE: The JSP must ensure the proper authentication and - // authorisation if required! - LOGGER.info("NO page registered to serve the requst url."); - - RequestDispatcher rd = m_resolver.resolve(m_templatePath, - sreq, sresp, app); - if (rd != null) { - LOGGER.debug("Got dispatcher " + rd); - - final HttpServletRequest origreq = DispatcherHelper - .restoreOriginalRequest(sreq); - rd.forward(origreq, sresp); - } else { - - sresp.sendError(404, sreq.getRequestURI() - + " not found on this server."); - } - - } - - LOGGER.info("doService method completed"); - - } // END doService() - - /** - * Internal service mechod, adds one pair of Url - Page to the internal hash - * map, used as a cache. - * - * @param pathInfo url stub for a page to display - * @param page Page object to display - */ - private void addPage(final String pathInfo, final Page page) { - - // Current Implementation requires pathInfo to start with a leading '/' - // SUN Servlet API specifies: "PathInfo *may be empty* or will start - // with a '/' character." - pages.put(pathInfo, page); - - } - -// /** -// * Service Method returns the URL stub for the class name, can return null -// * if not mapped -// */ -// // Currently still in use by c.ad.cms.ui.ItemSearchWidget -// public static String getURLStubForClass(String classname) { -// LOGGER.debug("Getting URL Stub for : " + classname); -// Iterator itr = s_pageURLs.keySet().iterator(); -// while (itr.hasNext()) { -// String classname2 = (String) itr.next(); -// s_log.debug("key: " + classname + " value: " -// + (String) s_pageURLs.get(classname2)); -// } -// String url = (String) s_pageURLs.get(classname); -// return url; -// } - /** - * Verify that the user is logged in and is able to view the page. - * Subclasses can override this method if they need to, but should always be - * sure to call super.checkUserAccess(...) - * - * @param request The HTTP request - * @param response The HTTP response - * @param actx The request context - * - */ - protected void checkUserAccess(final HttpServletRequest request, - final HttpServletResponse response //, - /// final RequestContext actx - ) - throws ServletException { - - if (!CdiUtil.createCdiUtil().findBean(Shiro.class).getSubject() - .isAuthenticated()) { - throw new LoginSignal(request); - } - } - - /** - * Redirects the client to the login page, setting the return url to the - * current request URI. - * - * @exception ServletException If there is an exception thrown while trying - * to redirect, wrap that exception in a - * ServletException - * - */ - protected void redirectToLoginPage(HttpServletRequest req, - HttpServletResponse resp) - throws ServletException { - String url = Util.getSecurityHelper() - .getLoginURL(req) - + "?" + LoginHelper.RETURN_URL_PARAM_NAME - + "=" + DispatcherHelper.encodeReturnURL(req); - try { - LoginHelper.sendRedirect(req, resp, url); - } catch (IOException e) { - LOGGER.error("IO Exception", e); - throw new ServletException(e.getMessage(), e); - } - } - - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ContentItemXMLRenderer.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ContentItemXMLRenderer.java.off deleted file mode 100644 index 0ce8896c3..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ContentItemXMLRenderer.java.off +++ /dev/null @@ -1,155 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package com.arsdigita.cms; - -import com.arsdigita.cms.contenttypes.GenericAddress; -import com.arsdigita.dispatcher.DispatcherHelper; -import com.arsdigita.domain.DomainObject; -import com.arsdigita.domain.DomainObjectTraversalAdapter; -import com.arsdigita.domain.DomainObjectXMLRenderer; -import com.arsdigita.globalization.GlobalizationHelper; -import com.arsdigita.persistence.metadata.Property; -import com.arsdigita.xml.Element; -import org.apache.log4j.Logger; - -/** - * This is a special ContentItemXMLRenderer for CMS to get a more transparent - * way to handle ContentBundles during XML output. - * - * The problem was to change RelatedLinks and therefore Link to always link to - * the corresponding ContentBundle instead of the content item. To get the - * corresponding content item during XML generation, I have to test for - * ContentBundle and negotiate the language version. - * This is not possible in com.arsdigita.ccm - * - * @author quasi - */ -public class ContentItemXMLRenderer extends DomainObjectXMLRenderer { - - private static final Logger logger = - Logger.getLogger(ContentItemXMLRenderer.class); - private String m_propertyName = ""; - private String m_keyName = ""; - private String m_relationAttribute = ""; - - public ContentItemXMLRenderer(final Element root) { - super(root); - } - - // This method will be called by DomainObjectTraversal.walk() - // It's purpose is to test for ContentBundle objects and if found, replace - // that object with the negotiated version of the content item. - // Otherwise this methd will do nothing. - @Override - protected void walk(final DomainObjectTraversalAdapter adapter, - final DomainObject obj, - final String path, - final String context, - final DomainObject linkObject) { - //final long start = System.nanoTime(); - - DomainObject nObj = obj; - - if (nObj instanceof ContentBundle) { - - nObj = ((ContentBundle) obj).getInstance(GlobalizationHelper.getNegotiatedLocale(), true); - } - - super.walk(adapter, nObj, path, context, linkObject); - - //System.out.printf("Walked object in %d ms\n", (System.nanoTime() - start) / 1000000); - } - - @Override - protected void handleAttribute(final DomainObject obj, final String path, final Property property) { - final String propertyName = property.getName(); - - // Special handling for the isoCountryCode field in GenericAddress - if (obj instanceof GenericAddress && "isoCountryCode".equals(propertyName)) { - //if (propertyName.equals("isoCountryCode")) { - super.handleAttribute(obj, path, property); - - final Element element = newElement(m_element, "country"); - element.setText(GenericAddress.getCountryNameFromIsoCode(((GenericAddress) obj).getIsoCountryCode())); - return; - - } - - // Special handling for the relation attribute keys - if (!m_relationAttribute.isEmpty()) { - String key = ""; - - // The RelationAttribute is part of this domain object as field - if (obj instanceof RelationAttributeInterface - && ((RelationAttributeInterface) obj). - hasRelationAttributeProperty(propertyName)) { - - final RelationAttributeInterface relationAttributeObject = (RelationAttributeInterface) obj; - key = relationAttributeObject.getRelationAttributeKey( - propertyName); - - } - - // This RelationAttribute is part of an n:m association as link attribute - if (obj instanceof LinkDomainObject - && propertyName.equals(m_keyName)) { - key = (String) ((LinkDomainObject) obj).get(m_keyName); - } - - // Replace value of the property defined in RELATION_ATTRIBUTES string - // of the primary domain object with the localized String. - if (!key.isEmpty()) { -// logger.debug(String.format( -// "Getting relation attribute value for key '%s' of relation attribute '%s'", -// key, m_relationAttribute)); - final RelationAttributeCollection relationAttributeCollection = new RelationAttributeCollection( - m_relationAttribute, key); - relationAttributeCollection.addLanguageFilter(GlobalizationHelper. - getNegotiatedLocale().getLanguage()); - if (!relationAttributeCollection.isEmpty()) { - relationAttributeCollection.next(); - final Element element = newElement(m_element, m_keyName); - element.setText(relationAttributeCollection.getName()); - final Element elementId = newElement(m_element, m_keyName + "Id"); - elementId.setText(relationAttributeCollection.getKey()); - relationAttributeCollection.close(); - } - return; - } - } - - super.handleAttribute(obj, path, property); - } - - @Override - protected void beginAssociation(final DomainObject obj, final String path, final Property property) { - super.beginAssociation(obj, path, property); - - final String propertyName = property.getName(); - - if (obj instanceof RelationAttributeInterface - && ((RelationAttributeInterface) obj).hasRelationAttributeProperty( - propertyName)) { - - final RelationAttributeInterface relationAttributeObject = (RelationAttributeInterface) obj; - - m_propertyName = propertyName; - m_keyName = relationAttributeObject.getRelationAttributeKeyName(propertyName); - m_relationAttribute = relationAttributeObject.getRelationAttributeName(propertyName); - - } - } - - @Override - protected void endAssociation(final DomainObject obj, final String path, final Property property) { - - m_propertyName = ""; - m_keyName = ""; - m_relationAttribute = ""; - - super.endAssociation(obj, path, property); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/ContentSectionDispatcher.java b/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/ContentSectionDispatcher.java index d2988c5c6..b77290f96 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/ContentSectionDispatcher.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/ContentSectionDispatcher.java @@ -57,10 +57,10 @@ public class ContentSectionDispatcher implements Dispatcher { public ContentSectionDispatcher() { - dispatcherChain.addChainedDispatcher(new CMSDispatcher(true)); - dispatcherChain.addChainedDispatcher(new FileDispatcher()); - dispatcherChain.addChainedDispatcher(new ItemDispatcher()); - dispatcherChain.addChainedDispatcher(new CMSDispatcher()); +// dispatcherChain.addChainedDispatcher(new CMSDispatcher(true)); +// dispatcherChain.addChainedDispatcher(new FileDispatcher()); +// dispatcherChain.addChainedDispatcher(new ItemDispatcher()); +// dispatcherChain.addChainedDispatcher(new CMSDispatcher()); } public void dispatch(HttpServletRequest request, diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/DefaultTemplateResolver.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/DefaultTemplateResolver.java.off deleted file mode 100755 index 16c522f5b..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/DefaultTemplateResolver.java.off +++ /dev/null @@ -1,246 +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.dispatcher; - -import com.arsdigita.cms.ContentItem; -import com.arsdigita.cms.ContentSection; -import com.arsdigita.cms.ContentType; -import com.arsdigita.cms.Folder; -import com.arsdigita.cms.Template; -import com.arsdigita.cms.TemplateManager; -import com.arsdigita.cms.TemplateManagerFactory; -import com.arsdigita.mimetypes.MimeType; -import com.arsdigita.util.Assert; -import org.apache.log4j.Logger; - -import javax.servlet.http.HttpServletRequest; - -/** - * ------- May be outdated. TemplateResolver has been reworked. ---------- - * Resolves the JSP template to use for dispatching an - * item. This replaces TemplateResolver since the latter - * has a useless API. - * ------------------------------------------------------------------------ - * - *

In general, the process for resolving a template involves two - * steps:

- * - *
    - * - *
  1. The template resolver examines specific properties of the - * item, the content section, and/or the request itself and selects - * an appropriate context. A context is simply a token - * such as "plain" or "fancy". - * - *
  2. Based on the selected context, the template resolver - * identifies an appropriate template for the item. This is a - * three-step process: (1) the resolver queries for an association - * between the item and a specific template for the selected - * context; (2) if no such association exists, the resolver queries - * the item's content type for a default template to use in the - * selected context; (3) if a default template is not found, return - * null (at which point the dispatcher should probably give up and - * return a 404 error). - * - *
- */ - -public class DefaultTemplateResolver extends AbstractTemplateResolver - implements TemplateResolver { - - private static Logger s_log = Logger.getLogger(DefaultTemplateResolver.class); - - /** - * Returns the JSP template filename relative to the webapp - * root. - * - * @param section The ContentSection for the request - * @param item The ContentItem for the request - * @param request The current HttpServletRequest - * - * @return The path to the jsp template. - */ - public String getTemplate(ContentSection section, - ContentItem item, - HttpServletRequest request) { - - String template = getItemTemplate(section, item, request); - MimeType mimeType = MimeType.loadMimeType(Template.JSP_MIME_TYPE); - - if (template == null) { - if (s_log.isDebugEnabled()) { - s_log.debug("No item template, looking for content type template"); - } - template = getTypeTemplate(section, item, request, mimeType); - } - - if (template == null) { - if (s_log.isDebugEnabled()) { - s_log.debug("No content type template, looking for default template"); - } - - template = getDefaultTemplate(section, item, request); - - Assert.exists(template, "default template"); - } - - if (s_log.isInfoEnabled()) { - s_log.info("Got template " + template + " for item " + item.getOID()); - } - - return ContentSection.getConfig().getTemplateRoot() + template; - } - - /** - * Returns the JSP template filename relative to the webapp - * root for a given Template reference. - * - * @param template The Template to resolve the URL for. - * - * @return The path to the jsp template. - */ - public String getTemplatePath(Template template) { - - return ContentSection.getConfig().getTemplateRoot() + - getTemplateFilename(template, template.getContentSection()); - } - - /** - * Returns the XSL template filename relative to the webapp - * root for a given Template reference. - * - * @param template The Template to resolve the URL for. - * - * @return The path to the xsl template. - */ - public String getTemplateXSLPath(Template template) { - - return ContentSection.getConfig().getTemplateRoot() + - getTemplateXSLFilename(template, template.getContentSection()); - } - - /** - * Returns the template associated with the item (if any) - */ - protected String getItemTemplate(ContentSection section, - ContentItem item, - HttpServletRequest request) { - TemplateManager manager = TemplateManagerFactory.getInstance(); - String context = getTemplateContext(request); - Template template = manager.getTemplate(item, context); - - return template == null ? null : getTemplateFilename( - template, section - ); - } - - /** - * Returns the template associated with the type (if any) - * @deprecated Use the version that specifies a mime type - */ - protected String getTypeTemplate(ContentSection section, - ContentItem item, - HttpServletRequest request) { - MimeType mimeType = MimeType.loadMimeType(Template.JSP_MIME_TYPE); - return getTypeTemplate(section, item, request, mimeType); - } - - /** - * Returns the template associated with the type (if any) - */ - protected String getTypeTemplate(ContentSection section, - ContentItem item, - HttpServletRequest request, - MimeType mimeType) { - TemplateManager manager = TemplateManagerFactory.getInstance(); - ContentType type = item.getContentType(); - - Template template = null; - - if (type != null ) { - String context = getTemplateContext(request); - template = manager.getDefaultTemplate(section, type, context, mimeType); - } else { - if (s_log.isDebugEnabled()) { - s_log.debug("Item has no content type, not looking for a " + - "content type specific template"); - } - } - - return template == null ? null : getTemplateFilename( - template, section - ); - } - - /** - * Returns the default template - */ - protected String getDefaultTemplate(ContentSection section, - ContentItem item, - HttpServletRequest request) { - String path = (item instanceof Folder) ? - ContentSection.getConfig().getDefaultFolderTemplatePath() : - ContentSection.getConfig().getDefaultItemTemplatePath(); - - return path; - } - - /** - * Returns the filename for a Template object - */ - protected String getTemplateFilename(Template template, - ContentSection section, - ContentItem item, - HttpServletRequest request) { - return getTemplateFilename(template, section); - } - - /** - * Returns the filename for a Template object - */ - protected String getTemplateXSLFilename(Template template, - ContentSection section, - ContentItem item, - HttpServletRequest request) { - return getTemplateXSLFilename(template, section); - } - - /** - * Returns the filename for a Template object - */ - protected String getTemplateFilename(Template template, - ContentSection section) { - - String templateName = template.getPath(); - String sectionURL = section.getPath(); - return sectionURL + "/" + templateName; - } - - /** - * Returns the filename for a Template object - */ - protected String getTemplateXSLFilename(Template template, - ContentSection section) { - - String templateName = template.getPathNoJsp() + ".xsl"; - String sectionURL = section.getPath(); - - return sectionURL + "/" + templateName; - } -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/FileDispatcher.java b/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/FileDispatcher.java deleted file mode 100755 index efea84744..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/FileDispatcher.java +++ /dev/null @@ -1,99 +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.dispatcher; - -import com.arsdigita.dispatcher.ChainedDispatcher; -import com.arsdigita.dispatcher.DispatcherHelper; -import com.arsdigita.dispatcher.RequestContext; - -import org.apache.logging.log4j.LogManager; - -import java.io.File; -import java.io.IOException; - -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.logging.log4j.Logger; - -/** - * Dispatches to a file stored under the CMS package root - * (/packages/cms/www). This includes both unmanaged files copied - * or created directly in the file system, as well as pages and assets published - * to the file system from CMS. - * - * @author Karl Goldstein (karlg@arsdigita.com) - * @version $Revision$ $DateTime: 2004/08/17 23:15:09 $ - * @version $Id$ - * - */ -public class FileDispatcher implements ChainedDispatcher { - - private static final Logger LOGGER = LogManager.getLogger( - ChainedDispatcher.class); - - @Override - public int chainedDispatch(HttpServletRequest request, - HttpServletResponse response, - RequestContext context) - throws IOException, ServletException { - - File jspFile = getPackageFile(context); - - if (jspFile.exists() && !jspFile.isDirectory()) { - String packageURL = context.getPageBase() + context - .getRemainingURLPart(); - LOGGER.debug("DISPATCHING to " + packageURL); - - // don't match folders, since they don't actually match a file - if (!packageURL.endsWith("/")) { - LOGGER.debug("DISPATCHING to " + packageURL); - // Don't set caching headers - let JSP file do it if required - //DispatcherHelper.maybeCacheDisable(response); - DispatcherHelper.setRequestContext(request, context); - DispatcherHelper.forwardRequestByPath(packageURL, request, - response); - return ChainedDispatcher.DISPATCH_BREAK; - } - } - - return ChainedDispatcher.DISPATCH_CONTINUE; - } - - /** - * Matches the request URL to a file in the package www directory. - * - */ - private File getPackageFile(RequestContext appContext) { - - ServletContext servletContext = appContext.getServletContext(); - - String filePath = appContext.getRemainingURLPart(); - - String packageDocRoot = servletContext.getRealPath(appContext - .getPageBase()); - - File jspFile = new File(packageDocRoot, filePath); - - return jspFile; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/SimpleXMLGenerator.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/SimpleXMLGenerator.java.off deleted file mode 100755 index 29e87838c..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/SimpleXMLGenerator.java.off +++ /dev/null @@ -1,445 +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.dispatcher; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.cms.CMS; -import com.arsdigita.cms.CMSConfig; -import com.arsdigita.cms.ContentItem; -import com.arsdigita.cms.ContentItemXMLRenderer; -import com.arsdigita.cms.ExtraXMLGenerator; -import com.arsdigita.cms.SecurityManager; -import com.arsdigita.cms.UserDefinedContentItem; -import com.arsdigita.cms.XMLDeliveryCache; -import com.arsdigita.cms.util.GlobalizationUtil; -import com.arsdigita.domain.DataObjectNotFoundException; -import com.arsdigita.domain.DomainObjectFactory; -import com.arsdigita.domain.DomainObjectTraversal; -import com.arsdigita.domain.SimpleDomainObjectTraversalAdapter; -import com.arsdigita.kernel.Kernel; -import com.arsdigita.kernel.Party; -import com.arsdigita.kernel.permissions.PermissionDescriptor; -import com.arsdigita.kernel.permissions.PermissionService; -import com.arsdigita.kernel.permissions.PrivilegeDescriptor; -import com.arsdigita.metadata.DynamicObjectType; -import com.arsdigita.persistence.OID; -import com.arsdigita.persistence.metadata.Property; -import com.arsdigita.util.UncheckedWrapperException; -import com.arsdigita.xml.Element; -import org.apache.log4j.Logger; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.Map; - -/** - *

The default XMLGenerator implementation.

- * - * @author Michael Pih - * @version $Revision: #20 $ $DateTime: 2004/08/17 23:15:09 $ - * @version $Id: SimpleXMLGenerator.java 2167 2011-06-19 21:12:12Z pboy $ - */ -public class SimpleXMLGenerator implements XMLGenerator { - - private static final Logger s_log = Logger.getLogger(SimpleXMLGenerator.class); - public static final String ADAPTER_CONTEXT = SimpleXMLGenerator.class.getName(); - /** - * jensp 2011-10-23: Sometimes the extra XML is not needed, for example - * when embedding the XML of a content item into the XML output of another - * content item. The default value {@code true}. To change the value - * call {@link #setUseExtraXml(booelan)} after creating an instance of - * your generator. - */ - private boolean useExtraXml = true; - /** - * jensp 2012-04-18: This value is forwarded to this ExtraXMLGenerators - * by calling {@link ExtraXMLGenerator#setListMode(boolean)}. The behavior - * triggered by this value depends on the specific implementation of - * the {@code ExtraXMLGenerator} - */ - private boolean listMode = false; - /** - * Extra attributes for the cms:item element. - */ - private final Map itemAttributes = new LinkedHashMap(); - /** - * Allows to overwrite the name and the namespace of the XML element - * used to wrap the rendered item. - */ - private String itemElemName = "cms:item"; - private String itemElemNs = CMS.CMS_XML_NS; - - // Register general purpose adaptor for all content items - static { - s_log.debug("Static initializer starting..."); - final SimpleDomainObjectTraversalAdapter adapter = new SimpleDomainObjectTraversalAdapter(); - adapter.addAssociationProperty("/object/type"); - adapter.addAssociationProperty("/object/categories"); - - DomainObjectTraversal.registerAdapter( - ContentItem.BASE_DATA_OBJECT_TYPE, - adapter, - ADAPTER_CONTEXT); - s_log.debug("Static initializer finished"); - } - - public SimpleXMLGenerator() { - super(); - } - - public void setUseExtraXml(final boolean useExtraXml) { - this.useExtraXml = useExtraXml; - } - - public void setListMode(final boolean listMode) { - this.listMode = listMode; - } - - public void addItemAttribute(final String name, final String value) { - itemAttributes.put(name, value); - } - - public void setItemElemName(final String itemElemName, final String itemElemNs) { - this.itemElemName = itemElemName; - this.itemElemNs = itemElemNs; - } - - /** - * Generates the XML to render the content panel. - * - * @param state The page state - * @param parent The parent DOM element - * @param useContext The use context - */ - @Override - public void generateXML(final PageState state, final Element parent, final String useContext) { - //final long start = System.nanoTime(); - - //ContentSection section = CMS.getContext().getContentSection(); - ContentItem item = getContentItem(state); - - s_log.info("Generate XML for item " + item.getOID()); - - Party currentParty = Kernel.getContext().getParty(); - if (currentParty == null) { - currentParty = Kernel.getPublicUser(); - } - // check if current user can edit the current item (nb privilege is granted on draft item, but live item - // has draft as its permission context - // - // Note that the xml that is generated is only of use if you DO NOT CACHE content pages. - // cg. - final PermissionDescriptor edit = new PermissionDescriptor( - PrivilegeDescriptor.get(SecurityManager.CMS_EDIT_ITEM), item, currentParty); - if (PermissionService.checkPermission(edit)) { - parent.addAttribute("canEdit", "true"); - final Element canEditElem = parent.newChildElement("canEdit"); - canEditElem.setText("true"); - - } - final PermissionDescriptor publish = new PermissionDescriptor( - PrivilegeDescriptor.get(SecurityManager.CMS_PUBLISH), item, currentParty); - if (PermissionService.checkPermission(publish)) { - parent.addAttribute("canPublish", "true"); - } - final String className = item.getDefaultDomainClass(); - - // Ensure correct subtype of ContentItem is instantiated - if (!item.getClass().getName().equals(className)) { - s_log.info("Specializing item"); - try { - item = (ContentItem) DomainObjectFactory.newInstance( - new OID(item.getObjectType().getQualifiedName(), item.getID())); - } catch (DataObjectNotFoundException ex) { - throw new UncheckedWrapperException( - (String) GlobalizationUtil.globalize( - "cms.dispatcher.cannot_find_domain_object").localize(), - ex); - } - } - - // Implementing XMLGenerator directly is now deprecated - if (item instanceof XMLGenerator) { - s_log.info("Item implements XMLGenerator interface"); - final XMLGenerator xitem = (XMLGenerator) item; - xitem.generateXML(state, parent, useContext); - - } else if ("com.arsdigita.cms.UserDefinedContentItem".equals(className)) { - s_log.info("Item is a user defined content item"); - final UserDefinedContentItem UDItem = (UserDefinedContentItem) item; - generateUDItemXML(UDItem, state, parent, useContext); - - } else { - s_log.info("Item is using DomainObjectXMLRenderer"); - - // This is the preferred method - //final Element content = startElement(useContext, parent); - final Element content = startElement(useContext); - s_log.debug("Item is not in cache, generating item."); - - final XMLDeliveryCache xmlCache = XMLDeliveryCache.getInstance(); - - if (CMSConfig.getInstanceOf().getEnableXmlCache() && xmlCache.isCached(item.getOID(), useContext, listMode)) { - xmlCache.retrieveFromCache(content, item.getOID(), useContext, listMode); - } else { - final ContentItemXMLRenderer renderer = new ContentItemXMLRenderer(content); - - renderer.setWrapAttributes(true); - renderer.setWrapRoot(false); - renderer.setWrapObjects(false); - renderer.setRevisitFullObject(true); - - //System.out.printf("Prepared renderer in %d ms\n", (System.nanoTime() - start) - // / 1000000); - - renderer.walk(item, ADAPTER_CONTEXT); - - //System.out.printf("Rendered standard item xml in %d ms\n", (System.nanoTime() - start) - // / 1000000); - - //parent.addContent(content); - - //Only item XML Cache End - -// s_log.debug("Content elem content: "); -// logElementTree(content); -// s_log.debug("Content elem content end -- "); - - - /* - * 2011-08-27 jensp: Introduced to remove the annoying special templates - * for MultiPartArticle, SiteProxy and others. The method called - * here was already definied but not used. - * - * 2011-10-23 jensp: It is now possible to disable the use of - * extra XML. - */ - //final long extraXMLStart = System.nanoTime(); - if (useExtraXml) { - for (ExtraXMLGenerator generator : item.getExtraXMLGenerators()) { - generator.setListMode(listMode); - generator.generateXML(item, content, state); - } - } - - //Only published items - //Only the XML of the item itself, no extra XML - if (CMSConfig.getInstanceOf().getEnableXmlCache() && item.isLiveVersion()) { - xmlCache.cache(item.getOID(), item, content, useContext, listMode); - } - } - - if (PermissionService.checkPermission(edit)) { - final ItemResolver resolver = item.getContentSection().getItemResolver(); - final Element editLinkElem = content.newChildElement("editLink"); - final ContentItem draftItem = item.getDraftVersion(); - editLinkElem.setText(resolver.generateItemURL(state, - draftItem, - item.getContentSection(), - draftItem.getVersion())); - } - - parent.addContent(content); - - //System.out.printf("Rendered item in %d ms\n\n", (System.nanoTime() - start) / 1000000); - } - } - - /** - * Fetches the current content item. This method can be overridden to - * fetch any {@link com.arsdigita.cms.ContentItem}, but by default, - * it fetches the ContentItem that is set in the page state - * by the dispatcher. - * - * @param state The page state - * @return A content item - */ - protected ContentItem getContentItem(final PageState state) { - if (CMS.getContext().hasContentItem()) { - return CMS.getContext().getContentItem(); - } else { - final CMSPage page = (CMSPage) state.getPage(); - return page.getContentItem(state); - } - } - - protected void generateUDItemXML(final UserDefinedContentItem UDItem, - final PageState state, - final Element parent, - final String useContext) { - - final Element element = startElement(useContext, parent); - final Element additionalAttrs = UDItemElement(useContext); - - element.addAttribute("type", UDItem.getContentType().getName()); - element.addAttribute("id", UDItem.getID().toString()); - element.addAttribute("name", UDItem.getName()); - element.addAttribute("title", UDItem.getTitle()); - element.addAttribute("javaClass", UDItem.getContentType().getClassName()); - - final DynamicObjectType dot = new DynamicObjectType(UDItem.getSpecificObjectType()); - final Iterator declaredProperties = - dot.getObjectType().getDeclaredProperties(); - Property currentProperty; - Object value; - while (declaredProperties.hasNext()) { - currentProperty = (Property) declaredProperties.next(); - value = (Object) UDItem.get(currentProperty.getName()); - if (value != null) { - element.addContent( - UDItemAttrElement(currentProperty.getName(), - value.toString())); - } else { - element.addContent( - UDItemAttrElement(currentProperty.getName(), - "none specified")); - } - } - - //element.addContent(additionalAttrs); - //parent.addContent(element); - - } - - private Element startElement(final String useContext, final Element parent) { - //Element element = new Element("cms:item", CMS.CMS_XML_NS); - //final Element element = new Element(itemElemName, itemElemNs); - final Element element = parent.newChildElement(itemElemName, itemElemNs); - if (useContext != null) { - element.addAttribute("useContext", useContext); - } - - for (Map.Entry attr : itemAttributes.entrySet()) { - element.addAttribute(attr.getKey(), attr.getValue()); - } - - return element; - } - - private Element startElement(final String useContext) { - final Element element = new Element(itemElemName, itemElemNs); - - if (useContext != null) { - element.addAttribute("useContext", useContext); - } - - for (Map.Entry attr : itemAttributes.entrySet()) { - element.addAttribute(attr.getKey(), attr.getValue()); - } - - return element; - } - - private Element startCachedElement(final String useContext) { - final Element element = new Element(itemElemName, itemElemNs) { - @Override - public Element newChildElement(Element copyFrom) { - s_log.debug("Copy of element added to cached elem."); - return super.newChildElement(copyFrom); - } - - @Override - public Element newChildElement(String name, Element copyFrom) { - s_log.debug("Copy of element added to cached elem."); - return super.newChildElement(name, copyFrom); - } - - @Override - public Element addContent(final Element newContent) { - s_log.debug("Content added to cached element"); - return super.addContent(newContent); - } - - }; - - if (useContext != null) { - element.addAttribute("useContext", useContext); - } - - for (Map.Entry attr : itemAttributes.entrySet()) { - element.addAttribute(attr.getKey(), attr.getValue()); - } - - return element; - } - - private void copyElement(final Element parent, final Element element) { - final Element copy = parent.newChildElement(element.getName()); - final Iterator attrs = element.getAttributes().entrySet().iterator(); - Map.Entry attr; - while (attrs.hasNext()) { - attr = (Map.Entry) attrs.next(); - copy.addAttribute((String) attr.getKey(), (String) attr.getValue()); - } - - final Iterator childs = element.getChildren().iterator(); - while (childs.hasNext()) { - copyElement(copy, (Element) childs.next()); - } - - if (element.getText() != null) { - copy.setText(element.getText()); - } - - if (element.getCDATASection() != null) { - copy.setCDATASection(element.getCDATASection()); - } - - } - - private Element UDItemElement(final String useContext) { - final Element element = new Element("cms:UDItemAttributes", CMS.CMS_XML_NS); - /* - if ( useContext != null ) { - element.addAttribute("useContext", useContext); - } - */ - return element; - } - - private Element UDItemAttrElement(final String name, final String value) { - final Element element = new Element("cms:UDItemAttribute", CMS.CMS_XML_NS); - element.addAttribute("UDItemAttrName", name); - element.addAttribute("UDItemAttrValue", value); - return element; - } - - private void logElementTree(final Element element) { - s_log.debug("Tree of element" + element.getName() + ":\n"); - s_log.debug("\n" + logElementTree(element, new StringBuilder(), 0)); - } - - private String logElementTree(final Element element, final StringBuilder builder, final int depth) { - for (int i = 0; i < depth; i++) { - builder.append('\t'); - } - builder.append('<').append(element.getName()).append(">\n"); - - for (Object childObj : element.getChildren()) { - final Element child = (Element) childObj; - logElementTree(child, builder, depth + 1); - } - - for (int i = 0; i < depth; i++) { - builder.append('\t'); - } - builder.append("\n"); - return builder.toString(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/TemplateResolver.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/TemplateResolver.java.off deleted file mode 100755 index cd38be0bc..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/dispatcher/TemplateResolver.java.off +++ /dev/null @@ -1,97 +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.dispatcher; - -import javax.servlet.http.HttpServletRequest; - -/** - * Reimplementation, based on ItemTemplateResolver - * - *

- * Many sites offer alternative views of the same content item depending on - * device or browser, or on user preference. For example, a site may have - * "plain" and "fancy" versions of its pages. The fancy versions would be the - * defaults, while the plain versions would be appropriate for users with - * low-bandwidth connections, older browsers, or a distaste for flashy - * appurtenances. In this the case the selection might be made based on a - * cookie.

- * - *

- * Another common example is the "printable" version of a page. In this case a - * query variable might be more appropriate.

- * - * - * @author Karl Goldstein (karlg@arsdigita.com) - * @version $Id: TemplateResolver.java 1967 2009-08-29 21:05:51Z pboy $ - * - */ -public interface TemplateResolver { - - /** - * Returns the JSP template filename relative to the webapp root. - * - * @param section The ContentSection for the request - * @param item The ContentItem for the request - * @param request The current HttpServletRequest - * - * @return The path to the jsp template. - */ - public String getTemplate(ContentSection section, - ContentItem item, - HttpServletRequest request); - - /** - * Returns the JSP template filename relative to the webapp root for a given - * Template reference. - * - * @param template The Template to resolve the URL for. - * - * @return The path to the jsp template. - */ - public String getTemplatePath(Template template); - - /** - * Returns the XSL template filename relative to the webapp root for a given - * Template reference. - * - * @param template The Template to resolve the URL for. - * - * @return The path to the xsl template. - */ - public String getTemplateXSLPath(Template template); - - /** - * Sets the TemplateContext parameter in the request - * - * @param sTemplateContext the template context to set - * @param request the request in which to set the template context - */ - public void setTemplateContext(String sTemplateContext, - HttpServletRequest request); - - /** - * Gets the template context from the request. - * - * @param request the request from which to get the template context - * - * @return the template context - */ - public String getTemplateContext(HttpServletRequest request); - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/BaseTree.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/BaseTree.java deleted file mode 100755 index 81940c8c2..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/BaseTree.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Tree; -import com.arsdigita.bebop.event.ChangeEvent; -import com.arsdigita.bebop.event.ChangeListener; -import com.arsdigita.bebop.event.TreeExpansionEvent; -import com.arsdigita.bebop.event.TreeExpansionListener; -import com.arsdigita.bebop.tree.TreeModelBuilder; - -/** - * A convenience class for CMS trees. - * - * @author Justin Ross <jross@redhat.com> - */ -public class BaseTree extends Tree { - - public BaseTree(final TreeModelBuilder builder) { - super(builder); - - addChangeListener(new Change()); - addTreeExpansionListener(new TreeExpansion()); - } - - private class Change implements ChangeListener { - public final void stateChanged(final ChangeEvent e) { - final PageState state = e.getPageState(); - final Object key = BaseTree.this.getSelectedKey(state); - - if (key != null) { - expand(key.toString(), state); - } - } - } - - private class TreeExpansion implements TreeExpansionListener { - public final void treeExpanded(final TreeExpansionEvent e) { - //s_log.error("expanded"); - } - - public final void treeCollapsed(final TreeExpansionEvent e) { - //s_log.error("collapsed"); - } - } -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemContextBar.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemContextBar.java deleted file mode 100755 index ea833518b..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemContextBar.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.CMS; - -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ContentSection; - -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.PageLocations; -import com.arsdigita.kernel.KernelConfig; -import com.arsdigita.web.ParameterMap; -import com.arsdigita.web.URL; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.contentsection.ContentItemL10NManager; - -import java.util.List; -import java.util.Locale; - -/** - *

- * The context bar of the content section UI.

- * - * @author Justin Ross - * @author Jens Pelzetter - */ -class ContentItemContextBar extends ContentSectionContextBar { - - private final ItemSelectionModel itemSelectionModel; - private final StringParameter selectedLanguageParam; - - ContentItemContextBar(final ItemSelectionModel itemSelectionModel, - final StringParameter selectedLanguageParam) { - super(); - - this.itemSelectionModel = itemSelectionModel; - this.selectedLanguageParam = selectedLanguageParam; - } - - @Override - protected final List entries(final PageState state) { - final List entries = super.entries(state); - final ContentItem item = itemSelectionModel.getSelectedObject(state); - final ContentSection section = CMS.getContext().getContentSection(); - - final URL url = URL.there(state.getRequest(), - section.getPrimaryUrl() + "/" - + PageLocations.ITEM_PAGE, - params(item)); - - final StringBuilder title = new StringBuilder(); - title.append(localize("cms.ui.content_item")); - title.append(": ") - .append(item.getDisplayName()); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentItemL10NManager l10nManager = cdiUtil - .findBean(ContentItemL10NManager.class); - final String selectedLanguage = (String) state - .getValue(selectedLanguageParam); - final Locale selectedLocale; - if (selectedLanguage == null - || selectedLanguage.isEmpty()) { - selectedLocale = KernelConfig.getConfig().getDefaultLocale(); - } else { - selectedLocale = new Locale(selectedLanguage); - } - - final String language; - if (l10nManager.hasLanguage(item, selectedLocale)) { - language = selectedLanguage; - } else { - state.setValue(selectedLanguageParam, - KernelConfig.getConfig().getDefaultLanguage()); - language = KernelConfig.getConfig().getDefaultLanguage(); - } - if (language != null) { - title.append(" (") - .append(language) - .append(")"); - } - - entries.add(new Entry(title.toString(), url)); - - return entries; - } - - private static ParameterMap params(final ContentItem item) { - final ParameterMap params = new ParameterMap(); - - params.setParameter(ContentItemPage.ITEM_ID, item.getObjectId()); - - return params; - } - - private static String localize(final String key) { - return (String) ContentSectionPage.globalize(key).localize(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java index fbbec5045..13eb91680 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java @@ -24,10 +24,8 @@ import com.arsdigita.bebop.FormProcessException; import com.arsdigita.bebop.Label; import com.arsdigita.bebop.Link; import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.ParameterSingleSelectionModel; import com.arsdigita.bebop.Resettable; import com.arsdigita.bebop.SimpleContainer; -import com.arsdigita.bebop.SingleSelectionModel; import com.arsdigita.bebop.TabbedPane; import com.arsdigita.bebop.event.ActionEvent; import com.arsdigita.bebop.event.ActionListener; @@ -156,7 +154,6 @@ public class ContentItemPage extends CMSPage implements ActionListener { private final ItemTemplates templatesPane; private final Link previewLink; private final GlobalNavigation globalNavigation; - private final ContentItemContextBar contextBar; private final StringParameter selectedLanguageParam; @@ -268,9 +265,7 @@ public class ContentItemPage extends CMSPage implements ActionListener { globalNavigation = new GlobalNavigation(); add(globalNavigation); - contextBar = new ContentItemContextBar(itemSelectionModel, - selectedLanguageParam); - add(contextBar); + // Create panels. summaryPane = new Summary(itemSelectionModel); diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionContextBar.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionContextBar.java deleted file mode 100755 index ebaec6d78..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionContextBar.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.cms.CMS; -import com.arsdigita.cms.PageLocations; - -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ContentSection; - -import com.arsdigita.web.ParameterMap; -import com.arsdigita.web.URL; - -import org.apache.logging.log4j.LogManager; - -import java.math.BigDecimal; -import java.util.List; -import java.util.Stack; - -import org.apache.logging.log4j.Logger; - -/** - * The context bar of the content section UI. - * - * @author Justin Ross - * @author Jens Pelzetter - */ -public class ContentSectionContextBar extends WorkspaceContextBar { - - private static final Logger LOGGER = LogManager.getLogger( - ContentSectionContextBar.class); - - @Override - protected List entries(final PageState state) { - - /* Include breadcrumb entries already set by content-center (i.e. the - * URL of the content center itself */ - final List entries = super.entries(state); - - final ContentSection section = CMS.getContext().getContentSection(); - final Stack folderEntryStack = new Stack<>(); - String currentFolderLabel = null; - ParameterMap params = new ParameterMap(); - boolean isTemplate = false; - BigDecimal templateID = null; - - if (CMS.getContext().hasContentItem()) { - final ContentItem item = CMS.getContext().getContentItem(); - if (item == null) { - LOGGER.warn("item is null"); - } else if (item.getContentType() == null) { - LOGGER.warn( - "item.getContentType() returns null. item.class.getName(): " - + item.getClass().getName()); - } - - //ToDo NG - Not sure what happens here... -// final Optional parent = item.getParent(); -// -// while (!isTemplate -// && parent.isPresent() -// && parent.get() instanceof ContentItem) { -// if (currentFolderLabel != null) { -// final URL folderURL = URL.there -// (state.getRequest(), -// section.getPath() + "/" + PageLocations.SECTION_PAGE, -// params); -// folderEntryStack.push(new Entry(currentFolderLabel, folderURL)); -// currentFolderLabel = null; -// params = new ParameterMap(); -// } -// final ContentItem pitem = (ContentItem) parent; -// -// if (pitem instanceof Folder) { -// final Folder folder = (Folder) pitem; -// parent = folder.getParent(); -// -// currentFolderLabel = folder.getLabel(); -// if (parent != null || folder.equals(section.getRootFolder())) { -// params.setParameter -// (ContentSectionPage.SET_FOLDER, folder.getID()); -// } -// } else if (pitem instanceof ContentBundle) { -// final ACSObject ppitem = pitem.getParent(); -// -// if (ppitem != null && ppitem instanceof Folder) { -// final Folder folder = (Folder) ppitem; -// -// parent = folder.getParent(); -// currentFolderLabel = folder.getLabel(); -// if (parent != null || folder.equals(section -// .getRootFolder())) { -// params.setParameter -// (ContentSectionPage.SET_FOLDER, folder.getID()); -// } -// } else { -// parent = null; -// } -// } else { -// parent = null; -// } -// } - } - - if (isTemplate) { - params.setParameter(ContentSectionPage.SET_TAB, - new BigDecimal( - ContentSectionPage.CONTENTTYPES_TAB)); - params.setParameter(ContentSectionPage.SET_TEMPLATE, templateID); - } - - // add section-level entry. if this is for an item page, the URL - // will be for the root folder. - final URL url = URL.there( - state.getRequest(), - String.format("%s/" + PageLocations.SECTION_PAGE, - section.getPrimaryUrl()), - params); - - final String sectionTitle = lz("cms.ui.content_section"); - final String title = sectionTitle + ": " + section.getLabel(); - - entries.add(new Entry(title, url)); - - // add any folders to the path now - while (!folderEntryStack.empty()) { - entries.add(folderEntryStack.pop()); - } - - return entries; - } - - private static String lz(final String key) { - return (String) ContentSectionPage.globalize(key).localize(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java index 94b4d4701..e7cd7552f 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java @@ -132,7 +132,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener { private ContentTypeAdminPane m_typePane; //private LayoutPanel m_userAdminPane; private LayoutPanel m_csePane; - private ReportPane m_reportPane; /** * Creates the content section index page containing - a Navigaton bar for @@ -145,7 +144,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener { setClassAttr("cms-admin"); add(new GlobalNavigation()); - add(new ContentSectionContextBar()); // Initialize the individual panes m_folderPane = getFolderAdminPane(); @@ -349,13 +347,7 @@ public class ContentSectionPage extends CMSPage implements ActionListener { return m_csePane; } - protected ReportPane getReportPane() { - if (m_reportPane == null) { - m_reportPane = new ReportPane(); - } - return m_reportPane; - } - + /** * Adds the specified component, with the specified tab name, to the tabbed * pane only if it is not null. diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ImagesPane.java.todo b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ImagesPane.java.todo deleted file mode 100644 index 897899eb4..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ImagesPane.java.todo +++ /dev/null @@ -1,265 +0,0 @@ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package com.arsdigita.cms.ui; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.FormModel; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.List; -import com.arsdigita.bebop.MapComponentSelectionModel; -import com.arsdigita.bebop.Page; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.ParameterSingleSelectionModel; -import com.arsdigita.bebop.Resettable; -import com.arsdigita.bebop.SegmentedPanel; -import com.arsdigita.bebop.SegmentedPanel.Segment; -import com.arsdigita.bebop.SimpleContainer; -import com.arsdigita.bebop.event.ChangeEvent; -import com.arsdigita.bebop.event.ChangeListener; -import com.arsdigita.bebop.list.ListModel; -import com.arsdigita.bebop.list.ListModelBuilder; -import com.arsdigita.bebop.parameters.ParameterModel; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.util.GlobalizationUtil; -import com.arsdigita.toolbox.ui.ActionGroup; -import com.arsdigita.toolbox.ui.LayoutPanel; -import com.arsdigita.toolbox.ui.Section; -import com.arsdigita.util.Assert; -import com.arsdigita.util.LockableImpl; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import org.apache.log4j.Logger; - -/** - * A {@link LayoutPanel} to insert into {@link ContentSectionPage}. - * - * @author Sören Bernstein - */ -public class ImagesPane extends LayoutPanel implements Resettable { - - public static final Logger S_LOG = Logger.getLogger(ImagesPane.class); - private final StringParameter m_imageComponentKey; - private final MapComponentSelectionModel m_imageComponent; - private final ImageComponentAdminListener m_adminListener; - final private SegmentedPanel m_body; - private HashMap m_bodySegments = new HashMap(); - private final ResettableParameterSingleSelectionModel m_model; - private final List m_links; - private final LinksSection m_modes; - - public ImagesPane() { - super(); - - m_model = new ResettableParameterSingleSelectionModel(new - StringParameter(List.SELECTED)); - m_model.setDefaultSelection(ImageComponent.LIBRARY); - m_model.addChangeListener(new ImageAdminSelectionListener()); - - m_links = new List(new ImageAdminListModelBuilder()); - m_links.setSelectionModel(m_model); - - final SimpleContainer left = new SimpleContainer(); - setLeft(left); - - m_modes = new LinksSection(); - left.add(m_modes); - - m_body = new SegmentedPanel(); - setBody(m_body); - - m_imageComponentKey = new StringParameter("imageComponent"); - - final ParameterSingleSelectionModel componentModel = new - ParameterSingleSelectionModel(m_imageComponentKey); - m_imageComponent = new MapComponentSelectionModel(componentModel, - new HashMap()); - - final Map selectors = m_imageComponent.getComponentsMap(); - m_adminListener = new ImageComponentAdminListener(m_imageComponent, this); - - // Image library component - final ImageLibraryComponent library = new - ImageLibraryComponent(ImageComponent.ADMIN_IMAGES); - library.getForm().addInitListener(m_adminListener); - library.getForm().addProcessListener(m_adminListener); - selectors.put(ImageComponent.LIBRARY, library); - m_bodySegments.put(ImageComponent.LIBRARY, m_body.addSegment( - new Label(GlobalizationUtil.globalize( - "cms.contentasset.image.ui.image_library")), - library)); - - // Image upload component - final ImageUploadComponent upload = new - ImageUploadComponent(ImageComponent.ADMIN_IMAGES); - upload.getForm().addInitListener(m_adminListener); - upload.getForm().addSubmissionListener(m_adminListener); - upload.getForm().addProcessListener(m_adminListener); - selectors.put(ImageComponent.UPLOAD, upload); - m_bodySegments.put(ImageComponent.UPLOAD, m_body.addSegment( - new Label(GlobalizationUtil.globalize( - "cms.contentasset.image.ui.image_upload")), - upload)); - - } - - @Override - public final void register(final Page page) { - super.register(page); - - Iterator keys = m_bodySegments.keySet().iterator(); - - while (keys.hasNext()) { - String key = keys.next(); - page.setVisibleDefault(m_bodySegments.get(key), - m_model.getDefaultSelection().equals(key)); - } - - page.addComponentStateParam(this, m_imageComponentKey); - } - - /** - * Resets this pane and all its resettable components. - * - * @param state Page state - */ - @Override - public final void reset(final PageState state) { - super.reset(state); - - m_model.reset(state); - this.setActiveImageComponent(state, m_model.getDefaultSelection()); - } - - public final void setActiveImageComponent(PageState state, String activeComp) { - - Iterator keys = m_bodySegments.keySet().iterator(); - m_imageComponent.setSelectedKey(state, activeComp); - - while (keys.hasNext()) { - - String key = keys.next(); - final boolean visibility = key.equals(activeComp); - state.setVisible(m_bodySegments.get(key), visibility); - - for (int index = 0; index < m_bodySegments.get(key).size(); index++) { - - Component component = m_bodySegments.get(key).get(index); - - // Reset all components if they are of type Resettable - if (component instanceof Resettable) { - ((Resettable) component).reset(state); - } - - // Set visibility - component.setVisible(state, visibility); - } - } - } - - /** - * - */ - private class ResettableParameterSingleSelectionModel - extends ParameterSingleSelectionModel - implements Resettable { - - private String defaultKey; - - public ResettableParameterSingleSelectionModel(ParameterModel m) { - super(m); - } - - public void setDefaultSelection(String selKey) { - this.defaultKey = selKey; - } - - public String getDefaultSelection() { - return defaultKey; - } - - public void reset(PageState state) { - - if (Assert.isEnabled()) { - final FormModel model = state.getPage().getStateModel(); - Assert.isTrue(model.containsFormParam(getStateParameter())); - } - - state.setValue(getStateParameter(), this.defaultKey); - } - } - - /** - * - */ - private class ImageAdminListModel implements ListModel { - - private ArrayList m_keys; - private int m_index = -1; - - public ImageAdminListModel(ArrayList keys) { - m_keys = keys; - } - - public boolean next() { - return (m_index++ < m_keys.size() - 1); - } - - public Object getElement() { - return GlobalizationUtil.globalize( - "cms.contentasset.image.ui.image_" + m_keys.get(m_index)).localize(); - } - - public String getKey() { - return m_keys.get(m_index); - } - } - - private class ImageAdminListModelBuilder extends LockableImpl - implements ListModelBuilder { - - public ListModel makeModel(final List list, final PageState state) { - ArrayList keys = new ArrayList(2); - keys.add(ImageComponent.LIBRARY); - keys.add(ImageComponent.UPLOAD); - return new ImageAdminListModel(keys); - } - } - - private class ImageAdminSelectionListener implements ChangeListener { - - public final void stateChanged(final ChangeEvent e) { - S_LOG.debug("Selection state changed; I may change " - +"the body's visible pane"); - - final PageState state = e.getPageState(); - -// ImagesPane.this.reset(state); - - if (m_model.isSelected(state)) { - S_LOG.debug("The selection model is selected; displaying " - +"the item pane"); - - ImagesPane.this.setActiveImageComponent( - state, - state.getControlEventValue()); - } - } - } - - private class LinksSection extends Section { - - LinksSection() { - setHeading(GlobalizationUtil.globalize( - "cms.contentasset.image.ui.images")); - - final ActionGroup group = new ActionGroup(); - setBody(group); - - group.setSubject(m_links); - } - } -} \ No newline at end of file diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ReportPane.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ReportPane.java deleted file mode 100644 index 0eb5efee3..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ReportPane.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Copyright (C) 2009 Permeance Technologies Pty Ltd. 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; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; - -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.List; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.ParameterSingleSelectionModel; -import com.arsdigita.bebop.SingleSelectionModel; -import com.arsdigita.bebop.event.ChangeEvent; -import com.arsdigita.bebop.event.ChangeListener; -import com.arsdigita.bebop.list.ListModel; -import com.arsdigita.bebop.list.ListModelBuilder; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.ui.report.ContentSectionSummaryTable; -import com.arsdigita.cms.ui.report.Report; -import com.arsdigita.cms.ui.report.ReportListModel; -import com.arsdigita.toolbox.ui.ActionGroup; -import com.arsdigita.toolbox.ui.Section; -import com.arsdigita.util.LockableImpl; - -/** - * A pane that shows selectable reports and their results. A selectable list of - * reports is shown on the left-hand side, a selected report is shown as body. - * - * @author - * thomas-buckel - * @author - * tim-permeance - * @author Jens Pelzetter - */ -public class ReportPane extends BaseAdminPane { - - private final SingleSelectionModel selectionModel; - private final java.util.List availableReports; - - public ReportPane() { - availableReports = getReports(); - - selectionModel = new ParameterSingleSelectionModel<>( - new StringParameter(List.SELECTED)); - selectionModel.addChangeListener(new SelectionListener()); - setSelectionModel(selectionModel); - - List m_reports = new List(new ReportListModelBuilder(availableReports)); - m_reports.setSelectionModel(selectionModel); - - final ReportsListSection reportsListSection = new ReportsListSection( - m_reports); - setLeft(reportsListSection); - - // Register the actual components of the reports for later usage - for (Report report : availableReports) { - getBody().add(report.getComponent()); - } - - setIntroPane(new Label(gz("cms.ui.reports.intro"))); - } - - /** - * @return List of available reports. - */ - private java.util.List getReports() { - java.util.List reports = new ArrayList<>(); - reports.add(new Report("cms.ui.reports.css.reportName", - new ContentSectionSummaryTable())); - // Add other reports as required - - Collections.sort( - reports, - (r1, r2) -> r1.getName().compareTo(r2.getName())); - - return reports; - } - - /** - * Get the report model that matches the given key. - * - * @param key Key to match. - * - * @return Report model that matches that given key, null if no matching - * report was found. - */ - private Report getReportByKey(final String key) { - for (Report report : availableReports) { - if (report.getKey().equals(key)) { - return report; - } - } - return null; - } - - /** - * UI section for left-hand list of reports. - */ - private class ReportsListSection extends Section { - - ReportsListSection(final List reports) { - setHeading(gz("cms.ui.reports.header")); - ActionGroup group = new ActionGroup(); - setBody(group); - group.setSubject(reports); - } - - } - - /** - * SelectionListener for selected report. It shows the selected report in - * the body of this component. - */ - private class SelectionListener implements ChangeListener { - - @Override - public final void stateChanged(final ChangeEvent event) { - - final PageState state = event.getPageState(); - - getBody().reset(state); - - if (selectionModel.isSelected(state)) { - Report selectedReport = getReportByKey(selectionModel - .getSelectedKey(state).toString()); - if (selectedReport != null) { - getBody().push(state, selectedReport.getComponent()); - } - } - } - - } - - /** - * ListModelBuilder creating a ReportListModel for a list of reports. - */ - private static class ReportListModelBuilder - extends LockableImpl - implements ListModelBuilder { - - private final java.util.List reports; - - private ReportListModelBuilder(final java.util.List reports) { - this.reports = reports; - } - - @Override - public final ListModel makeModel(final List list, - final PageState state) { - return new ReportListModel(reports); - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractBinaryAssetForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractBinaryAssetForm.java deleted file mode 100644 index 58cf71b42..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractBinaryAssetForm.java +++ /dev/null @@ -1,198 +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.assets.forms; - -import com.arsdigita.bebop.BoxPanel; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Text; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.TextArea; -import com.arsdigita.cms.ui.FileUploadSection; -import com.arsdigita.cms.ui.assets.AbstractAssetForm; -import com.arsdigita.cms.ui.assets.AssetPane; -import com.arsdigita.globalization.GlobalizedMessage; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; - -import org.librecms.CmsConstants; -import org.librecms.assets.BinaryAsset; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -/** - * Base form for assets which extend {@link BinaryAsset}. - * - * @author Jens Pelzetter - * @param Type of binary asset - */ -public abstract class AbstractBinaryAssetForm - extends AbstractAssetForm { - - private TextArea description; - - private Text fileName; - - private Text mimeType; - - private Text size; - - private FileUploadSection fileUpload; - - public AbstractBinaryAssetForm(final AssetPane assetPane) { - super(assetPane); - } - - @Override - protected void addWidgets() { - - final BoxPanel panel = new BoxPanel(BoxPanel.VERTICAL); - - panel.add(new Label(new GlobalizedMessage( - "cms.ui.assets.binaryasset.description", - CmsConstants.CMS_BUNDLE))); - description = new TextArea("binaryasset-description"); - panel.add(description); - - panel.add(new Label( - new GlobalizedMessage("cms.ui.assets.binaryasset.filename", - CmsConstants.CMS_BUNDLE))); - fileName = new Text(); - panel.add(fileName); - - panel.add(new Label( - new GlobalizedMessage("cms.ui.assets.binaryasset.mimetype", - CmsConstants.CMS_BUNDLE))); - mimeType = new Text(); - panel.add(mimeType); - - panel.add(new Label( - new GlobalizedMessage("cms.ui.assets.binaryasset.size", - CmsConstants.CMS_BUNDLE))); - size = new Text(); - panel.add(size); - - fileUpload = new FileUploadSection( - new GlobalizedMessage("cms.ui.assets.binaryasset.mimetype", - CmsConstants.CMS_BUNDLE), - "", - ""); - panel.add(fileUpload); - - add(panel); - - setEncType(CmsConstants.FORM_ENCTYPE_MULTIPART); - } - - @Override - protected void initForm(final PageState state, - final Map data) { - - super.initForm(state, data); - - if (!data.isEmpty()) { - - description.setValue(state, - data.get("description")); - - if (data.containsKey("data")) { - - final byte[] binaryData = (byte[]) data.get("data"); - if (binaryData.length == 0) { - fileName.setText("-"); - mimeType.setText("-"); - size.setText("-"); - } else { - fileName.setText((String) data.get("fileName")); - mimeType.setText((String) data.get("mimeType")); - size.setText(Long.toString((long) data.get("size"))); - } - - } else { - fileName.setText("-"); - mimeType.setText("-"); - size.setText("-"); - } - } - } - - @Override - protected void showLocale(final PageState state) { - - final Long selectedAssetId = getSelectedAssetId(state); - - if (selectedAssetId != null) { - - final Map data = getController() - .getAssetData(selectedAssetId, - getAssetClass(), - getSelectedLocale(state)); - - description - .setValue( - state, - data - .get(AbstractBinaryAssetFormController.DESCRIPTION)); - } - } - - @Override - protected Map collectData(final FormSectionEvent event) - throws FormProcessException { - - return getFileData(event); - } - - private Map getFileData(final FormSectionEvent event) - throws FormProcessException { - - final File file = fileUpload.getFile(event); - if (file == null) { - return Collections.emptyMap(); - } else { - final Path path = file.toPath(); - final byte[] data; - try { - data = Files.readAllBytes(path); - } catch (IOException ex) { - throw new FormProcessException(ex); - } - - final Map assetData = new HashMap<>(); - - assetData.put(AbstractBinaryAssetFormController.DATA, - data); - assetData.put(AbstractBinaryAssetFormController.FILE_NAME, - fileUpload.getFileName(event)); - assetData.put(AbstractBinaryAssetFormController.SIZE, - data.length); - assetData.put(AbstractBinaryAssetFormController.MIME_TYPE, - fileUpload.getMimeType(event)); - - return assetData; - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractBinaryAssetFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractBinaryAssetFormController.java deleted file mode 100644 index 151f6d651..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractBinaryAssetFormController.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.cms.ui.assets.AbstractAssetFormController; - -import org.librecms.assets.BinaryAsset; - -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -import javax.activation.MimeType; -import javax.transaction.Transactional; - -/** - * - * @author Jens Pelzetter - * @param - */ -public abstract class AbstractBinaryAssetFormController - extends AbstractAssetFormController { - - protected static final String DESCRIPTION = "description"; - - protected static final String FILE_NAME = "fileName"; - - protected static final String MIME_TYPE = "mimeType"; - - protected static final String DATA = "data"; - - protected static final String SIZE = "size"; - - @Override - @Transactional(Transactional.TxType.REQUIRED) - protected Map getAssetData(final T asset, - final Locale selectedLocale) { - - final Map data = new HashMap<>(); - - final String description = asset - .getDescription() - .getValue(selectedLocale); - - data.put(DESCRIPTION, description); - data.put(FILE_NAME, asset.getFileName()); - data.put(MIME_TYPE, asset.getMimeType()); - data.put(DATA, asset.getData()); - data.put(SIZE, asset.getSize()); - - return data; - } - - @Override - @Transactional(Transactional.TxType.REQUIRED) - public void updateAssetProperties(final T asset, - final Locale selectedLocale, - final Map data) { - - if (data.containsKey(DESCRIPTION)) { - asset.getDescription().putValue(selectedLocale, - (String) data.get(DESCRIPTION)); - } - - if (data.containsKey(FILE_NAME)) { - asset.setFileName((String) data.get(FILE_NAME)); - } - - if (data.containsKey(MIME_TYPE)) { - asset.setMimeType((MimeType) data.get(MIME_TYPE)); - } - - if (data.containsKey(DATA)) { - //asset.setData((byte[]) data.get(DATA)); - } - - if (data.containsKey(SIZE)) { - asset.setSize((long) data.get(SIZE)); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractBookmarkForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractBookmarkForm.java deleted file mode 100644 index 98be1388a..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractBookmarkForm.java +++ /dev/null @@ -1,141 +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.assets.forms; - -import com.arsdigita.bebop.FormData; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.event.FormValidationListener; -import com.arsdigita.bebop.form.TextArea; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.cms.ui.assets.AbstractAssetForm; -import com.arsdigita.cms.ui.assets.AssetPane; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.librecms.CmsConstants; -import org.librecms.assets.Bookmark; -import org.librecms.contentsection.Asset; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Map; -import java.util.Objects; -import java.util.Optional; - -/** - * Abstract base form for all forms for {@link BookmarkAsset}s. - * - * @author Jens Pelzetter - * @param Type of the Bookmark Asset. - */ -public abstract class AbstractBookmarkForm - extends AbstractAssetForm { - - private TextArea description; - - private TextField url; - - public AbstractBookmarkForm(final AssetPane assetPane) { - super(assetPane); - } - - @Override - protected void addWidgets() { - - add(new Label( - new GlobalizedMessage("cms.ui.assets.bookmark.description", - CmsConstants.CMS_BUNDLE))); - description = new TextArea("bookmark-description"); - add(description); - - add(new Label(new GlobalizedMessage("cms.ui.assets.bookmark.url", - CmsConstants.CMS_BUNDLE))); - url = new TextField("bookmark-url"); - add(url); - - addValidationListener(new FormValidationListener() { - - @Override - public void validate(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - final FormData data = event.getFormData(); - - try { - new URL((String) url.getValue(state)); - } catch (MalformedURLException ex) { - data.addError(new GlobalizedMessage( - "cms.ui.assets.bookmark.url.malformed", - CmsConstants.CMS_BUNDLE)); - } - } - - }); - - } - - @Override - protected void initForm(final PageState state, - final Map data) { - - super.initForm(state, data); - - if (!data.isEmpty()) { - - description - .setValue( - state, - data.get(AbstractBookmarkFormController.DESCRIPTION)); - url.setValue(state, data.get(AbstractBookmarkFormController.URL)); - - } - } - - @Override - protected void showLocale(final PageState state) { - - final Long selectedAssetId = getSelectedAssetId(state); - - if (selectedAssetId != null) { - - final Map data = getController() - .getAssetData(selectedAssetId, - getAssetClass(), - getSelectedLocale(state)); - - description.setValue( - state, - data.get(AbstractBinaryAssetFormController.DESCRIPTION)); - } - } - - protected void updateData(final Bookmark bookmark, - final PageState state) { - bookmark - .getDescription() - .putValue(getSelectedLocale(state), - (String) description.getValue(state)); - - bookmark.setUrl((String) url.getValue(state)); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractBookmarkFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractBookmarkFormController.java deleted file mode 100644 index db319efa8..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractBookmarkFormController.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.cms.ui.assets.AbstractAssetFormController; - -import org.librecms.assets.Bookmark; - -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -/** - * - * @author Jens Pelzetter - * @param - */ -public abstract class AbstractBookmarkFormController - extends AbstractAssetFormController { - - protected static final String DESCRIPTION = "description"; - - protected static final String URL = "url"; - - @Override - protected Map getAssetData(final T asset, - final Locale selectedLocale) { - - final String description = asset - .getDescription() - .getValue(selectedLocale); - - final String url = asset.getUrl(); - - final Map data = new HashMap<>(); - - data.put("description", description); - data.put("url", url); - - return data; - } - - @Override - public void updateAssetProperties(final T asset, - final Locale selectedLocale, - final Map data) { - - if (data.containsKey(DESCRIPTION)) { - - asset.getDescription().putValue(selectedLocale, - (String) data.get(DESCRIPTION)); - - } - - if (data.containsKey(URL)) { - - asset.setUrl((String) data.get(URL)); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractContactableEntityForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractContactableEntityForm.java deleted file mode 100644 index c271e493c..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractContactableEntityForm.java +++ /dev/null @@ -1,434 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.bebop.BoxPanel; -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.ControlLink; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SimpleContainer; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.Text; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.event.PrintEvent; -import com.arsdigita.bebop.event.PrintListener; -import com.arsdigita.bebop.event.TableActionEvent; -import com.arsdigita.bebop.event.TableActionListener; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.form.SingleSelect; -import com.arsdigita.bebop.form.Submit; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.table.TableCellRenderer; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.bebop.table.TableColumnModel; -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.bebop.table.TableModelBuilder; -import com.arsdigita.cms.ui.assets.AbstractAssetForm; -import com.arsdigita.cms.ui.assets.AssetPane; -import com.arsdigita.cms.ui.assets.AssetSearchWidget; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.util.LockableImpl; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.l10n.GlobalizationHelper; -import org.librecms.CmsConstants; -import org.librecms.assets.ContactEntryKey; -import org.librecms.assets.ContactableEntity; -import org.librecms.assets.PostalAddress; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.TooManyListenersException; - -import static org.librecms.CmsConstants.*; - -/** - * - * @author Jens Pelzetter - * @param - */ -public abstract class AbstractContactableEntityForm - extends AbstractAssetForm { - - private static final int COL_CONTACT_ENTRIES_KEY = 0; - - private static final int COL_CONTACT_ENTRIES_VALUE = 1; - - private static final int COL_CONTACT_ENTRIES_REMOVE = 2; - - private SimpleContainer contactEntriesContainer; - - private Table contactEntriesTable; - - private SingleSelect contactEntryKeySelect; - - private TextField contactEntryValueField; - - private Submit addContactEntryLink; - - private AssetSearchWidget postalAddressSearchWidget; - - public AbstractContactableEntityForm(final AssetPane assetPane) { - - super(assetPane); - } - - @Override - protected void addWidgets() { - - addPropertyWidgets(); - - contactEntriesContainer = new BoxPanel(BoxPanel.VERTICAL) { - - @Override - public boolean isVisible(final PageState state) { - return getSelectedAssetId(state) != null; - } - - }; - add(contactEntriesContainer); - - contactEntriesTable = buildContactEntriesTable(); - contactEntriesContainer.add(contactEntriesTable); - - contactEntryKeySelect = new SingleSelect(new StringParameter( - "contactentry-key")); - try { - contactEntryKeySelect - .addPrintListener(new ContactEntryKeySelectPrintListener()); - } catch (TooManyListenersException ex) { - throw new RuntimeException(ex); - } - contactEntriesContainer.add(new Label( - new GlobalizedMessage( - "cms.ui.authoring.assets.contactable.contactentries.key", - CMS_BUNDLE)) - ); - contactEntriesContainer.add(contactEntryKeySelect); - - contactEntryValueField = new TextField("contact-entry-value"); - contactEntriesContainer.add(new Label( - new GlobalizedMessage( - "cms.ui.authoring.assets.contactable.contactentries.value", - CMS_BUNDLE)) - ); - contactEntriesContainer.add(contactEntryValueField); - - addContactEntryLink = new Submit( - new GlobalizedMessage( - "cms.ui.authoring.assets.contactable.contactentries.add", - CMS_BUNDLE) - ); - contactEntriesContainer.add(addContactEntryLink); - - contactEntriesContainer.add(new Label( - new GlobalizedMessage( - "cms.ui.authoring.assets.contactable.postaladdress", - CMS_BUNDLE)) - ); - postalAddressSearchWidget = new AssetSearchWidget( - "contactable-postaladdress", PostalAddress.class - ); - contactEntriesContainer.add(postalAddressSearchWidget); - - } - - @Override - public void initForm(final PageState state, - final Map data) { - - super.initForm(state, data); - - final Long selectedAssetId = getSelectedAssetId(state); - - if (selectedAssetId != null) { - - postalAddressSearchWidget.setValue( - state, - data.get(AbstractContactableEntityFormController.POSTAL_ADDRESS) - ); - } - } - - @Override - protected Map collectData( - final FormSectionEvent event) { - - final PageState state = event.getPageState(); - - final Map data = new HashMap<>(); - - if (postalAddressSearchWidget.getValue(state) != null) { - - data.put(AbstractContactableEntityFormController.POSTAL_ADDRESS, - postalAddressSearchWidget.getValue(state)); - } - - return data; - } - - @Override - public void process(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - if (addContactEntryLink.isSelected(state)) { - - final Long selectedAssetId = getSelectedAssetId(state); - if (selectedAssetId == null) { - throw new FormProcessException( - new GlobalizedMessage( - "cms.ui.assets.none_selected", CMS_BUNDLE) - ); - } - - @SuppressWarnings("unchecked") - final AbstractContactableEntityFormController controller - = (AbstractContactableEntityFormController) getController(); - - final String key = (String) contactEntryKeySelect - .getValue(state); - final String value = (String) contactEntryValueField.getValue(state); - - controller.addContactEntry(key, value, selectedAssetId); - - contactEntryKeySelect.setValue(state, null); - contactEntryValueField.setValue(state, null); - } else { - super.process(event); - } - } - - protected abstract void addPropertyWidgets(); - - private Table buildContactEntriesTable() { - - final Table table = new Table(); -// { - -// @Override -// public boolean isVisible(final PageState state) { -// return getSelectedAsset(state).isPresent(); -// } -// }; - final TableColumnModel columnModel = table.getColumnModel(); - columnModel.add(new TableColumn( - COL_CONTACT_ENTRIES_KEY, - new Label( - new GlobalizedMessage( - "cms.ui.authoring.assets.contactable.contactentries.key", - CmsConstants.CMS_BUNDLE - ) - ) - )); - columnModel.add(new TableColumn( - COL_CONTACT_ENTRIES_VALUE, - new Label( - new GlobalizedMessage( - "cms.ui.authoring.assets.contactable.contactentries.value", - CmsConstants.CMS_BUNDLE - ) - ) - )); - columnModel.add(new TableColumn( - COL_CONTACT_ENTRIES_REMOVE, - new Label( - new GlobalizedMessage( - "cms.ui.authoring.assets.contactable.contactentries.remove", - CmsConstants.CMS_BUNDLE - ) - ) - )); - - table.setModelBuilder(new ContactEntriesTableModelBuilder()); - - table - .getColumn(COL_CONTACT_ENTRIES_REMOVE) - .setCellRenderer(new ContactEntryRemoveCellRenderer()); - - table.setEmptyView( - new Label( - new GlobalizedMessage( - "cms.ui.authoring.assets.contactable.contactentries.none", - CmsConstants.CMS_BUNDLE - ) - ) - ); - - table.addTableActionListener(new TableActionListener() { - - @Override - public void cellSelected(final TableActionEvent event) - throws FormProcessException { - - final Integer rowKey = (Integer) event.getRowKey(); - - @SuppressWarnings("unchecked") - final AbstractContactableEntityFormController controller - = (AbstractContactableEntityFormController) getController(); - final PageState state = event.getPageState(); - final Long selectedId = getSelectedAssetId(state); - if (selectedId != null) { - controller.removeContactEntry(rowKey, selectedId); - } - } - - @Override - public void headSelected(final TableActionEvent event) { - - // Nothing - } - - }); - - return table; - } - - private class ContactEntriesTableModelBuilder - extends LockableImpl implements TableModelBuilder { - - @Override - public TableModel makeModel(final Table table, - final PageState state) { - - final Long selectedId = getSelectedAssetId(state); - if (selectedId == null) { - throw new RuntimeException("No asset selected."); - } - - @SuppressWarnings("unchecked") - final AbstractContactableEntityFormController controller - = (AbstractContactableEntityFormController) getController(); - final List contactEntries = controller - .getContactEntries(selectedId, getSelectedLocale(state)); - - return new ContactEntriesTableModel(contactEntries); - } - - } - - private class ContactEntriesTableModel implements TableModel { - - private final Iterator contactEntries; - - private String[] currentContactEntry; - - public ContactEntriesTableModel( - final List contactEntries) { - - this.contactEntries = contactEntries.iterator(); - } - - @Override - public int getColumnCount() { - return 3; - } - - @Override - public boolean nextRow() { - - if (contactEntries.hasNext()) { - currentContactEntry = contactEntries.next(); - return true; - } else { - return false; - } - } - - @Override - public Object getElementAt(final int columnIndex) { - - switch (columnIndex) { - case COL_CONTACT_ENTRIES_KEY: - return currentContactEntry[1]; - case COL_CONTACT_ENTRIES_VALUE: - return currentContactEntry[2]; - case COL_CONTACT_ENTRIES_REMOVE: - return new Label( - new GlobalizedMessage( - "cms.ui.authoring.assets.contactable" - + ".contactentries.remove", - CmsConstants.CMS_BUNDLE - ) - ); - default: - throw new IllegalArgumentException(String.format( - "Illegal column index %d.", columnIndex)); - - } - } - - @Override - public Object getKeyAt(int columnIndex) { - return currentContactEntry[0]; - } - - } - - private class ContactEntryRemoveCellRenderer implements TableCellRenderer { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - - return new ControlLink((Component) value); - } - - } - - private class ContactEntryKeySelectPrintListener implements PrintListener { - - @Override - public void prepare(final PrintEvent event) { - - final SingleSelect target = (SingleSelect) event.getTarget(); - target.clearOptions(); - - target.addOption( - new Option("", - new Label(new GlobalizedMessage("cms.ui.select_one", - CMS_BUNDLE))) - ); - - final AbstractContactableEntityFormController controller = (AbstractContactableEntityFormController) getController(); - - final PageState state = event.getPageState(); - - final List keys = controller - .findAvailableContactEntryKeys(getSelectedLocale(state)); - - for (final String[] key : keys) { - target.addOption(new Option(key[0], new Text(key[1]))); - } - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractContactableEntityFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractContactableEntityFormController.java deleted file mode 100644 index 4cfebbf64..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AbstractContactableEntityFormController.java +++ /dev/null @@ -1,210 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.cms.ui.assets.AbstractAssetFormController; - -import org.libreccm.l10n.GlobalizationHelper; -import org.librecms.assets.ContactEntry; -import org.librecms.assets.ContactEntryKey; -import org.librecms.assets.ContactEntryKeyByLabelComparator; -import org.librecms.assets.ContactEntryKeyRepository; -import org.librecms.assets.ContactableEntity; -import org.librecms.assets.ContactableEntityManager; -import org.librecms.assets.ContactableEntityRepository; -import org.librecms.assets.PostalAddress; -import org.librecms.contentsection.AssetRepository; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; - -import javax.inject.Inject; -import javax.transaction.Transactional; - -/** - * - * @author Jens Pelzetter - * @param - */ -public abstract class AbstractContactableEntityFormController - extends AbstractAssetFormController { - - protected static final String POSTAL_ADDRESS = "postalAddress"; - - @Inject - private AssetRepository assetRepository; - - @Inject - private ContactableEntityRepository contactableEntityRepository; - - @Inject - private ContactableEntityManager contactableEntityManager; - - @Inject - private ContactEntryKeyRepository keyRepository; - - @Inject - private GlobalizationHelper globalizationHelper; - - @Transactional(Transactional.TxType.REQUIRED) - @Override - protected Map getAssetData(final T asset, - final Locale selectedLocale) { - - final Map data = new HashMap<>(); - - final PostalAddress postalAddress = asset.getPostalAddress(); - if (postalAddress != null) { - data.put(POSTAL_ADDRESS, postalAddress.getObjectId()); - } - - return data; - } - - @Override - public void updateAssetProperties(final T asset, - final Locale selectedLocale, - final Map data) { - - if (data.containsKey(POSTAL_ADDRESS)) { - - final long addressId = (long) data.get(POSTAL_ADDRESS); - final PostalAddress postalAddress = assetRepository - .findById(addressId, PostalAddress.class) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No PostalAddress with ID %d found.", addressId))); - - contactableEntityManager - .addPostalAddressToContactableEntity(postalAddress, asset); - } - } - - /** - * Returns the contact entries of the provided contentable entity for the - * provided language. - * - * @param contactableId The ID of the contactable entity. - * @param selectedLocale The selected locale. - * - * @return An list of the contact entires - */ - @Transactional(Transactional.TxType.REQUIRED) - public List getContactEntries( - final Long contactableId, final Locale selectedLocale) { - - Objects.requireNonNull(contactableId, - "Can't get contact entries from null."); - - final ContactableEntity entity = contactableEntityRepository - .findById(contactableId) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No ContactEntity with ID %d found.", contactableId))); - - return entity - .getContactEntries() - .stream() - .map(contactEntry -> toContactEntryArray(contactEntry, - selectedLocale)) - .collect(Collectors.toList()); - } - - private String[] toContactEntryArray(final ContactEntry entry, - final Locale selectedLocale) { - - final String key = entry.getKey().getEntryKey(); - final String label = entry.getKey().getLabel().getValue(selectedLocale); - final String value = entry.getValue(); - - return new String[]{key, label, value}; - } - - @Transactional(Transactional.TxType.REQUIRED) - public void addContactEntry(final String contactEntryKey, - final String contactEntryValue, - final Long toContactableEntityWithId) { - - final ContactableEntity contactable = contactableEntityRepository - .findById(toContactableEntityWithId) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No ContactableEntity with ID %d found", - toContactableEntityWithId))); - - final ContactEntryKey key = keyRepository - .findByEntryKey(contactEntryKey) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No ContactEntryKey with key \"%s\" found.", contactEntryKey))); - final ContactEntry entry = new ContactEntry(); - entry.setKey(key); - entry.setValue(contactEntryValue); - entry.setOrder(contactable.getContactEntries().size()); - - contactableEntityManager - .addContactEntryToContactableEntity(entry, contactable); - } - - @Transactional(Transactional.TxType.REQUIRED) - public void removeContactEntry(final int withIndex, - final Long fromContactableEntityWithId) { - - final ContactableEntity contactable = contactableEntityRepository - .findById(fromContactableEntityWithId) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No ContactableEntity with ID %d found", - fromContactableEntityWithId))); - - if (contactable.getContactEntries().size() > withIndex) { - - final ContactEntry contactEntry = contactable - .getContactEntries() - .get(withIndex); - contactableEntityManager.removeContactEntryFromContactableEntity( - contactEntry, contactable - ); - } - } - - @Transactional(Transactional.TxType.REQUIRED) - public List findAvailableContactEntryKeys( - final Locale selectedLocale) { - - return keyRepository - .findAll() - .stream() - .sorted(new ContactEntryKeyByLabelComparator(selectedLocale)) - .map(key -> buildContactEntryKeyArray(key, - selectedLocale)) - .collect(Collectors.toList()); - } - - private String[] buildContactEntryKeyArray( - final ContactEntryKey contactEntryKey, final Locale selectedLocale) { - - final String key = contactEntryKey.getEntryKey(); - final String label = contactEntryKey.getLabel().getValue(selectedLocale); - - return new String[]{key, label}; - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AudioForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AudioForm.java deleted file mode 100644 index 67288af40..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AudioForm.java +++ /dev/null @@ -1,128 +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.assets.forms; - -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.cms.ui.assets.AssetPane; -import com.arsdigita.cms.ui.assets.AssetSearchWidget; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.librecms.CmsConstants; -import org.librecms.assets.AudioAsset; -import org.librecms.assets.LegalMetadata; - -import java.util.Map; - -/** - * - * @author Yannick Bülter - * @author Jens Pelzetter - */ -public class AudioForm extends AbstractBinaryAssetForm { - - private AssetSearchWidget assetSearchWidget; - - public AudioForm(final AssetPane assetPane) { - super(assetPane); - } - - @Override - protected void addWidgets() { - - assetSearchWidget = new AssetSearchWidget("legal-metadata", - LegalMetadata.class); - - add(new Label(new GlobalizedMessage( - "cms.ui.assets.audio.legal_metadata.label", - CmsConstants.CMS_BUNDLE - ))); - add(assetSearchWidget); - } - - @Override - protected void initForm(final PageState state, - final Map data) { - - super.initForm(state, data); - - if (data.containsKey(AudioFormController.LEGAL_METADATA_ID)) { - - final Long legalMetadataId = (Long) data - .get(AudioFormController.LEGAL_METADATA_ID); - if (legalMetadataId != null) { - assetSearchWidget.setValue(state, legalMetadataId); - } - } - } - - @Override - protected Class getAssetClass() { - return AudioAsset.class; - } - -// @Override -// protected Asset createAsset(final FormSectionEvent event) -// throws FormProcessException { -// -// final AudioAsset audioAsset = (AudioAsset) super.createAsset(event); -// -// final PageState state = event.getPageState(); -// -// updateData(audioAsset, state); -// -// return audioAsset; -// } -// @Override -// protected void updateAsset(final Asset asset, -// final FormSectionEvent event) -// throws FormProcessException { -// -// super.updateAsset(asset, event); -// -// final PageState state = event.getPageState(); -// -// final AudioAsset audioAsset = (AudioAsset) asset; -// -// updateData(audioAsset, state); -// } - -// protected void updateData(final AudioAsset audioAsset, -// final PageState state) { -// -// final Long legalMetadataId = (Long) assetSearchWidget.getValue(state); -// if (legalMetadataId != null) { -// final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); -// final AssetRepository assetRepo = cdiUtil.findBean( -// AssetRepository.class); -// final LegalMetadata legalMetadata = (LegalMetadata) assetRepo -// .findById(legalMetadataId) -// .orElseThrow(() -> new IllegalArgumentException(String.format( -// "No LegalMetadata asset with ID %d in the database.", -// legalMetadataId))); -// -// audioAsset.setLegalMetadata(legalMetadata); -// } -// } - -// @Override -// protected BinaryAsset createBinaryAsset(final PageState state) { -// return new AudioAsset(); -// } -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AudioFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AudioFormController.java deleted file mode 100644 index a7bf6c172..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/AudioFormController.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.cms.ui.assets.IsControllerForAssetType; - -import org.librecms.assets.AudioAsset; -import org.librecms.assets.LegalMetadata; -import org.librecms.contentsection.AssetRepository; -import org.librecms.contentsection.Folder; - -import java.util.Locale; -import java.util.Map; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -@IsControllerForAssetType(AudioAsset.class) -public class AudioFormController extends AbstractBinaryAssetFormController { - - protected static final String LEGAL_METADATA_ID = "legalMetadataId"; - - @Inject - private AssetRepository assetRepository; - - @Override - protected Map getAssetData(final AudioAsset asset, - final Locale selectedLocale) { - - final Map data = super.getAssetData(asset, - selectedLocale); - - final LegalMetadata legalMetadata = asset.getLegalMetadata(); - if (legalMetadata != null) { - data.put(LEGAL_METADATA_ID, legalMetadata.getObjectId()); - } - - return data; - } - - @Override - public void updateAssetProperties(final AudioAsset asset, - final Locale selectedLocale, - final Map data) { - - super.updateAssetProperties(asset, selectedLocale, data); - - if (data.containsKey(LEGAL_METADATA_ID)) { - - final long legalMetadataId = (long) data.get(LEGAL_METADATA_ID); - - final LegalMetadata legalMetadata = assetRepository - .findById(legalMetadataId, LegalMetadata.class) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No LegalMetadata with ID %d found.", legalMetadataId))); - - asset.setLegalMetadata(legalMetadata); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/BookmarkForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/BookmarkForm.java deleted file mode 100644 index 124e89df2..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/BookmarkForm.java +++ /dev/null @@ -1,182 +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.assets.forms; - -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.cms.ui.assets.AssetPane; - -import org.librecms.assets.Bookmark; - -import java.util.Collections; -import java.util.Map; - -/** - * - * @author Jens Pelzetter - */ -public class BookmarkForm extends AbstractBookmarkForm { - -// private TextArea description; -// private TextField url; - public BookmarkForm(final AssetPane assetPane) { - super(assetPane); - } - -// @Override -// protected void addWidgets() { -// -// add(new Label( -// new GlobalizedMessage("cms.ui.assets.bookmark.description", -// CmsConstants.CMS_BUNDLE))); -// description = new TextArea("bookmark-description"); -// add(description); -// -// add(new Label(new GlobalizedMessage("cms.ui.assets.bookmark.url", -// CmsConstants.CMS_BUNDLE))); -// url = new TextField("bookmark-url"); -// add(url); -// -// addValidationListener(new FormValidationListener() { -// -// @Override -// public void validate(final FormSectionEvent event) -// throws FormProcessException { -// -// final PageState state = event.getPageState(); -// final FormData data = event.getFormData(); -// -// try { -// new URL((String) url.getValue(state)); -// } catch (MalformedURLException ex) { -// data.addError(new GlobalizedMessage( -// "cms.ui.assets.bookmark.url.malformed", -// CmsConstants.CMS_BUNDLE)); -// } -// } -// -// }); -// -// } -// -// @Override -// protected void initForm(final PageState state, -// final Optional selectedAsset) { -// -// if (selectedAsset.isPresent()) { -// -// if (!(selectedAsset.get() instanceof Bookmark)) { -// throw new IllegalArgumentException(String.format( -// "The provided asset must be an instanceof of class '%s' or " -// + "an subclass but is an instanceof of class '%s'.", -// Bookmark.class.getName(), -// selectedAsset.get().getClass().getName())); -// } -// -// final Bookmark bookmark = selectedAsset.get(); -// -// description.setValue(state, -// bookmark -// .getDescription() -// .getValue(getSelectedLocale(state))); -// url.setValue(state, bookmark.getUrl()); -// -// } -// -// } -// -// @Override -// protected void showLocale(final PageState state) { -// final Optional selectedAsset = getSelectedAsset(state); -// -// if (selectedAsset.isPresent()) { -// if (!(getSelectedAsset(state).get() instanceof Bookmark)) { -// throw new IllegalArgumentException( -// "Selected asset is not a bookmark"); -// } -// -// final Bookmark bookmark = selectedAsset.get(); -// -// description.setValue(state, -// bookmark -// .getDescription() -// .getValue(getSelectedLocale(state))); -// } -// } - @Override - @SuppressWarnings("unchecked") - protected Class getAssetClass() { - return Bookmark.class; - } - -// @Override -// protected Asset createAsset(final FormSectionEvent event) -// throws FormProcessException { -// -// Objects.requireNonNull(event); -// -// final PageState state = event.getPageState(); -// -// final Bookmark bookmark = new Bookmark(); -// -// updateData(bookmark, state); -// -// return bookmark; -// } -// protected void updateData(final Bookmark bookmark, -// final PageState state) { -// bookmark -// .getDescription() -// .addValue(getSelectedLocale(state), -// (String) description.getValue(state)); -// -// bookmark.setUrl((String) url.getValue(state)); -// } -// -// -// @Override -// protected void updateAsset(final Asset asset, -// final FormSectionEvent event) -// throws FormProcessException { -// -// Objects.requireNonNull(asset); -// Objects.requireNonNull(event); -// -// final PageState state = event.getPageState(); -// -// if (!(asset instanceof Bookmark)) { -// throw new IllegalArgumentException(String.format( -// "Provided asset is not an instance of class (or sub class of) " -// + "'%s' but is an instance of class '%s'", -// Bookmark.class.getName(), -// asset.getClass().getName())); -// } -// -// final Bookmark bookmark = (Bookmark) asset; -// -// updateData(bookmark, state); -// } - @Override - protected Map collectData(final FormSectionEvent event) - throws FormProcessException { - - return Collections.emptyMap(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/BookmarkFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/BookmarkFormController.java deleted file mode 100644 index 9e5ff7ac3..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/BookmarkFormController.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.cms.ui.assets.IsControllerForAssetType; - -import org.librecms.assets.Bookmark; - -import javax.enterprise.context.RequestScoped; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -@IsControllerForAssetType(Bookmark.class) -public class BookmarkFormController - extends AbstractBookmarkFormController { - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalAudioAssetForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalAudioAssetForm.java deleted file mode 100644 index 25f931406..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalAudioAssetForm.java +++ /dev/null @@ -1,104 +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.assets.forms; - -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.cms.ui.assets.AssetPane; -import com.arsdigita.cms.ui.assets.AssetSearchWidget; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.librecms.CmsConstants; -import org.librecms.assets.ExternalAudioAsset; -import org.librecms.assets.LegalMetadata; - -import java.util.HashMap; -import java.util.Map; - -/** - * - * @author Jens Pelzetter - * @author Yannick Bülter - */ -public class ExternalAudioAssetForm - extends AbstractBookmarkForm { - - private AssetSearchWidget assetSearchWidget; - - public ExternalAudioAssetForm(final AssetPane assetPane) { - super(assetPane); - } - - @Override - public void addWidgets() { - super.addWidgets(); - - add(new Label(new GlobalizedMessage( - "cms.ui.assets.external_audio_asset.legal_metadata.label", - CmsConstants.CMS_BUNDLE))); - assetSearchWidget = new AssetSearchWidget("legal-metadata", - LegalMetadata.class); - add(assetSearchWidget); - } - - @Override - protected void initForm(final PageState state, - final Map data) { - - super.initForm(state, data); - - final Long selectedAssetId = getSelectedAssetId(state); - - if (selectedAssetId != null) { - - if (data.containsKey( - ExternalAudioAssetFormController.LEGAL_METADATA_ID)) { - - final long legalMetadataId = (long) data - .get(ExternalAudioAssetFormController.LEGAL_METADATA_ID); - - assetSearchWidget.setValue(state, legalMetadataId); - } - } - } - - @Override - protected Class getAssetClass() { - return ExternalAudioAsset.class; - } - - @Override - protected Map collectData(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - final Map data = new HashMap<>(); - if (assetSearchWidget.getValue(state) != null) { - - data.put(ExternalAudioAssetFormController.LEGAL_METADATA_ID, - assetSearchWidget.getValue(state)); - } - - return data; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalAudioAssetFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalAudioAssetFormController.java deleted file mode 100644 index 35efe05df..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalAudioAssetFormController.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.cms.ui.assets.IsControllerForAssetType; - -import org.librecms.assets.ExternalAudioAsset; -import org.librecms.assets.LegalMetadata; -import org.librecms.contentsection.AssetRepository; - -import java.util.Locale; -import java.util.Map; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -@IsControllerForAssetType(ExternalAudioAsset.class) -public class ExternalAudioAssetFormController - extends AbstractBookmarkFormController { - - protected static final String LEGAL_METADATA_ID = "legalMetadataId"; - - @Inject - private AssetRepository assetRepository; - - @Override - protected Map getAssetData(final ExternalAudioAsset asset, - final Locale selectedLocale) { - - final Map data = super.getAssetData(asset, - selectedLocale); - - final LegalMetadata legalMetadata = asset.getLegalMetadata(); - if (legalMetadata != null) { - data.put(LEGAL_METADATA_ID, legalMetadata.getObjectId()); - } - - return data; - } - - @Override - public void updateAssetProperties(final ExternalAudioAsset asset, - final Locale selectedLocale, - final Map data) { - - super.updateAssetProperties(asset, selectedLocale, data); - - if (data.containsKey(LEGAL_METADATA_ID)) { - - final long legalMetadataId = (long) data.get(LEGAL_METADATA_ID); - final LegalMetadata legalMetadata = assetRepository - .findById(legalMetadataId, LegalMetadata.class) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No LegalMetadata with ID %d found.", legalMetadataId))); - - asset.setLegalMetadata(legalMetadata); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalVideoAssetForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalVideoAssetForm.java deleted file mode 100644 index d0760b9ad..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalVideoAssetForm.java +++ /dev/null @@ -1,100 +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.assets.forms; - -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.cms.ui.assets.AssetPane; -import com.arsdigita.cms.ui.assets.AssetSearchWidget; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.librecms.CmsConstants; - -import org.librecms.assets.ExternalVideoAsset; -import org.librecms.assets.LegalMetadata; - -import java.util.HashMap; -import java.util.Map; - -/** - * - * @author Jens Pelzetter - */ -public class ExternalVideoAssetForm - extends AbstractBookmarkForm { - - private AssetSearchWidget assetSearchWidget; - - public ExternalVideoAssetForm(final AssetPane assetPane) { - super(assetPane); - } - - @Override - public void addWidgets() { - super.addWidgets(); - - add(new Label(new GlobalizedMessage( - "cms.ui.assets.external_video_asset.legal_metadata.label", - CmsConstants.CMS_BUNDLE))); - assetSearchWidget = new AssetSearchWidget("legal-metadata", - LegalMetadata.class); - add(assetSearchWidget); - } - - @Override - protected void initForm(final PageState state, - final Map data) { - - super.initForm(state, data); - - final Long selectedAssetId = getSelectedAssetId(state); - if (selectedAssetId != null) { - - if (data.containsKey( - ExternalVideoAssetFormController.LEGAL_METADATA_ID)) { - assetSearchWidget.setValue( - state, - data.get(ExternalVideoAssetFormController.LEGAL_METADATA_ID)); - } - } - } - - @Override - protected Class getAssetClass() { - return ExternalVideoAsset.class; - } - - @Override - protected Map collectData(final FormSectionEvent event) - throws FormProcessException { - - final Map data = new HashMap<>(); - final PageState state = event.getPageState(); - - if (assetSearchWidget.getValue(state) != null) { - data.put(ExternalAudioAssetFormController.LEGAL_METADATA_ID, - assetSearchWidget.getValue(state)); - } - - return data; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalVideoAssetFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalVideoAssetFormController.java deleted file mode 100644 index bd2cc2c8a..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ExternalVideoAssetFormController.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.cms.ui.assets.IsControllerForAssetType; - -import org.librecms.assets.ExternalVideoAsset; -import org.librecms.assets.LegalMetadata; -import org.librecms.contentsection.AssetRepository; - -import java.util.Locale; -import java.util.Map; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.transaction.Transactional; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -@IsControllerForAssetType(ExternalVideoAsset.class) -public class ExternalVideoAssetFormController - extends AbstractBookmarkFormController { - - protected static final String LEGAL_METADATA_ID = "legalMetadataId"; - - @Inject - private AssetRepository assetRepository; - - @Transactional(Transactional.TxType.REQUIRED) - @Override - protected Map getAssetData(final ExternalVideoAsset asset, - final Locale selectedLocale) { - - final Map data = super.getAssetData(asset, - selectedLocale); - if (asset.getLegalMetadata() != null) { - - data.put(LEGAL_METADATA_ID, asset.getLegalMetadata().getObjectId()); - } - - return data; - } - - @Override - public void updateAssetProperties(final ExternalVideoAsset asset, - final Locale selectedLocale, - final Map data) { - - super.updateAssetProperties(asset, selectedLocale, data); - - if (data.containsKey(LEGAL_METADATA_ID)) { - - final long legalMetadataId = (long) data.get(LEGAL_METADATA_ID); - - final LegalMetadata legalMetadata = assetRepository - .findById(legalMetadataId, LegalMetadata.class) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No LegalMetadata with ID %d found.", legalMetadataId))); - - asset.setLegalMetadata(legalMetadata); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/FileAssetForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/FileAssetForm.java deleted file mode 100644 index bc01566bb..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/FileAssetForm.java +++ /dev/null @@ -1,40 +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.assets.forms; - -import com.arsdigita.cms.ui.assets.AssetPane; - -import org.librecms.assets.FileAsset; - -/** - * - * @author Jens Pelzetter - */ -public class FileAssetForm extends AbstractBinaryAssetForm { - - public FileAssetForm(final AssetPane assetPane) { - super(assetPane); - } - - @Override - protected Class getAssetClass() { - return FileAsset.class; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/FileAssetFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/FileAssetFormController.java deleted file mode 100644 index 4e7e6ac52..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/FileAssetFormController.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.cms.ui.assets.IsControllerForAssetType; - -import org.librecms.assets.FileAsset; - -import javax.enterprise.context.RequestScoped; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -@IsControllerForAssetType(FileAsset.class) -public class FileAssetFormController extends AbstractBinaryAssetFormController { - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ImageForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ImageForm.java deleted file mode 100644 index 2ff95c29f..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ImageForm.java +++ /dev/null @@ -1,133 +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.assets.forms; - -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.cms.ui.assets.AssetPane; -import com.arsdigita.cms.ui.assets.AssetSearchWidget; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; -import org.librecms.assets.Image; -import org.librecms.assets.LegalMetadata; -import org.librecms.contentsection.Asset; -import org.librecms.contentsection.AssetRepository; - -import java.util.Map; - -/** - * - * @author Yannick Bülter - * @author Jens Pelzetter - */ -public class ImageForm extends AbstractBinaryAssetForm { - - private TextField width; - private TextField height; - private AssetSearchWidget assetSearchWidget; - - public ImageForm(final AssetPane assetPane) { - super(assetPane); - } - - @Override - protected void addWidgets() { - - super.addWidgets(); - - width = new TextField("width-text"); - height = new TextField("height-text"); - assetSearchWidget = new AssetSearchWidget("legal-metadata", - LegalMetadata.class); - - add(new Label(new GlobalizedMessage( - "cms.ui.assets.image.width.label", - CmsConstants.CMS_BUNDLE - ))); - add(width); - - add(new Label(new GlobalizedMessage( - "cms.ui.assets.image.height.label", - CmsConstants.CMS_BUNDLE - ))); - add(height); - - add(new Label(new GlobalizedMessage( - "cms.ui.assets.image.legal_metadata.label", - CmsConstants.CMS_BUNDLE - ))); - add(assetSearchWidget); - } - - @Override - protected void initForm(final PageState state, - final Map data) { - - super.initForm(state, data); - - if (getSelectedAssetId(state) != null) { - - if (data.containsKey(ImageFormController.WIDTH)) { - final long widthValue = (long) data - .get(ImageFormController.WIDTH); - width.setValue(state, Long.toString(widthValue)); - } - if (data.containsKey(ImageFormController.HEIGHT)) { - final long heightValue = (long) data - .get(ImageFormController.HEIGHT); - height.setValue(state, Long.toString(heightValue)); - } - - if (data.containsKey(ImageFormController.LEGAL_METADATA_ID)) { - assetSearchWidget - .setValue(state, - data.get(ImageFormController.LEGAL_METADATA_ID)); - } - } - } - - @Override - protected Class getAssetClass() { - return Image.class; - } - - @Override - protected Map collectData(final FormSectionEvent event) - throws FormProcessException { - - final Map data = super.collectData(event); - final PageState state = event.getPageState(); - - data.put(ImageFormController.WIDTH, width.getValue(state)); - data.put(ImageFormController.HEIGHT, height.getValue(state)); - - if (assetSearchWidget.getValue(state) != null) { - data.put(ImageFormController.LEGAL_METADATA_ID, - assetSearchWidget.getValue(state)); - } - - return data; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ImageFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ImageFormController.java deleted file mode 100644 index 7bf33e469..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/ImageFormController.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.cms.ui.assets.IsControllerForAssetType; - -import org.librecms.assets.Image; -import org.librecms.assets.LegalMetadata; -import org.librecms.contentsection.AssetRepository; - -import java.util.Locale; -import java.util.Map; - -import javax.enterprise.context.RequestScoped; - -import javax.inject.Inject; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -@IsControllerForAssetType(Image.class) -public class ImageFormController - extends AbstractBinaryAssetFormController { - - protected static final String LEGAL_METADATA_ID = "legalMetadataId"; - protected static final String HEIGHT = "height"; - protected static final String WIDTH = "width"; - - @Inject - private AssetRepository assetRepository; - - @Override - protected Map getAssetData(final Image asset, - final Locale selectedLocale) { - - final Map data = super.getAssetData(asset, - selectedLocale); - - data.put(WIDTH, asset.getWidth()); - data.put(HEIGHT, asset.getHeight()); - - if (asset.getLegalMetadata() != null) { - data.put(LEGAL_METADATA_ID, - asset.getLegalMetadata().getObjectId()); - } - - return data; - } - - @Override - public void updateAssetProperties(final Image asset, - final Locale selectedLocale, - final Map data) { - - super.updateAssetProperties(asset, selectedLocale, data); - - if (data.containsKey(WIDTH)) { - asset.setWidth((long) data.get(WIDTH)); - } - - if (data.containsKey(HEIGHT)) { - asset.setHeight((long) data.get(HEIGHT)); - } - - if (data.containsKey(LEGAL_METADATA_ID)) { - final long legalMetadataId = (long) data.get(LEGAL_METADATA_ID); - - final LegalMetadata legalMetadata = assetRepository - .findById(legalMetadataId, LegalMetadata.class) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No LegalMetadata with ID %d found.", legalMetadataId))); - - asset.setLegalMetadata(legalMetadata); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/LegalMetadataForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/LegalMetadataForm.java deleted file mode 100644 index 72933c1e4..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/LegalMetadataForm.java +++ /dev/null @@ -1,143 +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.assets.forms; - -import com.arsdigita.bebop.BoxPanel; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.TextArea; -import com.arsdigita.cms.ui.assets.AbstractAssetForm; -import com.arsdigita.cms.ui.assets.AssetPane; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.librecms.CmsConstants; -import org.librecms.assets.LegalMetadata; - -import java.util.HashMap; -import java.util.Map; - -/** - * - * @author Jens Pelzetter - */ -public class LegalMetadataForm extends AbstractAssetForm { - - private TextArea rightsHolder; - private TextArea rights; - private TextArea publisher; - private TextArea creator; - - public LegalMetadataForm(final AssetPane assetPane) { - super(assetPane); - } - - @Override - protected void addWidgets() { - - final BoxPanel panel = new BoxPanel(BoxPanel.VERTICAL); - - panel.add(new Label(new GlobalizedMessage( - "cms.ui.assets.legalmetadata.rightsholder", - CmsConstants.CMS_BUNDLE))); - rightsHolder = new TextArea("legalmetadata-rightsholder"); - panel.add(rightsHolder); - - panel.add(new Label(new GlobalizedMessage( - "cms.ui.assets.legalmetadata.rights", - CmsConstants.CMS_BUNDLE))); - rights = new TextArea("legalmetadata-rights"); - panel.add(rights); - - panel.add(new Label(new GlobalizedMessage( - "cms.ui.assets.legalmetadata.publisher", - CmsConstants.CMS_BUNDLE))); - publisher = new TextArea("legalmetadata-rights"); - panel.add(publisher); - - panel.add(new Label(new GlobalizedMessage( - "cms.ui.assets.legalmetadata.creator", - CmsConstants.CMS_BUNDLE))); - creator = new TextArea("legalmetadata-creator"); - panel.add(creator); - - add(panel); - } - - @Override - protected void initForm(final PageState state, - final Map data) { - - super.initForm(state, data); - - if (getSelectedAssetId(state) != null) { - - rightsHolder.setValue( - state, - data.get(LegalMetadataFormController.RIGHTS_HOLDER)); - rights.setValue(state, - data.get(LegalMetadataFormController.RIGHTS)); - publisher.setValue(state, - data.get(LegalMetadataFormController.PUBLISHER)); - creator.setValue(state, - data.get(LegalMetadataFormController.CREATOR)); - } - } - - @Override - protected void showLocale(final PageState state) { - - final Long selectedAssetId = getSelectedAssetId(state); - - if (selectedAssetId != null) { - - final Map data = getController() - .getAssetData(selectedAssetId, - LegalMetadata.class, - getSelectedLocale(state)); - - rights.setValue(state, - data.get(LegalMetadataFormController.RIGHTS)); - } - } - - @Override - protected Class getAssetClass() { - return LegalMetadata.class; - } - - @Override - protected Map collectData(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - final Map data = new HashMap<>(); - - data.put(LegalMetadataFormController.CREATOR, creator.getValue(state)); - data.put(LegalMetadataFormController.PUBLISHER, - publisher.getValue(state)); - data.put(LegalMetadataFormController.RIGHTS, - rights.getValue(state)); - data.put(LegalMetadataFormController.RIGHTS_HOLDER, - rightsHolder.getValue(state)); - - return data; - } -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/LegalMetadataFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/LegalMetadataFormController.java deleted file mode 100644 index 402a19fc7..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/LegalMetadataFormController.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.cms.ui.assets.AbstractAssetFormController; -import com.arsdigita.cms.ui.assets.IsControllerForAssetType; - -import org.librecms.assets.LegalMetadata; - -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import javax.enterprise.context.RequestScoped; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -@IsControllerForAssetType(LegalMetadata.class) -public class LegalMetadataFormController - extends AbstractAssetFormController { - - protected static final String CONTRIBUTORS = "contributors"; - protected static final String CREATOR = "creator"; - protected static final String PUBLISHER = "publisher"; - protected static final String RIGHTS = "rights"; - protected static final String RIGHTS_HOLDER = "rightsHolder"; - - @Override - protected Map getAssetData(final LegalMetadata asset, - final Locale selectedLocale) { - - final Map data = new HashMap<>(); - - data.put(RIGHTS_HOLDER, asset.getRightsHolder()); - data.put(RIGHTS, asset.getRights().getValue(selectedLocale)); - data.put(PUBLISHER, asset.getPublisher()); - data.put(CREATOR, asset.getCreator()); - data.put(CONTRIBUTORS, asset.getContributors()); - - return data; - } - - @Override - public void updateAssetProperties(final LegalMetadata asset, - final Locale selectedLocale, - final Map data) { - - if (data.containsKey(RIGHTS_HOLDER)) { - asset.setRightsHolder((String) data.get(RIGHTS_HOLDER)); - } - - if (data.containsKey(RIGHTS)) { - asset.getRights().putValue(selectedLocale, - (String) data.get(RIGHTS)); - } - - if (data.containsKey(PUBLISHER)) { - asset.setPublisher((String) data.get(PUBLISHER)); - } - - if (data.containsKey(CREATOR)) { - asset.setCreator((String) data.get(CREATOR)); - } - - if (data.containsKey(CONTRIBUTORS)) { - @SuppressWarnings("unchecked") - final List contributors = (List) data - .get(CONTRIBUTORS); - asset.setContributors(contributors); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/OrganizationForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/OrganizationForm.java deleted file mode 100644 index f76a33eb7..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/OrganizationForm.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.cms.ui.assets.AssetPane; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.librecms.CmsConstants; -import org.librecms.assets.Organization; - -import java.util.HashMap; -import java.util.Map; - -/** - * - * @author Jens Pelzetter - */ -public class OrganizationForm extends AbstractContactableEntityForm { - - private TextField organizationName; - - public OrganizationForm(final AssetPane assetPane) { - - super(assetPane); - } - - @Override - public void initForm(final PageState state, - final Map data) { - - super.initForm(state, data); - - if (getSelectedAssetId(state) != null) { - - organizationName.setValue( - state, - data.get(OrganizationFormController.ORGANIZATION_NAME)); - } - } - - @Override - protected void addPropertyWidgets() { - - add(new Label( - new GlobalizedMessage("cms.ui.assets.organization.name", - CmsConstants.CMS_BUNDLE))); - organizationName = new TextField("organization-name"); - add(organizationName); - } - - @Override - protected Class getAssetClass() { - - return Organization.class; - } - - @Override - protected void showLocale(final PageState state) { - - // Organization has no localizable fields. - } - - @Override - protected Map collectData(final FormSectionEvent event) { - - final PageState state = event.getPageState(); - - final Map data = super.collectData(event); - data.put(OrganizationFormController.ORGANIZATION_NAME, - organizationName.getValue(state)); - - return data; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/OrganizationFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/OrganizationFormController.java deleted file mode 100644 index 832437182..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/OrganizationFormController.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.cms.ui.assets.IsControllerForAssetType; - -import org.librecms.assets.Organization; - -import java.util.Locale; -import java.util.Map; - -import javax.enterprise.context.RequestScoped; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -@IsControllerForAssetType(Organization.class) -public class OrganizationFormController - extends AbstractContactableEntityFormController { - - protected static final String ORGANIZATION_NAME = "organizationName"; - - @Override - protected Map getAssetData(final Organization asset, - final Locale selectedLocale) { - - final Map data = super.getAssetData(asset, - selectedLocale); - data.put(ORGANIZATION_NAME, asset.getName()); - - return data; - } - - @Override - public void updateAssetProperties(final Organization asset, - final Locale selectedLocale, - final Map data) { - - super.updateAssetProperties(asset, selectedLocale, data); - - if (data.containsKey(ORGANIZATION_NAME)) { - final String organizationName = (String) data.get(ORGANIZATION_NAME); - asset.setName(organizationName); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/PersonForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/PersonForm.java deleted file mode 100644 index 1d928b84e..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/PersonForm.java +++ /dev/null @@ -1,323 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.Date; -import com.arsdigita.bebop.form.Submit; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.bebop.table.TableColumnModel; -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.bebop.table.TableModelBuilder; -import com.arsdigita.cms.ui.assets.AssetPane; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.util.LockableImpl; - -import org.librecms.assets.Person; - -import java.time.LocalDate; -import java.time.ZoneId; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Objects; - -import static org.librecms.CmsConstants.*; - -/** - * - * @author Jens Pelzetter - */ -public class PersonForm extends AbstractContactableEntityForm { - - private TextField surnameField; - - private TextField givenNameField; - - private TextField prefixField; - - private TextField suffixField; - - private Submit addPersonNameButton; - - private Date birthdateField; - - public PersonForm(final AssetPane assetPane) { - super(assetPane); - } - - @Override - protected void addPropertyWidgets() { - - final Label surnameLabel = new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.person.surname", - CMS_BUNDLE)); - surnameField = new TextField("surname"); - add(surnameLabel); - add(surnameField); - - final Label givenNameLabel = new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.person.given_name", - CMS_BUNDLE)); - givenNameField = new TextField("givenName"); - add(givenNameLabel); - add(givenNameField); - - final Label prefixLabel = new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.person.prefix", - CMS_BUNDLE - )); - prefixField = new TextField("prefix"); - add(prefixLabel); - add(prefixField); - - final Label suffixLabel = new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.person.suffix", - CMS_BUNDLE - )); - suffixField = new TextField("suffix"); - add(suffixLabel); - add(suffixField); - - add(buildPersonNamesTable()); - - addPersonNameButton = new Submit(new GlobalizedMessage( - "cms.ui.authoring.assets.person.add_name", - CMS_BUNDLE)); - add(addPersonNameButton); - - final Label birthdateLabel = new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.person.birthdate", - CMS_BUNDLE)); - add(birthdateLabel); - birthdateField = new Date("birthdate"); - final LocalDate today = LocalDate.now(ZoneId.systemDefault()); - birthdateField.setYearRange(1930, today.getYear()); - add(birthdateField); - } - - @Override - protected Class getAssetClass() { - return Person.class; - } - - @Override - protected void showLocale(final PageState state) { - - // Nothing - } - - @Override - protected Map collectData(final FormSectionEvent event) { - - final PageState state = event.getPageState(); - - final Map data = new HashMap<>(); - - data.put(PersonFormController.SURNAME, surnameField.getValue(state)); - data.put(PersonFormController.GIVENNAME, - givenNameField.getValue(state)); - data.put(PersonFormController.PREFIX, prefixField.getValue(state)); - data.put(PersonFormController.SUFFIX, suffixField.getValue(state)); - - data.put(PersonFormController.BIRTHDATE, - birthdateField.getValue(state)); - - return data; - } - - @Override - public void initForm(final PageState state, - final Map data) { - - super.initForm(state, data); - - if (data.containsKey(PersonFormController.SURNAME)) { - surnameField.setValue(state, - data.get(PersonFormController.SURNAME)); - } - - if (data.containsKey(PersonFormController.GIVENNAME)) { - givenNameField.setValue(state, - data.get(PersonFormController.GIVENNAME)); - } - - if (data.containsKey(PersonFormController.PREFIX)) { - prefixField.setValue(state, data.get(PersonFormController.PREFIX)); - } - - if (data.containsKey(PersonFormController.SUFFIX)) { - suffixField.setValue(state, data.get(PersonFormController.SUFFIX)); - } - - if (data.containsKey(PersonFormController.BIRTHDATE)) { - birthdateField.setValue(state, - data.get(PersonFormController.BIRTHDATE)); - } - } - - @Override - public void process(final FormSectionEvent event) throws - FormProcessException { - - if (addPersonNameButton.equals(event.getSource())) { - - final PersonFormController controller - = (PersonFormController) getController(); - controller.addPersonName(getSelectedAssetId(event.getPageState())); - - } else { - super.process(event); - } - } - - private Table buildPersonNamesTable() { - - final Table table = new Table() { - - @Override - public boolean isVisible(final PageState state) { - return getSelectedAssetId(state) != null; - } - }; - - final TableColumnModel columnModel = table.getColumnModel(); - columnModel.add(new TableColumn( - 0, - new Label( - new GlobalizedMessage( - "cms.ui.authoring.assets.person.surname", - CMS_BUNDLE - ) - ) - )); - columnModel.add(new TableColumn( - 1, - new Label( - new GlobalizedMessage( - "cms.ui.authoring.assets.person.givenName", - CMS_BUNDLE - ) - ) - )); - columnModel.add(new TableColumn( - 2, - new Label( - new GlobalizedMessage( - "cms.ui.authoring.assets.person.prefix", - CMS_BUNDLE - ) - ) - )); - columnModel.add(new TableColumn( - 3, - new Label( - new GlobalizedMessage( - "cms.ui.authoring.assets.person.suffix", - CMS_BUNDLE - ) - ) - )); - - table.setModelBuilder(new PersonNamesTableModelBuilder()); - - table.setEmptyView(new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.person.names.none"))); - - return table; - } - - private class PersonNamesTableModelBuilder - extends LockableImpl - implements TableModelBuilder { - - @Override - public TableModel makeModel(final Table table, final PageState state) { - - final Long selectedPersonId = getSelectedAssetId(state); - if (selectedPersonId == null) { - throw new RuntimeException("No asset selected."); - } - - final PersonFormController controller - = (PersonFormController) getController(); - final List personNames = controller - .getPersonNames(selectedPersonId); - - return new PersonNamesTableModel(personNames); - } - - } - - private class PersonNamesTableModel implements TableModel { - - private final Iterator personNames; - - private String[] currentPersonName; - - private int row; - - public PersonNamesTableModel(final List personNames) { - - this.personNames = Objects - .requireNonNull(personNames, - "Can't create PersonNamesTableModel without a " - + "list of person names.") - .iterator(); - } - - @Override - public int getColumnCount() { - return 4; - } - - @Override - public boolean nextRow() { - - if (personNames.hasNext()) { - currentPersonName = personNames.next(); - row++; - return true; - } else { - return false; - } - } - - @Override - public Object getElementAt(final int columnIndex) { - - return currentPersonName[columnIndex]; - - } - - @Override - public Object getKeyAt(final int columnIndex) { - - return row; - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/PersonFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/PersonFormController.java deleted file mode 100644 index 07ac21250..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/PersonFormController.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.cms.ui.assets.IsControllerForAssetType; - -import org.librecms.assets.Person; -import org.librecms.assets.PersonManager; -import org.librecms.assets.PersonName; -import org.librecms.assets.PersonRepository; - -import java.time.Instant; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.stream.Collectors; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.transaction.Transactional; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -@IsControllerForAssetType(Person.class) -public class PersonFormController - extends AbstractContactableEntityFormController { - - protected static final String SUFFIX = "suffix"; - - protected static final String PREFIX = "prefix"; - - protected static final String GIVENNAME = "givenName"; - - protected static final String SURNAME = "surname"; - - protected static final String BIRTHDATE = "birthdate"; - - protected static final String PERSON_NAMES = "personNames"; - - protected static final int SURNAME_INDEX = 0; - - protected static final int GIVENNAME_INDEX = 1; - - protected static final int PREFIX_INDEX = 2; - - protected static final int SUFFIX_INDEX = 3; - - @Inject - private PersonRepository personRepository; - - @Inject - private PersonManager personManager; - - @Transactional - @Override - protected Map getAssetData(final Person asset, - final Locale selectedLocale) { - - final Map data = super.getAssetData(asset, - selectedLocale); - - final PersonName personName = asset.getPersonName(); - data.put(SURNAME, personName.getSurname()); - data.put(GIVENNAME, personName.getGivenName()); - data.put(PREFIX, personName.getPrefix()); - data.put(SUFFIX, personName.getSuffix()); - - final List names = asset - .getPersonNames() - .subList(0, asset.getPersonNames().size() - 1) - .stream() - .map(this::convertPersonName) - .collect(Collectors.toList()); - data.put(PERSON_NAMES, names); - - final LocalDate birthdate = asset.getBirthdate(); - if (birthdate != null) { - final Instant instant = birthdate - .atStartOfDay() - .atZone(ZoneId.systemDefault()) - .toInstant(); - final Date birthdateValue = Date.from(instant); - data.put(BIRTHDATE, birthdateValue); - } - - return data; - } - - @Transactional(Transactional.TxType.REQUIRED) - protected List getPersonNames(final Long personId) { - - final Person person = personRepository - .findById(personId) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No Person with ID %d found.", personId))); - - return person - .getPersonNames() - .subList(0, person.getPersonNames().size() - 1) - .stream() - .map(this::convertPersonName) - .collect(Collectors.toList()); - } - - private String[] convertPersonName(final PersonName name) { - - final String[] result = new String[4]; - - result[SURNAME_INDEX] = name.getSurname(); - result[GIVENNAME_INDEX] = name.getGivenName(); - result[PREFIX_INDEX] = name.getPrefix(); - result[SUFFIX_INDEX] = name.getSuffix(); - - return result; - } - - @Override - public void updateAssetProperties(final Person asset, - final Locale selectedLocale, - final Map data) { - - super.updateAssetProperties(asset, selectedLocale, data); - - if (data.containsKey(BIRTHDATE)) { - - final Date birthdateValue = (Date) data.get(BIRTHDATE); - final Instant instant = birthdateValue.toInstant(); - final LocalDate birthdate = LocalDateTime - .ofInstant(instant, ZoneId.systemDefault()) - .toLocalDate(); - - asset.setBirthdate(birthdate); - } - - final String surname = (String) data.get(SURNAME); - final String givenName = (String) data.get(GIVENNAME); - final String prefix = (String) data.get(PREFIX); - final String suffix = (String) data.get(SUFFIX); - - if (asset.getPersonName() == null) { - final PersonName personName = new PersonName(); - personName.setGivenName(givenName); - personName.setSuffix(suffix); - personName.setPrefix(prefix); - personName.setSurname(surname); - personManager.addPersonName(asset, personName); - } - } - - @Transactional(Transactional.TxType.REQUIRED) - public void addPersonName(final long personId) { - final Person person = personRepository - .findById(personId) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No Person with ID %d found.", personId))); - - personManager.addPersonName(person, new PersonName()); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/PostalAddressForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/PostalAddressForm.java deleted file mode 100644 index 8e0f5fa34..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/PostalAddressForm.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.TextArea; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.cms.ui.assets.AbstractAssetForm; -import com.arsdigita.cms.ui.assets.AssetPane; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.librecms.assets.PostalAddress; - -import java.util.HashMap; -import java.util.Map; - -import static org.librecms.CmsConstants.*; - -/** - * - * @author Jens Pelzetter - */ -public class PostalAddressForm extends AbstractAssetForm { - - private TextArea addressArea; - private TextField postalCodeField; - private TextField cityField; - private TextField stateField; - private TextField isoCountryCodeField; - - public PostalAddressForm(final AssetPane assetPane) { - super(assetPane); - } - - @Override - protected void addWidgets() { - - super.addWidgets(); - - addressArea = new TextArea("address"); - addressArea.setLabel(new GlobalizedMessage( - "cms.ui.authoring.assets.postaladdress.address", CMS_BUNDLE)); - addressArea.setCols(80); - addressArea.setRows(10); - add(addressArea); - - postalCodeField = new TextField("postalCode"); - postalCodeField.setLabel(new GlobalizedMessage( - "cms.ui.authoring.assets.postaladdress.postalcode", CMS_BUNDLE)); - add(postalCodeField); - - cityField = new TextField("city"); - cityField.setLabel(new GlobalizedMessage( - "cms.ui.authoring.assets.postaladdress.city", CMS_BUNDLE)); - add(cityField); - - stateField = new TextField("state"); - stateField.setLabel(new GlobalizedMessage( - "cms.ui.authoring.assets.postaladdress.state", CMS_BUNDLE)); - add(stateField); - } - - @Override - protected Class getAssetClass() { - return PostalAddress.class; - } - - @Override - protected void showLocale(final PageState state) { - // Nothing - } - - @Override - protected Map collectData(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - final Map data = new HashMap<>(); - - data.put(PostalAddressFormController.ADDRESS, - addressArea.getValue(state)); - data.put(PostalAddressFormController.CITY, - cityField.getValue(state)); - data.put(PostalAddressFormController.POSTAL_CODE, - postalCodeField.getValue(state)); - data.put(PostalAddressFormController.STATE, - stateField.getValue(state)); - - return data; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/PostalAddressFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/PostalAddressFormController.java deleted file mode 100644 index 1b0360f0f..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/PostalAddressFormController.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.cms.ui.assets.AbstractAssetFormController; -import com.arsdigita.cms.ui.assets.IsControllerForAssetType; - -import org.librecms.assets.PostalAddress; - -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -import javax.enterprise.context.RequestScoped; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -@IsControllerForAssetType(PostalAddress.class) -public class PostalAddressFormController - extends AbstractAssetFormController { - - protected static final String STATE = "state"; - protected static final String CITY = "city"; - protected static final String POSTAL_CODE = "postalCode"; - protected static final String ADDRESS = "address"; - - @Override - protected Map getAssetData(final PostalAddress asset, - final Locale selectedLocale) { - - final Map data = new HashMap<>(); - - data.put(ADDRESS, asset.getAddress()); - data.put(POSTAL_CODE, asset.getPostalCode()); - data.put(CITY, asset.getCity()); - data.put(STATE, asset.getState()); - - return data; - } - - @Override - public void updateAssetProperties(final PostalAddress asset, - final Locale selectedLocale, - final Map data) { - - if (data.containsKey(ADDRESS)) { - asset.setAddress((String) data.get(ADDRESS)); - } - - if (data.containsKey(POSTAL_CODE)) { - asset.setPostalCode((String) data.get(POSTAL_CODE)); - } - - if (data.containsKey(CITY)) { - asset.setCity((String) data.get(CITY)); - } - - if (data.containsKey(STATE)) { - asset.setState((String) data.get(STATE)); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/RelatedLinkForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/RelatedLinkForm.java deleted file mode 100644 index d589b4a58..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/RelatedLinkForm.java +++ /dev/null @@ -1,58 +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.assets.forms; - -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.cms.ui.assets.AbstractAssetForm; -import com.arsdigita.cms.ui.assets.AssetPane; - -import org.librecms.assets.RelatedLink; -import org.librecms.assets.SideNote; - -import java.util.Map; - -/** - * - * @author Jens Pelzetter - */ -public class RelatedLinkForm extends AbstractAssetForm{ - - public RelatedLinkForm(final AssetPane assetPane) { - super(assetPane); - } - - @Override - protected Class getAssetClass() { - return RelatedLink.class; - } - - @Override - protected void showLocale(final PageState state) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - protected Map collectData(final FormSectionEvent event) throws - FormProcessException { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/SideNoteForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/SideNoteForm.java deleted file mode 100644 index bc5849925..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/SideNoteForm.java +++ /dev/null @@ -1,102 +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.assets.forms; - -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.TextArea; -import com.arsdigita.cms.ui.assets.AbstractAssetForm; -import com.arsdigita.cms.ui.assets.AssetPane; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.librecms.CmsConstants; -import org.librecms.assets.SideNote; - -import java.util.HashMap; -import java.util.Map; - -/** - * - * @author Jens Pelzetter - */ -public class SideNoteForm extends AbstractAssetForm { - - private TextArea text; - - public SideNoteForm(final AssetPane assetPane) { - super(assetPane); - } - - @Override - protected void addWidgets() { - - add(new Label(new GlobalizedMessage("cms.ui.assets.sidenote.text", - CmsConstants.CMS_BUNDLE))); - text = new TextArea("sidenote-text"); - add(text); - } - - @Override - protected void initForm(final PageState state, - final Map data) { - - super.initForm(state, data); - - if (getSelectedAssetId(state) != null) { - - text.setValue(state, data.get(SideNoteFormController.TEXT)); - } - - } - - @Override - protected void showLocale(final PageState state) { - - if (getSelectedAssetId(state) != null) { - - final Long selectedAssetId = getSelectedAssetId(state); - final Map data = getController() - .getAssetData(selectedAssetId, - SideNote.class, - getSelectedLocale(state)); - - text.setValue(state, data.get(SideNoteFormController.TEXT)); - } - } - - @Override - protected Class getAssetClass() { - return SideNote.class; - } - - @Override - protected Map collectData(final FormSectionEvent event) - throws FormProcessException { - - final Map data = new HashMap<>(); - final PageState state = event.getPageState(); - - data.put(SideNoteFormController.TEXT, text.getValue(state)); - - return data; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/SideNoteFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/SideNoteFormController.java deleted file mode 100644 index 01ccd05dc..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/SideNoteFormController.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.cms.ui.assets.AbstractAssetFormController; -import com.arsdigita.cms.ui.assets.IsControllerForAssetType; - -import org.librecms.assets.SideNote; - -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; - -import javax.enterprise.context.RequestScoped; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -@IsControllerForAssetType(SideNote.class) -public class SideNoteFormController - extends AbstractAssetFormController { - - protected static final String TEXT = "text"; - - @Override - protected Map getAssetData(final SideNote asset, - final Locale selectedLocale) { - - final Map data = new HashMap<>(); - - data.put(TEXT, asset.getText().getValue(selectedLocale)); - - return data; - } - - @Override - public void updateAssetProperties(final SideNote asset, - final Locale selectedLocale, - final Map data) { - - if (data.containsKey(TEXT)) { - - final String value = (String) data.get(TEXT); - asset.getText().putValue(selectedLocale, value); - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/VideoForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/VideoForm.java deleted file mode 100644 index 32b320ab6..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/VideoForm.java +++ /dev/null @@ -1,130 +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.assets.forms; - -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.cms.ui.assets.AssetPane; -import com.arsdigita.cms.ui.assets.AssetSearchWidget; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.librecms.CmsConstants; -import org.librecms.assets.VideoAsset; -import org.librecms.assets.LegalMetadata; - -import java.util.Map; - -/** - * - * @author Yannick Bülter - * @author Jens Pelzetter - * - */ -public class VideoForm extends AbstractBinaryAssetForm { - - private TextField width; - private TextField height; - private AssetSearchWidget assetSearchWidget; - - public VideoForm(final AssetPane assetPane) { - super(assetPane); - } - - @Override - protected void addWidgets() { - - width = new TextField("width-text"); - height = new TextField("height-text"); - assetSearchWidget = new AssetSearchWidget("legal-metadata", - LegalMetadata.class); - - add(new Label(new GlobalizedMessage( - "cms.ui.assets.video.width.label", - CmsConstants.CMS_BUNDLE - ))); - add(width); - - add(new Label(new GlobalizedMessage( - "cms.ui.assets.video.height.label", - CmsConstants.CMS_BUNDLE - ))); - add(height); - - add(new Label(new GlobalizedMessage( - "cms.ui.assets.video.legal_metadata.label", - CmsConstants.CMS_BUNDLE - ))); - add(assetSearchWidget); - } - - @Override - protected void initForm(final PageState state, - final Map data) { - - super.initForm(state, data); - - if (getSelectedAssetId(state) != null) { - - final long widthValue = (long) data.get(VideoFormController.WIDTH); - final long heightValue = (long) data - .get(VideoFormController.HEIGHT); - - width.setValue(state, Long.toString(widthValue)); - height.setValue(state, Long.toString(heightValue)); - - if (data.containsKey(VideoFormController.LEGAL_METADATA_ID)) { - - assetSearchWidget.setValue( - state, - data.containsKey(VideoFormController.LEGAL_METADATA_ID)); - - } - } - } - - @Override - protected Class getAssetClass() { - return VideoAsset.class; - } - - @Override - protected Map collectData(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - final Map data = super.collectData(event); - - data.put(VideoFormController.WIDTH, width.getValue(state)); - data.put(VideoFormController.HEIGHT, height.getValue(state)); - - if (assetSearchWidget.getValue(state) != null) { - - data.put(VideoFormController.LEGAL_METADATA_ID, - assetSearchWidget.getValue(state)); - - } - - return data; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/VideoFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/VideoFormController.java deleted file mode 100644 index f2d4c6c7e..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/forms/VideoFormController.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2019 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.assets.forms; - -import com.arsdigita.cms.ui.assets.IsControllerForAssetType; - -import org.librecms.contentsection.AssetRepository; - -import java.util.Locale; -import java.util.Map; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; - -import org.librecms.assets.LegalMetadata; -import org.librecms.assets.VideoAsset; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -@IsControllerForAssetType(VideoAsset.class) -public class VideoFormController - extends AbstractBinaryAssetFormController { - - protected static final String LEGAL_METADATA_ID = "legalMetadataId"; - protected static final String HEIGHT = "height"; - protected static final String WIDTH = "width"; - - @Inject - private AssetRepository assetRepository; - - @Override - protected Map getAssetData(final VideoAsset asset, - final Locale selectedLocale) { - - final Map data = super.getAssetData(asset, - selectedLocale); - - data.put(WIDTH, asset.getWidth()); - data.put(HEIGHT, asset.getHeight()); - - if (asset.getLegalMetadata() != null) { - final long legalMetadataId = asset.getLegalMetadata().getObjectId(); - data.put(LEGAL_METADATA_ID, legalMetadataId); - } - - return data; - } - - @Override - public void updateAssetProperties(final VideoAsset asset, - final Locale selectedLocale, - final Map data) { - - super.updateAssetProperties(asset, selectedLocale, data); - - if (data.containsKey(WIDTH)) { - final long width = (long) data.get(WIDTH); - asset.setWidth(width); - } - - if (data.containsKey(HEIGHT)) { - final long height = (long) data.get(HEIGHT); - asset.setHeight(height); - } - - if (data.containsKey(LEGAL_METADATA_ID)) { - - final LegalMetadata legalMetadata = assetRepository - .findById((long) data.get(LEGAL_METADATA_ID), - LegalMetadata.class) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No LegalMetadata with ID %d found", - data.get(LEGAL_METADATA_ID) - ))); - asset.setLegalMetadata(legalMetadata); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/searchpage/AssetSearchPage.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/searchpage/AssetSearchPage.java deleted file mode 100644 index 2ce5e16df..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/searchpage/AssetSearchPage.java +++ /dev/null @@ -1,185 +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.assets.searchpage; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.Form; -import com.arsdigita.bebop.FormData; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.Link; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SimpleContainer; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.Text; -import com.arsdigita.bebop.event.FormInitListener; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.Submit; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.bebop.parameters.LongParameter; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.table.TableCellRenderer; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.bebop.table.TableColumnModel; -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.bebop.table.TableModelBuilder; -import com.arsdigita.cms.dispatcher.CMSPage; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.toolbox.ui.LayoutPanel; -import com.arsdigita.util.LockableImpl; -import java.util.List; -import org.libreccm.cdi.utils.CdiUtil; - -import org.librecms.CmsConstants; - -/** - * Page contains the widgets for selecting an asset. - * - * @author Jens Pelzetter - */ -public class AssetSearchPage extends CMSPage { - - private static final String QUERY_PARAM = "query"; - private static final String WIDGET_PARAM = "widget"; - private static final String ASSET_TYPE_PARAM = "assettype"; - - private static final int RESULTS_TABLE_COL_TITLE = 0; - private static final int RESULTS_TABLE_COL_PLACE = 1; - private static final int RESULTS_TABLE_COL_TYPE = 2; - - private final LongParameter contentSectionId; - - private TextField query; - - public AssetSearchPage() { - super(new Label(new GlobalizedMessage("cms.ui.assets.search_page.title", - CmsConstants.CMS_BUNDLE)), - new SimpleContainer()); - - addGlobalStateParam(new StringParameter(ASSET_TYPE_PARAM)); - addGlobalStateParam(new StringParameter(WIDGET_PARAM)); - addGlobalStateParam(new StringParameter(QUERY_PARAM)); - - contentSectionId = new LongParameter("content-section-id"); - - final LayoutPanel mainPanel = new LayoutPanel(); - - final Form queryForm = new Form("asset-search-page-query-form"); - queryForm.add(new Label(new GlobalizedMessage( - "cms.ui.assets.search_page.query", - CmsConstants.CMS_BUNDLE))); - query = new TextField("asset-search-page-query-form"); - queryForm.add(query); - final Submit querySubmit = new Submit(new GlobalizedMessage( - "cms.ui.assets.search_page.query.submit")); - queryForm.add(querySubmit); - - queryForm.addInitListener(new FormInitListener() { - - @Override - public void init(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - final FormData data = event.getFormData(); - - final String query = (String) data.get(QUERY_PARAM); - - } - - }); - - mainPanel.setLeft(queryForm); - - final Table resultsTable = new Table(); - resultsTable.setEmptyView( - new Label( - new GlobalizedMessage( - "cms.ui.assets.search_page.none", - CmsConstants.CMS_BUNDLE))); - resultsTable.setClassAttr("dataTable"); - - final TableColumnModel columnModel = resultsTable.getColumnModel(); - columnModel.add(new TableColumn( - RESULTS_TABLE_COL_TITLE, - new GlobalizedMessage( - "cms.ui.assets.search_page.results_table.title", - CmsConstants.CMS_BUNDLE))); - columnModel.add(new TableColumn( - RESULTS_TABLE_COL_PLACE, - new GlobalizedMessage( - "cms.ui.assets.search_page.results_table.place", - CmsConstants.CMS_BUNDLE))); - columnModel.add(new TableColumn( - RESULTS_TABLE_COL_TYPE, - new GlobalizedMessage( - "cms.ui.assets.search_page.results_table.type", - CmsConstants.CMS_BUNDLE))); - resultsTable.setModelBuilder(new ResultsTableModelBuilder()); - - mainPanel.setBody(resultsTable); - - } - - private class ResultsTableModelBuilder - extends LockableImpl - implements TableModelBuilder { - - @Override - public TableModel makeModel(final Table table, final PageState state) { - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final AssetSearchPageController controller = cdiUtil - .findBean(AssetSearchPageController.class); - - final List rows = controller - .findAssets((String) query.getValue(state)); - return new ResultsTableModel(rows); - } - - } - - private class TitleCellRenderer - extends LockableImpl - implements TableCellRenderer { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - - if (value == null) { - return new Text("???"); - } - - final Link link = new Link(new Text(value.toString()), ""); - - return link; - - - } - - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/searchpage/AssetSearchPageController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/searchpage/AssetSearchPageController.java deleted file mode 100644 index e62e8c967..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/searchpage/AssetSearchPageController.java +++ /dev/null @@ -1,85 +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.assets.searchpage; - -import java.util.List; -import java.util.ResourceBundle; -import java.util.stream.Collectors; -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.transaction.Transactional; -import org.libreccm.configuration.ConfigurationManager; -import org.libreccm.l10n.GlobalizationHelper; -import org.librecms.assets.AssetTypeInfo; -import org.librecms.assets.AssetTypesManager; -import org.librecms.contentsection.Asset; -import org.librecms.contentsection.AssetManager; -import org.librecms.contentsection.AssetRepository; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -class AssetSearchPageController { - - @Inject - private AssetRepository assetRepo; - - @Inject - private AssetTypesManager assetTypesManager; - - @Inject - private AssetManager assetManager; - - @Inject - private GlobalizationHelper globalizationHelper; - - @Transactional(Transactional.TxType.REQUIRED) - protected List findAssets(final String title) { - - final List assets = assetRepo.findByTitle(title); - - return assets - .stream() - .map(asset -> createRow(asset)) - .collect(Collectors.toList()); - - } - - private ResultsTableRow createRow(final Asset asset) { - final ResultsTableRow row = new ResultsTableRow(); - - row.setAssetUuid(asset.getUuid()); - row.setTitle(globalizationHelper - .getValueFromLocalizedString(asset.getTitle())); - - final AssetTypeInfo typeInfo = assetTypesManager - .getAssetTypeInfo(asset.getClass()); - final ResourceBundle bundle = ResourceBundle - .getBundle(typeInfo.getLabelBundle(), - globalizationHelper.getNegotiatedLocale()); - row.setType(bundle.getString(typeInfo.getLabelKey())); - - row.setPlace(assetManager.getAssetPath(asset)); - - return row; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/searchpage/ResultsTableModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/searchpage/ResultsTableModel.java deleted file mode 100644 index 85c84d05c..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/searchpage/ResultsTableModel.java +++ /dev/null @@ -1,76 +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.assets.searchpage; - -import com.arsdigita.bebop.table.TableModel; -import java.util.Iterator; -import java.util.List; - -/** - * - * @author Jens Pelzetter - */ -class ResultsTableModel implements TableModel { - - private static final int COL_TITLE = 0; - private static final int COL_PLACE = 1; - private static final int COL_TYPE = 2; - - private final Iterator iterator; - private ResultsTableRow currentRow; - - public ResultsTableModel(final List rows) { - iterator = rows.iterator(); - } - - @Override - public int getColumnCount() { - return 3; - } - - @Override - public boolean nextRow() { - if (iterator.hasNext()) { - currentRow = iterator.next(); - return true; - } else { - return false; - } - } - - @Override - public Object getElementAt(final int columnIndex) { - switch(columnIndex) { - case COL_TITLE: - return currentRow.getTitle(); - case COL_PLACE: - return currentRow.getPlace(); - case COL_TYPE: - return currentRow.getType(); - default: - throw new IllegalArgumentException("Illegal column index."); - } - } - - @Override - public Object getKeyAt(final int columnIndex) { - return currentRow.getAssetUuid(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/searchpage/ResultsTableRow.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/searchpage/ResultsTableRow.java deleted file mode 100644 index aaf2292d0..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/searchpage/ResultsTableRow.java +++ /dev/null @@ -1,64 +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.assets.searchpage; - -/** - * - * @author Jens Pelzetter - */ -class ResultsTableRow { - - private String assetUuid; - private String title; - private String place; - private String type; - - public String getAssetUuid() { - return assetUuid; - } - - public void setAssetUuid(final String assetUuid) { - this.assetUuid = assetUuid; - } - - public String getTitle() { - return title; - } - - public void setTitle(final String title) { - this.title = title; - } - - public String getPlace() { - return place; - } - - public void setPlace(final String place) { - this.place = place; - } - - public String getType() { - return type; - } - - public void setType(final String type) { - this.type = type; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/AbstractContentItemComponentForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/AbstractContentItemComponentForm.java deleted file mode 100644 index b5d5f4bbf..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/AbstractContentItemComponentForm.java +++ /dev/null @@ -1,97 +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.pagemodel; - -import com.arsdigita.bebop.FormData; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.ParameterSingleSelectionModel; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.ui.admin.pagemodels.AbstractComponentModelForm; -import com.arsdigita.ui.admin.pagemodels.PageModelsTab; - -import org.librecms.CmsConstants; -import org.librecms.pagemodel.ContentItemComponent; - -/** - * Basic form for all subclasses of {@link ContentItemComponent}. - * - * @param - * - * @author Jens Pelzetter - * - */ -public abstract class AbstractContentItemComponentForm - extends AbstractComponentModelForm { - - /** - * Constant for the name of the {@link #modeField}. - */ - private static final String ITEM_MODE = "itemMode"; - - /** - * Text field for {@link ContentItemComponent#mode}. - */ - private TextField modeField; - - public AbstractContentItemComponentForm( - final String name, - final PageModelsTab pageModelTab, - final ParameterSingleSelectionModel selectedModelId, - final ParameterSingleSelectionModel selectedComponentId) { - - super(name, pageModelTab, selectedModelId, selectedComponentId); - } - - @Override - protected void addWidgets() { - - modeField = new TextField(ITEM_MODE); - modeField.setLabel(new GlobalizedMessage( - "cms.ui.pagemodel.contentitem_component_form.mode.label", - CmsConstants.CMS_BUNDLE)); - add(modeField); - } - - @Override - public void updateComponentModel(final ContentItemComponent componentModel, - final PageState state, - final FormData data) { - - final String modeValue = data.getString(ITEM_MODE); - componentModel.setMode(modeValue); - } - - @Override - public void init(final FormSectionEvent event) - throws FormProcessException { - - super.init(event); - - final PageState state = event.getPageState(); - final ContentItemComponent component = getComponentModel(); - - if (getComponentModel() != null) { - modeField.setValue(state, component.getMode()); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/CategorizedItemComponentForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/CategorizedItemComponentForm.java deleted file mode 100644 index a48e89e32..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/CategorizedItemComponentForm.java +++ /dev/null @@ -1,50 +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.pagemodel; - -import com.arsdigita.bebop.ParameterSingleSelectionModel; -import com.arsdigita.ui.admin.pagemodels.PageModelsTab; - -import org.librecms.pagemodel.CategorizedItemComponent; - -/** - * Form for editing/creating a {@link CategorizedItemComponent}. - * - * @author Jens Pelzetter - */ -public class CategorizedItemComponentForm - extends AbstractContentItemComponentForm { - - public CategorizedItemComponentForm( - final PageModelsTab pageModelTab, - final ParameterSingleSelectionModel selectedModelId, - final ParameterSingleSelectionModel selectedComponentId) { - - super("CategorizedItemComponentForm", - pageModelTab, - selectedModelId, - selectedComponentId); - } - - @Override - public CategorizedItemComponent createComponentModel() { - return new CategorizedItemComponent(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/CategoryTreeComponentForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/CategoryTreeComponentForm.java deleted file mode 100644 index de7c52a12..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/CategoryTreeComponentForm.java +++ /dev/null @@ -1,111 +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.pagemodel; - -import com.arsdigita.bebop.FormData; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.ParameterSingleSelectionModel; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.CheckboxGroup; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.ui.admin.pagemodels.AbstractComponentModelForm; -import com.arsdigita.ui.admin.pagemodels.PageModelsTab; - -import org.librecms.CmsConstants; -import org.librecms.pagemodel.CategoryTreeComponent; - -/** - * Form for creating/editing a {@link CategoryTreeComponent}. - * - * @author Jens Pelzetter - */ -public class CategoryTreeComponentForm extends AbstractComponentModelForm { - - private final static String SHOW_FULL_TREE_BOX = "showFullTreeBox"; - private final static String SHOW_FULL_TREE = "showFullTree"; - - private CheckboxGroup showFullTreeCheckbox; - - public CategoryTreeComponentForm( - final PageModelsTab pageModelTab, - final ParameterSingleSelectionModel selectedModelId, - final ParameterSingleSelectionModel selectedComponentId) { - - super("CategoryTreeComponentForm", pageModelTab, selectedModelId, - selectedComponentId); - } - - @Override - protected void addWidgets() { - - showFullTreeCheckbox = new CheckboxGroup(SHOW_FULL_TREE_BOX); - showFullTreeCheckbox.addOption(new Option( - SHOW_FULL_TREE, - new Label(new GlobalizedMessage( - "cms.ui.pagemodel.category_tree_component_form.show_full_tree.label", - CmsConstants.CMS_BUNDLE)))); - add(showFullTreeCheckbox); - } - - @Override - protected CategoryTreeComponent createComponentModel() { - return new CategoryTreeComponent(); - } - - @Override - protected void updateComponentModel( - final CategoryTreeComponent componentModel, - final PageState state, - final FormData data) { - - final Object[] value = (Object[]) data.get(SHOW_FULL_TREE_BOX); - if (value != null - && value.length != 0 - && SHOW_FULL_TREE.equals(value[0])) { - - componentModel.setShowFullTree(true); - } else { - componentModel.setShowFullTree(false); - } - } - - @Override - public void init(final FormSectionEvent event) - throws FormProcessException { - - super.init(event); - - final PageState state = event.getPageState(); - - final CategoryTreeComponent component = getComponentModel(); - - final Object[] showFullTreeValue; - if (component != null && component.isShowFullTree()) { - showFullTreeValue = new Object[]{SHOW_FULL_TREE}; - } else { - showFullTreeValue = new Object[]{}; - } - - showFullTreeCheckbox.setValue(state, showFullTreeValue); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/FixedContentItemComponentForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/FixedContentItemComponentForm.java deleted file mode 100644 index a806129b7..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/FixedContentItemComponentForm.java +++ /dev/null @@ -1,123 +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.pagemodel; - -import com.arsdigita.bebop.FormData; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.ParameterSingleSelectionModel; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.cms.ui.assets.ItemSearchWidget; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.ui.admin.pagemodels.PageModelsTab; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.pagemodel.FixedContentItemComponent; - -/** - * Form for creating/editing a {@link FixedContentItemComponent}. - * - * @author Jens Pelzetter - */ -public class FixedContentItemComponentForm - extends AbstractContentItemComponentForm { - - private final static String ITEM_SEARCH = "itemSearch"; - - private ItemSearchWidget itemSearchWidget; - - public FixedContentItemComponentForm( - final PageModelsTab pageModelTab, - final ParameterSingleSelectionModel selectedModelId, - final ParameterSingleSelectionModel selectedComponentId) { - - super("FixedContentItemComponentForm", - pageModelTab, - selectedModelId, - selectedComponentId); - } - - @Override - protected void addWidgets() { - - itemSearchWidget = new ItemSearchWidget(ITEM_SEARCH); - itemSearchWidget.setLabel(new GlobalizedMessage( - "cms.ui.pagemodel.fixed_contentitem_component_form.itemsearch.label", - CmsConstants.CMS_BUNDLE)); - add(itemSearchWidget); - } - - @Override - protected FixedContentItemComponent createComponentModel() { - return new FixedContentItemComponent(); - } - - @Override - protected void updateComponentModel( - final FixedContentItemComponent component, - final PageState state, - final FormData data) { - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentItemRepository itemRepo = cdiUtil - .findBean(ContentItemRepository.class); - - final long itemId = (long) itemSearchWidget.getValue(state); - - final ContentItem item = itemRepo - .findById(itemId) - .orElseThrow(() -> new IllegalArgumentException()); - - component.setContentItem(item); - } - - @Override - public void init(final FormSectionEvent event) - throws FormProcessException { - - super.init(event); - - final PageState state = event.getPageState(); - final FixedContentItemComponent component = getComponentModel(); - - if (component != null) { - itemSearchWidget.setValue(state, component.getContentItem()); - } - } - - @Override - public void validate(final FormSectionEvent event) - throws FormProcessException { - - super.validate(event); - - final FormData data = event.getFormData(); - final Object value = data.get(ITEM_SEARCH); - - if (value == null) { - data.addError(new GlobalizedMessage( - "cms.ui.pagemodel.fixed_contentitem_component_form.error.no_item_selected", - CmsConstants.CMS_BUNDLE)); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/GreetingItemComponentForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/GreetingItemComponentForm.java deleted file mode 100644 index 994643ecf..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/GreetingItemComponentForm.java +++ /dev/null @@ -1,50 +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.pagemodel; - -import com.arsdigita.bebop.ParameterSingleSelectionModel; -import com.arsdigita.ui.admin.pagemodels.PageModelsTab; - -import org.librecms.pagemodel.GreetingItemComponent; - -/** - * Form for creating/editing a {@link GreetingItemComponent}. - * - * @author Jens Pelzetter - */ -public class GreetingItemComponentForm - extends AbstractContentItemComponentForm { - - public GreetingItemComponentForm( - final PageModelsTab pageModelTab, - final ParameterSingleSelectionModel selectedModelId, - final ParameterSingleSelectionModel selectedComponentId) { - - super("GreetingItemComponentForm", - pageModelTab, - selectedModelId, - selectedComponentId); - } - - @Override - public GreetingItemComponent createComponentModel() { - return new GreetingItemComponent(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/ItemListComponentForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/ItemListComponentForm.java deleted file mode 100644 index 06f89bc05..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pagemodel/ItemListComponentForm.java +++ /dev/null @@ -1,207 +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.pagemodel; - -import com.arsdigita.bebop.FormData; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.ParameterSingleSelectionModel; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.CheckboxGroup; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.form.TextArea; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.ui.admin.pagemodels.AbstractComponentModelForm; -import com.arsdigita.ui.admin.pagemodels.PageModelsTab; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.pagemodel.ComponentModelRepository; -import org.librecms.CmsConstants; -import org.librecms.pagemodel.ItemListComponent; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -/** - * Form for adding/editing a {@link ItemListComponent}. - * - * @author Jens Pelzetter - */ -public class ItemListComponentForm - extends AbstractComponentModelForm { - - private static final String DESCENDING_BOX = "descendingBox"; - private static final String DESCENDING = "descending"; - private static final String LIMIT_TO_TYPE = "limitToType"; - private static final String PAGE_SIZE = "pageSize"; - private static final String LIST_ORDER = "listOrder"; - - private CheckboxGroup descendingBox; - private TextField limitToTypeField; - private TextField pageSizeField; - private TextArea listOrderArea; - - public ItemListComponentForm( - final PageModelsTab pageModelTab, - final ParameterSingleSelectionModel selectedModelId, - final ParameterSingleSelectionModel selectedComponentId) { - - super("ItemListComponentForm", - pageModelTab, - selectedModelId, - selectedComponentId); - } - - @Override - protected void addWidgets() { - - descendingBox = new CheckboxGroup(DESCENDING_BOX); - descendingBox.addOption(new Option( - DESCENDING, new Label( - new GlobalizedMessage( - "cms.ui.pagemodel.itemlist_component_form.descending.label", - CmsConstants.CMS_BUNDLE)))); - add(descendingBox); - - limitToTypeField = new TextField(LIMIT_TO_TYPE); - limitToTypeField.setLabel(new GlobalizedMessage( - "cms.ui.pagemodel.itemlist_component_form.limit_to_type.label", - CmsConstants.CMS_BUNDLE)); - add(limitToTypeField); - - pageSizeField = new TextField(PAGE_SIZE); - pageSizeField.setLabel(new GlobalizedMessage( - "cms.ui.pagemodel.itemlist_component_form.page_size.label", - CmsConstants.CMS_BUNDLE)); - add(pageSizeField); - - listOrderArea = new TextArea(LIST_ORDER); - listOrderArea.setLabel(new GlobalizedMessage( - "cms.ui.pagemodel.itemlist_component_form.list_order.label", - CmsConstants.CMS_BUNDLE)); - add(listOrderArea); - } - - @Override - protected ItemListComponent createComponentModel() { - return new ItemListComponent(); - } - - @Override - protected void updateComponentModel(final ItemListComponent componentModel, - final PageState state, - final FormData data) { - - final Object[] descendingValues = (Object[]) data.get(DESCENDING_BOX); - final String limitToTypeValue = data.getString(LIMIT_TO_TYPE); - final String pageSizeValue = data.getString(PAGE_SIZE); - final String listOrderValue = data.getString(LIST_ORDER); - - final boolean descendingValue = isDescending(descendingValues); - final List listOrder = Arrays - .stream(listOrderValue.split("\n")) - .collect(Collectors.toList()); - - componentModel.setDescending(descendingValue); - componentModel.setLimitToType(limitToTypeValue); - componentModel.setPageSize(Integer.parseInt(pageSizeValue)); - - componentModel.setListOrder(listOrder); - } - - private boolean isDescending(final Object[] descendingValues) { - return descendingValues != null - && descendingValues.length != 0 - && DESCENDING.equals(descendingValues[0]); - } - - @Override - public void init(final FormSectionEvent event) throws FormProcessException { - - super.init(event); - - final PageState state = event.getPageState(); - - final ItemListComponent component = getComponentModel(); - - if (component == null) { - pageSizeField.setValue(state, "30"); - } else { - final Object[] descendingValue; - if (component.isDescending()) { - descendingValue = new Object[]{DESCENDING}; - } else { - descendingValue = new Object[]{}; - } - descendingBox.setValue(state, descendingValue); - - limitToTypeField.setValue(state, component.getLimitToType()); - - pageSizeField.setValue(state, Integer.toString(component - .getPageSize())); - - listOrderArea.setValue(state, - String.join("\n", component.getListOrder())); - } - } - - @Override - protected ItemListComponent loadSelectedComponent(final long componentId) { - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ComponentModelRepository componentModelRepo = cdiUtil - .findBean(ComponentModelRepository.class); - - return componentModelRepo.findById(componentId, - ItemListComponent.class, - new String[]{"listOrder"}) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No ComponentModel with ID %d in the database.", - componentId))); - } - - @Override - public void validate(final FormSectionEvent event) - throws FormProcessException { - - super.validate(event); - - final PageState state = event.getPageState(); - final FormData data = event.getFormData(); - - if (getSaveCancelSection().getSaveButton().isSelected(state)) { - - final String pageSizeValue = data.getString(PAGE_SIZE); - if (pageSizeValue != null - && !pageSizeValue.isEmpty() - && !pageSizeValue.matches("\\d*")) { - - data.addError( - PAGE_SIZE, - new GlobalizedMessage( - "cms.ui.pagemodel.itemlist_component_form.page_size.error.not_a_number", - CmsConstants.CMS_BUNDLE)); - } - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/london/terms/ui/CategorySubtree.java b/ccm-cms/src/main/java/com/arsdigita/london/terms/ui/CategorySubtree.java deleted file mode 100644 index 9dd28193e..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/london/terms/ui/CategorySubtree.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.arsdigita.london.terms.ui; - - -import org.apache.commons.lang.StringUtils; -import org.apache.logging.log4j.Logger; - -import com.arsdigita.bebop.Page; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SimpleComponent; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.CMS; - -import org.libreccm.categorization.Category; - -import com.arsdigita.xml.Element; - -import org.apache.logging.log4j.LogManager; -import org.libreccm.categorization.CategoryRepository; -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.core.UnexpectedErrorException; -import org.libreccm.l10n.GlobalizationHelper; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.StringTokenizer; - -/** - * Generate part of the category tree. Used by Assign Category authoring step. - * - * Class is directly used by JSP page(s), eg. load-cat.jsp (currently in - * ~/packages/content-section/www/admin, source in ccm-ldn-aplaws or - * corresponding integration module). - * - * @author Alan Pevec - * @author Jens Pelzetter - */ -public class CategorySubtree extends SimpleComponent { - - private static final Logger LOGGER = LogManager - .getLogger(CategorySubtree.class); - - private final StringParameter selectedCatsParam = new StringParameter( - "selectedCats"); - private final StringParameter nodeIdParam = new StringParameter("nodeID"); - - @Override - public void register(final Page page) { - super.register(page); - page.addGlobalStateParam(nodeIdParam); - page.addGlobalStateParam(selectedCatsParam); - } - - @Override - public void generateXML(final PageState state, final Element parent) { - - final String node = (String) state.getValue(nodeIdParam); - final Set ids = new HashSet<>(); - - if (((String) state.getValue(selectedCatsParam)) != null) { - StringTokenizer values = new StringTokenizer((String) state - .getValue(selectedCatsParam), ","); - while (values.hasMoreTokens()) { - ids.add(Long.parseLong(values.nextToken().trim())); - } - } - - LOGGER.debug("selected node = {}", node); - final String[] pathElements = StringUtils.split(node, "-"); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final CategoryRepository categoryRepo = cdiUtil - .findBean(CategoryRepository.class); - - final Category root = categoryRepo - .findById(Long.parseLong(pathElements[pathElements.length - 1])) - .orElseThrow(() -> new UnexpectedErrorException(String - .format("No Category with ID %s in the database.", - pathElements[pathElements.length - 1]))); - - LOGGER.debug("generating subtree for cat {}...", root.getObjectId()); -// TermWidget.generateSubtree(parent, root, ids); - generateSubtreeXml(parent, root, ids); - } - - private void generateSubtreeXml(final Element parentElem, - final Category root, - final Set ids) { - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final CategorySubtreeController controller = cdiUtil - .findBean(CategorySubtreeController.class); - - final List subCategories = controller.getSubCategories(root); - - final Element rootCategoryElem = generateCategoryXml(parentElem, - root, - ids); - - controller - .getSubCategories(root) - .stream() - .sorted((category1, category2) -> { - return category1.getName().compareTo(category2.getName()); - }) - .forEach(subCategory -> generateCategoryXml(rootCategoryElem, - root, - ids)); - } - - private Element generateCategoryXml(final Element parentElem, - final Category category, - final Set ids) { - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final GlobalizationHelper globalizationHelper = cdiUtil - .findBean(GlobalizationHelper.class); - - final Element element = parentElem.newChildElement("cms:category", - CMS.CMS_XML_NS); - element.addAttribute("id", Long.toString(category.getObjectId())); - element.addAttribute("name", category.getName()); - final String desc = globalizationHelper - .getValueFromLocalizedString(category.getDescription()); - element.addAttribute("description", desc); - if (ids.contains(category.getObjectId())) { - element.addAttribute("isSelected", "1"); - } else { - element.addAttribute("isSelected", "0"); - } - if (category.isAbstractCategory()) { - element.addAttribute("isAbstract", "1"); - } else { - element.addAttribute("isAbstract", "0"); - } - if (category.isEnabled()) { - element.addAttribute("isEnabled", "1"); - } else { - element.addAttribute("isEnabled", "0"); - } - - final StringBuilder path = new StringBuilder(parentElem - .getAttribute("fullname")); - if (path.length() > 0) { - path.append(" > "); - } - path.append(category.getName()); - element.addAttribute("fullname", path.toString()); - - final StringBuilder nodeId = new StringBuilder(parentElem - .getAttribute("node-id")); - if (nodeId.length() > 0) { - nodeId.append("-"); - } - nodeId.append(category.getObjectId()); - element.addAttribute("node-id", nodeId.toString()); - - return element; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/london/terms/ui/CategorySubtreeController.java b/ccm-cms/src/main/java/com/arsdigita/london/terms/ui/CategorySubtreeController.java deleted file mode 100644 index 1732b8732..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/london/terms/ui/CategorySubtreeController.java +++ /dev/null @@ -1,50 +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.london.terms.ui; - -import org.libreccm.categorization.Category; -import org.libreccm.categorization.CategoryRepository; - -import java.util.List; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -class CategorySubtreeController { - - @Inject - private CategoryRepository categoryRepo; - - protected List getSubCategories(final Category ofCategory) { - - final Category category = categoryRepo - .findById(ofCategory.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No Category with ID %d in the database.", - ofCategory.getObjectId()))); - - return category.getSubCategories(); - } - -} diff --git a/ccm-cms/src/main/java/org/librecms/Cms.java b/ccm-cms/src/main/java/org/librecms/Cms.java index 464e03a96..0d9d2e720 100644 --- a/ccm-cms/src/main/java/org/librecms/Cms.java +++ b/ccm-cms/src/main/java/org/librecms/Cms.java @@ -4,13 +4,7 @@ package org.librecms; import com.arsdigita.cms.ContentCenterAppCreator; -import com.arsdigita.cms.ContentCenterServlet; import com.arsdigita.cms.ContentCenterSetup; -import com.arsdigita.cms.ui.pagemodel.CategorizedItemComponentForm; -import com.arsdigita.cms.ui.pagemodel.CategoryTreeComponentForm; -import com.arsdigita.cms.ui.pagemodel.FixedContentItemComponentForm; -import com.arsdigita.cms.ui.pagemodel.GreetingItemComponentForm; -import com.arsdigita.cms.ui.pagemodel.ItemListComponentForm; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -22,7 +16,6 @@ import org.libreccm.modules.Module; import org.libreccm.modules.RequiredModule; import org.libreccm.modules.ShutdownEvent; import org.libreccm.modules.UnInstallEvent; -import org.libreccm.pagemodel.PageModelComponentModel; import org.libreccm.ui.admin.contentsections.ContentSectionApplicationController; import org.libreccm.web.ApplicationType; import org.libreccm.web.CcmApplication; @@ -43,18 +36,11 @@ import org.librecms.assets.VideoAsset; import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.ContentSectionCreator; import org.librecms.contentsection.ContentSectionSetup; -import org.librecms.contentsection.ui.admin.ApplicationInstanceForm; -import org.librecms.contentsection.ui.admin.SettingsPane; import org.librecms.contenttypes.Article; import org.librecms.contenttypes.ContentTypes; import org.librecms.contenttypes.Event; import org.librecms.contenttypes.MultiPartArticle; import org.librecms.contenttypes.News; -import org.librecms.pagemodel.CategorizedItemComponent; -import org.librecms.pagemodel.CategoryTreeComponent; -import org.librecms.pagemodel.FixedContentItemComponent; -import org.librecms.pagemodel.GreetingItemComponent; -import org.librecms.pagemodel.ItemListComponent; import org.librecms.pages.Pages; import org.librecms.pages.PagesCreator; @@ -71,24 +57,19 @@ import java.util.Properties; name = CmsConstants.CONTENT_CENTER_APP_TYPE, applicationClass = CcmApplication.class, descBundle = CmsConstants.CONTENT_CENTER_DESC_BUNDLE, - creator = ContentCenterAppCreator.class, - servlet = ContentCenterServlet.class + creator = ContentCenterAppCreator.class ), @ApplicationType( name = CmsConstants.CONTENT_SECTION_APP_TYPE, applicationClass = ContentSection.class, - instanceForm = ApplicationInstanceForm.class, - settingsPane = SettingsPane.class, descBundle = CmsConstants.CONTENT_SECTION_DESC_BUNDLE, creator = ContentSectionCreator.class, servletPath = "/templates/servlet/content-section", - applicationController = ContentSectionApplicationController.class + applicationController = ContentSectionApplicationController.class ), @ApplicationType( name = "org.librecms.pages.Pages", applicationClass = Pages.class, - instanceForm = ApplicationInstanceForm.class, - settingsPane = SettingsPane.class, descBundle = CmsConstants.CMS_BUNDLE, titleKey = "pages_application.title", creator = PagesCreator.class, @@ -98,44 +79,6 @@ import java.util.Properties; configurations = { org.librecms.CMSConfig.class, org.librecms.assets.BinaryAssetConfig.class - }, - pageModelComponentModels = { - @PageModelComponentModel( - modelClass = CategorizedItemComponent.class, - editor = CategorizedItemComponentForm.class, - descBundle = CmsConstants.CMS_BUNDLE, - titleKey - = "cms.ui.pagemodel.components.categorized_item_component.title", - descKey - = "cms.ui.pagemodel.components.categorized_item_component.desc"), - @PageModelComponentModel( - modelClass = CategoryTreeComponent.class, - editor = CategoryTreeComponentForm.class, - descBundle = CmsConstants.CMS_BUNDLE, - titleKey - = "cms.ui.pagemodel.components.category_tree_component.title", - descKey = "cms.ui.pagemodel.components.category_tree_component.desc"), - @PageModelComponentModel( - modelClass = FixedContentItemComponent.class, - editor = FixedContentItemComponentForm.class, - descBundle = CmsConstants.CMS_BUNDLE, - titleKey - = "cms.ui.pagemodel.components.fixed_contentitem_component.title", - descKey - = "cms.ui.pagemodel.components.fixed_contentitem_component.desc"), - @PageModelComponentModel( - modelClass = GreetingItemComponent.class, - editor = GreetingItemComponentForm.class, - descBundle = CmsConstants.CMS_BUNDLE, - titleKey - = "cms.ui.pagemodel.components.greetingitem_component.title", - descKey = "cms.ui.pagemodel.components.greetingitem_component.desc"), - @PageModelComponentModel( - modelClass = ItemListComponent.class, - editor = ItemListComponentForm.class, - descBundle = CmsConstants.CMS_BUNDLE, - titleKey = "cms.ui.pagemodel.components.itemlist_component.title", - descKey = "cms.ui.pagemodel.components.itemlist_component.desc") } ) @ContentTypes({Article.class, diff --git a/ccm-cms/src/main/java/org/librecms/assets/AssetType.java b/ccm-cms/src/main/java/org/librecms/assets/AssetType.java index b1bda857f..f8be27c60 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/AssetType.java +++ b/ccm-cms/src/main/java/org/librecms/assets/AssetType.java @@ -43,15 +43,6 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) public @interface AssetType { - /** - * The form for editing and creating an asset of the annotated class. This - * parameter is required. - * - * @return The form for editing and creating assets of the annotated sub - * class {@link org.librecms.contentsection.Asset}. - */ - Class assetForm(); - /** * The key for the localised label of the asset type. If not set the default * value {@code label} is used. @@ -88,7 +79,7 @@ public @interface AssetType { * {@code org.librecms.assets.ImageBundle}. * * @return The fully qualified name of the bundle providing the description - * of the asset type. + * of the asset type. */ String descriptionBundle() default ""; diff --git a/ccm-cms/src/main/java/org/librecms/assets/AssetTypesManager.java b/ccm-cms/src/main/java/org/librecms/assets/AssetTypesManager.java index 97db086a0..063d1f36e 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/AssetTypesManager.java +++ b/ccm-cms/src/main/java/org/librecms/assets/AssetTypesManager.java @@ -132,8 +132,6 @@ public class AssetTypesManager { } else { assetTypeInfo.setDescriptionKey(assetType.descriptionKey()); } - - assetTypeInfo.setAssetForm(assetType.assetForm()); } return assetTypeInfo; diff --git a/ccm-cms/src/main/java/org/librecms/assets/AudioAsset.java b/ccm-cms/src/main/java/org/librecms/assets/AudioAsset.java index 1c37154fb..a6bf98331 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/AudioAsset.java +++ b/ccm-cms/src/main/java/org/librecms/assets/AudioAsset.java @@ -18,7 +18,6 @@ */ package org.librecms.assets; -import com.arsdigita.cms.ui.assets.forms.AudioForm; import org.hibernate.envers.Audited; import org.librecms.ui.contentsections.assets.AudioAssetCreateStep; @@ -44,11 +43,12 @@ import static org.librecms.assets.AssetConstants.ASSETS_BUNDLE; @Entity @Table(name = "AUDIO_ASSETS", schema = DB_SCHEMA) @Audited -@AssetType(assetForm = AudioForm.class, +@AssetType( labelKey = "audio_asset.label", labelBundle = ASSETS_BUNDLE, descriptionKey = "audio_asset.description", - descriptionBundle = ASSETS_BUNDLE) + descriptionBundle = ASSETS_BUNDLE +) @MvcAssetEditKit( createStep = AudioAssetCreateStep.class, editStep = AudioAssetEditStep.class diff --git a/ccm-cms/src/main/java/org/librecms/assets/Bookmark.java b/ccm-cms/src/main/java/org/librecms/assets/Bookmark.java index 4bb76066f..233a54f85 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/Bookmark.java +++ b/ccm-cms/src/main/java/org/librecms/assets/Bookmark.java @@ -18,7 +18,6 @@ */ package org.librecms.assets; -import com.arsdigita.cms.ui.assets.forms.BookmarkForm; import org.librecms.contentsection.Asset; @@ -48,11 +47,12 @@ import static org.librecms.assets.AssetConstants.*; * * @author Jens Pelzetter */ -@AssetType(assetForm = BookmarkForm.class, - labelBundle = ASSETS_BUNDLE, - labelKey = "bookmark.label", - descriptionBundle = ASSETS_BUNDLE, - descriptionKey = "bookmark.description") +@AssetType( + labelBundle = ASSETS_BUNDLE, + labelKey = "bookmark.label", + descriptionBundle = ASSETS_BUNDLE, + descriptionKey = "bookmark.description" +) @Entity @Table(name = "BOOKMARKS", schema = DB_SCHEMA) @Audited diff --git a/ccm-cms/src/main/java/org/librecms/assets/ExternalAudioAsset.java b/ccm-cms/src/main/java/org/librecms/assets/ExternalAudioAsset.java index 3eb7c7de6..bf2c39c48 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/ExternalAudioAsset.java +++ b/ccm-cms/src/main/java/org/librecms/assets/ExternalAudioAsset.java @@ -18,7 +18,6 @@ */ package org.librecms.assets; -import com.arsdigita.cms.ui.assets.forms.ExternalAudioAssetForm; import org.hibernate.envers.Audited; import org.librecms.ui.contentsections.assets.ExternalAudioAssetCreateStep; @@ -47,11 +46,12 @@ import static org.librecms.assets.AssetConstants.*; @Entity @Table(name = "EXTERNAL_AUDIO_ASSETS", schema = DB_SCHEMA) @Audited -@AssetType(assetForm = ExternalAudioAssetForm.class, - labelKey = "external_audio_asset.label", - labelBundle = ASSETS_BUNDLE, - descriptionKey = "external_audio_asset.description", - descriptionBundle = ASSETS_BUNDLE) +@AssetType( + labelKey = "external_audio_asset.label", + labelBundle = ASSETS_BUNDLE, + descriptionKey = "external_audio_asset.description", + descriptionBundle = ASSETS_BUNDLE +) @MvcAssetEditKit( createStep = ExternalAudioAssetCreateStep.class, editStep = ExternalAudioAssetEditStep.class diff --git a/ccm-cms/src/main/java/org/librecms/assets/ExternalVideoAsset.java b/ccm-cms/src/main/java/org/librecms/assets/ExternalVideoAsset.java index 2b9fb529d..223800d88 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/ExternalVideoAsset.java +++ b/ccm-cms/src/main/java/org/librecms/assets/ExternalVideoAsset.java @@ -18,7 +18,6 @@ */ package org.librecms.assets; -import com.arsdigita.cms.ui.assets.forms.ExternalVideoAssetForm; import org.hibernate.envers.Audited; import org.librecms.ui.contentsections.assets.ExternalVideoAssetCreateStep; @@ -38,17 +37,18 @@ import static org.librecms.assets.AssetConstants.*; /** * An asset for external videos, like videos from YouTube. - * + * * @author Jens Pelzetter */ @Entity @Table(name = "EXTERNAL_VIDEO_ASSETS", schema = DB_SCHEMA) @Audited -@AssetType(assetForm = ExternalVideoAssetForm.class, - labelKey = "external_video_asset.label", - labelBundle = ASSETS_BUNDLE, - descriptionKey = "external_video_asset.description", - descriptionBundle = ASSETS_BUNDLE) +@AssetType( + labelKey = "external_video_asset.label", + labelBundle = ASSETS_BUNDLE, + descriptionKey = "external_video_asset.description", + descriptionBundle = ASSETS_BUNDLE +) @MvcAssetEditKit( createStep = ExternalVideoAssetCreateStep.class, editStep = ExternalVideoAssetEditStep.class diff --git a/ccm-cms/src/main/java/org/librecms/assets/FileAsset.java b/ccm-cms/src/main/java/org/librecms/assets/FileAsset.java index c7103c2a0..5e321598b 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/FileAsset.java +++ b/ccm-cms/src/main/java/org/librecms/assets/FileAsset.java @@ -17,7 +17,6 @@ * MA 02110-1301 USA */package org.librecms.assets; -import com.arsdigita.cms.ui.assets.forms.FileAssetForm; import java.io.Serializable; @@ -34,17 +33,18 @@ import static org.librecms.assets.AssetConstants.*; /** * An asset for making files available for download. - * + * * @author Jens Pelzetter */ @Entity @Table(name = "FILES", schema = DB_SCHEMA) @Audited -@AssetType(assetForm = FileAssetForm.class, - labelKey = "fileasset.label", - labelBundle = ASSETS_BUNDLE, - descriptionKey = "fileasset.description", - descriptionBundle = ASSETS_BUNDLE) +@AssetType( + labelKey = "fileasset.label", + labelBundle = ASSETS_BUNDLE, + descriptionKey = "fileasset.description", + descriptionBundle = ASSETS_BUNDLE +) @MvcAssetEditKit( createStep = FileAssetCreateStep.class, editStep = FileAssetEditStep.class @@ -58,7 +58,7 @@ public class FileAsset extends BinaryAsset implements Serializable { return super.hashCode(); } - @Override + @Override public boolean equals(final Object obj) { if (this == obj) { return true; @@ -76,11 +76,10 @@ public class FileAsset extends BinaryAsset implements Serializable { final FileAsset other = (FileAsset) obj; return other.canEqual(this); } - + @Override public boolean canEqual(final Object obj) { return obj instanceof FileAsset; } - - + } diff --git a/ccm-cms/src/main/java/org/librecms/assets/Image.java b/ccm-cms/src/main/java/org/librecms/assets/Image.java index 8e6f05177..ae1d31b01 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/Image.java +++ b/ccm-cms/src/main/java/org/librecms/assets/Image.java @@ -26,8 +26,6 @@ import javax.persistence.Entity; import javax.persistence.JoinColumn; import javax.persistence.Table; -import com.arsdigita.cms.ui.assets.forms.ImageForm; - import org.hibernate.envers.Audited; import org.librecms.ui.contentsections.assets.ImageCreateStep; import org.librecms.ui.contentsections.assets.ImageEditStep; @@ -39,7 +37,7 @@ import static org.librecms.CmsConstants.*; import static org.librecms.assets.AssetConstants.*; /** - * An asset for images (in a format which can be displayed by a browser, like + * An asset for images (in a format which can be displayed by a browser, like * PNG, JPEG or GIF). * * @author Jens Pelzetter @@ -47,11 +45,12 @@ import static org.librecms.assets.AssetConstants.*; @Entity @Table(name = "IMAGES", schema = DB_SCHEMA) @Audited -@AssetType(assetForm = ImageForm.class, - labelKey = "image.label", - labelBundle = ASSETS_BUNDLE, - descriptionKey = "image.description", - descriptionBundle = ASSETS_BUNDLE) +@AssetType( + labelKey = "image.label", + labelBundle = ASSETS_BUNDLE, + descriptionKey = "image.description", + descriptionBundle = ASSETS_BUNDLE +) @MvcAssetEditKit( createStep = ImageCreateStep.class, editStep = ImageEditStep.class diff --git a/ccm-cms/src/main/java/org/librecms/assets/LegalMetadata.java b/ccm-cms/src/main/java/org/librecms/assets/LegalMetadata.java index 33c279a2f..7e4262cfb 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/LegalMetadata.java +++ b/ccm-cms/src/main/java/org/librecms/assets/LegalMetadata.java @@ -18,7 +18,6 @@ */ package org.librecms.assets; -import com.arsdigita.cms.ui.assets.forms.LegalMetadataForm; import org.librecms.contentsection.Asset; import org.hibernate.envers.Audited; @@ -56,7 +55,6 @@ import static org.librecms.assets.AssetConstants.*; @Table(name = "LEGAL_METADATA", schema = DB_SCHEMA) @Audited @AssetType( - assetForm = LegalMetadataForm.class, labelKey = "legal_metadata.label", labelBundle = ASSETS_BUNDLE, descriptionKey = "legal_metadata.description", diff --git a/ccm-cms/src/main/java/org/librecms/assets/Organization.java b/ccm-cms/src/main/java/org/librecms/assets/Organization.java index 442761a42..15d0d0eb3 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/Organization.java +++ b/ccm-cms/src/main/java/org/librecms/assets/Organization.java @@ -18,7 +18,6 @@ */ package org.librecms.assets; -import com.arsdigita.cms.ui.assets.forms.OrganizationForm; import org.hibernate.envers.Audited; import org.librecms.ui.contentsections.assets.MvcAssetEditKit; @@ -39,11 +38,12 @@ import static org.librecms.assets.AssetConstants.*; * * @author Jens Pelzetter */ -@AssetType(assetForm = OrganizationForm.class, - labelBundle = ASSETS_BUNDLE, - labelKey = "organization.label", - descriptionBundle = ASSETS_BUNDLE, - descriptionKey = "organization.description") +@AssetType( + labelBundle = ASSETS_BUNDLE, + labelKey = "organization.label", + descriptionBundle = ASSETS_BUNDLE, + descriptionKey = "organization.description" +) @MvcAssetEditKit( createStep = OrganizationCreateStep.class, editStep = OrganizationEditStep.class diff --git a/ccm-cms/src/main/java/org/librecms/assets/Person.java b/ccm-cms/src/main/java/org/librecms/assets/Person.java index 550c73977..8e9439dc9 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/Person.java +++ b/ccm-cms/src/main/java/org/librecms/assets/Person.java @@ -18,7 +18,6 @@ */ package org.librecms.assets; -import com.arsdigita.cms.ui.assets.forms.PersonForm; import org.hibernate.envers.Audited; import org.librecms.ui.contentsections.assets.MvcAssetEditKit; @@ -50,11 +49,10 @@ import static org.librecms.assets.AssetConstants.*; @Table(name = "PERSONS", schema = DB_SCHEMA) @Audited @AssetType( - assetForm = PersonForm.class, - labelBundle = ASSETS_BUNDLE, - labelKey = "person.label", - descriptionBundle = ASSETS_BUNDLE, - descriptionKey = "person.description" + labelBundle = ASSETS_BUNDLE, + labelKey = "person.label", + descriptionBundle = ASSETS_BUNDLE, + descriptionKey = "person.description" ) @MvcAssetEditKit( createStep = PersonCreateStep.class, diff --git a/ccm-cms/src/main/java/org/librecms/assets/PostalAddress.java b/ccm-cms/src/main/java/org/librecms/assets/PostalAddress.java index 2db3d563b..672ef0ba7 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/PostalAddress.java +++ b/ccm-cms/src/main/java/org/librecms/assets/PostalAddress.java @@ -18,7 +18,6 @@ */ package org.librecms.assets; -import com.arsdigita.cms.ui.assets.forms.PostalAddressForm; import org.hibernate.envers.Audited; import org.librecms.contentsection.Asset; @@ -35,7 +34,6 @@ import javax.persistence.Table; import static org.librecms.CmsConstants.DB_SCHEMA; import static org.librecms.assets.AssetConstants.ASSETS_BUNDLE; - /** * A reuable postal address. * @@ -45,11 +43,10 @@ import static org.librecms.assets.AssetConstants.ASSETS_BUNDLE; @Audited @Table(name = "POSTAL_ADDRESSES", schema = DB_SCHEMA) @AssetType( - assetForm = PostalAddressForm.class, - labelBundle = ASSETS_BUNDLE, - labelKey = "postaladdress.label", - descriptionBundle = ASSETS_BUNDLE, - descriptionKey = "postaladdress.description" + labelBundle = ASSETS_BUNDLE, + labelKey = "postaladdress.label", + descriptionBundle = ASSETS_BUNDLE, + descriptionKey = "postaladdress.description" ) @MvcAssetEditKit( createStep = PostalAddressCreateStep.class, diff --git a/ccm-cms/src/main/java/org/librecms/assets/RelatedLink.java b/ccm-cms/src/main/java/org/librecms/assets/RelatedLink.java index aed4a2d70..3dfed2f9e 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/RelatedLink.java +++ b/ccm-cms/src/main/java/org/librecms/assets/RelatedLink.java @@ -18,7 +18,6 @@ */ package org.librecms.assets; -import com.arsdigita.cms.ui.assets.forms.RelatedLinkForm; import org.librecms.contentsection.Asset; import org.hibernate.envers.Audited; @@ -46,7 +45,6 @@ import static org.librecms.assets.AssetConstants.ASSETS_BUNDLE; @Table(name = "RELATED_LINKS", schema = DB_SCHEMA) @Audited @AssetType( - assetForm = RelatedLinkForm.class, labelBundle = ASSETS_BUNDLE, labelKey = "relatedlink.label", descriptionBundle = ASSETS_BUNDLE, diff --git a/ccm-cms/src/main/java/org/librecms/assets/SideNote.java b/ccm-cms/src/main/java/org/librecms/assets/SideNote.java index 22d45f5cf..dae2d4a7c 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/SideNote.java +++ b/ccm-cms/src/main/java/org/librecms/assets/SideNote.java @@ -18,7 +18,6 @@ */ package org.librecms.assets; -import com.arsdigita.cms.ui.assets.forms.SideNoteForm; import org.librecms.contentsection.Asset; import org.hibernate.envers.Audited; @@ -49,7 +48,6 @@ import static org.librecms.assets.AssetConstants.*; @Table(name = "SIDE_NOTES", schema = DB_SCHEMA) @Audited @AssetType( - assetForm = SideNoteForm.class, labelBundle = ASSETS_BUNDLE, labelKey = "sidenote.label", descriptionBundle = ASSETS_BUNDLE, diff --git a/ccm-cms/src/main/java/org/librecms/assets/VideoAsset.java b/ccm-cms/src/main/java/org/librecms/assets/VideoAsset.java index ffc921ee3..680b2867b 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/VideoAsset.java +++ b/ccm-cms/src/main/java/org/librecms/assets/VideoAsset.java @@ -18,7 +18,6 @@ */ package org.librecms.assets; -import com.arsdigita.cms.ui.assets.forms.AudioForm; import org.hibernate.envers.Audited; import org.librecms.ui.contentsections.assets.MvcAssetEditKit; @@ -45,11 +44,12 @@ import static org.librecms.assets.AssetConstants.ASSETS_BUNDLE; @Entity @Table(name = "VIDEO_ASSETS", schema = DB_SCHEMA) @Audited -@AssetType(assetForm = AudioForm.class, +@AssetType( labelKey = "video_asset.label", labelBundle = ASSETS_BUNDLE, descriptionKey = "video_asset.description", - descriptionBundle = ASSETS_BUNDLE) + descriptionBundle = ASSETS_BUNDLE +) @MvcAssetEditKit( createStep = VideoAssetCreateStep.class, editStep = VideoAssetEditStep.class diff --git a/ccm-core/src/main/java/org/libreccm/modules/Module.java b/ccm-core/src/main/java/org/libreccm/modules/Module.java index 7fabb9a69..26ba25f37 100644 --- a/ccm-core/src/main/java/org/libreccm/modules/Module.java +++ b/ccm-core/src/main/java/org/libreccm/modules/Module.java @@ -99,6 +99,7 @@ public @interface Module { * @return An array containing all {@link ComponentModel}s provided by the * annotated module. */ + @Deprecated PageModelComponentModel[] pageModelComponentModels() default {}; } diff --git a/ccm-core/src/main/java/org/libreccm/web/ApplicationType.java b/ccm-core/src/main/java/org/libreccm/web/ApplicationType.java index a66cd3a61..81498bf77 100644 --- a/ccm-core/src/main/java/org/libreccm/web/ApplicationType.java +++ b/ccm-core/src/main/java/org/libreccm/web/ApplicationType.java @@ -118,8 +118,10 @@ public @interface ApplicationType { @SuppressWarnings("rawtypes") // Can't specify type here, otherwise problems in using classes. Class creator(); + @Deprecated Class instanceForm() default DefaultApplicationInstanceForm.class; + @Deprecated Class settingsPane() default DefaultApplicationSettingsPane.class; Class applicationController() default DefaultApplicationController.class; From fbb07d950172bd513122b2d066351962b449a9d6 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 16 Mar 2022 18:25:16 +0100 Subject: [PATCH 03/63] Removed deprecated package com/arsdigita/cms/ui/authoring/assets/relatedinfo from ccm-cms --- .../relatedinfo/AttachmentListTableRow.java | 66 --- .../relatedinfo/AttachmentTableRow.java | 57 --- .../assets/relatedinfo/AttachmentsTable.java | 203 --------- .../relatedinfo/AttachmentsTableModel.java | 120 ----- .../AttachmentsTableModelBuilder.java | 85 ---- .../relatedinfo/InternalLinkAddForm.java | 133 ------ .../RelatedInfoAttachAssetForm.java | 148 ------- .../relatedinfo/RelatedInfoListForm.java | 405 ----------------- .../relatedinfo/RelatedInfoListTable.java | 272 ------------ .../RelatedInfoListTableModel.java | 109 ----- .../RelatedInfoListTableModelBuilder.java | 79 ---- .../assets/relatedinfo/RelatedInfoStep.java | 315 -------------- .../RelatedInfoStepController.java | 411 ------------------ .../contentsection/ContentSectionConfig.java | 26 -- .../ContentItemAuthoringStepManager.java | 2 +- 15 files changed, 1 insertion(+), 2430 deletions(-) delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentListTableRow.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentTableRow.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTable.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTableModel.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTableModelBuilder.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/InternalLinkAddForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoAttachAssetForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTable.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTableModel.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTableModelBuilder.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStep.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStepController.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentListTableRow.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentListTableRow.java deleted file mode 100644 index a1a17a345..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentListTableRow.java +++ /dev/null @@ -1,66 +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.assets.relatedinfo; - -/** - * - * @author Jens Pelzetter - */ -class AttachmentListTableRow { - - private long listId; - private String name; - private String title; - private String description; - - public long getListId() { - return listId; - } - - public void setListId(final long listId) { - this.listId = listId; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - public String getTitle() { - return title; - } - - public void setTitle(final String title) { - this.title = title; - } - - public String getDescription() { - return description; - } - - public void setDescription(final String description) { - this.description = description; - } - - - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentTableRow.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentTableRow.java deleted file mode 100644 index 2b60a1bac..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentTableRow.java +++ /dev/null @@ -1,57 +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.assets.relatedinfo; - -import org.librecms.contentsection.Asset; - -/** - * - * @author Jens Pelzetter - */ -class AttachmentTableRow { - - private long attachmentId; - private String title; - private Class type; - - public long getAttachmentId() { - return attachmentId; - } - - public void setAttachmentId(final long attachmentId) { - this.attachmentId = attachmentId; - } - - public String getTitle() { - return title; - } - - public void setTitle(final String title) { - this.title = title; - } - - public Class getType() { - return type; - } - - public void setType(final Class type) { - this.type = type; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTable.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTable.java deleted file mode 100644 index 792a7abff..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTable.java +++ /dev/null @@ -1,203 +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.assets.relatedinfo; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.ControlLink; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.event.TableActionEvent; -import com.arsdigita.bebop.event.TableActionListener; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.table.TableCellRenderer; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.bebop.table.TableColumnModel; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel; -import com.arsdigita.cms.ui.authoring.assets.AttachmentSelectionModel; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ItemAttachment; - -/** - * - * @author Jens Pelzetter - */ -class AttachmentsTable extends Table { - - protected static final int COL_TITLE = 0; - protected static final int COL_TYPE = 1; - protected static final int COL_MOVE = 2; - protected static final int COL_REMOVE = 3; - - private final RelatedInfoStep relatedInfoStep; - private final ItemSelectionModel itemSelectionModel; - private final AttachmentListSelectionModel attachmentListSelectionModel; - private final AttachmentSelectionModel selectedAttachmentModel; - private final AttachmentSelectionModel moveAttachmentModel; - private final StringParameter selectedLanguageParam; - - public AttachmentsTable( - final RelatedInfoStep relatedInfoStep, - final ItemSelectionModel itemSelectionModel, - final AttachmentListSelectionModel attachmentListSelectionModel, - final AttachmentSelectionModel selectedAttachmentModel, - final AttachmentSelectionModel moveAttachmentModel, - final StringParameter selectedLanguageParam) { - - super(); - - this.relatedInfoStep = relatedInfoStep; - this.itemSelectionModel = itemSelectionModel; - this.attachmentListSelectionModel = attachmentListSelectionModel; - this.selectedAttachmentModel = selectedAttachmentModel; - this.moveAttachmentModel = moveAttachmentModel; - this.selectedLanguageParam = selectedLanguageParam; - - final TableColumnModel columnModel = super.getColumnModel(); - columnModel.add(new TableColumn( - COL_TITLE, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.attachment.title", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_TYPE, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.attachment.type", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_MOVE, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.attachment.move", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_REMOVE, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.attachment.remove", - CmsConstants.CMS_BUNDLE)))); - - super - .setModelBuilder(new AttachmentsTableModelBuilder( - itemSelectionModel, - attachmentListSelectionModel, - moveAttachmentModel, - selectedLanguageParam)); - - super - .getColumn(COL_MOVE) - .setCellRenderer(new ControlLinkCellRenderer()); - super - .getColumn(COL_REMOVE) - .setCellRenderer(new ControlLinkCellRenderer()); - - setEmptyView(new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.attachment.none", - CmsConstants.CMS_BUNDLE))); - - super - .addTableActionListener(new TableActionListener() { - - @Override - public void cellSelected(final TableActionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - final TableColumn column = getColumnModel() - .get(event.getColumn()); - - switch (column.getModelIndex()) { - case COL_MOVE: { - if (moveAttachmentModel - .getSelectedKey(state) == null) { - moveAttachmentModel - .setSelectedKey(state, - Long.parseLong( - (String) event - .getRowKey())); - } else { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final RelatedInfoStepController controller - = cdiUtil - .findBean( - RelatedInfoStepController.class); - - final ItemAttachment attachment - = moveAttachmentModel - .getSelectedAttachment(state); - - final Long destId = Long.parseLong( - (String) event.getRowKey()); - - controller.moveAfter( - attachmentListSelectionModel - .getSelectedAttachmentList(state), - attachment, - destId); - moveAttachmentModel.clearSelection(state); - - } - break; - } - case COL_REMOVE: { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final RelatedInfoStepController controller = cdiUtil - .findBean(RelatedInfoStepController.class); - controller.removeAttachment(Long.parseLong( - (String) event.getRowKey())); - } - default: - throw new IllegalArgumentException(String - .format("Illegal column index: %d", - column.getModelIndex())); - } - - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. - } - - @Override - public void headSelected(final TableActionEvent event) { - //Nothing - } - - }); - - } - - private class ControlLinkCellRenderer implements TableCellRenderer { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - - return new ControlLink((Component) value); - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTableModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTableModel.java deleted file mode 100644 index 2cf29ea01..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTableModel.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.assets.relatedinfo; - -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.cms.ui.authoring.assets.AttachmentSelectionModel; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.l10n.GlobalizationHelper; -import org.librecms.CmsConstants; -import org.librecms.assets.AssetTypeInfo; -import org.librecms.assets.AssetTypesManager; - -import java.util.Iterator; -import java.util.List; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -/** - * - * @author Jens Pelzetter - */ -class AttachmentsTableModel implements TableModel { - - private final PageState state; - private final AttachmentSelectionModel moveAttachmentModel; - - private final Iterator iterator; - private AttachmentTableRow currentRow; - - AttachmentsTableModel( - final List rows, - final PageState state, - final AttachmentSelectionModel moveAttachmentModel) { - - this.state = state; - this.moveAttachmentModel = moveAttachmentModel; - this.iterator = rows.iterator(); - } - - @Override - public int getColumnCount() { - return 4; - } - - @Override - public boolean nextRow() { - if (iterator.hasNext()) { - currentRow = iterator.next(); - return true; - } else { - return false; - } - } - - @Override - public Object getElementAt(final int columnIndex) { - - switch (columnIndex) { - case AttachmentsTable.COL_TITLE: - return currentRow.getTitle(); - case AttachmentsTable.COL_TYPE: { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final AssetTypesManager typesManager = cdiUtil - .findBean(AssetTypesManager.class); - final AssetTypeInfo typeInfo = typesManager - .getAssetTypeInfo(currentRow.getType()); - try { - final ResourceBundle bundle = ResourceBundle - .getBundle(typeInfo.getLabelBundle()); - return bundle.getString(typeInfo.getLabelKey()); - } catch (MissingResourceException ex) { - return typeInfo.getAssetClass().getName(); - } - } - case AttachmentsTable.COL_MOVE: - if (moveAttachmentModel.getSelectedAttachment(state) == null) { - return new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.attachment.move", - CmsConstants.CMS_BUNDLE)); - } else { - return new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.attachment.move_here", - CmsConstants.CMS_BUNDLE)); - } - case AttachmentsTable.COL_REMOVE: - return new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.attachment.remove", - CmsConstants.CMS_BUNDLE)); - default: - throw new IllegalArgumentException(String.format( - "Illegal column index %d.", columnIndex)); - } - } - - @Override - public Object getKeyAt(final int columnIndex) { - return currentRow.getAttachmentId(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTableModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTableModelBuilder.java deleted file mode 100644 index 33d15c893..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/AttachmentsTableModelBuilder.java +++ /dev/null @@ -1,85 +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.assets.relatedinfo; - -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.cms.ui.authoring.assets.AttachmentListSelectionModel; -import com.arsdigita.cms.ui.authoring.assets.AttachmentSelectionModel; -import com.arsdigita.util.LockableImpl; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.contentsection.AttachmentList; -import org.librecms.contentsection.ContentItem; - -import java.util.List; -import java.util.Locale; - -/** - * - * @author Jens Pelzetter - */ -class AttachmentsTableModelBuilder - extends LockableImpl - implements TableModelBuilder { - - private final ItemSelectionModel itemSelectionModel; - private final AttachmentListSelectionModel listSelectionModel; - private final AttachmentSelectionModel moveAttachmentModel; - private final StringParameter selectedLanguageParam; - - public AttachmentsTableModelBuilder( - final ItemSelectionModel itemSelectionModel, - final AttachmentListSelectionModel listSelectionModel, - final AttachmentSelectionModel moveAttachmentModel, - final StringParameter selectedLanguageParam) { - - super(); - - this.itemSelectionModel = itemSelectionModel; - this.listSelectionModel = listSelectionModel; - this.moveAttachmentModel = moveAttachmentModel; - this.selectedLanguageParam = selectedLanguageParam; - } - - @Override - public TableModel makeModel(final Table table, final PageState state) { - - final ContentItem selectedItem = itemSelectionModel - .getSelectedItem(state); - final AttachmentList list = listSelectionModel.getSelectedAttachmentList(state); - final String selectedLanguage = (String) state - .getValue(selectedLanguageParam); - final Locale selectedLocale = new Locale(selectedLanguage); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final RelatedInfoStepController controller = cdiUtil - .findBean(RelatedInfoStepController.class); - - final List rows = controller - .retrieveAttachments(selectedItem, list, selectedLocale); - - return new AttachmentsTableModel(rows, state, moveAttachmentModel); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/InternalLinkAddForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/InternalLinkAddForm.java deleted file mode 100644 index be658950c..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/InternalLinkAddForm.java +++ /dev/null @@ -1,133 +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.assets.relatedinfo; - -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.form.TextField; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.assets.ItemSearchWidget; -import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; - -/** - * - * @author Jens Pelzetter - */ -public class InternalLinkAddForm - extends Form - implements FormInitListener, - FormProcessListener, - FormSubmissionListener { - - private final RelatedInfoStep relatedInfoStep; - private final ItemSelectionModel itemSelectionModel; - private final AttachmentListSelectionModel listSelectionModel; - private final StringParameter selectedLanguageParam; - - private final TextField titleField; -// private final TextArea descriptionArea; - private final ItemSearchWidget itemSearchWidget; - private final SaveCancelSection saveCancelSection; - - public InternalLinkAddForm( - final RelatedInfoStep relatedInfoStep, - final ItemSelectionModel itemSelectionModel, - final AttachmentListSelectionModel listSelectionModel, - final StringParameter selectedLanguageParam) { - - super("relatedinfo-attach-internallink-form"); - - this.relatedInfoStep = relatedInfoStep; - this.itemSelectionModel = itemSelectionModel; - this.listSelectionModel = listSelectionModel; - this.selectedLanguageParam = selectedLanguageParam; - - final Label titleLabel = new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.internal_link.title", - CmsConstants.CMS_BUNDLE)); - titleField = new TextField("link-title"); - -// descriptionArea = new TextArea("link-description"); - final Label itemSearchLabel = new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.internal_link.target_item", - CmsConstants.CMS_BUNDLE)); - itemSearchWidget = new ItemSearchWidget("link-item-search"); - - saveCancelSection = new SaveCancelSection(); - - super.add(titleLabel); - super.add(titleField); - super.add(itemSearchLabel); - super.add(itemSearchWidget); - super.add(saveCancelSection); - - super.addProcessListener(this); - super.addSubmissionListener(this); - } - - @Override - public void init(final FormSectionEvent event) throws FormProcessException { - - } - - @Override - public void process(final FormSectionEvent event) throws - FormProcessException { - - final PageState state = event.getPageState(); - - if (saveCancelSection.getSaveButton().isSelected(state)) { - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final RelatedInfoStepController controller = cdiUtil - .findBean(RelatedInfoStepController.class); - - controller.createInternalLink( - listSelectionModel.getSelectedAttachmentList(state), - (Long) itemSearchWidget.getValue(state), - (String) titleField.getValue(state), - (String) state.getValue(selectedLanguageParam)); - - relatedInfoStep.showAttachmentsTable(state); - } - } - - @Override - public void submitted(final FormSectionEvent event) throws - FormProcessException { - - if (saveCancelSection.getCancelButton().isSelected(event.getPageState())) { - relatedInfoStep.showAttachmentsTable(event.getPageState()); - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoAttachAssetForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoAttachAssetForm.java deleted file mode 100644 index f4a713bb1..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoAttachAssetForm.java +++ /dev/null @@ -1,148 +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.assets.relatedinfo; - -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.assets.AssetSearchWidget; -import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.core.UnexpectedErrorException; -import org.librecms.CmsConstants; -import org.librecms.contentsection.AttachmentList; - -/** - * - * @author Jens Pelzetter - */ -class RelatedInfoAttachAssetForm - extends Form - implements FormInitListener, - FormProcessListener, - FormSubmissionListener { - - private final RelatedInfoStep relatedInfoStep; - private final ItemSelectionModel itemSelectionModel; - private final AttachmentListSelectionModel listSelectionModel; - private final StringParameter selectedLanguageParameter; - - private final AssetSearchWidget searchWidget; - private final SaveCancelSection saveCancelSection; - - public RelatedInfoAttachAssetForm( - final RelatedInfoStep relatedInfoStep, - final ItemSelectionModel itemSelectionModel, - final AttachmentListSelectionModel listSelectionModel, - final StringParameter selectedLangugeParam) { - - super("relatedinfo-attach-asset-form"); - - this.relatedInfoStep = relatedInfoStep; - this.itemSelectionModel = itemSelectionModel; - this.listSelectionModel = listSelectionModel; - this.selectedLanguageParameter = selectedLangugeParam; - - final Label label = new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.attach_asset.selected_asset", - CmsConstants.CMS_BUNDLE)); - super.add(label); - searchWidget = new AssetSearchWidget("asset-search-widget"); - super.add(searchWidget); - saveCancelSection = new SaveCancelSection(); - super.add(saveCancelSection); - - super.addInitListener(this); - super.addProcessListener(this); - super.addSubmissionListener(this); - } -// -// @Override -// public void register(final Page page) { -// super.register(page); -// -// page.addComponentStateParam(this, itemSelectionModel.getStateParameter()); -// page.addComponentStateParam(this, listSelectionModel.getStateParameter()); -// } - - @Override - public void init(final FormSectionEvent event) throws FormProcessException { - if (listSelectionModel.getSelectedKey(event.getPageState()) == null) { - throw new UnexpectedErrorException("The selected list null. " - + "This should not happen."); - } - } - - @Override - public void process(final FormSectionEvent event) throws - FormProcessException { - - final PageState state = event.getPageState(); - - if (listSelectionModel.getSelectedKey(state) == null) { - throw new UnexpectedErrorException("The selected list null. " - + "This should not happen."); - } - - final Object value = searchWidget.getValue(state); - if (value != null) { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); -// final ItemAttachmentManager attachmentManager = cdiUtil -// .findBean(ItemAttachmentManager.class); -// final AssetRepository assetRepo = cdiUtil -// .findBean(AssetRepository.class); -// final Asset asset = assetRepo -// .findById((long) value) -// .orElseThrow(() -> new UnexpectedErrorException(String -// .format("No Asset with ID %d in the database.", value))); - - final AttachmentList list = listSelectionModel - .getSelectedAttachmentList(state); - -// attachmentManager.attachAsset(asset, list); - final RelatedInfoStepController controller = cdiUtil - .findBean(RelatedInfoStepController.class); - controller.attachAsset(list, (long) value); - } - - relatedInfoStep.showAttachmentsTable(state); - } - - @Override - public void submitted(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - if (saveCancelSection.getCancelButton().isSelected(state)) { - relatedInfoStep.showAttachmentsTable(state); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListForm.java deleted file mode 100644 index fc0a223d1..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListForm.java +++ /dev/null @@ -1,405 +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.assets.relatedinfo; - -import com.arsdigita.bebop.BoxPanel; -import com.arsdigita.bebop.Form; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SaveCancelSection; -import com.arsdigita.bebop.Text; -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.ParameterEvent; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.form.SingleSelect; -import com.arsdigita.bebop.form.Submit; -import com.arsdigita.bebop.form.TextArea; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.bebop.parameters.GlobalizedParameterListener; -import com.arsdigita.bebop.parameters.ParameterData; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.kernel.KernelConfig; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.core.UnexpectedErrorException; -import org.librecms.CmsConstants; -import org.librecms.contentsection.AttachmentList; -import org.librecms.contentsection.AttachmentListL10NManager; -import org.librecms.contentsection.AttachmentListManager; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Optional; -import java.util.TooManyListenersException; - -/** - * - * @author Jens Pelzetter - */ -class RelatedInfoListForm - extends Form - implements FormInitListener, - FormProcessListener, - FormSubmissionListener { - - private final RelatedInfoStep relatedInfoStep; - private final ItemSelectionModel itemSelectionModel; - private final AttachmentListSelectionModel listSelectionModel; - private final StringParameter selectedLanguage; - - private BoxPanel showLocalePanel; - private SingleSelect showLocaleSelect; - private Submit showLocaleSubmit; - - private BoxPanel addLocalePanel; - private SingleSelect addLocaleSelect; - private Submit addLocaleSubmit; - - private TextField nameField; - private TextField titleField; - private TextArea descriptionArea; - - private SaveCancelSection saveCancelSection; - - public RelatedInfoListForm( - final RelatedInfoStep relatedInfoStep, - final ItemSelectionModel itemSelectionModel, - final AttachmentListSelectionModel listSelectionModel, - final StringParameter selectedLanguageParam) { - - super("relatedinfo-list-form", new BoxPanel(BoxPanel.VERTICAL)); - - this.relatedInfoStep = relatedInfoStep; - this.itemSelectionModel = itemSelectionModel; - this.listSelectionModel = listSelectionModel; - this.selectedLanguage = selectedLanguageParam; - - showLocalePanel = new BoxPanel(BoxPanel.HORIZONTAL); - final Label showLocaleLabel = new Label(event -> { - - final PageState state = event.getPageState(); - final Optional selectedList = getSelectedList(state); - final Label target = (Label) event.getTarget(); - if (selectedList.isPresent()) { - target.setLabel(new GlobalizedMessage( - "cms.ui.assetlist.show_locale", - CmsConstants.CMS_BUNDLE)); - } else { - target.setLabel(new GlobalizedMessage( - "cms.ui.assetlist.initial_locale", - CmsConstants.CMS_BUNDLE)); - } - }); - showLocaleSelect = new SingleSelect("selected-locale"); - try { - showLocaleSelect.addPrintListener(event -> { - - final PageState state = event.getPageState(); - - final Optional selectedList = getSelectedList( - state); - if (selectedList.isPresent()) { - final SingleSelect target = (SingleSelect) event.getTarget(); - - target.clearOptions();; - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final AttachmentListL10NManager l10NManager = cdiUtil - .findBean(AttachmentListL10NManager.class); - final List availableLocales = new ArrayList<>( - l10NManager.availableLocales(selectedList.get())); - availableLocales.sort((locale1, locale2) -> { - return locale1.toString().compareTo(locale2.toString()); - }); - availableLocales.forEach(locale -> target.addOption( - new Option(locale.toString(), - new Text(locale.toString())))); - } else { - final SingleSelect target = (SingleSelect) event - .getTarget(); - - target.clearOptions(); - - final List langs = new ArrayList<>( - KernelConfig.getConfig().getSupportedLanguages()); - langs.sort((lang1, lang2) -> lang1.compareTo(lang2)); - - langs.forEach(lang -> { - target.addOption(new Option(lang, new Text(lang))); - }); - - } - - }); - } catch (TooManyListenersException ex) { - throw new UnexpectedErrorException(ex); - } - showLocaleSubmit = new Submit(new GlobalizedMessage( - "cms.ui.assetlist.show_locale", - CmsConstants.CMS_BUNDLE)) { - - @Override - public boolean isVisible(final PageState state) { - return getSelectedList(state).isPresent(); - } - - }; - showLocalePanel.add(showLocaleLabel); - showLocalePanel.add(showLocaleSelect); - showLocalePanel.add(showLocaleSubmit); - super.add(showLocalePanel); - - addLocalePanel = new BoxPanel(BoxPanel.HORIZONTAL) { - - @Override - public boolean isVisible(final PageState state) { - return getSelectedList(state).isPresent(); - } - - }; - final Label addLocaleLabel = new Label( - new GlobalizedMessage("cms.ui.assetlist.add_locale", - CmsConstants.CMS_BUNDLE)); - addLocaleSelect = new SingleSelect("add-locale-select"); - try { - addLocaleSelect.addPrintListener(event -> { - - final PageState state = event.getPageState(); - final Optional selectedList = getSelectedList( - state); - if (selectedList.isPresent()) { - final SingleSelect target = (SingleSelect) event.getTarget(); - - target.clearOptions(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final AttachmentListL10NManager l10nManager = cdiUtil - .findBean(AttachmentListL10NManager.class); - final List creatableLocales = new ArrayList<>( - l10nManager.creatableLocales(selectedList.get())); - creatableLocales.sort((locale1, locale2) -> { - return locale1 - .toString() - .compareTo(locale2.toString()); - }); - creatableLocales.forEach(locale -> target.addOption( - new Option(locale.toString(), - new Text(locale.toString())))); - - } - - }); - } catch (TooManyListenersException ex) { - throw new UnexpectedErrorException(ex); - } - addLocaleSubmit = new Submit(new GlobalizedMessage( - "cms.ui.assetlist.add_locale", - CmsConstants.CMS_BUNDLE)); - addLocalePanel.add(addLocaleLabel); - addLocalePanel.add(addLocaleSelect); - addLocalePanel.add(addLocaleSubmit); - super.add(addLocalePanel); - - super.add(new Label(new GlobalizedMessage("cms.ui.assetlist.name", - CmsConstants.CMS_BUNDLE))); - nameField = new TextField("attachmentListName"); - nameField.addValidationListener(new AssetListNameValidator()); - super.add(nameField); - - super.add(new Label(new GlobalizedMessage("cms.ui.assetlist.title", - CmsConstants.CMS_BUNDLE))); - titleField = new TextField("attachmentListTitle"); - super.add(titleField); - - super.add(new Label( - new GlobalizedMessage("cms.ui.assetlist.description", - CmsConstants.CMS_BUNDLE))); - descriptionArea = new TextArea("attachmentListDesc"); - super.add(descriptionArea); - - saveCancelSection = new SaveCancelSection(); - super.add(saveCancelSection); - - super.addInitListener(this); - super.addProcessListener(this); - super.addSubmissionListener(this); - } - - protected Optional getSelectedList(final PageState state) { - - if (listSelectionModel.getSelectedKey(state) == null) { - return Optional.empty(); - } else { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final AttachmentListManager manager = cdiUtil - .findBean(AttachmentListManager.class); - final AttachmentList list = manager - .getAttachmentList(listSelectionModel.getSelectedKey(state)) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No AttachmentList with ID %d in the database.", - listSelectionModel.getSelectedKey(state)))); - return Optional.of(list); - } - } - - @Override - public void init(final FormSectionEvent event) throws FormProcessException { - - final PageState state = event.getPageState(); - - final Optional selectedList = getSelectedList(state); - - if (selectedList.isPresent()) { - - nameField.setValue(state, selectedList.get().getName()); - - showLocaleSelect.setValue(state, - KernelConfig - .getConfig() - .getDefaultLocale() - .toString()); - - titleField.setValue(state, - selectedList - .get() - .getTitle() - .getValue(getSelectedLocale(state))); - - descriptionArea.setValue(state, - selectedList - .get() - .getTitle() - .getValue(getSelectedLocale(state))); - } else { - showLocaleSelect.setValue(state, - KernelConfig - .getConfig() - .getDefaultLocale() - .toString()); - } - } - - protected Locale getSelectedLocale(final PageState state) { - final String selected = (String) showLocaleSelect.getValue(state); - if (selected == null) { - return KernelConfig.getConfig().getDefaultLocale(); - } else { - return new Locale(selected); - } - } - - @Override - public void process(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - - if (showLocaleSubmit.isSelected(state)) { - - return; - } - - if (addLocaleSubmit.isSelected(state)) { - final AttachmentListL10NManager l10nManager = cdiUtil - .findBean(AttachmentListL10NManager.class); - final Locale add = new Locale((String) addLocaleSelect - .getValue(state)); - final Optional selectedList = getSelectedList(state); - l10nManager.addLanguage(selectedList.get(), add); - } - - if (saveCancelSection.getSaveButton().isSelected(state)) { - - final RelatedInfoStepController controller = cdiUtil - .findBean(RelatedInfoStepController.class); - final AttachmentListManager attachmentListManager = cdiUtil - .findBean(AttachmentListManager.class); - - final Optional selectedList = getSelectedList(state); - final AttachmentList attachmentList; - if (selectedList.isPresent()) { - attachmentList = selectedList.get(); - } else { - attachmentList = attachmentListManager - .createAttachmentList(itemSelectionModel - .getSelectedItem(state), - (String) nameField.getValue(state)); - } - - attachmentList.setName((String) nameField.getValue(state)); - attachmentList - .getTitle() - .putValue(getSelectedLocale(state), - (String) titleField.getValue(state)); - attachmentList - .getDescription() - .putValue(getSelectedLocale(state), - (String) descriptionArea.getValue(state)); - - controller.saveAttachmentList(attachmentList); - } - - relatedInfoStep.showAttachmentListTable(state); - } - - @Override - public void submitted(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - if (saveCancelSection.getCancelButton().isSelected(state)) { - listSelectionModel.clearSelection(state); - relatedInfoStep.showAttachmentListTable(state); - } - } - - private class AssetListNameValidator extends GlobalizedParameterListener { - - public AssetListNameValidator() { - super.setError(new GlobalizedMessage( - "cms.ui.assetlist.name_cant_start_with_dot", - CmsConstants.CMS_BUNDLE)); - } - - @Override - public void validate(final ParameterEvent event) throws - FormProcessException { - - final ParameterData data = event.getParameterData(); - final String value = (String) data.getValue(); - - if (value.startsWith(".")) { - data.addError(getError()); - } - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTable.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTable.java deleted file mode 100644 index b9837dd7a..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTable.java +++ /dev/null @@ -1,272 +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.assets.relatedinfo; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.ControlLink; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.event.TableActionEvent; -import com.arsdigita.bebop.event.TableActionListener; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.table.TableCellRenderer; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.bebop.table.TableColumnModel; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; -import org.librecms.contentsection.AttachmentList; - -/** - * - * @author Jens Pelzetter - */ -class RelatedInfoListTable extends Table { - - protected static final int COL_NAME = 0; - protected static final int COL_TITLE = 1; - protected static final int COL_DESC = 2; - protected static final int COL_EDIT = 3; - protected static final int COL_MOVE = 4; - protected static final int COL_DELETE = 5; - - private final RelatedInfoStep relatedInfoStep; - private final ItemSelectionModel itemSelectionModel; - private final AttachmentListSelectionModel selectedListModel; - private final AttachmentListSelectionModel moveListModel; - private final StringParameter selectedLanguageParam; - - protected RelatedInfoListTable( - final RelatedInfoStep relatedInfoStep, - final ItemSelectionModel itemSelectionModel, - final AttachmentListSelectionModel selectedListModel, - final AttachmentListSelectionModel moveListModel, - final StringParameter selectedLanguageParam) { - - super(); - this.relatedInfoStep = relatedInfoStep; - this.itemSelectionModel = itemSelectionModel; - this.selectedListModel = selectedListModel; - this.moveListModel = moveListModel; - this.selectedLanguageParam = selectedLanguageParam; - - final TableColumnModel columnModel = super.getColumnModel(); - columnModel.add(new TableColumn( - COL_NAME, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.list.name", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_TITLE, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.list.title", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_DESC, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.list.description", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_EDIT, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.list.edit", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_MOVE, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.list.move", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_DELETE, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.list.delete", - CmsConstants.CMS_BUNDLE)))); - - super - .setModelBuilder(new RelatedInfoListTableModelBuilder( - itemSelectionModel, - moveListModel, - selectedLanguageParam)); - - super - .getColumn(COL_NAME) - .setCellRenderer(new ControlLinkCellRenderer()); - super - .getColumn(COL_EDIT) - .setCellRenderer(new ControlLinkCellRenderer()); - super - .getColumn(COL_MOVE) - .setCellRenderer(new ControlLinkCellRenderer()); - super - .getColumn(COL_DELETE) - .setCellRenderer(new ControlLinkCellRenderer()); - - super.setEmptyView(new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.list.none", - CmsConstants.CMS_BUNDLE))); - - super - .addTableActionListener(new TableActionListener() { - - @Override - public void cellSelected(final TableActionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - final TableColumn column = getColumnModel() - .get(event.getColumn()); - - switch (column.getModelIndex()) { - case COL_NAME: - selectedListModel - .setSelectedKey(state, - Long.parseLong((String) event - .getRowKey())); - relatedInfoStep.showAttachmentsTable(state); - break; - case COL_EDIT: - selectedListModel - .setSelectedKey(state, - Long.parseLong((String) event - .getRowKey())); - relatedInfoStep.showListEditForm(state); - break; - case COL_MOVE: - if (moveListModel.getSelectedKey(state) == null) { - - moveListModel - .setSelectedKey(state, - Long.parseLong( - (String) event - .getRowKey())); - } else { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final RelatedInfoStepController controller - = cdiUtil - .findBean( - RelatedInfoStepController.class); - - final AttachmentList selectedList - = moveListModel - .getSelectedAttachmentList(state); - - final Long destId = Long - .parseLong((String) event.getRowKey()); - - controller.moveAfter(itemSelectionModel - .getSelectedItem(state), - selectedList, - destId); - moveListModel.clearSelection(state); - } - break; - case COL_DELETE: { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final RelatedInfoStepController controller = cdiUtil - .findBean(RelatedInfoStepController.class); - controller.deleteList(Long - .parseLong((String) event.getRowKey())); - break; - } - default: - throw new IllegalArgumentException(String - .format("Illegal column index: %d", - column.getModelIndex())); - } - } - - @Override - public void headSelected(final TableActionEvent event) { - //Nothing - } - - }); - } - - private class ControlLinkCellRenderer implements TableCellRenderer { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - - return new ControlLink((Component) value); - } - - } -// -// private class MoveCellRenderer implements TableCellRenderer { -// -// @Override -// public Component getComponent(final Table table, -// final PageState state, -// final Object value, -// final boolean isSelected, -// final Object key, -// final int row, -// final int column) { -// -// return new ControlLink((Component) value); -// } -// -// } -// -// private class EditCellRenderer implements TableCellRenderer { -// -// @Override -// public Component getComponent(final Table table, -// final PageState state, -// final Object value, -// final boolean isSelected, -// final Object key, -// final int row, -// final int column) { -// -// return new ControlLink((Component) value); -// } -// -// } -// -// private class DeleteCellRenderer implements TableCellRenderer { -// -// @Override -// public Component getComponent(final Table table, -// final PageState state, -// final Object value, -// final boolean isSelected, -// final Object key, -// final int row, -// final int column) { -// -// return new ControlLink((Component) value); -// } -// -//} - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTableModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTableModel.java deleted file mode 100644 index 3651c9082..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTableModel.java +++ /dev/null @@ -1,109 +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.assets.relatedinfo; - -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Text; -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.librecms.CmsConstants; - -import java.util.Iterator; -import java.util.List; - -/** - * - * @author Jens Pelzetter - */ -class RelatedInfoListTableModel implements TableModel { - - private final PageState state; - private final AttachmentListSelectionModel moveListModel; - - private final Iterator iterator; - private AttachmentListTableRow currentRow; - - RelatedInfoListTableModel( - final List rows, - final PageState state, - final AttachmentListSelectionModel moveListModel) { - - this.iterator = rows.iterator(); - this.state = state; - this.moveListModel = moveListModel; - } - - @Override - public int getColumnCount() { - return 6; - } - - @Override - public boolean nextRow() { - if (iterator.hasNext()) { - currentRow = iterator.next(); - return true; - } else { - return false; - } - } - - @Override - public Object getElementAt(final int columnIndex) { - - switch (columnIndex) { - case RelatedInfoListTable.COL_NAME: - return new Text(currentRow.getName()); - case RelatedInfoListTable.COL_TITLE: - return new Text(currentRow.getTitle()); - case RelatedInfoListTable.COL_DESC: - return new Text(currentRow.getDescription()); - case RelatedInfoListTable.COL_EDIT: - return new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.list.edit", - CmsConstants.CMS_BUNDLE)); - case RelatedInfoListTable.COL_MOVE: - if (moveListModel.getSelectedAttachmentList(state) == null) { - return new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.list.move", - CmsConstants.CMS_BUNDLE)); - } else { - return new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.list.move_here", - CmsConstants.CMS_BUNDLE)); - } - case RelatedInfoListTable.COL_DELETE: - return new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.list.delete", - CmsConstants.CMS_BUNDLE)); - default: - throw new IllegalArgumentException(String.format( - "Illegal column index %d.", columnIndex)); - } - } - - @Override - public Object getKeyAt(final int columnIndex) { - return currentRow.getListId(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTableModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTableModelBuilder.java deleted file mode 100644 index 9bf752d3c..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoListTableModelBuilder.java +++ /dev/null @@ -1,79 +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.assets.relatedinfo; - -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.cms.ui.authoring.assets.AttachmentListSelectionModel; -import com.arsdigita.util.LockableImpl; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.contentsection.ContentItem; - -import java.util.List; -import java.util.Locale; - -/** - * - * @author Jens Pelzetter - */ -class RelatedInfoListTableModelBuilder - extends LockableImpl - implements TableModelBuilder { - - private final ItemSelectionModel itemSelectionModel; - private final AttachmentListSelectionModel moveListModel; - private final StringParameter selectedLanguageParam; - - protected RelatedInfoListTableModelBuilder( - final ItemSelectionModel itemSelectionModel, - final AttachmentListSelectionModel moveListModel, - final StringParameter selectedLanguageParam) { - - super(); - - this.itemSelectionModel = itemSelectionModel; - this.moveListModel = moveListModel; - this.selectedLanguageParam = selectedLanguageParam; - } - - @Override - public TableModel makeModel(final Table table, final PageState state) { - - final ContentItem selectedItem = itemSelectionModel - .getSelectedItem(state); - final String selectedLanguage = (String) state - .getValue(selectedLanguageParam); - final Locale selectedLocale = new Locale(selectedLanguage); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final RelatedInfoStepController controller = cdiUtil - .findBean(RelatedInfoStepController.class); - - final List rows = controller - .retrieveAttachmentLists(selectedItem, selectedLocale); - - return new RelatedInfoListTableModel(rows, state, moveListModel); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStep.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStep.java deleted file mode 100644 index d761f228d..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStep.java +++ /dev/null @@ -1,315 +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.assets.relatedinfo; - -import com.arsdigita.bebop.ActionLink; -import com.arsdigita.bebop.BoxPanel; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.Page; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SimpleContainer; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; -import com.arsdigita.cms.ui.authoring.ResettableContainer; -import com.arsdigita.cms.ui.authoring.assets.AttachmentListSelectionModel; -import com.arsdigita.cms.ui.authoring.assets.AttachmentSelectionModel; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; -import org.librecms.contentsection.AttachmentList; -import org.librecms.contentsection.ItemAttachment; -import org.librecms.ui.authoring.ContentItemAuthoringStep; - -/** - * - * @author Jens Pelzetter - */ -@ContentItemAuthoringStep( - labelBundle = CmsConstants.CMS_BUNDLE, - labelKey = "related_info_step.label", - descriptionBundle = CmsConstants.CMS_BUNDLE, - descriptionKey = "related_info_step.description") -public class RelatedInfoStep extends ResettableContainer { - - private final ItemSelectionModel itemSelectionModel; - private final AuthoringKitWizard authoringKitWizard; - private final StringParameter selectedLanguageParam; - - private final AttachmentListSelectionModel selectedListModel; - private final AttachmentListSelectionModel moveListModel; - - private final RelatedInfoListTable listTable; - private final RelatedInfoListForm listForm; - private final ActionLink addListLink; - private final ActionLink listToFirstLink; - - private final AttachmentSelectionModel selectedAttachmentModel; - private final AttachmentSelectionModel moveAttachmentModel; - - private final AttachmentsTable attachmentsTable; - private final RelatedInfoAttachAssetForm attachAssetForm; - private final InternalLinkAddForm internalLinkAddForm; - - private final ActionLink attachAssetLink; - private final ActionLink internalLinkAddLink; - private final ActionLink attachmentToFirstLink; - - public RelatedInfoStep(final ItemSelectionModel itemSelectionModel, - final AuthoringKitWizard authoringKitWizard, - final StringParameter selectedLanguage) { - - super(); - - this.itemSelectionModel = itemSelectionModel; - this.authoringKitWizard = authoringKitWizard; - this.selectedLanguageParam = selectedLanguage; - - selectedListModel = new AttachmentListSelectionModel( - "selected-attachment-list"); - moveListModel = new AttachmentListSelectionModel( - "move-attachment-list-model"); - - listTable = new RelatedInfoListTable(this, - itemSelectionModel, - selectedListModel, moveListModel, - selectedLanguageParam); - listForm = new RelatedInfoListForm(this, - itemSelectionModel, - selectedListModel, - selectedLanguageParam); - - addListLink = new ActionLink(new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.add_list", - CmsConstants.CMS_BUNDLE))); - addListLink.addActionListener(event -> { - showListEditForm(event.getPageState()); - }); - - listToFirstLink = new ActionLink(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.attachment_list" - + ".move_to_beginning", - CmsConstants.CMS_BUNDLE)); - listToFirstLink.addActionListener(event -> { - final PageState state = event.getPageState(); - final AttachmentList toMove = moveListModel - .getSelectedAttachmentList(state); - - final RelatedInfoStepController controller = CdiUtil - .createCdiUtil() - .findBean(RelatedInfoStepController.class); - - controller.moveToFirst(itemSelectionModel.getSelectedItem(state), - toMove); - - moveListModel.clearSelection(state); - }); - - moveListModel.addChangeListener(event -> { - - final PageState state = event.getPageState(); - - if (moveListModel.getSelectedKey(state) == null) { - addListLink.setVisible(state, true); - listToFirstLink.setVisible(state, false); - } else { - addListLink.setVisible(state, false); - listToFirstLink.setVisible(state, true); - } - }); - - selectedAttachmentModel = new AttachmentSelectionModel( - "selected-attachment-model"); - moveAttachmentModel = new AttachmentSelectionModel( - "move-attachment-model"); - - attachmentsTable = new AttachmentsTable(this, itemSelectionModel, - selectedListModel, - selectedAttachmentModel, - moveAttachmentModel, - selectedLanguageParam); - attachAssetForm = new RelatedInfoAttachAssetForm(this, - itemSelectionModel, - selectedListModel, - selectedLanguageParam); - internalLinkAddForm = new InternalLinkAddForm(this, - itemSelectionModel, - selectedListModel, - selectedLanguageParam); - - - attachAssetLink = new ActionLink(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.attach_asset", - CmsConstants.CMS_BUNDLE)); - attachAssetLink.addActionListener(event -> { - showAttachAssetForm(event.getPageState()); - }); - - internalLinkAddLink = new ActionLink(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.add_internal_link", - CmsConstants.CMS_BUNDLE)); - internalLinkAddLink.addActionListener(event -> { - showAddInternalLinkForm(event.getPageState()); - }); - - attachmentToFirstLink = new ActionLink(new GlobalizedMessage( - "cms.ui.authoring.assets.related_info_step.attachment.move_to_first", - CmsConstants.CMS_BUNDLE)); - attachmentToFirstLink.addActionListener(event -> { - final PageState state = event.getPageState(); - final ItemAttachment toMove = moveAttachmentModel - .getSelectedAttachment(state); - - final RelatedInfoStepController controller = CdiUtil - .createCdiUtil() - .findBean(RelatedInfoStepController.class); - - controller.moveToFirst(selectedListModel - .getSelectedAttachmentList(state), toMove); - - moveAttachmentModel.clearSelection(state); - }); - - moveAttachmentModel.addChangeListener(event -> { - - final PageState state = event.getPageState(); - - if (moveAttachmentModel.getSelectedKey(state) == null) { - attachAssetLink.setVisible(state, true); - attachmentToFirstLink.setVisible(state, false); - } else { - attachAssetLink.setVisible(state, false); - attachmentToFirstLink.setVisible(state, true); - } - }); - - final SimpleContainer addLinks = new SimpleContainer(); - addLinks.add(addListLink); - addLinks.add(internalLinkAddLink); - - final BoxPanel panel = new BoxPanel(BoxPanel.VERTICAL); - - panel.add(addLinks); - panel.add(listToFirstLink); - panel.add(listTable); - panel.add(listForm); - - panel.add(attachAssetLink); - panel.add(attachmentToFirstLink); - panel.add(attachmentsTable); - panel.add(attachAssetForm); - panel.add(internalLinkAddForm); - - super.add(panel); - } - - @Override - public void register(final Page page) { - - super.register(page); - - page.addComponentStateParam(this, selectedListModel.getStateParameter()); - page.addComponentStateParam(this, moveListModel.getStateParameter()); - page.addComponentStateParam(this, - selectedAttachmentModel.getStateParameter()); - page.addComponentStateParam(this, - moveAttachmentModel.getStateParameter()); - - page.setVisibleDefault(listTable, true); - page.setVisibleDefault(listForm, false); - page.setVisibleDefault(addListLink, true); - page.setVisibleDefault(listToFirstLink, false); - page.setVisibleDefault(attachmentsTable, false); - page.setVisibleDefault(attachAssetForm, false); - page.setVisibleDefault(internalLinkAddForm, false); - page.setVisibleDefault(internalLinkAddLink, false); - page.setVisibleDefault(attachAssetLink, false); - page.setVisibleDefault(attachmentToFirstLink, false); - } - - protected void showAttachmentListTable(final PageState state) { - - listTable.setVisible(state, true); - addListLink.setVisible(state, true); - listForm.setVisible(state, false); - listToFirstLink.setVisible(state, false); - attachmentsTable.setVisible(state, false); - attachAssetForm.setVisible(state, false); - attachAssetLink.setVisible(state, false); - attachmentToFirstLink.setVisible(state, false); - internalLinkAddForm.setVisible(state, false); - internalLinkAddLink.setVisible(state, false); - } - - void showListEditForm(final PageState state) { - - listTable.setVisible(state, false); - listForm.setVisible(state, true); - addListLink.setVisible(state, false); - listToFirstLink.setVisible(state, false); - attachmentsTable.setVisible(state, false); - attachAssetForm.setVisible(state, false); - attachAssetLink.setVisible(state, false); - attachmentToFirstLink.setVisible(state, false); - internalLinkAddForm.setVisible(state, false); - internalLinkAddLink.setVisible(state, false); - } - - void showAttachmentsTable(final PageState state) { - - listTable.setVisible(state, false); - listForm.setVisible(state, false); - addListLink.setVisible(state, false); - listToFirstLink.setVisible(state, false); - attachmentsTable.setVisible(state, true); - attachAssetForm.setVisible(state, false); - attachAssetLink.setVisible(state, true); - attachmentToFirstLink.setVisible(state, false); - internalLinkAddForm.setVisible(state, false); - internalLinkAddLink.setVisible(state, true); - } - - void showAttachAssetForm(final PageState state) { - listTable.setVisible(state, false); - listForm.setVisible(state, false); - addListLink.setVisible(state, false); - listToFirstLink.setVisible(state, false); - attachmentsTable.setVisible(state, false); - attachAssetForm.setVisible(state, true); - attachAssetLink.setVisible(state, false); - attachmentToFirstLink.setVisible(state, false); - internalLinkAddForm.setVisible(state, false); - internalLinkAddLink.setVisible(state, false); - } - - void showAddInternalLinkForm(final PageState state) { - listTable.setVisible(state, false); - listForm.setVisible(state, false); - addListLink.setVisible(state, false); - listToFirstLink.setVisible(state, false); - attachmentsTable.setVisible(state, false); - attachAssetForm.setVisible(state, false); - attachAssetLink.setVisible(state, false); - attachmentToFirstLink.setVisible(state, false); - internalLinkAddForm.setVisible(state, true); - internalLinkAddLink.setVisible(state, false); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStepController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStepController.java deleted file mode 100644 index 43f47f0a1..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/relatedinfo/RelatedInfoStepController.java +++ /dev/null @@ -1,411 +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.assets.relatedinfo; - -import com.arsdigita.kernel.KernelConfig; - -import org.libreccm.configuration.ConfigurationManager; -import org.libreccm.core.UnexpectedErrorException; -import org.librecms.assets.RelatedLink; -import org.librecms.contentsection.Asset; -import org.librecms.contentsection.AssetRepository; -import org.librecms.contentsection.AttachmentList; -import org.librecms.contentsection.AttachmentListManager; -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.contentsection.ItemAttachment; -import org.librecms.contentsection.ItemAttachmentManager; - -import java.util.List; -import java.util.Locale; -import java.util.Objects; -import java.util.stream.Collectors; - -import javax.annotation.PostConstruct; -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.persistence.EntityManager; -import javax.transaction.Transactional; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -class RelatedInfoStepController { - - @Inject - private AssetRepository assetRepo; - - @Inject - private AttachmentListManager attachmentListManager; - - @Inject - private ConfigurationManager confManager; - - @Inject - private ContentItemRepository itemRepo; - - @Inject - private EntityManager entityManager; - - @Inject - private ItemAttachmentManager itemAttachmentManager; - - private Locale defaultLocale; - - @PostConstruct - private void init() { - - final KernelConfig kernelConfig = confManager - .findConfiguration(KernelConfig.class); - defaultLocale = kernelConfig.getDefaultLocale(); - - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void saveAttachmentList(final AttachmentList attachmentList) { - - if (attachmentList.getListId() == 0) { - entityManager.persist(attachmentList); - } else { - entityManager.merge(attachmentList); - } - } - - @Transactional(Transactional.TxType.REQUIRED) - void moveToFirst(final ContentItem selectedItem, - final AttachmentList listToMove) { - - Objects.requireNonNull(selectedItem); - Objects.requireNonNull(listToMove); - - final ContentItem item = itemRepo - .findById(selectedItem.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No ContentItem with ID %d in the database.", - selectedItem.getObjectId()))); - - final AttachmentList toMove = attachmentListManager - .getAttachmentList(listToMove.getListId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No AttachmentList with ID %d in the database.", - listToMove.getListId()))); - - final List lists = item - .getAttachments() - .stream() - .sorted((list1, list2) -> list1.compareTo(list2)) - .collect(Collectors.toList()); - - toMove.setListOrder(0); - lists - .stream() - .filter(current -> !current.equals(toMove)) - .forEach(current -> current.setListOrder(current.getListOrder() + 1)); - - lists.forEach(entityManager::merge); - } - - @Transactional(Transactional.TxType.REQUIRED) - void moveToFirst(final AttachmentList selectedList, - final ItemAttachment attachmentToMove) { - - Objects.requireNonNull(selectedList); - Objects.requireNonNull(attachmentToMove); - - final AttachmentList list = attachmentListManager - .getAttachmentList(selectedList.getListId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No AttachmentList with ID %d in the database.", - selectedList.getListId()))); - - final ItemAttachment toMove = itemAttachmentManager - .findById(attachmentToMove.getAttachmentId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No ItemAttachment with ID %d in the database.", - attachmentToMove.getAttachmentId()))); - - final List> attachments = list - .getAttachments() - .stream() - .sorted((attachment1, attachment2) -> { - return attachment1.compareTo(attachment2); - }) - .collect(Collectors.toList()); - - toMove.setSortKey(0); - attachments - .stream() - .filter(current -> !current.equals(toMove)) - .forEach(current -> current.setSortKey(current.getSortKey() + 1)); - - attachments.forEach(entityManager::merge); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void moveAfter(final ContentItem selectedItem, - final AttachmentList listToMove, - final Long destId) { - - Objects.requireNonNull(selectedItem); - Objects.requireNonNull(listToMove); - - final ContentItem item = itemRepo - .findById(selectedItem.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No ContentItem with ID %d in the database.", - selectedItem.getObjectId()))); - - final AttachmentList toMove = attachmentListManager - .getAttachmentList(listToMove.getListId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No AttachmentList with ID %d in the database.", - listToMove.getListId()))); - - final AttachmentList after = attachmentListManager - .getAttachmentList(destId) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No AttachmentList with ID %d in the database.", destId))); - - final List lists = item - .getAttachments() - .stream() - .sorted((list1, list2) -> list1.compareTo(list2)) - .collect(Collectors.toList()); - - if (!lists.contains(toMove)) { - throw new IllegalArgumentException(String - .format("AttachmentList %d is not part of ContentItem %d.", - toMove.getListId(), - item.getObjectId())); - } - - if (!lists.contains(after)) { - throw new IllegalArgumentException(String - .format("AttachmentList %d is not part of ContentItem %d.", - after.getListId(), - item.getObjectId())); - } - - final int afterIndex = lists.indexOf(after); - for (int i = afterIndex + 1; i < lists.size(); i++) { - final AttachmentList current = lists.get(i); - current.setListOrder(current.getListOrder() + 1); - entityManager.merge(current); - } - - toMove.setListOrder(afterIndex + 1); - entityManager.merge(toMove); - } - - protected void moveAfter(final AttachmentList list, - final ItemAttachment attachment, - final long destId) { - //ToDo - throw new UnsupportedOperationException(); - } - - protected void deleteList(final Long listId) { - - final AttachmentList list = attachmentListManager - .getAttachmentList(listId) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No AttachmentList with ID %d in the database.", - listId))); - - entityManager.remove(list); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void removeAttachment(final long attachmentId) { - - final ItemAttachment attachment = itemAttachmentManager - .findById(attachmentId) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No ItemAttachment with ID %d in the database.", - attachmentId))); - - entityManager.remove(attachment); - - } - - @Transactional(Transactional.TxType.REQUIRED) - protected List retrieveAttachmentLists( - final ContentItem forContentItem, - final Locale selectedLocale) { - - final ContentItem item = itemRepo - .findById(forContentItem.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No ContentItem with ID %d in the database.", - forContentItem.getObjectId()))); - - return item.getAttachments() - .stream() - .filter(list -> !list.getName().startsWith(".")) - .map(list -> buildAttachmentListTableRow(list, selectedLocale)) - .collect(Collectors.toList()); - - } - - @Transactional(Transactional.TxType.REQUIRED) - protected List retrieveAttachments( - final ContentItem selectedItem, - final AttachmentList fromList, - final Locale selectedLocale) { - - final AttachmentList list = attachmentListManager - .getAttachmentList(fromList.getListId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No AttachmentList with ID %d in the database.", - fromList.getListId()))); - - return list - .getAttachments() - .stream() - .map(attachment -> buildAttachmentTableRow(attachment, - selectedLocale)) - .collect(Collectors.toList()); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void createInternalLink(final AttachmentList attachmentList, - final long targetItemId, - final String title, - // final String description, - final String selectedLanguage) { - - final ContentItem targetItem = itemRepo - .findById(targetItemId) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No ContentItem with ID %d in the database.", targetItemId))); - - final RelatedLink link = new RelatedLink(); - link.setTargetItem(targetItem); - final Locale selectedLocale = new Locale(selectedLanguage); - link.getTitle().putValue(selectedLocale, title); - - final AttachmentList list = attachmentListManager - .getAttachmentList(attachmentList.getListId()) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No AttachmentList with Id %d in the database.", - attachmentList.getListId()))); - - itemAttachmentManager.attachAsset(link, list); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void attachAsset(final AttachmentList attachmentList, - final long assetId) { - - final Asset asset = assetRepo - .findById(assetId) - .orElseThrow(() -> new UnexpectedErrorException(String - .format("No Asset with ID %d in the database.", assetId))); - - final AttachmentList list = attachmentListManager - .getAttachmentList(attachmentList.getListId()) - .orElseThrow(() -> new UnexpectedErrorException(String - .format("No AttachmentList with ID %d in the database.", - attachmentList.getListId()))); - - itemAttachmentManager.attachAsset(asset, list); - } - - private AttachmentListTableRow buildAttachmentListTableRow( - final AttachmentList attachmentList, - final Locale selectedLocale) { - - final AttachmentListTableRow row = new AttachmentListTableRow(); - - row.setListId(attachmentList.getListId()); - - row.setName(attachmentList.getName()); - if (attachmentList.getTitle().hasValue(selectedLocale)) { - row.setTitle(attachmentList.getTitle().getValue(selectedLocale)); - } else if (attachmentList.getTitle().hasValue(defaultLocale)) { - row.setTitle(attachmentList.getTitle().getValue(defaultLocale)); - } else { - row.setTitle(attachmentList.getTitle().getValue()); - } - - if (attachmentList.getDescription().hasValue(selectedLocale)) { - row.setDescription(shortenDescription(attachmentList - .getDescription() - .getValue(selectedLocale))); - } else if (attachmentList.getDescription().hasValue(defaultLocale)) { - row.setDescription(shortenDescription(attachmentList - .getDescription() - .getValue(defaultLocale))); - } else { - row.setDescription(shortenDescription(attachmentList - .getDescription() - .getValue())); - } - - return row; - } - - private AttachmentTableRow buildAttachmentTableRow( - final ItemAttachment attachment, - final Locale selectedLocale) { - - final AttachmentTableRow row = new AttachmentTableRow(); - - row.setAttachmentId(attachment.getAttachmentId()); - if (attachment.getAsset().getTitle().hasValue(selectedLocale)) { - row.setTitle(attachment - .getAsset() - .getTitle() - .getValue(selectedLocale)); - } else if (attachment.getAsset().getTitle().hasValue(defaultLocale)) { - row.setTitle(attachment - .getAsset() - .getTitle() - .getValue(defaultLocale)); - } else { - row.setTitle(attachment - .getAsset() - .getTitle() - .getValue()); - } - - row.setType(attachment.getAsset().getClass()); - - return row; - } - - private String shortenDescription(final String description) { - - if (description == null) { - return ""; - } else if (description.trim().length() < 140) { - return description.trim(); - } else { - final String tmp = description.trim().substring(0, 140); - - return String - .format("%s...", - tmp.substring(0, tmp.lastIndexOf(" "))); - } - - } - -} diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionConfig.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionConfig.java index 7141d1d62..8ae33dc6e 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionConfig.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentSectionConfig.java @@ -18,10 +18,6 @@ */ package org.librecms.contentsection; -import com.arsdigita.cms.ui.authoring.ItemCategoryStep; -import com.arsdigita.cms.ui.permissions.ItemPermissionsStep; -import com.arsdigita.cms.ui.authoring.assets.relatedinfo.RelatedInfoStep; -import com.arsdigita.cms.ui.authoring.assets.images.ImageStep; import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.configuration.Configuration; @@ -119,19 +115,6 @@ public class ContentSectionConfig { @Setting private int maxAlerts = 5; - /** - * Assets steps which are added which are present on all content items. - */ - @Setting - private List defaultAuthoringSteps = Arrays - .asList( - new String[]{ - ItemCategoryStep.class.getName(), - ImageStep.class.getName(), - RelatedInfoStep.class.getName(), - ItemPermissionsStep.class.getName() - }); - public static ContentSectionConfig getConfig() { final ConfigurationManager confManager = CdiUtil.createCdiUtil() .findBean(ConfigurationManager.class); @@ -182,13 +165,4 @@ public class ContentSectionConfig { this.maxAlerts = maxAlerts; } - public List getDefaultAuthoringSteps() { - return new ArrayList<>(defaultAuthoringSteps); - } - - public void setDefaultAuthoringSteps( - final List defaultAuthoringSteps) { - this.defaultAuthoringSteps = new ArrayList<>(defaultAuthoringSteps); - } - } diff --git a/ccm-cms/src/main/java/org/librecms/ui/authoring/ContentItemAuthoringStepManager.java b/ccm-cms/src/main/java/org/librecms/ui/authoring/ContentItemAuthoringStepManager.java index d92a4e109..a6dcde46a 100644 --- a/ccm-cms/src/main/java/org/librecms/ui/authoring/ContentItemAuthoringStepManager.java +++ b/ccm-cms/src/main/java/org/librecms/ui/authoring/ContentItemAuthoringStepManager.java @@ -52,7 +52,7 @@ public class ContentItemAuthoringStepManager { final ContentSectionConfig config = confManager .findConfiguration(ContentSectionConfig.class); - final List classNames = config.getDefaultAuthoringSteps(); + final List classNames = Collections.emptyList(); stepInfos = classNames .stream() From 433a44afa11dc2c90db7c9b6ae201d70f2c175e3 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 16 Mar 2022 18:40:38 +0100 Subject: [PATCH 04/63] Removed depcreated package com/arsdigita/cms/ui/authoring/assets/images --- .../assets/images/AssignedImageTableRow.java | 103 ---- .../assets/images/AssignedImagesTable.java | 265 ---------- .../images/AssignedImagesTableModel.java | 119 ----- .../AssignedImagesTableModelBuilder.java | 94 ---- .../assets/images/AvailableImageTableRow.java | 101 ---- .../assets/images/AvailableImages.java | 256 ---------- .../images/AvailableImagesTableModel.java | 99 ---- .../AvailableImagesTableModelBuilder.java | 100 ---- .../assets/images/ImageProperties.java | 72 --- .../ui/authoring/assets/images/ImageStep.java | 224 --------- .../assets/images/ImageStepController.java | 474 ------------------ 11 files changed, 1907 deletions(-) delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImageTableRow.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImagesTable.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImagesTableModel.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImagesTableModelBuilder.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AvailableImageTableRow.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AvailableImages.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AvailableImagesTableModel.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AvailableImagesTableModelBuilder.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageProperties.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageStep.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageStepController.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImageTableRow.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImageTableRow.java deleted file mode 100644 index 6c95e2968..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImageTableRow.java +++ /dev/null @@ -1,103 +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.assets.images; - -/** - * A container for the data shown in the table of assigned images. - * - * @author Jens Pelzetter - */ -class AssignedImageTableRow { - - private long attachmentId; - private String imageUuid; - private String filename; - private long width; - private long height; - private String type; - private String title; - private String caption; - - public long getAttachmentId() { - return attachmentId; - } - - public void setAttachmentId(final long attachmentId) { - this.attachmentId = attachmentId; - } - - public String getImageUuid() { - return imageUuid; - } - - public void setImageUuid(final String imageUuid) { - this.imageUuid = imageUuid; - } - - public String getFilename() { - return filename; - } - - public void setFilename(final String filename) { - this.filename = filename; - } - - public long getWidth() { - return width; - } - - public void setWidth(final long width) { - this.width = width; - } - - public long getHeight() { - return height; - } - - public void setHeight(final long height) { - this.height = height; - } - - public String getType() { - return type; - } - - public void setType(final String type) { - this.type = type; - } - - public String getTitle() { - return title; - } - - public void setTitle(final String title) { - this.title = title; - } - - public String getCaption() { - return caption; - } - - public void setCaption(final String caption) { - this.caption = caption; - } - - - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImagesTable.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImagesTable.java deleted file mode 100644 index 222830168..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImagesTable.java +++ /dev/null @@ -1,265 +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.assets.images; - -import com.arsdigita.bebop.BoxPanel; -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.ControlLink; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Image; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.Text; -import com.arsdigita.bebop.event.TableActionEvent; -import com.arsdigita.bebop.event.TableActionListener; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.table.TableCellRenderer; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.bebop.table.TableColumnModel; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.authoring.assets.ItemAttachmentSelectionModel; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ItemAttachment; - -/** - * - * @author Jens Pelzetter - */ -class AssignedImagesTable extends Table { - - protected static final int COL_PREVIEW = 0; - protected static final int COL_TITLE = 1; - protected static final int COL_IMAGE_DATA = 2; - protected static final int COL_CAPTION = 3; - protected static final int COL_MOVE = 4; - protected static final int COL_REMOVE = 5; - - private final ItemSelectionModel itemSelectionModel; - private final ItemAttachmentSelectionModel moveAttachmentModel; - private final StringParameter selectedLanguageParam; - - public AssignedImagesTable( - final ItemSelectionModel itemSelectionModel, - final ItemAttachmentSelectionModel moveAttachmentModel, - final StringParameter selectedLanguageParam) { - - super(); - this.itemSelectionModel = itemSelectionModel; - this.moveAttachmentModel = moveAttachmentModel; - this.selectedLanguageParam = selectedLanguageParam; - - final TableColumnModel columnModel = super.getColumnModel(); - columnModel.add(new TableColumn( - COL_PREVIEW, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_images.preview_header", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_TITLE, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_images.title_header", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_IMAGE_DATA, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_images.properties_header", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_CAPTION, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_images.caption_header", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_MOVE, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_images.move_header", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_REMOVE, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_images.remove_header", - CmsConstants.CMS_BUNDLE)))); - - super - .setModelBuilder(new AssignedImagesTableModelBuilder( - itemSelectionModel, - moveAttachmentModel, - selectedLanguageParam)); - - super - .getColumn(COL_PREVIEW) - .setCellRenderer(new ThumbnailCellRenderer()); - super - .getColumn(COL_IMAGE_DATA) - .setCellRenderer(new PropertiesCellRenderer()); - super - .getColumn(COL_MOVE) - .setCellRenderer(new MoveCellRenderer()); - super - .getColumn(COL_REMOVE) - .setCellRenderer(new RemoveCellRenderer()); - - super.addTableActionListener(new TableActionListener() { - - @Override - public void cellSelected(final TableActionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - final TableColumn column = getColumnModel() - .get(event.getColumn()); - - switch (column.getModelIndex()) { - case COL_MOVE: - if (moveAttachmentModel.getSelectedKey(state) == null) { - - moveAttachmentModel - .setSelectedKey(state, - Long.parseLong((String) event - .getRowKey())); - } else { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ImageStepController controller = cdiUtil - .findBean(ImageStepController.class); - - final ItemAttachment selectedAttachment - = moveAttachmentModel - .getSelectedAttachment(state); - - final Long destId = Long - .parseLong((String) event.getRowKey()); - - controller.moveAfter(selectedAttachment, destId); - moveAttachmentModel.clearSelection(state); - } - break; - case COL_REMOVE: - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ImageStepController controller = cdiUtil - .findBean(ImageStepController.class); - controller.deleteAttachment(Long - .parseLong((String) event.getRowKey())); - break; - } - } - - @Override - public void headSelected(final TableActionEvent event) { - //Nothing - } - - }); - - super.setEmptyView(new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_images.none", - CmsConstants.CMS_BUNDLE))); - - } - - private class ThumbnailCellRenderer implements TableCellRenderer { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - if (value == null) { - return new Text(""); - } else { - final Image image = new Image((String) value, ""); - return image; - } - } - - } - - private class PropertiesCellRenderer implements TableCellRenderer { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - - @SuppressWarnings("unchecked") - final ImageProperties properties = (ImageProperties) value; - final BoxPanel panel = new BoxPanel(BoxPanel.VERTICAL); - - panel.add(new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_images.properties.filename", - CmsConstants.CMS_BUNDLE, - new Object[]{properties.getFilename()}))); - panel.add(new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_images.properties.size", - CmsConstants.CMS_BUNDLE, - new Object[]{properties.getWidth(), properties.getHeight()}))); - panel.add(new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_images.properties.type", - CmsConstants.CMS_BUNDLE, - new String[]{properties.getType()}))); - - return panel; - } - - } - - private class MoveCellRenderer implements TableCellRenderer { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - - return new ControlLink((Component) value); - } - - } - - private class RemoveCellRenderer implements TableCellRenderer { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - - return new ControlLink((Component) value); - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImagesTableModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImagesTableModel.java deleted file mode 100644 index a22f392e9..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImagesTableModel.java +++ /dev/null @@ -1,119 +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.assets.images; - -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.cms.CMS; -import com.arsdigita.cms.ui.authoring.assets.ItemAttachmentSelectionModel; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.web.CCMDispatcherServlet; - -import org.librecms.CmsConstants; - -import java.util.Iterator; -import java.util.List; - -/** - * - * @author Jens Pelzetter - */ -class AssignedImagesTableModel implements TableModel { - - private final PageState state; - private final ItemAttachmentSelectionModel moveAttachmentModel; - - private final Iterator iterator; - private AssignedImageTableRow currentRow; - - public AssignedImagesTableModel( - final List rows, - final PageState state, - final ItemAttachmentSelectionModel moveAttachmentModel) { - - this.iterator = rows.iterator(); - this.state = state; - this.moveAttachmentModel = moveAttachmentModel; - } - - @Override - public int getColumnCount() { - return 4; - } - - @Override - public boolean nextRow() { - if (iterator.hasNext()) { - currentRow = iterator.next(); - return true; - } else { - return false; - } - } - - @Override - public Object getElementAt(final int columnIndex) { - switch (columnIndex) { - case AssignedImagesTable.COL_PREVIEW: - return String - .format("%s/content-sections/%s/images/" - + "uuid-%s?width=150&height=100", - CCMDispatcherServlet.getContextPath(), - CMS.getContext().getContentSection().getLabel(), - currentRow.getImageUuid()); - case AssignedImagesTable.COL_IMAGE_DATA: { - final ImageProperties imageProperties = new ImageProperties(); - imageProperties.setFilename(currentRow.getFilename()); - imageProperties.setWidth(currentRow.getWidth()); - imageProperties.setHeight(currentRow.getHeight()); - imageProperties.setType(currentRow.getType()); - - return imageProperties; - } - case AssignedImagesTable.COL_TITLE: - return currentRow.getTitle(); - case AssignedImagesTable.COL_CAPTION: - return currentRow.getCaption(); - case AssignedImagesTable.COL_MOVE: - if (moveAttachmentModel.getSelectedKey(state) == null) { - return new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_image.link_move", - CmsConstants.CMS_BUNDLE)); - } else { - return new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_image.link_move_below_here", - CmsConstants.CMS_BUNDLE)); - } - case AssignedImagesTable.COL_REMOVE: - return new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_images.remove", - CmsConstants.CMS_BUNDLE)); - default: - throw new IllegalArgumentException(String.format( - "Illegal column index %d.", columnIndex)); - } - } - - @Override - public Object getKeyAt(final int columnIndex) { - return currentRow.getAttachmentId(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImagesTableModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImagesTableModelBuilder.java deleted file mode 100644 index b95ed6352..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AssignedImagesTableModelBuilder.java +++ /dev/null @@ -1,94 +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.assets.images; - -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.cms.ui.authoring.assets.ItemAttachmentSelectionModel; -import com.arsdigita.util.LockableImpl; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.contentsection.ContentItem; - -import java.util.List; -import java.util.Locale; - -/** - * Creates the {@link AssignedImagesTableModel} which is used in - * {@link ImageStep} for the table of assigned images. This - * {@link TableModelBuilder} takes the selected item and retrieves all retrieved - * images from the item. For each assigned image an instance - * {@link AssignedImageTableRow} is created. The resulting list (which might be - * empty) is than used to create the image model. This also means that all - * interaction with the database is done by this {@link TableModelBuilder}. - * - * @author Jens Pelzetter - */ -class AssignedImagesTableModelBuilder extends LockableImpl implements - TableModelBuilder { - - private final ItemSelectionModel itemSelectionModel; - private final ItemAttachmentSelectionModel moveAttachmentModel; - private final StringParameter selectedLanguageParam; - - /** - * Constructor for this {@link TableModelBuilder}. - * - * @param itemSelectionModel The model used to determine the selected - * {@link ContentItem}. - * @param selectedLanguageParam Parameter used to determine the selected - * language variant of the selected - * {@link ContentItem}. - */ - protected AssignedImagesTableModelBuilder( - final ItemSelectionModel itemSelectionModel, - final ItemAttachmentSelectionModel moveAttachmentModel, - final StringParameter selectedLanguageParam) { - - this.itemSelectionModel = itemSelectionModel; - this.moveAttachmentModel = moveAttachmentModel; - this.selectedLanguageParam = selectedLanguageParam; - } - - @Override - public TableModel makeModel(final Table table, final PageState state) { - - final ContentItem selectedItem = itemSelectionModel - .getSelectedItem(state); - final String selectedLanguage = (String) state - .getValue(selectedLanguageParam); - final Locale selectedLocale = new Locale(selectedLanguage); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ImageStepController controller = cdiUtil - .findBean(ImageStepController.class); - - final List rows = controller - .retrieveAssignedImagesRows(selectedItem, selectedLocale); - - return new AssignedImagesTableModel(rows, - state, - moveAttachmentModel); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AvailableImageTableRow.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AvailableImageTableRow.java deleted file mode 100644 index ca1411e7f..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AvailableImageTableRow.java +++ /dev/null @@ -1,101 +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.assets.images; - -/** - * A container for the data shown in the table of assigned images. - * - * @author Jens Pelzetter - */ -class AvailableImageTableRow { - - private long imageId; - private String imageUuid; - private String title; - private String filename; - private long width; - private long height; - private String type; - private String caption; - - public long getImageId() { - return imageId; - } - - public void setImageId(final long imageId) { - this.imageId = imageId; - } - - public String getImageUuid() { - return imageUuid; - } - - public void setImageUuid(final String imageUuid) { - this.imageUuid = imageUuid; - } - - public String getTitle() { - return title; - } - - public void setTitle(final String title) { - this.title = title; - } - - public String getFilename() { - return filename; - } - - public void setFilename(final String filename) { - this.filename = filename; - } - - public long getWidth() { - return width; - } - - public void setWidth(final long width) { - this.width = width; - } - - public long getHeight() { - return height; - } - - public void setHeight(final long height) { - this.height = height; - } - - public String getType() { - return type; - } - - public void setType(final String type) { - this.type = type; - } - - public String getCaption() { - return caption; - } - - public void setCaption(final String caption) { - this.caption = caption; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AvailableImages.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AvailableImages.java deleted file mode 100644 index 8b70dbeff..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AvailableImages.java +++ /dev/null @@ -1,256 +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.assets.images; - -import com.arsdigita.bebop.BoxPanel; -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.ControlLink; -import com.arsdigita.bebop.Form; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.PaginationModelBuilder; -import com.arsdigita.bebop.Paginator; -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.form.Submit; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.table.TableCellRenderer; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.bebop.table.TableColumnModel; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; - -/** - * - * @author Jens Pelzetter - */ -class AvailableImages extends BoxPanel { - - protected static final int COL_PREVIEW = 0; - protected static final int COL_TITLE = 1; - protected static final int COL_PROPERTIES = 2; - protected static final int COL_CAPTION = 3; - protected static final int COL_ADD = 4; - - public AvailableImages(final ImageStep imageStep, - final ItemSelectionModel itemSelectionModel, - final StringParameter selectedLanguageParam) { - - super(BoxPanel.VERTICAL); - - final Form filterForm = new Form("filter_available_images_form", - new BoxPanel(BoxPanel.HORIZONTAL)); - final TextField filterField = new TextField("filter_available_images"); - filterField.setLabel(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.available_images.filter_label", - CmsConstants.CMS_BUNDLE)); - final Submit submitFilter = new Submit(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.available_images.submit_filter", - CmsConstants.CMS_BUNDLE)); - filterForm.add(filterField); - filterForm.add(submitFilter); - - super.add(filterForm); - - final Paginator paginator = new Paginator(new PaginationModelBuilder() { - - @Override - public int getTotalSize(final Paginator paginator, - final PageState state) { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ImageStepController controller = cdiUtil - .findBean(ImageStepController.class); - - return (int) controller - .getNumberOfAvailableImages( - itemSelectionModel.getSelectedItem(state), - (String) filterField.getValue(state)); - } - - @Override - public boolean isVisible(final PageState state) { - return true; - } - - }, - 30); - - super.add(paginator); - - final Table table = new Table(); - final TableColumnModel columnModel = table.getColumnModel(); - columnModel.add(new TableColumn( - COL_PREVIEW, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.available_images.preview_header", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_TITLE, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.available_images.title_header", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_PROPERTIES, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.available_images.properties_header", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_CAPTION, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.available_images.caption_header", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_ADD, - new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.available_images.select_header", - CmsConstants.CMS_BUNDLE)))); - - table.setModelBuilder(new AvailableImagesTableModelBuilder( - itemSelectionModel, selectedLanguageParam, filterField, paginator)); - - table - .getColumn(COL_PREVIEW) - .setCellRenderer(new ThumbnailCellRenderer()); - table - .getColumn(COL_PROPERTIES) - .setCellRenderer(new PropertiesCellRenderer()); - table - .getColumn(COL_ADD) - .setCellRenderer(new AddCellRenderer()); - - table.setEmptyView(new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.available_images.none", - CmsConstants.CMS_BUNDLE))); - - table.addTableActionListener(new TableActionListener() { - - @Override - public void cellSelected(final TableActionEvent event) - throws FormProcessException { - - final Object rowKey = event.getRowKey(); - final long imageId; - if (rowKey instanceof Long) { - imageId = (Long) event.getRowKey(); - } else if(rowKey instanceof String) { - imageId = Long.parseLong((String) rowKey); - } else { - imageId = Long.parseLong(rowKey.toString()); - } - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ImageStepController controller = cdiUtil - .findBean(ImageStepController.class); - controller - .attachImage(itemSelectionModel - .getSelectedItem(event.getPageState()), - imageId); - - imageStep.showAssignedImages(event.getPageState()); - } - - @Override - public void headSelected(final TableActionEvent event) { - //Nothing - } - - }); - - super.add(table); - } - - private class ThumbnailCellRenderer implements TableCellRenderer { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - if (value == null) { - return new Text(""); - } else { - final com.arsdigita.bebop.Image image - = new com.arsdigita.bebop.Image( - (String) value, ""); - return image; - } - } - - } - - private class PropertiesCellRenderer implements TableCellRenderer { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - - @SuppressWarnings("unchecked") - final ImageProperties properties = (ImageProperties) value; - final BoxPanel panel = new BoxPanel(BoxPanel.VERTICAL); - - panel.add(new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_images.properties.filename", - CmsConstants.CMS_BUNDLE, - new Object[]{properties.getFilename()}))); - panel.add(new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_images.properties.size", - CmsConstants.CMS_BUNDLE, - new Object[]{properties.getWidth(), properties.getHeight()}))); - panel.add(new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_images.properties.type", - CmsConstants.CMS_BUNDLE, - new String[]{properties.getType()}))); - - return panel; - } - - } - - private class AddCellRenderer implements TableCellRenderer { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - - return new ControlLink((Component) value); - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AvailableImagesTableModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AvailableImagesTableModel.java deleted file mode 100644 index acc3eb2ff..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AvailableImagesTableModel.java +++ /dev/null @@ -1,99 +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.assets.images; - -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.cms.CMS; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.web.CCMDispatcherServlet; - -import org.librecms.CmsConstants; - -import java.util.Iterator; -import java.util.List; - -/** - * - * @author Jens Pelzetter - */ -class AvailableImagesTableModel implements TableModel { - - private final Iterator iterator; - private AvailableImageTableRow currentRow; - - public AvailableImagesTableModel(final List rows) { - iterator = rows.iterator(); - } - - @Override - public int getColumnCount() { - return 4; - } - - @Override - public boolean nextRow() { - if (iterator.hasNext()) { - currentRow = iterator.next(); - return true; - } else { - return false; - } - } - - @Override - public Object getElementAt(final int columnIndex) { - - switch (columnIndex) { - case AvailableImages.COL_PREVIEW: - return String - .format("%s/content-sections/%s/images/" - + "uuid-%s?width=150&height=100", - CCMDispatcherServlet.getContextPath(), - CMS.getContext().getContentSection().getLabel(), - currentRow.getImageUuid()); - case AvailableImages.COL_TITLE: - return currentRow.getTitle(); - case AvailableImages.COL_PROPERTIES: - final ImageProperties imageProperties = new ImageProperties(); - imageProperties.setFilename(currentRow.getFilename()); - imageProperties.setWidth(currentRow.getWidth()); - imageProperties.setHeight(currentRow.getHeight()); - imageProperties.setType(currentRow.getType()); - - return imageProperties; - case AvailableImages.COL_CAPTION: - return currentRow.getCaption(); - case AvailableImages.COL_ADD: - return new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.available_images.add", - CmsConstants.CMS_BUNDLE)); - default: - throw new IllegalArgumentException(String.format( - "Illegal column index %d.", columnIndex)); - } - - } - - @Override - public Object getKeyAt(final int columnIndex) { - return currentRow.getImageId(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AvailableImagesTableModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AvailableImagesTableModelBuilder.java deleted file mode 100644 index a2e98a427..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/AvailableImagesTableModelBuilder.java +++ /dev/null @@ -1,100 +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.assets.images; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Paginator; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.form.TextField; -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.libreccm.cdi.utils.CdiUtil; -import org.librecms.assets.Image; -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ItemAttachment; - -import java.util.List; -import java.util.Locale; -import java.util.stream.Collectors; - -/** - * - * @author Jens Pelzetter - */ -public class AvailableImagesTableModelBuilder - extends LockableImpl - implements TableModelBuilder { - - private final ItemSelectionModel itemSelectionModel; - private final StringParameter selectedLanguageParam; - private final TextField filterField; - private final Paginator paginator; - - public AvailableImagesTableModelBuilder( - final ItemSelectionModel itemSelectionModel, - final StringParameter selectedLanguageParam, - final TextField filterField, - final Paginator paginator) { - - this.itemSelectionModel = itemSelectionModel; - this.selectedLanguageParam = selectedLanguageParam; - this.filterField = filterField; - this.paginator = paginator; - } - - @Override - public TableModel makeModel(final Table table, - final PageState state) { - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ImageStepController controller = cdiUtil - .findBean(ImageStepController.class); - - final ContentItem selectedItem = itemSelectionModel - .getSelectedItem(state); - - final List> imageAttachments = controller - .retrieveAssignedImages(selectedItem); - - final List excludedImages = imageAttachments - .stream() - .map(attachment -> attachment.getAsset()) - .collect(Collectors.toList()); - - //Paginator count from 1, JPA from 0 - final int firstResult = paginator.getFirst(state) - 1; - final int maxResults = paginator.getPageSize(state); - - final Locale selectedLocale = new Locale((String) state.getValue(selectedLanguageParam)); - - final List rows = controller - .getAvailableImageRows(excludedImages, - selectedLocale, - (String) filterField.getValue(state), - firstResult, - maxResults); - - return new AvailableImagesTableModel(rows); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageProperties.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageProperties.java deleted file mode 100644 index a8b8581ea..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageProperties.java +++ /dev/null @@ -1,72 +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.assets.images; - -/** - * - * @author Jens Pelzetter - */ -class ImageProperties { - - protected static final String IMAGE_DATA_FILE_NAME = "filename"; - protected static final String IMAGE_DATA_WIDTH = "width"; - protected static final String IMAGE_DATA_HEIGHT = "height"; - protected static final String IMAGE_DATA_TYPE = "type"; - - private String filename; - - private long width; - - private long height; - - private String type; - - public String getFilename() { - return filename; - } - - public void setFilename(final String filename) { - this.filename = filename; - } - - public long getWidth() { - return width; - } - - public void setWidth(final long width) { - this.width = width; - } - - public long getHeight() { - return height; - } - - public void setHeight(final long height) { - this.height = height; - } - - public String getType() { - return type; - } - - public void setType(final String type) { - this.type = type; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageStep.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageStep.java deleted file mode 100644 index e045f90ac..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageStep.java +++ /dev/null @@ -1,224 +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.assets.images; - -import com.arsdigita.bebop.ActionLink; -import com.arsdigita.bebop.BoxPanel; -import com.arsdigita.bebop.ControlLink; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.Page; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.parameters.LongParameter; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.authoring.AuthoringKitWizard; -import com.arsdigita.cms.ui.authoring.ResettableContainer; -import com.arsdigita.cms.ui.authoring.assets.ItemAttachmentSelectionModel; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.kernel.KernelConfig; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ItemAttachment; -import org.librecms.ui.authoring.ContentItemAuthoringStep; - -import java.util.Locale; - -/** - * - * @author Jens Pelzetter - */ -@ContentItemAuthoringStep( - labelBundle = CmsConstants.CMS_BUNDLE, - labelKey = "image_step.label", - descriptionBundle = CmsConstants.CMS_BUNDLE, - descriptionKey = "image_step.description") -public class ImageStep extends ResettableContainer { - - public static final String IMAGES_ATTACHMENT_LIST = ".images"; - - private final LongParameter moveAttachmentParam; - private final ItemAttachmentSelectionModel moveAttachmentModel; - - private final Label assignedImagesHeader; - private final ControlLink addImageLink; - private final ActionLink beginLink; - private final Table assignedImagesTable; - private final Label addImageHeader; - private final AvailableImages availableImages; - private final ControlLink cancelAddImage; - - public ImageStep(final ItemSelectionModel itemSelectionModel, - final AuthoringKitWizard authoringKitWizard, - final StringParameter selectedLanguageParam) { - - super(); - - moveAttachmentParam = new LongParameter("moveAttachment"); - moveAttachmentModel = new ItemAttachmentSelectionModel( - moveAttachmentParam); - - assignedImagesHeader = new Label(event -> { - final PageState state = event.getPageState(); - final Label target = (Label) event.getTarget(); - - final ContentItem selectedItem = itemSelectionModel - .getSelectedItem(state); - final String selectedLanguage = (String) state - .getValue(selectedLanguageParam); - final Locale selectedLocale = new Locale(selectedLanguage); - final String title; - if (selectedItem.getTitle().hasValue(selectedLocale)) { - title = selectedItem.getTitle().getValue(selectedLocale); - } else { - title = selectedItem.getTitle().getValue(KernelConfig - .getConfig() - .getDefaultLocale()); - } - - target.setLabel(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.heading", - CmsConstants.CMS_BUNDLE, - new String[]{title})); - }); - assignedImagesHeader.setClassAttr(""); - - addImageHeader = new Label(event -> { - final PageState state = event.getPageState(); - final Label target = (Label) event.getTarget(); - - final ContentItem selectedItem = itemSelectionModel - .getSelectedItem(state); - final String selectedLanguage = (String) state - .getValue(selectedLanguageParam); - final Locale selectedLocale = new Locale(selectedLanguage); - final String title; - if (selectedItem.getTitle().hasValue(selectedLocale)) { - title = selectedItem.getTitle().getValue(selectedLocale); - } else { - title = selectedItem.getTitle().getValue(KernelConfig - .getConfig() - .getDefaultLocale()); - } - - target.setLabel(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.add_heading", - CmsConstants.CMS_BUNDLE, - new String[]{title})); - }); - - addImageLink = new ActionLink(new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_images.add_image", - CmsConstants.CMS_BUNDLE))); - addImageLink.addActionListener(event -> { - showAvailableImages(event.getPageState()); - }); - - beginLink = new ActionLink(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_images.move_to_beginning", - CmsConstants.CMS_BUNDLE)); - - beginLink.addActionListener(event -> { - final PageState state = event.getPageState(); - final ItemAttachment toMove = moveAttachmentModel - .getSelectedAttachment(state); - - final ImageStepController controller = CdiUtil - .createCdiUtil() - .findBean(ImageStepController.class); - - controller.moveToFirst(toMove); - - moveAttachmentModel.clearSelection(state); - }); - - assignedImagesTable = new AssignedImagesTable(itemSelectionModel, - moveAttachmentModel, - selectedLanguageParam); - - cancelAddImage = new ControlLink(new Label(new GlobalizedMessage( - "cms.ui.authoring.assets.imagestep.assigned_images.cancel_add_image", - CmsConstants.CMS_BUNDLE))); - cancelAddImage.addActionListener(event -> { - showAssignedImages(event.getPageState()); - }); - - availableImages = new AvailableImages(this, - itemSelectionModel, - selectedLanguageParam); - - final BoxPanel panel = new BoxPanel(BoxPanel.VERTICAL); - panel.add(assignedImagesHeader); - panel.add(addImageLink); - panel.add(beginLink); - panel.add(assignedImagesTable); - panel.add(addImageHeader); - panel.add(availableImages); - super.add(panel); - - moveAttachmentModel.addChangeListener(event -> { - - final PageState state = event.getPageState(); - - if (moveAttachmentModel.getSelectedKey(state) == null) { - addImageLink.setVisible(state, true); - beginLink.setVisible(state, false); - } else { - addImageLink.setVisible(state, false); - beginLink.setVisible(state, true); - } - }); - } - - @Override - public void register(final Page page) { - super.register(page); - - page.setVisibleDefault(assignedImagesHeader, true); - page.setVisibleDefault(addImageLink, true); - page.setVisibleDefault(beginLink, false); - page.setVisibleDefault(assignedImagesTable, true); - page.setVisibleDefault(addImageHeader, false); - page.setVisibleDefault(cancelAddImage, false); - page.setVisibleDefault(availableImages, false); - - page.addComponentStateParam(assignedImagesTable, moveAttachmentParam); - } - - protected void showAssignedImages(final PageState state) { - assignedImagesHeader.setVisible(state, true); - addImageLink.setVisible(state, true); - assignedImagesTable.setVisible(state, true); - addImageHeader.setVisible(state, false); - - availableImages.setVisible(state, false); - } - - protected void showAvailableImages(final PageState state) { - assignedImagesHeader.setVisible(state, false); - addImageLink.setVisible(state, false); - assignedImagesTable.setVisible(state, false); - addImageHeader.setVisible(state, true); - cancelAddImage.setVisible(state, true); - availableImages.setVisible(state, true); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageStepController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageStepController.java deleted file mode 100644 index c20818a36..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/images/ImageStepController.java +++ /dev/null @@ -1,474 +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.assets.images; - -import com.arsdigita.kernel.KernelConfig; - -import org.libreccm.configuration.ConfigurationManager; -import org.libreccm.l10n.LocalizedString; -import org.librecms.assets.Image; -import org.librecms.contentsection.AssetRepository; -import org.librecms.contentsection.AttachmentList; -import org.librecms.contentsection.AttachmentListManager; -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.contentsection.ItemAttachment; -import org.librecms.contentsection.ItemAttachmentManager; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Locale; -import java.util.Objects; -import java.util.stream.Collectors; - -import javax.annotation.PostConstruct; -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.persistence.EntityManager; -import javax.persistence.TypedQuery; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Join; -import javax.persistence.criteria.Root; -import javax.transaction.Transactional; - -/** - * Encapsulates all interaction between the {@link ImageStep} and associated - * classes like the {@link ImageStepTableModelBuilder} and CDI beans. - * - * @author Jens Pelzetter - */ -@RequestScoped -class ImageStepController { - - @Inject - private AssetRepository assetRepo; - - @Inject - private AttachmentListManager attachmentListManager; - - @Inject - private ItemAttachmentManager attachmentManager; - - @Inject - private ConfigurationManager confManager; - - @Inject - private EntityManager entityManager; - - @Inject - private ContentItemRepository itemRepo; - - private Locale defaultLocale; - - @PostConstruct - private void init() { - - final KernelConfig kernelConfig = confManager - .findConfiguration(KernelConfig.class); - defaultLocale = kernelConfig.getDefaultLocale(); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected List> retrieveAssignedImages( - final ContentItem fromContentItem) { - - Objects.requireNonNull(fromContentItem); - - final ContentItem item = itemRepo - .findById(fromContentItem.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No ContentItem with id %d in the database.", - fromContentItem.getObjectId()))); - - final List imageLists = attachmentListManager - .getAttachmentList(item, ImageStep.IMAGES_ATTACHMENT_LIST); - - if (imageLists.isEmpty()) { - return Collections.emptyList(); - } - - final List> attachments = new ArrayList<>(); - for (final AttachmentList imageList : imageLists) { - for (final ItemAttachment attachment : imageList.getAttachments()) { - attachments.add(attachment); - } - } - - @SuppressWarnings("unchecked") - final List> imageAttachments = attachments - .stream() - .sorted((attachment1, attachment2) -> { - return attachment1.compareTo(attachment2); - }) - .filter(attachment -> attachment.getAsset() instanceof Image) - .map(attachment -> (ItemAttachment) attachment) - .collect(Collectors.toList()); - - return imageAttachments; - } - - @Transactional(Transactional.TxType.REQUIRED) - protected List retrieveAssignedImagesRows( - final ContentItem fromContentItem, final Locale selectedLocale) { - -// Objects.requireNonNull(fromContentItem); -// Objects.requireNonNull(selectedLocale); -// -// final ContentItem item = itemRepo -// .findById(fromContentItem.getObjectId()) -// .orElseThrow(() -> new IllegalArgumentException(String -// .format("No ContentItem with id %d in the database.", -// fromContentItem.getObjectId()))); -// -// final List imageLists = attachmentListManager -// .getAttachmentList(item, ImageStep.IMAGES_ATTACHMENT_LIST); -// -// if (imageLists.isEmpty()) { -// return Collections.emptyList(); -// } -// -// final List> attachments = new ArrayList<>(); -// for (final AttachmentList imageList : imageLists) { -// for (final ItemAttachment attachment : imageList.getAttachments()) { -// attachments.add(attachment); -// } -// } - final List> imageAttachments - = retrieveAssignedImages( - fromContentItem); - -// @SuppressWarnings("unchecked") -// final List rows = attachments -// .stream() -// .sorted((attachment1, attachment2) -> { -// return attachment1.compareTo(attachment2); -// }) -// .filter(attachment -> attachment.getAsset() instanceof Image) -// .map(attachment -> (ItemAttachment) attachment) -// .map(imageAttachment -> buildAssignedImageTableRow(imageAttachment, -// selectedLocale)) -// .collect(Collectors.toList()); -// -// return rows; - return imageAttachments - .stream() - .map(imageAttachment -> buildAssignedImageTableRow(imageAttachment, - selectedLocale)) - .collect(Collectors.toList()); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void moveToFirst(final ItemAttachment attachmentToMove) { - - Objects.requireNonNull(attachmentToMove); - - final ItemAttachment toMove = attachmentManager - .findById(attachmentToMove.getAttachmentId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No ItemAttachment with ID %d in the database.", - attachmentToMove.getAttachmentId()))); - - final AttachmentList attachmentList = toMove.getAttachmentList(); - final List> attachments = attachmentList - .getAttachments() - .stream() - .sorted((attachment1, attachment2) -> { - return attachment1.compareTo(attachment2); - }) - .collect(Collectors.toList()); - - toMove.setSortKey(0); - attachments - .stream() - .filter(current -> !current.equals(toMove)) - .forEach(current -> current.setSortKey(current.getSortKey() + 1)); - - attachments - .forEach(current -> entityManager.merge(current)); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void moveAfter(final ItemAttachment attachmentToMove, - final long destId) { - - Objects.requireNonNull(attachmentToMove); - - final ItemAttachment toMove = attachmentManager - .findById(attachmentToMove.getAttachmentId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No ItemAttachment with ID %d in the database.", - attachmentToMove.getAttachmentId()))); - - final ItemAttachment after = attachmentManager - .findById(destId) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No ItemAttachment with ID %d in the database.", - attachmentToMove.getAttachmentId()))); - - final AttachmentList attachmentList = toMove.getAttachmentList(); - final List> attachments = attachmentList - .getAttachments() - .stream() - .sorted((attachment1, attachment2) -> { - return attachment1.compareTo(attachment2); - }) - .collect(Collectors.toList()); - - if (!attachments.contains(toMove)) { - throw new IllegalArgumentException(String.format( - "ItemAttachment %d is not part of AttachmentList %d.", - toMove.getAttachmentId(), - attachmentList.getListId())); - } - - if (!attachments.contains(after)) { - throw new IllegalArgumentException(String.format( - "ItemAttachment %d is not part of AttachmentList %d.", - after.getAttachmentId(), - attachmentList.getListId())); - } - - final int afterIndex = attachments.indexOf(after); - for (int i = afterIndex + 1; i < attachments.size(); i++) { - final ItemAttachment current = attachments.get(i); - current.setSortKey(current.getSortKey() + 1); - entityManager.merge(current); - } - - toMove.setSortKey(afterIndex + 1); - entityManager.merge(toMove); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void deleteAttachment(final long attachmentId) { - - final ItemAttachment attachment = attachmentManager - .findById(attachmentId) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No ItemAttachment with ID %d in the database.", - attachmentId))); - - deleteAttachment(attachment); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void deleteAttachment(final ItemAttachment attachment) { - - Objects.requireNonNull(attachment); - - final ItemAttachment toRemove = attachmentManager - .findById(attachment.getAttachmentId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No ItemAttachment with ID %d in the database.", - attachment.getAttachmentId()))); - - entityManager.remove(toRemove); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected long getNumberOfAvailableImages(final ContentItem selectedItem, - final String filter) { - - Objects.requireNonNull(selectedItem); - - final ContentItem item = itemRepo - .findById(selectedItem.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No ContentItem with ID %d in the database.", - selectedItem.getObjectId()))); - - final List> imageAttachments - = retrieveAssignedImages(item); - final List excluededImages = imageAttachments - .stream() - .map(imageAttachment -> imageAttachment.getAsset()) - .collect(Collectors.toList()); - - final CriteriaBuilder criteriaBuilder = entityManager - .getCriteriaBuilder(); - - final CriteriaQuery query = criteriaBuilder - .createQuery(Long.class); - final Root from = query.from(Image.class); - final Join titleJoin = from.join("title"); - final Join titleValuesJoin = titleJoin.join("values"); - - query - .select(criteriaBuilder.count(from)); - - if (filter == null || filter.trim().isEmpty()) { - if (excluededImages != null && !excluededImages.isEmpty()) { - query.where(criteriaBuilder.not(from.in(excluededImages))); - } - } else { - if (excluededImages == null || excluededImages.isEmpty()) { - query.where(criteriaBuilder.like(titleValuesJoin, - String.format("%s%%", filter))); - } else { - query.where(criteriaBuilder.and( - criteriaBuilder.not(from.in(excluededImages)), - criteriaBuilder.like(titleValuesJoin, - String.format("%s%%", filter)))); - } - } - - final long result = entityManager.createQuery(query) - .getSingleResult(); - return result; - } - - @Transactional(Transactional.TxType.REQUIRED) - protected List getAvailableImages(final List excludedImages, - final String filter, - final long firstImage, - final long maxImages) { - - final CriteriaBuilder criteriaBuilder = entityManager - .getCriteriaBuilder(); - - final CriteriaQuery criteriaQuery = criteriaBuilder - .createQuery(Image.class); - final Root from = criteriaQuery.from(Image.class); - final Join titleJoin = from.join("title"); - final Join titleValuesJoin = titleJoin.join("values"); - - if (filter == null || filter.trim().isEmpty()) { - if (excludedImages != null && !excludedImages.isEmpty()) { - criteriaQuery.where(criteriaBuilder.not(from.in( - excludedImages))); - } - } else { - if (excludedImages == null || excludedImages.isEmpty()) { - criteriaQuery - .where(criteriaBuilder.like(titleValuesJoin, - String.format("%s%%", filter))); - } else { - criteriaQuery.where(criteriaBuilder.and( - criteriaBuilder.not(from.in(excludedImages)), - criteriaBuilder.like(titleValuesJoin, - String.format("%s%%", filter)))); - } - } - - final TypedQuery query = entityManager - .createQuery(criteriaQuery); - query.setFirstResult((int) firstImage); - query.setMaxResults((int) maxImages); - - final List result = query.getResultList(); - return result; - - } - - @Transactional(Transactional.TxType.REQUIRED) - protected List getAvailableImageRows( - final List excludedImages, - final Locale selectedLocale, - final String filter, - final long firstImage, - final long lastImage - ) { - - return getAvailableImages(excludedImages, filter, firstImage, - lastImage) - .stream() - .map(image -> buildAvailableImageRow(image, selectedLocale)) - .collect(Collectors.toList()); - - } - - private AvailableImageTableRow buildAvailableImageRow( - final Image image, final Locale selectedLocale) { - final AvailableImageTableRow row = new AvailableImageTableRow(); - row.setImageId(image.getObjectId()); - row.setImageUuid(image.getUuid()); - if (image.getTitle().hasValue(selectedLocale)) { - row.setTitle(image.getTitle().getValue(selectedLocale)); - } else if (image.getTitle().hasValue(defaultLocale)) { - row.setTitle(image.getTitle().getValue(defaultLocale)); - } else { - row.setTitle(image.getTitle().getValue()); - } - row.setFilename(image.getFileName()); - row.setWidth(image.getWidth()); - row.setHeight(image.getHeight()); - row.setType(image.getMimeType().toString()); - - return row; - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void attachImage(final ContentItem contentItem, - final long imageId) { - - final ContentItem item = itemRepo - .findById(contentItem.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No ContentItem with ID %d in the database.", - contentItem.getObjectId()))); - - final List list = attachmentListManager - .getAttachmentList(item, ImageStep.IMAGES_ATTACHMENT_LIST); - - final AttachmentList addTo; - if (list == null || list.isEmpty()) { - addTo = attachmentListManager - .createAttachmentList(item, ImageStep.IMAGES_ATTACHMENT_LIST); - } else { - addTo = list.get(0); - } - - final Image image = assetRepo - .findById(imageId, Image.class) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No Image with ID %d in the database.", - imageId))); - - attachmentManager.attachAsset(image, addTo); - } - - private AssignedImageTableRow buildAssignedImageTableRow( - final ItemAttachment imageAttachment, - final Locale selectedLocale) { - - final AssignedImageTableRow row = new AssignedImageTableRow(); - - row.setAttachmentId(imageAttachment.getAttachmentId()); - - final Image image = imageAttachment.getAsset(); - row.setImageUuid(image.getUuid()); - row.setFilename(image.getFileName()); - row.setWidth(image.getWidth()); - row.setHeight(image.getHeight()); - row.setType(image.getMimeType().toString()); - if (image.getTitle().hasValue(selectedLocale)) { - row.setTitle(image.getTitle().getValue(selectedLocale)); - } else if (image.getTitle().hasValue(defaultLocale)) { - row.setTitle(image.getTitle().getValue(defaultLocale)); - } else { - row.setTitle(image.getTitle().getValue()); - } - row.setCaption(image.getDescription().getValue(selectedLocale)); - - return row; - } - -} From 4bb0117366bfe44d7bf2a8e85713335e0e384fa7 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 16 Mar 2022 19:13:09 +0100 Subject: [PATCH 05/63] Removed deprecated package com/arsdigita/cms/ui/authoring/assets --- .../assets/AttachmentListSelectionModel.java | 106 ------------------ .../assets/AttachmentSelectionModel.java | 105 ----------------- .../assets/ItemAttachmentSelectionModel.java | 104 ----------------- 3 files changed, 315 deletions(-) delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/AttachmentListSelectionModel.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/AttachmentSelectionModel.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/ItemAttachmentSelectionModel.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/AttachmentListSelectionModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/AttachmentListSelectionModel.java deleted file mode 100644 index b47f0a79d..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/AttachmentListSelectionModel.java +++ /dev/null @@ -1,106 +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.assets; - -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.librecms.contentsection.AttachmentList; -import org.librecms.contentsection.AttachmentListManager; - -/** - * - * @author Jens Pelzetter - */ -public class AttachmentListSelectionModel implements - SingleSelectionModel { - - private final SingleSelectionModel model; - - public AttachmentListSelectionModel(final LongParameter parameter) { - this.model = new ParameterSingleSelectionModel<>(parameter); - } - - public AttachmentListSelectionModel(final String parameterName) { - this(new LongParameter(parameterName)); - } - - @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 AttachmentList getSelectedAttachmentList(final PageState state) { - final Long key = getSelectedKey(state); - if (key == null) { - return null; - } else { - final AttachmentListManager manager = CdiUtil - .createCdiUtil() - .findBean(AttachmentListManager.class); - return manager.getAttachmentList(key).get(); - } - } - - @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/assets/AttachmentSelectionModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/AttachmentSelectionModel.java deleted file mode 100644 index ca120633a..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/AttachmentSelectionModel.java +++ /dev/null @@ -1,105 +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.assets; - -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.librecms.contentsection.ItemAttachment; -import org.librecms.contentsection.ItemAttachmentManager; - -/** - * - * @author Jens Pelzetter - */ -public class AttachmentSelectionModel implements SingleSelectionModel { - - private final SingleSelectionModel model; - - public AttachmentSelectionModel(final LongParameter parameter) { - this.model = new ParameterSingleSelectionModel<>(parameter); - } - - public AttachmentSelectionModel(final String parameterName) { - this(new LongParameter(parameterName)); - } - - @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 ItemAttachment getSelectedAttachment(final PageState state) { - final Long key = getSelectedKey(state); - if (key == null) { - return null; - } else { - final ItemAttachmentManager manager = CdiUtil - .createCdiUtil() - .findBean(ItemAttachmentManager.class); - return manager.findById(key).get(); - } - } - - @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/assets/ItemAttachmentSelectionModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/ItemAttachmentSelectionModel.java deleted file mode 100644 index 4e1c0c4a1..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/assets/ItemAttachmentSelectionModel.java +++ /dev/null @@ -1,104 +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.assets; - -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.librecms.contentsection.ItemAttachment; -import org.librecms.contentsection.ItemAttachmentManager; - -/** - * - * @author Jens Pelzetter - */ -public class ItemAttachmentSelectionModel implements SingleSelectionModel { - - private final SingleSelectionModel model; - - public ItemAttachmentSelectionModel(final LongParameter parameter) { - this.model = new ParameterSingleSelectionModel<>(parameter); - } - - public ItemAttachmentSelectionModel(final String parameterName) { - this(new LongParameter(parameterName)); - } - - @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 ItemAttachment getSelectedAttachment(final PageState state) { - final Long key = getSelectedKey(state); - if (key == null) { - return null; - } else { - final ItemAttachmentManager manager = CdiUtil - .createCdiUtil() - .findBean(ItemAttachmentManager.class); - return manager.findById(key).get(); - } - } - - @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(); - } - -} From 6bfa90616b80b8499faae85368daaae2ea51d9ad Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 16 Mar 2022 19:33:16 +0100 Subject: [PATCH 06/63] Removed depcreated package com/arsdigita/cms/ui/assets from ccm-cms --- .../arsdigita/cms/ui/ContentSectionPage.java | 17 +- .../cms/ui/assets/AbstractAssetForm.java | 433 ------ .../assets/AbstractAssetFormController.java | 263 ---- .../cms/ui/assets/AssetFolderBrowser.java | 446 ------ .../assets/AssetFolderBrowserController.java | 638 --------- ...etFolderBrowserPaginationModelBuilder.java | 65 - .../assets/AssetFolderBrowserTableModel.java | 110 -- .../AssetFolderBrowserTableModelBuilder.java | 101 -- .../ui/assets/AssetFolderBrowserTableRow.java | 148 -- .../cms/ui/assets/AssetFormController.java | 107 -- .../cms/ui/assets/AssetFormControllers.java | 82 -- .../arsdigita/cms/ui/assets/AssetPane.java | 1229 ----------------- .../cms/ui/assets/AssetSearchWidget.java | 114 -- .../assets/AssetSearchWidgetController.java | 82 -- .../ui/assets/IsControllerForAssetType.java | 46 - .../cms/ui/assets/ItemSearchWidget.java | 119 -- .../java/org/librecms/assets/AssetType.java | 1 - .../org/librecms/assets/AssetTypeInfo.java | 59 +- .../librecms/contentsection/rs/Assets.java | 4 +- 19 files changed, 29 insertions(+), 4035 deletions(-) delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AbstractAssetForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AbstractAssetFormController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowser.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserPaginationModelBuilder.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserTableModel.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserTableModelBuilder.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserTableRow.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFormController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFormControllers.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetPane.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchWidget.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchWidgetController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/IsControllerForAssetType.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/ItemSearchWidget.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java index e7cd7552f..df3d9b518 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java @@ -35,7 +35,6 @@ import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentSection; import com.arsdigita.cms.dispatcher.CMSPage; -import com.arsdigita.cms.ui.assets.AssetPane; import com.arsdigita.cms.ui.category.CategoryAdminPane; //ToDo NG import com.arsdigita.cms.ui.category.CategoryAdminPane; import com.arsdigita.cms.ui.cse.ContentSoonExpiredPane; @@ -123,7 +122,7 @@ public class ContentSectionPage extends CMSPage implements ActionListener { private FolderAdminPane m_folderPane; private BrowsePane m_browsePane; private ItemSearch m_searchPane; - private AssetPane m_assetPane; +// private AssetPane m_assetPane; //ToDo NG private ImagesPane m_imagesPane; private RoleAdminPane m_rolePane; private WorkflowAdminPane m_workflowPane; @@ -261,13 +260,13 @@ public class ContentSectionPage extends CMSPage implements ActionListener { return m_searchPane; } - protected AssetPane getAssetPane() { - if (m_assetPane == null) { - m_assetPane = new AssetPane(); - } - - return m_assetPane; - } +// protected AssetPane getAssetPane() { +// if (m_assetPane == null) { +// m_assetPane = new AssetPane(); +// } +// +// return m_assetPane; +// } // ToDo NG // protected ImagesPane getImagesPane() { diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AbstractAssetForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AbstractAssetForm.java deleted file mode 100644 index 87eaae99c..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AbstractAssetForm.java +++ /dev/null @@ -1,433 +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.assets; - -import com.arsdigita.bebop.BoxPanel; -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.SingleSelectionModel; -import com.arsdigita.bebop.Text; -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.PrintEvent; -import com.arsdigita.bebop.event.PrintListener; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.form.SingleSelect; -import com.arsdigita.bebop.form.Submit; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.kernel.KernelConfig; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; -import org.librecms.contentsection.Asset; - -import org.libreccm.core.UnexpectedErrorException; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.TooManyListenersException; - -/** - * Basic Form for manipulating assets. - * - * @author Jens Pelzetter - * @param The type of the asset. - */ -public abstract class AbstractAssetForm - extends Form implements FormInitListener, - FormProcessListener, - FormSubmissionListener { - - private static final String ASSET_TITLE = "asset-name"; - - private static final String ASSET_NAME = "asset-title"; - - private final AssetPane assetPane; - - private final SingleSelectionModel selectionModel; - - private BoxPanel showLocalePanel; - - private SingleSelect showLocaleSelect; - - private Submit showLocaleSubmit; - - private BoxPanel addLocalePanel; - - private SingleSelect addLocaleSelect; - - private Submit addLocaleSubmit; - - private TextField name; - - private TextField title; - - private SaveCancelSection saveCancelSection; - - public AbstractAssetForm(final AssetPane assetPane) { - super("asset-form", new ColumnPanel(1)); - - this.assetPane = assetPane; - selectionModel = assetPane.getSelectedAssetModel(); - - initComponents(); - } - - private void initComponents() { - - showLocalePanel = new BoxPanel(BoxPanel.HORIZONTAL); - final Label showLocaleLabel = new Label(new PrintListener() { - - @Override - public void prepare(final PrintEvent event) { - final PageState state = event.getPageState(); - final Long selectedAssetId = getSelectedAssetId(state); - final Label target = (Label) event.getTarget(); - if (selectedAssetId == null) { - target.setLabel(new GlobalizedMessage( - "cms.ui.asset.initial_locale", - CmsConstants.CMS_BUNDLE)); - } else { - target.setLabel(new GlobalizedMessage( - "cms.ui.asset.show_locale", - CmsConstants.CMS_BUNDLE)); - } - } - - }); - showLocaleSelect = new SingleSelect("selected-locale"); - try { - showLocaleSelect.addPrintListener(new PrintListener() { - - @Override - public void prepare(final PrintEvent event) { - final PageState state = event.getPageState(); - - final Long selectedAssetId = getSelectedAssetId(state); - if (selectedAssetId == null) { - final SingleSelect target = (SingleSelect) event - .getTarget(); - - target.clearOptions(); - - final List langs = new ArrayList<>( - KernelConfig.getConfig().getSupportedLanguages()); - langs.sort((lang1, lang2) -> lang1.compareTo(lang2)); - - langs.forEach(lang -> { - target.addOption(new Option(lang, new Text(lang))); - }); - } else { - final SingleSelect target = (SingleSelect) event - .getTarget(); - - target.clearOptions(); - - final List availableLocales = getController() - .availableLocales(selectedAssetId, - getAssetClass()); - availableLocales.sort((locale1, locale2) -> { - return locale1.toString().compareTo(locale2 - .toString()); - }); - availableLocales.forEach(locale -> target.addOption( - new Option(locale.toString(), - new Text(locale.toString())))); - } - } - - }); - } catch (TooManyListenersException ex) { - throw new UnexpectedErrorException(ex); - } - showLocaleSubmit = new Submit(new GlobalizedMessage( - "cms.ui.asset.show_locale", - CmsConstants.CMS_BUNDLE)) { - - @Override - public boolean isVisible(final PageState state) { - return getSelectedAssetId(state) != null; - } - - }; - showLocalePanel.add(showLocaleLabel); - showLocalePanel.add(showLocaleSelect); - showLocalePanel.add(showLocaleSubmit); - add(showLocalePanel); - - addLocalePanel = new BoxPanel(BoxPanel.HORIZONTAL) { - - @Override - public boolean isVisible(final PageState state) { - return getSelectedAssetId(state) != null; - } - - }; - final Label addLocaleLabel = new Label( - new GlobalizedMessage("cms.ui.asset.add_locale", - CmsConstants.CMS_BUNDLE)); - addLocaleSelect = new SingleSelect("add-locale-select"); - try { - addLocaleSelect.addPrintListener(new PrintListener() { - - @Override - public void prepare(final PrintEvent event) { - final PageState state = event.getPageState(); - - final Long selectedAssetId = getSelectedAssetId(state); - if (selectedAssetId != null) { - final SingleSelect target = (SingleSelect) event - .getTarget(); - - target.clearOptions(); - - final List creatableLocales = getController() - .creatableLocales(selectedAssetId, - getAssetClass()); - creatableLocales.sort((locale1, locale2) -> { - return locale1 - .toString() - .compareTo(locale2.toString()); - }); - creatableLocales.forEach(locale -> target.addOption( - new Option(locale.toString(), - new Text(locale.toString())))); - } - } - - }); - } catch (TooManyListenersException ex) { - throw new UnexpectedErrorException(ex); - } - addLocaleSubmit = new Submit(new GlobalizedMessage( - "cms.ui.asset.add_locale", - CmsConstants.CMS_BUNDLE)); - addLocalePanel.add(addLocaleLabel); - addLocalePanel.add(addLocaleSelect); - addLocalePanel.add(addLocaleSubmit); - add(addLocalePanel); - - add(new Label(new GlobalizedMessage("cms.ui.asset.name", - CmsConstants.CMS_BUNDLE))); - name = new TextField(ASSET_NAME); - add(name); - - add(new Label(new GlobalizedMessage("cms.ui.asset.title", - CmsConstants.CMS_BUNDLE))); - title = new TextField(ASSET_TITLE); - add(title); - - addWidgets(); - - saveCancelSection = new SaveCancelSection(); - add(saveCancelSection); - - addInitListener(this); - addProcessListener(this); - addSubmissionListener(this); - } - - protected void addWidgets() { - //Nothing here - } - - protected String getTitle(final PageState state) { - return (String) title.getValue(state); - } - - protected Long getSelectedAssetId(final PageState state) { - - final Object key = selectionModel.getSelectedKey(state); - if (key == null) { - return null; - } else { - return (Long) key; - } - } - - @Override - public void init(final FormSectionEvent event) throws FormProcessException { - - final PageState state = event.getPageState(); - - final Long selectedAssetId = getSelectedAssetId(state); - - final Map data; - if (selectedAssetId == null) { - showLocaleSelect.setValue(state, - KernelConfig - .getConfig() - .getDefaultLocale() - .toString()); - - data = Collections.emptyMap(); - - } else { - - showLocaleSelect.setValue(state, - getSelectedLocale(state)); - - data = getController().getAssetData(selectedAssetId, - getAssetClass(), - getSelectedLocale(state)); - - name.setValue(state, - data.get(AbstractAssetFormController.DISPLAY_NAME)); - title.setValue(state, - data.get(AbstractAssetFormController.TITLE)); - } - - initForm(state, data); - } - - protected Locale getSelectedLocale(final PageState state) { - - final Object selected = showLocaleSelect.getValue(state); - if (selected == null) { - return KernelConfig.getConfig().getDefaultLocale(); - } else if (selected instanceof Locale) { - return (Locale) selected; - } else if (selected instanceof String) { - return new Locale((String) selected); - } else { - return new Locale(selected.toString()); - } - } - - protected String getTitleValue(final PageState state) { - return (String) title.getValue(state); - } - - protected void initForm(final PageState state, - final Map data) { - - if (!data.isEmpty()) { - - name.setValue(state, - data.get(AbstractAssetFormController.DISPLAY_NAME)); - -// final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); -// @SuppressWarnings("unchecked") -// final AbstractAssetFormController controller = cdiUtil -// .findBean(AbstractAssetFormController.class); - title.setValue(state, - data.get(AbstractAssetFormController.TITLE)); - showLocale(state); - } - } - - @Override - public void process(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - -// final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - if (showLocaleSubmit.isSelected(state)) { - - final Long selectedAssetId = getSelectedAssetId(state); - - initForm(state, - getController().getAssetData(selectedAssetId, - getAssetClass(), - getSelectedLocale(state))); - - return; - } - - if (addLocaleSubmit.isSelected(state)) { - final Locale add = new Locale((String) addLocaleSelect - .getValue(state)); - final Long selectedAssetId = getSelectedAssetId(state); - getController().addLocale(selectedAssetId, add, getAssetClass()); - } - - if (saveCancelSection.getSaveButton().isSelected(state)) { - - final Map data = new HashMap<>(); - data.put(AbstractAssetFormController.DISPLAY_NAME, - name.getValue(state)); - data.put(AbstractAssetFormController.TITLE, - title.getValue(state)); - data.putAll(collectData(event)); - - final Long selectedAssetId; - if (getSelectedAssetId(state) == null) { - - selectedAssetId = getController() - .createAsset(assetPane - .getFolderSelectionModel() - .getSelectedObject(state), - getSelectedLocale(state), - getAssetClass(), - data); - } else { - selectedAssetId = getSelectedAssetId(state); - } - - getController().updateAsset(selectedAssetId, - getSelectedLocale(state), - getAssetClass(), - data); - - assetPane.browseMode(state); - } - } - - protected abstract Class getAssetClass(); - - protected abstract void showLocale(final PageState state); - - protected abstract Map collectData( - final FormSectionEvent event) - throws FormProcessException; - - @Override - public void submitted(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - if (saveCancelSection.getCancelButton().isSelected(state)) { - selectionModel.clearSelection(state); - assetPane.browseMode(state); - } - } - - protected AssetFormController getController() { - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final AssetFormControllers controllers = cdiUtil - .findBean(AssetFormControllers.class); - - return controllers.findController(getAssetClass()); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AbstractAssetFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AbstractAssetFormController.java deleted file mode 100644 index 0fa230288..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AbstractAssetFormController.java +++ /dev/null @@ -1,263 +0,0 @@ -/* - * Copyright (C) 2019 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.assets; - -import org.librecms.assets.AssetL10NManager; -import org.librecms.contentsection.Asset; -import org.librecms.contentsection.AssetManager; -import org.librecms.contentsection.AssetRepository; -import org.librecms.contentsection.Folder; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Objects; - -import javax.inject.Inject; -import javax.transaction.Transactional; - -/** - * An base class for implementations of {@link AssetFormController}. - * - * @author Jens Pelzetter - * @param - */ -public abstract class AbstractAssetFormController implements - AssetFormController { - - protected static final String DISPLAY_NAME = "displayName"; - protected static final String TITLE = "title"; - - @Inject - private AssetManager assetManager; - - @Inject - private AssetRepository assetRepository; - - @Inject - private AssetL10NManager l10nManager; - - /** - * Retrieves the basic data of the provided asset. Subclasses should not - * overrride this method. Instead they should provided an implementation of - * {@link #getAssetData(org.librecms.contentsection.Asset, java.util.Locale)}. - * - * @param assetType The {@link Asset} from which the data is read. - * @param selectedLocale The locale for which the data is read. - * - * @return A map with the data of the basic properties of the provided - * asset. - */ - @Transactional(Transactional.TxType.REQUIRED) - @Override - public Map getAssetData(final Long assetId, - final Class assetType, - final Locale selectedLocale) { - - Objects.requireNonNull(assetId, "Can't get data from asset null."); - Objects.requireNonNull(selectedLocale, - "Can't get data from asset for locale null."); - - final T asset = loadAsset(assetId, assetType); - - final Map data = new HashMap<>(); - - data.put(DISPLAY_NAME, asset.getDisplayName()); - data.put(TITLE, asset.getTitle().getValue(selectedLocale)); - - data.putAll(getAssetData(asset, selectedLocale)); - - return data; - } - - protected abstract Map getAssetData( - final T asset, final Locale selectedLocale); - - @Transactional(Transactional.TxType.REQUIRED) - @Override - public long createAsset(final Folder infolder, - final Locale selectedLocale, - final Class assetType, - final Map data) { - - if (!data.containsKey(DISPLAY_NAME)) { - throw new IllegalArgumentException( - "data does not contain a value for displayName."); - } - - if (!data.containsKey(TITLE)) { - throw new IllegalArgumentException( - "data does not contain a value for title."); - } - - final String name = (String) data.get(DISPLAY_NAME); - final String title = (String) data.get(TITLE); - - final T asset = assetManager - .createAsset(name, - title, - selectedLocale, - infolder, - assetType); - - return asset.getObjectId(); - } - - /** - * Updates the provided asset with the provided data. - * - * This method is not intended to be overridden, but can't be {@code final} - * because of limitations of CDI. To update type specific properties - * implement - * {@link #updateAssetProperties(org.librecms.contentsection.Asset, java.util.Locale, java.util.Map)}. - * - * This method calls - * {@link AssetRepository#save(org.librecms.contentsection.Asset)} after the - * properties are set to save the changes to the database. - * - * @param assetId The ID of the asset to update. - * @param selectedLocale The locale for which the asset is updated. - * @param data The data used to update the asset. - */ - @Transactional(Transactional.TxType.REQUIRED) - @Override - public void updateAsset(final Long assetId, - final Locale selectedLocale, - final Class assetType, - final Map data) { - - Objects.requireNonNull(selectedLocale, - "Can't get update asset for locale null."); - Objects.requireNonNull(data, "Can't update asset without data."); - - final T asset = loadAsset(assetId, assetType); - if (data.containsKey(DISPLAY_NAME)) { - asset.setDisplayName((String) data.get(DISPLAY_NAME)); - } - - if (data.containsKey(TITLE)) { - - final String title = (String) data.get(TITLE); - asset.getTitle().putValue(selectedLocale, title); - } - - updateAssetProperties(asset, selectedLocale, data); - - assetRepository.save(asset); - } - - /** - * Override this method to process data for type specific properties. - * - * This method is called by - * {@link #updateAsset(org.librecms.contentsection.Asset, java.util.Locale, java.util.Map)}. - * Implementations should not call - * {@link AssetRepository#save}. Saving the update asset is done by - * {@link #updateAsset(org.librecms.contentsection.Asset, java.util.Locale, java.util.Map)}. - * - * An implementation should not assume that a value for each property is - * present in the provided map. Instead the overriding method should check - * if a value for a property is available by using - * {@link Map#containsKey(java.lang.Object)} first. - * - * @param asset The asset to update. - * @param selectedLocale The locale for which the asset is updated. - * @param data The data used to update the asset. - */ - public abstract void updateAssetProperties(final T asset, - final Locale selectedLocale, - final Map data); - - /** - * Determines for which locales the provided asset has data. - * - * @param assetId The asset. - * - * @return A list of all locales for which the asset has data. - */ - @Transactional(Transactional.TxType.REQUIRED) - @Override - public List availableLocales(final Long assetId, - final Class assetType) { - - Objects.requireNonNull( - assetId, - "Can't get available locales for asset with ID null."); - - final T selectedAsset = loadAsset(assetId, assetType); - - return new ArrayList<>(l10nManager.availableLocales(selectedAsset)); - } - - /** - * Determines for locales the asset has no data yet. - * - * @param assetId The asset. - * - * @return A list of all locales for which the provided asset has no data - * yet. - */ - @Transactional(Transactional.TxType.REQUIRED) - @Override - public List creatableLocales(final Long assetId, - final Class assetType) { - - Objects.requireNonNull( - assetId, - "Can't get creatable locales for asset with ID null."); - - final T selectedAsset = loadAsset(assetId, assetType); - - return new ArrayList<>(l10nManager.creatableLocales(selectedAsset)); - } - - @Transactional(Transactional.TxType.REQUIRED) - @Override - public void addLocale(final Long assetId, - final Locale locale, - final Class assetType) { - - Objects.requireNonNull(assetId, "Can't add a locale to asset null."); - Objects.requireNonNull(locale, "Can't add locale null to an asset."); - - final T selectedAsset = loadAsset(assetId, assetType); - - l10nManager.addLanguage(selectedAsset, locale); - } - - /** - * - * @param assetId - * @param assetType - * - * @return - */ - protected T loadAsset(final Long assetId, final Class assetType) { - - Objects.requireNonNull(assetId, "null is not a valid assetId"); - - return assetRepository - .findById(assetId, assetType) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No asset with ID %d found.", assetId))); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowser.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowser.java deleted file mode 100644 index b5a70488b..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowser.java +++ /dev/null @@ -1,446 +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.assets; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.ControlLink; -import com.arsdigita.bebop.Image; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.Page; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Paginator; -import com.arsdigita.bebop.SimpleContainer; -import com.arsdigita.bebop.SingleSelectionModel; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.Text; -import com.arsdigita.bebop.event.TableActionAdapter; -import com.arsdigita.bebop.event.TableActionEvent; -import com.arsdigita.bebop.event.TableActionListener; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.table.DefaultTableCellRenderer; -import com.arsdigita.bebop.table.DefaultTableColumnModel; -import com.arsdigita.bebop.table.TableCellRenderer; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.bebop.table.TableHeader; -import com.arsdigita.cms.CMS; -import com.arsdigita.cms.ui.folder.FolderSelectionModel; -import com.arsdigita.globalization.GlobalizedMessage; - -import java.util.Date; - -import org.libreccm.cdi.utils.CdiUtil; - -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.ContentSectionManager; - -import static org.librecms.CmsConstants.*; - -/** - * Browse folder and assets. - * - * @author Jens Pelzetter - */ -public class AssetFolderBrowser extends Table { - - protected static final String SORT_ACTION_UP = "sortActionUp"; - protected static final String SORT_ACTION_DOWN = "sortActionDown"; - protected final static String SORT_KEY_NAME = "name"; - protected final static String SORT_KEY_TITLE = "title"; - protected final static String SORT_KEY_TYPE = "type"; - protected final static String SORT_KEY_LAST_MODIFIED_DATE = "lastModified"; - protected final static String SORT_KEY_CREATION_DATE = "creationDate"; - - private final AssetPane assetPane; - private TableActionListener folderChanger; - private TableActionListener folderDeleter; - private TableColumn nameColumn; - private TableColumn deleteColumn; - private final StringParameter sortTypeParameter = new StringParameter( - "sortType"); - private final StringParameter sortDirectionParameter = new StringParameter( - "sortDir"); - - private Paginator paginator; - private long folderSize; - - public AssetFolderBrowser(final AssetPane assetPane) { - super(); - sortTypeParameter.setDefaultValue(SORT_KEY_NAME); - sortDirectionParameter.setDefaultValue(SORT_ACTION_UP); - - this.assetPane = assetPane; - - initComponents(); - } - - private void initComponents() { - - final GlobalizedMessage[] headers = { - new GlobalizedMessage("cms.ui.folder.name", - CMS_FOLDER_BUNDLE), - new GlobalizedMessage("cms.ui.folder.title", - CMS_FOLDER_BUNDLE), - new GlobalizedMessage("cms.ui.folder.type", - CMS_FOLDER_BUNDLE), - new GlobalizedMessage("cms.ui.asset.thumbnail", - CMS_BUNDLE), - new GlobalizedMessage("cms.ui.folder.creation_date", - CMS_FOLDER_BUNDLE), - new GlobalizedMessage("cms.ui.folder.last_modified", - CMS_FOLDER_BUNDLE), - new GlobalizedMessage("cms.ui.folder.action", - CMS_FOLDER_BUNDLE)}; - - setModelBuilder(new AssetFolderBrowserTableModelBuilder()); - setColumnModel(new DefaultTableColumnModel(headers)); - setHeader(new TableHeader(getColumnModel())); - setClassAttr("dataTable"); - - getHeader().setDefaultRenderer( - new com.arsdigita.cms.ui.util.DefaultTableCellRenderer()); - - nameColumn = getColumn(AssetFolderBrowserTableModel.COL_NAME); - nameColumn.setCellRenderer(new NameCellRenderer()); - nameColumn.setHeaderRenderer(new HeaderCellRenderer(SORT_KEY_NAME)); - - getColumn(AssetFolderBrowserTableModel.COL_THUMBNAIL) - .setCellRenderer(new ThumbnailCellRenderer()); - - getColumn(AssetFolderBrowserTableModel.COL_CREATION_DATE) - .setHeaderRenderer( - new HeaderCellRenderer(SORT_KEY_CREATION_DATE)); - getColumn(AssetFolderBrowserTableModel.COL_CREATION_DATE) - .setCellRenderer(new DateCellRenderer()); - - getColumn(AssetFolderBrowserTableModel.COL_LAST_MODIFIED) - .setHeaderRenderer(new HeaderCellRenderer( - SORT_KEY_LAST_MODIFIED_DATE)); - getColumn(AssetFolderBrowserTableModel.COL_LAST_MODIFIED) - .setCellRenderer(new DateCellRenderer()); - - deleteColumn = getColumn(AssetFolderBrowserTableModel.COL_DELETEABLE); - deleteColumn.setCellRenderer(new ActionCellRenderer()); - deleteColumn.setAlign("center"); - - folderChanger = new FolderChanger(); - addTableActionListener(folderChanger); - - folderDeleter = new ItemDeleter(); - addTableActionListener(folderDeleter); - - setEmptyView(new Label(new GlobalizedMessage("cms.ui.folder.no_assets", - CMS_FOLDER_BUNDLE))); - } - - @Override - public void register(final Page page) { - - super.register(page); - - page.addComponentStateParam( - this, - getFolderSelectionModel().getStateParameter()); - page.addComponentStateParam(this, sortTypeParameter); - page.addComponentStateParam(this, sortDirectionParameter); - } - - protected FolderSelectionModel getFolderSelectionModel() { - return assetPane.getFolderSelectionModel(); - } - - protected SingleSelectionModel getSelectedAssetModel() { - return assetPane.getSelectedAssetModel(); - } - - protected Paginator getPaginator() { - return paginator; - } - - protected void setPaginator(final Paginator paginator) { - this.paginator = paginator; - } - - protected String getSortType(final PageState state) { - return (String) state.getValue(sortTypeParameter); - } - - protected String getSortDirection(final PageState state) { - return (String) state.getValue(sortDirectionParameter); - } - - private class HeaderCellRenderer extends DefaultTableCellRenderer { - - private final String headerKey; - - public HeaderCellRenderer(final String headerKey) { - super(true); - this.headerKey = headerKey; - } - - @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 GlobalizedMessage headerName = (GlobalizedMessage) value; - final String sortKey = (String) state.getValue(sortTypeParameter); - final boolean isCurrentKey = sortKey.equals(key); - final String currentSortDirection = (String) state - .getValue(sortDirectionParameter); - final String imageUrlStub; - - if (SORT_ACTION_UP.equals(currentSortDirection)) { - imageUrlStub = "gray-triangle-up.gif"; - } else { - imageUrlStub = "gray-triangle-down.gif"; - } - - final ControlLink link = new ControlLink(new Label(headerName)) { - - @Override - public void setControlEvent(final PageState state) { - String sortDirectionAction; - // by default, everything sorts "up" unless it - // is the current key and it is already pointing up - if (SORT_ACTION_UP.equals(currentSortDirection) - && isCurrentKey) { - sortDirectionAction = SORT_ACTION_DOWN; - } else { - sortDirectionAction = SORT_ACTION_UP; - } - state.setControlEvent(table, - sortDirectionAction, - headerKey); - } - - }; - final Label label = new Label(); - label.setLabel(headerName); - label.setClassAttr("folderBrowserLink"); - label.setOutputEscaping(false); - label.setFontWeight(Label.BOLD); - - final SimpleContainer container = new SimpleContainer(); - container.add(label); - if (isCurrentKey) { - Image image = new Image("/assets/" + imageUrlStub); - image.setBorder("0"); - container.add(image); - } - link.setChild(container); - return link; - } - - } - - /** - * Produce links to view an item or control links for folders to change into - * the folder. - */ - private class NameCellRenderer extends DefaultTableCellRenderer { - - public NameCellRenderer() { - super(true); - } - - @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 String name = (String) value; - final ContentSection section = CMS.getContext(). - getContentSection(); - final ContentSectionManager sectionManager = CdiUtil. - createCdiUtil() - .findBean(ContentSectionManager.class); - - final boolean isFolder = ((AssetFolderBrowserTableModel) table - .getTableModel(state)) - .isFolder(); - final long objectId = getObjectId(key); - - if (isFolder) { - //return new ControlLink(new Text(name)); - return super.getComponent(table, - state, - value, - isSelected, - objectId, - row, - column); - } else { - return new ControlLink(new Text(name)); - -// return new Link(new Text(name), -// itemResolver.generateItemURL(state, -// objectId, -// name, -// section, -// "DRAFT")); - } - } - - } - - private class ThumbnailCellRenderer implements TableCellRenderer { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - if (value == null) { - return new Text(""); - } else { - final Image image = new Image((String) value, ""); - return image; - } - } - - } - - private class DateCellRenderer implements TableCellRenderer { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - if (value instanceof Date) { - final Date date = (Date) value; - return new Text(String.format("%1$TF %1$TT", date)); - } else if (value == null) { - return new Text(""); - } else { - return new Text(value.toString()); - } - } - - } - - /** - * Produce delete links for items and non-empty folders. - */ - private class ActionCellRenderer implements TableCellRenderer { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - if ((!(Boolean) value)) { - return new Label(" ", false); - } else { - final ControlLink link = new ControlLink( - new Label( - new GlobalizedMessage("cms.ui.folder.delete", - CmsConstants.CMS_FOLDER_BUNDLE))); - link.setConfirmation( - new GlobalizedMessage( - "cms.ui.folder.delete_confirmation_assets", - CmsConstants.CMS_FOLDER_BUNDLE)); - return link; - } - } - - } - - // Deletes an item - private class ItemDeleter extends TableActionAdapter { - - @Override - public void cellSelected(final TableActionEvent event) { - int col = event.getColumn(); - - if (deleteColumn != getColumn(col)) { - return; - } - - final PageState state = event.getPageState(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final AssetFolderBrowserController controller = cdiUtil.findBean( - AssetFolderBrowserController.class); - controller.deleteObject((String) event.getRowKey()); - - ((Table) event.getSource()).clearSelection(state); - } - - } - - private class FolderChanger extends TableActionAdapter { - - @Override - public void cellSelected(final TableActionEvent event) { - final PageState state = event.getPageState(); - final int col = event.getColumn(); - - if (nameColumn != getColumn(col)) { - return; - } - - clearSelection(state); - final String rowKey = (String) event.getRowKey(); - if (rowKey.startsWith(CmsConstants.FOLDER_BROWSER_KEY_PREFIX_FOLDER)) { - getFolderSelectionModel().setSelectedKey(state, - getObjectId(rowKey)); - } else if (rowKey.startsWith( - CmsConstants.FOLDER_BROWSER_KEY_PREFIX_ASSET)) { - getSelectedAssetModel().setSelectedKey(state, - getObjectId(rowKey)); - assetPane.editAssetMode(state); - } - } - - } - - private long getObjectId(final Object key) { - - final String keyStr = (String) key; - - if (keyStr.startsWith("folder-")) { - return Long.parseLong(keyStr.substring("folder-".length())); - } else if (keyStr.startsWith("asset-")) { - return Long.parseLong(keyStr.substring("asset-".length())); - } else { - return Long.parseLong(keyStr); - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserController.java deleted file mode 100644 index b3ed0b26b..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserController.java +++ /dev/null @@ -1,638 +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.assets; - -import com.arsdigita.cms.CMS; -import com.arsdigita.kernel.KernelConfig; -import com.arsdigita.web.CCMDispatcherServlet; - -import org.libreccm.categorization.Category; -import org.libreccm.categorization.CategoryManager; -import org.libreccm.configuration.ConfigurationManager; -import org.libreccm.l10n.GlobalizationHelper; -import org.librecms.CmsConstants; -import org.librecms.assets.AssetTypeInfo; -import org.librecms.assets.AssetTypesManager; -import org.librecms.contentsection.Asset; - -import org.librecms.contentsection.Folder; - -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Objects; -import java.util.stream.Collectors; - -import javax.annotation.PostConstruct; -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.persistence.EntityManager; -import javax.persistence.TypedQuery; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Join; -import javax.persistence.criteria.Order; -import javax.persistence.criteria.Path; -import javax.persistence.criteria.Root; -import javax.transaction.Transactional; - -import org.libreccm.core.CcmObject; -import org.librecms.contentsection.AssetManager; -import org.librecms.contentsection.AssetRepository; -import org.librecms.contentsection.FolderManager; -import org.librecms.contentsection.FolderRepository; - -import java.util.Collections; -import java.util.Optional; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.librecms.assets.Image; - -import static org.librecms.CmsConstants.*; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -public class AssetFolderBrowserController { - - private static final Logger LOGGER = LogManager - .getLogger(AssetFolderBrowserController.class); - - @Inject - private EntityManager entityManager; - - @Inject - private ConfigurationManager confManager; - - @Inject - private CategoryManager categoryManager; - - @Inject - private AssetTypesManager typesManager; - - @Inject - private FolderRepository folderRepo; - - @Inject - private FolderManager folderManager; - - @Inject - private AssetRepository assetRepo; - - @Inject - private AssetManager assetManager; - - @Inject - private GlobalizationHelper globalizationHelper; - - private Locale defaultLocale; - - /** - * Initialisation method called by the CDI-Container after an instance of - * this class has be created by the container. Sets the - * {@link #defaultLocale} property using the the value from the - * {@link KernelConfig}. - */ - @PostConstruct - private void init() { - final KernelConfig kernelConfig = confManager.findConfiguration( - KernelConfig.class); - defaultLocale = kernelConfig.getDefaultLocale(); - } - - @Transactional(Transactional.TxType.REQUIRED) - List getAssetRows(final Folder folder, - final String orderBy, - final String orderDirection, - final int firstResult, - final int maxResults) { - final List subFolders = findSubFolders(folder, - "%", - orderBy, - orderDirection, - firstResult, - maxResults); - final List subFolderRows = subFolders - .stream() - .map(subFolder -> buildRow(subFolder)) - .collect(Collectors.toList()); - - if (subFolders.size() > maxResults) { - return subFolderRows; - } else { - final int maxAssets = maxResults - subFolders.size(); - final int firstAsset = firstResult - subFolders.size(); - - final List assets = findAssetsInFolder(folder, - "%", - orderBy, - orderDirection, - firstAsset, - maxAssets); - final List assetRows = assets - .stream() - .map(asset -> buildRow(asset)) - .collect(Collectors.toList()); - - final List rows = new ArrayList<>(); - rows.addAll(subFolderRows); - rows.addAll(assetRows); - - return rows; - } - } - - @Transactional(Transactional.TxType.REQUIRED) - protected long countObjects(final Folder folder) { - - return countObjects(folder, "%"); - - } - - @Transactional(Transactional.TxType.REQUIRED) - protected long countObjects(final Folder folder, final String filterTerm) { - - Objects.requireNonNull(folder); - Objects.requireNonNull(filterTerm); - - final CriteriaBuilder builder = entityManager.getCriteriaBuilder(); - CriteriaQuery criteriaQuery = builder.createQuery(Long.class); - final Root from = criteriaQuery.from(CcmObject.class); - - criteriaQuery = criteriaQuery.select(builder.count(from)); - - final List subFolders = findSubFolders( - folder, - filterTerm, - AssetFolderBrowser.SORT_KEY_NAME, - AssetFolderBrowser.SORT_ACTION_UP, - -1, - -1); - final List assets = findAssetsInFolder( - folder, - filterTerm, - AssetFolderBrowser.SORT_KEY_NAME, - AssetFolderBrowser.SORT_ACTION_UP, - -1, - -1); - - if (subFolders.isEmpty() && assets.isEmpty()) { - return 0; - } else if (subFolders.isEmpty() && !assets.isEmpty()) { - criteriaQuery = criteriaQuery.where(from.in(assets)); - } else if (!subFolders.isEmpty() && assets.isEmpty()) { - criteriaQuery = criteriaQuery.where(from.in(subFolders)); - } else { - criteriaQuery = criteriaQuery.where(builder.or( - from.in(subFolders), - from.in(assets))); - } - - return entityManager.createQuery(criteriaQuery).getSingleResult(); - - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void copyObjects(final Folder targetFolder, - final String[] objectIds) { - - Objects.requireNonNull(targetFolder); - Objects.requireNonNull(objectIds); - - for (final String objectId : objectIds) { - if (objectId.startsWith(FOLDER_BROWSER_KEY_PREFIX_FOLDER)) { - copyFolder(targetFolder, - Long.parseLong(objectId.substring( - FOLDER_BROWSER_KEY_PREFIX_FOLDER.length()))); - } else if (objectId.startsWith(FOLDER_BROWSER_KEY_PREFIX_ASSET)) { - copyAsset(targetFolder, - Long.parseLong(objectId.substring( - FOLDER_BROWSER_KEY_PREFIX_ASSET.length()))); - } else { - throw new IllegalArgumentException(String.format( - "ID '%s' does not start with '%s' or '%s'.", - objectId, - FOLDER_BROWSER_KEY_PREFIX_FOLDER, - FOLDER_BROWSER_KEY_PREFIX_ASSET)); - } - } - - } - - private void copyFolder(final Folder targetFolder, - final long folderId) { - - Objects.requireNonNull(targetFolder); - - final Folder folder = folderRepo.findById(folderId) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No folder with ID %d in the database. " - + "Where did that ID come from?", - folderId))); - - folderManager.copyFolder(folder, targetFolder); - - } - - private void copyAsset(final Folder targetFolder, - final long assetId) { - - Objects.requireNonNull(targetFolder); - - final Asset asset = assetRepo - .findById(assetId) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No asset ith ID %d in the database. Where did that ID come from?", - assetId))); - - assetManager.copy(asset, targetFolder); - } - - @Transactional(Transactional.TxType.REQUIRED) - public void moveObjects(final Folder targetFolder, - final String[] objectIds) { - - Objects.requireNonNull(targetFolder); - Objects.requireNonNull(objectIds); - - for (final String objectId : objectIds) { - if (objectId.startsWith(FOLDER_BROWSER_KEY_PREFIX_FOLDER)) { - moveFolder(targetFolder, - Long.parseLong(objectId.substring( - FOLDER_BROWSER_KEY_PREFIX_FOLDER.length()))); - } else if (objectId.startsWith(FOLDER_BROWSER_KEY_PREFIX_ASSET)) { - moveAsset(targetFolder, - Long.parseLong(objectId.substring( - FOLDER_BROWSER_KEY_PREFIX_ASSET.length()))); - } else { - throw new IllegalArgumentException(String.format( - "ID '%s' does not start with '%s' or '%s'.", - objectId, - FOLDER_BROWSER_KEY_PREFIX_FOLDER, - FOLDER_BROWSER_KEY_PREFIX_ASSET)); - } - } - } - - private void moveFolder(final Folder targetFolder, final long folderId) { - - Objects.requireNonNull(targetFolder); - - final Folder folder = folderRepo.findById(folderId) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No folder with ID %d in the database. " - + "Where did that ID come from?", - folderId))); - - folderManager.moveFolder(folder, targetFolder); - } - - private void moveAsset(final Folder targetFolder, final long assetId) { - - Objects.requireNonNull(targetFolder); - - final Asset asset = assetRepo - .findById(assetId) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No asset with ID %d in the database. Where did that ID come from?", - assetId))); - - assetManager.move(asset, targetFolder); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected List createInvalidTargetsList(final List sources) { - - Objects.requireNonNull(sources); - - final List sourceFolderIds = sources - .stream() - .filter(source -> source.startsWith( - FOLDER_BROWSER_KEY_PREFIX_FOLDER)) - .collect(Collectors.toList()); - final List parentFolderIds = sourceFolderIds - .stream() - .map(sourceFolderId -> findParentFolderId(sourceFolderId)) - .filter(Optional::isPresent) - .map(Optional::get) - .collect(Collectors.toList()); - final List> subFolderIds = sourceFolderIds - .stream() - .map(sourceFolderId -> findSubFolderIds(sourceFolderId)) - .collect(Collectors.toList()); - - final List invalidTargetIds = new ArrayList<>(); - invalidTargetIds.addAll(sourceFolderIds); - invalidTargetIds.addAll(parentFolderIds); - for (final List subFolderIdList : subFolderIds) { - invalidTargetIds.addAll(subFolderIdList); - } - - return invalidTargetIds; - - } - - private Optional findParentFolderId(final String folderId) { - - Objects.requireNonNull(folderId); - - if (!folderId.startsWith(FOLDER_BROWSER_KEY_PREFIX_FOLDER)) { - throw new IllegalArgumentException(String.format( - "Provided string '%s' is not an ID of a folder.", - folderId)); - } - - final long objectId = Long.parseLong(folderId.substring( - FOLDER_BROWSER_KEY_PREFIX_FOLDER.length())); - final Folder folder = folderRepo.findById(objectId) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No folder with ID %d found in database. " - + "Where did that ID come form?", - objectId))); - final Optional parentFolder = folderManager.getParentFolder( - folder); - if (parentFolder.isPresent()) { - return Optional.empty(); - } else { - return Optional.ofNullable(String.format( - "%s%d", - FOLDER_BROWSER_KEY_PREFIX_FOLDER, - parentFolder.get().getObjectId())); - } - } - - private List findSubFolderIds(final String folderId) { - - Objects.requireNonNull(folderId); - - if (!folderId.startsWith(FOLDER_BROWSER_KEY_PREFIX_FOLDER)) { - throw new IllegalArgumentException(String.format( - "Provided string '%s' is not the ID of a folder.", - folderId)); - } - - final long objectId = Long.parseLong(folderId.substring( - FOLDER_BROWSER_KEY_PREFIX_FOLDER.length())); - final Folder folder = folderRepo.findById(objectId) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No folder with ID %d found in database. " - + "Where did that ID come form?", - objectId))); - return findSubFolders(folder) - .stream() - .map(subFolder -> String.format("%s%d", - FOLDER_BROWSER_KEY_PREFIX_FOLDER, - subFolder.getObjectId())) - .collect(Collectors.toList()); - } - - private List findSubFolders(final Folder folder) { - - Objects.requireNonNull(folder); - - if (folder.getSubFolders() == null - || folder.getSubFolders().isEmpty()) { - return Collections.emptyList(); - } - - final List subFolders = new ArrayList<>(); - for (final Folder subFolder : folder.getSubFolders()) { - subFolders.add(subFolder); - subFolders.addAll(findSubFolders(subFolder)); - } - - return subFolders; - } - - /** - * Called by the {@link AssetFolderBrowser} to delete an object. - * - * @param objectId - */ - @Transactional(Transactional.TxType.REQUIRED) - protected void deleteObject(final String objectId) { - - Objects.requireNonNull(objectId); - - if (objectId.startsWith("folder-")) { - final long folderId = Long.parseLong( - objectId.substring("folder-".length())); - - folderRepo - .findById(folderId) - .ifPresent(folderRepo::delete); - } else if (objectId.startsWith("asset-")) { - final long assetId = Long.parseLong( - objectId.substring("asset-".length())); - - assetRepo - .findById(assetId) - .ifPresent(assetRepo::delete); - } else { - throw new IllegalArgumentException( - "The objectId is expected to start with 'folder-' or 'asset-'."); - } - } - - private AssetFolderBrowserTableRow buildRow(final Folder folder) { - - final AssetFolderBrowserTableRow row = new AssetFolderBrowserTableRow(); - - row.setObjectId(folder.getObjectId()); - row.setObjectUuid(folder.getUuid()); - row.setName(folder.getName()); - if (folder.getTitle().hasValue(globalizationHelper - .getNegotiatedLocale())) { - row.setTitle(folder.getTitle().getValue(globalizationHelper - .getNegotiatedLocale())); - } else { - row.setTitle(folder.getTitle().getValue(defaultLocale)); - } - row.setFolder(true); - row.setDeletable(!categoryManager.hasSubCategories(folder) - && !categoryManager.hasObjects(folder)); - - return row; - } - - private AssetFolderBrowserTableRow buildRow(final Asset asset) { - - final AssetFolderBrowserTableRow row = new AssetFolderBrowserTableRow(); - - row.setObjectId(asset.getObjectId()); - row.setObjectUuid(asset.getUuid()); - row.setName(asset.getDisplayName()); - if (asset.getTitle().hasValue(globalizationHelper - .getNegotiatedLocale())) { - row.setTitle(asset.getTitle().getValue(globalizationHelper - .getNegotiatedLocale())); - } else { - row.setTitle(asset.getTitle().getValue(defaultLocale)); - } - if (asset instanceof Image) { - row.setThumbnailUrl(String - .format("%s/content-sections/%s/images/" - + "uuid-%s?width=150&height=100", - CCMDispatcherServlet.getContextPath(), - CMS.getContext().getContentSection().getLabel(), - asset.getUuid())); - } - final AssetTypeInfo typeInfo = typesManager - .getAssetTypeInfo(asset.getClass()); - row.setTypeLabelBundle(typeInfo.getLabelBundle()); - row.setTypeLabelKey(typeInfo.getLabelKey()); - - row.setFolder(false); - - row.setDeletable(!assetManager.isAssetInUse(asset)); - - return row; - } - - private List findSubFolders(final Folder folder, - final String filterTerm, - final String orderBy, - final String orderDirection, - final int firstResult, - final int maxResults) { - - final CriteriaBuilder builder = entityManager.getCriteriaBuilder(); - - final CriteriaQuery criteria = builder - .createQuery(Folder.class); - final Root from = criteria.from(Folder.class); - - final Order order; - if (AssetFolderBrowser.SORT_KEY_NAME.equals(orderBy) - && AssetFolderBrowser.SORT_ACTION_DOWN. - equals(orderDirection)) { - order = builder.desc(from.get("name")); - } else { - order = builder.asc(from.get("name")); - } - - final TypedQuery query = entityManager - .createQuery( - criteria.where( - builder.and( - builder. - equal(from.get("parentCategory"), - folder), - builder.like(builder.lower(from.get( - "name")), - filterTerm) - ) - ) - .orderBy(order) - ); - - if (firstResult >= 0) { - query.setFirstResult(firstResult); - } - - if (maxResults >= 0) { - query.setMaxResults(maxResults); - } - - return query.getResultList(); - } - - private List findAssetsInFolder(final Folder folder, - final String filterTerm, - final String orderBy, - final String orderDirection, - final int firstResult, - final int maxResults) { - - final CriteriaBuilder builder = entityManager.getCriteriaBuilder(); - - final CriteriaQuery criteria = builder.createQuery(Asset.class); - final Root fromAsset = criteria.from(Asset.class); - final Join join = fromAsset.join("categories"); - - final Path orderPath; - switch (orderBy) { - case AssetFolderBrowser.SORT_KEY_NAME: - orderPath = fromAsset.get("displayName"); - break; - case AssetFolderBrowser.SORT_KEY_CREATION_DATE: - orderPath = fromAsset.get("creationDate"); - break; - case AssetFolderBrowser.SORT_KEY_LAST_MODIFIED_DATE: - orderPath = fromAsset.get("lastModifed"); - break; - default: - orderPath = fromAsset.get("displayName"); - break; - } - - final Order order; - if (AssetFolderBrowser.SORT_ACTION_DOWN.equals(orderDirection)) { - order = builder.desc(orderPath); - } else { - order = builder.asc(orderPath); - } - - LOGGER.debug("The database contains {} assets.", - entityManager.createQuery(criteria.select(fromAsset) - .where( - builder.and( - builder.equal(join.get("category"), - folder), - builder.equal(join.get("type"), - CmsConstants.CATEGORIZATION_TYPE_FOLDER), - builder.like(builder.lower( - fromAsset.get( - "displayName")), - filterTerm) - ))).getResultList().size()); - - final TypedQuery query = entityManager - .createQuery( - criteria.select(fromAsset) - .where( - builder.and( - builder.equal(join.get( - "category"), folder), - builder.equal(join.get("type"), - CmsConstants.CATEGORIZATION_TYPE_FOLDER), - builder.like(builder.lower( - fromAsset.get( - "displayName")), - filterTerm) - ) - ) - .orderBy(order) - ); - - if (firstResult >= 0) { - query.setFirstResult(firstResult); - } - - if (maxResults >= 0) { - query.setMaxResults(maxResults); - } - - return query.getResultList(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserPaginationModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserPaginationModelBuilder.java deleted file mode 100644 index 85ea33141..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserPaginationModelBuilder.java +++ /dev/null @@ -1,65 +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.assets; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.PaginationModelBuilder; -import com.arsdigita.bebop.Paginator; -import com.arsdigita.cms.ui.folder.FolderSelectionModel; -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.contentsection.Folder; - -/** - * - * @author Jens Pelzetter - */ -class AssetFolderBrowserPaginationModelBuilder implements PaginationModelBuilder { - - private final AssetFolderBrowser folderBrowser; - - public AssetFolderBrowserPaginationModelBuilder( - final AssetFolderBrowser folderBrowser) { - - this.folderBrowser = folderBrowser; - } - - @Override - public int getTotalSize(final Paginator paginator, final PageState state) { - - final FolderSelectionModel folderSelectionModel = folderBrowser - .getFolderSelectionModel(); - final Folder folder = folderSelectionModel.getSelectedObject(state); - if (folder == null) { - return 0; - } else { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final AssetFolderBrowserController controller = cdiUtil.findBean( - AssetFolderBrowserController.class); - return (int) controller.countObjects(folder); - } - } - - @Override - public boolean isVisible(final PageState state) { - return folderBrowser != null && folderBrowser.isVisible(state); - } - - - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserTableModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserTableModel.java deleted file mode 100644 index 56b7a2d6a..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserTableModel.java +++ /dev/null @@ -1,110 +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.assets; - -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.librecms.CmsConstants; - -import java.util.Iterator; -import java.util.List; - -/** - * - * @author Jens Pelzetter - */ -class AssetFolderBrowserTableModel implements TableModel { - - protected static final int COL_NAME = 0; - protected static final int COL_TITLE = 1; - protected static final int COL_TYPE = 2; - protected static final int COL_THUMBNAIL = 3; - protected static final int COL_CREATION_DATE = 4; - protected static final int COL_LAST_MODIFIED = 5; - protected static final int COL_DELETEABLE = 6; - - private final Iterator iterator; - private AssetFolderBrowserTableRow currentRow; - - public AssetFolderBrowserTableModel( - final List rows) { - - iterator = rows.iterator(); - } - - @Override - public int getColumnCount() { - return 6; - } - - @Override - public boolean nextRow() { - if (iterator.hasNext()) { - currentRow = iterator.next(); - return true; - } else { - return false; - } - } - - @Override - public Object getElementAt(final int columnIndex) { - switch (columnIndex) { - case COL_NAME: - return currentRow.getName(); - case COL_TITLE: - return currentRow.getTitle(); - case COL_TYPE: - final String typeLabelBundle = currentRow.getTypeLabelBundle(); - final String typeLabelKey = currentRow.getTypeLabelKey(); - if (typeLabelKey == null) { - return new GlobalizedMessage("empty_text", - CmsConstants.CMS_BUNDLE); - } else { - return new GlobalizedMessage(typeLabelKey, typeLabelBundle); - } - case COL_THUMBNAIL: - return currentRow.getThumbnailUrl(); - case COL_CREATION_DATE: - return currentRow.getCreated(); - case COL_LAST_MODIFIED: - return currentRow.getLastModified(); - case COL_DELETEABLE: - return currentRow.isDeletable(); - default: - throw new IllegalArgumentException(String.format( - "Illegal column index %d.", columnIndex)); - } - } - - @Override - public Object getKeyAt(final int columnIndex) { - if (currentRow.isFolder()) { - return String.format("folder-%d", currentRow.getObjectId()); - } else { - return String.format("asset-%d", currentRow.getObjectId()); - } - } - - public boolean isFolder() { - return currentRow.isFolder(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserTableModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserTableModelBuilder.java deleted file mode 100644 index afbf71efd..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserTableModelBuilder.java +++ /dev/null @@ -1,101 +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.assets; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Paginator; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.bebop.table.TableModelBuilder; -import com.arsdigita.cms.ui.folder.FolderSelectionModel; -import com.arsdigita.util.LockableImpl; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.contentsection.Folder; - -import java.util.List; - -/** - * Creates the {@link TableModel} for the {@link AssetFolderBrowser}. - * - * @author Jens Pelzetter - */ -class AssetFolderBrowserTableModelBuilder - extends LockableImpl - implements TableModelBuilder { - - private static final Logger LOGGER = LogManager - .getLogger(AssetFolderBrowserTableModelBuilder.class); - - @Override - public TableModel makeModel(final Table table, - final PageState state) { - - if (!(table instanceof AssetFolderBrowser)) { - throw new IllegalArgumentException( - "The AssetFolderBrowserTableModelBuilder can only be used " - + "for the AssetFolderBrowser."); - } - - final AssetFolderBrowser assetFolderBrowser = (AssetFolderBrowser) table; - final FolderSelectionModel folderSelectionModel = assetFolderBrowser - .getFolderSelectionModel(); - final Folder folder = folderSelectionModel.getSelectedObject(state); - if (folder == null) { - return Table.EMPTY_MODEL; - } else { - assetFolderBrowser.getRowSelectionModel().clearSelection(state); - final Paginator paginator = assetFolderBrowser.getPaginator(); - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final AssetFolderBrowserController controller = cdiUtil - .findBean(AssetFolderBrowserController.class); - final String orderBy; - if (assetFolderBrowser.getSortType(state) == null) { - orderBy = AssetFolderBrowser.SORT_KEY_NAME; - } else { - orderBy = assetFolderBrowser.getSortType(state); - } - final String orderDirection; - if (assetFolderBrowser.getSortDirection(state) == null) { - orderDirection = AssetFolderBrowser.SORT_ACTION_UP; - } else { - orderDirection = assetFolderBrowser.getSortDirection(state); - } - final int first = paginator.getFirst(state); - final int pageSize = paginator.getPageSize(state); - - final long start = System.nanoTime(); - LOGGER.debug("Retrieving table rows..."); - final List rows = controller - .getAssetRows(folder, - orderBy, - orderDirection, - first - 1, - pageSize); - - LOGGER.debug("Retrieve table rows in {} ms.", - (System.nanoTime() - start) / 1000); - return new AssetFolderBrowserTableModel(rows); - - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserTableRow.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserTableRow.java deleted file mode 100644 index 045a35093..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFolderBrowserTableRow.java +++ /dev/null @@ -1,148 +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.assets; - -import java.util.Date; - -/** - * - * @author Jens Pelzetter - */ -class AssetFolderBrowserTableRow { - - private long objectId; - private String objectUuid; - private String name; - private String title; - private String thumbnailUrl; - private String typeLabelBundle; - private String typeLabelKey; - private Date created; - private Date lastModified; - private boolean deletable; - private boolean folder; - - public long getObjectId() { - return objectId; - } - - public void setObjectId(final long objectId) { - this.objectId = objectId; - } - - public String getObjectUuid() { - return objectUuid; - } - - public void setObjectUuid(final String objectUuid) { - this.objectUuid = objectUuid; - } - - public String getName() { - return name; - } - - public void setName(final String name) { - this.name = name; - } - - public String getTitle() { - return title; - } - - public void setTitle(final String title) { - this.title = title; - } - - public String getThumbnailUrl() { - return thumbnailUrl; - } - - public void setThumbnailUrl(final String thumbnailUrl) { - this.thumbnailUrl = thumbnailUrl; - } - - public String getTypeLabelBundle() { - return typeLabelBundle; - } - - public void setTypeLabelBundle(final String typeLabelBundle) { - this.typeLabelBundle = typeLabelBundle; - } - - public String getTypeLabelKey() { - return typeLabelKey; - } - - public void setTypeLabelKey(final String typeLabelKey) { - this.typeLabelKey = typeLabelKey; - } - - public Date getCreated() { - if (created == null) { - return null; - } else { - return new Date(created.getTime()); - } - } - - protected void setCreated(final Date created) { - if (created == null) { - this.created = null; - } else { - this.created = new Date(created.getTime()); - } - } - - public Date getLastModified() { - if (lastModified == null) { - return null; - } else { - return new Date(lastModified.getTime()); - } - } - - protected void setLastModified(final Date lastModified) { - if (lastModified == null) { - this.lastModified = null; - } else { - this.lastModified = new Date(lastModified.getTime()); - } - } - - public boolean isDeletable() { - return deletable; - } - - public void setDeletable(final boolean deletable) { - this.deletable = deletable; - } - - public boolean isFolder() { - return folder; - } - - public void setFolder(final boolean folder) { - this.folder = folder; - } - - - - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFormController.java deleted file mode 100644 index c188d613a..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFormController.java +++ /dev/null @@ -1,107 +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.assets; - -import org.librecms.contentsection.Asset; -import org.librecms.contentsection.Folder; - -import java.util.List; -import java.util.Locale; -import java.util.Map; - -/** - * - * Interface for the CDI backend for the forms to manage assets.To avoid - * problems with transactions etc. - * - * the Bebop based forms should access any other CDI beans beside the - * approbriate implementation of this interface. To minimize the efford to - * create an implementation the {@link AbstractAssetFormController} class should - * be used. This class provides basic implementations for most methods. - * - * Implementations of the methods defined by this interface should annotated - * with {@code @Transactional(Transactional.TxType.REQUIRED)}. - * - * @author Jens Pelzetter - * - * @param The type asset managed by this controller. - */ -public interface AssetFormController { - - /** - * Gets the data for the forms from the asset. - * - * @param assetId The ID of the asset. - * @param assetType - * @param selectedLocale The selected locale - * - * @return The values of the properties of the asset for the the selected - * locale. - */ - Map getAssetData(Long assetId, - Class assetType, - Locale selectedLocale); - - /** - * Updates the asset with the provided data and saves the changes. - * - * @param assetId - * @param selectedLocale - * @param assetType - * @param data - */ - void updateAsset(Long assetId, - Locale selectedLocale, - Class assetType, - Map data); - - long createAsset(Folder inFolder, - Locale selectedLocale, - Class assetType, - Map data); - - - - /** - * Determines in which locales the provided asset is available. - * - * - * @param assetId - * @param assetType - * - * @return A list of the locales for which the asset has data. - */ - List availableLocales(Long assetId, Class assetType); - - /** - * Determines for which the provided asset has no data. - * - * - * @param assetId - * @param assetType - * - * @return A list of the locales for which the asset has data yet. - */ - List creatableLocales(Long assetId, Class assetType); - - void addLocale(final Long assetId, - final Locale locale, - final Class assetType); - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFormControllers.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFormControllers.java deleted file mode 100644 index 8fa79557f..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetFormControllers.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2019 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.assets; - -import org.librecms.contentsection.Asset; - -import javax.enterprise.context.RequestScoped; -import javax.enterprise.inject.Any; -import javax.enterprise.inject.Instance; -import javax.enterprise.util.AnnotationLiteral; -import javax.inject.Inject; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -public class AssetFormControllers { - - @Inject - @Any - private Instance> controllers; - - @SuppressWarnings("unchecked") - public AssetFormController findController( - final Class assetType) { - - final IsControllerForAssetTypeLiteral literal - = new IsControllerForAssetTypeLiteral( - assetType); - - final Instance> instance = controllers - .select(literal); - - if (instance.isUnsatisfied()) { - throw new IllegalArgumentException(String.format( - "No controller for asset type \"%s\".", - assetType.getClass().getName())); - } else { - return (AssetFormController) instance.iterator().next(); - } - } - - private class IsControllerForAssetTypeLiteral - extends AnnotationLiteral - implements IsControllerForAssetType { - - private static final long serialVersionUID = 1L; - - private final Class assetType; - - public IsControllerForAssetTypeLiteral( - final Class assetType) { - - this.assetType = assetType; - } - - @Override - public Class value() { - - return assetType; - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetPane.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetPane.java deleted file mode 100644 index 02c3d87d5..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetPane.java +++ /dev/null @@ -1,1229 +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.assets; - -import com.arsdigita.bebop.ActionLink; -import com.arsdigita.bebop.BoxPanel; -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.ControlLink; -import com.arsdigita.bebop.Form; -import com.arsdigita.bebop.FormData; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.MetaForm; -import com.arsdigita.bebop.Page; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Paginator; -import com.arsdigita.bebop.ParameterSingleSelectionModel; -import com.arsdigita.bebop.RequestLocal; -import com.arsdigita.bebop.Resettable; -import com.arsdigita.bebop.SaveCancelSection; -import com.arsdigita.bebop.SegmentedPanel; -import com.arsdigita.bebop.SimpleContainer; -import com.arsdigita.bebop.SingleSelectionModel; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.Text; -import com.arsdigita.bebop.Tree; -import com.arsdigita.bebop.event.ActionEvent; -import com.arsdigita.bebop.event.ActionListener; -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.event.PrintEvent; -import com.arsdigita.bebop.event.PrintListener; -import com.arsdigita.bebop.form.CheckboxGroup; -import com.arsdigita.bebop.form.FormErrorDisplay; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.form.SingleSelect; -import com.arsdigita.bebop.form.Submit; -import com.arsdigita.bebop.parameters.ArrayParameter; -import com.arsdigita.bebop.parameters.LongParameter; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.table.TableCellRenderer; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.bebop.tree.TreeCellRenderer; -import com.arsdigita.cms.CMS; -import com.arsdigita.cms.ui.BaseTree; -import com.arsdigita.cms.ui.folder.FolderCreateForm; -import com.arsdigita.cms.ui.folder.FolderEditorForm; -import com.arsdigita.cms.ui.folder.FolderRequestLocal; -import com.arsdigita.cms.ui.folder.FolderSelectionModel; -import com.arsdigita.cms.ui.folder.FolderTreeModelBuilder; -import com.arsdigita.cms.ui.folder.FolderTreeModelController; -import com.arsdigita.cms.ui.permissions.CMSPermissionsPane; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.toolbox.ui.ActionGroup; -import com.arsdigita.toolbox.ui.LayoutPanel; -import com.arsdigita.ui.CcmObjectSelectionModel; - -import java.lang.reflect.InvocationTargetException; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.libreccm.categorization.Category; -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.Folder; - -import java.util.List; - -import org.librecms.CMSConfig; -import org.libreccm.categorization.CategoryManager; -import org.libreccm.core.CcmObject; -import org.libreccm.core.UnexpectedErrorException; -import org.libreccm.security.PermissionChecker; -import org.libreccm.security.PermissionManager; -import org.librecms.assets.AssetTypeInfo; -import org.librecms.assets.AssetTypesManager; -import org.librecms.contentsection.Asset; -import org.librecms.contentsection.AssetManager; -import org.librecms.contentsection.AssetRepository; -import org.librecms.contentsection.FolderManager; -import org.librecms.contentsection.FolderRepository; -import org.librecms.contentsection.privileges.AssetPrivileges; -import org.librecms.contentsection.privileges.ItemPrivileges; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.ResourceBundle; -import java.util.TooManyListenersException; - -import static org.librecms.CmsConstants.*; - -/** - * - * @author Jens Pelzetter - */ -public class AssetPane extends LayoutPanel implements Resettable { - - private static final Logger LOGGER = LogManager.getLogger(AssetPane.class); - - public static final String SET_FOLDER = "set_folder"; - private static final String SOURCES_PARAM = "sources"; - private static final String ACTION_PARAM = "action"; - private static final String MOVE = "Move"; - private static final String COPY = "Copy"; - - private final BaseTree tree; - private final SingleSelectionModel selectionModel; - private final FolderSelectionModel folderSelectionModel; - private final FolderRequestLocal folderRequestLocal; - private final SingleSelectionModel selectedAssetModel; - private final ArrayParameter sourcesParameter = new ArrayParameter( - new StringParameter(SOURCES_PARAM)); - private final StringParameter actionParameter = new StringParameter( - ACTION_PARAM); - private final StringParameter selectedAssetTypeParam = new StringParameter( - "selected_asset_type"); - - private AssetFolderBrowser folderBrowser; - private Form browserForm; - private SingleSelect actionSelect; - private Submit actionSubmit; - private TargetSelector targetSelector; - - private SegmentedPanel.Segment browseSegment; -// private SegmentedPanel.Segment currentFolderSegment; - private SegmentedPanel.Segment actionsSegment; - private SegmentedPanel.Segment newFolderSegment; - private SegmentedPanel.Segment editFolderSegment; - private SegmentedPanel.Segment editAssetSegment; - private SegmentedPanel.Segment folderPermissionsSegment; - - @SuppressWarnings("unchecked") - public AssetPane() { - tree = new BaseTree(new FolderTreeModelBuilder() { - - @Override - protected Folder getRootFolder(final PageState state) { - final ContentSection section = CMS - .getContext() - .getContentSection(); - return section.getRootAssetsFolder(); - } - - }); - selectionModel = tree.getSelectionModel(); - folderSelectionModel = new FolderSelectionModel(selectionModel) { - - @Override - protected Long getRootFolderID(final PageState state) { - final ContentSection section = CMS - .getContext() - .getContentSection(); - return section.getRootAssetsFolder().getObjectId(); - } - - }; - folderRequestLocal = new FolderRequestLocal(folderSelectionModel); - - selectedAssetModel = new ParameterSingleSelectionModel<>( - new LongParameter("selected-asset")); - - final SegmentedPanel left = new SegmentedPanel(); - setLeft(left); - - final Label heading = new Label( - new GlobalizedMessage("cms.ui.folder_browser", - CmsConstants.CMS_BUNDLE)); - left.addSegment(heading, tree); - -// final Text placeholder = new Text("Placeholder"); - setBody(createBrowserPane()); - - } - - private SimpleContainer createBrowserPane() { - - final SegmentedPanel panel = new SegmentedPanel(); - - browseSegment = panel.addSegment(); - browserForm = new Form("assetFolderBrowser", - new BoxPanel(BoxPanel.VERTICAL)); - browserForm.setMethod(Form.GET); - folderBrowser = new AssetFolderBrowser(this); - final Paginator paginator = new Paginator( - new AssetFolderBrowserPaginationModelBuilder(folderBrowser), - CMSConfig.getConfig().getFolderBrowseListSize()); - folderBrowser.setPaginator(paginator); - - final CheckboxGroup checkboxGroup = new CheckboxGroup(sourcesParameter); - browserForm.add(checkboxGroup); - final TableColumn checkboxCol = new TableColumn(); - checkboxCol.setHeaderValue( - new GlobalizedMessage("empty_text", CmsConstants.CMS_BUNDLE)); - checkboxCol.setCellRenderer(new TableCellRenderer() { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - - final Option result = new Option(key.toString(), - new Text("")); - result.setGroup(checkboxGroup); - return result; - } - - }); - folderBrowser.getColumnModel().add(0, checkboxCol); - - browserForm.add(paginator); - browserForm.add(folderBrowser); - final SimpleContainer actionFormContainer = new SimpleContainer(); - actionFormContainer.add(new Label( - new GlobalizedMessage( - "cms.ui.folder.edit_selection", - CmsConstants.CMS_FOLDER_BUNDLE))); - actionSelect = new SingleSelect(actionParameter); - actionSelect.addOption( - new Option(COPY, - new Label(new GlobalizedMessage( - "cms.ui.folder.copy.action", - CmsConstants.CMS_FOLDER_BUNDLE)))); - actionSelect.addOption( - new Option(MOVE, - new Label(new GlobalizedMessage( - "cms.ui.folder.move.action", - CmsConstants.CMS_FOLDER_BUNDLE)))); - actionFormContainer.add(actionSelect); - actionSubmit = new Submit( - "Go", - new GlobalizedMessage("cms.ui.folder.go", - CmsConstants.CMS_FOLDER_BUNDLE)); - actionFormContainer.add(actionSubmit); - browserForm.addProcessListener(new FormProcessListener() { - - @Override - public void process(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - moveCopyMode(state); - - } - - }); - browserForm.add(actionFormContainer); - - targetSelector = new TargetSelector(); - targetSelector.addProcessListener(new FormProcessListener() { - - @Override - public void process(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - browseMode(state); - targetSelector.setVisible(state, false); - - final Folder folder = targetSelector.getTarget(state); - final String[] objectIds = getSources(state); - - if (isCopy(state)) { - copyObjects(folder, objectIds); - } else if (isMove(state)) { - moveObjects(folder, objectIds); - } - - reset(state); - } - - }); - targetSelector.addValidationListener( - new TargetSelectorValidationListener()); - targetSelector.addSubmissionListener(new FormSubmissionListener() { - - @Override - public void submitted(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - if (targetSelector.isCancelled(state)) { - reset(state); - browseMode(state); - throw new FormProcessException(new GlobalizedMessage( - "cms.ui.folder.cancelled", - CmsConstants.CMS_FOLDER_BUNDLE)); - } - } - - }); - browseSegment.add(targetSelector); - -// browseSegment.add(paginator); -// browseSegment.add(folderBrowser); - browseSegment.add(browserForm); - -// currentFolderSegment = panel.addSegment(); -// currentFolderSegment.addHeader(new Text("Current folder")); -// final Label currentFolderLabel = new Label(); -// currentFolderLabel.addPrintListener(new PrintListener() { -// -// @Override -// public void prepare(final PrintEvent event) { -// final PageState state = event.getPageState(); -// final Label target = (Label) event.getTarget(); -// -// final long selectedId = Long.parseLong(selectionModel -// .getSelectedKey(state).toString()); -// final long currentFolderId = folderSelectionModel -// .getSelectedObject(state).getObjectId(); -// target.setLabel(String.format( -// "selectedId = %d; currentFolderId = %d", -// selectedId, -// currentFolderId)); -// } -// -// }); -// currentFolderSegment.add(currentFolderLabel); - actionsSegment = panel.addSegment(); - actionsSegment.setIdAttr("folder-browse"); - - final ActionGroup actions = new ActionGroup(); - actionsSegment.add(actions); - - final FolderCreateForm folderCreateForm = new FolderCreateForm( - "fcreat", folderSelectionModel); - folderCreateForm.addSubmissionListener(new FormSubmissionListener() { - - @Override - public void submitted(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - if (event.getSource() == folderCreateForm - && folderCreateForm.isCancelled(state)) { - browseMode(state); - throw new FormProcessException(new GlobalizedMessage( - "cms.ui.cancelled", CmsConstants.CMS_BUNDLE)); - - } - } - - }); - folderCreateForm.addProcessListener(new FormProcessListener() { - - @Override - public void process(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - final Object source = event.getSource(); - if (source == folderCreateForm) { - browseMode(state); - } - } - - }); - newFolderSegment = panel.addSegment( - new Label(new GlobalizedMessage("cms.ui.new_folder", - CmsConstants.CMS_BUNDLE)), - folderCreateForm); - - final FolderEditorForm folderEditorForm = new FolderEditorForm( - "fedit", folderSelectionModel); - folderEditorForm.addSubmissionListener(new FormSubmissionListener() { - - @Override - public void submitted(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - if (event.getSource() == folderEditorForm - && folderEditorForm.isCancelled(state)) { - browseMode(state); - throw new FormProcessException(new GlobalizedMessage( - "cms.ui.cancelled", CmsConstants.CMS_BUNDLE)); - } - } - - }); - folderEditorForm.addProcessListener(new FormProcessListener() { - - @Override - public void process(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - final Object source = event.getSource(); - if (source == folderEditorForm) { - browseMode(state); - } - } - - }); - editFolderSegment = panel.addSegment( - new Label(new GlobalizedMessage("cms.ui.edit_folder", - CmsConstants.CMS_BUNDLE)), - folderEditorForm); - - final ActionLink createFolderAction = new ActionLink( - new Label(new GlobalizedMessage("cms.ui.new_folder", - CmsConstants.CMS_BUNDLE))); - createFolderAction.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(final ActionEvent event) { - final PageState state = event.getPageState(); - final Object source = event.getSource(); - if (source == createFolderAction) { - newFolderMode(state); - } - } - - }); - actions.addAction(createFolderAction); - - final ActionLink editFolderAction = new ActionLink( - new Label(new GlobalizedMessage("cms.ui.edit_folder", - CmsConstants.CMS_BUNDLE))); - editFolderAction.addActionListener(new ActionListener() { - - @Override - public void actionPerformed(final ActionEvent event) { - final PageState state = event.getPageState(); - final Object source = event.getSource(); - if (source == editFolderAction) { - editFolderMode(state); - } - } - - }); - actions.addAction(editFolderAction); - - final Form newAssetForm = new Form("new-asset-form", - new BoxPanel(BoxPanel.HORIZONTAL)); - newAssetForm.setMethod("GET"); - newAssetForm.add(new Label(new GlobalizedMessage( - "cms.ui.assets.new", CmsConstants.CMS_BUNDLE))); - final SingleSelect newAssetTypeSelect = new SingleSelect( - selectedAssetTypeParam); - try { - newAssetTypeSelect.addPrintListener(new PrintListener() { - - @Override - public void prepare(final PrintEvent event) { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final AssetTypesManager typesManager = cdiUtil - .findBean(AssetTypesManager.class); - final SingleSelect target = (SingleSelect) event.getTarget(); - target.clearOptions(); - for (final AssetTypeInfo type : typesManager - .getAvailableAssetTypes()) { - final String labelKey = type.getLabelKey(); - final String labelBundle = type.getLabelBundle(); - final ResourceBundle bundle = ResourceBundle - .getBundle(labelBundle); - final String label = bundle.getString(labelKey); - target.addOption(new Option( - type.getAssetClass().getName(), - new Text(label))); - } - } - - }); - } catch (TooManyListenersException ex) { - throw new UnexpectedErrorException(ex); - } - newAssetForm.add(newAssetTypeSelect); - newAssetForm.add(new Submit(new GlobalizedMessage( - "cms.ui.assets.new.create", CmsConstants.CMS_BUNDLE))); - newAssetForm.addProcessListener(new FormProcessListener() { - - @Override - public void process(final FormSectionEvent event) - throws FormProcessException { - editAssetMode(event.getPageState()); - } - - }); - - actionsSegment.add(newAssetForm); - - final MetaForm editAssetForm = new MetaForm("editAsset") { - - @Override - public Form buildForm(final PageState state) { - - final boolean newAsset; - - final Long selectedAssetId = selectedAssetModel - .getSelectedKey(state); - newAsset = selectedAssetId == null; - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - - final String selectedAssetType; - if (newAsset) { - selectedAssetType = (String) newAssetTypeSelect - .getValue(state); - } else { - final AssetRepository assetRepo = cdiUtil - .findBean(AssetRepository.class); - final Asset asset = assetRepo.findById(selectedAssetModel - .getSelectedKey(state)) - .orElseThrow(() -> new IllegalArgumentException( - String.format("No asset with ID %d in the " - + "database.", - selectedAssetModel - .getSelectedKey(state)))); - selectedAssetType = asset.getClass().getName(); - } - - final AssetTypesManager typesManager = cdiUtil - .findBean(AssetTypesManager.class); - final AssetTypeInfo typeInfo = typesManager - .getAssetTypeInfo(selectedAssetType); - final Class assetForm = typeInfo - .getAssetForm(); - try { - return assetForm - .getConstructor(AssetPane.class) - .newInstance(AssetPane.this); - } catch (NoSuchMethodException - | SecurityException - | InstantiationException - | IllegalAccessException - | InvocationTargetException ex) { - throw new UnexpectedErrorException(String.format( - "Failed to create form '%s' for editing assets " - + "of type '%s'.", - assetForm.getName(), - selectedAssetType)); - } - - } - - }; - editAssetSegment = panel.addSegment(); - editAssetSegment.addHeader( - new Label(new PrintListener() { - - @Override - public void prepare(final PrintEvent event) { - - final PageState state = event.getPageState(); - final Label target = (Label) event.getTarget(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final AssetTypesManager typesManager = cdiUtil - .findBean(AssetTypesManager.class); - - if (selectedAssetModel.isSelected(state)) { - target.setLabel( - new GlobalizedMessage( - "cms.ui.admin.assets.edit", - CmsConstants.CMS_BUNDLE)); - } else { - final String assetType = (String) newAssetTypeSelect - .getValue(state); - final AssetTypeInfo typeInfo = typesManager - .getAssetTypeInfo(assetType); - final ResourceBundle bundle = ResourceBundle.getBundle( - typeInfo.getLabelBundle()); - final String typeLabel = bundle - .getString(typeInfo.getLabelKey()); - - target.setLabel(new GlobalizedMessage( - "cms.ui.admin.assets.create", - CmsConstants.CMS_BUNDLE, - new Object[]{typeLabel})); - } - } - - })); - editAssetSegment.add(editAssetForm); - - folderPermissionsSegment = panel.addSegment(); - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final PermissionManager permissionManager = cdiUtil - .findBean(PermissionManager.class); - final String[] privileges = permissionManager - .listDefiniedPrivileges(AssetPrivileges.class) - .toArray(new String[]{}); - final Map privilegeNameMap = new HashMap<>(); - Arrays - .stream(privileges) - .forEach(privilege -> privilegeNameMap.put(privilege, privilege)); - final CcmObjectSelectionModel objSelectionModel - = new CcmObjectSelectionModel<>( - CcmObject.class, folderSelectionModel); - final CMSPermissionsPane folderPermissionsPane = new CMSPermissionsPane( - privileges, privilegeNameMap, objSelectionModel); - folderPermissionsSegment.add(folderPermissionsPane); - - - return panel; - - } - - protected void browseMode(final PageState state) { - tree.setVisible(state, true); - browseSegment.setVisible(state, true); - folderBrowser.setVisible(state, true); - browserForm.setVisible(state, true); - targetSelector.setVisible(state, false); - actionsSegment.setVisible(state, true); - newFolderSegment.setVisible(state, false); - editFolderSegment.setVisible(state, false); - editAssetSegment.setVisible(state, false); - folderPermissionsSegment.setVisible(state, true); - } - - protected void moveCopyMode(final PageState state) { - tree.setVisible(state, false); - browseSegment.setVisible(state, true); - folderBrowser.setVisible(state, false); - browserForm.setVisible(state, false); - targetSelector.setVisible(state, true); - actionsSegment.setVisible(state, false); - newFolderSegment.setVisible(state, false); - editFolderSegment.setVisible(state, false); - targetSelector.expose(state); - editAssetSegment.setVisible(state, false); - folderPermissionsSegment.setVisible(state, false); - } - - protected void newFolderMode(final PageState state) { - tree.setVisible(state, false); - browseSegment.setVisible(state, false); - folderBrowser.setVisible(state, false); - browserForm.setVisible(state, false); - targetSelector.setVisible(state, false); - actionsSegment.setVisible(state, false); - newFolderSegment.setVisible(state, true); - editFolderSegment.setVisible(state, false); - editAssetSegment.setVisible(state, false); - folderPermissionsSegment.setVisible(state, false); - } - - protected void editFolderMode(final PageState state) { - tree.setVisible(state, false); - browseSegment.setVisible(state, false); - targetSelector.setVisible(state, false); - actionsSegment.setVisible(state, false); - newFolderSegment.setVisible(state, false); - editFolderSegment.setVisible(state, true); - editAssetSegment.setVisible(state, false); - folderPermissionsSegment.setVisible(state, false); - } - - protected void editAssetMode(final PageState state) { - tree.setVisible(state, false); - browseSegment.setVisible(state, false); - targetSelector.setVisible(state, false); - actionsSegment.setVisible(state, false); - newFolderSegment.setVisible(state, false); - editFolderSegment.setVisible(state, false); - editAssetSegment.setVisible(state, true); - folderPermissionsSegment.setVisible(state, false); - } - - @Override - public void register(final Page page) { - - super.register(page); - - page.addActionListener(new TreeListener()); - page.addActionListener(new FolderListener()); - - page.setVisibleDefault(tree, true); - page.setVisibleDefault(browseSegment, true); - page.setVisibleDefault(folderBrowser, true); - page.setVisibleDefault(browserForm, true); - page.setVisibleDefault(targetSelector, false); - page.setVisibleDefault(actionsSegment, true); - page.setVisibleDefault(newFolderSegment, false); - page.setVisibleDefault(editFolderSegment, false); - page.setVisibleDefault(editAssetSegment, false); - page.setVisibleDefault(folderPermissionsSegment, true); - - page.addComponentStateParam(this, actionParameter); - page.addComponentStateParam(this, sourcesParameter); - page.addComponentStateParam(this, selectedAssetTypeParam); - page.addComponentStateParam(this, - selectedAssetModel.getStateParameter()); - } - - @Override - public void reset(final PageState state) { - - super.reset(state); - - folderBrowser.getPaginator().reset(state); - - state.setValue(actionParameter, null); - state.setValue(sourcesParameter, null); - - } - - protected SingleSelectionModel getSelectedAssetModel() { - return selectedAssetModel; - } - - protected FolderSelectionModel getFolderSelectionModel() { - return folderSelectionModel; - } - - private String[] getSources(final PageState state) { - - final String[] result = (String[]) state.getValue(sourcesParameter); - - if (result == null) { - return new String[0]; - } else { - return result; - } - } - - protected final boolean isMove(final PageState state) { - return MOVE.equals(getAction(state)); - } - - protected final boolean isCopy(final PageState state) { - return COPY.equals(getAction(state)); - } - - private String getAction(final PageState state) { - return (String) state.getValue(actionParameter); - } - - protected void moveObjects(final Folder target, final String[] objectIds) { - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final AssetFolderBrowserController controller = cdiUtil.findBean( - AssetFolderBrowserController.class); - - controller.moveObjects(target, objectIds); - } - - protected void copyObjects(final Folder target, final String[] objectIds) { - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final AssetFolderBrowserController controller = cdiUtil.findBean( - AssetFolderBrowserController.class); - - controller.copyObjects(target, objectIds); - } - - private final class FolderListener implements ActionListener { - - @Override - @SuppressWarnings("unchecked") - public void actionPerformed(final ActionEvent event) { - - final PageState state = event.getPageState(); - - if (!selectionModel.isSelected(state)) { - final String folder = state - .getRequest() - .getParameter(SET_FOLDER); - - if (folder == null) { - final Category root = CMS - .getContext() - .getContentSection() - .getRootAssetsFolder(); - final Long folderId = root.getObjectId(); - - selectionModel.setSelectedKey(state, folderId); - } else { - selectionModel.setSelectedKey(state, Long.parseLong(folder)); - } - } - } - - } - - private final class TreeListener implements ActionListener { - - @Override - public void actionPerformed(final ActionEvent event) { - - final PageState state = event.getPageState(); - - final Category root = CMS - .getContext() - .getContentSection() - .getRootAssetsFolder(); - - if (!root.equals(folderRequestLocal.getFolder(state))) { - // Expand the ancestor nodes of the currently - // selected node. - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final FolderTreeModelController controller = cdiUtil.findBean( - FolderTreeModelController.class); - final List ancestorIds = controller.findAncestorIds( - folderRequestLocal.getFolder(state)); - ancestorIds.forEach(id -> tree.expand(id.toString(), state)); - - } - } - - } - - private class TargetSelector extends Form implements Resettable { - - private final FolderSelectionModel targetFolderModel; - private final AssetFolderTree folderTree; - private final Submit cancelButton; - - public TargetSelector() { - super("targetSelector", new BoxPanel()); - setMethod(GET); - targetFolderModel = new FolderSelectionModel("target") { - - @Override - protected Long getRootFolderID(final PageState state) { - final ContentSection section = CMS - .getContext() - .getContentSection(); - return section.getRootAssetsFolder().getObjectId(); - } - - }; - folderTree = new AssetFolderTree(targetFolderModel); - - folderTree.setCellRenderer(new FolderTreeCellRenderer()); - - final Label label = new Label(new PrintListener() { - - @Override - public void prepare(final PrintEvent event) { - - final PageState state = event.getPageState(); - final Label label = (Label) event.getTarget(); - final int numberOfItems = getSources(state).length; - final Category folder = (Category) folderSelectionModel - .getSelectedObject(state); - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final CategoryManager categoryManager = cdiUtil - .findBean(CategoryManager.class); - - final String targetFolderPath; - if (targetFolderModel.getSelectedObject(state) == null) { - targetFolderPath = ""; - } else { - targetFolderPath = categoryManager.getCategoryPath( - targetFolderModel.getSelectedObject(state)); - } - - if (isMove(state)) { - label.setLabel(new GlobalizedMessage( - "cms.ui.folder.move", - CmsConstants.CMS_FOLDER_BUNDLE, - new Object[]{ - numberOfItems, - categoryManager.getCategoryPath(folder), - targetFolderPath - })); - } else if (isCopy(state)) { - label.setLabel(new GlobalizedMessage( - "cms.ui.folder.copy", - CMS_BUNDLE, - new Object[]{ - numberOfItems, - categoryManager.getCategoryPath(folder), - targetFolderPath - })); - } - } - - }); - - label.setOutputEscaping(false); - add(label); - add(folderTree); - add(new FormErrorDisplay(this)); - final SaveCancelSection saveCancelSection = new SaveCancelSection(); - cancelButton = saveCancelSection.getCancelButton(); - add(saveCancelSection); - } - - @Override - public void register(final Page page) { - super.register(page); - page.addComponentStateParam(this, - targetFolderModel.getStateParameter()); - } - - public void expose(final PageState state) { - - final Folder folder = folderSelectionModel.getSelectedObject(state); - targetFolderModel.clearSelection(state); - if (folder != null) { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final FolderManager folderManager = cdiUtil.findBean( - FolderManager.class); - if (!folderManager.getParentFolder(folder).isPresent()) { - folderTree.expand(Long.toString(folder.getObjectId()), - state); - } else { - final List parents = folderManager - .getParentFolders(folder); - parents - .stream() - .map(parent -> Long.toString(parent.getObjectId())) - .forEach(folderId -> folderTree.expand(folderId, - state)); - } - } - } - - @Override - public void reset(final PageState state) { - folderTree.clearSelection(state); - state.setValue(folderTree.getSelectionModel().getStateParameter(), - null); - } - - public Folder getTarget(final PageState state) { - return targetFolderModel.getSelectedObject(state); - } - - public boolean isCancelled(final PageState state) { - return cancelButton.isSelected(state); - } - - } - - private class FolderTreeCellRenderer implements TreeCellRenderer { - - private final RequestLocal invalidFoldersRequestLocal - = new RequestLocal(); - - /** - * Render the folders appropriately. The selected folder is a bold - * label. Invalid folders are plain labels. Unselected, valid folders - * are control links. Invalid folders are: the parent folder of the - * sources, any of the sources, and any subfolders of the sources. - */ - @Override - @SuppressWarnings("unchecked") - public Component getComponent(final Tree tree, - final PageState state, - final Object value, - final boolean isSelected, - final boolean isExpanded, - final boolean isLeaf, - final Object key) { - - // Get the list of invalid folders once per request. - final List invalidFolders; - - if (invalidFoldersRequestLocal.get(state) == null) { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final AssetFolderBrowserController controller = cdiUtil - .findBean(AssetFolderBrowserController.class); - invalidFolders = controller.createInvalidTargetsList( - Arrays.asList(getSources(state))); - invalidFoldersRequestLocal.set(state, invalidFolders); - } else { - invalidFolders = (List) invalidFoldersRequestLocal - .get(state); - } - final Label label = new Label(value.toString()); - - if (invalidFolders.contains(String.format( - FOLDER_BROWSER_KEY_PREFIX_FOLDER + "%s", key))) { - return label; - } - - // Bold if selected - if (isSelected) { - label.setFontWeight(Label.BOLD); - return label; - } - - return new ControlLink(label); - } - - } - - private class TargetSelectorValidationListener - implements FormValidationListener { - - @Override - public void validate(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - if (getSources(state).length <= 0) { - throw new IllegalStateException("No source items specified"); - } - - final Folder target = targetSelector.getTarget(state); - final FormData data = event.getFormData(); - if (target == null) { - data.addError(new GlobalizedMessage( - "cms.ui.folder.need_select_target_folder", - CmsConstants.CMS_FOLDER_BUNDLE)); - //If the target is null, we can skip the rest of the checks - return; - } - - if (target.equals(folderSelectionModel.getSelectedObject(state))) { - data.addError(new GlobalizedMessage( - "cms.ui.folder.not_within_same_folder", - CmsConstants.CMS_FOLDER_BUNDLE)); - } - - // check create item permission - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final PermissionChecker permissionChecker = cdiUtil.findBean( - PermissionChecker.class); - if (!permissionChecker.isPermitted( - ItemPrivileges.CREATE_NEW, target)) { - data.addError("cms.ui.folder.no_permission_for_item", - CmsConstants.CMS_FOLDER_BUNDLE); - } - - for (String source : getSources(state)) { - - validateObject(source, target, state, data); - - } - } - - private void validateObject(final String objectId, - final Folder target, - final PageState state, - final FormData data) { - - Objects.requireNonNull(objectId, "objectId can't be null."); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final FolderRepository folderRepo = cdiUtil - .findBean(FolderRepository.class); - final AssetRepository assetRepo = cdiUtil - .findBean(AssetRepository.class); - final AssetManager assetManager = cdiUtil - .findBean(AssetManager.class); - final AssetFolderBrowserController controller = cdiUtil - .findBean(AssetFolderBrowserController.class); - final FolderManager folderManager = cdiUtil - .findBean(FolderManager.class); - final PermissionChecker permissionChecker = cdiUtil.findBean( - PermissionChecker.class); - - final CcmObject object; - final String name; - if (objectId.startsWith(FOLDER_BROWSER_KEY_PREFIX_FOLDER)) { - - final long folderId = Long.parseLong(objectId.substring( - FOLDER_BROWSER_KEY_PREFIX_FOLDER.length())); - final Folder folder = folderRepo.findById(folderId).orElseThrow( - () -> new IllegalArgumentException(String.format( - "No folder with id %d in database.", folderId))); - - name = folder.getName(); - - //Check if folder or subfolder contains in use assets - if (isMove(state)) { - final FolderManager.FolderIsMovable movable = folderManager - .folderIsMovable(folder, target); - switch (movable) { - case DIFFERENT_SECTIONS: - addErrorMessage(data, - "cms.ui.folder.different_sections", - name); - break; - case HAS_IN_USE_ASSETS: - addErrorMessage(data, - "cms.ui.folder.has_in_use_assets", - name); - break; - case DIFFERENT_TYPES: - addErrorMessage(data, - "cms.ui.folder.different_folder_types", - name); - break; - case IS_ROOT_FOLDER: - addErrorMessage(data, - "cms.ui.folder.is_root_folder", - name); - break; - case SAME_FOLDER: - addErrorMessage(data, - "cms.ui.folder.same_folder", - name); - break; - case YES: - //Nothing - break; - default: - throw new UnexpectedErrorException(String.format( - "Unknown state '%s' for '%s'.", - movable, - FolderManager.FolderIsMovable.class. - getName())); - } - } - - object = folder; - } else if (objectId.startsWith(FOLDER_BROWSER_KEY_PREFIX_ASSET)) { - final long assetId = Long.parseLong(objectId.substring( - FOLDER_BROWSER_KEY_PREFIX_ASSET.length())); - final Asset asset = assetRepo - .findById(assetId) - .orElseThrow(() -> new IllegalArgumentException( - String.format( - "No asset with id %d in the database.", - assetId))); - - name = asset.getDisplayName(); - - if (isMove(state) && assetManager.isAssetInUse(asset)) { - addErrorMessage(data, "cms.ui.folder.item_is_live", name); - } - - object = asset; - } else { - throw new IllegalArgumentException(String.format( - "Provided objectId '%s' does not start with '%s' " - + "or '%s'.", - objectId, - FOLDER_BROWSER_KEY_PREFIX_FOLDER, - FOLDER_BROWSER_KEY_PREFIX_ASSET)); - } - - final long count = controller.countObjects(target, name); - if (count > 0) { - // there is an item or subfolder in the target folder that already has this name - addErrorMessage(data, "cms.ui.folder.item_already_exists", - name); - } - - if (!(permissionChecker.isPermitted( - ItemPrivileges.DELETE, object)) - && isMove(state)) { - addErrorMessage(data, - "cms.ui.folder.no_permission_for_item", - object.getDisplayName()); - } - - } - - } - - private void addErrorMessage(final FormData data, - final String message, - final String itemName) { - data.addError(new GlobalizedMessage(message, - CmsConstants.CMS_FOLDER_BUNDLE, - new Object[]{itemName})); - } - - private class AssetFolderTree extends Tree { - - public AssetFolderTree(final FolderSelectionModel folderSelectionModel) { - - super(new FolderTreeModelBuilder() { - - @Override - protected Folder getRootFolder(final PageState state) { - final ContentSection section = CMS - .getContext() - .getContentSection(); - - return section.getRootAssetsFolder(); - } - - }); - setSelectionModel(folderSelectionModel); - } - - @Override - public void setSelectedKey(final PageState state, final Object key) { - if (key instanceof String) { - final Long keyAsLong; - if (((String) key).startsWith( - FOLDER_BROWSER_KEY_PREFIX_FOLDER)) { - keyAsLong = Long.parseLong(((String) key).substring( - FOLDER_BROWSER_KEY_PREFIX_FOLDER.length())); - } else { - keyAsLong = Long.parseLong((String) key); - } - super.setSelectedKey(state, keyAsLong); - } else if (key instanceof Long) { - super.setSelectedKey(state, key); - } else { - //We know that a FolderSelectionModel only takes keys of type Long. - //Therefore we try to cast here - final Long keyAsLong = (Long) key; - super.setSelectedKey(state, keyAsLong); - } - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchWidget.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchWidget.java deleted file mode 100644 index 8b95bc58d..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchWidget.java +++ /dev/null @@ -1,114 +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.assets; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.form.Widget; -import com.arsdigita.bebop.parameters.LongParameter; -import com.arsdigita.cms.CMS; -import com.arsdigita.xml.Element; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.l10n.GlobalizationHelper; -import org.librecms.assets.AssetTypeInfo; -import org.librecms.assets.AssetTypesManager; -import org.librecms.contentsection.Asset; -import org.librecms.contentsection.AssetRepository; -import org.librecms.contentsection.ContentSection; - -import java.util.Map; -import java.util.ResourceBundle; - -/** - * A widget for selecting an asset. The widget does not contain any other - * widgets, only the information required to create an HTML/JavaScript dialog - * for selecting an asset. To create the dialog the - * {@link org.librecms.contentsection.rs.Assets} class can be used which - * provides several methods for getting the assets of an content section. - * - * @author Jens Pelzetter - */ -public class AssetSearchWidget extends Widget { - - private Class type; - - public AssetSearchWidget(final String name) { - super(new LongParameter(name)); - } - - public AssetSearchWidget(final String name, - final Class type) { - this(name); - this.type = type; - } - - @Override - public boolean isCompound() { - return true; - } - - @Override - protected String getType() { - return "asset-search-widget"; - } - - @Override - protected String getElementTag() { - return "cms:asset-search-widget"; - } - - @Override - public void generateWidget(final PageState state, - final Element parent) { - - final Element widget = parent.newChildElement(getElementTag(), - CMS.CMS_XML_NS); - - widget.addAttribute("name", getName()); - - if (type != null) { - widget.addAttribute("asset-type", type.getName()); - } - - final ContentSection section = CMS.getContext().getContentSection(); - widget.addAttribute("content-section", section.getLabel()); - - final Long value = (Long) getValue(state); - if (value != null) { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final AssetSearchWidgetController controller = cdiUtil - .findBean(AssetSearchWidgetController.class); - - final Map data = controller.getData(value); - - final Element selected = widget - .newChildElement("cms:selected-asset", CMS.CMS_XML_NS); - selected.addAttribute( - "assetId", data.get(AssetSearchWidgetController.OBJECT_ID) - ); - selected.addAttribute("title", - data.get(AssetSearchWidgetController.TITLE)); - selected.addAttribute("type", - data.get(AssetSearchWidgetController.TYPE)); - - exportAttributes(widget); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchWidgetController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchWidgetController.java deleted file mode 100644 index cac64adad..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/AssetSearchWidgetController.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (C) 2019 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.assets; - -import org.libreccm.l10n.GlobalizationHelper; -import org.librecms.assets.AssetTypeInfo; -import org.librecms.assets.AssetTypesManager; -import org.librecms.contentsection.Asset; -import org.librecms.contentsection.AssetRepository; - -import java.util.HashMap; -import java.util.Map; -import java.util.ResourceBundle; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.transaction.Transactional; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -public class AssetSearchWidgetController { - - protected static final String OBJECT_ID = "objectId"; - protected static final String TYPE = "type"; - protected static final String TITLE = "title"; - - @Inject - private AssetRepository assetRepository; - - @Inject - private AssetTypesManager typesManager; - - @Inject - private GlobalizationHelper globalizationHelper; - - @Transactional(Transactional.TxType.REQUIRED) - public Map getData(final long assetId) { - - final Asset asset = assetRepository - .findById(assetId) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No Asset with ID %d in the database.", assetId))); - - final Map data = new HashMap<>(); - - data.put(OBJECT_ID, Long.toString(asset.getObjectId())); - - data.put(TITLE, - globalizationHelper - .getValueFromLocalizedString(asset.getTitle())); - final AssetTypeInfo typeInfo = typesManager - .getAssetTypeInfo(asset.getClass().getName()); - final ResourceBundle bundle = ResourceBundle - .getBundle(typeInfo.getLabelBundle(), - globalizationHelper.getNegotiatedLocale()); - final String typeLabel = bundle.getString(typeInfo.getLabelKey()); - - data.put(TYPE, typeLabel); - - return data; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/IsControllerForAssetType.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/IsControllerForAssetType.java deleted file mode 100644 index 9962cf2fa..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/IsControllerForAssetType.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (C) 2019 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.assets; - -import org.librecms.contentsection.Asset; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import javax.inject.Qualifier; - -/** - * - * @author Jens Pelzetter - */ -@Qualifier -@Retention(RetentionPolicy.RUNTIME) -@Target({ - ElementType.METHOD, - ElementType.FIELD, - ElementType.PARAMETER, - ElementType.TYPE -}) -public @interface IsControllerForAssetType { - - Class value(); - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/ItemSearchWidget.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/ItemSearchWidget.java deleted file mode 100644 index c43804d81..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/assets/ItemSearchWidget.java +++ /dev/null @@ -1,119 +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.assets; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.form.Widget; -import com.arsdigita.bebop.parameters.LongParameter; -import com.arsdigita.cms.CMS; -import com.arsdigita.xml.Element; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.l10n.GlobalizationHelper; -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.contentsection.ContentSection; -import org.librecms.contenttypes.ContentTypeInfo; -import org.librecms.contenttypes.ContentTypesManager; - -import java.util.ResourceBundle; - -/** - * - * @author Jens Pelzetter - */ -public class ItemSearchWidget extends Widget { - - private Class type; - - public ItemSearchWidget(final String name) { - super(new LongParameter(name)); - } - - @Override - public boolean isCompound() { - return true; - } - - @Override - protected String getType() { - return "item-search-widget"; - } - - @Override - protected String getElementTag() { - return "cms:item-search-widget"; - } - - @Override - public void generateWidget(final PageState state, - final Element parent) { - - final Element widget = parent.newChildElement(getElementTag(), - CMS.CMS_XML_NS); - - widget.addAttribute("name", getName()); - widget.addAttribute("content-section", - CMS.getContext().getContentSection().getLabel()); - - if (type != null) { - widget.addAttribute("asset-type", type.getName()); - } - -// final ContentSection section = CMS.getContext().getContentSection(); -// widget.addAttribute("content-section", section.getLabel()); - - final Long value = (Long) getValue(state); - if (value != null) { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentItemRepository itemRepo = cdiUtil - .findBean(ContentItemRepository.class); - final ContentTypesManager typesManager = cdiUtil - .findBean(ContentTypesManager.class); - final GlobalizationHelper globalizationHelper = cdiUtil - .findBean(GlobalizationHelper.class); - - final ContentItem item = itemRepo - .findById(value) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No ContentItem with ID %d in the database.", value))); - - final Element selected = widget - .newChildElement("cms:selected-content-item", CMS.CMS_XML_NS); - selected.addAttribute("contentItemId", - Long.toString(item.getObjectId())); - selected.addAttribute("name", item.getDisplayName()); - selected.addAttribute( - "title", - globalizationHelper.getValueFromLocalizedString(item.getTitle())); - final ContentTypeInfo typeInfo = typesManager - .getContentTypeInfo(item.getClass()); - final ResourceBundle bundle = ResourceBundle - .getBundle(typeInfo.getLabelBundle(), - globalizationHelper.getNegotiatedLocale()); - final String typeLabel = bundle.getString(typeInfo.getLabelKey()); - selected.addAttribute("type", typeLabel); - - exportAttributes(widget); - - } - - } - -} diff --git a/ccm-cms/src/main/java/org/librecms/assets/AssetType.java b/ccm-cms/src/main/java/org/librecms/assets/AssetType.java index f8be27c60..cf3787ad1 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/AssetType.java +++ b/ccm-cms/src/main/java/org/librecms/assets/AssetType.java @@ -18,7 +18,6 @@ */ package org.librecms.assets; -import com.arsdigita.cms.ui.assets.AbstractAssetForm; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/ccm-cms/src/main/java/org/librecms/assets/AssetTypeInfo.java b/ccm-cms/src/main/java/org/librecms/assets/AssetTypeInfo.java index 4d0012106..e00bf2e56 100644 --- a/ccm-cms/src/main/java/org/librecms/assets/AssetTypeInfo.java +++ b/ccm-cms/src/main/java/org/librecms/assets/AssetTypeInfo.java @@ -18,8 +18,6 @@ */ package org.librecms.assets; -import com.arsdigita.cms.ui.assets.AbstractAssetForm; - import org.librecms.contentsection.Asset; import java.util.Objects; @@ -56,11 +54,6 @@ public class AssetTypeInfo { */ private Class assetClass; - /** - * The form for editing and creating asset of the type described. - */ - private Class assetForm; - public String getLabelBundle() { return labelBundle; } @@ -101,14 +94,6 @@ public class AssetTypeInfo { this.assetClass = assetClass; } - public Class getAssetForm() { - return assetForm; - } - - public void setAssetForm(final Class assetForm) { - this.assetForm = assetForm; - } - @Override public int hashCode() { int hash = 5; @@ -117,7 +102,6 @@ public class AssetTypeInfo { hash = 59 * hash + Objects.hashCode(descriptionBundle); hash = 59 * hash + Objects.hashCode(descriptionKey); hash = 59 * hash + Objects.hashCode(assetClass); - hash = 59 * hash + Objects.hashCode(assetForm); return hash; } @@ -148,38 +132,35 @@ public class AssetTypeInfo { if (!Objects.equals(descriptionKey, other.getDescriptionKey())) { return false; } - if (!Objects.equals(assetClass, other.getAssetClass())) { - return false; - } - return Objects.equals(assetForm, other.getAssetForm()); + return Objects.equals(assetClass, other.getAssetClass()); } - + private boolean canEqual(final Object obj) { return obj instanceof AssetTypeInfo; } - + @Override public final String toString() { return toString(""); } - + public String toString(final String data) { - return String.format("%s{ " - + "labelBundle = \"%s\", " - + "labelKey = \"%s\", " - + "descriptionBundle = \"%s\", " - + "descriptionKey = \"%s\", " - + "assetClass = \"%s\", " - + "assetForm = \"%s\"%s " - + " }", - super.toString(), - labelBundle, - labelKey, - descriptionBundle, - descriptionKey, - Objects.toString(assetClass), - Objects.toString(assetForm), - data); + return String.format( + "%s{ " + + "labelBundle = \"%s\", " + + "labelKey = \"%s\", " + + "descriptionBundle = \"%s\", " + + "descriptionKey = \"%s\", " + + "assetClass = \"%s\"%s " + + " }", + super.toString(), + labelBundle, + labelKey, + descriptionBundle, + descriptionKey, + Objects.toString(assetClass), + data + ); } } diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/rs/Assets.java b/ccm-cms/src/main/java/org/librecms/contentsection/rs/Assets.java index d00893b84..9dbccb516 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/rs/Assets.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/rs/Assets.java @@ -18,7 +18,6 @@ */ package org.librecms.contentsection.rs; -import com.arsdigita.cms.ui.assets.AssetSearchWidget; import com.arsdigita.kernel.KernelConfig; import org.libreccm.configuration.ConfigurationManager; @@ -64,8 +63,7 @@ import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; /** - * Provides a Web Service (build using JAX-RS). Used for example by the - * {@link AssetSearchWidget}. + * Provides a Web Service (build using JAX-RS). * * @author Jens Pelzetter */ From 7a62bc4ad23ac920f39ad0a1b2afdec208f8ad94 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 16 Mar 2022 19:36:55 +0100 Subject: [PATCH 07/63] Removed deprecated package com/arsdigita/cms/ui/templates from ccm-cms --- .../com/arsdigita/cms/ui/ContentItemPage.java | 8 +- .../cms/ui/category/CategoryItemPane.java | 3 +- .../cms/ui/templates/CategoryTemplates.java | 370 ------------------ .../cms/ui/templates/ItemTemplates.java | 262 ------------- 4 files changed, 4 insertions(+), 639 deletions(-) delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/templates/CategoryTemplates.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/templates/ItemTemplates.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java index 13eb91680..34a3fcb53 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java @@ -47,7 +47,6 @@ import com.arsdigita.cms.ui.item.ItemLanguages; import com.arsdigita.cms.ui.item.Summary; import com.arsdigita.cms.ui.lifecycle.ItemLifecycleAdminPane; import com.arsdigita.cms.ui.revision.ItemRevisionAdminPane; -import com.arsdigita.cms.ui.templates.ItemTemplates; import com.arsdigita.cms.ui.workflow.ItemWorkflowAdminPane; import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.kernel.KernelConfig; @@ -151,7 +150,6 @@ public class ContentItemPage extends CMSPage implements ActionListener { private final WizardSelector wizardPane; private final ItemLanguages languagesPane; private final ItemRevisionAdminPane revisionsPane; - private final ItemTemplates templatesPane; private final Link previewLink; private final GlobalNavigation globalNavigation; @@ -276,7 +274,7 @@ public class ContentItemPage extends CMSPage implements ActionListener { workflowPane = new ItemWorkflowAdminPane(itemId); // Make this use m_item XXX lifecyclePane = new ItemLifecycleAdminPane(itemRequestLocal); revisionsPane = new ItemRevisionAdminPane(itemRequestLocal); - templatesPane = new ItemTemplates(itemSelectionModel); +// templatesPane = new ItemTemplates(itemSelectionModel); // Create tabbed pane. tabbedPane = new TabbedPane(); @@ -295,8 +293,8 @@ public class ContentItemPage extends CMSPage implements ActionListener { lifecyclePane); tabbedPane.addTab(new Label(gz("cms.ui.item.history")), revisionsPane); - tabbedPane.addTab(new Label(gz("cms.ui.item.templates")), - templatesPane); +// tabbedPane.addTab(new Label(gz("cms.ui.item.templates")), +// templatesPane); tabbedPane.addActionListener(new ActionListener() { diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryItemPane.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryItemPane.java index afcc40d62..3b033c4eb 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryItemPane.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/category/CategoryItemPane.java @@ -36,7 +36,6 @@ import com.arsdigita.cms.ui.BaseItemPane; import com.arsdigita.cms.ui.CMSForm; import com.arsdigita.cms.ui.ContentItemPage; import com.arsdigita.cms.ui.VisibilityComponent; -import com.arsdigita.cms.ui.templates.CategoryTemplates; import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.kernel.KernelConfig; import com.arsdigita.toolbox.ui.ActionGroup; @@ -467,7 +466,7 @@ class CategoryItemPane extends BaseItemPane { final ActionGroup group = new ActionGroup(); setBody(group); - group.setSubject(new CategoryTemplates(m_category)); +// group.setSubject(new CategoryTemplates(m_category)); // XXX secvis //group.addAction(link); } diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/templates/CategoryTemplates.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/templates/CategoryTemplates.java deleted file mode 100755 index e651d550b..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/templates/CategoryTemplates.java +++ /dev/null @@ -1,370 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.templates; - -import com.arsdigita.bebop.*; -import com.arsdigita.bebop.event.ActionEvent; -import com.arsdigita.bebop.event.ActionListener; -import com.arsdigita.bebop.event.FormProcessListener; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.event.PrintEvent; -import com.arsdigita.bebop.event.PrintListener; -import com.arsdigita.bebop.event.TableActionAdapter; -import com.arsdigita.bebop.event.TableActionEvent; -import com.arsdigita.bebop.form.Hidden; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.form.SingleSelect; -import com.arsdigita.bebop.form.Submit; -import com.arsdigita.bebop.parameters.BigDecimalParameter; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.table.TableCellRenderer; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.cms.CMS; -import com.arsdigita.cms.ui.CMSContainer; -import com.arsdigita.cms.ui.FormSecurityListener; -import com.arsdigita.cms.ui.category.CategoryComponentAccess; -import com.arsdigita.cms.ui.category.CategoryRequestLocal; -import com.arsdigita.kernel.ui.ACSObjectSelectionModel; -import com.arsdigita.util.Assert; -import com.arsdigita.util.UncheckedWrapperException; - -import java.util.TooManyListenersException; - -/** - * This component will eventually contain the full templates UI - * for content items. It is just a placeholder for now. - * - * @author Stanislav Freidin (sfreidin@arsdigita.com) - * @author Yannick Bülter - */ -public class CategoryTemplates extends CMSContainer { - private CategoryRequestLocal m_category; - private ACSObjectSelectionModel m_types; - private SingleSelectionModel m_contexts; - - private CMSContainer m_display; - private CMSContainer m_assign; - - public static final String ASSIGN_TEMPLATE = "assignTemplate"; - - /** - * TODO: Needs to be implemented and will then finally - * Construct a new CategoryTemplates component - * - * @param category the CategoryRequestLocal that will supply the - * current content item - */ - public CategoryTemplates(CategoryRequestLocal category) { - super(); - m_category = category; - add(new Text("Placeholder")); -// -// m_types = new ACSObjectSelectionModel(new BigDecimalParameter("t")); -// m_contexts = new ParameterSingleSelectionModel(new StringParameter("c")); -// -// AssignForm form = new AssignForm("assign", -// m_types, -// m_contexts); -// form.addSubmissionListener -// (new FormSecurityListener(SecurityManager.CATEGORY_ADMIN)); -// -// form.addProcessListener(new FormProcessListener() { -// public void process(FormSectionEvent e) -// throws FormProcessException { -// -// PageState state = e.getPageState(); -// -// m_display.setVisible(state, false); -// m_assign.setVisible(state, true); -// } -// }); -// -// CategoryTemplatesListingImpl l = new CategoryTemplatesListingImpl(category); -// SegmentedPanel st = new SegmentedPanel(); -// st.addSegment(new Label("Assigned Templates"), l); -// -// m_display = new CMSContainer(); -// m_display.add(form); -// m_display.add(st); -// add(m_display); -// -// SegmentedPanel sa = new SegmentedPanel(); -// Label assignLabel = new Label("dummy"); -// assignLabel.addPrintListener(new PrintListener() { -// public void prepare(PrintEvent e) { -// PageState s = e.getPageState(); -// Label targetLabel = (Label)e.getTarget(); -// Category category = m_category.getCategory(s); -// Assert.exists(category, "category"); -// targetLabel.setLabel("Assign a template to " + category.getName()); -// } -// }); -// sa.addSegment(assignLabel, -// new AvailableTemplatesListing(m_category, -// m_types, -// m_contexts)); -// -// ActionLink returnLink = new ActionLink("Return to template listing"); -// returnLink.setClassAttr("actionLink"); -// returnLink.addActionListener(new ActionListener() { -// public void actionPerformed(ActionEvent e) { -// PageState s = e.getPageState(); -// m_display.setVisible(s, true); -// m_assign.setVisible(s, false); -// } -// }); -// -// m_assign = new CMSContainer(); -// m_assign.add(sa); -// m_assign.add(returnLink); -// add(m_assign); - } - - @Override - public void register(Page p) { - super.register(p); - - p.setVisibleDefault(m_assign, false); - p.addComponentStateParam(this, m_types.getStateParameter()); - p.addComponentStateParam(this, m_contexts.getStateParameter()); - } - - /** - * Displays a list of templates which are currently assigned to - * the current item - */ -// protected class CategoryTemplatesListingImpl extends CategoryTemplatesListing { -// -// private CategoryComponentAccess m_access; -// -// public CategoryTemplatesListingImpl(CategoryRequestLocal category) { -// super(category); -// m_access = new CategoryComponentAccess(null, category); -// } -// -// public void assignLinkClicked(PageState s, -// Category category, -// String useContext) { -// } -// -// @Override -// public void register(Page p) { -// super.register(p); -// -// // Hide action columns if user has no access -// -// p.addActionListener(new ActionListener() { -// public void actionPerformed(ActionEvent e) { -// final PageState state = e.getPageState(); -// -// if (state.isVisibleOnPage(CategoryTemplates.this) -// && !m_access.canAccess -// (state, -// CMS.getContext().getSecurityManager())) { -// getRemoveColumn().setVisible(state, false); -// } -// } -// }); -// } -// } -// -// /** -// * Displays a list of templates for the given content item in the -// * given context, along with a link to select a template -// */ -// protected class AvailableTemplatesListing extends TemplatesListing { -// TableColumn m_assignCol; -// ACSObjectSelectionModel m_type; -// CategoryRequestLocal m_category; -// SingleSelectionModel m_context; -// -// /** -// * Construct a new AvailableTemplatesListing -// * -// * @param contextModel the SingleSelectionModel that will define the -// * current use context -// */ -// public AvailableTemplatesListing(CategoryRequestLocal category, -// ACSObjectSelectionModel type, -// SingleSelectionModel context) { -// m_type = type; -// m_category = category; -// m_context = context; -// -// // Add the "assign" column and corresponding action listener -// m_assignCol = addColumn("Assign", -// TemplateCollection.TEMPLATE, false, -// new AssignCellRenderer()); -// -// addTableActionListener(new TableActionAdapter() { -// @Override -// public void cellSelected(TableActionEvent e) { -// PageState s = e.getPageState(); -// TemplatesListing l = (TemplatesListing)e.getSource(); -// int i = e.getColumn().intValue(); -// TableColumn c = l.getColumnModel().get(i); -// -// // Safe to check pointer equality since the column is -// // created statically -// if(c == m_assignCol) { -// SectionTemplateMapping m = -// (SectionTemplateMapping)getMappingModel() -// .getSelectedObject(s); -// assignTemplate(s, m.getTemplate()); -// } -// } -// }); -// } -// -// /** -// * Get all the templates for the given type in the current section -// */ -// protected TemplateCollection getTemplateCollection(PageState s) { -// ContentSection sec = ContentSectionServlet.getContentSection(s.getRequest()); -// Assert.exists(sec, "content section"); -// -// /* -// ContentItem item = m_category.getSelectedItem(s); -// Assert.exists(item, "item"); -// */ -// -// ContentType type = getContentType(s); -// -// TemplateCollection c = TemplateManagerFactory -// .getInstance().getTemplates(sec, type); -// /* -// c.addEqualsFilter(TemplateCollection.USE_CONTEXT, -// TemplateManager.PUBLIC_CONTEXT); -// */ -// return c; -// } -// -// /** -// * Get the currently selected use context -// */ -// protected ContentType getContentType(PageState s) { -// ContentType type = (ContentType)m_type.getSelectedObject(s); -// Assert.exists(type, "content type"); -// return type; -// } -// -// /** -// * Assign a template to the current item -// */ -// public void assignTemplate(PageState s, Template t) { -// Category category = m_category.getCategory(s); -// ContentType type = (ContentType)m_type.getSelectedObject(s); -// String useContext = (String)m_context.getSelectedKey(s); -// CategoryTemplateMapping map = -// CategoryTemplateMapping.getMapping(category, type, t, -// useContext); -// if(map == null) { -// map = new CategoryTemplateMapping(); -// map.setCategory(category); -// map.setContentType(type); -// map.setUseContext(useContext); -// map.setTemplate(t); -// } -// map.setContentSection(ContentSectionServlet -// .getContentSection(s.getRequest())); -// map.save(); -// -// m_display.setVisible(s, true); -// m_assign.setVisible(s, false); -// } -// -// /** -// * Render the "assign" link -// */ -// protected class AssignCellRenderer implements TableCellRenderer { -// -// private ControlLink m_link; -// -// public AssignCellRenderer() { -// m_link = new ControlLink("Assign this template"); -// m_link.setClassAttr("assignTemplateLink"); -// } -// -// public Component getComponent(Table table, PageState state, -// Object value, -// boolean isSelected, Object key, -// int row, int column) { -// return m_link; -// } -// } -// -// } -// -// /** -// * -// */ -// private class AssignForm extends Form { -// -// SingleSelect m_type; -// //SingleSelect m_context; -// Hidden m_context; -// -// public AssignForm(String name, -// final ACSObjectSelectionModel type, -// final SingleSelectionModel context) { -// -// super(name, new GridPanel(3)); -// -// add(new Label("Content type:")); -// //add(new Label("Use context:")); -// //add(new Label("")); -// -// m_type = new SingleSelect(type.getStateParameter()); -// try { -// m_type.addPrintListener(new PrintListener() { -// @Override -// public void prepare(PrintEvent event) { -// PageState state = event.getPageState(); -// ContentSection section = ContentSectionServlet -// .getContentSection(state -// .getRequest()); -// -// SingleSelect target = (SingleSelect)event.getTarget(); -// target.clearOptions(); -// -// ContentTypeCollection types = section.getContentTypes(); -// types.addOrder(ContentType.LABEL); -// -// while (types.next()) { -// ContentType type = types.getContentType(); -// target.addOption(new Option(type.getID().toString(), -// type.getName())); -// } -// } -// }); -// } catch (TooManyListenersException ex) { -// throw new UncheckedWrapperException("This can never happen", ex); -// } -// add(m_type); -// -// // XXX no need for selecting template contexts currently -// m_context = new Hidden(context.getStateParameter()); -// m_context.setDefaultValue(TemplateManager.PUBLIC_CONTEXT); -// -// add(m_context); -// -// add(new Submit("Assign template")); -// } -// } -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/templates/ItemTemplates.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/templates/ItemTemplates.java deleted file mode 100755 index 4cf85a0f8..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/templates/ItemTemplates.java +++ /dev/null @@ -1,262 +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.templates; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.ControlLink; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.Page; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SegmentedPanel; -import com.arsdigita.bebop.SingleSelectionModel; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.Text; -import com.arsdigita.bebop.event.ActionEvent; -import com.arsdigita.bebop.event.ActionListener; -import com.arsdigita.bebop.event.PrintEvent; -import com.arsdigita.bebop.event.PrintListener; -import com.arsdigita.bebop.event.TableActionAdapter; -import com.arsdigita.bebop.event.TableActionEvent; -import com.arsdigita.bebop.table.TableCellRenderer; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.cms.CMS; - -import org.librecms.contentsection.ContentItem; - -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.ContentType; - -import com.arsdigita.cms.ItemSelectionModel; -import com.arsdigita.cms.ui.SecurityPropertyEditor; -import com.arsdigita.cms.ui.workflow.WorkflowLockedComponentAccess; -import com.arsdigita.toolbox.ui.LayoutPanel; -import com.arsdigita.util.Assert; - -/** - * This component will eventually contain the full templates UI for - * content items. It is just a placeholder for now. - * - * @author Stanislav Freidin - * @author Jens Pelzetter - */ -public class ItemTemplates extends SecurityPropertyEditor { - private ItemSelectionModel m_itemModel; - - public static final String ASSIGN_TEMPLATE = "assignTemplate"; - - /** - * Construct a new ItemTemplates component - * - * @param model the ItemSelectionModel that will supply the - * current content item - */ - public ItemTemplates(ItemSelectionModel model) { - super(); - m_itemModel = model; - - addComponent("Placeholder", new Text("Placeholder")); - -// ToDo -// ItemTemplatesListingImpl l = new ItemTemplatesListingImpl(model); -// - final LayoutPanel layout = new LayoutPanel(); - setDisplayComponent(layout); - -// ToDo -// SegmentedPanel st = new SegmentedPanel(); -// layout.setBody(st); -// -// st.addSegment(new Label(GlobalizationUtil.globalize("cms.ui.templates.assigned_templates")), l); -// -// SegmentedPanel sa = new SegmentedPanel(); -// Label assignLabel = new Label(GlobalizationUtil.globalize("cms.ui.templates.dummy")); -// assignLabel.addPrintListener(new PrintListener() { -// public void prepare(PrintEvent e) { -// PageState s = e.getPageState(); -// Label targetLabel = (Label)e.getTarget(); -// ContentPage item = (ContentPage)m_itemModel.getSelectedItem(s); -// Assert.exists(item, "item"); -// targetLabel.setLabel( (String) GlobalizationUtil.globalize("cms.ui.templates.assign_a_template_to").localize() + item.getTitle()); -// } -// }); -// sa.addSegment(assignLabel, -// new AvailableTemplatesListing(l.getRowSelectionModel())); -// addComponent(ASSIGN_TEMPLATE, sa); - } - - /** - * Displays a list of templates which are currently assigned to - * the current item - */ -// protected class ItemTemplatesListingImpl extends ItemTemplatesListing { -// -// private WorkflowLockedComponentAccess m_access; -// -// public ItemTemplatesListingImpl(ItemSelectionModel model) { -// super(model); -// m_access = new WorkflowLockedComponentAccess(null, model); -// } -// -// public void assignLinkClicked(PageState s, -// ContentItem item, -// String useContext) { -// showComponent(s, ASSIGN_TEMPLATE); -// } -// -// public void register(Page p) { -// super.register(p); -// // Hide action columns if user has no access -// p.addActionListener(new ActionListener() { -// public void actionPerformed(ActionEvent e) { -// final PageState state = e.getPageState(); -// -// if (state.isVisibleOnPage(ItemTemplates.this)) { -// if (m_access.canAccess -// (state, -// CMS.getContext().getSecurityManager())) { -// getRemoveColumn().setVisible(state, true); -// getAssignColumn().setVisible(state, true); -// } else { -// getRemoveColumn().setVisible(state, false); -// getAssignColumn().setVisible(state, false); -// } -// } -// } -// }); -// } -// } -// -// /** -// * Displays a list of templates for the given content item in the -// * given context, along with a link to select a template -// */ -// protected class AvailableTemplatesListing extends TemplatesListing { -// -// TableColumn m_assignCol; -// SingleSelectionModel m_contextModel; -// -// /** -// * Construct a new AvailableTemplatesListing -// * -// * @param contextModel the SingleSelectionModel that will define the -// * current use context -// */ -// public AvailableTemplatesListing(SingleSelectionModel contextModel) { -// super(); -// m_contextModel = contextModel; -// -// // Add the "assign" column and corresponding action listener -// m_assignCol = addColumn("Assign", -// TemplateCollection.TEMPLATE, false, -// new AssignCellRenderer()); -// -// addTableActionListener(new TableActionAdapter() { -// public void cellSelected(TableActionEvent e) { -// PageState s = e.getPageState(); -// TemplatesListing l = (TemplatesListing)e.getSource(); -// int i = e.getColumn().intValue(); -// TableColumn c = l.getColumnModel().get(i); -// -// // Safe to check pointer equality since the column is -// // created statically -// if(c == m_assignCol) { -// SectionTemplateMapping m = -// (SectionTemplateMapping)getMappingModel().getSelectedObject(s); -// assignTemplate(s, m.getTemplate()); -// } -// } -// }); -// } -// -// /** -// * Get all the templates for the given context in the current section -// */ -// protected TemplateCollection getTemplateCollection(PageState s) { -// ContentSection sec = CMS.getContext().getContentSection(); -// -// ContentItem item = m_itemModel.getSelectedItem(s); -// Assert.exists(item, "item"); -// -// ContentType type = item.getContentType(); -// Assert.exists(type, "content type"); -// -// MimeType mimeType = getMimeType(s); -// TemplateCollection c = -// TemplateManagerFactory.getInstance().getTemplates(sec, type); -// if (mimeType != null) { -// c.addEqualsFilter(TemplateCollection.TEMPLATE + "." + -// Template.MIME_TYPE + "." + -// MimeType.MIME_TYPE, mimeType.getMimeType()); -// } -// c.addEqualsFilter(TemplateCollection.USE_CONTEXT, -// getUseContext(s)); -// return c; -// } -// -// // TODO: this is a 100% convoluted interdependent mess that -// // really needs to be reworked -// /** -// * Get the currently selected use context -// */ -// protected String getUseContext(PageState s) { -// String c = (String)m_contextModel.getSelectedKey(s); -// Assert.exists(c, "use context"); -// return ItemTemplatesListing.getUseContextFromKey(c); -// } -// -// protected MimeType getMimeType(PageState s) { -// String key = (String)m_contextModel.getSelectedKey(s); -// return ItemTemplatesListing.getMimeTypeFromKey(key); -// } -// -// /** -// * Assign a template to the current item -// */ -// public void assignTemplate(PageState s, Template t) { -// ContentItem item = m_itemModel.getSelectedItem(s); -// Assert.exists(item, "item"); -// -// TemplateManagerFactory.getInstance() -// .addTemplate(item, t, getUseContext(s)); -// -// showDisplayPane(s); -// } -// -// /** -// * Render the "assign" link -// */ -// protected class AssignCellRenderer implements TableCellRenderer { -// -// private ControlLink m_link; -// -// public AssignCellRenderer() { -// m_link = new ControlLink -// (new Label(GlobalizationUtil.globalize -// ("cms.ui.templates.assign_this_template"))); -// m_link.setClassAttr("assignTemplateLink"); -// } -// -// public Component getComponent(Table table, PageState state, Object value, -// boolean isSelected, Object key, -// int row, int column) { -// return m_link; -// } -// } -// } -} From ad387198bebed616c6ea8ef607738381ac530936 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 16 Mar 2022 19:37:56 +0100 Subject: [PATCH 08/63] Removed some already disabled classes from ccm-cms --- .../ui/type/AddContentItemElement.java.off | 142 ---------- .../cms/ui/type/AddDateElement.java.off | 174 ------------ .../arsdigita/cms/ui/type/AddElement.java.off | 112 -------- .../cms/ui/type/AddFileElement.java.off | 74 ----- .../cms/ui/type/AddImageElement.java.off | 74 ----- .../cms/ui/type/AddNumberElement.java.off | 90 ------ .../cms/ui/type/AddTextAssetElement.java.off | 69 ----- .../cms/ui/type/AddTextElement.java.off | 143 ---------- .../cms/ui/type/TypeElements.java.off | 267 ------------------ 9 files changed, 1145 deletions(-) delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddContentItemElement.java.off delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddDateElement.java.off delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddElement.java.off delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddFileElement.java.off delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddImageElement.java.off delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddNumberElement.java.off delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddTextAssetElement.java.off delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddTextElement.java.off delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypeElements.java.off diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddContentItemElement.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddContentItemElement.java.off deleted file mode 100755 index 79e562a1d..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddContentItemElement.java.off +++ /dev/null @@ -1,142 +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.type; - -import com.arsdigita.bebop.ColumnPanel; -import com.arsdigita.bebop.FormProcessException; -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.SingleSelect; -import com.arsdigita.bebop.parameters.BigDecimalParameter; -import com.arsdigita.cms.CMS; -import com.arsdigita.cms.ContentSection; -import com.arsdigita.cms.ContentType; -import com.arsdigita.cms.ContentTypeCollection; -import com.arsdigita.cms.util.GlobalizationUtil; -import com.arsdigita.domain.DataObjectNotFoundException; -import com.arsdigita.formbuilder.PersistentForm; -import com.arsdigita.formbuilder.PersistentHidden; -import com.arsdigita.formbuilder.PersistentSingleSelect; -import com.arsdigita.kernel.ui.ACSObjectSelectionModel; -import com.arsdigita.metadata.DynamicObjectType; -import com.arsdigita.persistence.metadata.MetadataRoot; -import com.arsdigita.util.Assert; -import com.arsdigita.util.UncheckedWrapperException; -import org.apache.log4j.Logger; - -import java.math.BigDecimal; -import java.util.TooManyListenersException; - -/** - * This class contains the form component for adding a Content Item element to - * a content type - * - * @author Scott Seago (scott@arsdigita.com) - * @version $Revision: #15 $ $Date: 2004/08/17 $ - */ -public class AddContentItemElement extends ElementAddForm { - - private static final Logger s_log = - Logger.getLogger(AddContentItemElement.class); - private SingleSelect m_itemTypeSelect; - - /** - * Constructor - */ - public AddContentItemElement(ACSObjectSelectionModel types) { - super("ContentTypeAddContentItemElement", "Add a ContentItem Element", types); - - add(new Label(GlobalizationUtil.globalize("cms.ui.type.association_content_type"))); - m_itemTypeSelect = new SingleSelect(new BigDecimalParameter("AddContentItemTypeSelect")); - try { - m_itemTypeSelect.addPrintListener(new ItemTypeSelectPrintListener()); - } catch (TooManyListenersException ex) { - s_log.error("too many listeners", ex); - throw new UncheckedWrapperException(ex); - } - add(m_itemTypeSelect); - - add(m_buttons, ColumnPanel.FULL_WIDTH | ColumnPanel.CENTER); - } - - private ContentType getItemType(PageState state) - throws FormProcessException { - - BigDecimal itemTypeID = - (BigDecimal) m_itemTypeSelect.getValue(state); - - ContentType itemType = null; - Assert.exists(itemTypeID, "itemTypeID"); - try { - itemType = new ContentType(itemTypeID); - } catch (DataObjectNotFoundException ex) { - throw new FormProcessException(GlobalizationUtil.globalize("cms.ui.type.invalid")); - } - return itemType; - } - - protected final void addAttribute(DynamicObjectType dot, String label, - PageState state) - throws FormProcessException { - - ContentType itemType = getItemType(state); - dot.addOptionalAssociation(label, - MetadataRoot.getMetadataRoot().getObjectType(itemType.getAssociatedObjectType())); - } - - protected final void addFormComponent(PersistentForm pForm, String label, - PageState state) - throws FormProcessException { - - ContentType itemType = getItemType(state); - PersistentHidden pContentTypeName = PersistentHidden.create(label + "Type"); - pContentTypeName.setDefaultValue(itemType.getAssociatedObjectType()); - pContentTypeName.save(); - pForm.addComponent(pContentTypeName); - PersistentSingleSelect pSelect = PersistentSingleSelect.create(label); - pSelect.setParameterModel("com.arsdigita.bebop.parameters.BigDecimalParameter"); - pSelect.save(); - pForm.addComponent(pSelect); - } - - /** - * Print listener: generates the SingleSelect options for itemType - */ - private class ItemTypeSelectPrintListener implements PrintListener { - - public void prepare(PrintEvent event) { - - SingleSelect t = (SingleSelect) event.getTarget(); - t.clearOptions(); - - // Get the current content section - ContentSection section = CMS.getContext().getContentSection(); - - ContentTypeCollection contentTypes = section.getCreatableContentTypes(true); - contentTypes.addOrder(ContentType.LABEL); - while (contentTypes.next()) { - ContentType type = contentTypes.getContentType(); - t.addOption(new Option(type.getID().toString(), type.getName())); - } - } - } -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddDateElement.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddDateElement.java.off deleted file mode 100755 index 04035a43f..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddDateElement.java.off +++ /dev/null @@ -1,174 +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.type; - -import com.arsdigita.bebop.BoxPanel; -import com.arsdigita.bebop.ColumnPanel; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.FormSection; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.CheckboxGroup; -import com.arsdigita.bebop.form.Date; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.bebop.parameters.IntegerParameter; -import com.arsdigita.cms.util.GlobalizationUtil; -import com.arsdigita.formbuilder.PersistentDate; -import com.arsdigita.formbuilder.PersistentForm; -import com.arsdigita.kernel.ui.ACSObjectSelectionModel; -import com.arsdigita.metadata.DynamicObjectType; -import com.arsdigita.persistence.metadata.MetadataRoot; - -/** - * This class contains the form component for adding a date element to - * a content type - * - * @author Xixi D'Moon (xdmoon@arsdigita.com) - * @author Stanislav Freidin (sfreidin@arsdigita.com) - * @version $Revision: #14 $ $Date: 2004/08/17 $ - */ -public class AddDateElement extends ElementAddForm { - - private Date m_date; - private CheckboxGroup m_valReq; //whether a value is requred - private TextField m_fromYear, m_toYear; - - /** - * Constructor - */ - public AddDateElement(ACSObjectSelectionModel types) { - super("ContentTypeAddDateElement", "Add a Date Element", types); - -/* - add(new Label(GlobalizationUtil.globalize - ("cms.ui.type.element.value_required"))); - m_valReq = new CheckboxGroup("AddDateElementValReq"); - // XXX fix l18n wrt request - m_valReq.addOption(new Option(lz("cms.ui.no"), lz("cms.ui.yes"))); - add(m_valReq); -*/ - - add(new Label(GlobalizationUtil.globalize - ("cms.ui.type.default_date"))); - m_date = new Date("elementdate"); - long cur = System.currentTimeMillis(); - java.util.Date curtime = new java.util.Date(cur); - m_date.setDefaultValue(curtime); - m_date.setClassAttr("AddDateElementChooseDate"); - add(m_date); - - add(new Label(GlobalizationUtil.globalize - ("cms.ui.type.year_range"))); - - m_fromYear = new TextField(new IntegerParameter("fromYear")); - m_fromYear.setSize(6); - m_fromYear.setMaxLength(4); - m_toYear = new TextField(new IntegerParameter("toYear")); - m_toYear.setSize(6); - m_toYear.setMaxLength(4); - - FormSection rangeSec = new FormSection - (new BoxPanel(BoxPanel.HORIZONTAL, false)); - - rangeSec.add(new Label(GlobalizationUtil.globalize("cms.ui.type.from"))); - rangeSec.add(m_fromYear); - rangeSec.add(new Label(GlobalizationUtil.globalize("cms.ui.type.to"))); - rangeSec.add(m_toYear); - add(rangeSec); - - add(m_buttons, ColumnPanel.FULL_WIDTH|ColumnPanel.CENTER); - } - - - protected final void addAttribute(DynamicObjectType dot, String label, - PageState state) - throws FormProcessException { - - java.util.Date date = (java.util.Date) m_date.getValue(state); -// String[] valReq = (String[]) m_valReq.getValue(state); - // Quasimodo - // Disable the value requierd feature - String[] valReq = null; - - if (valReq == null) { - dot.addOptionalAttribute(label, MetadataRoot.DATE); - } else { - dot.addRequiredAttribute(label, MetadataRoot.DATE, date); - } - } - - - protected final void addFormComponent(PersistentForm pForm, String label, - PageState state) - throws FormProcessException { - - PersistentDate pDate = PersistentDate.create(label); - pDate.setParameterModel("com.arsdigita.bebop.parameters.DateParameter"); - pForm.addComponent(pDate); - } - - /** - * Initializes date widget to current date. - */ - protected final void doInit(FormSectionEvent event) { - java.util.Date date = new java.util.Date(System.currentTimeMillis()); - m_date.setValue(event.getPageState(), date); - } - - protected final void doValidate(FormSectionEvent e) - throws FormProcessException { - - PageState state = e.getPageState(); - - Integer fromYear = (Integer) m_fromYear.getValue(state); - Integer toYear = (Integer) m_toYear.getValue(state); - - if (!(fromYear != null && toYear != null)) { - throw new FormProcessException(GlobalizationUtil.globalize( - "cms.ui.type.year_range_not_balanced")); - } else { - if ((fromYear.intValue() < 0) || (toYear.intValue() < 0)) { - throw new FormProcessException(GlobalizationUtil.globalize( - "cms.ui.type.year_is_negative")); - } - - if (fromYear.intValue() > toYear.intValue()) { - throw new FormProcessException(GlobalizationUtil.globalize( - "cms.ui.type.year_range_wrong_order")); - } - - if ((toYear.intValue() - fromYear.intValue()) > 200) { - throw new FormProcessException(GlobalizationUtil.globalize( - "cms.ui.type.year_range_too_great")); - } - - if ((fromYear.intValue() < 1900 || fromYear.intValue() > 2100) && - (toYear.intValue() < 1900 || toYear.intValue() > 2100)) { - throw new FormProcessException(GlobalizationUtil.globalize( - "cms.ui.type.year_too_anachronistic")); - } - } - } - - private static String lz(final String key) { - return (String) GlobalizationUtil.globalize(key).localize(); - } -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddElement.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddElement.java.off deleted file mode 100755 index 1aa0472b1..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddElement.java.off +++ /dev/null @@ -1,112 +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.type; - - -import com.arsdigita.bebop.BoxPanel; -import com.arsdigita.bebop.ColumnPanel; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.form.SingleSelect; -import com.arsdigita.bebop.form.Submit; -import com.arsdigita.cms.ui.CMSForm; -import com.arsdigita.cms.util.GlobalizationUtil; - - -/** - * This class contains the form component for selecting which - * type of element to add to a content type - * - * @author Xixi D'Moon (xdmoon@arsdigita.com) - * @version $Revision: #11 $ $Date: 2004/08/17 $ - */ -public class AddElement extends CMSForm { - - private SingleSelect m_elementType; - private Submit m_submit; - - public static final String TEXT_ELEMENT = "text"; - public static final String NUMBER_ELEMENT = "number"; - public static final String DATE_ELEMENT = "date"; - public static final String TEXT_ASSET_ELEMENT = "textAsset"; - public static final String IMAGE_ELEMENT = "image"; - public static final String FILE_ELEMENT = "file"; - public static final String CONTENT_ITEM_ELEMENT = "contentItem"; - - /** - * Constructor - */ - - public AddElement() { - super("ContentTypeAddElement", new BoxPanel(BoxPanel.HORIZONTAL)); - - //possible types of elements that can be added to a user-defined - //content type - add(new Label(GlobalizationUtil.globalize("cms.ui.type.element.type"))); - m_elementType = new SingleSelect("elementTypeSelect"); - m_elementType.setClassAttr("AddElementSelectType"); - m_elementType.addOption(new Option("text", "Text")); - m_elementType.addOption(new Option("number", "Number")); - m_elementType.addOption(new Option("date", "Date")); - m_elementType.addOption(new Option("textAsset", "Text Asset")); - m_elementType.addOption(new Option("image", "Image")); - m_elementType.addOption(new Option("contentItem", "Content Item")); - m_elementType.addOption(new Option("file", "File")); - //m_elementType.addOption(new Option("document", "Document")); - //m_elementType.addOption(new Option("multimedia", "Multimedia")); - add(m_elementType); - - m_submit = new Submit("submit"); - m_submit.setButtonLabel("Add Element"); - add(m_submit, ColumnPanel.FULL_WIDTH|ColumnPanel.CENTER); - - //add the listeners - //does not do anything other than ui logic in OneType.java - //addProcessListener(this); - } - - protected SingleSelect getElementTypeSelect(){ - return m_elementType; - } - - protected Submit getSubmit(){ - return m_submit; - } - - /** - * Processes the form - */ - /* public void process(FormSectionEvent e) throws FormProcessException { - PageState state = e.getPageState(); - FormData data = e.getFormData(); - - String type = (String) data.get(m_elementType.getName()); - - }*/ - - /** - * Retrieve the type of the element that the user wants to add - * during form processing - */ - public String getElementType(FormSectionEvent e) { - return (String)m_elementType.getValue(e.getPageState()); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddFileElement.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddFileElement.java.off deleted file mode 100755 index 4f4f89456..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddFileElement.java.off +++ /dev/null @@ -1,74 +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.type; - -import com.arsdigita.bebop.ColumnPanel; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.PageState; -import com.arsdigita.cms.FileAsset; -import com.arsdigita.formbuilder.PersistentForm; -import com.arsdigita.formbuilder.PersistentHidden; -import com.arsdigita.kernel.ui.ACSObjectSelectionModel; -import com.arsdigita.metadata.DynamicObjectType; -import com.arsdigita.persistence.metadata.MetadataRoot; - -/** - * This class contains the form component for adding a File element to - * a content type - * - * @author Scott Seago (scott@arsdigita.com) - * @version $Revision: #13 $ $Date: 2004/08/17 $ - */ -public class AddFileElement extends ElementAddForm { - - public static final String ACTION_NONE = "none"; - public static final String ACTION_UPLOAD = "upload"; - public static final String ACTION_DELETE = "delete"; - public static final String ACTION = "action"; - - /** - * Constructor - */ - public AddFileElement(ACSObjectSelectionModel types) { - super("ContentTypeAddFileElement", "Add a File Element", types); - - add(m_buttons, ColumnPanel.FULL_WIDTH|ColumnPanel.CENTER); - } - - - protected final void addAttribute(DynamicObjectType dot, String label, - PageState state) - throws FormProcessException { - - dot.addOptionalAssociation(label, - MetadataRoot.getMetadataRoot().getObjectType - (FileAsset.BASE_DATA_OBJECT_TYPE)); - } - - - protected final void addFormComponent(PersistentForm pForm, String label, - PageState state) - throws FormProcessException { - - PersistentHidden pFile = PersistentHidden.create(label); - pFile.setDefaultValue(label+".file"); - pFile.save(); - pForm.addComponent(pFile); - } -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddImageElement.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddImageElement.java.off deleted file mode 100755 index 47ba24d3a..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddImageElement.java.off +++ /dev/null @@ -1,74 +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.type; - -import com.arsdigita.bebop.ColumnPanel; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.PageState; -import com.arsdigita.cms.ImageAsset; -import com.arsdigita.formbuilder.PersistentForm; -import com.arsdigita.formbuilder.PersistentHidden; -import com.arsdigita.kernel.ui.ACSObjectSelectionModel; -import com.arsdigita.metadata.DynamicObjectType; -import com.arsdigita.persistence.metadata.MetadataRoot; - - -/** - * This class contains the form component for adding a Image element to - * a content type - * - * @author Scott Seago (scott@arsdigita.com) - * @version $Revision: #13 $ $Date: 2004/08/17 $ - */ -public class AddImageElement extends ElementAddForm { - - public static final String ACTION_NONE = "none"; - public static final String ACTION_UPLOAD = "upload"; - public static final String ACTION_DELETE = "delete"; - public static final String ACTION = "action"; - - /** - * Constructor - */ - public AddImageElement(ACSObjectSelectionModel types) { - super("ContentTypeAddImageElement", "Add a Image Element", types); - - add(m_buttons, ColumnPanel.FULL_WIDTH|ColumnPanel.CENTER); - } - - protected final void addAttribute(DynamicObjectType dot, String label, - PageState state) - throws FormProcessException { - - dot.addOptionalAssociation(label, - MetadataRoot.getMetadataRoot().getObjectType - (ImageAsset.BASE_DATA_OBJECT_TYPE)); - } - - - protected final void addFormComponent(PersistentForm pForm, String label, - PageState state) - throws FormProcessException { - - PersistentHidden pImage = PersistentHidden.create(label); - pImage.setDefaultValue(label+".image"); - pImage.save(); - pForm.addComponent(pImage); - } -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddNumberElement.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddNumberElement.java.off deleted file mode 100755 index 348900a9b..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddNumberElement.java.off +++ /dev/null @@ -1,90 +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.type; - - -import com.arsdigita.bebop.ColumnPanel; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.form.CheckboxGroup; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.cms.util.GlobalizationUtil; -import com.arsdigita.formbuilder.PersistentForm; -import com.arsdigita.formbuilder.PersistentTextField; -import com.arsdigita.kernel.ui.ACSObjectSelectionModel; -import com.arsdigita.metadata.DynamicObjectType; -import com.arsdigita.persistence.metadata.MetadataRoot; - - -/** - * This class contains the form component for adding a number element to - * a content type - * - * @author Xixi D'Moon (xdmoon@arsdigita.com) - * @author Stanislav Freidin (sfreidin@arsdigita.com) - * @version $Revision: #13 $ $Date: 2004/08/17 $ - */ -public class AddNumberElement extends ElementAddForm { - - private CheckboxGroup m_valReq; //whether a value is requred - - /** - * Constructor - */ - public AddNumberElement(ACSObjectSelectionModel types) { - super("ContentTypeAddNumberElement", "Add a Number Element", types); - -/* - add(new Label(GlobalizationUtil.globalize("cms.ui.type.element.value_required"))); - m_valReq = new CheckboxGroup("AddNumberElementValReq"); - m_valReq.addOption(new Option("yes", "Yes")); - add(m_valReq); -*/ - - add(m_buttons, ColumnPanel.FULL_WIDTH|ColumnPanel.CENTER); - } - - protected final void addAttribute(DynamicObjectType dot, String label, - PageState state) - throws FormProcessException { - -// String[] valReq = (String[]) m_valReq.getValue(state); - // Quasimodo - // Disable the value requierd feature - String[] valReq = null; - - if (valReq == null) { - dot.addOptionalAttribute(label, MetadataRoot.BIGDECIMAL); - } else { - dot.addRequiredAttribute(label, MetadataRoot.BIGDECIMAL, "0"); - } - } - - protected final void addFormComponent(PersistentForm pForm, String label, - PageState state) - throws FormProcessException { - - PersistentTextField pTextField = PersistentTextField.create(label); - pTextField.setParameterModel - ("com.arsdigita.bebop.parameters.BigDecimalParameter"); - pTextField.save(); - pForm.addComponent(pTextField); - } -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddTextAssetElement.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddTextAssetElement.java.off deleted file mode 100755 index 0fab6d9c1..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddTextAssetElement.java.off +++ /dev/null @@ -1,69 +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.type; - -import com.arsdigita.bebop.ColumnPanel; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.PageState; -import com.arsdigita.cms.TextAsset; -import com.arsdigita.formbuilder.PersistentDeditor; -import com.arsdigita.formbuilder.PersistentForm; -import com.arsdigita.kernel.ui.ACSObjectSelectionModel; -import com.arsdigita.metadata.DynamicObjectType; -import com.arsdigita.persistence.metadata.MetadataRoot; - - -/** - * This class contains the form component for adding a TextAsset element to - * a content type - * - * @author Scott Seago (scott@arsdigita.com) - * @version $Revision: #13 $ $Date: 2004/08/17 $ - */ -public class AddTextAssetElement extends ElementAddForm { - - - /** - * Constructor - */ - public AddTextAssetElement(ACSObjectSelectionModel types) { - super("ContentTypeAddTextAssetElement", "Add a TextAsset Element", types); - - add(m_buttons, ColumnPanel.FULL_WIDTH|ColumnPanel.CENTER); - } - - protected final void addAttribute(DynamicObjectType dot, String label, - PageState state) - throws FormProcessException { - - dot.addOptionalAssociation(label, - MetadataRoot.getMetadataRoot().getObjectType - (TextAsset.BASE_DATA_OBJECT_TYPE)); - } - - - protected final void addFormComponent(PersistentForm pForm, String label, - PageState state) - throws FormProcessException { - - PersistentDeditor pTextArea = PersistentDeditor.create(label); - pTextArea.save(); - pForm.addComponent(pTextArea); - } -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddTextElement.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddTextElement.java.off deleted file mode 100755 index 56f621347..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddTextElement.java.off +++ /dev/null @@ -1,143 +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.type; - -import com.arsdigita.bebop.ColumnPanel; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.CheckboxGroup; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.form.RadioGroup; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.bebop.parameters.IntegerParameter; -import com.arsdigita.cms.util.GlobalizationUtil; -import com.arsdigita.formbuilder.PersistentForm; -import com.arsdigita.formbuilder.PersistentTextArea; -import com.arsdigita.formbuilder.PersistentTextField; -import com.arsdigita.kernel.ui.ACSObjectSelectionModel; -import com.arsdigita.metadata.DynamicObjectType; -import com.arsdigita.persistence.metadata.MetadataRoot; - - -/** - * This class contains the form component for adding an text element to - * a content type - * - * @author Xixi D'Moon (xdmoon@arsdigita.com) - * @author Stanislav Freidin (sfreidin@arsdigita.com) - * @version $Revision: #14 $ $Date: 2004/08/17 $ - */ -public class AddTextElement extends ElementAddForm { - - private static final String INPUT_BOX = "inputBox"; - private static final String TEXT_AREA = "textArea"; - - private TextField m_length; //can be a number or default 4000 - private RadioGroup m_dataEntry; //data entry method - private CheckboxGroup m_valReq; - - /** - * Constructor - */ - public AddTextElement(ACSObjectSelectionModel types) { - super("ContentTypeAddTextElement", "Add a Text Element", types); - - add(new Label(GlobalizationUtil.globalize - ("cms.ui.type.maximum_length"))); - m_length = new TextField(new IntegerParameter("length")); - m_length.setSize(15); - m_length.setMaxLength(10); - add(m_length); - - add(new Label(GlobalizationUtil.globalize - ("cms.ui.type.data_entry_method"))); - m_dataEntry = new RadioGroup("TextElementDataEntryMethodSelect"); - m_dataEntry.setClassAttr("vertical"); - m_dataEntry.addOption(new Option( INPUT_BOX, "Input box")); - m_dataEntry.addOption(new Option( TEXT_AREA, "Text Area")); - add(m_dataEntry); - -/* - add(new Label(GlobalizationUtil.globalize - ("cms.ui.type.element.value_required"))); - m_valReq = new CheckboxGroup("AddTextElementValReq"); - m_valReq.addOption(new Option("yes", "Yes")); - add(m_valReq); -*/ - - add(m_buttons, ColumnPanel.FULL_WIDTH|ColumnPanel.CENTER); - } - - - protected final void addAttribute(DynamicObjectType dot, String label, - PageState state) - throws FormProcessException { - - Integer length = (Integer) m_length.getValue(state); -// String[] valReq = (String[]) m_valReq.getValue(state); - // Quasimodo - // Disable the value requierd feature - String[] valReq = null; - - if (length == null) { - length = new Integer(4000); - } - - if (valReq == null) { - dot.addOptionalAttribute(label, MetadataRoot.STRING, - length.intValue()); - } else { - dot.addRequiredAttribute(label, MetadataRoot.STRING, - length.intValue(), " "); - } - } - - protected final void addFormComponent(PersistentForm pForm, String label, - PageState state) - throws FormProcessException { - - String dataEntry = (String) m_dataEntry.getValue(state); - Integer length = (Integer) m_length.getValue(state); - - if (dataEntry.equals(INPUT_BOX)) { - - PersistentTextField pTextField = PersistentTextField.create(label); - if (length!=null) { - pTextField.setMaxLength(length.intValue()); - } - pTextField.save(); - pForm.addComponent(pTextField); - } else if (dataEntry.equals(TEXT_AREA)) { - PersistentTextArea pTextArea = PersistentTextArea.create(label); - pTextArea.save(); - pForm.addComponent(pTextArea); - } - } - - /** - * Sets default values for input fields. - */ - protected final void doInit(FormSectionEvent e) { - PageState state = e.getPageState(); - - m_dataEntry.setValue(state, INPUT_BOX); - } -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypeElements.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypeElements.java.off deleted file mode 100755 index e4d9a4fd8..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypeElements.java.off +++ /dev/null @@ -1,267 +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.type; - -import com.arsdigita.bebop.BoxPanel; -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.ControlLink; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.Page; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SingleSelectionModel; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.event.TableActionAdapter; -import com.arsdigita.bebop.event.TableActionEvent; -import com.arsdigita.bebop.table.TableCellRenderer; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.bebop.table.TableModelBuilder; -import com.arsdigita.cms.ContentType; -import com.arsdigita.cms.ui.CMSContainer; -import com.arsdigita.cms.util.GlobalizationUtil; -import com.arsdigita.domain.DataObjectNotFoundException; -import com.arsdigita.metadata.DynamicObjectType; -import com.arsdigita.persistence.metadata.Property; -import com.arsdigita.util.UncheckedWrapperException; -import org.apache.log4j.Logger; - -import java.math.BigDecimal; -import java.util.Iterator; - -/** - * This class contains the component to generate a table - * of elements for a particular content type - */ -public class TypeElements extends BoxPanel { - - private static Logger s_log = - Logger.getLogger(TypeElements.class); - private SingleSelectionModel m_types; - private Table m_elementsTable; - private TableColumn m_removeColumn; - - public TypeElements(SingleSelectionModel m) { - super(); - - m_types = m; - - m_elementsTable = makeElementsTable(); - - m_removeColumn = m_elementsTable.getColumn(3); - m_removeColumn.setCellRenderer(new RemoveCellRenderer()); - m_removeColumn.setAlign("center"); - - m_elementsTable.addTableActionListener(new ElementRemover()); - - add(m_elementsTable); - } - - public void register(Page p) { - p.addComponent(this); - } - - public Table getTable() { - return m_elementsTable; - } - - /** - * creates and returns a content type - */ - private ContentType makeType(BigDecimal typeId) { - ContentType type = null; - try { - type = new ContentType(typeId); - } catch (DataObjectNotFoundException e) { - UncheckedWrapperException.throwLoggedException(getClass(), "Unable to make content type for id: " - + typeId, - e); - } - return type; - } - - /** - * Produce remove links. - */ - private static class RemoveCellRenderer implements TableCellRenderer { - - private static final Logger logger = Logger.getLogger(RemoveCellRenderer.class); - private static Label s_noAction; - private static ControlLink s_link; - - static { - logger.debug("Static initializer is starting..."); - s_noAction = new Label(" ", false); - s_noAction.lock(); - s_link = new ControlLink(new Label(GlobalizationUtil.globalize( - "cms.ui.type.element.delete"))); - s_link.setConfirmation("Permanently remove this element?"); - logger.debug("Static initalizer finished."); - } - - public Component getComponent(Table table, PageState state, Object value, - boolean isSelected, Object key, - int row, int column) { - if (((Boolean) value).booleanValue()) { - return s_link; - } else { - return s_noAction; - } - } - } - - // Removes an element - private class ElementRemover extends TableActionAdapter { - - public void cellSelected(TableActionEvent e) { - int col = e.getColumn().intValue(); - - if (m_removeColumn != m_elementsTable.getColumn(col)) { - return; - } - - PageState s = e.getPageState(); - DynamicObjectType dot = getDynamicObjectType(s); - String element = e.getRowKey().toString(); - - dot.removeAttribute(element); - dot.save(); - } - } - - private DynamicObjectType getDynamicObjectType(PageState s) { - BigDecimal typeId = new BigDecimal(m_types.getSelectedKey(s).toString()); - ContentType type = makeType(typeId); - return new DynamicObjectType(type.getAssociatedObjectType()); - } - - /** - * creates and returns the list of elements of this udct - * by iterating through the declared properties of the associated - * dynamic object type - * - * return the table of elements of this type - */ - private Table makeElementsTable() { - - final String[] headers = {"Name", "Element Type", "Multiplicity", - "Remove"}; - - TableModelBuilder b = new TableModelBuilder() { - - private boolean m_locked; - - public TableModel makeModel(final Table t, final PageState s) { - - return new TableModel() { - - DynamicObjectType dot = getDynamicObjectType(s); - //NOTE: this only gets the non-inherited properties of - // the object type - Iterator declaredProperties = dot.getObjectType(). - getDeclaredProperties(); - Property currentProperty = null; - - public int getColumnCount() { - return headers.length; - } - - public boolean nextRow() { - boolean next = declaredProperties.hasNext(); - if (next) { - currentProperty = - (Property) declaredProperties.next(); - } - return next; - } - - public Object getElementAt(int columnIndex) { - if (currentProperty == null) { - throw new IllegalArgumentException(); - } - - switch (columnIndex) { - case 0: - return currentProperty.getName(); - case 1: - String dataType = currentProperty.getType(). - getName(); - if (dataType.equals("String")) { - return "text"; - } else if (dataType.equals("BigDecimal")) { - return "number"; - } else if (dataType.equals("Date")) { - return "date"; - } else { - return dataType; - } - case 2: - if (currentProperty.isNullable()) { - return "0 or 1"; - } else if (currentProperty.isRequired()) { - return "1"; - } else if (currentProperty.isCollection()) { - return "0 to n"; - } else { - return new Integer(currentProperty. - getMultiplicity()); - } - case 3: - return new Boolean(isRemovable()); - default: - throw new IllegalArgumentException( - "columnIndex exceeds " - + "number of columns available"); - } - } - - public Object getKeyAt(int columnIndex) { - if (currentProperty == null) { - throw new IllegalArgumentException(); - } else { - //uses the element name as key, unique for each row - return currentProperty.getName(); - } - } - - private boolean isRemovable() { - return true; - } - }; - - } - - public void lock() { - m_locked = true; - } - - public boolean isLocked() { - return m_locked; - } - }; - - Table result = new Table(b, headers); - CMSContainer ifemptable = new CMSContainer(); - ifemptable.setClassAttr("emptyTypeElementsTable"); - result.setEmptyView(ifemptable); - //result.getColumn(0).setCellRenderer(new DefaultTableCellRenderer(true)); - result.setClassAttr("ContentTypeElementsTable"); - return result; - - } -} From 01d8874193c6d82562ff964848127e722efc141c Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 16 Mar 2022 19:44:23 +0100 Subject: [PATCH 09/63] Removed depcrecated package com/arsdigita/cms/ui/type --- .../arsdigita/cms/ui/ContentSectionPage.java | 83 ++-- .../cms/ui/type/ContentTypeAdminPane.java | 366 ----------------- .../type/ContentTypeAdminPaneController.java | 247 ----------- .../cms/ui/type/ContentTypeItemPane.java | 355 ---------------- .../ui/type/ContentTypeListModelBuilder.java | 90 ---- .../cms/ui/type/ContentTypePropertyList.java | 141 ------- .../cms/ui/type/ContentTypeRequestLocal.java | 34 -- .../com/arsdigita/cms/ui/type/EditType.java | 386 ------------------ .../com/arsdigita/cms/ui/type/SelectType.java | 211 ---------- .../cms/ui/type/TypePermissionsTable.java | 262 ------------ .../type/TypePermissionsTableController.java | 114 ------ .../cms/ui/type/TypeSecurityContainer.java | 55 --- .../cms/ui/type/TypeSecurityListener.java | 51 --- 13 files changed, 26 insertions(+), 2369 deletions(-) delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPane.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPaneController.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeItemPane.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeListModelBuilder.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypePropertyList.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeRequestLocal.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/EditType.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/SelectType.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypePermissionsTable.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypePermissionsTableController.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypeSecurityContainer.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypeSecurityListener.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java index df3d9b518..c5a2875cf 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java @@ -36,12 +36,10 @@ import org.librecms.contentsection.ContentSection; import com.arsdigita.cms.dispatcher.CMSPage; import com.arsdigita.cms.ui.category.CategoryAdminPane; -//ToDo NG import com.arsdigita.cms.ui.category.CategoryAdminPane; import com.arsdigita.cms.ui.cse.ContentSoonExpiredPane; import com.arsdigita.cms.ui.folder.FolderAdminPane; import com.arsdigita.cms.ui.lifecycle.LifecycleAdminPane; import com.arsdigita.cms.ui.role.RoleAdminPane; -import com.arsdigita.cms.ui.type.ContentTypeAdminPane; import com.arsdigita.cms.ui.workflow.WorkflowAdminPane; import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.toolbox.ui.LayoutPanel; @@ -77,59 +75,73 @@ public class ContentSectionPage extends CMSPage implements ActionListener { * expansion from content item page. */ public static final String SET_FOLDER = "set_folder"; + /** * The URL parameter that can be passed in in order to set the current * template (for setting the content type) */ public static final String SET_TEMPLATE = "set_template"; + /** * The URL parameter that can be passed in in order to set the current tab. * This is a KLUDGE right now because the TabbedDialog's current tab is * selected with a local state parameter. */ public static final String SET_TAB = "set_tab"; + /** * Index of the search tab */ public static final int SEARCH_TAB = 0; + /** * Index of the browse tab */ public static final int BROWSE_TAB = 1; + /** * Index of the roles tab */ public static final int ROLES_TAB = 2; + /** * Index of the workflows tab */ public static final int WORKFLOW_TAB = 3; + /** * Index of the lifecycles tab */ public static final int LIFECYCLES_TAB = 4; + /** * Index of the categories tab */ public static final int CATEGORIES_TAB = 5; + /** * Index of the content types tab */ public static final int CONTENTTYPES_TAB = 6; + public static final int USER_ADMIN_TAB = 7; private TabbedPane m_tabbedPane; + private FolderAdminPane m_folderPane; + private BrowsePane m_browsePane; + private ItemSearch m_searchPane; -// private AssetPane m_assetPane; -//ToDo NG private ImagesPane m_imagesPane; + private RoleAdminPane m_rolePane; + private WorkflowAdminPane m_workflowPane; + private LifecycleAdminPane m_lifecyclePane; + private CategoryAdminPane m_categoryPane; - private ContentTypeAdminPane m_typePane; - //private LayoutPanel m_userAdminPane; + private LayoutPanel m_csePane; /** @@ -148,18 +160,11 @@ public class ContentSectionPage extends CMSPage implements ActionListener { m_folderPane = getFolderAdminPane(); m_browsePane = getBrowsePane(); m_searchPane = getSearchPane(); - m_assetPane = getAssetPane(); -//ToDo NG m_imagesPane = getImagesPane(); m_rolePane = getRoleAdminPane(); m_workflowPane = getWorkflowAdminPane(); m_lifecyclePane = getLifecycleAdminPane(); m_categoryPane = getCategoryAdminPane(); - m_typePane = getContentTypeAdminPane(); - // userAdminPane removed, used to contain just one item (reset user - // folder) which moved to the FolderAdminPane - //m_userAdminPane = getUserAdminPane(); m_csePane = getCSEPane(); - m_reportPane = getReportPane(); // The panes m_tabbedPane = createTabbedPane(); @@ -187,7 +192,8 @@ public class ContentSectionPage extends CMSPage implements ActionListener { m_tabbedPane.setTabVisible( state, m_workflowPane, - permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_WORKFLOWS)); + permissionChecker.isPermitted( + AdminPrivileges.ADMINISTER_WORKFLOWS)); m_tabbedPane.setTabVisible( state, m_categoryPane, @@ -198,11 +204,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener { m_lifecyclePane, permissionChecker.isPermitted( AdminPrivileges.ADMINISTER_LIFECYLES)); - m_tabbedPane.setTabVisible( - state, - m_typePane, - permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_CONTENT_TYPES)); m_tabbedPane.setTabVisible( state, @@ -253,7 +254,7 @@ public class ContentSectionPage extends CMSPage implements ActionListener { protected ItemSearch getSearchPane() { if (m_searchPane == null) { m_searchPane - = new ItemSearch( + = new ItemSearch( ContentItemVersion.DRAFT.toString(), CMSConfig.getConfig().isLimitItemSearchToContentSection()); } @@ -267,7 +268,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener { // // return m_assetPane; // } - // ToDo NG // protected ImagesPane getImagesPane() { // if (m_imagesPane == null) { @@ -315,28 +315,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener { return m_categoryPane; } - /** - * Creates, and then caches, the content type administration pane. - * Overriding this method to return null will prevent this tab from - * appearing. - * - * @return - */ - protected ContentTypeAdminPane getContentTypeAdminPane() { - if (m_typePane == null) { - m_typePane = new ContentTypeAdminPane(); - } - return m_typePane; - } - -// protected LayoutPanel getUserAdminPane() { -// if (m_userAdminPane == null) { -// m_userAdminPane = new LayoutPanel(); -// m_userAdminPane.setLeft(new SimpleComponent()); -// m_userAdminPane.setBody(new UserAdminPane()); -// } -// return m_userAdminPane; -// } protected LayoutPanel getCSEPane() { if (m_csePane == null) { m_csePane = new LayoutPanel(); @@ -346,14 +324,13 @@ public class ContentSectionPage extends CMSPage implements ActionListener { return m_csePane; } - /** * Adds the specified component, with the specified tab name, to the tabbed * pane only if it is not null. * - * @param pane The pane to which to add the tab + * @param pane The pane to which to add the tab * @param tabName The name of the tab if it's added - * @param comp The component to add to the pane + * @param comp The component to add to the pane */ protected void addToPane(final TabbedPane pane, final String tabName, @@ -391,15 +368,12 @@ public class ContentSectionPage extends CMSPage implements ActionListener { //tab(pane, "cms.ui.folders", getFolderAdminPane()); tab(pane, "cms.ui.browse", getBrowsePane()); tab(pane, "cms.ui.search", getSearchPane()); - tab(pane, "cms.ui.assets", getAssetPane()); // ToDo NG replace with media tab tab(pane, "cms.ui.images", getImagesPane()); tab(pane, "cms.ui.roles", getRoleAdminPane()); tab(pane, "cms.ui.workflows", getWorkflowAdminPane()); tab(pane, "cms.ui.lifecycles", getLifecycleAdminPane()); tab(pane, "cms.ui.categories", getCategoryAdminPane()); - tab(pane, "cms.ui.content_types", getContentTypeAdminPane()); tab(pane, "cms.ui.cse", getCSEPane()); - tab(pane, "cms.ui.reports", getReportPane()); return pane; } @@ -436,9 +410,7 @@ public class ContentSectionPage extends CMSPage implements ActionListener { // } else if (pane == m_imagesPane) { // m_imagesPane.reset(state); // } else - if (pane == m_assetPane) { - m_assetPane.reset(state); - } else if (pane == m_folderPane) { + if (pane == m_folderPane) { m_folderPane.reset(state); //ToDo NG } else if (pane == m_browsePane) { // m_browsePane.reset(state); @@ -450,10 +422,7 @@ public class ContentSectionPage extends CMSPage implements ActionListener { m_lifecyclePane.reset(state); } else if (pane == m_categoryPane) { m_categoryPane.reset(state); - } else if (pane == m_typePane) { - m_typePane.reset(state); -// } else if (pane == m_userAdminPane) { - //m_userAdminPane.reset(state); + } else if (pane == m_csePane) { m_csePane.reset(state); } @@ -463,7 +432,7 @@ public class ContentSectionPage extends CMSPage implements ActionListener { * Construct a URL for displaying the tab * * @param item The item from which we get the corresponding content section - * @param tab The index of the tab to display + * @param tab The index of the tab to display * * @return */ diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPane.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPane.java deleted file mode 100755 index 58ec05906..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPane.java +++ /dev/null @@ -1,366 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.type; - -import com.arsdigita.bebop.ActionLink; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.GridPanel; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.Page; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.event.ActionEvent; -import com.arsdigita.bebop.event.ActionListener; -import com.arsdigita.bebop.event.FormProcessListener; -import com.arsdigita.bebop.event.FormSubmissionListener; -import com.arsdigita.bebop.event.PrintEvent; -import com.arsdigita.bebop.event.PrintListener; -import com.arsdigita.cms.CMS; - -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.ContentType; -//ToDo import com.arsdigita.cms.SectionTemplateMapping; - -import com.arsdigita.cms.ui.BaseAdminPane; -import com.arsdigita.cms.ui.BaseDeleteForm; -import com.arsdigita.globalization.GlobalizedMessage; -//ToDo insert later import com.arsdigita.cms.ui.ContentSectionPage; - -import com.arsdigita.kernel.ui.ACSObjectSelectionModel; -import com.arsdigita.toolbox.ui.ActionGroup; -import com.arsdigita.toolbox.ui.Cancellable; -import com.arsdigita.toolbox.ui.Section; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.core.UnexpectedErrorException; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentSectionManager; -import org.librecms.contentsection.ContentTypeManager; -import org.librecms.contenttypes.ContentTypeInfo; - -import java.util.List; -import java.util.TooManyListenersException; - -/** - * This class contains the split pane for the ContentType administration - * interface. - * - * @author Jack Chung - * @author Michael Pih - * @author Stanislav Freidin - * @author Justin Ross <jross@redhat.com> - * @author Jens Pelzetter - */ -public final class ContentTypeAdminPane extends BaseAdminPane { - - private static final Logger LOGGER = LogManager.getLogger( - ContentTypeAdminPane.class); - - private final ACSObjectSelectionModel m_model; - private final ContentTypeRequestLocal m_type; - - /** - * Constructs an admin pane. It is containing (a) a list of available - * content types in a given content section and adds a link to make - * additional content types available (out of a list of installed, but - * available in a given content section). - */ - public ContentTypeAdminPane() { - - // - super(new Label(gz("cms.ui.types")), - new ContentTypeListModelBuilder()); //list with all Types avail. - - m_model = new ACSObjectSelectionModel(getSelectionModel()); - m_type = new SelectionRequestLocal(); - - ActionLink addTypeLink - = new ActionLink(new Label(gz("cms.ui.type.add"))); - - AddTypeContainer addTypeContainer = new AddTypeContainer(); - getBody().add(addTypeContainer); - getBody().connect(addTypeLink, addTypeContainer); - addTypeLink.addActionListener(addTypeContainer); - - setEdit(new ActionLink(new Label(gz("cms.ui.type.edit"))), - new EditType(m_model)); - - setDelete(new ActionLink(new Label(gz("cms.ui.type.delete"))), - new DeleteForm()); - - setIntroPane(new Label(gz("cms.ui.type.intro"))); - setItemPane(new ContentTypeItemPane(m_model, - m_type, - getEditLink(), - getDeleteLink())); - - addAction(new TypeSecurityContainer(addTypeLink), ActionGroup.ADD); - } - - @Override - public void register(final Page page) { - super.register(page); - - page.addActionListener(new ActionListener() { - - /** - * - * @param event - */ - @Override - public void actionPerformed(final ActionEvent event) { -// ToDo -// final PageState state = event.getPageState(); -// ContentType contentType = (ContentType) m_model.getSelectedObject(state); -// ContentSection section = CMS.getContext().getContentSection(); -// if (contentType == null) { -// final String template = state.getRequest() -// .getParameter(ContentSectionPage -// .SET_TEMPLATE); -// if (template != null) { -// DataCollection da = SessionManager.getSession().retrieve(SectionTemplateMapping.BASE_DATA_OBJECT_TYPE); -// DomainCollection c = new DomainCollection(da); -// c.addEqualsFilter(SectionTemplateMapping.SECTION + "." + ACSObject.ID, -// section.getID()); -// c.addEqualsFilter(SectionTemplateMapping.TEMPLATE + "." + ACSObject.ID, -// new BigDecimal(template)); -// c.addOrder(SectionTemplateMapping.CONTENT_TYPE + "." + ContentType.LABEL); -// if (c.next()) { -// SectionTemplateMapping mapping = -// (SectionTemplateMapping) c.getDomainObject(); -// contentType = mapping.getContentType(); -// } -// c.close(); -// } -// if (contentType == null) { -// ContentTypeCollection contentTypes = section.getContentTypes(); -// contentTypes.addOrder("label asc"); -// try { -// if (contentTypes.next()) { -// contentType = contentTypes.getContentType(); -// } -// } finally { -// contentTypes.close(); -// } -// } -// if (contentType != null) { -// m_model.setSelectedObject(state, contentType); -// getBody().push(state, getItemPane()); -// } -// -// -// } - } - - }); - } - -// ToDo (?) User Definied Content Types -// private class AddTypeContainer extends GridPanel implements ActionListener, -// FormProcessListener { -// -// private Label m_noTypesAvailable = -// new Label(gz("cms.ui.type.select.none")); -// private SelectType m_selectType; -//// User Definied Content Types private CreateType m_createType; -// -// /** -// * -// */ -// AddTypeContainer() { -// super(1); -// Section selectSection = new Section(); -// selectSection.setHeading(new Label(gz("cms.ui.type.select"))); -// add(selectSection); -// -// GridPanel container = new GridPanel(1); -// container.add(m_noTypesAvailable); -// m_selectType = new SelectType(); -// m_selectType.addSubmissionListener(new CancelListener(m_selectType)); -// m_selectType.addProcessListener(this); -// container.add(m_selectType); -// selectSection.setBody(container); -// -// Section addSection = new Section() { -// -// @Override -// public final boolean isVisible(final PageState state) { -// return super.isVisible(state) -// && !ContentSection.getConfig().getHideUDCTUI(); -// } -// }; -// addSection.setHeading(new Label(gz("cms.ui.type.define"))); -// m_createType = new CreateType(m_model); -// m_createType.addSubmissionListener(new CancelListener(m_createType)); -// m_createType.addProcessListener(this); -// addSection.setBody(m_createType); -// add(addSection); -// } -// -// /** -// * -// * @param e -// */ -// @Override -// public void actionPerformed(ActionEvent e) { -// PageState s = e.getPageState(); -// ContentSection section = CMS.getContext().getContentSection(); -// ContentTypeCollection contentTypes = -// section.getNotAssociatedContentTypes(); -// boolean hasAvailableTypes = !contentTypes.isEmpty(); -// m_selectType.setVisible(s, hasAvailableTypes); -// m_noTypesAvailable.setVisible(s, !hasAvailableTypes); -// } -// -// public final void process(final FormSectionEvent e) -// throws FormProcessException { -// final PageState state = e.getPageState(); -// resetPane(state); -// } -// } - /** - * This class is essentially a copy of the CancelListener inside of - * ModalPanel. We could not use the one in ModalPanel because it was - * protected - */ - private final class CancelListener implements FormSubmissionListener { - - Cancellable m_form; - - CancelListener(final Cancellable form) { - m_form = form; - } - - @Override - public void submitted(FormSectionEvent event) - throws FormProcessException { - PageState state = event.getPageState(); - if (m_form.isCancelled(state)) { - getBody().pop(state); - throw new FormProcessException(new GlobalizedMessage( - "cms.ui.type.cancelled", CmsConstants.CMS_BUNDLE)); - } - } - - } // end private class - - private void resetPane(final PageState state) { - getBody().reset(state); - if (getSelectionModel().isSelected(state)) { - LOGGER.debug("The selection model is selected; displaying " - + "the item pane"); - getBody().push(state, getItemPane()); - } - } - - private class SelectionRequestLocal extends ContentTypeRequestLocal { - - @Override - protected final Object initialValue(final PageState state) { - ContentType contentType = (ContentType) m_model.getSelectedObject( - state); - return contentType; - } - - } - - private class DeleteForm extends BaseDeleteForm { - - DeleteForm() { - super(new Label(gz("cms.ui.type.delete_prompt"))); - - addSubmissionListener(new TypeSecurityListener()); - } - - @Override - public final void process(final FormSectionEvent e) - throws FormProcessException { - final PageState state = e.getPageState(); - final ContentSection section = CMS.getContext().getContentSection(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentSectionManager sectionManager = cdiUtil.findBean( - ContentSectionManager.class); - final ContentTypeManager typeManager = cdiUtil.findBean( - ContentTypeManager.class); - - m_type.getContentType(state).getContentItemClass(); - - sectionManager.removeContentTypeFromSection( - typeManager.classNameToClass(m_type.getContentType(state) - .getContentItemClass()), - section); - - getSelectionModel().clearSelection(state); - } - - } - - private class AddTypeContainer - extends GridPanel - implements ActionListener, FormProcessListener { - - private final Label noTypesAvailableLabel - = new Label(gz("cms.ui.type.select.none")); - private final SelectType selectType; - - public AddTypeContainer() { - super(1); - - final Section selectSection = new Section(); - selectSection.setHeading(new Label(gz("cms.ui.type.select"))); - add(selectSection); - - final GridPanel container = new GridPanel(1); - container.add(noTypesAvailableLabel); - selectType = new SelectType(); - selectType.addSubmissionListener(new CancelListener(selectType)); - selectType.addProcessListener(this); - container.add(selectType); - selectSection.setBody(container); - } - - @Override - public void actionPerformed(final ActionEvent event) { - - final PageState state = event.getPageState(); - final ContentSection section = CMS.getContext().getContentSection(); - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentTypeAdminPaneController controller = cdiUtil - .findBean(ContentTypeAdminPaneController.class); - final List contentTypes = controller - .getNotAssociatedContentTypes(section); - final boolean hasAvailableTypes = !contentTypes.isEmpty(); - selectType.setVisible(state, hasAvailableTypes); - noTypesAvailableLabel.setVisible(state, !hasAvailableTypes); - } - - @Override - public void process(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - resetPane(state); - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPaneController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPaneController.java deleted file mode 100644 index 5b60a7236..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPaneController.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Copyright (C) 2016 LibreCCM Foundation. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package com.arsdigita.cms.ui.type; - -import org.libreccm.workflow.Workflow; -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.ContentSectionManager; -import org.librecms.contentsection.ContentSectionRepository; -import org.librecms.contentsection.ContentType; -import org.librecms.contentsection.ContentTypeManager; -import org.librecms.contentsection.ContentTypeRepository; -import org.librecms.contenttypes.ContentTypeInfo; -import org.librecms.contenttypes.ContentTypesManager; -import org.librecms.lifecycle.LifecycleDefinition; - -import java.nio.charset.IllegalCharsetNameException; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Objects; -import java.util.Optional; -import java.util.ResourceBundle; -import java.util.stream.Collectors; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.persistence.EntityManager; -import javax.transaction.Transactional; - -/** - * A controller class for the {@link ContentTypeAdminPane} and its associated - * classes. For now it only contains methods which require or transaction (which - * are controlled by the container now). - * - * - * @author Jens Pelzetter - */ -@RequestScoped -class ContentTypeAdminPaneController { - - @Inject - private EntityManager entityManager; - - @Inject - private ContentSectionRepository sectionRepo; - - @Inject - private ContentSectionManager sectionManager; - - @Inject - private ContentTypeRepository typeRepo; - - @Inject - private ContentTypeManager typeManager; - - @Inject - private ContentTypesManager typesManager; - - @Transactional(Transactional.TxType.REQUIRED) - protected List getTypeList(final ContentSection section) { - final List types = typeRepo.findByContentSection(section); - - return types.stream() - .map(type -> generateListEntry(type)) - .collect(Collectors.toList()); - } - - @Transactional - protected List getContentItemClassesList( - final ContentSection ofSection - ) { - final ContentSection section = sectionRepo.findById( - ofSection.getObjectId() - ) - .orElseThrow( - () -> new IllegalArgumentException( - String.format( - "No ContentSection with ID %d found.", - ofSection.getObjectId() - ) - ) - ); - return section.getContentTypes() - .stream() - .map(type -> type.getContentItemClass()) - .collect(Collectors.toList()); - } - - private String[] generateListEntry(final ContentType type) { - final String[] entry = new String[2]; - - entry[0] = Long.toString(type.getObjectId()); - - final ContentTypeInfo typeInfo = typesManager - .getContentTypeInfo(type.getContentItemClass()); - final ResourceBundle labelBundle = ResourceBundle - .getBundle(typeInfo.getLabelBundle()); - final String labelKey = typeInfo.getLabelKey(); - - entry[1] = labelBundle.getString(labelKey); - - return entry; - } - - @Transactional(Transactional.TxType.REQUIRED) - protected List getNotAssociatedContentTypes( - final ContentSection section) { - - final List availableTypes = typesManager - .getAvailableContentTypes(); - final List associatedTypes = typeRepo - .findByContentSection(section) - .stream() - .map(type -> typesManager.getContentTypeInfo(type)) - .collect(Collectors.toList()); - - return availableTypes - .stream() - .filter(typeInfo -> !associatedTypes.contains(typeInfo)) - .collect(Collectors.toList()); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected LifecycleDefinition getLifecycleDefinition(final ContentType type) { - - final ContentType contentType = typeRepo - .findById(type.getObjectId()) - .orElseThrow(() -> new IllegalCharsetNameException(String.format( - "No ContentType with Id %d in the database. " - + "Where did that ID come from?", - type.getObjectId()))); - - return contentType.getDefaultLifecycle(); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected Optional getLifecycleDefinitionLabel( - final ContentType type, - final Locale locale) { - - final LifecycleDefinition lifecycleDefinition = getLifecycleDefinition( - type); - - if (lifecycleDefinition == null) { - return Optional.empty(); - } else { - return Optional.of(lifecycleDefinition.getLabel().getValue(locale)); - } - } - - @Transactional(Transactional.TxType.REQUIRED) - protected Workflow getWorkflowTemplate(final ContentType type) { - - final ContentType contentType = typeRepo - .findById(type.getObjectId()) - .orElseThrow(() -> new IllegalCharsetNameException(String.format( - "No ContentType with Id %d in the database. " - + "Where did that ID come from?", - type.getObjectId()))); - - return contentType.getDefaultWorkflow(); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected Optional getWorkflowTemplateName(final ContentType type, - final Locale locale) { - - final Workflow workflowTemplate = getWorkflowTemplate(type); - - if (workflowTemplate == null) { - return Optional.empty(); - } else { - return Optional.of(workflowTemplate.getName().getValue(locale)); - } - } - - @Transactional(Transactional.TxType.REQUIRED) - protected List getLifecycleDefinitions( - final ContentSection section) { - - final ContentSection contentSection = sectionRepo - .findById(section.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No ContentSection with ID %d in the database. " - + "Where did that ID come from?", - section.getObjectId()))); - - return new ArrayList<>(contentSection.getLifecycleDefinitions()); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected List getWorkflowTemplates( - final ContentSection section) { - - final ContentSection contentSection = sectionRepo - .findById(section.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No ContentSection with ID %d in the database. " - + "Where did that ID come from?", - section.getObjectId()))); - - return new ArrayList<>(contentSection.getWorkflowTemplates()); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void addContentTypeToContentSection( - final String type, final ContentSection toSection - ) { - Objects.requireNonNull(type); - Objects.requireNonNull(toSection); - - final ContentSection section = sectionRepo - .findById(toSection.getObjectId()) - .orElseThrow( - () -> new IllegalArgumentException( - String.format( - "No ContentSection identified by ID %d found.", - toSection.getObjectId() - ) - ) - ); - - sectionManager.addContentTypeToSection( - typeManager.classNameToClass(type), - section, - section.getLifecycleDefinitions().get(0), - section.getWorkflowTemplates().get(0) - ); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeItemPane.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeItemPane.java deleted file mode 100755 index d8162a027..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeItemPane.java +++ /dev/null @@ -1,355 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.type; - -import com.arsdigita.bebop.ActionLink; -import com.arsdigita.bebop.Form; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.Page; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SimpleContainer; -import com.arsdigita.bebop.event.ActionEvent; -import com.arsdigita.bebop.event.ActionListener; -import com.arsdigita.bebop.form.Submit; -import com.arsdigita.cms.CMS; - -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.ContentType; - -import com.arsdigita.cms.ui.BaseItemPane; -import com.arsdigita.cms.ui.ContentSectionRequestLocal; -//ToDo import com.arsdigita.cms.ui.templates.SectionTemplatesListing; -//ToDo import com.arsdigita.cms.ui.templates.TemplateCreate; -import com.arsdigita.kernel.ui.ACSObjectSelectionModel; -import com.arsdigita.toolbox.ui.ActionGroup; -import com.arsdigita.toolbox.ui.Cancellable; -import com.arsdigita.toolbox.ui.Section; -import com.arsdigita.util.UncheckedWrapperException; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.security.PermissionChecker; -import org.librecms.contentsection.ContentSectionManager; -import org.librecms.contentsection.ContentTypeManager; -import org.librecms.contentsection.privileges.AdminPrivileges; - -/** - * - * @author Justin Ross <jross@redhat.com> - * @author Jens Pelzetter - */ -final class ContentTypeItemPane extends BaseItemPane { - - private final ACSObjectSelectionModel m_model; - private final ContentTypeRequestLocal m_type; - private final SimpleContainer m_detailPane; -// Only useful for user definied content types private final TypeElements m_elements; -// Only useful for user definied content types private final AddElement m_elementAddForm; -// ToDo private final SectionTemplatesListing m_templates; - private final TypePermissionsTable m_permissions; - - ContentTypeItemPane(final ACSObjectSelectionModel model, - final ContentTypeRequestLocal type, - final ActionLink editLink, - final ActionLink deleteLink) { - m_model = model; - m_type = type; - - m_detailPane = new SimpleContainer(); - add(m_detailPane); - setDefault(m_detailPane); - -// m_elements = new TypeElements(m_model); -// m_elementAddForm = new AddElement(); -// ToDo -// m_templates = new SectionTemplatesListing( -// new ContentSectionRequestLocal(), m_type); - m_permissions = new TypePermissionsTable( - new ContentSectionRequestLocal(), m_type); - - final ActionLink templateAddLink = new ActionLink(new Label(gz( - "cms.ui.type.template.add"))); -// ToDo -// final TemplateCreate templateFormSection = new TemplateCreate(m_model); -// final Form templateForm = new CancellableForm("AddTemplate", -// templateFormSection. -// getSaveCancelSection().getCancelButton()); -// templateForm.add(templateFormSection); -// add(templateForm); - -// final AddTextElement textForm = new AddTextElement(m_model); -// add(textForm); -// -// final AddNumberElement numberForm = new AddNumberElement(m_model); -// add(numberForm); -// -// final AddDateElement dateForm = new AddDateElement(m_model); -// add(dateForm); -// -// final AddTextAssetElement assetForm = new AddTextAssetElement(m_model); -// add(assetForm); -// -// final AddImageElement imageForm = new AddImageElement(m_model); -// add(imageForm); -// -// final AddFileElement fileForm = new AddFileElement(m_model); -// add(fileForm); -// -// final AddContentItemElement itemForm -// = new AddContentItemElement(m_model); -// add(itemForm); - m_detailPane.add(new SummarySection(editLink, deleteLink)); -// m_detailPane.add(new RelationAttributeSection()); - - m_detailPane.add(new TypeSecurityContainer(new ElementSection())); - m_detailPane.add(new TemplateSection(templateAddLink)); - - //m_detailPane.add(new PermissionsSection(permissionAddLink)); - m_detailPane.add(new PermissionsSection()); - -// connect(templateAddLink, templateForm); - // connect(permissionAddLink, permissionsForm); -// final SingleSelect elementSelect -// = m_elementAddForm.getElementTypeSelect(); -// -// connect(m_elementAddForm, elementSelect, -// AddElement.TEXT_ELEMENT, textForm); -// connect(textForm); -// -// connect(m_elementAddForm, elementSelect, -// AddElement.NUMBER_ELEMENT, numberForm); -// connect(numberForm); -// -// connect(m_elementAddForm, elementSelect, -// AddElement.DATE_ELEMENT, dateForm); -// connect(dateForm); -// -// connect(m_elementAddForm, elementSelect, -// AddElement.TEXT_ASSET_ELEMENT, assetForm); -// connect(assetForm); -// -// connect(m_elementAddForm, elementSelect, -// AddElement.IMAGE_ELEMENT, imageForm); -// connect(imageForm); -// -// connect(m_elementAddForm, elementSelect, -// AddElement.FILE_ELEMENT, fileForm); -// connect(fileForm); -// -// connect(m_elementAddForm, elementSelect, -// AddElement.CONTENT_ITEM_ELEMENT, itemForm); -// connect(itemForm); - } - - // XXX A temporary, low-impact fix. - private class CancellableForm extends Form implements Cancellable { - - private final Submit m_cancel; - - CancellableForm(final String name, final Submit cancel) { - super(name); - - m_cancel = cancel; - } - - public final boolean isCancelled(final PageState state) { - return m_cancel.isSelected(state); - } - - } - - private class SummarySection extends Section { - - SummarySection(final ActionLink editLink, - final ActionLink deleteLink) { - setHeading(new Label(gz("cms.ui.type.details"))); - - final ActionGroup group = new ActionGroup(); - setBody(group); - - group.setSubject(new ContentTypePropertyList(m_type)); - - group.addAction(new TypeSecurityContainer(editLink)); - group.addAction(new TypeSecurityContainer(deleteLink)); - } - - } - - private class ElementSection extends Section { - - ElementSection() { - setHeading(new Label(gz("cms.ui.type.elements"))); - - final ActionGroup group = new ActionGroup(); - setBody(group); - -// group.setSubject(m_elements); -// group.addAction(m_elementAddForm); - } - - @Override - public final boolean isVisible(final PageState state) { -// return m_model.isSelected(state) && isDynamicType(state) -// && !ContentSection.getConfig().getHideUDCTUI(); - return false; - } - - } - - private class TemplateSection extends Section { - - TemplateSection(final ActionLink templateAddLink) { - setHeading(new Label(gz("cms.ui.type.templates"))); - - final ActionGroup group = new ActionGroup(); - setBody(group); - -// ToDo group.setSubject(m_templates); - group.addAction(new TypeSecurityContainer(templateAddLink)); - } - - @Override - public final boolean isVisible(final PageState state) { - return m_model.isSelected(state) && !isDynamicType(state); - } - - } - - private class PermissionsSection extends Section { - - public PermissionsSection() { - setHeading(new Label(gz("cms.ui.type.permissions"))); - - final ActionGroup group = new ActionGroup(); - setBody(group); - - group.setSubject(m_permissions); - //group.addAction(new TypeSecurityContainer(permissionsAddLink)); - } - - @Override - public final boolean isVisible(final PageState state) { - return m_model.isSelected(state) && !isDynamicType(state); - } - - } - -// private class RelationAttributeSection extends Section { -// -// RelationAttributeSection() { -// setHeading(new Label(gz("cms.ui.type.attributes"))); -// -// setBody(new RelationAttributeList(m_type)); -// } -// -// @Override -// public final boolean isVisible(final PageState state) { -//// ISt es möglich, den folgenden Code nur einmal zu haben?? Kann man auf die isVisible von RelationAttributeList -// // zurückgreifen?? -// boolean retVal = false; -// ContentType ct = (ContentType) m_type.getContentType(state); -// ContentItem ci = null; -// -// try { -// Class clazz = Class.forName(ct. -// getClassName()).asSubclass(ContentItem.class); -// ci = clazz.newInstance(); -// if (ci instanceof RelationAttributeInterface) { -// RelationAttributeInterface rai -// = (RelationAttributeInterface) ci; -// retVal = rai.hasRelationAttributes(); -// } -// ci.delete(); -// } catch (Exception ex) { -// //retVal = false; -// } -// -// return retVal; -// } -// } - @Override - public final void register(final Page page) { - super.register(page); - - page.addActionListener(new ActionListener() { - - @Override - public final void actionPerformed(final ActionEvent event) { - final PageState state = event.getPageState(); - - if (state.isVisibleOnPage(ContentTypeItemPane.this) - && m_model.isSelected(state) - && !userCanEdit(state)) { -// m_templates.getRemoveColumn().setVisible(state, false); -// m_templates.getDefaultColumn().setVisible(state, false); -// m_elements.getTable().getColumn(3).setVisible(state, false); - } - } - - }); - } - - /** - * Unregister a content type from a content section. - */ - private void removeType(final PageState state) { - final ContentSection section = CMS.getContext().getContentSection(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentTypeManager typeManager = cdiUtil.findBean( - ContentTypeManager.class); - final ContentSectionManager sectionManager = cdiUtil.findBean( - ContentSectionManager.class); - - final ContentType type = m_type.getContentType(state); - final Class typeClass; - try { - typeClass = (Class) Class.forName( - type.getContentItemClass()); - } catch (ClassNotFoundException ex) { - throw new UncheckedWrapperException(ex); - } - - sectionManager.removeContentTypeFromSection(typeClass, section); - } - - /** - * Determine if the current user has access to edit the content type - */ - protected static boolean userCanEdit(final PageState state) { - final PermissionChecker permissionChecker = CdiUtil.createCdiUtil() - .findBean(PermissionChecker.class); - final ContentSection section = CMS.getContext().getContentSection(); - - return permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_CONTENT_TYPES, section); - } - - /** - * utility method get the DataObject from the DataBase, returns true if it - * is a modifiable type, false otherwise. - * - * Because we don't have modifiable types aka User Definied Content Types in - * CCM NG yet, this method returns always false for now. - */ - protected final boolean isDynamicType(final PageState state) { - return false; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeListModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeListModelBuilder.java deleted file mode 100755 index f28975a32..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeListModelBuilder.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.type; - -import com.arsdigita.bebop.List; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.list.ListModel; -import com.arsdigita.bebop.list.ListModelBuilder; -import com.arsdigita.cms.CMS; - -import org.librecms.contentsection.ContentSection; - -import com.arsdigita.util.LockableImpl; - -import org.libreccm.cdi.utils.CdiUtil; - -import java.util.NoSuchElementException; - -/** - * Builds a dynamic list of content types for a content section. - */ -class ContentTypeListModelBuilder - extends LockableImpl - implements ListModelBuilder { - - /** - * - * @param list - * @param state - * - * @return - */ - @Override - public ListModel makeModel(final List list, final PageState state) { - return new Model(); - } - - /** - * - */ - private class Model implements ListModel { - - private final java.util.List types; - private int index = -1; - - Model() { - final ContentSection section = CMS.getContext().getContentSection(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentTypeAdminPaneController controller = cdiUtil.findBean( - ContentTypeAdminPaneController.class); - - types = controller.getTypeList(section); - } - - @Override - public boolean next() throws NoSuchElementException { - index++; - return index < types.size(); - } - - @Override - public Object getElement() { - return types.get(index)[1]; - } - - @Override - public String getKey() { - return types.get(index)[0]; - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypePropertyList.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypePropertyList.java deleted file mode 100755 index 2dafd940e..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypePropertyList.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.type; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.cms.CMS; - -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.ContentType; - -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.kernel.KernelConfig; -import com.arsdigita.toolbox.ui.Property; -import com.arsdigita.toolbox.ui.PropertyList; - -import org.libreccm.cdi.utils.CdiUtil; - -import java.util.Locale; - -import org.librecms.CmsConstants; -import org.librecms.contenttypes.ContentTypeInfo; -import org.librecms.contenttypes.ContentTypesManager; - -import java.util.List; -import java.util.Optional; -import java.util.ResourceBundle; - -/** - * This component displays basic attributes of a content type including: - * - * label, description, default lifecycle definition, default workflow template - * - * @author Michael Pih - * @author Justin Ross - * @author Jens Pelzetter - */ -class ContentTypePropertyList extends PropertyList { - - private final ContentTypeRequestLocal m_type; - - public ContentTypePropertyList(final ContentTypeRequestLocal type) { - m_type = type; - } - - @Override - protected final List properties(final PageState state) { - final List props = super.properties(state); - final ContentType type = m_type.getContentType(state); - final ContentSection section = CMS.getContext().getContentSection(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentTypesManager typesManager = cdiUtil - .findBean(ContentTypesManager.class); - final ContentTypeInfo typeInfo = typesManager.getContentTypeInfo(type); - - final KernelConfig kernelConfig = KernelConfig.getConfig(); - final Locale defaultLocale = kernelConfig.getDefaultLocale(); - - final ResourceBundle labelBundle = ResourceBundle - .getBundle(typeInfo.getLabelBundle()); - final ResourceBundle descBundle = ResourceBundle - .getBundle(typeInfo.getDescriptionBundle()); - - props.add(new Property(gz("cms.ui.name"), - labelBundle.getString(typeInfo.getLabelKey()))); - props.add(new Property(gz("cms.ui.description"), - descBundle - .getString(typeInfo.getDescriptionKey()))); -// props.add(new Property(gz("cms.ui.type.parent"), -// type.getParent().orElse(null))); - props.add(new Property(gz("cms.ui.type.lifecycle"), - getLifecycle(section, type))); - props.add(new Property(gz("cms.ui.type.workflow"), - getWorkflow(section, type))); - - return props; - } - - private String getLifecycle(final ContentSection section, - final ContentType type) { - final KernelConfig kernelConfig = KernelConfig.getConfig(); - final Locale defaultLocale = kernelConfig.getDefaultLocale(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentTypeAdminPaneController controller = cdiUtil - .findBean(ContentTypeAdminPaneController.class); - - final Optional label = controller - .getLifecycleDefinitionLabel(type, defaultLocale); - - if (label.isPresent()) { - return label.get(); - } else { - return lz("cms.ui.type.lifecycle.none"); - } - } - - private String getWorkflow(final ContentSection section, - final ContentType type) { - final KernelConfig kernelConfig = KernelConfig.getConfig(); - final Locale defaultLocale = kernelConfig.getDefaultLocale(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentTypeAdminPaneController controller = cdiUtil - .findBean(ContentTypeAdminPaneController.class); - - final Optional name = controller - .getWorkflowTemplateName(type, defaultLocale); - - if (name.isPresent()) { - return name.get(); - } else { - return lz("cms.ui.type.workflow.none"); - } - } - - private static GlobalizedMessage gz(final String key) { - return new GlobalizedMessage(key, CmsConstants.CMS_BUNDLE); - } - - private static String lz(final String key) { - return (String) gz(key).localize(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeRequestLocal.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeRequestLocal.java deleted file mode 100755 index d2125e9d2..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeRequestLocal.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.type; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.RequestLocal; - -import org.librecms.contentsection.ContentType; - -public abstract class ContentTypeRequestLocal extends RequestLocal { - - @Override - protected abstract Object initialValue(final PageState state); - - public final ContentType getContentType(final PageState state) { - return (ContentType) get(state); - } -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/EditType.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/EditType.java deleted file mode 100755 index 2acd84c19..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/EditType.java +++ /dev/null @@ -1,386 +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.type; - -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.SimpleContainer; -import com.arsdigita.bebop.SingleSelectionModel; -import com.arsdigita.bebop.Text; -import com.arsdigita.bebop.event.FormInitListener; -import com.arsdigita.bebop.event.FormProcessListener; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.event.PrintEvent; -import com.arsdigita.bebop.event.PrintListener; -import com.arsdigita.bebop.form.Hidden; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.form.SingleSelect; -import com.arsdigita.bebop.form.Submit; -import com.arsdigita.bebop.parameters.LongParameter; -import com.arsdigita.bebop.parameters.NotNullValidationListener; -import com.arsdigita.cms.CMS; - -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.ContentType; -import org.librecms.lifecycle.LifecycleDefinition; - -import com.arsdigita.cms.ui.CMSForm; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.kernel.KernelConfig; -import com.arsdigita.util.UncheckedWrapperException; - -import org.apache.logging.log4j.Logger; -import org.apache.logging.log4j.LogManager; -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.workflow.Workflow; -import org.libreccm.workflow.WorkflowRepository; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentTypeManager; -import org.librecms.contentsection.ContentTypeRepository; -import org.librecms.lifecycle.LifecycleDefinitionRepository; - -import java.util.List; -import java.util.Locale; -import java.util.Optional; -import java.util.TooManyListenersException; - -/** - * This class contains a form component to edit a content type - * - * @author Jack Chung (flattop@arsdigita.com) - * @author Michael Pih (pihman@arsdigita.com) - * @author Jens Pelzetter - */ -public class EditType extends CMSForm - implements FormInitListener, FormProcessListener { - - private static final Logger LOGGER = LogManager.getLogger(EditType.class); - - private final SingleSelectionModel selectedTypeModel; - - // Form widgets - private final Hidden idField; -// private TextField m_label; -// private TextArea m_description; - private final SingleSelect lifecycleSelect; - private final SingleSelect workflowSelect; - private final Submit submitButton; - private final Submit cancelButton; - - /** - * @param selectedTypeModel The content type selection model. This tells the - * form which content type is selected. - */ - public EditType(final SingleSelectionModel selectedTypeModel) { - super("EditContentType"); - - this.selectedTypeModel = selectedTypeModel; - - idField = new Hidden(new LongParameter("id")); - idField.addValidationListener(new NotNullValidationListener()); - super.add(idField); - -// add(new Label(new GlobalizedMessage("cms.ui.type.label", -// CmsConstants.CMS_BUNDLE))); -// m_label = new TextField(new StringParameter("label")); -// m_label.addValidationListener(new NotNullValidationListener()); -// m_label.setSize(40); -// m_label.setMaxLength(1000); -// add(m_label); -// -// add(new Label(new GlobalizedMessage("cms.ui.description", -// CmsConstants.CMS_BUNDLE))); -// m_description = new TextArea(new StringParameter("description")); -// m_description.addValidationListener( -// new StringLengthValidationListener(4000)); -// m_description.setCols(40); -// m_description.setRows(5); -// m_description.setWrap(TextArea.SOFT); -// add(m_description); - super.add(new Label(new GlobalizedMessage("cms.ui.type.lifecycle", - CmsConstants.CMS_BUNDLE))); - lifecycleSelect = new SingleSelect(new LongParameter("lifecycle")); - try { - lifecycleSelect.addPrintListener(new SelectLifecyclePrintListener()); - } catch (TooManyListenersException e) { - throw new UncheckedWrapperException("TooManyListeners: " + e - .getMessage(), e); - } - super.add(lifecycleSelect); - - super.add(new Label(new GlobalizedMessage("cms.ui.type.workflow", - CmsConstants.CMS_BUNDLE))); - workflowSelect = new SingleSelect(new LongParameter("workflow")); - try { - workflowSelect.addPrintListener(new SelectWorkflowPrintListener()); - } catch (TooManyListenersException ex) { - throw new UncheckedWrapperException("TooManyListeners: " + ex - .getMessage(), ex); - } - super.add(workflowSelect); - - final SimpleContainer buttonContainer = new SimpleContainer(); - submitButton = new Submit(new GlobalizedMessage("cms.ui.save", - CmsConstants.CMS_BUNDLE)); - buttonContainer.add(submitButton); - cancelButton = new Submit(new GlobalizedMessage("cms.ui.cancel", - CmsConstants.CMS_BUNDLE)); - buttonContainer.add(cancelButton); - super.add(buttonContainer, ColumnPanel.FULL_WIDTH | ColumnPanel.CENTER); - - super.addInitListener(this); - super.addSubmissionListener(new TypeSecurityListener()); - super.addProcessListener(this); - } - - /** - * Returns true if the "cancel" button was submitted. - * - * @param state The page state - * - * @return True if the form was cancelled, false otherwise - */ - @Override - public boolean isCancelled(final PageState state) { - return cancelButton.isSelected(state); - } - - /** - * Returns the "cancel" button on the form - * - * @return the cancel button on the form - */ - public Submit getCancelButton() { - return cancelButton; - } - - /** - * Populates the form with the content type properties. - * - * @param event - */ - @Override - public void init(final FormSectionEvent event) { - - final FormData data = event.getFormData(); - final PageState state = event.getPageState(); - -// final ContentSection section = CMS.getContext().getContentSection(); -// -// final KernelConfig kernelConfig = KernelConfig.getConfig(); - final ContentType type = getContentType(state); - final long typeId = type.getObjectId(); -// final String label = type.getLabel().getValue(kernelConfig -// .getDefaultLocale()); -// final String description = type.getDescription().getValue(kernelConfig -// .getDefaultLocale()); - - data.put(idField.getName(), typeId); -// data.put(m_label.getName(), label); -// data.put(m_description.getName(), description); - - final LifecycleDefinition cycle = type.getDefaultLifecycle(); - if (cycle != null) { - data.put(lifecycleSelect.getName(), cycle.getDefinitionId()); - } - - final Workflow template = type.getDefaultWorkflow(); - if (template != null) { - data.put(workflowSelect.getName(), template.getWorkflowId()); - } - } - - /** - * Fetches the currently selected content type from the single selection - * model. - */ - private ContentType getContentType(final PageState state) { - - final String key = selectedTypeModel.getSelectedKey(state); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentTypeRepository typeRepo = cdiUtil.findBean( - ContentTypeRepository.class); - - final Optional result; - try { - result = typeRepo.findByIdAndFetchAttributes(Long.parseLong(key), - "defaultLifecycle", - "defaultWorkflow"); - } catch (NumberFormatException ex) { - throw new UncheckedWrapperException(String.format( - "The provided key \"%s\" is not a long.", key), - ex); - } - - if (result.isPresent()) { - return result.get(); - } else { - throw new UncheckedWrapperException(String.format( - "ContentType with ID %s not found.", key)); - } - } - - /** - * Edits the content type. - * - * @param event - * - * @throws FormProcessException - */ - @Override - public void process(final FormSectionEvent event) throws - FormProcessException { - final FormData data = event.getFormData(); - - // Get the current content section. - final ContentSection section = CMS.getContext().getContentSection(); - - // Read form variables. - final Long key = (Long) data.get(idField.getName()); -// final String label = (String) data.get(m_label.getName()); -// final String description = (String) data.get(m_description.getName()); - final Long lifecycleId = (Long) data.get(lifecycleSelect.getName()); - final Long workflowId = (Long) data.get(workflowSelect.getName()); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentTypeRepository typeRepo = cdiUtil.findBean( - ContentTypeRepository.class); - final LifecycleDefinitionRepository lifecycleDefRepo = cdiUtil.findBean( - LifecycleDefinitionRepository.class); - final WorkflowRepository workflowRepo = cdiUtil - .findBean(WorkflowRepository.class); - final ContentTypeManager typeManager = cdiUtil.findBean( - ContentTypeManager.class); - - final Optional type = typeRepo.findById(key); - if (!type.isPresent()) { - LOGGER.error("Can't find ContentType with key {}", key); - throw new FormProcessException(new GlobalizedMessage( - "cms.ui.type.content_editing_failed", - CmsConstants.CMS_BUNDLE, - new Object[]{key})); - } - -// final KernelConfig kernelConfig = KernelConfig.getConfig(); -// type.get().getLabel().putValue(kernelConfig.getDefaultLocale(), label); -// type.get().getDescription().putValue(kernelConfig.getDefaultLocale(), -// description); - typeRepo.save(type.get()); - - // Handle default lifecycle and workflow. - final LifecycleDefinition defaultLifecycle; - if (lifecycleId == 0) { - defaultLifecycle = null; - } else { - defaultLifecycle = lifecycleDefRepo.findById(lifecycleId).get(); - } - final Workflow defaultWorkflow; - if (workflowId == 0) { - defaultWorkflow = null; - } else { - defaultWorkflow = workflowRepo.findById(workflowId).get(); - } - - typeManager.setDefaultLifecycle(type.get(), defaultLifecycle); - typeManager.setDefaultWorkflow(type.get(), defaultWorkflow); - - } - - /** - * Print listener to generate the select widget for the list of lifecyle - * definitions. - */ - private class SelectLifecyclePrintListener implements PrintListener { - - @Override - public void prepare(final PrintEvent event) { - - final SingleSelect lifecycleSelect = (SingleSelect) event - .getTarget(); - lifecycleSelect.clearOptions(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentTypeAdminPaneController controller = cdiUtil - .findBean(ContentTypeAdminPaneController.class); - - // Get the current content section - ContentSection section = CMS.getContext().getContentSection(); - - lifecycleSelect.addOption(new Option( - "0", - new Label(new GlobalizedMessage("cms.ui.type.lifecycle.select", - CmsConstants.CMS_BUNDLE)))); - - final List cycles = controller - .getLifecycleDefinitions(section); - final Locale defaultLocale = KernelConfig.getConfig() - .getDefaultLocale(); - cycles.forEach(cycle -> { - lifecycleSelect.addOption( - new Option(Long.toString(cycle.getDefinitionId()), - new Text(cycle.getLabel().getValue(defaultLocale)))); - }); - } - - } - - /** - * Print listener to generate the select widget for the list of workflow - * templates. - */ - private class SelectWorkflowPrintListener implements PrintListener { - - @Override - public void prepare(final PrintEvent event) { - - final SingleSelect workflowSelect = (SingleSelect) event.getTarget(); - workflowSelect.clearOptions(); - - // Get the current content section - ContentSection section = CMS.getContext().getContentSection(); - - workflowSelect.addOption(new Option( - "0", - new Label(new GlobalizedMessage("cms.ui.type.workflow.select", - CmsConstants.CMS_BUNDLE)))); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentTypeAdminPaneController controller = cdiUtil - .findBean(ContentTypeAdminPaneController.class); - - final List templates = controller - .getWorkflowTemplates(section); - final Locale defaultLocale = KernelConfig.getConfig() - .getDefaultLocale(); - templates.forEach(template -> { - workflowSelect.addOption( - new Option( - Long.toString(template.getWorkflowId()), - new Text(template.getName().getValue(defaultLocale)))); - }); - - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/SelectType.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/SelectType.java deleted file mode 100755 index ae35157d9..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/SelectType.java +++ /dev/null @@ -1,211 +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.type; - -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.SimpleContainer; -import com.arsdigita.bebop.event.FormProcessListener; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.event.FormSubmissionListener; -import com.arsdigita.bebop.event.PrintEvent; -import com.arsdigita.bebop.event.PrintListener; -import com.arsdigita.bebop.form.CheckboxGroup; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.form.Submit; -import com.arsdigita.cms.CMS; - -import org.librecms.contentsection.ContentSection; - -import com.arsdigita.cms.ui.CMSForm; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.ui.admin.GlobalizationUtil; -import com.arsdigita.util.UncheckedWrapperException; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentSectionManager; -import org.librecms.contentsection.ContentTypeManager; -import org.librecms.contenttypes.ContentTypeInfo; -import org.librecms.contenttypes.ContentTypesManager; - -import java.util.List; -import java.util.TooManyListenersException; -import java.util.stream.Collectors; - -/** - * This class contains a form component to that allows adding already-existing - * content type to a content section. - * - * @author Jack Chung - * @author Michael Pih - * @author Jens Pelzetter - */ -public class SelectType extends CMSForm implements PrintListener, - FormSubmissionListener, - FormProcessListener { - - private final static String TYPES = "types"; - private CheckboxGroup m_typesCheckbox; - private Submit m_submit; - private Submit m_cancel; - - public SelectType() { - super("ContentTypeSelect"); - - m_typesCheckbox = new CheckboxGroup(TYPES); - try { - m_typesCheckbox.addPrintListener(this); - } catch (TooManyListenersException e) { - throw new UncheckedWrapperException("TooManyListeners: " + e - .getMessage()); - } - - add(new Label(new GlobalizedMessage("cms.ui.type.available_types", - CmsConstants.CMS_BUNDLE))); - add(m_typesCheckbox); - - SimpleContainer s = new SimpleContainer(); - m_submit = new Submit("submit"); - m_submit.setButtonLabel("Add Selected Content Types"); - s.add(m_submit); - m_cancel = new Submit("cancel"); - m_cancel.setButtonLabel("Cancel"); - s.add(m_cancel); - add(s, ColumnPanel.FULL_WIDTH | ColumnPanel.CENTER); - - addProcessListener(this); - addSubmissionListener(new TypeSecurityListener()); - addSubmissionListener(this); - } - - /** - * Generate a checkbox list of all content type not associated with the - * current content section - * @param event - */ - @Override - public void prepare(final PrintEvent event) { - - final CheckboxGroup target = (CheckboxGroup) event.getTarget(); - - // Get the current content section - final ContentSection section = CMS.getContext().getContentSection(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentTypeAdminPaneController controller = cdiUtil - .findBean(ContentTypeAdminPaneController.class); - final ContentTypesManager typesManager = cdiUtil.findBean( - ContentTypesManager.class); - - final List availableTypes = typesManager - .getAvailableContentTypes(); - final List assignedTypes = controller - .getContentItemClassesList(section); -// = section.getContentTypes() -// .stream() -// .map(contentType -> contentType.getContentItemClass()) -// .collect(Collectors.toList()); - - final List notAssignedTypes = availableTypes.stream() - .filter(type -> !assignedTypes.contains(type.getContentItemClass() - .getName())) - .collect(Collectors.toList()); - - for (final ContentTypeInfo typeInfo : notAssignedTypes) { - addOption(target, typeInfo); - } - } - - private void addOption(final CheckboxGroup target, - final ContentTypeInfo typeInfo) { - final Label label = new Label(new GlobalizedMessage(typeInfo - .getLabelKey(), typeInfo.getLabelBundle())); - target.addOption(new Option(typeInfo.getContentItemClass().getName(), - label)); - } - - /** - * Form submission listener. If the cancel button was pressed, do not - * process the form. - * - * @param event The submit event - * - * @throws com.arsdigita.bebop.FormProcessException - */ - @Override - public void submitted(final FormSectionEvent event) throws - FormProcessException { - PageState state = event.getPageState(); - if (isCancelled(state)) { - throw new FormProcessException(GlobalizationUtil.globalize( - "cms.ui.cancelled")); - } - } - - /** - * Returns true if this form was cancelled. - * - * @return true if the form was cancelled, false otherwise - */ - @Override - public boolean isCancelled(final PageState state) { - return m_cancel.isSelected(state); - } - - /** - * Processes form listener which updates a life cycle - * - * @param event - * - * @throws com.arsdigita.bebop.FormProcessException - */ - @Override - public void process(final FormSectionEvent event) - throws FormProcessException { - - final ContentSection section = CMS.getContext().getContentSection(); - - final FormData data = event.getFormData(); - final String[] types = (String[]) data.get(TYPES); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); -// final ContentTypeManager typeManager = cdiUtil.findBean( -// ContentTypeManager.class); -// final ContentSectionManager sectionManager = cdiUtil.findBean( -// ContentSectionManager.class); - final ContentTypeAdminPaneController controller = cdiUtil - .findBean(ContentTypeAdminPaneController.class); - - if (types != null) { - for (String type : types) { -// sectionManager.addContentTypeToSection( -// typeManager.classNameToClass(type), -// section, -// section.getLifecycleDefinitions().get(0), -// section.getWorkflowTemplates().get(0)); - controller.addContentTypeToContentSection(type, section); - } - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypePermissionsTable.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypePermissionsTable.java deleted file mode 100644 index 2fd5ddce4..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypePermissionsTable.java +++ /dev/null @@ -1,262 +0,0 @@ -package com.arsdigita.cms.ui.type; - -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.table.RowData; -import com.arsdigita.bebop.table.TableCellRenderer; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.bebop.table.TableColumnModel; -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.bebop.table.TableModelBuilder; -import com.arsdigita.cms.CMS; - -import org.librecms.contentsection.ContentType; - -import com.arsdigita.cms.ui.ContentSectionRequestLocal; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.security.Role; - -import com.arsdigita.util.LockableImpl; - -import java.util.List; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.security.PermissionChecker; -import org.libreccm.security.RoleRepository; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.privileges.AdminPrivileges; - -import java.util.Iterator; - -/** - * - * ToDo, maybe not needed anymore... - * - * @author Jens Pelzetter - */ -public class TypePermissionsTable extends Table implements TableActionListener { - - private final String TABLE_COL_ROLE = "table_col_role"; - private final String TABLE_COL_CAN_USE = "table_col_can_use"; - private final String TABLE_COL_ACTION = "table_col_action"; - private final ContentTypeRequestLocal type; - - public TypePermissionsTable(final ContentSectionRequestLocal section, - final ContentTypeRequestLocal type) { - super(); - - this.type = type; - - setEmptyView(new Label(new GlobalizedMessage( - "cms.ui.type.permissions.none", - CmsConstants.CMS_BUNDLE))); - - TableColumnModel columnModel = getColumnModel(); - - columnModel.add(new TableColumn( - 0, - new GlobalizedMessage("cms.ui.type.permissions.role", - CmsConstants.CMS_BUNDLE).localize(), - TABLE_COL_ROLE)); - - columnModel.add(new TableColumn( - 1, - new GlobalizedMessage("cms.ui.type.permissions_can_use", - CmsConstants.CMS_BUNDLE).localize(), - TABLE_COL_CAN_USE)); - - columnModel.add(new TableColumn( - 2, - new GlobalizedMessage("cms.ui.type.permission.action", - CmsConstants.CMS_BUNDLE).localize(), - TABLE_COL_ACTION)); - - setModelBuilder(new TypePermissionsTableModelBuilder()); - - columnModel.get(0).setCellRenderer(new RoleCellRenderer()); - columnModel.get(1).setCellRenderer(new CanUseCellRenderer()); - columnModel.get(2).setCellRenderer(new ActionCellRenderer()); - - addTableActionListener(this); - } - - @Override - public void cellSelected(final TableActionEvent event) { - final PageState state = event.getPageState(); - - final TableColumn column = getColumnModel().get(event.getColumn()); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final RoleRepository roleRepo = cdiUtil.findBean(RoleRepository.class); - final TypePermissionsTableController controller = cdiUtil.findBean( - TypePermissionsTableController.class); - - if (TABLE_COL_ACTION.equals(column.getHeaderKey().toString())) { - final Role role = roleRepo.findById(Long.parseLong( - event.getRowKey().toString())).get(); - ContentType contentType = getType().getContentType(state); - - controller.toggleTypeUsePermission(contentType, role); - } - } - - @Override - public void headSelected(final TableActionEvent event) { - //Nothing to do - } - - private class TypePermissionsTableModelBuilder - extends LockableImpl - implements TableModelBuilder { - - public TypePermissionsTableModelBuilder() { - } - - @Override - public TableModel makeModel(final Table table, final PageState state) { - table.getRowSelectionModel().clearSelection(state); - return new TypePermissionsTableModel(table, state); - } - - } - - private class TypePermissionsTableModel implements TableModel { - - private final Iterator> iterator; - private RowData currentRow; - - public TypePermissionsTableModel(final Table table, - final PageState state) { - final ContentType contentType = ((TypePermissionsTable) table) - .getType() - .getContentType(state); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final TypePermissionsTableController controller = cdiUtil.findBean( - TypePermissionsTableController.class); - final ContentSection section = CMS.getContext().getContentSection(); - final List> rows = controller.retrieveTypePermissions( - contentType, section); - iterator = rows.iterator(); - } - - @Override - public int getColumnCount() { - return 3; - } - - @Override - public boolean nextRow() { - if (iterator.hasNext()) { - currentRow = iterator.next(); - return true; - } else { - return false; - } - } - - @Override - public Object getElementAt(final int columnIndex) { - switch (columnIndex) { - case 0: - return currentRow.getColData(0); - case 1: - return currentRow.getColData(1); - case 2: - if ("cms.ui.type.permissions.can_use.yes".equals(currentRow - .getColData(1))) { - return "cms.ui.type.permissions.actions.revoke"; - } else { - return "cms.ui.type.permissions.can_use.grant"; - } - default: - throw new IllegalArgumentException("Invalid column index."); - } - } - - @Override - public Object getKeyAt(final int columnIndex) { - return currentRow.getRowKey(); - } - - } - - private class RoleCellRenderer - extends LockableImpl - implements TableCellRenderer { - - @Override - public Component getComponent(Table table, - PageState state, - Object value, - boolean isSelected, - Object key, - int row, - int column) { - return new Text(value.toString()); - } - - } - - private class CanUseCellRenderer - extends LockableImpl - implements TableCellRenderer { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - return new Label(new GlobalizedMessage(value.toString(), - CmsConstants.CMS_BUNDLE)); - } - - } - - private class ActionCellRenderer - extends LockableImpl - implements TableCellRenderer { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - boolean isSelected, - final Object key, - final int row, - final int column) { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final PermissionChecker permissionChecker = cdiUtil.findBean( - PermissionChecker.class); - - final ContentSection section = CMS.getContext().getContentSection(); - - if (permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_CONTENT_TYPES, section)) { - - return new ControlLink(new Label(new GlobalizedMessage( - (String) value), CmsConstants.CMS_BUNDLE)); - } else { - return new Text(""); - } - - } - - } - - private ContentTypeRequestLocal getType() { - return type; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypePermissionsTableController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypePermissionsTableController.java deleted file mode 100644 index 9e9984aff..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypePermissionsTableController.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2016 LibreCCM Foundation. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package com.arsdigita.cms.ui.type; - -import org.librecms.contentsection.privileges.TypePrivileges; - -import com.arsdigita.bebop.table.RowData; - -import org.libreccm.security.PermissionChecker; -import org.libreccm.security.PermissionManager; -import org.libreccm.security.Role; -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.ContentSectionRepository; -import org.librecms.contentsection.ContentType; -import org.librecms.contentsection.ContentTypeRepository; - -import java.util.List; -import java.util.stream.Collectors; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.transaction.Transactional; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -public class TypePermissionsTableController { - - @Inject - private PermissionChecker permissionChecker; - - @Inject - private PermissionManager permissionManager; - - @Inject - private ContentSectionRepository sectionRepo; - - @Inject - private ContentTypeRepository typeRepo; - - @Transactional(Transactional.TxType.REQUIRED) - public List> retrieveTypePermissions( - final ContentType type, final ContentSection section) { - - //Ensure that we use a sane object for the type - return retrieveTypePermissions(type.getObjectId(), section); - } - - @Transactional(Transactional.TxType.REQUIRED) - public List> retrieveTypePermissions( - final long typeId, final ContentSection section) { - - final ContentType type = typeRepo.findById(typeId).get(); - final ContentSection contentSection = sectionRepo - .findById(section.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No ContentSection with ID %d in the database. " - + "Where did that Id come from?", - section.getObjectId()))); - - final List roles = contentSection.getRoles(); - - return roles.stream() - .map(role -> retrievePermissionsForRole(type, role)) - .collect(Collectors.toList()); - } - - private RowData retrievePermissionsForRole(final ContentType type, - final Role role) { - final RowData rowData = new RowData<>(2); - rowData.setRowKey(role.getRoleId()); - rowData.setColData(0, role.getName()); - - if (permissionChecker.isPermitted(TypePrivileges.USE_TYPE, type)) { - rowData.setColData(1, "cms.ui.type.permissions.can_use.yes"); - } else { - rowData.setColData(1, "cms.ui.type.permissions.can_use.no"); - } - - return rowData; - } - - public void toggleTypeUsePermission(final ContentType type, - final Role role) { - if (permissionChecker.isPermitted(TypePrivileges.USE_TYPE, type, role)) { - permissionManager.revokePrivilege(TypePrivileges.USE_TYPE, - role, - type); - } else { - permissionManager.grantPrivilege(TypePrivileges.USE_TYPE, - role, - type); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypeSecurityContainer.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypeSecurityContainer.java deleted file mode 100755 index 5d5a8e64e..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypeSecurityContainer.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.type; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.PageState; -import com.arsdigita.cms.CMS; - -import org.libreccm.security.Party; - -import com.arsdigita.toolbox.ui.SecurityContainer; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.security.PermissionChecker; -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.privileges.AdminPrivileges; - -/** - * - * @author Justin Ross - * @author Jens Pelzetter - */ -public final class TypeSecurityContainer extends SecurityContainer { - - public TypeSecurityContainer(final Component component) { - super(component); - } - - @Override - protected final boolean canAccess(final Party party, - final PageState state) { - final PermissionChecker permissionChecker = CdiUtil.createCdiUtil().findBean(PermissionChecker.class); - - final ContentSection section = CMS.getContext().getContentSection(); - - return permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_CONTENT_TYPES, section); - } -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypeSecurityListener.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypeSecurityListener.java deleted file mode 100755 index 7a163f192..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypeSecurityListener.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.type; - -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.event.FormSubmissionListener; -import com.arsdigita.cms.CMS; -import com.arsdigita.dispatcher.AccessDeniedException; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.security.PermissionChecker; -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.privileges.AdminPrivileges; - -/** - * - * @author Justin Ross <jross@redhat.com> - * @autor Jens Pelzetter - */ -final class TypeSecurityListener implements FormSubmissionListener { - - - @Override - public final void submitted(final FormSectionEvent event) - throws FormProcessException { - - final ContentSection section = CMS.getContext().getContentSection(); - final PermissionChecker permissionChecker = CdiUtil.createCdiUtil().findBean(PermissionChecker.class); - if (!permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_CONTENT_TYPES, section)) { - throw new AccessDeniedException(); - } - } -} From 5efeef8136bea7c28009bdfefcec75e371cfaaaf Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 16 Mar 2022 19:46:09 +0100 Subject: [PATCH 10/63] Removed some already disabled classes from ccm-cms --- .../ui/role/AdminTableModelBuilder.java.off | 125 -------------- .../cms/ui/role/RoleAdminAddForm.java.off | 152 ------------------ 2 files changed, 277 deletions(-) delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/role/AdminTableModelBuilder.java.off delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleAdminAddForm.java.off diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/AdminTableModelBuilder.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/AdminTableModelBuilder.java.off deleted file mode 100755 index d13ec1ee1..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/AdminTableModelBuilder.java.off +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.role; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.table.AbstractTableModelBuilder; -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.ui.admin.GlobalizationUtil; -import org.apache.log4j.Logger; -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.core.EmailAddress; -import org.libreccm.security.Party; -import org.libreccm.security.Role; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; - -/** - * TODO Needs a description. - * - * @author Yannick Bülter - * @author Justin Ross <jross@redhat.com> - * @version $Id: AdminTableModelBuilder.java 287 2005-02-22 00:29:02Z sskracic $ - */ -class AdminTableModelBuilder extends AbstractTableModelBuilder { - - private static final Logger s_log = Logger.getLogger - (AdminTableModelBuilder.class); - - private final RoleRequestLocal m_role; - - AdminTableModelBuilder(final RoleRequestLocal role) { - m_role = role; - } - - public final TableModel makeModel(final Table table, - final PageState state) { - final Role role = m_role.getRole(state); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - - /*TODO What does this mean? - Session session = SessionManager.getSession(); - DataQuery query = session.retrieveQuery - ("com.arsdigita.cms.roleAdminListing"); - - query.setParameter("roleID", role.getID()); - - final DataCollection admins = new DataQueryDataCollectionAdapter - (query, "party");*/ - - - return new Model(new HashSet<>()); - } - - private static class Model implements TableModel { - private Party m_party; - private final Collection m_parties; - private final Iterator iterator; - - Model(final Collection parties) { - m_parties = parties; - iterator = m_parties.iterator(); - } - - public final int getColumnCount() { - return 3; - } - - public final boolean nextRow() { - if (iterator.hasNext()) { - m_party = iterator.next(); - return true; - } else { - return false; - } - } - - public final Object getKeyAt(final int column) { - return m_party.getPartyId(); - } - - public final Object getElementAt(final int column) { - switch (column) { - case 0: - return m_party.getName(); - case 1: - //FIXME Since parties don't have emails atm. - final EmailAddress email = null; - - if (email == null) { - return lz("cms.ui.none"); - } else { - return email.toString(); - } - case 2: - return lz("cms.ui.role.admin.remove"); - default: - throw new IllegalStateException(); - } - } - } - - protected final static String lz(final String key) { - return (String) GlobalizationUtil.globalize(key).localize(); - } -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleAdminAddForm.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleAdminAddForm.java.off deleted file mode 100755 index a038f4a8a..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleAdminAddForm.java.off +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.role; - -import com.arsdigita.bebop.FormData; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SingleSelectionModel; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.cms.ui.FormSecurityListener; -import com.arsdigita.cms.ui.UserAddForm; -import com.arsdigita.util.Assert; -import org.libreccm.security.Group; -import org.libreccm.security.Role; -import org.libreccm.security.User; -import org.librecms.CmsConstants; - -import java.math.BigDecimal; -import java.util.LinkedList; -import java.util.List; - -/** - * @author Michael Pih - * @author Uday Mathur - * @version $Id: RoleAdminAddForm.java 287 2005-02-22 00:29:02Z sskracic $ - */ -class RoleAdminAddForm extends UserAddForm { - - private final SingleSelectionModel m_roles; - - private static final String NAME_FILTER = - "(upper(lastName) like ('%' || upper(:search) || '%'))" + - " or " + - "(upper(firstName) like ('%' || upper(:search) || '%'))" + - " or " + - "(upper(email) like ('%' || upper(:search) || '%'))"; - - public RoleAdminAddForm(SingleSelectionModel roles, TextField search) { - super(search, "RoleAddAdmin"); - - m_roles = roles; - - getForm().addSubmissionListener - (new FormSecurityListener(CmsConstants.PRIVILEGE_ADMINISTER_ROLES)); - } - - - protected List makeQuery(PageState s) { - Assert.isTrue(m_roles.isSelected(s)); - - /* - Session session = SessionManager.getSession(); - - // XXX: Figure out how to use role directly here - DataQuery dq = - session.retrieveQuery("com.arsdigita.cms.roleAdminUserSearch"); - - BigDecimal roleId = new BigDecimal((String) m_roles.getSelectedKey(s)); - String searchQuery = (String) getSearchWidget().getValue(s); - - makeFilter(dq, roleId, searchQuery); - dq.addOrder("upper(lastName), upper(firstName), upper(email)");*/ - return new LinkedList<>(); - } - - /** - * Filters out members of the current group and users whose name or email - * address matches the search string. - */ - /* - private void makeFilter(DataQuery dq, BigDecimal roleId, String search) { - dq.setParameter("excludedRoleId", roleId); - - // Add the search filter if the search query is not null. - if ( search != null ) { - dq.clearFilter(); - Filter filter = dq.addFilter(NAME_FILTER); - filter.set("search", search); - } - }*/ - - public void process(FormSectionEvent event) throws FormProcessException { - FormData data = event.getFormData(); - PageState state = event.getPageState(); - Assert.isTrue(m_roles.isSelected(state)); - - String[] users = (String[]) data.get("users"); - /* - if ( users != null ) { - - BigDecimal roleId = - new BigDecimal((String) m_roles.getSelectedKey(state)); - - Role role = null; - try { - role = new Role(roleId); - } catch (DataObjectNotFoundException e) { - e.printStackTrace(); - throw new FormProcessException(e); - } - - Group group = role.getGroup(); - - // Add each checked user to the role - try { - User user; - for ( int i = 0; i < users.length; i++ ) { - - user = User.retrieve(new BigDecimal(users[i])); - - PermissionDescriptor perm = - new PermissionDescriptor(PrivilegeDescriptor.ADMIN, - group, - user); - - // double click protection - if ( !PermissionService.checkPermission(perm) ) { - PermissionService.grantPermission(perm); - } - } - role.save(); - - } catch (DataObjectNotFoundException e) { - e.printStackTrace(); - throw new FormProcessException(GlobalizationUtil.globalize("cms.ui.staff.cannot_add_user")); - } - - } else { - throw new FormProcessException(GlobalizationUtil.globalize( - "cms.ui.staff.no_users_were_selected")); - }*/ - - fireCompletionEvent(state); - } -} From 980f958bae5c60d78e168402929192a7b550625d Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 16 Mar 2022 19:51:52 +0100 Subject: [PATCH 11/63] Removed depcrecated package com/arsdigita/cms/ui/role from ccm-cms --- .../arsdigita/cms/ui/ContentSectionPage.java | 33 -- .../arsdigita/cms/ui/role/BaseRoleForm.java | 168 -------- .../cms/ui/role/BaseRoleItemPane.java | 273 ------------ .../cms/ui/role/MemberTableModelBuilder.java | 120 ------ .../arsdigita/cms/ui/role/RoleAddForm.java | 87 ---- .../arsdigita/cms/ui/role/RoleAdminPane.java | 215 ---------- .../cms/ui/role/RoleAdminPaneController.java | 402 ------------------ .../arsdigita/cms/ui/role/RoleEditForm.java | 115 ----- .../arsdigita/cms/ui/role/RoleListModel.java | 84 ---- .../cms/ui/role/RolePartyAddForm.java | 131 ------ .../cms/ui/role/RoleRequestLocal.java | 42 -- 11 files changed, 1670 deletions(-) delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/role/BaseRoleForm.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/role/BaseRoleItemPane.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/role/MemberTableModelBuilder.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleAddForm.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleAdminPane.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleAdminPaneController.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleEditForm.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleListModel.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RolePartyAddForm.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleRequestLocal.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java index c5a2875cf..9434d21b0 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java @@ -39,7 +39,6 @@ import com.arsdigita.cms.ui.category.CategoryAdminPane; import com.arsdigita.cms.ui.cse.ContentSoonExpiredPane; import com.arsdigita.cms.ui.folder.FolderAdminPane; import com.arsdigita.cms.ui.lifecycle.LifecycleAdminPane; -import com.arsdigita.cms.ui.role.RoleAdminPane; import com.arsdigita.cms.ui.workflow.WorkflowAdminPane; import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.toolbox.ui.LayoutPanel; @@ -134,8 +133,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener { private ItemSearch m_searchPane; - private RoleAdminPane m_rolePane; - private WorkflowAdminPane m_workflowPane; private LifecycleAdminPane m_lifecyclePane; @@ -160,7 +157,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener { m_folderPane = getFolderAdminPane(); m_browsePane = getBrowsePane(); m_searchPane = getSearchPane(); - m_rolePane = getRoleAdminPane(); m_workflowPane = getWorkflowAdminPane(); m_lifecyclePane = getLifecycleAdminPane(); m_categoryPane = getCategoryAdminPane(); @@ -205,11 +201,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener { permissionChecker.isPermitted( AdminPrivileges.ADMINISTER_LIFECYLES)); - m_tabbedPane.setTabVisible( - state, - m_rolePane, - permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_ROLES)); // csePane: should check permission m_tabbedPane.setTabVisible(state, m_csePane, true); // TODO Check for reportPane as well @@ -261,27 +252,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener { return m_searchPane; } -// protected AssetPane getAssetPane() { -// if (m_assetPane == null) { -// m_assetPane = new AssetPane(); -// } -// -// return m_assetPane; -// } -// ToDo NG -// protected ImagesPane getImagesPane() { -// if (m_imagesPane == null) { -// m_imagesPane = new ImagesPane(); -// } -// return m_imagesPane; -// } - protected RoleAdminPane getRoleAdminPane() { - if (m_rolePane == null) { - m_rolePane = new RoleAdminPane(); - } - return m_rolePane; - } - /** * Creates, and then caches, the workflow administration pane. Overriding * this method to return null will prevent this tab from appearing. @@ -365,11 +335,8 @@ public class ContentSectionPage extends CMSPage implements ActionListener { protected TabbedPane createTabbedPane() { final TabbedPane pane = new TabbedPane(); - //tab(pane, "cms.ui.folders", getFolderAdminPane()); tab(pane, "cms.ui.browse", getBrowsePane()); tab(pane, "cms.ui.search", getSearchPane()); -// ToDo NG replace with media tab tab(pane, "cms.ui.images", getImagesPane()); - tab(pane, "cms.ui.roles", getRoleAdminPane()); tab(pane, "cms.ui.workflows", getWorkflowAdminPane()); tab(pane, "cms.ui.lifecycles", getLifecycleAdminPane()); tab(pane, "cms.ui.categories", getCategoryAdminPane()); diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/BaseRoleForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/BaseRoleForm.java deleted file mode 100755 index 63d647634..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/BaseRoleForm.java +++ /dev/null @@ -1,168 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.role; - -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.ParameterEvent; -import com.arsdigita.bebop.event.ParameterListener; -import com.arsdigita.bebop.event.PrintEvent; -import com.arsdigita.bebop.event.PrintListener; -import com.arsdigita.bebop.form.CheckboxGroup; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.cms.CMS; -import com.arsdigita.cms.ui.BaseForm; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.ui.admin.GlobalizationUtil; -import com.arsdigita.util.UncheckedWrapperException; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.security.PermissionManager; -import org.libreccm.security.Role; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.privileges.AdminPrivileges; -import org.librecms.contentsection.privileges.AssetPrivileges; -import org.librecms.contentsection.privileges.ItemPrivileges; - -import java.util.ArrayList; -import java.util.List; -import java.util.TooManyListenersException; - -/** - * For more detailed information see {@link com.arsdigita.bebop.Form}. - * - * @author Yannick Bülter - * @author Justin Ross <jross@redhat.com> - * - */ -class BaseRoleForm extends BaseForm { - - private final Name roleName; - private final Description roleDescription; - private CheckboxGroup privileges; - - BaseRoleForm(final String key, - final GlobalizedMessage message) { - super(key, message); - - roleName = new Name("label", 200, true); - addField(gz("cms.ui.role.name"), roleName); - - roleDescription = new Description("description", 4000, false); - addField(gz("cms.ui.role.description"), roleDescription); - - privileges = new CheckboxGroup("privileges"); - addField(gz("cms.ui.role.privileges"), privileges); - - try { - privileges.addPrintListener(new PrivilegePrinter()); - } catch (TooManyListenersException tmle) { - throw new UncheckedWrapperException(tmle); - } - - addAction(new Finish()); - addAction(new Cancel()); - - addSecurityListener(AdminPrivileges.ADMINISTER_ROLES); - } - - protected Name getRoleName() { - return roleName; - } - - protected Description getRoleDescription() { - return roleDescription; - } - - protected CheckboxGroup getPrivileges() { - return privileges; - } - - private class PrivilegePrinter implements PrintListener { - - @Override - public final void prepare(final PrintEvent event) { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final PermissionManager permissionManager = cdiUtil.findBean( - PermissionManager.class); - - final CheckboxGroup target = (CheckboxGroup) event.getTarget(); - target.clearOptions(); - - final List adminPrivileges = permissionManager - .listDefiniedPrivileges(AdminPrivileges.class); - final List itemPrivileges = permissionManager - .listDefiniedPrivileges(ItemPrivileges.class); - final List assetPrivileges = permissionManager - .listDefiniedPrivileges(AssetPrivileges.class); - - final List possiblePrivileges = new ArrayList<>(); - possiblePrivileges.addAll(adminPrivileges); - possiblePrivileges.addAll(itemPrivileges); - possiblePrivileges.addAll(assetPrivileges); - - for (final String privilege : possiblePrivileges) { - target.addOption(new Option( - privilege, - new Label(new GlobalizedMessage(privilege, - CmsConstants.CMS_BUNDLE)))); - } - } - - } - - class NameUniqueListener implements ParameterListener { - - private final RoleRequestLocal roleRequestLocal; - - NameUniqueListener(final RoleRequestLocal role) { - roleRequestLocal = role; - } - - /** - * Validates that there are no duplicates between the names of roles. - */ - @Override - public final void validate(final ParameterEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - final String name = (String) roleName.getValue(state); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final RoleAdminPaneController controller = cdiUtil.findBean( - RoleAdminPaneController.class); - final Role selectedRole; - if (roleRequestLocal == null) { - selectedRole = null; - } else { - selectedRole = roleRequestLocal.getRole(state); - } - - if (!controller.validateRoleNameUniqueness(name, selectedRole)) { - throw new FormProcessException(GlobalizationUtil.globalize( - "cms.ui.role.name_not_unique")); - } - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/BaseRoleItemPane.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/BaseRoleItemPane.java deleted file mode 100755 index 856691fc7..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/BaseRoleItemPane.java +++ /dev/null @@ -1,273 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.role; - -import com.arsdigita.bebop.ActionLink; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SimpleContainer; -import com.arsdigita.bebop.SingleSelectionModel; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.event.TableActionAdapter; -import com.arsdigita.bebop.event.TableActionEvent; -import com.arsdigita.bebop.table.DefaultTableCellRenderer; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.bebop.table.TableColumnModel; -import com.arsdigita.cms.CMS; -import com.arsdigita.cms.ui.BaseItemPane; -import com.arsdigita.cms.ui.PartySearchForm; -import com.arsdigita.cms.ui.VisibilityComponent; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.toolbox.ui.ActionGroup; -import com.arsdigita.toolbox.ui.Property; -import com.arsdigita.toolbox.ui.PropertyList; -import com.arsdigita.toolbox.ui.Section; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.security.Party; -import org.libreccm.security.PartyRepository; -import org.libreccm.security.PermissionChecker; -import org.libreccm.security.Role; -import org.libreccm.security.RoleManager; -import org.librecms.CmsConstants; -import org.librecms.contentsection.privileges.AdminPrivileges; - -/** - * This pane is for showing the properties of a {@link Role}. That includes - * name, description, permissions and members. The last one is a list of - * {@link Party parties} to which the role corresponds to. - * - * NOTE: There was an AdminTable besides the MemberTable. Since this function - * was/is never used, it was deemed deprecated and was removed. - * - * - * @author Justin Ross <jross@redhat.com> - * @author Yannick Bülter - * @author Jens Pelzetter - */ -class BaseRoleItemPane extends BaseItemPane { - - private final RoleRequestLocal roleRequestLocal; - - private final MemberTable membersTable; - - BaseRoleItemPane(final SingleSelectionModel model, - final RoleRequestLocal role, - final ActionLink editLink, - final ActionLink deleteLink) { - roleRequestLocal = role; - - membersTable = new MemberTable(); - - final ActionLink memberAddLink = new ActionLink(new Label(gz( - "cms.ui.role.member.add"))); - - final SimpleContainer m_detailPane = new SimpleContainer(); - add(m_detailPane); - setDefault(m_detailPane); - - m_detailPane.add(new SummarySection(editLink, deleteLink)); - m_detailPane.add(new MemberSection(memberAddLink)); - - final PartySearchForm memberSearchForm = new PartySearchForm(); - add(memberSearchForm); - - final RolePartyAddForm memberAddForm = new RolePartyAddForm( - model, memberSearchForm.getSearchWidget()); - add(memberAddForm); - - connect(memberAddLink, memberSearchForm); - connect(memberSearchForm, memberAddForm); - memberAddForm.getForm().addSubmissionListener(new CancelListener( - memberAddForm.getForm())); - resume(memberAddForm.getForm(), m_detailPane); - } - - private class SummarySection extends Section { - - SummarySection(final ActionLink editLink, - final ActionLink deleteLink) { - setHeading(gz("cms.ui.role.details")); - - final ActionGroup group = new ActionGroup(); - setBody(group); - - group.setSubject(new Properties()); - group.addAction( - new VisibilityComponent(editLink, - AdminPrivileges.ADMINISTER_ROLES), - ActionGroup.DELETE); - group.addAction( - new VisibilityComponent(deleteLink, - AdminPrivileges.ADMINISTER_ROLES), - ActionGroup.DELETE); - } - - @SuppressWarnings("unchecked") - private class Properties extends PropertyList { - - @Override - protected final java.util.List properties( - final PageState state - ) { - - final java.util.List properties = super.properties( - state - ); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final RoleAdminPaneController controller = cdiUtil - .findBean(RoleAdminPaneController.class); - - final Role role = roleRequestLocal.getRole(state); - - properties.add( - new Property(lz("cms.ui.role.name"), role.getName()) - ); - - // Right now just loads the default locale description. - properties.add( - new Property( - lz("cms.ui.role.description"), - controller.getRoleDescription(role) - ) - ); - - // Since Permissions don't seem to have a "pretty" form, the - // granted privilege is used. - final String permissions = controller - .generateGrantedPermissionsString( - role, - CMS.getContext().getContentSection() - ); - - if (permissions.length() > 0) { - properties.add( - new Property( - lz("cms.ui.role.privileges"), - permissions - ) - ); - } else { - properties.add( - new Property( - lz("cms.ui.role.privileges"), - lz("cms.ui.role.privilege.none") - ) - ); - } - - return properties; - } - - } - - } - - private class MemberSection extends Section { - - MemberSection(final ActionLink memberAddLink) { - setHeading(gz("cms.ui.role.members")); - - final ActionGroup group = new ActionGroup(); - setBody(group); - - group.setSubject(membersTable); - group.addAction( - new VisibilityComponent(memberAddLink, - AdminPrivileges.ADMINISTER_ROLES), - ActionGroup.ADD); - } - - } - - private class MemberTable extends Table { - - private static final int COL_NAME = 0; - - private static final int COL_EMAIL = 1; - - private static final int COL_REMOVE = 2; - - MemberTable() { - super(); - - final TableColumnModel columnModel = getColumnModel(); - columnModel.add(new TableColumn( - COL_NAME, - new Label(new GlobalizedMessage("cms.ui.name", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_EMAIL, - new Label(new GlobalizedMessage("cms.ui.role.member.email", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_REMOVE, - new Label(new GlobalizedMessage("cms.ui.role.member.remove", - CmsConstants.CMS_BUNDLE)))); - - setEmptyView(new Label(gz("cms.ui.role.member.none"))); - - setModelBuilder(new MemberTableModelBuilder(roleRequestLocal)); - - getColumn(2).setCellRenderer(new DefaultTableCellRenderer(true)); - - addTableActionListener(new Listener()); - } - - private class Listener extends TableActionAdapter { - - @Override - public final void cellSelected(final TableActionEvent e) throws - FormProcessException { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final PageState state = e.getPageState(); - final PermissionChecker permissionChecker = cdiUtil.findBean( - PermissionChecker.class); - - if (!permissionChecker.isPermitted( - AdminPrivileges.ADMINISTER_ROLES)) { - throw new FormProcessException( - new GlobalizedMessage( - "cms.ui.role.insufficient_privileges", - CmsConstants.CMS_BUNDLE)); - } - - if (e.getColumn() == 2) { - final Role role = roleRequestLocal.getRole(state); - long itemId = Long.parseLong(e.getRowKey().toString()); - - final PartyRepository partyRepository = cdiUtil.findBean( - PartyRepository.class); - final RoleManager roleManager = cdiUtil.findBean( - RoleManager.class); - final Party party = partyRepository.findById(itemId).get(); - - roleManager.removeRoleFromParty(role, party); - - getRowSelectionModel().clearSelection(state); - } - } - - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/MemberTableModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/MemberTableModelBuilder.java deleted file mode 100755 index 7c912317c..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/MemberTableModelBuilder.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.role; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.table.AbstractTableModelBuilder; -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.ui.admin.GlobalizationUtil; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.security.Party; -import org.libreccm.security.PartyRepository; -import org.libreccm.security.Role; -import org.libreccm.security.RoleManager; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.stream.Collectors; - -/** - * Creates a table model based on the {@link Party parties} of the given - * {@link Role role}. - * - * @author Yannick Bülter - * @author Justin Ross <jross@redhat.com> - * @version $Id: MemberTableModelBuilder.java 287 2005-02-22 00:29:02Z sskracic - * $ - */ -class MemberTableModelBuilder extends AbstractTableModelBuilder { - - private final RoleRequestLocal roleRequestLocal; - - MemberTableModelBuilder(final RoleRequestLocal role) { - roleRequestLocal = role; - } - - @Override - public final TableModel makeModel(final Table table, - final PageState state) { - final Role role = roleRequestLocal.getRole(state); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final RoleAdminPaneController controller = cdiUtil.findBean( - RoleAdminPaneController.class); - final List members = controller.createRoleMemberList(role); - - return new Model(members); - } - - private static class Model implements TableModel { - - private Party m_party; - private final Collection m_parties; - private final Iterator iterator; - - Model(final Collection parties) { - m_parties = parties; - iterator = m_parties.iterator(); - } - - @Override - public final int getColumnCount() { - return 3; - } - - @Override - public final boolean nextRow() { - if (iterator.hasNext()) { - m_party = iterator.next(); - return true; - } else { - return false; - } - } - - @Override - public final Object getKeyAt(final int column) { - return m_party.getPartyId(); - } - - @Override - public final Object getElementAt(final int column) { - switch (column) { - case 0: - return m_party.getName(); - case 1: - return lz("cms.ui.none"); - case 2: - return lz("cms.ui.role.member.remove"); - default: - throw new IllegalStateException(); - } - } - - } - - protected static String lz(final String key) { - return (String) GlobalizationUtil.globalize(key).localize(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleAddForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleAddForm.java deleted file mode 100755 index 93751117e..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleAddForm.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.role; - -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SingleSelectionModel; -import com.arsdigita.bebop.event.FormProcessListener; -import com.arsdigita.bebop.event.FormSectionEvent; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.security.Role; - -/** - * Provides a {@link com.arsdigita.bebop.Form} for adding {@link Role roles}. - * - * - * @author Michael Pih - * @author Justin Ross <jross@redhat.com> - * @author Yannick Bülter - */ -final class RoleAddForm extends BaseRoleForm { - - private final SingleSelectionModel selectionModel; - - RoleAddForm(final SingleSelectionModel selectionModel) { - super("AddStaffRole", gz("cms.ui.role.add")); - - this.selectionModel = selectionModel; - - getRoleName().addValidationListener(new NameUniqueListener(null)); - - addProcessListener(new ProcessListener()); - } - - /** - * The {@link Role} gets saved to the database and permissions are granted - * as needed. - * - * NOTE: The part about granting and revoking privileges is mostly Copy & - * Paste from {@link RoleEditForm}. If you find any bugs or errors in this - * code, be sure to change it there accordingly. - */ - private class ProcessListener implements FormProcessListener { - - @Override - public final void process(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - final String roleName = (String) getRoleName().getValue(state); - final String roleDesc = (String) getRoleDescription() - .getValue(state); - final String[] selectedPrivileges = (String[]) getPrivileges() - .getValue(state); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final RoleAdminPaneController controller = cdiUtil.findBean( - RoleAdminPaneController.class); - - final Role role = controller.addRole(roleName, - roleDesc, - selectedPrivileges); - - selectionModel - .setSelectedKey(state, Long.toString(role.getRoleId())); - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleAdminPane.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleAdminPane.java deleted file mode 100755 index 95541f0e0..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleAdminPane.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.role; - -import com.arsdigita.bebop.ActionLink; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.List; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.ParameterSingleSelectionModel; -import com.arsdigita.bebop.SimpleContainer; -import com.arsdigita.bebop.SingleSelectionModel; -import com.arsdigita.bebop.event.ChangeEvent; -import com.arsdigita.bebop.event.ChangeListener; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.list.ListModel; -import com.arsdigita.bebop.list.ListModelBuilder; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.cms.CMS; -import com.arsdigita.cms.ui.BaseAdminPane; -import com.arsdigita.cms.ui.BaseDeleteForm; -import com.arsdigita.cms.ui.VisibilityComponent; -import com.arsdigita.toolbox.ui.ActionGroup; -import com.arsdigita.toolbox.ui.Section; -import com.arsdigita.util.LockableImpl; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.security.Role; -import org.libreccm.security.RoleRepository; -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.privileges.AdminPrivileges; - -/** - * Provides the logic to administer {@link Role roles}. - * - * NOTE: Prior, this class managed two {@link ListModelBuilder}. The reason - * being, that roles where differentiated between Viewer and Member groups. - * Since this is no longer the case, there exists only the - * {@link RoleListModelBuilder} now. - * - * - * @author Justin Ross <jross@redhat.com> - * @author Yannick Bülter - * @author Jens Pelzetter - * - */ -public class RoleAdminPane extends BaseAdminPane { - - private static final Logger LOGGER = LogManager.getLogger( - RoleAdminPane.class); - - private final SingleSelectionModel selectionModel; - - private final List rolesList; - - public RoleAdminPane() { - selectionModel = new ParameterSingleSelectionModel<>( - new StringParameter(List.SELECTED)); - setSelectionModel(selectionModel); - - selectionModel.addChangeListener(new SelectionListener()); - - RoleRequestLocal m_role = new SelectionRequestLocal(); - - rolesList = new List(new RoleListModelBuilder()); - rolesList.setSelectionModel(selectionModel); - - final SimpleContainer left = new SimpleContainer(); - setLeft(left); - - final RoleSection roleSection = new RoleSection(); - left.add(roleSection); - - setEdit(gz("cms.ui.role.edit"), new RoleEditForm(m_role)); - setDelete(gz("cms.ui.role.delete"), new DeleteForm()); - - setIntroPane(new Label(gz("cms.ui.role.intro"))); - setItemPane(new BaseRoleItemPane(selectionModel, m_role, - getEditLink(), getDeleteLink())); - } - - private class RoleSection extends Section { - - RoleSection() { - setHeading(gz("cms.ui.role.staff")); - - final ActionGroup group = new ActionGroup(); - setBody(group); - - group.setSubject(rolesList); - - final ActionLink link = new ActionLink(new Label(gz( - "cms.ui.role.staff.add"))); - - group.addAction( - new VisibilityComponent(link, - AdminPrivileges.ADMINISTER_ROLES), - ActionGroup.ADD); - - final RoleAddForm form = new RoleAddForm(selectionModel); - getBody().add(form); - getBody().connect(link, form); - } - - } - - private class SelectionListener implements ChangeListener { - - @Override - public final void stateChanged(final ChangeEvent event) { - LOGGER.debug("Selection state changed; I may change " - + "the body's visible pane"); - - final PageState state = event.getPageState(); - - getBody().reset(state); - - if (selectionModel.isSelected(state)) { - LOGGER.debug("The selection model is selected; displaying " - + "the item pane"); - - getBody().push(state, getItemPane()); - } - } - - } - - private class SelectionRequestLocal extends RoleRequestLocal { - - @Override - protected final Object initialValue(final PageState state) { - final Long id = Long.parseLong(selectionModel.getSelectedKey(state)); - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final RoleRepository roleRepository = cdiUtil.findBean( - RoleRepository.class); - - return roleRepository.findById(id); - } - - } - - /** - * This builder provides a list model of the {@link Role roles} which - * correspond to the {@link ContentSection} in this context. - */ - private static class RoleListModelBuilder extends LockableImpl implements - ListModelBuilder { - - RoleListModelBuilder() { - super(); - } - - @Override - public final ListModel makeModel(final List list, final PageState state) { - final ContentSection section = CMS.getContext().getContentSection(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final RoleAdminPaneController controller = cdiUtil - .findBean(RoleAdminPaneController.class); - final java.util.List roles = controller - .findRolesForContentSection(section); - - return new RoleListModel(roles); - } - - } - - /** - * Provides a simple delete form to remove a {@link Role}. - */ - private class DeleteForm extends BaseDeleteForm { - - DeleteForm() { - super(gz("cms.ui.role.delete_prompt")); - - addSecurityListener(AdminPrivileges.ADMINISTER_ROLES); - } - - @Override - public final void process(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final RoleAdminPaneController controller = cdiUtil.findBean( - RoleAdminPaneController.class); - - controller.deleteRole(CMS.getContext().getContentSection(), - selectionModel.getSelectedKey(state)); - - selectionModel.clearSelection(state); - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleAdminPaneController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleAdminPaneController.java deleted file mode 100644 index 2bd4000bb..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleAdminPaneController.java +++ /dev/null @@ -1,402 +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.role; - -import com.arsdigita.cms.CMS; -import com.arsdigita.kernel.KernelConfig; - -import org.libreccm.configuration.ConfigurationManager; -import org.libreccm.security.Party; -import org.libreccm.security.PartyRepository; -import org.libreccm.security.Permission; -import org.libreccm.security.PermissionManager; -import org.libreccm.security.Role; -import org.libreccm.security.RoleManager; -import org.libreccm.security.RoleRepository; -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.ContentSectionManager; -import org.librecms.contentsection.ContentSectionRepository; -import org.librecms.contentsection.Folder; -import org.librecms.contentsection.privileges.AdminPrivileges; -import org.librecms.contentsection.privileges.AssetPrivileges; -import org.librecms.contentsection.privileges.ItemPrivileges; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Locale; -import java.util.stream.Collectors; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.transaction.Transactional; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -class RoleAdminPaneController { - - @Inject - private ConfigurationManager confManager; - - @Inject - private PartyRepository partyRepo; - - @Inject - private PermissionManager permissionManager; - - @Inject - private RoleManager roleManager; - - @Inject - private RoleRepository roleRepo; - - @Inject - private ContentSectionManager sectionManager; - - @Inject - private ContentSectionRepository sectionRepo; - - @Transactional(Transactional.TxType.REQUIRED) - public List findRolesForContentSection(final ContentSection section) { - final ContentSection contentSection = sectionRepo - .findById(section.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No ContentSection with id %d in the database. " - + "Where did that ID come from?", - section.getObjectId()))); - - return new ArrayList<>(contentSection.getRoles()); - } - - @Transactional - public String getRoleDescription(final Role ofRole) { - final Role role = roleRepo - .findById(ofRole.getRoleId()) - .orElseThrow( - () -> new IllegalArgumentException( - String.format( - "No role with ID %d found.", ofRole.getRoleId() - ) - ) - ); - final KernelConfig config = confManager - .findConfiguration(KernelConfig.class); - return role.getDescription().getValue(config.getDefaultLocale()); - } - - public String[] getGrantedPrivileges(final Role role, - final ContentSection section) { - final List sectionPermissions = permissionManager - .findPermissionsForRoleAndObject(role, section); - final List itemPermissions = permissionManager - .findPermissionsForRoleAndObject(role, - section.getRootDocumentsFolder()); - final List assetPermissions = permissionManager - .findPermissionsForRoleAndObject(role, - section.getRootAssetsFolder()); - final List permissions = new ArrayList<>(); - permissions.addAll(sectionPermissions); - permissions.addAll(itemPermissions); - permissions.addAll(assetPermissions); - final List privileges = permissions.stream() - .map(Permission::getGrantedPrivilege) - .collect(Collectors.toList()); - - return privileges.toArray(new String[]{}); - } - - @Transactional(Transactional.TxType.REQUIRED) - public String generateGrantedPermissionsString(final Role role, - final ContentSection section) { - - final List sectionPermissions = permissionManager - .findPermissionsForRoleAndObject(role, section); - final List itemPermissions = permissionManager - .findPermissionsForRoleAndObject(role, - section.getRootDocumentsFolder()); - final List assetPermissions = permissionManager - .findPermissionsForRoleAndObject(role, - section.getRootAssetsFolder()); - final List permissions = new ArrayList<>(); - permissions.addAll(sectionPermissions); - permissions.addAll(itemPermissions); - permissions.addAll(assetPermissions); - - return permissions.stream() - .map(Permission::getGrantedPrivilege) - .collect(Collectors.joining("; ")); - - } - - @Transactional(Transactional.TxType.REQUIRED) - public List createRoleMemberList(final Role role) { - - final Role theRole = roleRepo - .findById(role.getRoleId()) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No role with ID %d in the database. Where did that Id come from?", - role.getRoleId()))); - - return theRole.getMemberships() - .stream() - .map(membership -> membership.getMember()) - .sorted((member1, member2) -> { - return member1.getName().compareTo(member2.getName()); - }) - .collect(Collectors.toList()); - } - - @Transactional(Transactional.TxType.REQUIRED) - public void deleteRole(final ContentSection section, - final String roleId) { - - final Role role = roleRepo.findById(Long.parseLong(roleId)) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No Role with ID %s in the database. Where did that ID come from?", - roleId))); - final ContentSection contentSection = sectionRepo - .findById(section.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No ContentSection with ID %d in the database. " - + "Where did that ID come from?", - section.getObjectId()))); - - sectionManager.removeRoleFromContentSection(contentSection, role); - roleRepo.delete(role); - } - - /** - * - * @param name - * @param selectedRole - * - * @return {@code true} if name is unique, {@code false} otherwise. - */ - @Transactional(Transactional.TxType.REQUIRED) - public boolean validateRoleNameUniqueness(final String name, - final Role selectedRole) { - - final ContentSection section = CMS.getContext().getContentSection(); - - final ContentSection contentSection = sectionRepo - .findById(section.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No ContentSection with ID %d in the database." - + " Where did that ID come from?", - section.getObjectId()))); - - final Collection roles = contentSection.getRoles(); - boolean result = true; - for (final Role role : roles) { - if (role.getName().equalsIgnoreCase(name) - && (selectedRole == null - || selectedRole.getRoleId() != role.getRoleId())) { - result = false; - break; - } - } - - return result; - } - - public void saveRole(final Role role, - final String roleName, - final String roleDescription, - final String[] selectedPermissions) { - - final Role roleToSave = roleRepo.findById(role.getRoleId()) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No Role with ID %d in the database. Where did that ID come from?", - role.getRoleId()))); - - final KernelConfig kernelConfig = confManager.findConfiguration( - KernelConfig.class); - final Locale defaultLocale = kernelConfig.getDefaultLocale(); - - roleToSave.setName(roleName); - roleToSave.getDescription().putValue(defaultLocale, roleDescription); - - roleRepo.save(roleToSave); - - final ContentSection contentSection = sectionRepo.findById( - CMS.getContext().getContentSection().getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No ContentSection with ID %d in the database." - + "Where did that ID come from?", - CMS.getContext().getContentSection().getObjectId()))); - - final List adminPrivileges = permissionManager - .listDefiniedPrivileges(AdminPrivileges.class); - final List itemPrivileges = permissionManager - .listDefiniedPrivileges(ItemPrivileges.class); - final List assetPrivileges = permissionManager - .listDefiniedPrivileges(AssetPrivileges.class); - - final Folder rootDocumentsFolder = contentSection - .getRootDocumentsFolder(); - final Folder rootAssetsFolder = contentSection.getRootAssetsFolder(); - - final List currentPermissionsSection = permissionManager - .findPermissionsForRoleAndObject(roleToSave, contentSection); - final List currentPermissionsDocuments = permissionManager - .findPermissionsForRoleAndObject(roleToSave, rootDocumentsFolder); - final List currentPermissionsAssets = permissionManager - .findPermissionsForRoleAndObject(roleToSave, rootAssetsFolder); - - //Revoke permissions not in selectedPermissions - revokeNotSelectedPrivileges(selectedPermissions, - roleToSave, - currentPermissionsSection); - revokeNotSelectedPrivileges(selectedPermissions, - roleToSave, - currentPermissionsDocuments); - revokeNotSelectedPrivileges(selectedPermissions, - roleToSave, - currentPermissionsAssets); - - // Grant selected privileges - for (final String privilege : adminPrivileges) { - if (isPrivilegeSelected(selectedPermissions, privilege)) { - permissionManager.grantPrivilege(privilege, - roleToSave, - contentSection); - } - } - - for (final String privilege : itemPrivileges) { - if (isPrivilegeSelected(selectedPermissions, privilege)) { - permissionManager.grantPrivilege(privilege, - roleToSave, - rootDocumentsFolder); - } - } - - for (final String privilege : assetPrivileges) { - if (isPrivilegeSelected(selectedPermissions, privilege)) { - permissionManager.grantPrivilege(privilege, - roleToSave, - rootAssetsFolder); - } - } - } - - private void revokeNotSelectedPrivileges(final String[] selectedPrivileges, - final Role role, - final List permissions) { - for (final Permission permission : permissions) { - if (!isPrivilegeSelected(selectedPrivileges, - permission.getGrantedPrivilege())) { - permissionManager.revokePrivilege( - permission.getGrantedPrivilege(), - role, - permission.getObject()); - } - } - } - - private boolean isPrivilegeSelected( - final String[] selectedPrivileges, final String privilege) { - - return Arrays.stream(selectedPrivileges) - .anyMatch(current -> current.equals(privilege)); - - } - - @Transactional(Transactional.TxType.REQUIRED) - public Role addRole(final String name, - final String description, - final String[] selectedPrivileges) { - - final KernelConfig kernelConfig = confManager.findConfiguration( - KernelConfig.class); - final Locale defaultLocale = kernelConfig.getDefaultLocale(); - - final Role role = new Role(); - role.setName(name); - role.getDescription().putValue(defaultLocale, description); - - roleRepo.save(role); - - final List adminPrivileges = permissionManager - .listDefiniedPrivileges(AdminPrivileges.class); - final List itemPrivileges = permissionManager - .listDefiniedPrivileges(ItemPrivileges.class); - final List assetPrivileges = permissionManager - .listDefiniedPrivileges(AssetPrivileges.class); - - final ContentSection contentSection = sectionRepo.findById( - CMS.getContext().getContentSection().getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String.format( - "No ContentSection with ID %d in the database." - + "Where did that ID come from?", - CMS.getContext().getContentSection().getObjectId()))); - sectionManager.addRoleToContentSection(role, contentSection); - final Folder rootDocumentsFolder = contentSection - .getRootDocumentsFolder(); - final Folder rootAssetsFolder = contentSection.getRootAssetsFolder(); - - for (final String privilege : adminPrivileges) { - if (isPrivilegeSelected(selectedPrivileges, privilege)) { - permissionManager.grantPrivilege(privilege, - role, - contentSection); - } - } - - for (final String privilege : itemPrivileges) { - if (isPrivilegeSelected(selectedPrivileges, privilege)) { - permissionManager.grantPrivilege(privilege, - role, - rootDocumentsFolder); - } - } - - for (final String privilege : assetPrivileges) { - if (isPrivilegeSelected(selectedPrivileges, privilege)) { - permissionManager.grantPrivilege(privilege, - role, - rootAssetsFolder); - } - } - - return role; - } - - @Transactional(Transactional.TxType.REQUIRED) - public void assignRoleToParty(final long roleId, final long partyId) { - - final Role role = roleRepo - .findById(roleId) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No role with ID %d in the database.", - roleId))); - final Party party = partyRepo - .findById(partyId) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No party with ID %d in the database.", - partyId))); - - roleManager.assignRoleToParty(role, party); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleEditForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleEditForm.java deleted file mode 100755 index db0fd80fc..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleEditForm.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.role; - -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.cms.CMS; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.security.PermissionManager; -import org.libreccm.security.Role; - -/** - * Represents a {@link com.arsdigita.bebop.Form Form} to edit - * {@link Role roles}. - * - * - * @author Michael Pih - * @author Justin Ross <jross@redhat.com> - * @author Yannick Bülter - * @author Jens Pelzetter - */ -final class RoleEditForm extends BaseRoleForm { - - private final RoleRequestLocal roleRequestLocal; - - RoleEditForm(final RoleRequestLocal role) { - super("EditStaffRole", gz("cms.ui.role.edit")); - - roleRequestLocal = role; - - getRoleName().addValidationListener(new NameUniqueListener( - roleRequestLocal)); - - addInitListener(new InitListener()); - addProcessListener(new ProcessListener()); - } - - /** - * Sets the initial values of a {@link Role} which were received from the - * database. - */ - private class InitListener implements FormInitListener { - - @Override - public final void init(final FormSectionEvent event) { - final PageState state = event.getPageState(); - final Role role = roleRequestLocal.getRole(state); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final RoleAdminPaneController controller = cdiUtil.findBean( - RoleAdminPaneController.class); - - getRoleName().setValue(state, role.getName()); - getRoleDescription().setValue( - state, - controller.getRoleDescription(role) - ); - - final String[] permissions = controller.getGrantedPrivileges( - role, CMS.getContext().getContentSection()); - - getPrivileges().setValue(state, permissions); - } - - } - - /** - * Updates a role and it's permissions. It uses the - * {@link PermissionManager} to grant and revoke permissions as needed. - * - */ - private class ProcessListener implements FormProcessListener { - - @Override - public final void process(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - final String roleName = (String) getRoleName().getValue(state); - final String roleDesc = (String) getRoleDescription() - .getValue(state); - final String[] selectedPermissions = (String[]) getPrivileges() - .getValue(state); - final Role role = roleRequestLocal.getRole(state); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final RoleAdminPaneController controller = cdiUtil.findBean( - RoleAdminPaneController.class); - - controller.saveRole(role, roleName, roleDesc, selectedPermissions); - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleListModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleListModel.java deleted file mode 100755 index 8d99874d8..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleListModel.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.role; - -import com.arsdigita.bebop.list.ListModel; - -import org.libreccm.security.Role; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -/** - * Provides a {@link ListModel} implementation for Collections of Roles. This - * class is usable like an iterator, with an exception. The {@link #next()} - * method only moves the iterator forward. To get elements you need to first use - * {@link #next()} and afterwards {@link #getRole()}, {@link #getElement()} or - * {@link #getKey()}. - * - * Also remember that the iterator does not move unless {@link #next()} is - * called. - * - * @author Yannick Bülter - */ -class RoleListModel implements ListModel { - - private final List m_roles; - private Iterator iterator; - private Role currentRole; - - RoleListModel(final List roles) { - m_roles = roles; - iterator = roles.iterator(); - } - - @Override - public final boolean next() { - if (iterator.hasNext()) { - currentRole = iterator.next(); - return true; - } else { - return false; - } - } - - @Override - public final Object getElement() { - return currentRole.getName(); - } - - @Override - public final String getKey() { - return Long.toString(currentRole.getRoleId()); - } - - public final boolean isEmpty() { - return m_roles.isEmpty(); - } - - public final Role getRole() { - return currentRole; - } - - public final void reset() { - iterator = m_roles.iterator(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RolePartyAddForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RolePartyAddForm.java deleted file mode 100755 index 372445bdf..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RolePartyAddForm.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.role; - -import com.arsdigita.bebop.FormData; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.SingleSelectionModel; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.cms.ui.FormSecurityListener; -import com.arsdigita.cms.ui.PartyAddForm; -import com.arsdigita.ui.admin.GlobalizationUtil; -import com.arsdigita.util.Assert; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.libreccm.cdi.utils.CdiUtil; - -import org.libreccm.security.Party; -import org.libreccm.security.PartyRepository; -import org.libreccm.security.Role; -import org.libreccm.security.RoleManager; -import org.libreccm.security.RoleRepository; -import org.libreccm.security.User; -import org.librecms.contentsection.privileges.AdminPrivileges; - -import java.util.Arrays; -import java.util.List; - -/** - * Adds a form which can add {@link Party parties} to {@link Role roles}. Also - * enables searching for parties. - * - * NOTE: In earlier versions it was also possible to filter parties using - * {@link User} attributes such as username, name, last name, etc. This feature - * may be added later if still needed. - * - * - * @author Michael Pih - * @author Uday Mathur - * @author Yannick Bülter - */ -class RolePartyAddForm extends PartyAddForm { - - private static final Logger LOGGER = LogManager - .getLogger(RolePartyAddForm.class); - - private final SingleSelectionModel roleSelectionModel; - - RolePartyAddForm(final SingleSelectionModel roleSelectionModel, - final TextField search) { - - super(search); - - this.roleSelectionModel = roleSelectionModel; - - super - .getForm() - .addSubmissionListener( - new FormSecurityListener(AdminPrivileges.ADMINISTER_ROLES)); - } - - @Override - protected List makeQuery(final PageState state) { - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final PartyRepository partyRepository = cdiUtil.findBean( - PartyRepository.class); - - final String searchQuery = (String) getSearchWidget().getValue(state); - - return partyRepository.searchByName(searchQuery); - } - - @Override - public void process(FormSectionEvent event) throws FormProcessException { - - final FormData data = event.getFormData(); - final PageState state = event.getPageState(); - - final String[] parties = (String[]) data.get("parties"); - LOGGER.debug("PARTIES = " + Arrays.toString(parties)); - if (parties == null) { - throw new FormProcessException(GlobalizationUtil.globalize( - "cms.ui.role.no_party_selected")); - } - - final Long roleId = Long - .parseLong(roleSelectionModel.getSelectedKey(state)); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); -// final RoleRepository roleRepository = cdiUtil.findBean( -// RoleRepository.class); -// final PartyRepository partyRepository = cdiUtil.findBean( -// PartyRepository.class); -// final RoleManager roleManager = cdiUtil.findBean(RoleManager.class); - final RoleAdminPaneController controller = cdiUtil - .findBean(RoleAdminPaneController.class); - -// final Role role = roleRepository.findById(roleId).get(); - - // Add each checked party to the role -// Party party; - for (int i = 0; i < parties.length; i++) { - if (LOGGER.isDebugEnabled()) { - LOGGER.debug("parties[" + i + "] = " + parties[i]); - } -// party = partyRepository.findById(Long.parseLong(parties[i])).get(); -// roleManager.assignRoleToParty(role, party); - controller.assignRoleToParty(roleId, Long.parseLong(parties[i])); - } - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleRequestLocal.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleRequestLocal.java deleted file mode 100755 index 6b1f06e0c..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/role/RoleRequestLocal.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.role; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.RequestLocal; - -import org.libreccm.security.Role; - -import java.util.Optional; - -/** - * See {@link RequestLocal} for more information. - * - * @author Yannick Bülter - */ -abstract class RoleRequestLocal extends RequestLocal { - - final Role getRole(final PageState state) { - @SuppressWarnings("unchecked") - final Optional role = (Optional) get(state); - - return role.get(); - } - -} From 7e3b0821bbe9cfdf7e5b495aee12852386c3e9ea Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 16 Mar 2022 19:54:09 +0100 Subject: [PATCH 12/63] Removed depcrecated package com/arsdigita/cms/ui from ccm-cms --- .../com/arsdigita/cms/ui/ContentItemPage.java | 40 +- .../ui/revision/ItemRevisionAdminPane.java | 361 ------------------ .../cms/ui/revision/RevisionRequestLocal.java | 33 -- .../revision/RevisionTableModelBuilder.java | 164 -------- 4 files changed, 28 insertions(+), 570 deletions(-) delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/revision/ItemRevisionAdminPane.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/revision/RevisionRequestLocal.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/revision/RevisionTableModelBuilder.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java index 34a3fcb53..679ce5f0c 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java @@ -46,7 +46,6 @@ import com.arsdigita.cms.ui.item.CustomizedPreviewLink; import com.arsdigita.cms.ui.item.ItemLanguages; import com.arsdigita.cms.ui.item.Summary; import com.arsdigita.cms.ui.lifecycle.ItemLifecycleAdminPane; -import com.arsdigita.cms.ui.revision.ItemRevisionAdminPane; import com.arsdigita.cms.ui.workflow.ItemWorkflowAdminPane; import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.kernel.KernelConfig; @@ -91,36 +90,45 @@ public class ContentItemPage extends CMSPage implements ActionListener { */ private static final Logger LOGGER = LogManager.getLogger( ContentItemPage.class); + /** * The URL parameter that must be passed in in order to set the current tab. * This is a KLUDGE right now because the TabbedDialog's current tab is * selected with a local state parameter */ public static final String SET_TAB = "set_tab"; + /** * The name of the global state parameter that holds the item id. */ public static final String ITEM_ID = "item_id"; + /** * The name of th global state parameter that holds the selected language. */ public static final String SELECTED_LANGUAGE = "selected_language"; + /** * The name of the global state parameter which holds the return URL. */ public static final String RETURN_URL = "return_url"; + /** * The name of the global state parameter that determines whether or not to * use the streamlined authoring process (assuming the option is turned on). * */ public static final String STREAMLINED_CREATION = "streamlined_creation"; + public static final String STREAMLINED_CREATION_ACTIVE = "active"; + public static final String STREAMLINED_CREATION_INACTIVE = "active"; + /** * Index of the summary tab */ public static final int SUMMARY_TAB = 0; + /** *

* The name of the state parameter which indicates the content type of the @@ -131,26 +139,42 @@ public class ContentItemPage extends CMSPage implements ActionListener { * content type.

*/ public static final String CONTENT_TYPE = "content_type"; + public static final int AUTHORING_TAB = 1; + public static final int LANGUAGE_TAB = 2; + public static final int WORKFLOW_TAB = 3; + public static final int PUBLISHING_TAB = 4; + public static final int HISTORY_TAB = 5; + public static final int TEMPLATES_TAB = 6; private final TabbedPane tabbedPane; + private final StringParameter returnUrlParameter; + private final ItemSelectionModel itemSelectionModel; // private final SingleSelectionModel selectedLanguageModel; + private final ACSObjectSelectionModel typeSelectionModel; + private final ContentItemRequestLocal itemRequestLocal; + private final Summary summaryPane; + private final ItemWorkflowAdminPane workflowPane; + private final ItemLifecycleAdminPane lifecyclePane; + private final WizardSelector wizardPane; + private final ItemLanguages languagesPane; - private final ItemRevisionAdminPane revisionsPane; + private final Link previewLink; + private final GlobalNavigation globalNavigation; private final StringParameter selectedLanguageParam; @@ -263,18 +287,14 @@ public class ContentItemPage extends CMSPage implements ActionListener { globalNavigation = new GlobalNavigation(); add(globalNavigation); - - // Create panels. summaryPane = new Summary(itemSelectionModel); wizardPane = new WizardSelector(itemSelectionModel, typeSelectionModel); languagesPane = new ItemLanguages(itemSelectionModel, -// selectedLanguageModel, + // selectedLanguageModel, selectedLanguageParam); workflowPane = new ItemWorkflowAdminPane(itemId); // Make this use m_item XXX lifecyclePane = new ItemLifecycleAdminPane(itemRequestLocal); - revisionsPane = new ItemRevisionAdminPane(itemRequestLocal); -// templatesPane = new ItemTemplates(itemSelectionModel); // Create tabbed pane. tabbedPane = new TabbedPane(); @@ -291,10 +311,6 @@ public class ContentItemPage extends CMSPage implements ActionListener { workflowPane); tabbedPane.addTab(new Label(gz("cms.ui.item.lifecycles")), lifecyclePane); - tabbedPane.addTab(new Label(gz("cms.ui.item.history")), - revisionsPane); -// tabbedPane.addTab(new Label(gz("cms.ui.item.templates")), -// templatesPane); tabbedPane.addActionListener(new ActionListener() { @@ -538,7 +554,7 @@ public class ContentItemPage extends CMSPage implements ActionListener { */ public static String getItemURL(final ContentItem item, final int tab) { - + final ContentSection section = item.getContentType().getContentSection(); if (section == null) { diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/revision/ItemRevisionAdminPane.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/revision/ItemRevisionAdminPane.java deleted file mode 100755 index 27148b839..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/revision/ItemRevisionAdminPane.java +++ /dev/null @@ -1,361 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.revision; - -import com.arsdigita.bebop.ActionLink; -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.ControlLink; -import com.arsdigita.bebop.Form; -import com.arsdigita.bebop.GridPanel; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.Link; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.Text; -import com.arsdigita.bebop.event.TableActionAdapter; -import com.arsdigita.bebop.event.TableActionEvent; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.form.RadioGroup; -import com.arsdigita.bebop.form.Submit; -import com.arsdigita.bebop.table.DefaultTableCellRenderer; -import com.arsdigita.bebop.table.DefaultTableColumnModel; -import com.arsdigita.bebop.table.TableCellRenderer; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.bebop.table.TableColumnModel; - -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ContentSection; - -import com.arsdigita.cms.dispatcher.CMSDispatcher; -import com.arsdigita.cms.ui.BaseItemPane; -import com.arsdigita.cms.ui.item.ContentItemRequestLocal; -import com.arsdigita.toolbox.ui.ActionGroup; -import com.arsdigita.toolbox.ui.LayoutPanel; -import com.arsdigita.toolbox.ui.NullComponent; -import com.arsdigita.toolbox.ui.Section; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.contentsection.ContentSectionManager; -import org.librecms.dispatcher.ItemResolver; - -import java.math.BigInteger; - -/** - * Displays the revision history of a {@link ContentItem} - * - * @author unknown - * @author Jens Pelzetter - * - */ -public final class ItemRevisionAdminPane extends BaseItemPane { - - private final ContentItemRequestLocal itemRequestLocal; - - private final RevisionTable revisionsTable; - - private final RevisionRequestLocal fromRequestLocal; - private final RevisionRequestLocal toRequestLocal; - - private final LayoutPanel selectPane; - //ToDo - //private final DifferencePane diffPane; - - public ItemRevisionAdminPane(final ContentItemRequestLocal itemRequestLocal) { - this.itemRequestLocal = itemRequestLocal; - - final RadioGroup fromSelect = new RadioGroup("from"); - final RadioGroup toSelect = new RadioGroup("to"); - - fromRequestLocal = new SelectionRequestLocal(fromSelect); - toRequestLocal = new SelectionRequestLocal(toSelect); - - revisionsTable = new RevisionTable(fromSelect, toSelect); - - final RevisionForm form = new RevisionForm(fromSelect, toSelect, - revisionsTable); - - selectPane = new LayoutPanel(); - add(selectPane); - setDefault(selectPane); - - selectPane.setBody(new Section(gz("cms.ui.item.revisions"), form)); - - final ActionLink returnLink = new ActionLink(new Label(gz( - "cms.ui.item.revision.return"))); - -// Todo -// diffPane = new DifferencePane(itemRequestLocal, -// fromRequestLocal, -// toRequestLocal, -// returnLink); -// add(diffPane); -// -// connect(form, diffPane); - connect(returnLink, selectPane); - } - - private class SelectionRequestLocal extends RevisionRequestLocal { - - private final RadioGroup group; - - SelectionRequestLocal(final RadioGroup group) { - this.group = group; - } - - @Override - protected final Object initialValue(final PageState state) { - final Object selected = group.getValue(state); - - if (selected == null || selected.toString().equals("")) { - return null; - } else { - final long revisionNumber = Long.parseLong(selected.toString()); - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentItemRepository itemRepository = cdiUtil.findBean( - ContentItemRepository.class); - return itemRepository.retrieveRevision(revisionNumber); - } - } - - } - - private class RevisionForm extends Form { - - RevisionForm(final RadioGroup fromSelect, - final RadioGroup toSelect, - final RevisionTable revisions) { - super("revisions", new GridPanel(1)); - - setMethod("get"); - - add(fromSelect); - add(toSelect); - - // Sets the 'to' revision to the dummy current revision - // and the 'from' revision to the dummy root revision. - fromSelect.setOptionSelected(""); - toSelect.setOptionSelected(""); - - final ActionGroup group = new ActionGroup(); - add(group); - - group.setSubject(revisions); - - group.addAction(new Submit("diff", - gz("cms.ui.item.revision.difference.show"))); - } - - } - - private class RevisionTable extends Table { - // XXX Need to fix the static l18n stuff - - private final TableColumn fromCol = new TableColumn( - RevisionTableModelBuilder.FROM, lz("cms.ui.item.revision.from")); - private final TableColumn toCol = new TableColumn( - RevisionTableModelBuilder.TO, - lz("cms.ui.item.revision.to")); - private final TableColumn timestampCol = new TableColumn( - RevisionTableModelBuilder.TIMESTAMP, lz("cms.ui.item.revision")); - private final TableColumn userCol = new TableColumn( - RevisionTableModelBuilder.USER, lz("cms.ui.user")); - private final TableColumn descriptionCol = new TableColumn( - RevisionTableModelBuilder.DESCRIPTION, lz("cms.ui.description")); - private final TableColumn previewCol = new TableColumn( - RevisionTableModelBuilder.PREVIEW, lz("cms.ui.item.revision.view")); - private final TableColumn rollbackCol = new TableColumn( - RevisionTableModelBuilder.ROLLBACK, - lz("cms.ui.item.revision.rollback")); - - public RevisionTable(final RadioGroup fromSelect, - final RadioGroup toSelect) { - super(new RevisionTableModelBuilder(itemRequestLocal), - new DefaultTableColumnModel()); - - final TableColumnModel columns = getColumnModel(); - columns.add(fromCol); - columns.add(toCol); - columns.add(timestampCol); - columns.add(userCol); - columns.add(descriptionCol); - columns.add(previewCol); - columns.add(rollbackCol); - - fromCol.setCellRenderer(new RadioCellRenderer(fromSelect)); - toCol.setCellRenderer(new RadioCellRenderer(toSelect)); - timestampCol.setCellRenderer(new DefaultTableCellRenderer(false)); - userCol.setCellRenderer(new DefaultTableCellRenderer(false)); - descriptionCol.setCellRenderer(new DefaultTableCellRenderer(false)); - previewCol.setCellRenderer(new ViewCellRenderer()); - rollbackCol.setCellRenderer(new RollbackCellRenderer()); - - setEmptyView(new Label(gz("cms.ui.item.revision.none"))); - - addTableActionListener(new RollbackActionListener()); - } - - class RadioCellRenderer implements TableCellRenderer { - - private final RadioGroup group; - - RadioCellRenderer(final RadioGroup group) { - this.group = group; - } - - @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) { - switch (key.toString()) { - case "first": - if (column == RevisionTableModelBuilder.FROM) { - return new NullComponent(); - } else { - final Option option = new Option("", new Text("")); - - option.setGroup(group); - - return option; - } - case "last": - if (column == RevisionTableModelBuilder.FROM) { - final Option option = new Option("", ""); - - option.setGroup(group); - - return option; - } else { - return new NullComponent(); - } - default: - final Option option = new Option(key.toString(), - new Text("")); - - option.setGroup(group); - - return option; - } - } - - } - - class ViewCellRenderer implements TableCellRenderer { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - if (key instanceof String) { - return new NullComponent(); - } else { - final BigInteger transID = (BigInteger) key; - final ContentItem item = itemRequestLocal.getContentItem( - state); - final ContentSection section = item.getContentType() - .getContentSection(); - - final ContentSectionManager sectionManager = CdiUtil - .createCdiUtil().findBean(ContentSectionManager.class); - final ItemResolver itemResolver = sectionManager - .getItemResolver(section); - - final StringBuffer url = new StringBuffer(itemResolver - .generateItemURL(state, item, section, - CMSDispatcher.PREVIEW)); - - // Cheesy code should be fixed - final String sep; - if (url.toString().indexOf('?') == -1) { - sep = "?"; - } else { - sep = "&"; - } - - // TODO: fix this - //url.append(sep).append - // (HistoryCollection.TRANS_ID).append("="); - url.append(sep).append("transID").append("="); - url.append(transID.toString()); - - final Link link = new Link(new Label(gz( - "cms.ui.item.revision.view")), - url.toString()); - - link.setTargetFrame(lz("cms.ui.item.revision.view")); - - return link; - } - } - - } - - class RollbackActionListener extends TableActionAdapter { - - @Override - public final void cellSelected(final TableActionEvent event) { - final PageState state = event.getPageState(); - - if (event.getColumn() == RevisionTableModelBuilder.ROLLBACK) { - final ContentItem item = itemRequestLocal.getContentItem( - state); - - //Rollback not supported yet - -// Versions.rollback(item.getOID(), -// new BigInteger(event.getRowKey() -// .toString())); -// -// item.applyTag(lz("cms.ui.item.revision.rolled_back")); - } - } - - } - - class RollbackCellRenderer implements TableCellRenderer { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - if (key instanceof String) { - return new NullComponent(); - } else { - return new ControlLink(new Label(gz( - "cms.ui.item.revision.rollback"))); - } - } - - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/revision/RevisionRequestLocal.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/revision/RevisionRequestLocal.java deleted file mode 100755 index e5806e310..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/revision/RevisionRequestLocal.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.revision; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.RequestLocal; - -import org.libreccm.auditing.CcmRevision; - -public abstract class RevisionRequestLocal extends RequestLocal { - - public final CcmRevision getRevision(final PageState state) { - final CcmRevision revision = (CcmRevision) get(state); - - return revision; - } -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/revision/RevisionTableModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/revision/RevisionTableModelBuilder.java deleted file mode 100755 index e0df62508..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/revision/RevisionTableModelBuilder.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (C) 2003-2004 Red Hat Inc. All Rights Reserved. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -package com.arsdigita.cms.ui.revision; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.table.AbstractTableModelBuilder; -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.cms.ui.item.ContentItemRequestLocal; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.security.User; - -import com.arsdigita.toolbox.ui.FormatStandards; - -import org.libreccm.auditing.CcmRevision; -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ContentItemRepository; - -import java.util.List; - -/** - * @author Stanislav Freidin <sfreidin@redhat.com> - * @author Justin Ross <jross@redhat.com> - * @version $Id: RevisionTableModelBuilder.java 1942 2009-05-29 07:53:23Z terry - * $ - */ -class RevisionTableModelBuilder extends AbstractTableModelBuilder { - - static final int FROM = 0; - static final int TO = 1; - static final int TIMESTAMP = 2; - static final int USER = 3; - static final int DESCRIPTION = 4; - static final int PREVIEW = 5; - static final int ROLLBACK = 6; - - static final int COLUMNS = 7; - - private final ContentItemRequestLocal itemRequestLocal; - - RevisionTableModelBuilder(final ContentItemRequestLocal itemRequestLocal) { - this.itemRequestLocal = itemRequestLocal; - } - - @Override - public final TableModel makeModel(final Table table, - final PageState state) { - return new Model(itemRequestLocal.getContentItem(state)); - } - - private static class Model implements TableModel { - - private final List revisions; - private CcmRevision currentRevision; - private long count = 0; - private long last = 2; - private int index = -1; - - public Model(final ContentItem item) { - final ContentItemRepository itemRepository = CdiUtil - .createCdiUtil() - .findBean(ContentItemRepository.class); - revisions = itemRepository.retrieveRevisions(item, - item.getObjectId()); - - last = revisions.size() + 2; - } - - @Override - public final int getColumnCount() { - return COLUMNS; - } - - @Override - public final boolean nextRow() { - count++; - index++; - - if (count == 1) { - return true; - } else if (count == last) { - return true; - } else if (revisions.size() < index) { - currentRevision = revisions.get(index); - - return true; - } else { - return false; - } - } - - @Override - public final Object getElementAt(final int column) { - if (count == 1) { - switch (column) { - case TIMESTAMP: - return lz("cms.ui.item.revision.current"); - default: - return ""; - } - } else if (count == last) { - switch (column) { - case TIMESTAMP: - return lz("cms.ui.item.revision.first"); - default: - return ""; - } - } else { - switch (column) { - case TIMESTAMP: - return FormatStandards.formatDateTime( - currentRevision.getRevisionDate()); - case USER: - - return currentRevision.getUserName(); - case DESCRIPTION: - return ""; - default: - return ""; - } - } - } - - @Override - public final Object getKeyAt(final int column) { - if (count == 1) { - return "first"; - } else if (count == last) { - return "last"; - } else { - return currentRevision.getId(); - } - } - - } - - private static GlobalizedMessage gz(final String key) { - return new GlobalizedMessage(key, CmsConstants.CMS_BUNDLE); - } - - private static String lz(final String key) { - return (String) gz(key).localize(); - } - -} From d73bfd03b5f3d89a0a80b207cb6971063c9aa1b1 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 16 Mar 2022 19:57:38 +0100 Subject: [PATCH 13/63] Removed depcrecated package com/arsdigita/cms/ui/report --- .../ContentSectionSummaryController.java | 215 ------------------ .../ui/report/ContentSectionSummaryTable.java | 75 ------ .../ContentSectionSummaryTableModel.java | 82 ------- ...ontentSectionSummaryTableModelBuilder.java | 55 ----- .../com/arsdigita/cms/ui/report/Report.java | 67 ------ .../cms/ui/report/ReportListModel.java | 58 ----- 6 files changed, 552 deletions(-) delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTable.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTableModel.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTableModelBuilder.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/report/Report.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ReportListModel.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryController.java deleted file mode 100644 index b5da98d2c..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryController.java +++ /dev/null @@ -1,215 +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.report; - -import com.arsdigita.bebop.table.RowData; - -import org.libreccm.categorization.Categorization; -import org.libreccm.l10n.GlobalizationHelper; -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ContentItemManager; -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.ContentSectionRepository; -import org.librecms.contentsection.ContentType; -import org.librecms.contentsection.Folder; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.transaction.Transactional; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -public class ContentSectionSummaryController { - - @Inject - private ContentSectionRepository sectionRepo; - - @Inject - private ContentItemManager itemManager; - - @Inject - private GlobalizationHelper globalizationHelper; - - @Transactional(Transactional.TxType.REQUIRED) - public List> createReportData(final ContentSection section) { - final ContentSection contentSection = sectionRepo.findById( - section.getObjectId()).get(); - - final List rootFolders = contentSection.getRootDocumentsFolder() - .getSubFolders(); - - final List> data = new ArrayList<>(); - - for (final Folder folder : rootFolders) { - data.addAll(createFolderData(folder)); - } - - return data; - } - - private List> createFolderData(final Folder folder) { - final List> data = new ArrayList<>(); - - final long subFolderCount = countSubFolders(folder); - final List contentTypeInfo = generateContentTypeInfoForFolder( - folder); - - final RowData firstRow = new RowData<>(5); - firstRow.setRowKey(-1L); - firstRow.setColData(ContentSectionSummaryTable.COL_FOLDER_NAME, - folder.getDisplayName()); - firstRow.setColData(ContentSectionSummaryTable.COL_SUBFOLDER_COUNT, - Long.toString(subFolderCount)); - firstRow.setColData(ContentSectionSummaryTable.COL_CONTENT_TYPE, - contentTypeInfo.get(0).getTypeName()); - firstRow.setColData(ContentSectionSummaryTable.COL_CONTENT_TYPE, - Long.toString(contentTypeInfo.get(0).getDraftCount())); - firstRow.setColData(ContentSectionSummaryTable.COL_CONTENT_TYPE, - Long.toString(contentTypeInfo.get(0).getLiveCount())); - data.add(firstRow); - - for(int i = 1; i < contentTypeInfo.size(); i++) { - data.add(createRow(contentTypeInfo.get(i))); - } - - return data; - } - - private RowData createRow(final ContentTypeFolderInfo info) { - final RowData row = new RowData<>(5); - - row.setRowKey(-1L); - row.setColData(ContentSectionSummaryTable.COL_FOLDER_NAME, ""); - row.setColData(ContentSectionSummaryTable.COL_SUBFOLDER_COUNT, ""); - row.setColData(ContentSectionSummaryTable.COL_CONTENT_TYPE, - info.getTypeClassName()); - row.setColData(ContentSectionSummaryTable.COL_DRAFT_COUNT, - Long.toString(info.getDraftCount())); - row.setColData(ContentSectionSummaryTable.COL_LIVE_COUNT, - Long.toString(info.getLiveCount())); - - return row; - } - - private long countSubFolders(final Folder folder) { - long count = 0; - for (final Folder subFolder : folder.getSubFolders()) { - count++; - count += countSubFolders(subFolder); - } - - return count; - } - - private List generateContentTypeInfoForFolder( - final Folder folder) { - - final Map dataMap = new HashMap<>(); - generateContentTypeInfoForFolder(folder, dataMap); - final List data = new ArrayList<>(dataMap - .values()); - Collections.sort( - data, - (info1, info2) -> { - return info1.getTypeName().compareTo(info2.getTypeName()); - }); - return data; - } - - private void generateContentTypeInfoForFolder( - final Folder folder, final Map data) { - - for (final Categorization categorization : folder.getObjects()) { - if (!(categorization.getCategorizedObject() instanceof ContentItem)) { - continue; - } - - final ContentItem item = (ContentItem) categorization - .getCategorizedObject(); - final ContentType type = item.getContentType(); - - final ContentTypeFolderInfo info; - if (data.containsKey(type.getContentItemClass())) { - info = data.get(type.getContentItemClass()); - } else { - info = new ContentTypeFolderInfo( - type.getContentItemClass(), - type.getLabel().getValue(globalizationHelper - .getNegotiatedLocale())); - } - info.increaseDraftCount(); - if (itemManager.isLive(item)) { - info.increaseLiveCount(); - } - } - - for (final Folder subFolder : folder.getSubFolders()) { - generateContentTypeInfoForFolder(subFolder, data); - } - } - - private class ContentTypeFolderInfo { - - private final String typeClassName; - private final String typeName; - private long draftCount = 0; - private long liveCount = 0; - - public ContentTypeFolderInfo(final String typeClassName, - final String typeName) { - this.typeClassName = typeClassName; - this.typeName = typeName; - } - - public String getTypeClassName() { - return typeClassName; - } - - public String getTypeName() { - return typeName; - } - - public long getDraftCount() { - return draftCount; - } - - public void increaseDraftCount() { - draftCount++; - } - - public long getLiveCount() { - return liveCount; - } - - public void increaseLiveCount() { - liveCount++; - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTable.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTable.java deleted file mode 100644 index a1c7b27a6..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTable.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2009 Permeance Technologies Pty Ltd. 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.report; - -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.bebop.table.TableColumnModel; -import com.arsdigita.globalization.GlobalizedMessage; -import org.librecms.CmsConstants; - -/** - * Table component for content section summary report. - * - * @author - * thomas-buckel - */ -public class ContentSectionSummaryTable extends Table { - - public static final int COL_FOLDER_NAME = 0; - public static final int COL_SUBFOLDER_COUNT = 1; - public static final int COL_CONTENT_TYPE = 2; - public static final int COL_DRAFT_COUNT = 3; - public static final int COL_LIVE_COUNT = 4; - - public ContentSectionSummaryTable() { - super(); - - setModelBuilder(new ContentSectionSummaryTableModelBuilder()); - - final TableColumnModel columnModel = getColumnModel(); - columnModel.add(new TableColumn( - COL_FOLDER_NAME, - new Label(new GlobalizedMessage("cms.ui.reports.css.folder", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_SUBFOLDER_COUNT, - new Label(new GlobalizedMessage( - "cms.ui.reports.css.subfolderCount", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_CONTENT_TYPE, - new Label( - new GlobalizedMessage("cms.ui.reports.css.contentType", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_DRAFT_COUNT, - new Label(new GlobalizedMessage("cms.ui.reports.css.draft", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_LIVE_COUNT, - new Label(new GlobalizedMessage("cms.ui.reports.css.live", - CmsConstants.CMS_BUNDLE)))); - - setEmptyView(new Label(new GlobalizedMessage( - "cms.ui.reports.css.emptyResult", - CmsConstants.CMS_BUNDLE))); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTableModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTableModel.java deleted file mode 100644 index 82a36270d..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTableModel.java +++ /dev/null @@ -1,82 +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.report; - -import com.arsdigita.bebop.table.RowData; -import com.arsdigita.bebop.table.TableModel; -import java.util.Iterator; -import java.util.List; - -/** - * - * @author Jens Pelzetter - */ -class ContentSectionSummaryTableModel implements TableModel { - - private final Iterator> iterator; - private RowData currentRow; - - protected ContentSectionSummaryTableModel(final List> rows) { - iterator = rows.iterator(); - } - - @Override - public int getColumnCount() { - return 5; - } - - @Override - public boolean nextRow() { - if (iterator.hasNext()) { - currentRow = iterator.next(); - return true; - } else { - return false; - } - } - - @Override - public Object getElementAt(final int columnIndex) { - switch (columnIndex) { - case ContentSectionSummaryTable.COL_FOLDER_NAME: - return currentRow.getColData( - ContentSectionSummaryTable.COL_FOLDER_NAME); - case ContentSectionSummaryTable.COL_SUBFOLDER_COUNT: - return currentRow.getColData( - ContentSectionSummaryTable.COL_SUBFOLDER_COUNT); - case ContentSectionSummaryTable.COL_CONTENT_TYPE: - return currentRow.getColData( - ContentSectionSummaryTable.COL_CONTENT_TYPE); - case ContentSectionSummaryTable.COL_DRAFT_COUNT: - return currentRow.getColData( - ContentSectionSummaryTable.COL_DRAFT_COUNT); - case ContentSectionSummaryTable.COL_LIVE_COUNT: - return currentRow.getColData( - ContentSectionSummaryTable.COL_LIVE_COUNT); - default: - throw new IllegalArgumentException("Invalid column index"); - } - } - - @Override - public Object getKeyAt(final int columnIndex) { - return currentRow.getRowKey(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTableModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTableModelBuilder.java deleted file mode 100644 index 92c180cc7..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ContentSectionSummaryTableModelBuilder.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2009 Permeance Technologies Pty Ltd. 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.report; - -import java.util.List; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.table.AbstractTableModelBuilder; -import com.arsdigita.bebop.table.RowData; -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.cms.CMS; -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.contentsection.ContentSection; - -/** - * TableModelBuilder that creates a model for the content section summary - * report. - * - * @author - * thomas-buckel - * @author Jens Pelzetter - */ -class ContentSectionSummaryTableModelBuilder - extends AbstractTableModelBuilder { - - @Override - public TableModel makeModel(final Table table, final PageState state) { - - final ContentSection section = CMS.getContext().getContentSection(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentSectionSummaryController controller = cdiUtil.findBean( - ContentSectionSummaryController.class); - - final List> rows = controller.createReportData(section); - - return new ContentSectionSummaryTableModel(rows); - } -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/Report.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/Report.java deleted file mode 100644 index f3bb4d558..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/Report.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2009 Permeance Technologies Pty Ltd. 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.report; - -import com.arsdigita.bebop.Component; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.util.Assert; - -import org.librecms.CmsConstants; - -/** - * UI model for a report. - * A report has a name and a component that displays the report. - * - * @author thomas-buckel - * @author tim-permeance - * @author Jens Pelzetter - */ -public class Report { - - private final String key; - private final String name; - private final Component component; - - public Report(final String key, final Component component) { - Assert.exists(key, "Key for report is required"); - Assert.isTrue(key.length() > 0, "Key for report must not be empty"); - Assert.exists(component, "Component for report is required"); - - this.key = key; - name = gz(key).localize().toString(); - this.component = component; - } - - public String getKey() { - return key; - } - - public String getName() { - return name; - } - - public Component getComponent() { - return component; - } - - protected final static GlobalizedMessage gz(final String key) { - return new GlobalizedMessage(key, CmsConstants.CMS_BUNDLE); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ReportListModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ReportListModel.java deleted file mode 100644 index ebcca8a84..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/report/ReportListModel.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2009 Permeance Technologies Pty Ltd. 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.report; - -import java.util.List; - -import com.arsdigita.bebop.list.ListModel; -import com.arsdigita.util.Assert; - -/** - * ListModel for Reports. - * - * @author thomas-buckel - * @author tim-permeance - */ -public class ReportListModel implements ListModel { - - private int m_index = -1; - private final List m_reports; - - public ReportListModel(List reports) { - Assert.exists(reports); - m_reports = reports; - } - - @Override - public Object getElement() { - return m_reports.get(m_index).getName(); - } - - @Override - public String getKey() { - return m_reports.get(m_index).getKey(); - } - - @Override - public boolean next() { - m_index++; - return (m_reports.size() > m_index); - } - -} From 7a4aa27eefadbb60788e1f8c30de2e758d1cd3dc Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 16 Mar 2022 20:01:15 +0100 Subject: [PATCH 14/63] Removed depcrecated package com/arsdigita/cms/ui/cse from ccm-cms --- .../arsdigita/cms/ui/ContentSectionPage.java | 21 +-- .../cms/ui/cse/ContentSoonExpiredPane.java | 35 ----- .../cse/ContentSoonExpiredPaneController.java | 129 ---------------- .../cms/ui/cse/ContentSoonExpiredTable.java | 141 ------------------ .../ui/cse/ContentSoonExpiredTableModel.java | 81 ---------- .../ContentSoonExpiredTableModelBuilder.java | 56 ------- 6 files changed, 1 insertion(+), 462 deletions(-) delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredPane.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredPaneController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTable.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTableModel.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTableModelBuilder.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java index 9434d21b0..135f2a9c6 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionPage.java @@ -36,7 +36,6 @@ import org.librecms.contentsection.ContentSection; import com.arsdigita.cms.dispatcher.CMSPage; import com.arsdigita.cms.ui.category.CategoryAdminPane; -import com.arsdigita.cms.ui.cse.ContentSoonExpiredPane; import com.arsdigita.cms.ui.folder.FolderAdminPane; import com.arsdigita.cms.ui.lifecycle.LifecycleAdminPane; import com.arsdigita.cms.ui.workflow.WorkflowAdminPane; @@ -139,8 +138,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener { private CategoryAdminPane m_categoryPane; - private LayoutPanel m_csePane; - /** * Creates the content section index page containing - a Navigaton bar for * the various tasks (items, search, images, ....) - a breadcrumb - .... @@ -160,7 +157,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener { m_workflowPane = getWorkflowAdminPane(); m_lifecyclePane = getLifecycleAdminPane(); m_categoryPane = getCategoryAdminPane(); - m_csePane = getCSEPane(); // The panes m_tabbedPane = createTabbedPane(); @@ -201,9 +197,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener { permissionChecker.isPermitted( AdminPrivileges.ADMINISTER_LIFECYLES)); - // csePane: should check permission - m_tabbedPane.setTabVisible(state, m_csePane, true); - // TODO Check for reportPane as well } } @@ -285,15 +278,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener { return m_categoryPane; } - protected LayoutPanel getCSEPane() { - if (m_csePane == null) { - m_csePane = new LayoutPanel(); - m_csePane.setLeft(new SimpleComponent()); - m_csePane.setBody(new ContentSoonExpiredPane()); - } - return m_csePane; - } - /** * Adds the specified component, with the specified tab name, to the tabbed * pane only if it is not null. @@ -340,7 +324,6 @@ public class ContentSectionPage extends CMSPage implements ActionListener { tab(pane, "cms.ui.workflows", getWorkflowAdminPane()); tab(pane, "cms.ui.lifecycles", getLifecycleAdminPane()); tab(pane, "cms.ui.categories", getCategoryAdminPane()); - tab(pane, "cms.ui.cse", getCSEPane()); return pane; } @@ -390,9 +373,7 @@ public class ContentSectionPage extends CMSPage implements ActionListener { } else if (pane == m_categoryPane) { m_categoryPane.reset(state); - } else if (pane == m_csePane) { - m_csePane.reset(state); - } + } } /** diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredPane.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredPane.java deleted file mode 100755 index 791a16fcd..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredPane.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2002-2005 Runtime Collective Ltd. 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.cse; - -import com.arsdigita.bebop.SimpleContainer; - -/** - * A pane that contains details to soon to be expired content. - * - * @author Unknown - * @author Jens Pelzetter - */ -public class ContentSoonExpiredPane extends SimpleContainer { - - public ContentSoonExpiredPane() { - super(); - super.add(new ContentSoonExpiredTable()); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredPaneController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredPaneController.java deleted file mode 100644 index ccfe70630..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredPaneController.java +++ /dev/null @@ -1,129 +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.cse; - -import com.arsdigita.bebop.table.RowData; - -import org.librecms.CMSConfig; -import org.libreccm.auditing.CcmRevision; -import org.libreccm.configuration.ConfigurationManager; -import org.libreccm.l10n.GlobalizationHelper; -import org.libreccm.security.PermissionChecker; -import org.librecms.contentsection.ContentItem; -import org.librecms.contentsection.ContentItemRepository; -import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.privileges.ItemPrivileges; - -import java.text.DateFormat; -import java.util.Calendar; -import java.util.List; -import java.util.Locale; -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; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -public class ContentSoonExpiredPaneController { - - @Inject - private EntityManager entityManager; - - @Inject - private ConfigurationManager confManager; - - @Inject - private ContentItemRepository itemRepo; - - @Inject - private GlobalizationHelper globalizationHelper; - - @Inject - private PermissionChecker permissionChecker; - - @Transactional(Transactional.TxType.REQUIRED) - public List> getSoonExpiredItems( - final ContentSection section) { - final TypedQuery query = entityManager.createQuery( - "SELECT i FROM ContentItem i " - + "WHERE i.contentType.contentSection = :section " - + "AND :endDateTime <= i.lifecycle.endDateTime", - ContentItem.class); - - final CMSConfig cmsConfig = confManager.findConfiguration( - CMSConfig.class); - final int months = cmsConfig.getSoonExpiredTimespanMonths(); - final int days = cmsConfig.getSoonExpiredTimespanDays(); - - final Calendar date = Calendar.getInstance(Locale.ROOT); - date.add(Calendar.DAY_OF_YEAR, days); - date.add(Calendar.MONTH, months); - query.setParameter("endDateTime", date.getTime()); - - query.setParameter("section", section); - - final List result = query.getResultList(); - - return result.stream() - .map(item -> createRow(item)) - .collect(Collectors.toList()); - - } - - private RowData createRow(final ContentItem item) { - final RowData row = new RowData<>(5); - row.setRowKey(item.getObjectId()); - - final CcmRevision current = itemRepo.retrieveCurrentRevision( - item, item.getObjectId()); - row.setColData(ContentSoonExpiredTable.COL_AUTHOR_NAME, - current.getUserName()); - - row.setColData(ContentSoonExpiredTable.COL_ITEM_NAME, - item.getDisplayName()); - - row.setColData(ContentSoonExpiredTable.COL_VIEW, - item.getUuid()); - - if (permissionChecker.isPermitted(ItemPrivileges.EDIT, item)) { - row.setColData(ContentSoonExpiredTable.COL_EDIT, - item.getUuid()); - } else { - row.setColData(ContentSoonExpiredTable.COL_EDIT, - "--"); - } - - final DateFormat dateFormat = DateFormat.getDateTimeInstance( - DateFormat.LONG, - DateFormat.LONG, - globalizationHelper.getNegotiatedLocale()); - row.setColData(ContentSoonExpiredTable.COL_END_DATE_TIME, - dateFormat.format(item.getLifecycle().getEndDateTime())); - - return row; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTable.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTable.java deleted file mode 100644 index 892d6f19f..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTable.java +++ /dev/null @@ -1,141 +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.cse; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.Link; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.Text; -import com.arsdigita.bebop.table.TableCellRenderer; -import com.arsdigita.bebop.table.TableColumn; -import com.arsdigita.bebop.table.TableColumnModel; -import com.arsdigita.cms.CMS; -import com.arsdigita.cms.ui.ContentItemPage; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.util.UncheckedWrapperException; -import com.arsdigita.web.Web; - -import org.librecms.CmsConstants; -import org.librecms.contentsection.ContentSection; - -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; - -/** - * - * @author Jens Pelzetter - */ -public class ContentSoonExpiredTable extends Table { - - protected static final int COL_AUTHOR_NAME = 0; - protected static final int COL_ITEM_NAME = 1; - protected static final int COL_VIEW = 2; - protected static final int COL_EDIT = 3; - protected static final int COL_END_DATE_TIME = 4; - - public ContentSoonExpiredTable() { - - super(); - -// final ContentSection section = CMS.getContext().getContentSection(); - - super.setModelBuilder(new ContentSoonExpiredTableModelBuilder()); - - final TableColumnModel columnModel = getColumnModel(); - columnModel.add(new TableColumn( - COL_AUTHOR_NAME, - new Label(new GlobalizedMessage("cms.ui.cse.authorName", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_ITEM_NAME, - new Label(new GlobalizedMessage("cms.ui.cse.itemName", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_VIEW, - new Label(new GlobalizedMessage("cms.ui.cse.view", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_EDIT, - new Label(new GlobalizedMessage("cms.ui.cse.edit", - CmsConstants.CMS_BUNDLE)))); - columnModel.add(new TableColumn( - COL_END_DATE_TIME, - new Label(new GlobalizedMessage("cms.ui.cse.endDateTime", - CmsConstants.CMS_BUNDLE)))); - - columnModel.get(COL_VIEW).setCellRenderer(new TableCellRenderer() { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - try { - final Link link = new Link( - new Label(new GlobalizedMessage( - "cms.ui.cse.viewLink", - CmsConstants.CMS_BUNDLE)), - String.format( - "%s/redirect/?oid=%s", - Web.getWebappContextPath(), - URLEncoder.encode( - (String) value, "UTF-8"))); - return link; - } catch (UnsupportedEncodingException ex) { - throw new UncheckedWrapperException(ex); - } - } - - }); - - columnModel.get(COL_EDIT).setCellRenderer(new TableCellRenderer() { - - @Override - public Component getComponent(final Table table, - final PageState state, - final Object value, - final boolean isSelected, - final Object key, - final int row, - final int column) { - if ("--".equals(value)) { - //No access for current user - return new Text(""); - } else { - return new Link(new Label(new GlobalizedMessage( - "cms.ui.cse.editLink", - CmsConstants.CMS_BUNDLE)), - ContentItemPage.getItemURL( - (Long) key, - ContentItemPage.AUTHORING_TAB)); - } - } - - }); - - setEmptyView(new Label(new GlobalizedMessage("cms.ui.cse.none", - CmsConstants.CMS_BUNDLE))); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTableModel.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTableModel.java deleted file mode 100644 index b7f4b5e33..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTableModel.java +++ /dev/null @@ -1,81 +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.cse; - -import com.arsdigita.bebop.table.RowData; -import com.arsdigita.bebop.table.TableModel; - -import java.util.Iterator; -import java.util.List; - -/** - * - * @author Jens Pelzetter - */ -class ContentSoonExpiredTableModel implements TableModel { - - private final Iterator> iterator; - private RowData currentRow; - - protected ContentSoonExpiredTableModel(final List> rows) { - iterator = rows.iterator(); - } - - @Override - public int getColumnCount() { - return 5; - } - - @Override - public boolean nextRow() { - if (iterator.hasNext()) { - currentRow = iterator.next(); - return true; - } else { - return false; - } - } - - @Override - public Object getElementAt(final int columnIndex) { - switch (columnIndex) { - case ContentSoonExpiredTable.COL_AUTHOR_NAME: - return currentRow.getColData( - ContentSoonExpiredTable.COL_AUTHOR_NAME); - case ContentSoonExpiredTable.COL_ITEM_NAME: - return currentRow.getColData( - ContentSoonExpiredTable.COL_ITEM_NAME); - case ContentSoonExpiredTable.COL_VIEW: - return currentRow.getColData(ContentSoonExpiredTable.COL_VIEW); - case ContentSoonExpiredTable.COL_EDIT: - return currentRow.getColData(ContentSoonExpiredTable.COL_EDIT); - case ContentSoonExpiredTable.COL_END_DATE_TIME: - return currentRow.getColData( - ContentSoonExpiredTable.COL_END_DATE_TIME); - default: - throw new IllegalArgumentException("Invalid column index."); - } - } - - @Override - public Object getKeyAt(final int columnIndex) { - return currentRow.getRowKey(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTableModelBuilder.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTableModelBuilder.java deleted file mode 100644 index 197ef7509..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/cse/ContentSoonExpiredTableModelBuilder.java +++ /dev/null @@ -1,56 +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.cse; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.table.RowData; -import com.arsdigita.bebop.table.TableModel; -import com.arsdigita.bebop.table.TableModelBuilder; -import com.arsdigita.cms.CMS; -import com.arsdigita.util.LockableImpl; - -import org.libreccm.cdi.utils.CdiUtil; -import org.librecms.contentsection.ContentSection; - -import java.util.List; - -/** - * - * @author Jens Pelzetter - */ -class ContentSoonExpiredTableModelBuilder - extends LockableImpl - implements TableModelBuilder { - - @Override - public TableModel makeModel(final Table table, final PageState state) { - - final ContentSection section = CMS.getContext().getContentSection(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ContentSoonExpiredPaneController controller = cdiUtil.findBean( - ContentSoonExpiredPaneController.class); - - final List> rows = controller.getSoonExpiredItems(section); - - return new ContentSoonExpiredTableModel(rows); - } - -} From 77d73fd33671ed9ea6c109fc72c6bf9265d6039b Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Wed, 16 Mar 2022 20:05:20 +0100 Subject: [PATCH 15/63] Removed depcrecated package com/arsdigita/cms/ui/pages and depcrecated PagesServlet (replaced by JAX-RS application) --- .../pages/PageModelAdminPageController.java | 67 --- .../arsdigita/cms/ui/pages/PageModelData.java | 47 -- .../cms/ui/pages/PagesAdminPage.java | 447 ------------------ .../cms/ui/pages/PagesContextBar.java | 78 --- .../java/org/librecms/pages/PagesServlet.java | 96 ---- 5 files changed, 735 deletions(-) delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/pages/PageModelAdminPageController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/pages/PageModelData.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/pages/PagesAdminPage.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/pages/PagesContextBar.java delete mode 100644 ccm-cms/src/main/java/org/librecms/pages/PagesServlet.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pages/PageModelAdminPageController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/pages/PageModelAdminPageController.java deleted file mode 100644 index cfa46aad8..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pages/PageModelAdminPageController.java +++ /dev/null @@ -1,67 +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.pages; - -import org.libreccm.l10n.GlobalizationHelper; -import org.libreccm.pagemodel.PageModel; -import org.libreccm.pagemodel.PageModelRepository; -import org.librecms.pages.Pages; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.transaction.Transactional; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -class PageModelAdminPageController { - - @Inject - private GlobalizationHelper globalizationHelper; - - @Inject - private PageModelRepository pageModelRepository; - - @Transactional(Transactional.TxType.REQUIRED) - protected List findDraftPageModelsByApplication( - final Pages pages - ) { - final List pageModels = pageModelRepository - .findDraftByApplication(pages); - return pageModels.stream().map(this::buildPageModelData).collect( - Collectors.toList() - ); - } - - private PageModelData buildPageModelData(final PageModel fromPageModel) { - final PageModelData result = new PageModelData(); - result.setPageModelId(fromPageModel.getPageModelId()); - result.setTitle(globalizationHelper.getValueFromLocalizedString( - fromPageModel.getTitle())); - return result; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pages/PageModelData.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/pages/PageModelData.java deleted file mode 100644 index 218eae658..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pages/PageModelData.java +++ /dev/null @@ -1,47 +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.pages; - -/** - * - * @author Jens Pelzetter - */ -class PageModelData { - - private long pageModelId; - - private String title; - - public long getPageModelId() { - return pageModelId; - } - - public void setPageModelId(long pageModelId) { - this.pageModelId = pageModelId; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pages/PagesAdminPage.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/pages/PagesAdminPage.java deleted file mode 100644 index 98b7c56e3..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pages/PagesAdminPage.java +++ /dev/null @@ -1,447 +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.pages; - -import com.arsdigita.bebop.BoxPanel; -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.ParameterSingleSelectionModel; -import com.arsdigita.bebop.SaveCancelSection; -import com.arsdigita.bebop.SimpleContainer; -import com.arsdigita.bebop.TabbedPane; -import com.arsdigita.bebop.Text; -import com.arsdigita.bebop.Tree; -import com.arsdigita.bebop.event.ActionEvent; -import com.arsdigita.bebop.event.ChangeEvent; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.event.PrintEvent; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.form.SingleSelect; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.tree.TreeModel; -import com.arsdigita.bebop.tree.TreeModelBuilder; -import com.arsdigita.cms.ui.CMSApplicationPage; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.toolbox.ui.LayoutPanel; -import com.arsdigita.ui.ReactApp; -import com.arsdigita.ui.admin.categories.CategoriesTreeModel; -import com.arsdigita.util.LockableImpl; - -import org.libreccm.categorization.Category; -import org.libreccm.categorization.CategoryRepository; -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.core.UnexpectedErrorException; -import org.libreccm.pagemodel.PageModel; -import org.libreccm.pagemodel.PageModelRepository; -import org.librecms.CmsConstants; -import org.librecms.pages.PageManager; -import org.librecms.pages.PageRepository; -import org.librecms.pages.Pages; - -import java.util.List; -import java.util.Optional; -import java.util.TooManyListenersException; - - -/** - * - * @author Jens Pelzetter - */ -public class PagesAdminPage extends CMSApplicationPage { - - private static final String INDEX_PAGE_MODEL_SELECT = "indexPageModelSelect"; - - private static final String ITEM_PAGE_MODEL_SELECT = "itemPageModelSelect"; - - private static final String INHERIT_PAGEMODEL = "--inherit--"; - - private final ParameterSingleSelectionModel selectedCategory; - - private final Tree categoryTree; - - private final Label nothingSelectedLabel; - - private final Form pageModelForm; - - private final SingleSelect indexPageModelSelect; - - private final SingleSelect itemPageModelSelect; - - private final SaveCancelSection saveCancelSection; - - private Pages pagesInstance; - - private PagesContextBar pagesContextBar; - - public PagesAdminPage() { - - super("", new SimpleContainer()); - - super.setAttribute("application", "admin"); - super.setClassAttr("cms-admin"); -// super.setTitle(new Label(new GlobalizedMessage("cms.ui.pages.title", -// CmsConstants.CMS_BUNDLE))); - - selectedCategory = new ParameterSingleSelectionModel<>( - new StringParameter("selectedCategory")); - super.addGlobalStateParam(selectedCategory.getStateParameter()); - - categoryTree = new Tree(new CategoryTreeModelBuilder()); - categoryTree.addChangeListener(this::categoryTreeStateChanged); - - final LayoutPanel panel = new LayoutPanel(); - panel.setLeft(categoryTree); - - nothingSelectedLabel = new Label(new GlobalizedMessage( - "cms.ui.pages.no_category_selected", - CmsConstants.CMS_BUNDLE)); -// nothingSelectedLabel.addPrintListener(this::printNothingSelectedLabel); - super.setVisibleDefault(nothingSelectedLabel, true); - - pageModelForm = new Form("pageModelForm"); - super.setVisibleDefault(pageModelForm, false); - - final Label heading = new Label(); - heading.addPrintListener(this::printPageModelFormHeading); - heading.setClassAttr("heading"); - pageModelForm.add(heading); - - indexPageModelSelect = new SingleSelect(INDEX_PAGE_MODEL_SELECT); - indexPageModelSelect - .setLabel(new GlobalizedMessage("cms.ui.pages.index_page_model", - CmsConstants.CMS_BUNDLE)); - try { - indexPageModelSelect.addPrintListener(this::populatePageModelSelect); - } catch (TooManyListenersException ex) { - throw new UnexpectedErrorException(ex); - } - pageModelForm.add(indexPageModelSelect); -// super.setVisibleDefault(indexPageModelSelect, false); - - itemPageModelSelect = new SingleSelect(ITEM_PAGE_MODEL_SELECT); - itemPageModelSelect - .setLabel(new GlobalizedMessage("cms.ui.pages.item_page_model", - CmsConstants.CMS_BUNDLE)); - try { - itemPageModelSelect.addPrintListener(this::populatePageModelSelect); - } catch (TooManyListenersException ex) { - throw new UnexpectedErrorException(ex); - } - pageModelForm.add(itemPageModelSelect); -// super.setVisibleDefault(itemPageModelSelect, false); - - saveCancelSection = new SaveCancelSection(); - pageModelForm.add(saveCancelSection); -// super.setVisibleDefault(saveCancelSection, false); - - pageModelForm.addInitListener(this::initPageModelForm); - pageModelForm.addValidationListener(this::validatePageModelForm); - pageModelForm.addProcessListener(this::processPageModelForm); - - final BoxPanel rightPanel = new BoxPanel(BoxPanel.VERTICAL); - rightPanel.setClassAttr("right-panel"); - rightPanel.add(nothingSelectedLabel); - rightPanel.add(pageModelForm); - panel.setRight(rightPanel); - -// final SimpleContainer pageModelsManager = new SimpleContainer( -// "admin:pageModelsManager", AdminUiConstants.ADMIN_XML_NS); -// pageModelsManager.add(new Text("Placeholder page models editor")); - final ReactApp pageModelsManager = new ReactApp( - "page-models-editor", "scripts/dist/ccm-cms-pagemodelseditor.js"); - - pagesContextBar = new PagesContextBar(); - super.add(pagesContextBar); - - final TabbedPane tabbedPane = new TabbedPane(); - tabbedPane.addTab(new Label(new GlobalizedMessage( - "cms.ui.pages.tab.pages", CmsConstants.CMS_BUNDLE)), - panel); - tabbedPane - .addTab(new Label(new GlobalizedMessage( - "cms.ui.pages.tab.page_models", CmsConstants.CMS_BUNDLE)), - pageModelsManager); - super.add(tabbedPane); - - super.addActionListener(this::initPage); - - super.lock(); - } - - public Pages getPagesInstance() { - return pagesInstance; - } - - public void setPagesInstance(final Pages pagesInstance) { - this.pagesInstance = pagesInstance; - pagesContextBar.setPagesInstance(pagesInstance); - } - -// @Override -// public void register(final Page page) { -// -// super.register(page); -// -// page.setVisibleDefault(nothingSelectedLabel, true); -// page.setVisibleDefault(pageModelForm, false); -// -// page.addGlobalStateParam(selectedCategory.getStateParameter()); -// -// } - private void initPage(final ActionEvent event) { - - final PageState state = event.getPageState(); - - if (selectedCategory.isSelected(state)) { - nothingSelectedLabel.setVisible(state, false); - pageModelForm.setVisible(state, true); - } else { - nothingSelectedLabel.setVisible(state, true); - pageModelForm.setVisible(state, false); - } - - } - -// private void printNothingSelectedLabel(final PrintEvent event) { -// -// final PageState state = event.getPageState(); -// final Label target = (Label) event.getTarget(); -// -// target.setVisible(state, !selectedCategory.isSelected(state)); -// } - private void printPageModelFormHeading(final PrintEvent event) { - - final PageState state = event.getPageState(); - final Label target = (Label) event.getTarget(); - -// target.setVisible(state, !selectedCategory.isSelected(state)); - if (selectedCategory.isSelected(state)) { - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final CategoryRepository categoryRepo = cdiUtil - .findBean(CategoryRepository.class); - - final Category category = categoryRepo - .findById(Long.parseLong(selectedCategory.getSelectedKey(state))) - .orElseThrow(() -> new UnexpectedErrorException(String - .format("No Category with ID %s in the database.", - selectedCategory.getSelectedKey(state)))); - - target.setLabel(new GlobalizedMessage( - "cms.ui.pages.page_config_for_category", - CmsConstants.CMS_BUNDLE, - new Object[]{category.getName()})); - } - } - - private void populatePageModelSelect(final PrintEvent event) { - -// final PageState state = event.getPageState(); - final SingleSelect target = (SingleSelect) event.getTarget(); - -// if (!selectedCategory.isSelected(state)) { -// target.setVisible(state, false); -// return; -// } - target.clearOptions(); - - target.addOption(new Option(INHERIT_PAGEMODEL, - new Label(new GlobalizedMessage( - "cms.ui.pages.assigned_page_model.inherit", - CmsConstants.CMS_BUNDLE)))); - -// final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); -// final PageModelRepository pageModelRepo = cdiUtil.findBean( -// PageModelRepository.class -// ); -// final List pageModels = pageModelRepo -// .findDraftByApplication(pagesInstance); -// final GlobalizationHelper globalizationHelper = cdiUtil -// .findBean(GlobalizationHelper.class); -// for (final PageModel pageModel : pageModels) { -// target.addOption( -// new Option( -// Long.toString(pageModel.getPageModelId()), -// new Text( -// globalizationHelper.getValueFromLocalizedString( -// pageModel.getTitle() -// ) -// ) -// ) -// ); -// } - final PageModelAdminPageController controller = CdiUtil.createCdiUtil() - .findBean(PageModelAdminPageController.class); - final List pageModels = controller - .findDraftPageModelsByApplication(pagesInstance); - for (final PageModelData pageModel : pageModels) { - target.addOption( - new Option( - Long.toString(pageModel.getPageModelId()), - new Text(pageModel.getTitle()) - ) - ); - } - } - - private void categoryTreeStateChanged(final ChangeEvent event) { - - final PageState state = event.getPageState(); - - final String selectedKey = (String) categoryTree.getSelectedKey(state); - selectedCategory.setSelectedKey(state, selectedKey); - } - - private void initPageModelForm(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - -// pageModelForm.setVisible(state, selectedCategory.isSelected(state)); - saveCancelSection.setVisible(state, selectedCategory.isSelected(state)); - - if (!selectedCategory.isSelected(state)) { - return; - } - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final CategoryRepository categoryRepo = cdiUtil - .findBean(CategoryRepository.class); - final PageRepository pageRepo = cdiUtil - .findBean(PageRepository.class); - - final Category category = categoryRepo - .findById(Long.parseLong(selectedCategory.getSelectedKey(state))) - .orElseThrow(() -> new UnexpectedErrorException(String - .format("No Category with ID %s in the database.", - selectedCategory.getSelectedKey(state)))); - - final Optional page = pageRepo - .findPageForCategory(category); - - if (page.isPresent()) { - -// if (page.get().getIndexPageModel() == null) { -// indexPageModelSelect.setValue(state, INHERIT_PAGEMODEL); -// } else { -// indexPageModelSelect.setValue(state, -// Long.toString(page -// .get() -// .getIndexPageModel() -// .getPageModelId())); -// } -// -// if (page.get().getItemPageModel() == null) { -// itemPageModelSelect.setValue(state, INHERIT_PAGEMODEL); -// } else { -// itemPageModelSelect.setValue(state, -// Long.toString(page -// .get() -// .getItemPageModel() -// .getPageModelId())); -// } - } else { - indexPageModelSelect.setValue(state, INHERIT_PAGEMODEL); - itemPageModelSelect.setValue(state, INHERIT_PAGEMODEL); - } - } - - private void validatePageModelForm(final FormSectionEvent event) - throws FormProcessException { - - //Nothing for now - } - - private void processPageModelForm(final FormSectionEvent event) - throws FormProcessException { - - final PageState state = event.getPageState(); - - if (saveCancelSection.getSaveButton().isSelected(state)) { - - final FormData data = event.getFormData(); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final CategoryRepository categoryRepo = cdiUtil - .findBean(CategoryRepository.class); - final PageManager pageManager = cdiUtil - .findBean(PageManager.class); - final PageRepository pageRepo = cdiUtil - .findBean(PageRepository.class); - final PageModelRepository pageModelRepo = cdiUtil - .findBean(PageModelRepository.class); - - final Category category = categoryRepo - .findById(Long.parseLong(selectedCategory.getSelectedKey(state))) - .orElseThrow(() -> new UnexpectedErrorException(String - .format("No Category with ID %s in the database.", - selectedCategory.getSelectedKey(state)))); - - final org.librecms.pages.Page page = pageRepo - .findPageForCategory(category) - .orElse(pageManager.createPageForCategory(category)); - - final String selectedIndexPageModelId = data - .getString(INDEX_PAGE_MODEL_SELECT); - final String selectedItemPageModelId = data - .getString(ITEM_PAGE_MODEL_SELECT); - -// if (!INHERIT_PAGEMODEL.equals(selectedIndexPageModelId)) { -// final PageModel model = pageModelRepo -// .findById(Long.parseLong(selectedIndexPageModelId)) -// .orElseThrow(() -> new UnexpectedErrorException(String -// .format("No PageModel with ID %s in the database.", -// selectedIndexPageModelId))); -// page.setIndexPageModel(model); -// } -// -// if (!INHERIT_PAGEMODEL.equals(selectedItemPageModelId)) { -// final PageModel model = pageModelRepo -// .findById(Long.parseLong(selectedItemPageModelId)) -// .orElseThrow(() -> new UnexpectedErrorException(String -// .format("No PageModel with ID %s in the database.", -// selectedItemPageModelId))); -// page.setItemPageModel(model); -// } - - pageRepo.save(page); - } - - categoryTree.clearSelection(state); - selectedCategory.clearSelection(state); - } - - private class CategoryTreeModelBuilder - extends LockableImpl - implements TreeModelBuilder { - - @Override - public TreeModel makeModel(final Tree tree, - final PageState state) { - - return new CategoriesTreeModel(tree, - pagesInstance.getCategoryDomain()); - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pages/PagesContextBar.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/pages/PagesContextBar.java deleted file mode 100644 index d24a9e49f..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/pages/PagesContextBar.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (C) 2018 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.pages; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.toolbox.ui.ContextBar; -import com.arsdigita.web.URL; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.web.ApplicationRepository; -import org.libreccm.web.CcmApplication; -import org.librecms.CmsConstants; -import org.librecms.pages.Pages; - -import java.util.List; - -/** - * - * @author Jens Pelzetter - */ -class PagesContextBar extends ContextBar { - - private Pages pagesInstance; - - @Override - public List entries(final PageState state) { - - final List entries = super.entries(state); - - final String centerTitle = (String) new GlobalizedMessage( - "cms.ui.content_center", CmsConstants.CMS_BUNDLE).localize(); - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final ApplicationRepository appRepo = cdiUtil.findBean( - ApplicationRepository.class); - final List apps = appRepo.findByType( - CmsConstants.CONTENT_CENTER_APP_TYPE); - - final String centerPath = apps.get(0).getPrimaryUrl(); - final URL url = URL.there(state.getRequest(), centerPath); - entries.add(new Entry(centerTitle, url)); - - final URL pagesUrl = URL.there( - state.getRequest(), - pagesInstance.getPrimaryUrl()); - entries.add(new Entry(String.format("Pages:: %s", - pagesInstance.getPrimaryUrl()), - pagesUrl)); - - return entries; - - } - - protected Pages getPagesInstance() { - return pagesInstance; - } - - protected void setPagesInstance(final Pages pagesInstance) { - this.pagesInstance = pagesInstance; - } - -} diff --git a/ccm-cms/src/main/java/org/librecms/pages/PagesServlet.java b/ccm-cms/src/main/java/org/librecms/pages/PagesServlet.java deleted file mode 100644 index 2fb5af005..000000000 --- a/ccm-cms/src/main/java/org/librecms/pages/PagesServlet.java +++ /dev/null @@ -1,96 +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 org.librecms.pages; - -import com.arsdigita.cms.ui.pages.PagesAdminPage; -import com.arsdigita.templating.PresentationManager; -import com.arsdigita.templating.Templating; -import com.arsdigita.web.BaseApplicationServlet; -import com.arsdigita.web.LoginSignal; -import com.arsdigita.xml.Document; - -import org.apache.shiro.authz.AuthorizationException; -import org.libreccm.security.PermissionChecker; -import org.libreccm.security.Shiro; -import org.libreccm.web.ApplicationRepository; -import org.libreccm.web.CcmApplication; - -import java.io.IOException; - -import javax.inject.Inject; -import javax.servlet.ServletException; -import javax.servlet.annotation.WebServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Servlet for the Admin UI for pages a {@link /ccm/{primaryUrl}}. The admin UI - * itself is implemented by {@link PagesAdminPage}. - * - * @author Jens Pelzetter - */ -@WebServlet(urlPatterns = {"/templates/servlet/pages/*"}) -public class PagesServlet extends BaseApplicationServlet { - - private static final long serialVersionUID = -303317198251922697L; - - @Inject - private ApplicationRepository applicationRepo; - - @Inject - private PagesRepository pagesRepo; - - @Inject - private PermissionChecker permissionChecker; - - @Inject - private Shiro shiro; - - @Override - protected void doService(final HttpServletRequest request, - final HttpServletResponse response, - final CcmApplication application) - throws ServletException, IOException { - - if (!shiro.getSubject().isAuthenticated()) { - throw new LoginSignal(request); - } - - if (!permissionChecker.isPermitted(PagesPrivileges.ADMINISTER_PAGES)) { - throw new AuthorizationException("The current user is not " - + "permitted to administer pages."); - } - - final PagesAdminPage page = new PagesAdminPage(); - - if (!(application instanceof Pages)) { - throw new ServletException( - "Provided application is not an instance of Pages"); - } - - page.setPagesInstance((Pages) application); - - final Document document = page.buildDocument(request, response); - - final PresentationManager presentationManager = Templating - .getPresentationManager(); - presentationManager.servePage(document, request, response); - } - -} From b9dc94e48bb20b0122627705dd5cff96fdaf7d48 Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Thu, 17 Mar 2022 18:51:50 +0100 Subject: [PATCH 16/63] Removed depcrecated package com.arsdigita.london.terms.ui from ccm-cms --- .../cms/ui/authoring/ItemCategoryStep.java | 4 +- .../terms/ui/ACSObjectCategoryPicker.java | 202 ---------- .../terms/ui/CategoryPickerController.java | 241 ------------ .../london/terms/ui/ItemCategoryPicker.java | 79 ---- .../arsdigita/london/terms/ui/TermWidget.java | 370 ------------------ .../src/main/java/org/librecms/CMSConfig.java | 17 - 6 files changed, 1 insertion(+), 912 deletions(-) delete mode 100644 ccm-cms/src/main/java/com/arsdigita/london/terms/ui/ACSObjectCategoryPicker.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/london/terms/ui/CategoryPickerController.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/london/terms/ui/ItemCategoryPicker.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/london/terms/ui/TermWidget.java diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/ItemCategoryStep.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/ItemCategoryStep.java index 8d876a45c..b48595c04 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/ItemCategoryStep.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/ItemCategoryStep.java @@ -75,9 +75,7 @@ public class ItemCategoryStep extends SimpleContainer implements Resettable { itemCategorySummary.registerAction(ItemCategorySummary.ACTION_ADD_JS, new AddActionListener("javascript")); - final String addFormClassName = CMSConfig - .getConfig() - .getCategoryAuthoringAddForm(); + final String addFormClassName = null; final Class addFormClass; try { addFormClass = Class.forName(addFormClassName); diff --git a/ccm-cms/src/main/java/com/arsdigita/london/terms/ui/ACSObjectCategoryPicker.java b/ccm-cms/src/main/java/com/arsdigita/london/terms/ui/ACSObjectCategoryPicker.java deleted file mode 100644 index 5b3300b22..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/london/terms/ui/ACSObjectCategoryPicker.java +++ /dev/null @@ -1,202 +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.london.terms.ui; - -import com.arsdigita.bebop.SimpleContainer; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.event.ActionEvent; -import com.arsdigita.bebop.event.ActionListener; -import com.arsdigita.bebop.parameters.LongParameter; -import com.arsdigita.categorization.ui.ACSObjectCategoryForm; - -import org.apache.logging.log4j.LogManager; -import org.libreccm.categorization.Domain; - -import org.apache.logging.log4j.Logger; -import org.libreccm.categorization.DomainRepository; -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.core.CcmObject; - -import java.math.BigDecimal; -import java.util.Optional; - -/** - * abstracted from original version of c.ad.aplaws.ui.ItemCategoryPicker r1297 - * - * @author Chris Gilbert - * @author Jens Pelzetter - */ -// NON JavaDoc: -// copied from c.ad.aplaws.ui (module ccm-ldn-aplaws) in order to avoid a -// dependency from the integration layer for forum-categorised. Otherwise you -// have had to specify the specific integration layer (i.e. ccm-???-aplaws) in -// application.xml for compiling, which may be different for each installation. -public abstract class ACSObjectCategoryPicker extends SimpleContainer { - - private static final Logger LOGGER = LogManager - .getLogger(ACSObjectCategoryPicker.class); - - private final ACSObjectCategoryForm form; - private final LongParameter rootParam; - - public ACSObjectCategoryPicker(final LongParameter rootParam, - final StringParameter mode) { - - form = getForm(rootParam, mode); - this.rootParam = rootParam; - - super.add(form); - form.addCompletionListener(new ItemCategoryFormCompletion()); - } - - protected abstract ACSObjectCategoryForm getForm(LongParameter root, - StringParameter mode); - - protected abstract CcmObject getObject(PageState state); - -// protected List getCurrentCategories(final Domain domain, -// final CcmObject object) { -// -// LOGGER.debug("Getting terms from {} to {}", domain, object); -// final List terms = domain.getRoot().getSubCategories(); -// terms.addEqualsFilter("model.childObjects.id", object.getID()); -// terms.addPath("model.id"); -// -// List current = new ArrayList<>(); -// while (terms.next()) { -// if (LOGGER.isDebugEnabled()) { -// LOGGER.debug("Got term " + terms.get("model.id")); -// } -// current.add(terms.get("model.id")); -// } -// return current; -// } - // TODO move out of UI code -// public static Collection getCurrentTerms(Domain domain, ACSObject object) { -// if (LOGGER.isDebugEnabled()) { -// LOGGER.debug("Getting terms from " + domain + " to " + object); -// } -// Collection current = new LinkedList(); -// DomainCollection terms = domain.getTerms(); -// terms.addEqualsFilter("model.childObjects.id", object.getID()); -// terms.addPath("model.id"); -// while (terms.next()) { -// if (LOGGER.isDebugEnabled()) { -// LOGGER.debug("Got term " + terms.get("model.id")); -// } -// current.add(terms.getDomainObject()); -// } -// return current; -// } -// -// // TODO move out of UI code -// public static Collection getRelatedTerms(Collection src, Domain domain) { -// if (LOGGER.isDebugEnabled()) { -// LOGGER.debug("Getting related terms to " + domain); -// -// } -// if (src.isEmpty()) { -// // this is a hack, it would be better not to use a completion event listener as -// // this is called even when the form is cancelled... -// return new LinkedList(); -// } -// DomainCollection terms = domain.getTerms(); -// // these next two lines build the query -// terms.addEqualsFilter("model.parents.link.relationType", "related"); -// terms.addFilter("model.parents.id in :ids").set("ids", src); -// -// Collection related = new LinkedList(); -// while (terms.next()) { -// if (LOGGER.isDebugEnabled()) { -// LOGGER.debug("Got term " + terms.getDomainObject()); -// } -// related.add(terms.getDomainObject()); -// } -// return related; -// } -// protected void clearTerms(Domain domain, ACSObject object) { -// if (LOGGER.isDebugEnabled()) { -// LOGGER.debug("Removing terms from " + domain + " to " + object); -// } -// Iterator terms = getCurrentTerms(domain, object).iterator(); -// while (terms.hasNext()) { -// Term term = (Term) terms.next(); -// if (LOGGER.isDebugEnabled()) { -// LOGGER.debug("Removing term " + term + " from " + object); -// } -// term.removeObject(object); -// } -// } -// // TODO move out of UI code -// public static void assignTerms(Collection terms, ACSObject object) { -// if (LOGGER.isDebugEnabled()) { -// LOGGER.debug("Assigning terms to " + object); -// } -// Iterator i = terms.iterator(); -// while (i.hasNext()) { -// Term term = (Term) i.next(); -// if (LOGGER.isDebugEnabled()) { -// LOGGER.debug("Assigning term " + term + " to " + object); -// } -// term.addObject(object); -// } -// } - protected Domain getDomain(final PageState state) { - - LOGGER.debug("Getting domain for {}", state.getValue(rootParam)); - - final Object value = state.getValue(rootParam); - final Long domainId; - if (value instanceof Long) { - domainId = (Long) value; - } else if (value instanceof BigDecimal) { - domainId = ((Number) value).longValue(); - } else if (value instanceof String) { - domainId = Long.parseLong((String) value); - } else { - domainId = Long.parseLong(value.toString()); - } - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final CategoryPickerController controller = cdiUtil - .findBean(CategoryPickerController.class); - - return controller.findDomainByRootCategory(domainId); - } - - /** - * - */ - private class ItemCategoryFormCompletion implements ActionListener { - - @Override - public void actionPerformed(final ActionEvent event) { - - final PageState state = event.getPageState(); - final Domain domain = getDomain(state); - final String domainKey = domain.getDomainKey(); - - LOGGER.debug("Saving categories in: {}", domainKey); - - fireCompletionEvent(state); - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/london/terms/ui/CategoryPickerController.java b/ccm-cms/src/main/java/com/arsdigita/london/terms/ui/CategoryPickerController.java deleted file mode 100644 index 005df55de..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/london/terms/ui/CategoryPickerController.java +++ /dev/null @@ -1,241 +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.london.terms.ui; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.libreccm.categorization.Category; -import org.libreccm.categorization.CategoryManager; -import org.libreccm.categorization.CategoryRepository; -import org.libreccm.categorization.Domain; -import org.libreccm.categorization.DomainManager; -import org.libreccm.categorization.DomainRepository; -import org.libreccm.categorization.ObjectNotAssignedToCategoryException; -import org.libreccm.core.CcmObject; -import org.libreccm.core.CcmObjectRepository; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; -import javax.persistence.EntityManager; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Join; -import javax.persistence.criteria.Root; -import javax.transaction.Transactional; - -/** - * - * @author Jens Pelzetter - */ -@RequestScoped -class CategoryPickerController { - - private final static Logger LOGGER = LogManager - .getLogger(CategoryPickerController.class); - - @Inject - private CategoryManager categoryManager; - - @Inject - private CategoryRepository categoryRepo; - - @Inject - private CcmObjectRepository ccmObjectRepo; - - @Inject - private DomainRepository domainRepo; - - @Inject - private DomainManager domainManager; - - @Inject - private EntityManager entityManager; - - @Transactional(Transactional.TxType.REQUIRED) - protected Domain findDomainByRootCategory(final long rootCategoryId) { - - final CriteriaBuilder builder = entityManager.getCriteriaBuilder(); - final CriteriaQuery query = builder.createQuery(Domain.class); - - final Root from = query.from(Domain.class); - final Join rootCatJoin = from.join("root"); - - query.where(builder.equal(rootCatJoin.get("objectId"), rootCategoryId)); - - return entityManager - .createQuery(query) - .getSingleResult(); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected List getCurrentCategories(final Domain domain, - final CcmObject object) { - - Objects.requireNonNull(domain); - Objects.requireNonNull(object); - - final Domain catDomain = domainRepo - .findById(domain.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No Domain with ID %d in the database.", - domain.getObjectId()))); - - final CcmObject ccmObject = ccmObjectRepo - .findById(object.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No CcmObject with ID %d in the database.", - object.getObjectId()))); - - final Category root = catDomain.getRoot(); - return collectAssignedCategories(ccmObject, root); - } - - private List collectAssignedCategories(final CcmObject object, - final Category root) { - - final List categories = new ArrayList<>(); - if (categoryManager.isAssignedToCategory(root, object)) { - categories.add(root); - } - - if (!root.getSubCategories().isEmpty()) { - for (final Category subCategory : root.getSubCategories()) { - categories.addAll(collectAssignedCategories(object, - subCategory)); - } - } - - return categories; - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void clearCategories(final Domain domain, final CcmObject object) { - - Objects.requireNonNull(domain); - Objects.requireNonNull(object); - - final Domain catDomain = domainRepo - .findById(domain.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No Domain with ID %d in the database.", - domain.getObjectId()))); - - final CcmObject ccmObject = ccmObjectRepo - .findById(object.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No CcmObject with ID %d in the database.", - object.getObjectId()))); - - final Category root = catDomain.getRoot(); - final List assignedCategories = collectAssignedCategories( - ccmObject, root); - - for (final Category category : assignedCategories) { - try { - categoryManager.removeObjectFromCategory(ccmObject, category); - } catch (ObjectNotAssignedToCategoryException ex) { - LOGGER.warn("Tried to remove category {} from object {} but " - + "the object was not assigned to that category.", - Objects.toString(category), - Objects.toString(ccmObject)); - } - } - } - - @Transactional(Transactional.TxType.REQUIRED) - protected void assignCategories(final List categories, - final CcmObject object) { - - Objects.requireNonNull(categories); - Objects.requireNonNull(object); - - final CcmObject ccmObject = ccmObjectRepo - .findById(object.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No CcmObject with ID %d in the database.", - object.getObjectId()))); - - for (final Category category : categories) { - - final Category cat = categoryRepo - .findById(category.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No Category with ID %d in the database.", - category.getObjectId()))); - categoryManager.addObjectToCategory(ccmObject, category, ""); - } - } - - @Transactional(Transactional.TxType.REQUIRED) - protected Category getDomainModelCategory(final Domain domain) { - - Objects.requireNonNull(domain); - - final Domain catDomain = domainRepo - .findById(domain.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No Domain with ID %d in the database.", - domain.getObjectId()))); - - return catDomain.getRoot(); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected List getRootCategories(final Domain domain) { - - return getDomainModelCategory(domain) - .getSubCategories() - .stream() - .collect(Collectors.toList()); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected List getSubCategories(final Category category) { - - Objects.requireNonNull(category); - - final Category cat = categoryRepo - .findById(category.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No Category with ID %d in the database.", - category.getObjectId()))); - - return cat.getSubCategories(); - } - - @Transactional(Transactional.TxType.REQUIRED) - protected Category getParentCategory(final Category category) { - - Objects.requireNonNull(category); - - final Category cat = categoryRepo - .findById(category.getObjectId()) - .orElseThrow(() -> new IllegalArgumentException(String - .format("No Category with ID %d in the database.", - category.getObjectId()))); - - return cat.getParentCategory(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/london/terms/ui/ItemCategoryPicker.java b/ccm-cms/src/main/java/com/arsdigita/london/terms/ui/ItemCategoryPicker.java deleted file mode 100755 index 2da9fdf75..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/london/terms/ui/ItemCategoryPicker.java +++ /dev/null @@ -1,79 +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.london.terms.ui; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.parameters.BigDecimalParameter; -import com.arsdigita.bebop.parameters.LongParameter; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.categorization.ui.ACSObjectCategoryForm; -import com.arsdigita.cms.CMS; - -import org.librecms.contentsection.ContentItem; - -import com.arsdigita.cms.ui.authoring.ItemCategoryForm; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.libreccm.core.CcmObject; - -/** - * Replacement for cms authoring ItemCategoryForm which replaces the category - * widget with a terms based widget. - * - * Provides a ccm-cms specific concrete implementation of - * {@link com.arsdigita.london.terms.ui.ACSObjectCategoryPicker}. - * - * Is is activated / used by pointing the parameter - * {@code com.arsdigita.cms.category_authoring_add_form} to it. -*/ -public class ItemCategoryPicker extends ACSObjectCategoryPicker { - - private static final Logger LOGGER = LogManager - .getLogger(ItemCategoryPicker.class); - - public ItemCategoryPicker(final LongParameter root, - final StringParameter mode) { - super(root, mode); - LOGGER.debug("instantiating ItemCategoryPicker"); - - } - - /* - * @see com.arsdigita.london.terms.ui.ACSObjectCategoryPicker#getForm( - * com.arsdigita.bebop.parameters.BigDecimalParameter, - * com.arsdigita.bebop.parameters.StringParameter) - */ - @Override - protected ACSObjectCategoryForm getForm(final LongParameter root, - final StringParameter mode) { - LOGGER.debug("getForm"); - return new ItemCategoryForm(root, mode, new TermWidget(mode, this)); - } - - - /* - * @see com.arsdigita.london.terms.ui.ACSObjectCategoryPicker#getObject() - */ - @Override - protected CcmObject getObject(final PageState state) { - - return CMS.getContext().getContentItem(); - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/london/terms/ui/TermWidget.java b/ccm-cms/src/main/java/com/arsdigita/london/terms/ui/TermWidget.java deleted file mode 100644 index 349aa7568..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/london/terms/ui/TermWidget.java +++ /dev/null @@ -1,370 +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.london.terms.ui; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.form.Widget; -import com.arsdigita.bebop.parameters.ArrayParameter; -import com.arsdigita.bebop.parameters.BigDecimalParameter; -import com.arsdigita.bebop.parameters.StringParameter; - -import org.libreccm.categorization.Category; - -import com.arsdigita.cms.CMS; - -import org.libreccm.categorization.Domain; - -import com.arsdigita.xml.Element; -import com.arsdigita.xml.XML; - -import org.librecms.CMSConfig; -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.l10n.GlobalizationHelper; - -import java.util.ArrayList; - -/** - * A Widget for selecting Terms. Based heavily on CategoryWidget. - * - * @author mbooth@redhat.com - * @author Chris Gilbert - * @author Jens Pelzetter - * - * Chris Gilbert - updated to identify each node uniquely (correct behaviour for - * polyhierarchical trees) - also, allow ajax update on all branches or just top - * level branch - * - * nb - widget applies to allocation of categories to any ACSObject hence xml - * prefix should be more generic eg bebop rather than cms. cms retained for - * compatibility with existing stylesheets - * - * Jens Pelzetter: Variable naming etc changed to comply with usual Java - * conventions. Adapted to CCM NG. - */ -// NON Javadoc comment: -// Copied from c.ad.aplaws.ui in order to make forum-categorised independend from -// a specific ccm-???-aplaws, i.e. a specific integration layer. -public class TermWidget extends Widget { - - private final StringParameter mode; - private final ACSObjectCategoryPicker picker; - - public TermWidget(final StringParameter mode, - final ACSObjectCategoryPicker picker) { - - super(new ArrayParameter(new BigDecimalParameter("category"))); - - this.mode = mode; - this.picker = picker; - - } - - @Override - protected String getType() { - return "category"; - } - - @Override - public boolean isCompound() { - return false; - } - - @Override - protected void generateWidget(final PageState state, final Element parent) { - - final Domain domain = picker.getDomain(state); - - final Element widget = parent.newChildElement("cms:categoryWidget", - CMS.CMS_XML_NS); - exportAttributes(widget); - - widget.addAttribute("mode", (String) state.getValue(mode)); - widget.addAttribute("name", getName()); - - final Set selectedCats = new HashSet<>(); - - //jensp 2015-03-12: In same cases we need to be able to pass the - //selected categories *and* the selected roots for displaying the - //categories nicely. To maintain backwards - //compatibility we check the type of the value and work either with the - //selected categories only or with the selected categories and their - //roots. - final Set selectedAncestors = new HashSet<>(); - - final Long[] values; - final Long[] selAncestorsValues; //selectedAncestors - final Object valueObj = getValue(state); - if (valueObj instanceof Long[][]) { - if (((Long[][]) valueObj).length >= 1) { - values = ((Long[][]) valueObj)[0]; - } else { - throw new IllegalArgumentException( - "Value of TermWidget is of type BigDecimal[][] but the array is empty."); - } - - if (((Long[][]) valueObj).length >= 2) { - selAncestorsValues = ((Long[][]) valueObj)[1]; - } else { - selAncestorsValues = null; - } - } else if (valueObj instanceof Long[]) { - values = (Long[]) valueObj; - selAncestorsValues = null; - } else { - throw new IllegalArgumentException( - "Value of TermWidget is not of type BigDecimal[] or BigDecimal[][]"); - } - - //BigDecimal[] values = (BigDecimal[]) getValue(state); - if (values != null) { - selectedCats.addAll(Arrays.asList(values)); - } - - if (selAncestorsValues != null) { - selectedAncestors.addAll(Arrays.asList(selAncestorsValues)); - } - - final Element selEl = widget.newChildElement( - "cms:selectedCategories", CMS.CMS_XML_NS); - selEl.addAttribute("name", getName()); - final Iterator selCats = selectedCats.iterator(); -// while (selCats.hasNext()) { -// final Element selCat = selEl.newChildElement("cms:category", -// CMS.CMS_XML_NS); -// selCat.addAttribute("id", selCats.next().toString()); -// } - for (Long selectedCat : selectedCats) { - final Element selectedCatElem = selEl.newChildElement( - "cms:category", CMS.CMS_XML_NS); - selectedCatElem.addAttribute("id", selectedCat.toString()); - } - - final Element selAncestorsElem = widget.newChildElement( - "cms:selectedAncestorCategories", CMS.CMS_XML_NS); - selAncestorsElem.addAttribute("name", getName()); - for (Long selAncestor : selectedAncestors) { - final Element selAncestorElem = selAncestorsElem.newChildElement( - "cms:category", CMS.CMS_XML_NS); - selAncestorElem.addAttribute("id", selAncestor.toString()); - } - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final CategoryPickerController controller = cdiUtil - .findBean(CategoryPickerController.class); - - // only root terms at first, the rest is loaded on-demand via AJAX - final List roots = controller.getRootCategories(domain); - - final Element element = generateCategory( - widget, - controller.getDomainModelCategory(domain), - selectedCats, - null); - - if (CMSConfig.getConfig().isCategoryPickerAjaxExpandAll()) { - // add attribute to the parent node, so that in stylesheet - // we can look for any ancestor with this attribute (can't - // add attribute to categoryWidget element as that is not - // visible when subbranches are transformed) - element.addAttribute("expand", "all"); - } - - for (final Category category : roots) { - - generateRootTerm(element, - category, - selectedCats, - category.getCategoryOrder()); - - } - } - - public static Element generateCategory(final Element parent, - final Category category, - final Set selected, - final Long sortKey) { - - final Element element = parent.newChildElement("cms:category", - CMS.CMS_XML_NS); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final GlobalizationHelper globalizationHelper = cdiUtil - .findBean(GlobalizationHelper.class); - - element.addAttribute("id", XML.format(category.getObjectId())); - element.addAttribute("name", category.getName()); - element.addAttribute( - "description", - globalizationHelper.getValueFromLocalizedString(category - .getDescription())); - if (selected.contains(category.getObjectId())) { - element.addAttribute("isSelected", "1"); - } else { - element.addAttribute("isSelected", "0"); - } - if (category.isAbstractCategory()) { - element.addAttribute("isAbstract", "1"); - } else { - element.addAttribute("isAbstract", "0"); - } - if (category.isEnabled()) { - element.addAttribute("isEnabled", "1"); - } else { - element.addAttribute("isEnabled", "0"); - } - if (sortKey != null) { - element.addAttribute("sortKey", sortKey.toString()); - } - // sort order attribute added to every node so that we can - // correctly transform xml fragments returned by ajax - element.addAttribute("order", "sortKey"); - element.addAttribute("genCat", "true"); - - StringBuilder path = new StringBuilder(parent.getAttribute("fullname")); - if (path.length() > 0) { - path.append(" > "); - - } - path.append(category.getName()); - element.addAttribute("fullname", path.toString()); - - // need to uniquely identify each node in polyhierarchical trees - // so that expand/contract is applied to the correct node by - // javascript getElementByID function - StringBuilder nodeID = new StringBuilder(parent.getAttribute("node-id")); - if (nodeID.length() > 0) { - nodeID.append("-"); - - } - nodeID.append(category.getObjectId()); - element.addAttribute("node-id", nodeID.toString()); - - return element; - } - - public static Element generateTerm(final Element parent, - final Category category, - final Set selected, - final Long sortKey) { - final Element element = generateCategory(parent, - category, - selected, - sortKey); - - element.addAttribute("pid", category.getUniqueId()); - return element; - } - - private static void generateRootTerm(final Element parent, - final Category term, - final Set selected, - final Long sortKey) { - final Element element = generateTerm(parent, term, selected, sortKey); - element.addAttribute("root", "1"); - } - - public static void generateSubtree(final Element parent, - final Category root, - final Set ids) { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final CategoryPickerController controller = cdiUtil - .findBean(CategoryPickerController.class); - - final List terms = controller.getSubCategories(root); - - final Map> children = new HashMap<>(); - for (final Category term : terms) { - final Long parentId = controller - .getParentCategory(term) - .getObjectId(); - - final List childList; - if (children.containsKey(parentId)) { - childList = children.get(parentId); - } else { - childList = new ArrayList<>(); - children.put(parentId, childList); - } - - childList.add(term); - } - - final Element element = generateCategory(parent, root, ids, null); - element.addAttribute("fullname", root.getName()); - element.addAttribute("node-id", Long.toString(root.getObjectId())); - element.addAttribute("order", "sortKey"); - if (CMSConfig.getConfig().isCategoryPickerAjaxExpandAll()) { - //recognisable attribute has to be in the XML for each snippet that - //is transformed, hence add it to the parent - element.addAttribute("expand", "all"); - } - - if (children.containsKey(root.getObjectId())) { - final List roots = children.get(root.getObjectId()); - for (final Category category : roots) { - generateTermWithChildren(element, - category, - ids, - category.getCategoryOrder(), - children); - } - } - } - - private static void generateTermWithChildren( - final Element parent, - final Category category, - final Set selected, - final Long sortKey, - final Map> children) { - - final Element element = generateCategory(parent, - category, - selected, - sortKey); - - element.addAttribute("pid", category.getUniqueId()); - - if (children.containsKey(category.getObjectId())) { - final List childs = children.get(category.getObjectId()); - for (final Category child : childs) { - if (CMSConfig.getConfig().isCategoryPickerAjaxExpandAll()) { - generateTerm(element, - child, - selected, - child.getCategoryOrder()); - } else { - generateTermWithChildren(element, - child, - selected, - child.getCategoryOrder(), - children); - } - } - } - } -} diff --git a/ccm-cms/src/main/java/org/librecms/CMSConfig.java b/ccm-cms/src/main/java/org/librecms/CMSConfig.java index 1443dc615..9cd2f083c 100644 --- a/ccm-cms/src/main/java/org/librecms/CMSConfig.java +++ b/ccm-cms/src/main/java/org/librecms/CMSConfig.java @@ -20,7 +20,6 @@ package org.librecms; import com.arsdigita.bebop.form.DHTMLEditor; import com.arsdigita.cms.ui.authoring.ItemCategoryExtension; -import com.arsdigita.london.terms.ui.ItemCategoryPicker; import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.configuration.Configuration; @@ -554,12 +553,6 @@ public class CMSConfig { ) private int xmlCacheAge = 60 * 60 * 24; - @Setting( - descKey = "categoryAuthoringAddForm.desc", - labelKey = "categoryAuthoringAddForm.label" - ) - private String categoryAuthoringAddForm = ItemCategoryPicker.class.getName(); - @Setting( descKey = "categoryAuthoringExtension.desc", labelKey = "categoryAuthoringExtension.label" @@ -1136,16 +1129,6 @@ public class CMSConfig { this.linkDescMaxLength = linkDescMaxLength; } - public String getCategoryAuthoringAddForm() { - return categoryAuthoringAddForm; - } - - public void setCategoryAuthoringAddForm( - final String categoryAuthoringAddForm) { - - this.categoryAuthoringAddForm = categoryAuthoringAddForm; - } - public String getCategoryAuthoringExtension() { return categoryAuthoringExtension; } From 9d16918052b0c382143414f07a3133043ce1bf7e Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Thu, 17 Mar 2022 19:10:56 +0100 Subject: [PATCH 17/63] Removed depcrecated package com/arsdigita/cms/ui/permissions from ccm-cms --- .../com/arsdigita/cms/ui/FlatItemList.java | 46 +- .../CMSDirectPermissionsTableRow.java | 69 -- .../permissions/CMSPermissionsConstants.java | 167 ----- .../ui/permissions/CMSPermissionsGrant.java | 212 ------ .../ui/permissions/CMSPermissionsHeader.java | 99 --- .../ui/permissions/CMSPermissionsPane.java | 686 ------------------ .../CMSPermissionsTableColumn.java | 99 --- .../CMSPermissionsTableController.java | 120 --- .../permissions/CMSPermissionsTableModel.java | 101 --- .../CMSPermissionsTableModelBuilder.java | 48 -- .../permissions/CMSPermissionsTableRow.java | 116 --- .../ui/permissions/CMSPermissionsTables.java | 545 -------------- .../ui/permissions/CMSUserObjectStruct.java | 114 --- .../cms/ui/permissions/CMSUserSearchForm.java | 136 ---- .../ui/permissions/ItemPermissionsStep.java | 80 -- .../cms/ui/permissions/ObjectAddAdmin.java | 287 -------- .../ui/permissions/ObjectAddSearchAdmin.java | 118 --- .../ui/permissions/ObjectAdminListing.java | 256 ------- .../cms/ui/permissions/PermissionStatus.java | 67 -- .../cms/ui/permissions/UserPrivilegeKey.java | 84 --- 20 files changed, 22 insertions(+), 3428 deletions(-) delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSDirectPermissionsTableRow.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsConstants.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsGrant.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsHeader.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsPane.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsTableColumn.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsTableController.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsTableModel.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsTableModelBuilder.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsTableRow.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsTables.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSUserObjectStruct.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSUserSearchForm.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/ItemPermissionsStep.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/ObjectAddAdmin.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/ObjectAddSearchAdmin.java delete mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/ObjectAdminListing.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/PermissionStatus.java delete mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/UserPrivilegeKey.java 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 e20ccb72b..522b564b9 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 @@ -19,7 +19,6 @@ package com.arsdigita.cms.ui; import com.arsdigita.bebop.ActionLink; -import com.arsdigita.bebop.Form; import com.arsdigita.bebop.FormProcessException; import com.arsdigita.bebop.Label; import com.arsdigita.bebop.Page; @@ -35,8 +34,6 @@ import com.arsdigita.bebop.event.ChangeListener; import com.arsdigita.bebop.event.FormProcessListener; import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.event.FormSubmissionListener; -import com.arsdigita.bebop.event.PrintEvent; -import com.arsdigita.bebop.event.PrintListener; import com.arsdigita.bebop.parameters.LongParameter; import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.cms.CMS; @@ -51,7 +48,6 @@ import com.arsdigita.cms.ui.folder.FolderManipulator; import com.arsdigita.cms.ui.folder.FolderPath; import com.arsdigita.cms.ui.folder.FolderRequestLocal; import com.arsdigita.cms.ui.folder.FolderSelectionModel; -import com.arsdigita.cms.ui.permissions.CMSPermissionsPane; import com.arsdigita.globalization.GlobalizedMessage; import com.arsdigita.toolbox.ui.ActionGroup; @@ -82,31 +78,45 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener, ActionListener { private static final String CONTENT_TYPE_ID = "ct"; + // The folder selectors private final FolderSelectionModel folderSelectionModel; + private final FolderRequestLocal folderRequestLocal; + private final NewItemForm newItemForm; + private final SingleSelectionModel typeSelectionModel; + private final CreationSelector creationSelector; + private final FolderManipulator folderManipulator; + private final FolderCreateForm folderCreator; -// private final ActionLink m_setHomeFolderAction; -// private final ActionLink m_removeHomeFolderAction; + private final ActionLink createFolderAction; -// private final ActionLink togglePrivateAction; -// private final Label m_homeFolderLabel; + private final Segment browseSegment; + private final Segment newItemSegment; + private final Segment newFolderSegment; + private final Segment editFolderSegment; + private final Segment permissionsSegment; - private final CMSPermissionsPane permissionsPane; + // Folder edit/rename functionality. private final ActionLink editFolderAction; + private final FolderEditorForm folderEditor; + private final Label contentLabel; + private final FolderPath folderPath; + private final Label chooseLabel; + private final StringParameter selectedLanguageParam; /** @@ -180,8 +190,9 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener, permissionsSegment.addHeader(new Label(new GlobalizedMessage( "cms.ui.permissions", CmsConstants.CMS_BUNDLE))); - selectedLanguageParam = new StringParameter(ContentItemPage.SELECTED_LANGUAGE); - + selectedLanguageParam = new StringParameter( + ContentItemPage.SELECTED_LANGUAGE); + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final PermissionManager permissionManager = cdiUtil.findBean( PermissionManager.class); @@ -190,12 +201,6 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener, final Map privNameMap = new HashMap<>(); privileges.forEach(privilege -> privNameMap.put(privilege, privilege)); - permissionsPane = new CMSPermissionsPane( - privileges.toArray(new String[]{}), - privNameMap, - (CcmObjectSelectionModel) folderSelectionModel); - permissionActions.setSubject(permissionsPane); - newItemSegment.addHeader(new Label(globalize("cms.ui.new_item"))); typeSelectionModel = new ParameterSingleSelectionModel<>( new LongParameter(CONTENT_TYPE_ID)); @@ -408,8 +413,6 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener, PermissionChecker.class); permissionChecker.checkPermission(ItemPrivileges.ADMINISTER, currentFolder); - - permissionsPane.reset(state); } @Override @@ -419,17 +422,12 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener, // switching between folders used to keep showing the permission pane // in the same perm mode (direct or inherited) regardless // of the folder status - permissionsPane.reset(state); } public final FolderManipulator getManipulator() { return folderManipulator; } - public final CMSPermissionsPane getPermissionsPane() { - return permissionsPane; - } - public void setPermissionLinkVis(final PageState state) { // final Folder currentFolder = folderRequestLocal.getFolder(state); // final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSDirectPermissionsTableRow.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSDirectPermissionsTableRow.java deleted file mode 100644 index 7eb91b9dd..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSDirectPermissionsTableRow.java +++ /dev/null @@ -1,69 +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.permissions; - -/** - * - * @author Jens Pelzetter - */ -class CMSDirectPermissionsTableRow { - - private long granteeKey; - - private String granteeName; - - private boolean permitted; - - private UserPrivilegeKey userPrivilegeKey; - - public long getGranteeKey() { - return granteeKey; - } - - protected void setGranteeKey(final long granteeKey) { - this.granteeKey = granteeKey; - } - - public String getGranteeName() { - return granteeName; - } - - protected void setGranteeName(final String granteeName) { - this.granteeName = granteeName; - } - - public boolean isPermitted() { - return permitted; - } - - protected void setPermitted(final boolean permitted) { - this.permitted = permitted; - } - - public UserPrivilegeKey getUserPrivilegeKey() { - return userPrivilegeKey; - } - - protected void setUserPrivilegeKey(final UserPrivilegeKey userPrivilegeKey) { - this.userPrivilegeKey = userPrivilegeKey; - } - - - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsConstants.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsConstants.java deleted file mode 100755 index f8f0c07a6..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsConstants.java +++ /dev/null @@ -1,167 +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.permissions; - -import com.arsdigita.globalization.GlobalizedMessage; - -import org.librecms.contentsection.privileges.ItemPrivileges; - -/** - * This interface is used to centralise constants and labels used in the - * Permissions UI package. - * - * @author Stefan Deusch (stefan@arsdigita.com) - * @author Jens Pelzetter - */ -class CMSPermissionsConstants { - - private CMSPermissionsConstants() { - //Nothing - } - - /** - * These are our five default privileges. - */ - public static final String[] DEFAULT_PRIVILEGES = new String[]{ - ItemPrivileges.VIEW_PUBLISHED, - ItemPrivileges.EDIT, - ItemPrivileges.CREATE_NEW, - ItemPrivileges.DELETE,}; - - public static final String BUNDLE_NAME - = "com.arsdigita.ui.permissions.PermissionsResources"; - - public static final GlobalizedMessage SEARCH_LABEL = new GlobalizedMessage( - "permissions.userSearchForm.label", BUNDLE_NAME); - - public static final GlobalizedMessage SEARCH_BUTTON = new GlobalizedMessage( - "permissions.button.search", BUNDLE_NAME); - - public static final GlobalizedMessage SAVE_BUTTON = new GlobalizedMessage( - "permissions.button.save", BUNDLE_NAME); - - public static final GlobalizedMessage NO_RESULTS = new GlobalizedMessage( - "permissions.userSearchForm.noResults", BUNDLE_NAME); - - // Direct / Indirect permissions - public static final GlobalizedMessage PERM_TABLE_DIRECT_HEADING - = new GlobalizedMessage( - "permissions.directPermissions.heading", BUNDLE_NAME); - - public static final GlobalizedMessage PERM_TABLE_DIRECT_EXPLANATION - = new GlobalizedMessage( - "permissions.directPermissions.explanation", BUNDLE_NAME); - - public static final GlobalizedMessage PERM_TABLE_INDIRECT_HEADING - = new GlobalizedMessage( - "permissions.indirectPermissions.heading", BUNDLE_NAME); - - public static final GlobalizedMessage PERM_TABLE_INDIRECT_EXPLANATION - = new GlobalizedMessage( - "permissions.indirectPermissions.explanation", BUNDLE_NAME); - - public static final GlobalizedMessage PERM_TABLE_INDIRECT_CONTEXT - = new GlobalizedMessage( - "permissions.indirectPermissions.context", BUNDLE_NAME); - - public static final GlobalizedMessage PERM_TABLE_GRANTEE - = new GlobalizedMessage( - "permissions.table.grantee", BUNDLE_NAME); - - public static final GlobalizedMessage PERM_TABLE_ACTIONS - = new GlobalizedMessage( - "permissions.table.actions", BUNDLE_NAME); - - public static final GlobalizedMessage REMOVE_ALL_CONFIRM - = new GlobalizedMessage( - "permissions.table.actions.removeAll", BUNDLE_NAME); - - public static final GlobalizedMessage PERM_TABLE_INHERITED - = new GlobalizedMessage( - "permissions.table.inherited", BUNDLE_NAME); - - public static final GlobalizedMessage PERM_TABLE_NO_PARENT_CONTEXT - = new GlobalizedMessage( - "permissions.table.parent.context.null", BUNDLE_NAME); - - // Permissions header - public static final GlobalizedMessage PAGE_TITLE = new GlobalizedMessage( - "permissions.one.title", BUNDLE_NAME); - - public static final GlobalizedMessage MAIN_SITE = new GlobalizedMessage( - "permissions.main.site", BUNDLE_NAME); - - public static final GlobalizedMessage PERSONAL_SITE = new GlobalizedMessage( - "permissions.personal.site", BUNDLE_NAME); - - public static final GlobalizedMessage PERMISSIONS_INDEX - = new GlobalizedMessage( - "permissions.index.title", BUNDLE_NAME); - - public static final GlobalizedMessage PERMISSIONS_INDEX_NAVBAR - = new GlobalizedMessage( - "permissions.index.navbarItem", BUNDLE_NAME); - - // Permissions grant form - public static final GlobalizedMessage PAGE_GRANT_TITLE - = new GlobalizedMessage( - "permissions.one.grant.title", BUNDLE_NAME); - - public static final GlobalizedMessage PAGE_GRANT_LEFT - = new GlobalizedMessage( - "permissions.one.grant.explanation.left", BUNDLE_NAME); - - public static final GlobalizedMessage PAGE_GRANT_RIGHT - = new GlobalizedMessage( - "permissions.one.grant.explanation.right", BUNDLE_NAME); - - // Access denied page - public static final GlobalizedMessage PAGE_DENIED_TITLE - = new GlobalizedMessage( - "permissions.denied.title", BUNDLE_NAME); - - // Index page - public static final GlobalizedMessage PAGE_OBJECT_INDEX - = new GlobalizedMessage( - "permissions.index.adminObjects", BUNDLE_NAME); - - public static final GlobalizedMessage PAGE_OBJECT_PANEL_TITLE - = new GlobalizedMessage( - "permissions.index.panelTitle", BUNDLE_NAME); - - public static final GlobalizedMessage PAGE_OBJECT_NONE - = new GlobalizedMessage( - "permissions.index.noAdminObjects", BUNDLE_NAME); - - // Flats for permission types - public static final int DIRECT = 0; - public static final int INHERITED = 1; - - // Form constants - public static final String OBJECT_ID = "po_id"; - public static final String DIRECT_PERMISSIONS = "direct"; - public static final String INDIRECT_PERMISSIONS = "indirect"; - public static final String SEARCH_QUERY = "query"; - public static final String PRIV_SET = "privs_set"; - - // shared query - public static final String RETRIEVE_USERS - = "com.arsdigita.kernel.RetrieveUsers"; - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsGrant.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsGrant.java deleted file mode 100755 index bd7c042df..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsGrant.java +++ /dev/null @@ -1,212 +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.permissions; - -import com.arsdigita.bebop.BoxPanel; -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.SegmentedPanel; -import com.arsdigita.bebop.Text; -import com.arsdigita.bebop.event.FormSectionEvent; -import com.arsdigita.bebop.event.FormSubmissionListener; -import com.arsdigita.bebop.event.PrintEvent; -import com.arsdigita.bebop.event.PrintListener; -import com.arsdigita.bebop.form.CheckboxGroup; -import com.arsdigita.bebop.form.Option; -import com.arsdigita.bebop.form.OptionGroup; -import com.arsdigita.bebop.form.Submit; -import com.arsdigita.bebop.parameters.ArrayParameter; -import com.arsdigita.bebop.parameters.StringParameter; - -import com.arsdigita.util.StringUtils; -import com.arsdigita.util.UncheckedWrapperException; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.security.PermissionManager; -import org.libreccm.security.Role; -import org.libreccm.security.RoleRepository; - -import java.util.List; -import java.util.TooManyListenersException; - -import static com.arsdigita.cms.ui.permissions.CMSPermissionsConstants.*; - -/** - * Permissions Grant container for permissions assignment. Widgets are currently - * organised on a bebop SegmentedPanel. - * - * @author Stefan Deusch (sdeusch@arsdigita.com) - * @author Jens Pelzetter - */ -class CMSPermissionsGrant { - - private final static String PARTIES_CBG = "parties_cbg"; - private final static String PRIVILEGES_CBG = "privs_cbg"; - - // data keys - private static final String USER_ID = "userID"; - private static final String SCREEN_NAME = "screenName"; - private static final String FIRST_NAME = "firstName"; - private static final String LAST_NAME = "lastName"; - - private final CMSPermissionsPane parent; - private final SegmentedPanel grantPanel; - private CheckboxGroup partiesCheckboxGroup; - private CheckboxGroup privilegesCheckboxGroup; - private Form form; - private Submit saveSubmit; - - /** - * Creates a PermissionsGrant object that will be contained with another - * component. This is currently used inside the permissions pane. - * - * @param parent the enclosing container - */ - public CMSPermissionsGrant(final CMSPermissionsPane parent) { - this.parent = parent; - makeForm(); - grantPanel = new SegmentedPanel(); - grantPanel.addSegment(new Label(PAGE_GRANT_TITLE), form); - } - - /** - * Builds the form used to grant pivileges to users and groups. - */ - private void makeForm() { - form = new Form("GrantPrivileges", new BoxPanel()); - form.setMethod(Form.POST); - form.addSubmissionListener(new GrantFormSubmissionListener()); - form.add(new Label(PAGE_GRANT_LEFT)); - partiesCheckboxGroup = new CheckboxGroup(PARTIES_CBG); - try { - partiesCheckboxGroup.addPrintListener(new UserSearchPrintListener()); - } catch (TooManyListenersException e) { - throw new UncheckedWrapperException("TooManyListeners: " + e - .getMessage(), e); - } - form.add(partiesCheckboxGroup); - - form.add(new Label(PAGE_GRANT_RIGHT)); - privilegesCheckboxGroup = new CheckboxGroup(PRIVILEGES_CBG); - try { - privilegesCheckboxGroup.addPrintListener( - new PrivilegePrintListener()); - } catch (TooManyListenersException e) { - throw new UncheckedWrapperException("TooManyListeners: " + e - .getMessage(), e); - } - form.add(privilegesCheckboxGroup); - - saveSubmit = new Submit("save", SAVE_BUTTON); - form.add(saveSubmit); - } - - /** - * Returns the SegmentedPanel with the permissions grant Form - * - * @return the SegmentedPanel with the permissions grant form - */ - public SegmentedPanel getPanel() { - return grantPanel; - } - - private class GrantFormSubmissionListener - implements FormSubmissionListener { - - @Override - public void submitted(FormSectionEvent event) throws - FormProcessException { - final PageState state = event.getPageState(); - final FormData data = event.getFormData(); - final String[] gids = (String[]) data.get(PARTIES_CBG); - final String[] privs = (String[]) data.get(PRIVILEGES_CBG); - if (privs != null && gids != null) { - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final PermissionManager permissionManager = cdiUtil.findBean( - PermissionManager.class); - - final Long oID = parent.getObject(state).getObjectId(); - for (String gid : gids) { - final Long gID = Long.parseLong(gid); - final CMSUserObjectStruct userObjectStruct - = new CMSUserObjectStruct(gID, - oID); - for (String priv : privs) { - permissionManager.grantPrivilege( - priv, - userObjectStruct.getRole(), - userObjectStruct.getObject()); - } - } - } -// parent.showAdmin(state); - } - - } - - private class UserSearchPrintListener implements PrintListener { - - @Override - public void prepare(final PrintEvent event) { - final PageState state = event.getPageState(); - final OptionGroup target = (OptionGroup) event.getTarget(); - - // get query string - final String search = StringUtils.stripWhiteSpace((String) state. - getValue(new StringParameter(SEARCH_QUERY))); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final RoleRepository roleRepo = cdiUtil.findBean( - RoleRepository.class); - - final List roles = roleRepo.searchByName(search); - - roles.forEach(role -> target.addOption(new Option( - Long.toString(role.getRoleId()), - new Text(role.getName())))); - } - - } - - private class PrivilegePrintListener implements PrintListener { - - @Override - public void prepare(final PrintEvent event) { - final PageState state = event.getPageState(); - final OptionGroup target = (OptionGroup) event.getTarget(); - - // get privileges from page state - final Object[] privileges = (Object[]) state.getValue( - new ArrayParameter( - PRIV_SET)); - - // print ceckbox group with privileges - for (Object privilege : privileges) { - target.addOption(new Option((String) privilege, - new Text(parent.getPrivilegeName( - (String) privilege)))); - } - } - - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsHeader.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsHeader.java deleted file mode 100755 index d481f4e67..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsHeader.java +++ /dev/null @@ -1,99 +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.permissions; - -import com.arsdigita.bebop.BoxPanel; -import com.arsdigita.bebop.DimensionalNavbar; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.Link; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.event.PrintEvent; -import com.arsdigita.bebop.event.PrintListener; - -import org.libreccm.core.CcmObject; - -import static com.arsdigita.cms.ui.permissions.CMSPermissionsConstants.*; - -/** - * - * Component that Renders the Header of the Permissions Admin pages - * - * @author sdeusch@arsdigita.com - * @author Jens Pelzetter - */ -class CMSPermissionsHeader extends BoxPanel { - - private final CMSPermissionsPane parent; - private final Label title; - - /** - * Constructor - */ - CMSPermissionsHeader(final CMSPermissionsPane parent) { - this.parent = parent; - title = new Label(); - title.addPrintListener(new PrintListener() { - - @Override - public void prepare(final PrintEvent event) { - final Label target = (Label) event.getTarget(); - target.setLabel(PAGE_TITLE); - } - - }); - title.setClassAttr("heading"); - add(title); - - // Used to render the object name in the navbar - final Label objectName = new Label(); - objectName.addPrintListener(new PrintListener() { - - public void prepare(final PrintEvent event) { - final Label target = (Label) event.getTarget(); - target.setLabel(getObjectName(event)); - } - - }); - - final DimensionalNavbar navbar = new DimensionalNavbar(); - navbar.add(new Link(new Label(PERSONAL_SITE), "/pvt/home")); - navbar.add(new Link(new Label(MAIN_SITE), "/")); - navbar.add(new Link(new Label(PERMISSIONS_INDEX), "/permissions/")); - navbar.add(objectName); - navbar.setClassAttr("permNavBar"); - add(navbar); - } - - private String getObjectName(final PrintEvent event) { - final PageState state = event.getPageState(); - final CcmObject object = parent.getObject(state); - final String objectName = String.format("%s (ID %d)", - object.getDisplayName(), - object.getObjectId()); - return objectName; - } - - /** - * Returns the object used to render the title of the panel. - */ - Label getTitle() { - return title; - } - -} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsPane.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsPane.java deleted file mode 100755 index b140a2a6d..000000000 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/permissions/CMSPermissionsPane.java +++ /dev/null @@ -1,686 +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.permissions; - -import com.arsdigita.bebop.BoxPanel; -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.ControlLink; -import com.arsdigita.bebop.Form; -import com.arsdigita.bebop.FormProcessException; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.Page; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.RequestLocal; -import com.arsdigita.bebop.Resettable; -import com.arsdigita.bebop.SegmentedPanel; -import com.arsdigita.bebop.SimpleComponent; -import com.arsdigita.bebop.SimpleContainer; -import com.arsdigita.bebop.Table; -import com.arsdigita.bebop.Text; -import com.arsdigita.bebop.event.ActionEvent; -import com.arsdigita.bebop.event.ActionListener; -import com.arsdigita.bebop.event.RequestEvent; -import com.arsdigita.bebop.event.RequestListener; -import com.arsdigita.bebop.event.TableActionEvent; -import com.arsdigita.bebop.event.TableActionListener; -import com.arsdigita.bebop.parameters.ArrayParameter; -import com.arsdigita.bebop.parameters.ParameterModel; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.bebop.table.TableCellRenderer; -import com.arsdigita.dispatcher.DispatcherHelper; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.ui.CcmObjectSelectionModel; - -import com.arsdigita.util.UncheckedWrapperException; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.core.CcmObject; -import org.libreccm.core.UnexpectedErrorException; -import org.libreccm.security.PermissionChecker; -import org.libreccm.security.PermissionManager; -import org.libreccm.security.Role; -import org.libreccm.security.RoleRepository; -import org.librecms.CmsConstants; -import org.librecms.contentsection.privileges.ItemPrivileges; - -import java.io.IOException; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; - -/** - * A pane used to administer the permissions of one {@link - * ACSObject}. This is a reusable component that can be embedded into a page to - * provide a generic UI. The page must have the "?po_id=" parameter to supply to - * ACSObject id of the item one is managing permissions for. - * - * @author sdeusch@arsdigita.com - * @authro Jens Pelzetter - */ -public class CMSPermissionsPane extends SimpleContainer implements Resettable, - ActionListener, - RequestListener { - - // non-shared parameter models; leave package scope for access from its members. - private ParameterModel searchString = new StringParameter( - CMSPermissionsConstants.SEARCH_QUERY); - private ParameterModel privilegeArray = new ArrayParameter( - CMSPermissionsConstants.PRIV_SET); - - private String[] privileges; - private Map privilegeNameMap; - private SimpleContainer permissionsTable; - private CMSPermissionsTables allPermissions; - private CMSPermissionsHeader PermissionsHeader; - private SimpleContainer directPermissions; - private Form roleSearchForm; - private SimpleContainer inheritedPermissions; - private SimpleComponent contextPanel; - private SimpleContainer permissionsGrantPanel; - private SimpleContainer noResultsPanel; - private ObjectAdminListing adminListing; - private CcmObjectSelectionModel selectionModel; - - private RequestLocal userObjectInfo; - - /** - * Default constructor creates components that show the default privileges - * as defined in PermissionsConstants interface - * - * @param model - */ - public CMSPermissionsPane(final CcmObjectSelectionModel model) { - this(CMSPermissionsConstants.DEFAULT_PRIVILEGES, new HashMap<>(), model); - privilegeNameMap.put("read", "Read"); - privilegeNameMap.put("write", "Write"); - privilegeNameMap.put("create", "Create"); - privilegeNameMap.put("delete", "Delete"); - privilegeNameMap.put("admin", "Admin"); - } - - /** - * Creates a PermissionsPane with components showing the privileges that are - * passed in as argument. - * - * @param privileges - * @param privilegeNameMap - * @param selectionModel - */ - public CMSPermissionsPane( - final String[] privileges, - final Map privilegeNameMap, - final CcmObjectSelectionModel selectionModel) { - - userObjectInfo = new RequestLocal() { - - @Override - protected Object initialValue(final PageState state) { - return new CMSUserObjectStruct(state, selectionModel); - } - - }; - - this.privileges = privileges; - this.selectionModel = selectionModel; - this.privilegeNameMap = privilegeNameMap; - } - - public CMSPermissionsPane( - final Class privilegesClass, - final CcmObjectSelectionModel selectionModel) { - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final PermissionManager permissionManager = cdiUtil.findBean( - PermissionManager.class); - final List privilegesFromClass = permissionManager - .listDefiniedPrivileges(privilegesClass); - - final Map nameMap = new HashMap<>(); - for(final String privilege: privilegesFromClass) { - nameMap.put(privilege, privilege); - } - - this.privileges = privilegesFromClass.toArray(new String[]{}); - this.selectionModel = selectionModel; - this.privilegeNameMap = nameMap; - } - - /** - * Overwrite this method to construct your default Permissions Pane with the - * components you need. You can subclass anonymously overwriting just the - * register method. Note: the getXXX methods are lazy instantiators, i.e. - * they produce the components only if not already there. (You can even - * overwrite the getXXX components with your own implementation, e.g., if - * you want to show a List instead of a Table for the direct permissions, - * but still use a Table for the inherited permissions. - * - * @param page - */ - @Override - public void register(final Page page) { - super.register(page); - - // add permissions components to this specific implementation - // add(getPermissionsHeader()); -// add(getContextPanel()); - add(getPermissionsTable()); -// add(getDirectPermissionsPanel()); -// add(getUserSearchForm()) -// add(getInheritedPermissionsPanel()); -// add(getPermissionGrantPanel()); -// add(getNoSearchResultPanel()); -// add(getAdminListingPanel()); - - // set initial visibility of components - // p.setVisibleDefault(getPermissionsHeader(), true); - page.setVisibleDefault(getPermissionsTable(), true); -// page.setVisibleDefault(getDirectPermissionsPanel(), true); -// page.setVisibleDefault(getUserSearchForm(), true); -// page.setVisibleDefault(getInheritedPermissionsPanel(), true); -// page.setVisibleDefault(getContextPanel(), true); -// page.setVisibleDefault(getPermissionGrantPanel(), false); -// page.setVisibleDefault(getNoSearchResultPanel(), false); -// page.setVisibleDefault(getAdminListingPanel(), false); - - // p.addActionListener(this); - // p.addRequestListener(this); - // add state parameters - page.addGlobalStateParam(searchString); - page.addGlobalStateParam(privilegeArray); - - } - - /** - * Implementation of interface bebop.Resettable. Use {@code reset} to reset - * permissions component to initial state, e.g. if you embed it into another - * container. - */ - @Override - public void reset(final PageState state) { -// showAdmin(state); - } - - /** - * Utility method to get the authenticated user or group - * - * @param state - * - * @return - */ - public Role getRequestingRole(final PageState state) { - return ((CMSUserObjectStruct) userObjectInfo.get(state)).getRole(); - } - - /** - * Utility method to get the ACSObject from the page state - * - * @param state - * - * @return - */ - public CcmObject getObject(final PageState state) { - return ((CMSUserObjectStruct) userObjectInfo.get(state)).getObject(); - } - - /** - * Returns the title "Permissions on object articles", e.g. - * - * @return - */ - public Label getTitle() { - return ((CMSPermissionsHeader) getPermissionsHeader()).getTitle(); - } - - /** - * Returns a string array of privilege names as defined in the constructor - * - * @return - */ - public String[] getPrivileges() { - return Arrays.copyOf(privileges, privileges.length); - } - - private SimpleContainer getPermissionsTable() { - if (permissionsTable != null) { - return permissionsTable; - } - - final BoxPanel panel = new BoxPanel(BoxPanel.VERTICAL); - final Label header = new Label(new GlobalizedMessage( - "cms.ui.permissions.table.header", - CmsConstants.CMS_BUNDLE)); - panel.add(header); - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); - final PermissionManager permissionManager = cdiUtil.findBean( - PermissionManager.class); -// final List privileges = permissionManager -// .listDefiniedPrivileges(ItemPrivileges.class); -// final List