Search in sources :

Example 1 with ConfigElement

use of org.springframework.extensions.config.ConfigElement in project alfresco-remote-api by Alfresco.

the class OpenSearchElementReader method parse.

/**
 * @see org.springframework.extensions.config.xml.elementreader.ConfigElementReader#parse(org.dom4j.Element)
 */
@SuppressWarnings("unchecked")
public ConfigElement parse(Element element) {
    OpenSearchConfigElement configElement = null;
    if (element != null) {
        String elementName = element.getName();
        if (elementName.equals(ELEMENT_OPENSEARCH) == false) {
            throw new ConfigException("OpenSearchElementReader can only parse " + ELEMENT_OPENSEARCH + "elements, the element passed was '" + elementName + "'");
        }
        // go through the registered engines
        configElement = new OpenSearchConfigElement();
        Element pluginsElem = element.element(ELEMENT_ENGINES);
        if (pluginsElem != null) {
            Iterator<Element> engines = pluginsElem.elementIterator(ELEMENT_ENGINE);
            while (engines.hasNext()) {
                // construct engine
                Element engineElem = engines.next();
                String label = engineElem.attributeValue(ATTR_LABEL);
                String labelId = engineElem.attributeValue(ATTR_LABEL_ID);
                String proxy = engineElem.attributeValue(ATTR_PROXY);
                EngineConfig engineCfg = new EngineConfig(label, labelId, proxy);
                // construct urls for engine
                Iterator<Element> urlsConfig = engineElem.elementIterator(ELEMENT_URL);
                while (urlsConfig.hasNext()) {
                    Element urlConfig = urlsConfig.next();
                    String type = urlConfig.attributeValue(ATTR_TYPE);
                    String url = urlConfig.getTextTrim();
                    engineCfg.addUrl(type, url);
                }
                // register engine config
                configElement.addEngine(engineCfg);
            }
        }
        // extract proxy configuration
        String url = null;
        Element proxyElem = element.element(ELEMENT_PROXY);
        if (proxyElem != null) {
            Element urlElem = proxyElem.element(ELEMENT_URL);
            if (urlElem != null) {
                url = urlElem.getTextTrim();
                ProxyConfig proxyCfg = new ProxyConfig(url);
                configElement.setProxy(proxyCfg);
            }
        }
    }
    return configElement;
}
Also used : ConfigElement(org.springframework.extensions.config.ConfigElement) Element(org.dom4j.Element) ConfigException(org.springframework.extensions.config.ConfigException) EngineConfig(org.alfresco.repo.web.scripts.config.OpenSearchConfigElement.EngineConfig) ProxyConfig(org.alfresco.repo.web.scripts.config.OpenSearchConfigElement.ProxyConfig)

Example 2 with ConfigElement

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

the class BaseActionWizard method getTestableAspects.

/**
 * Returns a list of aspects that can be tested i.e. hasAspect
 *
 * @return List of SelectItem objects representing the aspects that can be tested for
 */
