Search in sources :

Example 26 with Config

use of org.springframework.extensions.config.Config in project acs-community-packaging by Alfresco.

the class BaseActionWizard method getTransformers.

/**
 * Returns the transformers that are available
 *
 * @return List of SelectItem objects representing the available transformers
 */
public List<SelectItem> getTransformers() {
    if ((this.transformers == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
        Config wizardCfg = svc.getConfig("Action Wizards");
        if (wizardCfg != null) {
            ConfigElement transformersCfg = wizardCfg.getConfigElement("transformers");
            if (transformersCfg != null) {
                FacesContext context = FacesContext.getCurrentInstance();
                Map<String, String> mimeTypes = this.getMimetypeService().getDisplaysByMimetype();
                this.transformers = new ArrayList<SelectItem>();
                for (ConfigElement child : transformersCfg.getChildren()) {
                    String id = child.getAttribute("name");
                    // try and get the display label from config
                    String label = Utils.getDisplayLabel(context, child);
                    // if there wasn't a client based label get it from the mime type service
                    if (label == null) {
                        label = mimeTypes.get(id);
                    }
                    // if there is still no label use the raw mimetype
                    if (label == null) {
                        label = id;
                    }
                    this.transformers.add(new SelectItem(id, label));
                }
                // make sure the list is sorted by the label
                QuickSort sorter = new QuickSort(this.transformers, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
                sorter.sort();
            } else {
                logger.warn("Could not find 'transformers' configuration element");
            }
        } else {
            logger.warn("Could not find 'Action Wizards' configuration section");
        }
    }
    return this.transformers;
}
Also used : FacesContext(javax.faces.context.FacesContext) QuickSort(org.alfresco.web.data.QuickSort) ConfigService(org.springframework.extensions.config.ConfigService) ConfigElement(org.springframework.extensions.config.ConfigElement) Config(org.springframework.extensions.config.Config) SelectItem(javax.faces.model.SelectItem)

Example 27 with Config

use of org.springframework.extensions.config.Config in project acs-community-packaging by Alfresco.

the class ImportDialog method getEncoding.

/**
 * @return  Returns the encoding currently selected
 */
public String getEncoding() {
    if (encoding == null) {
        ConfigService configSvc = Application.getConfigService(FacesContext.getCurrentInstance());
        Config config = configSvc.getConfig("Import Dialog");
        if (config != null) {
            ConfigElement defaultEncCfg = config.getConfigElement("default-encoding");
            if (defaultEncCfg != null) {
                String value = defaultEncCfg.getValue();
                if (value != null) {
                    encoding = value.trim();
                }
            }
        }
        if (encoding == null || encoding.length() == 0) {
            // if not configured, set to a sensible default for most character sets
            encoding = "UTF-8";
        }
    }
    return encoding;
}
Also used : ConfigService(org.springframework.extensions.config.ConfigService) ConfigElement(org.springframework.extensions.config.ConfigElement) Config(org.springframework.extensions.config.Config)

Example 28 with Config

use of org.springframework.extensions.config.Config in project acs-community-packaging by Alfresco.

the class ImportDialog method getEncodings.

public List<SelectItem> getEncodings() {
    if ((this.encodings == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        FacesContext context = FacesContext.getCurrentInstance();
        this.encodings = new ArrayList<SelectItem>(3);
        ConfigService svc = Application.getConfigService(context);
        Config cfg = svc.getConfig("Import Dialog");
        if (cfg != null) {
            ConfigElement typesCfg = cfg.getConfigElement("encodings");
            if (typesCfg != null) {
                for (ConfigElement child : typesCfg.getChildren()) {
                    String encoding = child.getAttribute("name");
                    if (encoding != null) {
                        this.encodings.add(new SelectItem(encoding, encoding));
                    }
                }
            } else {
                logger.warn("Could not find 'encodings' configuration element");
            }
        } else {
            encodings = UICharsetSelector.getCharsetEncodingList();
        }
    }
    return this.encodings;
}
Also used : FacesContext(javax.faces.context.FacesContext) ConfigService(org.springframework.extensions.config.ConfigService) ConfigElement(org.springframework.extensions.config.ConfigElement) SelectItem(javax.faces.model.SelectItem) Config(org.springframework.extensions.config.Config)

Example 29 with Config

use of org.springframework.extensions.config.Config in project acs-community-packaging by Alfresco.

the class UIActions method encodeBegin.

/**
 * @see javax.faces.component.UIComponentBase#encodeBegin(javax.faces.context.FacesContext)
 */
@SuppressWarnings("unchecked")
public void encodeBegin(FacesContext context) throws IOException {
    if (isRendered() == false) {
        return;
    }
    if (logger.isDebugEnabled())
        logger.debug("encodeBegin() for <r:actions/> Id: " + getId() + " groupId: " + getValue());
    // put the context object into the requestMap so it is accessable
    // by any child component value binding expressions
    Object actionContext = getContext();
    Map requestMap = getFacesContext().getExternalContext().getRequestMap();
    requestMap.put(ACTION_CONTEXT, actionContext);
    String contextId;
    if (actionContext instanceof Node) {
        contextId = ((Node) actionContext).getType().toString();
        if (this.groups.contains(contextId)) {
            if (logger.isDebugEnabled())
                logger.debug("---already built component tree for actions contextId: " + contextId);
            return;
        }
    } else {
        contextId = CONTEXTID_DEFAULT;
        if (this.groups.contains(contextId)) {
            if (logger.isDebugEnabled())
                logger.debug("---already built component tree for default actions.");
            return;
        }
    }
    // this will need removing from the child component set to ensure that it does not grow endlessly
    for (Iterator i = getChildren().iterator(); i.hasNext(); ) /**/
    {
        UIComponent child = (UIComponent) i.next();
        if (contextId.equals(child.getAttributes().get("contextId"))) {
            if (logger.isDebugEnabled())
                logger.debug("***removing old child component set for contextId: " + contextId);
            i.remove();
            break;
        }
    }
    String groupId = getValue();
    if (groupId != null && groupId.length() != 0) {
        Config config;
        if (actionContext instanceof Node) {
            config = Application.getConfigService(context).getConfig(actionContext);
        } else {
            config = Application.getConfigService(context).getGlobalConfig();
        }
        if (config != null) {
            // find the Actions specific config element
            ActionsConfigElement actionConfig = (ActionsConfigElement) config.getConfigElement(ActionsConfigElement.CONFIG_ELEMENT_ID);
            if (actionConfig != null) {
                // and lookup our ActionGroup by Id
                ActionGroup actionGroup = actionConfig.getActionGroup(groupId);
                if (actionGroup != null) {
                    // render the action group component tree
                    if (logger.isDebugEnabled())
                        logger.debug("-constructing ActionGroup: " + groupId + " for ContextId: " + contextId);
                    buildActionGroup(context, actionConfig, actionGroup, contextId);
                } else {
                    logger.warn("Unable to find specified Action Group config ID: " + groupId);
                }
            }
        }
    }
}
Also used : ActionsConfigElement(org.alfresco.web.config.ActionsConfigElement) ActionGroup(org.alfresco.web.config.ActionsConfigElement.ActionGroup) Config(org.springframework.extensions.config.Config) Node(org.alfresco.web.bean.repository.Node) Iterator(java.util.Iterator) UIComponent(javax.faces.component.UIComponent) Map(java.util.Map)

Example 30 with Config

use of org.springframework.extensions.config.Config in project acs-community-packaging by Alfresco.

the class Application method getLanguage.

/**
 * Return the language Locale for the current user context
 *
 * @param fc        FacesContext for the current user
 *
 * @return Current language Locale set or the VM default if none set - never null
 */
public static Locale getLanguage(FacesContext fc) {
    boolean useInterfaceLanguage = Application.getClientConfig(fc).isLanguageSelect();
    Map sessionMap = fc.getExternalContext().getSessionMap();
    Boolean useSessionLocale = (Boolean) sessionMap.get(USE_SESSION_LOCALE);
    if (useSessionLocale == null) {
        useSessionLocale = Boolean.TRUE;
        sessionMap.put(USE_SESSION_LOCALE, useSessionLocale);
    }
    Locale locale = (Locale) sessionMap.get(LOCALE);
    if (locale == null || (!locale.equals(I18NUtil.getLocale()) && !useInterfaceLanguage)) {
        if (useSessionLocale && useInterfaceLanguage) {
            // first check saved user preferences
            String strLocale = null;
            if (getCurrentUser(fc) != null) {
                strLocale = (String) PreferencesService.getPreferences(fc).getValue(UserPreferencesBean.PREF_INTERFACELANGUAGE);
                if (strLocale != null) {
                    locale = I18NUtil.parseLocale(strLocale);
                } else {
                    // failing that, use the server default locale
                    locale = Locale.getDefault();
                }
            } else {
                // else get from web-client config - the first item in the configured list of languages
                Config config = Application.getConfigService(fc).getConfig("Languages");
                LanguagesConfigElement langConfig = (LanguagesConfigElement) config.getConfigElement(LanguagesConfigElement.CONFIG_ELEMENT_ID);
                List<String> languages = langConfig.getLanguages();
                if (languages != null && languages.size() != 0) {
                    locale = I18NUtil.parseLocale(languages.get(0));
                } else {
                    // failing that, use the server default locale
                    locale = Locale.getDefault();
                }
            }
            // save in user session
            sessionMap.put(LOCALE, locale);
        } else {
            // Get the request default, already decoded from the request headers
            locale = I18NUtil.getLocale();
        }
    }
    return locale;
}
Also used : Locale(java.util.Locale) LanguagesConfigElement(org.alfresco.web.config.LanguagesConfigElement) Config(org.springframework.extensions.config.Config) Map(java.util.Map) MimetypeMap(org.alfresco.repo.content.MimetypeMap)

Aggregations

Config (org.springframework.extensions.config.Config)38 ConfigService (org.springframework.extensions.config.ConfigService)28 ConfigElement (org.springframework.extensions.config.ConfigElement)21 SelectItem (javax.faces.model.SelectItem)11 FacesContext (javax.faces.context.FacesContext)10 QuickSort (org.alfresco.web.data.QuickSort)9 Map (java.util.Map)5 QName (org.alfresco.service.namespace.QName)5 DialogConfig (org.alfresco.web.config.DialogsConfigElement.DialogConfig)5 WizardConfig (org.alfresco.web.config.WizardsConfigElement.WizardConfig)5 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)4 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)3 LanguagesConfigElement (org.alfresco.web.config.LanguagesConfigElement)3 UIListItem (org.alfresco.web.ui.common.component.UIListItem)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 UIComponent (javax.faces.component.UIComponent)2 MimetypeMap (org.alfresco.repo.content.MimetypeMap)2 OpenSearchConfigElement (org.alfresco.repo.web.scripts.config.OpenSearchConfigElement)2