Search in sources :

Example 1 with ProxyConfig

use of org.alfresco.repo.web.scripts.config.OpenSearchConfigElement.ProxyConfig 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 ProxyConfig

use of org.alfresco.repo.web.scripts.config.OpenSearchConfigElement.ProxyConfig in project alfresco-remote-api by Alfresco.

the class SearchProxy method afterPropertiesSet.

/* (non-Javadoc)
     * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
     */
public void afterPropertiesSet() throws Exception {
    Config config = configService.getConfig("OpenSearch");
    searchConfig = (OpenSearchConfigElement) config.getConfigElement(OpenSearchConfigElement.CONFIG_ELEMENT_ID);
    if (searchConfig == null) {
        throw new WebScriptException("OpenSearch configuration not found");
    }
    ProxyConfig proxyConfig = searchConfig.getProxy();
    if (proxyConfig == null) {
        throw new WebScriptException("OpenSearch proxy configuration not found");
    }
    proxyPath = proxyConfig.getUrl();
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) EngineConfig(org.alfresco.repo.web.scripts.config.OpenSearchConfigElement.EngineConfig) ProxyConfig(org.alfresco.repo.web.scripts.config.OpenSearchConfigElement.ProxyConfig) Config(org.springframework.extensions.config.Config) ProxyConfig(org.alfresco.repo.web.scripts.config.OpenSearchConfigElement.ProxyConfig)

Aggregations

EngineConfig (org.alfresco.repo.web.scripts.config.OpenSearchConfigElement.EngineConfig)2 ProxyConfig (org.alfresco.repo.web.scripts.config.OpenSearchConfigElement.ProxyConfig)2 Element (org.dom4j.Element)1 Config (org.springframework.extensions.config.Config)1 ConfigElement (org.springframework.extensions.config.ConfigElement)1 ConfigException (org.springframework.extensions.config.ConfigException)1 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)1