All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dynamicextensionsalfresco.controlpanel.WebScriptHelper Maven / Gradle / Ivy

Go to download

Adds an OSGi container to alfresco repository supporting dynamic code reloading, classpath isolation and a bunch of other useful features

There is a newer version: 3.1.0
Show newest version
package com.github.dynamicextensionsalfresco.controlpanel;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.github.dynamicextensionsalfresco.controlpanel.template.TemplateWebScript;
import com.github.dynamicextensionsalfresco.webscripts.WebScriptUriRegistry;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.extensions.webscripts.WebScript;
import org.springframework.stereotype.Component;

import static java.util.Arrays.asList;

@Component
public class WebScriptHelper {

	@Autowired
	private BundleHelper bundleHelper;

	/* Main operations */

	public Map> getWebScripts() {
		final WebScriptUriRegistry registry = getApplicationContextBean(WebScriptUriRegistry.class);
		if (registry != null) {
			final List webScripts = registry.getWebScripts();
			final List templateWebScripts = new ArrayList(webScripts.size());
			for (final WebScript webScript : webScripts) {
				templateWebScripts.add(new TemplateWebScript(webScript));
			}
			Map> byFamily = new HashMap>();
			for (TemplateWebScript templateWebScript : templateWebScripts) {
				Set familys = templateWebScript.getFamilys();
				if (familys == null) {
					familys = new HashSet(asList("no family"));
				}
				for (String family : familys) {
					List familiyList = byFamily.get(family);
					if (familiyList == null) {
						familiyList = new ArrayList();
						byFamily.put(family, familiyList);
					}
					familiyList.add(templateWebScript);
				}
			}
			return byFamily;
		} else {
			return Collections.emptyMap();
		}
	}

	/* Utility operations */

	protected  T getApplicationContextBean(final Class clazz) {
		final ApplicationContext applicationContext = bundleHelper.getService(ApplicationContext.class);
		if (applicationContext != null) {
			return applicationContext.getBean(clazz);
		} else {
			return null;
		}
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy