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

Former-commit-id: 51a49ca93f
pull/2/head
jensp 2017-06-29 14:32:00 +00:00
parent 82083d7608
commit 0e94e8c9cd
13 changed files with 287 additions and 186 deletions

View File

@ -9,3 +9,7 @@ ccmRealm.credentialsMatcher = $passwordMatcher
securityManager.realms = $ccmRealm securityManager.realms = $ccmRealm
securityManager.rememberMeManager.cipherKey = p5h/Aphy0gfV+XThbEPqSG4iQNh2fTNH9ZEkSBAt/Ok= securityManager.rememberMeManager.cipherKey = p5h/Aphy0gfV+XThbEPqSG4iQNh2fTNH9ZEkSBAt/Ok=
cacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager
securityManager.cacheManager = $cacheManager

View File

@ -30,6 +30,7 @@ import com.arsdigita.bebop.event.FormSubmissionListener;
import com.arsdigita.bebop.event.FormValidationListener; import com.arsdigita.bebop.event.FormValidationListener;
import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.ui.authoring.ApplyWorkflowFormSection; 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.CreationComponent;
import com.arsdigita.cms.ui.authoring.CreationSelector; import com.arsdigita.cms.ui.authoring.CreationSelector;
import com.arsdigita.cms.ui.authoring.LanguageWidget; import com.arsdigita.cms.ui.authoring.LanguageWidget;
@ -44,6 +45,8 @@ import org.librecms.contentsection.ContentSection;
import org.librecms.contentsection.Folder; import org.librecms.contentsection.Folder;
import org.librecms.contenttypes.MultiPartArticle; import org.librecms.contenttypes.MultiPartArticle;
import java.util.Locale;
/** /**
* A form which will create a MultiPartArticle or one of its subclasses. * A form which will create a MultiPartArticle or one of its subclasses.
* *
@ -135,16 +138,20 @@ public class MultiPartArticleCreateForm
} }
@Override @Override
public void process(final FormSectionEvent e) throws FormProcessException { public void process(final FormSectionEvent event) throws FormProcessException {
final FormData data = e.getFormData(); final FormData data = event.getFormData();
final PageState state = e.getPageState(); final PageState state = event.getPageState();
final ContentSection section = creationSelector.getContentSection(state); final ContentSection section = creationSelector.getContentSection(state);
final Folder folder = creationSelector.getFolder(state); final Folder folder = creationSelector.getFolder(state);
final Locale locale = new Locale((String) data
.get(BasicItemForm.LANGUAGE));
final MultiPartArticle article = createArticle(state, final MultiPartArticle article = createArticle(state,
(String) data.get(NAME), (String) data.get(NAME),
section, section,
folder); folder,
locale);
article.getTitle().addValue(KernelConfig.getConfig().getDefaultLocale(), article.getTitle().addValue(KernelConfig.getConfig().getDefaultLocale(),
(String) data.get(TITLE)); (String) data.get(TITLE));
if (!CMSConfig.getConfig().isHideLaunchDate()) { if (!CMSConfig.getConfig().isHideLaunchDate()) {

View File

@ -301,6 +301,7 @@ public abstract class MultiPartArticleForm
* @param name * @param name
* @param section * @param section
* @param folder * @param folder
* @param locale Initial locale of the article.
* *
* @return the new content item (or a proper subclass) * @return the new content item (or a proper subclass)
* @throws com.arsdigita.bebop.FormProcessException * @throws com.arsdigita.bebop.FormProcessException
@ -308,7 +309,8 @@ public abstract class MultiPartArticleForm
public MultiPartArticle createArticle(final PageState state, public MultiPartArticle createArticle(final PageState state,
final String name, final String name,
final ContentSection section, final ContentSection section,
final Folder folder) final Folder folder,
final Locale locale)
throws FormProcessException { throws FormProcessException {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
@ -319,7 +321,8 @@ public abstract class MultiPartArticleForm
.createContentItem(name, .createContentItem(name,
section, section,
folder, folder,
MultiPartArticle.class); MultiPartArticle.class,
locale);
if (itemSelectionModel.getSelectedKey(state) == null) { if (itemSelectionModel.getSelectedKey(state) == null) {
itemSelectionModel.setSelectedKey(state, article.getObjectId()); itemSelectionModel.setSelectedKey(state, article.getObjectId());

View File

@ -19,6 +19,7 @@
package com.arsdigita.cms.ui; package com.arsdigita.cms.ui;
import com.arsdigita.bebop.PageState; import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.CMS; import com.arsdigita.cms.CMS;
import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItem;
@ -26,10 +27,15 @@ import org.librecms.contentsection.ContentSection;
import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.PageLocations; import com.arsdigita.cms.PageLocations;
import com.arsdigita.kernel.KernelConfig;
import com.arsdigita.web.ParameterMap; import com.arsdigita.web.ParameterMap;
import com.arsdigita.web.URL; import com.arsdigita.web.URL;
import org.libreccm.cdi.utils.CdiUtil;
import org.librecms.contentsection.ContentItemL10NManager;
import java.util.List; import java.util.List;
import java.util.Locale;
/** /**
* <p> * <p>
@ -41,11 +47,14 @@ import java.util.List;
class ContentItemContextBar extends ContentSectionContextBar { class ContentItemContextBar extends ContentSectionContextBar {
private final ItemSelectionModel itemSelectionModel; private final ItemSelectionModel itemSelectionModel;
private final StringParameter selectedLanguageParam;
ContentItemContextBar(final ItemSelectionModel itemSelectionModel) { ContentItemContextBar(final ItemSelectionModel itemSelectionModel,
final StringParameter selectedLanguageParam) {
super(); super();
this.itemSelectionModel = itemSelectionModel; this.itemSelectionModel = itemSelectionModel;
this.selectedLanguageParam = selectedLanguageParam;
} }
@Override @Override
@ -63,12 +72,33 @@ class ContentItemContextBar extends ContentSectionContextBar {
title.append(localize("cms.ui.content_item")); title.append(localize("cms.ui.content_item"));
title.append(": ") title.append(": ")
.append(item.getDisplayName()); .append(item.getDisplayName());
// final String language = item.getLanguage();
// if (language != null) { final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
// title.append(" (") final ContentItemL10NManager l10nManager = cdiUtil
// .append(language) .findBean(ContentItemL10NManager.class);
// .append(")"); 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)); entries.add(new Entry(title.toString(), url));

View File

@ -29,6 +29,7 @@ import com.arsdigita.bebop.Resettable;
import com.arsdigita.bebop.SimpleContainer; import com.arsdigita.bebop.SimpleContainer;
import com.arsdigita.bebop.SingleSelectionModel; import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.TabbedPane; import com.arsdigita.bebop.TabbedPane;
import com.arsdigita.bebop.Text;
import com.arsdigita.bebop.event.ActionEvent; import com.arsdigita.bebop.event.ActionEvent;
import com.arsdigita.bebop.event.ActionListener; import com.arsdigita.bebop.event.ActionListener;
import com.arsdigita.bebop.event.FormSectionEvent; import com.arsdigita.bebop.event.FormSectionEvent;
@ -66,6 +67,7 @@ import org.arsdigita.cms.CMSConfig;
import org.libreccm.cdi.utils.CdiUtil; import org.libreccm.cdi.utils.CdiUtil;
import org.librecms.CmsConstants; import org.librecms.CmsConstants;
import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentItemL10NManager;
import org.librecms.contentsection.ContentItemRepository; import org.librecms.contentsection.ContentItemRepository;
import org.librecms.contentsection.ContentItemVersion; import org.librecms.contentsection.ContentItemVersion;
import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.ContentSection;
@ -74,6 +76,7 @@ import org.librecms.contentsection.ContentType;
import org.librecms.dispatcher.ItemResolver; import org.librecms.dispatcher.ItemResolver;
import java.io.IOException; import java.io.IOException;
import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.Optional; import java.util.Optional;
@ -145,9 +148,9 @@ public class ContentItemPage extends CMSPage implements ActionListener {
private final TabbedPane tabbedPane; private final TabbedPane tabbedPane;
private final StringParameter returnUrlParameter; private final StringParameter returnUrlParameter;
private final ItemSelectionModel itemModel; private final ItemSelectionModel itemSelectionModel;
private final SingleSelectionModel<String> selectedLanguageModel; private final SingleSelectionModel<String> selectedLanguageModel;
private final ACSObjectSelectionModel typeModel; private final ACSObjectSelectionModel typeSelectionModel;
private final ContentItemRequestLocal itemRequestLocal; private final ContentItemRequestLocal itemRequestLocal;
private final Summary summaryPane; private final Summary summaryPane;
private final ItemWorkflowAdminPane workflowPane; private final ItemWorkflowAdminPane workflowPane;
@ -156,9 +159,9 @@ public class ContentItemPage extends CMSPage implements ActionListener {
private final ItemLanguages languagesPane; private final ItemLanguages languagesPane;
private final ItemRevisionAdminPane revisionsPane; private final ItemRevisionAdminPane revisionsPane;
private final ItemTemplates templatesPane; private final ItemTemplates templatesPane;
private final Link m_previewLink; private final Link previewLink;
private final GlobalNavigation m_globalNavigation; private final GlobalNavigation globalNavigation;
private final ContentItemContextBar m_contextBar; private final ContentItemContextBar contextBar;
private final StringParameter selectedLanguageParam; private final StringParameter selectedLanguageParam;
@ -175,11 +178,44 @@ public class ContentItemPage extends CMSPage implements ActionListener {
@Override @Override
public final void prepare(final PrintEvent event) { public final void prepare(final PrintEvent event) {
final PageState state = event.getPageState();
final Label label = (Label) event.getTarget(); final Label label = (Label) event.getTarget();
final ContentItem item = itemRequestLocal.getContentItem(event. final ContentItem item = itemRequestLocal.getContentItem(event.
getPageState()); 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); final LongParameter itemId = new LongParameter(ITEM_ID);
itemId.addParameterListener(new NotNullValidationListener(ITEM_ID)); itemId.addParameterListener(new NotNullValidationListener(ITEM_ID));
addGlobalStateParam(itemId); addGlobalStateParam(itemId);
itemModel = new ItemSelectionModel(itemId); itemSelectionModel = new ItemSelectionModel(itemId);
// Add the selected item language as parameter // Add the selected item language as parameter
selectedLanguageParam = new StringParameter( selectedLanguageParam = new StringParameter(
SELECTED_LANGUAGE); SELECTED_LANGUAGE);
selectedLanguageParam.addParameterListener( selectedLanguageParam.addParameterListener(
new NotNullValidationListener( new NotNullValidationListener(SELECTED_LANGUAGE));
SELECTED_LANGUAGE));
addGlobalStateParam(selectedLanguageParam); addGlobalStateParam(selectedLanguageParam);
selectedLanguageModel = new ParameterSingleSelectionModel<>( selectedLanguageModel = new ParameterSingleSelectionModel<>(
selectedLanguageParam); selectedLanguageParam);
@ -222,8 +257,10 @@ public class ContentItemPage extends CMSPage implements ActionListener {
STREAMLINED_CREATION); STREAMLINED_CREATION);
addGlobalStateParam(streamlinedCreation); addGlobalStateParam(streamlinedCreation);
typeModel = new ACSObjectSelectionModel(ContentType.class.getName(), typeSelectionModel = new ACSObjectSelectionModel(ContentType.class
ContentType.class.getName(), .getName(),
ContentType.class
.getName(),
contentType); contentType);
// Validate the item ID parameter (caches the validation). // Validate the item ID parameter (caches the validation).
@ -234,20 +271,22 @@ public class ContentItemPage extends CMSPage implements ActionListener {
returnUrlParameter = new StringParameter(RETURN_URL); returnUrlParameter = new StringParameter(RETURN_URL);
addGlobalStateParam(returnUrlParameter); addGlobalStateParam(returnUrlParameter);
m_globalNavigation = new GlobalNavigation(); globalNavigation = new GlobalNavigation();
add(m_globalNavigation); add(globalNavigation);
m_contextBar = new ContentItemContextBar(itemModel); contextBar = new ContentItemContextBar(itemSelectionModel,
add(m_contextBar); selectedLanguageParam);
add(contextBar);
// Create panels. // Create panels.
summaryPane = new Summary(itemModel); summaryPane = new Summary(itemSelectionModel);
wizardPane = new WizardSelector(itemModel, typeModel); wizardPane = new WizardSelector(itemSelectionModel, typeSelectionModel);
languagesPane = new ItemLanguages(itemModel, selectedLanguageModel); languagesPane = new ItemLanguages(itemSelectionModel,
selectedLanguageModel);
workflowPane = new ItemWorkflowAdminPane(itemId); // Make this use m_item XXX workflowPane = new ItemWorkflowAdminPane(itemId); // Make this use m_item XXX
lifecyclePane = new ItemLifecycleAdminPane(itemRequestLocal); lifecyclePane = new ItemLifecycleAdminPane(itemRequestLocal);
revisionsPane = new ItemRevisionAdminPane(itemRequestLocal); revisionsPane = new ItemRevisionAdminPane(itemRequestLocal);
templatesPane = new ItemTemplates(itemModel); templatesPane = new ItemTemplates(itemSelectionModel);
// Create tabbed pane. // Create tabbed pane.
tabbedPane = new TabbedPane(); tabbedPane = new TabbedPane();
@ -285,7 +324,7 @@ public class ContentItemPage extends CMSPage implements ActionListener {
}); });
// Build the preview link. // Build the preview link.
m_previewLink = new Link(new Label(gz("cms.ui.preview")), previewLink = new Link(new Label(gz("cms.ui.preview")),
new PrintListener() { new PrintListener() {
@Override @Override
@ -298,8 +337,8 @@ public class ContentItemPage extends CMSPage implements ActionListener {
} }
}); });
m_previewLink.setIdAttr("preview_link"); previewLink.setIdAttr("preview_link");
add(m_previewLink); add(previewLink);
addActionListener(this); addActionListener(this);
@ -374,7 +413,7 @@ public class ContentItemPage extends CMSPage implements ActionListener {
*/ */
@Override @Override
public ContentItem getContentItem(final PageState state) { public ContentItem getContentItem(final PageState state) {
return (ContentItem) itemModel.getSelectedObject(state); return (ContentItem) itemSelectionModel.getSelectedObject(state);
} }
/** /**

View File

@ -38,6 +38,7 @@ import com.arsdigita.bebop.event.FormSubmissionListener;
import com.arsdigita.bebop.event.PrintEvent; import com.arsdigita.bebop.event.PrintEvent;
import com.arsdigita.bebop.event.PrintListener; import com.arsdigita.bebop.event.PrintListener;
import com.arsdigita.bebop.parameters.LongParameter; import com.arsdigita.bebop.parameters.LongParameter;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.CMS; import com.arsdigita.cms.CMS;
import org.librecms.contentsection.ContentSection; import org.librecms.contentsection.ContentSection;
@ -106,6 +107,7 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener,
private final Label contentLabel; private final Label contentLabel;
private final FolderPath folderPath; private final FolderPath folderPath;
private final Label chooseLabel; private final Label chooseLabel;
private final StringParameter selectedLanguageParam;
/** /**
* Construct a new item listing pane. The provided folder selection model is * 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( permissionsSegment.addHeader(new Label(new GlobalizedMessage(
"cms.ui.permissions", CmsConstants.CMS_BUNDLE))); "cms.ui.permissions", CmsConstants.CMS_BUNDLE)));
selectedLanguageParam = new StringParameter(ContentItemPage.SELECTED_LANGUAGE);
final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final PermissionManager permissionManager = cdiUtil.findBean( final PermissionManager permissionManager = cdiUtil.findBean(
PermissionManager.class); PermissionManager.class);
@ -198,7 +202,8 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener,
typeSelectionModel.addChangeListener(this); typeSelectionModel.addChangeListener(this);
creationSelector = new CreationSelector(typeSelectionModel, creationSelector = new CreationSelector(typeSelectionModel,
folderSelectionModel); folderSelectionModel,
selectedLanguageParam);
newItemSegment.add(creationSelector); newItemSegment.add(creationSelector);
//m_newItemSeg.add(new Label("<br/>", false)); //m_newItemSeg.add(new Label("<br/>", false));
@ -234,6 +239,7 @@ public class FlatItemList extends SegmentedPanel implements FormProcessListener,
page.addComponentStateParam(this, page.addComponentStateParam(this,
typeSelectionModel.getStateParameter()); typeSelectionModel.getStateParameter());
page.addGlobalStateParam(selectedLanguageParam);
page.addActionListener(new ActionListener() { page.addActionListener(new ActionListener() {

View File

@ -272,6 +272,7 @@ public abstract class BasicPageForm extends BasicItemForm {
* @param section * @param section
* @param folder * @param folder
* @param initializer * @param initializer
* @param locale
* *
* @return the new content item (or a proper subclass thereof) * @return the new content item (or a proper subclass thereof)
* *
@ -282,47 +283,16 @@ public abstract class BasicPageForm extends BasicItemForm {
final String name, final String name,
final ContentSection section, final ContentSection section,
final Folder folder, final Folder folder,
final ContentItemInitializer<T> initializer) throws FormProcessException { final ContentItemInitializer<T> 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<? extends ContentItem> clazz
// = (Class<? extends ContentItem>) 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, return createContentItemPage(state,
name, name,
section, section,
folder, folder,
null, null,
initializer); initializer,
locale);
} }
public <T extends ContentItem> T createContentItemPage( public <T extends ContentItem> T createContentItemPage(
@ -331,15 +301,14 @@ public abstract class BasicPageForm extends BasicItemForm {
final ContentSection section, final ContentSection section,
final Folder folder, final Folder folder,
final WorkflowTemplate workflowTemplate, final WorkflowTemplate workflowTemplate,
final ContentItemInitializer<T> initializer) throws FormProcessException { final ContentItemInitializer<T> initializer,
final Locale locale) throws FormProcessException {
final ItemSelectionModel selectionModel = getItemSelectionModel(); final ItemSelectionModel selectionModel = getItemSelectionModel();
final ContentType contentType = selectionModel.getContentType(); final ContentType contentType = selectionModel.getContentType();
// Create new item // Create new item
final CdiUtil cdiUtil = CdiUtil.createCdiUtil(); final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
// final ContentItemManager itemManager = cdiUtil
// .findBean(ContentItemManager.class);
final BasicPageFormController controller = cdiUtil final BasicPageFormController controller = cdiUtil
.findBean(BasicPageFormController.class); .findBean(BasicPageFormController.class);
@ -349,33 +318,22 @@ public abstract class BasicPageForm extends BasicItemForm {
final Class<T> clazz = (Class<T>) Class final Class<T> clazz = (Class<T>) Class
.forName(contentType.getContentItemClass()); .forName(contentType.getContentItemClass());
// @SuppressWarnings("unchecked")
// final Class<? extends ContentItem> clazz
// = (Class<? extends ContentItem>) Class
// .forName(contentType.getContentItemClass());
//
if (workflowTemplate == null) { if (workflowTemplate == null) {
// item = itemManager.createContentItem(name,
// section,
// folder,
// clazz,
// initializer);
item = controller item = controller
.createContentItem(name, section, folder, clazz, .createContentItem(name,
initializer); section,
folder,
clazz,
initializer,
locale);
} else { } else {
// item = itemManager.createContentItem(name,
// section,
// folder,
// workflowTemplate,
// clazz,
// initializer);
item = controller.createContentItem(name, item = controller.createContentItem(name,
section, section,
folder, folder,
workflowTemplate, workflowTemplate,
clazz, clazz,
initializer); initializer,
locale);
} }
} catch (ClassNotFoundException ex) { } catch (ClassNotFoundException ex) {
throw new FormProcessException( throw new FormProcessException(

View File

@ -29,6 +29,8 @@ import org.librecms.contentsection.ContentSectionRepository;
import org.librecms.contentsection.Folder; import org.librecms.contentsection.Folder;
import org.librecms.contentsection.FolderRepository; import org.librecms.contentsection.FolderRepository;
import java.util.Locale;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.inject.Inject; import javax.inject.Inject;
import javax.transaction.Transactional; import javax.transaction.Transactional;
@ -61,9 +63,16 @@ class BasicPageFormController {
final ContentSection section, final ContentSection section,
final Folder folder, final Folder folder,
final Class<T> clazz, final Class<T> clazz,
final ContentItemInitializer<T> initializer) { final ContentItemInitializer<T> 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) @Transactional(Transactional.TxType.REQUIRED)
@ -73,7 +82,8 @@ class BasicPageFormController {
final Folder folder, final Folder folder,
final WorkflowTemplate workflowTemplate, final WorkflowTemplate workflowTemplate,
final Class<T> clazz, final Class<T> clazz,
final ContentItemInitializer<T> initializer) { final ContentItemInitializer<T> initializer,
final Locale locale) {
final ContentSection contentSection = sectionRepo final ContentSection contentSection = sectionRepo
.findById(section.getObjectId()) .findById(section.getObjectId())
@ -94,7 +104,8 @@ class BasicPageFormController {
contentSection, contentSection,
itemFolder, itemFolder,
clazz, clazz,
initializer); initializer,
locale);
} else { } else {
final WorkflowTemplate itemWorkflowTemplate = workflowTemplateRepo final WorkflowTemplate itemWorkflowTemplate = workflowTemplateRepo
@ -108,7 +119,8 @@ class BasicPageFormController {
itemFolder, itemFolder,
itemWorkflowTemplate, itemWorkflowTemplate,
clazz, clazz,
initializer); initializer,
locale);
} }
return item; return item;

View File

@ -28,6 +28,7 @@ import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.SingleSelectionModel; import com.arsdigita.bebop.SingleSelectionModel;
import com.arsdigita.bebop.form.FormErrorDisplay; import com.arsdigita.bebop.form.FormErrorDisplay;
import com.arsdigita.bebop.parameters.LongParameter; import com.arsdigita.bebop.parameters.LongParameter;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.ItemSelectionModel;
import com.arsdigita.cms.ui.ContentItemPage; import com.arsdigita.cms.ui.ContentItemPage;
import com.arsdigita.cms.ui.folder.FolderSelectionModel; import com.arsdigita.cms.ui.folder.FolderSelectionModel;
@ -91,10 +92,12 @@ public class CreationSelector extends MetaForm {
private final FolderSelectionModel folderSelectionModel; private final FolderSelectionModel folderSelectionModel;
private final SingleSelectionModel<Long> typeSelectionModel; private final SingleSelectionModel<Long> typeSelectionModel;
private final StringParameter selectedLanguageParam;
private static final Class[] ARGUMENTS = new Class[]{ private static final Class[] ARGUMENTS = new Class[]{
ItemSelectionModel.class, ItemSelectionModel.class,
CreationSelector.class CreationSelector.class,
StringParameter.class
}; };
private Object[] values; private Object[] values;
@ -115,14 +118,17 @@ public class CreationSelector extends MetaForm {
* @param folderSelectionModel the {@link FolderSelectionModel} containing * @param folderSelectionModel the {@link FolderSelectionModel} containing
* the folder in which new items are to be * the folder in which new items are to be
* created * created
* @param selectedLanguageParam
*/ */
public CreationSelector(final SingleSelectionModel<Long> typeSelectionModel, public CreationSelector(final SingleSelectionModel<Long> typeSelectionModel,
final FolderSelectionModel folderSelectionModel) { final FolderSelectionModel folderSelectionModel,
final StringParameter selectedLanguageParam) {
super("pageCreate"); super("pageCreate");
this.typeSelectionModel = typeSelectionModel; this.typeSelectionModel = typeSelectionModel;
this.folderSelectionModel = folderSelectionModel; this.folderSelectionModel = folderSelectionModel;
this.selectedLanguageParam = selectedLanguageParam;
itemIdParameter = new LongParameter(ITEM_ID); itemIdParameter = new LongParameter(ITEM_ID);
itemSelectionModel = new ItemSelectionModel(itemIdParameter); itemSelectionModel = new ItemSelectionModel(itemIdParameter);
@ -200,7 +206,9 @@ public class CreationSelector extends MetaForm {
final ItemSelectionModel itemSelectionModel final ItemSelectionModel itemSelectionModel
= new ItemSelectionModel( = new ItemSelectionModel(
type, itemIdParameter); type, itemIdParameter);
vals = new Object[]{itemSelectionModel, this}; vals = new Object[]{itemSelectionModel,
this,
selectedLanguageParam};
final Constructor<? extends FormSection> constructor = createClass final Constructor<? extends FormSection> constructor = createClass
.getConstructor(ARGUMENTS); .getConstructor(ARGUMENTS);

View File

@ -44,6 +44,7 @@ import org.libreccm.workflow.WorkflowTemplateRepository;
import org.librecms.CmsConstants; import org.librecms.CmsConstants;
import org.librecms.contentsection.ContentItem; import org.librecms.contentsection.ContentItem;
import org.librecms.contentsection.ContentItemInitializer; import org.librecms.contentsection.ContentItemInitializer;
import org.librecms.contentsection.ContentItemRepository;
import org.librecms.contenttypes.ContentTypeInfo; import org.librecms.contenttypes.ContentTypeInfo;
import org.librecms.contenttypes.ContentTypesManager; import org.librecms.contenttypes.ContentTypesManager;
@ -68,14 +69,15 @@ public class PageCreateForm
extends BasicPageForm extends BasicPageForm
implements FormSubmissionListener, CreationComponent { implements FormSubmissionListener, CreationComponent {
private final CreationSelector creationSelector;
private ApplyWorkflowFormSection workflowSection;
/** /**
* The state parameter which specifies the content section * The state parameter which specifies the content section
*/ */
public static final String SECTION_ID = "sid"; public static final String SECTION_ID = "sid";
private final CreationSelector creationSelector;
private ApplyWorkflowFormSection workflowSection;
private final StringParameter selectedLanguageParam;
/** /**
* Construct a new PageCreationForm * Construct a new PageCreationForm
* *
@ -95,6 +97,7 @@ public class PageCreateForm
super("PageCreate", itemModel, selectedLanguageParam); super("PageCreate", itemModel, selectedLanguageParam);
this.creationSelector = creationSelector; this.creationSelector = creationSelector;
this.selectedLanguageParam = selectedLanguageParam;
workflowSection.setCreationSelector(creationSelector); workflowSection.setCreationSelector(creationSelector);
addSubmissionListener(this); addSubmissionListener(this);
@ -223,16 +226,19 @@ public class PageCreateForm
final Long selectedWorkflowTemplateId = workflowSection final Long selectedWorkflowTemplateId = workflowSection
.getSelectedWorkflowTemplateId(state); .getSelectedWorkflowTemplateId(state);
final Locale locale = new Locale((String) data.get(LANGUAGE));
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final ContentItem item; final ContentItem item;
if (selectedWorkflowTemplateId == null) { if (selectedWorkflowTemplateId == null) {
item = createContentPage(state, item = createContentPage(state,
(String) data.get(NAME), (String) data.get(NAME),
section, section,
folder, folder,
getItemInitializer(data, state)); getItemInitializer(data, state),
locale);
} else { } else {
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
final WorkflowTemplateRepository workflowTemplateRepo = cdiUtil final WorkflowTemplateRepository workflowTemplateRepo = cdiUtil
.findBean(WorkflowTemplateRepository.class); .findBean(WorkflowTemplateRepository.class);
final WorkflowTemplate workflowTemplate = workflowTemplateRepo final WorkflowTemplate workflowTemplate = workflowTemplateRepo
@ -246,14 +252,19 @@ public class PageCreateForm
section, section,
folder, folder,
workflowTemplate, 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)); 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); creationSelector.editItem(state, item);
} }

View File

@ -372,18 +372,24 @@ public class FolderBrowserController {
final FolderBrowserTableRow row = new FolderBrowserTableRow(); final FolderBrowserTableRow row = new FolderBrowserTableRow();
final Locale negotiatedLocale = globalizationHelper
.getNegotiatedLocale();
row.setObjectId(item.getObjectId()); row.setObjectId(item.getObjectId());
row.setObjectUuid(item.getItemUuid()); row.setObjectUuid(item.getItemUuid());
if (item.getName().hasValue(negotiatedLocale)) {
row.setName(item.getName().getValue(negotiatedLocale));
} else {
row.setName(item.getName().getValue(defaultLocale)); row.setName(item.getName().getValue(defaultLocale));
}
final List<Locale> languages = new ArrayList<>(itemL10NManager final List<Locale> languages = new ArrayList<>(itemL10NManager
.availableLanguages(item)); .availableLanguages(item));
languages.sort((lang1, lang2) -> lang1.toString().compareTo( languages.sort((lang1, lang2) -> lang1.toString().compareTo(
lang2.toString())); lang2.toString()));
row.setLanguages(languages); row.setLanguages(languages);
if (item.getTitle().hasValue(globalizationHelper if (item.getTitle().hasValue(negotiatedLocale)) {
.getNegotiatedLocale())) { row.setTitle(item.getTitle().getValue(negotiatedLocale));
row.setTitle(item.getTitle().getValue(globalizationHelper
.getNegotiatedLocale()));
} else { } else {
row.setTitle(item.getTitle().getValue(defaultLocale)); row.setTitle(item.getTitle().getValue(defaultLocale));
} }
@ -573,7 +579,8 @@ public class FolderBrowserController {
CmsConstants.CATEGORIZATION_TYPE_FOLDER), CmsConstants.CATEGORIZATION_TYPE_FOLDER),
builder.equal(fromItem.get("version"), builder.equal(fromItem.get("version"),
ContentItemVersion.DRAFT), ContentItemVersion.DRAFT),
builder.like(builder.lower(fromItem.get("displayName")), builder.like(builder.lower(fromItem.get(
"displayName")),
filterTerm) filterTerm)
) )
) )

View File

@ -132,6 +132,7 @@ public class ContentItemManager {
* @param section The content section in which the item is generated. * @param section The content section in which the item is generated.
* @param folder The folder in which in the item is stored. * @param folder The folder in which in the item is stored.
* @param type The type of the new content item. * @param type The type of the new content item.
* @param locale Initial locale of the new item
* *
* @return The new content item. * @return The new content item.
*/ */
@ -142,14 +143,16 @@ public class ContentItemManager {
final ContentSection section, final ContentSection section,
@RequiresPrivilege(ItemPrivileges.CREATE_NEW) @RequiresPrivilege(ItemPrivileges.CREATE_NEW)
final Folder folder, final Folder folder,
final Class<T> type) { final Class<T> type,
final Locale locale) {
return createContentItem(name, return createContentItem(name,
section, section,
folder, folder,
type, type,
item -> { item -> {
}); },
locale);
} }
@ -168,6 +171,7 @@ public class ContentItemManager {
* @param type The type of the new content item. * @param type The type of the new content item.
* @param initalizer A {@link ContentItemInitializer} for setting mandatory * @param initalizer A {@link ContentItemInitializer} for setting mandatory
* values * values
* @param locale Initial locale of the new item
* *
* @return The new content item. * @return The new content item.
*/ */
@ -179,7 +183,8 @@ public class ContentItemManager {
@RequiresPrivilege(ItemPrivileges.CREATE_NEW) @RequiresPrivilege(ItemPrivileges.CREATE_NEW)
final Folder folder, final Folder folder,
final Class<T> type, final Class<T> type,
final ContentItemInitializer<T> initalizer) { final ContentItemInitializer<T> initalizer,
final Locale locale) {
final Optional<ContentType> contentType = typeRepo final Optional<ContentType> contentType = typeRepo
.findByContentSectionAndClass(section, type); .findByContentSectionAndClass(section, type);
@ -196,7 +201,8 @@ public class ContentItemManager {
folder, folder,
contentType.get().getDefaultWorkflow(), contentType.get().getDefaultWorkflow(),
type, type,
initalizer); initalizer,
locale);
} }
/** /**
@ -219,6 +225,7 @@ public class ContentItemManager {
* @param workflowTemplate The template for the workflow to apply to the new * @param workflowTemplate The template for the workflow to apply to the new
* item. * item.
* @param type The type of the new content item. * @param type The type of the new content item.
* @param locale
* *
* @return The new content item. * @return The new content item.
*/ */
@ -230,7 +237,8 @@ public class ContentItemManager {
@RequiresPrivilege(ItemPrivileges.CREATE_NEW) @RequiresPrivilege(ItemPrivileges.CREATE_NEW)
final Folder folder, final Folder folder,
final WorkflowTemplate workflowTemplate, final WorkflowTemplate workflowTemplate,
final Class<T> type) { final Class<T> type,
final Locale locale) {
return createContentItem(name, return createContentItem(name,
section, section,
@ -238,7 +246,8 @@ public class ContentItemManager {
workflowTemplate, workflowTemplate,
type, type,
item -> { item -> {
}); },
locale);
} }
@ -264,6 +273,7 @@ public class ContentItemManager {
* @param type The type of the new content item. * @param type The type of the new content item.
* @param initializer Initialiser implementation for setting mandatory * @param initializer Initialiser implementation for setting mandatory
* properties of the new item. * properties of the new item.
* @param locale Initial locale of the new item
* *
* @return The new content item. * @return The new content item.
*/ */
@ -276,7 +286,8 @@ public class ContentItemManager {
final Folder folder, final Folder folder,
final WorkflowTemplate workflowTemplate, final WorkflowTemplate workflowTemplate,
final Class<T> type, final Class<T> type,
final ContentItemInitializer<T> initializer) { final ContentItemInitializer<T> initializer,
final Locale locale) {
final Optional<ContentType> contentType = typeRepo final Optional<ContentType> contentType = typeRepo
.findByContentSectionAndClass(section, type); .findByContentSectionAndClass(section, type);
@ -312,7 +323,7 @@ public class ContentItemManager {
KernelConfig.class); KernelConfig.class);
item.setDisplayName(name); item.setDisplayName(name);
item.getName().addValue(kernelConfig.getDefaultLocale(), item.getName().addValue(locale,
name); name);
item.setVersion(ContentItemVersion.DRAFT); item.setVersion(ContentItemVersion.DRAFT);

View File

@ -130,7 +130,8 @@ public class DomainObjectPropertySheet extends PropertySheet {
this.objectSelectionModel = objectSelectionModel; this.objectSelectionModel = objectSelectionModel;
properties = new LinkedList<>(); properties = new LinkedList<>();
if (selectedLanguageParam == null) { if (selectedLanguageParam == null) {
this.selectedLanguageParam = new StringParameter("selected_language"); this.selectedLanguageParam
= new StringParameter("selected_language");
} else { } else {
this.selectedLanguageParam = selectedLanguageParam; this.selectedLanguageParam = selectedLanguageParam;
} }
@ -609,11 +610,15 @@ public class DomainObjectPropertySheet extends PropertySheet {
if (tmp instanceof LocalizedString) { if (tmp instanceof LocalizedString) {
final LocalizedString localizedString final LocalizedString localizedString
= (LocalizedString) tmp; = (LocalizedString) tmp;
final Locale selectedLocale = new Locale( final Object selectedLanguage = state.getValue(
(String) state.getValue(selectedLanguageParam)); selectedLanguageParam);
final Locale defaultLocale = KernelConfig final Locale selectedLocale;
.getConfig() if (selectedLanguage instanceof Locale) {
.getDefaultLocale(); selectedLocale = (Locale) selectedLanguage;
} else {
selectedLocale = new Locale((String) selectedLanguage);
}
if (localizedString.hasValue(selectedLocale)) { if (localizedString.hasValue(selectedLocale)) {
value = localizedString.getValue(selectedLocale); value = localizedString.getValue(selectedLocale);
} else { } else {