public List<SelectItem> getTestableAspects() {
    if ((this.testableAspects == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        // get the list of common aspects
        this.testableAspects = new ArrayList<SelectItem>();
        this.testableAspects.addAll(getCommonAspects());
        // get those aspects configured to appear only in the remove aspect action
        ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
        Config wizardCfg = svc.getConfig("Action Wizards");
        if (wizardCfg != null) {
            ConfigElement aspectsCfg = wizardCfg.getConfigElement("aspects-test");
            if (aspectsCfg != null) {
                List<SelectItem> aspects = readAspectsConfig(FacesContext.getCurrentInstance(), aspectsCfg);
                this.testableAspects.addAll(aspects);
            } else {
                logger.warn("Could not find 'aspects-test' configuration element");
            }
        } else {
            logger.warn("Could not find 'Action Wizards' configuration section");
        }
        // make sure the list is sorted by the label
        QuickSort sorter = new QuickSort(this.testableAspects, "label", true, IDataContainer.SORT_CASEINSENSITIVE);
        sorter.sort();
    }
    return this.testableAspects;
}
Also used : QuickSort(org.alfresco.web.data.QuickSort) ConfigService(org.springframework.extensions.config.ConfigService) ConfigElement(org.springframework.extensions.config.ConfigElement) SelectItem(javax.faces.model.SelectItem) Config(org.springframework.extensions.config.Config)

Example 3 with ConfigElement

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

the class BaseActionWizard method initialiseActionHandlers.

/**
 * Initialises the action handlers from the current configuration.
 */
protected void initialiseActionHandlers() {
    if ((this.actionHandlers == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
        Config wizardCfg = svc.getConfig("Action Wizards");
        if (wizardCfg != null) {
            ConfigElement actionHandlerCfg = wizardCfg.getConfigElement("action-handlers");
            if (actionHandlerCfg != null) {
                this.actionHandlers = new HashMap<String, IHandler>(20);
                // instantiate each handler and store in the map
                for (ConfigElement child : actionHandlerCfg.getChildren()) {
                    String actionName = child.getAttribute("name");
                    String handlerClass = child.getAttribute("class");
                    if (actionName != null && actionName.length() > 0 && handlerClass != null && handlerClass.length() > 0) {
                        try {
                            @SuppressWarnings("unchecked") Class klass = Class.forName(handlerClass);
                            IHandler handler = (IHandler) klass.newInstance();
                            this.actionHandlers.put(actionName, handler);
                        } catch (Exception e) {
                            throw new AlfrescoRuntimeException("Failed to setup action handler for '" + actionName + "'", e);
                        }
                    }
                }
            } else {
                logger.warn("Could not find 'action-handlers' configuration element");
            }
        } else {
            logger.warn("Could not find 'Action Wizards' configuration section");
        }
    }
}
Also used : ConfigService(org.springframework.extensions.config.ConfigService) ConfigElement(org.springframework.extensions.config.ConfigElement) Config(org.springframework.extensions.config.Config) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Example 4 with ConfigElement

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

the class BaseActionWizard method readAspectsConfig.

protected List<SelectItem> readAspectsConfig(FacesContext context, ConfigElement aspectsCfg) {
    List<SelectItem> aspects = new ArrayList<SelectItem>();
    for (ConfigElement child : aspectsCfg.getChildren()) {
        QName idQName = Repository.resolveToQName(child.getAttribute("name"));
        if (idQName != null) {
            // try and get the display label from config
            String label = Utils.getDisplayLabel(context, child);
            // if there wasn't a client based label try and get it from the dictionary
            if (label == null) {
                AspectDefinition aspectDef = this.getDictionaryService().getAspect(idQName);
                if (aspectDef != null) {
                    label = aspectDef.getTitle(this.getDictionaryService());
                } else {
                    label = idQName.getLocalName();
                }
            }
            aspects.add(new SelectItem(idQName.toString(), label));
        } else {
            logger.warn("Failed to resolve aspect '" + child.getAttribute("name") + "'");
        }
    }
    return aspects;
}
Also used : ConfigElement(org.springframework.extensions.config.ConfigElement) SelectItem(javax.faces.model.SelectItem) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) AspectDefinition(org.alfresco.service.cmr.dictionary.AspectDefinition)

Example 5 with ConfigElement

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

the class CreateRuleWizard method initialiseConditionHandlers.

/**
 * Initialises the condition handlers from the current configuration.
 */
protected void initialiseConditionHandlers() {
    if ((this.conditionHandlers == null) || (Application.isDynamicConfig(FacesContext.getCurrentInstance()))) {
        ConfigService svc = Application.getConfigService(FacesContext.getCurrentInstance());
        Config wizardCfg = svc.getConfig("Action Wizards");
        if (wizardCfg != null) {
            ConfigElement conditionHandlerCfg = wizardCfg.getConfigElement("condition-handlers");
            if (conditionHandlerCfg != null) {
                this.conditionHandlers = new HashMap<String, IHandler>(20);
                // instantiate each handler and store in the map
                for (ConfigElement child : conditionHandlerCfg.getChildren()) {
                    String conditionName = child.getAttribute("name");
                    String handlerClass = child.getAttribute("class");
                    if (conditionName != null && conditionName.length() > 0 && handlerClass != null && handlerClass.length() > 0) {
                        try {
                            @SuppressWarnings("unchecked") Class klass = Class.forName(handlerClass);
                            IHandler handler = (IHandler) klass.newInstance();
                            this.conditionHandlers.put(conditionName, handler);
                        } catch (Exception e) {
                            throw new AlfrescoRuntimeException("Failed to setup condition handler for '" + conditionName + "'", e);
                        }
                    }
                }
            } else {
                logger.warn("Could not find 'condition-handlers' configuration element");
            }
        } else {
            logger.warn("Could not find 'Action Wizards' configuration section");
        }
    }
}
Also used : ConfigService(org.springframework.extensions.config.ConfigService) ConfigElement(org.springframework.extensions.config.ConfigElement) Config(org.springframework.extensions.config.Config) IHandler(org.alfresco.web.bean.actions.IHandler) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException) IOException(java.io.IOException) AlfrescoRuntimeException(org.alfresco.error.AlfrescoRuntimeException)

Aggregations

ConfigElement (org.springframework.extensions.config.ConfigElement)38 Config (org.springframework.extensions.config.Config)21 ConfigService (org.springframework.extensions.config.ConfigService)18 Element (org.dom4j.Element)14 ConfigException (org.springframework.extensions.config.ConfigException)13 SelectItem (javax.faces.model.SelectItem)11 FacesContext (javax.faces.context.FacesContext)10 QuickSort (org.alfresco.web.data.QuickSort)9 QName (org.alfresco.service.namespace.QName)7 ArrayList (java.util.ArrayList)4 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)4 UIListItem (org.alfresco.web.ui.common.component.UIListItem)3 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)2 IOException (java.io.IOException)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 UIComponent (javax.faces.component.UIComponent)1