Localization Stuff, the 2nd
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4574 8810af33-2d31-482b-a856-94f89814c4dfccm-docs
parent
60423ae059
commit
d8845c4008
|
|
@ -21,15 +21,21 @@ package com.arsdigita.cms.ui.category;
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
import com.arsdigita.bebop.FormProcessException;
|
||||||
import com.arsdigita.bebop.PageState;
|
import com.arsdigita.bebop.PageState;
|
||||||
import com.arsdigita.bebop.SingleSelectionModel;
|
import com.arsdigita.bebop.SingleSelectionModel;
|
||||||
|
import com.arsdigita.bebop.Text;
|
||||||
import com.arsdigita.bebop.event.FormInitListener;
|
import com.arsdigita.bebop.event.FormInitListener;
|
||||||
import com.arsdigita.bebop.event.FormProcessListener;
|
import com.arsdigita.bebop.event.FormProcessListener;
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||||
import com.arsdigita.bebop.form.Option;
|
import com.arsdigita.bebop.form.Option;
|
||||||
import com.arsdigita.categorization.Category;
|
|
||||||
import com.arsdigita.dispatcher.AccessDeniedException;
|
import com.arsdigita.dispatcher.AccessDeniedException;
|
||||||
import java.util.Locale;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.libreccm.categorization.Category;
|
||||||
|
import org.libreccm.categorization.CategoryRepository;
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.libreccm.security.PermissionChecker;
|
||||||
|
import org.librecms.contentsection.privileges.AdminPrivileges;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a form for editing an existing localisation for the given category.
|
* Generates a form for editing an existing localisation for the given category.
|
||||||
|
|
@ -38,12 +44,12 @@ import org.apache.log4j.Logger;
|
||||||
* in order to present forms for managing the multi-language categories.
|
* in order to present forms for managing the multi-language categories.
|
||||||
*
|
*
|
||||||
* @author Sören Bernstein <quasi@quasiweb.de>
|
* @author Sören Bernstein <quasi@quasiweb.de>
|
||||||
* @version $Id: CategoryLocalizationEditForm.java $
|
* @author <a href="mailto:yannick.buelter@yabue.de">Yannick Bülter</a>
|
||||||
*/
|
*/
|
||||||
public class CategoryLocalizationEditForm extends CategoryLocalizationForm {
|
public class CategoryLocalizationEditForm extends CategoryLocalizationForm {
|
||||||
|
|
||||||
private static final Logger s_log = Logger.getLogger
|
private static final Logger LOGGER = LogManager.getLogger(
|
||||||
(CategoryLocalizationEditForm.class);
|
CategoryLocalizationAddForm.class);
|
||||||
|
|
||||||
private final SingleSelectionModel m_catLocale;
|
private final SingleSelectionModel m_catLocale;
|
||||||
/**
|
/**
|
||||||
|
|
@ -72,19 +78,20 @@ public class CategoryLocalizationEditForm extends CategoryLocalizationForm {
|
||||||
final Category category = m_category.getCategory(state);
|
final Category category = m_category.getCategory(state);
|
||||||
|
|
||||||
final String categoryLocalizationLocale = (String) m_catLocale.getSelectedKey(state);
|
final String categoryLocalizationLocale = (String) m_catLocale.getSelectedKey(state);
|
||||||
|
final Locale locale = new Locale(categoryLocalizationLocale);
|
||||||
|
|
||||||
// Hide Locale-Widget and lock it (read-only)
|
// Hide Locale-Widget and lock it (read-only)
|
||||||
m_locale.addOption(new Option(categoryLocalizationLocale,
|
m_locale.addOption(new Option(categoryLocalizationLocale,
|
||||||
new Locale(categoryLocalizationLocale).getDisplayLanguage()), state);
|
new Text(locale.getDisplayLanguage())), state);
|
||||||
m_locale.setValue(state, categoryLocalizationLocale);
|
m_locale.setValue(state, categoryLocalizationLocale);
|
||||||
// m_locale.setVisible(state, false);
|
// m_locale.setVisible(state, false);
|
||||||
m_locale.lock();
|
m_locale.lock();
|
||||||
|
|
||||||
m_name.setValue(state, category.getName(categoryLocalizationLocale));
|
m_title.setValue(state, category.getTitle().getValue(locale));
|
||||||
m_description.setValue(state, category.getDescription(categoryLocalizationLocale));
|
m_description.setValue(state, category.getDescription().getValue(locale));
|
||||||
m_url.setValue(state, category.getURL(categoryLocalizationLocale));
|
m_url.setValue(state, category.getName());
|
||||||
|
|
||||||
if (category.isEnabled(categoryLocalizationLocale)) {
|
if (category.isEnabled()) {
|
||||||
m_isEnabled.setValue(state, "yes");
|
m_isEnabled.setValue(state, "yes");
|
||||||
} else {
|
} else {
|
||||||
m_isEnabled.setValue(state, "no");
|
m_isEnabled.setValue(state, "no");
|
||||||
|
|
@ -99,25 +106,25 @@ public class CategoryLocalizationEditForm extends CategoryLocalizationForm {
|
||||||
public final void process(final FormSectionEvent e)
|
public final void process(final FormSectionEvent e)
|
||||||
throws FormProcessException {
|
throws FormProcessException {
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final PermissionChecker permissionChecker = cdiUtil.findBean(PermissionChecker.class);
|
||||||
|
final CategoryRepository categoryRepository = cdiUtil.findBean(CategoryRepository.class);
|
||||||
|
|
||||||
final PageState state = e.getPageState();
|
final PageState state = e.getPageState();
|
||||||
final Category category = m_category.getCategory(state);
|
final Category category = m_category.getCategory(state);
|
||||||
|
|
||||||
if (s_log.isDebugEnabled()) {
|
if (LOGGER.isDebugEnabled()) {
|
||||||
s_log.debug("Editing localization for locale " + m_locale +
|
LOGGER.debug("Editing localization for locale " + m_locale +
|
||||||
" for category " + category);
|
" for category " + category);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (category.canEdit()) {
|
if (permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES, category)) {
|
||||||
category.setName((String) m_name.getValue(state),
|
final Locale locale = new Locale((String) m_locale.getValue(state));
|
||||||
(String) m_locale.getValue(state));
|
category.getTitle().addValue(locale, (String) m_title.getValue(state));
|
||||||
category.setDescription((String) m_description.getValue(state),
|
category.getDescription().addValue(locale, (String) m_description.getValue(state));
|
||||||
(String) m_locale.getValue(state));
|
category.setName((String) m_url.getValue(state));
|
||||||
category.setURL((String) m_url.getValue(state),
|
category.setEnabled("yes".equals(m_isEnabled.getValue(state)));
|
||||||
(String) m_locale.getValue(state));
|
categoryRepository.save(category);
|
||||||
category.setEnabled("yes".equals(
|
|
||||||
(String) m_isEnabled.getValue(state)),
|
|
||||||
(String) m_locale.getValue(state));
|
|
||||||
category.save();
|
|
||||||
} else {
|
} else {
|
||||||
throw new AccessDeniedException();
|
throw new AccessDeniedException();
|
||||||
}
|
}
|
||||||
|
|
@ -44,12 +44,11 @@ import com.arsdigita.cms.ui.BaseForm;
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
import com.arsdigita.web.Web;
|
import com.arsdigita.web.Web;
|
||||||
import com.arsdigita.xml.Element;
|
import com.arsdigita.xml.Element;
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.libreccm.categorization.Category;
|
import org.libreccm.categorization.Category;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.TooManyListenersException;
|
import java.util.TooManyListenersException;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for CategoryLocalizationAddForm and CategoryLocalizationEditForm.
|
* Base class for CategoryLocalizationAddForm and CategoryLocalizationEditForm.
|
||||||
|
|
@ -62,6 +61,9 @@ import java.util.logging.Logger;
|
||||||
*/
|
*/
|
||||||
public class CategoryLocalizationForm extends BaseForm {
|
public class CategoryLocalizationForm extends BaseForm {
|
||||||
|
|
||||||
|
private static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(
|
||||||
|
CategoryLocalizationForm.class);
|
||||||
|
|
||||||
final CategoryRequestLocal m_category;
|
final CategoryRequestLocal m_category;
|
||||||
final SingleSelect m_locale;
|
final SingleSelect m_locale;
|
||||||
final TextField m_title;
|
final TextField m_title;
|
||||||
|
|
@ -178,10 +180,8 @@ public class CategoryLocalizationForm extends BaseForm {
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
} catch (TooManyListenersException ex) {
|
} catch (TooManyListenersException | IllegalArgumentException ex) {
|
||||||
Logger.getLogger(CategoryLocalizationForm.class.getName()).log(Level.SEVERE, null, ex);
|
LOGGER.fatal(ex);
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
Logger.getLogger(CategoryLocalizationForm.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
}
|
||||||
addField(gz("cms.ui.category.url"), m_url);
|
addField(gz("cms.ui.category.url"), m_url);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue