Search in sources :

Example 1 with OpenSearchConfigElement

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

the class SearchEngines method getUrls.

/**
 * Retrieve registered search engines
 *
 * @return  set of search engines
 */
private Set<UrlTemplate> getUrls(String urlType) {
    if (logger.isDebugEnabled())
        logger.debug("Search Engine parameters: urltype=" + urlType);
    Set<UrlTemplate> urls = new HashSet<UrlTemplate>();
    Config config = configService.getConfig("OpenSearch");
    OpenSearchConfigElement searchConfig = (OpenSearchConfigElement) config.getConfigElement(OpenSearchConfigElement.CONFIG_ELEMENT_ID);
    for (OpenSearchConfigElement.EngineConfig engineConfig : searchConfig.getEngines()) {
        Map<String, String> engineUrls = engineConfig.getUrls();
        for (Map.Entry<String, String> engineUrl : engineUrls.entrySet()) {
            String type = engineUrl.getKey();
            String url = searchProxy.createUrl(engineConfig, type);
            if ((urlType.equals(URL_ARG_ALL)) || (urlType.equals(URL_ARG_DESCRIPTION) && type.equals(MimetypeMap.MIMETYPE_OPENSEARCH_DESCRIPTION)) || (urlType.equals(URL_ARG_TEMPLATE) && !type.equals(MimetypeMap.MIMETYPE_OPENSEARCH_DESCRIPTION))) {
                String label = engineConfig.getLabel();
                String labelId = engineConfig.getLabelId();
                if (labelId != null && labelId.length() > 0) {
                    String i18nLabel = I18NUtil.getMessage(labelId);
                    if (i18nLabel == null && label == null) {
                        label = (i18nLabel == null) ? "$$" + labelId + "$$" : i18nLabel;
                    }
                }
                urls.add(new UrlTemplate(label, type, url));
            } else // TODO: Extract URL templates from OpenSearch description
            if (urlType.equals(URL_ARG_TEMPLATE) && type.equals(MimetypeMap.MIMETYPE_OPENSEARCH_DESCRIPTION)) {
            }
        }
    }
    if (logger.isDebugEnabled())
        logger.debug("Retrieved " + urls.size() + " engine registrations");
    return urls;
}
Also used : Config(org.springframework.extensions.config.Config) OpenSearchConfigElement(org.alfresco.repo.web.scripts.config.OpenSearchConfigElement) MimetypeMap(org.alfresco.repo.content.MimetypeMap) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 2 with OpenSearchConfigElement

use of org.alfresco.repo.web.scripts.config.OpenSearchConfigElement in project acs-community-packaging by Alfresco.

the class UIOpenSearch method getRegisteredEngines.

/**
 * Returns a list of OpenSearchEngine objects representing the
 * registered OpenSearch engines.
 *
 * @param context Faces context
 * @return List of registered engines
 */
private List<OpenSearchEngine> getRegisteredEngines(FacesContext context) {
    List<OpenSearchEngine> engines = null;
    // get the web api config service object from spring
    ConfigService cfgSvc = (ConfigService) FacesContextUtils.getRequiredWebApplicationContext(context).getBean("webscripts.config");
    SearchProxy searchProxy = (SearchProxy) FacesContextUtils.getRequiredWebApplicationContext(context).getBean("webscript.org.alfresco.repository.search.searchproxy.get");
    if (cfgSvc != null) {
        // get the OpenSearch configuration
        Config cfg = cfgSvc.getConfig("OpenSearch");
        OpenSearchConfigElement osConfig = (OpenSearchConfigElement) cfg.getConfigElement(OpenSearchConfigElement.CONFIG_ELEMENT_ID);
        if (osConfig != null) {
            // generate the the list of engines with a unique for each
            int id = 1;
            engines = new ArrayList<OpenSearchEngine>();
            Set<EngineConfig> enginesCfg = osConfig.getEngines();
            for (EngineConfig engineCfg : enginesCfg) {
                // resolve engine label
                String label = engineCfg.getLabel();
                String labelId = engineCfg.getLabelId();
                if (labelId != null && labelId.length() > 0) {
                    label = Application.getMessage(context, labelId);
                }
                // locate search engine template url of most appropriate response type
                String url = searchProxy.createUrl(engineCfg, MimetypeMap.MIMETYPE_ATOM);
                if (url == null) {
                    url = searchProxy.createUrl(engineCfg, MimetypeMap.MIMETYPE_RSS);
                }
                if (url != null) {
                    if (url.startsWith("/")) {
                        url = context.getExternalContext().getRequestContextPath() + "/wcservice" + url;
                    }
                    // add the engine
                    OpenSearchEngine engine = new OpenSearchEngine(id, label, url);
                    engines.add(engine);
                    // increase the id counter
                    id++;
                }
            }
        }
    }
    return engines;
}
Also used : ConfigService(org.springframework.extensions.config.ConfigService) EngineConfig(org.alfresco.repo.web.scripts.config.OpenSearchConfigElement.EngineConfig) Config(org.springframework.extensions.config.Config) SearchProxy(org.alfresco.repo.web.scripts.bean.SearchProxy) EngineConfig(org.alfresco.repo.web.scripts.config.OpenSearchConfigElement.EngineConfig) OpenSearchConfigElement(org.alfresco.repo.web.scripts.config.OpenSearchConfigElement)

Aggregations

OpenSearchConfigElement (org.alfresco.repo.web.scripts.config.OpenSearchConfigElement)2 Config (org.springframework.extensions.config.Config)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 MimetypeMap (org.alfresco.repo.content.MimetypeMap)1 SearchProxy (org.alfresco.repo.web.scripts.bean.SearchProxy)1 EngineConfig (org.alfresco.repo.web.scripts.config.OpenSearchConfigElement.EngineConfig)1 ConfigService (org.springframework.extensions.config.ConfigService)1