From 4a29a3446a6600014eb4abfb6b7abdabaa9fd7ab Mon Sep 17 00:00:00 2001 From: jensp Date: Thu, 29 Jun 2017 14:32:00 +0000 Subject: [PATCH] CCM NG/ccm-cms: Several changes, especially to handle the new localisation model for content items git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4824 8810af33-2d31-482b-a856-94f89814c4df --- .../src/main/resources/shiro.ini | 6 +- .../mparticle/MultiPartArticleCreateForm.java | 15 ++- .../ui/mparticle/MultiPartArticleForm.java | 9 +- .../cms/ui/ContentItemContextBar.java | 44 +++++-- .../com/arsdigita/cms/ui/ContentItemPage.java | 107 ++++++++++++------ .../com/arsdigita/cms/ui/FlatItemList.java | 8 +- .../cms/ui/authoring/BasicPageForm.java | 72 +++--------- .../ui/authoring/BasicPageFormController.java | 38 ++++--- .../cms/ui/authoring/CreationSelector.java | 14 ++- .../cms/ui/authoring/PageCreateForm.java | 31 +++-- .../ui/folder/FolderBrowserController.java | 19 +++- .../contentsection/ContentItemManager.java | 93 ++++++++------- .../toolbox/ui/DomainObjectPropertySheet.java | 17 ++- 13 files changed, 287 insertions(+), 186 deletions(-) diff --git a/ccm-bundle-devel-wildfly-web/src/main/resources/shiro.ini b/ccm-bundle-devel-wildfly-web/src/main/resources/shiro.ini index 73ee402ca..469c812fa 100644 --- a/ccm-bundle-devel-wildfly-web/src/main/resources/shiro.ini +++ b/ccm-bundle-devel-wildfly-web/src/main/resources/shiro.ini @@ -8,4 +8,8 @@ ccmRealm = org.libreccm.security.CcmShiroRealm ccmRealm.credentialsMatcher = $passwordMatcher securityManager.realms = $ccmRealm -securityManager.rememberMeManager.cipherKey = p5h/Aphy0gfV+XThbEPqSG4iQNh2fTNH9ZEkSBAt/Ok= \ No newline at end of file +securityManager.rememberMeManager.cipherKey = p5h/Aphy0gfV+XThbEPqSG4iQNh2fTNH9ZEkSBAt/Ok= + +cacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager +securityManager.cacheManager = $cacheManager + diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleCreateForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleCreateForm.java index f507aa559..ae8c02336 100644 --- a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleCreateForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleCreateForm.java @@ -30,6 +30,7 @@ import com.arsdigita.bebop.event.FormSubmissionListener; import com.arsdigita.bebop.event.FormValidationListener; import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ui.authoring.ApplyWorkflowFormSection; +import com.arsdigita.cms.ui.authoring.BasicItemForm; import com.arsdigita.cms.ui.authoring.CreationComponent; import com.arsdigita.cms.ui.authoring.CreationSelector; import com.arsdigita.cms.ui.authoring.LanguageWidget; @@ -44,6 +45,8 @@ import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.Folder; import org.librecms.contenttypes.MultiPartArticle; +import java.util.Locale; + /** * A form which will create a MultiPartArticle or one of its subclasses. * @@ -135,16 +138,20 @@ public class MultiPartArticleCreateForm } @Override - public void process(final FormSectionEvent e) throws FormProcessException { - final FormData data = e.getFormData(); - final PageState state = e.getPageState(); + public void process(final FormSectionEvent event) throws FormProcessException { + final FormData data = event.getFormData(); + final PageState state = event.getPageState(); final ContentSection section = creationSelector.getContentSection(state); final Folder folder = creationSelector.getFolder(state); + final Locale locale = new Locale((String) data + .get(BasicItemForm.LANGUAGE)); + final MultiPartArticle article = createArticle(state, (String) data.get(NAME), section, - folder); + folder, + locale); article.getTitle().addValue(KernelConfig.getConfig().getDefaultLocale(), (String) data.get(TITLE)); if (!CMSConfig.getConfig().isHideLaunchDate()) { diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleForm.java index 8622e43e7..471cd4b2b 100644 --- a/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/contenttypes/ui/mparticle/MultiPartArticleForm.java @@ -1,4 +1,4 @@ -/* + /* * Copyright (C) 2017 LibreCCM Foundation. * * This library is free software; you can redistribute it and/or @@ -301,6 +301,7 @@ public abstract class MultiPartArticleForm * @param name * @param section * @param folder + * @param locale Initial locale of the article. * * @return the new content item (or a proper subclass) * @throws com.arsdigita.bebop.FormProcessException @@ -308,7 +309,8 @@ public abstract class MultiPartArticleForm public MultiPartArticle createArticle(final PageState state, final String name, final ContentSection section, - final Folder folder) + final Folder folder, + final Locale locale) throws FormProcessException { final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); @@ -319,7 +321,8 @@ public abstract class MultiPartArticleForm .createContentItem(name, section, folder, - MultiPartArticle.class); + MultiPartArticle.class, + locale); if (itemSelectionModel.getSelectedKey(state) == null) { itemSelectionModel.setSelectedKey(state, article.getObjectId()); diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemContextBar.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemContextBar.java index 57aa93bca..ea833518b 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemContextBar.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemContextBar.java @@ -19,6 +19,7 @@ package com.arsdigita.cms.ui; import com.arsdigita.bebop.PageState; +import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.cms.CMS; import org.librecms.contentsection.ContentItem; @@ -26,10 +27,15 @@ import org.librecms.contentsection.ContentSection; import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.PageLocations; +import com.arsdigita.kernel.KernelConfig; import com.arsdigita.web.ParameterMap; import com.arsdigita.web.URL; +import org.libreccm.cdi.utils.CdiUtil; +import org.librecms.contentsection.ContentItemL10NManager; + import java.util.List; +import java.util.Locale; /** *

@@ -41,11 +47,14 @@ import java.util.List; class ContentItemContextBar extends ContentSectionContextBar { private final ItemSelectionModel itemSelectionModel; + private final StringParameter selectedLanguageParam; - ContentItemContextBar(final ItemSelectionModel itemSelectionModel) { + ContentItemContextBar(final ItemSelectionModel itemSelectionModel, + final StringParameter selectedLanguageParam) { super(); this.itemSelectionModel = itemSelectionModel; + this.selectedLanguageParam = selectedLanguageParam; } @Override @@ -63,12 +72,33 @@ class ContentItemContextBar extends ContentSectionContextBar { title.append(localize("cms.ui.content_item")); title.append(": ") .append(item.getDisplayName()); -// final String language = item.getLanguage(); -// if (language != null) { -// title.append(" (") -// .append(language) -// .append(")"); -// } + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final ContentItemL10NManager l10nManager = cdiUtil + .findBean(ContentItemL10NManager.class); + final String selectedLanguage = (String) state + .getValue(selectedLanguageParam); + final Locale selectedLocale; + if (selectedLanguage == null + || selectedLanguage.isEmpty()) { + selectedLocale = KernelConfig.getConfig().getDefaultLocale(); + } else { + selectedLocale = new Locale(selectedLanguage); + } + + final String language; + if (l10nManager.hasLanguage(item, selectedLocale)) { + language = selectedLanguage; + } else { + state.setValue(selectedLanguageParam, + KernelConfig.getConfig().getDefaultLanguage()); + language = KernelConfig.getConfig().getDefaultLanguage(); + } + if (language != null) { + title.append(" (") + .append(language) + .append(")"); + } entries.add(new Entry(title.toString(), url)); diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java index d59ab875a..b44f8e106 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/ContentItemPage.java @@ -29,6 +29,7 @@ import com.arsdigita.bebop.Resettable; import com.arsdigita.bebop.SimpleContainer; import com.arsdigita.bebop.SingleSelectionModel; import com.arsdigita.bebop.TabbedPane; +import com.arsdigita.bebop.Text; import com.arsdigita.bebop.event.ActionEvent; import com.arsdigita.bebop.event.ActionListener; import com.arsdigita.bebop.event.FormSectionEvent; @@ -66,6 +67,7 @@ import org.arsdigita.cms.CMSConfig; import org.libreccm.cdi.utils.CdiUtil; import org.librecms.CmsConstants; import org.librecms.contentsection.ContentItem; +import org.librecms.contentsection.ContentItemL10NManager; import org.librecms.contentsection.ContentItemRepository; import org.librecms.contentsection.ContentItemVersion; import org.librecms.contentsection.ContentSection; @@ -74,6 +76,7 @@ import org.librecms.contentsection.ContentType; import org.librecms.dispatcher.ItemResolver; import java.io.IOException; +import java.util.Locale; import java.util.Objects; import java.util.Optional; @@ -145,9 +148,9 @@ public class ContentItemPage extends CMSPage implements ActionListener { private final TabbedPane tabbedPane; private final StringParameter returnUrlParameter; - private final ItemSelectionModel itemModel; + private final ItemSelectionModel itemSelectionModel; private final SingleSelectionModel selectedLanguageModel; - private final ACSObjectSelectionModel typeModel; + private final ACSObjectSelectionModel typeSelectionModel; private final ContentItemRequestLocal itemRequestLocal; private final Summary summaryPane; private final ItemWorkflowAdminPane workflowPane; @@ -156,9 +159,9 @@ public class ContentItemPage extends CMSPage implements ActionListener { private final ItemLanguages languagesPane; private final ItemRevisionAdminPane revisionsPane; private final ItemTemplates templatesPane; - private final Link m_previewLink; - private final GlobalNavigation m_globalNavigation; - private final ContentItemContextBar m_contextBar; + private final Link previewLink; + private final GlobalNavigation globalNavigation; + private final ContentItemContextBar contextBar; private final StringParameter selectedLanguageParam; @@ -175,11 +178,44 @@ public class ContentItemPage extends CMSPage implements ActionListener { @Override public final void prepare(final PrintEvent event) { + + final PageState state = event.getPageState(); + final Label label = (Label) event.getTarget(); final ContentItem item = itemRequestLocal.getContentItem(event. getPageState()); - label.setLabel(item.getDisplayName()); + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final ContentItemL10NManager l10nManager = cdiUtil + .findBean(ContentItemL10NManager.class); + final String selectedLanguage = (String) state + .getValue(selectedLanguageParam); + final Locale selectedLocale; + if (selectedLanguage == null + || selectedLanguage.isEmpty()) { + selectedLocale = KernelConfig.getConfig().getDefaultLocale(); + } else { + selectedLocale = new Locale(selectedLanguage); + } + + final String language; + if (l10nManager.hasLanguage(item, selectedLocale)) { + language = selectedLanguage; + } else { + state.setValue(selectedLanguageParam, + KernelConfig.getConfig().getDefaultLanguage()); + language = KernelConfig.getConfig().getDefaultLanguage(); + } + + final StringBuffer title = new StringBuffer(item.getDisplayName()); + if (language != null) { + title + .append(" (") + .append(language) + .append(")"); + } + + label.setLabel(title.toString()); } } @@ -199,14 +235,13 @@ public class ContentItemPage extends CMSPage implements ActionListener { final LongParameter itemId = new LongParameter(ITEM_ID); itemId.addParameterListener(new NotNullValidationListener(ITEM_ID)); addGlobalStateParam(itemId); - itemModel = new ItemSelectionModel(itemId); + itemSelectionModel = new ItemSelectionModel(itemId); // Add the selected item language as parameter selectedLanguageParam = new StringParameter( SELECTED_LANGUAGE); selectedLanguageParam.addParameterListener( - new NotNullValidationListener( - SELECTED_LANGUAGE)); + new NotNullValidationListener(SELECTED_LANGUAGE)); addGlobalStateParam(selectedLanguageParam); selectedLanguageModel = new ParameterSingleSelectionModel<>( selectedLanguageParam); @@ -222,9 +257,11 @@ public class ContentItemPage extends CMSPage implements ActionListener { STREAMLINED_CREATION); addGlobalStateParam(streamlinedCreation); - typeModel = new ACSObjectSelectionModel(ContentType.class.getName(), - ContentType.class.getName(), - contentType); + typeSelectionModel = new ACSObjectSelectionModel(ContentType.class + .getName(), + ContentType.class + .getName(), + contentType); // Validate the item ID parameter (caches the validation). getStateModel().addValidationListener( @@ -234,20 +271,22 @@ public class ContentItemPage extends CMSPage implements ActionListener { returnUrlParameter = new StringParameter(RETURN_URL); addGlobalStateParam(returnUrlParameter); - m_globalNavigation = new GlobalNavigation(); - add(m_globalNavigation); + globalNavigation = new GlobalNavigation(); + add(globalNavigation); - m_contextBar = new ContentItemContextBar(itemModel); - add(m_contextBar); + contextBar = new ContentItemContextBar(itemSelectionModel, + selectedLanguageParam); + add(contextBar); // Create panels. - summaryPane = new Summary(itemModel); - wizardPane = new WizardSelector(itemModel, typeModel); - languagesPane = new ItemLanguages(itemModel, selectedLanguageModel); + summaryPane = new Summary(itemSelectionModel); + wizardPane = new WizardSelector(itemSelectionModel, typeSelectionModel); + languagesPane = new ItemLanguages(itemSelectionModel, + selectedLanguageModel); workflowPane = new ItemWorkflowAdminPane(itemId); // Make this use m_item XXX lifecyclePane = new ItemLifecycleAdminPane(itemRequestLocal); revisionsPane = new ItemRevisionAdminPane(itemRequestLocal); - templatesPane = new ItemTemplates(itemModel); + templatesPane = new ItemTemplates(itemSelectionModel); // Create tabbed pane. tabbedPane = new TabbedPane(); @@ -285,21 +324,21 @@ public class ContentItemPage extends CMSPage implements ActionListener { }); // Build the preview link. - m_previewLink = new Link(new Label(gz("cms.ui.preview")), - new PrintListener() { + previewLink = new Link(new Label(gz("cms.ui.preview")), + new PrintListener() { - @Override - public final void prepare( - final PrintEvent event) { - final Link link = (Link) event.getTarget(); - link.setTarget(getPreviewURL(event. - getPageState())); - link.setTargetFrame(Link.NEW_FRAME); - } + @Override + public final void prepare( + final PrintEvent event) { + final Link link = (Link) event.getTarget(); + link.setTarget(getPreviewURL(event. + getPageState())); + link.setTargetFrame(Link.NEW_FRAME); + } - }); - m_previewLink.setIdAttr("preview_link"); - add(m_previewLink); + }); + previewLink.setIdAttr("preview_link"); + add(previewLink); addActionListener(this); @@ -374,7 +413,7 @@ public class ContentItemPage extends CMSPage implements ActionListener { */ @Override public ContentItem getContentItem(final PageState state) { - return (ContentItem) itemModel.getSelectedObject(state); + return (ContentItem) itemSelectionModel.getSelectedObject(state); } /** diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/FlatItemList.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/FlatItemList.java index 196b551cd..67173e9fa 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/FlatItemList.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/FlatItemList.java @@ -38,6 +38,7 @@ import com.arsdigita.bebop.event.FormSubmissionListener; import com.arsdigita.bebop.event.PrintEvent; import com.arsdigita.bebop.event.PrintListener; import com.arsdigita.bebop.parameters.LongParameter; +import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.cms.CMS; import org.librecms.contentsection.ContentSection; @@ -106,6 +107,7 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener, private final Label contentLabel; private final FolderPath folderPath; private final Label chooseLabel; + private final StringParameter selectedLanguageParam; /** * Construct a new item listing pane. The provided folder selection model is @@ -178,6 +180,8 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener, permissionsSegment.addHeader(new Label(new GlobalizedMessage( "cms.ui.permissions", CmsConstants.CMS_BUNDLE))); + selectedLanguageParam = new StringParameter(ContentItemPage.SELECTED_LANGUAGE); + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final PermissionManager permissionManager = cdiUtil.findBean( PermissionManager.class); @@ -198,7 +202,8 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener, typeSelectionModel.addChangeListener(this); creationSelector = new CreationSelector(typeSelectionModel, - folderSelectionModel); + folderSelectionModel, + selectedLanguageParam); newItemSegment.add(creationSelector); //m_newItemSeg.add(new Label("
", false)); @@ -234,6 +239,7 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener, page.addComponentStateParam(this, typeSelectionModel.getStateParameter()); + page.addGlobalStateParam(selectedLanguageParam); page.addActionListener(new ActionListener() { diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicPageForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicPageForm.java index a266a716b..a8f57b4d9 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicPageForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicPageForm.java @@ -272,6 +272,7 @@ public abstract class BasicPageForm extends BasicItemForm { * @param section * @param folder * @param initializer + * @param locale * * @return the new content item (or a proper subclass thereof) * @@ -282,47 +283,16 @@ public abstract class BasicPageForm extends BasicItemForm { final String name, final ContentSection section, final Folder folder, - final ContentItemInitializer initializer) throws FormProcessException { + final ContentItemInitializer initializer, + final Locale locale) throws FormProcessException { -// final ItemSelectionModel selectionModel = getItemSelectionModel(); -// final ContentType contentType = selectionModel.getContentType(); -// -// final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); -// final ContentItemManager itemManager = cdiUtil -// .findBean(ContentItemManager.class); -// -// // Create new item -// final ContentItem item; -// try { -// @SuppressWarnings("unchecked") -// final Class clazz -// = (Class) Class -// .forName(contentType.getContentItemClass()); -// item = itemManager.createContentItem(name, -// section, -// folder, -// clazz, -// initializer); -// } catch (ClassNotFoundException ex) { -// throw new FormProcessException( -// "Couldn't create contentpage", -// new GlobalizedMessage( -// "cms.ui.authoring.couldnt_create_contentpage", -// CmsConstants.CMS_BUNDLE), -// ex); -// } -// -// // Create new item -// // Make sure the item will be remembered across requests -// selectionModel.setSelectedKey(state, item.getObjectId()); -// -// return item; return createContentItemPage(state, name, section, folder, null, - initializer); + initializer, + locale); } public T createContentItemPage( @@ -331,15 +301,14 @@ public abstract class BasicPageForm extends BasicItemForm { final ContentSection section, final Folder folder, final WorkflowTemplate workflowTemplate, - final ContentItemInitializer initializer) throws FormProcessException { + final ContentItemInitializer initializer, + final Locale locale) throws FormProcessException { final ItemSelectionModel selectionModel = getItemSelectionModel(); final ContentType contentType = selectionModel.getContentType(); // Create new item final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); -// final ContentItemManager itemManager = cdiUtil -// .findBean(ContentItemManager.class); final BasicPageFormController controller = cdiUtil .findBean(BasicPageFormController.class); @@ -349,33 +318,22 @@ public abstract class BasicPageForm extends BasicItemForm { final Class clazz = (Class) Class .forName(contentType.getContentItemClass()); -// @SuppressWarnings("unchecked") -// final Class clazz -// = (Class) Class -// .forName(contentType.getContentItemClass()); -// if (workflowTemplate == null) { -// item = itemManager.createContentItem(name, -// section, -// folder, -// clazz, -// initializer); item = controller - .createContentItem(name, section, folder, clazz, - initializer); + .createContentItem(name, + section, + folder, + clazz, + initializer, + locale); } else { -// item = itemManager.createContentItem(name, -// section, -// folder, -// workflowTemplate, -// clazz, -// initializer); item = controller.createContentItem(name, section, folder, workflowTemplate, clazz, - initializer); + initializer, + locale); } } catch (ClassNotFoundException ex) { throw new FormProcessException( diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicPageFormController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicPageFormController.java index 1d59daae5..ecf060772 100644 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicPageFormController.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/BasicPageFormController.java @@ -29,6 +29,8 @@ import org.librecms.contentsection.ContentSectionRepository; import org.librecms.contentsection.Folder; import org.librecms.contentsection.FolderRepository; +import java.util.Locale; + import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.transaction.Transactional; @@ -61,9 +63,16 @@ class BasicPageFormController { final ContentSection section, final Folder folder, final Class clazz, - final ContentItemInitializer initializer) { + final ContentItemInitializer initializer, + final Locale locale) { - return createContentItem(name, section, folder, null, clazz, initializer); + return createContentItem(name, + section, + folder, + null, + clazz, + initializer, + locale); } @Transactional(Transactional.TxType.REQUIRED) @@ -73,7 +82,8 @@ class BasicPageFormController { final Folder folder, final WorkflowTemplate workflowTemplate, final Class clazz, - final ContentItemInitializer initializer) { + final ContentItemInitializer initializer, + final Locale locale) { final ContentSection contentSection = sectionRepo .findById(section.getObjectId()) @@ -90,25 +100,27 @@ class BasicPageFormController { final T item; if (workflowTemplate == null) { - item = itemManager.createContentItem(name, - contentSection, - itemFolder, + item = itemManager.createContentItem(name, + contentSection, + itemFolder, clazz, - initializer); - + initializer, + locale); + } else { final WorkflowTemplate itemWorkflowTemplate = workflowTemplateRepo .findById(workflowTemplate.getWorkflowId()) .orElseThrow(() -> new IllegalArgumentException(String .format("No WorkflowTemplate with ID %d in the database.", workflowTemplate.getWorkflowId()))); - - item = itemManager.createContentItem(name, - contentSection, + + item = itemManager.createContentItem(name, + contentSection, itemFolder, - itemWorkflowTemplate, + itemWorkflowTemplate, clazz, - initializer); + initializer, + locale); } return item; diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/CreationSelector.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/CreationSelector.java index 9f530b86d..d4f854f32 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/CreationSelector.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/CreationSelector.java @@ -28,6 +28,7 @@ import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.SingleSelectionModel; import com.arsdigita.bebop.form.FormErrorDisplay; import com.arsdigita.bebop.parameters.LongParameter; +import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ui.ContentItemPage; import com.arsdigita.cms.ui.folder.FolderSelectionModel; @@ -91,10 +92,12 @@ public class CreationSelector extends MetaForm { private final FolderSelectionModel folderSelectionModel; private final SingleSelectionModel typeSelectionModel; + private final StringParameter selectedLanguageParam; private static final Class[] ARGUMENTS = new Class[]{ ItemSelectionModel.class, - CreationSelector.class + CreationSelector.class, + StringParameter.class }; private Object[] values; @@ -115,14 +118,17 @@ public class CreationSelector extends MetaForm { * @param folderSelectionModel the {@link FolderSelectionModel} containing * the folder in which new items are to be * created + * @param selectedLanguageParam */ public CreationSelector(final SingleSelectionModel typeSelectionModel, - final FolderSelectionModel folderSelectionModel) { + final FolderSelectionModel folderSelectionModel, + final StringParameter selectedLanguageParam) { super("pageCreate"); this.typeSelectionModel = typeSelectionModel; this.folderSelectionModel = folderSelectionModel; + this.selectedLanguageParam = selectedLanguageParam; itemIdParameter = new LongParameter(ITEM_ID); itemSelectionModel = new ItemSelectionModel(itemIdParameter); @@ -200,7 +206,9 @@ public class CreationSelector extends MetaForm { final ItemSelectionModel itemSelectionModel = new ItemSelectionModel( type, itemIdParameter); - vals = new Object[]{itemSelectionModel, this}; + vals = new Object[]{itemSelectionModel, + this, + selectedLanguageParam}; final Constructor constructor = createClass .getConstructor(ARGUMENTS); diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/PageCreateForm.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/PageCreateForm.java index 201b0bcfe..5fff620aa 100755 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/PageCreateForm.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/authoring/PageCreateForm.java @@ -44,6 +44,7 @@ import org.libreccm.workflow.WorkflowTemplateRepository; import org.librecms.CmsConstants; import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItemInitializer; +import org.librecms.contentsection.ContentItemRepository; import org.librecms.contenttypes.ContentTypeInfo; import org.librecms.contenttypes.ContentTypesManager; @@ -68,14 +69,15 @@ public class PageCreateForm extends BasicPageForm implements FormSubmissionListener, CreationComponent { - private final CreationSelector creationSelector; - private ApplyWorkflowFormSection workflowSection; - /** * The state parameter which specifies the content section */ public static final String SECTION_ID = "sid"; + private final CreationSelector creationSelector; + private ApplyWorkflowFormSection workflowSection; + private final StringParameter selectedLanguageParam; + /** * Construct a new PageCreationForm * @@ -95,6 +97,7 @@ public class PageCreateForm super("PageCreate", itemModel, selectedLanguageParam); this.creationSelector = creationSelector; + this.selectedLanguageParam = selectedLanguageParam; workflowSection.setCreationSelector(creationSelector); addSubmissionListener(this); @@ -223,16 +226,19 @@ public class PageCreateForm final Long selectedWorkflowTemplateId = workflowSection .getSelectedWorkflowTemplateId(state); + final Locale locale = new Locale((String) data.get(LANGUAGE)); + + final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); + final ContentItem item; if (selectedWorkflowTemplateId == null) { item = createContentPage(state, (String) data.get(NAME), section, folder, - getItemInitializer(data, state)); + getItemInitializer(data, state), + locale); } else { - - final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final WorkflowTemplateRepository workflowTemplateRepo = cdiUtil .findBean(WorkflowTemplateRepository.class); final WorkflowTemplate workflowTemplate = workflowTemplateRepo @@ -246,14 +252,19 @@ public class PageCreateForm section, folder, workflowTemplate, - getItemInitializer(data, state)); + getItemInitializer(data, state), + locale); } - final Locale locale = new Locale((String) data.get(LANGUAGE)); - item.getName().addValue(locale, (String) data.get(NAME)); +// item.getName().addValue(locale, (String) data.get(NAME)); item.getTitle().addValue(locale, (String) data.get(TITLE)); -// workflowSection.applyWorkflow(state, item); + final ContentItemRepository itemRepo = cdiUtil + .findBean(ContentItemRepository.class); + itemRepo.save(item); + + state.setValue(selectedLanguageParam, locale.toString()); + creationSelector.editItem(state, item); } diff --git a/ccm-cms/src/main/java/com/arsdigita/cms/ui/folder/FolderBrowserController.java b/ccm-cms/src/main/java/com/arsdigita/cms/ui/folder/FolderBrowserController.java index ce35cd74d..794c5d244 100644 --- a/ccm-cms/src/main/java/com/arsdigita/cms/ui/folder/FolderBrowserController.java +++ b/ccm-cms/src/main/java/com/arsdigita/cms/ui/folder/FolderBrowserController.java @@ -372,18 +372,24 @@ public class FolderBrowserController { final FolderBrowserTableRow row = new FolderBrowserTableRow(); + final Locale negotiatedLocale = globalizationHelper + .getNegotiatedLocale(); + row.setObjectId(item.getObjectId()); row.setObjectUuid(item.getItemUuid()); - row.setName(item.getName().getValue(defaultLocale)); + + if (item.getName().hasValue(negotiatedLocale)) { + row.setName(item.getName().getValue(negotiatedLocale)); + } else { + row.setName(item.getName().getValue(defaultLocale)); + } final List languages = new ArrayList<>(itemL10NManager .availableLanguages(item)); languages.sort((lang1, lang2) -> lang1.toString().compareTo( lang2.toString())); row.setLanguages(languages); - if (item.getTitle().hasValue(globalizationHelper - .getNegotiatedLocale())) { - row.setTitle(item.getTitle().getValue(globalizationHelper - .getNegotiatedLocale())); + if (item.getTitle().hasValue(negotiatedLocale)) { + row.setTitle(item.getTitle().getValue(negotiatedLocale)); } else { row.setTitle(item.getTitle().getValue(defaultLocale)); } @@ -573,7 +579,8 @@ public class FolderBrowserController { CmsConstants.CATEGORIZATION_TYPE_FOLDER), builder.equal(fromItem.get("version"), ContentItemVersion.DRAFT), - builder.like(builder.lower(fromItem.get("displayName")), + builder.like(builder.lower(fromItem.get( + "displayName")), filterTerm) ) ) diff --git a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java index 0d88adb5b..ec2ee7c4e 100644 --- a/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java +++ b/ccm-cms/src/main/java/org/librecms/contentsection/ContentItemManager.java @@ -132,6 +132,7 @@ public class ContentItemManager { * @param section The content section in which the item is generated. * @param folder The folder in which in the item is stored. * @param type The type of the new content item. + * @param locale Initial locale of the new item * * @return The new content item. */ @@ -142,14 +143,16 @@ public class ContentItemManager { final ContentSection section, @RequiresPrivilege(ItemPrivileges.CREATE_NEW) final Folder folder, - final Class type) { + final Class type, + final Locale locale) { return createContentItem(name, section, folder, type, item -> { - }); + }, + locale); } @@ -168,6 +171,7 @@ public class ContentItemManager { * @param type The type of the new content item. * @param initalizer A {@link ContentItemInitializer} for setting mandatory * values + * @param locale Initial locale of the new item * * @return The new content item. */ @@ -179,7 +183,8 @@ public class ContentItemManager { @RequiresPrivilege(ItemPrivileges.CREATE_NEW) final Folder folder, final Class type, - final ContentItemInitializer initalizer) { + final ContentItemInitializer initalizer, + final Locale locale) { final Optional contentType = typeRepo .findByContentSectionAndClass(section, type); @@ -196,7 +201,8 @@ public class ContentItemManager { folder, contentType.get().getDefaultWorkflow(), type, - initalizer); + initalizer, + locale); } /** @@ -219,6 +225,7 @@ public class ContentItemManager { * @param workflowTemplate The template for the workflow to apply to the new * item. * @param type The type of the new content item. + * @param locale * * @return The new content item. */ @@ -230,7 +237,8 @@ public class ContentItemManager { @RequiresPrivilege(ItemPrivileges.CREATE_NEW) final Folder folder, final WorkflowTemplate workflowTemplate, - final Class type) { + final Class type, + final Locale locale) { return createContentItem(name, section, @@ -238,7 +246,8 @@ public class ContentItemManager { workflowTemplate, type, item -> { - }); + }, + locale); } @@ -264,6 +273,7 @@ public class ContentItemManager { * @param type The type of the new content item. * @param initializer Initialiser implementation for setting mandatory * properties of the new item. + * @param locale Initial locale of the new item * * @return The new content item. */ @@ -276,7 +286,8 @@ public class ContentItemManager { final Folder folder, final WorkflowTemplate workflowTemplate, final Class type, - final ContentItemInitializer initializer) { + final ContentItemInitializer initializer, + final Locale locale) { final Optional contentType = typeRepo .findByContentSectionAndClass(section, type); @@ -312,7 +323,7 @@ public class ContentItemManager { KernelConfig.class); item.setDisplayName(name); - item.getName().addValue(kernelConfig.getDefaultLocale(), + item.getName().addValue(locale, name); item.setVersion(ContentItemVersion.DRAFT); @@ -336,7 +347,7 @@ public class ContentItemManager { CATEGORIZATION_TYPE_FOLDER); contentItemRepo.save(item); - + if (item.getWorkflow() != null) { workflowManager.start(item.getWorkflow()); } @@ -526,8 +537,8 @@ public class ContentItemManager { source = (LocalizedString) readMethod.invoke(draftItem); target = (LocalizedString) readMethod.invoke(copy); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } @@ -539,8 +550,8 @@ public class ContentItemManager { try { linkedItem = (ContentItem) readMethod.invoke(draftItem); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } @@ -550,8 +561,8 @@ public class ContentItemManager { try { writeMethod.invoke(copy, linkedDraftItem); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } } else if (propType != null @@ -562,8 +573,8 @@ public class ContentItemManager { source = (List) readMethod.invoke(draftItem); target = (List) readMethod.invoke(copy); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } @@ -577,8 +588,8 @@ public class ContentItemManager { source = (Map) readMethod.invoke(draftItem); target = (Map) readMethod.invoke(copy); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } @@ -592,8 +603,8 @@ public class ContentItemManager { source = (Set) readMethod.invoke(draftItem); target = (Set) readMethod.invoke(copy); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } @@ -604,8 +615,8 @@ public class ContentItemManager { value = readMethod.invoke(draftItem); writeMethod.invoke(copy, value); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } } @@ -774,8 +785,8 @@ public class ContentItemManager { sourceStr = (LocalizedString) readMethod.invoke(source); targetStr = (LocalizedString) readMethod.invoke(target); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new UnexpectedErrorException(ex); } @@ -786,8 +797,8 @@ public class ContentItemManager { value = readMethod.invoke(source); writeMethod.invoke(target, value); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new UnexpectedErrorException(ex); } } @@ -911,8 +922,8 @@ public class ContentItemManager { source = (LocalizedString) readMethod.invoke(draftItem); target = (LocalizedString) readMethod.invoke(liveItem); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } @@ -923,8 +934,8 @@ public class ContentItemManager { try { linkedItem = (ContentItem) readMethod.invoke(draftItem); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } @@ -938,8 +949,8 @@ public class ContentItemManager { linkedDraftItem, ContentItem.class); writeMethod.invoke(liveItem, linkedLiveItem); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } } @@ -951,8 +962,8 @@ public class ContentItemManager { source = (List) readMethod.invoke(draftItem); target = (List) readMethod.invoke(liveItem); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } @@ -966,8 +977,8 @@ public class ContentItemManager { source = (Map) readMethod.invoke(draftItem); target = (Map) readMethod.invoke(liveItem); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } @@ -981,8 +992,8 @@ public class ContentItemManager { source = (Set) readMethod.invoke(draftItem); target = (Set) readMethod.invoke(liveItem); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } @@ -993,8 +1004,8 @@ public class ContentItemManager { value = readMethod.invoke(item); writeMethod.invoke(liveItem, value); } catch (IllegalAccessException - | IllegalArgumentException - | InvocationTargetException ex) { + | IllegalArgumentException + | InvocationTargetException ex) { throw new RuntimeException(ex); } } diff --git a/ccm-core/src/main/java/com/arsdigita/toolbox/ui/DomainObjectPropertySheet.java b/ccm-core/src/main/java/com/arsdigita/toolbox/ui/DomainObjectPropertySheet.java index 10bdd04dd..b4f54d9ee 100755 --- a/ccm-core/src/main/java/com/arsdigita/toolbox/ui/DomainObjectPropertySheet.java +++ b/ccm-core/src/main/java/com/arsdigita/toolbox/ui/DomainObjectPropertySheet.java @@ -130,7 +130,8 @@ public class DomainObjectPropertySheet extends PropertySheet { this.objectSelectionModel = objectSelectionModel; properties = new LinkedList<>(); if (selectedLanguageParam == null) { - this.selectedLanguageParam = new StringParameter("selected_language"); + this.selectedLanguageParam + = new StringParameter("selected_language"); } else { this.selectedLanguageParam = selectedLanguageParam; } @@ -609,11 +610,15 @@ public class DomainObjectPropertySheet extends PropertySheet { if (tmp instanceof LocalizedString) { final LocalizedString localizedString = (LocalizedString) tmp; - final Locale selectedLocale = new Locale( - (String) state.getValue(selectedLanguageParam)); - final Locale defaultLocale = KernelConfig - .getConfig() - .getDefaultLocale(); + final Object selectedLanguage = state.getValue( + selectedLanguageParam); + final Locale selectedLocale; + if (selectedLanguage instanceof Locale) { + selectedLocale = (Locale) selectedLanguage; + } else { + selectedLocale = new Locale((String) selectedLanguage); + } + if (localizedString.hasValue(selectedLocale)) { value = localizedString.getValue(selectedLocale); } else {