Search in sources :

Example 1 with GrailsTagLibClass

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;
}
Also used : HashMap(java.util.HashMap) HashMap(java.util.HashMap) Map(java.util.Map) GrailsTagLibClass(grails.core.GrailsTagLibClass) GroovyObject(groovy.lang.GroovyObject)

Example 2 with GrailsTagLibClass

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);
                }
            }
        }
    }
}
Also used : GrailsClass(grails.core.GrailsClass) GrailsTagLibClass(grails.core.GrailsTagLibClass) DefaultGrailsTagLibClass(org.grails.core.DefaultGrailsTagLibClass)

Example 3 with GrailsTagLibClass

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;
}
Also used : GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) GroovyObject(groovy.lang.GroovyObject) GrailsTagLibClass(grails.core.GrailsTagLibClass) DefaultGrailsTagLibClass(org.grails.core.DefaultGrailsTagLibClass)

Example 4 with GrailsTagLibClass

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);
    }
}
Also used : DefaultGrailsTagLibClass(org.grails.core.DefaultGrailsTagLibClass) GrailsTagLibClass(grails.core.GrailsTagLibClass) DefaultGrailsTagLibClass(org.grails.core.DefaultGrailsTagLibClass)

Aggregations

GrailsTagLibClass (grails.core.GrailsTagLibClass)4 DefaultGrailsTagLibClass (org.grails.core.DefaultGrailsTagLibClass)3 GroovyObject (groovy.lang.GroovyObject)2 GrailsClass (grails.core.GrailsClass)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 GenericBeanDefinition (org.springframework.beans.factory.support.GenericBeanDefinition)1