use of grails.core.GrailsTagLibClass in project grails-core by grails.
the class JspInvokeGrailsTagLibTag method getTagLib.
@SuppressWarnings({ "unchecked", "rawtypes" })
private GroovyObject getTagLib(String name) {
if (application == null) {
initPageState();
}
Map tagLibs = (Map) pageContext.getAttribute(TAG_LIBS_ATTRIBUTE);
if (tagLibs == null) {
tagLibs = new HashMap();
pageContext.setAttribute(TAG_LIBS_ATTRIBUTE, tagLibs);
}
GrailsTagLibClass tagLibClass = (GrailsTagLibClass) application.getArtefactForFeature(TagLibArtefactHandler.TYPE, GroovyPage.DEFAULT_NAMESPACE + ':' + name);
GroovyObject tagLib;
if (tagLibs.containsKey(tagLibClass.getFullName())) {
tagLib = (GroovyObject) tagLibs.get(tagLibClass.getFullName());
} else {
tagLib = (GroovyObject) appContext.getBean(tagLibClass.getFullName());
tagLibs.put(tagLibClass.getFullName(), tagLib);
}
return tagLib;
}
use of grails.core.GrailsTagLibClass in project grails-core by grails.
the class TagLibArtefactHandler method initialize.
/**
* Creates a map of tags (keyed on "${namespace}:${tagName}") to tag libraries.
*/
@Override
public void initialize(ArtefactInfo artefacts) {
tag2libMap = new HashMap<String, GrailsTagLibClass>();
for (GrailsClass aClass : artefacts.getGrailsClasses()) {
GrailsTagLibClass taglibClass = (GrailsTagLibClass) aClass;
String namespace = taglibClass.getNamespace();
namespace2tagLibMap.put(namespace, taglibClass);
for (Object o : taglibClass.getTagNames()) {
String tagName = namespace + ":" + o;
if (!tag2libMap.containsKey(tagName)) {
tag2libMap.put(tagName, taglibClass);
} else {
GrailsTagLibClass current = tag2libMap.get(tagName);
if (!taglibClass.equals(current)) {
LogFactory.getLog(TagLibArtefactHandler.class).info("There are conflicting tags: " + taglibClass.getFullName() + "." + tagName + " vs. " + current.getFullName() + "." + tagName + ". The former will take precedence.");
tag2libMap.put(tagName, taglibClass);
}
}
}
}
}
use of grails.core.GrailsTagLibClass in project grails-core by grails.
the class LazyTagLibraryLookup method lookupTagLibrary.
@Override
public GroovyObject lookupTagLibrary(String namespace, String tagName) {
GroovyObject tagLibrary = super.lookupTagLibrary(namespace, tagName);
if (tagLibrary == null) {
String tagKey = tagNameKey(namespace, tagName);
GrailsTagLibClass taglibClass = lazyLoadableTagLibs.get(tagKey);
if (taglibClass != null) {
if (!applicationContext.containsBean(taglibClass.getFullName())) {
GenericBeanDefinition bd = new GenericBeanDefinition();
bd.setBeanClass(taglibClass.getClazz());
bd.setAutowireCandidate(true);
bd.setAutowireMode(AbstractBeanDefinition.AUTOWIRE_BY_NAME);
((GenericApplicationContext) applicationContext).getDefaultListableBeanFactory().registerBeanDefinition(taglibClass.getFullName(), bd);
}
registerTagLib(taglibClass);
tagLibrary = super.lookupTagLibrary(namespace, tagName);
}
}
return tagLibrary;
}
use of grails.core.GrailsTagLibClass in project grails-core by grails.
the class LazyTagLibraryLookup method registerLazyLoadableTagLibClass.
public void registerLazyLoadableTagLibClass(Class tagLibClass) {
GrailsTagLibClass grailsTagLibClass = new DefaultGrailsTagLibClass(tagLibClass);
if (!hasNamespace(grailsTagLibClass.getNamespace())) {
registerNamespaceDispatcher(grailsTagLibClass.getNamespace());
}
for (String tagName : grailsTagLibClass.getTagNames()) {
String tagKey = tagNameKey(grailsTagLibClass.getNamespace(), tagName);
lazyLoadableTagLibs.put(tagKey, grailsTagLibClass);
}
}
Aggregations