From 40f71ce13f1bc195ed842c173edf12c3a6e26c4b Mon Sep 17 00:00:00 2001 From: jensp Date: Thu, 3 Jul 2014 09:41:28 +0000 Subject: [PATCH] Finished admin UI for the ContentItemJSRPortlet git-svn-id: https://svn.libreccm.org/ccm/trunk@2736 8810af33-2d31-482b-a856-94f89814c4df --- .../cms/portlet/ContentItemJSRPortlet.java | 116 ++++++++++++++++-- .../ContentItemJSRPortletResources.properties | 10 ++ ...ntentItemJSRPortletResources_de.properties | 7 ++ .../portlets/ContentItemJSRPortletAdmin.jsp | 74 ++++++++--- .../arsdigita/bebop/DescriptiveComponent.java | 4 +- 5 files changed, 182 insertions(+), 29 deletions(-) diff --git a/ccm-cms/src/com/arsdigita/cms/portlet/ContentItemJSRPortlet.java b/ccm-cms/src/com/arsdigita/cms/portlet/ContentItemJSRPortlet.java index 612584a17..a0b952c3b 100644 --- a/ccm-cms/src/com/arsdigita/cms/portlet/ContentItemJSRPortlet.java +++ b/ccm-cms/src/com/arsdigita/cms/portlet/ContentItemJSRPortlet.java @@ -20,19 +20,26 @@ package com.arsdigita.cms.portlet; import com.arsdigita.cms.ContentBundle; import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.ContentPage; import com.arsdigita.cms.ContentSection; import com.arsdigita.cms.ContentSectionCollection; import com.arsdigita.cms.ItemCollection; +import com.arsdigita.domain.DataObjectNotFoundException; +import com.arsdigita.domain.DomainObjectFactory; +import com.arsdigita.globalization.GlobalizationHelper; import com.arsdigita.persistence.OID; import com.arsdigita.portal.JSRPortlet; import java.io.IOException; import java.io.PrintWriter; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; +import java.util.ResourceBundle; import javax.portlet.ActionRequest; import javax.portlet.ActionResponse; import javax.portlet.PortletException; +import javax.portlet.PortletPreferences; import javax.portlet.PortletRequestDispatcher; import javax.portlet.RenderRequest; import javax.portlet.RenderResponse; @@ -54,8 +61,15 @@ public class ContentItemJSRPortlet extends JSRPortlet { * /WEB-INF/conf/log4j.properties int the runtime environment and set * com.arsdigita.portal.JSRPortlet=DEBUG by uncommenting or adding the line. */ - private static final Logger s_log = Logger.getLogger(ContentItemJSRPortlet.class); - private static final String BACKING_BEAN = "comArsdigitaCMSContentItemJSRPortletAdmin"; + private static final Logger LOGGER = Logger.getLogger(ContentItemJSRPortlet.class); + private static final String PREFS_SELECTED_ITEM = ".selectedContentItem"; + private static final String SELECTED_ITEM = "selectedItem"; + private static final String ACTION = "action"; + private static final String SELECT_ITEM = "selectItem"; + private static final String CONTENT_ITEM_SEARCH_STRING = "contentItemSearchString"; + private static final String CONTENT_SECTION_SELECT = "contentSectionSelect"; + + private final List errors = new ArrayList(); private String selectedContentSection; private String search; @@ -83,7 +97,7 @@ public class ContentItemJSRPortlet extends JSRPortlet { request.setAttribute("contentSections", sections); request.setAttribute("selectedContentSection", selectedContentSection); - request.setAttribute("contentItemSearchString", search); + request.setAttribute(CONTENT_ITEM_SEARCH_STRING, search); if ((selectedContentSection != null)) { final ContentSection selectedSection = new ContentSection(OID.valueOf( @@ -102,8 +116,53 @@ public class ContentItemJSRPortlet extends JSRPortlet { request.setAttribute("matchingItems", matchingItems); } - request.setAttribute("helloworld", "Hello World Attribute"); + request.setAttribute("errors", errors); + final String itemOID = request.getPreferences().getValue(response.getNamespace().concat( + PREFS_SELECTED_ITEM), ""); + if (!itemOID.isEmpty()) { + try { + final OID oid = OID.valueOf(itemOID); + ContentItem item = (ContentItem) DomainObjectFactory.newInstance(oid); + if (item instanceof ContentBundle) { + final ContentBundle bundle = (ContentBundle) item; + if (bundle.hasInstance(request.getLocale().getLanguage())) { + item = bundle.getInstance(request.getLocale().getLanguage()); + } else { + item = bundle.getPrimaryInstance(); + } + } + + request.setAttribute("selectedItemOID", item.getOID().toString()); + request.setAttribute("selectedItemPath", item.getPath()); + request.setAttribute("selectedItemTitle", item.getDisplayName()); + request.setAttribute("selectedItemType", item.getContentType().getName()); + + if (item.getPublicVersion() == null) { + request.setAttribute("selectedItemStatus", "unpublished"); + } else { + request.setAttribute("selectedItemStatus", "published"); + } + + } catch (IllegalArgumentException ex) { + //errors.add(String.format("The OID '%s' set in the preferences is invalid.", + // itemOID)); + errors.add(MessageFormat.format(getResourceBundle(request.getLocale()).getString( + "contentItemJSRPortlet.errors.perferences.illegal_oid"), + itemOID)); + } catch (DataObjectNotFoundException ex) { + //errors.add(String.format("The item identified by the OID '%s' does not exist.", + // itemOID)); + errors.add(MessageFormat.format( + getResourceBundle(request.getLocale()).getString( + "contentItemJSRPortlet.errors.perferences.item_does_not_exist"), + itemOID)); + } + } + + request.setAttribute("namespace", response.getNamespace()); + + //request.setAttribute("helloworld", "Hello World Attribute"); final PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher( "/templates/portlets/ContentItemJSRPortletAdmin.jsp"); dispatcher.include(request, response); @@ -118,10 +177,10 @@ public class ContentItemJSRPortlet extends JSRPortlet { * @throws IOException */ @Override - protected void doHelp(RenderRequest request, RenderResponse response) + protected void doHelp(final RenderRequest request, final RenderResponse response) throws PortletException, IOException { response.setContentType("text/html"); - PrintWriter writer = new PrintWriter(response.getWriter()); + final PrintWriter writer = new PrintWriter(response.getWriter()); writer.println("You're now in Help mode."); } @@ -134,10 +193,10 @@ public class ContentItemJSRPortlet extends JSRPortlet { * @throws IOException */ @Override - protected void doView(RenderRequest request, RenderResponse response) + protected void doView(final RenderRequest request, final RenderResponse response) throws PortletException, IOException { response.setContentType("text/html"); - PrintWriter writer = new PrintWriter(response.getWriter()); + final PrintWriter writer = new PrintWriter(response.getWriter()); writer.println("Hello world! You're in View mode."); } @@ -145,9 +204,44 @@ public class ContentItemJSRPortlet extends JSRPortlet { public void processAction(final ActionRequest actionRequest, final ActionResponse actionResponse) throws PortletException, IOException { - if (actionRequest.getParameter("contentSectionSelect") != null) { - selectedContentSection = actionRequest.getParameter("contentSectionSelect"); - search = actionRequest.getParameter("contentItemSearchString"); + if (actionRequest.getParameter(CONTENT_SECTION_SELECT) != null) { + selectedContentSection = actionRequest.getParameter(CONTENT_SECTION_SELECT); + search = actionRequest.getParameter(CONTENT_ITEM_SEARCH_STRING); + } + + if (SELECT_ITEM.equals(actionRequest.getParameter(ACTION))) { + final String itemOID = actionRequest.getParameter(SELECTED_ITEM); + + if ((itemOID == null) || itemOID.isEmpty()) { + errors.add("OID is null"); + } else { + try { + OID oid = OID.valueOf(itemOID); + final ContentItem item = new ContentItem(oid); + + final ContentItem draftItem = item.getDraftVersion(); + if (draftItem instanceof ContentPage) { + final ContentPage page = (ContentPage) draftItem; + final ContentBundle bundle = page.getContentBundle(); + oid = bundle.getOID(); + } + + final PortletPreferences preferences = actionRequest.getPreferences(); + preferences.setValue(actionResponse.getNamespace().concat(PREFS_SELECTED_ITEM), + oid.toString()); + preferences.store(); + + } catch (IllegalArgumentException ex) { + errors.add(MessageFormat.format(getResourceBundle(actionRequest.getLocale()). + getString("contentItemJSRPortlet.errors.parameters.illegal_oid"), + itemOID)); + } catch (DataObjectNotFoundException ex) { + errors.add(MessageFormat.format(getResourceBundle(actionRequest.getLocale()) + .getString( + "contentItemJSRPortlet.errors.parameters.item_does_not_exist"), + itemOID)); + } + } } } diff --git a/ccm-cms/src/com/arsdigita/cms/portlet/ContentItemJSRPortletResources.properties b/ccm-cms/src/com/arsdigita/cms/portlet/ContentItemJSRPortletResources.properties index 9b0e6515c..1554882bb 100644 --- a/ccm-cms/src/com/arsdigita/cms/portlet/ContentItemJSRPortletResources.properties +++ b/ccm-cms/src/com/arsdigita/cms/portlet/ContentItemJSRPortletResources.properties @@ -1,2 +1,12 @@ javax.portlet.title=CCM Single Content Item javax.portlet.short-title=Single Content Item + +contentItemJSRPortlet.errors.perferences.illegal_oid=The OID '{0}' set in the preferences is malformed. +contentItemJSRPortlet.errors.perferences.item_does_not_exist=The item identified by the OID {0} which is set in the preferences does not exist. +contentItemJSRPortlet.errors.parameters.illegal_oid=The OID '{0}' which as provided as parameter is invalid. +contentItemJSRPortlet.errors.parameters.item_does_not_exist=There is no item with the OID '{0}'. + +contentItemJSRPortlet.edit.contentSectionSelect.label=Content section +contentitemJSRPortlet.edit.search.label=Title of the content item + +contentItemJSRPortlet.edit.fieldset.label=Please choose the content item to display diff --git a/ccm-cms/src/com/arsdigita/cms/portlet/ContentItemJSRPortletResources_de.properties b/ccm-cms/src/com/arsdigita/cms/portlet/ContentItemJSRPortletResources_de.properties index f191bda2f..03e3e7412 100644 --- a/ccm-cms/src/com/arsdigita/cms/portlet/ContentItemJSRPortletResources_de.properties +++ b/ccm-cms/src/com/arsdigita/cms/portlet/ContentItemJSRPortletResources_de.properties @@ -1,2 +1,9 @@ javax.portlet.title=Ein CCM Dokument javax.portlet.short-title=Einzeldokument +contentItemJSRPortlet.errors.perferences.illegal_oid=Die in den Einstellungen gespeicherte OID '{0}' ist fehlerhaft. +contentItemJSRPortlet.errors.perferences.item_does_not_exist=Es existiert kein ContentItem mit der konfigurierten OID '{0}'. +contentItemJSRPortlet.errors.parameters.illegal_oid=Die als Parameter \u00fcbergebene OID '{0}' ist fehlerhaft. +contentItemJSRPortlet.errors.parameters.item_does_not_exist=Es gibt kein Item mit der OID '{0}'. +contentItemJSRPortlet.edit.contentSectionSelect.label=Content Section +contentitemJSRPortlet.edit.search.label=Titel des Content Items +contentItemJSRPortlet.edit.fieldset.label=Bitte w\u00e4hlen Sie das anzuzeigende Content Item diff --git a/ccm-cms/web/templates/portlets/ContentItemJSRPortletAdmin.jsp b/ccm-cms/web/templates/portlets/ContentItemJSRPortletAdmin.jsp index d85d54af8..4b461dae8 100644 --- a/ccm-cms/web/templates/portlets/ContentItemJSRPortletAdmin.jsp +++ b/ccm-cms/web/templates/portlets/ContentItemJSRPortletAdmin.jsp @@ -6,26 +6,62 @@ <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" - prefix="c" %> + prefix="c" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" + prefix="fmt" %> <%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet"%>
+ +

