Search in sources :

Example 26 with ConfigService

use of org.springframework.extensions.config.ConfigService 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 ConfigService

use of org.springframework.extensions.config.ConfigService 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 ConfigService

use of org.springframework.extensions.config.ConfigService 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 ConfigService

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

the class Application method getErrorPage.

/**
 * Retrieves the configured error page for the application
 *
 * @param context The Spring context
 * @return The configured error page or null if the configuration is missing
 */
public static String getErrorPage(ApplicationContext context) {
    String errorPage = null;
    ConfigService svc = (ConfigService) context.getBean(BEAN_CONFIG_SERVICE);
    ClientConfigElement clientConfig = (ClientConfigElement) svc.getGlobalConfig().getConfigElement(ClientConfigElement.CONFIG_ELEMENT_ID);
    if (clientConfig != null) {
        errorPage = clientConfig.getErrorPage();
    }
    return errorPage;
}
Also used : ConfigService(org.springframework.extensions.config.ConfigService) ClientConfigElement(org.alfresco.web.config.ClientConfigElement)

Example 30 with ConfigService

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

the class AlfrescoNavigationHandler method handleDispatch.

private void handleDispatch(FacesContext context, String fromAction, String outcome, Node dispatchNode) {
    if (dispatchNode != null) {
        if (logger.isDebugEnabled())
            logger.debug("Found node with type '" + dispatchNode.getType().toString() + "' in dispatch context");
        // get the current view id
        String viewId = context.getViewRoot().getViewId();
        // see if there is any navigation config for the node type
        ConfigService configSvc = Application.getConfigService(context);
        NavigationConfigElement navigationCfg = null;
        try {
            Config nodeConfig = configSvc.getConfig(dispatchNode);
            navigationCfg = (NavigationConfigElement) nodeConfig.getConfigElement(NavigationElementReader.ELEMENT_NAVIGATION);
        } catch (InvalidNodeRefException e) {
            if (logger.isDebugEnabled())
                logger.debug("Invalid node reference: " + dispatchNode);
        }
        if (navigationCfg != null) {
            // see if there is config for the current view state
            NavigationResult navResult = navigationCfg.getOverride(viewId, outcome);
            if (navResult != null) {
                if (logger.isDebugEnabled())
                    logger.debug("Found navigation config: " + navResult);
                if (navResult.isOutcome()) {
                    navigate(context, fromAction, navResult.getResult());
                } else {
                    String newViewId = navResult.getResult();
                    if (newViewId.equals(viewId) == false) {
                        if (logger.isDebugEnabled())
                            logger.debug("Dispatching to new view id: " + newViewId);
                        goToView(context, newViewId);
                    } else {
                        if (logger.isDebugEnabled())
                            logger.debug("New view id is the same as the current one so setting outcome to null");
                        navigate(context, fromAction, null);
                    }
                }
            } else {
                if (logger.isDebugEnabled())
                    logger.debug("No override configuration found for current view or outcome");
                navigate(context, fromAction, outcome);
            }
        } else {
            if (logger.isDebugEnabled())
                logger.debug("No navigation configuration found for node");
            navigate(context, fromAction, outcome);
        }
        // reset the dispatch context
        ((NavigationBean) context.getExternalContext().getSessionMap().get(NavigationBean.BEAN_NAME)).resetDispatchContext();
    } else {
        if (logger.isDebugEnabled())
            logger.debug("No dispatch context found");
        // pass off to the original handler
        navigate(context, fromAction, outcome);
    }
}
Also used : ConfigService(org.springframework.extensions.config.ConfigService) NavigationBean(org.alfresco.web.bean.NavigationBean) WizardConfig(org.alfresco.web.config.WizardsConfigElement.WizardConfig) DialogConfig(org.alfresco.web.config.DialogsConfigElement.DialogConfig) Config(org.springframework.extensions.config.Config) InvalidNodeRefException(org.alfresco.service.cmr.repository.InvalidNodeRefException) NavigationResult(org.alfresco.web.config.NavigationResult) NavigationConfigElement(org.alfresco.web.config.NavigationConfigElement)

Aggregations

ConfigService (org.springframework.extensions.config.ConfigService)35 Config (org.springframework.extensions.config.Config)28 ConfigElement (org.springframework.extensions.config.ConfigElement)18 SelectItem (javax.faces.model.SelectItem)10 QuickSort (org.alfresco.web.data.QuickSort)9 FacesContext (javax.faces.context.FacesContext)7 DialogConfig (org.alfresco.web.config.DialogsConfigElement.DialogConfig)5 WizardConfig (org.alfresco.web.config.WizardsConfigElement.WizardConfig)5 ClientConfigElement (org.alfresco.web.config.ClientConfigElement)4 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)3 QName (org.alfresco.service.namespace.QName)3 IOException (java.io.IOException)2 Map (java.util.Map)2 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 PropertySheetConfigElement (org.alfresco.web.config.PropertySheetConfigElement)2 Collection (java.util.Collection)1 Iterator (java.util.Iterator)1 UIComponent (javax.faces.component.UIComponent)1 ResponseWriter (javax.faces.context.ResponseWriter)1 PropertyNotFoundException (javax.faces.el.PropertyNotFoundException)1