use of org.alfresco.repo.web.scripts.bean.SearchProxy 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;
}
Aggregations