Hello World from ContentItemJSRPortletAdmin.jsp

- + +
    + +
  • ${error}
  • +
    +
+ +
+

Currently selected item

+ +
+
OID
+
${selectedItemOID}
+ +
Path
+
${selectedItemPath}
+ +
Title
+
${selectedItemTitle}
+ +
Type
+
${selectedItemType}
+ +
Status
+
${selectedItemStatus}
+
+
+
+
+
+ + + + - + - + +
- + @@ -48,14 +85,19 @@ - - - - - + + + + +
${matchingItem.path}${matchingItem.displayName} - - Select -
${matchingItem.path}${matchingItem.displayName} + + + + + + Select +
diff --git a/ccm-core/src/com/arsdigita/bebop/DescriptiveComponent.java b/ccm-core/src/com/arsdigita/bebop/DescriptiveComponent.java index 787ad6a2a..55629068c 100755 --- a/ccm-core/src/com/arsdigita/bebop/DescriptiveComponent.java +++ b/ccm-core/src/com/arsdigita/bebop/DescriptiveComponent.java @@ -84,8 +84,8 @@ abstract public class DescriptiveComponent extends SimpleComponent { } /** - * Retrieve the labej for the component. It is specifically meant for - * client classes which have to generate the xml on their own and can not + * Retrieve the label for the component. It is specifically meant for + * client classes which have to generate the XML on their own and can not * use the generateDescriptionXML method provided. * * @return popup hint message for the component