icfnext / aem-groovy-extension

OSGi bundle containing Groovy builders and metaclasses for Adobe Experience Manager.
http://icfnext.github.io/aem-groovy-extension/groovydocs/index.html
Other
4 stars 10 forks source link

Is it possible to use this osgi bundle to code in groovy for AEM. #6

Closed puttyman closed 8 years ago

puttyman commented 8 years ago

Same as title: Is it possible to use this osgi bundle to code in groovy for AEM. For example in Sightly you can import a groovy class as such:

<sly data-sly-use.logoComp="${ 'com.company.GroovyClass'}">
</sly>
package com.company;

import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.ValueMap;
import com.adobe.cq.sightly.WCMUsePojo;

public class GroovyClass extends WCMUsePojo {

    def String title;

    @Override
    def activate() throws Exception {

        ValueMap props = getProperties();
        try {
            if (props != null) {
                title = props.get("title", String.class);

            }
        } finally {
            props = null;
        }
    }

    def getTitle() {
        return title;
    }
}
markdaugherty commented 8 years ago

Yes, it is no different than using a Java class, as long as your bundle metadata is exporting the packages containing Groovy classes.

markdaugherty commented 8 years ago

You can also simplify your Sightly tag: <sly data-sly-use.logoComp="com.company.GroovyClass"> </sly>