Search in sources :

Example 1 with UserPreferencesBean

use of org.alfresco.web.bean.users.UserPreferencesBean in project acs-community-packaging by Alfresco.

the class AuthenticationHelper method setupThread.

/**
 * Does all the stuff you need to do after successfully authenticating/validating a user ticket to set up the request
 * thread. A useful utility method for an authentication filter.
 *
 * @param sc
 *           the servlet context
 * @param req
 *           the request
 * @param res
 *           the response
 */
public static void setupThread(ServletContext sc, HttpServletRequest req, HttpServletResponse res, boolean useInterfaceLanguage) {
    if (logger.isDebugEnabled())
        logger.debug("Setting up the request thread.");
    // setup faces context
    FacesContext fc = Application.inPortalServer() ? AlfrescoFacesPortlet.getFacesContext(req) : FacesHelper.getFacesContext(req, res, sc);
    // Set the current locale and language (overriding the one already decoded from the Accept-Language header
    if (WebApplicationContextUtils.getRequiredWebApplicationContext(sc).containsBean(Application.BEAN_CONFIG_SERVICE)) {
        I18NUtil.setLocale(Application.getLanguage(req.getSession(), Application.getClientConfig(fc).isLanguageSelect() && useInterfaceLanguage));
    } else {
        Application.getLanguage(req.getSession(), false);
    }
    if (logger.isDebugEnabled())
        logger.debug("The general locale is : " + I18NUtil.getLocale());
    // Programatically retrieve the UserPreferencesBean from JSF
    UserPreferencesBean userPreferencesBean = (UserPreferencesBean) FacesHelper.getManagedBean(fc, "UserPreferencesBean");
    if (logger.isDebugEnabled())
        logger.debug("The UserPreferencesBean is : " + userPreferencesBean);
    if (userPreferencesBean != null) {
        String contentFilterLanguageStr = userPreferencesBean.getContentFilterLanguage();
        if (contentFilterLanguageStr != null) {
            // Set the locale for the method interceptor for MLText properties
            I18NUtil.setContentLocale(I18NUtil.parseLocale(contentFilterLanguageStr));
        } else {
            // Nothing has been selected, so remove the content filter
            I18NUtil.setContentLocale(null);
        }
        if (logger.isDebugEnabled())
            logger.debug("The content locale is : " + I18NUtil.getContentLocale());
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) UserPreferencesBean(org.alfresco.web.bean.users.UserPreferencesBean)

Example 2 with UserPreferencesBean

use of org.alfresco.web.bean.users.UserPreferencesBean in project acs-community-packaging by Alfresco.

the class MakeMultilingualEvaluator method evaluate.

public boolean evaluate(Node node) {
    FacesContext fc = FacesContext.getCurrentInstance();
    UserPreferencesBean userprefs = (UserPreferencesBean) FacesHelper.getManagedBean(fc, "UserPreferencesBean");
    // the total number of available languages for the translation have to be greather that 0
    int contentFilterLanguagesCount = userprefs.getContentFilterLanguages(false).length;
    return (node.isLocked() == false && node.hasAspect(ContentModel.ASPECT_WORKING_COPY) == false && node.hasAspect(ContentModel.ASPECT_MULTILINGUAL_DOCUMENT) == false && contentFilterLanguagesCount > 0);
}
Also used : FacesContext(javax.faces.context.FacesContext) UserPreferencesBean(org.alfresco.web.bean.users.UserPreferencesBean)

Example 3 with UserPreferencesBean

use of org.alfresco.web.bean.users.UserPreferencesBean in project acs-community-packaging by Alfresco.

the class UILanguageSelector method createList.

/**
 * Creates the list of SelectItem components to represent the list
 * of Langages the user can select from
 *
 * @return List of SelectItem components
 */
protected SelectItem[] createList() {
    FacesContext fc = FacesContext.getCurrentInstance();
    SpaceUsersBean spaceUserBean = (SpaceUsersBean) FacesHelper.getManagedBean(fc, "SpaceUsersBean");
    UserPreferencesBean userPreferencesBean = (UserPreferencesBean) FacesHelper.getManagedBean(fc, "UserPreferencesBean");
    // get the node ref
    NodeRef nodeRef = spaceUserBean.getNode().getNodeRef();
    if (this.onlyAvailableLanguages) {
        return userPreferencesBean.getAvailablesContentFilterLanguages(nodeRef, this.returnCurrentLanguage);
    } else {
        return userPreferencesBean.getContentFilterLanguages(false);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) NodeRef(org.alfresco.service.cmr.repository.NodeRef) UserPreferencesBean(org.alfresco.web.bean.users.UserPreferencesBean) SpaceUsersBean(org.alfresco.web.bean.users.SpaceUsersBean)

Example 4 with UserPreferencesBean

use of org.alfresco.web.bean.users.UserPreferencesBean in project acs-community-packaging by Alfresco.

the class AddTranslationEvaluator method evaluate.

/**
 * @see org.alfresco.web.action.ActionEvaluator#evaluate(org.alfresco.web.bean.repository.Node)
 */
public boolean evaluate(Node node) {
    boolean isNodeMultililingal = node.hasAspect(ContentModel.ASPECT_MULTILINGUAL_DOCUMENT);
    boolean isMLContainer = node.getType().equals(ContentModel.TYPE_MULTILINGUAL_CONTAINER);
    // the node must be multiligual (translation or ml container)
    if (isNodeMultililingal || isMLContainer) {
        FacesContext fc = FacesContext.getCurrentInstance();
        // where the pivot translation is located in
        if (MultilingualUtils.canAddChildrenToPivotSpace(node, fc)) {
            MultilingualContentService mlservice = (MultilingualContentService) FacesHelper.getManagedBean(fc, "MultilingualContentService");
            UserPreferencesBean userprefs = (UserPreferencesBean) FacesHelper.getManagedBean(fc, "UserPreferencesBean");
            // the number of translation of this document
            int availableTranslationCount = mlservice.getTranslations(node.getNodeRef()).size();
            // the total number of available languages for the translation
            int contentFilterLanguagesCount = userprefs.getContentFilterLanguages(false).length;
            // the number of translation must be < to the total number of available language for the content filter
            return (availableTranslationCount < contentFilterLanguagesCount);
        } else {
            return false;
        }
    } else {
        return false;
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) MultilingualContentService(org.alfresco.service.cmr.ml.MultilingualContentService) UserPreferencesBean(org.alfresco.web.bean.users.UserPreferencesBean)

Aggregations

FacesContext (javax.faces.context.FacesContext)4 UserPreferencesBean (org.alfresco.web.bean.users.UserPreferencesBean)4 MultilingualContentService (org.alfresco.service.cmr.ml.MultilingualContentService)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 SpaceUsersBean (org.alfresco.web.bean.users.SpaceUsersBean)1