Localization Stuff, the 2nd
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4574 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
933e9da587
commit
6ebdf6ab43
|
|
@ -21,15 +21,21 @@ package com.arsdigita.cms.ui.category;
|
|||
import com.arsdigita.bebop.FormProcessException;
|
||||
import com.arsdigita.bebop.PageState;
|
||||
import com.arsdigita.bebop.SingleSelectionModel;
|
||||
import com.arsdigita.bebop.Text;
|
||||
import com.arsdigita.bebop.event.FormInitListener;
|
||||
import com.arsdigita.bebop.event.FormProcessListener;
|
||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||
import com.arsdigita.bebop.form.Option;
|
||||
import com.arsdigita.categorization.Category;
|
||||
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.
|
||||
|
|
@ -38,12 +44,12 @@ import org.apache.log4j.Logger;
|
|||
* in order to present forms for managing the multi-language categories.
|
||||
*
|
||||
* @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 {
|
||||
|
||||
private static final Logger s_log = Logger.getLogger
|
||||
(CategoryLocalizationEditForm.class);
|
||||
private static final Logger LOGGER = LogManager.getLogger(
|
||||
CategoryLocalizationAddForm.class);
|
||||
|
||||
private final SingleSelectionModel m_catLocale;
|
||||
/**
|
||||
|
|
@ -72,19 +78,20 @@ public class CategoryLocalizationEditForm extends CategoryLocalizationForm {
|
|||
final Category category = m_category.getCategory(state);
|
||||
|
||||
final String categoryLocalizationLocale = (String) m_catLocale.getSelectedKey(state);
|
||||
final Locale locale = new Locale(categoryLocalizationLocale);
|
||||
|
||||
// Hide Locale-Widget and lock it (read-only)
|
||||
m_locale.addOption(new Option(categoryLocalizationLocale,
|
||||
new Locale(categoryLocalizationLocale).getDisplayLanguage()), state);
|
||||
new Text(locale.getDisplayLanguage())), state);
|
||||
m_locale.setValue(state, categoryLocalizationLocale);
|
||||
// m_locale.setVisible(state, false);
|
||||
m_locale.lock();
|
||||
|
||||
m_name.setValue(state, category.getName(categoryLocalizationLocale));
|
||||
m_description.setValue(state, category.getDescription(categoryLocalizationLocale));
|
||||
m_url.setValue(state, category.getURL(categoryLocalizationLocale));
|
||||
m_title.setValue(state, category.getTitle().getValue(locale));
|
||||
m_description.setValue(state, category.getDescription().getValue(locale));
|
||||
m_url.setValue(state, category.getName());
|
||||
|
||||
if (category.isEnabled(categoryLocalizationLocale)) {
|
||||
if (category.isEnabled()) {
|
||||
m_isEnabled.setValue(state, "yes");
|
||||
} else {
|
||||
m_isEnabled.setValue(state, "no");
|
||||
|
|
@ -99,25 +106,25 @@ public class CategoryLocalizationEditForm extends CategoryLocalizationForm {
|
|||
public final void process(final FormSectionEvent e)
|
||||
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 Category category = m_category.getCategory(state);
|
||||
|
||||
if (s_log.isDebugEnabled()) {
|
||||
s_log.debug("Editing localization for locale " + m_locale +
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Editing localization for locale " + m_locale +
|
||||
" for category " + category);
|
||||
}
|
||||
|
||||
if (category.canEdit()) {
|
||||
category.setName((String) m_name.getValue(state),
|
||||
(String) m_locale.getValue(state));
|
||||
category.setDescription((String) m_description.getValue(state),
|
||||
(String) m_locale.getValue(state));
|
||||
category.setURL((String) m_url.getValue(state),
|
||||
(String) m_locale.getValue(state));
|
||||
category.setEnabled("yes".equals(
|
||||
(String) m_isEnabled.getValue(state)),
|
||||
(String) m_locale.getValue(state));
|
||||
category.save();
|
||||
if (permissionChecker.isPermitted(AdminPrivileges.ADMINISTER_CATEGORIES, category)) {
|
||||
final Locale locale = new Locale((String) m_locale.getValue(state));
|
||||
category.getTitle().addValue(locale, (String) m_title.getValue(state));
|
||||
category.getDescription().addValue(locale, (String) m_description.getValue(state));
|
||||
category.setName((String) m_url.getValue(state));
|
||||
category.setEnabled("yes".equals(m_isEnabled.getValue(state)));
|
||||
categoryRepository.save(category);
|
||||
} else {
|
||||
throw new AccessDeniedException();
|
||||
}
|
||||
|
|
@ -44,12 +44,11 @@ import com.arsdigita.cms.ui.BaseForm;
|
|||
import com.arsdigita.globalization.GlobalizedMessage;
|
||||
import com.arsdigita.web.Web;
|
||||
import com.arsdigita.xml.Element;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.libreccm.categorization.Category;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.TooManyListenersException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Base class for CategoryLocalizationAddForm and CategoryLocalizationEditForm.
|
||||
|
|
@ -62,6 +61,9 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public class CategoryLocalizationForm extends BaseForm {
|
||||
|
||||
private static final org.apache.logging.log4j.Logger LOGGER = LogManager.getLogger(
|
||||
CategoryLocalizationForm.class);
|
||||
|
||||
final CategoryRequestLocal m_category;
|
||||
final SingleSelect m_locale;
|
||||
final TextField m_title;
|
||||
|
|
@ -178,10 +180,8 @@ public class CategoryLocalizationForm extends BaseForm {
|
|||
}
|
||||
|
||||
});
|
||||
} catch (TooManyListenersException ex) {
|
||||
Logger.getLogger(CategoryLocalizationForm.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Logger.getLogger(CategoryLocalizationForm.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (TooManyListenersException | IllegalArgumentException ex) {
|
||||
LOGGER.fatal(ex);
|
||||
}
|
||||
addField(gz("cms.ui.category.url"), m_url);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue