From 44e21fb842df20772f34e6f9e971f58843768e1f Mon Sep 17 00:00:00 2001 From: jensp Date: Mon, 7 Nov 2016 18:58:24 +0000 Subject: [PATCH] CCM NG/ccm-cms: First part of mibgration of the ConentTypeAdminPane git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4431 8810af33-2d31-482b-a856-94f89814c4df --- .../arsdigita/cms/ContentSectionServlet.java | 12 - .../cms/ui/ContentSectionRequestLocal.java | 43 +++ .../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/ContentTypeAdminPane.java.off | 22 +- .../type/ContentTypeAdminPaneController.java | 83 ++++ .../cms/ui/type/ContentTypeItemPane.java.off | 346 +++++++++++++++++ .../ui/type/ContentTypeListModelBuilder.java | 90 +++++ .../cms/ui/type/ContentTypeRequestLocal.java | 34 ++ .../com/arsdigita/cms/ui/type/EditType.java | 363 ++++++++++++++++++ .../cms/ui/type/TypeElements.java.off | 267 +++++++++++++ .../cms/ui/type/TypePermissionsTable.java.off | 270 +++++++++++++ .../cms/ui/type/TypeSecurityContainer.java | 57 +++ .../cms/ui/type/TypeSecurityListener.java | 52 +++ .../contentsection/ContentTypeManager.java | 66 ++++ ...eManager.java => ContentTypesManager.java} | 2 +- 22 files changed, 2559 insertions(+), 26 deletions(-) create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionRequestLocal.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddContentItemElement.java.off create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddDateElement.java.off create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddElement.java.off create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddFileElement.java.off create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddImageElement.java.off create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddNumberElement.java.off create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddTextAssetElement.java.off create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddTextElement.java.off create mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPaneController.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeItemPane.java.off create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeListModelBuilder.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeRequestLocal.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/EditType.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypeElements.java.off create mode 100644 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypePermissionsTable.java.off create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypeSecurityContainer.java create mode 100755 ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypeSecurityListener.java create mode 100644 ccm-cms/src/main/java/org/librecms/contentsection/ContentTypeManager.java rename ccm-cms/src/main/java/org/librecms/contenttypes/{ContentTypeManager.java => ContentTypesManager.java} (99%) diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ContentSectionServlet.java b/ccm-cms/src/main/java/com/arsdigita/cms/ContentSectionServlet.java index a867436be..d2137b794 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ContentSectionServlet.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ContentSectionServlet.java @@ -39,10 +39,7 @@ import com.arsdigita.web.WebConfig; import com.arsdigita.xml.Document; import java.io.IOException; -import java.math.BigDecimal; -import java.math.BigInteger; import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -54,24 +51,15 @@ import javax.servlet.http.HttpServletResponse; import org.apache.log4j.Logger; import org.arsdigita.cms.CMSConfig; -import org.hibernate.secure.spi.PermissibleAction; -import org.hibernate.secure.spi.PermissionCheckEntityInformation; import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.l10n.GlobalizationHelper; import org.libreccm.security.PermissionChecker; import org.libreccm.security.Shiro; -import org.libreccm.security.User; import org.libreccm.web.CcmApplication; -import org.librecms.CmsConstants; import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItemManager; -import org.librecms.contentsection.ContentItemRepository; import org.librecms.contentsection.ContentSection; -import org.librecms.contentsection.ContentSectionConfig; import org.librecms.contentsection.privileges.ItemPrivileges; -import org.librecms.lifecycle.Lifecycle; - -import javax.enterprise.inject.spi.CDI; /* * NOTE: diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionRequestLocal.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionRequestLocal.java new file mode 100755 index 000000000..250012b4e --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentSectionRequestLocal.java @@ -0,0 +1,43 @@ +/* + * 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.RequestLocal; +import com.arsdigita.cms.CMS; +import org.librecms.contentsection.ContentSection; +import org.apache.log4j.Logger; + +/** + * + */ +public final class ContentSectionRequestLocal extends RequestLocal { + + private static final Logger s_log = Logger.getLogger + (ContentSectionRequestLocal.class); + + @Override + protected Object initialValue(final PageState state) { + return CMS.getContext().getContentSection(); + } + + public final ContentSection getContentSection(final PageState state) { + return (ContentSection) get(state); + } +} 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 new file mode 100755 index 000000000..79e562a1d --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddContentItemElement.java.off @@ -0,0 +1,142 @@ +/* + * 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 new file mode 100755 index 000000000..04035a43f --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddDateElement.java.off @@ -0,0 +1,174 @@ +/* + * 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 new file mode 100755 index 000000000..1aa0472b1 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddElement.java.off @@ -0,0 +1,112 @@ +/* + * 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 new file mode 100755 index 000000000..4f4f89456 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddFileElement.java.off @@ -0,0 +1,74 @@ +/* + * 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 new file mode 100755 index 000000000..47ba24d3a --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddImageElement.java.off @@ -0,0 +1,74 @@ +/* + * 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 new file mode 100755 index 000000000..348900a9b --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddNumberElement.java.off @@ -0,0 +1,90 @@ +/* + * 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 new file mode 100755 index 000000000..0fab6d9c1 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddTextAssetElement.java.off @@ -0,0 +1,69 @@ +/* + * 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 new file mode 100755 index 000000000..56f621347 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/AddTextElement.java.off @@ -0,0 +1,143 @@ +/* + * 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/ContentTypeAdminPane.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPane.java.off index 8f5daf254..57c4d3a67 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPane.java.off +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPane.java.off @@ -35,12 +35,8 @@ 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.cms.ui.ContentSectionPage; -import com.arsdigita.cms.util.GlobalizationUtil; -import com.arsdigita.kernel.ACSObject; -import com.arsdigita.domain.DomainCollection; -import com.arsdigita.persistence.DataCollection; -import com.arsdigita.persistence.SessionManager; +//ToDo insert later import com.arsdigita.cms.ui.ContentSectionPage; +import org.libreccm.core.CcmObject; import com.arsdigita.kernel.ui.ACSObjectSelectionModel; import com.arsdigita.toolbox.ui.ActionGroup; import com.arsdigita.toolbox.ui.Section; @@ -53,11 +49,11 @@ import java.math.BigDecimal; * This class contains the split pane for the ContentType * administration interface. * + * @author Jens Pelzetter * @author Jack Chung * @author Michael Pih * @author Stanislav Freidin * @author Justin Ross <jross@redhat.com> - * @version $Id: ContentTypeAdminPane.java 1942 2009-05-29 07:53:23Z terry $ */ public final class ContentTypeAdminPane extends BaseAdminPane { @@ -105,18 +101,18 @@ public final class ContentTypeAdminPane extends BaseAdminPane { } @Override - public void register(Page p) { - super.register(p); + public void register(final Page page) { + super.register(page); - p.addActionListener(new ActionListener() { + page.addActionListener(new ActionListener() { /** * - * @param e + * @param event */ @Override - public void actionPerformed(ActionEvent e) { - final PageState state = e.getPageState(); + public void actionPerformed(final ActionEvent event) { + final PageState state = event.getPageState(); ContentType contentType = (ContentType) m_model.getSelectedObject(state); ContentSection section = CMS.getContext().getContentSection(); if (contentType == null) { 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 new file mode 100644 index 000000000..dcb989f8e --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeAdminPaneController.java @@ -0,0 +1,83 @@ +/* + * 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 com.arsdigita.kernel.KernelConfig; + +import org.libreccm.configuration.ConfigurationManager; +import org.libreccm.l10n.GlobalizationHelper; +import org.librecms.contentsection.ContentSection; +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; + +/** + * 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 +public class ContentTypeAdminPaneController { + + @Inject + private ContentTypeRepository typeRepo; + + @Inject + private GlobalizationHelper globalizationHelper; + + @Inject + private ConfigurationManager confManager; + + @Transactional(Transactional.TxType.REQUIRED) + public List getTypeList(final ContentSection section) { + final List types = typeRepo.findByContentSection(section); + + return types.stream() + .map(type -> generateListEntry(type)) + .collect(Collectors.toList()); + } + + private String[] generateListEntry(final ContentType type) { + final String[] entry = new String[2]; + + final KernelConfig kernelConfig = confManager.findConfiguration( + KernelConfig.class); + + entry[0] = type.getUuid(); + // Enable if admin UI has fields for editing localised labels... +// if (type.getLabel().hasValue(globalizationHelper.getNegotiatedLocale())) { +// entry[1] = type.getLabel().getValue(globalizationHelper +// .getNegotiatedLocale()); +// } else { + entry[1] = type.getLabel().getValue(kernelConfig.getDefaultLocale()); +// } + + return entry; + } + +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeItemPane.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeItemPane.java.off new file mode 100755 index 000000000..42394c327 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeItemPane.java.off @@ -0,0 +1,346 @@ +/* + * 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.SingleSelect; +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.dispatcher.Utilities; +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 org.apache.log4j.Logger; + +/** + * + * @authro Jens Pelzetter + * @author Justin Ross <jross@redhat.com> + */ +final class ContentTypeItemPane extends BaseItemPane { + + private static Logger s_log = Logger.getLogger(ContentTypeItemPane.class); + private final ACSObjectSelectionModel m_model; + private final ContentTypeRequestLocal m_type; + private final SimpleContainer m_detailPane; + private final TypeElements m_elements; + private final AddElement m_elementAddForm; + //ToDo private final SectionTemplatesListing m_templates; + private final TypePermissionsTable m_permissions; +// private final RelationAttributeSection m_relationAttributes; + + 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(); + } + } + + private class TemplateSection extends Section { + + TemplateSection(final ActionLink templateAddLink) { + setHeading(new Label(gz("cms.ui.type.templates"))); + + final ActionGroup group = new ActionGroup(); + setBody(group); + + 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() { + + public final void actionPerformed(final ActionEvent e) { + final PageState state = e.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. + * XXX domlay + */ + private void removeType(final PageState state) { + final ContentSection section = CMS.getContext().getContentSection(); + + section.removeContentType(m_type.getContentType(state)); + + section.save(); + } + + /** + * Determine if the current user has access to edit the content type + * XXX domlay + */ + protected static boolean userCanEdit(final PageState state) { + SecurityManager sm = Utilities.getSecurityManager(state); + return sm.canAccess(state.getRequest(), + SecurityManager.CONTENT_TYPE_ADMIN); + } + + /** + * utility method + * get the DataObject from the DataBase, returns true if it + * is a modifiable type, false otherwise. + * + * XXX domlay + */ + protected final boolean isDynamicType(final PageState state) { + final ContentType type = m_type.getContentType(state); + + final String objectTypeString = + "com.arsdigita.persistence.DynamicObjectType"; + final DataCollection collection = SessionManager.getSession().retrieve( + objectTypeString); + collection.addEqualsFilter("dynamicType", type.getAssociatedObjectType()); + + final boolean b = collection.next(); + + collection.close(); + + return b; + } +} 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 new file mode 100755 index 000000000..f28975a32 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeListModelBuilder.java @@ -0,0 +1,90 @@ +/* + * 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/ContentTypeRequestLocal.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeRequestLocal.java new file mode 100755 index 000000000..d2125e9d2 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/ContentTypeRequestLocal.java @@ -0,0 +1,34 @@ +/* + * 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 new file mode 100755 index 000000000..a832c40c9 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/EditType.java @@ -0,0 +1,363 @@ +/* + * 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.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.form.TextArea; +import com.arsdigita.bebop.form.TextField; +import com.arsdigita.bebop.parameters.BigDecimalParameter; +import com.arsdigita.bebop.parameters.NotNullValidationListener; +import com.arsdigita.bebop.parameters.StringLengthValidationListener; +import com.arsdigita.bebop.parameters.StringParameter; +import com.arsdigita.cms.CMS; + +import org.librecms.contentsection.ContentSection; +import org.librecms.contentsection.ContentType; +import org.librecms.lifecycle.LifecycleDefinition; +import org.libreccm.workflow.WorkflowTemplate; + +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.WorkflowTemplateRepository; +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.TooManyListenersException; + +import javax.persistence.NoResultException; + +/** + * This class contains a form component to edit a content type + * + * @author Jens Pelzetter + * @author Jack Chung (flattop@arsdigita.com) + * @author Michael Pih (pihman@arsdigita.com) + */ +public class EditType extends CMSForm + implements FormInitListener, FormProcessListener { + + private static final Logger LOGGER = LogManager.getLogger(EditType.class); + + private final SingleSelectionModel m_types; + + // Form widgets + private Hidden m_id; + private TextField m_label; + private TextArea m_description; + private SingleSelect m_lcSelect; + private SingleSelect m_wfSelect; + private Submit m_submit; + private Submit m_cancel; + + /** + * @param model The content type selection model. This tells the form which + * content type is selected. + */ + public EditType(final SingleSelectionModel model) { + super("EditContentType"); + + m_types = model; + + m_id = new Hidden(new BigDecimalParameter("id")); + m_id.addValidationListener(new NotNullValidationListener()); + add(m_id); + + 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); + + add(new Label(new GlobalizedMessage("cms.ui.type.lifecycle", + CmsConstants.CMS_BUNDLE))); + m_lcSelect = new SingleSelect(new BigDecimalParameter("lifecycle")); + try { + m_lcSelect.addPrintListener(new SelectLifecyclePrintListener()); + } catch (TooManyListenersException e) { + throw new UncheckedWrapperException("TooManyListeners: " + e + .getMessage(), e); + } + add(m_lcSelect); + + add(new Label(new GlobalizedMessage("cms.ui.type.workflow", + CmsConstants.CMS_BUNDLE))); + m_wfSelect = new SingleSelect(new BigDecimalParameter("workflow")); + try { + m_wfSelect.addPrintListener(new SelectWorkflowPrintListener()); + } catch (TooManyListenersException e) { + throw new UncheckedWrapperException("TooManyListeners: " + e + .getMessage(), e); + } + add(m_wfSelect); + + SimpleContainer s = new SimpleContainer(); + m_submit = new Submit("submit"); + m_submit.setButtonLabel("Save"); + s.add(m_submit); + m_cancel = new Submit("cancel"); + m_cancel.setButtonLabel("Cancel"); + s.add(m_cancel); + add(s, ColumnPanel.FULL_WIDTH | ColumnPanel.CENTER); + + addInitListener(this); + addSubmissionListener(new TypeSecurityListener()); + 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 m_cancel.isSelected(state); + } + + /** + * Returns the "cancel" button on the form + * + * @return the cancel button on the form + */ + public Submit getCancelButton() { + return m_cancel; + } + + /** + * 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(m_id.getName(), typeId); + data.put(m_label.getName(), label); + data.put(m_description.getName(), description); + + final LifecycleDefinition cycle = type.getDefaultLifecycle(); + if (cycle != null) { + data.put(m_lcSelect.getName(), cycle.getDefinitionId()); + } + + WorkflowTemplate template = type.getDefaultWorkflow(); + if (template != null) { + data.put(m_wfSelect.getName(), template.getWorkflowId()); + } + } + + /** + * Fetches the currently selected content type from the single selection + * model. + */ + private ContentType getContentType(final PageState state) { + final String key = m_types.getSelectedKey(state).toString(); + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final ContentTypeRepository typeRepo = cdiUtil.findBean( + ContentTypeRepository.class); + + try { + return typeRepo.findById(Long.parseLong(key)); + } catch (NumberFormatException + | NoResultException ex) { + throw new UncheckedWrapperException(String.format( + "ContentType with ID %s not found.", key), ex); + } + } + + /** + * 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(m_id.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(m_lcSelect.getName()); + final Long workflowId = (Long) data.get(m_wfSelect.getName()); + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final ContentTypeRepository typeRepo = cdiUtil.findBean( + ContentTypeRepository.class); + final LifecycleDefinitionRepository lifecycleDefRepo = cdiUtil.findBean( + LifecycleDefinitionRepository.class); + final WorkflowTemplateRepository workflowTemplateRepo = cdiUtil + .findBean(WorkflowTemplateRepository.class); + final ContentTypeManager typeManager = cdiUtil.findBean( + ContentTypeManager.class); + + ContentType type = null; + try { + type = typeRepo.findById(key); + } catch (NoResultException ex) { + LOGGER.error("Can't find ContentType with key {}", key); + LOGGER.error(ex); + + throw new FormProcessException(new GlobalizedMessage( + "cms.ui.type.content_editing_failed", + CmsConstants.CMS_BUNDLE, + new Object[]{key})); + } + + final KernelConfig kernelConfig = KernelConfig.getConfig(); + + type.getLabel().addValue(kernelConfig.getDefaultLocale(), label); + type.getDescription().addValue(kernelConfig.getDefaultLocale(), + description); + + typeRepo.save(type); + + // Handle default lifecycle and workflow. + final LifecycleDefinition defaultLifecycle = lifecycleDefRepo.findById( + lifecycleId); + final WorkflowTemplate defaultWorkflow = workflowTemplateRepo.findById( + workflowId); + + typeManager.setDefaultLifecycle(type, defaultLifecycle); + typeManager.setDefaultWorkflow(type, 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(); + + // Get the current content section + ContentSection section = CMS.getContext().getContentSection(); + + lifecycleSelect.addOption(new Option("", "-- select --")); + + final List cycles = section + .getLifecycleDefinitions(); + final Locale defaultLocale = KernelConfig.getConfig() + .getDefaultLocale(); + cycles.forEach(cycle -> { + lifecycleSelect.addOption( + new Option(Long.toString(cycle.getDefinitionId()), + 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("", "-- select --")); + + final List templates = section + .getWorkflowTemplates(); + final Locale defaultLocale = KernelConfig.getConfig() + .getDefaultLocale(); + templates.forEach(template -> { + workflowSelect.addOption( + new Option(Long.toString(template.getWorkflowId()), + template.getName().getValue(defaultLocale))); + }); + + } + + } + +} 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 new file mode 100755 index 000000000..e4d9a4fd8 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypeElements.java.off @@ -0,0 +1,267 @@ +/* + * 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; + + } +} diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypePermissionsTable.java.off b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypePermissionsTable.java.off new file mode 100644 index 000000000..49c607734 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypePermissionsTable.java.off @@ -0,0 +1,270 @@ +package com.arsdigita.cms.ui.type; + +import com.arsdigita.bebop.Column; +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.event.TableActionEvent; +import com.arsdigita.bebop.event.TableActionListener; +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 com.arsdigita.cms.ContentType; +import com.arsdigita.cms.dispatcher.Utilities; +import com.arsdigita.cms.ui.ContentSectionRequestLocal; +import com.arsdigita.cms.util.GlobalizationUtil; +import com.arsdigita.cms.util.SecurityConstants; +import com.arsdigita.kernel.Kernel; +import com.arsdigita.kernel.Party; +import com.arsdigita.kernel.Role; +import com.arsdigita.kernel.RoleCollection; +import com.arsdigita.kernel.permissions.ObjectPermissionCollection; +import com.arsdigita.kernel.permissions.PermissionDescriptor; +import com.arsdigita.kernel.permissions.PermissionService; +import com.arsdigita.kernel.permissions.PrivilegeDescriptor; +import com.arsdigita.util.LockableImpl; +import java.math.BigDecimal; +import java.math.BigInteger; + +/** + * + * @author Jens Pelzetter + * @version $Id$ + */ +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(GlobalizationUtil.globalize( + "cms.ui.type.permissions.none"))); + + TableColumnModel columnModel = getColumnModel(); + + columnModel.add(new TableColumn( + 0, + GlobalizationUtil.globalize("cms.ui.type.permissions.role"). + localize(), + TABLE_COL_ROLE)); + + columnModel.add(new TableColumn( + 1, + GlobalizationUtil.globalize("cms.ui.type.permissions_can_use"). + localize(), + TABLE_COL_CAN_USE)); + + columnModel.add(new TableColumn( + 2, + GlobalizationUtil.globalize( + "cms.ui.type.permission.action").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); + } + + public void cellSelected(final TableActionEvent event) { + PageState state = event.getPageState(); + + TableColumn column = getColumnModel().get(event.getColumn().intValue()); + + if (TABLE_COL_ACTION.equals(column.getHeaderKey().toString())) { + Role role = new Role(new BigDecimal(event.getRowKey().toString())); + ContentType contentType = getType().getContentType(state); + ObjectPermissionCollection permissions = + PermissionService. + getDirectGrantedPermissions(contentType.getOID()); + + if ((permissions.size() == 0)) { + role.grantPermission(contentType, + PrivilegeDescriptor.get( + com.arsdigita.cms.SecurityManager.CMS_NEW_ITEM)); + } else if (!role.checkPermission(contentType, PrivilegeDescriptor. + get(com.arsdigita.cms.SecurityManager.CMS_NEW_ITEM))) { + role.grantPermission(contentType, + PrivilegeDescriptor.get( + com.arsdigita.cms.SecurityManager.CMS_NEW_ITEM)); + } else { + role.revokePermission(contentType, + PrivilegeDescriptor.get( + com.arsdigita.cms.SecurityManager.CMS_NEW_ITEM)); + } + } + } + + public void headSelected(final TableActionEvent event) { + //Nothing to do + } + + private class TypePermissionsTableModelBuilder + extends LockableImpl + implements TableModelBuilder { + + public TypePermissionsTableModelBuilder() { + } + + public TableModel makeModel(Table table, PageState state) { + table.getRowSelectionModel().clearSelection(state); + return new TypePermissionsTableModel(table, state); + } + } + + private class TypePermissionsTableModel implements TableModel { + + private Table table; + private RoleCollection roles; + private ContentType contentType; + private ObjectPermissionCollection permissions; + + public TypePermissionsTableModel(Table table, PageState state) { + this.table = table; + contentType = + ((TypePermissionsTable) table).getType().getContentType( + state); + + roles = CMS.getContext().getContentSection().getStaffGroup(). + getRoles(); + + permissions = + PermissionService.getDirectGrantedPermissions(contentType.getOID()); + } + + public int getColumnCount() { + if (roles == null) { + return 0; + } else { + return (int) roles.size(); + } + } + + public boolean nextRow() { + if (roles == null) { + return false; + } else { + return roles.next(); + } + } + + public Object getElementAt(int columnIndex) { + switch (columnIndex) { + case 0: + return roles.getRole().getName(); + case 1: + if (permissions.size() == 0) { + return "cms.ui.type.permissions.can_use.yes"; + } else { + if (roles.getRole().checkPermission(contentType, + PrivilegeDescriptor. + get( + com.arsdigita.cms.SecurityManager.CMS_NEW_ITEM))) { + return "cms.ui.type.permissions.can_use.yes"; + } else { + return "cms.ui.type.permissions.can_use.no"; + } + } + case 2: + if (permissions.size() == 0) { + return "cms.ui.type.permissions.actions.restrict_to_this_role"; + } else { + if (roles.getRole().checkPermission(contentType, + PrivilegeDescriptor. + get( + com.arsdigita.cms.SecurityManager.CMS_NEW_ITEM))) { + return "cms.ui.type.permissions.actions.revoke"; + } else { + return "cms.ui.type.permissions.can_use.grant"; + } + } + default: + return null; + } + } + + public Object getKeyAt(int columnIndex) { + return roles.getRole().getID(); + } + } + + private class RoleCellRenderer + extends LockableImpl + implements TableCellRenderer { + + public Component getComponent(Table table, + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int column) { + return new Label(value.toString()); + } + } + + private class CanUseCellRenderer + extends LockableImpl + implements TableCellRenderer { + + public Component getComponent(Table table, + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int column) { + return new Label(GlobalizationUtil.globalize(value.toString())); + } + } + + private class ActionCellRenderer + extends LockableImpl + implements TableCellRenderer { + + public Component getComponent(Table table, + PageState state, + Object value, + boolean isSelected, + Object key, + int row, + int column) { + com.arsdigita.cms.SecurityManager securityManager = Utilities. + getSecurityManager(state); + Party party = Kernel.getContext().getParty(); + if (party == null) { + party = Kernel.getPublicUser(); + } + if (securityManager.canAccess(party, + SecurityConstants.CONTENT_TYPE_ADMIN)) { + ControlLink link = new ControlLink((String)GlobalizationUtil.globalize( + value.toString()).localize()); + + return link; + } else { + return new Label(value.toString()); + } + + + } + } + + private ContentTypeRequestLocal getType() { + return 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 new file mode 100755 index 000000000..c7d185e3f --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypeSecurityContainer.java @@ -0,0 +1,57 @@ +/* + * 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 com.arsdigita.cms.dispatcher.Utilities; + +import org.libreccm.security.Party; + +import com.arsdigita.toolbox.ui.SecurityContainer; + +import org.apache.log4j.Logger; +import org.libreccm.cdi.utils.CdiUtil; +import org.libreccm.security.PermissionChecker; +import org.librecms.contentsection.ContentSection; +import org.librecms.contentsection.privileges.AdminPrivileges; + +/** + * + * @author Jens Pelzetter + * @author Justin Ross + */ +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 new file mode 100755 index 000000000..941742d36 --- /dev/null +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/type/TypeSecurityListener.java @@ -0,0 +1,52 @@ +/* + * 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; + +/** + * + * @autor Jens Pelzetter + * @author Justin Ross <jross@redhat.com> + + */ +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(); + } + } +} diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentTypeManager.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentTypeManager.java new file mode 100644 index 000000000..f639e1609 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentTypeManager.java @@ -0,0 +1,66 @@ +/* + * 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 org.librecms.contentsection; + +import org.libreccm.security.AuthorizationRequired; +import org.libreccm.security.RequiresPrivilege; +import org.libreccm.workflow.WorkflowTemplate; +import org.librecms.contentsection.privileges.AdminPrivileges; +import org.librecms.lifecycle.LifecycleDefinition; + +import javax.enterprise.context.RequestScoped; +import javax.inject.Inject; +import javax.transaction.Transactional; + +/** + * Methods for managing the default lifecycle and workflow of a content type. + * + * @author Jens Pelzetter + */ +@RequestScoped +public class ContentTypeManager { + + @Inject + private ContentTypeRepository typeRepo; + + @Transactional(Transactional.TxType.REQUIRED) + @AuthorizationRequired + public void setDefaultLifecycle( + @RequiresPrivilege(AdminPrivileges.ADMINISTER_CONTENT_TYPES) + final ContentType type, + final LifecycleDefinition definition) { + + type.setDefaultLifecycle(definition); + + typeRepo.save(type); + } + + @Transactional(Transactional.TxType.REQUIRED) + @AuthorizationRequired + public void setDefaultWorkflow( + @RequiresPrivilege(AdminPrivileges.ADMINISTER_CONTENT_TYPES) + final ContentType type, + final WorkflowTemplate template) { + + type.setDefaultWorkflow(template); + + typeRepo.save(type); + } + +} diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/ContentTypeManager.java b/ccm-cms/src/main/java/org/librecms/contenttypes/ContentTypesManager.java similarity index 99% rename from ccm-cms/src/main/java/org/librecms/contenttypes/ContentTypeManager.java rename to ccm-cms/src/main/java/org/librecms/contenttypes/ContentTypesManager.java index f196f4f27..54d0932a8 100644 --- a/ccm-cms/src/main/java/org/librecms/contenttypes/ContentTypeManager.java +++ b/ccm-cms/src/main/java/org/librecms/contenttypes/ContentTypesManager.java @@ -37,7 +37,7 @@ import javax.enterprise.context.RequestScoped; * @author Jens Pelzetter */ @RequestScoped -public class ContentTypeManager { +public class ContentTypesManager { private static final String DEFAULT_DESCRIPTION_KEY = "description"; private static final String DEFAULT_LABEL_KEY = "label";